update dev300-m58
[ooovba.git] / svx / source / tbxctrls / grafctrl.cxx
blob87e65ec556abc2c5baa1853b99544829d3f52eb3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: grafctrl.cxx,v $
10 * $Revision: 1.41 $
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>
38 #endif
39 #ifndef _FIELD_HXX //autogen
40 #include <vcl/field.hxx>
41 #endif
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"
73 // namespaces
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
82 // -----------
83 // - Defines -
84 // -----------
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" ) )
90 // ----------------
91 // - TbxImageItem -
92 // ----------------
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;
125 private:
126 Timer maTimer;
127 OUString maCommand;
128 Reference< XFrame > mxFrame;
130 DECL_LINK( ImplModifyHdl, Timer* );
132 protected:
134 virtual void Modify();
136 public:
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 ),
149 maCommand( rCmd ),
150 mxFrame( rFrame )
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 );
161 SetMin( 10 );
162 SetFirst( 10 );
163 SetMax( 1000 );
164 SetLast( 1000 );
165 SetSpinSize( 10 );
167 else
169 const long nMinVal = ( maCommand.equalsAscii( ".uno:GrafTransparence" )) ? 0 : -100;
171 SetUnit( FUNIT_CUSTOM );
172 SetCustomUnitText( String::CreateFromAscii(" %") );
173 SetDecimalDigits( 0 );
175 SetMin( nMinVal );
176 SetFirst( nMinVal );
177 SetMax( 100 );
178 SetLast( 100 );
179 SetSpinSize( 1 );
182 maTimer.SetTimeout( 100 );
183 maTimer.SetTimeoutHdl( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
186 // -----------------------------------------------------------------------------
188 ImplGrafMetricField::~ImplGrafMetricField()
192 // -----------------------------------------------------------------------------
194 void ImplGrafMetricField::Modify()
196 maTimer.Start();
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
206 Any a;
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 ));
217 if ( a.hasValue() )
219 INetURLObject aObj( maCommand );
221 Sequence< PropertyValue > aArgs( 1 );
222 aArgs[0].Name = aObj.GetURLPath();
223 aArgs[0].Value = a;
225 SfxToolBoxControl::Dispatch(
226 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
227 maCommand,
228 aArgs );
230 return 0L;
233 // -----------------------------------------------------------------------------
235 void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
237 if( pItem )
239 long nValue;
241 if ( maCommand.equalsAscii( ".uno:GrafTransparence" ))
242 nValue = ( (SfxUInt16Item*) pItem )->GetValue();
243 else if ( maCommand.equalsAscii( ".uno:GrafGamma" ))
244 nValue = ( (SfxUInt32Item*) pItem )->GetValue();
245 else
246 nValue = ( (SfxInt16Item*) pItem )->GetValue();
248 SetValue( nValue );
250 else
251 SetText( String() );
254 // --------------------
255 // - ImplGrafControl -
256 // --------------------
258 struct CommandToRID
260 const char* pCommand;
261 USHORT nResId;
262 USHORT nHCResId;
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 },
276 { 0, 0, 0 }
279 USHORT nRID = 0;
281 sal_Int32 i( 0 );
282 while ( aImplCommandToResMap[ i ].pCommand )
284 if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
286 if ( bHighContrast )
287 nRID = aImplCommandToResMap[ i ].nHCResId;
288 else
289 nRID = aImplCommandToResMap[ i ].nResId;
290 break;
292 ++i;
295 return nRID;
298 // -----------------------------------------------------------------------------
300 class ImplGrafControl : public Control
302 using Window::Update;
303 private:
304 FixedImage maImage;
305 ImplGrafMetricField maField;
307 protected:
309 virtual void GetFocus();
311 public:
313 ImplGrafControl( Window* pParent, USHORT nSlotId, const rtl::OUString& rCmd, const Reference< XFrame >& rFrame );
314 ~ImplGrafControl();
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 ),
324 maImage ( this ),
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() );
335 long nFldY, nImgY;
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;
346 else
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
357 maImage.Show();
359 maField.SetHelpId( nSlotId );
360 maField.SetSmartHelpId( SmartId( rCmd ));
361 maField.Show();
364 // -----------------------------------------------------------------------------
366 ImplGrafControl::~ImplGrafControl()
370 // -----------------------------------------------------------------------------
372 void ImplGrafControl::GetFocus()
374 maField.GrabFocus();
377 // -----------------------
378 // - ImplGrafModeControl -
379 // -----------------------
381 class ImplGrafModeControl : public ListBox
383 using Window::Update;
384 private:
385 USHORT mnCurPos;
386 Reference< XFrame > mxFrame;
388 virtual void Select();
389 virtual long PreNotify( NotifyEvent& rNEvt );
390 virtual long Notify( NotifyEvent& rNEvt );
391 void ImplReleaseFocus();
393 public:
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 ),
405 mnCurPos( 0 ),
406 mxFrame( rFrame )
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 ) );
415 Show();
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. */
437 ImplReleaseFocus();
439 SfxToolBoxControl::Dispatch(
440 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
441 OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GrafMode" )),
442 aArgs );
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() )
470 case KEY_RETURN:
472 Select();
473 nHandled = 1;
475 break;
477 case KEY_ESCAPE:
479 SelectEntryPos( mnCurPos );
480 ImplReleaseFocus();
481 nHandled = 1;
483 break;
487 return nHandled;
490 // -----------------------------------------------------------------------
492 void ImplGrafModeControl::ImplReleaseFocus()
494 if( SfxViewShell::Current() )
496 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
498 if( pShellWnd )
499 pShellWnd->GrabFocus();
503 // -----------------------------------------------------------------------
505 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
507 if( pItem )
508 SelectEntryPos( ((SfxUInt16Item*)pItem)->GetValue() );
509 else
510 SetNoSelection();
513 // -----------------------
514 // - ImplGrafFilterPopup -
515 // -----------------------
517 CD!!!
518 class ImplGrafFilterPopup : public SfxPopupWindow
520 private:
522 SvxGrafFilterToolBoxControl* mpParent;
523 Reference< XConfigurableUIElement > m_xToolBar;
524 // SfxToolBoxManager maTbxMgr;
525 ResId maResIdWin;
526 ResId maResIdTbx;
527 WindowAlign meTbxAlign;
528 Link maSelectHdl;
530 DECL_LINK( TbxSelectHdl, void* );
532 public:
533 ImplGrafFilterPopup( USHORT nId, SvxGrafFilterToolBoxControl* pParent,
534 WindowAlign eAlign,
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(); }
543 void Update();
546 // -----------------------------------------------------------------------------
548 ImplGrafFilterPopup::ImplGrafFilterPopup( USHORT nId, SvxGrafFilterToolBoxControl* pParent,
549 WindowAlign eAlign,
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 ) );
563 FreeResource();
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() )
609 EndPopupMode();
611 GetBindings().GetDispatcher()->Execute( nSlotId, SFX_CALLMODE_ASYNCHRON );
613 return 0;
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 ) );
628 rTbx.Invalidate();
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 );
659 return NULL;
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 ) );
674 rTbx.Invalidate();
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 )
693 pCtrl->Disable();
694 pCtrl->SetText( String() );
696 else
698 pCtrl->Enable();
700 if( eState == SFX_ITEM_AVAILABLE )
701 pCtrl->Update( pState );
702 else
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 )
834 pCtrl->Disable();
835 pCtrl->SetText( String() );
837 else
839 pCtrl->Enable();
841 if( eState == SFX_ITEM_AVAILABLE )
842 pCtrl->Update( pState );
843 else
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();
866 String aUndoStr;
868 if( bUndo )
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 ))
879 pItem = 0;
881 switch( nSlot )
883 case SID_ATTR_GRAF_RED:
885 if( pItem )
887 aSet.Put( SdrGrafRedItem( ((SfxInt16Item*)pItem)->GetValue() ));
888 if( bUndo )
889 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED ) ) );
892 break;
894 case SID_ATTR_GRAF_GREEN:
896 if( pItem )
898 aSet.Put( SdrGrafGreenItem( ((SfxInt16Item*)pItem)->GetValue() ));
899 if( bUndo )
900 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN ) ) );
903 break;
905 case SID_ATTR_GRAF_BLUE:
907 if( pItem )
909 aSet.Put( SdrGrafBlueItem( ((SfxInt16Item*)pItem)->GetValue() ));
910 if( bUndo )
911 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE ) ) );
914 break;
916 case SID_ATTR_GRAF_LUMINANCE:
918 if( pItem )
920 aSet.Put( SdrGrafLuminanceItem( ((SfxInt16Item*)pItem)->GetValue() ));
921 if( bUndo )
922 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE ) ) );
925 break;
927 case SID_ATTR_GRAF_CONTRAST:
929 if( pItem )
931 aSet.Put( SdrGrafContrastItem( ((SfxInt16Item*)pItem)->GetValue() ));
932 if( bUndo )
933 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST ) ) );
936 break;
938 case SID_ATTR_GRAF_GAMMA:
940 if( pItem )
942 aSet.Put( SdrGrafGamma100Item( ((SfxUInt32Item*)pItem)->GetValue() ));
943 if( bUndo )
944 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA ) ) );
947 break;
949 case SID_ATTR_GRAF_TRANSPARENCE:
951 if( pItem )
953 aSet.Put( SdrGrafTransparenceItem( ((SfxUInt16Item*)pItem)->GetValue() ));
954 if( bUndo )
955 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY ) ) );
958 break;
960 case SID_ATTR_GRAF_MODE:
962 if( pItem )
964 aSet.Put( SdrGrafModeItem( (GraphicDrawMode) ((SfxUInt16Item*)pItem)->GetValue() ));
965 if( bUndo )
966 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE ) ) );
969 break;
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 );
1023 //CHINA001 end
1024 pTabPage->SetText( aCropStr );
1025 aCropDialog.SetTabPage( pTabPage );
1027 if( aCropDialog.Execute() == RET_OK )
1029 const SfxItemSet* pOutAttr = aCropDialog.GetOutputItemSet();
1031 if( pOutAttr )
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)
1067 ShearPoly(aPol,
1068 aNewRect.TopLeft(),
1069 aGeo.nTan);
1070 ShearPoint(aOffset, Point(0,0), aGeo.nTan);
1072 if (aGeo.nDrehWink!=0)
1074 RotatePoly(aPol,
1075 aNewRect.TopLeft(),
1076 aGeo.nSin,aGeo.nCos);
1077 RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
1080 // apply offset
1081 aPol.Move( -aOffset.X(), -aOffset.Y() );
1082 aNewRect=aPol.GetBoundRect();
1084 else
1086 aNewRect.Move( -aOffset.X(), -aOffset.Y() );
1089 if( !aSet.Count() )
1090 rView.SetMarkedObjRect( aNewRect );
1091 else
1093 if( bUndo )
1095 rView.BegUndo( aUndoStr );
1096 rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
1098 pObj->SetSnapRect( aNewRect );
1099 rView.SetAttributes( aSet );
1101 if( bUndo )
1102 rView.EndUndo();
1103 aSet.ClearItem();
1109 rPool.SetDefaultMetric( eOldMetric );
1113 break;
1115 case SID_COLOR_SETTINGS:
1117 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1118 aToolboxAccess.toggleToolbox();
1119 rReq.Done();
1120 break;
1123 default:
1124 break;
1127 if( aSet.Count() )
1129 if( bUndo )
1130 rView.BegUndo( aUndoStr );
1132 rView.SetAttributes( aSet );
1134 if( bUndo )
1135 rView.EndUndo();
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 );
1150 while( nWhich )
1152 USHORT nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
1154 switch( nSlotId )
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 ) ) ) );
1164 break;
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 ) ) );
1174 break;
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 ) ) );
1184 break;
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 ) ) );
1194 break;
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 ) ) );
1204 break;
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 ) ) );
1214 break;
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 ) ) );
1224 break;
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() )
1242 bEnable = FALSE;
1246 if( bEnable )
1247 rSet.Put( SfxUInt16Item( nSlotId,
1248 ITEMVALUE( aAttrSet, SDRATTR_GRAFTRANSPARENCE, SdrGrafTransparenceItem ) ) );
1249 else
1250 rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
1253 break;
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 ) )
1271 bDisable = FALSE;
1276 if( bDisable )
1277 rSet.DisableItem( nSlotId );
1279 break;
1281 case SID_COLOR_SETTINGS :
1283 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1284 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
1285 break;
1288 default:
1289 break;
1292 nWhich = aIter.NextWhich();