1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
92 Reference
< XFrame
> mxFrame
;
94 DECL_LINK_TYPED(ImplModifyHdl
, Idle
*, void);
98 virtual void Modify() SAL_OVERRIDE
;
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
),
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 );
128 const long nMinVal
= maCommand
== ".uno:GrafTransparence" ? 0 : -100;
130 SetUnit(FUNIT_PERCENT
);
131 SetDecimalDigits( 0 );
140 maIdle
.SetPriority( SchedulerPriority::LOW
);
141 maIdle
.SetIdleHdl( LINK( this, ImplGrafMetricField
, ImplModifyHdl
) );
144 void ImplGrafMetricField::Modify()
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
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
));
167 INetURLObject
aObj( maCommand
);
169 Sequence
< PropertyValue
> aArgs( 1 );
170 aArgs
[0].Name
= aObj
.GetURLPath();
173 SfxToolBoxControl::Dispatch(
174 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
180 void ImplGrafMetricField::Update( const SfxPoolItem
* pItem
)
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();
191 nValue
= static_cast<const SfxInt16Item
*>( pItem
)->GetValue();
196 SetText( OUString() );
201 const char* pCommand
;
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
},
222 while ( aImplCommandToResMap
[ i
].pCommand
)
224 if ( aCommand
.equalsAscii( aImplCommandToResMap
[ i
].pCommand
))
226 nRID
= aImplCommandToResMap
[ i
].nResId
;
235 class ImplGrafControl
: public Control
237 using Window::Update
;
239 VclPtr
<FixedImage
> maImage
;
240 VclPtr
<ImplGrafMetricField
> maField
;
244 virtual void GetFocus() SAL_OVERRIDE
;
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() );
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;
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
292 maField
->SetHelpId( OUStringToOString( rCmd
, RTL_TEXTENCODING_UTF8
) );
296 ImplGrafControl::~ImplGrafControl()
301 void ImplGrafControl::dispose()
303 maImage
.disposeAndClear();
304 maField
.disposeAndClear();
308 void ImplGrafControl::GetFocus()
311 maField
->GrabFocus();
314 class ImplGrafModeControl
: public ListBox
316 using Window::Update
;
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();
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
),
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
) );
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. */
360 SfxToolBoxControl::Dispatch(
361 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
362 OUString( ".uno:GrafMode" ),
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() )
396 SelectEntryPos( mnCurPos
);
407 void ImplGrafModeControl::ImplReleaseFocus()
409 if( SfxViewShell::Current() )
411 vcl::Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
414 pShellWnd
->GrabFocus();
418 void ImplGrafModeControl::Update( const SfxPoolItem
* pItem
)
421 SelectEntryPos( static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() );
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
) );
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
);
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
) );
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
)
477 pCtrl
->SetText( OUString() );
483 if( eState
== SfxItemState::DEFAULT
)
484 pCtrl
->Update( pState
);
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
)
564 pCtrl
->SetText( OUString() );
570 if( eState
== SfxItemState::DEFAULT
)
571 pCtrl
->Update( pState
);
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
);
587 const bool bUndo
= rView
.IsUndoEnabled();
591 aUndoStr
= rView
.GetDescriptionOfMarkedObjects();
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
))
604 case SID_ATTR_GRAF_RED
:
608 aSet
.Put( SdrGrafRedItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
610 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED
);
615 case SID_ATTR_GRAF_GREEN
:
619 aSet
.Put( SdrGrafGreenItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
621 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN
);
626 case SID_ATTR_GRAF_BLUE
:
630 aSet
.Put( SdrGrafBlueItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
632 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE
);
637 case SID_ATTR_GRAF_LUMINANCE
:
641 aSet
.Put( SdrGrafLuminanceItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
643 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE
);
648 case SID_ATTR_GRAF_CONTRAST
:
652 aSet
.Put( SdrGrafContrastItem( static_cast<const SfxInt16Item
*>(pItem
)->GetValue() ));
654 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST
);
659 case SID_ATTR_GRAF_GAMMA
:
663 aSet
.Put( SdrGrafGamma100Item( static_cast<const SfxUInt32Item
*>(pItem
)->GetValue() ));
665 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA
);
670 case SID_ATTR_GRAF_TRANSPARENCE
:
674 aSet
.Put( SdrGrafTransparenceItem( static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() ));
676 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY
);
681 case SID_ATTR_GRAF_MODE
:
685 aSet
.Put( SdrGrafModeItem( (GraphicDrawMode
) static_cast<const SfxUInt16Item
*>(pItem
)->GetValue() ));
687 aUndoStr
+= SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE
);
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
,
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();
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)
792 ShearPoint(aOffset
, Point(0,0), aGeo
.nTan
);
794 if (aGeo
.nRotationAngle
!=0)
798 aGeo
.nSin
,aGeo
.nCos
);
799 RotatePoint(aOffset
, Point(0,0), aGeo
.nSin
,aGeo
.nCos
);
803 aPol
.Move( -aOffset
.X(), -aOffset
.Y() );
804 aNewRect
=aPol
.GetBoundRect();
808 aNewRect
.Move( -aOffset
.X(), -aOffset
.Y() );
812 rView
.SetMarkedObjRect( aNewRect
);
817 rView
.BegUndo( aUndoStr
);
818 rView
.AddUndo( rView
.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj
) );
820 pObj
->SetSnapRect( aNewRect
);
821 rView
.SetAttributes( aSet
);
831 rPool
.SetDefaultMetric( eOldMetric
);
837 case SID_COLOR_SETTINGS
:
839 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
840 aToolboxAccess
.toggleToolbox();
852 rView
.BegUndo( aUndoStr
);
854 rView
.SetAttributes( aSet
);
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() );
877 ( pGrafObj
->GetGraphicType() == GRAPHIC_NONE
) ||
878 ( pGrafObj
->GetGraphicType() == GRAPHIC_DEFAULT
))
880 bEnableColors
= bEnableTransparency
= bEnableCrop
= false;
883 else if( bEnableTransparency
&& ( pGrafObj
->HasGDIMetaFile() || pGrafObj
->IsAnimated() ) )
885 bEnableTransparency
= false;
889 rView
.GetAttributes( aAttrSet
);
893 sal_uInt16 nSlotId
= SfxItemPool::IsWhich( nWhich
) ? rPool
.GetSlotId( nWhich
) : nWhich
;
897 case( SID_ATTR_GRAF_MODE
):
899 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFMODE
) )
903 rSet
.Put( SfxUInt16Item( nSlotId
,
904 sal::static_int_cast
< sal_uInt16
>( ITEMVALUE( aAttrSet
, SDRATTR_GRAFMODE
, SdrGrafModeItem
) ) ) );
908 rSet
.DisableItem( SID_ATTR_GRAF_MODE
);
914 case( SID_ATTR_GRAF_RED
):
916 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFRED
) )
920 rSet
.Put( SfxInt16Item( nSlotId
,
921 ITEMVALUE( aAttrSet
, SDRATTR_GRAFRED
, SdrGrafRedItem
) ) );
925 rSet
.DisableItem( SID_ATTR_GRAF_RED
);
931 case( SID_ATTR_GRAF_GREEN
):
933 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGREEN
) )
937 rSet
.Put( SfxInt16Item( nSlotId
,
938 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGREEN
, SdrGrafGreenItem
) ) );
942 rSet
.DisableItem( SID_ATTR_GRAF_GREEN
);
948 case( SID_ATTR_GRAF_BLUE
):
950 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFBLUE
) )
954 rSet
.Put( SfxInt16Item( nSlotId
,
955 ITEMVALUE( aAttrSet
, SDRATTR_GRAFBLUE
, SdrGrafBlueItem
) ) );
959 rSet
.DisableItem( SID_ATTR_GRAF_BLUE
);
965 case( SID_ATTR_GRAF_LUMINANCE
):
967 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFLUMINANCE
) )
971 rSet
.Put( SfxInt16Item( nSlotId
,
972 ITEMVALUE( aAttrSet
, SDRATTR_GRAFLUMINANCE
, SdrGrafLuminanceItem
) ) );
976 rSet
.DisableItem( SID_ATTR_GRAF_LUMINANCE
);
982 case( SID_ATTR_GRAF_CONTRAST
):
984 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFCONTRAST
) )
988 rSet
.Put( SfxInt16Item( nSlotId
,
989 ITEMVALUE( aAttrSet
, SDRATTR_GRAFCONTRAST
, SdrGrafContrastItem
) ) );
993 rSet
.DisableItem( SID_ATTR_GRAF_CONTRAST
);
999 case( SID_ATTR_GRAF_GAMMA
):
1001 if( SfxItemState::DEFAULT
<= aAttrSet
.GetItemState( SDRATTR_GRAFGAMMA
) )
1005 rSet
.Put( SfxUInt32Item( nSlotId
,
1006 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGAMMA
, SdrGrafGamma100Item
) ) );
1010 rSet
.DisableItem( SID_ATTR_GRAF_GAMMA
);
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
) ) );
1027 rSet
.DisableItem( SID_ATTR_GRAF_TRANSPARENCE
);
1033 case( SID_ATTR_GRAF_CROP
):
1036 rSet
.DisableItem( nSlotId
);
1040 case SID_COLOR_SETTINGS
:
1042 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
1043 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
1051 nWhich
= aIter
.NextWhich();
1055 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */