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 .
20 #include <sal/config.h>
22 #include <comphelper/propertyvalue.hxx>
23 #include <o3tl/string_view.hxx>
24 #include <vcl/toolbox.hxx>
25 #include <vcl/idle.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/itempool.hxx>
28 #include <svl/eitem.hxx>
29 #include <svl/whiter.hxx>
30 #include <sfx2/viewsh.hxx>
31 #include <sfx2/request.hxx>
32 #include <sfx2/basedlgs.hxx>
33 #include <vcl/InterimItemWindow.hxx>
34 #include <sfx2/sfxdlg.hxx>
35 #include <tools/urlobj.hxx>
37 #include <svx/dialogs.hrc>
38 #include <svx/svxids.hrc>
39 #include <svx/strings.hrc>
40 #include <editeng/brushitem.hxx>
41 #include <editeng/sizeitem.hxx>
42 #include <svx/sdgcpitm.hxx>
44 #include <svx/dialmgr.hxx>
45 #include <svx/svdview.hxx>
46 #include <svx/svdmodel.hxx>
47 #include <svx/svdograf.hxx>
48 #include <svx/svdundo.hxx>
49 #include <svx/svdtrans.hxx>
50 #include <svx/grafctrl.hxx>
51 #include <svx/tbxcolor.hxx>
52 #include <sdgcoitm.hxx>
53 #include <svx/sdggaitm.hxx>
54 #include <svx/sdgluitm.hxx>
55 #include <svx/sdgmoitm.hxx>
56 #include <sdgtritm.hxx>
57 #include <bitmaps.hlst>
59 #include <com/sun/star/frame/XDispatchProvider.hpp>
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::frame
;
63 using namespace ::com::sun::star::util
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::lang
;
67 constexpr OUStringLiteral TOOLBOX_NAME
= u
"colorbar";
68 #define RID_SVXSTR_UNDO_GRAFCROP RID_SVXSTR_GRAFCROP
72 class ImplGrafControl final
: public InterimItemWindow
76 Reference
<XFrame
> mxFrame
;
77 std::unique_ptr
<weld::Image
> mxImage
;
78 std::unique_ptr
<weld::MetricSpinButton
> mxField
;
80 DECL_LINK(ValueChangedHdl
, weld::MetricSpinButton
&, void);
81 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
85 ImplGrafControl( vcl::Window
* pParent
, const OUString
& rCmd
, const Reference
< XFrame
>& rFrame
);
86 virtual ~ImplGrafControl() override
;
87 virtual void dispose() override
;
89 void Update( const SfxPoolItem
* pItem
);
90 void set_field_text(const OUString
& rStr
) { mxField
->set_text(rStr
); }
91 void set_sensitive(bool bSensitive
)
94 mxImage
->set_sensitive(bSensitive
);
95 mxField
->set_sensitive(bSensitive
);
101 IMPL_LINK_NOARG(ImplGrafControl
, ValueChangedHdl
, weld::MetricSpinButton
&, void)
106 void ImplGrafControl::ImplModify()
108 const sal_Int64 nVal
= mxField
->get_value(FieldUnit::NONE
);
110 // Convert value to an any to be usable with dispatch API
112 if ( maCommand
== ".uno:GrafRed" ||
113 maCommand
== ".uno:GrafGreen" ||
114 maCommand
== ".uno:GrafBlue" ||
115 maCommand
== ".uno:GrafLuminance" ||
116 maCommand
== ".uno:GrafContrast" )
117 a
<<= sal_Int16( nVal
);
118 else if ( maCommand
== ".uno:GrafGamma" ||
119 maCommand
== ".uno:GrafTransparence" )
120 a
<<= sal_Int32( nVal
);
125 INetURLObject
aObj( maCommand
);
127 Sequence
< PropertyValue
> aArgs
{ comphelper::makePropertyValue(aObj
.GetURLPath(), a
) };
129 SfxToolBoxControl::Dispatch(
130 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
135 void ImplGrafControl::Update( const SfxPoolItem
* pItem
)
141 if ( maCommand
== ".uno:GrafTransparence" )
142 nValue
= static_cast<const SfxUInt16Item
*>( pItem
)->GetValue();
143 else if ( maCommand
== ".uno:GrafGamma" )
144 nValue
= static_cast<const SfxUInt32Item
*>( pItem
)->GetValue();
146 nValue
= static_cast<const SfxInt16Item
*>( pItem
)->GetValue();
148 mxField
->set_value(nValue
, FieldUnit::NONE
);
151 mxField
->set_text(OUString());
158 const char* pCommand
;
159 rtl::OUStringConstExpr sResId
;
164 static OUString
ImplGetRID( std::u16string_view aCommand
)
166 static constexpr OUStringLiteral EMPTY
= u
"";
167 static const CommandToRID aImplCommandToResMap
[] =
169 { ".uno:GrafRed", RID_SVXBMP_GRAF_RED
},
170 { ".uno:GrafGreen", RID_SVXBMP_GRAF_GREEN
},
171 { ".uno:GrafBlue", RID_SVXBMP_GRAF_BLUE
},
172 { ".uno:GrafLuminance", RID_SVXBMP_GRAF_LUMINANCE
},
173 { ".uno:GrafContrast", RID_SVXBMP_GRAF_CONTRAST
},
174 { ".uno:GrafGamma", RID_SVXBMP_GRAF_GAMMA
},
175 { ".uno:GrafTransparence", RID_SVXBMP_GRAF_TRANSPARENCE
},
182 while ( aImplCommandToResMap
[ i
].pCommand
)
184 if ( o3tl::equalsAscii( aCommand
, aImplCommandToResMap
[ i
].pCommand
))
186 sRID
= aImplCommandToResMap
[i
].sResId
;
195 ImplGrafControl::ImplGrafControl(
196 vcl::Window
* pParent
,
197 const OUString
& rCmd
,
198 const Reference
< XFrame
>& rFrame
)
199 : InterimItemWindow(pParent
, "svx/ui/grafctrlbox.ui", "GrafCtrlBox")
202 , mxImage(m_xBuilder
->weld_image("image"))
203 , mxField(m_xBuilder
->weld_metric_spin_button("spinfield", FieldUnit::NONE
))
205 InitControlBase(&mxField
->get_widget());
207 OUString
sResId(ImplGetRID(rCmd
));
208 mxImage
->set_from_icon_name(sResId
);
209 mxImage
->set_toolbar_background();
211 SetBackground( Wallpaper() ); // transparent background
213 mxField
->set_help_id(rCmd
);
214 mxField
->get_widget().connect_key_press(LINK(this, ImplGrafControl
, KeyInputHdl
));
215 mxField
->connect_value_changed(LINK(this, ImplGrafControl
, ValueChangedHdl
));
217 if (maCommand
== ".uno:GrafGamma")
219 mxField
->set_digits(2);
221 mxField
->set_range(10, 1000, FieldUnit::NONE
);
222 mxField
->set_increments(10, 100, FieldUnit::NONE
);
226 const tools::Long nMinVal
= maCommand
== ".uno:GrafTransparence" ? 0 : -100;
228 mxField
->set_unit(FieldUnit::PERCENT
);
229 mxField
->set_digits(0);
231 mxField
->set_range(nMinVal
, 100, FieldUnit::PERCENT
);
232 mxField
->set_increments(1, 10, FieldUnit::PERCENT
);
235 SetSizePixel(m_xContainer
->get_preferred_size());
238 IMPL_LINK(ImplGrafControl
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
240 return ChildKeyInput(rKEvt
);
243 ImplGrafControl::~ImplGrafControl()
248 void ImplGrafControl::dispose()
252 InterimItemWindow::dispose();
257 class ImplGrafModeControl final
: public InterimItemWindow
261 Reference
< XFrame
> mxFrame
;
262 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
264 DECL_LINK(SelectHdl
, weld::ComboBox
&, void);
265 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
266 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
268 static void ImplReleaseFocus();
271 ImplGrafModeControl( vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
);
272 virtual void dispose() override
;
273 virtual ~ImplGrafModeControl() override
;
275 void set_sensitive(bool bSensitive
)
278 m_xWidget
->set_sensitive(true);
281 void set_active(int nActive
)
283 m_xWidget
->set_active(nActive
);
286 void Update( const SfxPoolItem
* pItem
);
291 ImplGrafModeControl::ImplGrafModeControl(vcl::Window
* pParent
, const Reference
<XFrame
>& rFrame
)
292 : InterimItemWindow(pParent
, "svx/ui/grafmodebox.ui", "GrafModeBox")
295 , m_xWidget(m_xBuilder
->weld_combo_box("grafmode"))
297 InitControlBase(m_xWidget
.get());
299 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_STANDARD
) );
300 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_GREYS
) );
301 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_MONO
) );
302 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_WATERMARK
) );
304 m_xWidget
->connect_changed(LINK(this, ImplGrafModeControl
, SelectHdl
));
305 m_xWidget
->connect_key_press(LINK(this, ImplGrafModeControl
, KeyInputHdl
));
306 m_xWidget
->connect_focus_in(LINK(this, ImplGrafModeControl
, FocusInHdl
));
308 SetSizePixel(m_xWidget
->get_preferred_size());
311 void ImplGrafModeControl::dispose()
314 InterimItemWindow::dispose();
317 ImplGrafModeControl::~ImplGrafModeControl()
322 IMPL_LINK(ImplGrafModeControl
, SelectHdl
, weld::ComboBox
&, rBox
, void)
324 Sequence
< PropertyValue
> aArgs
{ comphelper::makePropertyValue("GrafMode",
325 sal_Int16(rBox
.get_active())) };
327 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
328 This instance may be deleted in the meantime (i.e. when a dialog is opened
329 while in Dispatch()), accessing members will crash in this case. */
332 SfxToolBoxControl::Dispatch(
333 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
338 IMPL_LINK(ImplGrafModeControl
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
340 bool bHandled(false);
342 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
344 m_xWidget
->set_active(mnCurPos
);
349 return bHandled
|| ChildKeyInput(rKEvt
);
352 IMPL_LINK_NOARG(ImplGrafModeControl
, FocusInHdl
, weld::Widget
&, void)
354 mnCurPos
= m_xWidget
->get_active();
357 void ImplGrafModeControl::ImplReleaseFocus()
359 if( SfxViewShell::Current() )
361 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
364 pShellWnd
->GrabFocus();
368 void ImplGrafModeControl::Update( const SfxPoolItem
* pItem
)
371 m_xWidget
->set_active(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
373 m_xWidget
->set_active(-1);
376 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
377 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
379 rTbx
.SetItemBits( nId
, ToolBoxItemBits::DROPDOWN
| rTbx
.GetItemBits( nId
) );
383 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
387 void SvxGrafToolBoxControl::StateChangedAtToolBoxControl( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
389 ImplGrafControl
* pCtrl
= static_cast<ImplGrafControl
*>( GetToolBox().GetItemWindow( GetId() ) );
390 DBG_ASSERT( pCtrl
, "Control not found" );
392 if( eState
== SfxItemState::DISABLED
)
394 pCtrl
->set_sensitive(false);
395 pCtrl
->set_field_text( OUString() );
399 pCtrl
->set_sensitive(true);
401 if( eState
== SfxItemState::DEFAULT
)
402 pCtrl
->Update( pState
);
404 pCtrl
->Update( nullptr );
408 VclPtr
<InterimItemWindow
> SvxGrafToolBoxControl::CreateItemWindow( vcl::Window
*pParent
)
410 return VclPtr
<ImplGrafControl
>::Create( pParent
, m_aCommandURL
, m_xFrame
).get();
413 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl
, SfxInt16Item
);
415 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
416 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
420 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl
, SfxInt16Item
);
422 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
423 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
427 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl
, SfxInt16Item
);
429 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
430 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
434 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl
, SfxInt16Item
);
436 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
437 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
441 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl
, SfxInt16Item
);
443 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
444 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
448 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl
, SfxUInt32Item
);
450 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
451 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
455 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl
, SfxUInt16Item
);
457 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
458 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
462 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl
, SfxUInt16Item
);
464 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
465 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
469 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
473 void SvxGrafModeToolBoxControl::StateChangedAtToolBoxControl( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
476 ImplGrafModeControl
* pCtrl
= static_cast<ImplGrafModeControl
*>( GetToolBox().GetItemWindow( GetId() ) );
477 DBG_ASSERT( pCtrl
, "Control not found" );
479 if( eState
== SfxItemState::DISABLED
)
481 pCtrl
->set_sensitive(false);
482 pCtrl
->set_active(-1);
486 pCtrl
->set_sensitive(true);
488 if( eState
== SfxItemState::DEFAULT
)
489 pCtrl
->Update( pState
);
491 pCtrl
->Update( nullptr );
495 VclPtr
<InterimItemWindow
> SvxGrafModeToolBoxControl::CreateItemWindow( vcl::Window
*pParent
)
497 return VclPtr
<ImplGrafModeControl
>::Create( pParent
, m_xFrame
).get();
500 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest
& rReq
, SdrView
& rView
)
502 SfxItemPool
& rPool
= rView
.GetModel().GetItemPool();
503 SfxItemSetFixed
<SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
> aSet( rPool
);
505 const bool bUndo
= rView
.IsUndoEnabled();
509 aUndoStr
= rView
.GetDescriptionOfMarkedObjects() + " ";
512 const SfxItemSet
* pArgs
= rReq
.GetArgs();
513 const SfxPoolItem
* pItem
;
514 sal_uInt16 nSlot
= rReq
.GetSlot();
516 if( !pArgs
|| SfxItemState::SET
!= pArgs
->GetItemState( nSlot
, false, &pItem
))
521 case SID_ATTR_GRAF_RED
:
525 aSet
.Put( SdrGrafRedItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
527 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFRED
);
532 case SID_ATTR_GRAF_GREEN
:
536 aSet
.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
538 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFGREEN
);
543 case SID_ATTR_GRAF_BLUE
:
547 aSet
.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
549 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFBLUE
);
554 case SID_ATTR_GRAF_LUMINANCE
:
558 aSet
.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
560 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE
);
565 case SID_ATTR_GRAF_CONTRAST
:
569 aSet
.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
571 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST
);
576 case SID_ATTR_GRAF_GAMMA
:
580 aSet
.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item
*>(pItem
)->GetValue() ));
582 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA
);
587 case SID_ATTR_GRAF_TRANSPARENCE
:
591 aSet
.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() ));
593 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY
);
598 case SID_ATTR_GRAF_MODE
:
602 aSet
.Put( SdrGrafModeItem( static_cast<GraphicDrawMode
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue()) ));
604 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFMODE
);
609 case SID_ATTR_GRAF_CROP
:
611 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
613 if( 0 < rMarkList
.GetMarkCount() )
615 SdrGrafObj
* pObj
= static_cast<SdrGrafObj
*>( rMarkList
.GetMark( 0 )->GetMarkedSdrObj() );
617 if( ( pObj
->GetGraphicType() != GraphicType::NONE
) &&
618 ( pObj
->GetGraphicType() != GraphicType::Default
) )
620 SfxItemSetFixed
<SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
> aGrfAttr( rPool
);
621 const MapUnit eOldMetric
= rPool
.GetMetric( 0 );
623 aGrfAttr
.Put(pObj
->GetMergedItemSet());
624 rPool
.SetDefaultMetric( MapUnit::MapTwip
);
627 SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
,
628 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
629 SID_ATTR_GRAF_CROP
, SID_ATTR_GRAF_FRMSIZE
,
630 SID_ATTR_GRAF_GRAPHIC
, SID_ATTR_GRAF_GRAPHIC
>
633 aCropDlgAttr
.Put( SvxBrushItem( pObj
->GetGraphic(), GPOS_MM
, SID_ATTR_GRAF_GRAPHIC
) );
634 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE
,
635 o3tl::convert(Size(200000, 200000), o3tl::Length::mm100
, o3tl::Length::twip
)));
636 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE
,
637 o3tl::convert(pObj
->GetLogicRect().GetSize(), o3tl::Length::mm100
, o3tl::Length::twip
)));
639 const SdrGrafCropItem
& rCrop
= aGrfAttr
.Get( SDRATTR_GRAFCROP
);
640 Size aLTSize
= o3tl::convert(Size(rCrop
.GetLeft(), rCrop
.GetTop()), o3tl::Length::mm100
, o3tl::Length::twip
);
641 Size aRBSize
= o3tl::convert(Size(rCrop
.GetRight(), rCrop
.GetBottom()), o3tl::Length::mm100
, o3tl::Length::twip
);
643 aCropDlgAttr
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(),
644 aRBSize
.Width(), aRBSize
.Height() ) );
646 vcl::Window
* pParent(SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : nullptr);
647 SfxSingleTabDialogController
aCropDialog(pParent
? pParent
->GetFrameWeld() : nullptr,
649 const OUString
aCropStr(SvxResId(RID_SVXSTR_GRAFCROP
));
651 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
652 ::CreateTabPage fnCreatePage
= pFact
->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP
);
653 std::unique_ptr
<SfxTabPage
> xTabPage
= (*fnCreatePage
)(aCropDialog
.get_content_area(), &aCropDialog
, &aCropDlgAttr
);
654 sal_Int32 nPreferredDPI
= rView
.getSdrModelFromSdrView().getImagePreferredDPI();
655 xTabPage
->getAdditionalProperties().emplace("PreferredDPI", css::uno::Any(nPreferredDPI
));
656 xTabPage
->SetPageTitle(aCropStr
);
657 aCropDialog
.SetTabPage(std::move(xTabPage
));
659 if (aCropDialog
.run() == RET_OK
)
661 const SfxItemSet
* pOutAttr
= aCropDialog
.GetOutputItemSet();
665 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFCROP
);
667 // set crop attributes
668 if( SfxItemState::SET
<= pOutAttr
->GetItemState( SDRATTR_GRAFCROP
) )
670 const SdrGrafCropItem
& rNewCrop
= pOutAttr
->Get( SDRATTR_GRAFCROP
);
672 aLTSize
= o3tl::convert(Size(rNewCrop
.GetLeft(), rNewCrop
.GetTop()), o3tl::Length::twip
, o3tl::Length::mm100
);
673 aRBSize
= o3tl::convert(Size(rNewCrop
.GetRight(), rNewCrop
.GetBottom()), o3tl::Length::twip
, o3tl::Length::mm100
);
674 aSet
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(), aRBSize
.Width(), aRBSize
.Height() ) );
677 // set new logic rect
678 if( SfxItemState::SET
<= pOutAttr
->GetItemState( SID_ATTR_GRAF_FRMSIZE
) )
680 Point
aNewOrigin( pObj
->GetLogicRect().TopLeft() );
681 const Size
& rGrfSize
= pOutAttr
->Get( SID_ATTR_GRAF_FRMSIZE
).GetSize();
682 Size aNewGrfSize
= o3tl::convert(rGrfSize
, o3tl::Length::twip
, o3tl::Length::mm100
);
683 Size
aOldGrfSize( pObj
->GetLogicRect().GetSize() );
685 tools::Rectangle
aNewRect( aNewOrigin
, aNewGrfSize
);
686 Point
aOffset( (aNewGrfSize
.Width() - aOldGrfSize
.Width()) >> 1,
687 (aNewGrfSize
.Height() - aOldGrfSize
.Height()) >> 1 );
689 // #106181# rotate snap rect before setting it
690 const GeoStat
& aGeo
= pObj
->GetGeoStat();
692 if (aGeo
.nRotationAngle
|| aGeo
.nShearAngle
)
694 tools::Polygon
aPol(aNewRect
);
696 // also transform origin offset
697 if (aGeo
.nShearAngle
)
701 aGeo
.mfTanShearAngle
);
702 ShearPoint(aOffset
, Point(0,0), aGeo
.mfTanShearAngle
);
704 if (aGeo
.nRotationAngle
)
708 aGeo
.mfSinRotationAngle
,aGeo
.mfCosRotationAngle
);
709 RotatePoint(aOffset
, Point(0,0), aGeo
.mfSinRotationAngle
,aGeo
.mfCosRotationAngle
);
713 aPol
.Move( -aOffset
.X(), -aOffset
.Y() );
714 aNewRect
=aPol
.GetBoundRect();
718 aNewRect
.Move( -aOffset
.X(), -aOffset
.Y() );
722 rView
.SetMarkedObjRect( aNewRect
);
727 rView
.BegUndo( aUndoStr
);
728 rView
.AddUndo(rView
.GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
730 pObj
->SetSnapRect( aNewRect
);
731 rView
.SetAttributes( aSet
);
741 rPool
.SetDefaultMetric( eOldMetric
);
747 case SID_COLOR_SETTINGS
:
749 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
750 aToolboxAccess
.toggleToolbox();
762 rView
.BegUndo( aUndoStr
);
764 rView
.SetAttributes( aSet
);
771 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet
& rSet
, SdrView
const & rView
)
773 SfxItemPool
& rPool
= rView
.GetModel().GetItemPool();
774 SfxItemSet
aAttrSet( rPool
);
775 SfxWhichIter
aIter( rSet
);
776 sal_uInt16 nWhich
= aIter
.FirstWhich();
777 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
778 bool bEnableColors
= true;
779 bool bEnableTransparency
= true;
780 bool bEnableCrop
= ( 1 == rMarkList
.GetMarkCount() );
782 for( size_t i
= 0, nCount
= rMarkList
.GetMarkCount(); i
< nCount
; ++i
)
784 SdrGrafObj
* pGrafObj
= dynamic_cast< SdrGrafObj
* >( rMarkList
.GetMark( i
)->GetMarkedSdrObj() );
787 ( pGrafObj
->GetGraphicType() == GraphicType::NONE
) ||
788 ( pGrafObj
->GetGraphicType() == GraphicType::Default
))
790 bEnableColors
= bEnableTransparency
= bEnableCrop
= false;
793 else if( bEnableTransparency
&& ( pGrafObj
->HasGDIMetaFile() || pGrafObj
->IsAnimated() ) )
795 bEnableTransparency
= false;
799 rView
.GetAttributes( aAttrSet
);
803 sal_uInt16 nSlotId
= SfxItemPool::IsWhich( nWhich
) ? rPool
.GetSlotId( nWhich
) : nWhich
;
807 case SID_ATTR_GRAF_MODE
:
809 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFMODE
) )
813 rSet
.Put( SfxUInt16Item( nSlotId
,
814 sal::static_int_cast
< sal_uInt16
>( aAttrSet
.Get(SDRATTR_GRAFMODE
).GetValue() ) ) );
818 rSet
.DisableItem( SID_ATTR_GRAF_MODE
);
824 case SID_ATTR_GRAF_RED
:
826 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFRED
) )
830 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFRED
).GetValue() ) );
834 rSet
.DisableItem( SID_ATTR_GRAF_RED
);
840 case SID_ATTR_GRAF_GREEN
:
842 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGREEN
) )
846 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFGREEN
).GetValue()) );
850 rSet
.DisableItem( SID_ATTR_GRAF_GREEN
);
856 case SID_ATTR_GRAF_BLUE
:
858 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFBLUE
) )
862 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFBLUE
).GetValue()) );
866 rSet
.DisableItem( SID_ATTR_GRAF_BLUE
);
872 case SID_ATTR_GRAF_LUMINANCE
:
874 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFLUMINANCE
) )
878 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFLUMINANCE
).GetValue()) );
882 rSet
.DisableItem( SID_ATTR_GRAF_LUMINANCE
);
888 case SID_ATTR_GRAF_CONTRAST
:
890 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFCONTRAST
) )
894 rSet
.Put( SfxInt16Item( nSlotId
,
895 aAttrSet
.Get(SDRATTR_GRAFCONTRAST
).GetValue()) );
899 rSet
.DisableItem( SID_ATTR_GRAF_CONTRAST
);
905 case SID_ATTR_GRAF_GAMMA
:
907 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGAMMA
) )
911 rSet
.Put( SfxUInt32Item( nSlotId
,
912 aAttrSet
.Get(SDRATTR_GRAFGAMMA
).GetValue() ) );
916 rSet
.DisableItem( SID_ATTR_GRAF_GAMMA
);
922 case SID_ATTR_GRAF_TRANSPARENCE
:
924 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFTRANSPARENCE
) )
926 if( bEnableTransparency
)
928 rSet
.Put( SfxUInt16Item( nSlotId
,
929 aAttrSet
.Get(SDRATTR_GRAFTRANSPARENCE
).GetValue() ) );
933 rSet
.DisableItem( SID_ATTR_GRAF_TRANSPARENCE
);
939 case SID_ATTR_GRAF_CROP
:
942 rSet
.DisableItem( nSlotId
);
946 case SID_COLOR_SETTINGS
:
948 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
949 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
957 nWhich
= aIter
.NextWhich();
961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */