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