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>
29#include <unotools/resmgr.hxx>
30
31#include <memory>
32#include <mutex>
33
34namespace vcl { class Window; }
35class SwCursorShell;
36class SdrObject;
37class SwPaM;
38namespace utl {
39 class AccessibleStateSetHelper;
40}
41namespace accessibility {
42 class AccessibleShape;
43}
44
45inline 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 >,
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
66protected:
67 mutable std::mutex m_Mutex;
68
69private:
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)
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
101protected:
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,
165
166 virtual void InvalidateContent_( bool bVisibleDataFired );
167
168 virtual void InvalidateCursorPos_();
169 virtual void InvalidateFocus_();
170
171public:
172 void FireAccessibleEvent( css::accessibility::AccessibleEventObject& rEvent );
173
174protected:
175 // broadcast visual data event
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 {
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
207public:
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
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 bSelected);
355 bool IsSelectedInDoc() 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: */
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:45
constexpr OUStringLiteral sServiceName
Definition: accdoc.cxx:55
AccessibleStates
Definition: accmap.hxx:71
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true)
void GetAdditionalAccessibleChildren(std::vector< vcl::Window * > *pChildren)
#i88070# - get all additional accessible children
virtual ~SwAccessibleContext() override
Definition: acccontext.cxx:547
bool HasAdditionalAccessibleChildren()
virtual bool HasCursor()
const SwAccessibleMap * GetMap() const
Definition: acccontext.hxx:116
bool m_isRegisteredAtAccessibleMap
Definition: acccontext.hxx:97
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
Definition: acccontext.cxx:735
virtual css::uno::Sequence< css::uno::Reference< css::accessibility::XAccessible > > SAL_CALL getAccessibleChildren() override
Definition: acccontext.cxx:622
const OUString & GetName() const
Definition: acccontext.hxx:339
void RemoveFrameFromAccessibleMap()
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
virtual css::awt::Point SAL_CALL getLocation() override
Definition: acccontext.cxx:927
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:803
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:721
void ChildrenScrolled(const SwFrame *pFrame, const SwRect &rOldVisArea)
Definition: acccontext.cxx:122
css::uno::WeakReference< css::accessibility::XAccessible > m_xWeakParent
Definition: acccontext.hxx:75
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:813
void DisposeShape(const SdrObject *pObj, ::accessibility::AccessibleShape *pAccImpl)
bool Select(SdrObject *pObj, bool bAdd)
Definition: acccontext.hxx:348
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
Definition: acccontext.cxx:694
void SetName(const OUString &rName)
Definition: acccontext.hxx:102
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Definition: acccontext.cxx:727
virtual sal_Int16 SAL_CALL getAccessibleRole() override
Definition: acccontext.cxx:716
css::awt::Rectangle getBoundsImpl(bool bRelative)
Get bounding box.
Definition: acccontext.cxx:872
const SwViewShell * GetShell() const
Definition: acccontext.hxx:123
sal_Int16 GetRole() const
Definition: acccontext.hxx:103
virtual void InvalidateCursorPos_()
Definition: acccontext.cxx:434
virtual void InvalidateChildPosOrSize(const sw::access::SwAccessibleChild &rFrameOrObj, const SwRect &rFrame)
void FireStateChangedEvent(sal_Int16 nState, bool bNewState)
Definition: acccontext.cxx:466
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:442
void InvalidateRelation(sal_uInt16 nType)
void ScrolledInShape(::accessibility::AccessibleShape *pAccImpl)
vcl::Window * GetAdditionalAccessibleChild(const sal_Int32 nIndex)
#i88070# - get additional accessible child by index
bool IsDisposing() const
Definition: acccontext.hxx:112
virtual void GetStates(::utl::AccessibleStateSetHelper &rStateSet)
Definition: acccontext.cxx:480
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Definition: acccontext.cxx:685
virtual sal_Int32 SAL_CALL getBackground() override
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:752
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
Definition: acccontext.cxx:562
std::weak_ptr< SwAccessibleMap > m_wMap
note: the m_pMap is guaranteed to be valid until we hit the dtor ~SwAccessibleContext,...
Definition: acccontext.hxx:81
void ScrolledWithin(const SwRect &rOldVisArea)
Definition: acccontext.cxx:282
void DisposeChildren(const SwFrame *pFrame, bool bRecursive, bool bCanSkipInvisible)
Definition: acccontext.cxx:382
SwAccessibleMap * m_pMap
Definition: acccontext.hxx:77
vcl::Window * GetWindow()
Definition: acccontext.cxx:82
sal_uInt32 m_nClientId
Definition: acccontext.hxx:83
virtual void InvalidateFocus_()
Definition: acccontext.cxx:438
virtual sal_Int32 SAL_CALL getForeground() override
virtual void DisposeChild(const sw::access::SwAccessibleChild &rFrameOrObj, bool bRecursive, bool bCanSkipInvisible)
virtual void InvalidateContent_(bool bVisibleDataFired)
Definition: acccontext.cxx:430
virtual void SAL_CALL grabFocus() override
Definition: acccontext.cxx:961
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:115
void NotRegisteredAtAccessibleMap()
Definition: acccontext.hxx:193
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:772
bool Select(SwPaM *pPaM, SdrObject *pObj, bool bAdd)
virtual css::awt::Rectangle SAL_CALL getBounds() override
Definition: acccontext.cxx:922
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 nIndex) override
Definition: acccontext.cxx:578
std::mutex m_Mutex
Definition: acccontext.hxx:67
css::uno::Reference< css::accessibility::XAccessible > GetWeakParent() const
Definition: acccontext.cxx:74
void SetParent(SwAccessibleContext *pParent)
Definition: acccontext.cxx:66
SwAccessibleContext(std::shared_ptr< SwAccessibleMap > const &pMap, sal_Int16 nRole, const SwFrame *pFrame)
Definition: acccontext.cxx:531
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:760
SwCursorShell * GetCursorShell()
convenience method to get SwCursorShell through accessibility map
Definition: acccontext.cxx:100
virtual css::awt::Size SAL_CALL getSize() override
Definition: acccontext.cxx:953
void Scrolled(const SwRect &rOldVisArea)
Definition: acccontext.cxx:263
bool IsSelectedInDoc() const
Definition: acccontext.hxx:355
static OUString GetResource(TranslateId pResId, const OUString *pArg1=nullptr, const OUString *pArg2=nullptr)
virtual bool SetSelectedState(bool bSelected)
void InvalidateTextSelection()
#i27301# - text selection has changed
SwViewShell * GetShell()
convenience method to get the SwViewShell through accessibility map
Definition: acccontext.hxx:119
void ScrolledOut(const SwRect &rOldVisArea)
Definition: acccontext.cxx:325
void InvalidateChildrenStates(const SwFrame *_pFrame, AccessibleStates _nStates)
Definition: acccontext.cxx:349
void InvalidateAttr()
#i88069# - attributes has changed
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:568
virtual void InvalidatePosOrSize(const SwRect &rFrame)
void InvalidateStates(AccessibleStates _nStates)
bool Select(SwPaM &rPaM)
Definition: acccontext.hxx:344
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
Definition: acccontext.cxx:935
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParentImpl()
Definition: acccontext.cxx:663
SwViewShell * GetShell() const
Definition: accmap.hxx:174
Base class of the Writer layout elements.
Definition: frame.hxx:315
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:138
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
float u
unsigned char sal_Bool