1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grafctrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
36 #ifndef _TOOLBOX_HXX //autogen
37 #include <vcl/toolbox.hxx>
39 #ifndef _FIELD_HXX //autogen
40 #include <vcl/field.hxx>
42 #include <vcl/fixed.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <svtools/intitem.hxx>
45 #include <svtools/eitem.hxx>
46 #include <svtools/whiter.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <sfx2/viewsh.hxx>
51 #include <sfx2/request.hxx>
52 #include <sfx2/basedlgs.hxx>
53 #include <tools/urlobj.hxx>
54 #include <comphelper/processfactory.hxx>
56 #include <svx/svxids.hrc>
57 #include "grafctrl.hrc"
58 #include <svx/dialogs.hrc>
59 #include <svx/brshitem.hxx>
60 #include <svx/sizeitem.hxx>
61 #include <svx/sdgcpitm.hxx>
62 //CHINA001 #include "../dialog/grfpage.hxx"
63 #include <svx/itemwin.hxx>
64 #include <svx/dialmgr.hxx>
65 #include <svx/svdview.hxx>
66 #include <svx/svdmodel.hxx>
67 #include <svx/svdograf.hxx>
68 #include <svx/svdundo.hxx>
69 #include <svx/svdtrans.hxx>
70 #include "grafctrl.hxx"
71 #include "tbxcolor.hxx"
74 using ::rtl::OUString
;
75 using namespace ::com::sun::star::uno
;
76 using namespace ::com::sun::star::frame
;
77 using namespace ::com::sun::star::util
;
78 using namespace ::com::sun::star::beans
;
79 using namespace ::com::sun::star::lang
;
81 #include <svx/svxdlg.hxx> //CHINA001
86 #define SYMBOL_TO_FIELD_OFFSET 4
87 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
88 #define TOOLBOX_NAME ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "colorbar" ) )
94 TYPEINIT1_AUTOFACTORY( TbxImageItem
, SfxUInt16Item
);
96 //---------------------------------------------------------
98 TbxImageItem::TbxImageItem( USHORT _nWhich
, UINT16 nImage
) :
99 SfxUInt16Item( _nWhich
, nImage
)
103 //---------------------------------------------------------
105 SfxPoolItem
* TbxImageItem::Clone( SfxItemPool
* ) const
107 return new TbxImageItem( *this );
110 //---------------------------------------------------------
112 int TbxImageItem::operator==( const SfxPoolItem
& rItem
) const
114 return( ( (TbxImageItem
&) rItem
).GetValue() == GetValue() );
117 // -----------------------
118 // - ImplGrafMetricField -
119 // -----------------------
121 class ImplGrafMetricField
: public MetricField
123 using Window::Update
;
128 Reference
< XFrame
> mxFrame
;
130 DECL_LINK( ImplModifyHdl
, Timer
* );
134 virtual void Modify();
138 ImplGrafMetricField( Window
* pParent
, const rtl::OUString
& aCmd
, const Reference
< XFrame
>& rFrame
);
139 ~ImplGrafMetricField();
141 void Update( const SfxPoolItem
* pItem
);
142 const OUString
& GetCommand() const { return maCommand
; }
145 // -----------------------------------------------------------------------------
147 ImplGrafMetricField::ImplGrafMetricField( Window
* pParent
, const rtl::OUString
& rCmd
, const Reference
< XFrame
>& rFrame
) :
148 MetricField( pParent
, WB_BORDER
| WB_SPIN
| WB_REPEAT
| WB_3DLOOK
),
152 Size
aSize( GetTextWidth( String::CreateFromAscii("-100 %") ), GetTextHeight() );
154 aSize
.Width() += 20, aSize
.Height() += 6;
155 SetSizePixel( aSize
);
157 if ( maCommand
.equalsAscii( ".uno:GrafGamma" ))
159 SetDecimalDigits( 2 );
169 const long nMinVal
= ( maCommand
.equalsAscii( ".uno:GrafTransparence" )) ? 0 : -100;
171 SetUnit( FUNIT_CUSTOM
);
172 SetCustomUnitText( String::CreateFromAscii(" %") );
173 SetDecimalDigits( 0 );
182 maTimer
.SetTimeout( 100 );
183 maTimer
.SetTimeoutHdl( LINK( this, ImplGrafMetricField
, ImplModifyHdl
) );
186 // -----------------------------------------------------------------------------
188 ImplGrafMetricField::~ImplGrafMetricField()
192 // -----------------------------------------------------------------------------
194 void ImplGrafMetricField::Modify()
199 // -----------------------------------------------------------------------------
201 IMPL_LINK( ImplGrafMetricField
, ImplModifyHdl
, Timer
*, EMPTYARG
)
203 const sal_Int64 nVal
= GetValue();
205 // Convert value to an any to be usable with dispatch API
207 if ( maCommand
.equalsAscii( ".uno:GrafRed" ) ||
208 maCommand
.equalsAscii( ".uno:GrafGreen" ) ||
209 maCommand
.equalsAscii( ".uno:GrafBlue" ) ||
210 maCommand
.equalsAscii( ".uno:GrafLuminance" ) ||
211 maCommand
.equalsAscii( ".uno:GrafContrast" ))
212 a
= makeAny( sal_Int16( nVal
));
213 else if ( maCommand
.equalsAscii( ".uno:GrafGamma" ) ||
214 maCommand
.equalsAscii( ".uno:GrafTransparence" ))
215 a
= makeAny( sal_Int32( nVal
));
219 INetURLObject
aObj( maCommand
);
221 Sequence
< PropertyValue
> aArgs( 1 );
222 aArgs
[0].Name
= aObj
.GetURLPath();
225 SfxToolBoxControl::Dispatch(
226 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
233 // -----------------------------------------------------------------------------
235 void ImplGrafMetricField::Update( const SfxPoolItem
* pItem
)
241 if ( maCommand
.equalsAscii( ".uno:GrafTransparence" ))
242 nValue
= ( (SfxUInt16Item
*) pItem
)->GetValue();
243 else if ( maCommand
.equalsAscii( ".uno:GrafGamma" ))
244 nValue
= ( (SfxUInt32Item
*) pItem
)->GetValue();
246 nValue
= ( (SfxInt16Item
*) pItem
)->GetValue();
254 // --------------------
255 // - ImplGrafControl -
256 // --------------------
260 const char* pCommand
;
265 static USHORT
ImplGetRID( const OUString
& aCommand
, bool bHighContrast
)
267 static const CommandToRID aImplCommandToResMap
[] =
269 { ".uno:GrafRed", RID_SVXIMG_GRAF_RED
, RID_SVXIMG_GRAF_RED_H
},
270 { ".uno:GrafGreen", RID_SVXIMG_GRAF_GREEN
, RID_SVXIMG_GRAF_GREEN_H
},
271 { ".uno:GrafBlue", RID_SVXIMG_GRAF_BLUE
, RID_SVXIMG_GRAF_BLUE_H
},
272 { ".uno:GrafLuminance", RID_SVXIMG_GRAF_LUMINANCE
, RID_SVXIMG_GRAF_LUMINANCE_H
},
273 { ".uno:GrafContrast", RID_SVXIMG_GRAF_CONTRAST
, RID_SVXIMG_GRAF_CONTRAST_H
},
274 { ".uno:GrafGamma", RID_SVXIMG_GRAF_GAMMA
, RID_SVXIMG_GRAF_GAMMA_H
},
275 { ".uno:GrafTransparence", RID_SVXIMG_GRAF_TRANSPARENCE
, RID_SVXIMG_GRAF_TRANSPARENCE_H
},
282 while ( aImplCommandToResMap
[ i
].pCommand
)
284 if ( aCommand
.equalsAscii( aImplCommandToResMap
[ i
].pCommand
))
287 nRID
= aImplCommandToResMap
[ i
].nHCResId
;
289 nRID
= aImplCommandToResMap
[ i
].nResId
;
298 // -----------------------------------------------------------------------------
300 class ImplGrafControl
: public Control
302 using Window::Update
;
305 ImplGrafMetricField maField
;
309 virtual void GetFocus();
313 ImplGrafControl( Window
* pParent
, USHORT nSlotId
, const rtl::OUString
& rCmd
, const Reference
< XFrame
>& rFrame
);
316 void Update( const SfxPoolItem
* pItem
) { maField
.Update( pItem
); }
317 void SetText( const String
& rStr
) { maField
.SetText( rStr
); }
320 // -----------------------------------------------------------------------------
322 ImplGrafControl::ImplGrafControl( Window
* pParent
, USHORT nSlotId
, const rtl::OUString
& rCmd
, const Reference
< XFrame
>& rFrame
) :
323 Control( pParent
, WB_TABSTOP
),
325 maField ( this, rCmd
, rFrame
)
327 ResId
aResId( ImplGetRID( rCmd
, false ), DIALOG_MGR() ) ;
328 Image
aImage( aResId
);
330 ResId
aResIdHC( ImplGetRID( rCmd
, true ), DIALOG_MGR() ) ;
331 Image
aImageHC( aResIdHC
);
333 Size
aImgSize( aImage
.GetSizePixel() );
334 Size
aFldSize( maField
.GetSizePixel() );
337 maImage
.SetImage( aImage
);
338 maImage
.SetModeImage( aImageHC
, BMP_COLOR_HIGHCONTRAST
);
339 maImage
.SetSizePixel( aImgSize
);
340 // we want to see the backbround of the toolbox, not of the FixedImage or Control
341 maImage
.SetBackground( Wallpaper( COL_TRANSPARENT
) );
342 SetBackground( Wallpaper( COL_TRANSPARENT
) );
344 if( aImgSize
.Height() > aFldSize
.Height() )
345 nImgY
= 0, nFldY
= ( aImgSize
.Height() - aFldSize
.Height() ) >> 1;
347 nFldY
= 0, nImgY
= ( aFldSize
.Height() - aImgSize
.Height() ) >> 1;
349 long nOffset
= SYMBOL_TO_FIELD_OFFSET
/ 2;
350 maImage
.SetPosPixel( Point( nOffset
, nImgY
) );
351 maField
.SetPosPixel( Point( aImgSize
.Width() + SYMBOL_TO_FIELD_OFFSET
, nFldY
) );
352 SetSizePixel( Size( aImgSize
.Width() + aFldSize
.Width() + SYMBOL_TO_FIELD_OFFSET
+ nOffset
,
353 Max( aImgSize
.Height(), aFldSize
.Height() ) ) );
355 SetBackground( Wallpaper() ); // transparent background
359 maField
.SetHelpId( nSlotId
);
360 maField
.SetSmartHelpId( SmartId( rCmd
));
364 // -----------------------------------------------------------------------------
366 ImplGrafControl::~ImplGrafControl()
370 // -----------------------------------------------------------------------------
372 void ImplGrafControl::GetFocus()
377 // -----------------------
378 // - ImplGrafModeControl -
379 // -----------------------
381 class ImplGrafModeControl
: public ListBox
383 using Window::Update
;
386 Reference
< XFrame
> mxFrame
;
388 virtual void Select();
389 virtual long PreNotify( NotifyEvent
& rNEvt
);
390 virtual long Notify( NotifyEvent
& rNEvt
);
391 void ImplReleaseFocus();
395 ImplGrafModeControl( Window
* pParent
, const Reference
< XFrame
>& rFrame
);
396 ~ImplGrafModeControl();
398 void Update( const SfxPoolItem
* pItem
);
401 // -----------------------------------------------------------------------------
403 ImplGrafModeControl::ImplGrafModeControl( Window
* pParent
, const Reference
< XFrame
>& rFrame
) :
404 ListBox( pParent
, WB_BORDER
| WB_DROPDOWN
| WB_AUTOHSCROLL
),
408 SetSizePixel( Size( 100, 260 ) );
410 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_STANDARD
) );
411 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_GREYS
) );
412 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_MONO
) );
413 InsertEntry( SVX_RESSTR( RID_SVXSTR_GRAFMODE_WATERMARK
) );
418 // -----------------------------------------------------------------------
420 ImplGrafModeControl::~ImplGrafModeControl()
424 // -----------------------------------------------------------------------
426 void ImplGrafModeControl::Select()
428 if ( !IsTravelSelect() )
430 Sequence
< PropertyValue
> aArgs( 1 );
431 aArgs
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GrafMode" ));
432 aArgs
[0].Value
= makeAny( sal_Int16( GetSelectEntryPos() ));
434 /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
435 This instance may be deleted in the meantime (i.e. when a dialog is opened
436 while in Dispatch()), accessing members will crash in this case. */
439 SfxToolBoxControl::Dispatch(
440 Reference
< XDispatchProvider
>( mxFrame
->getController(), UNO_QUERY
),
441 OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GrafMode" )),
446 // -----------------------------------------------------------------------
448 long ImplGrafModeControl::PreNotify( NotifyEvent
& rNEvt
)
450 USHORT nType
= rNEvt
.GetType();
452 if( EVENT_MOUSEBUTTONDOWN
== nType
|| EVENT_GETFOCUS
== nType
)
453 mnCurPos
= GetSelectEntryPos();
455 return ListBox::PreNotify( rNEvt
);
458 // -----------------------------------------------------------------------
460 long ImplGrafModeControl::Notify( NotifyEvent
& rNEvt
)
462 long nHandled
= ListBox::Notify( rNEvt
);
464 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
466 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
468 switch( pKEvt
->GetKeyCode().GetCode() )
479 SelectEntryPos( mnCurPos
);
490 // -----------------------------------------------------------------------
492 void ImplGrafModeControl::ImplReleaseFocus()
494 if( SfxViewShell::Current() )
496 Window
* pShellWnd
= SfxViewShell::Current()->GetWindow();
499 pShellWnd
->GrabFocus();
503 // -----------------------------------------------------------------------
505 void ImplGrafModeControl::Update( const SfxPoolItem
* pItem
)
508 SelectEntryPos( ((SfxUInt16Item
*)pItem
)->GetValue() );
513 // -----------------------
514 // - ImplGrafFilterPopup -
515 // -----------------------
518 class ImplGrafFilterPopup : public SfxPopupWindow
522 SvxGrafFilterToolBoxControl* mpParent;
523 Reference< XConfigurableUIElement > m_xToolBar;
524 // SfxToolBoxManager maTbxMgr;
527 WindowAlign meTbxAlign;
530 DECL_LINK( TbxSelectHdl, void* );
533 ImplGrafFilterPopup( USHORT nId, SvxGrafFilterToolBoxControl* pParent,
535 const ResId& rResIdWin, const ResId& rResIdTbx,
536 SfxBindings& rBindings );
537 ~ImplGrafFilterPopup();
539 virtual SfxPopupWindow* Clone() const;
540 virtual void PopupModeEnd();
542 void StartSelection() { maTbxMgr.GetToolBox().StartSelection(); }
546 // -----------------------------------------------------------------------------
548 ImplGrafFilterPopup::ImplGrafFilterPopup( USHORT nId, SvxGrafFilterToolBoxControl* pParent,
550 const ResId& rResIdWin, const ResId& rResIdTbx ) :
551 SfxPopupWindow ( nId, rResIdWin ),
552 mpParent ( pParent ),
553 maTbxMgr ( this, GetBindings(), rResIdTbx ),
554 maResIdWin ( rResIdWin ),
555 maResIdTbx ( rResIdTbx ),
556 meTbxAlign ( eAlign )
558 maTbxMgr.UseDefault();
560 maSelectHdl = maTbxMgr.GetToolBox().GetSelectHdl();
561 maTbxMgr.GetToolBox().SetSelectHdl( LINK( this, ImplGrafFilterPopup, TbxSelectHdl ) );
565 const Size aSize( maTbxMgr.CalcWindowSizePixel() );
566 maTbxMgr.SetPosSizePixel( Point(), aSize );
567 SetOutputSizePixel( aSize );
570 // -----------------------------------------------------------------------------
572 ImplGrafFilterPopup::~ImplGrafFilterPopup()
576 // -----------------------------------------------------------------------------
578 SfxPopupWindow* ImplGrafFilterPopup::Clone() const
580 return( new ImplGrafFilterPopup( GetId(), mpParent, meTbxAlign,
581 maResIdWin, maResIdTbx,
582 (SfxBindings&) GetBindings() ) );
585 // -----------------------------------------------------------------------------
587 void ImplGrafFilterPopup::Update()
589 ToolBox* pBox = &maTbxMgr.GetToolBox();
590 maTbxMgr.Activate( pBox );
591 maTbxMgr.Deactivate( pBox );
594 // -----------------------------------------------------------------------------
596 void ImplGrafFilterPopup::PopupModeEnd()
598 maTbxMgr.GetToolBox().EndSelection();
599 SfxPopupWindow::PopupModeEnd();
602 // -----------------------------------------------------------------------------
604 IMPL_LINK( ImplGrafFilterPopup, TbxSelectHdl, void*, EMPTYARG )
606 const USHORT nSlotId = maTbxMgr.GetToolBox().GetCurItemId();
608 if( IsInPopupMode() )
611 GetBindings().GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_ASYNCHRON );
616 // -------------------------------
617 // - SvxGrafFilterToolBoxControl -
618 // -------------------------------
620 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafFilterToolBoxControl
, TbxImageItem
);
622 // -----------------------------------------------------------------------------
624 SvxGrafFilterToolBoxControl::SvxGrafFilterToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
625 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
627 rTbx
.SetItemBits( nId
, TIB_DROPDOWNONLY
| rTbx
.GetItemBits( nId
) );
631 // -----------------------------------------------------------------------------
633 SvxGrafFilterToolBoxControl::~SvxGrafFilterToolBoxControl()
637 // -----------------------------------------------------------------------------
639 void SvxGrafFilterToolBoxControl::StateChanged( USHORT
, SfxItemState eState
, const SfxPoolItem
* )
641 GetToolBox().EnableItem( GetId(), ( eState
!= SFX_ITEM_DISABLED
) );
644 // -----------------------------------------------------------------------------
646 SfxPopupWindowType
SvxGrafFilterToolBoxControl::GetPopupWindowType() const
648 return SFX_POPUPWINDOW_ONCLICK
;
651 // -----------------------------------------------------------------------------
653 SfxPopupWindow
* SvxGrafFilterToolBoxControl::CreatePopupWindow()
655 rtl::OUString
aSubTbxResName(
656 RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/graffilterbar" ) );
657 createAndPositionSubToolBar( aSubTbxResName
);
662 // -------------------------
663 // - SvxGrafToolBoxControl -
664 // -------------------------
666 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafToolBoxControl
, SfxVoidItem
);
668 // -----------------------------------------------------------------------------
670 SvxGrafToolBoxControl::SvxGrafToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
671 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
673 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
677 // -----------------------------------------------------------------------------
679 SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
683 // -----------------------------------------------------------------------------
685 void SvxGrafToolBoxControl::StateChanged( USHORT
, SfxItemState eState
, const SfxPoolItem
* pState
)
688 ImplGrafControl
* pCtrl
= (ImplGrafControl
*) GetToolBox().GetItemWindow( GetId() );
689 DBG_ASSERT( pCtrl
, "Control not found" );
691 if( eState
== SFX_ITEM_DISABLED
)
694 pCtrl
->SetText( String() );
700 if( eState
== SFX_ITEM_AVAILABLE
)
701 pCtrl
->Update( pState
);
703 pCtrl
->Update( NULL
);
707 // -----------------------------------------------------------------------------
709 Window
* SvxGrafToolBoxControl::CreateItemWindow( Window
*pParent
)
711 return( new ImplGrafControl( pParent
, GetSlotId(), m_aCommandURL
, m_xFrame
) );
714 // ----------------------------
715 // - SvxGrafRedToolBoxControl -
716 // ----------------------------
718 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafRedToolBoxControl
, SfxInt16Item
);
720 // -----------------------------------------------------------------------------
722 SvxGrafRedToolBoxControl::SvxGrafRedToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
723 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
727 // ------------------------------
728 // - SvxGrafGreenToolBoxControl -
729 // ------------------------------
731 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGreenToolBoxControl
, SfxInt16Item
);
733 // -----------------------------------------------------------------------------
735 SvxGrafGreenToolBoxControl::SvxGrafGreenToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
736 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
740 // -----------------------------
741 // - SvxGrafBlueToolBoxControl -
742 // -----------------------------
744 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafBlueToolBoxControl
, SfxInt16Item
);
746 // -----------------------------------------------------------------------------
748 SvxGrafBlueToolBoxControl::SvxGrafBlueToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
749 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
753 // ----------------------------------
754 // - SvxGrafLuminanceToolBoxControl -
755 // ----------------------------------
757 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafLuminanceToolBoxControl
, SfxInt16Item
);
759 // -----------------------------------------------------------------------------
761 SvxGrafLuminanceToolBoxControl::SvxGrafLuminanceToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
762 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
766 // ----------------------------------
767 // - SvxGrafContrastToolBoxControl -
768 // ----------------------------------
770 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafContrastToolBoxControl
, SfxInt16Item
);
772 // -----------------------------------------------------------------------------
774 SvxGrafContrastToolBoxControl::SvxGrafContrastToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
775 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
779 // ------------------------------
780 // - SvxGrafGammaToolBoxControl -
781 // ------------------------------
783 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafGammaToolBoxControl
, SfxUInt32Item
);
785 // -----------------------------------------------------------------------------
787 SvxGrafGammaToolBoxControl::SvxGrafGammaToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
788 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
792 // -------------------------------------
793 // - SvxGrafTransparenceToolBoxControl -
794 // -------------------------------------
796 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafTransparenceToolBoxControl
, SfxUInt16Item
);
798 // -----------------------------------------------------------------------------
800 SvxGrafTransparenceToolBoxControl::SvxGrafTransparenceToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
801 SvxGrafToolBoxControl( nSlotId
, nId
, rTbx
)
805 // -----------------------------
806 // - SvxGrafModeToolBoxControl -
807 // -----------------------------
809 SFX_IMPL_TOOLBOX_CONTROL( SvxGrafModeToolBoxControl
, SfxUInt16Item
);
811 // -----------------------------------------------------------------------------
813 SvxGrafModeToolBoxControl::SvxGrafModeToolBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
814 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
818 // -----------------------------------------------------------------------------
820 SvxGrafModeToolBoxControl::~SvxGrafModeToolBoxControl()
824 // -----------------------------------------------------------------------------
826 void SvxGrafModeToolBoxControl::StateChanged( USHORT
, SfxItemState eState
, const SfxPoolItem
* pState
)
829 ImplGrafModeControl
* pCtrl
= (ImplGrafModeControl
*) GetToolBox().GetItemWindow( GetId() );
830 DBG_ASSERT( pCtrl
, "Control not found" );
832 if( eState
== SFX_ITEM_DISABLED
)
835 pCtrl
->SetText( String() );
841 if( eState
== SFX_ITEM_AVAILABLE
)
842 pCtrl
->Update( pState
);
844 pCtrl
->Update( NULL
);
848 // -----------------------------------------------------------------------------
850 Window
* SvxGrafModeToolBoxControl::CreateItemWindow( Window
*pParent
)
852 return( new ImplGrafModeControl( pParent
, m_xFrame
) );
855 // ---------------------
856 // - SvxGrafAttrHelper -
857 // ---------------------
859 void SvxGrafAttrHelper::ExecuteGrafAttr( SfxRequest
& rReq
, SdrView
& rView
)
861 SfxItemPool
& rPool
= rView
.GetModel()->GetItemPool();
862 SfxItemSet
aSet( rPool
, SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
);
864 const bool bUndo
= rView
.IsUndoEnabled();
870 aUndoStr
= rView
.GetDescriptionOfMarkedObjects();
871 aUndoStr
.Append( sal_Unicode(' ') );
874 const SfxItemSet
* pArgs
= rReq
.GetArgs();
875 const SfxPoolItem
* pItem
;
876 USHORT nSlot
= rReq
.GetSlot();
878 if( !pArgs
|| SFX_ITEM_SET
!= pArgs
->GetItemState( nSlot
, FALSE
, &pItem
))
883 case SID_ATTR_GRAF_RED
:
887 aSet
.Put( SdrGrafRedItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
889 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED
) ) );
894 case SID_ATTR_GRAF_GREEN
:
898 aSet
.Put( SdrGrafGreenItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
900 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN
) ) );
905 case SID_ATTR_GRAF_BLUE
:
909 aSet
.Put( SdrGrafBlueItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
911 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE
) ) );
916 case SID_ATTR_GRAF_LUMINANCE
:
920 aSet
.Put( SdrGrafLuminanceItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
922 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE
) ) );
927 case SID_ATTR_GRAF_CONTRAST
:
931 aSet
.Put( SdrGrafContrastItem( ((SfxInt16Item
*)pItem
)->GetValue() ));
933 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST
) ) );
938 case SID_ATTR_GRAF_GAMMA
:
942 aSet
.Put( SdrGrafGamma100Item( ((SfxUInt32Item
*)pItem
)->GetValue() ));
944 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA
) ) );
949 case SID_ATTR_GRAF_TRANSPARENCE
:
953 aSet
.Put( SdrGrafTransparenceItem( ((SfxUInt16Item
*)pItem
)->GetValue() ));
955 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY
) ) );
960 case SID_ATTR_GRAF_MODE
:
964 aSet
.Put( SdrGrafModeItem( (GraphicDrawMode
) ((SfxUInt16Item
*)pItem
)->GetValue() ));
966 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE
) ) );
971 case( SID_ATTR_GRAF_CROP
):
973 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
975 if( 0 < rMarkList
.GetMarkCount() )
977 SdrGrafObj
* pObj
= (SdrGrafObj
*) rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
979 if( pObj
&& pObj
->ISA( SdrGrafObj
) &&
980 ( pObj
->GetGraphicType() != GRAPHIC_NONE
) &&
981 ( pObj
->GetGraphicType() != GRAPHIC_DEFAULT
) )
983 SfxItemSet
aGrfAttr( rPool
, SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
, 0 );
984 const SfxMapUnit eOldMetric
= rPool
.GetMetric( 0 );
985 const MapMode
aMap100( MAP_100TH_MM
);
986 const MapMode
aMapTwip( MAP_TWIP
);
988 aGrfAttr
.Put(pObj
->GetMergedItemSet());
989 rPool
.SetDefaultMetric( SFX_MAPUNIT_TWIP
);
991 SfxItemSet
aCropDlgAttr( rPool
,
992 SDRATTR_GRAFCROP
, SDRATTR_GRAFCROP
,
993 SID_ATTR_GRAF_GRAPHIC
, SID_ATTR_GRAF_GRAPHIC
,
994 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
995 SID_ATTR_GRAF_FRMSIZE
, SID_ATTR_GRAF_FRMSIZE
,
996 SID_ATTR_GRAF_CROP
, SID_ATTR_GRAF_CROP
, 0 );
998 aCropDlgAttr
.Put( SvxBrushItem( pObj
->GetGraphic(), GPOS_MM
, SID_ATTR_GRAF_GRAPHIC
) );
999 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_PAGE_SIZE
,
1000 Size( OutputDevice::LogicToLogic(
1001 Size( 200000, 200000 ), aMap100
, aMapTwip
) ) ) );
1002 aCropDlgAttr
.Put( SvxSizeItem( SID_ATTR_GRAF_FRMSIZE
, OutputDevice::LogicToLogic(
1003 pObj
->GetLogicRect().GetSize(), aMap100
, aMapTwip
) ) );
1005 const SdrGrafCropItem
& rCrop
= (const SdrGrafCropItem
&) aGrfAttr
.Get( SDRATTR_GRAFCROP
);
1006 Size
aLTSize( OutputDevice::LogicToLogic(
1007 Size( rCrop
.GetLeft(), rCrop
.GetTop() ), aMap100
, aMapTwip
) );
1008 Size
aRBSize( OutputDevice::LogicToLogic(
1009 Size( rCrop
.GetRight(), rCrop
.GetBottom() ), aMap100
, aMapTwip
) );
1011 aCropDlgAttr
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(),
1012 aRBSize
.Width(), aRBSize
.Height() ) );
1014 SfxSingleTabDialog
aCropDialog( SfxViewShell::Current() ? SfxViewShell::Current()->GetWindow() : NULL
,
1015 aCropDlgAttr
, 950 );
1016 const String aCropStr
= SVX_RESSTR( RID_SVXSTR_GRAFCROP
);
1017 //CHINA001 SfxTabPage* pTabPage = SvxGrfCropPage::Create( &aCropDialog, aCropDlgAttr );
1018 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
1019 DBG_ASSERT(pFact
, "Dialogdiet error!");//CHINA001
1020 ::CreateTabPage fnCreatePage
= pFact
->GetTabPageCreatorFunc( RID_SVXPAGE_GRFCROP
);
1021 DBG_ASSERT(fnCreatePage
, "Dialogdiet error!");//CHINA001
1022 SfxTabPage
* pTabPage
= (*fnCreatePage
)( &aCropDialog
, aCropDlgAttr
);
1024 pTabPage
->SetText( aCropStr
);
1025 aCropDialog
.SetTabPage( pTabPage
);
1027 if( aCropDialog
.Execute() == RET_OK
)
1029 const SfxItemSet
* pOutAttr
= aCropDialog
.GetOutputItemSet();
1033 aUndoStr
.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCROP
) ) );
1035 // set crop attributes
1036 if( SFX_ITEM_SET
<= pOutAttr
->GetItemState( SDRATTR_GRAFCROP
) )
1038 const SdrGrafCropItem
& rNewCrop
= (const SdrGrafCropItem
&) pOutAttr
->Get( SDRATTR_GRAFCROP
);
1040 aLTSize
= OutputDevice::LogicToLogic( Size( rNewCrop
.GetLeft(), rNewCrop
.GetTop() ), aMapTwip
, aMap100
);
1041 aRBSize
= OutputDevice::LogicToLogic( Size( rNewCrop
.GetRight(), rNewCrop
.GetBottom() ), aMapTwip
, aMap100
);
1042 aSet
.Put( SdrGrafCropItem( aLTSize
.Width(), aLTSize
.Height(), aRBSize
.Width(), aRBSize
.Height() ) );
1045 // set new logic rect
1046 if( SFX_ITEM_SET
<= pOutAttr
->GetItemState( SID_ATTR_GRAF_FRMSIZE
) )
1048 Point
aNewOrigin( pObj
->GetLogicRect().TopLeft() );
1049 const Size
& rGrfSize
= ( (const SvxSizeItem
&) pOutAttr
->Get( SID_ATTR_GRAF_FRMSIZE
) ).GetSize();
1050 Size
aNewGrfSize( OutputDevice::LogicToLogic( rGrfSize
, aMapTwip
, aMap100
) );
1051 Size
aOldGrfSize( pObj
->GetLogicRect().GetSize() );
1053 Rectangle
aNewRect( aNewOrigin
, aNewGrfSize
);
1054 Point
aOffset( (aNewGrfSize
.Width() - aOldGrfSize
.Width()) >> 1,
1055 (aNewGrfSize
.Height() - aOldGrfSize
.Height()) >> 1 );
1057 // #106181# rotate snap rect before setting it
1058 const GeoStat
& aGeo
= pObj
->GetGeoStat();
1060 if (aGeo
.nDrehWink
!=0 || aGeo
.nShearWink
!=0)
1062 Polygon
aPol(aNewRect
);
1064 // also transform origin offset
1065 if (aGeo
.nShearWink
!=0)
1070 ShearPoint(aOffset
, Point(0,0), aGeo
.nTan
);
1072 if (aGeo
.nDrehWink
!=0)
1076 aGeo
.nSin
,aGeo
.nCos
);
1077 RotatePoint(aOffset
, Point(0,0), aGeo
.nSin
,aGeo
.nCos
);
1081 aPol
.Move( -aOffset
.X(), -aOffset
.Y() );
1082 aNewRect
=aPol
.GetBoundRect();
1086 aNewRect
.Move( -aOffset
.X(), -aOffset
.Y() );
1090 rView
.SetMarkedObjRect( aNewRect
);
1095 rView
.BegUndo( aUndoStr
);
1096 rView
.AddUndo( rView
.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj
) );
1098 pObj
->SetSnapRect( aNewRect
);
1099 rView
.SetAttributes( aSet
);
1109 rPool
.SetDefaultMetric( eOldMetric
);
1115 case SID_COLOR_SETTINGS
:
1117 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
1118 aToolboxAccess
.toggleToolbox();
1130 rView
.BegUndo( aUndoStr
);
1132 rView
.SetAttributes( aSet
);
1139 // -----------------------------------------------------------------------------
1141 void SvxGrafAttrHelper::GetGrafAttrState( SfxItemSet
& rSet
, SdrView
& rView
)
1143 SfxItemPool
& rPool
= rView
.GetModel()->GetItemPool();
1144 SfxItemSet
aAttrSet( rPool
);
1145 SfxWhichIter
aIter( rSet
);
1146 USHORT nWhich
= aIter
.FirstWhich();
1148 rView
.GetAttributes( aAttrSet
);
1152 USHORT nSlotId
= SfxItemPool::IsWhich( nWhich
) ? rPool
.GetSlotId( nWhich
) : nWhich
;
1156 case( SID_ATTR_GRAF_MODE
):
1158 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFMODE
) )
1160 rSet
.Put( SfxUInt16Item( nSlotId
,
1161 sal::static_int_cast
< UINT16
>( ITEMVALUE( aAttrSet
, SDRATTR_GRAFMODE
, SdrGrafModeItem
) ) ) );
1166 case( SID_ATTR_GRAF_RED
):
1168 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFRED
) )
1170 rSet
.Put( SfxInt16Item( nSlotId
,
1171 ITEMVALUE( aAttrSet
, SDRATTR_GRAFRED
, SdrGrafRedItem
) ) );
1176 case( SID_ATTR_GRAF_GREEN
):
1178 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFGREEN
) )
1180 rSet
.Put( SfxInt16Item( nSlotId
,
1181 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGREEN
, SdrGrafGreenItem
) ) );
1186 case( SID_ATTR_GRAF_BLUE
):
1188 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFBLUE
) )
1190 rSet
.Put( SfxInt16Item( nSlotId
,
1191 ITEMVALUE( aAttrSet
, SDRATTR_GRAFBLUE
, SdrGrafBlueItem
) ) );
1196 case( SID_ATTR_GRAF_LUMINANCE
):
1198 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFLUMINANCE
) )
1200 rSet
.Put( SfxInt16Item( nSlotId
,
1201 ITEMVALUE( aAttrSet
, SDRATTR_GRAFLUMINANCE
, SdrGrafLuminanceItem
) ) );
1206 case( SID_ATTR_GRAF_CONTRAST
):
1208 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFCONTRAST
) )
1210 rSet
.Put( SfxInt16Item( nSlotId
,
1211 ITEMVALUE( aAttrSet
, SDRATTR_GRAFCONTRAST
, SdrGrafContrastItem
) ) );
1216 case( SID_ATTR_GRAF_GAMMA
):
1218 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFGAMMA
) )
1220 rSet
.Put( SfxUInt32Item( nSlotId
,
1221 ITEMVALUE( aAttrSet
, SDRATTR_GRAFGAMMA
, SdrGrafGamma100Item
) ) );
1226 case( SID_ATTR_GRAF_TRANSPARENCE
):
1228 if( SFX_ITEM_AVAILABLE
<= aAttrSet
.GetItemState( SDRATTR_GRAFTRANSPARENCE
) )
1230 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
1231 BOOL bEnable
= TRUE
;
1233 for( USHORT i
= 0, nCount
= (USHORT
) rMarkList
.GetMarkCount();
1234 ( i
< nCount
) && bEnable
; i
++ )
1236 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
1238 if( !pObj
|| !pObj
->ISA( SdrGrafObj
) ||
1239 ( (SdrGrafObj
*) pObj
)->HasGDIMetaFile() ||
1240 ( (SdrGrafObj
*) pObj
)->IsAnimated() )
1247 rSet
.Put( SfxUInt16Item( nSlotId
,
1248 ITEMVALUE( aAttrSet
, SDRATTR_GRAFTRANSPARENCE
, SdrGrafTransparenceItem
) ) );
1250 rSet
.DisableItem( SID_ATTR_GRAF_TRANSPARENCE
);
1255 case( SID_ATTR_GRAF_CROP
):
1257 const SdrMarkList
& rMarkList
= rView
.GetMarkedObjectList();
1258 BOOL bDisable
= TRUE
;
1260 if( 1 == rMarkList
.GetMarkCount() )
1262 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
1264 if( pObj
&& pObj
->ISA( SdrGrafObj
) )
1266 SdrGrafObj
* pGrafObj
= (SdrGrafObj
*) pObj
;
1268 if( ( pGrafObj
->GetGraphicType() != GRAPHIC_NONE
) &&
1269 ( pGrafObj
->GetGraphicType() != GRAPHIC_DEFAULT
) )
1277 rSet
.DisableItem( nSlotId
);
1281 case SID_COLOR_SETTINGS
:
1283 svx::ToolboxAccess
aToolboxAccess( TOOLBOX_NAME
);
1284 rSet
.Put( SfxBoolItem( nWhich
, aToolboxAccess
.isToolboxVisible() ) );
1292 nWhich
= aIter
.NextWhich();