1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include <svx/svxids.hrc>
33 #include <tools/shl.hxx>
34 #include <svl/eitem.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/viewsh.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <vcl/toolbox.hxx>
39 #include <osl/mutex.hxx>
41 #include <sfx2/imagemgr.hxx>
42 #include <vcl/svapp.hxx>
43 #include "svx/tbxcustomshapes.hxx"
45 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes
, SfxBoolItem
);
47 /*************************************************************************
51 \************************************************************************/
53 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
54 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
55 m_aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ) )
61 DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
63 case SID_DRAWTBX_CS_BASIC
:
65 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes.diamond" ) );
66 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basicshapes" ) );
70 case SID_DRAWTBX_CS_SYMBOL
:
72 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes.smiley" ) );
73 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "symbolshapes" ) );
77 case SID_DRAWTBX_CS_ARROW
:
79 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes.left-right-arrow" ) );
80 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "arrowshapes" ) );
83 case SID_DRAWTBX_CS_FLOWCHART
:
85 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes.flowchart-internal-storage" ) );
86 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchartshapes" ) );
89 case SID_DRAWTBX_CS_CALLOUT
:
91 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes.round-rectangular-callout" ) );
92 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calloutshapes" ) );
95 case SID_DRAWTBX_CS_STAR
:
97 m_aCommand
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes.star5" ) );
98 m_aSubTbName
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "starshapes" ) );
102 m_aSubTbxResName
+= m_aSubTbName
;
103 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
107 /*************************************************************************
109 |* Notification when the application status has changed
111 \************************************************************************/
113 void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
114 const SfxPoolItem
* pState
)
116 SfxToolBoxControl::StateChanged( nSID
, eState
, pState
);
119 /*************************************************************************
121 |* when one wants to create a popup window
123 \************************************************************************/
125 SfxPopupWindowType
SvxTbxCtlCustomShapes::GetPopupWindowType() const
127 return( m_aCommand
.isEmpty() ? SFX_POPUPWINDOW_ONCLICK
: SFX_POPUPWINDOW_ONTIMEOUT
);
130 /*************************************************************************
132 |* Here is the window created
133 |* The location of the Toolbox is queried through GetToolBox()
134 |* rItemRect are the screen coordinates
136 \************************************************************************/
138 SfxPopupWindow
* SvxTbxCtlCustomShapes::CreatePopupWindow()
140 createAndPositionSubToolBar( m_aSubTbxResName
);
144 // -----------------------------------------------------------------------
146 void SvxTbxCtlCustomShapes::Select( sal_Bool
/*bMod1*/ )
148 if ( !m_aCommand
.isEmpty() )
150 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
> aParamSeq( 0 );
151 Dispatch( m_aCommand
, aParamSeq
);
156 ::sal_Bool SAL_CALL
SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException
)
158 // We control a sub-toolbar therefore we have to return true.
162 ::rtl::OUString SAL_CALL
SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException
)
164 // Provide the controlled sub-toolbar name, so we are notified whenever
165 // this toolbar executes a function.
169 void SAL_CALL
SvxTbxCtlCustomShapes::functionSelected( const ::rtl::OUString
& rCommand
) throw (::com::sun::star::uno::RuntimeException
)
171 // remind the new command
172 m_aCommand
= rCommand
;
173 // Our sub-toolbar wants to execute a function.
174 // We have to change the image of our toolbar button to reflect the new function.
175 SolarMutexGuard aGuard
;
178 if ( !m_aCommand
.isEmpty() )
180 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( getFrameInterface());
181 Image aImage
= GetImage( xFrame
, m_aCommand
, hasBigImages() );
183 GetToolBox().SetItemImage( GetId(), aImage
);
188 void SAL_CALL
SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException
)
190 // We should update the button image of our parent (toolbar).
191 // Use the stored command to set the correct current image.
192 SolarMutexGuard aGuard
;
193 if ( !m_aCommand
.isEmpty() )
195 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( getFrameInterface());
196 Image aImage
= GetImage( xFrame
, m_aCommand
, hasBigImages() );
198 GetToolBox().SetItemImage( GetId(), aImage
);
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */