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