Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / include / editeng / AccessibleEditableTextPara.hxx
blob8ac3bd69ac3664e368a8b5113c95c254e327b5de
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/typeprovider.hxx>
28 #include <cppuhelper/interfacecontainer.hxx>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
34 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
35 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
36 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
37 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
38 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
40 #include <comphelper/accessibletexthelper.hxx>
41 #include <comphelper/broadcasthelper.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 ::comphelper::OBaseMutex, 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 ();
83 // XInterface
84 virtual css::uno::Any SAL_CALL queryInterface (const css::uno::Type & rType) throw (css::uno::RuntimeException, std::exception) override;
86 // XAccessible
87 virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (css::uno::RuntimeException, std::exception) override;
89 // XAccessibleContext
90 virtual sal_Int32 SAL_CALL getAccessibleChildCount() throw (css::uno::RuntimeException, std::exception) override;
91 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
92 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() throw (css::uno::RuntimeException, std::exception) override;
93 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() throw (css::uno::RuntimeException, std::exception) override;
94 virtual sal_Int16 SAL_CALL getAccessibleRole() throw (css::uno::RuntimeException, std::exception) override;
95 /// Maximal length of text returned by getAccessibleDescription()
96 enum { MaxDescriptionLen = 40 };
97 virtual OUString SAL_CALL getAccessibleDescription() throw (css::uno::RuntimeException, std::exception) override;
98 virtual OUString SAL_CALL getAccessibleName() throw (css::uno::RuntimeException, std::exception) override;
99 virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() throw (css::uno::RuntimeException, std::exception) override;
100 virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() throw (css::uno::RuntimeException, std::exception) override;
101 virtual css::lang::Locale SAL_CALL getLocale() throw (css::accessibility::IllegalAccessibleComponentStateException, css::uno::RuntimeException, std::exception) override;
103 // XAccessibleEventBroadcaster
104 virtual void SAL_CALL addAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
105 virtual void SAL_CALL removeAccessibleEventListener( const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener ) throw (css::uno::RuntimeException, std::exception) override;
107 // XAccessibleComponent
108 virtual sal_Bool SAL_CALL containsPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
109 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
110 virtual css::awt::Rectangle SAL_CALL getBounds( ) throw (css::uno::RuntimeException, std::exception) override;
111 virtual css::awt::Point SAL_CALL getLocation( ) throw (css::uno::RuntimeException, std::exception) override;
112 virtual css::awt::Point SAL_CALL getLocationOnScreen( ) throw (css::uno::RuntimeException, std::exception) override;
113 virtual css::awt::Size SAL_CALL getSize( ) throw (css::uno::RuntimeException, std::exception) override;
114 virtual void SAL_CALL grabFocus( ) throw (css::uno::RuntimeException, std::exception) override;
115 virtual sal_Int32 SAL_CALL getForeground( ) throw (css::uno::RuntimeException, std::exception) override;
116 virtual sal_Int32 SAL_CALL getBackground( ) throw (css::uno::RuntimeException, std::exception) override;
118 // XAccessibleText (this comes implicitly inherited by XAccessibleEditableText AND by XAccessibleMultiLineText)
119 virtual sal_Int32 SAL_CALL getCaretPosition() throw (css::uno::RuntimeException, std::exception) override;
120 virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
121 virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
122 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& aRequestedAttributes ) throw (css::lang::IndexOutOfBoundsException, css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) override;
123 virtual css::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
124 virtual sal_Int32 SAL_CALL getCharacterCount() throw (css::uno::RuntimeException, std::exception) override;
125 virtual sal_Int32 SAL_CALL getIndexAtPoint( const css::awt::Point& aPoint ) throw (css::uno::RuntimeException, std::exception) override;
126 virtual OUString SAL_CALL getSelectedText() throw (css::uno::RuntimeException, std::exception) override;
127 virtual sal_Int32 SAL_CALL getSelectionStart() throw (css::uno::RuntimeException, std::exception) override;
128 virtual sal_Int32 SAL_CALL getSelectionEnd() throw (css::uno::RuntimeException, std::exception) override;
129 virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
130 virtual OUString SAL_CALL getText() throw (css::uno::RuntimeException, std::exception) override;
131 virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) 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 ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) 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 ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) 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 ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
138 virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
140 // XAccessibleEditableText
141 virtual sal_Bool SAL_CALL cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
142 virtual sal_Bool SAL_CALL pasteText( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
143 virtual sal_Bool SAL_CALL deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
144 virtual sal_Bool SAL_CALL insertText( const OUString& sText, sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
145 virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
146 virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const css::uno::Sequence< css::beans::PropertyValue >& aAttributeSet ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
147 virtual sal_Bool SAL_CALL setText( const OUString& sText ) throw (css::uno::RuntimeException, std::exception) override;
149 // XAccessibleTextAttributes
150 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getDefaultAttributes( const css::uno::Sequence< OUString >& RequestedAttributes ) throw (css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) override;
151 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getRunAttributes( ::sal_Int32 Index, const css::uno::Sequence< OUString >& RequestedAttributes ) throw (css::beans::UnknownPropertyException, css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
153 // XAccessibleHypertext
154 virtual ::sal_Int32 SAL_CALL getHyperLinkCount( ) throw (css::uno::RuntimeException, std::exception) override;
155 virtual css::uno::Reference< css::accessibility::XAccessibleHyperlink > SAL_CALL getHyperLink( ::sal_Int32 nLinkIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
156 virtual ::sal_Int32 SAL_CALL getHyperLinkIndex( ::sal_Int32 nCharIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
158 // XAccessibleMultiLineText
159 virtual ::sal_Int32 SAL_CALL getLineNumberAtIndex( ::sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
160 virtual css::accessibility::TextSegment SAL_CALL getTextAtLineNumber( ::sal_Int32 nLineNo ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) override;
161 virtual css::accessibility::TextSegment SAL_CALL getTextAtLineWithCaret( ) throw (css::uno::RuntimeException, std::exception) override;
162 virtual ::sal_Int32 SAL_CALL getNumberOfLineWithCaret( ) throw (css::uno::RuntimeException, std::exception) override;
164 // XServiceInfo
165 virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException, std::exception) override;
166 virtual sal_Bool SAL_CALL supportsService (const OUString& sServiceName) throw (css::uno::RuntimeException, std::exception) override;
167 virtual css::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) override;
169 // XServiceName
170 static OUString SAL_CALL getServiceName() throw (css::uno::RuntimeException);
172 /** Set the current index in the accessibility parent
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.
179 void SetIndexInParent( sal_Int32 nIndex );
181 /** Get the current index in the accessibility parent
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.
188 sal_Int32 GetIndexInParent() const { return mnIndexInParent; }
190 /** Set the current paragraph number
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.
197 void SetParagraphIndex( sal_Int32 nIndex );
199 /** Query the current paragraph number (0 - nParas-1)
201 @attention This method does not lock the SolarMutex,
202 leaving that to the calling code. This is because only
203 there potential deadlock situations can be resolved. Thus,
204 make sure SolarMutex is locked when calling this.
206 sal_Int32 GetParagraphIndex() const { return mnParagraphIndex; }
208 /** Set the edit engine offset
210 @attention This method does not lock the SolarMutex,
211 leaving that to the calling code. This is because only
212 there potential deadlock situations can be resolved. Thus,
213 make sure SolarMutex is locked when calling this.
215 void SetEEOffset( const Point& rOffset );
217 /** Set the EditEngine offset
219 @attention This method does not lock the SolarMutex,
220 leaving that to the calling code. This is because only
221 there potential deadlock situations can be resolved. Thus,
222 make sure SolarMutex is locked when calling this.
224 void SetEditSource( SvxEditSourceAdapter* pEditSource );
226 /** Dispose this object
228 Notifies and deregisters the listeners, drops all references.
230 void Dispose();
232 /// Calls all Listener objects to tell them the change. Don't hold locks when calling this!
233 void FireEvent(const sal_Int16 nEventId, const css::uno::Any& rNewValue = css::uno::Any(), const css::uno::Any& rOldValue = css::uno::Any() ) const;
235 /// Sets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this!
236 void SetState( const sal_Int16 nStateId );
237 /// Unsets the given state on the internal state set and fires STATE_CHANGE event. Don't hold locks when calling this!
238 void UnSetState( const sal_Int16 nStateId );
240 static Rectangle LogicToPixel( const Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder& rForwarder );
242 SvxEditSourceAdapter& GetEditSource() const;
244 /** Query the SvxTextForwarder for EditEngine access.
246 @attention This method does not lock the SolarMutex,
247 leaving that to the calling code. This is because only
248 there potential deadlock situations can be resolved. Thus,
249 make sure SolarMutex is locked when calling this.
251 SvxAccessibleTextAdapter& GetTextForwarder() const;
253 /** Query the SvxViewForwarder for EditEngine access.
255 @attention This method does not lock the SolarMutex,
256 leaving that to the calling code. This is because only
257 there potential deadlock situations can be resolved. Thus,
258 make sure SolarMutex is locked when calling this.
260 SvxViewForwarder& GetViewForwarder() const;
262 /** Query whether a GetEditViewForwarder( sal_False ) will return a forwarder
264 @attention This method does not lock the SolarMutex,
265 leaving that to the calling code. This is because only
266 there potential deadlock situations can be resolved. Thus,
267 make sure SolarMutex is locked when calling this.
269 bool HaveEditView() const;
271 /** Query the SvxEditViewForwarder for EditEngine access.
273 @attention This method does not lock the SolarMutex,
274 leaving that to the calling code. This is because only
275 there potential deadlock situations can be resolved. Thus,
276 make sure SolarMutex is locked when calling this.
278 SvxAccessibleTextEditViewAdapter& GetEditViewForwarder( bool bCreate = false ) const;
280 /** Send a TEXT_CHANGED event for this paragraph
282 This method internally caters for calculating text
283 differences, and sends the appropriate Anys in the
284 Accessibility::TEXT_CHANGED event
286 void TextChanged();
288 private:
289 AccessibleEditableTextPara( const AccessibleEditableTextPara& ) = delete;
290 AccessibleEditableTextPara& operator= ( const AccessibleEditableTextPara& ) = delete;
292 /** Calculate character range of similar attributes
294 @param nStartIndex
295 Therein, the start of the character range with the same attributes is returned
297 @param nEndIndex
298 Therein, the end (exclusively) of the character range with the same attributes is returned
300 @param nIndex
301 The character index at where to look for similar character attributes
303 @return false, if the method was not able to determine the range
305 bool GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nIndex );
307 // syntactic sugar for FireEvent
308 void GotPropertyEvent( const css::uno::Any& rNewValue, const sal_Int16 nEventId ) const;
309 void LostPropertyEvent( const css::uno::Any& rOldValue, const sal_Int16 nEventId ) const;
311 int getNotifierClientId() const { return mnNotifierClientId; }
313 /// Do we have children? This is the case for image bullets
314 bool HaveChildren();
316 const Point& GetEEOffset() const { return maEEOffset; }
318 // Get text from forwarder
319 OUString GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex );
320 sal_Int32 GetTextLen() const;
322 /** Get the current selection of this paragraph
324 @return sal_False, if nothing in this paragraph is selected
326 bool GetSelection(sal_Int32& nStartPos, sal_Int32& nEndPos );
328 /** create selection from Accessible selection.
331 ESelection MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex );
332 ESelection MakeSelection( sal_Int32 nEEIndex );
333 ESelection MakeCursor( sal_Int32 nEEIndex );
335 // check whether index value is within permitted range
337 /// Check whether 0<=nIndex<=n-1
338 void CheckIndex( sal_Int32 nIndex );
339 /// Check whether 0<=nIndex<=n
340 void CheckPosition( sal_Int32 nIndex );
341 /// Check whether 0<=nStart<=n and 0<=nEnd<=n
342 void CheckRange( sal_Int32 nStart, sal_Int32 nEnd );
344 void _correctValues( const sal_Int32 nIndex, css::uno::Sequence< css::beans::PropertyValue >& rValues );
345 sal_Int32 SkipField(sal_Int32 nIndex, bool bForward);
346 // get overlapped field, extend return string. Only extend forward for now
347 void ExtendByField( css::accessibility::TextSegment& Segment );
348 OUString GetFieldTypeNameAtIndex(sal_Int32 nIndex);
349 // the paragraph index in the edit engine (guarded by solar mutex)
350 sal_Int32 mnParagraphIndex;
352 // our current index in the parent (guarded by solar mutex)
353 sal_Int32 mnIndexInParent;
355 // the current edit source (guarded by solar mutex)
356 SvxEditSourceAdapter* mpEditSource;
358 // the possible child (for image bullets, guarded by solar mutex)
359 typedef WeakCppRef < css::accessibility::XAccessible, AccessibleImageBullet > WeakBullet;
360 WeakBullet maImageBullet;
362 // the last string used for an Accessibility::TEXT_CHANGED event (guarded by solar mutex)
363 OUString maLastTextString;
365 // the offset of the underlying EditEngine from the shape/cell (guarded by solar mutex)
366 Point maEEOffset;
368 // the current state set (updated from SetState/UnSetState and guarded by solar mutex)
369 css::uno::Reference< css::accessibility::XAccessibleStateSet > mxStateSet;
371 /// The shape we're the accessible for (unguarded)
372 css::uno::Reference< css::accessibility::XAccessible > mxParent;
374 /// Our listeners (guarded by maMutex)
375 int mnNotifierClientId;
376 private:
377 css::uno::Reference< css::accessibility::XAccessible > m_xAccInfo;
379 // Text paragraphs should provide FLOWS_TO and FLOWS_FROM relations (#i27138#)
380 // the paragraph manager, which created this instance - is NULL, if
381 // instance isn't created by AccessibleParaManager.
382 // Needed for method <getAccessibleRelationSet()> to retrieve predecessor
383 // paragraph and the successor paragraph.
384 const AccessibleParaManager* mpParaManager;
387 } // end of namespace accessibility
389 #endif
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */