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