bump product version to 7.6.3.2-android
[LibreOffice.git] / include / comphelper / accessibletexthelper.hxx
blob30730469be917bf07969a4cd99cf82071028fafd
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_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
23 #include <com/sun/star/accessibility/XAccessibleText.hpp>
24 #include <com/sun/star/accessibility/TextSegment.hpp>
25 #include <comphelper/accessiblecomponenthelper.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <comphelper/comphelperdllapi.h>
29 namespace com::sun::star::i18n { class XBreakIterator; }
30 namespace com::sun::star::i18n { class XCharacterClassification; }
31 namespace com::sun::star::i18n { struct Boundary; }
33 namespace comphelper
37 // OCommonAccessibleText
39 /** base class encapsulating common functionality for the helper classes implementing
40 the XAccessibleText
42 class COMPHELPER_DLLPUBLIC OCommonAccessibleText
44 private:
45 css::uno::Reference < css::i18n::XBreakIterator > m_xBreakIter;
46 css::uno::Reference < css::i18n::XCharacterClassification > m_xCharClass;
48 protected:
49 OCommonAccessibleText();
50 virtual ~OCommonAccessibleText();
52 css::uno::Reference < css::i18n::XBreakIterator > const & implGetBreakIterator();
53 css::uno::Reference < css::i18n::XCharacterClassification > const & implGetCharacterClassification();
54 static bool implIsValidBoundary( css::i18n::Boundary const & rBoundary, sal_Int32 nLength );
55 static bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
56 static bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
57 static sal_Unicode implGetCharacter( std::u16string_view rText, sal_Int32 nIndex );
58 static OUString implGetTextRange( std::u16string_view rText, sal_Int32 nStartIndex, sal_Int32 nEndIndex );
59 virtual OUString implGetText() = 0;
60 virtual css::lang::Locale implGetLocale() = 0;
61 virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
62 void implGetGlyphBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
63 bool implGetWordBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
64 void implGetSentenceBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
65 virtual void implGetParagraphBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
66 virtual void implGetLineBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
68 /** non-virtual versions of the methods
70 @throws css::lang::IndexOutOfBoundsException
71 @throws css::uno::RuntimeException
73 OUString getSelectedText();
74 /// @throws css::uno::RuntimeException
75 sal_Int32 getSelectionStart();
76 /// @throws css::uno::RuntimeException
77 sal_Int32 getSelectionEnd();
78 /// @throws css::lang::IndexOutOfBoundsException
79 /// @throws css::lang::IllegalArgumentException
80 /// @throws css::uno::RuntimeException
81 css::accessibility::TextSegment getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType );
82 /// @throws css::lang::IndexOutOfBoundsException
83 /// @throws css::lang::IllegalArgumentException
84 /// @throws css::uno::RuntimeException
85 css::accessibility::TextSegment getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType );
86 /// @throws css::lang::IndexOutOfBoundsException
87 /// @throws css::lang::IllegalArgumentException
88 /// @throws css::uno::RuntimeException
89 css::accessibility::TextSegment getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType );
91 public:
93 /** Helper method, that detects the difference between
94 two strings and returns the deleted selection and
95 the inserted selection if available.
97 @returns true if there are differences between the
98 two strings and false if both are equal
100 @see css::accessibility::AccessibleEventId
101 css::accessibility::TextSegment
103 static bool implInitTextChangedEvent(
104 std::u16string_view rOldString,
105 std::u16string_view rNewString,
106 /*out*/ css::uno::Any& rDeleted,
107 /*out*/ css::uno::Any& rInserted); // throw()
111 // OAccessibleTextHelper
114 /** a helper class for implementing an AccessibleExtendedComponent which at the same time
115 supports an XAccessibleText interface
117 class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public cppu::ImplInheritanceHelper<
118 OAccessibleExtendedComponentHelper,
119 css::accessibility::XAccessibleText>,
120 public OCommonAccessibleText
122 private:
123 OAccessibleTextHelper(OAccessibleTextHelper const &) = delete;
124 OAccessibleTextHelper(OAccessibleTextHelper &&) = delete;
125 void operator =(OAccessibleTextHelper const &) = delete;
126 void operator =(OAccessibleTextHelper &&) = delete;
128 protected:
129 OAccessibleTextHelper();
131 public:
132 // XAccessibleText
133 virtual OUString SAL_CALL getSelectedText() override;
134 virtual sal_Int32 SAL_CALL getSelectionStart() override;
135 virtual sal_Int32 SAL_CALL getSelectionEnd() override;
136 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
137 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
138 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
142 } // namespace comphelper
145 // OAccessibleTextHelper is a helper class for implementing the
146 // XAccessibleText interface.
148 // The following methods have a default implementation:
150 // getCharacter
151 // getSelectedText
152 // getSelectionStart
153 // getSelectionEnd
154 // getTextRange
155 // getTextAtIndex
156 // getTextBeforeIndex
157 // getTextBehindIndex
159 // The following methods must be overridden by derived classes:
161 // implGetText
162 // implGetLocale
163 // implGetSelection
164 // getCaretPosition
165 // setCaretPosition
166 // getCharacterAttributes
167 // getCharacterBounds
168 // getIndexAtPoint
169 // setSelection
170 // copyText
172 #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */