Update ooo320-m1
[ooovba.git] / svx / source / customshapes / tbxcustomshapes.cxx
bloba663bc6fcff1ed40700c9c8fbfae295cefe95103
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: tbxcustomshapes.cxx,v $
10 * $Revision: 1.11 $
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 _SVX_SVXIDS_HRC
37 #include <svx/svxids.hrc>
38 #endif
39 #include <tools/shl.hxx>
40 #include <svtools/eitem.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/viewsh.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <vcl/toolbox.hxx>
45 #include <vos/mutex.hxx>
47 #include <sfx2/imagemgr.hxx>
48 #include <vcl/svapp.hxx>
49 #include "tbxcustomshapes.hxx"
51 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes, SfxBoolItem);
53 /*************************************************************************
57 \************************************************************************/
59 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :
60 SfxToolBoxControl( nSlotId, nId, rTbx ),
61 m_aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ) )
63 switch( nSlotId )
65 default :
67 DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
69 case SID_DRAWTBX_CS_BASIC :
71 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes.diamond" ) );
72 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basicshapes" ) );
74 break;
76 case SID_DRAWTBX_CS_SYMBOL :
78 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes.smiley" ) );
79 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "symbolshapes" ) );
81 break;
83 case SID_DRAWTBX_CS_ARROW :
85 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes.left-right-arrow" ) );
86 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "arrowshapes" ) );
88 break;
89 case SID_DRAWTBX_CS_FLOWCHART :
91 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes.flowchart-internal-storage" ) );
92 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchartshapes" ) );
94 break;
95 case SID_DRAWTBX_CS_CALLOUT :
97 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes.round-rectangular-callout" ) );
98 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calloutshapes" ) );
100 break;
101 case SID_DRAWTBX_CS_STAR :
103 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes.star5" ) );
104 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "starshapes" ) );
106 break;
108 m_aSubTbxResName += m_aSubTbName;
109 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
110 rTbx.Invalidate();
113 /*************************************************************************
115 |* Benachrichtigung, wenn sich der Applikationsstatus geaendert hat
117 \************************************************************************/
119 void SvxTbxCtlCustomShapes::StateChanged( USHORT nSID, SfxItemState eState,
120 const SfxPoolItem* pState )
122 SfxToolBoxControl::StateChanged( nSID, eState, pState );
125 /*************************************************************************
127 |* Wenn man ein PopupWindow erzeugen will
129 \************************************************************************/
131 SfxPopupWindowType SvxTbxCtlCustomShapes::GetPopupWindowType() const
133 return( m_aCommand.getLength() == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT);
136 /*************************************************************************
138 |* Hier wird das Fenster erzeugt
139 |* Lage der Toolbox mit GetToolBox() abfragbar
140 |* rItemRect sind die Screen-Koordinaten
142 \************************************************************************/
144 SfxPopupWindow* SvxTbxCtlCustomShapes::CreatePopupWindow()
146 createAndPositionSubToolBar( m_aSubTbxResName );
147 return NULL;
150 // -----------------------------------------------------------------------
152 void SvxTbxCtlCustomShapes::Select( BOOL /*bMod1*/ )
154 if ( m_aCommand.getLength() > 0 )
156 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aParamSeq( 0 );
157 Dispatch( m_aCommand, aParamSeq );
162 ::sal_Bool SAL_CALL SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
164 // We control a sub-toolbar therefor, we have to return true.
165 return sal_True;
168 ::rtl::OUString SAL_CALL SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
170 // Provide the controlled sub-toolbar name, so we are notified whenever
171 // this toolbar executes a function.
172 return m_aSubTbName;
175 void SAL_CALL SvxTbxCtlCustomShapes::functionSelected( const ::rtl::OUString& rCommand ) throw (::com::sun::star::uno::RuntimeException)
177 // remind the new command
178 m_aCommand = rCommand;
179 // Our sub-toolbar wants to execute a function.
180 // We have to change the image of our toolbar button to reflect the new function.
181 ::vos::OGuard aGuard( Application::GetSolarMutex() );
182 if ( !m_bDisposed )
184 if ( m_aCommand.getLength() > 0 )
186 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
187 Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
188 if ( !!aImage )
189 GetToolBox().SetItemImage( GetId(), aImage );
194 void SAL_CALL SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException)
196 // We should update the button image of our parent (toolbar).
197 // Use the stored command to set the correct current image.
198 ::vos::OGuard aGuard( Application::GetSolarMutex() );
199 if ( m_aCommand.getLength() > 0 )
201 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
202 Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
203 if ( !!aImage )
204 GetToolBox().SetItemImage( GetId(), aImage );