1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: preventduplicateinteraction.cxx,v $
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 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 //_________________________________________________________________________________________________________________
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/task/XInteractionAbort.hpp>
44 #include <com/sun/star/task/XInteractionRetry.hpp>
46 //_________________________________________________________________________________________________________________
48 //_________________________________________________________________________________________________________________
50 //_________________________________________________________________________________________________________________
52 //_________________________________________________________________________________________________________________
56 namespace css
= ::com::sun::star
;
58 //_________________________________________________________________________________________________________________
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
)
76 //_________________________________________________________________________________________________________________
78 PreventDuplicateInteraction::~PreventDuplicateInteraction()
82 //_________________________________________________________________________________________________________________
84 void PreventDuplicateInteraction::setHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
)
87 ::osl::ResettableMutexGuard
aLock(m_aLock
);
88 m_xHandler
= xHandler
;
93 //_________________________________________________________________________________________________________________
95 void PreventDuplicateInteraction::useDefaultUUIHandler()
98 ::osl::ResettableMutexGuard
aLock(m_aLock
);
99 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
103 css::uno::Reference
< css::task::XInteractionHandler
> xHandler(
104 xSMGR
->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER
),
105 css::uno::UNO_QUERY_THROW
);
109 m_xHandler
= xHandler
;
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
;
123 ::osl::ResettableMutexGuard
aLock(m_aLock
);
125 InteractionList::iterator pIt
;
126 for ( pIt
= m_lInteractionRules
.begin();
127 pIt
!= m_lInteractionRules
.end() ;
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
);
141 css::uno::Reference
< css::task::XInteractionHandler
> xHandler
= m_xHandler
;
151 xHandler
->handle(xRequest
);
155 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
156 sal_Int32 c
= lContinuations
.getLength();
160 css::uno::Reference
< css::task::XInteractionAbort
> xAbort(lContinuations
[i
], css::uno::UNO_QUERY
);
170 //_________________________________________________________________________________________________________________
172 void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo
& aInteractionInfo
)
175 ::osl::ResettableMutexGuard
aLock(m_aLock
);
177 InteractionList::iterator pIt
;
178 for ( pIt
= m_lInteractionRules
.begin();
179 pIt
!= m_lInteractionRules
.end() ;
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
;
191 m_lInteractionRules
.push_back(aInteractionInfo
);
197 //_________________________________________________________________________________________________________________
199 sal_Bool
PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type
& aInteraction
,
200 PreventDuplicateInteraction::InteractionInfo
* pReturn
) const
203 ::osl::ResettableMutexGuard
aLock(m_aLock
);
205 PreventDuplicateInteraction::InteractionList::const_iterator pIt
;
206 for ( pIt
= m_lInteractionRules
.begin();
207 pIt
!= m_lInteractionRules
.end() ;
210 const PreventDuplicateInteraction::InteractionInfo
& rInfo
= *pIt
;
211 if (rInfo
.m_aInteraction
== aInteraction
)
224 } // namespace framework