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 #define TOOLBOX_NAME "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  {
121  INetURLObject aObj( maCommand );
122 
123  Sequence< PropertyValue > aArgs( 1 );
124  aArgs[0].Name = aObj.GetURLPath();
125  aArgs[0].Value = a;
126 
128  Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
129  maCommand,
130  aArgs );
131  }
132 }
133 
134 void ImplGrafControl::Update( const SfxPoolItem* pItem )
135 {
136  if( pItem )
137  {
138  long nValue;
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  , maCommand(rCmd)
199  , mxFrame(rFrame)
200  , mxImage(m_xBuilder->weld_image("image"))
201  , mxField(m_xBuilder->weld_metric_spin_button("spinfield", FieldUnit::NONE))
202 {
203  InitControlBase(&mxField->get_widget());
204 
205  OUString sResId(ImplGetRID(rCmd));
206  mxImage->set_from_icon_name(sResId);
207  mxImage->set_toolbar_background();
208 
209  SetBackground( Wallpaper() ); // transparent background
210 
211  mxField->set_help_id(OUStringToOString(rCmd, RTL_TEXTENCODING_UTF8));
212  mxField->get_widget().connect_key_press(LINK(this, ImplGrafControl, KeyInputHdl));
213  mxField->connect_value_changed(LINK(this, ImplGrafControl, ValueChangedHdl));
214 
215  if (maCommand == ".uno:GrafGamma")
216  {
217  mxField->set_digits(2);
218 
219  mxField->set_range(10, 1000, FieldUnit::NONE);
220  mxField->set_increments(10, 100, FieldUnit::NONE);
221  }
222  else
223  {
224  const long nMinVal = maCommand == ".uno:GrafTransparence" ? 0 : -100;
225 
226  mxField->set_unit(FieldUnit::PERCENT);
227  mxField->set_digits(0);
228 
229  mxField->set_range(nMinVal, 100, FieldUnit::PERCENT);
230  mxField->set_increments(1, 10, FieldUnit::PERCENT);
231  }
232 
233  maIdle.SetInvokeHandler( LINK( this, ImplGrafControl, ImplModifyHdl ) );
234 
235  SetSizePixel(m_xContainer->get_preferred_size());
236 }
237 
238 IMPL_LINK(ImplGrafControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
239 {
240  return ChildKeyInput(rKEvt);
241 }
242 
243 ImplGrafControl::~ImplGrafControl()
244 {
245  disposeOnce();
246 }
247 
248 void ImplGrafControl::dispose()
249 {
250  mxImage.reset();
251  mxField.reset();
253 }
254 
255 namespace {
256 
257 class ImplGrafModeControl final : public InterimItemWindow
258 {
259 private:
260  sal_uInt16 mnCurPos;
261  Reference< XFrame > mxFrame;
262  std::unique_ptr<weld::ComboBox> m_xWidget;
263 
264  DECL_LINK(SelectHdl, weld::ComboBox&, void);
265  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
266  DECL_LINK(FocusInHdl, weld::Widget&, void);
267 
268  static void ImplReleaseFocus();
269 
270 public:
271  ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame );
272  virtual void dispose() override;
273  virtual ~ImplGrafModeControl() override;
274 
275  void set_sensitive(bool bSensitive)
276  {
277  Enable(bSensitive);
278  m_xWidget->set_sensitive(true);
279  }
280 
281  void set_active(int nActive)
282  {
283  m_xWidget->set_active(nActive);
284  }
285 
286  void Update( const SfxPoolItem* pItem );
287 };
288 
289 }
290 
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"))
296 {
297  InitControlBase(m_xWidget.get());
298 
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 ) );
303 
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));
307 
308  SetSizePixel(m_xWidget->get_preferred_size());
309 }
310 
311 void ImplGrafModeControl::dispose()
312 {
313  m_xWidget.reset();
315 }
316 
317 ImplGrafModeControl::~ImplGrafModeControl()
318 {
319  disposeOnce();
320 }
321 
322 IMPL_LINK(ImplGrafModeControl, SelectHdl, weld::ComboBox&, rBox, void)
323 {
324  Sequence< PropertyValue > aArgs( 1 );
325  aArgs[0].Name = "GrafMode";
326  aArgs[0].Value <<= sal_Int16(rBox.get_active());
327 
328  /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
329  This instance may be deleted in the meantime (i.e. when a dialog is opened
330  while in Dispatch()), accessing members will crash in this case. */
331  ImplReleaseFocus();
332 
334  Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
335  ".uno:GrafMode",
336  aArgs );
337 }
338 
339 IMPL_LINK(ImplGrafModeControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
340 {
341  bool bHandled(false);
342 
343  if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
344  {
345  m_xWidget->set_active(mnCurPos);
346  ImplReleaseFocus();
347  bHandled = true;
348  }
349 
350  return bHandled || ChildKeyInput(rKEvt);
351 }
352 
353 IMPL_LINK_NOARG(ImplGrafModeControl, FocusInHdl, weld::Widget&, void)
354 {
355  mnCurPos = m_xWidget->get_active();
356 }
357 
358 void ImplGrafModeControl::ImplReleaseFocus()
359 {
360  if( SfxViewShell::Current() )
361  {
362  vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
363 
364  if( pShellWnd )
365  pShellWnd->GrabFocus();
366  }
367 }
368 
369 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
370 {
371  if( pItem )
372  m_xWidget->set_active(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
373  else
374  m_xWidget->set_active(-1);
375 }
376 
377 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx) :
378  SfxToolBoxControl( nSlotId, nId, rTbx )
379 {
380  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
381  rTbx.Invalidate();
382 }
383 
385 {
386 }
387 
388 void SvxGrafToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
389 {
390  ImplGrafControl* pCtrl = static_cast<ImplGrafControl*>( GetToolBox().GetItemWindow( GetId() ) );
391  DBG_ASSERT( pCtrl, "Control not found" );
392 
393  if( eState == SfxItemState::DISABLED )
394  {
395  pCtrl->set_sensitive(false);
396  pCtrl->set_field_text( OUString() );
397  }
398  else
399  {
400  pCtrl->set_sensitive(true);
401 
402  if( eState == SfxItemState::DEFAULT )
403  pCtrl->Update( pState );
404  else
405  pCtrl->Update( nullptr );
406  }
407 }
408 
410 {
411  return VclPtr<ImplGrafControl>::Create( pParent, m_aCommandURL, m_xFrame ).get();
412 }
413 
415 
416 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
417  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
418 {
419 }
420 
422 
423 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
424  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
425 {
426 }
427 
429 
430 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
431  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
432 {
433 }
434 
436 
437 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
438  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
439 {
440 }
441 
443 
444 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
445  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
446 {
447 }
448 
450 
451 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
452  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
453 {
454 }
455 
457 
459  SvxGrafToolBoxControl( nSlotId, nId, rTbx )
460 {
461 }
462 
464 
465 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
466  SfxToolBoxControl( nSlotId, nId, rTbx )
467 {
468 }
469 
471 {
472 }
473 
474 void SvxGrafModeToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
475 
476 {
477  ImplGrafModeControl* pCtrl = static_cast<ImplGrafModeControl*>( GetToolBox().GetItemWindow( GetId() ) );
478  DBG_ASSERT( pCtrl, "Control not found" );
479 
480  if( eState == SfxItemState::DISABLED )
481  {
482  pCtrl->set_sensitive(false);
483  pCtrl->set_active(-1);
484  }
485  else
486  {
487  pCtrl->set_sensitive(true);
488 
489  if( eState == SfxItemState::DEFAULT )
490  pCtrl->Update( pState );
491  else
492  pCtrl->Update( nullptr );
493  }
494 }
495 
497 {
498  return VclPtr<ImplGrafModeControl>::Create( pParent, m_xFrame ).get();
499 }
500 
502 {
503  SfxItemPool& rPool = rView.GetModel()->GetItemPool();
505  OUString aUndoStr;
506  const bool bUndo = rView.IsUndoEnabled();
507 
508  if( bUndo )
509  {
510  aUndoStr = rView.GetDescriptionOfMarkedObjects() + " ";
511  }
512 
513  const SfxItemSet* pArgs = rReq.GetArgs();
514  const SfxPoolItem* pItem;
515  sal_uInt16 nSlot = rReq.GetSlot();
516 
517  if( !pArgs || SfxItemState::SET != pArgs->GetItemState( nSlot, false, &pItem ))
518  pItem = nullptr;
519 
520  switch( nSlot )
521  {
522  case SID_ATTR_GRAF_RED:
523  {
524  if( pItem )
525  {
526  aSet.Put( SdrGrafRedItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
527  if( bUndo )
528  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFRED );
529  }
530  }
531  break;
532 
533  case SID_ATTR_GRAF_GREEN:
534  {
535  if( pItem )
536  {
537  aSet.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
538  if( bUndo )
539  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGREEN );
540  }
541  }
542  break;
543 
544  case SID_ATTR_GRAF_BLUE:
545  {
546  if( pItem )
547  {
548  aSet.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
549  if( bUndo )
550  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFBLUE );
551  }
552  }
553  break;
554 
555  case SID_ATTR_GRAF_LUMINANCE:
556  {
557  if( pItem )
558  {
559  aSet.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
560  if( bUndo )
561  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFLUMINANCE );
562  }
563  }
564  break;
565 
566  case SID_ATTR_GRAF_CONTRAST:
567  {
568  if( pItem )
569  {
570  aSet.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
571  if( bUndo )
572  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCONTRAST );
573  }
574  }
575  break;
576 
577  case SID_ATTR_GRAF_GAMMA:
578  {
579  if( pItem )
580  {
581  aSet.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item*>(pItem)->GetValue() ));
582  if( bUndo )
583  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFGAMMA );
584  }
585  }
586  break;
587 
588  case SID_ATTR_GRAF_TRANSPARENCE:
589  {
590  if( pItem )
591  {
592  aSet.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
593  if( bUndo )
594  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFTRANSPARENCY );
595  }
596  }
597  break;
598 
599  case SID_ATTR_GRAF_MODE:
600  {
601  if( pItem )
602  {
603  aSet.Put( SdrGrafModeItem( static_cast<GraphicDrawMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()) ));
604  if( bUndo )
605  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFMODE );
606  }
607  }
608  break;
609 
610  case SID_ATTR_GRAF_CROP:
611  {
612  const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
613 
614  if( 0 < rMarkList.GetMarkCount() )
615  {
616  SdrGrafObj* pObj = static_cast<SdrGrafObj*>( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
617 
618  if( ( pObj->GetGraphicType() != GraphicType::NONE ) &&
619  ( pObj->GetGraphicType() != GraphicType::Default ) )
620  {
622  const MapUnit eOldMetric = rPool.GetMetric( 0 );
623  const MapMode aMap100( MapUnit::Map100thMM );
624  const MapMode aMapTwip( MapUnit::MapTwip );
625 
626  aGrfAttr.Put(pObj->GetMergedItemSet());
627  rPool.SetDefaultMetric( MapUnit::MapTwip );
628 
629  SfxItemSet aCropDlgAttr(
630  rPool,
631  svl::Items<
633  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
634  SID_ATTR_GRAF_CROP, SID_ATTR_GRAF_FRMSIZE,
635  SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC>{});
636 
637  aCropDlgAttr.Put( SvxBrushItem( pObj->GetGraphic(), GPOS_MM, SID_ATTR_GRAF_GRAPHIC ) );
638  aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE,
640  Size( 200000, 200000 ), aMap100, aMapTwip ) ) );
641  aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE, OutputDevice::LogicToLogic(
642  pObj->GetLogicRect().GetSize(), aMap100, aMapTwip ) ) );
643 
644  const SdrGrafCropItem& rCrop = aGrfAttr.Get( SDRATTR_GRAFCROP );
646  Size( rCrop.GetLeft(), rCrop.GetTop() ), aMap100, aMapTwip ) );
648  Size( rCrop.GetRight(), rCrop.GetBottom() ), aMap100, aMapTwip ) );
649 
650  aCropDlgAttr.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(),
651  aRBSize.Width(), aRBSize.Height() ) );
652 
653  vcl::Window* pParent(SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : nullptr);
654  SfxSingleTabDialogController aCropDialog(pParent ? pParent->GetFrameWeld() : nullptr,
655  &aCropDlgAttr);
656  const OUString aCropStr(SvxResId(RID_SVXSTR_GRAFCROP));
657 
659  ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP );
660  std::unique_ptr<SfxTabPage> xTabPage = (*fnCreatePage)(aCropDialog.get_content_area(), &aCropDialog, &aCropDlgAttr);
661  xTabPage->SetPageTitle(aCropStr);
662  aCropDialog.SetTabPage(std::move(xTabPage));
663 
664  if (aCropDialog.run() == RET_OK)
665  {
666  const SfxItemSet* pOutAttr = aCropDialog.GetOutputItemSet();
667 
668  if( pOutAttr )
669  {
670  aUndoStr += SvxResId( RID_SVXSTR_UNDO_GRAFCROP );
671 
672  // set crop attributes
673  if( SfxItemState::SET <= pOutAttr->GetItemState( SDRATTR_GRAFCROP ) )
674  {
675  const SdrGrafCropItem& rNewCrop = pOutAttr->Get( SDRATTR_GRAFCROP );
676 
677  aLTSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetLeft(), rNewCrop.GetTop() ), aMapTwip, aMap100 );
678  aRBSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetRight(), rNewCrop.GetBottom() ), aMapTwip, aMap100 );
679  aSet.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(), aRBSize.Width(), aRBSize.Height() ) );
680  }
681 
682  // set new logic rect
683  if( SfxItemState::SET <= pOutAttr->GetItemState( SID_ATTR_GRAF_FRMSIZE ) )
684  {
685  Point aNewOrigin( pObj->GetLogicRect().TopLeft() );
686  const Size& rGrfSize = static_cast<const SvxSizeItem&>( pOutAttr->Get( SID_ATTR_GRAF_FRMSIZE ) ).GetSize();
687  Size aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize, aMapTwip, aMap100 ) );
688  Size aOldGrfSize( pObj->GetLogicRect().GetSize() );
689 
690  tools::Rectangle aNewRect( aNewOrigin, aNewGrfSize );
691  Point aOffset( (aNewGrfSize.Width() - aOldGrfSize.Width()) >> 1,
692  (aNewGrfSize.Height() - aOldGrfSize.Height()) >> 1 );
693 
694  // #106181# rotate snap rect before setting it
695  const GeoStat& aGeo = pObj->GetGeoStat();
696 
697  if (aGeo.nRotationAngle!=0 || aGeo.nShearAngle!=0)
698  {
699  tools::Polygon aPol(aNewRect);
700 
701  // also transform origin offset
702  if (aGeo.nShearAngle!=0)
703  {
704  ShearPoly(aPol,
705  aNewRect.TopLeft(),
706  aGeo.nTan);
707  ShearPoint(aOffset, Point(0,0), aGeo.nTan);
708  }
709  if (aGeo.nRotationAngle!=0)
710  {
711  RotatePoly(aPol,
712  aNewRect.TopLeft(),
713  aGeo.nSin,aGeo.nCos);
714  RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
715  }
716 
717  // apply offset
718  aPol.Move( -aOffset.X(), -aOffset.Y() );
719  aNewRect=aPol.GetBoundRect();
720  }
721  else
722  {
723  aNewRect.Move( -aOffset.X(), -aOffset.Y() );
724  }
725 
726  if( !aSet.Count() )
727  rView.SetMarkedObjRect( aNewRect );
728  else
729  {
730  if( bUndo )
731  {
732  rView.BegUndo( aUndoStr );
733  rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
734  }
735  pObj->SetSnapRect( aNewRect );
736  rView.SetAttributes( aSet );
737 
738  if( bUndo )
739  rView.EndUndo();
740  aSet.ClearItem();
741  }
742  }
743  }
744  }
745 
746  rPool.SetDefaultMetric( eOldMetric );
747  }
748  }
749  }
750  break;
751 
752  case SID_COLOR_SETTINGS:
753  {
754  svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
755  aToolboxAccess.toggleToolbox();
756  rReq.Done();
757  break;
758  }
759 
760  default:
761  break;
762  }
763 
764  if( aSet.Count() )
765  {
766  if( bUndo )
767  rView.BegUndo( aUndoStr );
768 
769  rView.SetAttributes( aSet );
770 
771  if( bUndo )
772  rView.EndUndo();
773  }
774 }
775 
777 {
778  SfxItemPool& rPool = rView.GetModel()->GetItemPool();
779  SfxItemSet aAttrSet( rPool );
780  SfxWhichIter aIter( rSet );
781  sal_uInt16 nWhich = aIter.FirstWhich();
782  const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
783  bool bEnableColors = true;
784  bool bEnableTransparency = true;
785  bool bEnableCrop = ( 1 == rMarkList.GetMarkCount() );
786 
787  for( size_t i = 0, nCount = rMarkList.GetMarkCount(); i < nCount; ++i )
788  {
789  SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( i )->GetMarkedSdrObj() );
790 
791  if( !pGrafObj ||
792  ( pGrafObj->GetGraphicType() == GraphicType::NONE ) ||
793  ( pGrafObj->GetGraphicType() == GraphicType::Default ))
794  {
795  bEnableColors = bEnableTransparency = bEnableCrop = false;
796  break;
797  }
798  else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
799  {
800  bEnableTransparency = false;
801  }
802  }
803 
804  rView.GetAttributes( aAttrSet );
805 
806  while( nWhich )
807  {
808  sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
809 
810  switch( nSlotId )
811  {
812  case SID_ATTR_GRAF_MODE:
813  {
814  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
815  {
816  if( bEnableColors )
817  {
818  rSet.Put( SfxUInt16Item( nSlotId,
819  sal::static_int_cast< sal_uInt16 >( aAttrSet.Get(SDRATTR_GRAFMODE).GetValue() ) ) );
820  }
821  else
822  {
823  rSet.DisableItem( SID_ATTR_GRAF_MODE );
824  }
825  }
826  }
827  break;
828 
829  case SID_ATTR_GRAF_RED:
830  {
831  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
832  {
833  if( bEnableColors )
834  {
835  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFRED).GetValue() ) );
836  }
837  else
838  {
839  rSet.DisableItem( SID_ATTR_GRAF_RED );
840  }
841  }
842  }
843  break;
844 
845  case SID_ATTR_GRAF_GREEN:
846  {
847  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
848  {
849  if( bEnableColors )
850  {
851  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFGREEN).GetValue()) );
852  }
853  else
854  {
855  rSet.DisableItem( SID_ATTR_GRAF_GREEN );
856  }
857  }
858  }
859  break;
860 
861  case SID_ATTR_GRAF_BLUE:
862  {
863  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
864  {
865  if( bEnableColors )
866  {
867  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFBLUE).GetValue()) );
868  }
869  else
870  {
871  rSet.DisableItem( SID_ATTR_GRAF_BLUE );
872  }
873  }
874  }
875  break;
876 
877  case SID_ATTR_GRAF_LUMINANCE:
878  {
879  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
880  {
881  if( bEnableColors )
882  {
883  rSet.Put( SfxInt16Item( nSlotId, aAttrSet.Get(SDRATTR_GRAFLUMINANCE).GetValue()) );
884  }
885  else
886  {
887  rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
888  }
889  }
890  }
891  break;
892 
893  case SID_ATTR_GRAF_CONTRAST:
894  {
895  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
896  {
897  if( bEnableColors )
898  {
899  rSet.Put( SfxInt16Item( nSlotId,
900  aAttrSet.Get(SDRATTR_GRAFCONTRAST).GetValue()) );
901  }
902  else
903  {
904  rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
905  }
906  }
907  }
908  break;
909 
910  case SID_ATTR_GRAF_GAMMA:
911  {
912  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
913  {
914  if( bEnableColors )
915  {
916  rSet.Put( SfxUInt32Item( nSlotId,
917  aAttrSet.Get(SDRATTR_GRAFGAMMA).GetValue() ) );
918  }
919  else
920  {
921  rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
922  }
923  }
924  }
925  break;
926 
927  case SID_ATTR_GRAF_TRANSPARENCE:
928  {
929  if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFTRANSPARENCE ) )
930  {
931  if( bEnableTransparency )
932  {
933  rSet.Put( SfxUInt16Item( nSlotId,
934  aAttrSet.Get(SDRATTR_GRAFTRANSPARENCE).GetValue() ) );
935  }
936  else
937  {
938  rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
939  }
940  }
941  }
942  break;
943 
944  case SID_ATTR_GRAF_CROP:
945  {
946  if( !bEnableCrop )
947  rSet.DisableItem( nSlotId );
948  }
949  break;
950 
951  case SID_COLOR_SETTINGS :
952  {
953  svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
954  rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
955  break;
956  }
957 
958  default:
959  break;
960  }
961 
962  nWhich = aIter.NextWhich();
963  }
964 }
965 
966 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
long Width() const
constexpr TypedWhichId< SdrGrafGamma100Item > SDRATTR_GRAFGAMMA(SDRATTR_GRAF_FIRST+5)
FieldUnit
size_t GetMarkCount() const
Definition: svdmark.hxx:180
#define TOOLBOX_NAME
Definition: grafctrl.cxx:63
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:122
static SfxAbstractDialogFactory * Create()
std::string GetValue
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
ToolBox & GetToolBox() const
long Height() const
double nSin
Definition: svdtrans.hxx:219
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool IsUndoEnabled() const
Definition: svdedtv.cxx:1027
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
void toggleToolbox() const
toggles the toolbox
Definition: tbxcolor.cxx:59
long nRotationAngle
Definition: svdtrans.hxx:216
css::uno::Reference< css::lang::XComponent > m_xFrame
void BegUndo()
Definition: svdedtv.hxx:179
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:80
void Done(bool bRemove=false)
SvxGrafModeToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:465
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: grafctrl.cxx:409
const SfxItemSet * GetArgs() const
GraphicType GetGraphicType() const
Definition: svdograf.cxx:351
sal_uInt16 NextWhich()
NONE
void Move(long nHorzMoveDelta, long nVertMoveDelta)
void ShearPoly(tools::Polygon &rPoly, const Point &rRef, double tn)
Definition: svdtrans.cxx:146
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
weld::Window * GetFrameWeld() const
Reference< XNameAccess > m_xContainer
void Enable(bool bEnable=true, bool bChild=true)
IMPL_LINK(ImplGrafControl, KeyInputHdl, const KeyEvent &, rKEvt, bool)
Definition: grafctrl.cxx:238
virtual CreateTabPage GetTabPageCreatorFunc(sal_uInt16 nId)=0
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
static void GetGrafAttrState(SfxItemSet &rSet, SdrView const &rView)
Definition: grafctrl.cxx:776
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:214
int nCount
static SfxViewShell * Current()
const GeoStat & GetGeoStat() const
Definition: svdotext.hxx:399
void EndUndo()
Definition: svdedtv.cxx:275
SvxGrafTransparenceToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:458
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
constexpr TypedWhichId< SdrGrafTransparenceItem > SDRATTR_GRAFTRANSPARENCE(SDRATTR_GRAF_FIRST+6)
SvxGrafBlueToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:430
void Move(long nHorzMove, long nVertMove)
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdedtv.hxx:183
bool IsAnimated() const
Definition: svdograf.cxx:391
double nCos
Definition: svdtrans.hxx:220
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define DBG_ASSERT(sCon, aError)
SvxGrafRedToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:416
constexpr TypedWhichId< SdrGrafLuminanceItem > SDRATTR_GRAFLUMINANCE(SDRATTR_GRAF_FIRST+3)
int i
uno_Any a
const Graphic & GetGraphic() const
Definition: svdograf.cxx:330
OUString const & GetDescriptionOfMarkedObjects() const
Definition: svdmrkv.hxx:261
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: grafctrl.cxx:388
constexpr TypedWhichId< SdrGrafBlueItem > SDRATTR_GRAFBLUE(SDRATTR_GRAF_FIRST+2)
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
const SdrMarkList & GetMarkedObjectList() const
Definition: svdmrkv.hxx:252
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
Definition: svdview.hxx:193
double nTan
Definition: svdtrans.hxx:218
constexpr TypedWhichId< SdrGrafModeItem > SDRATTR_GRAFMODE(SDRATTR_GRAF_FIRST+8)
GPOS_MM
vcl::Window * GetItemWindow(sal_uInt16 nItemId) const
SvxGrafGammaToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:451
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
DECL_LINK(DoResize, Timer *, void)
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:79
void GrabFocus()
constexpr TypedWhichId< SdrGrafCropItem > SDRATTR_GRAFCROP(SDRATTR_GRAF_FIRST+9)
SdrUndoFactory & GetSdrUndoFactory() const
returns the models undo factory.
Definition: svdmodel.cxx:1961
Size GetSize() const
long nShearAngle
Definition: svdtrans.hxx:217
SvxGrafGreenToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:423
virtual ~SvxGrafModeToolBoxControl() override
Definition: grafctrl.cxx:470
virtual std::unique_ptr< SdrUndoAction > CreateUndoGeoObject(SdrObject &rObject)
Definition: svdundo.cxx:1644
#define RID_SVXSTR_UNDO_GRAFCROP
Definition: grafctrl.cxx:64
constexpr TypedWhichId< SdrGrafGreenItem > SDRATTR_GRAFGREEN(SDRATTR_GRAF_FIRST+1)
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
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
virtual ~SvxGrafToolBoxControl() override
Definition: grafctrl.cxx:384
void SetDefaultMetric(MapUnit eNewMetric)
SFX_IMPL_TOOLBOX_CONTROL(SvxGrafRedToolBoxControl, SfxInt16Item)
SvxGrafContrastToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:444
SfxItemState
void DisableItem(sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
constexpr sal_uInt16 KEY_ESCAPE
static void ExecuteGrafAttr(SfxRequest &rReq, SdrView &rView)
Definition: grafctrl.cxx:501
virtual void dispose() override
unsigned short GetId() const
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1889
void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
Definition: svdview.cxx:246
bool HasGDIMetaFile() const
Definition: svdograf.cxx:834
RET_OK
static VclPtr< reference_type > Create(Arg &&...arg)
SvxGrafToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:377
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: grafctrl.cxx:496
vcl::Window * GetWindow() const
SvxGrafLuminanceToolBoxControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: grafctrl.cxx:437
IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton &, void)
Definition: grafctrl.cxx:98
virtual void SetSnapRect(const tools::Rectangle &rRect)
Definition: svdobj.cxx:1622
MapUnit
constexpr TypedWhichId< SdrGrafContrastItem > SDRATTR_GRAFCONTRAST(SDRATTR_GRAF_FIRST+4)
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:314
tools::Rectangle GetBoundRect() const
void SetMarkedObjRect(const tools::Rectangle &rRect)
Definition: svdedtv1.cxx:76
SdrModel * GetModel() const
Definition: svdpntv.hxx:265
void Dispatch(const OUString &aCommand, css::uno::Sequence< css::beans::PropertyValue > const &aArgs)
static OUString ImplGetRID(const OUString &aCommand)
Definition: grafctrl.cxx:163
static bool IsWhich(sal_uInt16 nId)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: grafctrl.cxx:474
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
virtual const tools::Rectangle & GetLogicRect() const override
Definition: svdotxtr.cxx:69