Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <cmdid.h>
21 : #include <hintids.hxx>
22 : #include <tools/urlobj.hxx>
23 : #include <vcl/msgbox.hxx>
24 : #include <svl/stritem.hxx>
25 : #include <svl/whiter.hxx>
26 : #include <svl/urihelper.hxx>
27 : #include <sfx2/docfile.hxx>
28 : #include <sfx2/dispatch.hxx>
29 :
30 : #include <sfx2/objface.hxx>
31 : #include <editeng/sizeitem.hxx>
32 : #include <editeng/protitem.hxx>
33 : #include <sfx2/request.hxx>
34 : #include <sfx2/sidebar/EnumContext.hxx>
35 : #include <svl/srchitem.hxx>
36 : #include <sfx2/htmlmode.hxx>
37 : #include <svx/sdgluitm.hxx>
38 : #include <svx/sdgcoitm.hxx>
39 : #include <svx/sdggaitm.hxx>
40 : #include <svx/sdgtritm.hxx>
41 : #include <svx/sdginitm.hxx>
42 : #include <svx/sdgmoitm.hxx>
43 : #include <editeng/brushitem.hxx>
44 : #include <svx/grfflt.hxx>
45 : #include <svx/compressgraphicdialog.hxx>
46 : #include <vcl/GraphicNativeTransform.hxx>
47 : #include <svx/tbxcolor.hxx>
48 : #include <fmturl.hxx>
49 : #include <view.hxx>
50 : #include <wrtsh.hxx>
51 : #include <viewopt.hxx>
52 : #include <swmodule.hxx>
53 : #include <frmatr.hxx>
54 : #include <swundo.hxx>
55 : #include <uitool.hxx>
56 : #include <docsh.hxx>
57 : #include <grfsh.hxx>
58 : #include <frmmgr.hxx>
59 : #include <frmdlg.hxx>
60 : #include <frmfmt.hxx>
61 : #include <grfatr.hxx>
62 : #include <usrpref.hxx>
63 : #include <edtwin.hxx>
64 : #include <swwait.hxx>
65 : #include <shells.hrc>
66 : #include <popup.hrc>
67 : #include <svx/extedit.hxx>
68 : #include <svx/graphichelper.hxx>
69 : #define SwGrfShell
70 : #include <sfx2/msg.hxx>
71 : #include "swslots.hxx"
72 :
73 : #include "swabstdlg.hxx"
74 :
75 : #define TOOLBOX_NAME "colorbar"
76 :
77 : namespace
78 : {
79 0 : class SwExternalToolEdit : public ExternalToolEdit
80 : {
81 : SwWrtShell* m_pShell;
82 :
83 : public:
84 0 : SwExternalToolEdit ( SwWrtShell* pShell ) :
85 0 : m_pShell (pShell)
86 0 : {}
87 :
88 0 : virtual void Update( Graphic& aGraphic )
89 : {
90 0 : m_pShell->ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aGraphic);
91 0 : }
92 : };
93 : }
94 :
95 198 : SFX_IMPL_INTERFACE(SwGrfShell, SwBaseShell, SW_RES(STR_SHELLNAME_GRAPHIC))
96 : {
97 33 : SFX_POPUPMENU_REGISTRATION(SW_RES(MN_GRF_POPUPMENU));
98 33 : SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_GRAFIK_TOOLBOX));
99 33 : }
100 :
101 0 : void SwGrfShell::Execute(SfxRequest &rReq)
102 : {
103 0 : SwWrtShell &rSh = GetShell();
104 :
105 0 : sal_uInt16 nSlot = rReq.GetSlot();
106 0 : switch(nSlot)
107 : {
108 : case SID_TWAIN_TRANSFER:
109 : {
110 0 : GetView().ExecuteScan( rReq );
111 0 : break;
112 : }
113 : case SID_SAVE_GRAPHIC:
114 : {
115 : const Graphic *pGraphic;
116 0 : if(0 != (pGraphic = rSh.GetGraphic()))
117 : {
118 0 : String sGrfNm, sFilterNm;
119 0 : rSh.GetGrfNms( &sGrfNm, &sFilterNm );
120 0 : GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
121 : }
122 : }
123 0 : break;
124 : case SID_COMPRESS_GRAPHIC:
125 : {
126 0 : const Graphic* pGraphic = rSh.GetGraphic();
127 0 : if( pGraphic )
128 : {
129 : Size aSize (
130 0 : TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width()),
131 0 : TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height()));
132 :
133 0 : SfxItemSet aSet( rSh.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
134 0 : rSh.GetCurAttr( aSet );
135 0 : SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
136 :
137 : Rectangle aCropRectangle(
138 0 : TWIP_TO_MM100(aCrop.GetLeft()),
139 0 : TWIP_TO_MM100(aCrop.GetTop()),
140 0 : TWIP_TO_MM100(aCrop.GetRight()),
141 0 : TWIP_TO_MM100(aCrop.GetBottom()) );
142 :
143 0 : Graphic aGraphic = Graphic( *pGraphic );
144 :
145 0 : CompressGraphicsDialog aDialog( GetView().GetWindow(), aGraphic, aSize, aCropRectangle, GetView().GetViewFrame()->GetBindings() );
146 0 : if( aDialog.Execute() == RET_OK )
147 : {
148 0 : rSh.StartAllAction();
149 0 : rSh.StartUndo(UNDO_START);
150 0 : Rectangle aScaledCropedRectangle = aDialog.GetScaledCropRectangle();
151 :
152 0 : aCrop.SetLeft( MM100_TO_TWIP( aScaledCropedRectangle.Left() ));
153 0 : aCrop.SetTop( MM100_TO_TWIP( aScaledCropedRectangle.Top() ));
154 0 : aCrop.SetRight( MM100_TO_TWIP( aScaledCropedRectangle.Right() ));
155 0 : aCrop.SetBottom( MM100_TO_TWIP( aScaledCropedRectangle.Bottom() ));
156 :
157 0 : Graphic aCompressedGraphic( aDialog.GetCompressedGraphic() );
158 0 : rSh.ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aCompressedGraphic);
159 :
160 0 : rSh.SetAttr(aCrop);
161 :
162 0 : rSh.EndUndo(UNDO_END);
163 0 : rSh.EndAllAction();
164 0 : }
165 : }
166 : }
167 0 : break;
168 : case SID_EXTERNAL_EDIT:
169 : {
170 : // When the graphic is selected to be opened via some external tool
171 : // for advanced editing
172 0 : GraphicObject *pGraphicObject = (GraphicObject *) rSh.GetGraphicObj();
173 0 : if(0 != pGraphicObject)
174 : {
175 0 : SwExternalToolEdit* externalToolEdit = new SwExternalToolEdit( &rSh );
176 0 : externalToolEdit->Edit ( pGraphicObject );
177 : }
178 : }
179 0 : break;
180 : case SID_INSERT_GRAPHIC:
181 : case FN_FORMAT_GRAFIC_DLG:
182 : case FN_DRAW_WRAP_DLG:
183 : {
184 0 : SwFlyFrmAttrMgr aMgr( sal_False, &rSh, rSh.IsFrmSelected() ?
185 0 : FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
186 0 : const SwViewOption* pVOpt = rSh.GetViewOptions();
187 0 : SwViewOption aUsrPref( *pVOpt );
188 :
189 0 : SfxItemSet aSet(GetPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1,
190 : RES_GRFATR_MIRRORGRF, RES_GRFATR_CROPGRF,
191 : SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
192 : SID_ATTR_GRAF_KEEP_ZOOM, SID_ATTR_GRAF_KEEP_ZOOM,
193 : SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
194 : SID_ATTR_GRAF_FRMSIZE_PERCENT, SID_ATTR_GRAF_FRMSIZE_PERCENT,
195 : SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
196 : FN_PARAM_GRF_CONNECT, FN_PARAM_GRF_CONNECT,
197 : SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
198 : FN_GET_PRINT_AREA, FN_GET_PRINT_AREA,
199 : FN_SET_FRM_NAME, FN_KEEP_ASPECT_RATIO,
200 : FN_PARAM_GRF_DIALOG, FN_PARAM_GRF_DIALOG,
201 : SID_DOCFRAME, SID_DOCFRAME,
202 : SID_HTML_MODE, SID_HTML_MODE,
203 : FN_SET_FRM_ALT_NAME, FN_SET_FRM_ALT_NAME,
204 0 : 0);
205 :
206 0 : sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
207 0 : aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
208 0 : FieldUnit eMetric = ::GetDfltMetric((0 != (nHtmlMode&HTMLMODE_ON)));
209 0 : SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
210 :
211 0 : const SwRect* pRect = &rSh.GetAnyCurRect(RECT_PAGE);
212 0 : SwFmtFrmSize aFrmSize( ATT_VAR_SIZE, pRect->Width(), pRect->Height());
213 0 : aFrmSize.SetWhich( GetPool().GetWhich( SID_ATTR_PAGE_SIZE ) );
214 0 : aSet.Put( aFrmSize );
215 :
216 0 : aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
217 0 : if ( nSlot == FN_FORMAT_GRAFIC_DLG )
218 : {
219 : // #i73249#
220 0 : aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
221 : }
222 :
223 0 : pRect = &rSh.GetAnyCurRect(RECT_PAGE_PRT);
224 0 : aFrmSize.SetWidth( pRect->Width() );
225 0 : aFrmSize.SetHeight( pRect->Height() );
226 0 : aFrmSize.SetWhich( GetPool().GetWhich(FN_GET_PRINT_AREA) );
227 0 : aSet.Put( aFrmSize );
228 :
229 0 : aSet.Put( aMgr.GetAttrSet() );
230 0 : aSet.SetParent( aMgr.GetAttrSet().GetParent() );
231 :
232 : // At percentage values initialize size
233 0 : SwFmtFrmSize aSizeCopy = (const SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
234 0 : if (aSizeCopy.GetWidthPercent() && aSizeCopy.GetWidthPercent() != 0xff)
235 0 : aSizeCopy.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
236 0 : if (aSizeCopy.GetHeightPercent() && aSizeCopy.GetHeightPercent() != 0xff)
237 0 : aSizeCopy.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
238 : // and now set the size for "external" tabpages
239 : {
240 0 : SvxSizeItem aSzItm( SID_ATTR_GRAF_FRMSIZE, aSizeCopy.GetSize() );
241 0 : aSet.Put( aSzItm );
242 :
243 0 : Size aSz( aSizeCopy.GetWidthPercent(), aSizeCopy.GetHeightPercent() );
244 0 : if( 0xff == aSz.Width() ) aSz.Width() = 0;
245 0 : if( 0xff == aSz.Height() ) aSz.Height() = 0;
246 :
247 0 : aSzItm.SetSize( aSz );
248 0 : aSzItm.SetWhich( SID_ATTR_GRAF_FRMSIZE_PERCENT );
249 0 : aSet.Put( aSzItm );
250 : }
251 :
252 0 : String sGrfNm, sFilterNm;
253 0 : rSh.GetGrfNms( &sGrfNm, &sFilterNm );
254 0 : if( sGrfNm.Len() )
255 : {
256 : aSet.Put( SvxBrushItem( INetURLObject::decode( sGrfNm,
257 : INET_HEX_ESCAPE,
258 : INetURLObject::DECODE_UNAMBIGUOUS,
259 : RTL_TEXTENCODING_UTF8 ),
260 : sFilterNm, GPOS_LT,
261 0 : SID_ATTR_GRAF_GRAPHIC ));
262 : }
263 : else
264 : {
265 : // #119353# - robust
266 0 : const GraphicObject* pGrfObj = rSh.GetGraphicObj();
267 0 : if ( pGrfObj )
268 : {
269 : aSet.Put( SvxBrushItem( *pGrfObj, GPOS_LT,
270 0 : SID_ATTR_GRAF_GRAPHIC ) );
271 : }
272 : }
273 0 : aSet.Put( SfxBoolItem( FN_PARAM_GRF_CONNECT, sGrfNm.Len() > 0 ) );
274 :
275 : // get Mirror and Crop
276 : {
277 0 : SfxItemSet aTmpSet( rSh.GetAttrPool(),
278 0 : RES_GRFATR_MIRRORGRF, RES_GRFATR_CROPGRF );
279 :
280 0 : rSh.GetCurAttr( aTmpSet );
281 0 : aSet.Put( aTmpSet );
282 : }
283 :
284 0 : aSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, aUsrPref.IsKeepRatio()));
285 0 : aSet.Put(SfxBoolItem( SID_ATTR_GRAF_KEEP_ZOOM, aUsrPref.IsGrfKeepZoom()));
286 :
287 0 : aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetTopFrame()));
288 :
289 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
290 : OSL_ENSURE(pFact, "Dialogdiet fail!");
291 : SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_GRF,
292 0 : GetView().GetViewFrame(),
293 0 : GetView().GetWindow(),
294 0 : aSet, sal_False, DLG_FRM_GRF);
295 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
296 :
297 0 : if (nSlot == FN_DRAW_WRAP_DLG)
298 0 : pDlg->SetCurPageId(TP_FRM_WRAP);
299 :
300 0 : if( pDlg->Execute() )
301 : {
302 0 : rSh.StartAllAction();
303 0 : rSh.StartUndo(UNDO_START);
304 : const SfxPoolItem* pItem;
305 0 : SfxItemSet* pSet = (SfxItemSet*)pDlg->GetOutputItemSet();
306 0 : rReq.Done(*pSet);
307 : // change the 2 frmsize SizeItems to the correct SwFrmSizeItem
308 0 : if( SFX_ITEM_SET == pSet->GetItemState(
309 0 : SID_ATTR_GRAF_FRMSIZE, sal_False, &pItem ))
310 : {
311 0 : SwFmtFrmSize aSize;
312 0 : const Size& rSz = ((SvxSizeItem*)pItem)->GetSize();
313 0 : aSize.SetWidth( rSz.Width() );
314 0 : aSize.SetHeight( rSz.Height() );
315 :
316 0 : if( SFX_ITEM_SET == pSet->GetItemState(
317 0 : SID_ATTR_GRAF_FRMSIZE_PERCENT, sal_False, &pItem ))
318 : {
319 0 : const Size& rRelativeSize = ((SvxSizeItem*)pItem)->GetSize();
320 0 : aSize.SetWidthPercent( static_cast< sal_uInt8 >( rRelativeSize.Width() ) );
321 0 : aSize.SetHeightPercent( static_cast< sal_uInt8 >( rRelativeSize.Height() ) );
322 : }
323 0 : pSet->Put( aSize );
324 : }
325 :
326 : // Templates AutoUpdate
327 0 : SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
328 0 : if(pFmt && pFmt->IsAutoUpdateFmt())
329 : {
330 0 : pFmt->SetFmtAttr(*pSet);
331 0 : SfxItemSet aShellSet(GetPool(), RES_FRM_SIZE, RES_FRM_SIZE,
332 : RES_SURROUND, RES_SURROUND,
333 : RES_ANCHOR, RES_ANCHOR,
334 : RES_VERT_ORIENT,RES_HORI_ORIENT,
335 0 : 0);
336 0 : aShellSet.Put(*pSet);
337 0 : aMgr.SetAttrSet(aShellSet);
338 : }
339 : else
340 : {
341 0 : aMgr.SetAttrSet(*pSet);
342 : }
343 0 : aMgr.UpdateFlyFrm();
344 :
345 0 : bool bApplyUsrPref = false;
346 0 : if (SFX_ITEM_SET == pSet->GetItemState(
347 0 : FN_KEEP_ASPECT_RATIO, sal_True, &pItem ))
348 : {
349 : aUsrPref.SetKeepRatio(
350 0 : ((const SfxBoolItem*)pItem)->GetValue() );
351 0 : bApplyUsrPref = true;
352 : }
353 0 : if( SFX_ITEM_SET == pSet->GetItemState(
354 0 : SID_ATTR_GRAF_KEEP_ZOOM, sal_True, &pItem ))
355 : {
356 : aUsrPref.SetGrfKeepZoom(
357 0 : ((const SfxBoolItem*)pItem)->GetValue() );
358 0 : bApplyUsrPref = true;
359 : }
360 :
361 0 : if( bApplyUsrPref )
362 0 : SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
363 :
364 : // and now set all the graphic attributes and other stuff
365 0 : if( SFX_ITEM_SET == pSet->GetItemState(
366 0 : SID_ATTR_GRAF_GRAPHIC, sal_True, &pItem ))
367 : {
368 0 : if( ((SvxBrushItem*)pItem)->GetGraphicLink() )
369 0 : sGrfNm = *((SvxBrushItem*)pItem)->GetGraphicLink();
370 : else
371 0 : sGrfNm.Erase();
372 :
373 0 : if( ((SvxBrushItem*)pItem)->GetGraphicFilter() )
374 0 : sFilterNm = *((SvxBrushItem*)pItem)->GetGraphicFilter();
375 : else
376 0 : sFilterNm.Erase();
377 :
378 0 : if( sGrfNm.Len() )
379 : {
380 0 : SwDocShell* pDocSh = GetView().GetDocShell();
381 0 : SwWait aWait( *pDocSh, sal_True );
382 0 : SfxMedium* pMedium = pDocSh->GetMedium();
383 0 : INetURLObject aAbs;
384 0 : if( pMedium )
385 0 : aAbs = pMedium->GetURLObject();
386 : rSh.ReRead( URIHelper::SmartRel2Abs(
387 : aAbs, sGrfNm,
388 : URIHelper::GetMaybeFileHdl() ),
389 0 : sFilterNm, 0 );
390 : }
391 : }
392 0 : if ( SFX_ITEM_SET == pSet->GetItemState(
393 0 : FN_SET_FRM_ALT_NAME, sal_True, &pItem ))
394 : {
395 : // #i73249#
396 0 : rSh.SetObjTitle( ((const SfxStringItem*)pItem)->GetValue() );
397 : }
398 :
399 0 : SfxItemSet aGrfSet( rSh.GetAttrPool(), RES_GRFATR_BEGIN,
400 0 : RES_GRFATR_END-1 );
401 0 : aGrfSet.Put( *pSet );
402 0 : if( aGrfSet.Count() )
403 0 : rSh.SetAttr( aGrfSet );
404 :
405 0 : rSh.EndUndo(UNDO_END);
406 0 : rSh.EndAllAction();
407 : }
408 0 : delete pDlg;
409 : }
410 0 : break;
411 :
412 : case FN_GRAPHIC_MIRROR_ON_EVEN_PAGES:
413 : {
414 0 : SfxItemSet aSet(rSh.GetAttrPool(), RES_GRFATR_MIRRORGRF, RES_GRFATR_MIRRORGRF);
415 0 : rSh.GetCurAttr( aSet );
416 0 : SwMirrorGrf aGrf((const SwMirrorGrf &)aSet.Get(RES_GRFATR_MIRRORGRF));
417 0 : aGrf.SetGrfToggle(!aGrf.IsGrfToggle());
418 0 : rSh.SetAttr(aGrf);
419 : }
420 0 : break;
421 :
422 : default:
423 : OSL_ENSURE(!this, "wrong dispatcher");
424 0 : return;
425 : }
426 : }
427 :
428 0 : void SwGrfShell::ExecAttr( SfxRequest &rReq )
429 : {
430 : sal_uInt16 nGrfType;
431 0 : if( CNT_GRF == GetShell().GetCntType() &&
432 0 : ( GRAPHIC_BITMAP == ( nGrfType = GetShell().GetGraphicType()) ||
433 : GRAPHIC_GDIMETAFILE == nGrfType ))
434 : {
435 0 : SfxItemSet aGrfSet( GetShell().GetAttrPool(), RES_GRFATR_BEGIN,
436 0 : RES_GRFATR_END -1 );
437 0 : const SfxItemSet *pArgs = rReq.GetArgs();
438 : const SfxPoolItem* pItem;
439 0 : sal_uInt16 nSlot = rReq.GetSlot();
440 0 : if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, sal_False, &pItem ))
441 0 : pItem = 0;
442 :
443 0 : switch( nSlot )
444 : {
445 : case SID_FLIP_VERTICAL:
446 : case SID_FLIP_HORIZONTAL:
447 : {
448 0 : GetShell().GetCurAttr( aGrfSet );
449 0 : SwMirrorGrf aMirror( (SwMirrorGrf&)aGrfSet.Get( RES_GRFATR_MIRRORGRF ) );
450 0 : sal_uInt16 nMirror = aMirror.GetValue();
451 0 : if ( nSlot==SID_FLIP_HORIZONTAL )
452 0 : switch( nMirror )
453 : {
454 0 : case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_VERT;
455 0 : break;
456 0 : case RES_MIRROR_GRAPH_HOR: nMirror = RES_MIRROR_GRAPH_BOTH;
457 0 : break;
458 0 : case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_DONT;
459 0 : break;
460 0 : case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_HOR;
461 0 : break;
462 : }
463 : else
464 0 : switch( nMirror )
465 : {
466 0 : case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_HOR;
467 0 : break;
468 0 : case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_BOTH;
469 0 : break;
470 0 : case RES_MIRROR_GRAPH_HOR: nMirror = RES_MIRROR_GRAPH_DONT;
471 0 : break;
472 0 : case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_VERT;
473 0 : break;
474 : }
475 0 : aMirror.SetValue( nMirror );
476 0 : aGrfSet.ClearItem();
477 0 : aGrfSet.Put( aMirror );
478 : }
479 0 : break;
480 :
481 : case SID_ATTR_GRAF_LUMINANCE:
482 0 : if( pItem )
483 : aGrfSet.Put( SwLuminanceGrf(
484 0 : ((SfxInt16Item*)pItem)->GetValue() ));
485 0 : break;
486 : case SID_ATTR_GRAF_CONTRAST:
487 0 : if( pItem )
488 : aGrfSet.Put( SwContrastGrf(
489 0 : ((SfxInt16Item*)pItem)->GetValue() ));
490 0 : break;
491 : case SID_ATTR_GRAF_RED:
492 0 : if( pItem )
493 : aGrfSet.Put( SwChannelRGrf(
494 0 : ((SfxInt16Item*)pItem)->GetValue() ));
495 0 : break;
496 : case SID_ATTR_GRAF_GREEN:
497 0 : if( pItem )
498 : aGrfSet.Put( SwChannelGGrf(
499 0 : ((SfxInt16Item*)pItem)->GetValue() ));
500 0 : break;
501 : case SID_ATTR_GRAF_BLUE:
502 0 : if( pItem )
503 : aGrfSet.Put( SwChannelBGrf(
504 0 : ((SfxInt16Item*)pItem)->GetValue() ));
505 0 : break;
506 : case SID_ATTR_GRAF_GAMMA:
507 0 : if( pItem )
508 : {
509 0 : double fVal = ((SfxUInt32Item*)pItem)->GetValue();
510 0 : aGrfSet.Put( SwGammaGrf(fVal/100. ));
511 : }
512 0 : break;
513 : case SID_ATTR_GRAF_TRANSPARENCE:
514 0 : if( pItem )
515 : aGrfSet.Put( SwTransparencyGrf(
516 0 : static_cast< sal_Int8 >( ( (SfxUInt16Item*)pItem )->GetValue() ) ) );
517 0 : break;
518 : case SID_ATTR_GRAF_INVERT:
519 0 : if( pItem )
520 : aGrfSet.Put( SwInvertGrf(
521 0 : ((SfxBoolItem*)pItem)->GetValue() ));
522 0 : break;
523 :
524 : case SID_ATTR_GRAF_MODE:
525 0 : if( pItem )
526 : aGrfSet.Put( SwDrawModeGrf(
527 0 : ((SfxUInt16Item*)pItem)->GetValue() ));
528 0 : break;
529 :
530 : case SID_COLOR_SETTINGS:
531 : {
532 0 : svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
533 0 : aToolboxAccess.toggleToolbox();
534 0 : break;
535 : }
536 : case SID_GRFFILTER:
537 : case SID_GRFFILTER_INVERT:
538 : case SID_GRFFILTER_SMOOTH:
539 : case SID_GRFFILTER_SHARPEN:
540 : case SID_GRFFILTER_REMOVENOISE:
541 : case SID_GRFFILTER_SOBEL:
542 : case SID_GRFFILTER_MOSAIC:
543 : case SID_GRFFILTER_EMBOSS:
544 : case SID_GRFFILTER_POSTER:
545 : case SID_GRFFILTER_POPART:
546 : case SID_GRFFILTER_SEPIA:
547 : case SID_GRFFILTER_SOLARIZE:
548 0 : if( GRAPHIC_BITMAP == nGrfType )
549 : {
550 : // #119353# - robust
551 0 : const GraphicObject* pFilterObj( GetShell().GetGraphicObj() );
552 0 : if ( pFilterObj )
553 : {
554 0 : GraphicObject aFilterObj( *pFilterObj );
555 0 : if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
556 0 : SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ))
557 0 : GetShell().ReRead( aEmptyStr, aEmptyStr,
558 0 : &aFilterObj.GetGraphic() );
559 : }
560 : }
561 0 : break;
562 :
563 : default:
564 : OSL_ENSURE(!this, "wrong dispatcher");
565 : }
566 0 : if( aGrfSet.Count() )
567 0 : GetShell().SetAttr( aGrfSet );
568 : }
569 0 : GetView().GetViewFrame()->GetBindings().Invalidate(rReq.GetSlot());
570 0 : }
571 :
572 0 : void SwGrfShell::GetAttrState(SfxItemSet &rSet)
573 : {
574 0 : SwWrtShell &rSh = GetShell();
575 0 : SfxItemSet aCoreSet( GetPool(), aNoTxtNodeSetRange );
576 0 : rSh.GetCurAttr( aCoreSet );
577 0 : bool bParentCntProt = 0 != rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
578 0 : bool bIsGrfCntnt = CNT_GRF == GetShell().GetCntType();
579 :
580 0 : SetGetStateSet( &rSet );
581 :
582 0 : SfxWhichIter aIter( rSet );
583 0 : sal_uInt16 nWhich = aIter.FirstWhich();
584 0 : while( nWhich )
585 : {
586 0 : bool bDisable = bParentCntProt;
587 0 : switch( nWhich )
588 : {
589 : case SID_INSERT_GRAPHIC:
590 : case FN_FORMAT_GRAFIC_DLG:
591 : case SID_TWAIN_TRANSFER:
592 0 : if( bParentCntProt || !bIsGrfCntnt )
593 0 : bDisable = true;
594 0 : break;
595 : case SID_SAVE_GRAPHIC:
596 : case SID_EXTERNAL_EDIT:
597 0 : if( rSh.GetGraphicType() == GRAPHIC_NONE )
598 0 : bDisable = true;
599 0 : break;
600 : case SID_COLOR_SETTINGS:
601 : {
602 0 : if ( bParentCntProt || !bIsGrfCntnt )
603 0 : bDisable = true;
604 : else
605 : {
606 0 : svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
607 0 : rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
608 : }
609 0 : break;
610 : }
611 :
612 : case SID_FLIP_HORIZONTAL:
613 0 : if( !bParentCntProt )
614 : {
615 : MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
616 0 : RES_GRFATR_MIRRORGRF )).GetValue());
617 :
618 0 : rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_VERT ||
619 0 : nState == RES_MIRROR_GRAPH_BOTH));
620 : }
621 0 : break;
622 :
623 : case SID_FLIP_VERTICAL:
624 0 : if( !bParentCntProt )
625 : {
626 : MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
627 0 : RES_GRFATR_MIRRORGRF )).GetValue());
628 :
629 0 : rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_HOR ||
630 0 : nState == RES_MIRROR_GRAPH_BOTH));
631 : }
632 0 : break;
633 :
634 :
635 : case SID_ATTR_GRAF_LUMINANCE:
636 0 : if( !bParentCntProt )
637 : rSet.Put( SfxInt16Item( nWhich, ((SwLuminanceGrf&)
638 0 : aCoreSet.Get(RES_GRFATR_LUMINANCE)).GetValue() ));
639 0 : break;
640 : case SID_ATTR_GRAF_CONTRAST:
641 0 : if( !bParentCntProt )
642 : rSet.Put( SfxInt16Item( nWhich, ((SwContrastGrf&)
643 0 : aCoreSet.Get(RES_GRFATR_CONTRAST)).GetValue() ));
644 0 : break;
645 : case SID_ATTR_GRAF_RED:
646 0 : if( !bParentCntProt )
647 : rSet.Put( SfxInt16Item( nWhich, ((SwChannelRGrf&)
648 0 : aCoreSet.Get(RES_GRFATR_CHANNELR)).GetValue() ));
649 0 : break;
650 : case SID_ATTR_GRAF_GREEN:
651 0 : if( !bParentCntProt )
652 : rSet.Put( SfxInt16Item( nWhich, ((SwChannelGGrf&)
653 0 : aCoreSet.Get(RES_GRFATR_CHANNELG)).GetValue() ));
654 0 : break;
655 : case SID_ATTR_GRAF_BLUE:
656 0 : if( !bParentCntProt )
657 : rSet.Put( SfxInt16Item( nWhich, ((SwChannelBGrf&)
658 0 : aCoreSet.Get(RES_GRFATR_CHANNELB)).GetValue() ));
659 0 : break;
660 :
661 : case SID_ATTR_GRAF_GAMMA:
662 0 : if( !bParentCntProt )
663 : rSet.Put( SfxUInt32Item( nWhich, static_cast< sal_uInt32 >(
664 0 : ( (SwGammaGrf&)aCoreSet.Get( RES_GRFATR_GAMMA ) ).GetValue() * 100 ) ) );
665 0 : break;
666 : case SID_ATTR_GRAF_TRANSPARENCE:
667 0 : if( !bParentCntProt )
668 : {
669 : // #119353# - robust
670 0 : const GraphicObject* pGrafObj = rSh.GetGraphicObj();
671 0 : if ( pGrafObj )
672 : {
673 0 : if( pGrafObj->IsAnimated() ||
674 0 : GRAPHIC_GDIMETAFILE == pGrafObj->GetType() )
675 0 : bDisable = true;
676 : else
677 : rSet.Put( SfxUInt16Item( nWhich, ((SwTransparencyGrf&)
678 0 : aCoreSet.Get(RES_GRFATR_TRANSPARENCY)).GetValue() ));
679 : }
680 : }
681 0 : break;
682 : case SID_ATTR_GRAF_INVERT:
683 0 : if( !bParentCntProt )
684 : rSet.Put( SfxBoolItem( nWhich, ((SwInvertGrf&)
685 0 : aCoreSet.Get(RES_GRFATR_INVERT)).GetValue() ));
686 0 : break;
687 :
688 : case SID_ATTR_GRAF_MODE:
689 0 : if( !bParentCntProt )
690 : rSet.Put( SfxUInt16Item( nWhich, ((SwDrawModeGrf&)
691 0 : aCoreSet.Get(RES_GRFATR_DRAWMODE)).GetValue() ));
692 0 : break;
693 :
694 : case SID_GRFFILTER:
695 : case SID_GRFFILTER_INVERT:
696 : case SID_GRFFILTER_SMOOTH:
697 : case SID_GRFFILTER_SHARPEN:
698 : case SID_GRFFILTER_REMOVENOISE:
699 : case SID_GRFFILTER_SOBEL:
700 : case SID_GRFFILTER_MOSAIC:
701 : case SID_GRFFILTER_EMBOSS:
702 : case SID_GRFFILTER_POSTER:
703 : case SID_GRFFILTER_POPART:
704 : case SID_GRFFILTER_SEPIA:
705 : case SID_GRFFILTER_SOLARIZE:
706 : {
707 0 : if( bParentCntProt || !bIsGrfCntnt )
708 0 : bDisable = true;
709 : // #i59688# load graphic only if type is unknown
710 : else
711 : {
712 0 : const sal_uInt16 eGraphicType( rSh.GetGraphicType() );
713 0 : if ( ( eGraphicType == GRAPHIC_NONE ||
714 0 : eGraphicType == GRAPHIC_DEFAULT ) &&
715 0 : rSh.IsGrfSwapOut( sal_True ) )
716 : {
717 0 : rSet.DisableItem( nWhich );
718 0 : if( AddGrfUpdateSlot( nWhich ))
719 0 : rSh.GetGraphic(sal_False); // start the loading
720 : }
721 : else
722 : {
723 0 : bDisable = eGraphicType != GRAPHIC_BITMAP;
724 : }
725 : }
726 : }
727 0 : break;
728 :
729 : default:
730 0 : bDisable = false;
731 : }
732 :
733 0 : if( bDisable )
734 0 : rSet.DisableItem( nWhich );
735 0 : nWhich = aIter.NextWhich();
736 : }
737 0 : SetGetStateSet( 0 );
738 0 : }
739 :
740 0 : void SwGrfShell::ExecuteRotation(SfxRequest &rReq)
741 : {
742 : sal_uInt16 aRotation;
743 :
744 0 : SwWrtShell& rShell = GetShell();
745 :
746 0 : if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_LEFT)
747 : {
748 0 : aRotation = 900;
749 : }
750 0 : else if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT)
751 : {
752 0 : aRotation = 2700;
753 : }
754 : else
755 : {
756 0 : return;
757 : }
758 :
759 0 : rShell.StartAllAction();
760 0 : rShell.StartUndo(UNDO_START);
761 :
762 0 : Graphic aGraphic = *rShell.GetGraphic();
763 0 : GraphicNativeTransform aTransform(aGraphic);
764 0 : aTransform.rotate(aRotation);
765 0 : rShell.ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aGraphic);
766 :
767 0 : SwFlyFrmAttrMgr aManager( false, &rShell, rShell.IsFrmSelected() ? FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
768 0 : Size aSize(aManager.GetSize().Height(), aManager.GetSize().Width());
769 0 : aManager.SetSize(aSize);
770 0 : aManager.UpdateFlyFrm();
771 :
772 0 : rShell.EndUndo(UNDO_END);
773 0 : rShell.EndAllAction();
774 : }
775 :
776 0 : void SwGrfShell::GetAttrStateForRotation(SfxItemSet &rSet)
777 : {
778 0 : SwWrtShell& rShell = GetShell();
779 0 : bool bIsParentContentProtected = 0 != rShell.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
780 :
781 0 : SetGetStateSet( &rSet );
782 :
783 0 : SfxWhichIter aIterator( rSet );
784 0 : sal_uInt16 nWhich = aIterator.FirstWhich();
785 0 : while( nWhich )
786 : {
787 0 : bool bDisable = bIsParentContentProtected;
788 0 : switch( nWhich )
789 : {
790 : case SID_ROTATE_GRAPHIC_LEFT:
791 : case SID_ROTATE_GRAPHIC_RIGHT:
792 0 : if( rShell.GetGraphicType() == GRAPHIC_NONE )
793 : {
794 0 : bDisable = true;
795 : }
796 : else
797 : {
798 0 : Graphic aGraphic = *rShell.GetGraphic();
799 0 : GraphicNativeTransform aTransform(aGraphic);
800 0 : if (!aTransform.canBeRotated())
801 : {
802 0 : bDisable = true;
803 0 : }
804 : }
805 0 : break;
806 : default:
807 0 : bDisable = false;
808 : }
809 :
810 0 : if( bDisable )
811 0 : rSet.DisableItem( nWhich );
812 0 : nWhich = aIterator.NextWhich();
813 : }
814 0 : SetGetStateSet( 0 );
815 0 : }
816 :
817 :
818 0 : SwGrfShell::SwGrfShell(SwView &_rView) :
819 0 : SwBaseShell(_rView)
820 :
821 : {
822 0 : SetName(OUString("Graphic"));
823 0 : SetHelpId(SW_GRFSHELL);
824 0 : SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
825 99 : }
826 :
827 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|