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 using SwAccessibleParagraph_BASE
= cppu::ImplInheritanceHelper
<SwAccessibleContext
,
54 css::accessibility::XAccessibleEditableText
,
55 css::accessibility::XAccessibleSelection
,
56 css::accessibility::XAccessibleHypertext
,
57 css::accessibility::XAccessibleTextMarkup
,
58 css::accessibility::XAccessibleMultiLineText
,
59 css::accessibility::XAccessibleTextAttributes
,
60 css::accessibility::XAccessibleTextSelection
,
61 css::accessibility::XAccessibleExtendedAttributes
>;
62 class SwAccessibleParagraph
:
64 public SwAccessibleParagraph_BASE
66 friend class SwAccessibleHyperlink
;
68 OUString m_sDesc
; // protected by base classes mutex
70 // data for this paragraph's text portions; this contains the
71 // mapping from the core 'model string' to the accessible text
73 // pPortionData may be NULL; it should only be accessed through the
74 // Get/Clear/Has/UpdatePortionData() methods
75 std::unique_ptr
<SwAccessiblePortionData
> m_pPortionData
;
76 std::unique_ptr
<SwAccessibleHyperTextData
> m_pHyperTextData
;
78 sal_Int32 m_nOldCaretPos
; // The 'old' caret pos. It's only valid as long
79 // as the cursor is inside this object (protected by
83 bool m_bIsHeading
; // protected by base classes mutex
84 sal_Int32 m_nHeadingLevel
;
86 // implementation for XAccessibleSelection
87 SwAccessibleSelectionHelper m_aSelectionHelper
;
89 std::unique_ptr
<SwParaChangeTrackingInfo
> mpParaChangeTrackInfo
; // #i108125#
91 // XAccessibleComponent
92 bool m_bLastHasSelection
;
94 const SwTextFrame
* GetTextFrame() const;
96 /// get the (accessible) text string (requires frame; check before)
97 OUString
const & GetString();
99 static const OUString
& GetDescription();
101 // get the current care position
102 sal_Int32
GetCaretPos();
104 // determine the current selection. Fill the values with
105 // -1 if there is no selection in the this paragraph
106 // @param pSelection (optional) check only Nth selection in ring
107 bool GetSelectionAtIndex(sal_Int32
* pSelection
, sal_Int32
& nStart
, sal_Int32
& nEnd
);
108 bool GetSelection(sal_Int32
& nStart
, sal_Int32
& nEnd
) {
109 return GetSelectionAtIndex(nullptr, nStart
, nEnd
);
112 // helper for GetSelection and getCaretPosition
113 // #i27301# - add parameter <_bForSelection>, which indicates,
114 // if the cursor is retrieved for selection or for caret position.
115 SwPaM
* GetCursor( const bool _bForSelection
);
117 // for cut/copy/paste: execute a particular slot at the view shell
118 void ExecuteAtViewShell( sal_uInt16 nSlot
);
120 // helper method for get/setAttributes
121 // (for the special case of (nEndIndex==-1) a single character will
123 rtl::Reference
<SwXTextPortion
> CreateUnoPortion( sal_Int32 nStart
, sal_Int32 nEnd
);
125 // methods for checking the parameter range:
127 // does nPos point to a char?
128 static bool IsValidChar(sal_Int32 nPos
, sal_Int32 nLength
);
130 // does nPos point to a position? (may be behind the last character)
131 static bool IsValidPosition(sal_Int32 nPos
, sal_Int32 nLength
);
133 // is nBegin...nEnd a valid range? (nEnd points past the last character)
134 static bool IsValidRange(sal_Int32 nBegin
, sal_Int32 nEnd
, sal_Int32 nLength
);
136 // Ensure ordered range (i.e. nBegin is smaller then nEnd)
137 static void OrderRange(sal_Int32
& nBegin
, sal_Int32
& nEnd
)
140 std::swap( nBegin
, nEnd
);
143 const SwRangeRedline
* GetRedlineAtIndex();
144 OUString
GetFieldTypeNameAtIndex(sal_Int32 nIndex
);
147 void _getDefaultAttributesImpl(
148 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
149 tAccParaPropValMap
& rDefAttrSeq
,
150 const bool bOnlyCharAttrs
= false );
151 void _getRunAttributesImpl(
152 const sal_Int32 nIndex
,
153 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
154 tAccParaPropValMap
& rRunAttrSeq
);
156 void _getSupplementalAttributesImpl(
157 const css::uno::Sequence
< OUString
>& aRequestedAttributes
,
158 tAccParaPropValMap
& rSupplementalAttrSeq
);
161 const sal_Int32 nIndex
,
162 std::vector
< css::beans::PropertyValue
>& rValues
);
165 bool IsHeading() const;
169 // Set states for getAccessibleStateSet.
170 // This derived class additionally sets MULTILINE(1), MULTISELECTABLE(+),
171 // FOCUSABLE(+) and FOCUSED(+)
172 virtual void GetStates( sal_Int64
& rStateSet
) override
;
174 virtual void InvalidateContent_( bool bVisibleDataFired
) override
;
176 virtual void InvalidateCursorPos_() override
;
177 virtual void InvalidateFocus_() override
;
179 virtual ~SwAccessibleParagraph() override
;
181 // handling of data for the text portions
183 // force update of new portion data
184 /// @throws css::uno::RuntimeException
185 void UpdatePortionData();
187 // remove the current portion data
188 void ClearPortionData();
190 // get portion data; update if necessary
191 /// @throws css::uno::RuntimeException
192 SwAccessiblePortionData
& GetPortionData()
194 if( m_pPortionData
== nullptr )
196 return *m_pPortionData
;
199 //helpers for word boundaries
201 bool GetCharBoundary( css::i18n::Boundary
& rBound
,
202 std::u16string_view text
,
204 bool GetWordBoundary( css::i18n::Boundary
& rBound
,
205 const OUString
& rText
,
207 bool GetSentenceBoundary( css::i18n::Boundary
& rBound
,
208 const OUString
& rText
,
210 bool GetLineBoundary( css::i18n::Boundary
& rBound
,
211 std::u16string_view aText
,
213 static bool GetParagraphBoundary( css::i18n::Boundary
& rBound
,
214 std::u16string_view aText
);
215 bool GetAttributeBoundary( css::i18n::Boundary
& rBound
,
217 bool GetGlyphBoundary( css::i18n::Boundary
& rBound
,
218 const OUString
& rText
,
221 // get boundaries of word/sentence/etc. for specified text type
222 // Does all argument checking, and then delegates to helper methods above.
223 /// @throws css::lang::IndexOutOfBoundsException
224 /// @throws css::lang::IllegalArgumentException
225 /// @throws css::uno::RuntimeException
226 bool GetTextBoundary( css::i18n::Boundary
& rBound
,
227 const OUString
& rText
,
229 sal_Int16 aTextType
);
231 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
235 SwAccessibleParagraph( std::shared_ptr
<SwAccessibleMap
> const& pInitMap
,
236 const SwTextFrame
& rTextFrame
);
238 virtual bool HasCursor() override
; // required by map to remember that object
240 css::uno::Sequence
< css::style::TabStop
> GetCurrentTabStop( sal_Int32 nIndex
);
241 virtual sal_Int16 SAL_CALL
getAccessibleRole() override
;
243 // XAccessibleContext
245 // Return this object's description.
246 virtual OUString SAL_CALL
247 getAccessibleDescription() override
;
249 // Return the parents locale or throw exception if this object has no
250 // parent yet/anymore.
251 virtual css::lang::Locale SAL_CALL
252 getLocale() override
;
254 // #i27138# - paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO
255 virtual css::uno::Reference
<
256 css::accessibility::XAccessibleRelationSet
> SAL_CALL
257 getAccessibleRelationSet() override
;
259 // XAccessibleComponent
261 virtual void SAL_CALL
grabFocus() override
;
263 virtual sal_Int32 SAL_CALL
getForeground() override
;
264 virtual sal_Int32 SAL_CALL
getBackground() override
;
268 // Returns an identifier for the implementation of this object.
269 virtual OUString SAL_CALL
270 getImplementationName() override
;
272 // Return whether the specified service is supported by this class.
273 virtual sal_Bool SAL_CALL
274 supportsService (const OUString
& sServiceName
) override
;
276 // Returns a list of all supported services. In this case that is just
277 // the AccessibleContext service.
278 virtual css::uno::Sequence
< OUString
> SAL_CALL
279 getSupportedServiceNames() override
;
282 virtual sal_Int32 SAL_CALL
getCaretPosition() override
;
283 virtual sal_Bool SAL_CALL
setCaretPosition( sal_Int32 nIndex
) override
;
284 virtual sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) override
;
285 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getCharacterAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
286 virtual css::awt::Rectangle SAL_CALL
getCharacterBounds( sal_Int32 nIndex
) override
;
287 virtual sal_Int32 SAL_CALL
getCharacterCount( ) override
;
288 virtual sal_Int32 SAL_CALL
getIndexAtPoint( const css::awt::Point
& aPoint
) override
;
289 virtual OUString SAL_CALL
getSelectedText( ) override
;
290 virtual sal_Int32 SAL_CALL
getSelectionStart() override
;
291 virtual sal_Int32 SAL_CALL
getSelectionEnd() override
;
292 virtual sal_Bool SAL_CALL
setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
293 virtual OUString SAL_CALL
getText( ) override
;
294 virtual OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
295 virtual css::accessibility::TextSegment SAL_CALL
getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
296 virtual css::accessibility::TextSegment SAL_CALL
getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
297 virtual css::accessibility::TextSegment SAL_CALL
getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) override
;
298 virtual sal_Bool SAL_CALL
copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
299 virtual sal_Bool SAL_CALL
scrollSubstringTo( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, css::accessibility::AccessibleScrollType aScrollType
) override
;
301 // XAccessibleEditableText
302 virtual sal_Bool SAL_CALL
cutText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
303 virtual sal_Bool SAL_CALL
pasteText( sal_Int32 nIndex
) override
;
304 virtual sal_Bool SAL_CALL
deleteText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) override
;
305 virtual sal_Bool SAL_CALL
insertText( const OUString
& sText
, sal_Int32 nIndex
) override
;
306 virtual sal_Bool SAL_CALL
replaceText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, const OUString
& sReplacement
) override
;
307 virtual sal_Bool SAL_CALL
setAttributes( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, const css::uno::Sequence
< css::beans::PropertyValue
>& aAttributeSet
) override
;
308 virtual sal_Bool SAL_CALL
setText( const OUString
& sText
) override
;
310 // XAccessibleSelection
311 virtual void SAL_CALL
selectAccessibleChild(
312 sal_Int64 nChildIndex
) override
;
314 virtual sal_Bool SAL_CALL
isAccessibleChildSelected(
315 sal_Int64 nChildIndex
) override
;
316 virtual void SAL_CALL
clearAccessibleSelection( ) override
;
317 virtual void SAL_CALL
selectAllAccessibleChildren( ) override
;
318 virtual sal_Int64 SAL_CALL
getSelectedAccessibleChildCount( ) override
;
319 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
getSelectedAccessibleChild(
320 sal_Int64 nSelectedChildIndex
) override
;
322 // index has to be treated as global child index.
323 virtual void SAL_CALL
deselectAccessibleChild(
324 sal_Int64 nChildIndex
) override
;
326 // XAccessibleHypertext
327 virtual sal_Int32 SAL_CALL
getHyperLinkCount() override
;
328 virtual css::uno::Reference
<
329 css::accessibility::XAccessibleHyperlink
>
330 SAL_CALL
getHyperLink( sal_Int32 nLinkIndex
) override
;
331 virtual sal_Int32 SAL_CALL
getHyperLinkIndex( sal_Int32 nCharIndex
) override
;
334 // XAccessibleTextMarkup
335 virtual sal_Int32 SAL_CALL
getTextMarkupCount( sal_Int32 nTextMarkupType
) override
;
337 virtual css::accessibility::TextSegment SAL_CALL
338 getTextMarkup( sal_Int32 nTextMarkupIndex
,
339 sal_Int32 nTextMarkupType
) override
;
341 virtual css::uno::Sequence
< css::accessibility::TextSegment
> SAL_CALL
342 getTextMarkupAtIndex( sal_Int32 nCharIndex
,
343 sal_Int32 nTextMarkupType
) override
;
345 // XAccessibleTextSelection
346 virtual sal_Bool SAL_CALL
scrollToPosition( const css::awt::Point
& aPoint
, sal_Bool isLeftTop
) override
;
347 virtual sal_Int32 SAL_CALL
getSelectedPortionCount( ) override
;
348 virtual sal_Int32 SAL_CALL
getSeletedPositionStart( sal_Int32 nSelectedPortionIndex
) override
;
349 virtual sal_Int32 SAL_CALL
getSeletedPositionEnd( sal_Int32 nSelectedPortionIndex
) override
;
350 virtual sal_Bool SAL_CALL
removeSelection( sal_Int32 selectionIndex
) override
;
351 virtual sal_Int32 SAL_CALL
addSelection( sal_Int32 selectionIndex
, sal_Int32 startOffset
, sal_Int32 endOffset
) override
;
352 // XAccessibleExtendedAttributes
353 virtual css::uno::Any SAL_CALL
getExtendedAttributes() override
;
354 sal_Int32
GetRealHeadingLevel();
358 // XAccessibleMultiLineText
359 virtual sal_Int32 SAL_CALL
getLineNumberAtIndex( sal_Int32 nIndex
) override
;
361 virtual css::accessibility::TextSegment SAL_CALL
362 getTextAtLineNumber( sal_Int32 nLineNo
) override
;
364 virtual css::accessibility::TextSegment SAL_CALL
365 getTextAtLineWithCaret() override
;
367 virtual sal_Int32 SAL_CALL
getNumberOfLineWithCaret() override
;
370 // XAccessibleTextAttributes
371 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getDefaultAttributes( const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
372 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getRunAttributes( sal_Int32 nIndex
, const css::uno::Sequence
< OUString
>& aRequestedAttributes
) override
;
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */