fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucbhelper / source / client / interceptedinteraction.cxx
blob284751f378bf68931497002beba515886e2f97e6
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 <ucbhelper/interceptedinteraction.hxx>
22 #include <osl/diagnose.h>
24 namespace ucbhelper{
26 InterceptedInteraction::InterceptedInteraction()
30 void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference< css::task::XInteractionHandler >& xInterceptedHandler)
32 m_xInterceptedHandler = xInterceptedHandler;
35 void InterceptedInteraction::setInterceptions(const ::std::vector< InterceptedRequest >& lInterceptions)
37 m_lInterceptions = lInterceptions;
40 InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
41 const InterceptedRequest&,
42 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >&)
44 // default behaviour! see impl_interceptRequest() for further information ...
45 return E_NOT_INTERCEPTED;
48 css::uno::Reference< css::task::XInteractionContinuation > InterceptedInteraction::extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations,
49 const css::uno::Type& aType )
51 const css::uno::Reference< css::task::XInteractionContinuation >* pContinuations = lContinuations.getConstArray();
53 sal_Int32 c = lContinuations.getLength();
54 sal_Int32 i = 0;
56 for (i=0; i<c; ++i)
58 css::uno::Reference< css::uno::XInterface > xCheck(pContinuations[i], css::uno::UNO_QUERY);
59 if (xCheck->queryInterface(aType).hasValue())
60 return pContinuations[i];
63 return css::uno::Reference< css::task::XInteractionContinuation >();
66 void SAL_CALL InterceptedInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
67 throw(css::uno::RuntimeException, std::exception)
69 impl_handleDefault(xRequest);
72 void InterceptedInteraction::impl_handleDefault(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
74 EInterceptionState eState = impl_interceptRequest(xRequest);
76 switch(eState)
78 case E_NOT_INTERCEPTED:
80 // Non of the intercepted requests match to the given one.
81 // => forward request to the internal wrapped handler - if there is one.
82 if (m_xInterceptedHandler.is())
83 m_xInterceptedHandler->handle(xRequest);
85 break;
87 case E_NO_CONTINUATION_FOUND:
89 // Runtime error! The defined continuation could not be located
90 // inside the set of available containuations of the incoming request.
91 // Whats wrong - the interception list or the request?
92 OSL_FAIL("InterceptedInteraction::handle()\nCould intercept this interaction request - but can't locate the right continuation!");
94 break;
96 case E_INTERCEPTED:
97 break;
101 InterceptedInteraction::EInterceptionState InterceptedInteraction::impl_interceptRequest(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
103 css::uno::Any aRequest = xRequest->getRequest();
104 css::uno::Type aRequestType = aRequest.getValueType();
105 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
107 // check against the list of static requests
108 sal_Int32 nHandle = 0;
109 ::std::vector< InterceptedRequest >::const_iterator pIt;
110 for ( pIt = m_lInterceptions.begin();
111 pIt != m_lInterceptions.end() ;
112 ++pIt )
114 const InterceptedRequest& rInterception = *pIt;
115 css::uno::Type aInterceptedType = rInterception.Request.getValueType();
117 // check the request
118 bool bMatch = false;
119 if (rInterception.MatchExact)
120 bMatch = aInterceptedType.equals(aRequestType);
121 else
122 bMatch = aInterceptedType.isAssignableFrom(aRequestType); // dont change intercepted and request type here -> it will check the wrong direction!
124 // intercepted ...
125 // Call they might existing derived class, so they can handle that by its own.
126 // If its not interested on that (may be its not overwritten and the default implementation
127 // returns E_NOT_INTERCEPTED as default) -> break this loop and search for the right continuation.
128 if (bMatch)
130 EInterceptionState eState = intercepted(rInterception, xRequest);
131 if (eState == E_NOT_INTERCEPTED)
132 break;
133 return eState;
136 ++nHandle;
139 if (pIt != m_lInterceptions.end()) // => can be true only if bMatch=TRUE!
141 // match -> search required continuation
142 const InterceptedRequest& rInterception = *pIt;
143 css::uno::Reference< css::task::XInteractionContinuation > xContinuation = InterceptedInteraction::extractContinuation(lContinuations, rInterception.Continuation);
144 if (xContinuation.is())
146 xContinuation->select();
147 return E_INTERCEPTED;
150 // Can be reached only, if the request does not support the given continuation!
151 // => RuntimeError!?
152 return E_NO_CONTINUATION_FOUND;
155 return E_NOT_INTERCEPTED;
158 } // namespace ucbhelper
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */