sdext: adapt xpdfwrapper to poppler 24.12
[LibreOffice.git] / svx / source / tbxctrls / grafctrl.cxx
blob70f6ca8d002a1817fc4ddb5d50a15334303a825b
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 <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
67 namespace {
69 class ImplGrafControl final : public InterimItemWindow
71 private:
72 OUString maCommand;
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);
79 void ImplModify();
81 public:
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)
90 Enable(bSensitive);
91 mxImage->set_sensitive(bSensitive);
92 mxField->set_sensitive(bSensitive);
98 IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton&, void)
100 ImplModify();
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
108 Any a;
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 );
119 if ( !a.hasValue() )
120 return;
122 INetURLObject aObj( maCommand );
124 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(aObj.GetURLPath(), a) };
126 SfxToolBoxControl::Dispatch(
127 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
128 maCommand,
129 aArgs );
132 void ImplGrafControl::Update( const SfxPoolItem* pItem )
134 if( pItem )
136 tools::Long nValue;
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();
142 else
143 nValue = static_cast<const SfxInt16Item*>( pItem )->GetValue();
145 mxField->set_value(nValue, FieldUnit::NONE);
147 else
148 mxField->set_text(OUString());
151 namespace {
153 struct CommandToRID
155 const char* pCommand;
156 OUString sResId;
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 }
175 OUString sRID;
177 sal_Int32 i( 0 );
178 while ( aImplCommandToResMap[ i ].pCommand )
180 if ( o3tl::equalsAscii( aCommand, aImplCommandToResMap[ i ].pCommand ))
182 sRID = aImplCommandToResMap[i].sResId;
183 break;
185 ++i;
188 return sRID;
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)
196 , maCommand(rCmd)
197 , mxFrame(rFrame)
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);
220 else
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()
241 disposeOnce();
244 void ImplGrafControl::dispose()
246 mxImage.reset();
247 mxField.reset();
248 InterimItemWindow::dispose();
251 namespace {
253 class ImplGrafModeControl final : public InterimItemWindow
255 private:
256 sal_uInt16 mnCurPos;
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();
266 public:
267 ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame );
268 virtual void dispose() override;
269 virtual ~ImplGrafModeControl() override;
271 void set_sensitive(bool bSensitive)
273 Enable(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)
289 , mnCurPos(0)
290 , mxFrame(rFrame)
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()
309 m_xWidget.reset();
310 InterimItemWindow::dispose();
313 ImplGrafModeControl::~ImplGrafModeControl()
315 disposeOnce();
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. */
326 ImplReleaseFocus();
328 SfxToolBoxControl::Dispatch(
329 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
330 u".uno:GrafMode"_ustr,
331 aArgs );
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);
341 ImplReleaseFocus();
342 bHandled = true;
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();
359 if( pShellWnd )
360 pShellWnd->GrabFocus();
364 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
366 if( pItem )
367 m_xWidget->set_active(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
368 else
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 ) );
376 rTbx.Invalidate();
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() );
393 else
395 pCtrl->set_sensitive(true);
397 if( eState == SfxItemState::DEFAULT )
398 pCtrl->Update( pState );
399 else
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);
480 else
482 pCtrl->set_sensitive(true);
484 if( eState == SfxItemState::DEFAULT )
485 pCtrl->Update( pState );
486 else
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 );
500 OUString aUndoStr;
501 const bool bUndo = rView.IsUndoEnabled();
503 if( bUndo )
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 ))
513 pItem = nullptr;
515 switch( nSlot )
517 case SID_ATTR_GRAF_RED:
519 if( pItem )
521 aSet.Put( SdrGrafRedItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
522 if( bUndo )
523 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFRED );
526 break;
528 case SID_ATTR_GRAF_GREEN:
530 if( pItem )
532 aSet.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
533 if( bUndo )
534 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGREEN );
537 break;
539 case SID_ATTR_GRAF_BLUE:
541 if( pItem )
543 aSet.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
544 if( bUndo )
545 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFBLUE );
548 break;
550 case SID_ATTR_GRAF_LUMINANCE:
552 if( pItem )
554 aSet.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
555 if( bUndo )
556 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE );
559 break;
561 case SID_ATTR_GRAF_CONTRAST:
563 if( pItem )
565 aSet.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
566 if( bUndo )
567 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST );
570 break;
572 case SID_ATTR_GRAF_GAMMA:
574 if( pItem )
576 aSet.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item*>(pItem)->GetValue() ));
577 if( bUndo )
578 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA );
581 break;
583 case SID_ATTR_GRAF_TRANSPARENCE:
585 if( pItem )
587 aSet.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
588 if( bUndo )
589 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY );
592 break;
594 case SID_ATTR_GRAF_MODE:
596 if( pItem )
598 aSet.Put( SdrGrafModeItem( static_cast<GraphicDrawMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()) ));
599 if( bUndo )
600 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFMODE );
603 break;
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 );
622 SfxItemSetFixed<
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>
627 aCropDlgAttr(rPool);
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,
645 &aCropDlgAttr);
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();
660 if( pOutAttr )
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)
696 ShearPoly(aPol,
697 aNewRect.TopLeft(),
698 aGeo.mfTanShearAngle);
699 ShearPoint(aOffset, Point(0,0), aGeo.mfTanShearAngle);
701 if (aGeo.m_nRotationAngle)
703 RotatePoly(aPol,
704 aNewRect.TopLeft(),
705 aGeo.mfSinRotationAngle,aGeo.mfCosRotationAngle);
706 RotatePoint(aOffset, Point(0,0), aGeo.mfSinRotationAngle,aGeo.mfCosRotationAngle);
709 // apply offset
710 aPol.Move( -aOffset.X(), -aOffset.Y() );
711 aNewRect=aPol.GetBoundRect();
713 else
715 aNewRect.Move( -aOffset.X(), -aOffset.Y() );
718 if( !aSet.Count() )
719 rView.SetMarkedObjRect( aNewRect );
720 else
722 if( bUndo )
724 rView.BegUndo( aUndoStr );
725 rView.AddUndo(rView.GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
727 pObj->SetSnapRect( aNewRect );
728 rView.SetAttributes( aSet );
730 if( bUndo )
731 rView.EndUndo();
732 aSet.ClearItem();
738 rPool.SetDefaultMetric( eOldMetric );
742 break;
744 case SID_COLOR_SETTINGS:
746 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
747 aToolboxAccess.toggleToolbox();
748 rReq.Done();
749 break;
752 default:
753 break;
756 if( aSet.Count() )
758 if( bUndo )
759 rView.BegUndo( aUndoStr );
761 rView.SetAttributes( aSet );
763 if( bUndo )
764 rView.EndUndo();
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() );
783 if( !pGrafObj ||
784 ( pGrafObj->GetGraphicType() == GraphicType::NONE ) ||
785 ( pGrafObj->GetGraphicType() == GraphicType::Default ))
787 bEnableColors = bEnableTransparency = bEnableCrop = false;
788 break;
790 else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
792 bEnableTransparency = false;
796 rView.GetAttributes( aAttrSet );
798 while( nWhich )
800 sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
802 switch( nSlotId )
804 case SID_ATTR_GRAF_MODE:
806 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
808 if( bEnableColors )
810 rSet.Put( SfxUInt16Item( nSlotId,
811 sal::static_int_cast< sal_uInt16 >( aAttrSet.Get(SDRATTR_GRAFMODE).GetValue() ) ) );
813 else
815 rSet.DisableItem( SID_ATTR_GRAF_MODE );
819 break;
821 case SID_ATTR_GRAF_RED:
823 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
825 if( bEnableColors )
827 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFRED).GetValue() ) );
829 else
831 rSet.DisableItem( SID_ATTR_GRAF_RED );
835 break;
837 case SID_ATTR_GRAF_GREEN:
839 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
841 if( bEnableColors )
843 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFGREEN).GetValue()) );
845 else
847 rSet.DisableItem( SID_ATTR_GRAF_GREEN );
851 break;
853 case SID_ATTR_GRAF_BLUE:
855 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
857 if( bEnableColors )
859 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFBLUE).GetValue()) );
861 else
863 rSet.DisableItem( SID_ATTR_GRAF_BLUE );
867 break;
869 case SID_ATTR_GRAF_LUMINANCE:
871 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
873 if( bEnableColors )
875 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFLUMINANCE).GetValue()) );
877 else
879 rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
883 break;
885 case SID_ATTR_GRAF_CONTRAST:
887 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
889 if( bEnableColors )
891 rSet.Put( SfxInt16Item( nSlotId,
892 aAttrSet.Get(SDRATTR_GRAFCONTRAST).GetValue()) );
894 else
896 rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
900 break;
902 case SID_ATTR_GRAF_GAMMA:
904 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
906 if( bEnableColors )
908 rSet.Put( SfxUInt32Item( nSlotId,
909 aAttrSet.Get(SDRATTR_GRAFGAMMA).GetValue() ) );
911 else
913 rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
917 break;
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() ) );
928 else
930 rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
934 break;
936 case SID_ATTR_GRAF_CROP:
938 if( !bEnableCrop )
939 rSet.DisableItem( nSlotId );
941 break;
943 case SID_COLOR_SETTINGS :
945 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
946 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
947 break;
950 default:
951 break;
954 nWhich = aIter.NextWhich();
958 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */