LibreOffice Module svx (master)  1
grafctrl.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <vcl/toolbox.hxx>
21 #include <vcl/idle.hxx>
22 #include <svl/intitem.hxx>
23 #include <svl/itempool.hxx>
24 #include <svl/eitem.hxx>
25 #include <svl/whiter.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/basedlgs.hxx>
30 #include <sfx2/sfxdlg.hxx>
31 #include <tools/urlobj.hxx>
32 
33 #include <svx/dialogs.hrc>
34 #include <svx/svxids.hrc>
35 #include <svx/strings.hrc>
36 #include <editeng/brushitem.hxx>
37 #include <editeng/sizeitem.hxx>
38 #include <svx/sdgcpitm.hxx>
39 
40 #include <svx/dialmgr.hxx>
41 #include <svx/svdview.hxx>
42 #include <svx/svdmodel.hxx>
43 #include <svx/svdograf.hxx>
44 #include <svx/svdundo.hxx>
45 #include <svx/svdtrans.hxx>
46 #include <svx/grafctrl.hxx>
47 #include <svx/tbxcolor.hxx>
48 #include <sdgcoitm.hxx>
49 #include <svx/sdggaitm.hxx>
50 #include <svx/sdgluitm.hxx>
51 #include <svx/sdgmoitm.hxx>
52 #include <sdgtritm.hxx>
53 #include <bitmaps.hlst>
54 
55 #include <com/sun/star/frame/XDispatchProvider.hpp>
56 
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::frame;
59 using namespace ::com::sun::star::util;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 
63 constexpr OUStringLiteral TOOLBOX_NAME = u"colorbar";
64 #define RID_SVXSTR_UNDO_GRAFCROP RID_SVXSTR_GRAFCROP
65 
66 namespace {
67 
68 class ImplGrafControl final : public InterimItemWindow
69 {
70 private:
71  Idle maIdle;
72  OUString maCommand;
73  Reference<XFrame> mxFrame;
74  std::unique_ptr<weld::Image> mxImage;
75  std::unique_ptr<weld::MetricSpinButton> mxField;
76 
77  DECL_LINK(ValueChangedHdl, weld::MetricSpinButton&, void);
78  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
79  DECL_LINK(ImplModifyHdl, Timer*, void);
80 
81 public:
82  ImplGrafControl( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame );
83  virtual ~ImplGrafControl() override;
84  virtual void dispose() override;
85 
86  void Update( const SfxPoolItem* pItem );
87  void set_field_text(const OUString& rStr) { mxField->set_text(rStr); }
88  void set_sensitive(bool bSensitive)
89  {
90  Enable(bSensitive);
91  mxImage->set_sensitive(bSensitive);
92  mxField->set_sensitive(bSensitive);
93  }
94 };
95 
96 }
97 
98 IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton&, void)
99 {
100  maIdle.Start();
101 }
102 
103 IMPL_LINK_NOARG(ImplGrafControl, ImplModifyHdl, Timer*, void)
104 {
105  const sal_Int64 nVal = mxField->get_value(FieldUnit::NONE);
106 
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 );
118 
119  if ( !a.hasValue() )
120  return;
121 
122  INetURLObject aObj( maCommand );
123 
124  Sequence< PropertyValue > aArgs( 1 );
125  aArgs[0].Name = aObj.GetURLPath();
126  aArgs[0].Value = a;
127 
129  Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
130  maCommand,
131  aArgs );
132 }
133 
134 void ImplGrafControl::Update( const SfxPoolItem* pItem )
135 {
136  if( pItem )
137  {
139 
140  if ( maCommand == ".uno:GrafTransparence" )
141  nValue = static_cast<const SfxUInt16Item*>( pItem )->GetValue();
142  else if ( maCommand == ".uno:GrafGamma" )
143  nValue = static_cast<const SfxUInt32Item*>( pItem )->GetValue();
144  else
145  nValue = static_cast<const SfxInt16Item*>( pItem )->GetValue();
146 
147  mxField->set_value(nValue, FieldUnit::NONE);
148  }
149  else
150  mxField->set_text(OUString());
151 }
152 
153 namespace {
154 
155 struct CommandToRID
156 {
157  const char* pCommand;
158  const char* sResId;
159 };
160 
161 }
162 
163 static OUString ImplGetRID( const OUString& aCommand )
164 {
165  static const CommandToRID aImplCommandToResMap[] =
166  {
167  { ".uno:GrafRed", RID_SVXBMP_GRAF_RED },
168  { ".uno:GrafGreen", RID_SVXBMP_GRAF_GREEN },
169  { ".uno:GrafBlue", RID_SVXBMP_GRAF_BLUE },
170  { ".uno:GrafLuminance", RID_SVXBMP_GRAF_LUMINANCE },
171  { ".uno:GrafContrast", RID_SVXBMP_GRAF_CONTRAST },
172  { ".uno:GrafGamma", RID_SVXBMP_GRAF_GAMMA },
173  { ".uno:GrafTransparence", RID_SVXBMP_GRAF_TRANSPARENCE },
174  { nullptr, "" }
175  };
176 
177  OUString sRID;
178 
179  sal_Int32 i( 0 );
180  while ( aImplCommandToResMap[ i ].pCommand )
181  {
182  if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
183  {
184  sRID = OUString::createFromAscii(aImplCommandToResMap[i].sResId);
185  break;
186  }
187  ++i;
188  }
189 
190  return sRID;
191 }
192 
193 ImplGrafControl::ImplGrafControl(
194  vcl::Window* pParent,
195  const OUString& rCmd,
196  const Reference< XFrame >& rFrame)
197  : InterimItemWindow(pParent, "svx/ui/grafctrlbox.ui", "GrafCtrlBox")
198  , maIdle("svx ImplGrafControl maIdle")
199  , maCommand(rCmd)
200  , mxFrame(rFrame)
201  , mxImage(m_xBuilder->weld_image("image"))
202  , mxField(m_xBuilder->weld_metric_spin_button("spinfield", FieldUnit::NONE))
203 {
204  InitControlBase(&mxField->get_widget());
205 
206  OUString sResId(ImplGetRID(rCmd));
207  mxImage->set_from_icon_name(sResId);
208  mxImage->set_toolbar_background();
209 
210  SetBackground( Wallpaper() ); // transparent background
211 
212  mxField->set_help_id(OUStringToOString(rCmd, RTL_TEXTENCODING_UTF8));
213  mxField->get_widget().connect_key_press(LINK(this, ImplGrafControl, KeyInputHdl));
214  mxField->connect_value_changed(LINK(this, ImplGrafControl, ValueChangedHdl));
215 
216  if (maCommand == ".uno:GrafGamma")
217  {
218  mxField->set_digits(2);
219 
220  mxField->set_range(10, 1000, FieldUnit::NONE);
221  mxField->set_increments(10, 100, FieldUnit::NONE);
222  }
223  else
224  {
225  const tools::Long nMinVal = maCommand == ".uno:GrafTransparence" ? 0 : -100;
226 
227  mxField->set_unit(FieldUnit::PERCENT);
228  mxField->set_digits(0);
229 
230  mxField->set_range(nMinVal, 100, FieldUnit::PERCENT);
231  mxField->set_increments(1, 10, FieldUnit::PERCENT);
232  }
233 
234  maIdle.SetInvokeHandler( LINK( this, ImplGrafControl, ImplModifyHdl ) );
235 
236  SetSizePixel(m_xContainer->get_preferred_size());
237 }
238 
239 IMPL_LINK(ImplGrafControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
240 {
241  return ChildKeyInput(rKEvt);
242 }
243 
244 ImplGrafControl::~ImplGrafControl()
245 {
246  disposeOnce();
247 }
248 
249 void ImplGrafControl::dispose()
250 {
251  mxImage.reset();
252  mxField.reset();
254 }
255 
256 namespace {
257 
258 class ImplGrafModeControl final : public InterimItemWindow
259 {
260 private:
261  sal_uInt16 mnCurPos;
262  Reference< XFrame > mxFrame;
263  std::unique_ptr<weld::ComboBox> m_xWidget;
264 
265  DECL_LINK(SelectHdl, weld::ComboBox&, void);
266  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
267  DECL_LINK(FocusInHdl, weld::Widget&, void);
268 
269  static void ImplReleaseFocus();
270 
271 public:
272  ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame );
273  virtual void dispose() override;
274  virtual ~ImplGrafModeControl() override;
275 
276  void set_sensitive(bool bSensitive)
277  {
278  Enable(bSensitive);
279  m_xWidget->set_sensitive(true);
280  }
281 
282  void set_active(int nActive)
283  {
284  m_xWidget->set_active(nActive);
285  }
286 
287  void Update( const SfxPoolItem* pItem );
288 };
289 
290 }
291 
292 ImplGrafModeControl::ImplGrafModeControl(vcl::Window* pParent, const Reference<XFrame>& rFrame)
293  : InterimItemWindow(pParent, "svx/ui/grafmodebox.ui", "GrafModeBox")
294  , mnCurPos(0)
295  , mxFrame(rFrame)
296  , m_xWidget(m_xBuilder->weld_combo_box("grafmode"))
297 {
298  InitControlBase(m_xWidget.get());
299 
300  m_xWidget->append_text( SvxResId( RID_SVXSTR_GRAFMODE_STANDARD ) );
301  m_xWidget->append_text( SvxResId( RID_SVXSTR_GRAFMODE_GREYS ) );
302  m_xWidget->append_text( SvxResId( RID_SVXSTR_GRAFMODE_MONO ) );
303  m_xWidget->append_text( SvxResId( RID_SVXSTR_GRAFMODE_WATERMARK ) );
304 
305  m_xWidget->connect_changed(LINK(this, ImplGrafModeControl, SelectHdl));
306  m_xWidget->connect_key_press(LINK(this, ImplGrafModeControl, KeyInputHdl));
307  m_xWidget->connect_focus_in(LINK(this, ImplGrafModeControl, FocusInHdl));
308 
309  SetSizePixel(m_xWidget->get_preferred_size());
310 }
311 
312 void ImplGrafModeControl::dispose()
313 {
314  m_xWidget.reset();
316 }
317 
318 ImplGrafModeControl::~ImplGrafModeControl()
319 {
320  disposeOnce();
321 }
322 
323 IMPL_LINK(ImplGrafModeControl, SelectHdl, weld::ComboBox&, rBox, void)
324 {
325  Sequence< PropertyValue > aArgs( 1 );
326  aArgs[0].Name = "GrafMode";
327  aArgs[0].Value <<= sal_Int16(rBox.get_active());
328 
329  /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
330  This instance may be deleted in the meantime (i.e. when a dialog is opened
331  while in Dispatch()), accessing members will crash in this case. */
332  ImplReleaseFocus();
333 
335  Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
336  ".uno:GrafMode",
337  aArgs );
338 }
339 
340 IMPL_LINK(ImplGrafModeControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
341 {
342  bool bHandled(false);
343 
344  if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
345  {
346  m_xWidget->set_active(mnCurPos);
347  ImplReleaseFocus();
348  bHandled = true;
349  }
350 
351  return bHandled || ChildKeyInput(rKEvt);
352 }
353 
354 IMPL_LINK_NOARG(ImplGrafModeControl, FocusInHdl, weld::Widget&, void)
355 {
356  mnCurPos = m_xWidget->get_active();
357 }
358 
359 void ImplGrafModeControl::ImplReleaseFocus()
360 {
361  if( SfxViewShell::Current() )
362  {
363  vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
364 
365  if( pShellWnd )
366  pShellWnd->GrabFocus();
367  }
368 }
369 
370 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
371 {
372  if( pItem )
373  m_xWidget->set_active(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
374  else
375  m_xWidget->set_active(-1);
376 }
377 
379  SfxToolBoxControl( nSlotId, nId, rTbx )
380 {
381  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
382  rTbx.Invalidate();
383 }
384 
386 {
387 }
388 
390 {
391  ImplGrafControl* pCtrl = static_cast<ImplGrafControl*>( GetToolBox().GetItemWindow( GetId() ) );
392  DBG_ASSERT( pCtrl, "Control not found" );
393 
394  if( eState == SfxItemState::DISABLED )
395  {
396  pCtrl->set_sensitive(false);
397  pCtrl->set_field_text( OUString() );
398  }
399  else
400  {
401  pCtrl->set_sensitive(true);
402 
403  if( eState == SfxItemState::DEFAULT )
404  pCtrl->Update( pState );
405  else
406  pCtrl->Update( nullptr );
407  }
408 }
409 
411 {
412  return VclPtr<ImplGrafControl>::Create( pParent, m_aCommandURL, m_xFrame ).get();
413 }
414 
416 
418  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
419 {
420 }
421 
423 
425  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
426 {
427 }
428 
430 
432  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
433 {
434 }
435 
437 
439  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
440 {
441 }
442 
444 
446  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
447 {
448 }
449 
451 
453  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
454 {
455 }
456 
458 
460  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
461 {
462 }
463 
465 
467  SfxToolBoxControl( nSlotId, nId, rTbx )
468 {
469 }
470 
472 {
473 }
474 
476 
477 {
478  ImplGrafModeControl* pCtrl = static_cast<ImplGrafModeControl*>( GetToolBox().GetItemWindow( GetId() ) );
479  DBG_ASSERT( pCtrl, "Control not found" );
480 
481  if( eState == SfxItemState::DISABLED )
482  {
483  pCtrl->set_sensitive(false);
484  pCtrl->set_active(-1);
485  }
486  else
487  {
488  pCtrl->set_sensitive(true);
489 
490  if( eState == SfxItemState::DEFAULT )
491  pCtrl->Update( pState );
492  else
493  pCtrl->Update( nullptr );
494  }
495 }
496 
498 {
499  return VclPtr<ImplGrafModeControl>::Create( pParent, m_xFrame ).get();
500 }
501 
503 {
504  SfxItemPool& rPool = rView.GetModel()->GetItemPool();
506  OUString aUndoStr;
507  const bool bUndo = rView.IsUndoEnabled();
508 
509  if( bUndo )
510  {
511  aUndoStr = rView.GetDescriptionOfMarkedObjects() + " ";
512  }
513 
514  const SfxItemSet* pArgs = rReq.GetArgs();
515  const SfxPoolItem* pItem;
516  sal_uInt16 nSlot = rReq.GetSlot();
517 
518  if( !pArgs || SfxItemState::SET != pArgs->GetItemState( nSlot, false, &pItem ))
519  pItem = nullptr;
520 
521  switch( nSlot )
522  {
523  case SID_ATTR_GRAF_RED:
524  {
525  if( pItem )
526  {
527  aSet.Put( SdrGrafRedItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
528  if( bUndo )
529  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFRED );
530  }
531  }
532  break;
533 
534  case SID_ATTR_GRAF_GREEN:
535  {
536  if( pItem )
537  {
538  aSet.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
539  if( bUndo )
540  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGREEN );
541  }
542  }
543  break;
544 
545  case SID_ATTR_GRAF_BLUE:
546  {
547  if( pItem )
548  {
549  aSet.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
550  if( bUndo )
551  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFBLUE );
552  }
553  }
554  break;
555 
556  case SID_ATTR_GRAF_LUMINANCE:
557  {
558  if( pItem )
559  {
560  aSet.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
561  if( bUndo )
562  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE );
563  }
564  }
565  break;
566 
567  case SID_ATTR_GRAF_CONTRAST:
568  {
569  if( pItem )
570  {
571  aSet.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
572  if( bUndo )
573  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST );
574  }
575  }
576  break;
577 
578  case SID_ATTR_GRAF_GAMMA:
579  {
580  if( pItem )
581  {
582  aSet.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item*>(pItem)->GetValue() ));
583  if( bUndo )
584  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA );
585  }
586  }
587  break;
588 
589  case SID_ATTR_GRAF_TRANSPARENCE:
590  {
591  if( pItem )
592  {
593  aSet.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
594  if( bUndo )
595  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY );
596  }
597  }
598  break;
599 
600  case SID_ATTR_GRAF_MODE:
601  {
602  if( pItem )
603  {
604  aSet.Put( SdrGrafModeItem( static_cast<GraphicDrawMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()) ));
605  if( bUndo )
606  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFMODE );
607  }
608  }
609  break;
610 
611  case SID_ATTR_GRAF_CROP:
612  {
613  const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
614 
615  if( 0 < rMarkList.GetMarkCount() )
616  {
617  SdrGrafObj* pObj = static_cast<SdrGrafObj*>( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
618 
619  if( ( pObj->GetGraphicType() != GraphicType::NONE ) &&
620  ( pObj->GetGraphicType() != GraphicType::Default ) )
621  {
623  const MapUnit eOldMetric = rPool.GetMetric( 0 );
624 
625  aGrfAttr.Put(pObj->GetMergedItemSet());
626  rPool.SetDefaultMetric( MapUnit::MapTwip );
627 
630  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
631  SID_ATTR_GRAF_CROP, SID_ATTR_GRAF_FRMSIZE,
632  SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC>
633  aCropDlgAttr(rPool);
634 
635  aCropDlgAttr.Put( SvxBrushItem( pObj->GetGraphic(), GPOS_MM, SID_ATTR_GRAF_GRAPHIC ) );
636  aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE,
638  aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE,
640 
641  const SdrGrafCropItem& rCrop = aGrfAttr.Get( SDRATTR_GRAFCROP );
642  Size aLTSize = o3tl::convert(Size(rCrop.GetLeft(), rCrop.GetTop()), o3tl::Length::mm100, o3tl::Length::twip);
643  Size aRBSize = o3tl::convert(Size(rCrop.GetRight(), rCrop.GetBottom()), o3tl::Length::mm100, o3tl::Length::twip);
644 
645  aCropDlgAttr.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(),
646  aRBSize.Width(), aRBSize.Height() ) );
647 
648  vcl::Window* pParent(SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : nullptr);
649  SfxSingleTabDialogController aCropDialog(pParent ? pParent->GetFrameWeld() : nullptr,
650  &aCropDlgAttr);
651  const OUString aCropStr(SvxResId(RID_SVXSTR_GRAFCROP));
652 
654  ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP );
655  std::unique_ptr<SfxTabPage> xTabPage = (*fnCreatePage)(aCropDialog.get_content_area(), &aCropDialog, &aCropDlgAttr);
656  xTabPage->SetPageTitle(aCropStr);
657  aCropDialog.SetTabPage(std::move(xTabPage));
658 
659  if (aCropDialog.run() == RET_OK)
660  {
661  const SfxItemSet* pOutAttr = aCropDialog.GetOutputItemSet();
662 
663  if( pOutAttr )
664  {
665  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCROP );
666 
667  // set crop attributes
668  if( SfxItemState::SET <= pOutAttr->GetItemState( SDRATTR_GRAFCROP ) )
669  {
670  const SdrGrafCropItem& rNewCrop = pOutAttr->Get( SDRATTR_GRAFCROP );
671 
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() ) );
675  }
676 
677  // set new logic rect
678  if( SfxItemState::SET <= pOutAttr->GetItemState( SID_ATTR_GRAF_FRMSIZE ) )
679  {
680  Point aNewOrigin( pObj->GetLogicRect().TopLeft() );
681  const Size& rGrfSize = static_cast<const SvxSizeItem&>( 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() );
684 
685  tools::Rectangle aNewRect( aNewOrigin, aNewGrfSize );
686  Point aOffset( (aNewGrfSize.Width() - aOldGrfSize.Width()) >> 1,
687  (aNewGrfSize.Height() - aOldGrfSize.Height()) >> 1 );
688 
689  // #106181# rotate snap rect before setting it
690  const GeoStat& aGeo = pObj->GetGeoStat();
691 
692  if (aGeo.nRotationAngle || aGeo.nShearAngle)
693  {
694  tools::Polygon aPol(aNewRect);
695 
696  // also transform origin offset
697  if (aGeo.nShearAngle)
698  {
699  ShearPoly(aPol,
700  aNewRect.TopLeft(),
701  aGeo.mfTanShearAngle);
702  ShearPoint(aOffset, Point(0,0), aGeo.mfTanShearAngle);
703  }
704  if (aGeo.nRotationAngle)
705  {
706  RotatePoly(aPol,
707  aNewRect.TopLeft(),
709  RotatePoint(aOffset, Point(0,0), aGeo.mfSinRotationAngle,aGeo.mfCosRotationAngle);
710  }
711 
712  // apply offset
713  aPol.Move( -aOffset.X(), -aOffset.Y() );
714  aNewRect=aPol.GetBoundRect();
715  }
716  else
717  {
718  aNewRect.Move( -aOffset.X(), -aOffset.Y() );
719  }
720 
721  if( !aSet.Count() )
722  rView.SetMarkedObjRect( aNewRect );
723  else
724  {
725  if( bUndo )
726  {
727  rView.BegUndo( aUndoStr );
728  rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
729  }
730  pObj->SetSnapRect( aNewRect );
731  rView.SetAttributes( aSet );
732 
733  if( bUndo )
734  rView.EndUndo();
735  aSet.ClearItem();
736  }
737  }
738  }
739  }
740 
741  rPool.SetDefaultMetric( eOldMetric );
742  }
743  }
744  }
745  break;
746 
747  case SID_COLOR_SETTINGS:
748  {
749  svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
750  aToolboxAccess.toggleToolbox();
751  rReq.Done();
752  break;
753  }
754 
755  default:
756  break;
757  }
758 
759  if( aSet.Count() )
760  {
761  if( bUndo )
762  rView.BegUndo( aUndoStr );
763 
764  rView.SetAttributes( aSet );
765 
766  if( bUndo )
767  rView.EndUndo();
768  }
769 }
770 
772 {
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() );
781 
782  for( size_t i = 0, nCount = rMarkList.GetMarkCount(); i < nCount; ++i )
783  {
784  SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( i )->GetMarkedSdrObj() );
785 
786  if( !pGrafObj ||
787  ( pGrafObj->GetGraphicType() == GraphicType::NONE ) ||
788  ( pGrafObj->GetGraphicType() == GraphicType::Default ))
789  {
790  bEnableColors = bEnableTransparency = bEnableCrop = false;
791  break;
792  }
793  else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
794  {
795  bEnableTransparency = false;
796  }
797  }
798 
799  rView.GetAttributes( aAttrSet );
800 
801  while( nWhich )
802  {
803  sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
804 
805  switch( nSlotId )
806  {
807  case SID_ATTR_GRAF_MODE:
808  {
809  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
810  {
811  if( bEnableColors )
812  {
813  rSet.Put( SfxUInt16Item( nSlotId,
814  sal::static_int_cast< sal_uInt16 >( aAttrSet.Get(SDRATTR_GRAFMODE).GetValue() ) ) );
815  }
816  else
817  {
818  rSet.DisableItem( SID_ATTR_GRAF_MODE );
819  }
820  }
821  }
822  break;
823 
824  case SID_ATTR_GRAF_RED:
825  {
826  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
827  {
828  if( bEnableColors )
829  {
830  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFRED).GetValue() ) );
831  }
832  else
833  {
834  rSet.DisableItem( SID_ATTR_GRAF_RED );
835  }
836  }
837  }
838  break;
839 
840  case SID_ATTR_GRAF_GREEN:
841  {
842  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
843  {
844  if( bEnableColors )
845  {
846  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFGREEN).GetValue()) );
847  }
848  else
849  {
850  rSet.DisableItem( SID_ATTR_GRAF_GREEN );
851  }
852  }
853  }
854  break;
855 
856  case SID_ATTR_GRAF_BLUE:
857  {
858  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
859  {
860  if( bEnableColors )
861  {
862  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFBLUE).GetValue()) );
863  }
864  else
865  {
866  rSet.DisableItem( SID_ATTR_GRAF_BLUE );
867  }
868  }
869  }
870  break;
871 
872  case SID_ATTR_GRAF_LUMINANCE:
873  {
874  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
875  {
876  if( bEnableColors )
877  {
878  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFLUMINANCE).GetValue()) );
879  }
880  else
881  {
882  rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
883  }
884  }
885  }
886  break;
887 
888  case SID_ATTR_GRAF_CONTRAST:
889  {
890  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
891  {
892  if( bEnableColors )
893  {
894  rSet.Put( SfxInt16Item( nSlotId,
895  aAttrSet.Get(SDRATTR_GRAFCONTRAST).GetValue()) );
896  }
897  else
898  {
899  rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
900  }
901  }
902  }
903  break;
904 
905  case SID_ATTR_GRAF_GAMMA:
906  {
907  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
908  {
909  if( bEnableColors )
910  {
911  rSet.Put( SfxUInt32Item( nSlotId,
912  aAttrSet.Get(SDRATTR_GRAFGAMMA).GetValue() ) );
913  }
914  else
915  {
916  rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
917  }
918  }
919  }
920  break;
921 
922  case SID_ATTR_GRAF_TRANSPARENCE:
923  {
924  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFTRANSPARENCE ) )
925  {
926  if( bEnableTransparency )
927  {
928  rSet.Put( SfxUInt16Item( nSlotId,
929  aAttrSet.Get(SDRATTR_GRAFTRANSPARENCE).GetValue() ) );
930  }
931  else
932  {
933  rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
934  }
935  }
936  }
937  break;
938 
939  case SID_ATTR_GRAF_CROP:
940  {
941  if( !bEnableCrop )
942  rSet.DisableItem( nSlotId );
943  }
944  break;
945 
946  case SID_COLOR_SETTINGS :
947  {
948  svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
949  rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
950  break;
951  }
952 
953  default:
954  break;
955  }
956 
957  nWhich = aIter.NextWhich();
958  }
959 }
960 
961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxGrafLuminanceToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:438
constexpr TypedWhichId< SdrGrafGamma100Item > SDRATTR_GRAFGAMMA(SDRATTR_GRAF_FIRST+5)
SvxGrafBlueToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:431
FieldUnit
size_t GetMarkCount() const
Definition: svdmark.hxx:178
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:122
static SfxAbstractDialogFactory * Create()
ToolBoxItemBits GetItemBits(ToolBoxItemId nItemId) const
vcl::Window * GetItemWindow(ToolBoxItemId nItemId) const
SvxGrafRedToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:417
std::string GetValue
ToolBox & GetToolBox() const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1064
constexpr OUStringLiteral TOOLBOX_NAME
Definition: grafctrl.cxx:63
long Long
void toggleToolbox() const
toggles the toolbox
Definition: tbxcolor.cxx:59
SvxGrafContrastToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:445
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
double mfSinRotationAngle
Definition: svdtrans.hxx:219
css::uno::Reference< css::lang::XComponent > m_xFrame
void BegUndo()
Definition: svdedtv.hxx:178
sal_uInt16 FirstWhich()
constexpr TypedWhichId< SdrGrafRedItem > SDRATTR_GRAFRED(SDRATTR_GRAF_FIRST+0)
bool isToolboxVisible() const
determines whether the toolbox is currently visible
Definition: tbxcolor.cxx:86
void RotatePoly(tools::Polygon &rPoly, const Point &rRef, double sn, double cs)
Definition: svdtrans.cxx:81
void Move(tools::Long nHorzMove, tools::Long nVertMove)
void Done(bool bRemove=false)
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:230
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: grafctrl.cxx:410
const SfxItemSet * GetArgs() const
GraphicType GetGraphicType() const
Definition: svdograf.cxx:404
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: grafctrl.cxx:389
sal_uInt16 NextWhich()
NONE
void ShearPoly(tools::Polygon &rPoly, const Point &rRef, double tn)
Definition: svdtrans.cxx:147
constexpr tools::Long Width() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
weld::Window * GetFrameWeld() const
Reference< XNameAccess > m_xContainer
SvxGrafModeToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:466
void Enable(bool bEnable=true, bool bChild=true)
IMPL_LINK(ImplGrafControl, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: grafctrl.cxx:239
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
static void GetGrafAttrState(SfxItemSet &rSet, SdrView const &rView)
Definition: grafctrl.cxx:771
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:214
void SetItemBits(ToolBoxItemId nItemId, ToolBoxItemBits nBits)
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
static SfxViewShell * Current()
const GeoStat & GetGeoStat() const
Definition: svdotext.hxx:392
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
double mfTanShearAngle
Definition: svdtrans.hxx:218
void EndUndo()
Definition: svdedtv.cxx:303
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
constexpr TypedWhichId< SdrGrafTransparenceItem > SDRATTR_GRAFTRANSPARENCE(SDRATTR_GRAF_FIRST+6)
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:182
bool IsAnimated() const
Definition: svdograf.cxx:444
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
constexpr TypedWhichId< SdrGrafLuminanceItem > SDRATTR_GRAFLUMINANCE(SDRATTR_GRAF_FIRST+3)
int i
uno_Any a
DECL_LINK(DoLayout, Timer *, void)
const Graphic & GetGraphic() const
Definition: svdograf.cxx:383
OUString const & GetDescriptionOfMarkedObjects() const
Definition: svdmrkv.hxx:261
constexpr TypedWhichId< SdrGrafBlueItem > SDRATTR_GRAFBLUE(SDRATTR_GRAF_FIRST+2)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
const SdrMarkList & GetMarkedObjectList() const
Definition: svdmrkv.hxx:252
sal_uInt16 Count() const
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
Definition: svdview.hxx:192
float u
constexpr TypedWhichId< SdrGrafModeItem > SDRATTR_GRAFMODE(SDRATTR_GRAF_FIRST+8)
GPOS_MM
SvxGrafTransparenceToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:459
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: grafctrl.cxx:475
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:67
void GrabFocus()
SvxGrafGreenToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:424
constexpr TypedWhichId< SdrGrafCropItem > SDRATTR_GRAFCROP(SDRATTR_GRAF_FIRST+9)
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1850
SvxGrafToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:378
constexpr Point TopLeft() const
virtual ~SvxGrafModeToolBoxControl() override
Definition: grafctrl.cxx:471
virtual std::unique_ptr< SdrUndoAction > CreateUndoGeoObject(SdrObject &rObject)
Definition: svdundo.cxx:1631
#define RID_SVXSTR_UNDO_GRAFCROP
Definition: grafctrl.cxx:64
constexpr TypedWhichId< SdrGrafGreenItem > SDRATTR_GRAFGREEN(SDRATTR_GRAF_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:114
constexpr Size GetSize() const
virtual ~SvxGrafToolBoxControl() override
Definition: grafctrl.cxx:385
void SetDefaultMetric(MapUnit eNewMetric)
SFX_IMPL_TOOLBOX_CONTROL(SvxGrafRedToolBoxControl, SfxInt16Item)
SfxItemState
void DisableItem(sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr tools::Long Height() const
constexpr sal_uInt16 KEY_ESCAPE
static void ExecuteGrafAttr(SfxRequest &rReq, SdrView &rView)
Definition: grafctrl.cxx:502
virtual void dispose() override
Degree100 nRotationAngle
Definition: svdtrans.hxx:216
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1978
ToolBoxItemId GetId() const
void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
Definition: svdview.cxx:249
bool HasGDIMetaFile() const
Definition: svdograf.cxx:856
RET_OK
double mfCosRotationAngle
Definition: svdtrans.hxx:220
static VclPtr< reference_type > Create(Arg &&...arg)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: grafctrl.cxx:497
vcl::Window * GetWindow() const
IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton &, void)
Definition: grafctrl.cxx:98
virtual void SetSnapRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1691
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
MapUnit
constexpr TypedWhichId< SdrGrafContrastItem > SDRATTR_GRAFCONTRAST(SDRATTR_GRAF_FIRST+4)
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:311
tools::Rectangle GetBoundRect() const
SvxGrafGammaToolBoxControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: grafctrl.cxx:452
std::unique_ptr< weld::Image > m_xWidget
void SetMarkedObjRect(const tools::Rectangle &rRect)
Definition: svdedtv1.cxx:77
SdrModel * GetModel() const
Definition: svdpntv.hxx:260
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
Degree100 nShearAngle
Definition: svdtrans.hxx:217
static OUString ImplGetRID(const OUString &aCommand)
Definition: grafctrl.cxx:163
static bool IsWhich(sal_uInt16 nId)
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
virtual const tools::Rectangle & GetLogicRect() const override
Definition: svdotxtr.cxx:69