Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / comphelper / accessibletexthelper.hxx
blob8083ba6ed211859087170faa7aa223c9a8fce3e8
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 <com/sun/star/i18n/XBreakIterator.hpp>
26 #include <com/sun/star/i18n/XCharacterClassification.hpp>
27 #include <comphelper/accessiblecomponenthelper.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <comphelper/comphelperdllapi.h>
32 namespace comphelper
36 // OCommonAccessibleText
38 /** base class encapsulating common functionality for the helper classes implementing
39 the XAccessibleText
41 class COMPHELPER_DLLPUBLIC OCommonAccessibleText
43 private:
44 css::uno::Reference < css::i18n::XBreakIterator > m_xBreakIter;
45 css::uno::Reference < css::i18n::XCharacterClassification > m_xCharClass;
47 protected:
48 OCommonAccessibleText();
49 virtual ~OCommonAccessibleText();
51 css::uno::Reference < css::i18n::XBreakIterator > const & implGetBreakIterator();
52 css::uno::Reference < css::i18n::XCharacterClassification > const & implGetCharacterClassification();
53 static bool implIsValidBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nLength );
54 static bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
55 static bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
56 virtual OUString implGetText() = 0;
57 virtual css::lang::Locale implGetLocale() = 0;
58 virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
59 void implGetGlyphBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
60 bool implGetWordBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
61 void implGetSentenceBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
62 virtual void implGetParagraphBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
63 virtual void implGetLineBoundary( css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
65 /** non-virtual versions of the methods
67 @throws css::lang::IndexOutOfBoundsException
68 @throws css::uno::RuntimeException
70 sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex );
71 /// @throws css::uno::RuntimeException
72 sal_Int32 SAL_CALL getCharacterCount();
73 /// @throws css::uno::RuntimeException
74 OUString SAL_CALL getSelectedText();
75 /// @throws css::uno::RuntimeException
76 sal_Int32 SAL_CALL getSelectionStart();
77 /// @throws css::uno::RuntimeException
78 sal_Int32 SAL_CALL getSelectionEnd();
79 /// @throws css::uno::RuntimeException
80 OUString SAL_CALL getText();
81 /// @throws css::lang::IndexOutOfBoundsException
82 /// @throws css::uno::RuntimeException
83 OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex );
84 /// @throws css::lang::IndexOutOfBoundsException
85 /// @throws css::lang::IllegalArgumentException
86 /// @throws css::uno::RuntimeException
87 css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType );
88 /// @throws css::lang::IndexOutOfBoundsException
89 /// @throws css::lang::IllegalArgumentException
90 /// @throws css::uno::RuntimeException
91 css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType );
92 /// @throws css::lang::IndexOutOfBoundsException
93 /// @throws css::lang::IllegalArgumentException
94 /// @throws css::uno::RuntimeException
95 css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType );
97 public:
99 /** Helper method, that detects the difference between
100 two strings and returns the deleted selection and
101 the inserted selection if available.
103 @returns true if there are differences between the
104 two strings and false if both are equal
106 @see css::accessibility::AccessibleEventId
107 css::accessibility::TextSegment
109 static bool implInitTextChangedEvent(
110 const OUString& rOldString,
111 const OUString& rNewString,
112 /*out*/ css::uno::Any& rDeleted,
113 /*out*/ css::uno::Any& rInserted); // throw()
117 // OAccessibleTextHelper
120 typedef ::cppu::ImplHelper1 < css::accessibility::XAccessibleText
121 > OAccessibleTextHelper_Base;
123 /** a helper class for implementing an AccessibleExtendedComponent which at the same time
124 supports an XAccessibleText interface
126 class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public OAccessibleExtendedComponentHelper,
127 public OCommonAccessibleText,
128 public OAccessibleTextHelper_Base
130 protected:
131 // see the respective base class ctor for an extensive comment on this, please
132 OAccessibleTextHelper( IMutex* _pExternalLock );
134 public:
135 // XInterface
136 DECLARE_XINTERFACE( )
138 // XTypeProvider
139 DECLARE_XTYPEPROVIDER( )
141 // XAccessibleText
142 virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) override;
143 virtual sal_Int32 SAL_CALL getCharacterCount() override;
144 virtual OUString SAL_CALL getSelectedText() override;
145 virtual sal_Int32 SAL_CALL getSelectionStart() override;
146 virtual sal_Int32 SAL_CALL getSelectionEnd() override;
147 virtual OUString SAL_CALL getText() override;
148 virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) override;
149 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
150 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
151 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
155 } // namespace comphelper
158 #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
161 // OAccessibleTextHelper is a helper class for implementing the
162 // XAccessibleText interface.
164 // The following methods have a default implementation:
166 // getCharacter
167 // getCharacterCount
168 // getSelectedText
169 // getSelectionStart
170 // getSelectionEnd
171 // getText
172 // getTextRange
173 // getTextAtIndex
174 // getTextBeforeIndex
175 // getTextBehindIndex
177 // The following methods must be overridden by derived classes:
179 // implGetText
180 // implGetLocale
181 // implGetSelection
182 // getCaretPosition
183 // setCaretPosition
184 // getCharacterAttributes
185 // getCharacterBounds
186 // getIndexAtPoint
187 // setSelection
188 // copyText
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */