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