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 accessibility {
39 class AccessibleShape;
40}
41
42inline constexpr OUStringLiteral sAccessibleServiceName = u"com.sun.star.accessibility.Accessible";
43
45 public ::cppu::WeakImplHelper<
46 css::accessibility::XAccessible,
47 css::accessibility::XAccessibleContext,
48 css::accessibility::XAccessibleContext3,
49 css::accessibility::XAccessibleComponent,
50 css::accessibility::XAccessibleEventBroadcaster,
51 css::lang::XServiceInfo
52 >,
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
63protected:
64 mutable std::mutex m_Mutex;
65
66private:
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 m_nRole; // immutable outside constructor
82
83 // The current states (protected by mutex)
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
98protected:
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,
162
163 virtual void InvalidateContent_( bool bVisibleDataFired );
164
165 virtual void InvalidateCursorPos_();
166 virtual void InvalidateFocus_();
167
168public:
169 void FireAccessibleEvent( css::accessibility::AccessibleEventObject& rEvent );
170
171protected:
172 // broadcast visual data event
174
175 // broadcast state change event
176 void FireStateChangedEvent( sal_Int64 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( sal_Int64& rStateSet );
182
183 bool IsEditableState();
184
186 css::awt::Rectangle
187 getBoundsImpl(bool bRelative);
188
189 // #i85634#
191 {
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
204public:
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_Int64 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_Int64 nIndex) override;
222
223 virtual css::uno::Sequence<css::uno::Reference< css::accessibility::XAccessible>> SAL_CALL
224 getAccessibleChildren() override;
225
226 // Return a reference to the parent.
227 virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
228 getAccessibleParent() override;
229
230 // Return this objects index among the parents children.
231 virtual sal_Int64 SAL_CALL
233
234 // Return this object's role.
235 virtual sal_Int16 SAL_CALL
236 getAccessibleRole() override;
237
238 // getAccessibleDescription() is abstract
239
240 // Return the object's current name.
241 virtual OUString SAL_CALL
242 getAccessibleName() override;
243
244 // Return NULL to indicate that an empty relation set.
245 virtual css::uno::Reference<
246 css::accessibility::XAccessibleRelationSet> SAL_CALL
247 getAccessibleRelationSet() override;
248
249 // Return the set of current states.
250 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
251
254 virtual css::lang::Locale SAL_CALL
255 getLocale() override;
256
257 // XAccessibleEventBroadcaster
258
259 virtual void SAL_CALL addAccessibleEventListener(
260 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
261 virtual void SAL_CALL removeAccessibleEventListener(
262 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
263
264 // XAccessibleComponent
265 virtual sal_Bool SAL_CALL containsPoint(
266 const css::awt::Point& aPoint ) override;
267
268 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(
269 const css::awt::Point& aPoint ) override;
270
271 virtual css::awt::Rectangle SAL_CALL getBounds() override;
272
273 virtual css::awt::Point SAL_CALL getLocation() override;
274
275 virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
276
277 virtual css::awt::Size SAL_CALL getSize() override;
278
279 virtual void SAL_CALL grabFocus() override;
280
281 virtual sal_Int32 SAL_CALL getForeground() override;
282 virtual sal_Int32 SAL_CALL getBackground() override;
283
284 // XServiceInfo
285
286 // getImplementationName() and getSupportedServiceNames are abstract
287
289 virtual sal_Bool SAL_CALL
290 supportsService (const OUString& sServiceName) override;
291
292 // thread safe C++ interface
293
294 // The object is not visible any longer and should be destroyed
295 virtual void Dispose(bool bRecursive, bool bCanSkipInvisible = true);
296
297 // The child object is not visible any longer and should be destroyed
298 virtual void DisposeChild(const sw::access::SwAccessibleChild& rFrameOrObj, bool bRecursive, bool bCanSkipInvisible);
299
300 // The object has been moved by the layout
301 virtual void InvalidatePosOrSize( const SwRect& rFrame );
302
303 // The child object has been moved by the layout
304 virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrameOrObj,
305 const SwRect& rFrame );
306
307 // The content may have changed (but it hasn't to have changed)
308 void InvalidateContent();
309
310 // The caretPos has changed
311 void InvalidateCursorPos();
312
313 // The Focus state has changed
314 void InvalidateFocus();
315
316 // Check states
317 // #i27301# - use new type definition for <_nStates>
318 void InvalidateStates( AccessibleStates _nStates );
319
320 // the XAccessibleRelationSet may have changed
321 void InvalidateRelation( sal_uInt16 nType );
322
323 void InvalidateTextSelection(); // #i27301# - text selection has changed
324 void InvalidateAttr(); // #i88069# - attributes has changed
325
327
328 // #i88070# - get additional child by index
329 vcl::Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
330
331 // #i88070# - get all additional accessible children
332 void GetAdditionalAccessibleChildren( std::vector< vcl::Window* >* pChildren );
333
334 const OUString& GetName() const { return m_sName; }
335
336 virtual bool HasCursor(); // required by map to remember that object
337
338 bool Select( SwPaM *pPaM, SdrObject *pObj, bool bAdd );
339 bool Select( SwPaM& rPaM )
340 {
341 return Select( &rPaM, nullptr, false );
342 }
343 bool Select( SdrObject *pObj, bool bAdd )
344 {
345 return Select( nullptr, pObj, bAdd );
346 }
347
348 //This method is used to update the selected state and fire the selected state changed event.
349 virtual bool SetSelectedState(bool bSelected);
350 bool IsSelectedInDoc() const { return m_isSelectedInDoc; }
351
352 bool IsDisposed() const;
353
354 static OUString GetResource(TranslateId pResId,
355 const OUString *pArg1 = nullptr,
356 const OUString *pArg2 = nullptr);
357};
358
359/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:42
constexpr OUStringLiteral sServiceName
Definition: accdoc.cxx:54
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 sal_Int64 SAL_CALL getAccessibleChildCount() override
Definition: acccontext.cxx:573
virtual ~SwAccessibleContext() override
Definition: acccontext.cxx:552
bool HasAdditionalAccessibleChildren()
virtual bool HasCursor()
const SwAccessibleMap * GetMap() const
Definition: acccontext.hxx:113
bool m_isRegisteredAtAccessibleMap
Definition: acccontext.hxx:94
virtual css::uno::Sequence< css::uno::Reference< css::accessibility::XAccessible > > SAL_CALL getAccessibleChildren() override
Definition: acccontext.cxx:630
const OUString & GetName() const
Definition: acccontext.hxx:334
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:933
void FireStateChangedEvent(sal_Int64 nState, bool bNewState)
Definition: acccontext.cxx:467
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:809
virtual OUString SAL_CALL getAccessibleName() override
Definition: acccontext.cxx:729
void ChildrenScrolled(const SwFrame *pFrame, const SwRect &rOldVisArea)
Definition: acccontext.cxx:120
css::uno::WeakReference< css::accessibility::XAccessible > m_xWeakParent
Definition: acccontext.hxx:72
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
Definition: acccontext.cxx:819
void DisposeShape(const SdrObject *pObj, ::accessibility::AccessibleShape *pAccImpl)
bool Select(SdrObject *pObj, bool bAdd)
Definition: acccontext.hxx:343
void SetName(const OUString &rName)
Definition: acccontext.hxx:99
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Definition: acccontext.cxx:735
virtual sal_Int16 SAL_CALL getAccessibleRole() override
Definition: acccontext.cxx:724
css::awt::Rectangle getBoundsImpl(bool bRelative)
Get bounding box.
Definition: acccontext.cxx:878
const SwViewShell * GetShell() const
Definition: acccontext.hxx:120
sal_Int16 GetRole() const
Definition: acccontext.hxx:100
virtual void InvalidateCursorPos_()
Definition: acccontext.cxx:433
virtual void InvalidateChildPosOrSize(const sw::access::SwAccessibleChild &rFrameOrObj, const SwRect &rFrame)
void FireAccessibleEvent(css::accessibility::AccessibleEventObject &rEvent)
Definition: acccontext.cxx:441
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:109
virtual void GetStates(sal_Int64 &rStateSet)
Definition: acccontext.cxx:481
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Definition: acccontext.cxx:693
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:758
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
Definition: acccontext.cxx:567
std::weak_ptr< SwAccessibleMap > m_wMap
note: the m_pMap is guaranteed to be valid until we hit the dtor ~SwAccessibleContext,...
Definition: acccontext.hxx:78
void ScrolledWithin(const SwRect &rOldVisArea)
Definition: acccontext.cxx:280
void DisposeChildren(const SwFrame *pFrame, bool bRecursive, bool bCanSkipInvisible)
Definition: acccontext.cxx:381
SwAccessibleMap * m_pMap
Definition: acccontext.hxx:74
vcl::Window * GetWindow()
Definition: acccontext.cxx:80
sal_uInt32 m_nClientId
Definition: acccontext.hxx:80
virtual void InvalidateFocus_()
Definition: acccontext.cxx:437
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:429
virtual void SAL_CALL grabFocus() override
Definition: acccontext.cxx:967
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
Definition: acccontext.cxx:702
void NotRegisteredAtAccessibleMap()
Definition: acccontext.hxx:190
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:778
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Definition: acccontext.cxx:742
bool Select(SwPaM *pPaM, SdrObject *pObj, bool bAdd)
virtual css::awt::Rectangle SAL_CALL getBounds() override
Definition: acccontext.cxx:928
std::mutex m_Mutex
Definition: acccontext.hxx:64
css::uno::Reference< css::accessibility::XAccessible > GetWeakParent() const
Definition: acccontext.cxx:72
void SetParent(SwAccessibleContext *pParent)
Definition: acccontext.cxx:64
SwAccessibleContext(std::shared_ptr< SwAccessibleMap > const &pMap, sal_Int16 nRole, const SwFrame *pFrame)
Definition: acccontext.cxx:536
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
Definition: acccontext.cxx:766
SwCursorShell * GetCursorShell()
convenience method to get SwCursorShell through accessibility map
Definition: acccontext.cxx:98
virtual css::awt::Size SAL_CALL getSize() override
Definition: acccontext.cxx:959
bool IsDisposed() const
Definition: acccontext.cxx:522
void Scrolled(const SwRect &rOldVisArea)
Definition: acccontext.cxx:261
bool IsSelectedInDoc() const
Definition: acccontext.hxx:350
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:116
void ScrolledOut(const SwRect &rOldVisArea)
Definition: acccontext.cxx:324
void InvalidateChildrenStates(const SwFrame *_pFrame, AccessibleStates _nStates)
Definition: acccontext.cxx:348
void InvalidateAttr()
#i88069# - attributes has changed
virtual void InvalidatePosOrSize(const SwRect &rFrame)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Definition: acccontext.cxx:583
void InvalidateStates(AccessibleStates _nStates)
bool Select(SwPaM &rPaM)
Definition: acccontext.hxx:339
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
Definition: acccontext.cxx:941
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParentImpl()
Definition: acccontext.cxx:671
SwViewShell * GetShell() const
Definition: accmap.hxx:173
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:188
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
float u
unsigned char sal_Bool