INTEGRATION: CWS docking3 (1.2.26); FILE MERGED

2004/07/22 07:38:07 cd 1.2.26.1: #i31831# Generic toolbar controller must execute dispatch asynchronously to keep toolbar responsive
This commit is contained in:
Oliver Bolte
2004-08-11 16:22:37 +00:00
parent 0ffabd6da8
commit a2bbbc5130

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: generictoolbarcontroller.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: obo $ $Date: 2004-07-06 17:00:58 $
* last change: $Author: obo $ $Date: 2004-08-11 17:22:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -120,6 +120,13 @@ using namespace ::com::sun::star::util;
namespace framework
{
struct ExecuteInfo
{
::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
::com::sun::star::util::URL aTargetURL;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
};
GenericToolbarController::GenericToolbarController( const Reference< XMultiServiceFactory >& rServiceManager,
const Reference< XFrame >& rFrame,
ToolBar* pToolbar,
@@ -146,6 +153,52 @@ throw ( RuntimeException )
m_nID = 0;
}
void SAL_CALL GenericToolbarController::execute( sal_Int16 KeyModifier )
throw ( RuntimeException )
{
Reference< XDispatch > xDispatch;
Reference< XURLTransformer > xURLTransformer;
OUString aCommandURL;
{
vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
if ( m_bDisposed )
throw DisposedException();
if ( m_bInitialized &&
m_xFrame.is() &&
m_xServiceManager.is() &&
m_aCommandURL.getLength() )
{
xURLTransformer = Reference< XURLTransformer >( m_xServiceManager->createInstance(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
UNO_QUERY );
aCommandURL = m_aCommandURL;
URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
if ( pIter != m_aListenerMap.end() )
xDispatch = pIter->second;
}
}
if ( xDispatch.is() && xURLTransformer.is() )
{
com::sun::star::util::URL aTargetURL;
Sequence<PropertyValue> aArgs;
aTargetURL.Complete = aCommandURL;
xURLTransformer->parseStrict( aTargetURL );
// Execute dispatch asynchronously
ExecuteInfo* pExecuteInfo = new ExecuteInfo;
pExecuteInfo->xDispatch = xDispatch;
pExecuteInfo->aTargetURL = aTargetURL;
pExecuteInfo->aArgs = aArgs;
Application::PostUserEvent( STATIC_LINK(0, GenericToolbarController , ExecuteHdl_Impl), pExecuteInfo );
}
}
void GenericToolbarController::statusChanged( const FeatureStateEvent& Event )
throw ( RuntimeException )
{
@@ -190,4 +243,20 @@ throw ( RuntimeException )
}
}
IMPL_STATIC_LINK( GenericToolbarController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
{
try
{
// Asynchronous execution as this can lead to our own destruction!
// Framework can recycle our current frame and the layout manager disposes all user interface
// elements if a component gets detached from its frame!
pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
}
catch ( Exception& )
{
}
delete pExecuteInfo;
return 0;
}
} // namespace