1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 //_________________________________________________________________________________________________________________
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>
49 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
66 //_________________________________________________________________________________________________________________
67 #include <cppuhelper/weak.hxx>
68 #include <cppuhelper/weakref.hxx>
69 #include <cppuhelper/interfacecontainer.h>
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
78 //_________________________________________________________________________________________________________________
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
,
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
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
,
116 // Order is neccessary for right initialization!
117 public ThreadHelpBase
,
118 public cppu::OWeakObject
120 //-------------------------------------------------------------------------------------------------------------
122 //-------------------------------------------------------------------------------------------------------------
126 //---------------------------------------------------------------------------------------------------------
127 // constructor / destructor
128 //---------------------------------------------------------------------------------------------------------
130 /*-****************************************************************************************************//**
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!!!
141 *//*-*****************************************************************************************************/
143 MenuDispatcher( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
,
144 const css::uno::Reference
< css::frame::XFrame
>& xOwner
);
146 //---------------------------------------------------------------------------------------------------------
148 //---------------------------------------------------------------------------------------------------------
150 FWK_DECLARE_XINTERFACE
151 FWK_DECLARE_XTYPEPROVIDER
153 //---------------------------------------------------------------------------------------------------------
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!
163 @param "aURL" , URL to dispatch.
164 @param "seqArguments" , list of optional arguments.
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.
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.
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 //---------------------------------------------------------------------------------------------------------
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.
224 @param "aEvent", information about source of this event.
228 *//*-*****************************************************************************************************/
230 void SAL_CALL
disposing( const EVENTOBJECT
& aEvent
) throw( css::uno::RuntimeException
);
232 //-------------------------------------------------------------------------------------------------------------
234 //-------------------------------------------------------------------------------------------------------------
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.
250 *//*-*****************************************************************************************************/
252 virtual ~MenuDispatcher();
254 //-------------------------------------------------------------------------------------------------------------
256 //-------------------------------------------------------------------------------------------------------------
260 DECL_LINK( Close_Impl
, void* );
262 /*-****************************************************************************************************//**
272 *//*-*****************************************************************************************************/
274 sal_Bool
impl_setMenuBar( MenuBar
* pMenuBar
, sal_Bool bMenuFromResource
= sal_False
);
276 /*-****************************************************************************************************//**
286 *//*-*****************************************************************************************************/
288 void impl_setAccelerators( Menu
* pMenu
, const Accelerator
& aAccel
);
290 //-------------------------------------------------------------------------------------------------------------
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>
307 *//*-*****************************************************************************************************/
309 #ifdef ENABLE_ASSERTIONS
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 //-------------------------------------------------------------------------------------------------------------
323 // (should be private everyway!)
324 //-------------------------------------------------------------------------------------------------------------
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_