xref: /AOO41X/main/svtools/source/uno/toolboxcontroller.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx>
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
28cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
29cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
32cdf0e10cSrcweir #include <vos/mutex.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <svtools/imgdef.hxx>
35cdf0e10cSrcweir #include <svtools/miscopt.hxx>
36cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
37cdf0e10cSrcweir #include <vcl/toolbox.hxx>
38cdf0e10cSrcweir //shizhobo
39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
40cdf0e10cSrcweir const int TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIABLE  = 1;
41cdf0e10cSrcweir const int TOOLBARCONTROLLER_PROPCOUNT               = 1;
42cdf0e10cSrcweir const rtl::OUString TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIABLE( RTL_CONSTASCII_USTRINGPARAM( "SupportsVisiable" ));
43cdf0e10cSrcweir //end
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using ::rtl::OUString;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace ::cppu;
48cdf0e10cSrcweir using namespace ::com::sun::star::awt;
49cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir using namespace ::com::sun::star::util;
51cdf0e10cSrcweir using namespace ::com::sun::star::beans;
52cdf0e10cSrcweir using namespace ::com::sun::star::lang;
53cdf0e10cSrcweir using namespace ::com::sun::star::frame;
54cdf0e10cSrcweir using namespace ::com::sun::star::frame;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace svt
57cdf0e10cSrcweir {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir struct DispatchInfo
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	Reference< XDispatch > mxDispatch;
62cdf0e10cSrcweir 	const URL maURL;
63cdf0e10cSrcweir 	const Sequence< PropertyValue > maArgs;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	DispatchInfo( const Reference< XDispatch >& xDispatch, const URL& rURL, const Sequence< PropertyValue >& rArgs )
66cdf0e10cSrcweir 		: mxDispatch( xDispatch ), maURL( rURL ), maArgs( rArgs ) {}
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir struct ToolboxController_Impl
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >          m_xParentWindow;
72cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xUrlTransformer;
73cdf0e10cSrcweir 	rtl::OUString m_sModuleName;
74cdf0e10cSrcweir 	 sal_uInt16 m_nToolBoxId;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	DECL_STATIC_LINK( ToolboxController_Impl, ExecuteHdl_Impl, DispatchInfo* );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	ToolboxController_Impl()
79cdf0e10cSrcweir 		: m_nToolBoxId( SAL_MAX_UINT16 )
80cdf0e10cSrcweir 	{}
81cdf0e10cSrcweir };
82cdf0e10cSrcweir 
83cdf0e10cSrcweir ToolboxController::ToolboxController(
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     const Reference< XMultiServiceFactory >& rServiceManager,
86cdf0e10cSrcweir     const Reference< XFrame >& xFrame,
87cdf0e10cSrcweir     const ::rtl::OUString& aCommandURL ) :
88cdf0e10cSrcweir     OPropertyContainer(GetBroadcastHelper())
89cdf0e10cSrcweir     ,	OWeakObject()
90cdf0e10cSrcweir     ,   m_bInitialized( sal_False )
91cdf0e10cSrcweir     ,   m_bDisposed( sal_False )
92cdf0e10cSrcweir 	,	m_xFrame(xFrame)
93cdf0e10cSrcweir     ,   m_xServiceManager( rServiceManager )
94cdf0e10cSrcweir     ,   m_aCommandURL( aCommandURL )
95cdf0e10cSrcweir     ,   m_aListenerContainer( m_aMutex )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	//registger Propertyh by shizhoubo
98cdf0e10cSrcweir 	registerProperty(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIABLE, TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIABLE, com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY,
99cdf0e10cSrcweir 		&m_bSupportVisiable, getCppuType(&m_bSupportVisiable));
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	m_pImpl = new ToolboxController_Impl;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	try
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		m_pImpl->m_xUrlTransformer.set( m_xServiceManager->createInstance(
106cdf0e10cSrcweir                                                             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
107cdf0e10cSrcweir                                                         UNO_QUERY );
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 	catch(const Exception&)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir ToolboxController::ToolboxController() :
115cdf0e10cSrcweir     OPropertyContainer(GetBroadcastHelper())
116cdf0e10cSrcweir     ,	OWeakObject()
117cdf0e10cSrcweir     ,   m_bInitialized( sal_False )
118cdf0e10cSrcweir     ,   m_bDisposed( sal_False )
119cdf0e10cSrcweir     ,   m_aListenerContainer( m_aMutex )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	//registger Propertyh by shizhoubo
122cdf0e10cSrcweir 	registerProperty(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIABLE, TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIABLE, com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY,
123cdf0e10cSrcweir 		&m_bSupportVisiable, getCppuType(&m_bSupportVisiable));
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	m_pImpl = new ToolboxController_Impl;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir ToolboxController::~ToolboxController()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	delete m_pImpl;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir Reference< XFrame > ToolboxController::getFrameInterface() const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
136cdf0e10cSrcweir     return m_xFrame;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir Reference< XMultiServiceFactory > ToolboxController::getServiceManager() const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
142cdf0e10cSrcweir     return m_xServiceManager;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir Reference< XLayoutManager > ToolboxController::getLayoutManager() const
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     Reference< XLayoutManager > xLayoutManager;
148cdf0e10cSrcweir     Reference< XPropertySet > xPropSet;
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
151cdf0e10cSrcweir         xPropSet = Reference< XPropertySet >( m_xFrame, UNO_QUERY );
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     if ( xPropSet.is() )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         try
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             xLayoutManager.set(xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))),UNO_QUERY);
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir         catch ( Exception& )
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     return xLayoutManager;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir // XInterface
169cdf0e10cSrcweir Any SAL_CALL ToolboxController::queryInterface( const Type& rType )
170cdf0e10cSrcweir throw ( RuntimeException )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
173cdf0e10cSrcweir 				rType ,
174cdf0e10cSrcweir 				static_cast< XToolbarController* >( this ),
175cdf0e10cSrcweir 				static_cast< XStatusListener* >( this ),
176cdf0e10cSrcweir 				static_cast< XEventListener* >( this ),
177cdf0e10cSrcweir 				static_cast< XInitialization* >( this ),
178cdf0e10cSrcweir                 static_cast< XComponent* >( this ),
179cdf0e10cSrcweir                 static_cast< XUpdatable* >( this ));
180cdf0e10cSrcweir     if ( !a.hasValue())
181cdf0e10cSrcweir 	{
182cdf0e10cSrcweir 		a = ::cppu::queryInterface(rType
183cdf0e10cSrcweir 			,static_cast<XPropertySet*>(this)
184cdf0e10cSrcweir 			,static_cast<XMultiPropertySet*>(this)
185cdf0e10cSrcweir 			,static_cast<XFastPropertySet*>(this));
186cdf0e10cSrcweir 		if (!a.hasValue())
187cdf0e10cSrcweir 			return OWeakObject::queryInterface( rType );
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	return a;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir void SAL_CALL ToolboxController::acquire() throw ()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     OWeakObject::acquire();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir void SAL_CALL ToolboxController::release() throw ()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     OWeakObject::release();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir void SAL_CALL ToolboxController::initialize( const Sequence< Any >& aArguments )
203cdf0e10cSrcweir throw ( Exception, RuntimeException )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     bool bInitialized( true );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         if ( m_bDisposed )
211cdf0e10cSrcweir             throw DisposedException();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         bInitialized = m_bInitialized;
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     if ( !bInitialized )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
219cdf0e10cSrcweir         m_bInitialized = sal_True;
220cdf0e10cSrcweir         //shizhoubo add
221cdf0e10cSrcweir         m_bSupportVisiable = sal_False;
222cdf0e10cSrcweir         PropertyValue aPropValue;
223cdf0e10cSrcweir         for ( int i = 0; i < aArguments.getLength(); i++ )
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             if ( aArguments[i] >>= aPropValue )
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Frame") ))
228cdf0e10cSrcweir 					m_xFrame.set(aPropValue.Value,UNO_QUERY);
229cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CommandURL") ))
230cdf0e10cSrcweir                     aPropValue.Value >>= m_aCommandURL;
231cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ServiceManager") ))
232cdf0e10cSrcweir 					m_xServiceManager.set(aPropValue.Value,UNO_QUERY);
233cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ParentWindow") ))
234cdf0e10cSrcweir 					m_pImpl->m_xParentWindow.set(aPropValue.Value,UNO_QUERY);
235cdf0e10cSrcweir 				else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("ModuleName" ) ) )
236cdf0e10cSrcweir 					aPropValue.Value >>= m_pImpl->m_sModuleName;
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 		try
241cdf0e10cSrcweir 		{
242cdf0e10cSrcweir 			if ( !m_pImpl->m_xUrlTransformer.is() && m_xServiceManager.is() )
243cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer.set( m_xServiceManager->createInstance(
244cdf0e10cSrcweir 																rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
245cdf0e10cSrcweir 															UNO_QUERY );
246cdf0e10cSrcweir 		}
247cdf0e10cSrcweir 		catch(const Exception&)
248cdf0e10cSrcweir 		{
249cdf0e10cSrcweir 		}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         if ( m_aCommandURL.getLength() )
252cdf0e10cSrcweir             m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() ));
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir void SAL_CALL ToolboxController::update()
257cdf0e10cSrcweir throw ( RuntimeException )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
261cdf0e10cSrcweir         if ( m_bDisposed )
262cdf0e10cSrcweir             throw DisposedException();
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     // Bind all registered listeners to their dispatch objects
266cdf0e10cSrcweir     bindListener();
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir // XComponent
270cdf0e10cSrcweir void SAL_CALL ToolboxController::dispose()
271cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
277cdf0e10cSrcweir         if ( m_bDisposed )
278cdf0e10cSrcweir             throw DisposedException();
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     com::sun::star::lang::EventObject aEvent( xThis );
282cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
285cdf0e10cSrcweir     Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
286cdf0e10cSrcweir     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
287cdf0e10cSrcweir     while ( pIter != m_aListenerMap.end() )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         try
290cdf0e10cSrcweir         {
291cdf0e10cSrcweir             Reference< XDispatch > xDispatch( pIter->second );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir             com::sun::star::util::URL aTargetURL;
294cdf0e10cSrcweir             aTargetURL.Complete = pIter->first;
295cdf0e10cSrcweir 			if ( m_pImpl->m_xUrlTransformer.is() )
296cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir             if ( xDispatch.is() && xStatusListener.is() )
299cdf0e10cSrcweir                 xDispatch->removeStatusListener( xStatusListener, aTargetURL );
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir         catch ( Exception& )
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         ++pIter;
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     m_bDisposed = sal_True;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir void SAL_CALL ToolboxController::addEventListener( const Reference< XEventListener >& xListener )
312cdf0e10cSrcweir throw ( RuntimeException )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir void SAL_CALL ToolboxController::removeEventListener( const Reference< XEventListener >& aListener )
318cdf0e10cSrcweir throw ( RuntimeException )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir     m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener );
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir // XEventListener
324cdf0e10cSrcweir void SAL_CALL ToolboxController::disposing( const EventObject& Source )
325cdf0e10cSrcweir throw ( RuntimeException )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir     Reference< XInterface > xSource( Source.Source );
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     if ( m_bDisposed )
332cdf0e10cSrcweir         return;
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
335cdf0e10cSrcweir     while ( pIter != m_aListenerMap.end() )
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         // Compare references and release dispatch references if they are equal.
338cdf0e10cSrcweir         Reference< XInterface > xIfac( pIter->second, UNO_QUERY );
339cdf0e10cSrcweir         if ( xSource == xIfac )
340cdf0e10cSrcweir             pIter->second.clear();
341cdf0e10cSrcweir 		++pIter;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     Reference< XInterface > xIfac( m_xFrame, UNO_QUERY );
345cdf0e10cSrcweir     if ( xIfac == xSource )
346cdf0e10cSrcweir         m_xFrame.clear();
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir // XStatusListener
350cdf0e10cSrcweir void SAL_CALL ToolboxController::statusChanged( const FeatureStateEvent& )
351cdf0e10cSrcweir throw ( RuntimeException )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir     // must be implemented by sub class
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir // XToolbarController
357cdf0e10cSrcweir void SAL_CALL ToolboxController::execute( sal_Int16 KeyModifier )
358cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     Reference< XDispatch >       xDispatch;
361cdf0e10cSrcweir     ::rtl::OUString                     aCommandURL;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     {
364cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         if ( m_bDisposed )
367cdf0e10cSrcweir             throw DisposedException();
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         if ( m_bInitialized &&
370cdf0e10cSrcweir              m_xFrame.is() &&
371cdf0e10cSrcweir              m_xServiceManager.is() &&
372cdf0e10cSrcweir              m_aCommandURL.getLength() )
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir 
375cdf0e10cSrcweir             aCommandURL = m_aCommandURL;
376cdf0e10cSrcweir             URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
377cdf0e10cSrcweir             if ( pIter != m_aListenerMap.end() )
378cdf0e10cSrcweir                 xDispatch = pIter->second;
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     if ( xDispatch.is() )
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         try
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir             com::sun::star::util::URL aTargetURL;
387cdf0e10cSrcweir             Sequence<PropertyValue>   aArgs( 1 );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir             // Provide key modifier information to dispatch function
390cdf0e10cSrcweir             aArgs[0].Name   = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
391cdf0e10cSrcweir             aArgs[0].Value  = makeAny( KeyModifier );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir             aTargetURL.Complete = aCommandURL;
394cdf0e10cSrcweir 			if ( m_pImpl->m_xUrlTransformer.is() )
395cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
396cdf0e10cSrcweir             xDispatch->dispatch( aTargetURL, aArgs );
397cdf0e10cSrcweir         }
398cdf0e10cSrcweir         catch ( DisposedException& )
399cdf0e10cSrcweir         {
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir     }
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir void SAL_CALL ToolboxController::click()
405cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir void SAL_CALL ToolboxController::doubleClick()
410cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir Reference< XWindow > SAL_CALL ToolboxController::createPopupWindow()
415cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     return Reference< XWindow >();
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir Reference< XWindow > SAL_CALL ToolboxController::createItemWindow( const Reference< XWindow >& )
421cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
422cdf0e10cSrcweir {
423cdf0e10cSrcweir     return Reference< XWindow >();
424cdf0e10cSrcweir }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir void ToolboxController::addStatusListener( const rtl::OUString& aCommandURL )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     Reference< XDispatch >       xDispatch;
429cdf0e10cSrcweir     Reference< XStatusListener > xStatusListener;
430cdf0e10cSrcweir     com::sun::star::util::URL    aTargetURL;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     {
433cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
434cdf0e10cSrcweir         URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir         // Already in the list of status listener. Do nothing.
437cdf0e10cSrcweir         if ( pIter != m_aListenerMap.end() )
438cdf0e10cSrcweir             return;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir         // Check if we are already initialized. Implementation starts adding itself as status listener when
441cdf0e10cSrcweir         // intialize is called.
442cdf0e10cSrcweir         if ( !m_bInitialized )
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir             // Put into the hash_map of status listener. Will be activated when initialized is called
445cdf0e10cSrcweir             m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, Reference< XDispatch >() ));
446cdf0e10cSrcweir             return;
447cdf0e10cSrcweir         }
448cdf0e10cSrcweir         else
449cdf0e10cSrcweir         {
450cdf0e10cSrcweir             // Add status listener directly as intialize has already been called.
451cdf0e10cSrcweir             Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
452cdf0e10cSrcweir             if ( m_xServiceManager.is() && xDispatchProvider.is() )
453cdf0e10cSrcweir             {
454cdf0e10cSrcweir                 aTargetURL.Complete = aCommandURL;
455cdf0e10cSrcweir                 if ( m_pImpl->m_xUrlTransformer.is() )
456cdf0e10cSrcweir 					m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
457cdf0e10cSrcweir                 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
458cdf0e10cSrcweir 
459cdf0e10cSrcweir                 xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
460cdf0e10cSrcweir                 URLToDispatchMap::iterator aIter = m_aListenerMap.find( aCommandURL );
461cdf0e10cSrcweir                 if ( aIter != m_aListenerMap.end() )
462cdf0e10cSrcweir                 {
463cdf0e10cSrcweir                     Reference< XDispatch > xOldDispatch( aIter->second );
464cdf0e10cSrcweir                     aIter->second = xDispatch;
465cdf0e10cSrcweir 
466cdf0e10cSrcweir                     try
467cdf0e10cSrcweir                     {
468cdf0e10cSrcweir                         if ( xOldDispatch.is() )
469cdf0e10cSrcweir                             xOldDispatch->removeStatusListener( xStatusListener, aTargetURL );
470cdf0e10cSrcweir                     }
471cdf0e10cSrcweir                     catch ( Exception& )
472cdf0e10cSrcweir                     {
473cdf0e10cSrcweir                     }
474cdf0e10cSrcweir                 }
475cdf0e10cSrcweir                 else
476cdf0e10cSrcweir                     m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, xDispatch ));
477cdf0e10cSrcweir             }
478cdf0e10cSrcweir         }
479cdf0e10cSrcweir     }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     // Call without locked mutex as we are called back from dispatch implementation
482cdf0e10cSrcweir     try
483cdf0e10cSrcweir     {
484cdf0e10cSrcweir         if ( xDispatch.is() )
485cdf0e10cSrcweir             xDispatch->addStatusListener( xStatusListener, aTargetURL );
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir     catch ( Exception& )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir     }
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir void ToolboxController::removeStatusListener( const rtl::OUString& aCommandURL )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir     URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL );
497cdf0e10cSrcweir     if ( pIter != m_aListenerMap.end() )
498cdf0e10cSrcweir     {
499cdf0e10cSrcweir         Reference< XDispatch > xDispatch( pIter->second );
500cdf0e10cSrcweir         Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
501cdf0e10cSrcweir         m_aListenerMap.erase( pIter );
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         try
504cdf0e10cSrcweir         {
505cdf0e10cSrcweir             com::sun::star::util::URL aTargetURL;
506cdf0e10cSrcweir             aTargetURL.Complete = aCommandURL;
507cdf0e10cSrcweir             if ( m_pImpl->m_xUrlTransformer.is() )
508cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
509cdf0e10cSrcweir 
510cdf0e10cSrcweir             if ( xDispatch.is() && xStatusListener.is() )
511cdf0e10cSrcweir                 xDispatch->removeStatusListener( xStatusListener, aTargetURL );
512cdf0e10cSrcweir         }
513cdf0e10cSrcweir         catch ( Exception& )
514cdf0e10cSrcweir         {
515cdf0e10cSrcweir         }
516cdf0e10cSrcweir     }
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir void ToolboxController::bindListener()
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     std::vector< Listener > aDispatchVector;
522cdf0e10cSrcweir     Reference< XStatusListener > xStatusListener;
523cdf0e10cSrcweir 
524cdf0e10cSrcweir     {
525cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir         if ( !m_bInitialized )
528cdf0e10cSrcweir             return;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir         // Collect all registered command URL's and store them temporary
531cdf0e10cSrcweir         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
532cdf0e10cSrcweir         if ( m_xServiceManager.is() && xDispatchProvider.is() )
533cdf0e10cSrcweir         {
534cdf0e10cSrcweir             xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
535cdf0e10cSrcweir             URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
536cdf0e10cSrcweir             while ( pIter != m_aListenerMap.end() )
537cdf0e10cSrcweir             {
538cdf0e10cSrcweir                 com::sun::star::util::URL aTargetURL;
539cdf0e10cSrcweir                 aTargetURL.Complete = pIter->first;
540cdf0e10cSrcweir                 if ( m_pImpl->m_xUrlTransformer.is() )
541cdf0e10cSrcweir 					m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir                 Reference< XDispatch > xDispatch( pIter->second );
544cdf0e10cSrcweir                 if ( xDispatch.is() )
545cdf0e10cSrcweir                 {
546cdf0e10cSrcweir                     // We already have a dispatch object => we have to requery.
547cdf0e10cSrcweir                     // Release old dispatch object and remove it as listener
548cdf0e10cSrcweir                     try
549cdf0e10cSrcweir                     {
550cdf0e10cSrcweir                         xDispatch->removeStatusListener( xStatusListener, aTargetURL );
551cdf0e10cSrcweir                     }
552cdf0e10cSrcweir                     catch ( Exception& )
553cdf0e10cSrcweir                     {
554cdf0e10cSrcweir                     }
555cdf0e10cSrcweir                 }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir                 pIter->second.clear();
558cdf0e10cSrcweir                 xDispatch.clear();
559cdf0e10cSrcweir 
560cdf0e10cSrcweir                 // Query for dispatch object. Old dispatch will be released with this, too.
561cdf0e10cSrcweir                 try
562cdf0e10cSrcweir                 {
563cdf0e10cSrcweir                     xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
564cdf0e10cSrcweir                 }
565cdf0e10cSrcweir                 catch ( Exception& )
566cdf0e10cSrcweir                 {
567cdf0e10cSrcweir                 }
568cdf0e10cSrcweir                 pIter->second = xDispatch;
569cdf0e10cSrcweir 
570cdf0e10cSrcweir                 Listener aListener( aTargetURL, xDispatch );
571cdf0e10cSrcweir                 aDispatchVector.push_back( aListener );
572cdf0e10cSrcweir                 ++pIter;
573cdf0e10cSrcweir             }
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     // Call without locked mutex as we are called back from dispatch implementation
578cdf0e10cSrcweir     if ( xStatusListener.is() )
579cdf0e10cSrcweir     {
580cdf0e10cSrcweir         try
581cdf0e10cSrcweir         {
582cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ )
583cdf0e10cSrcweir             {
584cdf0e10cSrcweir                 Listener& rListener = aDispatchVector[i];
585cdf0e10cSrcweir                 if ( rListener.xDispatch.is() )
586cdf0e10cSrcweir                     rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL );
587cdf0e10cSrcweir                 else if ( rListener.aURL.Complete == m_aCommandURL )
588cdf0e10cSrcweir                 {
589cdf0e10cSrcweir                     try
590cdf0e10cSrcweir                     {
591cdf0e10cSrcweir                         // Send status changed for the main URL, if we cannot get a valid dispatch object.
592cdf0e10cSrcweir                         // UI disables the button. Catch exception as we release our mutex, it is possible
593cdf0e10cSrcweir                         // that someone else already disposed this instance!
594cdf0e10cSrcweir                         FeatureStateEvent aFeatureStateEvent;
595cdf0e10cSrcweir                         aFeatureStateEvent.IsEnabled = sal_False;
596cdf0e10cSrcweir                         aFeatureStateEvent.FeatureURL = rListener.aURL;
597cdf0e10cSrcweir                         aFeatureStateEvent.State = Any();
598cdf0e10cSrcweir                         xStatusListener->statusChanged( aFeatureStateEvent );
599cdf0e10cSrcweir                     }
600cdf0e10cSrcweir                     catch ( Exception& )
601cdf0e10cSrcweir                     {
602cdf0e10cSrcweir                     }
603cdf0e10cSrcweir                 }
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir         }
606cdf0e10cSrcweir         catch ( Exception& )
607cdf0e10cSrcweir         {
608cdf0e10cSrcweir         }
609cdf0e10cSrcweir     }
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir void ToolboxController::unbindListener()
613cdf0e10cSrcweir {
614cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
615cdf0e10cSrcweir 
616cdf0e10cSrcweir     if ( !m_bInitialized )
617cdf0e10cSrcweir         return;
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     // Collect all registered command URL's and store them temporary
620cdf0e10cSrcweir     Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
621cdf0e10cSrcweir     if ( m_xServiceManager.is() && xDispatchProvider.is() )
622cdf0e10cSrcweir     {
623cdf0e10cSrcweir         Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY );
624cdf0e10cSrcweir         URLToDispatchMap::iterator pIter = m_aListenerMap.begin();
625cdf0e10cSrcweir         while ( pIter != m_aListenerMap.end() )
626cdf0e10cSrcweir         {
627cdf0e10cSrcweir             com::sun::star::util::URL aTargetURL;
628cdf0e10cSrcweir             aTargetURL.Complete = pIter->first;
629cdf0e10cSrcweir             if ( m_pImpl->m_xUrlTransformer.is() )
630cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
631cdf0e10cSrcweir 
632cdf0e10cSrcweir             Reference< XDispatch > xDispatch( pIter->second );
633cdf0e10cSrcweir             if ( xDispatch.is() )
634cdf0e10cSrcweir             {
635cdf0e10cSrcweir                 // We already have a dispatch object => we have to requery.
636cdf0e10cSrcweir                 // Release old dispatch object and remove it as listener
637cdf0e10cSrcweir                 try
638cdf0e10cSrcweir                 {
639cdf0e10cSrcweir                     xDispatch->removeStatusListener( xStatusListener, aTargetURL );
640cdf0e10cSrcweir                 }
641cdf0e10cSrcweir                 catch ( Exception& )
642cdf0e10cSrcweir                 {
643cdf0e10cSrcweir                 }
644cdf0e10cSrcweir             }
645cdf0e10cSrcweir             pIter->second.clear();
646cdf0e10cSrcweir             ++pIter;
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir sal_Bool ToolboxController::isBound() const
652cdf0e10cSrcweir {
653cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     if ( !m_bInitialized )
656cdf0e10cSrcweir         return sal_False;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     URLToDispatchMap::const_iterator pIter = m_aListenerMap.find( m_aCommandURL );
659cdf0e10cSrcweir     if ( pIter != m_aListenerMap.end() )
660cdf0e10cSrcweir         return ( pIter->second.is() );
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     return sal_False;
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir sal_Bool ToolboxController::hasBigImages() const
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     return SvtMiscOptions().AreCurrentSymbolsLarge();
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir sal_Bool ToolboxController::isHighContrast() const
671cdf0e10cSrcweir {
672cdf0e10cSrcweir     sal_Bool bHighContrast( sal_False );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     Reference< XWindow > xWindow = m_pImpl->m_xParentWindow;
675cdf0e10cSrcweir     if ( xWindow.is() )
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
678cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
679cdf0e10cSrcweir         if ( pWindow )
680cdf0e10cSrcweir 	        bHighContrast = ( ((ToolBox *)pWindow)->GetSettings().GetStyleSettings().GetHighContrastMode() );
681cdf0e10cSrcweir     }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir     return bHighContrast;
684cdf0e10cSrcweir }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir void ToolboxController::updateStatus()
687cdf0e10cSrcweir {
688cdf0e10cSrcweir     bindListener();
689cdf0e10cSrcweir }
690cdf0e10cSrcweir 
691cdf0e10cSrcweir void ToolboxController::updateStatus( const rtl::OUString aCommandURL )
692cdf0e10cSrcweir {
693cdf0e10cSrcweir     Reference< XDispatch > xDispatch;
694cdf0e10cSrcweir     Reference< XStatusListener > xStatusListener;
695cdf0e10cSrcweir     com::sun::star::util::URL aTargetURL;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir     {
698cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir         if ( !m_bInitialized )
701cdf0e10cSrcweir             return;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir         // Try to find a dispatch object for the requested command URL
704cdf0e10cSrcweir         Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
705cdf0e10cSrcweir         xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY );
706cdf0e10cSrcweir         if ( m_xServiceManager.is() && xDispatchProvider.is() )
707cdf0e10cSrcweir         {
708cdf0e10cSrcweir             aTargetURL.Complete = aCommandURL;
709cdf0e10cSrcweir             if ( m_pImpl->m_xUrlTransformer.is() )
710cdf0e10cSrcweir 				m_pImpl->m_xUrlTransformer->parseStrict( aTargetURL );
711cdf0e10cSrcweir             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, rtl::OUString(), 0 );
712cdf0e10cSrcweir         }
713cdf0e10cSrcweir     }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir     if ( xDispatch.is() && xStatusListener.is() )
716cdf0e10cSrcweir     {
717cdf0e10cSrcweir         // Catch exception as we release our mutex, it is possible that someone else
718cdf0e10cSrcweir         // has already disposed this instance!
719cdf0e10cSrcweir         // Add/remove status listener to get a update status information from the
720cdf0e10cSrcweir         // requested command.
721cdf0e10cSrcweir         try
722cdf0e10cSrcweir         {
723cdf0e10cSrcweir             xDispatch->addStatusListener( xStatusListener, aTargetURL );
724cdf0e10cSrcweir             xDispatch->removeStatusListener( xStatusListener, aTargetURL );
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir         catch ( Exception& )
727cdf0e10cSrcweir         {
728cdf0e10cSrcweir         }
729cdf0e10cSrcweir     }
730cdf0e10cSrcweir }
731cdf0e10cSrcweir 
732cdf0e10cSrcweir Reference< XURLTransformer > ToolboxController::getURLTransformer() const
733cdf0e10cSrcweir {
734cdf0e10cSrcweir 	return m_pImpl->m_xUrlTransformer;
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir Reference< ::com::sun::star::awt::XWindow > ToolboxController::getParent() const
738cdf0e10cSrcweir {
739cdf0e10cSrcweir 	return m_pImpl->m_xParentWindow;
740cdf0e10cSrcweir }
741cdf0e10cSrcweir 
742cdf0e10cSrcweir const rtl::OUString& ToolboxController::getModuleName() const
743cdf0e10cSrcweir {
744cdf0e10cSrcweir 	return m_pImpl->m_sModuleName;
745cdf0e10cSrcweir }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir void ToolboxController::dispatchCommand( const OUString& sCommandURL, const Sequence< PropertyValue >& rArgs )
748cdf0e10cSrcweir {
749cdf0e10cSrcweir     try
750cdf0e10cSrcweir     {
751cdf0e10cSrcweir 	    Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY_THROW );
752cdf0e10cSrcweir         URL aURL;
753cdf0e10cSrcweir         aURL.Complete = sCommandURL;
754cdf0e10cSrcweir         getURLTransformer()->parseStrict( aURL );
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 		Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch( aURL, OUString(), 0 ), UNO_QUERY_THROW );
757cdf0e10cSrcweir 
758cdf0e10cSrcweir         Application::PostUserEvent( STATIC_LINK(0, ToolboxController_Impl, ExecuteHdl_Impl), new DispatchInfo( xDispatch, aURL, rArgs ) );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir     }
761cdf0e10cSrcweir 	catch( Exception& )
762cdf0e10cSrcweir 	{
763cdf0e10cSrcweir 	}
764cdf0e10cSrcweir }
765cdf0e10cSrcweir 
766cdf0e10cSrcweir //
767cdf0e10cSrcweir //-------------------------------------------------------------------------
768cdf0e10cSrcweir // XPropertySet by shizhoubo
769cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >  SAL_CALL ToolboxController::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException)
770cdf0e10cSrcweir {
771cdf0e10cSrcweir 	Reference<XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) );
772cdf0e10cSrcweir 	return xInfo;
773cdf0e10cSrcweir }
774cdf0e10cSrcweir //-------------------------------------------------------------------------
775cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& ToolboxController::getInfoHelper()
776cdf0e10cSrcweir {
777cdf0e10cSrcweir 		return *const_cast<ToolboxController*>(this)->getArrayHelper();
778cdf0e10cSrcweir }
779cdf0e10cSrcweir //OPropertyArrayUsageHelper by shizhoubo
780cdf0e10cSrcweir //------------------------------------------------------------------------------
781cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* ToolboxController::createArrayHelper( ) const
782cdf0e10cSrcweir {
783cdf0e10cSrcweir 		com::sun::star::uno::Sequence< Property > aProps;
784cdf0e10cSrcweir 		describeProperties(aProps);
785cdf0e10cSrcweir 		return new ::cppu::OPropertyArrayHelper(aProps);
786cdf0e10cSrcweir }
787cdf0e10cSrcweir //shizhoubo for supportsvisiable
788cdf0e10cSrcweir void ToolboxController::setSupportVisiableProperty(sal_Bool bValue)
789cdf0e10cSrcweir {
790cdf0e10cSrcweir 	m_bSupportVisiable = bValue;
791cdf0e10cSrcweir }
792cdf0e10cSrcweir //OPropertySetHelper by shizhoubo
793cdf0e10cSrcweir sal_Bool SAL_CALL ToolboxController::convertFastPropertyValue( com::sun::star::uno::Any&    aConvertedValue ,
794cdf0e10cSrcweir                                              com::sun::star::uno::Any&        aOldValue       ,
795cdf0e10cSrcweir                                              sal_Int32                        nHandle         ,
796cdf0e10cSrcweir                                              const com::sun::star::uno::Any&  aValue          ) throw( com::sun::star::lang::IllegalArgumentException )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir 	switch (nHandle)
799cdf0e10cSrcweir 	{
800cdf0e10cSrcweir 		case TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIABLE:
801cdf0e10cSrcweir 		{
802cdf0e10cSrcweir 			sal_Bool aNewValue(sal_False);
803cdf0e10cSrcweir 			aValue >>= aNewValue;
804cdf0e10cSrcweir 			if (aNewValue != m_bSupportVisiable)
805cdf0e10cSrcweir 			{
806cdf0e10cSrcweir 				aConvertedValue <<= aNewValue;
807cdf0e10cSrcweir 				aOldValue <<= m_bSupportVisiable;
808cdf0e10cSrcweir 				return sal_True;
809cdf0e10cSrcweir 			}
810cdf0e10cSrcweir 			return sal_False;
811cdf0e10cSrcweir 		}
812cdf0e10cSrcweir 	}
813cdf0e10cSrcweir 	return OPropertyContainer::convertFastPropertyValue(aConvertedValue, aOldValue, nHandle, aValue);
814cdf0e10cSrcweir }
815cdf0e10cSrcweir 
816cdf0e10cSrcweir void SAL_CALL ToolboxController::setFastPropertyValue_NoBroadcast(
817cdf0e10cSrcweir     sal_Int32                       nHandle,
818cdf0e10cSrcweir     const com::sun::star::uno::Any& aValue )
819cdf0e10cSrcweir throw( com::sun::star::uno::Exception)
820cdf0e10cSrcweir {
821cdf0e10cSrcweir     OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, aValue);
822cdf0e10cSrcweir     if (TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIABLE == nHandle)
823cdf0e10cSrcweir     {
824cdf0e10cSrcweir         sal_Bool rValue(sal_False);
825cdf0e10cSrcweir         if (( aValue >>= rValue ) && m_bInitialized)
826cdf0e10cSrcweir             this->setSupportVisiableProperty( rValue );
827cdf0e10cSrcweir     }
828cdf0e10cSrcweir }
829cdf0e10cSrcweir 
830cdf0e10cSrcweir //--------------------------------------------------------------------
831cdf0e10cSrcweir 
832cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( ToolboxController_Impl, ExecuteHdl_Impl, DispatchInfo*, pDispatchInfo )
833cdf0e10cSrcweir {
834cdf0e10cSrcweir 	pDispatchInfo->mxDispatch->dispatch( pDispatchInfo->maURL, pDispatchInfo->maArgs );
835cdf0e10cSrcweir     delete pDispatchInfo;
836cdf0e10cSrcweir     return 0;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir void ToolboxController::enable( bool bEnable )
840cdf0e10cSrcweir {
841cdf0e10cSrcweir 	ToolBox* pToolBox = 0;
842cdf0e10cSrcweir 	sal_uInt16 nItemId = 0;
843cdf0e10cSrcweir 	if( getToolboxId( nItemId, &pToolBox ) )
844cdf0e10cSrcweir 	{
845cdf0e10cSrcweir 		pToolBox->EnableItem( nItemId, bEnable ? sal_True : sal_False );
846cdf0e10cSrcweir 	}
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir bool ToolboxController::getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir 	if( (m_pImpl->m_nToolBoxId != SAL_MAX_UINT16) && (ppToolBox == 0) )
852cdf0e10cSrcweir 		return m_pImpl->m_nToolBoxId;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 	if( (m_pImpl->m_nToolBoxId == SAL_MAX_UINT16) && pToolBox )
857cdf0e10cSrcweir 	{
858cdf0e10cSrcweir         const sal_uInt16 nCount = pToolBox->GetItemCount();
859cdf0e10cSrcweir 		for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
860cdf0e10cSrcweir 		{
861cdf0e10cSrcweir 			const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
862cdf0e10cSrcweir 			if ( pToolBox->GetItemCommand( nItemId ) == String( m_aCommandURL ) )
863cdf0e10cSrcweir 			{
864cdf0e10cSrcweir 				m_pImpl->m_nToolBoxId = nItemId;
865cdf0e10cSrcweir 				break;
866cdf0e10cSrcweir 			}
867cdf0e10cSrcweir 		}
868cdf0e10cSrcweir 	}
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 	if( ppToolBox )
871cdf0e10cSrcweir 		*ppToolBox = pToolBox;
872cdf0e10cSrcweir 
873cdf0e10cSrcweir 	rItemId = m_pImpl->m_nToolBoxId;
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 	return (rItemId != SAL_MAX_UINT16) && (( ppToolBox == 0) || (*ppToolBox != 0) );
876cdf0e10cSrcweir }
877cdf0e10cSrcweir //end
878cdf0e10cSrcweir 
879cdf0e10cSrcweir } // svt
880