1*5900e8ecSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5900e8ecSAndrew Rist * distributed with this work for additional information 6*5900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5900e8ecSAndrew Rist * "License"); you may not use this file except in compliance 9*5900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5900e8ecSAndrew Rist * software distributed under the License is distributed on an 15*5900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5900e8ecSAndrew Rist * KIND, either express or implied. See the License for the 17*5900e8ecSAndrew Rist * specific language governing permissions and limitations 18*5900e8ecSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5900e8ecSAndrew Rist *************************************************************/ 21*5900e8ecSAndrew Rist 22*5900e8ecSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svtools.hxx" 26cdf0e10cSrcweir #include <svtools/statusbarcontroller.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 <vcl/window.hxx> 35cdf0e10cSrcweir #include <vcl/status.hxx> 36cdf0e10cSrcweir #include <svtools/imgdef.hxx> 37cdf0e10cSrcweir #include <svtools/miscopt.hxx> 38cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::cppu; 41cdf0e10cSrcweir using namespace ::com::sun::star::awt; 42cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43cdf0e10cSrcweir using namespace ::com::sun::star::util; 44cdf0e10cSrcweir using namespace ::com::sun::star::beans; 45cdf0e10cSrcweir using namespace ::com::sun::star::lang; 46cdf0e10cSrcweir using namespace ::com::sun::star::frame; 47cdf0e10cSrcweir using namespace ::com::sun::star::frame; 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace svt 50cdf0e10cSrcweir { 51cdf0e10cSrcweir 52cdf0e10cSrcweir StatusbarController::StatusbarController( 53cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rServiceManager, 54cdf0e10cSrcweir const Reference< XFrame >& xFrame, 55cdf0e10cSrcweir const ::rtl::OUString& aCommandURL, 56cdf0e10cSrcweir unsigned short nID ) : 57cdf0e10cSrcweir OWeakObject() 58cdf0e10cSrcweir , m_bInitialized( sal_False ) 59cdf0e10cSrcweir , m_bDisposed( sal_False ) 60cdf0e10cSrcweir , m_nID( nID ) 61cdf0e10cSrcweir , m_xFrame( xFrame ) 62cdf0e10cSrcweir , m_xServiceManager( rServiceManager ) 63cdf0e10cSrcweir , m_aCommandURL( aCommandURL ) 64cdf0e10cSrcweir , m_aListenerContainer( m_aMutex ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir StatusbarController::StatusbarController() : 69cdf0e10cSrcweir OWeakObject() 70cdf0e10cSrcweir , m_bInitialized( sal_False ) 71cdf0e10cSrcweir , m_bDisposed( sal_False ) 72cdf0e10cSrcweir , m_nID( 0 ) 73cdf0e10cSrcweir , m_aListenerContainer( m_aMutex ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir StatusbarController::~StatusbarController() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir Reference< XFrame > StatusbarController::getFrameInterface() const 82cdf0e10cSrcweir { 83cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 84cdf0e10cSrcweir return m_xFrame; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir Reference< XMultiServiceFactory > StatusbarController::getServiceManager() const 88cdf0e10cSrcweir { 89cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 90cdf0e10cSrcweir return m_xServiceManager; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir Reference< XLayoutManager > StatusbarController::getLayoutManager() const 94cdf0e10cSrcweir { 95cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 96cdf0e10cSrcweir Reference< XLayoutManager > xLayoutManager; 97cdf0e10cSrcweir Reference< XPropertySet > xPropSet( m_xFrame, UNO_QUERY ); 98cdf0e10cSrcweir if ( xPropSet.is() ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir try 101cdf0e10cSrcweir { 102cdf0e10cSrcweir Any a; 103cdf0e10cSrcweir a = xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))); 104cdf0e10cSrcweir a >>= xLayoutManager; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir catch ( Exception& ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir return xLayoutManager; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir Reference< XURLTransformer > StatusbarController::getURLTransformer() const 115cdf0e10cSrcweir { 116cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 117cdf0e10cSrcweir if ( !m_xURLTransformer.is() && m_xServiceManager.is() ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir m_xURLTransformer = Reference< XURLTransformer >( 120cdf0e10cSrcweir m_xServiceManager->createInstance( 121cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))), 122cdf0e10cSrcweir UNO_QUERY ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir return m_xURLTransformer; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir // XInterface 129cdf0e10cSrcweir Any SAL_CALL StatusbarController::queryInterface( const Type& rType ) 130cdf0e10cSrcweir throw ( RuntimeException ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir Any a = ::cppu::queryInterface( 133cdf0e10cSrcweir rType , 134cdf0e10cSrcweir static_cast< XStatusbarController* >( this ), 135cdf0e10cSrcweir static_cast< XStatusListener* >( this ), 136cdf0e10cSrcweir static_cast< XEventListener* >( this ), 137cdf0e10cSrcweir static_cast< XInitialization* >( this ), 138cdf0e10cSrcweir static_cast< XComponent* >( this ), 139cdf0e10cSrcweir static_cast< XUpdatable* >( this )); 140cdf0e10cSrcweir 141cdf0e10cSrcweir if ( a.hasValue() ) 142cdf0e10cSrcweir return a; 143cdf0e10cSrcweir 144cdf0e10cSrcweir return OWeakObject::queryInterface( rType ); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir void SAL_CALL StatusbarController::acquire() throw () 148cdf0e10cSrcweir { 149cdf0e10cSrcweir OWeakObject::acquire(); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir void SAL_CALL StatusbarController::release() throw () 153cdf0e10cSrcweir { 154cdf0e10cSrcweir OWeakObject::release(); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir void SAL_CALL StatusbarController::initialize( const Sequence< Any >& aArguments ) 158cdf0e10cSrcweir throw ( Exception, RuntimeException ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir const rtl::OUString aFrameName( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 161cdf0e10cSrcweir const rtl::OUString aCommandURLName( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )); 162cdf0e10cSrcweir const rtl::OUString aServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" )); 163cdf0e10cSrcweir const rtl::OUString aParentWindow( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" )); 164cdf0e10cSrcweir const rtl::OUString aIdentifier( RTL_CONSTASCII_USTRINGPARAM( "Identifier" )); 165cdf0e10cSrcweir 166cdf0e10cSrcweir bool bInitialized( true ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir { 169cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir if ( m_bDisposed ) 172cdf0e10cSrcweir throw DisposedException(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir bInitialized = m_bInitialized; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir if ( !bInitialized ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 180cdf0e10cSrcweir m_bInitialized = sal_True; 181cdf0e10cSrcweir 182cdf0e10cSrcweir PropertyValue aPropValue; 183cdf0e10cSrcweir for ( int i = 0; i < aArguments.getLength(); i++ ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir if ( aArguments[i] >>= aPropValue ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if ( aPropValue.Name.equalsAscii( "Frame" )) 188cdf0e10cSrcweir aPropValue.Value >>= m_xFrame; 189cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "CommandURL" )) 190cdf0e10cSrcweir aPropValue.Value >>= m_aCommandURL; 191cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "ServiceManager" )) 192cdf0e10cSrcweir aPropValue.Value >>= m_xServiceManager; 193cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "ParentWindow" )) 194cdf0e10cSrcweir aPropValue.Value >>= m_xParentWindow; 195cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "Identifier" )) 196cdf0e10cSrcweir aPropValue.Value >>= m_nID; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir if ( m_aCommandURL.getLength() ) 201cdf0e10cSrcweir m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() )); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir void SAL_CALL StatusbarController::update() 206cdf0e10cSrcweir throw ( RuntimeException ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir { 209cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 210cdf0e10cSrcweir if ( m_bDisposed ) 211cdf0e10cSrcweir throw DisposedException(); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir // Bind all registered listeners to their dispatch objects 215cdf0e10cSrcweir bindListener(); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // XComponent 219cdf0e10cSrcweir void SAL_CALL StatusbarController::dispose() 220cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir { 225cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 226cdf0e10cSrcweir if ( m_bDisposed ) 227cdf0e10cSrcweir throw DisposedException(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir com::sun::star::lang::EventObject aEvent( xThis ); 231cdf0e10cSrcweir m_aListenerContainer.disposeAndClear( aEvent ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 234cdf0e10cSrcweir Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 235cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 236cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 237cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 238cdf0e10cSrcweir while ( pIter != m_aListenerMap.end() ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir try 241cdf0e10cSrcweir { 242cdf0e10cSrcweir Reference< XDispatch > xDispatch( pIter->second ); 243cdf0e10cSrcweir aTargetURL.Complete = pIter->first; 244cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir if ( xDispatch.is() && xStatusListener.is() ) 247cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir catch ( Exception& ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir ++pIter; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir // clear hash map 257cdf0e10cSrcweir m_aListenerMap.clear(); 258cdf0e10cSrcweir 259cdf0e10cSrcweir // release references 260cdf0e10cSrcweir m_xURLTransformer.clear(); 261cdf0e10cSrcweir m_xServiceManager.clear(); 262cdf0e10cSrcweir m_xFrame.clear(); 263cdf0e10cSrcweir m_xParentWindow.clear(); 264cdf0e10cSrcweir 265cdf0e10cSrcweir m_bDisposed = sal_True; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir void SAL_CALL StatusbarController::addEventListener( const Reference< XEventListener >& xListener ) 269cdf0e10cSrcweir throw ( RuntimeException ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir void SAL_CALL StatusbarController::removeEventListener( const Reference< XEventListener >& aListener ) 275cdf0e10cSrcweir throw ( RuntimeException ) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir // XEventListener 281cdf0e10cSrcweir void SAL_CALL StatusbarController::disposing( const EventObject& Source ) 282cdf0e10cSrcweir throw ( RuntimeException ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir Reference< XInterface > xSource( Source.Source ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 287cdf0e10cSrcweir 288cdf0e10cSrcweir if ( m_bDisposed ) 289cdf0e10cSrcweir return; 290cdf0e10cSrcweir 291cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 292cdf0e10cSrcweir while ( pIter != m_aListenerMap.end() ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir // Compare references and release dispatch references if they are equal. 295cdf0e10cSrcweir Reference< XInterface > xIfac( pIter->second, UNO_QUERY ); 296cdf0e10cSrcweir if ( xSource == xIfac ) 297cdf0e10cSrcweir pIter->second.clear(); 298cdf0e10cSrcweir pIter++; 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir Reference< XInterface > xIfac( m_xFrame, UNO_QUERY ); 302cdf0e10cSrcweir if ( xIfac == xSource ) 303cdf0e10cSrcweir m_xFrame.clear(); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir 306cdf0e10cSrcweir // XStatusListener 307cdf0e10cSrcweir void SAL_CALL StatusbarController::statusChanged( const FeatureStateEvent& Event ) 308cdf0e10cSrcweir throw ( RuntimeException ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 311cdf0e10cSrcweir 312cdf0e10cSrcweir if ( m_bDisposed ) 313cdf0e10cSrcweir return; 314cdf0e10cSrcweir 315cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( m_xParentWindow ); 316cdf0e10cSrcweir if ( pWindow && pWindow->GetType() == WINDOW_STATUSBAR && m_nID != 0 ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir rtl::OUString aStrValue; 319cdf0e10cSrcweir StatusBar* pStatusBar = (StatusBar *)pWindow; 320cdf0e10cSrcweir 321cdf0e10cSrcweir if ( Event.State >>= aStrValue ) 322cdf0e10cSrcweir pStatusBar->SetItemText( m_nID, aStrValue ); 323cdf0e10cSrcweir else if ( !Event.State.hasValue() ) 324cdf0e10cSrcweir pStatusBar->SetItemText( m_nID, String() ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // XStatusbarController 329cdf0e10cSrcweir ::sal_Bool SAL_CALL StatusbarController::mouseButtonDown( 330cdf0e10cSrcweir const ::com::sun::star::awt::MouseEvent& ) 331cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir return sal_False; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir ::sal_Bool SAL_CALL StatusbarController::mouseMove( 337cdf0e10cSrcweir const ::com::sun::star::awt::MouseEvent& ) 338cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir return sal_False; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir ::sal_Bool SAL_CALL StatusbarController::mouseButtonUp( 344cdf0e10cSrcweir const ::com::sun::star::awt::MouseEvent& ) 345cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir return sal_False; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir void SAL_CALL StatusbarController::command( 351cdf0e10cSrcweir const ::com::sun::star::awt::Point&, 352cdf0e10cSrcweir ::sal_Int32, 353cdf0e10cSrcweir ::sal_Bool, 354cdf0e10cSrcweir const ::com::sun::star::uno::Any& ) 355cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir void SAL_CALL StatusbarController::paint( 360cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >&, 361cdf0e10cSrcweir const ::com::sun::star::awt::Rectangle&, 362cdf0e10cSrcweir ::sal_Int32, 363cdf0e10cSrcweir ::sal_Int32 ) 364cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir void SAL_CALL StatusbarController::click() 369cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir void SAL_CALL StatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 376cdf0e10cSrcweir 377cdf0e10cSrcweir if ( m_bDisposed ) 378cdf0e10cSrcweir return; 379cdf0e10cSrcweir 380cdf0e10cSrcweir Sequence< PropertyValue > aArgs; 381cdf0e10cSrcweir execute( aArgs ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir void StatusbarController::addStatusListener( const rtl::OUString& aCommandURL ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir Reference< XDispatch > xDispatch; 387cdf0e10cSrcweir Reference< XStatusListener > xStatusListener; 388cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 389cdf0e10cSrcweir 390cdf0e10cSrcweir { 391cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 392cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL ); 393cdf0e10cSrcweir 394cdf0e10cSrcweir // Already in the list of status listener. Do nothing. 395cdf0e10cSrcweir if ( pIter != m_aListenerMap.end() ) 396cdf0e10cSrcweir return; 397cdf0e10cSrcweir 398cdf0e10cSrcweir // Check if we are already initialized. Implementation starts adding itself as status listener when 399cdf0e10cSrcweir // intialize is called. 400cdf0e10cSrcweir if ( !m_bInitialized ) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir // Put into the hash_map of status listener. Will be activated when initialized is called 403cdf0e10cSrcweir m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, Reference< XDispatch >() )); 404cdf0e10cSrcweir return; 405cdf0e10cSrcweir } 406cdf0e10cSrcweir else 407cdf0e10cSrcweir { 408cdf0e10cSrcweir // Add status listener directly as intialize has already been called. 409cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 410cdf0e10cSrcweir if ( m_xServiceManager.is() && xDispatchProvider.is() ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 413cdf0e10cSrcweir aTargetURL.Complete = aCommandURL; 414cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 415cdf0e10cSrcweir xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 416cdf0e10cSrcweir 417cdf0e10cSrcweir xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ); 418cdf0e10cSrcweir URLToDispatchMap::iterator aIter = m_aListenerMap.find( aCommandURL ); 419cdf0e10cSrcweir if ( aIter != m_aListenerMap.end() ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir Reference< XDispatch > xOldDispatch( aIter->second ); 422cdf0e10cSrcweir aIter->second = xDispatch; 423cdf0e10cSrcweir 424cdf0e10cSrcweir try 425cdf0e10cSrcweir { 426cdf0e10cSrcweir if ( xOldDispatch.is() ) 427cdf0e10cSrcweir xOldDispatch->removeStatusListener( xStatusListener, aTargetURL ); 428cdf0e10cSrcweir } 429cdf0e10cSrcweir catch ( Exception& ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir } 432cdf0e10cSrcweir } 433cdf0e10cSrcweir else 434cdf0e10cSrcweir m_aListenerMap.insert( URLToDispatchMap::value_type( aCommandURL, xDispatch )); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir } 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir // Call without locked mutex as we are called back from dispatch implementation 440cdf0e10cSrcweir try 441cdf0e10cSrcweir { 442cdf0e10cSrcweir if ( xDispatch.is() ) 443cdf0e10cSrcweir xDispatch->addStatusListener( xStatusListener, aTargetURL ); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir catch ( Exception& ) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir } 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir void StatusbarController::removeStatusListener( const rtl::OUString& aCommandURL ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 453cdf0e10cSrcweir 454cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL ); 455cdf0e10cSrcweir if ( pIter != m_aListenerMap.end() ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir Reference< XDispatch > xDispatch( pIter->second ); 458cdf0e10cSrcweir Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 459cdf0e10cSrcweir m_aListenerMap.erase( pIter ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir try 462cdf0e10cSrcweir { 463cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 464cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 465cdf0e10cSrcweir aTargetURL.Complete = aCommandURL; 466cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir if ( xDispatch.is() && xStatusListener.is() ) 469cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir catch ( Exception& ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir } 474cdf0e10cSrcweir } 475cdf0e10cSrcweir } 476cdf0e10cSrcweir 477cdf0e10cSrcweir void StatusbarController::bindListener() 478cdf0e10cSrcweir { 479cdf0e10cSrcweir std::vector< Listener > aDispatchVector; 480cdf0e10cSrcweir Reference< XStatusListener > xStatusListener; 481cdf0e10cSrcweir 482cdf0e10cSrcweir { 483cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir if ( !m_bInitialized ) 486cdf0e10cSrcweir return; 487cdf0e10cSrcweir 488cdf0e10cSrcweir // Collect all registered command URL's and store them temporary 489cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 490cdf0e10cSrcweir if ( m_xServiceManager.is() && xDispatchProvider.is() ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ); 493cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 494cdf0e10cSrcweir while ( pIter != m_aListenerMap.end() ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 497cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 498cdf0e10cSrcweir aTargetURL.Complete = pIter->first; 499cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 500cdf0e10cSrcweir 501cdf0e10cSrcweir Reference< XDispatch > xDispatch( pIter->second ); 502cdf0e10cSrcweir if ( xDispatch.is() ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir // We already have a dispatch object => we have to requery. 505cdf0e10cSrcweir // Release old dispatch object and remove it as listener 506cdf0e10cSrcweir try 507cdf0e10cSrcweir { 508cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir catch ( Exception& ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir } 513cdf0e10cSrcweir } 514cdf0e10cSrcweir 515cdf0e10cSrcweir pIter->second.clear(); 516cdf0e10cSrcweir xDispatch.clear(); 517cdf0e10cSrcweir 518cdf0e10cSrcweir // Query for dispatch object. Old dispatch will be released with this, too. 519cdf0e10cSrcweir try 520cdf0e10cSrcweir { 521cdf0e10cSrcweir xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir catch ( Exception& ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir } 526cdf0e10cSrcweir pIter->second = xDispatch; 527cdf0e10cSrcweir 528cdf0e10cSrcweir Listener aListener( aTargetURL, xDispatch ); 529cdf0e10cSrcweir aDispatchVector.push_back( aListener ); 530cdf0e10cSrcweir ++pIter; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir // Call without locked mutex as we are called back from dispatch implementation 536cdf0e10cSrcweir if ( xStatusListener.is() ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir try 539cdf0e10cSrcweir { 540cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir Listener& rListener = aDispatchVector[i]; 543cdf0e10cSrcweir if ( rListener.xDispatch.is() ) 544cdf0e10cSrcweir rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL ); 545cdf0e10cSrcweir else if ( rListener.aURL.Complete == m_aCommandURL ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir try 548cdf0e10cSrcweir { 549cdf0e10cSrcweir // Send status changed for the main URL, if we cannot get a valid dispatch object. 550cdf0e10cSrcweir // UI disables the button. Catch exception as we release our mutex, it is possible 551cdf0e10cSrcweir // that someone else already disposed this instance! 552cdf0e10cSrcweir FeatureStateEvent aFeatureStateEvent; 553cdf0e10cSrcweir aFeatureStateEvent.IsEnabled = sal_False; 554cdf0e10cSrcweir aFeatureStateEvent.FeatureURL = rListener.aURL; 555cdf0e10cSrcweir aFeatureStateEvent.State = Any(); 556cdf0e10cSrcweir xStatusListener->statusChanged( aFeatureStateEvent ); 557cdf0e10cSrcweir } 558cdf0e10cSrcweir catch ( Exception& ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir } 561cdf0e10cSrcweir } 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir catch ( Exception& ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir } 567cdf0e10cSrcweir } 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir void StatusbarController::unbindListener() 571cdf0e10cSrcweir { 572cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir if ( !m_bInitialized ) 575cdf0e10cSrcweir return; 576cdf0e10cSrcweir 577cdf0e10cSrcweir // Collect all registered command URL's and store them temporary 578cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 579cdf0e10cSrcweir if ( m_xServiceManager.is() && xDispatchProvider.is() ) 580cdf0e10cSrcweir { 581cdf0e10cSrcweir Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 582cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 583cdf0e10cSrcweir while ( pIter != m_aListenerMap.end() ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 586cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 587cdf0e10cSrcweir aTargetURL.Complete = pIter->first; 588cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir Reference< XDispatch > xDispatch( pIter->second ); 591cdf0e10cSrcweir if ( xDispatch.is() ) 592cdf0e10cSrcweir { 593cdf0e10cSrcweir // We already have a dispatch object => we have to requery. 594cdf0e10cSrcweir // Release old dispatch object and remove it as listener 595cdf0e10cSrcweir try 596cdf0e10cSrcweir { 597cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir catch ( Exception& ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir } 602cdf0e10cSrcweir } 603cdf0e10cSrcweir pIter->second.clear(); 604cdf0e10cSrcweir ++pIter; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir } 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir sal_Bool StatusbarController::isBound() const 610cdf0e10cSrcweir { 611cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 612cdf0e10cSrcweir 613cdf0e10cSrcweir if ( !m_bInitialized ) 614cdf0e10cSrcweir return sal_False; 615cdf0e10cSrcweir 616cdf0e10cSrcweir URLToDispatchMap::const_iterator pIter = m_aListenerMap.find( m_aCommandURL ); 617cdf0e10cSrcweir if ( pIter != m_aListenerMap.end() ) 618cdf0e10cSrcweir return ( pIter->second.is() ); 619cdf0e10cSrcweir 620cdf0e10cSrcweir return sal_False; 621cdf0e10cSrcweir } 622cdf0e10cSrcweir 623cdf0e10cSrcweir void StatusbarController::updateStatus() 624cdf0e10cSrcweir { 625cdf0e10cSrcweir bindListener(); 626cdf0e10cSrcweir } 627cdf0e10cSrcweir 628cdf0e10cSrcweir void StatusbarController::updateStatus( const rtl::OUString aCommandURL ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir Reference< XDispatch > xDispatch; 631cdf0e10cSrcweir Reference< XStatusListener > xStatusListener; 632cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 633cdf0e10cSrcweir 634cdf0e10cSrcweir { 635cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 636cdf0e10cSrcweir 637cdf0e10cSrcweir if ( !m_bInitialized ) 638cdf0e10cSrcweir return; 639cdf0e10cSrcweir 640cdf0e10cSrcweir // Try to find a dispatch object for the requested command URL 641cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 642cdf0e10cSrcweir xStatusListener = Reference< XStatusListener >( static_cast< OWeakObject* >( this ), UNO_QUERY ); 643cdf0e10cSrcweir if ( m_xServiceManager.is() && xDispatchProvider.is() ) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 646cdf0e10cSrcweir aTargetURL.Complete = aCommandURL; 647cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 648cdf0e10cSrcweir xDispatch = xDispatchProvider->queryDispatch( aTargetURL, rtl::OUString(), 0 ); 649cdf0e10cSrcweir } 650cdf0e10cSrcweir } 651cdf0e10cSrcweir 652cdf0e10cSrcweir if ( xDispatch.is() && xStatusListener.is() ) 653cdf0e10cSrcweir { 654cdf0e10cSrcweir // Catch exception as we release our mutex, it is possible that someone else 655cdf0e10cSrcweir // has already disposed this instance! 656cdf0e10cSrcweir // Add/remove status listener to get a update status information from the 657cdf0e10cSrcweir // requested command. 658cdf0e10cSrcweir try 659cdf0e10cSrcweir { 660cdf0e10cSrcweir xDispatch->addStatusListener( xStatusListener, aTargetURL ); 661cdf0e10cSrcweir xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 662cdf0e10cSrcweir } 663cdf0e10cSrcweir catch ( Exception& ) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir } 666cdf0e10cSrcweir } 667cdf0e10cSrcweir } 668cdf0e10cSrcweir 669cdf0e10cSrcweir ::Rectangle StatusbarController::getControlRect() const 670cdf0e10cSrcweir { 671cdf0e10cSrcweir ::Rectangle aRect; 672cdf0e10cSrcweir 673cdf0e10cSrcweir { 674cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 675cdf0e10cSrcweir 676cdf0e10cSrcweir if ( m_bDisposed ) 677cdf0e10cSrcweir throw DisposedException(); 678cdf0e10cSrcweir 679cdf0e10cSrcweir if ( m_xParentWindow.is() ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir StatusBar* pStatusBar = dynamic_cast< StatusBar* >( VCLUnoHelper::GetWindow( m_xParentWindow )); 682cdf0e10cSrcweir if ( pStatusBar && pStatusBar->GetType() == WINDOW_STATUSBAR ) 683cdf0e10cSrcweir aRect = pStatusBar->GetItemRect( m_nID ); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir return aRect; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir 690cdf0e10cSrcweir void StatusbarController::execute( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir Reference< XDispatch > xDispatch; 693cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer; 694cdf0e10cSrcweir rtl::OUString aCommandURL; 695cdf0e10cSrcweir 696cdf0e10cSrcweir { 697cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 698cdf0e10cSrcweir 699cdf0e10cSrcweir if ( m_bDisposed ) 700cdf0e10cSrcweir throw DisposedException(); 701cdf0e10cSrcweir 702cdf0e10cSrcweir if ( m_bInitialized && 703cdf0e10cSrcweir m_xFrame.is() && 704cdf0e10cSrcweir m_xServiceManager.is() && 705cdf0e10cSrcweir m_aCommandURL.getLength() ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir xURLTransformer = getURLTransformer(); 708cdf0e10cSrcweir aCommandURL = m_aCommandURL; 709cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL ); 710cdf0e10cSrcweir if ( pIter != m_aListenerMap.end() ) 711cdf0e10cSrcweir xDispatch = pIter->second; 712cdf0e10cSrcweir } 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir if ( xDispatch.is() && xURLTransformer.is() ) 716cdf0e10cSrcweir { 717cdf0e10cSrcweir try 718cdf0e10cSrcweir { 719cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 720cdf0e10cSrcweir 721cdf0e10cSrcweir aTargetURL.Complete = aCommandURL; 722cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 723cdf0e10cSrcweir xDispatch->dispatch( aTargetURL, aArgs ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir catch ( DisposedException& ) 726cdf0e10cSrcweir { 727cdf0e10cSrcweir } 728cdf0e10cSrcweir } 729cdf0e10cSrcweir } 730cdf0e10cSrcweir 731cdf0e10cSrcweir void StatusbarController::execute( 732cdf0e10cSrcweir const rtl::OUString& aCommandURL, 733cdf0e10cSrcweir const Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir Reference< XDispatch > xDispatch; 736cdf0e10cSrcweir com::sun::star::util::URL aTargetURL; 737cdf0e10cSrcweir 738cdf0e10cSrcweir { 739cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 740cdf0e10cSrcweir 741cdf0e10cSrcweir if ( m_bDisposed ) 742cdf0e10cSrcweir throw DisposedException(); 743cdf0e10cSrcweir 744cdf0e10cSrcweir if ( m_bInitialized && 745cdf0e10cSrcweir m_xFrame.is() && 746cdf0e10cSrcweir m_xServiceManager.is() && 747cdf0e10cSrcweir m_aCommandURL.getLength() ) 748cdf0e10cSrcweir { 749cdf0e10cSrcweir Reference< XURLTransformer > xURLTransformer( getURLTransformer() ); 750cdf0e10cSrcweir aTargetURL.Complete = aCommandURL; 751cdf0e10cSrcweir xURLTransformer->parseStrict( aTargetURL ); 752cdf0e10cSrcweir 753cdf0e10cSrcweir URLToDispatchMap::iterator pIter = m_aListenerMap.find( aCommandURL ); 754cdf0e10cSrcweir if ( pIter != m_aListenerMap.end() ) 755cdf0e10cSrcweir xDispatch = pIter->second; 756cdf0e10cSrcweir else 757cdf0e10cSrcweir { 758cdf0e10cSrcweir Reference< ::com::sun::star::frame::XDispatchProvider > xDispatchProvider( 759cdf0e10cSrcweir m_xFrame->getController(), UNO_QUERY ); 760cdf0e10cSrcweir if ( xDispatchProvider.is() ) 761cdf0e10cSrcweir xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir } 764cdf0e10cSrcweir } 765cdf0e10cSrcweir 766cdf0e10cSrcweir if ( xDispatch.is() ) 767cdf0e10cSrcweir { 768cdf0e10cSrcweir try 769cdf0e10cSrcweir { 770cdf0e10cSrcweir xDispatch->dispatch( aTargetURL, aArgs ); 771cdf0e10cSrcweir } 772cdf0e10cSrcweir catch ( DisposedException& ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir } 775cdf0e10cSrcweir } 776cdf0e10cSrcweir } 777cdf0e10cSrcweir 778cdf0e10cSrcweir } // svt 779