1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <hintids.hxx>
22 #include <tools/urlobj.hxx>
23 #include <tools/UnitConversion.hxx>
24 #include <svl/stritem.hxx>
25 #include <svl/whiter.hxx>
26 #include <svl/urihelper.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/objface.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <editeng/sizeitem.hxx>
32 #include <sfx2/request.hxx>
33 #include <vcl/EnumContext.hxx>
34 #include <sfx2/htmlmode.hxx>
35 #include <svx/svdview.hxx>
36 #include <editeng/brushitem.hxx>
37 #include <svx/grfflt.hxx>
38 #include <svx/compressgraphicdialog.hxx>
39 #include <svx/tbxcolor.hxx>
40 #include <svx/sdangitm.hxx>
41 #include <osl/diagnose.h>
42 #include <drawdoc.hxx>
45 #include <viewopt.hxx>
46 #include <swmodule.hxx>
55 #include <svx/extedit.hxx>
56 #include <svx/graphichelper.hxx>
58 #include <IDocumentDrawModelAccess.hxx>
59 #include <svx/drawitem.hxx>
60 #define ShellClass_SwGrfShell
62 #include <sfx2/msg.hxx>
63 #include <swslots.hxx>
64 #include <swabstdlg.hxx>
65 #include <unocrsr.hxx>
69 constexpr OUStringLiteral TOOLBOX_NAME
= u
"colorbar";
71 class SwGrfShell::SwExternalToolEdit
72 : public ExternalToolEdit
75 SwWrtShell
*const m_pShell
;
76 std::shared_ptr
<SwUnoCursor
> const m_pCursor
;
79 explicit SwExternalToolEdit(SwWrtShell
*const pShell
)
81 , m_pCursor( // need only Point, must point to SwGrfNode
82 pShell
->GetDoc()->CreateUnoCursor(
83 *pShell
->GetCurrentShellCursor().GetPoint()))
87 virtual void Update(Graphic
& rGraphic
) override
91 m_pShell
->GetCurrentShellCursor().DeleteMark();
92 *m_pShell
->GetCurrentShellCursor().GetPoint() = *m_pCursor
->GetPoint();
93 m_pShell
->ReRead(OUString(), OUString(), &rGraphic
);
98 SFX_IMPL_INTERFACE(SwGrfShell
, SwBaseShell
)
100 void SwGrfShell::InitInterface_Impl()
102 GetStaticInterface()->RegisterPopupMenu("graphic");
104 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
, SfxVisibilityFlags::Invisible
, ToolbarId::Grafik_Toolbox
);
107 void SwGrfShell::Execute(SfxRequest
&rReq
)
109 SwWrtShell
&rSh
= GetShell();
111 sal_uInt16 nSlot
= rReq
.GetSlot();
114 case SID_OBJECT_ROTATE
:
116 // RotGrfFlyFrame: start rotation when possible
117 SdrView
* pSdrView
= rSh
.GetDrawViewWithValidMarkList();
119 if(rSh
.IsRotationOfSwGrfNodePossible() && pSdrView
->IsRotateAllowed())
121 if(GetView().IsDrawRotate())
123 rSh
.SetDragMode(SdrDragMode::Move
);
127 rSh
.SetDragMode(SdrDragMode::Rotate
);
130 GetView().FlipDrawRotate();
135 case SID_TWAIN_TRANSFER
:
137 GetView().ExecuteScan( rReq
);
141 case SID_SAVE_GRAPHIC
:
143 GraphicAttr aGraphicAttr
;
144 rSh
.GetGraphicAttr(aGraphicAttr
);
146 short nState
= RET_CANCEL
;
147 if (aGraphicAttr
!= GraphicAttr()) // the image has been modified
149 weld::Window
* pWin
= GetView().GetFrameWeld();
152 nState
= GraphicHelper::HasToSaveTransformedImage(pWin
);
160 if (nState
== RET_YES
)
162 const GraphicObject
* pGraphicObj
= rSh
.GetGraphicObj();
165 Graphic aGraphic
= pGraphicObj
->GetTransformedGraphic(pGraphicObj
->GetPrefSize(), pGraphicObj
->GetPrefMapMode(), aGraphicAttr
);
168 rSh
.GetGrfNms( &sGrfNm
, &sFilterNm
);
169 GraphicHelper::ExportGraphic(GetView().GetFrameWeld(), aGraphic
, sGrfNm
);
172 else if (nState
== RET_NO
)
174 const Graphic
*pGraphic
= rSh
.GetGraphic();
175 if(nullptr != pGraphic
)
179 rSh
.GetGrfNms( &sGrfNm
, &sFilterNm
);
180 GraphicHelper::ExportGraphic(GetView().GetFrameWeld(), *pGraphic
, sGrfNm
);
186 case SID_COMPRESS_GRAPHIC
:
188 const Graphic
* pGraphic
= rSh
.GetGraphic();
192 convertTwipToMm100(rSh
.GetAnyCurRect(CurRectType::FlyEmbedded
).Width()),
193 convertTwipToMm100(rSh
.GetAnyCurRect(CurRectType::FlyEmbedded
).Height()));
195 SfxItemSetFixed
<RES_GRFATR_MIRRORGRF
, RES_GRFATR_CROPGRF
> aSet( rSh
.GetAttrPool() );
196 rSh
.GetCurAttr( aSet
);
197 SwMirrorGrf
aMirror( aSet
.Get(RES_GRFATR_MIRRORGRF
) );
198 SwCropGrf
aCrop( aSet
.Get(RES_GRFATR_CROPGRF
) );
200 tools::Rectangle
aCropRectangle(
201 convertTwipToMm100(aCrop
.GetLeft()),
202 convertTwipToMm100(aCrop
.GetTop()),
203 convertTwipToMm100(aCrop
.GetRight()),
204 convertTwipToMm100(aCrop
.GetBottom()) );
206 Graphic aGraphic
= *pGraphic
;
208 CompressGraphicsDialog
aDialog(GetView().GetFrameWeld(), std::move(aGraphic
), aSize
, aCropRectangle
, GetView().GetViewFrame().GetBindings());
209 if (aDialog
.run() == RET_OK
)
211 rSh
.StartAllAction();
212 rSh
.StartUndo(SwUndoId::START
);
213 tools::Rectangle aScaledCropedRectangle
= aDialog
.GetScaledCropRectangle();
215 aCrop
.SetLeft( o3tl::toTwips( aScaledCropedRectangle
.Left(), o3tl::Length::mm100
));
216 aCrop
.SetTop( o3tl::toTwips( aScaledCropedRectangle
.Top(), o3tl::Length::mm100
));
217 aCrop
.SetRight( o3tl::toTwips( aScaledCropedRectangle
.Right(), o3tl::Length::mm100
));
218 aCrop
.SetBottom( o3tl::toTwips( aScaledCropedRectangle
.Bottom(), o3tl::Length::mm100
));
220 Graphic
aCompressedGraphic( aDialog
.GetCompressedGraphic() );
221 rSh
.ReRead(OUString(), OUString(), const_cast<const Graphic
*>(&aCompressedGraphic
));
223 rSh
.SetAttrItem(aCrop
);
224 rSh
.SetAttrItem(aMirror
);
226 rSh
.EndUndo(SwUndoId::END
);
232 case SID_EXTERNAL_EDIT
:
234 // When the graphic is selected to be opened via some external tool
235 // for advanced editing
236 GraphicObject
const*const pGraphicObject(rSh
.GetGraphicObj());
237 if(nullptr != pGraphicObject
)
239 m_ExternalEdits
.push_back(std::make_unique
<SwExternalToolEdit
>(
241 m_ExternalEdits
.back()->Edit(pGraphicObject
);
245 case SID_CHANGE_PICTURE
:
246 case SID_INSERT_GRAPHIC
:
248 // #i123922# implement slot independent from the two below to
249 // bring up the insert graphic dialog and associated actions
250 SwView
& rLclView
= GetView();
251 rReq
.SetReturnValue(SfxBoolItem(nSlot
, rLclView
.InsertGraphicDlg( rReq
)));
254 case FN_FORMAT_GRAFIC_DLG
:
255 case FN_DRAW_WRAP_DLG
:
257 SwFlyFrameAttrMgr
aMgr( false, &rSh
, rSh
.IsFrameSelected() ?
258 Frmmgr_Type::NONE
: Frmmgr_Type::GRF
, nullptr);
259 const SwViewOption
* pVOpt
= rSh
.GetViewOptions();
260 SwViewOption
aUsrPref( *pVOpt
);
263 RES_FRMATR_BEGIN
, RES_GRFATR_CROPGRF
,
264 // FillAttribute support:
265 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
266 SID_DOCFRAME
, SID_DOCFRAME
,
267 SID_REFERER
, SID_REFERER
,
268 SID_ATTR_BORDER_INNER
, SID_ATTR_BORDER_INNER
,
269 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
, // 10051
270 // RotGrfFlyFrame: Need RotationAngle now
271 SID_ATTR_TRANSFORM_ANGLE
, SID_ATTR_TRANSFORM_ANGLE
, // 10095
272 // Items to hand over XPropertyList things like
273 // XColorList, XHatchList, XGradientList, and XBitmapList to
275 SID_COLOR_TABLE
, SID_PATTERN_LIST
, //10179
276 SID_HTML_MODE
, SID_HTML_MODE
, //10414
277 SID_ATTR_GRAF_KEEP_ZOOM
, SID_ATTR_GRAF_KEEP_ZOOM
, //10882
278 SID_ATTR_GRAF_FRMSIZE
, SID_ATTR_GRAF_GRAPHIC
, // 10884
279 // contains SID_ATTR_GRAF_FRMSIZE_PERCENT
280 FN_GET_PRINT_AREA
, FN_GET_PRINT_AREA
,
281 FN_PARAM_GRF_CONNECT
, FN_PARAM_GRF_CONNECT
,
282 FN_SET_FRM_NAME
, FN_KEEP_ASPECT_RATIO
,
283 FN_SET_FRM_ALT_NAME
, FN_SET_FRM_ALT_NAME
,
284 FN_UNO_DESCRIPTION
, FN_UNO_DESCRIPTION
> aSet( GetPool() );
286 // create needed items for XPropertyList entries from the DrawModel so that
287 // the Area TabPage can access them
288 const SwDrawModel
* pDrawModel
= rSh
.GetView().GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
290 aSet
.Put(SvxColorListItem(pDrawModel
->GetColorList(), SID_COLOR_TABLE
));
291 aSet
.Put(SvxGradientListItem(pDrawModel
->GetGradientList(), SID_GRADIENT_LIST
));
292 aSet
.Put(SvxHatchListItem(pDrawModel
->GetHatchList(), SID_HATCH_LIST
));
293 aSet
.Put(SvxBitmapListItem(pDrawModel
->GetBitmapList(), SID_BITMAP_LIST
));
294 aSet
.Put(SvxPatternListItem(pDrawModel
->GetPatternList(), SID_PATTERN_LIST
));
296 sal_uInt16 nHtmlMode
= ::GetHtmlMode(GetView().GetDocShell());
297 aSet
.Put(SfxUInt16Item(SID_HTML_MODE
, nHtmlMode
));
298 FieldUnit eMetric
= ::GetDfltMetric(0 != (nHtmlMode
&HTMLMODE_ON
));
299 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC
, static_cast< sal_uInt16
>(eMetric
)) );
301 const SwRect
* pRect
= &rSh
.GetAnyCurRect(CurRectType::Page
);
302 SwFormatFrameSize
aFrameSize( SwFrameSize::Variable
, pRect
->Width(), pRect
->Height());
303 aFrameSize
.SetWhich( GetPool().GetWhich( SID_ATTR_PAGE_SIZE
) );
304 aSet
.Put( aFrameSize
);
306 aSet
.Put(SfxStringItem(FN_SET_FRM_NAME
, rSh
.GetFlyName()));
307 aSet
.Put(SfxStringItem(FN_UNO_DESCRIPTION
, rSh
.GetObjDescription()));
308 if ( nSlot
== FN_FORMAT_GRAFIC_DLG
)
311 aSet
.Put( SfxStringItem( FN_SET_FRM_ALT_NAME
, rSh
.GetObjTitle() ) );
314 pRect
= &rSh
.GetAnyCurRect(CurRectType::PagePrt
);
315 aFrameSize
.SetWidth( pRect
->Width() );
316 aFrameSize
.SetHeight( pRect
->Height() );
317 aFrameSize
.SetWhich( GetPool().GetWhich(FN_GET_PRINT_AREA
) );
318 aSet
.Put( aFrameSize
);
320 aSet
.Put( aMgr
.GetAttrSet() );
321 SwFlyFrame
* pFly
= rSh
.GetSelectedFlyFrame();
324 // Work with the up to date layout size if possible.
325 SwFormatFrameSize aSize
= aSet
.Get(RES_FRM_SIZE
);
326 aSize
.SetWidth(pFly
->getFrameArea().Width());
327 aSize
.SetHeight(pFly
->getFrameArea().Height());
330 aSet
.SetParent( aMgr
.GetAttrSet().GetParent() );
332 // At percentage values initialize size
333 SwFormatFrameSize aSizeCopy
= aSet
.Get(RES_FRM_SIZE
);
334 if (aSizeCopy
.GetWidthPercent() && aSizeCopy
.GetWidthPercent() != SwFormatFrameSize::SYNCED
)
335 aSizeCopy
.SetWidth(rSh
.GetAnyCurRect(CurRectType::FlyEmbedded
).Width());
336 if (aSizeCopy
.GetHeightPercent() && aSizeCopy
.GetHeightPercent() != SwFormatFrameSize::SYNCED
)
337 aSizeCopy
.SetHeight(rSh
.GetAnyCurRect(CurRectType::FlyEmbedded
).Height());
338 // and now set the size for "external" tabpages
340 SvxSizeItem
aSzItm( SID_ATTR_GRAF_FRMSIZE
, aSizeCopy
.GetSize() );
343 Size
aSz( aSizeCopy
.GetWidthPercent(), aSizeCopy
.GetHeightPercent() );
344 if( SwFormatFrameSize::SYNCED
== aSz
.Width() ) aSz
.setWidth( 0 );
345 if( SwFormatFrameSize::SYNCED
== aSz
.Height() ) aSz
.setHeight( 0 );
347 aSzItm
.SetSize( aSz
);
348 aSzItm
.SetWhich( SID_ATTR_GRAF_FRMSIZE_PERCENT
);
354 rSh
.GetGrfNms( &sGrfNm
, &sFilterNm
);
355 if( !sGrfNm
.isEmpty() )
357 aSet
.Put( SvxBrushItem( INetURLObject::decode( sGrfNm
,
358 INetURLObject::DecodeMechanism::Unambiguous
),
360 SID_ATTR_GRAF_GRAPHIC
));
365 const GraphicObject
* pGrfObj
= rSh
.GetGraphicObj();
368 aSet
.Put( SvxBrushItem( *pGrfObj
, GPOS_LT
,
369 SID_ATTR_GRAF_GRAPHIC
) );
372 aSet
.Put( SfxBoolItem( FN_PARAM_GRF_CONNECT
, !sGrfNm
.isEmpty() ) );
374 // get Mirror and Crop
376 SfxItemSetFixed
<RES_GRFATR_MIRRORGRF
, RES_GRFATR_CROPGRF
> aTmpSet( rSh
.GetAttrPool() );
378 rSh
.GetCurAttr( aTmpSet
);
382 aSet
.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO
, aUsrPref
.IsKeepRatio()));
383 aSet
.Put(SfxBoolItem( SID_ATTR_GRAF_KEEP_ZOOM
, aUsrPref
.IsGrfKeepZoom()));
385 aSet
.Put(SfxFrameItem( SID_DOCFRAME
, &GetView().GetViewFrame().GetFrame()));
387 SfxObjectShell
* sh
= rSh
.GetDoc()->GetPersist();
388 if (sh
!= nullptr && sh
->HasName())
391 SfxStringItem(SID_REFERER
, sh
->GetMedium()->GetName()));
395 Degree10 nCurrentRotation
;
396 { // RotGrfFlyFrame: Add current RotationAngle value, convert from
397 // RES_GRFATR_ROTATION to SID_ATTR_TRANSFORM_ANGLE. Do not forget to
398 // convert from 10th degrees to 100th degrees
399 SfxItemSetFixed
<RES_GRFATR_ROTATION
, RES_GRFATR_ROTATION
> aTmpSet( rSh
.GetAttrPool() );
400 rSh
.GetCurAttr( aTmpSet
);
401 const SwRotationGrf
& rRotation
= aTmpSet
.Get(RES_GRFATR_ROTATION
);
402 nCurrentRotation
= rRotation
.GetValue();
403 aUnrotatedSize
= rRotation
.GetUnrotatedSize();
404 aSet
.Put(SdrAngleItem(SID_ATTR_TRANSFORM_ANGLE
, to
<Degree100
>(nCurrentRotation
)));
407 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
408 ScopedVclPtr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateFrameTabDialog("PictureDialog",
409 GetView().GetViewFrame(),
410 GetView().GetFrameWeld(),
412 if (nSlot
== FN_DRAW_WRAP_DLG
)
413 pDlg
->SetCurPageId("wrap");
415 if (pDlg
->Execute() == RET_OK
)
417 rSh
.StartAllAction();
418 rSh
.StartUndo(SwUndoId::START
);
419 SfxItemSet
* pSet
= const_cast<SfxItemSet
*>(pDlg
->GetOutputItemSet());
421 // change the 2 frmsize SizeItems to the correct SwFrameSizeItem
422 if( const SvxSizeItem
* pSizeItem
= pSet
->GetItemIfSet(
423 SID_ATTR_GRAF_FRMSIZE
, false ))
425 SwFormatFrameSize aSize
;
426 const Size
& rSz
= pSizeItem
->GetSize();
427 aSize
.SetWidth( rSz
.Width() );
428 aSize
.SetHeight( rSz
.Height() );
430 pSizeItem
= pSet
->GetItemIfSet( SID_ATTR_GRAF_FRMSIZE_PERCENT
, false );
433 const Size
& rRelativeSize
= pSizeItem
->GetSize();
434 aSize
.SetWidthPercent( static_cast< sal_uInt8
>( rRelativeSize
.Width() ) );
435 aSize
.SetHeightPercent( static_cast< sal_uInt8
>( rRelativeSize
.Height() ) );
440 // Templates AutoUpdate
441 SwFrameFormat
* pFormat
= rSh
.GetSelectedFrameFormat();
442 if(pFormat
&& pFormat
->IsAutoUpdateOnDirectFormat())
444 pFormat
->SetFormatAttr(*pSet
);
446 RES_FRM_SIZE
, RES_FRM_SIZE
,
447 RES_SURROUND
, RES_ANCHOR
> aShellSet( GetPool() );
448 aShellSet
.Put(*pSet
);
449 aMgr
.SetAttrSet(aShellSet
);
453 aMgr
.SetAttrSet(*pSet
);
455 aMgr
.UpdateFlyFrame();
457 bool bApplyUsrPref
= false;
458 if (const SfxBoolItem
* pRatioItem
= pSet
->GetItemIfSet(
459 FN_KEEP_ASPECT_RATIO
))
461 aUsrPref
.SetKeepRatio( pRatioItem
->GetValue() );
462 bApplyUsrPref
= true;
464 if( const SfxBoolItem
* pZoomItem
= pSet
->GetItemIfSet(
465 SID_ATTR_GRAF_KEEP_ZOOM
))
467 aUsrPref
.SetGrfKeepZoom( pZoomItem
->GetValue() );
468 bApplyUsrPref
= true;
472 SW_MOD()->ApplyUsrPref(aUsrPref
, &GetView());
474 // and now set all the graphic attributes and other stuff
475 if( const SvxBrushItem
* pGraphicBrushItem
= pSet
->GetItemIfSet(
476 SID_ATTR_GRAF_GRAPHIC
))
478 if( !pGraphicBrushItem
->GetGraphicLink().isEmpty() )
479 sGrfNm
= pGraphicBrushItem
->GetGraphicLink();
483 if( !pGraphicBrushItem
->GetGraphicFilter().isEmpty() )
484 sFilterNm
= pGraphicBrushItem
->GetGraphicFilter();
488 if( !sGrfNm
.isEmpty() )
490 SwDocShell
* pDocSh
= GetView().GetDocShell();
491 SwWait
aWait( *pDocSh
, true );
492 SfxMedium
* pMedium
= pDocSh
->GetMedium();
495 aAbs
= pMedium
->GetURLObject();
496 rSh
.ReRead( URIHelper::SmartRel2Abs(
498 URIHelper::GetMaybeFileHdl() ),
502 if ( const SfxStringItem
* pNameItem
= pSet
->GetItemIfSet(
503 FN_SET_FRM_ALT_NAME
))
506 rSh
.SetObjTitle( pNameItem
->GetValue() );
509 if ( const SfxStringItem
* pDescriptionItem
= pSet
->GetItemIfSet(
510 FN_UNO_DESCRIPTION
))
511 rSh
.SetObjDescription( pDescriptionItem
->GetValue() );
513 // RotGrfFlyFrame: Get and process evtl. changed RotationAngle
514 if ( const SdrAngleItem
* pAngleItem
= pSet
->GetItemIfSet(SID_ATTR_TRANSFORM_ANGLE
, false ))
516 const Degree10 aNewRotation
= to
<Degree10
>(pAngleItem
->GetValue() % 36000_deg100
);
518 // RotGrfFlyFrame: Possible rotation change here, SwFlyFrameAttrMgr aMgr is available
519 aMgr
.SetRotation(nCurrentRotation
, aNewRotation
, aUnrotatedSize
);
522 SfxItemSetFixed
<RES_GRFATR_BEGIN
, RES_GRFATR_END
-1> aGrfSet( rSh
.GetAttrPool() );
523 aGrfSet
.Put( *pSet
);
524 if( aGrfSet
.Count() )
525 rSh
.SetAttrSet( aGrfSet
);
527 rSh
.EndUndo(SwUndoId::END
);
533 case FN_GRAPHIC_MIRROR_ON_EVEN_PAGES
:
535 SfxItemSetFixed
<RES_GRFATR_MIRRORGRF
, RES_GRFATR_MIRRORGRF
> aSet(rSh
.GetAttrPool());
536 rSh
.GetCurAttr( aSet
);
537 SwMirrorGrf
aGrf(aSet
.Get(RES_GRFATR_MIRRORGRF
));
538 aGrf
.SetGrfToggle(!aGrf
.IsGrfToggle());
539 rSh
.SetAttrItem(aGrf
);
543 case SID_OBJECT_CROP
:
545 GraphicObject
const *pGraphicObject
= rSh
.GetGraphicObj();
546 if (nullptr != pGraphicObject
&& SdrDragMode::Crop
!= rSh
.GetDragMode()) {
547 rSh
.StartCropImage();
553 OSL_ENSURE(false, "wrong dispatcher");
558 void SwGrfShell::ExecAttr( SfxRequest
const &rReq
)
560 GraphicType nGrfType
= GraphicType::NONE
;
561 if (CNT_GRF
== GetShell().GetCntType())
562 nGrfType
= GetShell().GetGraphicType();
563 if (GraphicType::Bitmap
== nGrfType
||
564 GraphicType::GdiMetafile
== nGrfType
)
566 SfxItemSetFixed
<RES_GRFATR_BEGIN
, RES_GRFATR_END
-1> aGrfSet( GetShell().GetAttrPool() );
567 const SfxItemSet
*pArgs
= rReq
.GetArgs();
568 const SfxPoolItem
* pItem
;
569 sal_uInt16 nSlot
= rReq
.GetSlot();
570 if( !pArgs
|| SfxItemState::SET
!= pArgs
->GetItemState( nSlot
, false, &pItem
))
575 case SID_FLIP_VERTICAL
:
576 case SID_FLIP_HORIZONTAL
:
578 GetShell().GetCurAttr( aGrfSet
);
579 SwMirrorGrf
aMirror( aGrfSet
.Get( RES_GRFATR_MIRRORGRF
) );
580 MirrorGraph nMirror
= aMirror
.GetValue();
581 if ( nSlot
==SID_FLIP_HORIZONTAL
)
584 case MirrorGraph::Dont
: nMirror
= MirrorGraph::Vertical
;
586 case MirrorGraph::Horizontal
: nMirror
= MirrorGraph::Both
;
588 case MirrorGraph::Vertical
: nMirror
= MirrorGraph::Dont
;
590 case MirrorGraph::Both
: nMirror
= MirrorGraph::Horizontal
;
596 case MirrorGraph::Dont
: nMirror
= MirrorGraph::Horizontal
;
598 case MirrorGraph::Vertical
: nMirror
= MirrorGraph::Both
;
600 case MirrorGraph::Horizontal
: nMirror
= MirrorGraph::Dont
;
602 case MirrorGraph::Both
: nMirror
= MirrorGraph::Vertical
;
605 aMirror
.SetValue( nMirror
);
607 aGrfSet
.Put( aMirror
);
611 case SID_ATTR_GRAF_LUMINANCE
:
613 aGrfSet
.Put( SwLuminanceGrf(
614 static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
617 case SID_ATTR_GRAF_CONTRAST
:
619 aGrfSet
.Put( SwContrastGrf(
620 static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
623 case SID_ATTR_GRAF_RED
:
625 aGrfSet
.Put( SwChannelRGrf(
626 static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
629 case SID_ATTR_GRAF_GREEN
:
631 aGrfSet
.Put( SwChannelGGrf(
632 static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
635 case SID_ATTR_GRAF_BLUE
:
637 aGrfSet
.Put( SwChannelBGrf(
638 static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
641 case SID_ATTR_GRAF_GAMMA
:
644 double fVal
= static_cast<const SfxUInt32Item
*>(pItem
)->GetValue();
645 aGrfSet
.Put( SwGammaGrf(fVal
/100. ));
649 case SID_ATTR_GRAF_TRANSPARENCE
:
651 aGrfSet
.Put( SwTransparencyGrf(
652 static_cast< sal_Int8
>( static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() ) ) );
655 case SID_ATTR_GRAF_INVERT
:
657 aGrfSet
.Put( SwInvertGrf(
658 static_cast<const SfxBoolItem
*>(pItem
)->GetValue() ));
661 case SID_ATTR_GRAF_MODE
:
663 aGrfSet
.Put( SwDrawModeGrf(
664 static_cast<GraphicDrawMode
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue()) ));
667 case SID_COLOR_SETTINGS
:
669 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
670 aToolboxAccess
.toggleToolbox();
675 case SID_GRFFILTER_INVERT
:
676 case SID_GRFFILTER_SMOOTH
:
677 case SID_GRFFILTER_SHARPEN
:
678 case SID_GRFFILTER_REMOVENOISE
:
679 case SID_GRFFILTER_SOBEL
:
680 case SID_GRFFILTER_MOSAIC
:
681 case SID_GRFFILTER_EMBOSS
:
682 case SID_GRFFILTER_POSTER
:
683 case SID_GRFFILTER_POPART
:
684 case SID_GRFFILTER_SEPIA
:
685 case SID_GRFFILTER_SOLARIZE
:
686 if( GraphicType::Bitmap
== nGrfType
)
689 const GraphicObject
* pFilterObj( GetShell().GetGraphicObj() );
692 GraphicObject
aFilterObj( *pFilterObj
);
693 if( SvxGraphicFilterResult::NONE
==
694 SvxGraphicFilter::ExecuteGrfFilterSlot( rReq
, aFilterObj
))
695 GetShell().ReRead( OUString(), OUString(),
696 &aFilterObj
.GetGraphic() );
702 OSL_ENSURE(false, "wrong dispatcher");
705 if( aGrfSet
.Count() )
706 GetShell().SetAttrSet( aGrfSet
);
708 GetView().GetViewFrame().GetBindings().Invalidate(rReq
.GetSlot());
711 void SwGrfShell::GetAttrState(SfxItemSet
&rSet
)
713 SwWrtShell
&rSh
= GetShell();
714 SfxItemSet
aCoreSet( GetPool(), aNoTextNodeSetRange
);
715 rSh
.GetCurAttr( aCoreSet
);
716 bool bParentCntProt
= FlyProtectFlags::NONE
!= rSh
.IsSelObjProtected( FlyProtectFlags::Content
|FlyProtectFlags::Parent
);
717 bool bIsGrfContent
= CNT_GRF
== GetShell().GetCntType();
719 SetGetStateSet( &rSet
);
721 SfxWhichIter
aIter( rSet
);
722 sal_uInt16 nWhich
= aIter
.FirstWhich();
725 bool bDisable
= bParentCntProt
;
728 case SID_OBJECT_ROTATE
:
730 // RotGrfFlyFrame: steer rotation state
731 const bool bIsRotate(GetView().IsDrawRotate());
732 SdrView
* pSdrView
= rSh
.GetDrawViewWithValidMarkList();
734 if(!bIsRotate
&& !pSdrView
->IsRotateAllowed())
736 rSet
.DisableItem(nWhich
);
740 rSet
.Put(SfxBoolItem(nWhich
, bIsRotate
));
745 case SID_INSERT_GRAPHIC
:
746 case FN_FORMAT_GRAFIC_DLG
:
747 case SID_TWAIN_TRANSFER
:
748 if( bParentCntProt
|| !bIsGrfContent
)
750 else if ( nWhich
== SID_INSERT_GRAPHIC
751 && rSh
.CursorInsideInputField() )
757 case SID_SAVE_GRAPHIC
:
758 case SID_EXTERNAL_EDIT
:
759 if( rSh
.GetGraphicType() == GraphicType::NONE
|| GetObjectShell()->isExportLocked())
763 case SID_COLOR_SETTINGS
:
765 if ( bParentCntProt
|| !bIsGrfContent
)
769 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
770 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
775 case SID_FLIP_HORIZONTAL
:
776 if( !bParentCntProt
)
778 MirrorGraph nState
= aCoreSet
.Get(
779 RES_GRFATR_MIRRORGRF
).GetValue();
781 rSet
.Put(SfxBoolItem( nWhich
, nState
== MirrorGraph::Vertical
||
782 nState
== MirrorGraph::Both
));
786 case SID_FLIP_VERTICAL
:
787 if( !bParentCntProt
)
789 MirrorGraph nState
= aCoreSet
.GetItem
<SwMirrorGrf
>( RES_GRFATR_MIRRORGRF
)->GetValue();
790 rSet
.Put(SfxBoolItem( nWhich
, nState
== MirrorGraph::Horizontal
||
791 nState
== MirrorGraph::Both
));
795 case SID_ATTR_GRAF_LUMINANCE
:
796 if( !bParentCntProt
)
797 rSet
.Put( SfxInt16Item( nWhich
,
798 aCoreSet
.Get(RES_GRFATR_LUMINANCE
).GetValue() ));
801 case SID_ATTR_GRAF_CONTRAST
:
802 if( !bParentCntProt
)
803 rSet
.Put( SfxInt16Item( nWhich
,
804 aCoreSet
.Get(RES_GRFATR_CONTRAST
).GetValue() ));
807 case SID_ATTR_GRAF_RED
:
808 if( !bParentCntProt
)
809 rSet
.Put( SfxInt16Item( nWhich
,
810 aCoreSet
.Get(RES_GRFATR_CHANNELR
).GetValue() ));
813 case SID_ATTR_GRAF_GREEN
:
814 if( !bParentCntProt
)
815 rSet
.Put( SfxInt16Item( nWhich
,
816 aCoreSet
.Get(RES_GRFATR_CHANNELG
).GetValue() ));
819 case SID_ATTR_GRAF_BLUE
:
820 if( !bParentCntProt
)
821 rSet
.Put( SfxInt16Item( nWhich
,
822 aCoreSet
.Get(RES_GRFATR_CHANNELB
).GetValue() ));
825 case SID_ATTR_GRAF_GAMMA
:
826 if( !bParentCntProt
)
827 rSet
.Put( SfxUInt32Item( nWhich
, static_cast< sal_uInt32
>(
828 aCoreSet
.Get( RES_GRFATR_GAMMA
).GetValue() * 100 ) ) );
831 case SID_ATTR_GRAF_TRANSPARENCE
:
832 if( !bParentCntProt
)
835 const GraphicObject
* pGrafObj
= rSh
.GetGraphicObj();
838 if( pGrafObj
->IsAnimated() ||
839 GraphicType::GdiMetafile
== pGrafObj
->GetType() )
842 rSet
.Put( SfxUInt16Item( nWhich
,
843 aCoreSet
.Get(RES_GRFATR_TRANSPARENCY
).GetValue() ));
848 case SID_ATTR_GRAF_INVERT
:
849 if( !bParentCntProt
)
850 rSet
.Put( SfxBoolItem( nWhich
,
851 aCoreSet
.Get(RES_GRFATR_INVERT
).GetValue() ));
854 case SID_ATTR_GRAF_MODE
:
855 if( !bParentCntProt
)
856 rSet
.Put( SfxUInt16Item( nWhich
, static_cast<sal_uInt16
>(aCoreSet
.Get(RES_GRFATR_DRAWMODE
).GetValue()) ));
860 case SID_GRFFILTER_INVERT
:
861 case SID_GRFFILTER_SMOOTH
:
862 case SID_GRFFILTER_SHARPEN
:
863 case SID_GRFFILTER_REMOVENOISE
:
864 case SID_GRFFILTER_SOBEL
:
865 case SID_GRFFILTER_MOSAIC
:
866 case SID_GRFFILTER_EMBOSS
:
867 case SID_GRFFILTER_POSTER
:
868 case SID_GRFFILTER_POPART
:
869 case SID_GRFFILTER_SEPIA
:
870 case SID_GRFFILTER_SOLARIZE
:
872 if( bParentCntProt
|| !bIsGrfContent
)
874 // #i59688# load graphic only if type is unknown
877 const GraphicType
eGraphicType( rSh
.GetGraphicType() );
878 if ( ( eGraphicType
== GraphicType::NONE
||
879 eGraphicType
== GraphicType::Default
) &&
880 rSh
.IsLinkedGrfSwapOut() )
882 rSet
.DisableItem( nWhich
);
883 if( AddGrfUpdateSlot( nWhich
))
884 rSh
.GetGraphic(false); // start the loading
888 bDisable
= eGraphicType
!= GraphicType::Bitmap
;
894 case SID_OBJECT_CROP
:
896 bDisable
= FlyProtectFlags::NONE
!= rSh
.IsSelObjProtected( FlyProtectFlags::Content
|FlyProtectFlags::Parent
);
897 if( rSh
.GetGraphicType() == GraphicType::NONE
)
907 rSet
.DisableItem( nWhich
);
908 nWhich
= aIter
.NextWhich();
910 SetGetStateSet( nullptr );
913 void SwGrfShell::ExecuteRotation(SfxRequest
const &rReq
)
915 // RotGrfFlyFrame: Modify rotation attribute instead of manipulating the graphic
918 if (rReq
.GetSlot() == SID_ROTATE_GRAPHIC_LEFT
)
920 aRotation
= 900_deg10
;
922 else if (rReq
.GetSlot() == SID_ROTATE_GRAPHIC_RIGHT
)
924 aRotation
= 2700_deg10
;
926 else if (rReq
.GetSlot() == SID_ROTATE_GRAPHIC_180
)
928 aRotation
= 1800_deg10
;
931 if (rReq
.GetSlot() != SID_ROTATE_GRAPHIC_RESET
&& 0_deg10
== aRotation
)
934 SwWrtShell
& rShell
= GetShell();
935 SfxItemSetFixed
<RES_GRFATR_ROTATION
, RES_GRFATR_ROTATION
> aSet( rShell
.GetAttrPool() );
936 rShell
.GetCurAttr( aSet
);
937 const SwRotationGrf
& rRotation
= aSet
.Get(RES_GRFATR_ROTATION
);
938 SwFlyFrameAttrMgr
aMgr(false, &rShell
, rShell
.IsFrameSelected() ? Frmmgr_Type::NONE
: Frmmgr_Type::GRF
, nullptr);
940 // RotGrfFlyFrame: Possible rotation change here, SwFlyFrameAttrMgr aMgr is available
941 if (rReq
.GetSlot() == SID_ROTATE_GRAPHIC_RESET
)
943 aMgr
.SetRotation(rRotation
.GetValue(), 0_deg10
, rRotation
.GetUnrotatedSize());
945 else if(0_deg10
!= aRotation
)
947 const Degree10
aNewRotation((aRotation
+ rRotation
.GetValue()) % 3600_deg10
);
949 aMgr
.SetRotation(rRotation
.GetValue(), aNewRotation
, rRotation
.GetUnrotatedSize());
953 void SwGrfShell::GetAttrStateForRotation(SfxItemSet
&rSet
)
955 SwWrtShell
& rShell
= GetShell();
956 bool bIsParentContentProtected
= FlyProtectFlags::NONE
!= rShell
.IsSelObjProtected( FlyProtectFlags::Content
|FlyProtectFlags::Parent
);
958 SetGetStateSet( &rSet
);
960 SfxWhichIter
aIterator( rSet
);
961 sal_uInt16 nWhich
= aIterator
.FirstWhich();
964 bool bDisable
= bIsParentContentProtected
;
967 case SID_ROTATE_GRAPHIC_LEFT
:
968 case SID_ROTATE_GRAPHIC_RIGHT
:
969 case SID_ROTATE_GRAPHIC_180
:
971 if( rShell
.GetGraphicType() == GraphicType::NONE
)
977 case SID_ROTATE_GRAPHIC_RESET
:
979 // RotGrfFlyFrame: disable when already no rotation
980 SfxItemSetFixed
<RES_GRFATR_ROTATION
, RES_GRFATR_ROTATION
> aSet( rShell
.GetAttrPool() );
981 rShell
.GetCurAttr( aSet
);
982 const SwRotationGrf
& rRotation
= aSet
.Get(RES_GRFATR_ROTATION
);
983 bDisable
= (0_deg10
== rRotation
.GetValue());
986 case SID_ATTR_TRANSFORM_ANGLE
:
988 // RotGrfFlyFrame: get rotation value from RES_GRFATR_ROTATION and copy to rSet as
989 // SID_ATTR_TRANSFORM_ANGLE, convert from 10th degrees to 100th degrees
990 SfxItemSetFixed
<RES_GRFATR_ROTATION
, RES_GRFATR_ROTATION
> aSet( rShell
.GetAttrPool() );
991 rShell
.GetCurAttr( aSet
);
992 const SwRotationGrf
& rRotation
= aSet
.Get(RES_GRFATR_ROTATION
);
993 rSet
.Put(SdrAngleItem(SID_ATTR_TRANSFORM_ANGLE
, to
<Degree100
>(rRotation
.GetValue())));
1001 rSet
.DisableItem( nWhich
);
1002 nWhich
= aIterator
.NextWhich();
1004 SetGetStateSet( nullptr );
1007 SwGrfShell::~SwGrfShell()
1011 SwGrfShell::SwGrfShell(SwView
&_rView
) :
1015 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Graphic
));
1018 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */