Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / grafctrl.cxx
blob56669429c7272c9413c769933030b9ecbb8a379b
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 <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
70 namespace {
72 class ImplGrafControl final : public InterimItemWindow
74 private:
75 OUString maCommand;
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);
82 void ImplModify();
84 public:
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)
93 Enable(bSensitive);
94 mxImage->set_sensitive(bSensitive);
95 mxField->set_sensitive(bSensitive);
101 IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton&, void)
103 ImplModify();
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
111 Any a;
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 );
122 if ( !a.hasValue() )
123 return;
125 INetURLObject aObj( maCommand );
127 Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue(aObj.GetURLPath(), a) };
129 SfxToolBoxControl::Dispatch(
130 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
131 maCommand,
132 aArgs );
135 void ImplGrafControl::Update( const SfxPoolItem* pItem )
137 if( pItem )
139 tools::Long nValue;
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();
145 else
146 nValue = static_cast<const SfxInt16Item*>( pItem )->GetValue();
148 mxField->set_value(nValue, FieldUnit::NONE);
150 else
151 mxField->set_text(OUString());
154 namespace {
156 struct CommandToRID
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 },
176 { nullptr, EMPTY }
179 OUString sRID;
181 sal_Int32 i( 0 );
182 while ( aImplCommandToResMap[ i ].pCommand )
184 if ( o3tl::equalsAscii( aCommand, aImplCommandToResMap[ i ].pCommand ))
186 sRID = aImplCommandToResMap[i].sResId;
187 break;
189 ++i;
192 return sRID;
195 ImplGrafControl::ImplGrafControl(
196 vcl::Window* pParent,
197 const OUString& rCmd,
198 const Reference< XFrame >& rFrame)
199 : InterimItemWindow(pParent, "svx/ui/grafctrlbox.ui", "GrafCtrlBox")
200 , maCommand(rCmd)
201 , mxFrame(rFrame)
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);
224 else
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()
245 disposeOnce();
248 void ImplGrafControl::dispose()
250 mxImage.reset();
251 mxField.reset();
252 InterimItemWindow::dispose();
255 namespace {
257 class ImplGrafModeControl final : public InterimItemWindow
259 private:
260 sal_uInt16 mnCurPos;
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();
270 public:
271 ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame );
272 virtual void dispose() override;
273 virtual ~ImplGrafModeControl() override;
275 void set_sensitive(bool bSensitive)
277 Enable(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")
293 , mnCurPos(0)
294 , mxFrame(rFrame)
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()
313 m_xWidget.reset();
314 InterimItemWindow::dispose();
317 ImplGrafModeControl::~ImplGrafModeControl()
319 disposeOnce();
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. */
330 ImplReleaseFocus();
332 SfxToolBoxControl::Dispatch(
333 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
334 ".uno:GrafMode",
335 aArgs );
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);
345 ImplReleaseFocus();
346 bHandled = true;
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();
363 if( pShellWnd )
364 pShellWnd->GrabFocus();
368 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
370 if( pItem )
371 m_xWidget->set_active(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
372 else
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 ) );
380 rTbx.Invalidate();
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() );
397 else
399 pCtrl->set_sensitive(true);
401 if( eState == SfxItemState::DEFAULT )
402 pCtrl->Update( pState );
403 else
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);
484 else
486 pCtrl->set_sensitive(true);
488 if( eState == SfxItemState::DEFAULT )
489 pCtrl->Update( pState );
490 else
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 );
504 OUString aUndoStr;
505 const bool bUndo = rView.IsUndoEnabled();
507 if( bUndo )
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 ))
517 pItem = nullptr;
519 switch( nSlot )
521 case SID_ATTR_GRAF_RED:
523 if( pItem )
525 aSet.Put( SdrGrafRedItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
526 if( bUndo )
527 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFRED );
530 break;
532 case SID_ATTR_GRAF_GREEN:
534 if( pItem )
536 aSet.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
537 if( bUndo )
538 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGREEN );
541 break;
543 case SID_ATTR_GRAF_BLUE:
545 if( pItem )
547 aSet.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
548 if( bUndo )
549 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFBLUE );
552 break;
554 case SID_ATTR_GRAF_LUMINANCE:
556 if( pItem )
558 aSet.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
559 if( bUndo )
560 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE );
563 break;
565 case SID_ATTR_GRAF_CONTRAST:
567 if( pItem )
569 aSet.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
570 if( bUndo )
571 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST );
574 break;
576 case SID_ATTR_GRAF_GAMMA:
578 if( pItem )
580 aSet.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item*>(pItem)->GetValue() ));
581 if( bUndo )
582 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA );
585 break;
587 case SID_ATTR_GRAF_TRANSPARENCE:
589 if( pItem )
591 aSet.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
592 if( bUndo )
593 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY );
596 break;
598 case SID_ATTR_GRAF_MODE:
600 if( pItem )
602 aSet.Put( SdrGrafModeItem( static_cast<GraphicDrawMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()) ));
603 if( bUndo )
604 aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFMODE );
607 break;
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 );
626 SfxItemSetFixed<
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>
631 aCropDlgAttr(rPool);
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,
648 &aCropDlgAttr);
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();
663 if( pOutAttr )
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)
699 ShearPoly(aPol,
700 aNewRect.TopLeft(),
701 aGeo.mfTanShearAngle);
702 ShearPoint(aOffset, Point(0,0), aGeo.mfTanShearAngle);
704 if (aGeo.nRotationAngle)
706 RotatePoly(aPol,
707 aNewRect.TopLeft(),
708 aGeo.mfSinRotationAngle,aGeo.mfCosRotationAngle);
709 RotatePoint(aOffset, Point(0,0), aGeo.mfSinRotationAngle,aGeo.mfCosRotationAngle);
712 // apply offset
713 aPol.Move( -aOffset.X(), -aOffset.Y() );
714 aNewRect=aPol.GetBoundRect();
716 else
718 aNewRect.Move( -aOffset.X(), -aOffset.Y() );
721 if( !aSet.Count() )
722 rView.SetMarkedObjRect( aNewRect );
723 else
725 if( bUndo )
727 rView.BegUndo( aUndoStr );
728 rView.AddUndo(rView.GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
730 pObj->SetSnapRect( aNewRect );
731 rView.SetAttributes( aSet );
733 if( bUndo )
734 rView.EndUndo();
735 aSet.ClearItem();
741 rPool.SetDefaultMetric( eOldMetric );
745 break;
747 case SID_COLOR_SETTINGS:
749 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
750 aToolboxAccess.toggleToolbox();
751 rReq.Done();
752 break;
755 default:
756 break;
759 if( aSet.Count() )
761 if( bUndo )
762 rView.BegUndo( aUndoStr );
764 rView.SetAttributes( aSet );
766 if( bUndo )
767 rView.EndUndo();
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() );
786 if( !pGrafObj ||
787 ( pGrafObj->GetGraphicType() == GraphicType::NONE ) ||
788 ( pGrafObj->GetGraphicType() == GraphicType::Default ))
790 bEnableColors = bEnableTransparency = bEnableCrop = false;
791 break;
793 else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
795 bEnableTransparency = false;
799 rView.GetAttributes( aAttrSet );
801 while( nWhich )
803 sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
805 switch( nSlotId )
807 case SID_ATTR_GRAF_MODE:
809 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
811 if( bEnableColors )
813 rSet.Put( SfxUInt16Item( nSlotId,
814 sal::static_int_cast< sal_uInt16 >( aAttrSet.Get(SDRATTR_GRAFMODE).GetValue() ) ) );
816 else
818 rSet.DisableItem( SID_ATTR_GRAF_MODE );
822 break;
824 case SID_ATTR_GRAF_RED:
826 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
828 if( bEnableColors )
830 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFRED).GetValue() ) );
832 else
834 rSet.DisableItem( SID_ATTR_GRAF_RED );
838 break;
840 case SID_ATTR_GRAF_GREEN:
842 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
844 if( bEnableColors )
846 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFGREEN).GetValue()) );
848 else
850 rSet.DisableItem( SID_ATTR_GRAF_GREEN );
854 break;
856 case SID_ATTR_GRAF_BLUE:
858 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
860 if( bEnableColors )
862 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFBLUE).GetValue()) );
864 else
866 rSet.DisableItem( SID_ATTR_GRAF_BLUE );
870 break;
872 case SID_ATTR_GRAF_LUMINANCE:
874 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
876 if( bEnableColors )
878 rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFLUMINANCE).GetValue()) );
880 else
882 rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
886 break;
888 case SID_ATTR_GRAF_CONTRAST:
890 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
892 if( bEnableColors )
894 rSet.Put( SfxInt16Item( nSlotId,
895 aAttrSet.Get(SDRATTR_GRAFCONTRAST).GetValue()) );
897 else
899 rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
903 break;
905 case SID_ATTR_GRAF_GAMMA:
907 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
909 if( bEnableColors )
911 rSet.Put( SfxUInt32Item( nSlotId,
912 aAttrSet.Get(SDRATTR_GRAFGAMMA).GetValue() ) );
914 else
916 rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
920 break;
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() ) );
931 else
933 rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
937 break;
939 case SID_ATTR_GRAF_CROP:
941 if( !bEnableCrop )
942 rSet.DisableItem( nSlotId );
944 break;
946 case SID_COLOR_SETTINGS :
948 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
949 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
950 break;
953 default:
954 break;
957 nWhich = aIter.NextWhich();
961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */