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