bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / grfsh.cxx
blob911d1e202c1e032bf5597a12836dd5fef110e588
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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"
73 #include "swabstdlg.hxx"
75 #define TOOLBOX_NAME "colorbar"
77 namespace
79 class SwExternalToolEdit : public ExternalToolEdit
81 SwWrtShell* m_pShell;
83 public:
84 SwExternalToolEdit ( SwWrtShell* pShell ) :
85 m_pShell (pShell)
88 virtual void Update( Graphic& aGraphic )
90 m_pShell->ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aGraphic);
95 SFX_IMPL_INTERFACE(SwGrfShell, SwBaseShell, SW_RES(STR_SHELLNAME_GRAPHIC))
97 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_GRF_POPUPMENU));
98 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_GRAFIK_TOOLBOX));
101 void SwGrfShell::Execute(SfxRequest &rReq)
103 SwWrtShell &rSh = GetShell();
105 sal_uInt16 nSlot = rReq.GetSlot();
106 switch(nSlot)
108 case SID_TWAIN_TRANSFER:
110 GetView().ExecuteScan( rReq );
111 break;
113 case SID_SAVE_GRAPHIC:
115 const Graphic *pGraphic;
116 if(0 != (pGraphic = rSh.GetGraphic()))
118 String sGrfNm, sFilterNm;
119 rSh.GetGrfNms( &sGrfNm, &sFilterNm );
120 GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
123 break;
124 case SID_COMPRESS_GRAPHIC:
126 const Graphic* pGraphic = rSh.GetGraphic();
127 if( pGraphic )
129 Size aSize (
130 TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width()),
131 TWIP_TO_MM100(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height()));
133 SfxItemSet aSet( rSh.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
134 rSh.GetCurAttr( aSet );
135 SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
137 Rectangle aCropRectangle(
138 TWIP_TO_MM100(aCrop.GetLeft()),
139 TWIP_TO_MM100(aCrop.GetTop()),
140 TWIP_TO_MM100(aCrop.GetRight()),
141 TWIP_TO_MM100(aCrop.GetBottom()) );
143 Graphic aGraphic = Graphic( *pGraphic );
145 CompressGraphicsDialog aDialog( GetView().GetWindow(), aGraphic, aSize, aCropRectangle, GetView().GetViewFrame()->GetBindings() );
146 if( aDialog.Execute() == RET_OK )
148 rSh.StartAllAction();
149 rSh.StartUndo(UNDO_START);
150 Rectangle aScaledCropedRectangle = aDialog.GetScaledCropRectangle();
152 aCrop.SetLeft( MM100_TO_TWIP( aScaledCropedRectangle.Left() ));
153 aCrop.SetTop( MM100_TO_TWIP( aScaledCropedRectangle.Top() ));
154 aCrop.SetRight( MM100_TO_TWIP( aScaledCropedRectangle.Right() ));
155 aCrop.SetBottom( MM100_TO_TWIP( aScaledCropedRectangle.Bottom() ));
157 Graphic aCompressedGraphic( aDialog.GetCompressedGraphic() );
158 rSh.ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aCompressedGraphic);
160 rSh.SetAttr(aCrop);
162 rSh.EndUndo(UNDO_END);
163 rSh.EndAllAction();
167 break;
168 case SID_EXTERNAL_EDIT:
170 // When the graphic is selected to be opened via some external tool
171 // for advanced editing
172 GraphicObject *pGraphicObject = (GraphicObject *) rSh.GetGraphicObj();
173 if(0 != pGraphicObject)
175 SwExternalToolEdit* externalToolEdit = new SwExternalToolEdit( &rSh );
176 externalToolEdit->Edit ( pGraphicObject );
179 break;
180 case SID_INSERT_GRAPHIC:
181 case FN_FORMAT_GRAFIC_DLG:
182 case FN_DRAW_WRAP_DLG:
184 SwFlyFrmAttrMgr aMgr( sal_False, &rSh, rSh.IsFrmSelected() ?
185 FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
186 const SwViewOption* pVOpt = rSh.GetViewOptions();
187 SwViewOption aUsrPref( *pVOpt );
189 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,
206 sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
207 aSet.Put(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
208 FieldUnit eMetric = ::GetDfltMetric((0 != (nHtmlMode&HTMLMODE_ON)));
209 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)) );
211 const SwRect* pRect = &rSh.GetAnyCurRect(RECT_PAGE);
212 SwFmtFrmSize aFrmSize( ATT_VAR_SIZE, pRect->Width(), pRect->Height());
213 aFrmSize.SetWhich( GetPool().GetWhich( SID_ATTR_PAGE_SIZE ) );
214 aSet.Put( aFrmSize );
216 aSet.Put(SfxStringItem(FN_SET_FRM_NAME, rSh.GetFlyName()));
217 if ( nSlot == FN_FORMAT_GRAFIC_DLG )
219 // #i73249#
220 aSet.Put( SfxStringItem( FN_SET_FRM_ALT_NAME, rSh.GetObjTitle() ) );
223 pRect = &rSh.GetAnyCurRect(RECT_PAGE_PRT);
224 aFrmSize.SetWidth( pRect->Width() );
225 aFrmSize.SetHeight( pRect->Height() );
226 aFrmSize.SetWhich( GetPool().GetWhich(FN_GET_PRINT_AREA) );
227 aSet.Put( aFrmSize );
229 aSet.Put( aMgr.GetAttrSet() );
230 aSet.SetParent( aMgr.GetAttrSet().GetParent() );
232 // At percentage values ​​initialize size
233 SwFmtFrmSize aSizeCopy = (const SwFmtFrmSize&)aSet.Get(RES_FRM_SIZE);
234 if (aSizeCopy.GetWidthPercent() && aSizeCopy.GetWidthPercent() != 0xff)
235 aSizeCopy.SetWidth(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Width());
236 if (aSizeCopy.GetHeightPercent() && aSizeCopy.GetHeightPercent() != 0xff)
237 aSizeCopy.SetHeight(rSh.GetAnyCurRect(RECT_FLY_EMBEDDED).Height());
238 // and now set the size for "external" tabpages
240 SvxSizeItem aSzItm( SID_ATTR_GRAF_FRMSIZE, aSizeCopy.GetSize() );
241 aSet.Put( aSzItm );
243 Size aSz( aSizeCopy.GetWidthPercent(), aSizeCopy.GetHeightPercent() );
244 if( 0xff == aSz.Width() ) aSz.Width() = 0;
245 if( 0xff == aSz.Height() ) aSz.Height() = 0;
247 aSzItm.SetSize( aSz );
248 aSzItm.SetWhich( SID_ATTR_GRAF_FRMSIZE_PERCENT );
249 aSet.Put( aSzItm );
252 String sGrfNm, sFilterNm;
253 rSh.GetGrfNms( &sGrfNm, &sFilterNm );
254 if( sGrfNm.Len() )
256 aSet.Put( SvxBrushItem( INetURLObject::decode( sGrfNm,
257 INET_HEX_ESCAPE,
258 INetURLObject::DECODE_UNAMBIGUOUS,
259 RTL_TEXTENCODING_UTF8 ),
260 sFilterNm, GPOS_LT,
261 SID_ATTR_GRAF_GRAPHIC ));
263 else
265 // #119353# - robust
266 const GraphicObject* pGrfObj = rSh.GetGraphicObj();
267 if ( pGrfObj )
269 aSet.Put( SvxBrushItem( *pGrfObj, GPOS_LT,
270 SID_ATTR_GRAF_GRAPHIC ) );
273 aSet.Put( SfxBoolItem( FN_PARAM_GRF_CONNECT, sGrfNm.Len() > 0 ) );
275 // get Mirror and Crop
277 SfxItemSet aTmpSet( rSh.GetAttrPool(),
278 RES_GRFATR_MIRRORGRF, RES_GRFATR_CROPGRF );
280 rSh.GetCurAttr( aTmpSet );
281 aSet.Put( aTmpSet );
284 aSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, aUsrPref.IsKeepRatio()));
285 aSet.Put(SfxBoolItem( SID_ATTR_GRAF_KEEP_ZOOM, aUsrPref.IsGrfKeepZoom()));
287 aSet.Put(SfxFrameItem( SID_DOCFRAME, &GetView().GetViewFrame()->GetTopFrame()));
289 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
290 OSL_ENSURE(pFact, "Dialogdiet fail!");
291 SfxAbstractTabDialog* pDlg = pFact->CreateFrmTabDialog( DLG_FRM_GRF,
292 GetView().GetViewFrame(),
293 GetView().GetWindow(),
294 aSet, sal_False, DLG_FRM_GRF);
295 OSL_ENSURE(pDlg, "Dialogdiet fail!");
297 if (nSlot == FN_DRAW_WRAP_DLG)
298 pDlg->SetCurPageId(TP_FRM_WRAP);
300 if( pDlg->Execute() )
302 rSh.StartAllAction();
303 rSh.StartUndo(UNDO_START);
304 const SfxPoolItem* pItem;
305 SfxItemSet* pSet = (SfxItemSet*)pDlg->GetOutputItemSet();
306 rReq.Done(*pSet);
307 // change the 2 frmsize SizeItems to the correct SwFrmSizeItem
308 if( SFX_ITEM_SET == pSet->GetItemState(
309 SID_ATTR_GRAF_FRMSIZE, sal_False, &pItem ))
311 SwFmtFrmSize aSize;
312 const Size& rSz = ((SvxSizeItem*)pItem)->GetSize();
313 aSize.SetWidth( rSz.Width() );
314 aSize.SetHeight( rSz.Height() );
316 if( SFX_ITEM_SET == pSet->GetItemState(
317 SID_ATTR_GRAF_FRMSIZE_PERCENT, sal_False, &pItem ))
319 const Size& rRelativeSize = ((SvxSizeItem*)pItem)->GetSize();
320 aSize.SetWidthPercent( static_cast< sal_uInt8 >( rRelativeSize.Width() ) );
321 aSize.SetHeightPercent( static_cast< sal_uInt8 >( rRelativeSize.Height() ) );
323 pSet->Put( aSize );
326 // Templates AutoUpdate
327 SwFrmFmt* pFmt = rSh.GetCurFrmFmt();
328 if(pFmt && pFmt->IsAutoUpdateFmt())
330 pFmt->SetFmtAttr(*pSet);
331 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,
336 aShellSet.Put(*pSet);
337 aMgr.SetAttrSet(aShellSet);
339 else
341 aMgr.SetAttrSet(*pSet);
343 aMgr.UpdateFlyFrm();
345 bool bApplyUsrPref = false;
346 if (SFX_ITEM_SET == pSet->GetItemState(
347 FN_KEEP_ASPECT_RATIO, sal_True, &pItem ))
349 aUsrPref.SetKeepRatio(
350 ((const SfxBoolItem*)pItem)->GetValue() );
351 bApplyUsrPref = true;
353 if( SFX_ITEM_SET == pSet->GetItemState(
354 SID_ATTR_GRAF_KEEP_ZOOM, sal_True, &pItem ))
356 aUsrPref.SetGrfKeepZoom(
357 ((const SfxBoolItem*)pItem)->GetValue() );
358 bApplyUsrPref = true;
361 if( bApplyUsrPref )
362 SW_MOD()->ApplyUsrPref(aUsrPref, &GetView());
364 // and now set all the graphic attributes and other stuff
365 if( SFX_ITEM_SET == pSet->GetItemState(
366 SID_ATTR_GRAF_GRAPHIC, sal_True, &pItem ))
368 if( ((SvxBrushItem*)pItem)->GetGraphicLink() )
369 sGrfNm = *((SvxBrushItem*)pItem)->GetGraphicLink();
370 else
371 sGrfNm.Erase();
373 if( ((SvxBrushItem*)pItem)->GetGraphicFilter() )
374 sFilterNm = *((SvxBrushItem*)pItem)->GetGraphicFilter();
375 else
376 sFilterNm.Erase();
378 if( sGrfNm.Len() )
380 SwDocShell* pDocSh = GetView().GetDocShell();
381 SwWait aWait( *pDocSh, sal_True );
382 SfxMedium* pMedium = pDocSh->GetMedium();
383 INetURLObject aAbs;
384 if( pMedium )
385 aAbs = pMedium->GetURLObject();
386 rSh.ReRead( URIHelper::SmartRel2Abs(
387 aAbs, sGrfNm,
388 URIHelper::GetMaybeFileHdl() ),
389 sFilterNm, 0 );
392 if ( SFX_ITEM_SET == pSet->GetItemState(
393 FN_SET_FRM_ALT_NAME, sal_True, &pItem ))
395 // #i73249#
396 rSh.SetObjTitle( ((const SfxStringItem*)pItem)->GetValue() );
399 SfxItemSet aGrfSet( rSh.GetAttrPool(), RES_GRFATR_BEGIN,
400 RES_GRFATR_END-1 );
401 aGrfSet.Put( *pSet );
402 if( aGrfSet.Count() )
403 rSh.SetAttr( aGrfSet );
405 rSh.EndUndo(UNDO_END);
406 rSh.EndAllAction();
408 delete pDlg;
410 break;
412 case FN_GRAPHIC_MIRROR_ON_EVEN_PAGES:
414 SfxItemSet aSet(rSh.GetAttrPool(), RES_GRFATR_MIRRORGRF, RES_GRFATR_MIRRORGRF);
415 rSh.GetCurAttr( aSet );
416 SwMirrorGrf aGrf((const SwMirrorGrf &)aSet.Get(RES_GRFATR_MIRRORGRF));
417 aGrf.SetGrfToggle(!aGrf.IsGrfToggle());
418 rSh.SetAttr(aGrf);
420 break;
422 default:
423 OSL_ENSURE(!this, "wrong dispatcher");
424 return;
428 void SwGrfShell::ExecAttr( SfxRequest &rReq )
430 sal_uInt16 nGrfType;
431 if( CNT_GRF == GetShell().GetCntType() &&
432 ( GRAPHIC_BITMAP == ( nGrfType = GetShell().GetGraphicType()) ||
433 GRAPHIC_GDIMETAFILE == nGrfType ))
435 SfxItemSet aGrfSet( GetShell().GetAttrPool(), RES_GRFATR_BEGIN,
436 RES_GRFATR_END -1 );
437 const SfxItemSet *pArgs = rReq.GetArgs();
438 const SfxPoolItem* pItem;
439 sal_uInt16 nSlot = rReq.GetSlot();
440 if( !pArgs || SFX_ITEM_SET != pArgs->GetItemState( nSlot, sal_False, &pItem ))
441 pItem = 0;
443 switch( nSlot )
445 case SID_FLIP_VERTICAL:
446 case SID_FLIP_HORIZONTAL:
448 GetShell().GetCurAttr( aGrfSet );
449 SwMirrorGrf aMirror( (SwMirrorGrf&)aGrfSet.Get( RES_GRFATR_MIRRORGRF ) );
450 sal_uInt16 nMirror = aMirror.GetValue();
451 if ( nSlot==SID_FLIP_HORIZONTAL )
452 switch( nMirror )
454 case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_VERT;
455 break;
456 case RES_MIRROR_GRAPH_HOR: nMirror = RES_MIRROR_GRAPH_BOTH;
457 break;
458 case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_DONT;
459 break;
460 case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_HOR;
461 break;
463 else
464 switch( nMirror )
466 case RES_MIRROR_GRAPH_DONT: nMirror = RES_MIRROR_GRAPH_HOR;
467 break;
468 case RES_MIRROR_GRAPH_VERT: nMirror = RES_MIRROR_GRAPH_BOTH;
469 break;
470 case RES_MIRROR_GRAPH_HOR: nMirror = RES_MIRROR_GRAPH_DONT;
471 break;
472 case RES_MIRROR_GRAPH_BOTH: nMirror = RES_MIRROR_GRAPH_VERT;
473 break;
475 aMirror.SetValue( nMirror );
476 aGrfSet.ClearItem();
477 aGrfSet.Put( aMirror );
479 break;
481 case SID_ATTR_GRAF_LUMINANCE:
482 if( pItem )
483 aGrfSet.Put( SwLuminanceGrf(
484 ((SfxInt16Item*)pItem)->GetValue() ));
485 break;
486 case SID_ATTR_GRAF_CONTRAST:
487 if( pItem )
488 aGrfSet.Put( SwContrastGrf(
489 ((SfxInt16Item*)pItem)->GetValue() ));
490 break;
491 case SID_ATTR_GRAF_RED:
492 if( pItem )
493 aGrfSet.Put( SwChannelRGrf(
494 ((SfxInt16Item*)pItem)->GetValue() ));
495 break;
496 case SID_ATTR_GRAF_GREEN:
497 if( pItem )
498 aGrfSet.Put( SwChannelGGrf(
499 ((SfxInt16Item*)pItem)->GetValue() ));
500 break;
501 case SID_ATTR_GRAF_BLUE:
502 if( pItem )
503 aGrfSet.Put( SwChannelBGrf(
504 ((SfxInt16Item*)pItem)->GetValue() ));
505 break;
506 case SID_ATTR_GRAF_GAMMA:
507 if( pItem )
509 double fVal = ((SfxUInt32Item*)pItem)->GetValue();
510 aGrfSet.Put( SwGammaGrf(fVal/100. ));
512 break;
513 case SID_ATTR_GRAF_TRANSPARENCE:
514 if( pItem )
515 aGrfSet.Put( SwTransparencyGrf(
516 static_cast< sal_Int8 >( ( (SfxUInt16Item*)pItem )->GetValue() ) ) );
517 break;
518 case SID_ATTR_GRAF_INVERT:
519 if( pItem )
520 aGrfSet.Put( SwInvertGrf(
521 ((SfxBoolItem*)pItem)->GetValue() ));
522 break;
524 case SID_ATTR_GRAF_MODE:
525 if( pItem )
526 aGrfSet.Put( SwDrawModeGrf(
527 ((SfxUInt16Item*)pItem)->GetValue() ));
528 break;
530 case SID_COLOR_SETTINGS:
532 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
533 aToolboxAccess.toggleToolbox();
534 break;
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 if( GRAPHIC_BITMAP == nGrfType )
550 // #119353# - robust
551 const GraphicObject* pFilterObj( GetShell().GetGraphicObj() );
552 if ( pFilterObj )
554 GraphicObject aFilterObj( *pFilterObj );
555 if( SVX_GRAPHICFILTER_ERRCODE_NONE ==
556 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ))
557 GetShell().ReRead( aEmptyStr, aEmptyStr,
558 &aFilterObj.GetGraphic() );
561 break;
563 default:
564 OSL_ENSURE(!this, "wrong dispatcher");
566 if( aGrfSet.Count() )
567 GetShell().SetAttr( aGrfSet );
569 GetView().GetViewFrame()->GetBindings().Invalidate(rReq.GetSlot());
572 void SwGrfShell::GetAttrState(SfxItemSet &rSet)
574 SwWrtShell &rSh = GetShell();
575 SfxItemSet aCoreSet( GetPool(), aNoTxtNodeSetRange );
576 rSh.GetCurAttr( aCoreSet );
577 bool bParentCntProt = 0 != rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
578 bool bIsGrfCntnt = CNT_GRF == GetShell().GetCntType();
580 SetGetStateSet( &rSet );
582 SfxWhichIter aIter( rSet );
583 sal_uInt16 nWhich = aIter.FirstWhich();
584 while( nWhich )
586 bool bDisable = bParentCntProt;
587 switch( nWhich )
589 case SID_INSERT_GRAPHIC:
590 case FN_FORMAT_GRAFIC_DLG:
591 case SID_TWAIN_TRANSFER:
592 if( bParentCntProt || !bIsGrfCntnt )
593 bDisable = true;
594 break;
595 case SID_SAVE_GRAPHIC:
596 case SID_EXTERNAL_EDIT:
597 if( rSh.GetGraphicType() == GRAPHIC_NONE )
598 bDisable = true;
599 break;
600 case SID_COLOR_SETTINGS:
602 if ( bParentCntProt || !bIsGrfCntnt )
603 bDisable = true;
604 else
606 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
607 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
609 break;
612 case SID_FLIP_HORIZONTAL:
613 if( !bParentCntProt )
615 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
616 RES_GRFATR_MIRRORGRF )).GetValue());
618 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_VERT ||
619 nState == RES_MIRROR_GRAPH_BOTH));
621 break;
623 case SID_FLIP_VERTICAL:
624 if( !bParentCntProt )
626 MirrorGraph nState = static_cast< MirrorGraph >(((const SwMirrorGrf &) aCoreSet.Get(
627 RES_GRFATR_MIRRORGRF )).GetValue());
629 rSet.Put(SfxBoolItem( nWhich, nState == RES_MIRROR_GRAPH_HOR ||
630 nState == RES_MIRROR_GRAPH_BOTH));
632 break;
635 case SID_ATTR_GRAF_LUMINANCE:
636 if( !bParentCntProt )
637 rSet.Put( SfxInt16Item( nWhich, ((SwLuminanceGrf&)
638 aCoreSet.Get(RES_GRFATR_LUMINANCE)).GetValue() ));
639 break;
640 case SID_ATTR_GRAF_CONTRAST:
641 if( !bParentCntProt )
642 rSet.Put( SfxInt16Item( nWhich, ((SwContrastGrf&)
643 aCoreSet.Get(RES_GRFATR_CONTRAST)).GetValue() ));
644 break;
645 case SID_ATTR_GRAF_RED:
646 if( !bParentCntProt )
647 rSet.Put( SfxInt16Item( nWhich, ((SwChannelRGrf&)
648 aCoreSet.Get(RES_GRFATR_CHANNELR)).GetValue() ));
649 break;
650 case SID_ATTR_GRAF_GREEN:
651 if( !bParentCntProt )
652 rSet.Put( SfxInt16Item( nWhich, ((SwChannelGGrf&)
653 aCoreSet.Get(RES_GRFATR_CHANNELG)).GetValue() ));
654 break;
655 case SID_ATTR_GRAF_BLUE:
656 if( !bParentCntProt )
657 rSet.Put( SfxInt16Item( nWhich, ((SwChannelBGrf&)
658 aCoreSet.Get(RES_GRFATR_CHANNELB)).GetValue() ));
659 break;
661 case SID_ATTR_GRAF_GAMMA:
662 if( !bParentCntProt )
663 rSet.Put( SfxUInt32Item( nWhich, static_cast< sal_uInt32 >(
664 ( (SwGammaGrf&)aCoreSet.Get( RES_GRFATR_GAMMA ) ).GetValue() * 100 ) ) );
665 break;
666 case SID_ATTR_GRAF_TRANSPARENCE:
667 if( !bParentCntProt )
669 // #119353# - robust
670 const GraphicObject* pGrafObj = rSh.GetGraphicObj();
671 if ( pGrafObj )
673 if( pGrafObj->IsAnimated() ||
674 GRAPHIC_GDIMETAFILE == pGrafObj->GetType() )
675 bDisable = true;
676 else
677 rSet.Put( SfxUInt16Item( nWhich, ((SwTransparencyGrf&)
678 aCoreSet.Get(RES_GRFATR_TRANSPARENCY)).GetValue() ));
681 break;
682 case SID_ATTR_GRAF_INVERT:
683 if( !bParentCntProt )
684 rSet.Put( SfxBoolItem( nWhich, ((SwInvertGrf&)
685 aCoreSet.Get(RES_GRFATR_INVERT)).GetValue() ));
686 break;
688 case SID_ATTR_GRAF_MODE:
689 if( !bParentCntProt )
690 rSet.Put( SfxUInt16Item( nWhich, ((SwDrawModeGrf&)
691 aCoreSet.Get(RES_GRFATR_DRAWMODE)).GetValue() ));
692 break;
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:
707 if( bParentCntProt || !bIsGrfCntnt )
708 bDisable = true;
709 // #i59688# load graphic only if type is unknown
710 else
712 const sal_uInt16 eGraphicType( rSh.GetGraphicType() );
713 if ( ( eGraphicType == GRAPHIC_NONE ||
714 eGraphicType == GRAPHIC_DEFAULT ) &&
715 rSh.IsGrfSwapOut( sal_True ) )
717 rSet.DisableItem( nWhich );
718 if( AddGrfUpdateSlot( nWhich ))
719 rSh.GetGraphic(sal_False); // start the loading
721 else
723 bDisable = eGraphicType != GRAPHIC_BITMAP;
727 break;
729 default:
730 bDisable = false;
733 if( bDisable )
734 rSet.DisableItem( nWhich );
735 nWhich = aIter.NextWhich();
737 SetGetStateSet( 0 );
740 void SwGrfShell::ExecuteRotation(SfxRequest &rReq)
742 sal_uInt16 aRotation;
744 SwWrtShell& rShell = GetShell();
746 if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_LEFT)
748 aRotation = 900;
750 else if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT)
752 aRotation = 2700;
754 else
756 return;
759 rShell.StartAllAction();
760 rShell.StartUndo(UNDO_START);
762 Graphic aGraphic = *rShell.GetGraphic();
763 GraphicNativeTransform aTransform(aGraphic);
764 aTransform.rotate(aRotation);
765 rShell.ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &aGraphic);
767 SwFlyFrmAttrMgr aManager(false, &rShell, rShell.IsFrmSelected() ? FRMMGR_TYPE_NONE : FRMMGR_TYPE_GRF);
768 Size aSize(aManager.GetSize().Height(), aManager.GetSize().Width());
769 aManager.SetSize(aSize);
770 aManager.UpdateFlyFrm();
772 SfxItemSet aSet( rShell.GetAttrPool(), RES_GRFATR_CROPGRF, RES_GRFATR_CROPGRF );
773 rShell.GetCurAttr( aSet );
774 SwCropGrf aCrop( (const SwCropGrf&) aSet.Get(RES_GRFATR_CROPGRF) );
775 Rectangle aCropRectangle(aCrop.GetLeft(), aCrop.GetTop(), aCrop.GetRight(), aCrop.GetBottom());
777 if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_LEFT)
779 aCrop.SetLeft( aCropRectangle.Top() );
780 aCrop.SetTop( aCropRectangle.Right() );
781 aCrop.SetRight( aCropRectangle.Bottom() );
782 aCrop.SetBottom( aCropRectangle.Left() );
784 else if (rReq.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT)
786 aCrop.SetLeft( aCropRectangle.Bottom() );
787 aCrop.SetTop( aCropRectangle.Left() );
788 aCrop.SetRight( aCropRectangle.Top() );
789 aCrop.SetBottom( aCropRectangle.Right() );
792 rShell.SetAttr(aCrop);
794 rShell.EndUndo(UNDO_END);
795 rShell.EndAllAction();
798 void SwGrfShell::GetAttrStateForRotation(SfxItemSet &rSet)
800 SwWrtShell& rShell = GetShell();
801 bool bIsParentContentProtected = 0 != rShell.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT );
803 SetGetStateSet( &rSet );
805 SfxWhichIter aIterator( rSet );
806 sal_uInt16 nWhich = aIterator.FirstWhich();
807 while( nWhich )
809 bool bDisable = bIsParentContentProtected;
810 switch( nWhich )
812 case SID_ROTATE_GRAPHIC_LEFT:
813 case SID_ROTATE_GRAPHIC_RIGHT:
814 if( rShell.GetGraphicType() == GRAPHIC_NONE )
816 bDisable = true;
818 else
820 Graphic aGraphic = *rShell.GetGraphic();
821 GraphicNativeTransform aTransform(aGraphic);
822 if (!aTransform.canBeRotated())
824 bDisable = true;
827 break;
828 default:
829 bDisable = false;
832 if( bDisable )
833 rSet.DisableItem( nWhich );
834 nWhich = aIterator.NextWhich();
836 SetGetStateSet( 0 );
840 SwGrfShell::SwGrfShell(SwView &_rView) :
841 SwBaseShell(_rView)
844 SetName(OUString("Graphic"));
845 SetHelpId(SW_GRFSHELL);
846 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Graphic));
849 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */