Release CXNotifyingDataObject in separate thread
[LibreOffice.git] / include / framework / desktop.hxx
blob908459863f5924afdbdf2979a77917a27ea753f2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <sal/config.h>
24 #include <memory>
25 #include <vector>
27 #include "framecontainer.hxx"
28 #include "fwkdllapi.h"
29 #include "transactionmanager.hxx"
31 #include <com/sun/star/frame/XUntitledNumbers.hpp>
32 #include <com/sun/star/frame/XController.hpp>
33 #include <com/sun/star/frame/XDesktop2.hpp>
34 #include <com/sun/star/frame/XTerminateListener.hpp>
35 #include <com/sun/star/frame/XTask.hpp>
36 #include <com/sun/star/frame/XFramesSupplier.hpp>
37 #include <com/sun/star/frame/XFrames.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/frame/XDispatchProvider.hpp>
40 #include <com/sun/star/frame/XTasksSupplier.hpp>
41 #include <com/sun/star/container/XEnumerationAccess.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/multicontainer2.hxx>
50 #include <cppuhelper/basemutex.hxx>
51 #include <cppuhelper/compbase.hxx>
52 #include <cppuhelper/propshlp.hxx>
53 #include <rtl/ref.hxx>
54 #include <unotools/cmdoptions.hxx>
56 namespace comphelper { class NumberedCollection; }
58 namespace framework{
60 class InterceptionHelper;
61 class OFrames;
63 enum ELoadState
65 E_NOTSET ,
66 E_SUCCESSFUL ,
67 E_FAILED ,
68 E_INTERACTION
71 /*-************************************************************************************************************
72 @short implement the topframe of frame tree
73 @descr This is the root of the frame tree. The desktop has no window, is not visible but he is the logical
74 "masternode" to build the hierarchy.
76 @implements XInterface
77 XTypeProvider
78 XServiceInfo
79 XDesktop
80 XComponentLoader
81 XTasksSupplier
82 XDispatchProvider
83 XFramesSupplier
84 XFrame
85 XComponent
86 XPropertySet
87 XFastPropertySet
88 XMultiPropertySet
89 XDispatchResultListener
90 XEventListener
91 XInteractionHandler
93 @devstatus ready to use
94 @threadsafe yes
95 *//*-*************************************************************************************************************/
96 typedef cppu::WeakComponentImplHelper<
97 css::lang::XServiceInfo ,
98 css::frame::XDesktop2 ,
99 css::frame::XTasksSupplier ,
100 css::frame::XDispatchResultListener , // => XEventListener
101 css::task::XInteractionHandler ,
102 css::frame::XUntitledNumbers > Desktop_BASE;
104 class FWK_DLLPUBLIC Desktop final : private cppu::BaseMutex,
105 public Desktop_BASE,
106 public cppu::OPropertySetHelper
108 // internal used types, const etcpp.
109 private:
111 /** used temporary to know which listener was already called or not. */
112 typedef ::std::vector< css::uno::Reference< css::frame::XTerminateListener > > TTerminateListenerList;
114 // public methods
115 public:
117 // constructor / destructor
118 Desktop( css::uno::Reference< css::uno::XComponentContext > xContext );
119 virtual ~Desktop( ) override;
121 void constructorInit();
123 // XServiceInfo
124 virtual OUString SAL_CALL getImplementationName() override;
126 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
128 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
130 // XInterface
131 virtual void SAL_CALL acquire() noexcept override
132 { OWeakObject::acquire(); }
133 virtual void SAL_CALL release() noexcept override
134 { OWeakObject::release(); }
135 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& type) override;
137 // XTypeProvider
138 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
141 @interface XDesktop
143 @short try to shutdown these desktop environment.
145 @descr Will try to close all frames. If at least one frame could
146 not be closed successfully termination will be stopped.
148 Registered termination listener will be taken into account
149 also. As special feature some of our registered listener
150 are well known by its UNO implementation name. They are handled
151 different to all other listener.
153 Btw: Desktop.terminate() was designed in the past to be used
154 within an UI based environment. So it's allowed e.g. to
155 call XController.suspend() here. If UI isn't an option ... please
156 use XCloseable.close() at these desktop implementation.
157 ... if it will be supported in the future .-))
159 @seealso XTerminateListener
160 @seealso XTerminateListener2
162 @return true if all open frames could be closed and no listener threw
163 a veto exception; false otherwise.
165 @onerror False will be returned.
166 @threadsafe yes
168 virtual sal_Bool SAL_CALL terminate() override;
171 @interface XDesktop
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 won't be added
178 to the container of "normal listener". Those listener will be set as special
179 member.
180 see e.g. member m_xSfxTerminator
182 @seealso terminate()
184 @param xListener
185 the listener for registration.
187 @threadsafe yes
189 virtual void SAL_CALL addTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener ) override;
192 @interface XDesktop
194 @short remove a listener from this container.
196 @descr Additional to removing normal listener these method was implemented special.
197 Every listener will be asked for its uno implementation name.
198 Some of them are well known... and the corresponding listener was set as special member.
199 Now those special member will be reset also.
200 see e.g. member m_xSfxTerminator
202 @seealso terminate()
204 @param xListener
205 the listener for deregistration.
207 @threadsafe yes
209 virtual void SAL_CALL removeTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener ) override;
211 virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getComponents ( ) override;
212 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getCurrentComponent ( ) override;
213 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getCurrentFrame ( ) override;
215 // XComponentLoader
216 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL loadComponentFromURL ( const OUString& sURL ,
217 const OUString& sTargetFrameName ,
218 sal_Int32 nSearchFlags ,
219 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override;
221 // XTasksSupplier
222 virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getTasks ( ) override;
223 virtual css::uno::Reference< css::frame::XTask > SAL_CALL getActiveTask ( ) override;
225 // XDispatchProvider
226 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch ( const css::util::URL& aURL ,
227 const OUString& sTargetFrameName ,
228 sal_Int32 nSearchFlags ) override;
229 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches ( const css::uno::Sequence< css::frame::DispatchDescriptor >& lQueries ) override;
231 // XDispatchProviderInterception
232 virtual void SAL_CALL registerDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) override;
233 virtual void SAL_CALL releaseDispatchProviderInterceptor ( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) override;
235 // XFramesSupplier
236 virtual css::uno::Reference< css::frame::XFrames > SAL_CALL getFrames ( ) override;
237 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getActiveFrame ( ) override;
238 virtual void SAL_CALL setActiveFrame ( const css::uno::Reference< css::frame::XFrame >& xFrame ) override;
240 // XFrame
241 // Attention: findFrame() is implemented only! Other methods make no sense for our desktop!
242 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL findFrame ( const OUString& sTargetFrameName ,
243 sal_Int32 nSearchFlags ) override;
244 virtual void SAL_CALL initialize ( const css::uno::Reference< css::awt::XWindow >& xWindow ) override;
245 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getContainerWindow ( ) override;
246 virtual void SAL_CALL setCreator ( const css::uno::Reference< css::frame::XFramesSupplier >& xCreator ) override;
247 virtual css::uno::Reference< css::frame::XFramesSupplier > SAL_CALL getCreator ( ) override;
248 virtual OUString SAL_CALL getName ( ) override;
249 virtual void SAL_CALL setName ( const OUString& sName ) override;
250 virtual sal_Bool SAL_CALL isTop ( ) override;
251 virtual void SAL_CALL activate ( ) override;
252 virtual void SAL_CALL deactivate ( ) override;
253 virtual sal_Bool SAL_CALL isActive ( ) override;
254 virtual sal_Bool SAL_CALL setComponent ( const css::uno::Reference< css::awt::XWindow >& xComponentWindow ,
255 const css::uno::Reference< css::frame::XController >& xController ) override;
256 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getComponentWindow ( ) override;
257 virtual css::uno::Reference< css::frame::XController > SAL_CALL getController ( ) override;
258 virtual void SAL_CALL contextChanged ( ) override;
259 virtual void SAL_CALL addFrameActionListener ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener ) override;
260 virtual void SAL_CALL removeFrameActionListener ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener ) override;
262 // XComponent
263 virtual void SAL_CALL disposing() override;
264 virtual void SAL_CALL addEventListener ( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
265 virtual void SAL_CALL removeEventListener ( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
267 // XDispatchResultListener
268 virtual void SAL_CALL dispatchFinished ( const css::frame::DispatchResultEvent& aEvent ) override;
270 // XEventListener
271 virtual void SAL_CALL disposing ( const css::lang::EventObject& aSource ) override;
273 // XInteractionHandler
274 virtual void SAL_CALL handle ( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) override;
276 // css.frame.XUntitledNumbers
277 virtual ::sal_Int32 SAL_CALL leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent ) override;
279 // css.frame.XUntitledNumbers
280 virtual void SAL_CALL releaseNumber( ::sal_Int32 nNumber ) override;
282 // css.frame.XUntitledNumbers
283 virtual void SAL_CALL releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent ) override;
285 // css.frame.XUntitledNumbers
286 virtual OUString SAL_CALL getUntitledPrefix() override;
288 // we need this wrapped terminate()-call to terminate even the QuickStarter
289 // non-virtual and non-UNO for now
290 /// @throws css::uno::RuntimeException
291 bool terminateQuickstarterToo();
293 void shutdown();
295 private:
296 // OPropertySetHelper
297 virtual sal_Bool SAL_CALL convertFastPropertyValue ( css::uno::Any& aConvertedValue ,
298 css::uno::Any& aOldValue ,
299 sal_Int32 nHandle ,
300 const css::uno::Any& aValue ) override;
301 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
302 const css::uno::Any& aValue ) override;
303 using cppu::OPropertySetHelper::getFastPropertyValue;
304 virtual void SAL_CALL getFastPropertyValue ( css::uno::Any& aValue ,
305 sal_Int32 nHandle ) const override;
306 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper ( ) override;
307 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo ( ) override;
309 css::uno::Reference< css::lang::XComponent > impl_getFrameComponent ( const css::uno::Reference< css::frame::XFrame >& xFrame ) const;
311 /** calls queryTermination() on every registered termination listener.
313 * Note: Only normal termination listener (registered in list m_aListenerContainer
314 * will be recognized here. Special listener like quick starter, pipe or others
315 * has to be handled explicitly !
317 * @param [out] lCalledListener
318 * every called listener will be returned here.
319 * Those list will be used to inform all called listener
320 * about cancel this termination request.
322 * @return true if no one vetoed the termination.
324 * @see impl_sendCancelTerminationEvent()
326 bool impl_sendQueryTerminationEvent(TTerminateListenerList& lCalledListener);
328 /** calls cancelTermination() on every termination listener
329 * where queryTermination() was called before.
331 * Note: Only normal termination listener (registered in list m_aListenerContainer
332 * will be recognized here. Special listener like quick starter, pipe or others
333 * has to be handled explicitly !
335 * @param [in] lCalledListener
336 * every listener in this list was called within its method
337 * queryTermination() before.
339 * @see impl_sendQueryTerminationEvent()
341 void impl_sendCancelTerminationEvent(const TTerminateListenerList& lCalledListener);
343 /** calls notifyTermination() on the clipboard listener
345 * The system clipboard may decide that it wants copies
346 * in several formats of the clipboard content requiring
347 * nearly all the services
350 void impl_sendTerminateToClipboard();
352 /** calls notifyTermination() on every registered termination listener.
354 * Note: Only normal termination listener (registered in list m_aListenerContainer
355 * will be recognized here. Special listener like quick starter, pipe or others
356 * has to be handled explicitly !
358 void impl_sendNotifyTerminationEvent();
360 /** try to close all open frames.
362 * Iterates over all child frames and try to close them.
363 * Given parameter bAllowUI enable/disable showing any UI
364 * (which mostly occur on calling XController->suspend()).
366 * This method doesn't stop if one frame could not be closed.
367 * It will ignore such frames and try all other ones.
368 * But it returns false in such case - true otherwise.
370 * @param bAllowUI
371 * enable/disable showing of UI.
373 * @return true if all frames could be closed; false otherwise.
375 bool impl_closeFrames(bool bAllowUI);
377 private:
379 mutable TransactionManager m_aTransactionManager;
381 /** check flag to protect against multiple terminate runs
383 bool m_bIsTerminated;
385 /** check flag to protect us against dispose before terminate!
386 * see dispose() for further information!
388 bool m_bIsShutdown;
390 /** when true, the call came from session manager
391 * the method is Desktop::terminateQuickstarterToo()
392 * this the only one place where set this to true
393 * In this case, when one frame break, not make
394 * question for other, the break of shutdown or logout
395 * can be only once.
396 * In Desktop::impl_closeFrames would be test and break
397 * the loop and reset to false
399 bool m_bSession;
401 css::uno::Reference< css::uno::XComponentContext > m_xContext; /// reference to factory, which has create this instance
402 FrameContainer m_aChildTaskContainer; /// array of child tasks (children of desktop are tasks; and tasks are also frames - But pure frames are not accepted!)
403 comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer; /// container for ALL Listener
404 rtl::Reference< OFrames > m_xFramesHelper; /// helper for XFrames, XIndexAccess, XElementAccess and implementation of a childcontainer!
405 rtl::Reference< InterceptionHelper > m_xDispatchHelper; /// helper to dispatch something for new tasks, created by "_blank"!
406 ELoadState m_eLoadState; /// hold information about state of asynchron loading of component for loadComponentFromURL()!
407 bool m_bSuspendQuickstartVeto; /// don't ask quickstart for a veto
408 std::unique_ptr<SvtCommandOptions> m_xCommandOptions; /// ref counted class to support disabling commands defined by configuration file
409 OUString m_sName;
410 OUString m_sTitle;
411 css::uno::Reference< css::frame::XDispatchRecorderSupplier > m_xDispatchRecorderSupplier;
413 /** special terminate listener to close pipe and block external requests
414 * during/after termination process is/was running
416 css::uno::Reference< css::frame::XTerminateListener > m_xPipeTerminator;
418 /** special terminate listener shown inside system tray (quick starter)
419 * Will hinder the office on shutdown ... but wish to allow closing
420 * of open documents. And because that's different to a normal terminate listener
421 * it has to be handled special .-)
423 css::uno::Reference< css::frame::XTerminateListener > m_xQuickLauncher;
425 /** special terminate listener which loads images asynchronous for current open documents.
426 * Because internally it uses blocking system APIs... it can't be guaranteed that
427 * running jobs can be cancelled successfully if the corresponding document will be closed...
428 * it will not hinder those documents on closing. Instead it let all jobs running...
429 * but at least on terminate we have to wait for all those blocked requests.
430 * So these implementation must be a special terminate listener too .-(
432 css::uno::Reference< css::frame::XTerminateListener > m_xSWThreadManager;
434 /** special terminate listener shutting down the SfxApplication.
435 * Because these desktop instance closes documents and informs listener
436 * only... it does not really shutdown the whole application.
438 * Btw: that wouldn't be possible by design... because Desktop.terminate()
439 * has to return a boolean value about success... it can't really shutdown the
440 * process .-)
442 * So we uses a trick: a special listener (exactly these one here) listen for notifyTermination()
443 * and shutdown the process asynchronous. But desktop has to make this special
444 * notification as really last one ... Otherwise it can happen that asynchronous
445 * shutdown will be faster then all other code around Desktop.terminate() .-))
447 css::uno::Reference< css::frame::XTerminateListener > m_xSfxTerminator;
449 rtl::Reference< ::comphelper::NumberedCollection > m_xTitleNumberGenerator;
451 std::vector<css::uno::Reference<css::frame::XTerminateListener>> m_xComponentDllListeners;
453 }; // class Desktop
455 FWK_DLLPUBLIC const rtl::Reference<Desktop> & getDesktop(
456 css::uno::Reference<css::uno::XComponentContext> const & context);
458 } // namespace framework
460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */