bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / editeng / AccessibleEditableTextPara.hxx
blobd2b07f965c3d1c7404541f19f281a6988ca5e51d
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 #ifndef INCLUDED_EDITENG_ACCESSIBLEEDITABLETEXTPARA_HXX
21 #define INCLUDED_EDITENG_ACCESSIBLEEDITABLETEXTPARA_HXX
23 #include <rtl/ustring.hxx>
24 #include <tools/gen.hxx>
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/accessibility/XAccessible.hpp>
31 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
32 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
33 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
34 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
35 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
36 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
37 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
39 #include <comphelper/accessibletexthelper.hxx>
40 #include <editeng/AccessibleParaManager.hxx>
41 #include <editeng/editdata.hxx>
42 #include <editeng/editengdllapi.h>
44 class SvxViewForwarder;
45 class MapMode;
46 class SvxAccessibleTextAdapter;
47 class SvxAccessibleTextEditViewAdapter;
48 namespace accessibility { class AccessibleImageBullet; }
50 namespace accessibility
52 typedef ::cppu::WeakComponentImplHelper< css::accessibility::XAccessible,
53 css::accessibility::XAccessibleContext,
54 css::accessibility::XAccessibleComponent,
55 css::accessibility::XAccessibleEditableText,
56 css::accessibility::XAccessibleEventBroadcaster,
57 css::accessibility::XAccessibleTextAttributes,
58 css::accessibility::XAccessibleHypertext,
59 css::accessibility::XAccessibleMultiLineText,
60 css::lang::XServiceInfo > AccessibleTextParaInterfaceBase;
62 /** This class implements the actual text paragraphs for the EditEngine/Outliner UAA
64 class EDITENG_DLLPUBLIC AccessibleEditableTextPara final : public ::cppu::BaseMutex, public AccessibleTextParaInterfaceBase, private ::comphelper::OCommonAccessibleText
67 // override OCommonAccessibleText methods
68 virtual OUString implGetText() override;
69 virtual css::lang::Locale implGetLocale() override;
70 virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) override;
71 virtual void implGetParagraphBoundary( const OUString& rtext, css::i18n::Boundary& rBoundary, sal_Int32 nIndex ) override;
72 virtual void implGetLineBoundary( const OUString& rtext, css::i18n::Boundary& rBoundary, sal_Int32 nIndex ) override;
74 public:
75 /// Create accessible object for given parent
76 // #i27138#
77 // - add parameter <_pParaManager> (default value NULL)
78 // This has to be the instance of <AccessibleParaManager>, which
79 // created and manages this accessible paragraph.
80 AccessibleEditableTextPara ( const css::uno::Reference< css::accessibility::XAccessible >& rParent,
81 const AccessibleParaManager* _pParaManager = nullptr );
83 virtual ~AccessibleEditableTextPara () override;
85 // XInterface
86 virtual css::uno::Any SAL_CALL queryInterface (const css::uno::Type & rType) override;
88 // XAccessible
89 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override;
91 // XAccessibleContext
92 virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
93 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) override;
94 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override;
95 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override;
96 virtual sal_Int16 SAL_CALL getAccessibleRole() override;
97 /// Maximal length of text returned by getAccessibleDescription()
98 enum { MaxDescriptionLen = 40 };
99 virtual OUString SAL_CALL getAccessibleDescription() override;
100 virtual OUString SAL_CALL getAccessibleName() override;
101 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override;
102 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override;
103 virtual css::lang::Locale SAL_CALL getLocale() override;
105 // XAccessibleEventBroadcaster
106 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
107 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) override;
109 // XAccessibleComponent
110 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) override;
111 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) override;
112 virtual css::awt::Rectangle SAL_CALL getBounds( ) override;
113 virtual css::awt::Point SAL_CALL getLocation( ) override;
114 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) override;
115 virtual css::awt::Size SAL_CALL getSize( ) override;
116 virtual void SAL_CALL grabFocus( ) override;
117 virtual sal_Int32 SAL_CALL getForeground( ) override;
118 virtual sal_Int32 SAL_CALL getBackground( ) override;
120 // XAccessibleText (this comes implicitly inherited by XAccessibleEditableText AND by XAccessibleMultiLineText)
121 virtual sal_Int32 SAL_CALL getCaretPosition() override;
122 virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) override;
123 virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) override;
124 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) override;
125 virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) override;
126 virtual sal_Int32 SAL_CALL getCharacterCount() override;
127 virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& aPoint ) override;
128 virtual OUString SAL_CALL getSelectedText() override;
129 virtual sal_Int32 SAL_CALL getSelectionStart() override;
130 virtual sal_Int32 SAL_CALL getSelectionEnd() override;
131 virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
132 virtual OUString SAL_CALL getText() override;
133 virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
134 /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
135 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
136 /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
137 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
138 /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
139 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
140 virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
142 // XAccessibleEditableText
143 virtual sal_Bool SAL_CALL cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
144 virtual sal_Bool SAL_CALL pasteText( sal_Int32 nIndex ) override;
145 virtual sal_Bool SAL_CALL deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
146 virtual sal_Bool SAL_CALL insertText( const OUString& sText, sal_Int32 nIndex ) override;
147 virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) override;
148 virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const css::uno::Sequence< css::beans::PropertyValue >& aAttributeSet ) override;
149 virtual sal_Bool SAL_CALL setText( const OUString& sText ) override;
151 // XAccessibleTextAttributes
152 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getDefaultAttributes( const css::uno::Sequence< OUString >& RequestedAttributes ) override;
153 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getRunAttributes( ::sal_Int32 Index, const css::uno::Sequence< OUString >& RequestedAttributes ) override;
155 // XAccessibleHypertext
156 virtual ::sal_Int32 SAL_CALL getHyperLinkCount( ) override;
157 virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > SAL_CALL getHyperLink( ::sal_Int32 nLinkIndex ) override;
158 virtual ::sal_Int32 SAL_CALL getHyperLinkIndex( ::sal_Int32 nCharIndex ) override;
160 // XAccessibleMultiLineText
161 virtual ::sal_Int32 SAL_CALL getLineNumberAtIndex( ::sal_Int32 nIndex ) override;
162 virtual css::accessibility::TextSegment SAL_CALL getTextAtLineNumber( ::sal_Int32 nLineNo ) override;
163 virtual css::accessibility::TextSegment SAL_CALL getTextAtLineWithCaret( ) override;
164 virtual ::sal_Int32 SAL_CALL getNumberOfLineWithCaret( ) override;
166 // XServiceInfo
167 virtual OUString SAL_CALL getImplementationName() override;
168 virtual sal_Bool SAL_CALL supportsService (const OUString& sServiceName) override;
169 virtual css::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() override;
171 /** Set the current index in the accessibility parent
173 @attention This method does not lock the SolarMutex,
174 leaving that to the calling code. This is because only
175 there potential deadlock situations can be resolved. Thus,
176 make sure SolarMutex is locked when calling this.
178 void SetIndexInParent( sal_Int32 nIndex );
180 /** Get the current index in the accessibility parent
182 @attention This method does not lock the SolarMutex,
183 leaving that to the calling code. This is because only
184 there potential deadlock situations can be resolved. Thus,
185 make sure SolarMutex is locked when calling this.
187 sal_Int32 GetIndexInParent() const { return mnIndexInParent; }
189 /** Set the current paragraph number
191 @attention This method does not lock the SolarMutex,
192 leaving that to the calling code. This is because only
193 there potential deadlock situations can be resolved. Thus,
194 make sure SolarMutex is locked when calling this.
196 void SetParagraphIndex( sal_Int32 nIndex );
198 /** Query the current paragraph number (0 - nParas-1)
200 @attention This method does not lock the SolarMutex,
201 leaving that to the calling code. This is because only
202 there potential deadlock situations can be resolved. Thus,
203 make sure SolarMutex is locked when calling this.
205 sal_Int32 GetParagraphIndex() const { return mnParagraphIndex; }
207 /** Set the edit engine offset
209 @attention This method does not lock the SolarMutex,
210 leaving that to the calling code. This is because only
211 there potential deadlock situations can be resolved. Thus,
212 make sure SolarMutex is locked when calling this.
214 void SetEEOffset( const Point& rOffset );
216 /** Set the EditEngine offset
218 @attention This method does not lock the SolarMutex,
219 leaving that to the calling code. This is because only
220 there potential deadlock situations can be resolved. Thus,
221 make sure SolarMutex is locked when calling this.
223 void SetEditSource( SvxEditSourceAdapter* pEditSource );
225 /** Dispose this object
227 Notifies and deregisters the listeners, drops all references.
229 void Dispose();
231 /// Calls all Listener objects to tell them the change. Don't hold locks when calling this!
232 void FireEvent(const sal_Int16 nEventId, const css::uno::Any& rNewValue = css::uno::Any(), const css::uno::Any& rOldValue = css::uno::Any() ) const;
234 /// Sets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this!
235 void SetState( const sal_Int16 nStateId );
236 /// Unsets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this!
237 void UnSetState( const sal_Int16 nStateId );
239 static tools::Rectangle LogicToPixel( const tools::Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder const & rForwarder );
241 SvxEditSourceAdapter& GetEditSource() const;
243 /** Query the SvxTextForwarder for EditEngine access.
245 @attention This method does not lock the SolarMutex,
246 leaving that to the calling code. This is because only
247 there potential deadlock situations can be resolved. Thus,
248 make sure SolarMutex is locked when calling this.
250 SvxAccessibleTextAdapter& GetTextForwarder() const;
252 /** Query the SvxViewForwarder for EditEngine access.
254 @attention This method does not lock the SolarMutex,
255 leaving that to the calling code. This is because only
256 there potential deadlock situations can be resolved. Thus,
257 make sure SolarMutex is locked when calling this.
259 SvxViewForwarder& GetViewForwarder() const;
261 /** Query whether a GetEditViewForwarder( sal_False ) will return a forwarder
263 @attention This method does not lock the SolarMutex,
264 leaving that to the calling code. This is because only
265 there potential deadlock situations can be resolved. Thus,
266 make sure SolarMutex is locked when calling this.
268 bool HaveEditView() const;
270 /** Query the SvxEditViewForwarder for EditEngine access.
272 @attention This method does not lock the SolarMutex,
273 leaving that to the calling code. This is because only
274 there potential deadlock situations can be resolved. Thus,
275 make sure SolarMutex is locked when calling this.
277 SvxAccessibleTextEditViewAdapter& GetEditViewForwarder( bool bCreate = false ) const;
279 /** Send a TEXT_CHANGED event for this paragraph
281 This method internally caters for calculating text
282 differences, and sends the appropriate Anys in the
283 Accessibility::TEXT_CHANGED event
285 void TextChanged();
287 private:
288 AccessibleEditableTextPara( const AccessibleEditableTextPara& ) = delete;
289 AccessibleEditableTextPara& operator= ( const AccessibleEditableTextPara& ) = delete;
291 /** Calculate character range of similar attributes
293 @param nStartIndex
294 Therein, the start of the character range with the same attributes is returned
296 @param nEndIndex
297 Therein, the end (exclusively) of the character range with the same attributes is returned
299 @param nIndex
300 The character index at where to look for similar character attributes
302 @return false, if the method was not able to determine the range
304 bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nIndex );
306 int getNotifierClientId() const { return mnNotifierClientId; }
308 /// Do we have children? This is the case for image bullets
309 bool HaveChildren();
311 const Point& GetEEOffset() const { return maEEOffset; }
313 // Get text from forwarder
314 OUString GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex );
315 sal_Int32 GetTextLen() const;
317 /** Get the current selection of this paragraph
319 @return sal_False, if nothing in this paragraph is selected
321 bool GetSelection(sal_Int32& nStartPos, sal_Int32& nEndPos );
323 /** create selection from Accessible selection.
326 ESelection MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex );
327 ESelection MakeSelection( sal_Int32 nEEIndex );
328 ESelection MakeCursor( sal_Int32 nEEIndex );
330 // check whether index value is within permitted range
332 /// Check whether 0<=nIndex<=n-1
333 void CheckIndex( sal_Int32 nIndex );
334 /// Check whether 0<=nIndex<=n
335 void CheckPosition( sal_Int32 nIndex );
336 /// Check whether 0<=nStart<=n and 0<=nEnd<=n
337 void CheckRange( sal_Int32 nStart, sal_Int32 nEnd );
339 void _correctValues( css::uno::Sequence< css::beans::PropertyValue >& rValues );
340 sal_Int32 SkipField(sal_Int32 nIndex, bool bForward);
341 // get overlapped field, extend return string. Only extend forward for now
342 void ExtendByField( css::accessibility::TextSegment& Segment );
343 OUString GetFieldTypeNameAtIndex(sal_Int32 nIndex);
344 // the paragraph index in the edit engine (guarded by solar mutex)
345 sal_Int32 mnParagraphIndex;
347 // our current index in the parent (guarded by solar mutex)
348 sal_Int32 mnIndexInParent;
350 // the current edit source (guarded by solar mutex)
351 SvxEditSourceAdapter* mpEditSource;
353 // the possible child (for image bullets, guarded by solar mutex)
354 typedef WeakCppRef < css::accessibility::XAccessible, AccessibleImageBullet > WeakBullet;
355 WeakBullet maImageBullet;
357 // the last string used for an Accessibility::TEXT_CHANGED event (guarded by solar mutex)
358 OUString maLastTextString;
360 // the offset of the underlying EditEngine from the shape/cell (guarded by solar mutex)
361 Point maEEOffset;
363 // the current state set (updated from SetState/UnSetState and guarded by solar mutex)
364 css::uno::Reference< css::accessibility::XAccessibleStateSet > mxStateSet;
366 /// The shape we're the accessible for (unguarded)
367 css::uno::Reference< css::accessibility::XAccessible > mxParent;
369 /// Our listeners (guarded by maMutex)
370 int mnNotifierClientId;
371 private:
372 // Text paragraphs should provide FLOWS_TO and FLOWS_FROM relations (#i27138#)
373 // the paragraph manager, which created this instance - is NULL, if
374 // instance isn't created by AccessibleParaManager.
375 // Needed for method <getAccessibleRelationSet()> to retrieve predecessor
376 // paragraph and the successor paragraph.
377 const AccessibleParaManager* mpParaManager;
380 } // end of namespace accessibility
382 #endif
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */