/src/libreoffice/include/editeng/AccessibleEditableTextPara.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 | | #ifndef INCLUDED_EDITENG_ACCESSIBLEEDITABLETEXTPARA_HXX |
21 | | #define INCLUDED_EDITENG_ACCESSIBLEEDITABLETEXTPARA_HXX |
22 | | |
23 | | #include <config_options.h> |
24 | | #include <rtl/ustring.hxx> |
25 | | #include <tools/gen.hxx> |
26 | | |
27 | | #include <com/sun/star/uno/Reference.hxx> |
28 | | #include <com/sun/star/accessibility/XAccessible.hpp> |
29 | | #include <com/sun/star/accessibility/XAccessibleEditableText.hpp> |
30 | | #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp> |
31 | | #include <com/sun/star/accessibility/XAccessibleHypertext.hpp> |
32 | | #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp> |
33 | | |
34 | | #include <comphelper/accessibletexthelper.hxx> |
35 | | #include <cppuhelper/implbase.hxx> |
36 | | #include <editeng/editengdllapi.h> |
37 | | #include <editeng/unoedprx.hxx> |
38 | | #include <unotools/weakref.hxx> |
39 | | |
40 | | class SvxViewForwarder; |
41 | | class MapMode; |
42 | | class SvxAccessibleTextAdapter; |
43 | | class SvxAccessibleTextEditViewAdapter; |
44 | | namespace accessibility { class AccessibleImageBullet; } |
45 | | |
46 | | namespace accessibility |
47 | | { |
48 | | |
49 | | class AccessibleParaManager; |
50 | | |
51 | | /** This class implements the actual text paragraphs for the EditEngine/Outliner UAA |
52 | | */ |
53 | | class UNLESS_MERGELIBS(EDITENG_DLLPUBLIC) AccessibleEditableTextPara final |
54 | | : public cppu::ImplInheritanceHelper< |
55 | | comphelper::OAccessible, css::accessibility::XAccessibleEditableText, |
56 | | css::accessibility::XAccessibleTextAttributes, css::accessibility::XAccessibleHypertext, |
57 | | css::accessibility::XAccessibleMultiLineText>, |
58 | | private ::comphelper::OCommonAccessibleText |
59 | | { |
60 | | |
61 | | // override OCommonAccessibleText methods |
62 | | virtual OUString implGetText() override; |
63 | | virtual css::lang::Locale implGetLocale() override; |
64 | | virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) override; |
65 | | virtual void implGetParagraphBoundary( const OUString& rtext, css::i18n::Boundary& rBoundary, sal_Int32 nIndex ) override; |
66 | | virtual void implGetLineBoundary( const OUString& rtext, css::i18n::Boundary& rBoundary, sal_Int32 nIndex ) override; |
67 | | |
68 | | public: |
69 | | /// Create accessible object for given parent |
70 | | // #i27138# |
71 | | // - add parameter <_pParaManager> (default value NULL) |
72 | | // This has to be the instance of <AccessibleParaManager>, which |
73 | | // created and manages this accessible paragraph. |
74 | | AccessibleEditableTextPara(const rtl::Reference<comphelper::OAccessible>& rpParent, |
75 | | const AccessibleParaManager* _pParaManager = nullptr); |
76 | | |
77 | | // XAccessibleContext |
78 | | virtual sal_Int64 SAL_CALL getAccessibleChildCount() override; |
79 | | virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int64 i ) override; |
80 | | virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override; |
81 | | virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override; |
82 | | virtual sal_Int16 SAL_CALL getAccessibleRole() override; |
83 | | virtual OUString SAL_CALL getAccessibleDescription() override; |
84 | | virtual OUString SAL_CALL getAccessibleName() override; |
85 | | virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override; |
86 | | virtual sal_Int64 SAL_CALL getAccessibleStateSet() override; |
87 | | virtual css::lang::Locale SAL_CALL getLocale() override; |
88 | | |
89 | | // OAccessible |
90 | | virtual css::awt::Rectangle implGetBounds() override; |
91 | | |
92 | | // XAccessibleComponent |
93 | | virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override; |
94 | | virtual void SAL_CALL grabFocus( ) override; |
95 | | virtual sal_Int32 SAL_CALL getForeground( ) override; |
96 | | virtual sal_Int32 SAL_CALL getBackground( ) override; |
97 | | |
98 | | // XAccessibleText (this comes implicitly inherited by XAccessibleEditableText AND by XAccessibleMultiLineText) |
99 | | virtual sal_Int32 SAL_CALL getCaretPosition() override; |
100 | | virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) override; |
101 | | virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) override; |
102 | | virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) override; |
103 | | virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) override; |
104 | | virtual sal_Int32 SAL_CALL getCharacterCount() override; |
105 | | virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& aPoint ) override; |
106 | | virtual OUString SAL_CALL getSelectedText() override; |
107 | | virtual sal_Int32 SAL_CALL getSelectionStart() override; |
108 | | virtual sal_Int32 SAL_CALL getSelectionEnd() override; |
109 | | virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
110 | | virtual OUString SAL_CALL getText() override; |
111 | | virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
112 | | /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine) |
113 | | virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
114 | | /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine) |
115 | | virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
116 | | /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine) |
117 | | virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override; |
118 | | virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
119 | | virtual sal_Bool SAL_CALL scrollSubstringTo( sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override; |
120 | | |
121 | | // XAccessibleEditableText |
122 | | virtual sal_Bool SAL_CALL cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
123 | | virtual sal_Bool SAL_CALL pasteText( sal_Int32 nIndex ) override; |
124 | | virtual sal_Bool SAL_CALL deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override; |
125 | | virtual sal_Bool SAL_CALL insertText( const OUString& sText, sal_Int32 nIndex ) override; |
126 | | virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) override; |
127 | | virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const css::uno::Sequence< css::beans::PropertyValue >& aAttributeSet ) override; |
128 | | virtual sal_Bool SAL_CALL setText( const OUString& sText ) override; |
129 | | |
130 | | // XAccessibleTextAttributes |
131 | | virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getDefaultAttributes( const css::uno::Sequence< OUString >& RequestedAttributes ) override; |
132 | | virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getRunAttributes( ::sal_Int32 Index, const css::uno::Sequence< OUString >& RequestedAttributes ) override; |
133 | | |
134 | | // XAccessibleHypertext |
135 | | virtual ::sal_Int32 SAL_CALL getHyperLinkCount( ) override; |
136 | | virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > SAL_CALL getHyperLink( ::sal_Int32 nLinkIndex ) override; |
137 | | virtual ::sal_Int32 SAL_CALL getHyperLinkIndex( ::sal_Int32 nCharIndex ) override; |
138 | | |
139 | | // XAccessibleMultiLineText |
140 | | virtual ::sal_Int32 SAL_CALL getLineNumberAtIndex( ::sal_Int32 nIndex ) override; |
141 | | virtual css::accessibility::TextSegment SAL_CALL getTextAtLineNumber( ::sal_Int32 nLineNo ) override; |
142 | | virtual css::accessibility::TextSegment SAL_CALL getTextAtLineWithCaret( ) override; |
143 | | virtual ::sal_Int32 SAL_CALL getNumberOfLineWithCaret( ) override; |
144 | | |
145 | | /** Set the current index in the accessibility parent |
146 | | |
147 | | @attention This method does not lock the SolarMutex, |
148 | | leaving that to the calling code. This is because only |
149 | | there potential deadlock situations can be resolved. Thus, |
150 | | make sure SolarMutex is locked when calling this. |
151 | | */ |
152 | | void SetIndexInParent( sal_Int32 nIndex ); |
153 | | |
154 | | /** Get the current index in the accessibility parent |
155 | | |
156 | | @attention This method does not lock the SolarMutex, |
157 | | leaving that to the calling code. This is because only |
158 | | there potential deadlock situations can be resolved. Thus, |
159 | | make sure SolarMutex is locked when calling this. |
160 | | */ |
161 | 0 | sal_Int32 GetIndexInParent() const { return mnIndexInParent; } |
162 | | |
163 | | /** Set the current paragraph number |
164 | | |
165 | | @attention This method does not lock the SolarMutex, |
166 | | leaving that to the calling code. This is because only |
167 | | there potential deadlock situations can be resolved. Thus, |
168 | | make sure SolarMutex is locked when calling this. |
169 | | */ |
170 | | void SetParagraphIndex( sal_Int32 nIndex ); |
171 | | |
172 | | /** Query the current paragraph number (0 - nParas-1) |
173 | | |
174 | | @attention This method does not lock the SolarMutex, |
175 | | leaving that to the calling code. This is because only |
176 | | there potential deadlock situations can be resolved. Thus, |
177 | | make sure SolarMutex is locked when calling this. |
178 | | */ |
179 | 0 | sal_Int32 GetParagraphIndex() const { return mnParagraphIndex; } |
180 | | |
181 | | /** Set the edit engine offset |
182 | | |
183 | | @attention This method does not lock the SolarMutex, |
184 | | leaving that to the calling code. This is because only |
185 | | there potential deadlock situations can be resolved. Thus, |
186 | | make sure SolarMutex is locked when calling this. |
187 | | */ |
188 | | void SetEEOffset( const Point& rOffset ); |
189 | | |
190 | | /** Set the EditEngine offset |
191 | | |
192 | | @attention This method does not lock the SolarMutex, |
193 | | leaving that to the calling code. This is because only |
194 | | there potential deadlock situations can be resolved. Thus, |
195 | | make sure SolarMutex is locked when calling this. |
196 | | */ |
197 | | void SetEditSource( SvxEditSourceAdapter* pEditSource ); |
198 | | |
199 | | void SAL_CALL dispose() override; |
200 | | |
201 | | /// Calls all Listener objects to tell them the change. Don't hold locks when calling this! |
202 | | void FireEvent(const sal_Int16 nEventId, const css::uno::Any& rNewValue = css::uno::Any(), const css::uno::Any& rOldValue = css::uno::Any()); |
203 | | |
204 | | /// Sets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this! |
205 | | void SetState( const sal_Int64 nStateId ); |
206 | | /// Unsets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this! |
207 | | void UnSetState( const sal_Int64 nStateId ); |
208 | | |
209 | | static tools::Rectangle LogicToPixel( const tools::Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder const & rForwarder ); |
210 | | |
211 | | SvxEditSourceAdapter& GetEditSource() const; |
212 | | |
213 | | /** Query the SvxTextForwarder for EditEngine access. |
214 | | |
215 | | @attention This method does not lock the SolarMutex, |
216 | | leaving that to the calling code. This is because only |
217 | | there potential deadlock situations can be resolved. Thus, |
218 | | make sure SolarMutex is locked when calling this. |
219 | | */ |
220 | | SvxAccessibleTextAdapter& GetTextForwarder() const; |
221 | | |
222 | | /** Query the SvxViewForwarder for EditEngine access. |
223 | | |
224 | | @attention This method does not lock the SolarMutex, |
225 | | leaving that to the calling code. This is because only |
226 | | there potential deadlock situations can be resolved. Thus, |
227 | | make sure SolarMutex is locked when calling this. |
228 | | */ |
229 | | SvxViewForwarder& GetViewForwarder() const; |
230 | | |
231 | | /** Query whether a GetEditViewForwarder( sal_False ) will return a forwarder |
232 | | |
233 | | @attention This method does not lock the SolarMutex, |
234 | | leaving that to the calling code. This is because only |
235 | | there potential deadlock situations can be resolved. Thus, |
236 | | make sure SolarMutex is locked when calling this. |
237 | | */ |
238 | | bool HaveEditView() const; |
239 | | |
240 | | /** Query the SvxEditViewForwarder for EditEngine access. |
241 | | |
242 | | @attention This method does not lock the SolarMutex, |
243 | | leaving that to the calling code. This is because only |
244 | | there potential deadlock situations can be resolved. Thus, |
245 | | make sure SolarMutex is locked when calling this. |
246 | | */ |
247 | | SvxAccessibleTextEditViewAdapter& GetEditViewForwarder( bool bCreate = false ) const; |
248 | | |
249 | | /** Send a TEXT_CHANGED event for this paragraph |
250 | | |
251 | | This method internally caters for calculating text |
252 | | differences, and sends the appropriate Anys in the |
253 | | Accessibility::TEXT_CHANGED event |
254 | | */ |
255 | | void TextChanged(); |
256 | | |
257 | | private: |
258 | | AccessibleEditableTextPara( const AccessibleEditableTextPara& ) = delete; |
259 | | AccessibleEditableTextPara& operator= ( const AccessibleEditableTextPara& ) = delete; |
260 | | |
261 | | /** Calculate character range of similar attributes |
262 | | |
263 | | @param nStartIndex |
264 | | Therein, the start of the character range with the same attributes is returned |
265 | | |
266 | | @param nEndIndex |
267 | | Therein, the end (exclusively) of the character range with the same attributes is returned |
268 | | |
269 | | @param nIndex |
270 | | The character index at where to look for similar character attributes |
271 | | |
272 | | @return false, if the method was not able to determine the range |
273 | | */ |
274 | | bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nIndex ); |
275 | | |
276 | | /// Do we have children? This is the case for image bullets |
277 | | bool HaveChildren(); |
278 | | |
279 | | /// If there is a bullet, return it's text length, otherwise return 0 |
280 | | sal_Int32 GetBulletTextLength() const; |
281 | | |
282 | 0 | const Point& GetEEOffset() const { return maEEOffset; } |
283 | | |
284 | | // Get text from forwarder |
285 | | OUString GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ); |
286 | | sal_Int32 GetTextLen() const; |
287 | | |
288 | | /** Get the current selection of this paragraph |
289 | | |
290 | | @return sal_False, if nothing in this paragraph is selected |
291 | | */ |
292 | | bool GetSelection(sal_Int32& nStartPos, sal_Int32& nEndPos ); |
293 | | |
294 | | /** create selection from Accessible selection. |
295 | | |
296 | | */ |
297 | | ESelection MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex ); |
298 | | ESelection MakeSelection( sal_Int32 nEEIndex ); |
299 | | ESelection MakeCursor( sal_Int32 nEEIndex ); |
300 | | |
301 | | // check whether index value is within permitted range |
302 | | |
303 | | /// Check whether 0<=nIndex<=n-1 |
304 | | void CheckIndex( sal_Int32 nIndex ); |
305 | | /// Check whether 0<=nIndex<=n |
306 | | void CheckPosition( sal_Int32 nIndex ); |
307 | | /// Check whether 0<=nStart<=n and 0<=nEnd<=n |
308 | | void CheckRange( sal_Int32 nStart, sal_Int32 nEnd ); |
309 | | |
310 | | void _correctValues( css::uno::Sequence< css::beans::PropertyValue >& rValues ); |
311 | | sal_Int32 SkipField(sal_Int32 nIndex, bool bForward); |
312 | | // get overlapped field, extend return string. Only extend forward for now |
313 | | void ExtendByField( css::accessibility::TextSegment& Segment ); |
314 | | OUString GetFieldTypeNameAtIndex(sal_Int32 nIndex); |
315 | | // the paragraph index in the edit engine (guarded by solar mutex) |
316 | | sal_Int32 mnParagraphIndex; |
317 | | |
318 | | // our current index in the parent (guarded by solar mutex) |
319 | | sal_Int32 mnIndexInParent; |
320 | | |
321 | | // the current edit source (guarded by solar mutex) |
322 | | SvxEditSourceAdapter* mpEditSource; |
323 | | |
324 | | // the possible child (for image bullets, guarded by solar mutex) |
325 | | unotools::WeakReference<AccessibleImageBullet> maImageBullet; |
326 | | |
327 | | // the last string used for an Accessibility::TEXT_CHANGED event (guarded by solar mutex) |
328 | | OUString maLastTextString; |
329 | | |
330 | | // the offset of the underlying EditEngine from the shape/cell (guarded by solar mutex) |
331 | | Point maEEOffset; |
332 | | |
333 | | // the current state set (updated from SetState/UnSetState and guarded by solar mutex) |
334 | | sal_Int64 mnStateSet; |
335 | | |
336 | | /// The shape we're the accessible for (unguarded) |
337 | | rtl::Reference<comphelper::OAccessible> mpParent; |
338 | | |
339 | | private: |
340 | | // Text paragraphs should provide FLOWS_TO and FLOWS_FROM relations (#i27138#) |
341 | | // the paragraph manager, which created this instance - is NULL, if |
342 | | // instance isn't created by AccessibleParaManager. |
343 | | // Needed for method <getAccessibleRelationSet()> to retrieve predecessor |
344 | | // paragraph and the successor paragraph. |
345 | | const AccessibleParaManager* mpParaManager; |
346 | | }; |
347 | | |
348 | | } // end of namespace accessibility |
349 | | |
350 | | #endif |
351 | | |
352 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |