xref: /trunk/main/framework/inc/services/desktop.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_SERVICES_DESKTOP_HXX_
25 #define __FRAMEWORK_SERVICES_DESKTOP_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <classes/framecontainer.hxx>
32 #include <threadhelp/threadhelpbase.hxx>
33 #include <helper/oframes.hxx>
34 #include <macros/generic.hxx>
35 #include <macros/debug.hxx>
36 #include <macros/xinterface.hxx>
37 #include <macros/xtypeprovider.hxx>
38 #include <macros/xserviceinfo.hxx>
39 
40 //_________________________________________________________________________________________________________________
41 //  interface includes
42 //_________________________________________________________________________________________________________________
43 
44 #include <com/sun/star/frame/XUntitledNumbers.hpp>
45 
46 #include <com/sun/star/frame/XController.hpp>
47 #include <com/sun/star/frame/XDesktop.hpp>
48 #include <com/sun/star/frame/WindowArrange.hpp>
49 #include <com/sun/star/frame/TerminationVetoException.hpp>
50 #include <com/sun/star/frame/XTerminateListener.hpp>
51 #include <com/sun/star/frame/XWindowArranger.hpp>
52 #include <com/sun/star/frame/XTask.hpp>
53 #include <com/sun/star/frame/XStorable.hpp>
54 #include <com/sun/star/frame/XModel.hpp>
55 #include <com/sun/star/frame/XFramesSupplier.hpp>
56 #include <com/sun/star/frame/XFrames.hpp>
57 #include <com/sun/star/lang/XServiceName.hpp>
58 #include <com/sun/star/frame/XDispatchProvider.hpp>
59 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
60 #include <com/sun/star/frame/XComponentLoader.hpp>
61 #include <com/sun/star/frame/FrameAction.hpp>
62 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
63 #include <com/sun/star/frame/XTasksSupplier.hpp>
64 #include <com/sun/star/container/XEnumerationAccess.hpp>
65 #include <com/sun/star/lang/Locale.hpp>
66 #include <com/sun/star/frame/XDispatchResultListener.hpp>
67 #include <com/sun/star/lang/XEventListener.hpp>
68 #include <com/sun/star/frame/FeatureStateEvent.hpp>
69 #include <com/sun/star/task/XInteractionHandler.hpp>
70 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
71 
72 //_________________________________________________________________________________________________________________
73 //  other includes
74 //_________________________________________________________________________________________________________________
75 #include <unotools/cmdoptions.hxx>
76 #include <cppuhelper/propshlp.hxx>
77 #include <cppuhelper/interfacecontainer.hxx>
78 #include <cppuhelper/weak.hxx>
79 
80 #include <comphelper/numberedcollection.hxx>
81 
82 //_________________________________________________________________________________________________________________
83 //  namespace
84 //_________________________________________________________________________________________________________________
85 
86 namespace framework{
87 
88 //_________________________________________________________________________________________________________________
89 //  exported const
90 //_________________________________________________________________________________________________________________
91 
92 //_________________________________________________________________________________________________________________
93 //  exported definitions
94 //_________________________________________________________________________________________________________________
95 
96 enum ELoadState
97 {
98     E_NOTSET      ,
99     E_SUCCESSFUL  ,
100     E_FAILED      ,
101     E_INTERACTION
102 };
103 
104 /*-************************************************************************************************************//**
105     @short      implement the topframe of frame tree
106     @descr      This is the root of the frame tree. The desktop has no window, is not visible but he is the logical
107                 "masternode" to build the hierarchy.
108 
109     @implements XInterface
110                 XTypeProvider
111                 XServiceInfo
112                 XDesktop
113                 XComponentLoader
114                 XTasksSupplier
115                 XDispatchProvider
116                 XFramesSupplier
117                 XFrame
118                 XComponent
119                 XPropertySet
120                 XFastPropertySet
121                 XMultiPropertySet
122                 XDispatchResultListener
123                 XEventListener
124                 XInteractionHandler
125 
126     @base       ThreadHelpBase
127                 TransactionBase
128                 OBroadcastHelper
129                 OPropertySetHelper
130 
131     @devstatus  ready to use
132     @threadsafe yes
133 *//*-*************************************************************************************************************/
134 class Desktop   :   // interfaces
135                     public  css::lang::XTypeProvider             ,
136                     public  css::lang::XServiceInfo              ,
137                     public  css::frame::XDesktop                 ,
138                     public  css::frame::XComponentLoader         ,
139                     public  css::frame::XTasksSupplier           ,
140                     public  css::frame::XDispatchProvider        ,
141                     public  css::frame::XDispatchProviderInterception,
142                     public  css::frame::XFramesSupplier          ,   // => XFrame => XComponent
143                     public  css::frame::XDispatchResultListener  ,   // => XEventListener
144                     public  css::task::XInteractionHandler       ,
145                     public  css::frame::XUntitledNumbers         ,
146                     // base classes
147                     // Order is necessary for right initialization!
148                     private ThreadHelpBase                       ,
149                     private TransactionBase                      ,
150                     public  ::cppu::OBroadcastHelper             ,
151                     public  ::cppu::OPropertySetHelper           ,
152                     public  ::cppu::OWeakObject
153 {
154     // internal used types, const etcpp.
155     private:
156 
157         //---------------------------------------------------------------------
158         /** used temporary to know which listener was already called or not. */
159         typedef ::std::vector< css::uno::Reference< css::frame::XTerminateListener > > TTerminateListenerList;
160 
161     // public methods
162     public:
163 
164         //  constructor / destructor
165                  Desktop( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
166         virtual ~Desktop(                                                                        );
167 
168         //  XInterface, XTypeProvider, XServiceInfo
169         FWK_DECLARE_XINTERFACE
170         FWK_DECLARE_XTYPEPROVIDER
171         DECLARE_XSERVICEINFO
172 
173         //---------------------------------------------------------------------
174         /**
175             @interface  XDesktop
176 
177             @short      try to shutdown these desktop environment.
178 
179             @descr      Will try to close all frames. If at least one frame could
180                         not be closed successfully termination will be stopped.
181 
182                         Registered termination listener will be taken into account
183                         also. As special feature some of our registered listener
184                         are well known by its UNO implementation name. They are handled
185                         different to all other listener.
186 
187                         Btw: Desktop.terminate() was designed in the past to be used
188                         within an UI based envrionment. So it's allowed e.g. to
189                         call XController.suspend() here. If UI isn't an option ... please
190                         use XCloseable.close() at these desktop implementation.
191                         ... if it will be supported in the future .-))
192 
193             @seealso    XTerminateListener
194             @seealso    XTerminateListener2
195 
196             @return     true if all open frames could be closed and no listener throwed
197                         a veto exception; false otherwise.
198 
199             @onerror    False will be returned.
200             @threadsafe yes
201          */
202         virtual ::sal_Bool SAL_CALL terminate();
203 
204         //---------------------------------------------------------------------
205         /**
206             @interface  XDesktop
207 
208             @short      add a listener for termination events
209 
210             @descr      Additional to adding normal listener these method was implemented special.
211                         Every listener will be asked for it's uno implementation name.
212                         Some of them are well known ... and the corresponding listener won't be added
213                         to the container of "normal listener". Those listener will be set as special
214                         member.
215                         see e.g. member m_xSfxTerminator
216 
217             @seealso    terminate()
218 
219             @param      xListener
220                         the listener for registration.
221 
222             @threadsafe yes
223          */
224         virtual void SAL_CALL addTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener );
225 
226         //---------------------------------------------------------------------
227         /**
228             @interface  XDesktop
229 
230             @short      remove a listener from this container.
231 
232             @descr      Additional to removing normal listener these method was implemented special.
233                         Every listener will be asked for its uno implementation name.
234                         Some of them are well known ... and the corresponding listener was set as special member.
235                         Now those special member will be reseted also.
236                         see e.g. member m_xSfxTerminator
237 
238             @seealso    terminate()
239 
240             @param      xListener
241                         the listener for deregistration.
242 
243             @threadsafe yes
244          */
245         virtual void SAL_CALL removeTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener );
246 
247         virtual css::uno::Reference< css::container::XEnumerationAccess >           SAL_CALL getComponents              (                                                                                 );
248         virtual css::uno::Reference< css::lang::XComponent >                        SAL_CALL getCurrentComponent        (                                                                                 );
249         virtual css::uno::Reference< css::frame::XFrame >                           SAL_CALL getCurrentFrame            (                                                                                 );
250 
251         //  XComponentLoader
252         virtual css::uno::Reference< css::lang::XComponent >                        SAL_CALL loadComponentFromURL       ( const ::rtl::OUString&                                         sURL             ,
253                                                                                                                           const ::rtl::OUString&                                         sTargetFrameName ,
254                                                                                                                                 sal_Int32                                                nSearchFlags     ,
255                                                                                                                           const css::uno::Sequence< css::beans::PropertyValue >&         lArguments       );
256 
257         //  XTasksSupplier
258         virtual css::uno::Reference< css::container::XEnumerationAccess >           SAL_CALL getTasks                   (                                                                                 );
259         virtual css::uno::Reference< css::frame::XTask >                            SAL_CALL getActiveTask              (                                                                                 );
260 
261         //  XDispatchProvider
262         virtual css::uno::Reference< css::frame::XDispatch >                        SAL_CALL queryDispatch              ( const css::util::URL&                                          aURL             ,
263                                                                                                                           const ::rtl::OUString&                                         sTargetFrameName ,
264                                                                                                                                 sal_Int32                                                nSearchFlags     );
265         virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > >  SAL_CALL queryDispatches            ( const css::uno::Sequence< css::frame::DispatchDescriptor >&    lQueries         );
266 
267         // XDispatchProviderInterception
268         virtual void                                                                SAL_CALL registerDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor);
269         virtual void                                                                SAL_CALL releaseDispatchProviderInterceptor ( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor);
270 
271         //  XFramesSupplier
272         virtual css::uno::Reference< css::frame::XFrames >                          SAL_CALL getFrames                  (                                                                                 );
273         virtual css::uno::Reference< css::frame::XFrame >                           SAL_CALL getActiveFrame             (                                                                                 );
274         virtual void                                                                SAL_CALL setActiveFrame             ( const css::uno::Reference< css::frame::XFrame >&               xFrame           );
275 
276         //   XFrame
277         //  Attention: findFrame() is implemented only! Other methods make no sense for our desktop!
278         virtual css::uno::Reference< css::frame::XFrame >                           SAL_CALL findFrame                  ( const ::rtl::OUString&                                         sTargetFrameName ,
279                                                                                                                                 sal_Int32                                                nSearchFlags     );
280         virtual void                                                                SAL_CALL initialize                 ( const css::uno::Reference< css::awt::XWindow >&                xWindow          );
281         virtual css::uno::Reference< css::awt::XWindow >                            SAL_CALL getContainerWindow         (                                                                                 );
282         virtual void                                                                SAL_CALL setCreator                 ( const css::uno::Reference< css::frame::XFramesSupplier >&      xCreator         );
283         virtual css::uno::Reference< css::frame::XFramesSupplier >                  SAL_CALL getCreator                 (                                                                                 );
284         virtual ::rtl::OUString                                                     SAL_CALL getName                    (                                                                                 );
285         virtual void                                                                SAL_CALL setName                    ( const ::rtl::OUString&                                         sName            );
286         virtual sal_Bool                                                            SAL_CALL isTop                      (                                                                                 );
287         virtual void                                                                SAL_CALL activate                   (                                                                                 );
288         virtual void                                                                SAL_CALL deactivate                 (                                                                                 );
289         virtual sal_Bool                                                            SAL_CALL isActive                   (                                                                                 );
290         virtual sal_Bool                                                            SAL_CALL setComponent               ( const css::uno::Reference< css::awt::XWindow >&                xComponentWindow ,
291                                                                                                                           const css::uno::Reference< css::frame::XController >&          xController      );
292         virtual css::uno::Reference< css::awt::XWindow >                            SAL_CALL getComponentWindow         (                                                                                 );
293         virtual css::uno::Reference< css::frame::XController >                      SAL_CALL getController              (                                                                                 );
294         virtual void                                                                SAL_CALL contextChanged             (                                                                                 );
295         virtual void                                                                SAL_CALL addFrameActionListener     ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener        );
296         virtual void                                                                SAL_CALL removeFrameActionListener  ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener        );
297 
298         //   XComponent
299         using cppu::OPropertySetHelper::disposing;
300         virtual void                                                                SAL_CALL dispose                    (                                                                                 );
301         virtual void                                                                SAL_CALL addEventListener           ( const css::uno::Reference< css::lang::XEventListener >&        xListener        );
302         virtual void                                                                SAL_CALL removeEventListener        ( const css::uno::Reference< css::lang::XEventListener >&        xListener        );
303 
304         //   XDispatchResultListener
305         virtual void SAL_CALL dispatchFinished      ( const css::frame::DispatchResultEvent&                    aEvent     );
306 
307         //   XEventListener
308         virtual void                                                                SAL_CALL disposing                  ( const css::lang::EventObject&                                  aSource          );
309 
310         //   XInteractionHandler
311         virtual void                                                                SAL_CALL handle                     ( const css::uno::Reference< css::task::XInteractionRequest >&   xRequest         );
312 
313         // css.frame.XUntitledNumbers
314         virtual ::sal_Int32 SAL_CALL leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent );
315 
316         // css.frame.XUntitledNumbers
317         virtual void SAL_CALL releaseNumber( ::sal_Int32 nNumber );
318 
319         // css.frame.XUntitledNumbers
320         virtual void SAL_CALL releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent );
321 
322         // css.frame.XUntitledNumbers
323         virtual ::rtl::OUString SAL_CALL getUntitledPrefix();
324 
325     //-------------------------------------------------------------------------------------------------------------
326     //  protected methods
327     //-------------------------------------------------------------------------------------------------------------
328     protected:
329 
330         //  OPropertySetHelper
331         virtual sal_Bool                                            SAL_CALL convertFastPropertyValue        (       css::uno::Any&  aConvertedValue ,
332                                                                                                                      css::uno::Any&  aOldValue       ,
333                                                                                                                      sal_Int32       nHandle         ,
334                                                                                                                const css::uno::Any&  aValue          );
335         virtual void                                                SAL_CALL setFastPropertyValue_NoBroadcast(       sal_Int32       nHandle         ,
336                                                                                                                const css::uno::Any&  aValue          );
337         using cppu::OPropertySetHelper::getFastPropertyValue;
338         virtual void                                                SAL_CALL getFastPropertyValue            (       css::uno::Any&  aValue          ,
339                                                                                                                      sal_Int32       nHandle         ) const;
340         virtual ::cppu::IPropertyArrayHelper&                       SAL_CALL getInfoHelper                   (                                       );
341         virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo              (                                       );
342 
343     //-------------------------------------------------------------------------------------------------------------
344     //  private methods
345     //-------------------------------------------------------------------------------------------------------------
346     private:
347 
348         css::uno::Reference< css::lang::XComponent >            impl_getFrameComponent          ( const css::uno::Reference< css::frame::XFrame >&  xFrame          ) const;
349         static const css::uno::Sequence< css::beans::Property > impl_getStaticPropertyDescriptor(                                                                   );
350 
351         //---------------------------------------------------------------------
352         /** calls queryTermination() on every registered termination listener.
353          *
354          *  Note: Only normal termination listener (registered in list m_aListenerContainer
355          *        will be recognized here. Special listeners like quick starter, pipe or others
356          *        have to be handled explicitly !
357          *
358          *  @param  [out] lCalledListener
359          *          every called listener will be returned here.
360          *          Those list will be used to informa all called listener
361          *          about cancel this termination request.
362          *
363          *  @param  [out] bVeto
364          *          will be true if at least one listener throwed a veto exception;
365          *          false otherwise.
366          *
367          *  @see    impl_sendCancelTerminationEvent()
368          */
369         void impl_sendQueryTerminationEvent(TTerminateListenerList& lCalledListener,
370                                             ::sal_Bool&             bVeto          );
371 
372         //---------------------------------------------------------------------
373         /** calls cancelTermination() on every termination listener
374          *  where queryTermination() was called before.
375          *
376          *  Note: Only normal termination listener (registered in list m_aListenerContainer
377          *        will be recognized here. Special listener like quick starter, pipe or others
378          *        has to be handled explicitly !
379          *
380          *  @param  [in] lCalledListener
381          *          every listener in this list was called within its method
382          *          queryTermination() before.
383          *
384          *  @see    impl_sendQueryTerminationEvent()
385          */
386         void impl_sendCancelTerminationEvent(const TTerminateListenerList& lCalledListener);
387 
388         //---------------------------------------------------------------------
389         /** calls notifyTermination() on every registered termination listener.
390          *
391          *  Note: Only normal termination listener (registered in list m_aListenerContainer
392          *        will be recognized here. Special listener like quick starter, pipe or others
393          *        has to be handled explicitly !
394          */
395         void impl_sendNotifyTerminationEvent();
396 
397         //---------------------------------------------------------------------
398         /** try to close all open frames.
399          *
400          *  Iterates over all child frames and try to close them.
401          *  Given parameter bAllowUI enable/disable showing any UI
402          *  (which mostly occur on calling XController->suspend()).
403          *
404          *  These method doesn't stop if one frame could not be closed.
405          *  It will ignore such frames and try all other ones.
406          *  But it returns false in such case - true otherwise.
407          *
408          *  @param  bAllowUI
409          *          enable/disable showing of UI.
410          *
411          *  @return true if all frames could be closed; false otherwise.
412          */
413         ::sal_Bool impl_closeFrames(::sal_Bool bAllowUI);
414 
415     //-------------------------------------------------------------------------------------------------------------
416     //  debug methods
417     //  (should be private every time!)
418     //-------------------------------------------------------------------------------------------------------------
419     #ifdef ENABLE_ASSERTIONS
420     private:
421 
422         static sal_Bool implcp_ctor                     ( const css::uno::Reference< css::lang::XMultiServiceFactory >&     xFactory         );
423         static sal_Bool implcp_addEventListener         ( const css::uno::Reference< css::lang::XEventListener >&           xListener        );
424         static sal_Bool implcp_removeEventListener      ( const css::uno::Reference< css::lang::XEventListener >&           xListener        );
425 
426         sal_Bool m_bIsTerminated ;  /// check flag to protect us against dispose before terminate!
427                                     /// see dispose() for further informations!
428 
429     #endif  // #ifdef ENABLE_ASSERTIONS
430 
431     //-------------------------------------------------------------------------------------------------------------
432     //  variables
433     //  (should be private every time!)
434     //-------------------------------------------------------------------------------------------------------------
435     private:
436 
437         css::uno::Reference< css::lang::XMultiServiceFactory >          m_xFactory                  ;   /// reference to factory, which has create this instance
438         FrameContainer                                                  m_aChildTaskContainer       ;   /// array of child tasks (childs of desktop are tasks; and tasks are also frames - But pure frames are not accepted!)
439         ::cppu::OMultiTypeInterfaceContainerHelper                      m_aListenerContainer        ;   /// container for ALL Listener
440         css::uno::Reference< css::frame::XFrames >                      m_xFramesHelper             ;   /// helper for XFrames, XIndexAccess, XElementAccess and implementation of a childcontainer!
441         css::uno::Reference< css::frame::XDispatchProvider >            m_xDispatchHelper           ;   /// helper to dispatch something for new tasks, created by "_blank"!
442         ELoadState                                                      m_eLoadState                ;   /// hold information about state of asynchron loading of component for loadComponentFromURL()!
443         css::uno::Reference< css::frame::XFrame >                       m_xLastFrame                ;   /// last target of "loadComponentFromURL()"!
444         css::uno::Any                                                   m_aInteractionRequest       ;
445         sal_Bool                                                        m_bSuspendQuickstartVeto    ;   /// don't ask quickstart for a veto
446         SvtCommandOptions                                               m_aCommandOptions           ;   /// ref counted class to support disabling commands defined by configuration file
447         ::rtl::OUString                                                 m_sName                     ;
448         ::rtl::OUString                                                 m_sTitle                    ;
449         css::uno::Reference< css::frame::XDispatchRecorderSupplier >    m_xDispatchRecorderSupplier ;
450 
451         //---------------------------------------------------------------------
452         /** special terminate listener to close pipe and block external requests
453           * during/after termination process is/was running
454           */
455         css::uno::Reference< css::frame::XTerminateListener > m_xPipeTerminator;
456 
457         //---------------------------------------------------------------------
458         /** special terminate listener shown inside system tray (quick starter)
459           * Will hinder the office on shutdown ... but wish to allow closing
460           * of open documents. And because that's different to a normal terminate listener
461           * it has to be handled special .-)
462           */
463         css::uno::Reference< css::frame::XTerminateListener > m_xQuickLauncher;
464 
465         //---------------------------------------------------------------------
466         /** special terminate listener which loads images asynchronous for current open documents.
467           * Because internally it uses blocking system APIs ... it can't be guaranteed that
468           * running jobs can be cancelled successfully if the corresponding document will be closed ...
469           * it will not hinder those documents on closing. Instead it let all jobs running ...
470           * but at least on terminate we have to wait for all those blocked requests.
471           * So these implementation must be a special terminate listener too .-(
472           */
473         css::uno::Reference< css::frame::XTerminateListener > m_xSWThreadManager;
474 
475         //---------------------------------------------------------------------
476         /** special terminate listener shutting down the SfxApplication.
477           * Because these desktop instance closes documents and informs listener
478           * only ... it does not really shutdown the whole application.
479           *
480           * Btw: That wouldn't be possible by design ... because Desktop.terminate()
481           * has to return a boolean value about success ... it can't really shutdown the
482           * process .-)
483           *
484           * So we uses a trick: A special listener (exactly these one here) listen for notifyTermination()
485           * and shutdown the process asynchronous. But desktop has to make this special
486           * notification as really last one ... Otherwise it can happen that asynchronous
487           * shutdown will be faster then all other code around Desktop.terminate() .-))
488           */
489         css::uno::Reference< css::frame::XTerminateListener > m_xSfxTerminator;
490 
491         css::uno::Reference< css::frame::XUntitledNumbers > m_xTitleNumberGenerator;
492 
493 };      //  class Desktop
494 
495 }       //  namespace framework
496 
497 #endif  //  #ifndef __FRAMEWORK_SERVICES_DESKTOP_HXX_
498