Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / svx / source / tbxctrls / grafctrl.cxx
blob1bfd3d577c91c842c971aaf6f618b52543b6fe58
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 ************************************************************************/
30 #include <string>
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"
65 // namespaces
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>
74 // -----------
75 // - Defines -
76 // -----------
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" ) )
82 // ----------------
83 // - TbxImageItem -
84 // ----------------
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;
117 private:
118 Timer maTimer;
119 OUString maCommand;
120 Reference< XFrame > mxFrame;
122 DECL_LINK(ImplModifyHdl, void *);
124 protected:
126 virtual void Modify();
128 public:
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 ),
141 maCommand( rCmd ),
142 mxFrame( rFrame )
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 );
153 SetMin( 10 );
154 SetFirst( 10 );
155 SetMax( 1000 );
156 SetLast( 1000 );
157 SetSpinSize( 10 );
159 else
161 const long nMinVal = ( maCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".uno:GrafTransparence" ) )) ? 0 : -100;
163 SetUnit( FUNIT_CUSTOM );
164 SetCustomUnitText( String::CreateFromAscii(" %") );
165 SetDecimalDigits( 0 );
167 SetMin( nMinVal );
168 SetFirst( nMinVal );
169 SetMax( 100 );
170 SetLast( 100 );
171 SetSpinSize( 1 );
174 maTimer.SetTimeout( 100 );
175 maTimer.SetTimeoutHdl( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
178 // -----------------------------------------------------------------------------
180 ImplGrafMetricField::~ImplGrafMetricField()
184 // -----------------------------------------------------------------------------
186 void ImplGrafMetricField::Modify()
188 maTimer.Start();
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
198 Any a;
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 ));
209 if ( a.hasValue() )
211 INetURLObject aObj( maCommand );
213 Sequence< PropertyValue > aArgs( 1 );
214 aArgs[0].Name = aObj.GetURLPath();
215 aArgs[0].Value = a;
217 SfxToolBoxControl::Dispatch(
218 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
219 maCommand,
220 aArgs );
222 return 0L;
225 // -----------------------------------------------------------------------------
227 void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
229 if( pItem )
231 long nValue;
233 if ( maCommand == ".uno:GrafTransparence" )
234 nValue = ( (SfxUInt16Item*) pItem )->GetValue();
235 else if ( maCommand == ".uno:GrafGamma" )
236 nValue = ( (SfxUInt32Item*) pItem )->GetValue();
237 else
238 nValue = ( (SfxInt16Item*) pItem )->GetValue();
240 SetValue( nValue );
242 else
243 SetText( String() );
246 // --------------------
247 // - ImplGrafControl -
248 // --------------------
250 struct CommandToRID
252 const char* pCommand;
253 sal_uInt16 nResId;
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 },
267 { 0, 0 }
270 sal_uInt16 nRID = 0;
272 sal_Int32 i( 0 );
273 while ( aImplCommandToResMap[ i ].pCommand )
275 if ( aCommand.equalsAscii( aImplCommandToResMap[ i ].pCommand ))
277 nRID = aImplCommandToResMap[ i ].nResId;
278 break;
280 ++i;
283 return nRID;
286 // -----------------------------------------------------------------------------
288 class ImplGrafControl : public Control
290 using Window::Update;
291 private:
292 FixedImage maImage;
293 ImplGrafMetricField maField;
295 protected:
297 virtual void GetFocus();
299 public:
301 ImplGrafControl( Window* pParent, const rtl::OUString& rCmd, const Reference< XFrame >& rFrame );
302 ~ImplGrafControl();
304 void Update( const SfxPoolItem* pItem ) { maField.Update( pItem ); }
305 void SetText( const String& rStr ) { maField.SetText( rStr ); }
308 // -----------------------------------------------------------------------------
310 ImplGrafControl::ImplGrafControl(
311 Window* pParent,
312 const rtl::OUString& rCmd,
313 const Reference< XFrame >& rFrame
314 ) : Control( pParent, WB_TABSTOP )
315 , maImage( this )
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() );
323 long nFldY, nImgY;
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;
333 else
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
344 maImage.Show();
346 maField.SetHelpId( rtl::OUStringToOString( rCmd, RTL_TEXTENCODING_UTF8 ) );
347 maField.Show();
350 // -----------------------------------------------------------------------------
352 ImplGrafControl::~ImplGrafControl()
356 // -----------------------------------------------------------------------------
358 void ImplGrafControl::GetFocus()
360 maField.GrabFocus();
363 // -----------------------
364 // - ImplGrafModeControl -
365 // -----------------------
367 class ImplGrafModeControl : public ListBox
369 using Window::Update;
370 private:
371 sal_uInt16 mnCurPos;
372 Reference< XFrame > mxFrame;
374 virtual void Select();
375 virtual long PreNotify( NotifyEvent& rNEvt );
376 virtual long Notify( NotifyEvent& rNEvt );
377 void ImplReleaseFocus();
379 public:
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 ),
391 mnCurPos( 0 ),
392 mxFrame( rFrame )
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 ) );
401 Show();
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. */
423 ImplReleaseFocus();
425 SfxToolBoxControl::Dispatch(
426 Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ),
427 OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GrafMode" )),
428 aArgs );
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() )
456 case KEY_RETURN:
458 Select();
459 nHandled = 1;
461 break;
463 case KEY_ESCAPE:
465 SelectEntryPos( mnCurPos );
466 ImplReleaseFocus();
467 nHandled = 1;
469 break;
473 return nHandled;
476 // -----------------------------------------------------------------------
478 void ImplGrafModeControl::ImplReleaseFocus()
480 if( SfxViewShell::Current() )
482 Window* pShellWnd = SfxViewShell::Current()->GetWindow();
484 if( pShellWnd )
485 pShellWnd->GrabFocus();
489 // -----------------------------------------------------------------------
491 void ImplGrafModeControl::Update( const SfxPoolItem* pItem )
493 if( pItem )
494 SelectEntryPos( ((SfxUInt16Item*)pItem)->GetValue() );
495 else
496 SetNoSelection();
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 ) );
511 rTbx.Invalidate();
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 );
542 return NULL;
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 ) );
555 rTbx.Invalidate();
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 )
574 pCtrl->Disable();
575 pCtrl->SetText( String() );
577 else
579 pCtrl->Enable();
581 if( eState == SFX_ITEM_AVAILABLE )
582 pCtrl->Update( pState );
583 else
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 )
715 pCtrl->Disable();
716 pCtrl->SetText( String() );
718 else
720 pCtrl->Enable();
722 if( eState == SFX_ITEM_AVAILABLE )
723 pCtrl->Update( pState );
724 else
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 );
744 String aUndoStr;
745 const bool bUndo = rView.IsUndoEnabled();
747 if( bUndo )
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 ))
758 pItem = 0;
760 switch( nSlot )
762 case SID_ATTR_GRAF_RED:
764 if( pItem )
766 aSet.Put( SdrGrafRedItem( ((SfxInt16Item*)pItem)->GetValue() ));
767 if( bUndo )
768 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFRED ) ) );
771 break;
773 case SID_ATTR_GRAF_GREEN:
775 if( pItem )
777 aSet.Put( SdrGrafGreenItem( ((SfxInt16Item*)pItem)->GetValue() ));
778 if( bUndo )
779 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGREEN ) ) );
782 break;
784 case SID_ATTR_GRAF_BLUE:
786 if( pItem )
788 aSet.Put( SdrGrafBlueItem( ((SfxInt16Item*)pItem)->GetValue() ));
789 if( bUndo )
790 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFBLUE ) ) );
793 break;
795 case SID_ATTR_GRAF_LUMINANCE:
797 if( pItem )
799 aSet.Put( SdrGrafLuminanceItem( ((SfxInt16Item*)pItem)->GetValue() ));
800 if( bUndo )
801 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFLUMINANCE ) ) );
804 break;
806 case SID_ATTR_GRAF_CONTRAST:
808 if( pItem )
810 aSet.Put( SdrGrafContrastItem( ((SfxInt16Item*)pItem)->GetValue() ));
811 if( bUndo )
812 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFCONTRAST ) ) );
815 break;
817 case SID_ATTR_GRAF_GAMMA:
819 if( pItem )
821 aSet.Put( SdrGrafGamma100Item( ((SfxUInt32Item*)pItem)->GetValue() ));
822 if( bUndo )
823 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFGAMMA ) ) );
826 break;
828 case SID_ATTR_GRAF_TRANSPARENCE:
830 if( pItem )
832 aSet.Put( SdrGrafTransparenceItem( ((SfxUInt16Item*)pItem)->GetValue() ));
833 if( bUndo )
834 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFTRANSPARENCY ) ) );
837 break;
839 case SID_ATTR_GRAF_MODE:
841 if( pItem )
843 aSet.Put( SdrGrafModeItem( (GraphicDrawMode) ((SfxUInt16Item*)pItem)->GetValue() ));
844 if( bUndo )
845 aUndoStr.Append( String( SVX_RESSTR( RID_SVXSTR_UNDO_GRAFMODE ) ) );
848 break;
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,
894 aCropDlgAttr, 950 );
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();
910 if( pOutAttr )
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)
946 ShearPoly(aPol,
947 aNewRect.TopLeft(),
948 aGeo.nTan);
949 ShearPoint(aOffset, Point(0,0), aGeo.nTan);
951 if (aGeo.nDrehWink!=0)
953 RotatePoly(aPol,
954 aNewRect.TopLeft(),
955 aGeo.nSin,aGeo.nCos);
956 RotatePoint(aOffset, Point(0,0), aGeo.nSin,aGeo.nCos);
959 // apply offset
960 aPol.Move( -aOffset.X(), -aOffset.Y() );
961 aNewRect=aPol.GetBoundRect();
963 else
965 aNewRect.Move( -aOffset.X(), -aOffset.Y() );
968 if( !aSet.Count() )
969 rView.SetMarkedObjRect( aNewRect );
970 else
972 if( bUndo )
974 rView.BegUndo( aUndoStr );
975 rView.AddUndo( rView.GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
977 pObj->SetSnapRect( aNewRect );
978 rView.SetAttributes( aSet );
980 if( bUndo )
981 rView.EndUndo();
982 aSet.ClearItem();
988 rPool.SetDefaultMetric( eOldMetric );
992 break;
994 case SID_COLOR_SETTINGS:
996 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
997 aToolboxAccess.toggleToolbox();
998 rReq.Done();
999 break;
1002 default:
1003 break;
1006 if( aSet.Count() )
1008 if( bUndo )
1009 rView.BegUndo( aUndoStr );
1011 rView.SetAttributes( aSet );
1013 if( bUndo )
1014 rView.EndUndo();
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() );
1035 if( !pGrafObj ||
1036 ( pGrafObj->GetGraphicType() == GRAPHIC_NONE ) ||
1037 ( pGrafObj->GetGraphicType() == GRAPHIC_DEFAULT ) ||
1038 pGrafObj->HasRenderGraphic() )
1040 bEnableColors = bEnableTransparency = bEnableCrop = false;
1041 break;
1043 else if( bEnableTransparency && ( pGrafObj->HasGDIMetaFile() || pGrafObj->IsAnimated() ) )
1045 bEnableTransparency = false;
1049 rView.GetAttributes( aAttrSet );
1051 while( nWhich )
1053 sal_uInt16 nSlotId = SfxItemPool::IsWhich( nWhich ) ? rPool.GetSlotId( nWhich ) : nWhich;
1055 switch( nSlotId )
1057 case( SID_ATTR_GRAF_MODE ):
1059 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFMODE ) )
1061 if( bEnableColors )
1063 rSet.Put( SfxUInt16Item( nSlotId,
1064 sal::static_int_cast< sal_uInt16 >( ITEMVALUE( aAttrSet, SDRATTR_GRAFMODE, SdrGrafModeItem ) ) ) );
1066 else
1068 rSet.DisableItem( SID_ATTR_GRAF_MODE );
1072 break;
1074 case( SID_ATTR_GRAF_RED ):
1076 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFRED ) )
1078 if( bEnableColors )
1080 rSet.Put( SfxInt16Item( nSlotId,
1081 ITEMVALUE( aAttrSet, SDRATTR_GRAFRED, SdrGrafRedItem ) ) );
1083 else
1085 rSet.DisableItem( SID_ATTR_GRAF_RED );
1089 break;
1091 case( SID_ATTR_GRAF_GREEN ):
1093 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGREEN ) )
1095 if( bEnableColors )
1097 rSet.Put( SfxInt16Item( nSlotId,
1098 ITEMVALUE( aAttrSet, SDRATTR_GRAFGREEN, SdrGrafGreenItem ) ) );
1100 else
1102 rSet.DisableItem( SID_ATTR_GRAF_GREEN );
1106 break;
1108 case( SID_ATTR_GRAF_BLUE ):
1110 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFBLUE ) )
1112 if( bEnableColors )
1114 rSet.Put( SfxInt16Item( nSlotId,
1115 ITEMVALUE( aAttrSet, SDRATTR_GRAFBLUE, SdrGrafBlueItem ) ) );
1117 else
1119 rSet.DisableItem( SID_ATTR_GRAF_BLUE );
1123 break;
1125 case( SID_ATTR_GRAF_LUMINANCE ):
1127 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFLUMINANCE ) )
1129 if( bEnableColors )
1131 rSet.Put( SfxInt16Item( nSlotId,
1132 ITEMVALUE( aAttrSet, SDRATTR_GRAFLUMINANCE, SdrGrafLuminanceItem ) ) );
1134 else
1136 rSet.DisableItem( SID_ATTR_GRAF_LUMINANCE );
1140 break;
1142 case( SID_ATTR_GRAF_CONTRAST ):
1144 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFCONTRAST ) )
1146 if( bEnableColors )
1148 rSet.Put( SfxInt16Item( nSlotId,
1149 ITEMVALUE( aAttrSet, SDRATTR_GRAFCONTRAST, SdrGrafContrastItem ) ) );
1151 else
1153 rSet.DisableItem( SID_ATTR_GRAF_CONTRAST );
1157 break;
1159 case( SID_ATTR_GRAF_GAMMA ):
1161 if( SFX_ITEM_AVAILABLE <= aAttrSet.GetItemState( SDRATTR_GRAFGAMMA ) )
1163 if( bEnableColors )
1165 rSet.Put( SfxUInt32Item( nSlotId,
1166 ITEMVALUE( aAttrSet, SDRATTR_GRAFGAMMA, SdrGrafGamma100Item ) ) );
1168 else
1170 rSet.DisableItem( SID_ATTR_GRAF_GAMMA );
1174 break;
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 ) ) );
1185 else
1187 rSet.DisableItem( SID_ATTR_GRAF_TRANSPARENCE );
1191 break;
1193 case( SID_ATTR_GRAF_CROP ):
1195 if( !bEnableCrop )
1196 rSet.DisableItem( nSlotId );
1198 break;
1200 case SID_COLOR_SETTINGS :
1202 svx::ToolboxAccess aToolboxAccess( TOOLBOX_NAME );
1203 rSet.Put( SfxBoolItem( nWhich, aToolboxAccess.isToolboxVisible() ) );
1204 break;
1207 default:
1208 break;
1211 nWhich = aIter.NextWhich();
1215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */