1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include <vcl/toolbox.hxx>
33 #include <vcl/field.hxx>
34 #include <vcl/fixed.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svl/intitem.hxx>
37 #include <svl/eitem.hxx>
38 #include <svl/whiter.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/viewsh.hxx>
43 #include <sfx2/request.hxx>
44 #include <sfx2/basedlgs.hxx>
45 #include <tools/urlobj.hxx>
46 #include <comphelper/processfactory.hxx>
48 #include <svx/svxids.hrc>
49 #include "grafctrl.hrc"
50 #include <svx/dialogs.hrc>
51 #include <editeng/brshitem.hxx>
52 #include <editeng/sizeitem.hxx>
53 #include <svx/sdgcpitm.hxx>
55 #include <svx/itemwin.hxx>
56 #include <svx/dialmgr.hxx>
57 #include <svx/svdview.hxx>
58 #include <svx/svdmodel.hxx>
59 #include <svx/svdograf.hxx>
60 #include <svx/svdundo.hxx>
61 #include <svx/svdtrans.hxx>
62 #include "svx/grafctrl.hxx"
63 #include "svx/tbxcolor.hxx"
66 using ::rtl::OUString
;
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::frame
;
69 using namespace ::com::sun::star::util
;
70 using namespace ::com::sun::star::beans
;
71 using namespace ::com::sun::star::lang
;
73 #include <svx/svxdlg.hxx>
78 #define SYMBOL_TO_FIELD_OFFSET 4
79 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
80 #define TOOLBOX_NAME ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "colorbar" ) )
86 TYPEINIT1_AUTOFACTORY( TbxImageItem
, SfxUInt16Item
);
88 //---------------------------------------------------------
90 TbxImageItem::TbxImageItem( sal_uInt16 _nWhich
, sal_uInt16 nImage
) :
91 SfxUInt16Item( _nWhich
, nImage
)
95 //---------------------------------------------------------
97 SfxPoolItem
* TbxImageItem::Clone( SfxItemPool
* ) const
99 return new TbxImageItem( *this );
102 //---------------------------------------------------------
104 int TbxImageItem::operator==( const SfxPoolItem
& rItem
) const
106 return( ( (TbxImageItem
&) rItem
).GetValue() == GetValue() );
109 // -----------------------
110 // - ImplGrafMetricField -
111 // -----------------------
113 class ImplGrafMetricField
: public MetricField
115 using Window::Update
;
120 Reference
< XFrame
> mxFrame
;
122 DECL_LINK(ImplModifyHdl
, void *);
126 virtual void Modify();
130 ImplGrafMetricField( Window
* pParent
, const rtl::OUString
& aCmd
, const Reference
< XFrame
>& rFrame
);
131 ~ImplGrafMetricField();
133 void Update( const SfxPoolItem
* pItem
);
134 const OUString
& GetCommand() const { return maCommand
; }
137 // -----------------------------------------------------------------------------
139 ImplGrafMetricField::ImplGrafMetricField( Window
* pParent
, const rtl::OUString
& rCmd
, const Reference
< XFrame
>& rFrame
) :
140 MetricField( pParent
, WB_BORDER
| WB_SPIN
| WB_REPEAT
| WB_3DLOOK
),
144 Size
aSize( GetTextWidth( String::CreateFromAscii("-100 %") ), GetTextHeight() );
146 aSize
.Width() += 20, aSize
.Height() += 6;
147 SetSizePixel( aSize
);
149 if ( maCommand
== ".uno:GrafGamma" )
151 SetDecimalDigits( 2 );
161 const long nMinVal
= ( maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafTransparence" ) )) ? 0 : -100;
163 SetUnit( FUNIT_CUSTOM
);
164 SetCustomUnitText( String::CreateFromAscii(" %") );
165 SetDecimalDigits( 0 );
174 maTimer
.SetTimeout( 100 );
175 maTimer
.SetTimeoutHdl( LINK( this, ImplGrafMetricField
, ImplModifyHdl
) );
178 // -----------------------------------------------------------------------------
180 ImplGrafMetricField::~ImplGrafMetricField()
184 // -----------------------------------------------------------------------------
186 void ImplGrafMetricField::Modify()
191 // -----------------------------------------------------------------------------
193 IMPL_LINK_NOARG(ImplGrafMetricField
, ImplModifyHdl
)
195 const sal_Int64 nVal
= GetValue();
197 // Convert value to an any to be usable with dispatch API
199 if ( maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafRed" ) ) ||
200 maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafGreen" ) ) ||
201 maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafBlue" ) ) ||
202 maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafLuminance" ) ) ||
203 maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafContrast" ) ))
204 a
= makeAny( sal_Int16( nVal
));
205 else if ( maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafGamma" ) ) ||
206 maCommand
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafTransparence" ) ))
207 a
= makeAny( sal_Int32( nVal
));
211 INetURLObject
aObj( maCommand
);
213 Sequence
< PropertyValue
> aArgs( 1 );
214 aArgs
[0].Name
= aObj
.GetURLPath();
217 SfxToolBoxControl::Dispatch(
218 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
225 // -----------------------------------------------------------------------------
227 void ImplGrafMetricField::Update( const SfxPoolItem
* pItem
)
233 if ( maCommand
== ".uno:GrafTransparence" )
234 nValue
= ( (SfxUInt16Item
*) pItem
)->GetValue();
235 else if ( maCommand
== ".uno:GrafGamma" )
236 nValue
= ( (SfxUInt32Item
*) pItem
)->GetValue();
238 nValue
= ( (SfxInt16Item
*) pItem
)->GetValue();
246 // --------------------
247 // - ImplGrafControl -
248 // --------------------
252 const char* pCommand
;
256 static sal_uInt16
ImplGetRID( const OUString
& aCommand
)
258 static const CommandToRID aImplCommandToResMap
[] =
260 { ".uno:GrafRed", RID_SVXIMG_GRAF_RED
},
261 { ".uno:GrafGreen", RID_SVXIMG_GRAF_GREEN
},
262 { ".uno:GrafBlue", RID_SVXIMG_GRAF_BLUE
},
263 { ".uno:GrafLuminance", RID_SVXIMG_GRAF_LUMINANCE
},
264 { ".uno:GrafContrast", RID_SVXIMG_GRAF_CONTRAST
},
265 { ".uno:GrafGamma", RID_SVXIMG_GRAF_GAMMA
},
266 { ".uno:GrafTransparence", RID_SVXIMG_GRAF_TRANSPARENCE
},
273 while ( aImplCommandToResMap
[ i
].pCommand
)
275 if ( aCommand
.equalsAscii( aImplCommandToResMap
[ i
].pCommand
))
277 nRID
= aImplCommandToResMap
[ i
].nResId
;
286 // -----------------------------------------------------------------------------
288 class ImplGrafControl
: public Control
290 using Window::Update
;
293 ImplGrafMetricField maField
;
297 virtual void GetFocus();
301 ImplGrafControl( Window
* pParent
, const rtl::OUString
& rCmd
, const Reference
< XFrame
>& rFrame
);
304 void Update( const SfxPoolItem
* pItem
) { maField
.Update( pItem
); }
305 void SetText( const String
& rStr
) { maField
.SetText( rStr
); }
308 // -----------------------------------------------------------------------------
310 ImplGrafControl::ImplGrafControl(
312 const rtl::OUString
& rCmd
,
313 const Reference
< XFrame
>& rFrame
314 ) : Control( pParent
, WB_TABSTOP
)
316 , maField( this, rCmd
, rFrame
)
318 ResId
aResId( ImplGetRID( rCmd
), DIALOG_MGR() ) ;
319 Image
aImage( aResId
);
321 Size
aImgSize( aImage
.GetSizePixel() );
322 Size
aFldSize( maField
.GetSizePixel() );
325 maImage
.SetImage( aImage
);
326 maImage
.SetSizePixel( aImgSize
);
327 // we want to see the backbround of the toolbox, not of the FixedImage or Control
328 maImage
.SetBackground( Wallpaper( COL_TRANSPARENT
) );
329 SetBackground( Wallpaper( COL_TRANSPARENT
) );
331 if( aImgSize
.Height() > aFldSize
.Height() )
332 nImgY
= 0, nFldY
= ( aImgSize
.Height() - aFldSize
.Height() ) >> 1;
334 nFldY
= 0, nImgY
= ( aFldSize
.Height() - aImgSize
.Height() ) >> 1;
336 long nOffset
= SYMBOL_TO_FIELD_OFFSET
/ 2;
337 maImage
.SetPosPixel( Point( nOffset
, nImgY
) );
338 maField
.SetPosPixel( Point( aImgSize
.Width() + SYMBOL_TO_FIELD_OFFSET
, nFldY
) );
339 SetSizePixel( Size( aImgSize
.Width() + aFldSize
.Width() + SYMBOL_TO_FIELD_OFFSET
+ nOffset
,
340 Max( aImgSize
.Height(), aFldSize
.Height() ) ) );
342 SetBackground( Wallpaper() ); // transparent background
346 maField
.SetHelpId( rtl::OUStringToOString( rCmd
, RTL_TEXTENCODING_UTF8
) );
350 // -----------------------------------------------------------------------------
352 ImplGrafControl::~ImplGrafControl()
356 // -----------------------------------------------------------------------------
358 void ImplGrafControl::GetFocus()
363 // -----------------------
364 // - ImplGrafModeControl -
365 // -----------------------
367 class ImplGrafModeControl
: public ListBox
369 using Window::Update
;
372 Reference
< XFrame
> mxFrame
;
374 virtual void Select();
375 virtual long PreNotify( NotifyEvent
& rNEvt
);
376 virtual long Notify( NotifyEvent
& rNEvt
);
377 void ImplReleaseFocus();
381 ImplGrafModeControl( Window
* pParent
, const Reference
< XFrame
>& rFrame
);
382 ~ImplGrafModeControl();
384 void Update( const SfxPoolItem
* pItem
);
387 // -----------------------------------------------------------------------------
389 ImplGrafModeControl::ImplGrafModeControl( Window
* pParent
, const Reference
< XFrame
>& rFrame
) :
390 ListBox( pParent
, WB_BORDER
| WB_DROPDOWN
| WB_AUTOHSCROLL
),
394 SetSizePixel( Size( 100, 260 ) );
396 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_STANDARD
) );
397 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_GREYS
) );
398 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_MONO
) );
399 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_WATERMARK
) );
404 // -----------------------------------------------------------------------
406 ImplGrafModeControl::~ImplGrafModeControl()
410 // -----------------------------------------------------------------------
412 void ImplGrafModeControl::Select()
414 if ( !IsTravelSelect() )
416 Sequence
< PropertyValue
> aArgs( 1 );
417 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GrafMode" ));
418 aArgs
[0].Value
= makeAny( sal_Int16( GetSelectEntryPos() ));
420 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
421 This instance may be deleted in the meantime (i.e. when a dialog is opened
422 while in Dispatch()), accessing members will crash in this case. */
425 SfxToolBoxControl::Dispatch(
426 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
427 OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GrafMode" )),
432 // -----------------------------------------------------------------------
434 long ImplGrafModeControl::PreNotify( NotifyEvent
& rNEvt
)
436 sal_uInt16 nType
= rNEvt
.GetType();
438 if( EVENT_MOUSEBUTTONDOWN
== nType
|| EVENT_GETFOCUS
== nType
)
439 mnCurPos
= GetSelectEntryPos();
441 return ListBox::PreNotify( rNEvt
);
444 // -----------------------------------------------------------------------
446 long ImplGrafModeControl::Notify( NotifyEvent
& rNEvt
)
448 long nHandled
= ListBox::Notify( rNEvt
);
450 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
452 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
454 switch( pKEvt
->GetKeyCode().GetCode() )
465 SelectEntryPos( mnCurPos
);
476 // -----------------------------------------------------------------------
478 void ImplGrafModeControl::ImplReleaseFocus()
480 if( SfxViewShell::Current() )
482 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
485 pShellWnd
->GrabFocus();
489 // -----------------------------------------------------------------------
491 void ImplGrafModeControl::Update( const SfxPoolItem
* pItem
)
494 SelectEntryPos( ((SfxUInt16Item
*)pItem
)->GetValue() );
499 // -------------------------------
500 // - SvxGrafFilterToolBoxControl -
501 // -------------------------------
503 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafFilterToolBoxControl
, TbxImageItem
);
505 // -----------------------------------------------------------------------------
507 SvxGrafFilterToolBoxControl::SvxGrafFilterToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
508 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
510 rTbx
.SetItemBits( nId
, TIB_DROPDOWNONLY
| rTbx
.GetItemBits( nId
) );
514 // -----------------------------------------------------------------------------
516 SvxGrafFilterToolBoxControl::~SvxGrafFilterToolBoxControl()
520 // -----------------------------------------------------------------------------
522 void SvxGrafFilterToolBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* )
524 GetToolBox().EnableItem( GetId(), ( eState
!= SFX_ITEM_DISABLED
) );
527 // -----------------------------------------------------------------------------
529 SfxPopupWindowType
SvxGrafFilterToolBoxControl::GetPopupWindowType() const
531 return SFX_POPUPWINDOW_ONCLICK
;
534 // -----------------------------------------------------------------------------
536 SfxPopupWindow
* SvxGrafFilterToolBoxControl::CreatePopupWindow()
538 rtl::OUString
aSubTbxResName(
539 RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/graffilterbar" ) );
540 createAndPositionSubToolBar( aSubTbxResName
);
545 // -------------------------
546 // - SvxGrafToolBoxControl -
547 // -------------------------
549 // -----------------------------------------------------------------------------
551 SvxGrafToolBoxControl::SvxGrafToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
552 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
554 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
558 // -----------------------------------------------------------------------------
560 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
564 // -----------------------------------------------------------------------------
566 void SvxGrafToolBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
569 ImplGrafControl
* pCtrl
= (ImplGrafControl
*) GetToolBox().GetItemWindow( GetId() );
570 DBG_ASSERT( pCtrl
, "Control not found" );
572 if( eState
== SFX_ITEM_DISABLED
)
575 pCtrl
->SetText( String() );
581 if( eState
== SFX_ITEM_AVAILABLE
)
582 pCtrl
->Update( pState
);
584 pCtrl
->Update( NULL
);
588 // -----------------------------------------------------------------------------
590 Window
* SvxGrafToolBoxControl::CreateItemWindow( Window
*pParent
)
592 return( new ImplGrafControl( pParent
, m_aCommandURL
, m_xFrame
) );
595 // ----------------------------
596 // - SvxGrafRedToolBoxControl -
597 // ----------------------------
599 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl
, SfxInt16Item
);
601 // -----------------------------------------------------------------------------
603 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
604 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
608 // ------------------------------
609 // - SvxGrafGreenToolBoxControl -
610 // ------------------------------
612 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl
, SfxInt16Item
);
614 // -----------------------------------------------------------------------------
616 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
617 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
621 // -----------------------------
622 // - SvxGrafBlueToolBoxControl -
623 // -----------------------------
625 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl
, SfxInt16Item
);
627 // -----------------------------------------------------------------------------
629 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
630 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
634 // ----------------------------------
635 // - SvxGrafLuminanceToolBoxControl -
636 // ----------------------------------
638 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl
, SfxInt16Item
);
640 // -----------------------------------------------------------------------------
642 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
643 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
647 // ----------------------------------
648 // - SvxGrafContrastToolBoxControl -
649 // ----------------------------------
651 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl
, SfxInt16Item
);
653 // -----------------------------------------------------------------------------
655 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
656 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
660 // ------------------------------
661 // - SvxGrafGammaToolBoxControl -
662 // ------------------------------
664 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl
, SfxUInt32Item
);
666 // -----------------------------------------------------------------------------
668 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
669 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
673 // -------------------------------------
674 // - SvxGrafTransparenceToolBoxControl -
675 // -------------------------------------
677 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl
, SfxUInt16Item
);
679 // -----------------------------------------------------------------------------
681 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
682 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
686 // -----------------------------
687 // - SvxGrafModeToolBoxControl -
688 // -----------------------------
690 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl
, SfxUInt16Item
);
692 // -----------------------------------------------------------------------------
694 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
695 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
699 // -----------------------------------------------------------------------------
701 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
705 // -----------------------------------------------------------------------------
707 void SvxGrafModeToolBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
710 ImplGrafModeControl
* pCtrl
= (ImplGrafModeControl
*) GetToolBox().GetItemWindow( GetId() );
711 DBG_ASSERT( pCtrl
, "Control not found" );
713 if( eState
== SFX_ITEM_DISABLED
)
716 pCtrl
->SetText( String() );
722 if( eState
== SFX_ITEM_AVAILABLE
)
723 pCtrl
->Update( pState
);
725 pCtrl
->Update( NULL
);
729 // -----------------------------------------------------------------------------
731 Window
* SvxGrafModeToolBoxControl::CreateItemWindow( Window
*pParent
)
733 return( new ImplGrafModeControl( pParent
, m_xFrame
) );
736 // ---------------------
737 // - SvxGrafAttrHelper -
738 // ---------------------
740 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest
& rReq
, SdrView
& rView
)
742 SfxItemPool
& rPool
= rView
.GetModel()->GetItemPool();
743 SfxItemSet
aSet( rPool
, SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
);
745 const bool bUndo
= rView
.IsUndoEnabled();
749 aUndoStr
= rView
.GetDescriptionOfMarkedObjects();
750 aUndoStr
.Append( sal_Unicode(' ') );
753 const SfxItemSet
* pArgs
= rReq
.GetArgs();
754 const SfxPoolItem
* pItem
;
755 sal_uInt16 nSlot
= rReq
.GetSlot();
757 if( !pArgs
|| SFX_ITEM_SET
!= pArgs
->GetItemState( nSlot
, sal_False
, &pItem
))
762 case SID_ATTR_GRAF_RED
:
766 aSet
.Put( SdrGrafRedItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
768 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED
) ) );
773 case SID_ATTR_GRAF_GREEN
:
777 aSet
.Put( SdrGrafGreenItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
779 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN
) ) );
784 case SID_ATTR_GRAF_BLUE
:
788 aSet
.Put( SdrGrafBlueItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
790 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE
) ) );
795 case SID_ATTR_GRAF_LUMINANCE
:
799 aSet
.Put( SdrGrafLuminanceItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
801 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE
) ) );
806 case SID_ATTR_GRAF_CONTRAST
:
810 aSet
.Put( SdrGrafContrastItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
812 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST
) ) );
817 case SID_ATTR_GRAF_GAMMA
:
821 aSet
.Put( SdrGrafGamma100Item( ((SfxUInt32Item
*)pItem
)->GetValue() ));
823 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA
) ) );
828 case SID_ATTR_GRAF_TRANSPARENCE
:
832 aSet
.Put( SdrGrafTransparenceItem( ((SfxUInt16Item
*)pItem
)->GetValue() ));
834 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY
) ) );
839 case SID_ATTR_GRAF_MODE
:
843 aSet
.Put( SdrGrafModeItem( (GraphicDrawMode
) ((SfxUInt16Item
*)pItem
)->GetValue() ));
845 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE
) ) );
850 case( SID_ATTR_GRAF_CROP
):
852 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
854 if( 0 < rMarkList
.GetMarkCount() )
856 SdrGrafObj
* pObj
= (SdrGrafObj
*) rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
858 if( pObj
&& pObj
->ISA( SdrGrafObj
) &&
859 ( pObj
->GetGraphicType() != GRAPHIC_NONE
) &&
860 ( pObj
->GetGraphicType() != GRAPHIC_DEFAULT
) )
862 SfxItemSet
aGrfAttr( rPool
, SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
, 0 );
863 const SfxMapUnit eOldMetric
= rPool
.GetMetric( 0 );
864 const MapMode
aMap100( MAP_100TH_MM
);
865 const MapMode
aMapTwip( MAP_TWIP
);
867 aGrfAttr
.Put(pObj
->GetMergedItemSet());
868 rPool
.SetDefaultMetric( SFX_MAPUNIT_TWIP
);
870 SfxItemSet
aCropDlgAttr( rPool
,
871 SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
,
872 SID_ATTR_GRAF_GRAPHIC
, SID_ATTR_GRAF_GRAPHIC
,
873 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
874 SID_ATTR_GRAF_FRMSIZE
, SID_ATTR_GRAF_FRMSIZE
,
875 SID_ATTR_GRAF_CROP
, SID_ATTR_GRAF_CROP
, 0 );
877 aCropDlgAttr
.Put( SvxBrushItem( pObj
->GetGraphic(), GPOS_MM
, SID_ATTR_GRAF_GRAPHIC
) );
878 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE
,
879 Size( OutputDevice::LogicToLogic(
880 Size( 200000, 200000 ), aMap100
, aMapTwip
) ) ) );
881 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE
, OutputDevice::LogicToLogic(
882 pObj
->GetLogicRect().GetSize(), aMap100
, aMapTwip
) ) );
884 const SdrGrafCropItem
& rCrop
= (const SdrGrafCropItem
&) aGrfAttr
.Get( SDRATTR_GRAFCROP
);
885 Size
aLTSize( OutputDevice::LogicToLogic(
886 Size( rCrop
.GetLeft(), rCrop
.GetTop() ), aMap100
, aMapTwip
) );
887 Size
aRBSize( OutputDevice::LogicToLogic(
888 Size( rCrop
.GetRight(), rCrop
.GetBottom() ), aMap100
, aMapTwip
) );
890 aCropDlgAttr
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(),
891 aRBSize
.Width(), aRBSize
.Height() ) );
893 SfxSingleTabDialog
aCropDialog( SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : NULL
,
895 const String aCropStr
= SVX_RESSTR( RID_SVXSTR_GRAFCROP
);
897 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
898 DBG_ASSERT(pFact
, "Dialogdiet error!");
899 ::CreateTabPage fnCreatePage
= pFact
->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP
);
900 DBG_ASSERT(fnCreatePage
, "Dialogdiet error!");
901 SfxTabPage
* pTabPage
= (*fnCreatePage
)( &aCropDialog
, aCropDlgAttr
);
903 pTabPage
->SetText( aCropStr
);
904 aCropDialog
.SetTabPage( pTabPage
);
906 if( aCropDialog
.Execute() == RET_OK
)
908 const SfxItemSet
* pOutAttr
= aCropDialog
.GetOutputItemSet();
912 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCROP
) ) );
914 // set crop attributes
915 if( SFX_ITEM_SET
<= pOutAttr
->GetItemState( SDRATTR_GRAFCROP
) )
917 const SdrGrafCropItem
& rNewCrop
= (const SdrGrafCropItem
&) pOutAttr
->Get( SDRATTR_GRAFCROP
);
919 aLTSize
= OutputDevice::LogicToLogic( Size( rNewCrop
.GetLeft(), rNewCrop
.GetTop() ), aMapTwip
, aMap100
);
920 aRBSize
= OutputDevice::LogicToLogic( Size( rNewCrop
.GetRight(), rNewCrop
.GetBottom() ), aMapTwip
, aMap100
);
921 aSet
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(), aRBSize
.Width(), aRBSize
.Height() ) );
924 // set new logic rect
925 if( SFX_ITEM_SET
<= pOutAttr
->GetItemState( SID_ATTR_GRAF_FRMSIZE
) )
927 Point
aNewOrigin( pObj
->GetLogicRect().TopLeft() );
928 const Size
& rGrfSize
= ( (const SvxSizeItem
&) pOutAttr
->Get( SID_ATTR_GRAF_FRMSIZE
) ).GetSize();
929 Size
aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize
, aMapTwip
, aMap100
) );
930 Size
aOldGrfSize( pObj
->GetLogicRect().GetSize() );
932 Rectangle
aNewRect( aNewOrigin
, aNewGrfSize
);
933 Point
aOffset( (aNewGrfSize
.Width() - aOldGrfSize
.Width()) >> 1,
934 (aNewGrfSize
.Height() - aOldGrfSize
.Height()) >> 1 );
936 // #106181# rotate snap rect before setting it
937 const GeoStat
& aGeo
= pObj
->GetGeoStat();
939 if (aGeo
.nDrehWink
!=0 || aGeo
.nShearWink
!=0)
941 Polygon
aPol(aNewRect
);
943 // also transform origin offset
944 if (aGeo
.nShearWink
!=0)
949 ShearPoint(aOffset
, Point(0,0), aGeo
.nTan
);
951 if (aGeo
.nDrehWink
!=0)
955 aGeo
.nSin
,aGeo
.nCos
);
956 RotatePoint(aOffset
, Point(0,0), aGeo
.nSin
,aGeo
.nCos
);
960 aPol
.Move( -aOffset
.X(), -aOffset
.Y() );
961 aNewRect
=aPol
.GetBoundRect();
965 aNewRect
.Move( -aOffset
.X(), -aOffset
.Y() );
969 rView
.SetMarkedObjRect( aNewRect
);
974 rView
.BegUndo( aUndoStr
);
975 rView
.AddUndo( rView
.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj
) );
977 pObj
->SetSnapRect( aNewRect
);
978 rView
.SetAttributes( aSet
);
988 rPool
.SetDefaultMetric( eOldMetric
);
994 case SID_COLOR_SETTINGS
:
996 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
997 aToolboxAccess
.toggleToolbox();
1009 rView
.BegUndo( aUndoStr
);
1011 rView
.SetAttributes( aSet
);
1018 // -----------------------------------------------------------------------------
1020 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet
& rSet
, SdrView
& rView
)
1022 SfxItemPool
& rPool
= rView
.GetModel()->GetItemPool();
1023 SfxItemSet
aAttrSet( rPool
);
1024 SfxWhichIter
aIter( rSet
);
1025 sal_uInt16 nWhich
= aIter
.FirstWhich();
1026 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
1027 bool bEnableColors
= true;
1028 bool bEnableTransparency
= true;
1029 bool bEnableCrop
= ( 1 == rMarkList
.GetMarkCount() );
1031 for( int i
= 0, nCount
= rMarkList
.GetMarkCount(); i
< nCount
; ++i
)
1033 SdrGrafObj
* pGrafObj
= dynamic_cast< SdrGrafObj
* >( rMarkList
.GetMark( i
)->GetMarkedSdrObj() );
1036 ( pGrafObj
->GetGraphicType() == GRAPHIC_NONE
) ||
1037 ( pGrafObj
->GetGraphicType() == GRAPHIC_DEFAULT
) ||
1038 pGrafObj
->HasRenderGraphic() )
1040 bEnableColors
= bEnableTransparency
= bEnableCrop
= false;
1043 else if( bEnableTransparency
&& ( pGrafObj
->HasGDIMetaFile() || pGrafObj
->IsAnimated() ) )
1045 bEnableTransparency
= false;
1049 rView
.GetAttributes( aAttrSet
);
1053 sal_uInt16 nSlotId
= SfxItemPool::IsWhich( nWhich
) ? rPool
.GetSlotId( nWhich
) : nWhich
;
1057 case( SID_ATTR_GRAF_MODE
):
1059 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFMODE
) )
1063 rSet
.Put( SfxUInt16Item( nSlotId
,
1064 sal::static_int_cast
< sal_uInt16
>( ITEMVALUE( aAttrSet
, SDRATTR_GRAFMODE
, SdrGrafModeItem
) ) ) );
1068 rSet
.DisableItem( SID_ATTR_GRAF_MODE
);
1074 case( SID_ATTR_GRAF_RED
):
1076 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFRED
) )
1080 rSet
.Put( SfxInt16Item( nSlotId
,
1081 ITEMVALUE( aAttrSet
, SDRATTR_GRAFRED
, SdrGrafRedItem
) ) );
1085 rSet
.DisableItem( SID_ATTR_GRAF_RED
);
1091 case( SID_ATTR_GRAF_GREEN
):
1093 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFGREEN
) )
1097 rSet
.Put( SfxInt16Item( nSlotId
,
1098 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGREEN
, SdrGrafGreenItem
) ) );
1102 rSet
.DisableItem( SID_ATTR_GRAF_GREEN
);
1108 case( SID_ATTR_GRAF_BLUE
):
1110 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFBLUE
) )
1114 rSet
.Put( SfxInt16Item( nSlotId
,
1115 ITEMVALUE( aAttrSet
, SDRATTR_GRAFBLUE
, SdrGrafBlueItem
) ) );
1119 rSet
.DisableItem( SID_ATTR_GRAF_BLUE
);
1125 case( SID_ATTR_GRAF_LUMINANCE
):
1127 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFLUMINANCE
) )
1131 rSet
.Put( SfxInt16Item( nSlotId
,
1132 ITEMVALUE( aAttrSet
, SDRATTR_GRAFLUMINANCE
, SdrGrafLuminanceItem
) ) );
1136 rSet
.DisableItem( SID_ATTR_GRAF_LUMINANCE
);
1142 case( SID_ATTR_GRAF_CONTRAST
):
1144 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFCONTRAST
) )
1148 rSet
.Put( SfxInt16Item( nSlotId
,
1149 ITEMVALUE( aAttrSet
, SDRATTR_GRAFCONTRAST
, SdrGrafContrastItem
) ) );
1153 rSet
.DisableItem( SID_ATTR_GRAF_CONTRAST
);
1159 case( SID_ATTR_GRAF_GAMMA
):
1161 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFGAMMA
) )
1165 rSet
.Put( SfxUInt32Item( nSlotId
,
1166 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGAMMA
, SdrGrafGamma100Item
) ) );
1170 rSet
.DisableItem( SID_ATTR_GRAF_GAMMA
);
1176 case( SID_ATTR_GRAF_TRANSPARENCE
):
1178 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFTRANSPARENCE
) )
1180 if( bEnableTransparency
)
1182 rSet
.Put( SfxUInt16Item( nSlotId
,
1183 ITEMVALUE( aAttrSet
, SDRATTR_GRAFTRANSPARENCE
, SdrGrafTransparenceItem
) ) );
1187 rSet
.DisableItem( SID_ATTR_GRAF_TRANSPARENCE
);
1193 case( SID_ATTR_GRAF_CROP
):
1196 rSet
.DisableItem( nSlotId
);
1200 case SID_COLOR_SETTINGS
:
1202 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
1203 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
1211 nWhich
= aIter
.NextWhich();
1215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */