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