/src/libreoffice/include/svx/AccessibleShape.hxx
Line | Count | Source |
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 <com/sun/star/accessibility/AccessibleScrollType.hpp> |
23 | | #include <com/sun/star/accessibility/TextSegment.hpp> |
24 | | #include <com/sun/star/accessibility/XAccessibleSelection.hpp> |
25 | | #include <com/sun/star/accessibility/XAccessibleGroupPosition.hpp> |
26 | | #include <com/sun/star/accessibility/XAccessibleHypertext.hpp> |
27 | | #include <com/sun/star/awt/Point.hpp> |
28 | | #include <com/sun/star/awt/Rectangle.hpp> |
29 | | #include <com/sun/star/awt/Size.hpp> |
30 | | #include <com/sun/star/document/XShapeEventListener.hpp> |
31 | | #include <com/sun/star/lang/EventObject.hpp> |
32 | | #include <com/sun/star/uno/Any.hxx> |
33 | | #include <com/sun/star/uno/Reference.hxx> |
34 | | #include <com/sun/star/uno/Sequence.hxx> |
35 | | #include <com/sun/star/uno/Type.hxx> |
36 | | #include <com/sun/star/lang/XUnoTunnel.hpp> |
37 | | #include <comphelper/servicehelper.hxx> |
38 | | #include <editeng/AccessibleContextBase.hxx> |
39 | | #include <rtl/ustring.hxx> |
40 | | #include <sal/types.h> |
41 | | #include <svx/AccessibleShapeTreeInfo.hxx> |
42 | | #include <svx/IAccessibleViewForwarderListener.hxx> |
43 | | #include <svx/svxdllapi.h> |
44 | | #include <memory> |
45 | | |
46 | | namespace com::sun::star { |
47 | | namespace drawing { class XShape; } |
48 | | } |
49 | | |
50 | | class SdrObject; |
51 | | |
52 | | namespace accessibility { |
53 | | |
54 | | class AccessibleShapeInfo; |
55 | | class AccessibleTextHelper; |
56 | | class ChildrenManager; |
57 | | class IAccessibleParent; |
58 | | |
59 | | /** This base class provides a base implementation for all shapes. |
60 | | |
61 | | <p>The children of a shape can stem from two sources which, in case of |
62 | | SVX and SD shapes, are mutually exclusive. This implementation, |
63 | | however, handles both simultaneously to cope with future extensions or |
64 | | shapes from other projects. |
65 | | <ul> |
66 | | <li>If this shape is a group shape, i.e. a |
67 | | SvxShapeGroup or a <type>Svx3DSceneObject</type>, it |
68 | | can have nested shapes.</li> |
69 | | <li>If this shape is a descendant from SvxShapeText |
70 | | then the text paragraphs are its children.</li> |
71 | | </ul> |
72 | | </p> |
73 | | |
74 | | <p>Accessible shapes do not listen for disposing() calls of the UNO |
75 | | shapes they make accessible. This is the task of their owner, usually a |
76 | | container, who can then call dispose() at the accessible object.</p> |
77 | | */ |
78 | | class SVX_DLLPUBLIC AccessibleShape |
79 | | : public cppu::ImplInheritanceHelper< |
80 | | AccessibleContextBase, css::accessibility::XAccessibleSelection, |
81 | | css::accessibility::XAccessibleGroupPosition, css::accessibility::XAccessibleHypertext, |
82 | | css::document::XShapeEventListener, css::lang::XUnoTunnel>, |
83 | | public IAccessibleViewForwarderListener |
84 | | { |
85 | | public: |
86 | | /** Create a new accessible object that makes the given shape accessible. |
87 | | @param rShapeInfo |
88 | | This object contains all information specific to the new |
89 | | accessible shape. That are e.g. the shape to be made accessible |
90 | | and the accessible object that will become the parent of the new |
91 | | object. |
92 | | @param rShapeTreeInfo |
93 | | Bundle of information passed to this shape and all of its descendants. |
94 | | @attention |
95 | | Always call the <member>init</member> method after creating a |
96 | | new accessible shape. This is one way to overcome the potential |
97 | | problem of registering the new object with e.g. event |
98 | | broadcasters. That would delete the new object if a broadcaster |
99 | | would not keep a strong reference to the new object. |
100 | | */ |
101 | | AccessibleShape ( |
102 | | const AccessibleShapeInfo& rShapeInfo, |
103 | | const AccessibleShapeTreeInfo& rShapeTreeInfo); |
104 | | //Solution: Overwrite the object's current name. |
105 | | virtual OUString SAL_CALL getAccessibleName() override; |
106 | | virtual OUString SAL_CALL getAccessibleDescription() override; |
107 | | virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet> SAL_CALL getAccessibleRelationSet() override; |
108 | | //===== XAccessibleSelection ============================================ |
109 | | |
110 | | virtual void SAL_CALL selectAccessibleChild( |
111 | | sal_Int64 nChildIndex ) override; |
112 | | |
113 | | virtual sal_Bool SAL_CALL isAccessibleChildSelected( |
114 | | sal_Int64 nChildIndex ) override; |
115 | | |
116 | | virtual void SAL_CALL clearAccessibleSelection( ) override; |
117 | | |
118 | | virtual void SAL_CALL selectAllAccessibleChildren( ) override; |
119 | | |
120 | | virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount( ) override; |
121 | | |
122 | | virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( |
123 | | sal_Int64 nSelectedChildIndex ) override; |
124 | | |
125 | | virtual void SAL_CALL deselectAccessibleChild( |
126 | | sal_Int64 nSelectedChildIndex ) override; |
127 | | |
128 | | /// Return this object's role. |
129 | | virtual sal_Int16 SAL_CALL getAccessibleRole() override; |
130 | | //===== XAccessibleGroupPosition ========================================= |
131 | | virtual css::uno::Sequence< sal_Int32 > SAL_CALL |
132 | | getGroupPosition( const css::uno::Any& rAny ) override; |
133 | | virtual OUString SAL_CALL getObjectLink( const css::uno::Any& accoject ) override; |
134 | | /** The destructor releases its children manager and text engine if |
135 | | still existent. These are responsible to send appropriate events. |
136 | | */ |
137 | | virtual ~AccessibleShape() override; |
138 | | |
139 | | /** Initialize a new shape. See the documentation of the constructor |
140 | | for the reason of this method's existence. |
141 | | */ |
142 | | virtual void Init(); |
143 | | |
144 | | /** Set the specified state. If the state is <const>FOCUSED</const> |
145 | | then, additionally to the inherited functionality, the focus |
146 | | listeners registered with the XAccessibleComponent |
147 | | interface are called (if that state really changes). |
148 | | |
149 | | @param aState |
150 | | The state to turn on. |
151 | | |
152 | | @return |
153 | | The returned flag indicates whether the specified state has been |
154 | | changed (<TRUE/>), i.e. it has formerly not been set. |
155 | | */ |
156 | | virtual bool SetState (sal_Int64 aState) override; |
157 | | |
158 | | /** Reset the specified state. If the state is <const>FOCUSED</const> |
159 | | then, additionally to the inherited functionality, the focus |
160 | | listeners registered with the XAccessibleComponent |
161 | | interface are called (if that state really changes). |
162 | | |
163 | | @param aState |
164 | | The state to turn off. |
165 | | |
166 | | @return |
167 | | The returned flag indicates whether the specified state has been |
168 | | changed (<TRUE/>), i.e. it has formerly been set. |
169 | | */ |
170 | | virtual bool ResetState (sal_Int64 aState) override; |
171 | | |
172 | | /** Return the state of the specified state. Take the |
173 | | <const>FOCUSED</const> state from the accessible edit engine. |
174 | | |
175 | | @param aState |
176 | | The state for which to return its value. |
177 | | @return |
178 | | A value of <TRUE/> indicates that the state is set. A <FALSE/> |
179 | | value indicates an unset state or the inability to access the |
180 | | entity that manages the state set. |
181 | | |
182 | | */ |
183 | | bool GetState (sal_Int64 aState); |
184 | | |
185 | | |
186 | | //===== XAccessibleContext ============================================== |
187 | | |
188 | | /// Return the number of currently visible children. |
189 | | virtual sal_Int64 SAL_CALL |
190 | | getAccessibleChildCount() override; |
191 | | |
192 | | /** Return the specified child. |
193 | | @param nIndex |
194 | | Index of the requested child. |
195 | | @return |
196 | | Reference of the requested child which is the accessible object |
197 | | of a visible shape. |
198 | | @throws IndexOutOfBoundsException |
199 | | Throws an exception if the index is not valid. |
200 | | */ |
201 | | virtual css::uno::Reference< |
202 | | css::accessibility::XAccessible> SAL_CALL |
203 | | getAccessibleChild (sal_Int64 nIndex) override; |
204 | | |
205 | | |
206 | | /// Return the set of current states. |
207 | | virtual sal_Int64 SAL_CALL |
208 | | getAccessibleStateSet() override; |
209 | | |
210 | | /// Return this objects index among the parents children. |
211 | | virtual sal_Int64 SAL_CALL |
212 | | getAccessibleIndexInParent() override; |
213 | | |
214 | | // OAccessible |
215 | | virtual css::awt::Rectangle implGetBounds() override; |
216 | | virtual std::unordered_map<OUString, OUString> implGetExtendedAttributes() override; |
217 | | |
218 | | //===== XAccessibleComponent ============================================ |
219 | | |
220 | | virtual css::uno::Reference< |
221 | | css::accessibility::XAccessible > SAL_CALL |
222 | | getAccessibleAtPoint (const css::awt::Point& aPoint) override; |
223 | | |
224 | | virtual sal_Int32 SAL_CALL getForeground() override; |
225 | | |
226 | | virtual sal_Int32 SAL_CALL getBackground() override; |
227 | | |
228 | | //===== XAccessibleEventBroadcaster ===================================== |
229 | | |
230 | | /** This call is forwarded to a) the base class and b) to the |
231 | | accessible edit engine if it is present. |
232 | | |
233 | | @param rxListener |
234 | | This listener is informed about accessibility events. |
235 | | */ |
236 | | virtual void SAL_CALL |
237 | | addAccessibleEventListener ( |
238 | | const css::uno::Reference< |
239 | | css::accessibility::XAccessibleEventListener >& rxListener) override; |
240 | | |
241 | | /** This call is forwarded to a) the base class and b) to the |
242 | | accessible edit engine if it is present. |
243 | | |
244 | | @param rxListener |
245 | | This listener will not be informed about accessibility events |
246 | | anymore. |
247 | | */ |
248 | | virtual void SAL_CALL |
249 | | removeAccessibleEventListener ( |
250 | | const css::uno::Reference< |
251 | | css::accessibility::XAccessibleEventListener >& rxListener) override; |
252 | | |
253 | | //===== XTypeProvider =================================================== |
254 | | |
255 | | virtual css::uno::Sequence< css::uno::Type> SAL_CALL |
256 | | getTypes() override; |
257 | | |
258 | | //===== IAccessibleViewForwarderListener ================================ |
259 | | virtual void ViewForwarderChanged() override; |
260 | | |
261 | | /** Listen for disposing events of the model. The accessible shape |
262 | | remains functional when this happens. |
263 | | */ |
264 | | void disposing (const css::lang::EventObject& Source); |
265 | | |
266 | | //===== document::XShapeEventListener ======================================== |
267 | | |
268 | | virtual void SAL_CALL |
269 | | notifyShapeEvent (const css::document::EventObject& rEventObject) override; |
270 | | |
271 | | |
272 | | //===== XUnoTunnel ======================================================== |
273 | | |
274 | | UNO3_GETIMPLEMENTATION_DECL(AccessibleShape) |
275 | | |
276 | | //===== XAccessibleHypertext ======================================================== |
277 | | virtual sal_Int32 SAL_CALL getHyperLinkCount() override; |
278 | | virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > |
279 | | SAL_CALL getHyperLink( sal_Int32 nLinkIndex ) override; |
280 | | virtual sal_Int32 SAL_CALL getHyperLinkIndex( sal_Int32 nCharIndex ) override; |
281 | | //===== XAccessibleText ================================================== |
282 | | virtual sal_Int32 SAL_CALL getCaretPosition( ) override; |
283 | | virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) override; |
284 | | virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) override;//Shen Zhen Jie changed sal_Unicode to sal_uInt32; change back to sal_Unicode |
285 | | virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) override; |
286 | | virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) override; |
287 | | virtual sal_Int32 SAL_CALL getCharacterCount( ) override; |
288 | | virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& aPoint ) override; |
289 | | virtual OUString SAL_CALL getSelectedText( ) override; |
290 | | virtual sal_Int32 SAL_CALL getSelectionStart( ) override; |
291 | | virtual sal_Int32 SAL_CALL getSelectionEnd( ) override; |
292 | | virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
293 | | virtual OUString SAL_CALL getText( ) override; |
294 | | virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
295 | | virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
296 | | virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
297 | | virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
298 | | virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
299 | | virtual sal_Bool SAL_CALL scrollSubstringTo( sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override; |
300 | | |
301 | | //===== Misc ======================================================== |
302 | | |
303 | | const css::uno::Reference< css::drawing::XShape >& |
304 | 0 | GetXShape() const { return mxShape; } |
305 | | |
306 | | /** set the index _nIndex at the accessible shape |
307 | | @param _nIndex |
308 | | The new index in parent. |
309 | | */ |
310 | 0 | void setIndexInParent(sal_Int32 _nIndex) { m_nIndexInParent = _nIndex; } |
311 | | |
312 | | protected: |
313 | | /// Children manager. May be empty if there are no children. |
314 | | std::unique_ptr<ChildrenManager> mpChildrenManager; |
315 | | |
316 | | /// Reference to the actual shape. |
317 | | css::uno::Reference< |
318 | | css::drawing::XShape> mxShape; |
319 | | |
320 | | /** Bundle of information passed to all shapes in a document tree. |
321 | | */ |
322 | | AccessibleShapeTreeInfo maShapeTreeInfo; |
323 | | |
324 | | /** the index in parent. |
325 | | */ |
326 | | sal_Int32 m_nIndexInParent; |
327 | | |
328 | | /** The accessible text engine. May be NULL if it can not be created. |
329 | | */ |
330 | | std::unique_ptr<AccessibleTextHelper> mpText; |
331 | | |
332 | | /** This object can be used to modify the child list of our parent. |
333 | | */ |
334 | | IAccessibleParent* mpParent; |
335 | | |
336 | | /** This object can be removed when we have an extra interface to ask if the shape is selected |
337 | | */ |
338 | | SdrObject* m_pShape; |
339 | | |
340 | | /** This method is called from the component helper base class while |
341 | | disposing. |
342 | | */ |
343 | | virtual void SAL_CALL disposing() override; |
344 | | |
345 | | /** Create a base name string that contains the accessible name. |
346 | | |
347 | | @throws css::uno::RuntimeException |
348 | | */ |
349 | | virtual OUString |
350 | | CreateAccessibleBaseName(); |
351 | | |
352 | | /** Create a unique name string that contains the accessible name. The |
353 | | name consists of the base name and the index. |
354 | | */ |
355 | | virtual OUString |
356 | | CreateAccessibleName() override; |
357 | | |
358 | | /// @throws css::uno::RuntimeException |
359 | | OUString |
360 | | GetFullAccessibleName(AccessibleShape *shape); |
361 | | virtual OUString GetStyle() const; |
362 | | /** Update the <const>OPAQUE</const> and <const>SELECTED</const> state. |
363 | | */ |
364 | | void UpdateStates(); |
365 | | |
366 | | private: |
367 | | AccessibleShape (const AccessibleShape&) = delete; |
368 | | AccessibleShape& operator= (const AccessibleShape&) = delete; |
369 | | //Old accessible name |
370 | | OUString m_aAccName; |
371 | | |
372 | | /** Call this method when the title, name, or description of the mxShape |
373 | | member (may) have been changed. |
374 | | This method adapts the name and description members of the |
375 | | AccessibleContextBase base class. |
376 | | */ |
377 | | void UpdateNameAndDescription(); |
378 | | }; |
379 | | |
380 | | } // end of namespace accessibility |
381 | | |
382 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |