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 <sal/config.h>
24 
25 #include <map>
26 
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/compbase.hxx>
33 #include <cppuhelper/implbase.hxx>
34 #include <cppuhelper/implbase1.hxx>
35 #include <cppuhelper/basemutex.hxx>
36 #include <comphelper/uno3.hxx>
40 #include <rtl/ref.hxx>
41 
42 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
43 
44 namespace comphelper
45 {
46 
47 
48  //= OAccessibleWrapper
49 
50 
51  class OAccessibleContextWrapper;
52  class OWrappedAccessibleChildrenManager;
53 
55  public ::cppu::ImplHelper1 < css::accessibility::XAccessible >
56  {
57  protected:
59  };
60 
66 
67  {
68  private:
69  css::uno::Reference< css::accessibility::XAccessible >
71  css::uno::WeakReference< css::accessibility::XAccessibleContext >
73 
74  protected:
75  css::uno::Reference< css::accessibility::XAccessible >
77 
78  public:
90  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
91  const css::uno::Reference< css::accessibility::XAccessible >& _rxInnerAccessible,
92  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
93  );
96 
97  // returns the context without creating it
98  css::uno::Reference< css::accessibility::XAccessibleContext >
99  getContextNoCreate( ) const;
100 
101  protected:
102  virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL
103  getAccessibleContext( ) override;
104 
105  const css::uno::Reference< css::accessibility::XAccessible >&
106  getParent() const { return m_xParentAccessible; }
107 
108  // own overridables
109  virtual OAccessibleContextWrapper* createAccessibleContext(
110  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerContext
111  );
112 
113  protected:
114  virtual ~OAccessibleWrapper( ) override;
115 
116  private:
117  OAccessibleWrapper( const OAccessibleWrapper& ) = delete;
118  OAccessibleWrapper& operator=( const OAccessibleWrapper& ) = delete;
119  };
120 
121 
122  //= OAccessibleContextWrapperHelper
123 
124 
125  typedef ::cppu::ImplHelper1 < css::accessibility::XAccessibleEventListener
127 
146  {
147  protected:
149  css::uno::Reference< css::accessibility::XAccessibleContext >
152  css::uno::Reference< css::accessibility::XAccessible >
155  css::uno::Reference< css::accessibility::XAccessible >
157 
158  rtl::Reference<OWrappedAccessibleChildrenManager> m_xChildMapper; // for mapping children from our inner context to our callers
159 
160  protected:
179  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
180  ::cppu::OBroadcastHelper& _rBHelper,
181  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
182  const css::uno::Reference< css::accessibility::XAccessible >& _rxOwningAccessible,
183  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
184  );
185 
187  void aggregateProxy(
188  oslInterlockedCount& _rRefCount,
189  ::cppu::OWeakObject& _rDelegator
190  );
191 
192  protected:
193  // XInterface
194  css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override;
195 
196  // XTypeProvider
198 
199  // XAccessibleContext
201  sal_Int32 baseGetAccessibleChildCount( );
204  css::uno::Reference< css::accessibility::XAccessible > baseGetAccessibleChild( sal_Int32 i );
206  css::uno::Reference< css::accessibility::XAccessibleRelationSet > baseGetAccessibleRelationSet( );
207 
208  // XAccessibleEventListener
209  virtual void SAL_CALL notifyEvent( const css::accessibility::AccessibleEventObject& aEvent ) override;
210 
211  // XEventListener
212  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
213 
214  // XComponent/OComponentProxyAggregationHelper
215  virtual void SAL_CALL dispose() override;
216 
217  // own overridables
228  virtual void notifyTranslatedEvent( const css::accessibility::AccessibleEventObject& _rEvent ) = 0;
229 
230  protected:
231  virtual ~OAccessibleContextWrapperHelper( ) override;
232 
235  };
236 
237 
238  //= OAccessibleContextWrapper
239 
240  typedef ::cppu::WeakComponentImplHelper< css::accessibility::XAccessibleEventBroadcaster
241  , css::accessibility::XAccessibleContext
243 
245  :public cppu::BaseMutex
248  {
249  private:
251 
252  public:
271  const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
272  const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
273  const css::uno::Reference< css::accessibility::XAccessible >& _rxOwningAccessible,
274  const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
275  );
276 
277  // XInterface
279  // XTypeProvider
281 
282  // XAccessibleContext
283  virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) override;
284  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) override;
285  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override;
286  virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) override;
287  virtual sal_Int16 SAL_CALL getAccessibleRole( ) override;
288  virtual OUString SAL_CALL getAccessibleDescription( ) override;
289  virtual OUString SAL_CALL getAccessibleName( ) override;
290  virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override;
291  virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) override;
292  virtual css::lang::Locale SAL_CALL getLocale( ) override;
293 
294  // XAccessibleEventBroadcaster
295  virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
296  virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
297 
298  // OAccessibleContextWrapper
299  virtual void notifyTranslatedEvent( const css::accessibility::AccessibleEventObject& _rEvent ) override;
300 
301  // OComponentHelper
302  using OAccessibleContextWrapperHelper::disposing;
303  virtual void SAL_CALL disposing() override;
304 
305  protected:
306  virtual ~OAccessibleContextWrapper() override;
307 
308  private:
310  OAccessibleContextWrapper& operator=( const OAccessibleContextWrapper& ) = delete;
311  };
312 
313 
314  //= OWrappedAccessibleChildrenManager
315 
316 
317  typedef ::std::map < css::uno::Reference< css::accessibility::XAccessible >
318  , css::uno::Reference< css::accessibility::XAccessible >
320  // TODO: think about if we should hold these objects weak
321 
322  typedef ::cppu::WeakImplHelper< css::lang::XEventListener
327  {
328  protected:
329  css::uno::Reference< css::uno::XComponentContext >
331  css::uno::WeakReference< css::accessibility::XAccessible >
332  m_aOwningAccessible; // the XAccessible which belongs to the XAccessibleContext which we work for
333  AccessibleMap m_aChildrenMap; // for caching children
334  bool m_bTransientChildren; // are we prohibited to cache our children?
335 
336  public:
339  const css::uno::Reference< css::uno::XComponentContext >& _rxContext
340  );
341 
345  void setTransientChildren( bool _bSet );
346 
350  void setOwningAccessible( const css::uno::Reference< css::accessibility::XAccessible >& _rxAcc );
351 
353  css::uno::Reference< css::accessibility::XAccessible >
354  getAccessibleWrapperFor(
355  const css::uno::Reference< css::accessibility::XAccessible >& _rxKey
356  );
357 
359  void removeFromCache( const css::uno::Reference< css::accessibility::XAccessible >& _rxKey );
360 
362  void invalidateAll( );
363 
368  void dispose();
369 
373  void handleChildNotification( const css::accessibility::AccessibleEventObject& _rEvent );
374 
378  void translateAccessibleEvent(
379  const css::accessibility::AccessibleEventObject& _rEvent,
380  css::accessibility::AccessibleEventObject& _rTranslatedEvent
381  );
382 
383  protected:
384  // XEventListener
385  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
386 
387  protected:
388  void implTranslateChildEventValue( const css::uno::Any& _rInValue, css::uno::Any& _rOutValue );
389 
390  protected:
391  virtual ~OWrappedAccessibleChildrenManager( ) override;
392 
393  private:
396  };
397 
398 
399 } // namespace accessibility
400 
401 
402 #endif // INCLUDED_COMPHELPER_ACCESSIBLEWRAPPER_HXX
403 
404 /* 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
css::uno::WeakReference< css::accessibility::XAccessible > m_aOwningAccessible
::cppu::ImplHelper1< css::accessibility::XAccessibleEventListener > OAccessibleContextWrapperHelper_Base
Helper for wrapping an XAccessibleContext by aggregating a proxy for it.
::comphelper::AccessibleEventNotifier::TClientId m_nNotifierClient
css::uno::Reference< css::uno::XComponentContext > m_xContext
#define DECLARE_XTYPEPROVIDER()
Definition: uno3.hxx:126
::cppu::WeakImplHelper< css::lang::XEventListener > OWrappedAccessibleChildrenManager_Base
manages wrapping XAccessible's to XAccessible's
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
css::uno::Reference< css::accessibility::XAccessibleContext > m_xInnerContext
the context we're wrapping (properly typed, in opposite to OComponentProxyAggregationHelper::m_xInner...
#define COMPHELPER_DLLPUBLIC
void dispose()
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
#define DECLARE_XINTERFACE()
Definition: uno3.hxx:90