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