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 <svl/intitem.hxx>
26 #include <svl/itempool.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/whiter.hxx>
29 #include <sfx2/viewsh.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/basedlgs.hxx>
32 #include <vcl/InterimItemWindow.hxx>
33 #include <sfx2/sfxdlg.hxx>
34 #include <tools/urlobj.hxx>
36 #include <svx/dialogs.hrc>
37 #include <svx/svxids.hrc>
38 #include <svx/strings.hrc>
39 #include <editeng/brushitem.hxx>
40 #include <editeng/sizeitem.hxx>
41 #include <svx/sdgcpitm.hxx>
43 #include <svx/dialmgr.hxx>
44 #include <svx/svdview.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/svdograf.hxx>
47 #include <svx/svdundo.hxx>
48 #include <svx/svdtrans.hxx>
49 #include <svx/grafctrl.hxx>
50 #include <svx/tbxcolor.hxx>
51 #include <sdgcoitm.hxx>
52 #include <svx/sdggaitm.hxx>
53 #include <svx/sdgluitm.hxx>
54 #include <svx/sdgmoitm.hxx>
55 #include <sdgtritm.hxx>
56 #include <bitmaps.hlst>
58 #include <com/sun/star/frame/XDispatchProvider.hpp>
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::frame
;
62 using namespace ::com::sun::star::beans
;
64 constexpr OUString TOOLBOX_NAME
= u
"colorbar"_ustr
;
65 #define RID_SVXSTR_UNDO_GRAFCROP RID_SVXSTR_GRAFCROP
69 class ImplGrafControl final
: public InterimItemWindow
73 Reference
<XFrame
> mxFrame
;
74 std::unique_ptr
<weld::Image
> mxImage
;
75 std::unique_ptr
<weld::MetricSpinButton
> mxField
;
77 DECL_LINK(ValueChangedHdl
, weld::MetricSpinButton
&, void);
78 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
82 ImplGrafControl( vcl::Window
* pParent
, const OUString
& rCmd
, const Reference
< XFrame
>& rFrame
);
83 virtual ~ImplGrafControl() override
;
84 virtual void dispose() override
;
86 void Update( const SfxPoolItem
* pItem
);
87 void set_field_text(const OUString
& rStr
) { mxField
->set_text(rStr
); }
88 void set_sensitive(bool bSensitive
)
91 mxImage
->set_sensitive(bSensitive
);
92 mxField
->set_sensitive(bSensitive
);
98 IMPL_LINK_NOARG(ImplGrafControl
, ValueChangedHdl
, weld::MetricSpinButton
&, void)
103 void ImplGrafControl::ImplModify()
105 const sal_Int64 nVal
= mxField
->get_value(FieldUnit::NONE
);
107 // Convert value to an any to be usable with dispatch API
109 if ( maCommand
== ".uno:GrafRed" ||
110 maCommand
== ".uno:GrafGreen" ||
111 maCommand
== ".uno:GrafBlue" ||
112 maCommand
== ".uno:GrafLuminance" ||
113 maCommand
== ".uno:GrafContrast" )
114 a
<<= sal_Int16( nVal
);
115 else if ( maCommand
== ".uno:GrafGamma" ||
116 maCommand
== ".uno:GrafTransparence" )
117 a
<<= sal_Int32( nVal
);
122 INetURLObject
aObj( maCommand
);
124 Sequence
< PropertyValue
> aArgs
{ comphelper::makePropertyValue(aObj
.GetURLPath(), a
) };
126 SfxToolBoxControl::Dispatch(
127 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
132 void ImplGrafControl::Update( const SfxPoolItem
* pItem
)
138 if ( maCommand
== ".uno:GrafTransparence" )
139 nValue
= static_cast<const SfxUInt16Item
*>( pItem
)->GetValue();
140 else if ( maCommand
== ".uno:GrafGamma" )
141 nValue
= static_cast<const SfxUInt32Item
*>( pItem
)->GetValue();
143 nValue
= static_cast<const SfxInt16Item
*>( pItem
)->GetValue();
145 mxField
->set_value(nValue
, FieldUnit::NONE
);
148 mxField
->set_text(OUString());
155 const char* pCommand
;
161 static OUString
ImplGetRID( std::u16string_view aCommand
)
163 static constexpr CommandToRID aImplCommandToResMap
[] =
165 { ".uno:GrafRed", RID_SVXBMP_GRAF_RED
},
166 { ".uno:GrafGreen", RID_SVXBMP_GRAF_GREEN
},
167 { ".uno:GrafBlue", RID_SVXBMP_GRAF_BLUE
},
168 { ".uno:GrafLuminance", RID_SVXBMP_GRAF_LUMINANCE
},
169 { ".uno:GrafContrast", RID_SVXBMP_GRAF_CONTRAST
},
170 { ".uno:GrafGamma", RID_SVXBMP_GRAF_GAMMA
},
171 { ".uno:GrafTransparence", RID_SVXBMP_GRAF_TRANSPARENCE
},
172 { nullptr, EMPTY_OUSTRING
}
178 while ( aImplCommandToResMap
[ i
].pCommand
)
180 if ( o3tl::equalsAscii( aCommand
, aImplCommandToResMap
[ i
].pCommand
))
182 sRID
= aImplCommandToResMap
[i
].sResId
;
191 ImplGrafControl::ImplGrafControl(
192 vcl::Window
* pParent
,
193 const OUString
& rCmd
,
194 const Reference
< XFrame
>& rFrame
)
195 : InterimItemWindow(pParent
, u
"svx/ui/grafctrlbox.ui"_ustr
, u
"GrafCtrlBox"_ustr
)
198 , mxImage(m_xBuilder
->weld_image(u
"image"_ustr
))
199 , mxField(m_xBuilder
->weld_metric_spin_button(u
"spinfield"_ustr
, FieldUnit::NONE
))
201 InitControlBase(&mxField
->get_widget());
203 OUString
sResId(ImplGetRID(rCmd
));
204 mxImage
->set_from_icon_name(sResId
);
205 mxImage
->set_toolbar_background();
207 SetBackground( Wallpaper() ); // transparent background
209 mxField
->set_help_id(rCmd
);
210 mxField
->get_widget().connect_key_press(LINK(this, ImplGrafControl
, KeyInputHdl
));
211 mxField
->connect_value_changed(LINK(this, ImplGrafControl
, ValueChangedHdl
));
213 if (maCommand
== ".uno:GrafGamma")
215 mxField
->set_digits(2);
217 mxField
->set_range(10, 1000, FieldUnit::NONE
);
218 mxField
->set_increments(10, 100, FieldUnit::NONE
);
222 const tools::Long nMinVal
= maCommand
== ".uno:GrafTransparence" ? 0 : -100;
224 mxField
->set_unit(FieldUnit::PERCENT
);
225 mxField
->set_digits(0);
227 mxField
->set_range(nMinVal
, 100, FieldUnit::PERCENT
);
228 mxField
->set_increments(1, 10, FieldUnit::PERCENT
);
231 SetSizePixel(m_xContainer
->get_preferred_size());
234 IMPL_LINK(ImplGrafControl
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
236 return ChildKeyInput(rKEvt
);
239 ImplGrafControl::~ImplGrafControl()
244 void ImplGrafControl::dispose()
248 InterimItemWindow::dispose();
253 class ImplGrafModeControl final
: public InterimItemWindow
257 Reference
< XFrame
> mxFrame
;
258 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
260 DECL_LINK(SelectHdl
, weld::ComboBox
&, void);
261 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
262 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
264 static void ImplReleaseFocus();
267 ImplGrafModeControl( vcl::Window
* pParent
, const Reference
< XFrame
>& rFrame
);
268 virtual void dispose() override
;
269 virtual ~ImplGrafModeControl() override
;
271 void set_sensitive(bool bSensitive
)
274 m_xWidget
->set_sensitive(true);
277 void set_active(int nActive
)
279 m_xWidget
->set_active(nActive
);
282 void Update( const SfxPoolItem
* pItem
);
287 ImplGrafModeControl::ImplGrafModeControl(vcl::Window
* pParent
, const Reference
<XFrame
>& rFrame
)
288 : InterimItemWindow(pParent
, u
"svx/ui/grafmodebox.ui"_ustr
, u
"GrafModeBox"_ustr
)
291 , m_xWidget(m_xBuilder
->weld_combo_box(u
"grafmode"_ustr
))
293 InitControlBase(m_xWidget
.get());
295 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_STANDARD
) );
296 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_GREYS
) );
297 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_MONO
) );
298 m_xWidget
->append_text( SvxResId( RID_SVXSTR_GRAFMODE_WATERMARK
) );
300 m_xWidget
->connect_changed(LINK(this, ImplGrafModeControl
, SelectHdl
));
301 m_xWidget
->connect_key_press(LINK(this, ImplGrafModeControl
, KeyInputHdl
));
302 m_xWidget
->connect_focus_in(LINK(this, ImplGrafModeControl
, FocusInHdl
));
304 SetSizePixel(m_xWidget
->get_preferred_size());
307 void ImplGrafModeControl::dispose()
310 InterimItemWindow::dispose();
313 ImplGrafModeControl::~ImplGrafModeControl()
318 IMPL_LINK(ImplGrafModeControl
, SelectHdl
, weld::ComboBox
&, rBox
, void)
320 Sequence
< PropertyValue
> aArgs
{ comphelper::makePropertyValue(u
"GrafMode"_ustr
,
321 sal_Int16(rBox
.get_active())) };
323 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
324 This instance may be deleted in the meantime (i.e. when a dialog is opened
325 while in Dispatch()), accessing members will crash in this case. */
328 SfxToolBoxControl::Dispatch(
329 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
330 u
".uno:GrafMode"_ustr
,
334 IMPL_LINK(ImplGrafModeControl
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
336 bool bHandled(false);
338 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
340 m_xWidget
->set_active(mnCurPos
);
345 return bHandled
|| ChildKeyInput(rKEvt
);
348 IMPL_LINK_NOARG(ImplGrafModeControl
, FocusInHdl
, weld::Widget
&, void)
350 mnCurPos
= m_xWidget
->get_active();
353 void ImplGrafModeControl::ImplReleaseFocus()
355 if (const SfxViewShell
* pViewShell
= SfxViewShell::Current())
357 vcl::Window
* pShellWnd
= pViewShell
->GetWindow();
360 pShellWnd
->GrabFocus();
364 void ImplGrafModeControl::Update( const SfxPoolItem
* pItem
)
367 m_xWidget
->set_active(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
369 m_xWidget
->set_active(-1);
372 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
373 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
375 rTbx
.SetItemBits( nId
, ToolBoxItemBits::DROPDOWN
| rTbx
.GetItemBits( nId
) );
379 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
383 void SvxGrafToolBoxControl::StateChangedAtToolBoxControl( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
385 ImplGrafControl
* pCtrl
= static_cast<ImplGrafControl
*>( GetToolBox().GetItemWindow( GetId() ) );
386 DBG_ASSERT( pCtrl
, "Control not found" );
388 if( eState
== SfxItemState::DISABLED
)
390 pCtrl
->set_sensitive(false);
391 pCtrl
->set_field_text( OUString() );
395 pCtrl
->set_sensitive(true);
397 if( eState
== SfxItemState::DEFAULT
)
398 pCtrl
->Update( pState
);
400 pCtrl
->Update( nullptr );
404 VclPtr
<InterimItemWindow
> SvxGrafToolBoxControl::CreateItemWindow( vcl::Window
*pParent
)
406 return VclPtr
<ImplGrafControl
>::Create( pParent
, m_aCommandURL
, m_xFrame
).get();
409 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl
, SfxInt16Item
);
411 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
412 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
416 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl
, SfxInt16Item
);
418 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
419 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
423 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl
, SfxInt16Item
);
425 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
426 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
430 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl
, SfxInt16Item
);
432 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
433 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
437 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl
, SfxInt16Item
);
439 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
440 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
444 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl
, SfxUInt32Item
);
446 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
447 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
451 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl
, SfxUInt16Item
);
453 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
454 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
458 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl
, SfxUInt16Item
);
460 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
461 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
465 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
469 void SvxGrafModeToolBoxControl::StateChangedAtToolBoxControl( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
472 ImplGrafModeControl
* pCtrl
= static_cast<ImplGrafModeControl
*>( GetToolBox().GetItemWindow( GetId() ) );
473 DBG_ASSERT( pCtrl
, "Control not found" );
475 if( eState
== SfxItemState::DISABLED
)
477 pCtrl
->set_sensitive(false);
478 pCtrl
->set_active(-1);
482 pCtrl
->set_sensitive(true);
484 if( eState
== SfxItemState::DEFAULT
)
485 pCtrl
->Update( pState
);
487 pCtrl
->Update( nullptr );
491 VclPtr
<InterimItemWindow
> SvxGrafModeToolBoxControl::CreateItemWindow( vcl::Window
*pParent
)
493 return VclPtr
<ImplGrafModeControl
>::Create( pParent
, m_xFrame
).get();
496 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest
& rReq
, SdrView
& rView
)
498 SfxItemPool
& rPool
= rView
.GetModel().GetItemPool();
499 SfxItemSetFixed
<SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
> aSet( rPool
);
501 const bool bUndo
= rView
.IsUndoEnabled();
505 aUndoStr
= rView
.GetMarkedObjectList().GetMarkDescription() + " ";
508 const SfxItemSet
* pArgs
= rReq
.GetArgs();
509 const SfxPoolItem
* pItem
;
510 sal_uInt16 nSlot
= rReq
.GetSlot();
512 if( !pArgs
|| SfxItemState::SET
!= pArgs
->GetItemState( nSlot
, false, &pItem
))
517 case SID_ATTR_GRAF_RED
:
521 aSet
.Put( SdrGrafRedItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
523 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFRED
);
528 case SID_ATTR_GRAF_GREEN
:
532 aSet
.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
534 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFGREEN
);
539 case SID_ATTR_GRAF_BLUE
:
543 aSet
.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
545 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFBLUE
);
550 case SID_ATTR_GRAF_LUMINANCE
:
554 aSet
.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
556 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE
);
561 case SID_ATTR_GRAF_CONTRAST
:
565 aSet
.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
567 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST
);
572 case SID_ATTR_GRAF_GAMMA
:
576 aSet
.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item
*>(pItem
)->GetValue() ));
578 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA
);
583 case SID_ATTR_GRAF_TRANSPARENCE
:
587 aSet
.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() ));
589 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY
);
594 case SID_ATTR_GRAF_MODE
:
598 aSet
.Put( SdrGrafModeItem( static_cast<GraphicDrawMode
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue()) ));
600 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFMODE
);
605 case SID_ATTR_GRAF_CROP
:
607 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
609 if( 0 < rMarkList
.GetMarkCount() )
611 SdrGrafObj
* pObj
= static_cast<SdrGrafObj
*>( rMarkList
.GetMark( 0 )->GetMarkedSdrObj() );
613 if( ( pObj
->GetGraphicType() != GraphicType::NONE
) &&
614 ( pObj
->GetGraphicType() != GraphicType::Default
) )
616 SfxItemSetFixed
<SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
> aGrfAttr( rPool
);
617 const MapUnit eOldMetric
= rPool
.GetMetric( 0 );
619 aGrfAttr
.Put(pObj
->GetMergedItemSet());
620 rPool
.SetDefaultMetric( MapUnit::MapTwip
);
623 SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
,
624 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
625 SID_ATTR_GRAF_CROP
, SID_ATTR_GRAF_FRMSIZE
,
626 SID_ATTR_GRAF_GRAPHIC
, SID_ATTR_GRAF_GRAPHIC
>
629 aCropDlgAttr
.Put( SvxBrushItem( pObj
->GetGraphic(), GPOS_MM
, SID_ATTR_GRAF_GRAPHIC
) );
630 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE
,
631 o3tl::convert(Size(200000, 200000), o3tl::Length::mm100
, o3tl::Length::twip
)));
632 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE
,
633 o3tl::convert(pObj
->GetLogicRect().GetSize(), o3tl::Length::mm100
, o3tl::Length::twip
)));
635 const SdrGrafCropItem
& rCrop
= aGrfAttr
.Get( SDRATTR_GRAFCROP
);
636 Size aLTSize
= o3tl::convert(Size(rCrop
.GetLeft(), rCrop
.GetTop()), o3tl::Length::mm100
, o3tl::Length::twip
);
637 Size aRBSize
= o3tl::convert(Size(rCrop
.GetRight(), rCrop
.GetBottom()), o3tl::Length::mm100
, o3tl::Length::twip
);
639 aCropDlgAttr
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(),
640 aRBSize
.Width(), aRBSize
.Height() ) );
642 SfxViewShell
* pCurrentSh
= SfxViewShell::Current();
643 vcl::Window
* pParent(pCurrentSh
? pCurrentSh
->GetWindow() : nullptr);
644 SfxSingleTabDialogController
aCropDialog(pParent
? pParent
->GetFrameWeld() : nullptr,
646 const OUString
aCropStr(SvxResId(RID_SVXSTR_GRAFCROP
));
648 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
649 ::CreateTabPage fnCreatePage
= pFact
->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP
);
650 std::unique_ptr
<SfxTabPage
> xTabPage
= (*fnCreatePage
)(aCropDialog
.get_content_area(), &aCropDialog
, &aCropDlgAttr
);
651 sal_Int32 nPreferredDPI
= rView
.getSdrModelFromSdrView().getImagePreferredDPI();
652 xTabPage
->getAdditionalProperties().emplace("PreferredDPI", css::uno::Any(nPreferredDPI
));
653 xTabPage
->SetPageTitle(aCropStr
);
654 aCropDialog
.SetTabPage(std::move(xTabPage
));
656 if (aCropDialog
.run() == RET_OK
)
658 const SfxItemSet
* pOutAttr
= aCropDialog
.GetOutputItemSet();
662 aUndoStr
+= SvxResId( RID_SVXSTR_UNDO_GRAFCROP
);
664 // set crop attributes
665 if( SfxItemState::SET
<= pOutAttr
->GetItemState( SDRATTR_GRAFCROP
) )
667 const SdrGrafCropItem
& rNewCrop
= pOutAttr
->Get( SDRATTR_GRAFCROP
);
669 aLTSize
= o3tl::convert(Size(rNewCrop
.GetLeft(), rNewCrop
.GetTop()), o3tl::Length::twip
, o3tl::Length::mm100
);
670 aRBSize
= o3tl::convert(Size(rNewCrop
.GetRight(), rNewCrop
.GetBottom()), o3tl::Length::twip
, o3tl::Length::mm100
);
671 aSet
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(), aRBSize
.Width(), aRBSize
.Height() ) );
674 // set new logic rect
675 if( SfxItemState::SET
<= pOutAttr
->GetItemState( SID_ATTR_GRAF_FRMSIZE
) )
677 Point
aNewOrigin( pObj
->GetLogicRect().TopLeft() );
678 const Size
& rGrfSize
= pOutAttr
->Get( SID_ATTR_GRAF_FRMSIZE
).GetSize();
679 Size aNewGrfSize
= o3tl::convert(rGrfSize
, o3tl::Length::twip
, o3tl::Length::mm100
);
680 Size
aOldGrfSize( pObj
->GetLogicRect().GetSize() );
682 tools::Rectangle
aNewRect( aNewOrigin
, aNewGrfSize
);
683 Point
aOffset( (aNewGrfSize
.Width() - aOldGrfSize
.Width()) >> 1,
684 (aNewGrfSize
.Height() - aOldGrfSize
.Height()) >> 1 );
686 // #106181# rotate snap rect before setting it
687 const GeoStat
& aGeo
= pObj
->GetGeoStat();
689 if (aGeo
.m_nRotationAngle
|| aGeo
.m_nShearAngle
)
691 tools::Polygon
aPol(aNewRect
);
693 // also transform origin offset
694 if (aGeo
.m_nShearAngle
)
698 aGeo
.mfTanShearAngle
);
699 ShearPoint(aOffset
, Point(0,0), aGeo
.mfTanShearAngle
);
701 if (aGeo
.m_nRotationAngle
)
705 aGeo
.mfSinRotationAngle
,aGeo
.mfCosRotationAngle
);
706 RotatePoint(aOffset
, Point(0,0), aGeo
.mfSinRotationAngle
,aGeo
.mfCosRotationAngle
);
710 aPol
.Move( -aOffset
.X(), -aOffset
.Y() );
711 aNewRect
=aPol
.GetBoundRect();
715 aNewRect
.Move( -aOffset
.X(), -aOffset
.Y() );
719 rView
.SetMarkedObjRect( aNewRect
);
724 rView
.BegUndo( aUndoStr
);
725 rView
.AddUndo(rView
.GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj
));
727 pObj
->SetSnapRect( aNewRect
);
728 rView
.SetAttributes( aSet
);
738 rPool
.SetDefaultMetric( eOldMetric
);
744 case SID_COLOR_SETTINGS
:
746 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
747 aToolboxAccess
.toggleToolbox();
759 rView
.BegUndo( aUndoStr
);
761 rView
.SetAttributes( aSet
);
768 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet
& rSet
, SdrView
const & rView
)
770 SfxItemPool
& rPool
= rView
.GetModel().GetItemPool();
771 SfxItemSet
aAttrSet( rPool
);
772 SfxWhichIter
aIter( rSet
);
773 sal_uInt16 nWhich
= aIter
.FirstWhich();
774 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
775 bool bEnableColors
= true;
776 bool bEnableTransparency
= true;
777 bool bEnableCrop
= ( 1 == rMarkList
.GetMarkCount() );
779 for( size_t i
= 0, nCount
= rMarkList
.GetMarkCount(); i
< nCount
; ++i
)
781 SdrGrafObj
* pGrafObj
= dynamic_cast< SdrGrafObj
* >( rMarkList
.GetMark( i
)->GetMarkedSdrObj() );
784 ( pGrafObj
->GetGraphicType() == GraphicType::NONE
) ||
785 ( pGrafObj
->GetGraphicType() == GraphicType::Default
))
787 bEnableColors
= bEnableTransparency
= bEnableCrop
= false;
790 else if( bEnableTransparency
&& ( pGrafObj
->HasGDIMetaFile() || pGrafObj
->IsAnimated() ) )
792 bEnableTransparency
= false;
796 rView
.GetAttributes( aAttrSet
);
800 sal_uInt16 nSlotId
= SfxItemPool::IsWhich( nWhich
) ? rPool
.GetSlotId( nWhich
) : nWhich
;
804 case SID_ATTR_GRAF_MODE
:
806 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFMODE
) )
810 rSet
.Put( SfxUInt16Item( nSlotId
,
811 sal::static_int_cast
< sal_uInt16
>( aAttrSet
.Get(SDRATTR_GRAFMODE
).GetValue() ) ) );
815 rSet
.DisableItem( SID_ATTR_GRAF_MODE
);
821 case SID_ATTR_GRAF_RED
:
823 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFRED
) )
827 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFRED
).GetValue() ) );
831 rSet
.DisableItem( SID_ATTR_GRAF_RED
);
837 case SID_ATTR_GRAF_GREEN
:
839 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGREEN
) )
843 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFGREEN
).GetValue()) );
847 rSet
.DisableItem( SID_ATTR_GRAF_GREEN
);
853 case SID_ATTR_GRAF_BLUE
:
855 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFBLUE
) )
859 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFBLUE
).GetValue()) );
863 rSet
.DisableItem( SID_ATTR_GRAF_BLUE
);
869 case SID_ATTR_GRAF_LUMINANCE
:
871 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFLUMINANCE
) )
875 rSet
.Put( SfxInt16Item( nSlotId
, aAttrSet
.Get(SDRATTR_GRAFLUMINANCE
).GetValue()) );
879 rSet
.DisableItem( SID_ATTR_GRAF_LUMINANCE
);
885 case SID_ATTR_GRAF_CONTRAST
:
887 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFCONTRAST
) )
891 rSet
.Put( SfxInt16Item( nSlotId
,
892 aAttrSet
.Get(SDRATTR_GRAFCONTRAST
).GetValue()) );
896 rSet
.DisableItem( SID_ATTR_GRAF_CONTRAST
);
902 case SID_ATTR_GRAF_GAMMA
:
904 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGAMMA
) )
908 rSet
.Put( SfxUInt32Item( nSlotId
,
909 aAttrSet
.Get(SDRATTR_GRAFGAMMA
).GetValue() ) );
913 rSet
.DisableItem( SID_ATTR_GRAF_GAMMA
);
919 case SID_ATTR_GRAF_TRANSPARENCE
:
921 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFTRANSPARENCE
) )
923 if( bEnableTransparency
)
925 rSet
.Put( SfxUInt16Item( nSlotId
,
926 aAttrSet
.Get(SDRATTR_GRAFTRANSPARENCE
).GetValue() ) );
930 rSet
.DisableItem( SID_ATTR_GRAF_TRANSPARENCE
);
936 case SID_ATTR_GRAF_CROP
:
939 rSet
.DisableItem( nSlotId
);
943 case SID_COLOR_SETTINGS
:
945 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
946 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
954 nWhich
= aIter
.NextWhich();
958 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */