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>
28 #include <classes/framecontainer.hxx>
30 #include <com/sun/star/frame/XUntitledNumbers.hpp>
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/frame/XDesktop2.hpp>
33 #include <com/sun/star/frame/XTerminateListener.hpp>
34 #include <com/sun/star/frame/XTask.hpp>
35 #include <com/sun/star/frame/XFramesSupplier.hpp>
36 #include <com/sun/star/frame/XFrames.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/frame/XDispatchProvider.hpp>
39 #include <com/sun/star/frame/XTasksSupplier.hpp>
40 #include <com/sun/star/container/XEnumerationAccess.hpp>
41 #include <com/sun/star/lang/Locale.hpp>
42 #include <com/sun/star/frame/XDispatchResultListener.hpp>
43 #include <com/sun/star/lang/XEventListener.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/task/XInteractionHandler.hpp>
46 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
47 #include <com/sun/star/uno/XComponentContext.hpp>
49 #include <comphelper/numberedcollection.hxx>
50 #include <cppuhelper/compbase.hxx>
51 #include <cppuhelper/propshlp.hxx>
52 #include <unotools/cmdoptions.hxx>
64 /*-************************************************************************************************************
65 @short implement the topframe of frame tree
66 @descr This is the root of the frame tree. The desktop has no window, is not visible but he is the logical
67 "masternode" to build the hierarchy.
69 @implements XInterface
82 XDispatchResultListener
86 @devstatus ready to use
88 *//*-*************************************************************************************************************/
89 typedef cppu::WeakComponentImplHelper
<
90 css::lang::XServiceInfo
,
91 css::frame::XDesktop2
,
92 css::frame::XTasksSupplier
,
93 css::frame::XDispatchResultListener
, // => XEventListener
94 css::task::XInteractionHandler
,
95 css::frame::XUntitledNumbers
> Desktop_BASE
;
97 class Desktop
: private cppu::BaseMutex
,
98 private TransactionBase
,
100 public cppu::OPropertySetHelper
102 // internal used types, const etcpp.
105 /** used temporary to know which listener was already called or not. */
106 typedef ::std::vector
< css::uno::Reference
< css::frame::XTerminateListener
> > TTerminateListenerList
;
111 // constructor / destructor
112 Desktop( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
113 virtual ~Desktop( ) override
;
115 void constructorInit();
118 virtual OUString SAL_CALL
getImplementationName() override
;
120 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
) override
;
122 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
125 virtual void SAL_CALL
acquire() throw () override
126 { OWeakObject::acquire(); }
127 virtual void SAL_CALL
release() throw () override
128 { OWeakObject::release(); }
129 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& type
) override
;
132 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
137 @short try to shutdown these desktop environment.
139 @descr Will try to close all frames. If at least one frame could
140 not be closed successfully termination will be stopped.
142 Registered termination listener will be taken into account
143 also. As special feature some of our registered listener
144 are well known by its UNO implementation name. They are handled
145 different to all other listener.
147 Btw: Desktop.terminate() was designed in the past to be used
148 within an UI based environment. So it's allowed e.g. to
149 call XController.suspend() here. If UI isn't an option ... please
150 use XCloseable.close() at these desktop implementation.
151 ... if it will be supported in the future .-))
153 @seealso XTerminateListener
154 @seealso XTerminateListener2
156 @return true if all open frames could be closed and no listener throwed
157 a veto exception; false otherwise.
159 @onerror False will be returned.
162 virtual sal_Bool SAL_CALL
terminate() override
;
167 @short add a listener for termination events
169 @descr Additional to adding normal listener these method was implemented special.
170 Every listener will be asked for its uno implementation name.
171 Some of them are well known... and the corresponding listener won't be added
172 to the container of "normal listener". Those listener will be set as special
174 see e.g. member m_xSfxTerminator
179 the listener for registration.
183 virtual void SAL_CALL
addTerminateListener( const css::uno::Reference
< css::frame::XTerminateListener
>& xListener
) override
;
188 @short remove a listener from this container.
190 @descr Additional to removing normal listener these method was implemented special.
191 Every listener will be asked for its uno implementation name.
192 Some of them are well known... and the corresponding listener was set as special member.
193 Now those special member will be reset also.
194 see e.g. member m_xSfxTerminator
199 the listener for deregistration.
203 virtual void SAL_CALL
removeTerminateListener( const css::uno::Reference
< css::frame::XTerminateListener
>& xListener
) override
;
205 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
getComponents ( ) override
;
206 virtual css::uno::Reference
< css::lang::XComponent
> SAL_CALL
getCurrentComponent ( ) override
;
207 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getCurrentFrame ( ) override
;
210 virtual css::uno::Reference
< css::lang::XComponent
> SAL_CALL
loadComponentFromURL ( const OUString
& sURL
,
211 const OUString
& sTargetFrameName
,
212 sal_Int32 nSearchFlags
,
213 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
216 virtual css::uno::Reference
< css::container::XEnumerationAccess
> SAL_CALL
getTasks ( ) override
;
217 virtual css::uno::Reference
< css::frame::XTask
> SAL_CALL
getActiveTask ( ) override
;
220 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch ( const css::util::URL
& aURL
,
221 const OUString
& sTargetFrameName
,
222 sal_Int32 nSearchFlags
) override
;
223 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
queryDispatches ( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& lQueries
) override
;
225 // XDispatchProviderInterception
226 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& xInterceptor
) override
;
227 virtual void SAL_CALL
releaseDispatchProviderInterceptor ( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& xInterceptor
) override
;
230 virtual css::uno::Reference
< css::frame::XFrames
> SAL_CALL
getFrames ( ) override
;
231 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
getActiveFrame ( ) override
;
232 virtual void SAL_CALL
setActiveFrame ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) override
;
235 // Attention: findFrame() is implemented only! Other methods make no sense for our desktop!
236 virtual css::uno::Reference
< css::frame::XFrame
> SAL_CALL
findFrame ( const OUString
& sTargetFrameName
,
237 sal_Int32 nSearchFlags
) override
;
238 virtual void SAL_CALL
initialize ( const css::uno::Reference
< css::awt::XWindow
>& xWindow
) override
;
239 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
getContainerWindow ( ) override
;
240 virtual void SAL_CALL
setCreator ( const css::uno::Reference
< css::frame::XFramesSupplier
>& xCreator
) override
;
241 virtual css::uno::Reference
< css::frame::XFramesSupplier
> SAL_CALL
getCreator ( ) override
;
242 virtual OUString SAL_CALL
getName ( ) override
;
243 virtual void SAL_CALL
setName ( const OUString
& sName
) override
;
244 virtual sal_Bool SAL_CALL
isTop ( ) override
;
245 virtual void SAL_CALL
activate ( ) override
;
246 virtual void SAL_CALL
deactivate ( ) override
;
247 virtual sal_Bool SAL_CALL
isActive ( ) override
;
248 virtual sal_Bool SAL_CALL
setComponent ( const css::uno::Reference
< css::awt::XWindow
>& xComponentWindow
,
249 const css::uno::Reference
< css::frame::XController
>& xController
) override
;
250 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
getComponentWindow ( ) override
;
251 virtual css::uno::Reference
< css::frame::XController
> SAL_CALL
getController ( ) override
;
252 virtual void SAL_CALL
contextChanged ( ) override
;
253 virtual void SAL_CALL
addFrameActionListener ( const css::uno::Reference
< css::frame::XFrameActionListener
>& xListener
) override
;
254 virtual void SAL_CALL
removeFrameActionListener ( const css::uno::Reference
< css::frame::XFrameActionListener
>& xListener
) override
;
257 virtual void SAL_CALL
disposing() override
;
258 virtual void SAL_CALL
addEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
259 virtual void SAL_CALL
removeEventListener ( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
261 // XDispatchResultListener
262 virtual void SAL_CALL
dispatchFinished ( const css::frame::DispatchResultEvent
& aEvent
) override
;
265 virtual void SAL_CALL
disposing ( const css::lang::EventObject
& aSource
) override
;
267 // XInteractionHandler
268 virtual void SAL_CALL
handle ( const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
) override
;
270 // css.frame.XUntitledNumbers
271 virtual ::sal_Int32 SAL_CALL
leaseNumber( const css::uno::Reference
< css::uno::XInterface
>& xComponent
) override
;
273 // css.frame.XUntitledNumbers
274 virtual void SAL_CALL
releaseNumber( ::sal_Int32 nNumber
) override
;
276 // css.frame.XUntitledNumbers
277 virtual void SAL_CALL
releaseNumberForComponent( const css::uno::Reference
< css::uno::XInterface
>& xComponent
) override
;
279 // css.frame.XUntitledNumbers
280 virtual OUString SAL_CALL
getUntitledPrefix() override
;
282 // we need this wrapped terminate()-call to terminate even the QuickStarter
283 // non-virtual and non-UNO for now
284 /// @throws css::uno::RuntimeException
285 bool terminateQuickstarterToo();
291 // OPropertySetHelper
292 virtual sal_Bool SAL_CALL
convertFastPropertyValue ( css::uno::Any
& aConvertedValue
,
293 css::uno::Any
& aOldValue
,
295 const css::uno::Any
& aValue
) override
;
296 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
297 const css::uno::Any
& aValue
) override
;
298 using cppu::OPropertySetHelper::getFastPropertyValue
;
299 virtual void SAL_CALL
getFastPropertyValue ( css::uno::Any
& aValue
,
300 sal_Int32 nHandle
) const override
;
301 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper ( ) override
;
302 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo ( ) override
;
307 css::uno::Reference
< css::lang::XComponent
> impl_getFrameComponent ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) const;
309 /** calls queryTermination() on every registered termination listener.
311 * Note: Only normal termination listener (registered in list m_aListenerContainer
312 * will be recognized here. Special listener like quick starter, pipe or others
313 * has to be handled explicitly !
315 * @param [out] lCalledListener
316 * every called listener will be returned here.
317 * Those list will be used to inform all called listener
318 * about cancel this termination request.
321 * will be true if at least one listener throwed a veto exception;
324 * @see impl_sendCancelTerminationEvent()
326 void impl_sendQueryTerminationEvent(TTerminateListenerList
& lCalledListener
,
329 /** calls cancelTermination() on every termination listener
330 * where queryTermination() was called before.
332 * Note: Only normal termination listener (registered in list m_aListenerContainer
333 * will be recognized here. Special listener like quick starter, pipe or others
334 * has to be handled explicitly !
336 * @param [in] lCalledListener
337 * every listener in this list was called within its method
338 * queryTermination() before.
340 * @see impl_sendQueryTerminationEvent()
342 void impl_sendCancelTerminationEvent(const TTerminateListenerList
& lCalledListener
);
344 /** calls notifyTermination() on the clipboard listener
346 * The system clipboard may decide that it wants copies
347 * in several formats of the clipboard content requiring
348 * nearly all the services
351 void impl_sendTerminateToClipboard();
353 /** calls notifyTermination() on every registered termination listener.
355 * Note: Only normal termination listener (registered in list m_aListenerContainer
356 * will be recognized here. Special listener like quick starter, pipe or others
357 * has to be handled explicitly !
359 void impl_sendNotifyTerminationEvent();
361 /** try to close all open frames.
363 * Iterates over all child frames and try to close them.
364 * Given parameter bAllowUI enable/disable showing any UI
365 * (which mostly occur on calling XController->suspend()).
367 * This method doesn't stop if one frame could not be closed.
368 * It will ignore such frames and try all other ones.
369 * But it returns false in such case - true otherwise.
372 * enable/disable showing of UI.
374 * @return true if all frames could be closed; false otherwise.
376 bool impl_closeFrames(bool bAllowUI
);
380 /** check flag to protect us against dispose before terminate!
381 * see dispose() for further information!
383 bool m_bIsTerminated
;
385 /** when true, the call came form session manager
386 * the method is Desktop::terminateQuickstarterToo()
387 * this the only one place where set this to true
388 * In this case, when one frame break, not make
389 * question for other, the break of shutdown or logout
391 * In Desktop::impl_closeFrames would be test and break
392 * the loop and reset to false
396 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
; /// reference to factory, which has create this instance
397 FrameContainer m_aChildTaskContainer
; /// array of child tasks (children of desktop are tasks; and tasks are also frames - But pure frames are not accepted!)
398 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer
; /// container for ALL Listener
399 css::uno::Reference
< css::frame::XFrames
> m_xFramesHelper
; /// helper for XFrames, XIndexAccess, XElementAccess and implementation of a childcontainer!
400 css::uno::Reference
< css::frame::XDispatchProvider
> m_xDispatchHelper
; /// helper to dispatch something for new tasks, created by "_blank"!
401 ELoadState m_eLoadState
; /// hold information about state of asynchron loading of component for loadComponentFromURL()!
402 css::uno::Any m_aInteractionRequest
;
403 bool m_bSuspendQuickstartVeto
; /// don't ask quickstart for a veto
404 std::unique_ptr
<SvtCommandOptions
> m_xCommandOptions
; /// ref counted class to support disabling commands defined by configuration file
407 css::uno::Reference
< css::frame::XDispatchRecorderSupplier
> m_xDispatchRecorderSupplier
;
409 /** special terminate listener to close pipe and block external requests
410 * during/after termination process is/was running
412 css::uno::Reference
< css::frame::XTerminateListener
> m_xPipeTerminator
;
414 /** special terminate listener shown inside system tray (quick starter)
415 * Will hinder the office on shutdown ... but wish to allow closing
416 * of open documents. And because that's different to a normal terminate listener
417 * it has to be handled special .-)
419 css::uno::Reference
< css::frame::XTerminateListener
> m_xQuickLauncher
;
421 /** special terminate listener active when a macro is executing.
422 * Because basic runs Application::Yield internally the application may quit
423 * while running inside the internal basic event loop. So all the basic
424 * infrastructure may be deleted while the call is executing, leading to
425 * a variant of crashes. So this special terminate listener will
426 * veto the current quit attempt, stop basic execution, which will
427 * cause the inner event loop to quit, and on return to the outer normal
428 * application event loop then resend the quit attempt.
429 * So these implementation must be a special terminate listener too .-(
431 css::uno::Reference
< css::frame::XTerminateListener
> m_xStarBasicQuitGuard
;
433 /** special terminate listener which loads images asynchronous for current open documents.
434 * Because internally it uses blocking system APIs... it can't be guaranteed that
435 * running jobs can be cancelled successfully if the corresponding document will be closed...
436 * it will not hinder those documents on closing. Instead it let all jobs running...
437 * but at least on terminate we have to wait for all those blocked requests.
438 * So these implementation must be a special terminate listener too .-(
440 css::uno::Reference
< css::frame::XTerminateListener
> m_xSWThreadManager
;
442 /** special terminate listener shuting down the SfxApplication.
443 * Because these desktop instance closes documents and informs listener
444 * only... it does not really shutdown the whole application.
446 * Btw: that wouldn't be possible by design... because Desktop.terminate()
447 * has to return a boolean value about success... it can't really shutdown the
450 * So we uses a trick: a special listener (exactly these one here) listen for notifyTermination()
451 * and shutdown the process asynchronous. But desktop has to make this special
452 * notification as really last one ... Otherwise it can happen that asynchronous
453 * shutdown will be faster then all other code around Desktop.terminate() .-))
455 css::uno::Reference
< css::frame::XTerminateListener
> m_xSfxTerminator
;
457 css::uno::Reference
< css::frame::XUntitledNumbers
> m_xTitleNumberGenerator
;
459 std::vector
<css::uno::Reference
<css::frame::XTerminateListener
>> m_xComponentDllListeners
;
463 } // namespace framework
465 #endif // INCLUDED_FRAMEWORK_INC_SERVICES_DESKTOP_HXX
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */