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_PREVENTDUPLICATEINTERACTION_HXX
21 #define INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
23 #include <framework/fwedllapi.h>
27 #include <com/sun/star/task/XInteractionHandler2.hpp>
28 #include <com/sun/star/task/XInteractionRequest.hpp>
30 #include <cppuhelper/implbase1.hxx>
35 @short Prevent us from showing the same interaction more then once during
38 @descr Every interaction provided to this helper will be safed ... handled by the internal
39 used UUIInteractionHandler (!) and never be handled a second time!
41 On the other side there exists some interactions, which allow a retry.
42 So this helper allow to set a list of interactions combined with a retry value.
44 struct ThreadHelpBase2
47 mutable ::osl::Mutex m_aLock
;
50 class FWE_DLLPUBLIC PreventDuplicateInteraction
: private ThreadHelpBase2
51 ,public ::cppu::WeakImplHelper1
< css::task::XInteractionHandler2
>
53 //_____________________________________
54 // structs, types etcp.
57 struct InteractionInfo
60 /// describe the interaction.
61 css::uno::Type m_aInteraction
;
62 /// after max count was reached this interaction will be blocked.
63 sal_Int32 m_nMaxCount
;
64 /// count how often this interaction was called.
65 sal_Int32 m_nCallCount
;
66 /** hold the last intercepted request (matching the set interaction type) alive
67 so it can be used for further checks */
68 css::uno::Reference
< css::task::XInteractionRequest
> m_xRequest
;
72 InteractionInfo(const css::uno::Type
& aInteraction
,
74 : m_aInteraction(aInteraction
)
75 , m_nMaxCount (nMaxCount
)
79 InteractionInfo(const InteractionInfo
& aCopy
)
80 : m_aInteraction(aCopy
.m_aInteraction
)
81 , m_nMaxCount (aCopy
.m_nMaxCount
)
82 , m_nCallCount (aCopy
.m_nCallCount
)
83 , m_xRequest (aCopy
.m_xRequest
)
87 typedef ::std::vector
< InteractionInfo
> InteractionList
;
89 //_____________________________________
93 /// Used to create needed uno services at runtime.
94 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
96 /** The outside interaction handler, which is used to handle every incoming interaction,
97 if it's not blocked. */
98 css::uno::Reference
< css::task::XInteractionHandler
> m_xHandler
;
100 /** This list describe which and how incoming interactions must be handled.
101 Further it contains all collected information after this interaction
103 InteractionList m_lInteractionRules
;
105 //_____________________________________
109 //_________________________________
111 @interface XInteractionHandler
112 @short called from outside to handle a problem
113 @descr We filter the incoming interactions. some of them
114 will be forwarded to the generic UI interaction handler.
115 So we must not implement it twice. Some other ones
116 will be aborted only.
120 virtual void SAL_CALL
handle(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
121 throw(css::uno::RuntimeException
);
123 //_________________________________
125 @interface XInteractionHandler2
126 @short called from outside to handle a problem
127 @descr We filter the incoming interactions. some of them
128 will be forwarded to the generic UI interaction handler.
129 So we must not implement it twice. Some other ones
130 will be aborted only.
134 virtual ::sal_Bool SAL_CALL
handleInteractionRequest( const ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionRequest
>& xRequest
)
135 throw (::com::sun::star::uno::RuntimeException
);
137 //_________________________________
139 @interface XInterface
140 @short called to query another interface of the component
141 @descr Will allow to query for XInteractionHandler2 if and only if m_xHandler supports this interface, too.
145 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& aType
)
146 throw (::com::sun::star::uno::RuntimeException
);
147 //_____________________________________
151 //_________________________________
153 @short ctor to guarantee right initialized instances of this class
154 @descr It uses the given uno service manager to create the global
155 generic UI interaction handler for later internal using.
158 uno service manager for creating services internaly
160 @threadsafe not neccessary
162 PreventDuplicateInteraction(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
164 //_________________________________
166 @short dtor to free used memory.
168 virtual ~PreventDuplicateInteraction();
170 //_________________________________
172 @short set the outside interaction handler, which must be used internaly
173 if the interaction will not be blocked by the set list of rules.
175 @note This overwrites the settings of e.g. useDefaultUUIHandler()!
178 the new interaction handler
180 virtual void setHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
);
182 //_________________________________
184 @short instead of setting an outside interaction handler, this method
185 make sure the default UUI interaction handler of the office is used.
187 @note This overwrites the settings of e.g. setHandler()!
189 virtual void useDefaultUUIHandler();
191 //_________________________________
193 @short add a new interaction to the list of interactions, which
194 must be handled by this helper.
196 @descr This method must be called immediately after a new instance of this helper was
197 created. Without such list of InteractionRules, this instances does nothing!
198 On the other side there is no possibility to remove rules.
199 So the same instance cant be used within different transactions.
200 It's a OneWay-object .-)
202 @param aInteractionInfo
203 describe the type of interaction, hos often it can be called etcpp.
207 virtual void addInteractionRule(const PreventDuplicateInteraction::InteractionInfo
& aInteractionInfo
);
209 //_________________________________
211 @short return the info struct for the specified interaction.
214 specify the interaction.
217 provides information about:
218 - the count how often this interaction was handled during the
219 lifetime of this helper.
220 - the interaction itself, so it can be analyzed further
223 sal_True if the queried interaction could be found.
228 virtual sal_Bool
getInteractionInfo(const css::uno::Type
& aInteraction
,
229 PreventDuplicateInteraction::InteractionInfo
* pReturn
) const;
232 } // namespace framework
234 #endif // INCLUDED_FRAMEWORK_PREVENTDUPLICATEINTERACTION_HXX
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */