update dev300-m58
[ooovba.git] / svx / source / inc / fmdispatch.hxx
blob760ae305731d640a84e866ae7a783f4a35288456
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmdispatch.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SVX_FMDISPATCH_HXX
32 #define SVX_FMDISPATCH_HXX
34 #include <cppuhelper/implbase1.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 #include <com/sun/star/frame/XDispatch.hpp>
37 #include <com/sun/star/lang/DisposedException.hpp>
40 //........................................................................
41 namespace svx
43 //........................................................................
45 class FormControllerHelper;
47 //====================================================================
48 //= OSingleFeatureDispatcher
49 //====================================================================
50 typedef ::cppu::WeakImplHelper1 < ::com::sun::star::frame::XDispatch
51 > OSingleFeatureDispatcher_Base;
53 class OSingleFeatureDispatcher : public OSingleFeatureDispatcher_Base
55 private:
56 ::osl::Mutex& m_rMutex;
57 ::cppu::OInterfaceContainerHelper m_aStatusListeners;
58 const FormControllerHelper& m_rController;
59 const ::com::sun::star::util::URL m_aFeatureURL;
60 ::com::sun::star::uno::Any m_aLastKnownState;
61 const sal_Int32 m_nFeatureId;
62 sal_Bool m_bLastKnownEnabled;
63 sal_Bool m_bDisposed;
65 public:
66 /** constructs the dispatcher
68 @param _rFeatureURL
69 the URL of the feature which this instance is responsible for
71 @param _nFeatureId
72 the feature which this instance is responsible for
74 @param _rController
75 the controller which is responsible for providing the state of feature of this instance,
76 and for executing it. After disposing the dispatcher instance, the controller will
77 not be accessed anymore
79 @see dispose
81 OSingleFeatureDispatcher(
82 const ::com::sun::star::util::URL& _rFeatureURL,
83 sal_Int32 _nFeatureId,
84 const FormControllerHelper& _rController,
85 ::osl::Mutex& _rMutex
88 /** disposes the dispatcher instance
90 All status listeners will, after receiving an <member scope="com::sun::star::lang">XEventListener::disposing</member>
91 call, be released.
93 The controller provided in the in constructor will not be used anymore after returning from this call.
95 No further requests to dispatch slots will be accepted.
97 Multiple calls are allowed: if the object already was disposed, then subsequent calls are
98 silently ignored.
100 void dispose();
102 /** notifies all our listeners of the current state
104 void updateAllListeners();
106 protected:
107 // XDispatch
108 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);
109 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);
110 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);
112 protected:
113 /** notifies our current state to one or all listeners
115 @param _rxListener
116 the listener to notify. May be NULL, in this case all our listeners will be
117 notified with the current state
119 @param _rFreeForNotification
120 a guard which currently locks our mutex, and which is to be cleared
121 for actually doing the notification(s)
123 void notifyStatus(
124 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& _rxListener,
125 ::osl::ClearableMutexGuard& _rFreeForNotification
128 private:
129 /** checks whether our instance is alive
131 If the instance already received a <member>dispose</member> call, then a
132 <type scope="com::sun::star::lang">DisposedException</type> is thrown.
134 @precond
135 our Mutex is locked - else calling the method would not make sense, since
136 it's result could be out-of-date as soon as it's returned to the caller.
138 void checkAlive() const SAL_THROW((::com::sun::star::lang::DisposedException));
140 /** retrieves the current status of our feature, in a format which can be used
141 for UNO notifications
143 @precond
144 our mutex is locked
146 void getUnoState( ::com::sun::star::frame::FeatureStateEvent& /* [out] */ _rState ) const;
148 private:
149 OSingleFeatureDispatcher(); // never implemented
150 OSingleFeatureDispatcher( const OSingleFeatureDispatcher& ); // never implemented
151 OSingleFeatureDispatcher& operator=( const OSingleFeatureDispatcher& ); // never implemented
154 //........................................................................
155 } // namespace svx
156 //........................................................................
158 #endif