update dev300-m58
[ooovba.git] / framework / source / interaction / preventduplicateinteraction.cxx
blobbd97ef1d2a9fe0fa860703940abf046875b09879
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: preventduplicateinteraction.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 #include "interaction/preventduplicateinteraction.hxx"
36 //_________________________________________________________________________________________________________________
37 // my own includes
38 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
41 // interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/task/XInteractionAbort.hpp>
44 #include <com/sun/star/task/XInteractionRetry.hpp>
46 //_________________________________________________________________________________________________________________
47 // other includes
48 //_________________________________________________________________________________________________________________
50 //_________________________________________________________________________________________________________________
51 // namespace
52 //_________________________________________________________________________________________________________________
54 namespace framework{
56 namespace css = ::com::sun::star;
58 //_________________________________________________________________________________________________________________
59 // exported const
60 //_________________________________________________________________________________________________________________
62 #define IMPLEMENTATIONNAME_UIINTERACTIONHANDLER ::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")
64 //_________________________________________________________________________________________________________________
65 // exported definitions
66 //_________________________________________________________________________________________________________________
68 //_________________________________________________________________________________________________________________
70 PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
71 : ThreadHelpBase2()
72 , m_xSMGR(xSMGR)
76 //_________________________________________________________________________________________________________________
78 PreventDuplicateInteraction::~PreventDuplicateInteraction()
82 //_________________________________________________________________________________________________________________
84 void PreventDuplicateInteraction::setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
86 // SAFE ->
87 ::osl::ResettableMutexGuard aLock(m_aLock);
88 m_xHandler = xHandler;
89 aLock.clear();
90 // <- SAFE
93 //_________________________________________________________________________________________________________________
95 void PreventDuplicateInteraction::useDefaultUUIHandler()
97 // SAFE ->
98 ::osl::ResettableMutexGuard aLock(m_aLock);
99 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
100 aLock.clear();
101 // <- SAFE
103 css::uno::Reference< css::task::XInteractionHandler > xHandler(
104 xSMGR->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER),
105 css::uno::UNO_QUERY_THROW);
107 // SAFE ->
108 aLock.reset();
109 m_xHandler = xHandler;
110 aLock.clear();
111 // <- SAFE
114 //_________________________________________________________________________________________________________________
116 void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
117 throw(css::uno::RuntimeException)
119 css::uno::Any aRequest = xRequest->getRequest();
120 sal_Bool bHandleIt = sal_True;
122 // SAFE ->
123 ::osl::ResettableMutexGuard aLock(m_aLock);
125 InteractionList::iterator pIt;
126 for ( pIt = m_lInteractionRules.begin();
127 pIt != m_lInteractionRules.end() ;
128 ++pIt )
130 InteractionInfo& rInfo = *pIt;
132 if (aRequest.isExtractableTo(rInfo.m_aInteraction))
134 ++rInfo.m_nCallCount;
135 rInfo.m_xRequest = xRequest;
136 bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
137 break;
141 css::uno::Reference< css::task::XInteractionHandler > xHandler = m_xHandler;
143 aLock.clear();
144 // <- SAFE
146 if (
147 (bHandleIt ) &&
148 (xHandler.is())
151 xHandler->handle(xRequest);
153 else
155 const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
156 sal_Int32 c = lContinuations.getLength();
157 sal_Int32 i = 0;
158 for (i=0; i<c; ++i)
160 css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
161 if (xAbort.is())
163 xAbort->select();
164 break;
170 //_________________________________________________________________________________________________________________
172 void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo)
174 // SAFE ->
175 ::osl::ResettableMutexGuard aLock(m_aLock);
177 InteractionList::iterator pIt;
178 for ( pIt = m_lInteractionRules.begin();
179 pIt != m_lInteractionRules.end() ;
180 ++pIt )
182 InteractionInfo& rInfo = *pIt;
183 if (rInfo.m_aInteraction == aInteractionInfo.m_aInteraction)
185 rInfo.m_nMaxCount = aInteractionInfo.m_nMaxCount ;
186 rInfo.m_nCallCount = aInteractionInfo.m_nCallCount;
187 return;
191 m_lInteractionRules.push_back(aInteractionInfo);
193 aLock.clear();
194 // <- SAFE
197 //_________________________________________________________________________________________________________________
199 sal_Bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type& aInteraction,
200 PreventDuplicateInteraction::InteractionInfo* pReturn ) const
202 // SAFE ->
203 ::osl::ResettableMutexGuard aLock(m_aLock);
205 PreventDuplicateInteraction::InteractionList::const_iterator pIt;
206 for ( pIt = m_lInteractionRules.begin();
207 pIt != m_lInteractionRules.end() ;
208 ++pIt )
210 const PreventDuplicateInteraction::InteractionInfo& rInfo = *pIt;
211 if (rInfo.m_aInteraction == aInteraction)
213 *pReturn = rInfo;
214 return sal_True;
218 aLock.clear();
219 // <- SAFE
221 return sal_False;
224 } // namespace framework