fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / tbxctrls / grafctrl.cxx
blobcb5add9fe78cfa6eda2d8dc76beb6594248b28f3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <string>
22 #include <vcl/toolbox.hxx>
23 #include <vcl/field.hxx>
24 #include <vcl/fixed.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <vcl/idle.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 #include <comphelper/processfactory.hxx>
39 #include <svx/svxids.hrc>
40 #include <svx/dialogs.hrc>
41 #include <editeng/brushitem.hxx>
42 #include <editeng/sizeitem.hxx>
43 #include <svx/sdgcpitm.hxx>
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"
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::frame;
57 using namespace ::com::sun::star::util;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::lang;
61 #include <svx/svxdlg.hxx>
63 #define SYMBOL_TO_FIELD_OFFSET 4
64 #define ITEMVALUE(ItemSet,Id,Cast) static_cast<const Cast&>((ItemSet).Get(Id)).GetValue()
65 #define TOOLBOX_NAME OUString( "colorbar" )
67 TYPEINIT1_AUTOFACTORY( TbxImageItem, SfxUInt16Item );
69 TbxImageItem::TbxImageItem( sal_uInt16 _nWhich, sal_uInt16 nImage ) :
70 SfxUInt16Item( _nWhich, nImage )
75 SfxPoolItem* TbxImageItem::Clone( SfxItemPool* ) const
77 return new TbxImageItem( *this );
80 bool TbxImageItem::operator==( const SfxPoolItem& rItem ) const
82 return static_cast<const TbxImageItem&>(rItem).GetValue() == GetValue();
85 class ImplGrafMetricField : public MetricField
87 using Window::Update;
89 private:
90 Idle maIdle;
91 OUString maCommand;
92 Reference< XFrame > mxFrame;
94 DECL_LINK_TYPED(ImplModifyHdl, Idle *, void);
96 protected:
98 virtual void Modify() SAL_OVERRIDE;
100 public:
101 ImplGrafMetricField( vcl::Window* pParent, const OUString& aCmd, const Reference< XFrame >& rFrame );
103 void Update( const SfxPoolItem* pItem );
106 ImplGrafMetricField::ImplGrafMetricField( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame ) :
107 MetricField( pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_3DLOOK ),
108 maCommand( rCmd ),
109 mxFrame( rFrame )
111 Size aSize( GetTextWidth( OUString("-100 %") ), GetTextHeight() );
113 aSize.Width() += 20, aSize.Height() += 6;
114 SetSizePixel( aSize );
116 if ( maCommand == ".uno:GrafGamma" )
118 SetDecimalDigits( 2 );
120 SetMin( 10 );
121 SetFirst( 10 );
122 SetMax( 1000 );
123 SetLast( 1000 );
124 SetSpinSize( 10 );
126 else
128 const long nMinVal = maCommand == ".uno:GrafTransparence" ? 0 : -100;
130 SetUnit(FUNIT_PERCENT);
131 SetDecimalDigits( 0 );
133 SetMin( nMinVal );
134 SetFirst( nMinVal );
135 SetMax( 100 );
136 SetLast( 100 );
137 SetSpinSize( 1 );
140 maIdle.SetPriority( SchedulerPriority::LOW );
141 maIdle.SetIdleHdl( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
144 void ImplGrafMetricField::Modify()
146 maIdle.Start();
149 IMPL_LINK_NOARG_TYPED(ImplGrafMetricField, ImplModifyHdl, Idle *, void)
151 const sal_Int64 nVal = GetValue();
153 // Convert value to an any to be usable with dispatch API
154 Any a;
155 if ( maCommand == ".uno:GrafRed" ||
156 maCommand == ".uno:GrafGreen" ||
157 maCommand == ".uno:GrafBlue" ||
158 maCommand == ".uno:GrafLuminance" ||
159 maCommand == ".uno:GrafContrast" )
160 a = makeAny( sal_Int16( nVal ));
161 else if ( maCommand == ".uno:GrafGamma" ||
162 maCommand == ".uno:GrafTransparence" )
163 a = makeAny( sal_Int32( nVal ));
165 if ( a.hasValue() )
167 INetURLObject aObj( maCommand );
169 Sequence< PropertyValue > aArgs( 1 );
170 aArgs[0].Name = aObj.GetURLPath();
171 aArgs[0].Value = a;
173 SfxToolBoxControl::Dispatch(
174 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
175 maCommand,
176 aArgs );
180 void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
182 if( pItem )
184 long nValue;
186 if ( maCommand == ".uno:GrafTransparence" )
187 nValue = static_cast<const SfxUInt16Item*>( pItem )->GetValue();
188 else if ( maCommand == ".uno:GrafGamma" )
189 nValue = static_cast<const SfxUInt32Item*>( pItem )->GetValue();
190 else
191 nValue = static_cast<const SfxInt16Item*>( pItem )->GetValue();
193 SetValue( nValue );
195 else
196 SetText( OUString() );
199 struct CommandToRID
201 const char* pCommand;
202 sal_uInt16 nResId;
205 static sal_uInt16 ImplGetRID( const OUString& aCommand )
207 static const CommandToRID aImplCommandToResMap[] =
209 { ".uno:GrafRed", RID_SVXIMG_GRAF_RED },
210 { ".uno:GrafGreen", RID_SVXIMG_GRAF_GREEN },
211 { ".uno:GrafBlue", RID_SVXIMG_GRAF_BLUE },
212 { ".uno:GrafLuminance", RID_SVXIMG_GRAF_LUMINANCE },
213 { ".uno:GrafContrast", RID_SVXIMG_GRAF_CONTRAST },
214 { ".uno:GrafGamma", RID_SVXIMG_GRAF_GAMMA },
215 { ".uno:GrafTransparence", RID_SVXIMG_GRAF_TRANSPARENCE },
216 { 0, 0 }
219 sal_uInt16 nRID = 0;
221 sal_Int32 i( 0 );
222 while ( aImplCommandToResMap[ i ].pCommand )
224 if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
226 nRID = aImplCommandToResMap[ i ].nResId;
227 break;
229 ++i;
232 return nRID;
235 class ImplGrafControl : public Control
237 using Window::Update;
238 private:
239 VclPtr<FixedImage> maImage;
240 VclPtr<ImplGrafMetricField> maField;
242 protected:
244 virtual void GetFocus() SAL_OVERRIDE;
246 public:
248 ImplGrafControl( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame );
249 virtual ~ImplGrafControl();
250 virtual void dispose() SAL_OVERRIDE;
252 void Update( const SfxPoolItem* pItem ) { maField->Update( pItem ); }
253 void SetText( const OUString& rStr ) SAL_OVERRIDE { maField->SetText( rStr ); }
256 ImplGrafControl::ImplGrafControl(
257 vcl::Window* pParent,
258 const OUString& rCmd,
259 const Reference< XFrame >& rFrame
260 ) : Control( pParent, WB_TABSTOP )
261 , maImage( VclPtr<FixedImage>::Create(this) )
262 , maField( VclPtr<ImplGrafMetricField>::Create(this, rCmd, rFrame) )
264 ResId aResId( ImplGetRID( rCmd ), DIALOG_MGR() ) ;
265 Image aImage( aResId );
267 Size aImgSize( aImage.GetSizePixel() );
268 Size aFldSize( maField->GetSizePixel() );
269 long nFldY, nImgY;
271 maImage->SetImage( aImage );
272 maImage->SetSizePixel( aImgSize );
273 // we want to see the backbround of the toolbox, not of the FixedImage or Control
274 maImage->SetBackground( Wallpaper( COL_TRANSPARENT ) );
275 SetBackground( Wallpaper( COL_TRANSPARENT ) );
277 if( aImgSize.Height() > aFldSize.Height() )
278 nImgY = 0, nFldY = ( aImgSize.Height() - aFldSize.Height() ) >> 1;
279 else
280 nFldY = 0, nImgY = ( aFldSize.Height() - aImgSize.Height() ) >> 1;
282 long nOffset = SYMBOL_TO_FIELD_OFFSET / 2;
283 maImage->SetPosPixel( Point( nOffset, nImgY ) );
284 maField->SetPosPixel( Point( aImgSize.Width() + SYMBOL_TO_FIELD_OFFSET, nFldY ) );
285 SetSizePixel( Size( aImgSize.Width() + aFldSize.Width() + SYMBOL_TO_FIELD_OFFSET + nOffset,
286 std::max( aImgSize.Height(), aFldSize.Height() ) ) );
288 SetBackground( Wallpaper() ); // transparent background
290 maImage->Show();
292 maField->SetHelpId( OUStringToOString( rCmd, RTL_TEXTENCODING_UTF8 ) );
293 maField->Show();
296 ImplGrafControl::~ImplGrafControl()
298 disposeOnce();
301 void ImplGrafControl::dispose()
303 maImage.disposeAndClear();
304 maField.disposeAndClear();
305 Control::dispose();
308 void ImplGrafControl::GetFocus()
310 if (maField)
311 maField->GrabFocus();
314 class ImplGrafModeControl : public ListBox
316 using Window::Update;
317 private:
318 sal_uInt16 mnCurPos;
319 Reference< XFrame > mxFrame;
321 virtual void Select() SAL_OVERRIDE;
322 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
323 virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
324 static void ImplReleaseFocus();
326 public:
327 ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame );
329 void Update( const SfxPoolItem* pItem );
332 ImplGrafModeControl::ImplGrafModeControl( vcl::Window* pParent, const Reference< XFrame >& rFrame ) :
333 ListBox( pParent, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL ),
334 mnCurPos( 0 ),
335 mxFrame( rFrame )
337 SetSizePixel( Size( 100, 260 ) );
339 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_STANDARD ) );
340 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_GREYS ) );
341 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_MONO ) );
342 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_WATERMARK ) );
344 Show();
347 void ImplGrafModeControl::Select()
349 if ( !IsTravelSelect() )
351 Sequence< PropertyValue > aArgs( 1 );
352 aArgs[0].Name = "GrafMode";
353 aArgs[0].Value = makeAny( sal_Int16( GetSelectEntryPos() ));
355 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
356 This instance may be deleted in the meantime (i.e. when a dialog is opened
357 while in Dispatch()), accessing members will crash in this case. */
358 ImplReleaseFocus();
360 SfxToolBoxControl::Dispatch(
361 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
362 OUString( ".uno:GrafMode" ),
363 aArgs );
367 bool ImplGrafModeControl::PreNotify( NotifyEvent& rNEvt )
369 MouseNotifyEvent nType = rNEvt.GetType();
371 if( MouseNotifyEvent::MOUSEBUTTONDOWN == nType || MouseNotifyEvent::GETFOCUS == nType )
372 mnCurPos = GetSelectEntryPos();
374 return ListBox::PreNotify( rNEvt );
377 bool ImplGrafModeControl::Notify( NotifyEvent& rNEvt )
379 bool nHandled = ListBox::Notify( rNEvt );
381 if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
383 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
385 switch( pKEvt->GetKeyCode().GetCode() )
387 case KEY_RETURN:
389 Select();
390 nHandled = true;
392 break;
394 case KEY_ESCAPE:
396 SelectEntryPos( mnCurPos );
397 ImplReleaseFocus();
398 nHandled = true;
400 break;
404 return nHandled;
407 void ImplGrafModeControl::ImplReleaseFocus()
409 if( SfxViewShell::Current() )
411 vcl::Window* pShellWnd = SfxViewShell::Current()->GetWindow();
413 if( pShellWnd )
414 pShellWnd->GrabFocus();
418 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
420 if( pItem )
421 SelectEntryPos( static_cast<const SfxUInt16Item*>(pItem)->GetValue() );
422 else
423 SetNoSelection();
426 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafFilterToolBoxControl, TbxImageItem );
428 SvxGrafFilterToolBoxControl::SvxGrafFilterToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
429 SfxToolBoxControl( nSlotId, nId, rTbx )
431 rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWNONLY | rTbx.GetItemBits( nId ) );
432 rTbx.Invalidate();
435 SvxGrafFilterToolBoxControl::~SvxGrafFilterToolBoxControl()
439 void SvxGrafFilterToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* )
441 GetToolBox().EnableItem( GetId(), ( eState != SfxItemState::DISABLED ) );
444 SfxPopupWindowType SvxGrafFilterToolBoxControl::GetPopupWindowType() const
446 return SfxPopupWindowType::ONCLICK;
449 VclPtr<SfxPopupWindow> SvxGrafFilterToolBoxControl::CreatePopupWindow()
451 OUString aSubTbxResName( "private:resource/toolbar/graffilterbar" );
452 createAndPositionSubToolBar( aSubTbxResName );
454 return NULL;
457 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx) :
458 SfxToolBoxControl( nSlotId, nId, rTbx )
460 rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
461 rTbx.Invalidate();
464 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
468 void SvxGrafToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
471 ImplGrafControl* pCtrl = static_cast<ImplGrafControl*>( GetToolBox().GetItemWindow( GetId() ) );
472 DBG_ASSERT( pCtrl, "Control not found" );
474 if( eState == SfxItemState::DISABLED )
476 pCtrl->Disable();
477 pCtrl->SetText( OUString() );
479 else
481 pCtrl->Enable();
483 if( eState == SfxItemState::DEFAULT )
484 pCtrl->Update( pState );
485 else
486 pCtrl->Update( NULL );
490 VclPtr<vcl::Window> SvxGrafToolBoxControl::CreateItemWindow( vcl::Window *pParent )
492 return VclPtr<ImplGrafControl>::Create( pParent, m_aCommandURL, m_xFrame ).get();
495 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl, SfxInt16Item );
497 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
498 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
502 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl, SfxInt16Item );
504 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
505 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
509 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl, SfxInt16Item );
511 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
512 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
516 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl, SfxInt16Item );
518 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
519 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
523 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl, SfxInt16Item );
525 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
526 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
530 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl, SfxUInt32Item );
532 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
533 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
537 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl, SfxUInt16Item );
539 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
540 SvxGrafToolBoxControl( nSlotId, nId, rTbx )
544 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl, SfxUInt16Item );
546 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
547 SfxToolBoxControl( nSlotId, nId, rTbx )
551 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
555 void SvxGrafModeToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
558 ImplGrafModeControl* pCtrl = static_cast<ImplGrafModeControl*>( GetToolBox().GetItemWindow( GetId() ) );
559 DBG_ASSERT( pCtrl, "Control not found" );
561 if( eState == SfxItemState::DISABLED )
563 pCtrl->Disable();
564 pCtrl->SetText( OUString() );
566 else
568 pCtrl->Enable();
570 if( eState == SfxItemState::DEFAULT )
571 pCtrl->Update( pState );
572 else
573 pCtrl->Update( NULL );
577 VclPtr<vcl::Window> SvxGrafModeToolBoxControl::CreateItemWindow( vcl::Window *pParent )
579 return VclPtr<ImplGrafModeControl>::Create( pParent, m_xFrame ).get();
582 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest& rReq, SdrView& rView )
584 SfxItemPool& rPool = rView.GetModel()->GetItemPool();
585 SfxItemSet aSet( rPool, SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST );
586 OUString aUndoStr;
587 const bool bUndo = rView.IsUndoEnabled();
589 if( bUndo )
591 aUndoStr = rView.GetDescriptionOfMarkedObjects();
592 aUndoStr += " ";
595 const SfxItemSet* pArgs = rReq.GetArgs();
596 const SfxPoolItem* pItem;
597 sal_uInt16 nSlot = rReq.GetSlot();
599 if( !pArgs || SfxItemState::SET != pArgs->GetItemState( nSlot, false, &pItem ))
600 pItem = 0;
602 switch( nSlot )
604 case SID_ATTR_GRAF_RED:
606 if( pItem )
608 aSet.Put( SdrGrafRedItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
609 if( bUndo )
610 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED );
613 break;
615 case SID_ATTR_GRAF_GREEN:
617 if( pItem )
619 aSet.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
620 if( bUndo )
621 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN );
624 break;
626 case SID_ATTR_GRAF_BLUE:
628 if( pItem )
630 aSet.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
631 if( bUndo )
632 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE );
635 break;
637 case SID_ATTR_GRAF_LUMINANCE:
639 if( pItem )
641 aSet.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
642 if( bUndo )
643 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE );
646 break;
648 case SID_ATTR_GRAF_CONTRAST:
650 if( pItem )
652 aSet.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item*>(pItem)->GetValue() ));
653 if( bUndo )
654 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST );
657 break;
659 case SID_ATTR_GRAF_GAMMA:
661 if( pItem )
663 aSet.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item*>(pItem)->GetValue() ));
664 if( bUndo )
665 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA );
668 break;
670 case SID_ATTR_GRAF_TRANSPARENCE:
672 if( pItem )
674 aSet.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
675 if( bUndo )
676 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY );
679 break;
681 case SID_ATTR_GRAF_MODE:
683 if( pItem )
685 aSet.Put( SdrGrafModeItem( (GraphicDrawMode) static_cast<const SfxUInt16Item*>(pItem)->GetValue() ));
686 if( bUndo )
687 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE );
690 break;
692 case( SID_ATTR_GRAF_CROP ):
694 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
696 if( 0 < rMarkList.GetMarkCount() )
698 SdrGrafObj* pObj = static_cast<SdrGrafObj*>( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
700 if( pObj && pObj->ISA( SdrGrafObj ) &&
701 ( pObj->GetGraphicType() != GRAPHIC_NONE ) &&
702 ( pObj->GetGraphicType() != GRAPHIC_DEFAULT ) )
704 SfxItemSet aGrfAttr( rPool, SDRATTR_GRAFCROP, SDRATTR_GRAFCROP, 0 );
705 const SfxMapUnit eOldMetric = rPool.GetMetric( 0 );
706 const MapMode aMap100( MAP_100TH_MM );
707 const MapMode aMapTwip( MAP_TWIP );
709 aGrfAttr.Put(pObj->GetMergedItemSet());
710 rPool.SetDefaultMetric( SFX_MAPUNIT_TWIP );
712 SfxItemSet aCropDlgAttr( rPool,
713 SDRATTR_GRAFCROP, SDRATTR_GRAFCROP,
714 SID_ATTR_GRAF_GRAPHIC, SID_ATTR_GRAF_GRAPHIC,
715 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
716 SID_ATTR_GRAF_FRMSIZE, SID_ATTR_GRAF_FRMSIZE,
717 SID_ATTR_GRAF_CROP, SID_ATTR_GRAF_CROP, 0 );
719 aCropDlgAttr.Put( SvxBrushItem( pObj->GetGraphic(), GPOS_MM, SID_ATTR_GRAF_GRAPHIC ) );
720 aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE,
721 Size( OutputDevice::LogicToLogic(
722 Size( 200000, 200000 ), aMap100, aMapTwip ) ) ) );
723 aCropDlgAttr.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE, OutputDevice::LogicToLogic(
724 pObj->GetLogicRect().GetSize(), aMap100, aMapTwip ) ) );
726 const SdrGrafCropItem& rCrop = static_cast<const SdrGrafCropItem&>( aGrfAttr.Get( SDRATTR_GRAFCROP ) );
727 Size aLTSize( OutputDevice::LogicToLogic(
728 Size( rCrop.GetLeft(), rCrop.GetTop() ), aMap100, aMapTwip ) );
729 Size aRBSize( OutputDevice::LogicToLogic(
730 Size( rCrop.GetRight(), rCrop.GetBottom() ), aMap100, aMapTwip ) );
732 aCropDlgAttr.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(),
733 aRBSize.Width(), aRBSize.Height() ) );
735 ScopedVclPtrInstance<SfxSingleTabDialog> aCropDialog(
736 SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : NULL,
737 aCropDlgAttr);
738 const OUString aCropStr(SVX_RESSTR(RID_SVXSTR_GRAFCROP));
740 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
741 assert(pFact && "Dialog creation failed!");
742 ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP );
743 assert(fnCreatePage && "Dialog creation failed!");
744 SfxTabPage* pTabPage = (*fnCreatePage)( aCropDialog->get_content_area(), &aCropDlgAttr );
746 pTabPage->SetText( aCropStr );
747 aCropDialog->SetTabPage( pTabPage );
749 if( aCropDialog->Execute() == RET_OK )
751 const SfxItemSet* pOutAttr = aCropDialog->GetOutputItemSet();
753 if( pOutAttr )
755 aUndoStr += SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCROP );
757 // set crop attributes
758 if( SfxItemState::SET <= pOutAttr->GetItemState( SDRATTR_GRAFCROP ) )
760 const SdrGrafCropItem& rNewCrop = static_cast<const SdrGrafCropItem&>( pOutAttr->Get( SDRATTR_GRAFCROP ) );
762 aLTSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetLeft(), rNewCrop.GetTop() ), aMapTwip, aMap100 );
763 aRBSize = OutputDevice::LogicToLogic( Size( rNewCrop.GetRight(), rNewCrop.GetBottom() ), aMapTwip, aMap100 );
764 aSet.Put( SdrGrafCropItem( aLTSize.Width(), aLTSize.Height(), aRBSize.Width(), aRBSize.Height() ) );
767 // set new logic rect
768 if( SfxItemState::SET <= pOutAttr->GetItemState( SID_ATTR_GRAF_FRMSIZE ) )
770 Point aNewOrigin( pObj->GetLogicRect().TopLeft() );
771 const Size& rGrfSize = static_cast<const SvxSizeItem&>( pOutAttr->Get( SID_ATTR_GRAF_FRMSIZE ) ).GetSize();
772 Size aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize, aMapTwip, aMap100 ) );
773 Size aOldGrfSize( pObj->GetLogicRect().GetSize() );
775 Rectangle aNewRect( aNewOrigin, aNewGrfSize );
776 Point aOffset( (aNewGrfSize.Width() - aOldGrfSize.Width()) >> 1,
777 (aNewGrfSize.Height() - aOldGrfSize.Height()) >> 1 );
779 // #106181# rotate snap rect before setting it
780 const GeoStat& aGeo = pObj->GetGeoStat();
782 if (aGeo.nRotationAngle!=0 || aGeo.nShearAngle!=0)
784 Polygon aPol(aNewRect);
786 // also transform origin offset
787 if (aGeo.nShearAngle!=0)
789 ShearPoly(aPol,
790 aNewRect.TopLeft(),
791 aGeo.nTan);
792 ShearPoint(aOffset, Point(0,0), aGeo.nTan);
794 if (aGeo.nRotationAngle!=0)
796 RotatePoly(aPol,
797 aNewRect.TopLeft(),
798 aGeo.nSin,aGeo.nCos);
799 RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
802 // apply offset
803 aPol.Move( -aOffset.X(), -aOffset.Y() );
804 aNewRect=aPol.GetBoundRect();
806 else
808 aNewRect.Move( -aOffset.X(), -aOffset.Y() );
811 if( !aSet.Count() )
812 rView.SetMarkedObjRect( aNewRect );
813 else
815 if( bUndo )
817 rView.BegUndo( aUndoStr );
818 rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
820 pObj->SetSnapRect( aNewRect );
821 rView.SetAttributes( aSet );
823 if( bUndo )
824 rView.EndUndo();
825 aSet.ClearItem();
831 rPool.SetDefaultMetric( eOldMetric );
835 break;
837 case SID_COLOR_SETTINGS:
839 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
840 aToolboxAccess.toggleToolbox();
841 rReq.Done();
842 break;
845 default:
846 break;
849 if( aSet.Count() )
851 if( bUndo )
852 rView.BegUndo( aUndoStr );
854 rView.SetAttributes( aSet );
856 if( bUndo )
857 rView.EndUndo();
861 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet& rSet, SdrView& rView )
863 SfxItemPool& rPool = rView.GetModel()->GetItemPool();
864 SfxItemSet aAttrSet( rPool );
865 SfxWhichIter aIter( rSet );
866 sal_uInt16 nWhich = aIter.FirstWhich();
867 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
868 bool bEnableColors = true;
869 bool bEnableTransparency = true;
870 bool bEnableCrop = ( 1 == rMarkList.GetMarkCount() );
872 for( size_t i = 0, nCount = rMarkList.GetMarkCount(); i < nCount; ++i )
874 SdrGrafObj* pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( i )->GetMarkedSdrObj() );
876 if( !pGrafObj ||
877 ( pGrafObj->GetGraphicType() == GRAPHIC_NONE ) ||
878 ( pGrafObj->GetGraphicType() == GRAPHIC_DEFAULT ))
880 bEnableColors = bEnableTransparency = bEnableCrop = false;
881 break;
883 else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
885 bEnableTransparency = false;
889 rView.GetAttributes( aAttrSet );
891 while( nWhich )
893 sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
895 switch( nSlotId )
897 case( SID_ATTR_GRAF_MODE ):
899 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
901 if( bEnableColors )
903 rSet.Put( SfxUInt16Item( nSlotId,
904 sal::static_int_cast< sal_uInt16 >( ITEMVALUE( aAttrSet, SDRATTR_GRAFMODE, SdrGrafModeItem ) ) ) );
906 else
908 rSet.DisableItem( SID_ATTR_GRAF_MODE );
912 break;
914 case( SID_ATTR_GRAF_RED ):
916 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
918 if( bEnableColors )
920 rSet.Put( SfxInt16Item( nSlotId,
921 ITEMVALUE( aAttrSet, SDRATTR_GRAFRED, SdrGrafRedItem ) ) );
923 else
925 rSet.DisableItem( SID_ATTR_GRAF_RED );
929 break;
931 case( SID_ATTR_GRAF_GREEN ):
933 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
935 if( bEnableColors )
937 rSet.Put( SfxInt16Item( nSlotId,
938 ITEMVALUE( aAttrSet, SDRATTR_GRAFGREEN, SdrGrafGreenItem ) ) );
940 else
942 rSet.DisableItem( SID_ATTR_GRAF_GREEN );
946 break;
948 case( SID_ATTR_GRAF_BLUE ):
950 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
952 if( bEnableColors )
954 rSet.Put( SfxInt16Item( nSlotId,
955 ITEMVALUE( aAttrSet, SDRATTR_GRAFBLUE, SdrGrafBlueItem ) ) );
957 else
959 rSet.DisableItem( SID_ATTR_GRAF_BLUE );
963 break;
965 case( SID_ATTR_GRAF_LUMINANCE ):
967 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
969 if( bEnableColors )
971 rSet.Put( SfxInt16Item( nSlotId,
972 ITEMVALUE( aAttrSet, SDRATTR_GRAFLUMINANCE, SdrGrafLuminanceItem ) ) );
974 else
976 rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
980 break;
982 case( SID_ATTR_GRAF_CONTRAST ):
984 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
986 if( bEnableColors )
988 rSet.Put( SfxInt16Item( nSlotId,
989 ITEMVALUE( aAttrSet, SDRATTR_GRAFCONTRAST, SdrGrafContrastItem ) ) );
991 else
993 rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
997 break;
999 case( SID_ATTR_GRAF_GAMMA ):
1001 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
1003 if( bEnableColors )
1005 rSet.Put( SfxUInt32Item( nSlotId,
1006 ITEMVALUE( aAttrSet, SDRATTR_GRAFGAMMA, SdrGrafGamma100Item ) ) );
1008 else
1010 rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
1014 break;
1016 case( SID_ATTR_GRAF_TRANSPARENCE ):
1018 if( SfxItemState::DEFAULT <= aAttrSet.GetItemState( SDRATTR_GRAFTRANSPARENCE ) )
1020 if( bEnableTransparency )
1022 rSet.Put( SfxUInt16Item( nSlotId,
1023 ITEMVALUE( aAttrSet, SDRATTR_GRAFTRANSPARENCE, SdrGrafTransparenceItem ) ) );
1025 else
1027 rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
1031 break;
1033 case( SID_ATTR_GRAF_CROP ):
1035 if( !bEnableCrop )
1036 rSet.DisableItem( nSlotId );
1038 break;
1040 case SID_COLOR_SETTINGS :
1042 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1043 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
1044 break;
1047 default:
1048 break;
1051 nWhich = aIter.NextWhich();
1055 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */