1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_COMPHELPER_ACCESSIBLEWRAPPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
23 #include <sal/config.h>
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>
51 //= OAccessibleWrapper
54 class OAccessibleContextWrapper
;
55 class OWrappedAccessibleChildrenManager
;
57 struct OAccessibleWrapper_Base
:
58 public ::cppu::ImplHelper1
< ::com::sun::star::accessibility::XAccessible
>
61 ~OAccessibleWrapper_Base() {}
64 /** a class which aggregates a proxy for an XAccessible, and wrapping the context returned by this
67 class COMPHELPER_DLLPUBLIC OAccessibleWrapper
:public OAccessibleWrapper_Base
68 ,public OComponentProxyAggregation
72 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
74 ::com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessibleContext
>
78 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
86 @param _rxInnerAccessible
89 @param _rxParentAccessible
90 The XAccessible which is our parent
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
98 DECLARE_XTYPEPROVIDER()
100 // returns the context without creating it
101 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
102 getContextNoCreate( ) const;
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
;
108 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
109 getParent() const { return m_xParentAccessible
; }
112 virtual OAccessibleContextWrapper
* createAccessibleContext(
113 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>& _rxInnerContext
117 virtual ~OAccessibleWrapper( );
120 OAccessibleWrapper( const OAccessibleWrapper
& ) SAL_DELETED_FUNCTION
;
121 OAccessibleWrapper
& operator=( const OAccessibleWrapper
& ) SAL_DELETED_FUNCTION
;
125 //= OAccessibleContextWrapperHelper
128 typedef ::cppu::ImplHelper1
< ::com::sun::star::accessibility::XAccessibleEventListener
129 > OAccessibleContextWrapperHelper_Base
;
131 /** Helper for wrapping an XAccessibleContext by aggregating a proxy for it.
133 <p>This class does not have own ref counting. In addition, it does not implement
134 the XAccesibleContext interface, but provides all the methods from this interface
135 which must be implemented using the inner context (such as getAccessibleChild*).</p>
137 <p>Children of the aggregated XAccessibleContext are wrapped, too.</p>
139 <p>AccessibleEvents fired by the inner context are multiplexed, especially, any references to
140 children in such events are translated. This means that even in such events, no un-wrapped object
141 will ever leave this class - if the aggregated context notifies an child event, the child passed
142 to the event is wrapped</p>
144 @seealso OAccessibleContextWrapper
146 class COMPHELPER_DLLPUBLIC OAccessibleContextWrapperHelper
147 :private OComponentProxyAggregationHelper
148 ,public OAccessibleContextWrapperHelper_Base
151 /// the context we're wrapping (properly typed, in opposite to OComponentProxyAggregationHelper::m_xInner)
152 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
154 /// the XAccessible which created this context
155 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
157 /// the XAccessible which is to be returned in getAccessibleParent
158 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
161 OWrappedAccessibleChildrenManager
* m_pChildMapper
; // for mapping children from our inner context to our callers
169 @param _rxInnerAccessibleContext
172 @param _rxOwningAccessible
173 The XAccessible which created this object. This is necessary because children
174 of our wrapped context meed to be wrapped, too, and if they're asked for a parent,
175 they of course should return the proper parent<br/>
176 The object will be held with a hard reference
178 @param _rxParentAccessible
179 The XAccessible to return in the getAccessibleParent call
181 OAccessibleContextWrapperHelper(
182 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
183 ::cppu::OBroadcastHelper
& _rBHelper
,
184 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>& _rxInnerAccessibleContext
,
185 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxOwningAccessible
,
186 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxParentAccessible
189 /// to be called from within your ctor - does the aggregation of a proxy for m_xInnerContext
191 oslInterlockedCount
& _rRefCount
,
192 ::cppu::OWeakObject
& _rDelegator
197 ::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
;
200 DECLARE_XTYPEPROVIDER( )
202 // XAccessibleContext
203 sal_Int32
baseGetAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
);
204 ::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
);
205 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> baseGetAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
);
207 // XAccessibleEventListener
208 virtual void SAL_CALL
notifyEvent( const ::com::sun::star::accessibility::AccessibleEventObject
& aEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
211 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
213 // XComponent/OComponentProxyAggregationHelper
214 virtual void SAL_CALL
dispose() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
217 /** notify an accessible event which has been translated (if necessary)
219 <p>Usually, you derive your class from both OAccessibleContextWrapperHelper and XAccessibleEventBroadcaster,
220 and simply call all your XAccessibleEventListener with the given event.</p>
222 <p>The mutex of the BroadcastHelper passed to the instance's ctor is <em>not</em> locked when calling
225 virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject
& _rEvent
) throw (::com::sun::star::uno::RuntimeException
) = 0;
228 virtual ~OAccessibleContextWrapperHelper( );
230 OAccessibleContextWrapperHelper( ); // never implemented
231 OAccessibleContextWrapperHelper( const OAccessibleContextWrapperHelper
& ); // never implemented
232 OAccessibleContextWrapperHelper
& operator=( const OAccessibleContextWrapperHelper
& ); // never implemented
236 //= OAccessibleContextWrapper
238 typedef ::cppu::WeakComponentImplHelper2
< ::com::sun::star::accessibility::XAccessibleEventBroadcaster
239 , ::com::sun::star::accessibility::XAccessibleContext
240 > OAccessibleContextWrapper_CBase
;
242 class COMPHELPER_DLLPUBLIC OAccessibleContextWrapper
244 ,public OAccessibleContextWrapper_CBase
245 ,public OAccessibleContextWrapperHelper
248 ::comphelper::AccessibleEventNotifier::TClientId m_nNotifierClient
; // for notifying AccessibleEvents
256 @param _rxInnerAccessibleContext
259 @param _rxOwningAccessible
260 The XAccessible which created this object. This is necessary because children
261 of our wrapped context meed to be wrapped, too, and if they're asked for a parent,
262 they of course should return the proper parent<br/>
263 The object will be held with a hard reference
265 @param _rxParentAccessible
266 The XAccessible to return in the getAccessibleParent call
268 OAccessibleContextWrapper(
269 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
270 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>& _rxInnerAccessibleContext
,
271 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxOwningAccessible
,
272 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxParentAccessible
276 DECLARE_XINTERFACE( )
278 DECLARE_XTYPEPROVIDER( )
280 // XAccessibleContext
281 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 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
;
283 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
284 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
285 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
286 virtual OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
287 virtual OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
288 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
289 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
290 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 // XAccessibleEventBroadcaster
293 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
;
294 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 // OAccessibleContextWrapper
297 virtual void notifyTranslatedEvent( const ::com::sun::star::accessibility::AccessibleEventObject
& _rEvent
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
300 using OAccessibleContextWrapperHelper::disposing
;
301 virtual void SAL_CALL
disposing() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
304 virtual ~OAccessibleContextWrapper();
307 OAccessibleContextWrapper( const OAccessibleContextWrapper
& ) SAL_DELETED_FUNCTION
;
308 OAccessibleContextWrapper
& operator=( const OAccessibleContextWrapper
& ) SAL_DELETED_FUNCTION
;
312 //= OWrappedAccessibleChildrenManager
315 typedef ::std::map
< ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
316 , ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
317 , OInterfaceCompare
< ::com::sun::star::accessibility::XAccessible
>
319 // TODO: think about if we should hold these objects weak
321 typedef ::cppu::WeakImplHelper1
< ::com::sun::star::lang::XEventListener
322 > OWrappedAccessibleChildrenManager_Base
;
323 /** manages wrapping XAccessible's to XAccessible's
325 class COMPHELPER_DLLPUBLIC OWrappedAccessibleChildrenManager
: public OWrappedAccessibleChildrenManager_Base
328 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
330 ::com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
>
331 m_aOwningAccessible
; // the XAccessible which belongs to the XAccessibleContext which we work for
332 AccessibleMap m_aChildrenMap
; // for caching children
333 bool m_bTransientChildren
; // are we prohibited to cache our children?
337 OWrappedAccessibleChildrenManager(
338 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
341 /** specifies if the children are to be consideren transient (i.e.: not cached)
342 <p>to be called only once per lifetime</p>
344 void setTransientChildren( bool _bSet
= true );
346 /** sets the XAccessible which belongs to the XAccessibleContext which we work for
347 <p>to be called only once per lifetime</p>
349 void setOwningAccessible( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxAcc
);
351 /// retrieves a wrapper for the given accessible
352 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
353 getAccessibleWrapperFor(
354 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxKey
,
358 /// erases the given key from the map (if it is present there)
359 void removeFromCache( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxKey
);
361 /// invalidates (i.e. empties) the map
362 void invalidateAll( );
364 /** disposes (i.e. cleares) the manager
366 <p>Note that the XAccessibleContext's of the mapped XAccessible objects are disposed, too.</p>
370 /** handles a notification as got from the parent of the children we're managing
371 <p>This applies only to the notifications which have a direct impact on our map.</p>
373 void handleChildNotification( const ::com::sun::star::accessibility::AccessibleEventObject
& _rEvent
);
375 /** translates events as got from the parent of the children we're managing
376 <p>This applies only to the notifications which deal with child objects which we manage.</p>
378 void translateAccessibleEvent(
379 const ::com::sun::star::accessibility::AccessibleEventObject
& _rEvent
,
380 ::com::sun::star::accessibility::AccessibleEventObject
& _rTranslatedEvent
385 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
388 void implTranslateChildEventValue( const ::com::sun::star::uno::Any
& _rInValue
, ::com::sun::star::uno::Any
& _rOutValue
);
391 virtual ~OWrappedAccessibleChildrenManager( );
394 OWrappedAccessibleChildrenManager( const OWrappedAccessibleChildrenManager
& ) SAL_DELETED_FUNCTION
;
395 OWrappedAccessibleChildrenManager
& operator=( const OWrappedAccessibleChildrenManager
& ) SAL_DELETED_FUNCTION
;
399 } // namespace accessibility
402 #endif // INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */