1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26
27 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
28
29 #ifndef _SVX_SVXIDS_HRC
30 #include <svx/svxids.hrc>
31 #endif
32 #include <tools/shl.hxx>
33 #include <svl/eitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/viewsh.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <vcl/toolbox.hxx>
38 #include <vos/mutex.hxx>
39
40 #include <sfx2/imagemgr.hxx>
41 #include <vcl/svapp.hxx>
42 #include "svx/tbxcustomshapes.hxx"
43
44 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes, SfxBoolItem);
45
46 /*************************************************************************
47 |*
48 \************************************************************************/
49
SvxTbxCtlCustomShapes(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)50 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
51 SfxToolBoxControl( nSlotId, nId, rTbx ),
52 m_aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ) )
53 {
54 switch( nSlotId )
55 {
56 default :
57 {
58 DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
59 }
60 case SID_DRAWTBX_CS_BASIC :
61 {
62 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes.diamond" ) );
63 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basicshapes" ) );
64 }
65 break;
66
67 case SID_DRAWTBX_CS_SYMBOL :
68 {
69 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes.smiley" ) );
70 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "symbolshapes" ) );
71 }
72 break;
73
74 case SID_DRAWTBX_CS_ARROW :
75 {
76 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes.left-right-arrow" ) );
77 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "arrowshapes" ) );
78 }
79 break;
80 case SID_DRAWTBX_CS_FLOWCHART :
81 {
82 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes.flowchart-internal-storage" ) );
83 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchartshapes" ) );
84 }
85 break;
86 case SID_DRAWTBX_CS_CALLOUT :
87 {
88 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes.round-rectangular-callout" ) );
89 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calloutshapes" ) );
90 }
91 break;
92 case SID_DRAWTBX_CS_STAR :
93 {
94 m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes.star5" ) );
95 m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "starshapes" ) );
96 }
97 break;
98 }
99 m_aSubTbxResName += m_aSubTbName;
100 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
101 rTbx.Invalidate();
102 }
103
104 /*************************************************************************
105 |* Benachrichtigung, wenn sich der Applikationsstatus geaendert hat
106 \************************************************************************/
107
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)108 void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID, SfxItemState eState,
109 const SfxPoolItem* pState )
110 {
111 SfxToolBoxControl::StateChanged( nSID, eState, pState );
112 }
113
114 /*************************************************************************
115 |* Wenn man ein PopupWindow erzeugen will
116 \************************************************************************/
117
GetPopupWindowType() const118 SfxPopupWindowType SvxTbxCtlCustomShapes::GetPopupWindowType() const
119 {
120 return( m_aCommand.getLength() == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT);
121 }
122
123 /*************************************************************************
124 |* Hier wird das Fenster erzeugt
125 |* Lage der Toolbox mit GetToolBox() abfragbar
126 |* rItemRect sind die Screen-Koordinaten
127 \************************************************************************/
128
CreatePopupWindow()129 SfxPopupWindow* SvxTbxCtlCustomShapes::CreatePopupWindow()
130 {
131 createAndPositionSubToolBar( m_aSubTbxResName );
132 return NULL;
133 }
134
135 // -----------------------------------------------------------------------
136
Select(sal_Bool)137 void SvxTbxCtlCustomShapes::Select( sal_Bool /*bMod1*/ )
138 {
139 if ( m_aCommand.getLength() > 0 )
140 {
141 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aParamSeq( 0 );
142 Dispatch( m_aCommand, aParamSeq );
143 }
144 }
145
146
opensSubToolbar()147 ::sal_Bool SAL_CALL SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
148 {
149 // We control a sub-toolbar therefor, we have to return true.
150 return sal_True;
151 }
152
getSubToolbarName()153 ::rtl::OUString SAL_CALL SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
154 {
155 // Provide the controlled sub-toolbar name, so we are notified whenever
156 // this toolbar executes a function.
157 return m_aSubTbName;
158 }
159
functionSelected(const::rtl::OUString & rCommand)160 void SAL_CALL SvxTbxCtlCustomShapes::functionSelected( const ::rtl::OUString& rCommand ) throw (::com::sun::star::uno::RuntimeException)
161 {
162 // remind the new command
163 m_aCommand = rCommand;
164 // Our sub-toolbar wants to execute a function.
165 // We have to change the image of our toolbar button to reflect the new function.
166 ::vos::OGuard aGuard( Application::GetSolarMutex() );
167 if ( !m_bDisposed )
168 {
169 if ( m_aCommand.getLength() > 0 )
170 {
171 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
172 Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
173 if ( !!aImage )
174 GetToolBox().SetItemImage( GetId(), aImage );
175 }
176 }
177 }
178
updateImage()179 void SAL_CALL SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException)
180 {
181 // We should update the button image of our parent (toolbar).
182 // Use the stored command to set the correct current image.
183 ::vos::OGuard aGuard( Application::GetSolarMutex() );
184 if ( m_aCommand.getLength() > 0 )
185 {
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 );
190 }
191 }
192