statusbarcontroller.cxx (5900e8ec) | statusbarcontroller.cxx (0c02d14e) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 21 unchanged lines hidden (view full) --- 30#include <com/sun/star/lang/DisposedException.hpp> 31#include <com/sun/star/frame/XLayoutManager.hpp> 32#include <vos/mutex.hxx> 33#include <vcl/svapp.hxx> 34#include <vcl/window.hxx> 35#include <vcl/status.hxx> 36#include <svtools/imgdef.hxx> 37#include <svtools/miscopt.hxx> | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 21 unchanged lines hidden (view full) --- 30#include <com/sun/star/lang/DisposedException.hpp> 31#include <com/sun/star/frame/XLayoutManager.hpp> 32#include <vos/mutex.hxx> 33#include <vcl/svapp.hxx> 34#include <vcl/window.hxx> 35#include <vcl/status.hxx> 36#include <svtools/imgdef.hxx> 37#include <svtools/miscopt.hxx> |
38#include <toolkit/unohlp.hxx> | 38#include <toolkit/helper/vclunohelper.hxx> |
39 40using namespace ::cppu; 41using namespace ::com::sun::star::awt; 42using namespace ::com::sun::star::uno; 43using namespace ::com::sun::star::util; 44using namespace ::com::sun::star::beans; 45using namespace ::com::sun::star::lang; 46using namespace ::com::sun::star::frame; --- 105 unchanged lines hidden (view full) --- 152void SAL_CALL StatusbarController::release() throw () 153{ 154 OWeakObject::release(); 155} 156 157void SAL_CALL StatusbarController::initialize( const Sequence< Any >& aArguments ) 158throw ( Exception, RuntimeException ) 159{ | 39 40using namespace ::cppu; 41using namespace ::com::sun::star::awt; 42using namespace ::com::sun::star::uno; 43using namespace ::com::sun::star::util; 44using namespace ::com::sun::star::beans; 45using namespace ::com::sun::star::lang; 46using namespace ::com::sun::star::frame; --- 105 unchanged lines hidden (view full) --- 152void SAL_CALL StatusbarController::release() throw () 153{ 154 OWeakObject::release(); 155} 156 157void SAL_CALL StatusbarController::initialize( const Sequence< Any >& aArguments ) 158throw ( Exception, RuntimeException ) 159{ |
160 const rtl::OUString aFrameName( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 161 const rtl::OUString aCommandURLName( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )); 162 const rtl::OUString aServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" )); 163 const rtl::OUString aParentWindow( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" )); 164 const rtl::OUString aIdentifier( RTL_CONSTASCII_USTRINGPARAM( "Identifier" )); 165 | |
166 bool bInitialized( true ); 167 168 { 169 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 170 171 if ( m_bDisposed ) 172 throw DisposedException(); 173 --- 5 unchanged lines hidden (view full) --- 179 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 180 m_bInitialized = sal_True; 181 182 PropertyValue aPropValue; 183 for ( int i = 0; i < aArguments.getLength(); i++ ) 184 { 185 if ( aArguments[i] >>= aPropValue ) 186 { | 160 bool bInitialized( true ); 161 162 { 163 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 164 165 if ( m_bDisposed ) 166 throw DisposedException(); 167 --- 5 unchanged lines hidden (view full) --- 173 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 174 m_bInitialized = sal_True; 175 176 PropertyValue aPropValue; 177 for ( int i = 0; i < aArguments.getLength(); i++ ) 178 { 179 if ( aArguments[i] >>= aPropValue ) 180 { |
187 if ( aPropValue.Name.equalsAscii( "Frame" )) | 181 if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Frame" ))) |
188 aPropValue.Value >>= m_xFrame; | 182 aPropValue.Value >>= m_xFrame; |
189 else if ( aPropValue.Name.equalsAscii( "CommandURL" )) | 183 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CommandURL" ))) |
190 aPropValue.Value >>= m_aCommandURL; | 184 aPropValue.Value >>= m_aCommandURL; |
191 else if ( aPropValue.Name.equalsAscii( "ServiceManager" )) | 185 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ServiceManager" ))) |
192 aPropValue.Value >>= m_xServiceManager; | 186 aPropValue.Value >>= m_xServiceManager; |
193 else if ( aPropValue.Name.equalsAscii( "ParentWindow" )) | 187 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ))) |
194 aPropValue.Value >>= m_xParentWindow; | 188 aPropValue.Value >>= m_xParentWindow; |
195 else if ( aPropValue.Name.equalsAscii( "Identifier" )) | 189 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Identifier" ))) |
196 aPropValue.Value >>= m_nID; | 190 aPropValue.Value >>= m_nID; |
191 else if ( aPropValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusbarItem" ))) 192 aPropValue.Value >>= m_xStatusbarItem; |
|
197 } 198 } 199 200 if ( m_aCommandURL.getLength() ) 201 m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() )); 202 } 203} 204 --- 51 unchanged lines hidden (view full) --- 256 // clear hash map 257 m_aListenerMap.clear(); 258 259 // release references 260 m_xURLTransformer.clear(); 261 m_xServiceManager.clear(); 262 m_xFrame.clear(); 263 m_xParentWindow.clear(); | 193 } 194 } 195 196 if ( m_aCommandURL.getLength() ) 197 m_aListenerMap.insert( URLToDispatchMap::value_type( m_aCommandURL, Reference< XDispatch >() )); 198 } 199} 200 --- 51 unchanged lines hidden (view full) --- 252 // clear hash map 253 m_aListenerMap.clear(); 254 255 // release references 256 m_xURLTransformer.clear(); 257 m_xServiceManager.clear(); 258 m_xFrame.clear(); 259 m_xParentWindow.clear(); |
260 m_xStatusbarItem.clear(); |
|
264 265 m_bDisposed = sal_True; 266} 267 268void SAL_CALL StatusbarController::addEventListener( const Reference< XEventListener >& xListener ) 269throw ( RuntimeException ) 270{ 271 m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); --- 4 unchanged lines hidden (view full) --- 276{ 277 m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener ); 278} 279 280// XEventListener 281void SAL_CALL StatusbarController::disposing( const EventObject& Source ) 282throw ( RuntimeException ) 283{ | 261 262 m_bDisposed = sal_True; 263} 264 265void SAL_CALL StatusbarController::addEventListener( const Reference< XEventListener >& xListener ) 266throw ( RuntimeException ) 267{ 268 m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); --- 4 unchanged lines hidden (view full) --- 273{ 274 m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), aListener ); 275} 276 277// XEventListener 278void SAL_CALL StatusbarController::disposing( const EventObject& Source ) 279throw ( RuntimeException ) 280{ |
284 Reference< XInterface > xSource( Source.Source ); 285 | |
286 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 287 288 if ( m_bDisposed ) 289 return; 290 | 281 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 282 283 if ( m_bDisposed ) 284 return; 285 |
286 Reference< XFrame > xFrame( Source.Source, UNO_QUERY ); 287 if ( xFrame.is() ) 288 { 289 if ( xFrame == m_xFrame ) 290 m_xFrame.clear(); 291 return; 292 } 293 294 Reference< XDispatch > xDispatch( Source.Source, UNO_QUERY ); 295 if ( !xDispatch.is() ) 296 return; 297 |
|
291 URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 292 while ( pIter != m_aListenerMap.end() ) 293 { 294 // Compare references and release dispatch references if they are equal. | 298 URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 299 while ( pIter != m_aListenerMap.end() ) 300 { 301 // Compare references and release dispatch references if they are equal. |
295 Reference< XInterface > xIfac( pIter->second, UNO_QUERY ); 296 if ( xSource == xIfac ) | 302 if ( xDispatch == pIter->second ) |
297 pIter->second.clear(); 298 pIter++; 299 } | 303 pIter->second.clear(); 304 pIter++; 305 } |
300 301 Reference< XInterface > xIfac( m_xFrame, UNO_QUERY ); 302 if ( xIfac == xSource ) 303 m_xFrame.clear(); | |
304} 305 306// XStatusListener 307void SAL_CALL StatusbarController::statusChanged( const FeatureStateEvent& Event ) 308throw ( RuntimeException ) 309{ 310 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 311 --- 42 unchanged lines hidden (view full) --- 354 const ::com::sun::star::uno::Any& ) 355throw (::com::sun::star::uno::RuntimeException) 356{ 357} 358 359void SAL_CALL StatusbarController::paint( 360 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >&, 361 const ::com::sun::star::awt::Rectangle&, | 306} 307 308// XStatusListener 309void SAL_CALL StatusbarController::statusChanged( const FeatureStateEvent& Event ) 310throw ( RuntimeException ) 311{ 312 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 313 --- 42 unchanged lines hidden (view full) --- 356 const ::com::sun::star::uno::Any& ) 357throw (::com::sun::star::uno::RuntimeException) 358{ 359} 360 361void SAL_CALL StatusbarController::paint( 362 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >&, 363 const ::com::sun::star::awt::Rectangle&, |
362 ::sal_Int32, | |
363 ::sal_Int32 ) 364throw (::com::sun::star::uno::RuntimeException) 365{ 366} 367 | 364 ::sal_Int32 ) 365throw (::com::sun::star::uno::RuntimeException) 366{ 367} 368 |
368void SAL_CALL StatusbarController::click() | 369void SAL_CALL StatusbarController::click( const ::com::sun::star::awt::Point& ) |
369throw (::com::sun::star::uno::RuntimeException) 370{ 371} 372 | 370throw (::com::sun::star::uno::RuntimeException) 371{ 372} 373 |
373void SAL_CALL StatusbarController::doubleClick() throw (::com::sun::star::uno::RuntimeException) | 374void SAL_CALL StatusbarController::doubleClick( const ::com::sun::star::awt::Point& ) throw (::com::sun::star::uno::RuntimeException) |
374{ 375 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 376 377 if ( m_bDisposed ) 378 return; 379 380 Sequence< PropertyValue > aArgs; 381 execute( aArgs ); --- 146 unchanged lines hidden (view full) --- 528 Listener aListener( aTargetURL, xDispatch ); 529 aDispatchVector.push_back( aListener ); 530 ++pIter; 531 } 532 } 533 } 534 535 // Call without locked mutex as we are called back from dispatch implementation | 375{ 376 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 377 378 if ( m_bDisposed ) 379 return; 380 381 Sequence< PropertyValue > aArgs; 382 execute( aArgs ); --- 146 unchanged lines hidden (view full) --- 529 Listener aListener( aTargetURL, xDispatch ); 530 aDispatchVector.push_back( aListener ); 531 ++pIter; 532 } 533 } 534 } 535 536 // Call without locked mutex as we are called back from dispatch implementation |
536 if ( xStatusListener.is() ) | 537 if ( !xStatusListener.is() ) 538 return; 539 540 for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ ) |
537 { 538 try 539 { | 541 { 542 try 543 { |
540 for ( sal_uInt32 i = 0; i < aDispatchVector.size(); i++ ) | 544 Listener& rListener = aDispatchVector[i]; 545 if ( rListener.xDispatch.is() ) 546 rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL ); 547 else if ( rListener.aURL.Complete == m_aCommandURL ) |
541 { | 548 { |
542 Listener& rListener = aDispatchVector[i]; 543 if ( rListener.xDispatch.is() ) 544 rListener.xDispatch->addStatusListener( xStatusListener, rListener.aURL ); 545 else if ( rListener.aURL.Complete == m_aCommandURL ) 546 { 547 try 548 { 549 // Send status changed for the main URL, if we cannot get a valid dispatch object. 550 // UI disables the button. Catch exception as we release our mutex, it is possible 551 // that someone else already disposed this instance! 552 FeatureStateEvent aFeatureStateEvent; 553 aFeatureStateEvent.IsEnabled = sal_False; 554 aFeatureStateEvent.FeatureURL = rListener.aURL; 555 aFeatureStateEvent.State = Any(); 556 xStatusListener->statusChanged( aFeatureStateEvent ); 557 } 558 catch ( Exception& ) 559 { 560 } 561 } | 549 // Send status changed for the main URL, if we cannot get a valid dispatch object. 550 // UI disables the button. Catch exception as we release our mutex, it is possible 551 // that someone else already disposed this instance! 552 FeatureStateEvent aFeatureStateEvent; 553 aFeatureStateEvent.IsEnabled = sal_False; 554 aFeatureStateEvent.FeatureURL = rListener.aURL; 555 aFeatureStateEvent.State = Any(); 556 xStatusListener->statusChanged( aFeatureStateEvent ); |
562 } 563 } | 557 } 558 } |
564 catch ( Exception& ) 565 { 566 } | 559 catch ( ... ){} |
567 } 568} 569 570void StatusbarController::unbindListener() 571{ 572 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 573 574 if ( !m_bInitialized ) 575 return; 576 | 560 } 561} 562 563void StatusbarController::unbindListener() 564{ 565 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 566 567 if ( !m_bInitialized ) 568 return; 569 |
577 // Collect all registered command URL's and store them temporary 578 Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); 579 if ( m_xServiceManager.is() && xDispatchProvider.is() ) | 570 Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 571 URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 572 while ( pIter != m_aListenerMap.end() ) |
580 { | 573 { |
581 Reference< XStatusListener > xStatusListener( static_cast< OWeakObject* >( this ), UNO_QUERY ); 582 URLToDispatchMap::iterator pIter = m_aListenerMap.begin(); 583 while ( pIter != m_aListenerMap.end() ) 584 { 585 Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 586 com::sun::star::util::URL aTargetURL; 587 aTargetURL.Complete = pIter->first; 588 xURLTransformer->parseStrict( aTargetURL ); | 574 Reference< XURLTransformer > xURLTransformer = getURLTransformer(); 575 com::sun::star::util::URL aTargetURL; 576 aTargetURL.Complete = pIter->first; 577 xURLTransformer->parseStrict( aTargetURL ); |
589 | 578 |
590 Reference< XDispatch > xDispatch( pIter->second ); 591 if ( xDispatch.is() ) | 579 Reference< XDispatch > xDispatch( pIter->second ); 580 if ( xDispatch.is() ) 581 { 582 // We already have a dispatch object => we have to requery. 583 // Release old dispatch object and remove it as listener 584 try |
592 { | 585 { |
593 // We already have a dispatch object => we have to requery. 594 // Release old dispatch object and remove it as listener 595 try 596 { 597 xDispatch->removeStatusListener( xStatusListener, aTargetURL ); 598 } 599 catch ( Exception& ) 600 { 601 } | 586 xDispatch->removeStatusListener( xStatusListener, aTargetURL ); |
602 } | 587 } |
603 pIter->second.clear(); 604 ++pIter; | 588 catch ( Exception& ) 589 { 590 } |
605 } | 591 } |
592 pIter->second.clear(); 593 ++pIter; |
|
606 } 607} 608 609sal_Bool StatusbarController::isBound() const 610{ 611 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 612 613 if ( !m_bInitialized ) --- 165 unchanged lines hidden --- | 594 } 595} 596 597sal_Bool StatusbarController::isBound() const 598{ 599 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 600 601 if ( !m_bInitialized ) --- 165 unchanged lines hidden --- |