1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/toolboxcontroller.hxx>
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/frame/XLayoutManager.hpp>
28 #include <com/sun/star/util/URLTransformer.hpp>
29 #include <osl/mutex.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svtools/imgdef.hxx>
32 #include <svtools/miscopt.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <vcl/toolbox.hxx>
35 #include <comphelper/processfactory.hxx>
37 const int TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
= 1;
38 const char TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE
[] = "SupportsVisible";
41 using namespace ::cppu
;
42 using namespace ::com::sun::star::awt
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::util
;
45 using namespace ::com::sun::star::beans
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::frame
;
52 ToolboxController::ToolboxController(
53 const Reference
< XComponentContext
>& rxContext
,
54 const Reference
< XFrame
>& xFrame
,
55 const OUString
& aCommandURL
) :
56 OPropertyContainer( GetBroadcastHelper() )
57 , m_bSupportVisible( false )
58 , m_bInitialized( false )
59 , m_bDisposed( false )
60 , m_nToolBoxId( SAL_MAX_UINT16
)
62 , m_xContext( rxContext
)
63 , m_aCommandURL( aCommandURL
)
64 , m_aListenerContainer( m_aMutex
)
66 OSL_ASSERT( m_xContext
.is() );
67 registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE
),
68 TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
,
69 css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
,
70 &m_bSupportVisible
, cppu::UnoType
<decltype(m_bSupportVisible
)>::get());
74 m_xUrlTransformer
= URLTransformer::create( rxContext
);
76 catch(const Exception
&)
81 ToolboxController::ToolboxController() :
82 OPropertyContainer(GetBroadcastHelper())
83 , m_bSupportVisible(false)
84 , m_bInitialized( false )
85 , m_bDisposed( false )
86 , m_nToolBoxId( SAL_MAX_UINT16
)
87 , m_aListenerContainer( m_aMutex
)
89 registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE
),
90 TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
,
91 css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
,
92 &m_bSupportVisible
, cppu::UnoType
<decltype(m_bSupportVisible
)>::get());
95 ToolboxController::~ToolboxController()
99 Reference
< XFrame
> ToolboxController::getFrameInterface() const
101 SolarMutexGuard aSolarMutexGuard
;
105 const Reference
< XComponentContext
> & ToolboxController::getContext() const
107 SolarMutexGuard aSolarMutexGuard
;
111 Reference
< XLayoutManager
> ToolboxController::getLayoutManager() const
113 Reference
< XLayoutManager
> xLayoutManager
;
114 Reference
< XPropertySet
> xPropSet
;
116 SolarMutexGuard aSolarMutexGuard
;
117 xPropSet
= Reference
< XPropertySet
>( m_xFrame
, UNO_QUERY
);
124 xLayoutManager
.set(xPropSet
->getPropertyValue("LayoutManager"),UNO_QUERY
);
131 return xLayoutManager
;
135 Any SAL_CALL
ToolboxController::queryInterface( const Type
& rType
)
136 throw ( RuntimeException
, std::exception
)
138 css::uno::Any
a(ToolboxController_Base::queryInterface(rType
));
139 return a
.hasValue() ? a
: OPropertyContainer::queryInterface(rType
);
142 void SAL_CALL
ToolboxController::acquire() throw ()
144 ToolboxController_Base::acquire();
147 void SAL_CALL
ToolboxController::release() throw ()
149 ToolboxController_Base::release();
152 css::uno::Sequence
<css::uno::Type
> ToolboxController::getTypes()
153 throw (css::uno::RuntimeException
, std::exception
)
155 css::uno::Sequence
<css::uno::Type
> s1(ToolboxController_Base::getTypes());
156 css::uno::Sequence
<css::uno::Type
> s2(getBaseTypes());
157 sal_Int32 n
= s1
.getLength();
158 s1
.realloc(n
+ s2
.getLength());
159 for (sal_Int32 i
= 0; i
!= s2
.getLength(); ++i
) {
165 void SAL_CALL
ToolboxController::initialize( const Sequence
< Any
>& aArguments
)
166 throw ( Exception
, RuntimeException
, std::exception
)
168 bool bInitialized( true );
171 SolarMutexGuard aSolarMutexGuard
;
174 throw DisposedException();
176 bInitialized
= m_bInitialized
;
181 SolarMutexGuard aSolarMutexGuard
;
182 m_bInitialized
= true;
183 m_bSupportVisible
= false;
184 PropertyValue aPropValue
;
185 for ( int i
= 0; i
< aArguments
.getLength(); i
++ )
187 if ( aArguments
[i
] >>= aPropValue
)
189 if ( aPropValue
.Name
== "Frame" )
190 m_xFrame
.set(aPropValue
.Value
,UNO_QUERY
);
191 else if ( aPropValue
.Name
== "CommandURL" )
192 aPropValue
.Value
>>= m_aCommandURL
;
193 else if ( aPropValue
.Name
== "ServiceManager" )
195 Reference
<XMultiServiceFactory
> xMSF(aPropValue
.Value
, UNO_QUERY
);
197 m_xContext
= comphelper::getComponentContext(xMSF
);
199 else if ( aPropValue
.Name
== "ParentWindow" )
200 m_xParentWindow
.set(aPropValue
.Value
,UNO_QUERY
);
201 else if ( aPropValue
.Name
== "ModuleIdentifier" )
202 aPropValue
.Value
>>= m_sModuleName
;
203 else if ( aPropValue
.Name
== "Identifier" )
204 aPropValue
.Value
>>= m_nToolBoxId
;
210 if ( !m_xUrlTransformer
.is() && m_xContext
.is() )
211 m_xUrlTransformer
= URLTransformer::create( m_xContext
);
213 catch(const Exception
&)
217 if ( !m_aCommandURL
.isEmpty() )
218 m_aListenerMap
.insert( URLToDispatchMap::value_type( m_aCommandURL
, Reference
< XDispatch
>() ));
222 void SAL_CALL
ToolboxController::update()
223 throw ( RuntimeException
, std::exception
)
226 SolarMutexGuard aSolarMutexGuard
;
228 throw DisposedException();
231 // Bind all registered listeners to their dispatch objects
236 void SAL_CALL
ToolboxController::dispose()
237 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
239 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
242 SolarMutexGuard aSolarMutexGuard
;
244 throw DisposedException();
247 com::sun::star::lang::EventObject
aEvent( xThis
);
248 m_aListenerContainer
.disposeAndClear( aEvent
);
250 SolarMutexGuard aSolarMutexGuard
;
251 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
252 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
253 while ( pIter
!= m_aListenerMap
.end() )
257 Reference
< XDispatch
> xDispatch( pIter
->second
);
259 com::sun::star::util::URL aTargetURL
;
260 aTargetURL
.Complete
= pIter
->first
;
261 if ( m_xUrlTransformer
.is() )
262 m_xUrlTransformer
->parseStrict( aTargetURL
);
264 if ( xDispatch
.is() && xStatusListener
.is() )
265 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
277 void SAL_CALL
ToolboxController::addEventListener( const Reference
< XEventListener
>& xListener
)
278 throw ( RuntimeException
, std::exception
)
280 m_aListenerContainer
.addInterface( cppu::UnoType
<XEventListener
>::get(), xListener
);
283 void SAL_CALL
ToolboxController::removeEventListener( const Reference
< XEventListener
>& aListener
)
284 throw ( RuntimeException
, std::exception
)
286 m_aListenerContainer
.removeInterface( cppu::UnoType
<XEventListener
>::get(), aListener
);
290 void SAL_CALL
ToolboxController::disposing( const EventObject
& Source
)
291 throw ( RuntimeException
, std::exception
)
293 Reference
< XInterface
> xSource( Source
.Source
);
295 SolarMutexGuard aSolarMutexGuard
;
300 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
301 while ( pIter
!= m_aListenerMap
.end() )
303 // Compare references and release dispatch references if they are equal.
304 Reference
< XInterface
> xIfac( pIter
->second
, UNO_QUERY
);
305 if ( xSource
== xIfac
)
306 pIter
->second
.clear();
310 Reference
< XInterface
> xIfac( m_xFrame
, UNO_QUERY
);
311 if ( xIfac
== xSource
)
316 void SAL_CALL
ToolboxController::statusChanged( const FeatureStateEvent
& )
317 throw ( RuntimeException
, std::exception
)
319 // must be implemented by sub class
322 // XToolbarController
323 void SAL_CALL
ToolboxController::execute( sal_Int16 KeyModifier
)
324 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
326 Reference
< XDispatch
> xDispatch
;
327 OUString aCommandURL
;
330 SolarMutexGuard aSolarMutexGuard
;
333 throw DisposedException();
335 if ( m_bInitialized
&&
338 !m_aCommandURL
.isEmpty() )
341 aCommandURL
= m_aCommandURL
;
342 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( m_aCommandURL
);
343 if ( pIter
!= m_aListenerMap
.end() )
344 xDispatch
= pIter
->second
;
348 if ( xDispatch
.is() )
352 com::sun::star::util::URL aTargetURL
;
353 Sequence
<PropertyValue
> aArgs( 1 );
355 // Provide key modifier information to dispatch function
356 aArgs
[0].Name
= "KeyModifier";
357 aArgs
[0].Value
= makeAny( KeyModifier
);
359 aTargetURL
.Complete
= aCommandURL
;
360 if ( m_xUrlTransformer
.is() )
361 m_xUrlTransformer
->parseStrict( aTargetURL
);
362 xDispatch
->dispatch( aTargetURL
, aArgs
);
364 catch ( DisposedException
& )
370 void SAL_CALL
ToolboxController::click()
371 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
375 void SAL_CALL
ToolboxController::doubleClick()
376 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
380 Reference
< XWindow
> SAL_CALL
ToolboxController::createPopupWindow()
381 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
383 return Reference
< XWindow
>();
386 Reference
< XWindow
> SAL_CALL
ToolboxController::createItemWindow( const Reference
< XWindow
>& )
387 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
389 return Reference
< XWindow
>();
392 void ToolboxController::addStatusListener( const OUString
& aCommandURL
)
394 Reference
< XDispatch
> xDispatch
;
395 Reference
< XStatusListener
> xStatusListener
;
396 com::sun::star::util::URL aTargetURL
;
399 SolarMutexGuard aSolarMutexGuard
;
400 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( aCommandURL
);
402 // Already in the list of status listener. Do nothing.
403 if ( pIter
!= m_aListenerMap
.end() )
406 // Check if we are already initialized. Implementation starts adding itself as status listener when
407 // intialize is called.
408 if ( !m_bInitialized
)
410 // Put into the unordered_map of status listener. Will be activated when initialized is called
411 m_aListenerMap
.insert( URLToDispatchMap::value_type( aCommandURL
, Reference
< XDispatch
>() ));
416 // Add status listener directly as intialize has already been called.
417 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
418 if ( m_xContext
.is() && xDispatchProvider
.is() )
420 aTargetURL
.Complete
= aCommandURL
;
421 if ( m_xUrlTransformer
.is() )
422 m_xUrlTransformer
->parseStrict( aTargetURL
);
423 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
425 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
426 URLToDispatchMap::iterator aIter
= m_aListenerMap
.find( aCommandURL
);
427 if ( aIter
!= m_aListenerMap
.end() )
429 Reference
< XDispatch
> xOldDispatch( aIter
->second
);
430 aIter
->second
= xDispatch
;
434 if ( xOldDispatch
.is() )
435 xOldDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
442 m_aListenerMap
.insert( URLToDispatchMap::value_type( aCommandURL
, xDispatch
));
447 // Call without locked mutex as we are called back from dispatch implementation
450 if ( xDispatch
.is() )
451 xDispatch
->addStatusListener( xStatusListener
, aTargetURL
);
458 void ToolboxController::removeStatusListener( const OUString
& aCommandURL
)
460 SolarMutexGuard aSolarMutexGuard
;
462 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( aCommandURL
);
463 if ( pIter
!= m_aListenerMap
.end() )
465 Reference
< XDispatch
> xDispatch( pIter
->second
);
466 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
467 m_aListenerMap
.erase( pIter
);
471 com::sun::star::util::URL aTargetURL
;
472 aTargetURL
.Complete
= aCommandURL
;
473 if ( m_xUrlTransformer
.is() )
474 m_xUrlTransformer
->parseStrict( aTargetURL
);
476 if ( xDispatch
.is() && xStatusListener
.is() )
477 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
485 void ToolboxController::bindListener()
487 std::vector
< Listener
> aDispatchVector
;
488 Reference
< XStatusListener
> xStatusListener
;
491 SolarMutexGuard aSolarMutexGuard
;
493 if ( !m_bInitialized
)
496 // Collect all registered command URL's and store them temporary
497 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
498 if ( m_xContext
.is() && xDispatchProvider
.is() )
500 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
501 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
502 while ( pIter
!= m_aListenerMap
.end() )
504 com::sun::star::util::URL aTargetURL
;
505 aTargetURL
.Complete
= pIter
->first
;
506 if ( m_xUrlTransformer
.is() )
507 m_xUrlTransformer
->parseStrict( aTargetURL
);
509 Reference
< XDispatch
> xDispatch( pIter
->second
);
510 if ( xDispatch
.is() )
512 // We already have a dispatch object => we have to requery.
513 // Release old dispatch object and remove it as listener
516 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
523 pIter
->second
.clear();
526 // Query for dispatch object. Old dispatch will be released with this, too.
529 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
534 pIter
->second
= xDispatch
;
536 Listener
aListener( aTargetURL
, xDispatch
);
537 aDispatchVector
.push_back( aListener
);
543 // Call without locked mutex as we are called back from dispatch implementation
544 if ( xStatusListener
.is() )
548 for ( sal_uInt32 i
= 0; i
< aDispatchVector
.size(); i
++ )
550 Listener
& rListener
= aDispatchVector
[i
];
551 if ( rListener
.xDispatch
.is() )
552 rListener
.xDispatch
->addStatusListener( xStatusListener
, rListener
.aURL
);
553 else if ( rListener
.aURL
.Complete
== m_aCommandURL
)
557 // Send status changed for the main URL, if we cannot get a valid dispatch object.
558 // UI disables the button. Catch exception as we release our mutex, it is possible
559 // that someone else already disposed this instance!
560 FeatureStateEvent aFeatureStateEvent
;
561 aFeatureStateEvent
.IsEnabled
= sal_False
;
562 aFeatureStateEvent
.FeatureURL
= rListener
.aURL
;
563 aFeatureStateEvent
.State
= Any();
564 xStatusListener
->statusChanged( aFeatureStateEvent
);
578 void ToolboxController::unbindListener()
580 SolarMutexGuard aSolarMutexGuard
;
582 if ( !m_bInitialized
)
585 // Collect all registered command URL's and store them temporary
586 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
587 if ( m_xContext
.is() && xDispatchProvider
.is() )
589 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
590 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
591 while ( pIter
!= m_aListenerMap
.end() )
593 com::sun::star::util::URL aTargetURL
;
594 aTargetURL
.Complete
= pIter
->first
;
595 if ( m_xUrlTransformer
.is() )
596 m_xUrlTransformer
->parseStrict( aTargetURL
);
598 Reference
< XDispatch
> xDispatch( pIter
->second
);
599 if ( xDispatch
.is() )
601 // We already have a dispatch object => we have to requery.
602 // Release old dispatch object and remove it as listener
605 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
611 pIter
->second
.clear();
617 bool ToolboxController::isBound() const
619 SolarMutexGuard aSolarMutexGuard
;
621 if ( !m_bInitialized
)
624 URLToDispatchMap::const_iterator pIter
= m_aListenerMap
.find( m_aCommandURL
);
625 if ( pIter
!= m_aListenerMap
.end() )
626 return pIter
->second
.is();
631 void ToolboxController::updateStatus()
636 void ToolboxController::updateStatus( const OUString
& aCommandURL
)
638 Reference
< XDispatch
> xDispatch
;
639 Reference
< XStatusListener
> xStatusListener
;
640 com::sun::star::util::URL aTargetURL
;
643 SolarMutexGuard aSolarMutexGuard
;
645 if ( !m_bInitialized
)
648 // Try to find a dispatch object for the requested command URL
649 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
650 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
651 if ( m_xContext
.is() && xDispatchProvider
.is() )
653 aTargetURL
.Complete
= aCommandURL
;
654 if ( m_xUrlTransformer
.is() )
655 m_xUrlTransformer
->parseStrict( aTargetURL
);
656 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
660 if ( xDispatch
.is() && xStatusListener
.is() )
662 // Catch exception as we release our mutex, it is possible that someone else
663 // has already disposed this instance!
664 // Add/remove status listener to get a update status information from the
665 // requested command.
668 xDispatch
->addStatusListener( xStatusListener
, aTargetURL
);
669 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
679 void ToolboxController::dispatchCommand( const OUString
& sCommandURL
, const Sequence
< PropertyValue
>& rArgs
, const OUString
&sTarget
)
683 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY_THROW
);
685 aURL
.Complete
= sCommandURL
;
686 getURLTransformer()->parseStrict( aURL
);
688 Reference
< XDispatch
> xDispatch( xDispatchProvider
->queryDispatch( aURL
, sTarget
, 0 ), UNO_QUERY_THROW
);
690 DispatchInfo
*pDispatchInfo
= new DispatchInfo( xDispatch
, aURL
, rArgs
);
691 if ( !Application::PostUserEvent( LINK(0, ToolboxController
, ExecuteHdl_Impl
),
693 delete pDispatchInfo
;
703 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
ToolboxController::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
705 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
709 ::cppu::IPropertyArrayHelper
& ToolboxController::getInfoHelper()
711 return *getArrayHelper();
715 ::cppu::IPropertyArrayHelper
* ToolboxController::createArrayHelper( ) const
717 com::sun::star::uno::Sequence
< Property
> aProps
;
718 describeProperties(aProps
);
719 return new ::cppu::OPropertyArrayHelper(aProps
);
722 void ToolboxController::setSupportVisibleProperty(bool bValue
)
724 m_bSupportVisible
= bValue
;
727 sal_Bool SAL_CALL
ToolboxController::convertFastPropertyValue( com::sun::star::uno::Any
& aConvertedValue
,
728 com::sun::star::uno::Any
& aOldValue
,
730 const com::sun::star::uno::Any
& aValue
) throw( com::sun::star::lang::IllegalArgumentException
)
734 case TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
:
736 bool aNewValue(false);
737 aValue
>>= aNewValue
;
738 if (aNewValue
!= m_bSupportVisible
)
740 aConvertedValue
<<= aNewValue
;
741 aOldValue
<<= m_bSupportVisible
;
747 return OPropertyContainer::convertFastPropertyValue(aConvertedValue
, aOldValue
, nHandle
, aValue
);
750 void SAL_CALL
ToolboxController::setFastPropertyValue_NoBroadcast(
752 const com::sun::star::uno::Any
& aValue
)
753 throw( com::sun::star::uno::Exception
, std::exception
)
755 OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle
, aValue
);
756 if (TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
== nHandle
)
759 if (( aValue
>>= rValue
) && m_bInitialized
)
760 this->setSupportVisibleProperty( rValue
);
766 IMPL_STATIC_LINK( ToolboxController
, ExecuteHdl_Impl
, DispatchInfo
*, pDispatchInfo
)
768 pDispatchInfo
->mxDispatch
->dispatch( pDispatchInfo
->maURL
, pDispatchInfo
->maArgs
);
769 delete pDispatchInfo
;
773 void ToolboxController::enable( bool bEnable
)
775 ToolBox
* pToolBox
= 0;
776 sal_uInt16 nItemId
= 0;
777 if( getToolboxId( nItemId
, &pToolBox
) )
779 pToolBox
->EnableItem( nItemId
, bEnable
);
783 bool ToolboxController::getToolboxId( sal_uInt16
& rItemId
, ToolBox
** ppToolBox
)
785 if( (m_nToolBoxId
!= SAL_MAX_UINT16
) && (ppToolBox
== 0) )
788 ToolBox
* pToolBox
= static_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ).get() );
790 if( (m_nToolBoxId
== SAL_MAX_UINT16
) && pToolBox
)
792 const sal_uInt16 nCount
= pToolBox
->GetItemCount();
793 for ( sal_uInt16 nPos
= 0; nPos
< nCount
; ++nPos
)
795 const sal_uInt16 nItemId
= pToolBox
->GetItemId( nPos
);
796 if ( pToolBox
->GetItemCommand( nItemId
) == m_aCommandURL
)
798 m_nToolBoxId
= nItemId
;
805 *ppToolBox
= pToolBox
;
807 rItemId
= m_nToolBoxId
;
809 return (rItemId
!= SAL_MAX_UINT16
) && (( ppToolBox
== 0) || (*ppToolBox
!= 0) );
815 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */