1*3334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3334a7e6SAndrew Rist * distributed with this work for additional information 6*3334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 9*3334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 10*3334a7e6SAndrew Rist * 11*3334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3334a7e6SAndrew Rist * 13*3334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3334a7e6SAndrew Rist * software distributed under the License is distributed on an 15*3334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 17*3334a7e6SAndrew Rist * specific language governing permissions and limitations 18*3334a7e6SAndrew Rist * under the License. 19*3334a7e6SAndrew Rist * 20*3334a7e6SAndrew Rist *************************************************************/ 21*3334a7e6SAndrew Rist 22*3334a7e6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SVX_FMDISPATCH_HXX 25cdf0e10cSrcweir #define SVX_FMDISPATCH_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 30cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormOperations.hpp> 31cdf0e10cSrcweir /** === end UNO includes === **/ 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 34cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir //........................................................................ 37cdf0e10cSrcweir namespace svx 38cdf0e10cSrcweir { 39cdf0e10cSrcweir //........................................................................ 40cdf0e10cSrcweir 41cdf0e10cSrcweir //==================================================================== 42cdf0e10cSrcweir //= OSingleFeatureDispatcher 43cdf0e10cSrcweir //==================================================================== 44cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < ::com::sun::star::frame::XDispatch 45cdf0e10cSrcweir > OSingleFeatureDispatcher_Base; 46cdf0e10cSrcweir 47cdf0e10cSrcweir class OSingleFeatureDispatcher : public OSingleFeatureDispatcher_Base 48cdf0e10cSrcweir { 49cdf0e10cSrcweir private: 50cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 51cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aStatusListeners; 52cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > 53cdf0e10cSrcweir m_xFormOperations; 54cdf0e10cSrcweir const ::com::sun::star::util::URL m_aFeatureURL; 55cdf0e10cSrcweir ::com::sun::star::uno::Any m_aLastKnownState; 56cdf0e10cSrcweir const sal_Int16 m_nFormFeature; 57cdf0e10cSrcweir sal_Bool m_bLastKnownEnabled; 58cdf0e10cSrcweir sal_Bool m_bDisposed; 59cdf0e10cSrcweir 60cdf0e10cSrcweir public: 61cdf0e10cSrcweir /** constructs the dispatcher 62cdf0e10cSrcweir 63cdf0e10cSrcweir @param _rFeatureURL 64cdf0e10cSrcweir the URL of the feature which this instance is responsible for 65cdf0e10cSrcweir 66cdf0e10cSrcweir @param _nFeatureId 67cdf0e10cSrcweir the feature which this instance is responsible for 68cdf0e10cSrcweir 69cdf0e10cSrcweir @param _rController 70cdf0e10cSrcweir the controller which is responsible for providing the state of feature of this instance, 71cdf0e10cSrcweir and for executing it. After disposing the dispatcher instance, the controller will 72cdf0e10cSrcweir not be accessed anymore 73cdf0e10cSrcweir 74cdf0e10cSrcweir @see dispose 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir OSingleFeatureDispatcher( 77cdf0e10cSrcweir const ::com::sun::star::util::URL& _rFeatureURL, 78cdf0e10cSrcweir const sal_Int16 _nFormFeature, 79cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >& _rxFormOperations, 80cdf0e10cSrcweir ::osl::Mutex& _rMutex 81cdf0e10cSrcweir ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** disposes the dispatcher instance 84cdf0e10cSrcweir 85cdf0e10cSrcweir All status listeners will, after receiving an <member scope="com::sun::star::lang">XEventListener::disposing</member> 86cdf0e10cSrcweir call, be released. 87cdf0e10cSrcweir 88cdf0e10cSrcweir The controller provided in the in constructor will not be used anymore after returning from this call. 89cdf0e10cSrcweir 90cdf0e10cSrcweir No further requests to dispatch slots will be accepted. 91cdf0e10cSrcweir 92cdf0e10cSrcweir Multiple calls are allowed: if the object already was disposed, then subsequent calls are 93cdf0e10cSrcweir silently ignored. 94cdf0e10cSrcweir */ 95cdf0e10cSrcweir void dispose(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** notifies all our listeners of the current state 98cdf0e10cSrcweir */ 99cdf0e10cSrcweir void updateAllListeners(); 100cdf0e10cSrcweir 101cdf0e10cSrcweir protected: 102cdf0e10cSrcweir // XDispatch 103cdf0e10cSrcweir 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); 104cdf0e10cSrcweir 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); 105cdf0e10cSrcweir 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); 106cdf0e10cSrcweir 107cdf0e10cSrcweir protected: 108cdf0e10cSrcweir /** notifies our current state to one or all listeners 109cdf0e10cSrcweir 110cdf0e10cSrcweir @param _rxListener 111cdf0e10cSrcweir the listener to notify. May be NULL, in this case all our listeners will be 112cdf0e10cSrcweir notified with the current state 113cdf0e10cSrcweir 114cdf0e10cSrcweir @param _rFreeForNotification 115cdf0e10cSrcweir a guard which currently locks our mutex, and which is to be cleared 116cdf0e10cSrcweir for actually doing the notification(s) 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir void notifyStatus( 119cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& _rxListener, 120cdf0e10cSrcweir ::osl::ClearableMutexGuard& _rFreeForNotification 121cdf0e10cSrcweir ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir private: 124cdf0e10cSrcweir /** checks whether our instance is alive 125cdf0e10cSrcweir 126cdf0e10cSrcweir If the instance already received a <member>dispose</member> call, then a 127cdf0e10cSrcweir <type scope="com::sun::star::lang">DisposedException</type> is thrown. 128cdf0e10cSrcweir 129cdf0e10cSrcweir @precond 130cdf0e10cSrcweir our Mutex is locked - else calling the method would not make sense, since 131cdf0e10cSrcweir it's result could be out-of-date as soon as it's returned to the caller. 132cdf0e10cSrcweir */ 133cdf0e10cSrcweir void checkAlive() const SAL_THROW((::com::sun::star::lang::DisposedException)); 134cdf0e10cSrcweir 135cdf0e10cSrcweir /** retrieves the current status of our feature, in a format which can be used 136cdf0e10cSrcweir for UNO notifications 137cdf0e10cSrcweir 138cdf0e10cSrcweir @precond 139cdf0e10cSrcweir our mutex is locked 140cdf0e10cSrcweir */ 141cdf0e10cSrcweir void getUnoState( ::com::sun::star::frame::FeatureStateEvent& /* [out] */ _rState ) const; 142cdf0e10cSrcweir 143cdf0e10cSrcweir private: 144cdf0e10cSrcweir OSingleFeatureDispatcher(); // never implemented 145cdf0e10cSrcweir OSingleFeatureDispatcher( const OSingleFeatureDispatcher& ); // never implemented 146cdf0e10cSrcweir OSingleFeatureDispatcher& operator=( const OSingleFeatureDispatcher& ); // never implemented 147cdf0e10cSrcweir }; 148cdf0e10cSrcweir 149cdf0e10cSrcweir //........................................................................ 150cdf0e10cSrcweir } // namespace svx 151cdf0e10cSrcweir //........................................................................ 152cdf0e10cSrcweir 153cdf0e10cSrcweir #endif 154