android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / acccontext.hxx
blobd649390896224778df6d20afa2e83c82bee68e41
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
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 #include <unotools/resmgr.hxx>
31 #include <memory>
32 #include <mutex>
34 namespace vcl { class Window; }
35 class SwCursorShell;
36 class SdrObject;
37 class SwPaM;
38 namespace accessibility {
39 class AccessibleShape;
42 inline constexpr OUStringLiteral sAccessibleServiceName = u"com.sun.star.accessibility.Accessible";
44 class SwAccessibleContext :
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
53 public SwAccessibleFrame
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.
58 friend class SwAccessibleSelectionHelper;
59 #if OSL_DEBUG_LEVEL > 0
60 friend class SwAccessibleMap;
61 #endif
63 protected:
64 mutable std::mutex m_Mutex;
66 private:
67 OUString m_sName; // immutable outside constructor
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;
74 SwAccessibleMap *m_pMap; // must be protected by solar mutex
75 /// note: the m_pMap is guaranteed to be valid until we hit the
76 /// dtor ~SwAccessibleContext, then m_wMap must be checked if it's still
77 /// alive, after locking SolarMutex (alternatively, Dispose clears m_pMap)
78 std::weak_ptr<SwAccessibleMap> m_wMap;
80 sal_uInt32 m_nClientId; // client id in the AccessibleEventNotifier queue
81 sal_Int16 m_nRole; // immutable outside constructor
83 // The current states (protected by mutex)
84 bool m_isShowingState : 1;
85 bool m_isEditableState : 1;
86 bool m_isOpaqueState : 1;
87 bool m_isDefuncState : 1;
89 // Are we currently disposing that object (protected by solar mutex)?
90 bool m_isDisposing : 1;
92 // #i85634# - boolean, indicating if the accessible context is
93 // in general registered at the accessible map.
94 bool m_isRegisteredAtAccessibleMap;
96 void InitStates();
98 protected:
99 void SetName( const OUString& rName ) { m_sName = rName; }
100 sal_Int16 GetRole() const
102 return m_nRole;
104 //This flag is used to mark the object's selected state.
105 bool m_isSelectedInDoc;
106 void SetParent( SwAccessibleContext *pParent );
107 css::uno::Reference< css::accessibility::XAccessible> GetWeakParent() const;
109 bool IsDisposing() const { return m_isDisposing; }
111 vcl::Window *GetWindow();
112 SwAccessibleMap *GetMap() { return m_pMap; }
113 const SwAccessibleMap *GetMap() const { return m_pMap; }
115 /** convenience method to get the SwViewShell through accessibility map */
116 SwViewShell* GetShell()
118 return GetMap()->GetShell();
120 const SwViewShell* GetShell() const
122 return GetMap()->GetShell();
125 /** convenience method to get SwCursorShell through accessibility map
126 * @returns SwCursorShell, or NULL if none is found */
127 SwCursorShell* GetCursorShell();
128 const SwCursorShell* GetCursorShell() const;
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 );
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 );
139 // A child has been moved while setting the visible area
140 void ScrolledWithin( const SwRect& rOldVisArea );
142 // The has been added while setting the visible area
143 void ScrolledIn();
145 // The context has to be removed while setting the visible area
146 void ScrolledOut( const SwRect& rOldVisArea );
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 );
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);
159 void DisposeShape( const SdrObject *pObj,
160 ::accessibility::AccessibleShape *pAccImpl );
161 void ScrolledInShape( ::accessibility::AccessibleShape *pAccImpl );
163 virtual void InvalidateContent_( bool bVisibleDataFired );
165 virtual void InvalidateCursorPos_();
166 virtual void InvalidateFocus_();
168 public:
169 void FireAccessibleEvent( css::accessibility::AccessibleEventObject& rEvent );
171 protected:
172 // broadcast visual data event
173 void FireVisibleDataEvent();
175 // broadcast state change event
176 void FireStateChangedEvent( sal_Int64 nState, bool bNewState );
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 );
183 bool IsEditableState();
185 /// @throws css::uno::RuntimeException
186 css::awt::Rectangle
187 getBoundsImpl(bool bRelative);
189 // #i85634#
190 void NotRegisteredAtAccessibleMap()
192 m_isRegisteredAtAccessibleMap = false;
194 void RemoveFrameFromAccessibleMap();
196 void ThrowIfDisposed();
198 virtual ~SwAccessibleContext() override;
200 // Return a reference to the parent.
201 css::uno::Reference< css::accessibility::XAccessible>
202 getAccessibleParentImpl();
204 public:
205 SwAccessibleContext( std::shared_ptr<SwAccessibleMap> const& pMap,
206 sal_Int16 nRole, const SwFrame *pFrame );
208 // XAccessible
210 // Return the XAccessibleContext.
211 virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL
212 getAccessibleContext() override;
214 // XAccessibleContext
216 // Return the number of currently visible children.
217 virtual sal_Int64 SAL_CALL getAccessibleChildCount() override;
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;
223 virtual css::uno::Sequence<css::uno::Reference< css::accessibility::XAccessible>> SAL_CALL
224 getAccessibleChildren() override;
226 // Return a reference to the parent.
227 virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
228 getAccessibleParent() override;
230 // Return this objects index among the parents children.
231 virtual sal_Int64 SAL_CALL
232 getAccessibleIndexInParent() override;
234 // Return this object's role.
235 virtual sal_Int16 SAL_CALL
236 getAccessibleRole() override;
238 // getAccessibleDescription() is abstract
240 // Return the object's current name.
241 virtual OUString SAL_CALL
242 getAccessibleName() override;
244 // Return NULL to indicate that an empty relation set.
245 virtual css::uno::Reference<
246 css::accessibility::XAccessibleRelationSet> SAL_CALL
247 getAccessibleRelationSet() override;
249 // Return the set of current states.
250 virtual sal_Int64 SAL_CALL getAccessibleStateSet() override;
252 /** Return the parents locale or throw exception if this object has no
253 parent yet/anymore. */
254 virtual css::lang::Locale SAL_CALL
255 getLocale() override;
257 // XAccessibleEventBroadcaster
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;
264 // XAccessibleComponent
265 virtual sal_Bool SAL_CALL containsPoint(
266 const css::awt::Point& aPoint ) override;
268 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(
269 const css::awt::Point& aPoint ) override;
271 virtual css::awt::Rectangle SAL_CALL getBounds() override;
273 virtual css::awt::Point SAL_CALL getLocation() override;
275 virtual css::awt::Point SAL_CALL getLocationOnScreen() override;
277 virtual css::awt::Size SAL_CALL getSize() override;
279 virtual void SAL_CALL grabFocus() override;
281 virtual sal_Int32 SAL_CALL getForeground() override;
282 virtual sal_Int32 SAL_CALL getBackground() override;
284 // XServiceInfo
286 // getImplementationName() and getSupportedServiceNames are abstract
288 /** Return whether the specified service is supported by this class. */
289 virtual sal_Bool SAL_CALL
290 supportsService (const OUString& sServiceName) override;
292 // thread safe C++ interface
294 // The object is not visible any longer and should be destroyed
295 virtual void Dispose(bool bRecursive, bool bCanSkipInvisible = true);
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);
300 // The object has been moved by the layout
301 virtual void InvalidatePosOrSize( const SwRect& rFrame );
303 // The child object has been moved by the layout
304 virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrameOrObj,
305 const SwRect& rFrame );
307 // The content may have changed (but it hasn't to have changed)
308 void InvalidateContent();
310 // The caretPos has changed
311 void InvalidateCursorPos();
313 // The Focus state has changed
314 void InvalidateFocus();
316 // Check states
317 // #i27301# - use new type definition for <_nStates>
318 void InvalidateStates( AccessibleStates _nStates );
320 // the XAccessibleRelationSet may have changed
321 void InvalidateRelation( sal_uInt16 nType );
323 void InvalidateTextSelection(); // #i27301# - text selection has changed
324 void InvalidateAttr(); // #i88069# - attributes has changed
326 bool HasAdditionalAccessibleChildren();
328 // #i88070# - get additional child by index
329 vcl::Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex );
331 // #i88070# - get all additional accessible children
332 void GetAdditionalAccessibleChildren( std::vector< vcl::Window* >* pChildren );
334 const OUString& GetName() const { return m_sName; }
336 virtual bool HasCursor(); // required by map to remember that object
338 bool Select( SwPaM *pPaM, SdrObject *pObj, bool bAdd );
339 bool Select( SwPaM& rPaM )
341 return Select( &rPaM, nullptr, false );
343 bool Select( SdrObject *pObj, bool bAdd )
345 return Select( nullptr, pObj, bAdd );
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; }
352 bool IsDisposed() const;
354 static OUString GetResource(TranslateId pResId,
355 const OUString *pArg1 = nullptr,
356 const OUString *pArg2 = nullptr);
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */