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