LibreOffice Module sw (master)  1
acccontext.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 #pragma once
21 
22 #include "accframe.hxx"
23 #include <accmap.hxx>
24 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
25 #include <com/sun/star/accessibility/XAccessibleContext3.hpp>
26 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <unotools/resmgr.hxx>
30 
31 #include <memory>
32 #include <mutex>
33 
34 namespace vcl { class Window; }
35 class SwCursorShell;
36 class SdrObject;
37 class SwPaM;
38 namespace utl {
39  class AccessibleStateSetHelper;
40 }
41 namespace accessibility {
42  class AccessibleShape;
43 }
44 
45 inline constexpr OUStringLiteral sAccessibleServiceName = u"com.sun.star.accessibility.Accessible";
46 
48  public ::cppu::WeakImplHelper<
49  css::accessibility::XAccessible,
50  css::accessibility::XAccessibleContext,
51  css::accessibility::XAccessibleContext3,
52  css::accessibility::XAccessibleComponent,
53  css::accessibility::XAccessibleEventBroadcaster,
54  css::lang::XServiceInfo
55  >,
56  public SwAccessibleFrame
57 {
58  // The implements for the XAccessibleSelection interface has been
59  // 'externalized' and wants access to the protected members like
60  // GetMap, GetChild, GetParent, and GetFrame.
62 #if OSL_DEBUG_LEVEL > 0
63  friend class SwAccessibleMap;
64 #endif
65 
66 protected:
67  mutable std::mutex m_Mutex;
68 
69 private:
70  OUString m_sName; // immutable outside constructor
71 
72  // The parent if it has been retrieved. This is always an
73  // SwAccessibleContext. (protected by Mutex)
74  css::uno::WeakReference <
75  css::accessibility::XAccessible > m_xWeakParent;
76 
77  SwAccessibleMap *m_pMap; // must be protected by solar mutex
81  std::weak_ptr<SwAccessibleMap> m_wMap;
82 
83  sal_uInt32 m_nClientId; // client id in the AccessibleEventNotifier queue
84  sal_Int16 m_nRole; // immutable outside constructor
85 
86  // The current states (protected by mutex)
87  bool m_isShowingState : 1;
89  bool m_isOpaqueState : 1;
90  bool m_isDefuncState : 1;
91 
92  // Are we currently disposing that object (protected by solar mutex)?
93  bool m_isDisposing : 1;
94 
95  // #i85634# - boolean, indicating if the accessible context is
96  // in general registered at the accessible map.
98 
99  void InitStates();
100 
101 protected:
102  void SetName( const OUString& rName ) { m_sName = rName; }
103  sal_Int16 GetRole() const
104  {
105  return m_nRole;
106  }
107  //This flag is used to mark the object's selected state.
109  void SetParent( SwAccessibleContext *pParent );
110  css::uno::Reference< css::accessibility::XAccessible> GetWeakParent() const;
111 
112  bool IsDisposing() const { return m_isDisposing; }
113 
116  const SwAccessibleMap *GetMap() const { return m_pMap; }
117 
120  {
121  return GetMap()->GetShell();
122  }
123  const SwViewShell* GetShell() const
124  {
125  return GetMap()->GetShell();
126  }
127 
131  const SwCursorShell* GetCursorShell() const;
132 
133  // Notify all children that the visible area has changed.
134  // The SwFrame might belong to the current object or to any other child or
135  // grandchild.
136  void ChildrenScrolled( const SwFrame *pFrame, const SwRect& rOldVisArea );
137 
138  // The context's showing state changed. May only be called for context that
139  // exist even if they aren't visible.
140  void Scrolled( const SwRect& rOldVisArea );
141 
142  // A child has been moved while setting the visible area
143  void ScrolledWithin( const SwRect& rOldVisArea );
144 
145  // The has been added while setting the visible area
146  void ScrolledIn();
147 
148  // The context has to be removed while setting the visible area
149  void ScrolledOut( const SwRect& rOldVisArea );
150 
151  // Invalidate the states of all children of the specified SwFrame. The
152  // SwFrame might belong the current object or to any child or grandchild!
153  // #i27301# - use new type definition for <_nStates>
154  void InvalidateChildrenStates( const SwFrame* _pFrame,
155  AccessibleStates _nStates );
156 
157  // Dispose children of the specified SwFrame. The SwFrame might belong to
158  // the current object or to any other child or grandchild.
159  void DisposeChildren(const SwFrame *pFrame,
160  bool bRecursive, bool bCanSkipInvisible);
161 
162  void DisposeShape( const SdrObject *pObj,
163  ::accessibility::AccessibleShape *pAccImpl );
165 
166  virtual void InvalidateContent_( bool bVisibleDataFired );
167 
168  virtual void InvalidateCursorPos_();
169  virtual void InvalidateFocus_();
170 
171 public:
172  void FireAccessibleEvent( css::accessibility::AccessibleEventObject& rEvent );
173 
174 protected:
175  // broadcast visual data event
176  void FireVisibleDataEvent();
177 
178  // broadcast state change event
179  void FireStateChangedEvent( sal_Int16 nState, bool bNewState );
180 
181  // Set states for getAccessibleStateSet.
182  // This base class sets DEFUNC(0/1), EDITABLE(0/1), ENABLED(1),
183  // SHOWING(0/1), OPAQUE(0/1) and VISIBLE(1).
184  virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet );
185 
186  bool IsEditableState();
187 
189  css::awt::Rectangle
190  getBoundsImpl(bool bRelative);
191 
192  // #i85634#
194  {
195  m_isRegisteredAtAccessibleMap = false;
196  }
198 
199  void ThrowIfDisposed();
200 
201  virtual ~SwAccessibleContext() override;
202 
203  // Return a reference to the parent.
204  css::uno::Reference< css::accessibility::XAccessible>
206 
207 public:
208  SwAccessibleContext( std::shared_ptr<SwAccessibleMap> const& pMap,
209  sal_Int16 nRole, const SwFrame *pFrame );
210 
211  // XAccessible
212 
213  // Return the XAccessibleContext.
214  virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL
215  getAccessibleContext() override;
216 
217  // XAccessibleContext
218 
219  // Return the number of currently visible children.
220  virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
221 
222  // Return the specified child or NULL if index is invalid.
223  virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
224  getAccessibleChild (sal_Int32 nIndex) override;
225 
226  virtual css::uno::Sequence<css::uno::Reference< css::accessibility::XAccessible>> SAL_CALL
227  getAccessibleChildren() override;
228 
229  // Return a reference to the parent.
230  virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
231  getAccessibleParent() override;
232 
233  // Return this objects index among the parents children.
234  virtual sal_Int32 SAL_CALL
235  getAccessibleIndexInParent() override;
236 
237  // Return this object's role.
238  virtual sal_Int16 SAL_CALL
239  getAccessibleRole() override;
240 
241  // getAccessibleDescription() is abstract
242 
243  // Return the object's current name.
244  virtual OUString SAL_CALL
245  getAccessibleName() override;
246 
247  // Return NULL to indicate that an empty relation set.
248  virtual css::uno::Reference<
249  css::accessibility::XAccessibleRelationSet> SAL_CALL
250  getAccessibleRelationSet() override;
251 
252  // Return the set of current states.
253  virtual css::uno::Reference<
254  css::accessibility::XAccessibleStateSet> SAL_CALL
255  getAccessibleStateSet() override;
256 
259  virtual css::lang::Locale SAL_CALL
260  getLocale() override;
261 
262  // XAccessibleEventBroadcaster
263 
264  virtual void SAL_CALL addAccessibleEventListener(
265  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
266  virtual void SAL_CALL removeAccessibleEventListener(
267  const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
268 
269  // XAccessibleComponent
270  virtual sal_Bool SAL_CALL containsPoint(
271  const css::awt::Point& aPoint ) override;
272 
273  virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(
274  const css::awt::Point& aPoint ) override;
275 
276  virtual css::awt::Rectangle SAL_CALL getBounds() override;
277 
278  virtual css::awt::Point SAL_CALL getLocation() override;
279 
280  virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
281 
282  virtual css::awt::Size SAL_CALL getSize() override;
283 
284  virtual void SAL_CALL grabFocus() override;
285 
286  virtual sal_Int32 SAL_CALL getForeground() override;
287  virtual sal_Int32 SAL_CALL getBackground() override;
288 
289  // XServiceInfo
290 
291  // getImplementationName() and getSupportedServiceNames are abstract
292 
294  virtual sal_Bool SAL_CALL
295  supportsService (const OUString& sServiceName) override;
296 
297  // thread safe C++ interface
298 
299  // The object is not visible any longer and should be destroyed
300  virtual void Dispose(bool bRecursive, bool bCanSkipInvisible = true);
301 
302  // The child object is not visible any longer and should be destroyed
303  virtual void DisposeChild(const sw::access::SwAccessibleChild& rFrameOrObj, bool bRecursive, bool bCanSkipInvisible);
304 
305  // The object has been moved by the layout
306  virtual void InvalidatePosOrSize( const SwRect& rFrame );
307 
308  // The child object has been moved by the layout
309  virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrameOrObj,
310  const SwRect& rFrame );
311 
312  // The content may have changed (but it hasn't to have changed)
313  void InvalidateContent();
314 
315  // The caretPos has changed
316  void InvalidateCursorPos();
317 
318  // The Focus state has changed
319  void InvalidateFocus();
320 
321  // Check states
322  // #i27301# - use new type definition for <_nStates>
323  void InvalidateStates( AccessibleStates _nStates );
324 
325  // the XAccessibleRelationSet may have changed
326  void InvalidateRelation( sal_uInt16 nType );
327 
328  void InvalidateTextSelection(); // #i27301# - text selection has changed
329  void InvalidateAttr(); // #i88069# - attributes has changed
330 
332 
333  // #i88070# - get additional child by index
334  vcl::Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
335 
336  // #i88070# - get all additional accessible children
337  void GetAdditionalAccessibleChildren( std::vector< vcl::Window* >* pChildren );
338 
339  const OUString& GetName() const { return m_sName; }
340 
341  virtual bool HasCursor(); // required by map to remember that object
342 
343  bool Select( SwPaM *pPaM, SdrObject *pObj, bool bAdd );
344  bool Select( SwPaM& rPaM )
345  {
346  return Select( &rPaM, nullptr, false );
347  }
348  bool Select( SdrObject *pObj, bool bAdd )
349  {
350  return Select( nullptr, pObj, bAdd );
351  }
352 
353  //This method is used to update the selected state and fire the selected state changed event.
354  virtual bool SetSelectedState(bool bSeleted);
355  bool IsSeletedInDoc() const { return m_isSelectedInDoc; }
356 
357  static OUString GetResource(TranslateId pResId,
358  const OUString *pArg1 = nullptr,
359  const OUString *pArg2 = nullptr);
360 };
361 
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ScrolledOut(const SwRect &rOldVisArea)
Definition: acccontext.cxx:326
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParentImpl()
Definition: acccontext.cxx:664
sal_Int16 GetRole() const
Definition: acccontext.hxx:103
std::weak_ptr< SwAccessibleMap > m_wMap
note: the m_pMap is guaranteed to be valid until we hit the dtor ~SwAccessibleContext, then m_wMap must be checked if it's still alive, after locking SolarMutex (alternatively, Dispose clears m_pMap)
Definition: acccontext.hxx:81
Base class of the Writer layout elements.
Definition: frame.hxx:315
virtual css::awt::Point SAL_CALL getLocation() override
Definition: acccontext.cxx:928
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
Definition: acccontext.cxx:936
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:804
virtual css::awt::Size SAL_CALL getSize() override
Definition: acccontext.cxx:954
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:443
virtual void InvalidateCursorPos_()
Definition: acccontext.cxx:435
virtual void InvalidateChildPosOrSize(const sw::access::SwAccessibleChild &rFrameOrObj, const SwRect &rFrame)
void ChildrenScrolled(const SwFrame *pFrame, const SwRect &rOldVisArea)
Definition: acccontext.cxx:123
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:569
void SetParent(SwAccessibleContext *pParent)
Definition: acccontext.cxx:67
virtual sal_Int32 SAL_CALL getForeground() override
void DisposeChildren(const SwFrame *pFrame, bool bRecursive, bool bCanSkipInvisible)
Definition: acccontext.cxx:383
vcl::Window * GetWindow()
Definition: acccontext.cxx:83
void NotRegisteredAtAccessibleMap()
Definition: acccontext.hxx:193
void Scrolled(const SwRect &rOldVisArea)
Definition: acccontext.cxx:264
virtual void SAL_CALL grabFocus() override
Definition: acccontext.cxx:962
SwViewShell * GetShell()
convenience method to get the SwViewShell through accessibility map
Definition: acccontext.hxx:119
virtual bool HasCursor()
virtual css::lang::Locale SAL_CALL getLocale() override
Return the parents locale or throw exception if this object has no parent yet/anymore.
Definition: acccontext.cxx:753
vcl::Window * GetAdditionalAccessibleChild(const sal_Int32 nIndex)
#i88070# - get additional accessible child by index
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
SwAccessibleContext(std::shared_ptr< SwAccessibleMap > const &pMap, sal_Int16 nRole, const SwFrame *pFrame)
Definition: acccontext.cxx:532
SwCursorShell * GetCursorShell()
convenience method to get SwCursorShell through accessibility map
Definition: acccontext.cxx:101
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
SwViewShell * GetShell() const
Definition: accmap.hxx:169
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Definition: acccontext.cxx:728
constexpr OUStringLiteral sServiceName
Definition: accdoc.cxx:55
void GetAdditionalAccessibleChildren(std::vector< vcl::Window * > *pChildren)
#i88070# - get all additional accessible children
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:45
virtual void InvalidateContent_(bool bVisibleDataFired)
Definition: acccontext.cxx:431
virtual void DisposeChild(const sw::access::SwAccessibleChild &rFrameOrObj, bool bRecursive, bool bCanSkipInvisible)
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:761
bool Select(SwPaM *pPaM, SdrObject *pObj, bool bAdd)
void FireStateChangedEvent(sal_Int16 nState, bool bNewState)
Definition: acccontext.cxx:467
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwAccessibleMap * m_pMap
Definition: acccontext.hxx:77
const OUString & GetName() const
Definition: acccontext.hxx:339
static OUString GetResource(TranslateId pResId, const OUString *pArg1=nullptr, const OUString *pArg2=nullptr)
bool HasAdditionalAccessibleChildren()
void InvalidateChildrenStates(const SwFrame *_pFrame, AccessibleStates _nStates)
Definition: acccontext.cxx:350
void InvalidateStates(AccessibleStates _nStates)
void InvalidateAttr()
#i88069# - attributes has changed
float u
unsigned char sal_Bool
bool m_isRegisteredAtAccessibleMap
Definition: acccontext.hxx:97
const SwViewShell * GetShell() const
Definition: acccontext.hxx:123
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Definition: acccontext.cxx:686
void InvalidateRelation(sal_uInt16 nType)
virtual void InvalidatePosOrSize(const SwRect &rFrame)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 nIndex) override
Definition: acccontext.cxx:579
css::uno::WeakReference< css::accessibility::XAccessible > m_xWeakParent
Definition: acccontext.hxx:75
bool IsDisposing() const
Definition: acccontext.hxx:112
virtual css::awt::Rectangle SAL_CALL getBounds() override
Definition: acccontext.cxx:923
void ScrolledWithin(const SwRect &rOldVisArea)
Definition: acccontext.cxx:283
void ScrolledInShape(::accessibility::AccessibleShape *pAccImpl)
void DisposeShape(const SdrObject *pObj,::accessibility::AccessibleShape *pAccImpl)
css::awt::Rectangle getBoundsImpl(bool bRelative)
Get bounding box.
Definition: acccontext.cxx:873
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
Definition: acccontext.cxx:695
virtual sal_Int32 SAL_CALL getBackground() override
void RemoveFrameFromAccessibleMap()
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:722
bool IsSeletedInDoc() const
Definition: acccontext.hxx:355
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
Definition: acccontext.cxx:736
std::mutex m_Mutex
Definition: acccontext.hxx:67
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true)
virtual void GetStates(::utl::AccessibleStateSetHelper &rStateSet)
Definition: acccontext.cxx:481
sal_uInt32 m_nClientId
Definition: acccontext.hxx:83
virtual bool SetSelectedState(bool bSeleted)
void InvalidateTextSelection()
#i27301# - text selection has changed
css::uno::Reference< css::accessibility::XAccessible > GetWeakParent() const
Definition: acccontext.cxx:75
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:115
virtual void InvalidateFocus_()
Definition: acccontext.cxx:439
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:773
bool Select(SdrObject *pObj, bool bAdd)
Definition: acccontext.hxx:348
bool Select(SwPaM &rPaM)
Definition: acccontext.hxx:344
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:814
virtual sal_Int16 SAL_CALL getAccessibleRole() override
Definition: acccontext.cxx:717
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
Definition: acccontext.cxx:563
AccessibleStates
Definition: accmap.hxx:70
virtual css::uno::Sequence< css::uno::Reference< css::accessibility::XAccessible > > SAL_CALL getAccessibleChildren() override
Definition: acccontext.cxx:623
void SetName(const OUString &rName)
Definition: acccontext.hxx:102
virtual ~SwAccessibleContext() override
Definition: acccontext.cxx:548
const SwAccessibleMap * GetMap() const
Definition: acccontext.hxx:116