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/unohlp.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
;
54 Reference
< XDispatch
> mxDispatch
;
56 const Sequence
< PropertyValue
> maArgs
;
58 DispatchInfo( const Reference
< XDispatch
>& xDispatch
, const URL
& rURL
, const Sequence
< PropertyValue
>& rArgs
)
59 : mxDispatch( xDispatch
), maURL( rURL
), maArgs( rArgs
) {}
62 struct ToolboxController_Impl
64 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> m_xParentWindow
;
65 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XURLTransformer
> m_xUrlTransformer
;
66 OUString m_sModuleName
;
67 sal_uInt16 m_nToolBoxId
;
69 DECL_STATIC_LINK( ToolboxController_Impl
, ExecuteHdl_Impl
, DispatchInfo
* );
71 ToolboxController_Impl()
72 : m_nToolBoxId( SAL_MAX_UINT16
)
76 ToolboxController::ToolboxController(
77 const Reference
< XComponentContext
>& rxContext
,
78 const Reference
< XFrame
>& xFrame
,
79 const OUString
& aCommandURL
) :
80 OPropertyContainer(GetBroadcastHelper())
82 , m_bSupportVisible(sal_False
)
83 , m_bInitialized( sal_False
)
84 , m_bDisposed( sal_False
)
86 , m_xContext( rxContext
)
87 , m_aCommandURL( aCommandURL
)
88 , m_aListenerContainer( m_aMutex
)
90 OSL_ASSERT( m_xContext
.is() );
91 registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE
),
92 TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
,
93 css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
,
94 &m_bSupportVisible
, getCppuType(&m_bSupportVisible
));
96 m_pImpl
= new ToolboxController_Impl
;
100 m_pImpl
->m_xUrlTransformer
= URLTransformer::create( rxContext
);
102 catch(const Exception
&)
107 ToolboxController::ToolboxController() :
108 OPropertyContainer(GetBroadcastHelper())
110 , m_bSupportVisible(sal_False
)
111 , m_bInitialized( sal_False
)
112 , m_bDisposed( sal_False
)
113 , m_aListenerContainer( m_aMutex
)
115 registerProperty( OUString(TOOLBARCONTROLLER_PROPNAME_SUPPORTSVISIBLE
),
116 TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
,
117 css::beans::PropertyAttribute::TRANSIENT
| css::beans::PropertyAttribute::READONLY
,
118 &m_bSupportVisible
, getCppuType(&m_bSupportVisible
));
120 m_pImpl
= new ToolboxController_Impl
;
123 ToolboxController::~ToolboxController()
128 Reference
< XFrame
> ToolboxController::getFrameInterface() const
130 SolarMutexGuard aSolarMutexGuard
;
134 const Reference
< XComponentContext
> & ToolboxController::getContext() const
136 SolarMutexGuard aSolarMutexGuard
;
140 Reference
< XLayoutManager
> ToolboxController::getLayoutManager() const
142 Reference
< XLayoutManager
> xLayoutManager
;
143 Reference
< XPropertySet
> xPropSet
;
145 SolarMutexGuard aSolarMutexGuard
;
146 xPropSet
= Reference
< XPropertySet
>( m_xFrame
, UNO_QUERY
);
153 xLayoutManager
.set(xPropSet
->getPropertyValue( OUString( "LayoutManager" )),UNO_QUERY
);
160 return xLayoutManager
;
164 Any SAL_CALL
ToolboxController::queryInterface( const Type
& rType
)
165 throw ( RuntimeException
)
167 Any a
= ::cppu::queryInterface(
169 static_cast< XToolbarController
* >( this ),
170 static_cast< XStatusListener
* >( this ),
171 static_cast< XEventListener
* >( this ),
172 static_cast< XInitialization
* >( this ),
173 static_cast< XComponent
* >( this ),
174 static_cast< XUpdatable
* >( this ));
177 a
= ::cppu::queryInterface(rType
178 ,static_cast<XPropertySet
*>(this)
179 ,static_cast<XMultiPropertySet
*>(this)
180 ,static_cast<XFastPropertySet
*>(this));
182 return OWeakObject::queryInterface( rType
);
187 void SAL_CALL
ToolboxController::acquire() throw ()
189 OWeakObject::acquire();
192 void SAL_CALL
ToolboxController::release() throw ()
194 OWeakObject::release();
197 void SAL_CALL
ToolboxController::initialize( const Sequence
< Any
>& aArguments
)
198 throw ( Exception
, RuntimeException
)
200 bool bInitialized( true );
203 SolarMutexGuard aSolarMutexGuard
;
206 throw DisposedException();
208 bInitialized
= m_bInitialized
;
213 SolarMutexGuard aSolarMutexGuard
;
214 m_bInitialized
= sal_True
;
216 m_bSupportVisible
= sal_False
;
217 PropertyValue aPropValue
;
218 for ( int i
= 0; i
< aArguments
.getLength(); i
++ )
220 if ( aArguments
[i
] >>= aPropValue
)
222 if ( aPropValue
.Name
== "Frame" )
223 m_xFrame
.set(aPropValue
.Value
,UNO_QUERY
);
224 else if ( aPropValue
.Name
== "CommandURL" )
225 aPropValue
.Value
>>= m_aCommandURL
;
226 else if ( aPropValue
.Name
== "ServiceManager" )
228 Reference
<XMultiServiceFactory
> xMSF(aPropValue
.Value
, UNO_QUERY
);
230 m_xContext
= comphelper::getComponentContext(xMSF
);
232 else if ( aPropValue
.Name
== "ParentWindow" )
233 m_pImpl
->m_xParentWindow
.set(aPropValue
.Value
,UNO_QUERY
);
234 else if ( aPropValue
.Name
== "ModuleIdentifier" )
235 aPropValue
.Value
>>= m_pImpl
->m_sModuleName
;
241 if ( !m_pImpl
->m_xUrlTransformer
.is() && m_xContext
.is() )
242 m_pImpl
->m_xUrlTransformer
= URLTransformer::create( m_xContext
);
244 catch(const Exception
&)
248 if ( !m_aCommandURL
.isEmpty() )
249 m_aListenerMap
.insert( URLToDispatchMap::value_type( m_aCommandURL
, Reference
< XDispatch
>() ));
253 void SAL_CALL
ToolboxController::update()
254 throw ( RuntimeException
)
257 SolarMutexGuard aSolarMutexGuard
;
259 throw DisposedException();
262 // Bind all registered listeners to their dispatch objects
267 void SAL_CALL
ToolboxController::dispose()
268 throw (::com::sun::star::uno::RuntimeException
)
270 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
273 SolarMutexGuard aSolarMutexGuard
;
275 throw DisposedException();
278 com::sun::star::lang::EventObject
aEvent( xThis
);
279 m_aListenerContainer
.disposeAndClear( aEvent
);
281 SolarMutexGuard aSolarMutexGuard
;
282 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
283 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
284 while ( pIter
!= m_aListenerMap
.end() )
288 Reference
< XDispatch
> xDispatch( pIter
->second
);
290 com::sun::star::util::URL aTargetURL
;
291 aTargetURL
.Complete
= pIter
->first
;
292 if ( m_pImpl
->m_xUrlTransformer
.is() )
293 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
295 if ( xDispatch
.is() && xStatusListener
.is() )
296 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
305 m_bDisposed
= sal_True
;
308 void SAL_CALL
ToolboxController::addEventListener( const Reference
< XEventListener
>& xListener
)
309 throw ( RuntimeException
)
311 m_aListenerContainer
.addInterface( ::getCppuType( ( const Reference
< XEventListener
>* ) NULL
), xListener
);
314 void SAL_CALL
ToolboxController::removeEventListener( const Reference
< XEventListener
>& aListener
)
315 throw ( RuntimeException
)
317 m_aListenerContainer
.removeInterface( ::getCppuType( ( const Reference
< XEventListener
>* ) NULL
), aListener
);
321 void SAL_CALL
ToolboxController::disposing( const EventObject
& Source
)
322 throw ( RuntimeException
)
324 Reference
< XInterface
> xSource( Source
.Source
);
326 SolarMutexGuard aSolarMutexGuard
;
331 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
332 while ( pIter
!= m_aListenerMap
.end() )
334 // Compare references and release dispatch references if they are equal.
335 Reference
< XInterface
> xIfac( pIter
->second
, UNO_QUERY
);
336 if ( xSource
== xIfac
)
337 pIter
->second
.clear();
341 Reference
< XInterface
> xIfac( m_xFrame
, UNO_QUERY
);
342 if ( xIfac
== xSource
)
347 void SAL_CALL
ToolboxController::statusChanged( const FeatureStateEvent
& )
348 throw ( RuntimeException
)
350 // must be implemented by sub class
353 // XToolbarController
354 void SAL_CALL
ToolboxController::execute( sal_Int16 KeyModifier
)
355 throw (::com::sun::star::uno::RuntimeException
)
357 Reference
< XDispatch
> xDispatch
;
358 OUString aCommandURL
;
361 SolarMutexGuard aSolarMutexGuard
;
364 throw DisposedException();
366 if ( m_bInitialized
&&
369 !m_aCommandURL
.isEmpty() )
372 aCommandURL
= m_aCommandURL
;
373 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( m_aCommandURL
);
374 if ( pIter
!= m_aListenerMap
.end() )
375 xDispatch
= pIter
->second
;
379 if ( xDispatch
.is() )
383 com::sun::star::util::URL aTargetURL
;
384 Sequence
<PropertyValue
> aArgs( 1 );
386 // Provide key modifier information to dispatch function
387 aArgs
[0].Name
= OUString( "KeyModifier" );
388 aArgs
[0].Value
= makeAny( KeyModifier
);
390 aTargetURL
.Complete
= aCommandURL
;
391 if ( m_pImpl
->m_xUrlTransformer
.is() )
392 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
393 xDispatch
->dispatch( aTargetURL
, aArgs
);
395 catch ( DisposedException
& )
401 void SAL_CALL
ToolboxController::click()
402 throw (::com::sun::star::uno::RuntimeException
)
406 void SAL_CALL
ToolboxController::doubleClick()
407 throw (::com::sun::star::uno::RuntimeException
)
411 Reference
< XWindow
> SAL_CALL
ToolboxController::createPopupWindow()
412 throw (::com::sun::star::uno::RuntimeException
)
414 return Reference
< XWindow
>();
417 Reference
< XWindow
> SAL_CALL
ToolboxController::createItemWindow( const Reference
< XWindow
>& )
418 throw (::com::sun::star::uno::RuntimeException
)
420 return Reference
< XWindow
>();
423 void ToolboxController::addStatusListener( const OUString
& aCommandURL
)
425 Reference
< XDispatch
> xDispatch
;
426 Reference
< XStatusListener
> xStatusListener
;
427 com::sun::star::util::URL aTargetURL
;
430 SolarMutexGuard aSolarMutexGuard
;
431 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( aCommandURL
);
433 // Already in the list of status listener. Do nothing.
434 if ( pIter
!= m_aListenerMap
.end() )
437 // Check if we are already initialized. Implementation starts adding itself as status listener when
438 // intialize is called.
439 if ( !m_bInitialized
)
441 // Put into the boost::unordered_map of status listener. Will be activated when initialized is called
442 m_aListenerMap
.insert( URLToDispatchMap::value_type( aCommandURL
, Reference
< XDispatch
>() ));
447 // Add status listener directly as intialize has already been called.
448 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
449 if ( m_xContext
.is() && xDispatchProvider
.is() )
451 aTargetURL
.Complete
= aCommandURL
;
452 if ( m_pImpl
->m_xUrlTransformer
.is() )
453 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
454 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
456 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
457 URLToDispatchMap::iterator aIter
= m_aListenerMap
.find( aCommandURL
);
458 if ( aIter
!= m_aListenerMap
.end() )
460 Reference
< XDispatch
> xOldDispatch( aIter
->second
);
461 aIter
->second
= xDispatch
;
465 if ( xOldDispatch
.is() )
466 xOldDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
473 m_aListenerMap
.insert( URLToDispatchMap::value_type( aCommandURL
, xDispatch
));
478 // Call without locked mutex as we are called back from dispatch implementation
481 if ( xDispatch
.is() )
482 xDispatch
->addStatusListener( xStatusListener
, aTargetURL
);
489 void ToolboxController::removeStatusListener( const OUString
& aCommandURL
)
491 SolarMutexGuard aSolarMutexGuard
;
493 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( aCommandURL
);
494 if ( pIter
!= m_aListenerMap
.end() )
496 Reference
< XDispatch
> xDispatch( pIter
->second
);
497 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
498 m_aListenerMap
.erase( pIter
);
502 com::sun::star::util::URL aTargetURL
;
503 aTargetURL
.Complete
= aCommandURL
;
504 if ( m_pImpl
->m_xUrlTransformer
.is() )
505 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
507 if ( xDispatch
.is() && xStatusListener
.is() )
508 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
516 void ToolboxController::bindListener()
518 std::vector
< Listener
> aDispatchVector
;
519 Reference
< XStatusListener
> xStatusListener
;
522 SolarMutexGuard aSolarMutexGuard
;
524 if ( !m_bInitialized
)
527 // Collect all registered command URL's and store them temporary
528 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
529 if ( m_xContext
.is() && xDispatchProvider
.is() )
531 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
532 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
533 while ( pIter
!= m_aListenerMap
.end() )
535 com::sun::star::util::URL aTargetURL
;
536 aTargetURL
.Complete
= pIter
->first
;
537 if ( m_pImpl
->m_xUrlTransformer
.is() )
538 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
540 Reference
< XDispatch
> xDispatch( pIter
->second
);
541 if ( xDispatch
.is() )
543 // We already have a dispatch object => we have to requery.
544 // Release old dispatch object and remove it as listener
547 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
554 pIter
->second
.clear();
557 // Query for dispatch object. Old dispatch will be released with this, too.
560 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
565 pIter
->second
= xDispatch
;
567 Listener
aListener( aTargetURL
, xDispatch
);
568 aDispatchVector
.push_back( aListener
);
574 // Call without locked mutex as we are called back from dispatch implementation
575 if ( xStatusListener
.is() )
579 for ( sal_uInt32 i
= 0; i
< aDispatchVector
.size(); i
++ )
581 Listener
& rListener
= aDispatchVector
[i
];
582 if ( rListener
.xDispatch
.is() )
583 rListener
.xDispatch
->addStatusListener( xStatusListener
, rListener
.aURL
);
584 else if ( rListener
.aURL
.Complete
== m_aCommandURL
)
588 // Send status changed for the main URL, if we cannot get a valid dispatch object.
589 // UI disables the button. Catch exception as we release our mutex, it is possible
590 // that someone else already disposed this instance!
591 FeatureStateEvent aFeatureStateEvent
;
592 aFeatureStateEvent
.IsEnabled
= sal_False
;
593 aFeatureStateEvent
.FeatureURL
= rListener
.aURL
;
594 aFeatureStateEvent
.State
= Any();
595 xStatusListener
->statusChanged( aFeatureStateEvent
);
609 void ToolboxController::unbindListener()
611 SolarMutexGuard aSolarMutexGuard
;
613 if ( !m_bInitialized
)
616 // Collect all registered command URL's and store them temporary
617 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
618 if ( m_xContext
.is() && xDispatchProvider
.is() )
620 Reference
< XStatusListener
> xStatusListener( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
621 URLToDispatchMap::iterator pIter
= m_aListenerMap
.begin();
622 while ( pIter
!= m_aListenerMap
.end() )
624 com::sun::star::util::URL aTargetURL
;
625 aTargetURL
.Complete
= pIter
->first
;
626 if ( m_pImpl
->m_xUrlTransformer
.is() )
627 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
629 Reference
< XDispatch
> xDispatch( pIter
->second
);
630 if ( xDispatch
.is() )
632 // We already have a dispatch object => we have to requery.
633 // Release old dispatch object and remove it as listener
636 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
642 pIter
->second
.clear();
648 sal_Bool
ToolboxController::isBound() const
650 SolarMutexGuard aSolarMutexGuard
;
652 if ( !m_bInitialized
)
655 URLToDispatchMap::const_iterator pIter
= m_aListenerMap
.find( m_aCommandURL
);
656 if ( pIter
!= m_aListenerMap
.end() )
657 return ( pIter
->second
.is() );
662 sal_Bool
ToolboxController::hasBigImages() const
664 return SvtMiscOptions().AreCurrentSymbolsLarge();
667 void ToolboxController::updateStatus()
672 void ToolboxController::updateStatus( const OUString aCommandURL
)
674 Reference
< XDispatch
> xDispatch
;
675 Reference
< XStatusListener
> xStatusListener
;
676 com::sun::star::util::URL aTargetURL
;
679 SolarMutexGuard aSolarMutexGuard
;
681 if ( !m_bInitialized
)
684 // Try to find a dispatch object for the requested command URL
685 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY
);
686 xStatusListener
= Reference
< XStatusListener
>( static_cast< OWeakObject
* >( this ), UNO_QUERY
);
687 if ( m_xContext
.is() && xDispatchProvider
.is() )
689 aTargetURL
.Complete
= aCommandURL
;
690 if ( m_pImpl
->m_xUrlTransformer
.is() )
691 m_pImpl
->m_xUrlTransformer
->parseStrict( aTargetURL
);
692 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, OUString(), 0 );
696 if ( xDispatch
.is() && xStatusListener
.is() )
698 // Catch exception as we release our mutex, it is possible that someone else
699 // has already disposed this instance!
700 // Add/remove status listener to get a update status information from the
701 // requested command.
704 xDispatch
->addStatusListener( xStatusListener
, aTargetURL
);
705 xDispatch
->removeStatusListener( xStatusListener
, aTargetURL
);
713 Reference
< XURLTransformer
> ToolboxController::getURLTransformer() const
715 return m_pImpl
->m_xUrlTransformer
;
718 Reference
< ::com::sun::star::awt::XWindow
> ToolboxController::getParent() const
720 return m_pImpl
->m_xParentWindow
;
723 const OUString
& ToolboxController::getModuleName() const
725 return m_pImpl
->m_sModuleName
;
728 void ToolboxController::dispatchCommand( const OUString
& sCommandURL
, const Sequence
< PropertyValue
>& rArgs
)
732 Reference
< XDispatchProvider
> xDispatchProvider( m_xFrame
, UNO_QUERY_THROW
);
734 aURL
.Complete
= sCommandURL
;
735 getURLTransformer()->parseStrict( aURL
);
737 Reference
< XDispatch
> xDispatch( xDispatchProvider
->queryDispatch( aURL
, OUString(), 0 ), UNO_QUERY_THROW
);
739 Application::PostUserEvent( STATIC_LINK(0, ToolboxController_Impl
, ExecuteHdl_Impl
), new DispatchInfo( xDispatch
, aURL
, rArgs
) );
748 //-------------------------------------------------------------------------
749 // XPropertySet by shizhoubo
750 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
ToolboxController::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException
)
752 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
755 //-------------------------------------------------------------------------
756 ::cppu::IPropertyArrayHelper
& ToolboxController::getInfoHelper()
758 return *const_cast<ToolboxController
*>(this)->getArrayHelper();
760 //OPropertyArrayUsageHelper by shizhoubo
761 //------------------------------------------------------------------------------
762 ::cppu::IPropertyArrayHelper
* ToolboxController::createArrayHelper( ) const
764 com::sun::star::uno::Sequence
< Property
> aProps
;
765 describeProperties(aProps
);
766 return new ::cppu::OPropertyArrayHelper(aProps
);
768 //shizhoubo for supportsvisiable
769 void ToolboxController::setSupportVisibleProperty(sal_Bool bValue
)
771 m_bSupportVisible
= bValue
;
773 //OPropertySetHelper by shizhoubo
774 sal_Bool SAL_CALL
ToolboxController::convertFastPropertyValue( com::sun::star::uno::Any
& aConvertedValue
,
775 com::sun::star::uno::Any
& aOldValue
,
777 const com::sun::star::uno::Any
& aValue
) throw( com::sun::star::lang::IllegalArgumentException
)
781 case TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
:
783 sal_Bool
aNewValue(sal_False
);
784 aValue
>>= aNewValue
;
785 if (aNewValue
!= m_bSupportVisible
)
787 aConvertedValue
<<= aNewValue
;
788 aOldValue
<<= m_bSupportVisible
;
794 return OPropertyContainer::convertFastPropertyValue(aConvertedValue
, aOldValue
, nHandle
, aValue
);
797 void SAL_CALL
ToolboxController::setFastPropertyValue_NoBroadcast(
799 const com::sun::star::uno::Any
& aValue
)
800 throw( com::sun::star::uno::Exception
)
802 OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle
, aValue
);
803 if (TOOLBARCONTROLLER_PROPHANDLE_SUPPORTSVISIBLE
== nHandle
)
805 sal_Bool
rValue(sal_False
);
806 if (( aValue
>>= rValue
) && m_bInitialized
)
807 this->setSupportVisibleProperty( rValue
);
811 //--------------------------------------------------------------------
813 IMPL_STATIC_LINK_NOINSTANCE( ToolboxController_Impl
, ExecuteHdl_Impl
, DispatchInfo
*, pDispatchInfo
)
815 pDispatchInfo
->mxDispatch
->dispatch( pDispatchInfo
->maURL
, pDispatchInfo
->maArgs
);
816 delete pDispatchInfo
;
820 void ToolboxController::enable( bool bEnable
)
822 ToolBox
* pToolBox
= 0;
823 sal_uInt16 nItemId
= 0;
824 if( getToolboxId( nItemId
, &pToolBox
) )
826 pToolBox
->EnableItem( nItemId
, bEnable
? sal_True
: sal_False
);
830 bool ToolboxController::getToolboxId( sal_uInt16
& rItemId
, ToolBox
** ppToolBox
)
832 if( (m_pImpl
->m_nToolBoxId
!= SAL_MAX_UINT16
) && (ppToolBox
== 0) )
833 return m_pImpl
->m_nToolBoxId
;
835 ToolBox
* pToolBox
= static_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ) );
837 if( (m_pImpl
->m_nToolBoxId
== SAL_MAX_UINT16
) && pToolBox
)
839 const sal_uInt16 nCount
= pToolBox
->GetItemCount();
840 for ( sal_uInt16 nPos
= 0; nPos
< nCount
; ++nPos
)
842 const sal_uInt16 nItemId
= pToolBox
->GetItemId( nPos
);
843 if ( pToolBox
->GetItemCommand( nItemId
) == String( m_aCommandURL
) )
845 m_pImpl
->m_nToolBoxId
= nItemId
;
852 *ppToolBox
= pToolBox
;
854 rItemId
= m_pImpl
->m_nToolBoxId
;
856 return (rItemId
!= SAL_MAX_UINT16
) && (( ppToolBox
== 0) || (*ppToolBox
!= 0) );
862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */