LibreOffice Module sfx2 (master) 1
preventduplicateinteraction.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
21#define INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
22
23#include <vector>
24
25#include <com/sun/star/frame/Desktop.hpp>
26#include <com/sun/star/frame/TerminationVetoException.hpp>
27#include <com/sun/star/lang/XInitialization.hpp>
28#include <com/sun/star/task/XInteractionHandler2.hpp>
29#include <com/sun/star/task/XInteractionRequest.hpp>
30
33
35#include <vcl/wrkwin.hxx>
36#include <vcl/svapp.hxx>
37#include <mutex>
38
39namespace com::sun::star::uno {
40 class XComponentContext;
41}
42
43namespace sfx2 {
44
45inline void closedialogs(SystemWindow& rTopLevel, bool bCloseRoot)
46{
47 for (vcl::Window *pChild = rTopLevel.GetWindow(GetWindowType::FirstTopWindowChild); pChild; pChild = rTopLevel.GetWindow(GetWindowType::NextTopWindowSibling))
48 closedialogs(dynamic_cast<SystemWindow&>(*pChild), true);
49 if (bCloseRoot)
50 rTopLevel.Close();
51}
52
53// This is intended to be the parent for any warning dialogs launched
54// during the load of a document so that those dialogs are modal to
55// this window and don't block any existing windows.
56//
57// If there are dialog children open on exit then veto termination,
58// close the topmost dialog and retry termination.
60 public comphelper::WeakComponentImplHelper<css::frame::XTerminateListener>
61{
62private:
64 css::uno::Reference<css::awt::XWindow> m_xInterface;
65
66private:
67
68 DECL_STATIC_LINK(WarningDialogsParent, TerminateDesktop, void*, void);
69
71 {
72 if (!m_xWin)
73 return;
74 SolarMutexGuard aSolarGuard;
75 closedialogs(*m_xWin, false);
76 }
77
78public:
79
81 virtual void SAL_CALL disposing(const css::lang::EventObject&) override
82 {
83 }
84
85 // XTerminateListener
86 virtual void SAL_CALL queryTermination(const css::lang::EventObject&) override
87 {
90 throw css::frame::TerminationVetoException();
91 }
92
93 virtual void SAL_CALL notifyTermination(const css::lang::EventObject&) override
94 {
95 }
96
97public:
99 {
100 SolarMutexGuard aSolarGuard;
102 m_xWin->SetText("dialog parent for warning dialogs during load");
104 }
105
106 virtual ~WarningDialogsParent() override
107 {
110 }
111
112 const css::uno::Reference<css::awt::XWindow>& GetDialogParent() const
113 {
114 return m_xInterface;
115 }
116};
117
119{
120private:
121 css::uno::Reference<css::frame::XDesktop> m_xDesktop;
123
124public:
125 WarningDialogsParentScope(const css::uno::Reference<css::uno::XComponentContext>& rContext)
126 : m_xDesktop(css::frame::Desktop::create(rContext), css::uno::UNO_QUERY_THROW)
128 {
129 m_xDesktop->addTerminateListener(m_xListener);
130 }
131
132 const css::uno::Reference<css::awt::XWindow>& GetDialogParent() const
133 {
134 return m_xListener->GetDialogParent();
135 }
136
138 {
139 m_xDesktop->removeTerminateListener(m_xListener);
140 }
141};
142
154 public ::cppu::WeakImplHelper<css::lang::XInitialization, css::task::XInteractionHandler2>
155{
156 mutable std::mutex m_aLock;
157
158 // structs, types etc.
159 public:
160
162 {
163 public:
165 css::uno::Type m_aInteraction;
167 sal_Int32 m_nMaxCount;
169 sal_Int32 m_nCallCount;
172 css::uno::Reference< css::task::XInteractionRequest > m_xRequest;
173
174 public:
175
176 InteractionInfo(const css::uno::Type& aInteraction)
177 : m_aInteraction(aInteraction)
178 , m_nMaxCount (1 )
179 , m_nCallCount (0 )
180 {}
181 };
182
183 // member
184 private:
185
187 css::uno::Reference< css::uno::XComponentContext > m_xContext;
188
191 css::uno::Reference< css::task::XInteractionHandler > m_xHandler;
192
193 std::unique_ptr<WarningDialogsParentScope> m_xWarningDialogsParent;
194
198 std::vector< InteractionInfo > m_lInteractionRules;
199
200
201 // uno interface
202 public:
203
204 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
205
216 virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest) override;
217
218
229 virtual sal_Bool SAL_CALL handleInteractionRequest( const css::uno::Reference< css::task::XInteractionRequest >& xRequest ) override;
230
231
239 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
240
241 // c++ interface
242 public:
243
244
255 PreventDuplicateInteraction(css::uno::Reference< css::uno::XComponentContext > xContext);
256
257
261 virtual ~PreventDuplicateInteraction() override;
262
263
273 void setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler);
274
275
283
284
301
302
321 bool getInteractionInfo(const css::uno::Type& aInteraction,
323};
324
325} // namespace sfx2
326
327#endif // INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
328
329/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
virtual bool Close()
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void disposing(std::unique_lock< std::mutex > &)
Prevent us from showing the same interaction more than once during the same transaction.
std::vector< InteractionInfo > m_lInteractionRules
This list describe which and how incoming interactions must be handled.
std::unique_ptr< WarningDialogsParentScope > m_xWarningDialogsParent
css::uno::Reference< css::uno::XComponentContext > m_xContext
Used to create needed uno services at runtime.
bool getInteractionInfo(const css::uno::Type &aInteraction, PreventDuplicateInteraction::InteractionInfo *pReturn) const
return the info struct for the specified interaction.
virtual ~PreventDuplicateInteraction() override
dtor to free used memory.
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
virtual sal_Bool SAL_CALL handleInteractionRequest(const css::uno::Reference< css::task::XInteractionRequest > &xRequest) override
css::uno::Reference< css::task::XInteractionHandler > m_xHandler
The outside interaction handler, which is used to handle every incoming interaction,...
void useDefaultUUIHandler()
instead of setting an outside interaction handler, this method make sure the default UUI interaction ...
void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo &aInteractionInfo)
add a new interaction to the list of interactions, which must be handled by this helper.
virtual void SAL_CALL handle(const css::uno::Reference< css::task::XInteractionRequest > &xRequest) override
void setHandler(const css::uno::Reference< css::task::XInteractionHandler > &xHandler)
set the outside interaction handler, which must be used internally if the interaction will not be blo...
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
PreventDuplicateInteraction(css::uno::Reference< css::uno::XComponentContext > xContext)
ctor to guarantee right initialized instances of this class @descr It uses the given uno service mana...
css::uno::Reference< css::frame::XDesktop > m_xDesktop
const css::uno::Reference< css::awt::XWindow > & GetDialogParent() const
WarningDialogsParentScope(const css::uno::Reference< css::uno::XComponentContext > &rContext)
rtl::Reference< WarningDialogsParent > m_xListener
DECL_STATIC_LINK(WarningDialogsParent, TerminateDesktop, void *, void)
css::uno::Reference< css::awt::XWindow > m_xInterface
virtual void SAL_CALL queryTermination(const css::lang::EventObject &) override
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &) override
const css::uno::Reference< css::awt::XWindow > & GetDialogParent() const
virtual void SAL_CALL disposing(const css::lang::EventObject &) override
vcl::Window * GetWindow(GetWindowType nType) const
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
void closedialogs(SystemWindow &rTopLevel, bool bCloseRoot)
sal_Int32 m_nCallCount
count how often this interaction was called.
sal_Int32 m_nMaxCount
after max count was reached this interaction will be blocked.
css::uno::Reference< css::task::XInteractionRequest > m_xRequest
hold the last intercepted request (matching the set interaction type) alive so it can be used for fur...
unsigned char sal_Bool
WinBits const WB_STDWORK