Tag: cws_dev300_dba30d User: fs Date: 2008-06-01 20:59:37+0000 Modified: dba/dbaccess/source/ui/browser/genericcontroller.cxx
Log: #i80943# allow for 'user-defined' features, which are Commands registered by URL at runtime, but not known at compile time File Changes: Directory: /dba/dbaccess/source/ui/browser/ =========================================== File [changed]: genericcontroller.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/browser/genericcontroller.cxx?r1=1.88.6.1&r2=1.88.6.2 Delta lines: +114 -23 ---------------------- --- genericcontroller.cxx 2008-05-28 21:44:26+0000 1.88.6.1 +++ genericcontroller.cxx 2008-06-01 20:59:34+0000 1.88.6.2 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: genericcontroller.cxx,v $ - * $Revision: 1.88.6.1 $ + * $Revision: 1.88.6.2 $ * * This file is part of OpenOffice.org. * @@ -130,6 +130,7 @@ #endif #include <algorithm> #include <hash_map> +#include <limits> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -145,11 +146,12 @@ using namespace ::com::sun::star::awt; using namespace ::com::sun::star; using namespace ::dbtools; -using namespace ::dbaui; using namespace ::comphelper; // ------------------------------------------------------------------------- #define ALL_FEATURES -1 +#define FIRST_USER_DEFINED_FEATURE ( ::std::numeric_limits< sal_uInt16 >::max() - 1000 ) +#define LAST_USER_DEFINED_FEATURE ( ::std::numeric_limits< sal_uInt16 >::max() ) // ------------------------------------------------------------------------- typedef ::std::hash_map< sal_Int16, sal_Int16 > CommandHashMap; @@ -162,11 +164,30 @@ return sConfirmDeletionURL; } +namespace dbaui +{ + +//========================================================================== +//= OGenericUnoController_Data +//========================================================================== +struct OGenericUnoController_Data +{ + ::sfx2::UserInputInterception m_aUserInputInterception; + + OGenericUnoController_Data( OGenericUnoController& _rController, ::osl::Mutex& _rMutex ) + :m_aUserInputInterception( _rController, _rMutex ) + { + } +}; + +//========================================================================== +//= OGenericUnoController +//========================================================================== DBG_NAME(OGenericUnoController) // ------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFactory >& _rM) :OGenericUnoController_Base(m_aMutex) - ,m_aUserInputInterception( *this, m_aMutex ) + ,m_pData( new OGenericUnoController_Data( *this, m_aMutex ) ) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif @@ -196,7 +217,7 @@ // ----------------------------------------------------------------------------- OGenericUnoController::OGenericUnoController() :OGenericUnoController_Base(m_aMutex) - ,m_aUserInputInterception( *this, m_aMutex ) + ,m_pData( new OGenericUnoController_Data( *this, m_aMutex ) ) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) #endif @@ -661,8 +682,10 @@ { Reference< XDispatch > xReturn; + OSL_PRECOND( m_aSupportedFeatures.empty(), "OGenericUnoController::queryDispatch: shouldn't this be filled at construction time?" ); if ( m_aSupportedFeatures.empty() ) fillSupportedFeatures(); + // URL's we can handle ourself? if ( aURL.Complete.equals( getConfirmDeletionURL() ) || ( m_aSupportedFeatures.find( aURL.Complete ) != m_aSupportedFeatures.end() ) @@ -786,8 +809,10 @@ ++iterSearch; } + OSL_PRECOND( m_aSupportedFeatures.empty(), "OGenericUnoController::removeStatusListener: shouldn't this be filled at construction time?" ); if ( m_aSupportedFeatures.empty() ) fillSupportedFeatures(); + SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find(_rURL.Complete); if (aIter != m_aSupportedFeatures.end()) { // clear the cache for that feature @@ -885,6 +910,7 @@ #ifdef DBG_UTIL DBG_ASSERT( m_bDescribingSupportedFeatures, "OGenericUnoController::implDescribeSupportedFeature: bad timing for this call!" ); #endif + OSL_PRECOND( _nFeatureId < FIRST_USER_DEFINED_FEATURE, "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" ); ControllerFeature aFeature; aFeature.Command = ::rtl::OUString::createFromAscii( _pAsciiCommandURL ); @@ -923,9 +949,6 @@ case ID_BROWSER_SAVEDOC: aReturn.bEnabled = sal_True; break; - case 99: - aReturn.bEnabled = sal_False; - break; } } catch( const Exception& ) @@ -935,6 +958,35 @@ return aReturn; } + +//------------------------------------------------------------------------------ +void OGenericUnoController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue>& _rArgs ) +{ + OSL_ENSURE( isUserDefinedFeature( _nId ), + "OGenericUnoController::Execute: responsible for user defined features only!" ); + URL aFeatureURL( getURLForId( _nId ) ); + + // user defined features can be handled by dispatch interceptors only. So, we need to do + // a queryDispatch, and dispatch the URL + try + { + Reference< XDispatch > xDispatch( queryDispatch( + aFeatureURL, + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ), + FrameSearchFlag::AUTO + ) ); + if ( xDispatch == *this ) + xDispatch.clear(); + + if ( xDispatch.is() ) + xDispatch->dispatch( aFeatureURL, _rArgs ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + //------------------------------------------------------------------------------ URL OGenericUnoController::getURLForId(sal_Int32 _nId) const { @@ -957,6 +1009,12 @@ } //------------------------------------------------------------------------- +bool OGenericUnoController::isUserDefinedFeature( const sal_uInt16 _nFeatureId ) +{ + return ( _nFeatureId >= FIRST_USER_DEFINED_FEATURE ) && ( _nFeatureId < LAST_USER_DEFINED_FEATURE ); +} + +//------------------------------------------------------------------------- sal_Bool SAL_CALL OGenericUnoController::supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException) { Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); @@ -1124,8 +1182,10 @@ // ----------------------------------------------------------------------------- void OGenericUnoController::executeUnChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs) { + OSL_PRECOND( m_aSupportedFeatures.empty(), "OGenericUnoController::executeUnChecked: shouldn't this be filled at construction time?" ); if ( m_aSupportedFeatures.empty() ) fillSupportedFeatures(); + SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete ); if (aIter != m_aSupportedFeatures.end()) Execute( aIter->second.nFeatureId, aArgs ); @@ -1133,8 +1193,10 @@ // ----------------------------------------------------------------------------- void OGenericUnoController::executeChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs) { + OSL_PRECOND( m_aSupportedFeatures.empty(), "OGenericUnoController::executeChecked: shouldn't this be filled at construction time?" ); if ( m_aSupportedFeatures.empty() ) fillSupportedFeatures(); + SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete ); if ( aIter != m_aSupportedFeatures.end() ) { @@ -1255,12 +1317,6 @@ } } -//------------------------------------------------------------------------------ -// prototype out of UITools.cxx -namespace dbaui -{ - void AppendConfigToken_Impl( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark ); -} // ----------------------------------------------------------------------------- void OGenericUnoController::openHelpAgent(rtl::OUString const& _suHelpStringURL ) @@ -1269,7 +1325,7 @@ rtl::OUString sLanguage = rtl::OUString::createFromAscii("Language="); if (suURL.indexOf(sLanguage) == -1) { - dbaui::AppendConfigToken_Impl(suURL, sal_False /* sal_False := add '&' */ ); + AppendConfigToken(suURL, sal_False /* sal_False := add '&' */ ); } URL aURL; aURL.Complete = suURL; @@ -1394,26 +1450,26 @@ void SAL_CALL OGenericUnoController::addKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException) { if ( _rxHandler.is() ) - m_aUserInputInterception.addKeyHandler( _rxHandler ); + m_pData->m_aUserInputInterception.addKeyHandler( _rxHandler ); } // ----------------------------------------------------------------------------- void SAL_CALL OGenericUnoController::removeKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException) { - m_aUserInputInterception.removeKeyHandler( _rxHandler ); + m_pData->m_aUserInputInterception.removeKeyHandler( _rxHandler ); } // ----------------------------------------------------------------------------- void SAL_CALL OGenericUnoController::addMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException) { if ( _rxHandler.is() ) - m_aUserInputInterception.addMouseClickHandler( _rxHandler ); + m_pData->m_aUserInputInterception.addMouseClickHandler( _rxHandler ); } // ----------------------------------------------------------------------------- void SAL_CALL OGenericUnoController::removeMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException) { - m_aUserInputInterception.removeMouseClickHandler( _rxHandler ); + m_pData->m_aUserInputInterception.removeMouseClickHandler( _rxHandler ); } // ============================================================================= @@ -1431,13 +1487,47 @@ } // ----------------------------------------------------------------------------- +sal_uInt16 OGenericUnoController::registerCommandURL( const ::rtl::OUString& _rCompleteCommandURL ) +{ + if ( !_rCompleteCommandURL.getLength() ) + return 0; + + SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCompleteCommandURL ); + if ( aIter != m_aSupportedFeatures.end() ) + return aIter->second.nFeatureId; + + // this is a previously unkwnon command + sal_uInt16 nFeatureId = FIRST_USER_DEFINED_FEATURE; + while ( isFeatureSupported( nFeatureId ) && ( nFeatureId < LAST_USER_DEFINED_FEATURE ) ) + ++nFeatureId; + if ( nFeatureId == LAST_USER_DEFINED_FEATURE ) + { + OSL_ENSURE( false, "OGenericUnoController::registerCommandURL: no more space for user defined features!" ); + return 0L; + } + + ControllerFeature aFeature; + aFeature.Command = _rCompleteCommandURL; + aFeature.nFeatureId = nFeatureId; + aFeature.GroupId = CommandGroup::INTERNAL; + m_aSupportedFeatures[ aFeature.Command ] = aFeature; + + return nFeatureId; +} + +// ----------------------------------------------------------------------------- +void OGenericUnoController::notifyHiContrastChanged() +{ +} + +// ----------------------------------------------------------------------------- sal_Bool OGenericUnoController::isDataSourceReadOnly() const { return sal_False; } // ----------------------------------------------------------------------------- -Reference< XController > SAL_CALL OGenericUnoController::getXController() throw( RuntimeException ) +Reference< XController > OGenericUnoController::getXController() throw( RuntimeException ) { return this; } @@ -1445,7 +1535,7 @@ // ----------------------------------------------------------------------------- bool OGenericUnoController::interceptUserInput( const NotifyEvent& _rEvent ) { - return m_aUserInputInterception.handleNotifyEvent( _rEvent ); + return m_pData->m_aUserInputInterception.handleNotifyEvent( _rEvent ); } // ----------------------------------------------------------------------------- @@ -1548,3 +1638,4 @@ m_aSelectionListeners.removeInterface(xListener); } +} // namespace dbaui \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
