fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwe / interaction / preventduplicateinteraction.cxx
blobc4a62bbf3d8bc21b69718e0358b8de5498c0ea4a
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 #include <framework/preventduplicateinteraction.hxx>
22 #include <osl/diagnose.h>
24 #include <com/sun/star/task/InteractionHandler.hpp>
25 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionRetry.hpp>
28 namespace framework{
30 PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
31 : ThreadHelpBase2()
32 , m_xContext(rxContext)
36 PreventDuplicateInteraction::~PreventDuplicateInteraction()
40 void PreventDuplicateInteraction::setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
42 // SAFE ->
43 ::osl::ResettableMutexGuard aLock(m_aLock);
44 m_xHandler = xHandler;
45 aLock.clear();
46 // <- SAFE
49 void PreventDuplicateInteraction::useDefaultUUIHandler()
51 // SAFE ->
52 ::osl::ResettableMutexGuard aLock(m_aLock);
53 aLock.clear();
54 // <- SAFE
56 css::uno::Reference< css::task::XInteractionHandler > xHandler( css::task::InteractionHandler::createWithParent( m_xContext, 0 ), css::uno::UNO_QUERY_THROW );
58 // SAFE ->
59 aLock.reset();
60 m_xHandler = xHandler;
61 aLock.clear();
62 // <- SAFE
65 css::uno::Any SAL_CALL PreventDuplicateInteraction::queryInterface( const css::uno::Type& aType )
66 throw (css::uno::RuntimeException, std::exception)
68 if ( aType.equals( cppu::UnoType<XInteractionHandler2>::get() ) )
70 ::osl::ResettableMutexGuard aLock(m_aLock);
71 css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
72 if ( !xHandler.is() )
73 return css::uno::Any();
75 return ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >::queryInterface( aType );
78 void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
79 throw(css::uno::RuntimeException, std::exception)
81 css::uno::Any aRequest = xRequest->getRequest();
82 bool bHandleIt = true;
84 // SAFE ->
85 ::osl::ResettableMutexGuard aLock(m_aLock);
87 InteractionList::iterator pIt;
88 for ( pIt = m_lInteractionRules.begin();
89 pIt != m_lInteractionRules.end();
90 ++pIt )
92 InteractionInfo& rInfo = *pIt;
94 if (aRequest.isExtractableTo(rInfo.m_aInteraction))
96 ++rInfo.m_nCallCount;
97 rInfo.m_xRequest = xRequest;
98 bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
99 break;
103 css::uno::Reference< css::task::XInteractionHandler > xHandler = m_xHandler;
105 aLock.clear();
106 // <- SAFE
108 if (
109 (bHandleIt ) &&
110 (xHandler.is())
113 xHandler->handle(xRequest);
115 else
117 const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
118 sal_Int32 c = lContinuations.getLength();
119 sal_Int32 i = 0;
120 for (i=0; i<c; ++i)
122 css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
123 if (xAbort.is())
125 xAbort->select();
126 break;
132 sal_Bool SAL_CALL PreventDuplicateInteraction::handleInteractionRequest( const css::uno::Reference< css::task::XInteractionRequest >& xRequest )
133 throw (css::uno::RuntimeException, std::exception)
135 css::uno::Any aRequest = xRequest->getRequest();
136 bool bHandleIt = true;
138 // SAFE ->
139 ::osl::ResettableMutexGuard aLock(m_aLock);
141 InteractionList::iterator pIt;
142 for ( pIt = m_lInteractionRules.begin();
143 pIt != m_lInteractionRules.end();
144 ++pIt )
146 InteractionInfo& rInfo = *pIt;
148 if (aRequest.isExtractableTo(rInfo.m_aInteraction))
150 ++rInfo.m_nCallCount;
151 rInfo.m_xRequest = xRequest;
152 bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
153 break;
157 css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
158 OSL_ENSURE( xHandler.is() || !m_xHandler.is(),
159 "PreventDuplicateInteraction::handleInteractionRequest: inconsistency!" );
161 aLock.clear();
162 // <- SAFE
164 if (
165 (bHandleIt ) &&
166 (xHandler.is())
169 return xHandler->handleInteractionRequest(xRequest);
171 else
173 const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
174 sal_Int32 c = lContinuations.getLength();
175 sal_Int32 i = 0;
176 for (i=0; i<c; ++i)
178 css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
179 if (xAbort.is())
181 xAbort->select();
182 break;
186 return false;
189 void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo)
191 // SAFE ->
192 ::osl::ResettableMutexGuard aLock(m_aLock);
194 InteractionList::iterator pIt;
195 for ( pIt = m_lInteractionRules.begin();
196 pIt != m_lInteractionRules.end();
197 ++pIt )
199 InteractionInfo& rInfo = *pIt;
200 if (rInfo.m_aInteraction == aInteractionInfo.m_aInteraction)
202 rInfo.m_nMaxCount = aInteractionInfo.m_nMaxCount;
203 rInfo.m_nCallCount = aInteractionInfo.m_nCallCount;
204 return;
208 m_lInteractionRules.push_back(aInteractionInfo);
210 aLock.clear();
211 // <- SAFE
214 bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type& aInteraction,
215 PreventDuplicateInteraction::InteractionInfo* pReturn ) const
217 // SAFE ->
218 ::osl::ResettableMutexGuard aLock(m_aLock);
220 PreventDuplicateInteraction::InteractionList::const_iterator pIt;
221 for ( pIt = m_lInteractionRules.begin();
222 pIt != m_lInteractionRules.end();
223 ++pIt )
225 const PreventDuplicateInteraction::InteractionInfo& rInfo = *pIt;
226 if (rInfo.m_aInteraction == aInteraction)
228 *pReturn = rInfo;
229 return true;
233 aLock.clear();
234 // <- SAFE
236 return false;
239 } // namespace framework
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */