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_chart2.hxx"
26
27 #include "ShapeToolbarController.hxx"
28
29 #include <vos/mutex.hxx>
30 #include <comphelper/sequence.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/toolbox.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <svx/svxids.hrc>
35 #include <svx/tbxcustomshapes.hxx>
36
37
38 using namespace com::sun::star;
39
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42
43 //.............................................................................
44 namespace chart
45 {
46 //.............................................................................
47
getImplementationName()48 ::rtl::OUString ShapeToolbarController::getImplementationName() throw (uno::RuntimeException)
49 {
50 return getImplementationName_Static();
51 }
52
getImplementationName_Static()53 ::rtl::OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
54 {
55 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ShapeToolbarController" ) );
56 }
57
getSupportedServiceNames_Static()58 Sequence< ::rtl::OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
59 {
60 Sequence< ::rtl::OUString > aSupported(1);
61 aSupported.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ShapeToolbarController" ) );
62 return aSupported;
63 }
64
supportsService(const::rtl::OUString & ServiceName)65 ::sal_Bool ShapeToolbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
66 {
67 return ::comphelper::existsValue( ServiceName, getSupportedServiceNames_Static() );
68 }
69
getSupportedServiceNames()70 Sequence< ::rtl::OUString> ShapeToolbarController::getSupportedServiceNames() throw (uno::RuntimeException)
71 {
72 return getSupportedServiceNames_Static();
73 }
74
create(const Reference<uno::XComponentContext> & xContext)75 Reference< uno::XInterface > ShapeToolbarController::create( const Reference< uno::XComponentContext >& xContext )
76 {
77 return *( new ShapeToolbarController( Reference< lang::XMultiServiceFactory >( xContext->getServiceManager(), uno::UNO_QUERY ) ) );
78 }
79
ShapeToolbarController(const Reference<lang::XMultiServiceFactory> & rxFact)80 ShapeToolbarController::ShapeToolbarController( const Reference< lang::XMultiServiceFactory >& rxFact )
81 :m_pToolbarController( NULL )
82 ,m_nToolBoxId( 1 )
83 ,m_nSlotId( 0 )
84 {
85 osl_incrementInterlockedCount( &m_refCount );
86 m_xServiceManager = rxFact;
87 osl_decrementInterlockedCount( &m_refCount );
88 }
89
~ShapeToolbarController()90 ShapeToolbarController::~ShapeToolbarController()
91 {
92 }
93
94 // ::com::sun::star::uno::XInterface
queryInterface(const uno::Type & rType)95 uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException)
96 {
97 uno::Any aReturn = ToolboxController::queryInterface( rType );
98 if ( !aReturn.hasValue() )
99 {
100 aReturn = ShapeToolbarController_Base::queryInterface( rType );
101 }
102 return aReturn;
103 }
104
acquire()105 void ShapeToolbarController::acquire() throw ()
106 {
107 ToolboxController::acquire();
108 }
109
release()110 void ShapeToolbarController::release() throw ()
111 {
112 ToolboxController::release();
113 }
114
115 // ::com::sun::star::lang::XInitialization
initialize(const Sequence<uno::Any> & rArguments)116 void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException)
117 {
118 ToolboxController::initialize( rArguments );
119 ::vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
120 ::osl::MutexGuard aGuard( m_aMutex );
121
122 ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
123 if ( pToolBox )
124 {
125 const sal_uInt16 nCount = pToolBox->GetItemCount();
126 for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
127 {
128 const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
129 if ( pToolBox->GetItemCommand( nItemId ) == String( m_aCommandURL ) )
130 {
131 m_nToolBoxId = nItemId;
132 break;
133 }
134 }
135 if ( m_aCommandURL.equalsAscii( ".uno:BasicShapes" ) )
136 {
137 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes" ) ), sal_True ) );
138 m_nSlotId = SID_DRAWTBX_CS_BASIC;
139 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
140 }
141 else if ( m_aCommandURL.equalsAscii( ".uno:SymbolShapes" ) )
142 {
143 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes" ) ), sal_True ) );
144 m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
145 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
146 }
147 else if ( m_aCommandURL.equalsAscii( ".uno:ArrowShapes" ) )
148 {
149 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes" ) ), sal_True ) );
150 m_nSlotId = SID_DRAWTBX_CS_ARROW;
151 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox) );
152 }
153 else if ( m_aCommandURL.equalsAscii( ".uno:FlowChartShapes" ) )
154 {
155 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes" ) ), sal_True ) );
156 m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
157 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
158 }
159 else if ( m_aCommandURL.equalsAscii( ".uno:CalloutShapes" ) )
160 {
161 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes" ) ), sal_True ) );
162 m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
163 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
164 }
165 else if ( m_aCommandURL.equalsAscii( ".uno:StarShapes" ) )
166 {
167 m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes" ) ), sal_True ) );
168 m_nSlotId = SID_DRAWTBX_CS_STAR;
169 m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
170 }
171
172 for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
173 {
174 addStatusListener( aIter->first );
175 }
176
177 if ( m_pToolbarController.is() )
178 {
179 m_pToolbarController->initialize( rArguments );
180 }
181
182 // check if paste special is allowed, when not don't add DROPDOWN
183 pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | TIB_DROPDOWN );
184 }
185 }
186
187 // ::com::sun::star::frame::XStatusListener
statusChanged(const frame::FeatureStateEvent & Event)188 void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException )
189 {
190 ::osl::MutexGuard aGuard( m_aMutex );
191 TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
192 if ( aFind != m_aStates.end() )
193 {
194 aFind->second = Event.IsEnabled;
195 if ( m_pToolbarController.is() )
196 {
197 sal_Bool bCheckmark = sal_False;
198 ToolBox& rTb = m_pToolbarController->GetToolBox();
199
200 for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
201 {
202 sal_uInt16 nId = rTb.GetItemId( i );
203 if ( nId == 0 )
204 {
205 continue;
206 }
207 ::rtl::OUString aCmd = rTb.GetItemCommand( nId );
208 if ( aCmd == Event.FeatureURL.Complete )
209 {
210 rTb.EnableItem( nId, Event.IsEnabled );
211 if ( Event.State >>= bCheckmark )
212 {
213 rTb.CheckItem( nId, bCheckmark );
214 }
215 else
216 {
217 ::rtl::OUString aItemText;
218 if ( Event.State >>= aItemText )
219 {
220 rTb.SetItemText( nId, aItemText );
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228
229 // ::com::sun::star::frame::XToolbarController
createPopupWindow()230 Reference< awt::XWindow > ShapeToolbarController::createPopupWindow() throw (uno::RuntimeException)
231 {
232 ::vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
233 ::osl::MutexGuard aGuard( m_aMutex );
234
235 Reference< awt::XWindow > xRet;
236 if ( m_pToolbarController.is() )
237 {
238 xRet = m_pToolbarController.getRef()->createPopupWindow();
239 }
240
241 return xRet;
242 }
243
244 // ::com::sun::star::frame::XSubToolbarController
opensSubToolbar()245 ::sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException)
246 {
247 return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
248 m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
249 m_nSlotId == SID_DRAWTBX_CS_ARROW ||
250 m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
251 m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
252 m_nSlotId == SID_DRAWTBX_CS_STAR );
253 }
254
getSubToolbarName()255 ::rtl::OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException)
256 {
257 ::vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
258 ::osl::MutexGuard aGuard(m_aMutex);
259 uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
260 if ( xSub.is() )
261 {
262 return xSub->getSubToolbarName();
263 }
264 return ::rtl::OUString();
265 }
266
functionSelected(const::rtl::OUString & rCommand)267 void ShapeToolbarController::functionSelected( const ::rtl::OUString& rCommand ) throw (uno::RuntimeException)
268 {
269 ::vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
270 ::osl::MutexGuard aGuard( m_aMutex );
271
272 uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
273 if ( xSub.is() )
274 {
275 m_aCommandURL = rCommand;
276 xSub->functionSelected( rCommand );
277 }
278 }
279
updateImage()280 void ShapeToolbarController::updateImage() throw (uno::RuntimeException)
281 {
282 ::vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
283 ::osl::MutexGuard aGuard( m_aMutex );
284
285 uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
286 if ( xSub.is() )
287 {
288 xSub->updateImage();
289 }
290 }
291
292 //.............................................................................
293 } // namespace chart
294 //.............................................................................
295