LibreOffice Module comphelper (master)  1
accessiblecontexthelper.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_ACCESSIBLECONTEXTHELPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
22 
23 #include <cppuhelper/compbase2.hxx>
24 #include <cppuhelper/basemutex.hxx>
25 #include <com/sun/star/accessibility/XAccessibleContext2.hpp>
26 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
29 #include <memory>
30 
31 
32 namespace comphelper
33 {
34 
35 
36  //= OAccessibleContextHelper
37 
38 
40  typedef ::cppu::WeakAggComponentImplHelper2 < css::accessibility::XAccessibleContext2,
41  css::accessibility::XAccessibleEventBroadcaster
43 
47  :public ::cppu::BaseMutex
48  ,public OAccessibleContextHelper_Base
49  {
50  friend class OContextEntryGuard;
51  private:
52  std::unique_ptr<OContextHelper_Impl> m_pImpl;
53 
54  protected:
55  virtual ~OAccessibleContextHelper( ) override;
56 
58 
72  void lateInit( const css::uno::Reference< css::accessibility::XAccessible >& _rxAccessible );
73 
76  css::uno::Reference< css::accessibility::XAccessible >
77  getAccessibleCreator( ) const;
78 
79  public:
80  // XAccessibleEventBroadcaster
81  virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
82  virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
83 
84  // XAccessibleContext - still waiting to be overwritten
85  virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) override = 0;
86  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) override = 0;
87  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) override = 0;
88  virtual sal_Int16 SAL_CALL getAccessibleRole( ) override = 0;
89  virtual OUString SAL_CALL getAccessibleDescription( ) override = 0;
90  virtual OUString SAL_CALL getAccessibleName( ) override = 0;
91  virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) override = 0;
92  virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) override = 0;
93 
94  // XAccessibleContext2 - default implementation
95  virtual OUString SAL_CALL getAccessibleId( ) override;
96 
97  // XAccessibleContext - default implementations
102  virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) override;
107  virtual css::lang::Locale SAL_CALL getLocale( ) override;
108 
109  protected:
110  // OComponentHelper
111  virtual void SAL_CALL disposing() override;
112 
113  protected:
114  // helper
125  void NotifyAccessibleEvent(
126  const sal_Int16 _nEventId,
127  const css::uno::Any& _rOldValue,
128  const css::uno::Any& _rNewValue
129  );
130 
131  // life time control
133  bool isAlive() const;
135  void ensureAlive() const;
136 
141  void ensureDisposed( );
142 
145  css::uno::Reference< css::accessibility::XAccessibleContext >
146  implGetParentContext();
147 
148  // access to the base class' broadcast helper/mutex
149  ::osl::Mutex& GetMutex() { return m_aMutex; }
150  };
151 
152 
153  //= OContextEntryGuard
154 
167  class OContextEntryGuard : public ::osl::ClearableMutexGuard
168  {
169  public:
179  inline OContextEntryGuard( OAccessibleContextHelper* _pContext );
180  };
181 
182 
184  : ::osl::ClearableMutexGuard( _pContext->GetMutex() )
185  {
186  _pContext->ensureAlive();
187  }
188 
189 
190  //= OExternalLockGuard
191 
193  :public osl::Guard<SolarMutex>
194  ,public OContextEntryGuard
195  {
196  public:
197  inline OExternalLockGuard( OAccessibleContextHelper* _pContext );
198  };
199 
200 
202  :osl::Guard<SolarMutex>( SolarMutex::get() )
203  ,OContextEntryGuard( _pContext )
204  {
205  // Only lock the external mutex,
206  // release the ::osl::Mutex of the OAccessibleContextHelper instance.
207  // If you call into another UNO object with locked ::osl::Mutex,
208  // this may lead to dead locks.
209  clear();
210  }
211 
212 
213 } // namespace comphelper
214 
215 
216 #endif // INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
217 
218 
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
::osl::Mutex m_aMutex
std::unique_ptr< OContextHelper_Impl > m_pImpl
::cppu::WeakAggComponentImplHelper2< css::accessibility::XAccessibleContext2, css::accessibility::XAccessibleEventBroadcaster > OAccessibleContextHelper_Base
OContextEntryGuard(OAccessibleContextHelper *_pContext)
constructs the guard
OExternalLockGuard(OAccessibleContextHelper *_pContext)
helper class for guarding the entry into OAccessibleContextHelper methods.
bool isAlive()
void ensureAlive() const
checks for being alive. If the object is already disposed (i.e. not alive), an exception is thrown...
helper class for implementing an AccessibleContext
#define COMPHELPER_DLLPUBLIC
SolarMutex, needed for VCL's Application::GetSolarMutex().
Definition: solarmutex.hxx:46
implementation class for OAccessibleContextHelper.