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 .
19 #ifndef INCLUDED_SW_SOURCE_CORE_ACCESS_ACCPARA_HXX
20 #define INCLUDED_SW_SOURCE_CORE_ACCESS_ACCPARA_HXX
22 #include "acccontext.hxx"
23 #include <com/sun/star/accessibility/AccessibleScrollType.hpp>
24 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
25 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
26 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
27 #include <com/sun/star/accessibility/XAccessibleTextMarkup.hpp>
28 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
29 #include <com/sun/star/accessibility/XAccessibleTextSelection.hpp>
30 #include <com/sun/star/accessibility/XAccessibleExtendedAttributes.hpp>
31 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
32 #include "accselectionhelper.hxx"
33 #include <unordered_map>
34 #include <svl/lstner.hxx>
38 class SwAccessiblePortionData
;
39 class SwAccessibleHyperTextData
;
42 class SwParaChangeTrackingInfo
; //#i108125#
44 namespace com::sun::star
{
45 namespace i18n
{ struct Boundary
; }
46 namespace accessibility
{ class XAccessibleHyperlink
; }
47 namespace style
{ struct TabStop
; }
50 typedef std::unordered_map
< OUString
,
51 css::beans::PropertyValue
> tAccParaPropValMap
;
53 class SwAccessibleParagraph
:
55 public SwAccessibleContext
,
56 public css::accessibility::XAccessibleEditableText
,
57 public css::accessibility::XAccessibleSelection
,
58 public css::accessibility::XAccessibleHypertext
,
59 public css::accessibility::XAccessibleTextMarkup
,
60 public css::accessibility::XAccessibleMultiLineText
,
61 public css::accessibility::XAccessibleTextAttributes
,
62 public css::accessibility::XAccessibleTextSelection
,
63 public css::accessibility::XAccessibleExtendedAttributes
65 friend class SwAccessibleHyperlink
;
67 OUString m_sDesc
; // protected by base classes mutex
69 // data for this paragraph's text portions; this contains the
70 // mapping from the core 'model string' to the accessible text
72 // pPortionData may be NULL; it should only be accessed through the
73 // Get/Clear/Has/UpdatePortionData() methods
74 std::unique_ptr
<SwAccessiblePortionData
> m_pPortionData
;
75 std::unique_ptr
<SwAccessibleHyperTextData
> m_pHyperTextData
;
77 sal_Int32 m_nOldCaretPos
; // The 'old' caret pos. It's only valid as long
78 // as the cursor is inside this object (protected by
81 bool m_bIsHeading
; // protected by base classes mutex
82 sal_Int32 m_nHeadingLevel
;
84 // implementation for XAccessibleSelection
85 SwAccessibleSelectionHelper m_aSelectionHelper
;
87 std::unique_ptr
<SwParaChangeTrackingInfo
> mpParaChangeTrackInfo
; // #i108125#
89 // XAccessibleComponent
90 bool m_bLastHasSelection
;
92 /// get the (accessible) text string (requires frame; check before)
93 OUString
const & GetString();
95 static OUString
GetDescription();
97 // get the current care position
98 sal_Int32
GetCaretPos();
100 // determine the current selection. Fill the values with
101 // -1 if there is no selection in the this paragraph
102 // @param pSelection (optional) check only Nth selection in ring
103 bool GetSelectionAtIndex(sal_Int32
* pSelection
, sal_Int32
& nStart
, sal_Int32
& nEnd
);
104 bool GetSelection(sal_Int32
& nStart
, sal_Int32
& nEnd
) {
105 return GetSelectionAtIndex(nullptr, nStart
, nEnd
);
108 // helper for GetSelection and getCaretPosition
109 // #i27301# - add parameter <_bForSelection>, which indicates,
110 // if the cursor is retrieved for selection or for caret position.
111 SwPaM
* GetCursor( const bool _bForSelection
);
113 // for cut/copy/paste: execute a particular slot at the view shell
114 void ExecuteAtViewShell( sal_uInt16 nSlot
);
116 // helper method for get/setAttributes
117 // (for the special case of (nEndIndex==-1) a single character will
119 rtl::Reference
<SwXTextPortion
> CreateUnoPortion( sal_Int32 nStart
, sal_Int32 nEnd
);
121 // methods for checking the parameter range:
123 // does nPos point to a char?
124 static bool IsValidChar(sal_Int32 nPos
, sal_Int32 nLength
);
126 // does nPos point to a position? (may be behind the last character)
127 static bool IsValidPosition(sal_Int32 nPos
, sal_Int32 nLength
);
129 // is nBegin...nEnd a valid range? (nEnd points past the last character)
130 static bool IsValidRange(sal_Int32 nBegin
, sal_Int32 nEnd
, sal_Int32 nLength
);
132 // Ensure ordered range (i.e. nBegin is smaller then nEnd)
133 static void OrderRange(sal_Int32
& nBegin
, sal_Int32
& nEnd
)
136 std::swap( nBegin
, nEnd
);
139 const SwRangeRedline
* GetRedlineAtIndex();
140 OUString
GetFieldTypeNameAtIndex(sal_Int32 nIndex
);
143 void _getDefaultAttributesImpl(
144 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
145 tAccParaPropValMap
& rDefAttrSeq
,
146 const bool bOnlyCharAttrs
= false );
147 void _getRunAttributesImpl(
148 const sal_Int32 nIndex
,
149 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
150 tAccParaPropValMap
& rRunAttrSeq
);
152 void _getSupplementalAttributesImpl(
153 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
154 tAccParaPropValMap
& rSupplementalAttrSeq
);
157 const sal_Int32 nIndex
,
158 std::vector
< css::beans::PropertyValue
>& rValues
);
161 bool IsHeading() const;
165 // Set states for getAccessibleStateSet.
166 // This derived class additionally sets MULTILINE(1), MULTISELECTABLE(+),
167 // FOCUSABLE(+) and FOCUSED(+)
168 virtual void GetStates( sal_Int64
& rStateSet
) override
;
170 virtual void InvalidateContent_( bool bVisibleDataFired
) override
;
172 virtual void InvalidateCursorPos_() override
;
173 virtual void InvalidateFocus_() override
;
175 virtual ~SwAccessibleParagraph() override
;
177 // handling of data for the text portions
179 // force update of new portion data
180 /// @throws css::uno::RuntimeException
181 void UpdatePortionData();
183 // remove the current portion data
184 void ClearPortionData();
186 // get portion data; update if necessary
187 /// @throws css::uno::RuntimeException
188 SwAccessiblePortionData
& GetPortionData()
190 if( m_pPortionData
== nullptr )
192 return *m_pPortionData
;
195 //helpers for word boundaries
197 bool GetCharBoundary( css::i18n::Boundary
& rBound
,
198 std::u16string_view text
,
200 bool GetWordBoundary( css::i18n::Boundary
& rBound
,
201 const OUString
& rText
,
203 bool GetSentenceBoundary( css::i18n::Boundary
& rBound
,
204 const OUString
& rText
,
206 bool GetLineBoundary( css::i18n::Boundary
& rBound
,
207 std::u16string_view aText
,
209 static bool GetParagraphBoundary( css::i18n::Boundary
& rBound
,
210 std::u16string_view aText
);
211 bool GetAttributeBoundary( css::i18n::Boundary
& rBound
,
213 bool GetGlyphBoundary( css::i18n::Boundary
& rBound
,
214 const OUString
& rText
,
217 // get boundaries of word/sentence/etc. for specified text type
218 // Does all argument checking, and then delegates to helper methods above.
219 /// @throws css::lang::IndexOutOfBoundsException
220 /// @throws css::lang::IllegalArgumentException
221 /// @throws css::uno::RuntimeException
222 bool GetTextBoundary( css::i18n::Boundary
& rBound
,
223 const OUString
& rText
,
225 sal_Int16 aTextType
);
227 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
231 SwAccessibleParagraph( std::shared_ptr
<SwAccessibleMap
> const& pInitMap
,
232 const SwTextFrame
& rTextFrame
);
234 inline operator css::accessibility::XAccessibleText
*();
236 virtual bool HasCursor() override
; // required by map to remember that object
238 css::uno::Sequence
< css::style::TabStop
> GetCurrentTabStop( sal_Int32 nIndex
);
239 virtual sal_Int16 SAL_CALL
getAccessibleRole() override
;
241 // XAccessibleContext
243 // Return this object's description.
244 virtual OUString SAL_CALL
245 getAccessibleDescription() override
;
247 // Return the parents locale or throw exception if this object has no
248 // parent yet/anymore.
249 virtual css::lang::Locale SAL_CALL
250 getLocale() override
;
252 // #i27138# - paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO
253 virtual css::uno::Reference
<
254 css::accessibility::XAccessibleRelationSet
> SAL_CALL
255 getAccessibleRelationSet() override
;
257 // XAccessibleComponent
259 virtual void SAL_CALL
grabFocus() override
;
261 virtual sal_Int32 SAL_CALL
getForeground() override
;
262 virtual sal_Int32 SAL_CALL
getBackground() override
;
266 // Returns an identifier for the implementation of this object.
267 virtual OUString SAL_CALL
268 getImplementationName() override
;
270 // Return whether the specified service is supported by this class.
271 virtual sal_Bool SAL_CALL
272 supportsService (const OUString
& sServiceName
) override
;
274 // Returns a list of all supported services. In this case that is just
275 // the AccessibleContext service.
276 virtual css::uno::Sequence
< OUString
> SAL_CALL
277 getSupportedServiceNames() override
;
281 // (XInterface methods need to be implemented to disambiguate
282 // between those inherited through SwAccessibleContext and
283 // XAccessibleEditableText).
285 virtual css::uno::Any SAL_CALL
queryInterface(
286 const css::uno::Type
& aType
) override
;
288 virtual void SAL_CALL
acquire( ) noexcept override
289 { SwAccessibleContext::acquire(); };
291 virtual void SAL_CALL
release( ) noexcept override
292 { SwAccessibleContext::release(); };
295 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
296 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
299 virtual sal_Int32 SAL_CALL
getCaretPosition() override
;
300 virtual sal_Bool SAL_CALL
setCaretPosition( sal_Int32 nIndex
) override
;
301 virtual sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) override
;
302 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
303 virtual css::awt::Rectangle SAL_CALL
getCharacterBounds( sal_Int32 nIndex
) override
;
304 virtual sal_Int32 SAL_CALL
getCharacterCount( ) override
;
305 virtual sal_Int32 SAL_CALL
getIndexAtPoint( const css::awt::Point
& aPoint
) override
;
306 virtual OUString SAL_CALL
getSelectedText( ) override
;
307 virtual sal_Int32 SAL_CALL
getSelectionStart() override
;
308 virtual sal_Int32 SAL_CALL
getSelectionEnd() override
;
309 virtual sal_Bool SAL_CALL
setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
310 virtual OUString SAL_CALL
getText( ) override
;
311 virtual OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
312 virtual css::accessibility::TextSegment SAL_CALL
getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
313 virtual css::accessibility::TextSegment SAL_CALL
getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
314 virtual css::accessibility::TextSegment SAL_CALL
getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
315 virtual sal_Bool SAL_CALL
copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
316 virtual sal_Bool SAL_CALL
scrollSubstringTo( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, css::accessibility::AccessibleScrollType aScrollType
) override
;
318 // XAccessibleEditableText
319 virtual sal_Bool SAL_CALL
cutText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
320 virtual sal_Bool SAL_CALL
pasteText( sal_Int32 nIndex
) override
;
321 virtual sal_Bool SAL_CALL
deleteText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
322 virtual sal_Bool SAL_CALL
insertText( const OUString
& sText
, sal_Int32 nIndex
) override
;
323 virtual sal_Bool SAL_CALL
replaceText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, const OUString
& sReplacement
) override
;
324 virtual sal_Bool SAL_CALL
setAttributes( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, const css::uno::Sequence
< css::beans::PropertyValue
>& aAttributeSet
) override
;
325 virtual sal_Bool SAL_CALL
setText( const OUString
& sText
) override
;
327 // XAccessibleSelection
328 virtual void SAL_CALL
selectAccessibleChild(
329 sal_Int64 nChildIndex
) override
;
331 virtual sal_Bool SAL_CALL
isAccessibleChildSelected(
332 sal_Int64 nChildIndex
) override
;
333 virtual void SAL_CALL
clearAccessibleSelection( ) override
;
334 virtual void SAL_CALL
selectAllAccessibleChildren( ) override
;
335 virtual sal_Int64 SAL_CALL
getSelectedAccessibleChildCount( ) override
;
336 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getSelectedAccessibleChild(
337 sal_Int64 nSelectedChildIndex
) override
;
339 // index has to be treated as global child index.
340 virtual void SAL_CALL
deselectAccessibleChild(
341 sal_Int64 nChildIndex
) override
;
343 // XAccessibleHypertext
344 virtual sal_Int32 SAL_CALL
getHyperLinkCount() override
;
345 virtual css::uno::Reference
<
346 css::accessibility::XAccessibleHyperlink
>
347 SAL_CALL
getHyperLink( sal_Int32 nLinkIndex
) override
;
348 virtual sal_Int32 SAL_CALL
getHyperLinkIndex( sal_Int32 nCharIndex
) override
;
351 // XAccessibleTextMarkup
352 virtual sal_Int32 SAL_CALL
getTextMarkupCount( sal_Int32 nTextMarkupType
) override
;
354 virtual css::accessibility::TextSegment SAL_CALL
355 getTextMarkup( sal_Int32 nTextMarkupIndex
,
356 sal_Int32 nTextMarkupType
) override
;
358 virtual css::uno::Sequence
< css::accessibility::TextSegment
> SAL_CALL
359 getTextMarkupAtIndex( sal_Int32 nCharIndex
,
360 sal_Int32 nTextMarkupType
) override
;
362 // XAccessibleTextSelection
363 virtual sal_Bool SAL_CALL
scrollToPosition( const css::awt::Point
& aPoint
, sal_Bool isLeftTop
) override
;
364 virtual sal_Int32 SAL_CALL
getSelectedPortionCount( ) override
;
365 virtual sal_Int32 SAL_CALL
getSeletedPositionStart( sal_Int32 nSelectedPortionIndex
) override
;
366 virtual sal_Int32 SAL_CALL
getSeletedPositionEnd( sal_Int32 nSelectedPortionIndex
) override
;
367 virtual sal_Bool SAL_CALL
removeSelection( sal_Int32 selectionIndex
) override
;
368 virtual sal_Int32 SAL_CALL
addSelection( sal_Int32 selectionIndex
, sal_Int32 startOffset
, sal_Int32 endOffset
) override
;
369 // XAccessibleExtendedAttributes
370 virtual css::uno::Any SAL_CALL
getExtendedAttributes() override
;
371 sal_Int32
GetRealHeadingLevel();
374 // XAccessibleMultiLineText
375 virtual sal_Int32 SAL_CALL
getLineNumberAtIndex( sal_Int32 nIndex
) override
;
377 virtual css::accessibility::TextSegment SAL_CALL
378 getTextAtLineNumber( sal_Int32 nLineNo
) override
;
380 virtual css::accessibility::TextSegment SAL_CALL
381 getTextAtLineWithCaret() override
;
383 virtual sal_Int32 SAL_CALL
getNumberOfLineWithCaret() override
;
386 // XAccessibleTextAttributes
387 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getDefaultAttributes( const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
388 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getRunAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
391 inline SwAccessibleParagraph::operator css::accessibility::XAccessibleText
*()
393 return static_cast< css::accessibility::XAccessibleEditableText
* >( this );
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */