xref: /AOO41X/main/framework/inc/dispatch/menudispatcher.hxx (revision 5758ad8ce74c9f4c352d679950be760456f756ea)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_
25 #define __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <classes/taskcreator.hxx>
32 #include <services/frame.hxx>
33 #include <macros/generic.hxx>
34 #include <macros/xinterface.hxx>
35 #include <macros/xtypeprovider.hxx>
36 #include <macros/debug.hxx>
37 #include <threadhelp/threadhelpbase.hxx>
38 #include <classes/menumanager.hxx>
39 #include <general.h>
40 #include <stdtypes.h>
41 
42 //_________________________________________________________________________________________________________________
43 //  interface includes
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/lang/XTypeProvider.hpp>
46 #include <com/sun/star/frame/XDispatch.hpp>
47 #include <com/sun/star/util/URL.hpp>
48 #include <com/sun/star/frame/DispatchDescriptor.hpp>
49 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <com/sun/star/frame/XStatusListener.hpp>
51 #include <com/sun/star/frame/XFrameLoader.hpp>
52 #include <com/sun/star/frame/XLoadEventListener.hpp>
53 #include <com/sun/star/frame/XDesktop.hpp>
54 #include <com/sun/star/frame/FeatureStateEvent.hpp>
55 #include <com/sun/star/frame/XFrameActionListener.hpp>
56 
57 //_________________________________________________________________________________________________________________
58 //  other includes
59 //_________________________________________________________________________________________________________________
60 #include <cppuhelper/weak.hxx>
61 #include <cppuhelper/weakref.hxx>
62 #include <cppuhelper/interfacecontainer.h>
63 
64 //_________________________________________________________________________________________________________________
65 //  namespace
66 //_________________________________________________________________________________________________________________
67 
68 namespace framework{
69 
70 
71 //_________________________________________________________________________________________________________________
72 //  exported const
73 //_________________________________________________________________________________________________________________
74 
75 //_________________________________________________________________________________________________________________
76 //  exported definitions
77 //_________________________________________________________________________________________________________________
78 
79 /*-************************************************************************************************************//**
80     We must save informations about our listener and URL for listening.
81     We implement this as a hashtable for strings.
82 *//*-*************************************************************************************************************/
83 
84 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<  ::rtl::OUString         ,
85                                                         rtl::OUStringHash,
86                                                         std::equal_to< ::rtl::OUString > > IMPL_ListenerHashContainer;
87 
88 
89 /*-************************************************************************************************************//**
90     @short          helper for desktop only(!) to create new tasks on demand for dispatches
91     @descr          Use this class as member only! Never use it as baseclass.
92                     XInterface will be ambigous and we hold a weakcss::uno::Reference to ouer OWNER - not to ouer SUPERCLASS!
93 
94     @implements     XInterface
95                     XDispatch
96                     XLoadEventListener
97                     XFrameActionListener
98                     XEventListener
99     @base           ThreadHelpBase
100                     OWeakObject
101 
102     @devstatus      ready to use
103 *//*-*************************************************************************************************************/
104 class MenuDispatcher   :   // interfaces
105                                 public css::lang::XTypeProvider         ,
106                                 public css::frame::XDispatch            ,
107                                 public css::frame::XFrameActionListener ,
108                                 // baseclasses
109                                 // Order is neccessary for right initialization!
110                                 public ThreadHelpBase                       ,
111                                 public cppu::OWeakObject
112 {
113     //-------------------------------------------------------------------------------------------------------------
114     //  public methods
115     //-------------------------------------------------------------------------------------------------------------
116 
117     public:
118 
119         //---------------------------------------------------------------------------------------------------------
120         //  constructor / destructor
121         //---------------------------------------------------------------------------------------------------------
122 
123         /*-****************************************************************************************************//**
124             @short      standard ctor
125             @descr      These initialize a new instance of ths class with needed informations for work.
126 
127             @seealso    using at owner
128 
129             @param      "xFactory"  , css::uno::Reference to servicemanager for creation of new services
130             @param      "xOwner"    , css::uno::Reference to our owner, the Desktop!!!
131             @return     -
132 
133             @onerror    -
134         *//*-*****************************************************************************************************/
135 
136         MenuDispatcher(    const   css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory    ,
137                             const   css::uno::Reference< css::frame::XFrame >&              xOwner      );
138 
139         //---------------------------------------------------------------------------------------------------------
140         //  XInterface
141         //---------------------------------------------------------------------------------------------------------
142 
143         FWK_DECLARE_XINTERFACE
144         FWK_DECLARE_XTYPEPROVIDER
145 
146         //---------------------------------------------------------------------------------------------------------
147         //  XDispatch
148         //---------------------------------------------------------------------------------------------------------
149 
150         /*-****************************************************************************************************//**
151             @short      dispatch URL with arguments
152             @descr      Every dispatch create a new task. If load of URL failed task will deleted automaticly!
153 
154             @seealso    -
155 
156             @param      "aURL"          , URL to dispatch.
157             @param      "seqArguments"  , list of optional arguments.
158             @return     -
159 
160             @onerror    -
161         *//*-*****************************************************************************************************/
162 
163         virtual void SAL_CALL dispatch( const   css::util::URL&                                     aURL            ,
164                                         const   css::uno::Sequence< css::beans::PropertyValue >&    seqProperties   ) throw( css::uno::RuntimeException );
165 
166         /*-****************************************************************************************************//**
167             @short      add listener for state events
168             @descr      You can add a listener to get information about status of dispatch: OK or Failed.
169 
170             @seealso    method loadFinished()
171             @seealso    method loadCancelled()
172 
173             @param      "xControl"  , css::uno::Reference to a valid listener for state events.
174             @param      "aURL"      , URL about listener will be informed, if something occured.
175             @return     -
176 
177             @onerror    -
178         *//*-*****************************************************************************************************/
179 
180         virtual void SAL_CALL addStatusListener(    const   css::uno::Reference< css::frame::XStatusListener >& xControl,
181                                                     const   css::util::URL&                                     aURL    ) throw( css::uno::RuntimeException );
182 
183         /*-****************************************************************************************************//**
184             @short      remove listener for state events
185             @descr      You can remove a listener if information of dispatch isn't important for you any longer.
186 
187             @seealso    method loadFinished()
188             @seealso    method loadCancelled()
189 
190             @param      "xControl"  , css::uno::Reference to a valid listener.
191             @param      "aURL"      , URL on which listener has registered.
192             @return     -
193 
194             @onerror    -
195         *//*-*****************************************************************************************************/
196 
197         virtual void SAL_CALL removeStatusListener( const   css::uno::Reference< css::frame::XStatusListener >& xControl,
198                                                     const   css::util::URL&                                     aURL    ) throw( css::uno::RuntimeException );
199 
200 
201         //---------------------------------------------------------------------------------------------------------
202         //   XFrameActionListener
203         //---------------------------------------------------------------------------------------------------------
204 
205         virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) throw ( css::uno::RuntimeException );
206 
207         //---------------------------------------------------------------------------------------------------------
208         //   XEventListener
209         //---------------------------------------------------------------------------------------------------------
210 
211         /*-****************************************************************************************************//**
212             @short      dispose current instance
213             @descr      If service helper isn't required any longer call this method to release all used ressources.
214 
215             @seealso    -
216 
217             @param      "aEvent", information about source of this event.
218             @return     -
219 
220             @onerror    -
221         *//*-*****************************************************************************************************/
222 
223         void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw( css::uno::RuntimeException );
224 
225     //-------------------------------------------------------------------------------------------------------------
226     //  protected methods
227     //-------------------------------------------------------------------------------------------------------------
228 
229     protected:
230 
231         /*-****************************************************************************************************//**
232             @short      standard destructor
233             @descr      This method destruct an instance of this class and clear some member.
234                         This method is protected, because its not allowed to use an instance of this class as a member!
235                         You MUST use a pointer.
236 
237             @seealso    -
238 
239             @param      -
240             @return     -
241 
242             @onerror    -
243         *//*-*****************************************************************************************************/
244 
245         virtual ~MenuDispatcher();
246 
247     //-------------------------------------------------------------------------------------------------------------
248     //  private methods
249     //-------------------------------------------------------------------------------------------------------------
250 
251     private:
252 
253         DECL_LINK( Close_Impl, void* );
254 
255         /*-****************************************************************************************************//**
256             @short      -
257             @descr      -
258 
259             @seealso    -
260 
261             @param      -
262             @return     -
263 
264             @onerror    -
265         *//*-*****************************************************************************************************/
266 
267         sal_Bool impl_setMenuBar( MenuBar* pMenuBar, sal_Bool bMenuFromResource = sal_False );
268 
269         /*-****************************************************************************************************//**
270             @short      -
271             @descr      -
272 
273             @seealso    -
274 
275             @param      -
276             @return     -
277 
278             @onerror    -
279         *//*-*****************************************************************************************************/
280 
281         void impl_setAccelerators( Menu* pMenu, const Accelerator& aAccel );
282 
283     //-------------------------------------------------------------------------------------------------------------
284     //  debug methods
285     //  (should be private everyway!)
286     //-------------------------------------------------------------------------------------------------------------
287 
288         /*-****************************************************************************************************//**
289             @short      debug-method to check incoming parameter of some other mehods of this class
290             @descr      The following methods are used to check parameters for other methods
291                         of this class. The return value is used directly for an ASSERT(...).
292 
293             @seealso    ASSERTs in implementation!
294 
295             @param      css::uno::References to checking variables
296             @return     sal_False on invalid parameter<BR>
297                         sal_True  otherway
298 
299             @onerror    -
300         *//*-*****************************************************************************************************/
301 
302     #ifdef ENABLE_ASSERTIONS
303 
304     private:
305 
306         static sal_Bool impldbg_checkParameter_MenuDispatcher      (   const   css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory        ,
307                                                                         const   css::uno::Reference< css::frame::XFrame >&              xOwner          );
308         static sal_Bool impldbg_checkParameter_addStatusListener    (   const   css::uno::Reference< css::frame::XStatusListener >&     xControl        ,
309                                                                         const   css::util::URL&                                         aURL            );
310         static sal_Bool impldbg_checkParameter_removeStatusListener (   const   css::uno::Reference< css::frame::XStatusListener >&     xControl        ,
311                                                                         const   css::util::URL&                                         aURL            );
312     #endif  // #ifdef ENABLE_ASSERTIONS
313 
314     //-------------------------------------------------------------------------------------------------------------
315     //  variables
316     //  (should be private everyway!)
317     //-------------------------------------------------------------------------------------------------------------
318 
319     private:
320 
321         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!)
322         css::uno::Reference< css::lang::XMultiServiceFactory >  m_xFactory          ;   /// factory shared with our owner to create new services!
323         IMPL_ListenerHashContainer                              m_aListenerContainer;   /// hash table for listener at specified URLs
324         sal_Bool                                                m_bAlreadyDisposed  ;   /// Protection against multiple disposing calls.
325         sal_Bool                                                m_bActivateListener ;   /// dispatcher is listener for frame activation
326         MenuManager*                                            m_pMenuManager      ;   /// menu manager controlling menu dispatches
327 
328 };      //  class MenuDispatcher
329 
330 }       //  namespace framework
331 
332 #endif  //  #ifndef __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_
333