merge the formfield patch from ooo-build
[ooovba.git] / framework / inc / dispatch / menudispatcher.hxx
blob485d436ffe0f8eea15d837fd5b69bf4ae8d0701b
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: menudispatcher.hxx,v $
10 * $Revision: 1.7.82.1 $
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 __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_
32 #define __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <classes/taskcreator.hxx>
39 #include <services/frame.hxx>
40 #include <macros/generic.hxx>
41 #include <macros/xinterface.hxx>
42 #include <macros/xtypeprovider.hxx>
43 #include <macros/debug.hxx>
44 #include <threadhelp/threadhelpbase.hxx>
45 #include <classes/menumanager.hxx>
46 #include <general.h>
47 #include <stdtypes.h>
49 //_________________________________________________________________________________________________________________
50 // interface includes
51 //_________________________________________________________________________________________________________________
52 #include <com/sun/star/lang/XTypeProvider.hpp>
53 #include <com/sun/star/frame/XDispatch.hpp>
54 #include <com/sun/star/util/URL.hpp>
55 #include <com/sun/star/frame/DispatchDescriptor.hpp>
56 #include <com/sun/star/beans/PropertyValue.hpp>
57 #include <com/sun/star/frame/XStatusListener.hpp>
58 #include <com/sun/star/frame/XFrameLoader.hpp>
59 #include <com/sun/star/frame/XLoadEventListener.hpp>
60 #include <com/sun/star/frame/XDesktop.hpp>
61 #include <com/sun/star/frame/FeatureStateEvent.hpp>
62 #include <com/sun/star/frame/XFrameActionListener.hpp>
64 //_________________________________________________________________________________________________________________
65 // other includes
66 //_________________________________________________________________________________________________________________
67 #include <cppuhelper/weak.hxx>
68 #include <cppuhelper/weakref.hxx>
69 #include <cppuhelper/interfacecontainer.h>
71 //_________________________________________________________________________________________________________________
72 // namespace
73 //_________________________________________________________________________________________________________________
75 namespace framework{
78 //_________________________________________________________________________________________________________________
79 // exported const
80 //_________________________________________________________________________________________________________________
82 //_________________________________________________________________________________________________________________
83 // exported definitions
84 //_________________________________________________________________________________________________________________
86 /*-************************************************************************************************************//**
87 We must save informations about our listener and URL for listening.
88 We implement this as a hashtable for strings.
89 *//*-*************************************************************************************************************/
91 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString ,
92 OUStringHashCode ,
93 std::equal_to< ::rtl::OUString > > IMPL_ListenerHashContainer;
96 /*-************************************************************************************************************//**
97 @short helper for desktop only(!) to create new tasks on demand for dispatches
98 @descr Use this class as member only! Never use it as baseclass.
99 XInterface will be ambigous and we hold a weakcss::uno::Reference to ouer OWNER - not to ouer SUPERCLASS!
101 @implements XInterface
102 XDispatch
103 XLoadEventListener
104 XFrameActionListener
105 XEventListener
106 @base ThreadHelpBase
107 OWeakObject
109 @devstatus ready to use
110 *//*-*************************************************************************************************************/
111 class MenuDispatcher : // interfaces
112 public css::lang::XTypeProvider ,
113 public css::frame::XDispatch ,
114 public css::frame::XFrameActionListener ,
115 // baseclasses
116 // Order is neccessary for right initialization!
117 public ThreadHelpBase ,
118 public cppu::OWeakObject
120 //-------------------------------------------------------------------------------------------------------------
121 // public methods
122 //-------------------------------------------------------------------------------------------------------------
124 public:
126 //---------------------------------------------------------------------------------------------------------
127 // constructor / destructor
128 //---------------------------------------------------------------------------------------------------------
130 /*-****************************************************************************************************//**
131 @short standard ctor
132 @descr These initialize a new instance of ths class with needed informations for work.
134 @seealso using at owner
136 @param "xFactory" , css::uno::Reference to servicemanager for creation of new services
137 @param "xOwner" , css::uno::Reference to our owner, the Desktop!!!
138 @return -
140 @onerror -
141 *//*-*****************************************************************************************************/
143 MenuDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ,
144 const css::uno::Reference< css::frame::XFrame >& xOwner );
146 //---------------------------------------------------------------------------------------------------------
147 // XInterface
148 //---------------------------------------------------------------------------------------------------------
150 FWK_DECLARE_XINTERFACE
151 FWK_DECLARE_XTYPEPROVIDER
153 //---------------------------------------------------------------------------------------------------------
154 // XDispatch
155 //---------------------------------------------------------------------------------------------------------
157 /*-****************************************************************************************************//**
158 @short dispatch URL with arguments
159 @descr Every dispatch create a new task. If load of URL failed task will deleted automaticly!
161 @seealso -
163 @param "aURL" , URL to dispatch.
164 @param "seqArguments" , list of optional arguments.
165 @return -
167 @onerror -
168 *//*-*****************************************************************************************************/
170 virtual void SAL_CALL dispatch( const css::util::URL& aURL ,
171 const css::uno::Sequence< css::beans::PropertyValue >& seqProperties ) throw( css::uno::RuntimeException );
173 /*-****************************************************************************************************//**
174 @short add listener for state events
175 @descr You can add a listener to get information about status of dispatch: OK or Failed.
177 @seealso method loadFinished()
178 @seealso method loadCancelled()
180 @param "xControl" , css::uno::Reference to a valid listener for state events.
181 @param "aURL" , URL about listener will be informed, if something occured.
182 @return -
184 @onerror -
185 *//*-*****************************************************************************************************/
187 virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl,
188 const css::util::URL& aURL ) throw( css::uno::RuntimeException );
190 /*-****************************************************************************************************//**
191 @short remove listener for state events
192 @descr You can remove a listener if information of dispatch isn't important for you any longer.
194 @seealso method loadFinished()
195 @seealso method loadCancelled()
197 @param "xControl" , css::uno::Reference to a valid listener.
198 @param "aURL" , URL on which listener has registered.
199 @return -
201 @onerror -
202 *//*-*****************************************************************************************************/
204 virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl,
205 const css::util::URL& aURL ) throw( css::uno::RuntimeException );
208 //---------------------------------------------------------------------------------------------------------
209 // XFrameActionListener
210 //---------------------------------------------------------------------------------------------------------
212 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) throw ( css::uno::RuntimeException );
214 //---------------------------------------------------------------------------------------------------------
215 // XEventListener
216 //---------------------------------------------------------------------------------------------------------
218 /*-****************************************************************************************************//**
219 @short dispose current instance
220 @descr If service helper isn't required any longer call this method to release all used ressources.
222 @seealso -
224 @param "aEvent", information about source of this event.
225 @return -
227 @onerror -
228 *//*-*****************************************************************************************************/
230 void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw( css::uno::RuntimeException );
232 //-------------------------------------------------------------------------------------------------------------
233 // protected methods
234 //-------------------------------------------------------------------------------------------------------------
236 protected:
238 /*-****************************************************************************************************//**
239 @short standard destructor
240 @descr This method destruct an instance of this class and clear some member.
241 This method is protected, because its not allowed to use an instance of this class as a member!
242 You MUST use a pointer.
244 @seealso -
246 @param -
247 @return -
249 @onerror -
250 *//*-*****************************************************************************************************/
252 virtual ~MenuDispatcher();
254 //-------------------------------------------------------------------------------------------------------------
255 // private methods
256 //-------------------------------------------------------------------------------------------------------------
258 private:
260 DECL_LINK( Close_Impl, void* );
262 /*-****************************************************************************************************//**
263 @short -
264 @descr -
266 @seealso -
268 @param -
269 @return -
271 @onerror -
272 *//*-*****************************************************************************************************/
274 sal_Bool impl_setMenuBar( MenuBar* pMenuBar, sal_Bool bMenuFromResource = sal_False );
276 /*-****************************************************************************************************//**
277 @short -
278 @descr -
280 @seealso -
282 @param -
283 @return -
285 @onerror -
286 *//*-*****************************************************************************************************/
288 void impl_setAccelerators( Menu* pMenu, const Accelerator& aAccel );
290 //-------------------------------------------------------------------------------------------------------------
291 // debug methods
292 // (should be private everyway!)
293 //-------------------------------------------------------------------------------------------------------------
295 /*-****************************************************************************************************//**
296 @short debug-method to check incoming parameter of some other mehods of this class
297 @descr The following methods are used to check parameters for other methods
298 of this class. The return value is used directly for an ASSERT(...).
300 @seealso ASSERTs in implementation!
302 @param css::uno::References to checking variables
303 @return sal_False on invalid parameter<BR>
304 sal_True otherway
306 @onerror -
307 *//*-*****************************************************************************************************/
309 #ifdef ENABLE_ASSERTIONS
311 private:
313 static sal_Bool impldbg_checkParameter_MenuDispatcher ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ,
314 const css::uno::Reference< css::frame::XFrame >& xOwner );
315 static sal_Bool impldbg_checkParameter_addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& xControl ,
316 const css::util::URL& aURL );
317 static sal_Bool impldbg_checkParameter_removeStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& xControl ,
318 const css::util::URL& aURL );
319 #endif // #ifdef ENABLE_ASSERTIONS
321 //-------------------------------------------------------------------------------------------------------------
322 // variables
323 // (should be private everyway!)
324 //-------------------------------------------------------------------------------------------------------------
326 private:
328 css::uno::WeakReference< css::frame::XFrame > m_xOwnerWeak ; /// css::uno::WeakReference to owner (Don't use a hard css::uno::Reference. Owner can't delete us then!)
329 css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory ; /// factory shared with our owner to create new services!
330 IMPL_ListenerHashContainer m_aListenerContainer; /// hash table for listener at specified URLs
331 sal_Bool m_bAlreadyDisposed ; /// Protection against multiple disposing calls.
332 sal_Bool m_bActivateListener ; /// dispatcher is listener for frame activation
333 MenuManager* m_pMenuManager ; /// menu manager controlling menu dispatches
335 }; // class MenuDispatcher
337 } // namespace framework
339 #endif // #ifndef __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_