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