1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_FRAMEWORK_INC_SERVICES_DESKTOP_HXX
21 #define INCLUDED_FRAMEWORK_INC_SERVICES_DESKTOP_HXX
23 #include <sal/config.h>
25 #include <classes/framecontainer.hxx>
27 #include <com/sun/star/frame/XUntitledNumbers.hpp>
28 #include <com/sun/star/frame/XController.hpp>
29 #include <com/sun/star/frame/XDesktop2.hpp>
30 #include <com/sun/star/frame/XTerminateListener.hpp>
31 #include <com/sun/star/frame/XTask.hpp>
32 #include <com/sun/star/frame/XStorable.hpp>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/frame/XFramesSupplier.hpp>
35 #include <com/sun/star/frame/XFrames.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
39 #include <com/sun/star/frame/XComponentLoader.hpp>
40 #include <com/sun/star/frame/FrameAction.hpp>
41 #include <com/sun/star/frame/XTasksSupplier.hpp>
42 #include <com/sun/star/container/XEnumerationAccess.hpp>
43 #include <com/sun/star/lang/Locale.hpp>
44 #include <com/sun/star/frame/XDispatchResultListener.hpp>
45 #include <com/sun/star/lang/XEventListener.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <com/sun/star/task/XInteractionHandler.hpp>
48 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
49 #include <com/sun/star/uno/XComponentContext.hpp>
51 #include <comphelper/numberedcollection.hxx>
52 #include <cppuhelper/compbase6.hxx>
53 #include <cppuhelper/propshlp.hxx>
54 #include <unotools/cmdoptions.hxx>
66 /*-************************************************************************************************************
67 @short implement the topframe of frame tree
68 @descr This is the root of the frame tree. The desktop has no window, is not visible but he is the logical
69 "masternode" to build the hierarchy.
71 @implements XInterface
84 XDispatchResultListener
88 @devstatus ready to use
90 *//*-*************************************************************************************************************/
91 typedef cppu::WeakComponentImplHelper6
<
92 css::lang::XServiceInfo
,
93 css::frame::XDesktop2
,
94 css::frame::XTasksSupplier
,
95 css::frame::XDispatchResultListener
, // => XEventListener
96 css::task::XInteractionHandler
,
97 css::frame::XUntitledNumbers
> Desktop_BASE
;
99 class Desktop
: private cppu::BaseMutex
,
100 private TransactionBase
,
102 public cppu::OPropertySetHelper
104 // internal used types, const etcpp.
107 /** used temporary to know which listener was already called or not. */
108 typedef ::std::vector
< css::uno::Reference
< css::frame::XTerminateListener
> > TTerminateListenerList
;
113 // constructor / destructor
114 Desktop( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
117 void constructorInit();
120 virtual OUString SAL_CALL
getImplementationName()
121 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
124 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
126 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
127 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 virtual void SAL_CALL
acquire() throw () SAL_OVERRIDE
131 { OWeakObject::acquire(); }
132 virtual void SAL_CALL
release() throw () SAL_OVERRIDE
133 { OWeakObject::release(); }
134 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& type
) throw ( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
137 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
142 @short try to shutdown these desktop environment.
144 @descr Will try to close all frames. If at least one frame could
145 not be closed successfully termination will be stopped.
147 Registered termination listener will be taken into account
148 also. As special feature some of our registered listener
149 are well known by its UNO implementation name. They are handled
150 different to all other listener.
152 Btw: Desktop.terminate() was designed in the past to be used
153 within an UI based envrionment. So it's allowed e.g. to
154 call XController.suspend() here. If UI isn't an option ... please
155 use XCloseable.close() at these desktop implementation.
156 ... if it will be supported in the future .-))
158 @seealso XTerminateListener
159 @seealso XTerminateListener2
161 @return true if all open frames could be closed and no listener throwed
162 a veto exception; false otherwise.
164 @onerror False will be returned.
167 virtual sal_Bool SAL_CALL
terminate()
168 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
173 @short add a listener for termination events
175 @descr Additional to adding normal listener these method was implemented special.
176 Every listener will be asked for its uno implementation name.
177 Some of them are well known ... and the corresponding listener wont be added
178 to the container of "normal listener". Those listener will be set as special
180 see e.g. member m_xSfxTerminator
185 the listener for registration.
189 virtual void SAL_CALL
addTerminateListener( const css::uno::Reference
< css::frame::XTerminateListener
>& xListener
)
190 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
195 @short remove a listener from this container.
197 @descr Additional to removing normal listener these method was implemented special.
198 Every listener will be asked for its uno implementation name.
199 Some of them are well known ... and the corresponding listener was set as special member.
200 Now those special member will be reseted also.
201 see e.g. member m_xSfxTerminator
206 the listener for deregistration.
210 virtual void SAL_CALL
removeTerminateListener( const css::uno::Reference
< css::frame::XTerminateListener
>& xListener
)
211 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
213 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
getComponents ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
214 virtual css::uno::Reference
< css::lang::XComponent
> SAL_CALL
getCurrentComponent ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
215 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getCurrentFrame ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
218 virtual css::uno::Reference
< css::lang::XComponent
> SAL_CALL
loadComponentFromURL ( const OUString
& sURL
,
219 const OUString
& sTargetFrameName
,
220 sal_Int32 nSearchFlags
,
221 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) throw( css::io::IOException
,
222 css::lang::IllegalArgumentException
,
223 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
226 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
getTasks ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
227 virtual css::uno::Reference
< css::frame::XTask
> SAL_CALL
getActiveTask ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
230 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch ( const css::util::URL
& aURL
,
231 const OUString
& sTargetFrameName
,
232 sal_Int32 nSearchFlags
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 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
, std::exception
) SAL_OVERRIDE
;
235 // XDispatchProviderInterception
236 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& xInterceptor
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
237 virtual void SAL_CALL
releaseDispatchProviderInterceptor ( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& xInterceptor
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
240 virtual css::uno::Reference
< css::frame::XFrames
> SAL_CALL
getFrames ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
241 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getActiveFrame ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
242 virtual void SAL_CALL
setActiveFrame ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
245 // Attention: findFrame() is implemented only! Other methods make no sense for our desktop!
246 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
findFrame ( const OUString
& sTargetFrameName
,
247 sal_Int32 nSearchFlags
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
248 virtual void SAL_CALL
initialize ( const css::uno::Reference
< css::awt::XWindow
>& xWindow
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
249 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
getContainerWindow ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
250 virtual void SAL_CALL
setCreator ( const css::uno::Reference
< css::frame::XFramesSupplier
>& xCreator
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
251 virtual css::uno::Reference
< css::frame::XFramesSupplier
> SAL_CALL
getCreator ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
252 virtual OUString SAL_CALL
getName ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
253 virtual void SAL_CALL
setName ( const OUString
& sName
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
254 virtual sal_Bool SAL_CALL
isTop ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
255 virtual void SAL_CALL
activate ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
256 virtual void SAL_CALL
deactivate ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 virtual sal_Bool SAL_CALL
isActive ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
258 virtual sal_Bool SAL_CALL
setComponent ( const css::uno::Reference
< css::awt::XWindow
>& xComponentWindow
,
259 const css::uno::Reference
< css::frame::XController
>& xController
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
260 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
getComponentWindow ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
261 virtual css::uno::Reference
< css::frame::XController
> SAL_CALL
getController ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
262 virtual void SAL_CALL
contextChanged ( ) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
263 virtual void SAL_CALL
addFrameActionListener ( const css::uno::Reference
< css::frame::XFrameActionListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
264 virtual void SAL_CALL
removeFrameActionListener ( const css::uno::Reference
< css::frame::XFrameActionListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
267 virtual void SAL_CALL
disposing() throw( css::uno::RuntimeException
) SAL_OVERRIDE
;
268 virtual void SAL_CALL
addEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
269 virtual void SAL_CALL
removeEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
271 // XDispatchResultListener
272 virtual void SAL_CALL
dispatchFinished ( const css::frame::DispatchResultEvent
& aEvent
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
275 virtual void SAL_CALL
disposing ( const css::lang::EventObject
& aSource
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
277 // XInteractionHandler
278 virtual void SAL_CALL
handle ( const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
) throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
280 // css.frame.XUntitledNumbers
281 virtual ::sal_Int32 SAL_CALL
leaseNumber( const css::uno::Reference
< css::uno::XInterface
>& xComponent
)
282 throw (css::lang::IllegalArgumentException
,
283 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
285 // css.frame.XUntitledNumbers
286 virtual void SAL_CALL
releaseNumber( ::sal_Int32 nNumber
)
287 throw (css::lang::IllegalArgumentException
,
288 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
290 // css.frame.XUntitledNumbers
291 virtual void SAL_CALL
releaseNumberForComponent( const css::uno::Reference
< css::uno::XInterface
>& xComponent
)
292 throw (css::lang::IllegalArgumentException
,
293 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
295 // css.frame.XUntitledNumbers
296 virtual OUString SAL_CALL
getUntitledPrefix()
297 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
299 // we need this wrapped terminate()-call to terminate even the QuickStarter
300 // non-virtual and non-UNO for now
301 bool SAL_CALL
terminateQuickstarterToo()
302 throw( css::uno::RuntimeException
);
308 // OPropertySetHelper
309 virtual sal_Bool SAL_CALL
convertFastPropertyValue ( css::uno::Any
& aConvertedValue
,
310 css::uno::Any
& aOldValue
,
312 const css::uno::Any
& aValue
) throw( css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
313 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
314 const css::uno::Any
& aValue
) throw( css::uno::Exception
, std::exception
) SAL_OVERRIDE
;
315 using cppu::OPropertySetHelper::getFastPropertyValue
;
316 virtual void SAL_CALL
getFastPropertyValue ( css::uno::Any
& aValue
,
317 sal_Int32 nHandle
) const SAL_OVERRIDE
;
318 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper ( ) SAL_OVERRIDE
;
319 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo ( ) throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
324 css::uno::Reference
< css::lang::XComponent
> impl_getFrameComponent ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) const;
325 static const css::uno::Sequence
< css::beans::Property
> impl_getStaticPropertyDescriptor( );
327 /** calls queryTermination() on every registered termination listener.
329 * Note: Only normal termination listener (registered in list m_aListenerContainer
330 * will be recognized here. Special listener like quick starter, pipe or others
331 * has to be handled explicitly !
333 * @param [out] lCalledListener
334 * every called listener will be returned here.
335 * Those list will be used to informa all called listener
336 * about cancel this termination request.
339 * will be true if at least one listener throwed a veto exception;
342 * @see impl_sendCancelTerminationEvent()
344 void impl_sendQueryTerminationEvent(TTerminateListenerList
& lCalledListener
,
347 /** calls cancelTermination() on every termination listener
348 * where queryTermination() was called before.
350 * Note: Only normal termination listener (registered in list m_aListenerContainer
351 * will be recognized here. Special listener like quick starter, pipe or others
352 * has to be handled explicitly !
354 * @param [in] lCalledListener
355 * every listener in this list was called within its method
356 * queryTermination() before.
358 * @see impl_sendQueryTerminationEvent()
360 void impl_sendCancelTerminationEvent(const TTerminateListenerList
& lCalledListener
);
362 /** calls notifyTermination() on every registered termination listener.
364 * Note: Only normal termination listener (registered in list m_aListenerContainer
365 * will be recognized here. Special listener like quick starter, pipe or others
366 * has to be handled explicitly !
368 void impl_sendNotifyTerminationEvent();
370 /** try to close all open frames.
372 * Iterates over all child frames and try to close them.
373 * Given parameter bAllowUI enable/disable showing any UI
374 * (which mostly occur on calling XController->suspend()).
376 * This method doesn't stop if one frame could not be closed.
377 * It will ignore such frames and try all other ones.
378 * But it returns false in such case - true otherwise.
381 * enable/disable showing of UI.
383 * @return true if all frames could be closed; false otherwise.
385 bool impl_closeFrames(bool bAllowUI
);
388 // (should be private every time!)
392 static bool implcp_addEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
);
393 static bool implcp_removeEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
);
395 bool m_bIsTerminated
; /// check flag to protect us against dispose before terminate!
396 /// see dispose() for further information!
399 // (should be private every time!)
403 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
; /// reference to factory, which has create this instance
404 FrameContainer m_aChildTaskContainer
; /// array of child tasks (children of desktop are tasks; and tasks are also frames - But pure frames are not accepted!)
405 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer
; /// container for ALL Listener
406 css::uno::Reference
< css::frame::XFrames
> m_xFramesHelper
; /// helper for XFrames, XIndexAccess, XElementAccess and implementation of a childcontainer!
407 css::uno::Reference
< css::frame::XDispatchProvider
> m_xDispatchHelper
; /// helper to dispatch something for new tasks, created by "_blank"!
408 ELoadState m_eLoadState
; /// hold information about state of asynchron loading of component for loadComponentFromURL()!
409 css::uno::Reference
< css::frame::XFrame
> m_xLastFrame
; /// last target of "loadComponentFromURL()"!
410 css::uno::Any m_aInteractionRequest
;
411 bool m_bSuspendQuickstartVeto
; /// don't ask quickstart for a veto
412 SvtCommandOptions m_aCommandOptions
; /// ref counted class to support disabling commands defined by configuration file
415 css::uno::Reference
< css::frame::XDispatchRecorderSupplier
> m_xDispatchRecorderSupplier
;
417 /** special terminate listener to close pipe and block external requests
418 * during/after termination process is/was running
420 css::uno::Reference
< css::frame::XTerminateListener
> m_xPipeTerminator
;
422 /** special terminate listener shown inside system tray (quick starter)
423 * Will hinder the office on shutdown ... but wish to allow closing
424 * of open documents. And because thats different to a normal terminate listener
425 * it has to be handled special .-)
427 css::uno::Reference
< css::frame::XTerminateListener
> m_xQuickLauncher
;
429 /** special terminate listener which loads images asynchronous for current open documents.
430 * Because internally it uses blocking system APIs ... it can't be guaranteed that
431 * running jobs can be cancelled successfully if the corressponding document will be closed ...
432 * it will not hinder those documents on closing. Instead it let all jobs running ...
433 * but at least on terminate we have to wait for all those blocked requests.
434 * So these implementation must be a special terminate listener too .-(
436 css::uno::Reference
< css::frame::XTerminateListener
> m_xSWThreadManager
;
438 /** special terminate listener shuting down the SfxApplication.
439 * Because these desktop instance closes documents and informs listener
440 * only ... it does not really shutdown the whole application.
442 * Btw: That wouldnt be possible by design ... because Desktop.terminate()
443 * has to return a boolean value about success ... it can't really shutdown the
446 * So we uses a trick: A special listener (exactly these one here) listen for notifyTermination()
447 * and shutdown the process asynchronous. But desktop has to make this special
448 * notification as really last one ... Otherwise it can happen that asynchronous
449 * shutdown will be faster then all other code around Desktop.terminate() .-))
451 css::uno::Reference
< css::frame::XTerminateListener
> m_xSfxTerminator
;
453 css::uno::Reference
< css::frame::XUntitledNumbers
> m_xTitleNumberGenerator
;
457 } // namespace framework
459 #endif // INCLUDED_FRAMEWORK_INC_SERVICES_DESKTOP_HXX
461 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */