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