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