Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
21 : #define INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include <map>
26 :
27 : #include <comphelper/proxyaggregation.hxx>
28 : #include <com/sun/star/accessibility/XAccessible.hpp>
29 : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
30 : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
31 : #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
32 : #include <cppuhelper/compbase3.hxx>
33 : #include <cppuhelper/compbase2.hxx>
34 : #include <com/sun/star/lang/XComponent.hpp>
35 : #include <cppuhelper/implbase2.hxx>
36 : #include <cppuhelper/implbase1.hxx>
37 : #include <comphelper/sequence.hxx>
38 : #include <comphelper/uno3.hxx>
39 : #include <cppuhelper/interfacecontainer.hxx>
40 : #include <comphelper/broadcasthelper.hxx>
41 : #include <comphelper/accessibleeventnotifier.hxx>
42 : #include <comphelper/stl_types.hxx>
43 : #include <comphelper/comphelperdllapi.h>
44 :
45 :
46 : namespace comphelper
47 : {
48 :
49 :
50 :
51 : //= OAccessibleWrapper
52 :
53 :
54 : class OAccessibleContextWrapper;
55 : class OWrappedAccessibleChildrenManager;
56 :
57 412 : struct OAccessibleWrapper_Base :
58 : public ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessible >
59 : {
60 : protected:
61 32 : ~OAccessibleWrapper_Base() {}
62 : };
63 :
64 : /** a class which aggregates a proxy for an XAccessible, and wrapping the context returned by this
65 : XAccessible.
66 : */
67 : class COMPHELPER_DLLPUBLIC OAccessibleWrapper:public OAccessibleWrapper_Base
68 : ,public OComponentProxyAggregation
69 :
70 : {
71 : private:
72 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
73 : m_xParentAccessible;
74 : ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessibleContext >
75 : m_aContext;
76 :
77 : protected:
78 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
79 : m_xInnerAccessible;
80 :
81 : public:
82 : /** ctor
83 : @param _rxContext
84 : a service factory
85 :
86 : @param _rxInnerAccessible
87 : the object to wrap
88 :
89 : @param _rxParentAccessible
90 : The XAccessible which is our parent
91 : */
92 : OAccessibleWrapper(
93 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
94 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxInnerAccessible,
95 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible
96 : );
97 : DECLARE_XINTERFACE()
98 : DECLARE_XTYPEPROVIDER()
99 :
100 : // returns the context without creating it
101 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
102 : getContextNoCreate( ) const;
103 :
104 : protected:
105 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
106 : getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 :
108 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
109 20 : getParent() const { return m_xParentAccessible; }
110 :
111 : // own overridables
112 : virtual OAccessibleContextWrapper* createAccessibleContext(
113 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerContext
114 : );
115 :
116 : protected:
117 : virtual ~OAccessibleWrapper( );
118 :
119 : private:
120 : COMPHELPER_DLLPRIVATE OAccessibleWrapper( ); // never implemented
121 : COMPHELPER_DLLPRIVATE OAccessibleWrapper( const OAccessibleWrapper& ); // never implemented
122 : COMPHELPER_DLLPRIVATE OAccessibleWrapper& operator=( const OAccessibleWrapper& ); // never implemented
123 : };
124 :
125 :
126 : //= OAccessibleContextWrapperHelper
127 :
128 :
129 : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessibleEventListener
130 : > OAccessibleContextWrapperHelper_Base;
131 :
132 : /** Helper for wrapping an XAccessibleContext by aggregating a proxy for it.
133 :
134 : <p>This class does not have own ref counting. In addition, it does not implement
135 : the XAccesibleContext interface, but provides all the methods from this interface
136 : which must be implemented using the inner context (such as getAccessibleChild*).</p>
137 :
138 : <p>Children of the aggregated XAccessibleContext are wrapped, too.</p>
139 :
140 : <p>AccessibleEvents fired by the inner context are multiplexed, especially, any references to
141 : children in such events are translated. This means that even in such events, no un-wrapped object
142 : will ever leave this class - if the aggregated context notifies an child event, the child passed
143 : to the event is wrapped</p>
144 :
145 : @seealso OAccessibleContextWrapper
146 : */
147 : class COMPHELPER_DLLPUBLIC OAccessibleContextWrapperHelper
148 : :private OComponentProxyAggregationHelper
149 : ,public OAccessibleContextWrapperHelper_Base
150 : {
151 : protected:
152 : /// the context we're wrapping (properly typed, in opposite to OComponentProxyAggregationHelper::m_xInner)
153 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
154 : m_xInnerContext;
155 : /// the XAccessible which created this context
156 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
157 : m_xOwningAccessible;
158 : /// the XAccessible which is to be returned in getAccessibleParent
159 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
160 : m_xParentAccessible;
161 :
162 : OWrappedAccessibleChildrenManager* m_pChildMapper; // for mapping children from our inner context to our callers
163 :
164 : protected:
165 : /** ctor
166 :
167 : @param _rxContext
168 : a service factory
169 :
170 : @param _rxInnerAccessibleContext
171 : the object to wrap
172 :
173 : @param _rxOwningAccessible
174 : The XAccessible which created this object. This is necessary because children
175 : of our wrapped context meed to be wrapped, too, and if they're asked for a parent,
176 : they of course should return the proper parent<br/>
177 : The object will be held with a hard reference
178 :
179 : @param _rxParentAccessible
180 : The XAccessible to return in the getAccessibleParent call
181 : */
182 : OAccessibleContextWrapperHelper(
183 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
184 : ::cppu::OBroadcastHelper& _rBHelper,
185 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
186 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxOwningAccessible,
187 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible
188 : );
189 :
190 : /// to be called from within your ctor - does the aggregation of a proxy for m_xInnerContext
191 : void aggregateProxy(
192 : oslInterlockedCount& _rRefCount,
193 : ::cppu::OWeakObject& _rDelegator
194 : );
195 :
196 : protected:
197 : // XInterface
198 : ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 :
200 : // XTypeProvider
201 : DECLARE_XTYPEPROVIDER( )
202 :
203 : // XAccessibleContext
204 : sal_Int32 baseGetAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception);
205 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > baseGetAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception);
206 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > baseGetAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception);
207 :
208 : // XAccessibleEventListener
209 : virtual void SAL_CALL notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
210 :
211 : // XEventListener
212 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
213 :
214 : // XComponent/OComponentProxyAggregationHelper
215 : virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
216 :
217 : // own overridables
218 : /** notify an accessible event which has been translated (if necessary)
219 :
220 : <p>Usually, you derive your clas from both OAccessibleContextWrapperHelper and XAccessibleEventBroadcaster,
221 : and simply call all your XAccessibleEventListener with the given event.</p>
222 :
223 : <p>The mutex of the BroadcastHelper passed to the instance's ctor is <em>not</em> locked when calling
224 : into this method</p>
225 : */
226 : virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent ) throw (::com::sun::star::uno::RuntimeException) = 0;
227 :
228 : protected:
229 : virtual ~OAccessibleContextWrapperHelper( );
230 :
231 : OAccessibleContextWrapperHelper( ); // never implemented
232 : OAccessibleContextWrapperHelper( const OAccessibleContextWrapperHelper& ); // never implemented
233 : OAccessibleContextWrapperHelper& operator=( const OAccessibleContextWrapperHelper& ); // never implemented
234 : };
235 :
236 :
237 : //= OAccessibleContextWrapper
238 :
239 : typedef ::cppu::PartialWeakComponentImplHelper2< ::com::sun::star::accessibility::XAccessibleEventBroadcaster
240 : , ::com::sun::star::accessibility::XAccessibleContext
241 : > OAccessibleContextWrapper_CBase;
242 :
243 : class COMPHELPER_DLLPUBLIC OAccessibleContextWrapper
244 : :public OBaseMutex
245 : ,public OAccessibleContextWrapper_CBase
246 : ,public OAccessibleContextWrapperHelper
247 : {
248 : private:
249 : ::comphelper::AccessibleEventNotifier::TClientId m_nNotifierClient; // for notifying AccessibleEvents
250 :
251 : public:
252 : /** ctor
253 :
254 : @param _rxContext
255 : a service factory
256 :
257 : @param _rxInnerAccessibleContext
258 : the object to wrap
259 :
260 : @param _rxOwningAccessible
261 : The XAccessible which created this object. This is necessary because children
262 : of our wrapped context meed to be wrapped, too, and if they're asked for a parent,
263 : they of course should return the proper parent<br/>
264 : The object will be held with a hard reference
265 :
266 : @param _rxParentAccessible
267 : The XAccessible to return in the getAccessibleParent call
268 : */
269 : OAccessibleContextWrapper(
270 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
271 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
272 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxOwningAccessible,
273 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible
274 : );
275 :
276 : // XInterface
277 : DECLARE_XINTERFACE( )
278 : // XTypeProvider
279 : DECLARE_XTYPEPROVIDER( )
280 :
281 : // XAccessibleContext
282 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
283 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
284 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
285 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
286 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
287 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
288 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
289 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
290 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
291 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
292 :
293 : // XAccessibleEventBroadcaster
294 : virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
295 : virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
296 :
297 : // OAccessibleContextWrapper
298 : virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
299 :
300 : // XComponent
301 : virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
302 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
303 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
304 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
305 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
306 :
307 : // OComponentHelper
308 : using OAccessibleContextWrapperHelper::disposing;
309 : virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
310 :
311 : protected:
312 : virtual ~OAccessibleContextWrapper();
313 :
314 : private:
315 : COMPHELPER_DLLPRIVATE OAccessibleContextWrapper(); // never implemented
316 : COMPHELPER_DLLPRIVATE OAccessibleContextWrapper( const OAccessibleContextWrapper& ); // never implemented
317 : COMPHELPER_DLLPRIVATE OAccessibleContextWrapper& operator=( const OAccessibleContextWrapper& ); // never implemented
318 : };
319 :
320 :
321 : //= OWrappedAccessibleChildrenManager
322 :
323 :
324 : typedef ::std::map < ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
325 : , ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
326 : , OInterfaceCompare< ::com::sun::star::accessibility::XAccessible >
327 : > AccessibleMap;
328 : // TODO: think about if we should hold these objects weak
329 :
330 : typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener
331 : > OWrappedAccessibleChildrenManager_Base;
332 : /** manages wrapping XAccessible's to XAccessible's
333 : */
334 : class COMPHELPER_DLLPUBLIC OWrappedAccessibleChildrenManager : public OWrappedAccessibleChildrenManager_Base
335 : {
336 : protected:
337 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
338 : m_xContext;
339 : ::com::sun::star::uno::WeakReference< ::com::sun::star::accessibility::XAccessible >
340 : m_aOwningAccessible; // the XAccessible which belongs to the XAccessibleContext which we work for
341 : AccessibleMap m_aChildrenMap; // for caching children
342 : bool m_bTransientChildren; // are we prohibited to cache our children?
343 :
344 : public:
345 : /// ctor
346 : OWrappedAccessibleChildrenManager(
347 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
348 : );
349 :
350 : /** specifies if the children are to be consideren transient (i.e.: not cached)
351 : <p>to be called only once per lifetime</p>
352 : */
353 : void setTransientChildren( bool _bSet = true );
354 :
355 : /** sets the XAccessible which belongs to the XAccessibleContext which we work for
356 : <p>to be called only once per lifetime</p>
357 : */
358 : void setOwningAccessible( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxAcc );
359 :
360 : /// retrieves a wrapper for the given accessible
361 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
362 : getAccessibleWrapperFor(
363 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxKey,
364 : bool _bCreate = true
365 : );
366 :
367 : /// erases the given key from the map (if it is present there)
368 : void removeFromCache( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxKey );
369 :
370 : /// invalidates (i.e. empties) the map
371 : void invalidateAll( );
372 :
373 : /** disposes (i.e. cleares) the manager
374 :
375 : <p>Note that the XAccessibleContext's of the mapped XAccessible objects are disposed, too.</p>
376 : */
377 : void dispose();
378 :
379 : /** handles a notification as got from the parent of the children we're managing
380 : <p>This applies only to the notifications which have a direct impact on our map.</p>
381 : */
382 : void handleChildNotification( const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent );
383 :
384 : /** translates events as got from the parent of the children we're managing
385 : <p>This applies only to the notifications which deal with child objects which we manage.</p>
386 : */
387 : void translateAccessibleEvent(
388 : const ::com::sun::star::accessibility::AccessibleEventObject& _rEvent,
389 : ::com::sun::star::accessibility::AccessibleEventObject& _rTranslatedEvent
390 : );
391 :
392 : protected:
393 : // XEventListener
394 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
395 :
396 : protected:
397 : void implTranslateChildEventValue( const ::com::sun::star::uno::Any& _rInValue, ::com::sun::star::uno::Any& _rOutValue );
398 :
399 : protected:
400 : virtual ~OWrappedAccessibleChildrenManager( );
401 :
402 : private:
403 : COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager( ); // never implemented
404 : COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager( const OWrappedAccessibleChildrenManager& ); // never implemented
405 : COMPHELPER_DLLPRIVATE OWrappedAccessibleChildrenManager& operator=( const OWrappedAccessibleChildrenManager& ); // never implemented
406 : };
407 :
408 :
409 : } // namespace accessibility
410 :
411 :
412 : #endif // INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
413 :
414 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|