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