tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / include / comphelper / accessibletexthelper.hxx
blobeab5df05be418fcc9ead29b8459c36d7d5db642a
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 <config_options.h>
24 #include <com/sun/star/accessibility/XAccessibleText.hpp>
25 #include <com/sun/star/accessibility/TextSegment.hpp>
26 #include <comphelper/accessiblecomponenthelper.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <comphelper/comphelperdllapi.h>
30 namespace com::sun::star::i18n { class XBreakIterator; }
31 namespace com::sun::star::i18n { class XCharacterClassification; }
32 namespace com::sun::star::i18n { struct Boundary; }
34 namespace comphelper
38 // OCommonAccessibleText
40 /** base class encapsulating common functionality for the helper classes implementing
41 the XAccessibleText
43 class COMPHELPER_DLLPUBLIC OCommonAccessibleText
45 private:
46 css::uno::Reference < css::i18n::XBreakIterator > m_xBreakIter;
47 css::uno::Reference < css::i18n::XCharacterClassification > m_xCharClass;
49 protected:
50 OCommonAccessibleText();
51 virtual ~OCommonAccessibleText();
53 css::uno::Reference < css::i18n::XBreakIterator > const & implGetBreakIterator();
54 css::uno::Reference < css::i18n::XCharacterClassification > const & implGetCharacterClassification();
55 static bool implIsValidBoundary( css::i18n::Boundary const & rBoundary, sal_Int32 nLength );
56 static bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
57 static bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
58 static sal_Unicode implGetCharacter( std::u16string_view rText, sal_Int32 nIndex );
59 static OUString implGetTextRange( std::u16string_view rText, sal_Int32 nStartIndex, sal_Int32 nEndIndex );
60 virtual OUString implGetText() = 0;
61 virtual css::lang::Locale implGetLocale() = 0;
62 virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
63 void implGetGlyphBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
64 bool implGetWordBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
65 void implGetSentenceBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
66 virtual void implGetParagraphBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
67 virtual void implGetLineBoundary( const OUString& rText, css::i18n::Boundary& rBoundary, sal_Int32 nIndex );
69 /** non-virtual versions of the methods
71 @throws css::lang::IndexOutOfBoundsException
72 @throws css::uno::RuntimeException
74 OUString getSelectedText();
75 /// @throws css::uno::RuntimeException
76 sal_Int32 getSelectionStart();
77 /// @throws css::uno::RuntimeException
78 sal_Int32 getSelectionEnd();
79 /// @throws css::lang::IndexOutOfBoundsException
80 /// @throws css::lang::IllegalArgumentException
81 /// @throws css::uno::RuntimeException
82 css::accessibility::TextSegment getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType );
83 /// @throws css::lang::IndexOutOfBoundsException
84 /// @throws css::lang::IllegalArgumentException
85 /// @throws css::uno::RuntimeException
86 css::accessibility::TextSegment getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType );
87 /// @throws css::lang::IndexOutOfBoundsException
88 /// @throws css::lang::IllegalArgumentException
89 /// @throws css::uno::RuntimeException
90 css::accessibility::TextSegment getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType );
92 public:
94 /** Helper method, that detects the difference between
95 two strings and returns the deleted selection and
96 the inserted selection if available.
98 @returns true if there are differences between the
99 two strings and false if both are equal
101 @see css::accessibility::AccessibleEventId
102 css::accessibility::TextSegment
104 static bool implInitTextChangedEvent(
105 std::u16string_view rOldString,
106 std::u16string_view rNewString,
107 /*out*/ css::uno::Any& rDeleted,
108 /*out*/ css::uno::Any& rInserted); // throw()
112 // OAccessibleTextHelper
115 /** a helper class for implementing an AccessibleExtendedComponent which at the same time
116 supports an XAccessibleText interface
118 class UNLESS_MERGELIBS_MORE(COMPHELPER_DLLPUBLIC) OAccessibleTextHelper : public cppu::ImplInheritanceHelper<
119 OAccessibleExtendedComponentHelper,
120 css::accessibility::XAccessibleText>,
121 public OCommonAccessibleText
123 private:
124 OAccessibleTextHelper(OAccessibleTextHelper const &) = delete;
125 OAccessibleTextHelper(OAccessibleTextHelper &&) = delete;
126 void operator =(OAccessibleTextHelper const &) = delete;
127 void operator =(OAccessibleTextHelper &&) = delete;
129 protected:
130 OAccessibleTextHelper();
132 public:
133 // XAccessibleText
134 virtual OUString SAL_CALL getSelectedText() override final;
135 virtual sal_Int32 SAL_CALL getSelectionStart() override final;
136 virtual sal_Int32 SAL_CALL getSelectionEnd() override final;
137 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override final;
138 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override final;
139 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override final;
143 } // namespace comphelper
146 // OAccessibleTextHelper is a helper class for implementing the
147 // XAccessibleText interface.
149 // The following methods have a default implementation:
151 // getCharacter
152 // getSelectedText
153 // getSelectionStart
154 // getSelectionEnd
155 // getTextRange
156 // getTextAtIndex
157 // getTextBeforeIndex
158 // getTextBehindIndex
160 // The following methods must be overridden by derived classes:
162 // implGetText
163 // implGetLocale
164 // implGetSelection
165 // getCaretPosition
166 // setCaretPosition
167 // getCharacterAttributes
168 // getCharacterBounds
169 // getIndexAtPoint
170 // setSelection
171 // copyText
173 #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */