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 #ifndef SVX_FMDISPATCH_HXX 29*cdf0e10cSrcweir #define SVX_FMDISPATCH_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /** === begin UNO includes === **/ 32*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormOperations.hpp> 35*cdf0e10cSrcweir /** === end UNO includes === **/ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 38*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //........................................................................ 41*cdf0e10cSrcweir namespace svx 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir //........................................................................ 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //==================================================================== 46*cdf0e10cSrcweir //= OSingleFeatureDispatcher 47*cdf0e10cSrcweir //==================================================================== 48*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < ::com::sun::star::frame::XDispatch 49*cdf0e10cSrcweir > OSingleFeatureDispatcher_Base; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir class OSingleFeatureDispatcher : public OSingleFeatureDispatcher_Base 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir private: 54*cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 55*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aStatusListeners; 56*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > 57*cdf0e10cSrcweir m_xFormOperations; 58*cdf0e10cSrcweir const ::com::sun::star::util::URL m_aFeatureURL; 59*cdf0e10cSrcweir ::com::sun::star::uno::Any m_aLastKnownState; 60*cdf0e10cSrcweir const sal_Int16 m_nFormFeature; 61*cdf0e10cSrcweir sal_Bool m_bLastKnownEnabled; 62*cdf0e10cSrcweir sal_Bool m_bDisposed; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir /** constructs the dispatcher 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir @param _rFeatureURL 68*cdf0e10cSrcweir the URL of the feature which this instance is responsible for 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir @param _nFeatureId 71*cdf0e10cSrcweir the feature which this instance is responsible for 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir @param _rController 74*cdf0e10cSrcweir the controller which is responsible for providing the state of feature of this instance, 75*cdf0e10cSrcweir and for executing it. After disposing the dispatcher instance, the controller will 76*cdf0e10cSrcweir not be accessed anymore 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir @see dispose 79*cdf0e10cSrcweir */ 80*cdf0e10cSrcweir OSingleFeatureDispatcher( 81*cdf0e10cSrcweir const ::com::sun::star::util::URL& _rFeatureURL, 82*cdf0e10cSrcweir const sal_Int16 _nFormFeature, 83*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >& _rxFormOperations, 84*cdf0e10cSrcweir ::osl::Mutex& _rMutex 85*cdf0e10cSrcweir ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /** disposes the dispatcher instance 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir All status listeners will, after receiving an <member scope="com::sun::star::lang">XEventListener::disposing</member> 90*cdf0e10cSrcweir call, be released. 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir The controller provided in the in constructor will not be used anymore after returning from this call. 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir No further requests to dispatch slots will be accepted. 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir Multiple calls are allowed: if the object already was disposed, then subsequent calls are 97*cdf0e10cSrcweir silently ignored. 98*cdf0e10cSrcweir */ 99*cdf0e10cSrcweir void dispose(); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /** notifies all our listeners of the current state 102*cdf0e10cSrcweir */ 103*cdf0e10cSrcweir void updateAllListeners(); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir protected: 106*cdf0e10cSrcweir // XDispatch 107*cdf0e10cSrcweir virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& _rURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArguments ) throw (::com::sun::star::uno::RuntimeException); 108*cdf0e10cSrcweir virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& _rxControl, const ::com::sun::star::util::URL& _rURL ) throw (::com::sun::star::uno::RuntimeException); 109*cdf0e10cSrcweir virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& _rxControl, const ::com::sun::star::util::URL& _rURL ) throw (::com::sun::star::uno::RuntimeException); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir protected: 112*cdf0e10cSrcweir /** notifies our current state to one or all listeners 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir @param _rxListener 115*cdf0e10cSrcweir the listener to notify. May be NULL, in this case all our listeners will be 116*cdf0e10cSrcweir notified with the current state 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir @param _rFreeForNotification 119*cdf0e10cSrcweir a guard which currently locks our mutex, and which is to be cleared 120*cdf0e10cSrcweir for actually doing the notification(s) 121*cdf0e10cSrcweir */ 122*cdf0e10cSrcweir void notifyStatus( 123*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& _rxListener, 124*cdf0e10cSrcweir ::osl::ClearableMutexGuard& _rFreeForNotification 125*cdf0e10cSrcweir ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir private: 128*cdf0e10cSrcweir /** checks whether our instance is alive 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir If the instance already received a <member>dispose</member> call, then a 131*cdf0e10cSrcweir <type scope="com::sun::star::lang">DisposedException</type> is thrown. 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir @precond 134*cdf0e10cSrcweir our Mutex is locked - else calling the method would not make sense, since 135*cdf0e10cSrcweir it's result could be out-of-date as soon as it's returned to the caller. 136*cdf0e10cSrcweir */ 137*cdf0e10cSrcweir void checkAlive() const SAL_THROW((::com::sun::star::lang::DisposedException)); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir /** retrieves the current status of our feature, in a format which can be used 140*cdf0e10cSrcweir for UNO notifications 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir @precond 143*cdf0e10cSrcweir our mutex is locked 144*cdf0e10cSrcweir */ 145*cdf0e10cSrcweir void getUnoState( ::com::sun::star::frame::FeatureStateEvent& /* [out] */ _rState ) const; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir private: 148*cdf0e10cSrcweir OSingleFeatureDispatcher(); // never implemented 149*cdf0e10cSrcweir OSingleFeatureDispatcher( const OSingleFeatureDispatcher& ); // never implemented 150*cdf0e10cSrcweir OSingleFeatureDispatcher& operator=( const OSingleFeatureDispatcher& ); // never implemented 151*cdf0e10cSrcweir }; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir //........................................................................ 154*cdf0e10cSrcweir } // namespace svx 155*cdf0e10cSrcweir //........................................................................ 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir #endif 158