LibreOffice Module comphelper (master)  1
accessiblewrapper.hxx
Go to the documentation of this file.
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 <config_options.h>
24 #include <sal/config.h>
25 
26 #include <map>
27 
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
32 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
33 #include <cppuhelper/compbase.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/basemutex.hxx>
37 #include <comphelper/uno3.hxx>
41 #include <rtl/ref.hxx>
42 
43 namespace com::sun::star::uno { class XComponentContext; }
44 
45 namespace comphelper
46 {
47 
48 
49  //= OAccessibleWrapper
50 
51 
52  class OAccessibleContextWrapper;
53  class OWrappedAccessibleChildrenManager;
54 
56  public ::cppu::ImplHelper1 < css::accessibility::XAccessible >
57  {
58  protected:
60  };
61 
67 
68  {
69  private:
70  css::uno::Reference< css::accessibility::XAccessible >
72  css::uno::WeakReference< css::accessibility::XAccessibleContext >
74 
75  protected:
76  css::uno::Reference< css::accessibility::XAccessible >
78 
79  public:
91  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
92  const css::uno::Reference< css::accessibility::XAccessible >& _rxInnerAccessible,
93  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
94  );
97 
98  // returns the context without creating it
99  css::uno::Reference< css::accessibility::XAccessibleContext >
100  getContextNoCreate( ) const;
101 
102  protected:
103  virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL
104  getAccessibleContext( ) override;
105 
106  const css::uno::Reference< css::accessibility::XAccessible >&
107  getParent() const { return m_xParentAccessible; }
108 
109  // own overridables
110  virtual OAccessibleContextWrapper* createAccessibleContext(
111  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerContext
112  );
113 
114  protected:
115  virtual ~OAccessibleWrapper( ) override;
116 
117  private:
118  OAccessibleWrapper( const OAccessibleWrapper& ) = delete;
119  OAccessibleWrapper& operator=( const OAccessibleWrapper& ) = delete;
120  };
121 
122 
123  //= OAccessibleContextWrapperHelper
124 
125 
126  typedef ::cppu::ImplHelper1 < css::accessibility::XAccessibleEventListener
128 
147  {
148  protected:
150  css::uno::Reference< css::accessibility::XAccessibleContext >
153  css::uno::Reference< css::accessibility::XAccessible >
156  css::uno::Reference< css::accessibility::XAccessible >
158 
159  rtl::Reference<OWrappedAccessibleChildrenManager> m_xChildMapper; // for mapping children from our inner context to our callers
160 
161  protected:
180  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
181  ::cppu::OBroadcastHelper& _rBHelper,
182  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
183  const css::uno::Reference< css::accessibility::XAccessible >& _rxOwningAccessible,
184  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
185  );
186 
188  void aggregateProxy(
189  oslInterlockedCount& _rRefCount,
190  ::cppu::OWeakObject& _rDelegator
191  );
192 
193  protected:
194  // XInterface
195  css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override;
196 
197  // XTypeProvider
199 
200  // XAccessibleContext
202  sal_Int32 baseGetAccessibleChildCount( );
205  css::uno::Reference< css::accessibility::XAccessible > baseGetAccessibleChild( sal_Int32 i );
207  css::uno::Reference< css::accessibility::XAccessibleRelationSet > baseGetAccessibleRelationSet( );
208 
209  // XAccessibleEventListener
210  virtual void SAL_CALL notifyEvent( const css::accessibility::AccessibleEventObject& aEvent ) override;
211 
212  // XEventListener
213  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
214 
215  // XComponent/OComponentProxyAggregationHelper
216  virtual void SAL_CALL dispose() override;
217 
218  // own overridables
229  virtual void notifyTranslatedEvent( const css::accessibility::AccessibleEventObject& _rEvent ) = 0;
230 
231  protected:
232  virtual ~OAccessibleContextWrapperHelper( ) override;
233 
236  };
237 
238 
239  //= OAccessibleContextWrapper
240 
241  typedef ::cppu::WeakComponentImplHelper< css::accessibility::XAccessibleEventBroadcaster
242  , css::accessibility::XAccessibleContext
244 
246  :public cppu::BaseMutex
249  {
250  private:
252 
253  public:
272  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
273  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
274  const css::uno::Reference< css::accessibility::XAccessible >& _rxOwningAccessible,
275  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
276  );
277 
278  // XInterface
280  // XTypeProvider
282 
283  // XAccessibleContext
284  virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) override;
285  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) override;
286  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
287  virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) override;
288  virtual sal_Int16 SAL_CALL getAccessibleRole( ) override;
289  virtual OUString SAL_CALL getAccessibleDescription( ) override;
290  virtual OUString SAL_CALL getAccessibleName( ) override;
291  virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override;
292  virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) override;
293  virtual css::lang::Locale SAL_CALL getLocale( ) override;
294 
295  // XAccessibleEventBroadcaster
296  virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
297  virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
298 
299  // OAccessibleContextWrapper
300  virtual void notifyTranslatedEvent( const css::accessibility::AccessibleEventObject& _rEvent ) override;
301 
302  // OComponentHelper
303  using OAccessibleContextWrapperHelper::disposing;
304  virtual void SAL_CALL disposing() override;
305 
306  protected:
307  virtual ~OAccessibleContextWrapper() override;
308 
309  private:
311  OAccessibleContextWrapper& operator=( const OAccessibleContextWrapper& ) = delete;
312  };
313 
314 
315  //= OWrappedAccessibleChildrenManager
316 
317 
318  typedef ::std::map < css::uno::Reference< css::accessibility::XAccessible >
319  , css::uno::Reference< css::accessibility::XAccessible >
321  // TODO: think about if we should hold these objects weak
322 
323  typedef ::cppu::WeakImplHelper< css::lang::XEventListener
327  class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OWrappedAccessibleChildrenManager : public OWrappedAccessibleChildrenManager_Base
328  {
329  protected:
330  css::uno::Reference< css::uno::XComponentContext >
331  m_xContext;
332  css::uno::WeakReference< css::accessibility::XAccessible >
333  m_aOwningAccessible; // the XAccessible which belongs to the XAccessibleContext which we work for
334  AccessibleMap m_aChildrenMap; // for caching children
335  bool m_bTransientChildren; // are we prohibited to cache our children?
336 
337  public:
339  OWrappedAccessibleChildrenManager(
340  const css::uno::Reference< css::uno::XComponentContext >& _rxContext
341  );
342 
346  void setTransientChildren( bool _bSet );
347 
351  void setOwningAccessible( const css::uno::Reference< css::accessibility::XAccessible >& _rxAcc );
352 
354  css::uno::Reference< css::accessibility::XAccessible >
355  getAccessibleWrapperFor(
356  const css::uno::Reference< css::accessibility::XAccessible >& _rxKey
357  );
358 
360  void removeFromCache( const css::uno::Reference< css::accessibility::XAccessible >& _rxKey );
361 
363  void invalidateAll( );
364 
369  void dispose();
370 
374  void handleChildNotification( const css::accessibility::AccessibleEventObject& _rEvent );
375 
379  void translateAccessibleEvent(
380  const css::accessibility::AccessibleEventObject& _rEvent,
381  css::accessibility::AccessibleEventObject& _rTranslatedEvent
382  );
383 
384  protected:
385  // XEventListener
386  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
387 
388  protected:
389  void implTranslateChildEventValue( const css::uno::Any& _rInValue, css::uno::Any& _rOutValue );
390 
391  protected:
392  virtual ~OWrappedAccessibleChildrenManager( ) override;
393 
394  private:
395  OWrappedAccessibleChildrenManager( const OWrappedAccessibleChildrenManager& ) = delete;
396  OWrappedAccessibleChildrenManager& operator=( const OWrappedAccessibleChildrenManager& ) = delete;
397  };
398 
399 
400 } // namespace accessibility
401 
402 
403 #endif // INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
404 
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::accessibility::XAccessible > m_xOwningAccessible
the XAccessible which created this context
::cppu::WeakComponentImplHelper< css::accessibility::XAccessibleEventBroadcaster, css::accessibility::XAccessibleContext > OAccessibleContextWrapper_CBase
::std::map< css::uno::Reference< css::accessibility::XAccessible >, css::uno::Reference< css::accessibility::XAccessible > > AccessibleMap
a class which aggregates a proxy for an XAccessible, and wrapping the context returned by this XAcces...
css::uno::WeakReference< css::accessibility::XAccessibleContext > m_aContext
css::uno::Reference< css::accessibility::XAccessible > m_xInnerAccessible
::cppu::ImplHelper1< css::accessibility::XAccessibleEventListener > OAccessibleContextWrapperHelper_Base
Helper for wrapping an XAccessibleContext by aggregating a proxy for it.
::comphelper::AccessibleEventNotifier::TClientId m_nNotifierClient
#define DECLARE_XTYPEPROVIDER()
Definition: uno3.hxx:126
::cppu::WeakImplHelper< css::lang::XEventListener > OWrappedAccessibleChildrenManager_Base
rtl::Reference< OWrappedAccessibleChildrenManager > m_xChildMapper
css::uno::Reference< css::accessibility::XAccessible > m_xParentAccessible
the XAccessible which is to be returned in getAccessibleParent
a helper class for aggregating a proxy to an XComponent
css::uno::Reference< css::accessibility::XAccessible > m_xParentAccessible
class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) IndexAccessIterator
an iterator that iterates through all elements, starting from an XIndexAccess (pre-order) ...
Definition: container.hxx:37
css::uno::Reference< css::accessibility::XAccessibleContext > m_xInnerContext
the context we're wrapping (properly typed, in opposite to OComponentProxyAggregationHelper::m_xInner...
#define COMPHELPER_DLLPUBLIC
Reference< XComponentContext > m_xContext
void dispose()
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
AnyEventRef aEvent
#define DECLARE_XINTERFACE()
Definition: uno3.hxx:90