Handle pasting disallowed clipboard contents on iOS
[LibreOffice.git] / include / framework / desktop.hxx
blob3d525eb54938aca24247aa70ec2d24950b43a53b
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 framework{
58 enum ELoadState
60 E_NOTSET ,
61 E_SUCCESSFUL ,
62 E_FAILED ,
63 E_INTERACTION
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
72 XTypeProvider
73 XServiceInfo
74 XDesktop
75 XComponentLoader
76 XTasksSupplier
77 XDispatchProvider
78 XFramesSupplier
79 XFrame
80 XComponent
81 XPropertySet
82 XFastPropertySet
83 XMultiPropertySet
84 XDispatchResultListener
85 XEventListener
86 XInteractionHandler
88 @devstatus ready to use
89 @threadsafe yes
90 *//*-*************************************************************************************************************/
91 typedef cppu::WeakComponentImplHelper<
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 FWK_DLLPUBLIC Desktop final : private cppu::BaseMutex,
100 public Desktop_BASE,
101 public cppu::OPropertySetHelper
103 // internal used types, const etcpp.
104 private:
106 /** used temporary to know which listener was already called or not. */
107 typedef ::std::vector< css::uno::Reference< css::frame::XTerminateListener > > TTerminateListenerList;
109 // public methods
110 public:
112 // constructor / destructor
113 Desktop( css::uno::Reference< css::uno::XComponentContext > xContext );
114 virtual ~Desktop( ) override;
116 void constructorInit();
118 // XServiceInfo
119 virtual OUString SAL_CALL getImplementationName() override;
121 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
123 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
125 // XInterface
126 virtual void SAL_CALL acquire() noexcept override
127 { OWeakObject::acquire(); }
128 virtual void SAL_CALL release() noexcept override
129 { OWeakObject::release(); }
130 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& type) override;
132 // XTypeProvider
133 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
136 @interface XDesktop
138 @short try to shutdown these desktop environment.
140 @descr Will try to close all frames. If at least one frame could
141 not be closed successfully termination will be stopped.
143 Registered termination listener will be taken into account
144 also. As special feature some of our registered listener
145 are well known by its UNO implementation name. They are handled
146 different to all other listener.
148 Btw: Desktop.terminate() was designed in the past to be used
149 within an UI based environment. So it's allowed e.g. to
150 call XController.suspend() here. If UI isn't an option ... please
151 use XCloseable.close() at these desktop implementation.
152 ... if it will be supported in the future .-))
154 @seealso XTerminateListener
155 @seealso XTerminateListener2
157 @return true if all open frames could be closed and no listener threw
158 a veto exception; false otherwise.
160 @onerror False will be returned.
161 @threadsafe yes
163 virtual sal_Bool SAL_CALL terminate() override;
166 @interface XDesktop
168 @short add a listener for termination events
170 @descr Additional to adding normal listener these method was implemented special.
171 Every listener will be asked for its uno implementation name.
172 Some of them are well known... and the corresponding listener won't be added
173 to the container of "normal listener". Those listener will be set as special
174 member.
175 see e.g. member m_xSfxTerminator
177 @seealso terminate()
179 @param xListener
180 the listener for registration.
182 @threadsafe yes
184 virtual void SAL_CALL addTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener ) override;
187 @interface XDesktop
189 @short remove a listener from this container.
191 @descr Additional to removing normal listener these method was implemented special.
192 Every listener will be asked for its uno implementation name.
193 Some of them are well known... and the corresponding listener was set as special member.
194 Now those special member will be reset also.
195 see e.g. member m_xSfxTerminator
197 @seealso terminate()
199 @param xListener
200 the listener for deregistration.
202 @threadsafe yes
204 virtual void SAL_CALL removeTerminateListener( const css::uno::Reference< css::frame::XTerminateListener >& xListener ) override;
206 virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getComponents ( ) override;
207 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getCurrentComponent ( ) override;
208 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getCurrentFrame ( ) override;
210 // XComponentLoader
211 virtual css::uno::Reference< css::lang::XComponent > SAL_CALL loadComponentFromURL ( const OUString& sURL ,
212 const OUString& sTargetFrameName ,
213 sal_Int32 nSearchFlags ,
214 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override;
216 // XTasksSupplier
217 virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getTasks ( ) override;
218 virtual css::uno::Reference< css::frame::XTask > SAL_CALL getActiveTask ( ) override;
220 // XDispatchProvider
221 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch ( const css::util::URL& aURL ,
222 const OUString& sTargetFrameName ,
223 sal_Int32 nSearchFlags ) override;
224 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches ( const css::uno::Sequence< css::frame::DispatchDescriptor >& lQueries ) override;
226 // XDispatchProviderInterception
227 virtual void SAL_CALL registerDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) override;
228 virtual void SAL_CALL releaseDispatchProviderInterceptor ( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor) override;
230 // XFramesSupplier
231 virtual css::uno::Reference< css::frame::XFrames > SAL_CALL getFrames ( ) override;
232 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getActiveFrame ( ) override;
233 virtual void SAL_CALL setActiveFrame ( const css::uno::Reference< css::frame::XFrame >& xFrame ) override;
235 // XFrame
236 // Attention: findFrame() is implemented only! Other methods make no sense for our desktop!
237 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL findFrame ( const OUString& sTargetFrameName ,
238 sal_Int32 nSearchFlags ) override;
239 virtual void SAL_CALL initialize ( const css::uno::Reference< css::awt::XWindow >& xWindow ) override;
240 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getContainerWindow ( ) override;
241 virtual void SAL_CALL setCreator ( const css::uno::Reference< css::frame::XFramesSupplier >& xCreator ) override;
242 virtual css::uno::Reference< css::frame::XFramesSupplier > SAL_CALL getCreator ( ) override;
243 virtual OUString SAL_CALL getName ( ) override;
244 virtual void SAL_CALL setName ( const OUString& sName ) override;
245 virtual sal_Bool SAL_CALL isTop ( ) override;
246 virtual void SAL_CALL activate ( ) override;
247 virtual void SAL_CALL deactivate ( ) override;
248 virtual sal_Bool SAL_CALL isActive ( ) override;
249 virtual sal_Bool SAL_CALL setComponent ( const css::uno::Reference< css::awt::XWindow >& xComponentWindow ,
250 const css::uno::Reference< css::frame::XController >& xController ) override;
251 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getComponentWindow ( ) override;
252 virtual css::uno::Reference< css::frame::XController > SAL_CALL getController ( ) override;
253 virtual void SAL_CALL contextChanged ( ) override;
254 virtual void SAL_CALL addFrameActionListener ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener ) override;
255 virtual void SAL_CALL removeFrameActionListener ( const css::uno::Reference< css::frame::XFrameActionListener >& xListener ) override;
257 // XComponent
258 virtual void SAL_CALL disposing() override;
259 virtual void SAL_CALL addEventListener ( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
260 virtual void SAL_CALL removeEventListener ( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
262 // XDispatchResultListener
263 virtual void SAL_CALL dispatchFinished ( const css::frame::DispatchResultEvent& aEvent ) override;
265 // XEventListener
266 virtual void SAL_CALL disposing ( const css::lang::EventObject& aSource ) override;
268 // XInteractionHandler
269 virtual void SAL_CALL handle ( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) override;
271 // css.frame.XUntitledNumbers
272 virtual ::sal_Int32 SAL_CALL leaseNumber( const css::uno::Reference< css::uno::XInterface >& xComponent ) override;
274 // css.frame.XUntitledNumbers
275 virtual void SAL_CALL releaseNumber( ::sal_Int32 nNumber ) override;
277 // css.frame.XUntitledNumbers
278 virtual void SAL_CALL releaseNumberForComponent( const css::uno::Reference< css::uno::XInterface >& xComponent ) override;
280 // css.frame.XUntitledNumbers
281 virtual OUString SAL_CALL getUntitledPrefix() override;
283 // we need this wrapped terminate()-call to terminate even the QuickStarter
284 // non-virtual and non-UNO for now
285 /// @throws css::uno::RuntimeException
286 bool terminateQuickstarterToo();
288 void shutdown();
290 private:
291 // OPropertySetHelper
292 virtual sal_Bool SAL_CALL convertFastPropertyValue ( css::uno::Any& aConvertedValue ,
293 css::uno::Any& aOldValue ,
294 sal_Int32 nHandle ,
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;
304 css::uno::Reference< css::lang::XComponent > impl_getFrameComponent ( const css::uno::Reference< css::frame::XFrame >& xFrame ) const;
306 /** calls queryTermination() on every registered termination listener.
308 * Note: Only normal termination listener (registered in list m_aListenerContainer
309 * will be recognized here. Special listener like quick starter, pipe or others
310 * has to be handled explicitly !
312 * @param [out] lCalledListener
313 * every called listener will be returned here.
314 * Those list will be used to inform all called listener
315 * about cancel this termination request.
317 * @return true if no one vetoed the termination.
319 * @see impl_sendCancelTerminationEvent()
321 bool impl_sendQueryTerminationEvent(TTerminateListenerList& lCalledListener);
323 /** calls cancelTermination() on every termination listener
324 * where queryTermination() was called before.
326 * Note: Only normal termination listener (registered in list m_aListenerContainer
327 * will be recognized here. Special listener like quick starter, pipe or others
328 * has to be handled explicitly !
330 * @param [in] lCalledListener
331 * every listener in this list was called within its method
332 * queryTermination() before.
334 * @see impl_sendQueryTerminationEvent()
336 void impl_sendCancelTerminationEvent(const TTerminateListenerList& lCalledListener);
338 /** calls notifyTermination() on the clipboard listener
340 * The system clipboard may decide that it wants copies
341 * in several formats of the clipboard content requiring
342 * nearly all the services
345 void impl_sendTerminateToClipboard();
347 /** calls notifyTermination() on every registered termination listener.
349 * Note: Only normal termination listener (registered in list m_aListenerContainer
350 * will be recognized here. Special listener like quick starter, pipe or others
351 * has to be handled explicitly !
353 void impl_sendNotifyTerminationEvent();
355 /** try to close all open frames.
357 * Iterates over all child frames and try to close them.
358 * Given parameter bAllowUI enable/disable showing any UI
359 * (which mostly occur on calling XController->suspend()).
361 * This method doesn't stop if one frame could not be closed.
362 * It will ignore such frames and try all other ones.
363 * But it returns false in such case - true otherwise.
365 * @param bAllowUI
366 * enable/disable showing of UI.
368 * @return true if all frames could be closed; false otherwise.
370 bool impl_closeFrames(bool bAllowUI);
372 private:
374 mutable TransactionManager m_aTransactionManager;
376 /** check flag to protect against multiple terminate runs
378 bool m_bIsTerminated;
380 /** check flag to protect us against dispose before terminate!
381 * see dispose() for further information!
383 bool m_bIsShutdown;
385 /** when true, the call came from 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
390 * can be only once.
391 * In Desktop::impl_closeFrames would be test and break
392 * the loop and reset to false
394 bool m_bSession;
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 comphelper::OMultiTypeInterfaceContainerHelper2 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 bool m_bSuspendQuickstartVeto; /// don't ask quickstart for a veto
403 std::unique_ptr<SvtCommandOptions> m_xCommandOptions; /// ref counted class to support disabling commands defined by configuration file
404 OUString m_sName;
405 OUString m_sTitle;
406 css::uno::Reference< css::frame::XDispatchRecorderSupplier > m_xDispatchRecorderSupplier;
408 /** special terminate listener to close pipe and block external requests
409 * during/after termination process is/was running
411 css::uno::Reference< css::frame::XTerminateListener > m_xPipeTerminator;
413 /** special terminate listener shown inside system tray (quick starter)
414 * Will hinder the office on shutdown ... but wish to allow closing
415 * of open documents. And because that's different to a normal terminate listener
416 * it has to be handled special .-)
418 css::uno::Reference< css::frame::XTerminateListener > m_xQuickLauncher;
420 /** special terminate listener which loads images asynchronous for current open documents.
421 * Because internally it uses blocking system APIs... it can't be guaranteed that
422 * running jobs can be cancelled successfully if the corresponding document will be closed...
423 * it will not hinder those documents on closing. Instead it let all jobs running...
424 * but at least on terminate we have to wait for all those blocked requests.
425 * So these implementation must be a special terminate listener too .-(
427 css::uno::Reference< css::frame::XTerminateListener > m_xSWThreadManager;
429 /** special terminate listener shutting down the SfxApplication.
430 * Because these desktop instance closes documents and informs listener
431 * only... it does not really shutdown the whole application.
433 * Btw: that wouldn't be possible by design... because Desktop.terminate()
434 * has to return a boolean value about success... it can't really shutdown the
435 * process .-)
437 * So we uses a trick: a special listener (exactly these one here) listen for notifyTermination()
438 * and shutdown the process asynchronous. But desktop has to make this special
439 * notification as really last one ... Otherwise it can happen that asynchronous
440 * shutdown will be faster then all other code around Desktop.terminate() .-))
442 css::uno::Reference< css::frame::XTerminateListener > m_xSfxTerminator;
444 css::uno::Reference< css::frame::XUntitledNumbers > m_xTitleNumberGenerator;
446 std::vector<css::uno::Reference<css::frame::XTerminateListener>> m_xComponentDllListeners;
448 }; // class Desktop
450 FWK_DLLPUBLIC const rtl::Reference<Desktop> & getDesktop(
451 css::uno::Reference<css::uno::XComponentContext> const & context);
453 } // namespace framework
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */