fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / inc / dispatch / interceptionhelper.hxx
blobe032017d280cacfb439fc618663beaf98b559f0a
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 #ifndef INCLUDED_FRAMEWORK_INC_DISPATCH_INTERCEPTIONHELPER_HXX
21 #define INCLUDED_FRAMEWORK_INC_DISPATCH_INTERCEPTIONHELPER_HXX
23 #include <macros/xinterface.hxx>
24 #include <macros/generic.hxx>
25 #include <general.h>
27 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
28 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
29 #include <com/sun/star/frame/XDispatchProvider.hpp>
30 #include <com/sun/star/frame/XDispatch.hpp>
31 #include <com/sun/star/frame/XFrame.hpp>
32 #include <com/sun/star/frame/DispatchDescriptor.hpp>
34 #include <tools/wldcrd.hxx>
35 #include <cppuhelper/implbase3.hxx>
36 #include <cppuhelper/weakref.hxx>
38 #include <deque>
40 namespace framework{
42 /** @short implements a helper to support interception with additional functionality.
44 @descr This helper implements the complete XDispatchProviderInterception interface with
45 master/slave functionality AND using of optional features like registration of URL pattern!
47 @attention Don't use this class as direct member - use it dynamicly. Do not derive from this class.
48 We hold a weakreference to our owner not to our superclass.
50 class InterceptionHelper : public ::cppu::WeakImplHelper3<
51 css::frame::XDispatchProvider,
52 css::frame::XDispatchProviderInterception,
53 css::lang::XEventListener >
56 // structs, helper
58 /** @short bind an interceptor component to its URL pattern registration. */
59 struct InterceptorInfo
61 /** @short reference to the interceptor component. */
62 css::uno::Reference< css::frame::XDispatchProvider > xInterceptor;
64 /** @short it's registration for URL patterns.
66 @descr If the interceptor component does not support the optional interface
67 XInterceptorInfo, it will be registered for one pattern "*" by default.
68 That would make it possible to handle it in the same manner then real
69 registered interceptor objects and we must not implement any special code. */
70 css::uno::Sequence< OUString > lURLPattern;
73 /** @short implements a list of items of type InterceptorInfo, and provides some special
74 functions on it.
76 @descr Because interceptor objects can be registered for URL patterns,
77 it supports a wildcard search on all list items.
79 class InterceptorList : public ::std::deque< InterceptorInfo >
81 public:
83 /** @short search for an interceptor inside this list using it's reference.
85 @param xInterceptor
86 points to the interceptor object, which should be located inside this list.
88 @return An iterator object, which points directly to the located item inside this list.
89 In case no interceptor could be found, it points to the end of this list!
91 iterator findByReference(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor)
93 css::uno::Reference< css::frame::XDispatchProviderInterceptor > xProviderInterface(xInterceptor, css::uno::UNO_QUERY);
94 iterator pIt;
95 for (pIt=begin(); pIt!=end(); ++pIt)
97 if (pIt->xInterceptor == xProviderInterface)
98 return pIt;
100 return end();
103 /** @short search for an interceptor inside this list using it's reference.
105 @param xInterceptor
106 points to the interceptor object, which should be located inside this list.
108 @return An iterator object, which points directly to the located item inside this list.
109 In case no interceptor could be found, it points to the end of this list!
111 iterator findByPattern(const OUString& sURL)
113 iterator pIt;
114 for (pIt=begin(); pIt!=end(); ++pIt)
116 sal_Int32 c = pIt->lURLPattern.getLength();
117 const OUString* pPattern = pIt->lURLPattern.getConstArray();
119 for (sal_Int32 i=0; i<c; ++i)
121 WildCard aPattern(pPattern[i]);
122 if (aPattern.Matches(sURL))
123 return pIt;
126 return end();
130 // member
132 private:
134 /** @short reference to the frame, which uses this instance to implement it's own interception.
136 @descr We hold a weak reference only, to make disposing operations easy. */
137 css::uno::WeakReference< css::frame::XFrame > m_xOwnerWeak;
139 /** @short this interception helper implements the top level master of an interceptor list ...
140 but this member is the lowest possible slave! */
141 css::uno::Reference< css::frame::XDispatchProvider > m_xSlave;
143 /** @short contains all registered interceptor objects. */
144 InterceptorList m_lInterceptionRegs;
146 /** @short it regulates, which interceptor is used first.
147 The last or the first registered one. */
148 static bool m_bPreferrFirstInterceptor;
150 // native interface
152 public:
154 /** @short creates a new interception helper instance.
156 @param xOwner
157 points to the frame, which use this instances to support it's own interception interfaces.
159 @param xSlave
160 an outside creates dispatch provider, which has to be used here as lowest slave "interceptor".
162 InterceptionHelper(const css::uno::Reference< css::frame::XFrame >& xOwner,
163 const css::uno::Reference< css::frame::XDispatchProvider >& xSlave);
165 protected:
167 /** @short standard destructor.
169 @descr This method destruct an instance of this class and clear some member.
170 This method is protected, because its not allowed to use this class as a direct member!
171 You MUST use a dynamical instance (pointer). That's the reason for a protected dtor.
173 virtual ~InterceptionHelper();
175 // uno interface
177 public:
179 // XDispatchProvider
181 /** @short query for a dispatch, which implements the requested feature.
183 @descr We search inside our list of interception registrations, to locate
184 any interested interceptor. In case no interceptor exists or nobody is
185 interested on this URL our lowest slave will be used.
187 @param aURL
188 describes the requested dispatch functionality.
190 @param sTargetFrameName
191 the name of the target frame or a special name like "_blank", "_top" ...
192 Won't be used here ... but may by one of our registered interceptor objects
193 or our slave.
195 @param nSearchFlags
196 optional search parameter for targeting, if sTargetFrameName isn't a special one.
198 @return A valid dispatch object, if any interceptor or at least our slave is interested on the given URL;
199 or NULL otherwise.
201 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL& aURL ,
202 const OUString& sTargetFrameName,
203 sal_Int32 nSearchFlags )
204 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
206 // XDispatchProvider
208 /** @short implements an optimized queryDispatch() for remote.
210 @descr It capsulate more than one queryDispatch() requests and return a lits of dispatch objects
211 as result. Because both lists (in and out) coreespond together, it's not allowed to
212 pack it - means suppress NULL references!
214 @param lDescriptor
215 a list of queryDispatch() arguments.
217 @return A list of dispatch objects.
219 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor)
220 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
222 // XDispatchProviderInterception
224 /** @short register an interceptor.
226 @descr Somebody can register himself to intercept all or some special dispatches.
227 It's depend from his supported interfaces. If he implement XInterceptorInfo
228 he his called for some special URLs only - otherwise we call it for every request!
230 @attention We don't check for double registrations here!
232 @param xInterceptor
233 reference to interceptor, which wish to be registered here.
235 @throw A RuntimeException if the given reference is NULL!
237 virtual void SAL_CALL registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor)
238 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
240 // XDispatchProviderInterception
242 /** @short release an interceptor.
244 @descr Remove the registered interceptor from our internal list
245 and delete all special information about it.
247 @param xInterceptor
248 reference to the interceptor, which wish to be deregistered.
250 @throw A RuntimeException if the given reference is NULL!
252 virtual void SAL_CALL releaseDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor ) throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
254 // XEventListener
256 /** @short Is called from our owner frame, in case he will be disposed.
258 @descr We have to relaease all references to him then.
259 Normally we will die by ref count too ...
261 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
262 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 }; // class InterceptionHelper
266 } // namespace framework
268 #endif // INCLUDED_FRAMEWORK_INC_DISPATCH_INTERCEPTIONHELPER_HXX
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */