sw HTML export: fix PNG export of Writer images containing metafiles
[LibreOffice.git] / include / comphelper / accessibletexthelper.hxx
blob607004aee30fd41e54c96776138836fc8bfefd0b
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/implbase1.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 typedef ::cppu::ImplHelper1 < css::accessibility::XAccessibleText
115 > OAccessibleTextHelper_Base;
117 /** a helper class for implementing an AccessibleExtendedComponent which at the same time
118 supports an XAccessibleText interface
120 class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public OAccessibleExtendedComponentHelper,
121 public OCommonAccessibleText,
122 public OAccessibleTextHelper_Base
124 protected:
125 OAccessibleTextHelper();
127 public:
128 // XInterface
129 DECLARE_XINTERFACE( )
131 // XTypeProvider
132 DECLARE_XTYPEPROVIDER( )
134 // XAccessibleText
135 virtual OUString SAL_CALL getSelectedText() override;
136 virtual sal_Int32 SAL_CALL getSelectionStart() override;
137 virtual sal_Int32 SAL_CALL getSelectionEnd() override;
138 virtual css::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
139 virtual css::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
140 virtual css::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) override;
144 } // namespace comphelper
147 // OAccessibleTextHelper is a helper class for implementing the
148 // XAccessibleText interface.
150 // The following methods have a default implementation:
152 // getCharacter
153 // getSelectedText
154 // getSelectionStart
155 // getSelectionEnd
156 // getTextRange
157 // getTextAtIndex
158 // getTextBeforeIndex
159 // getTextBehindIndex
161 // The following methods must be overridden by derived classes:
163 // implGetText
164 // implGetLocale
165 // implGetSelection
166 // getCaretPosition
167 // setCaretPosition
168 // getCharacterAttributes
169 // getCharacterBounds
170 // getIndexAtPoint
171 // setSelection
172 // copyText
174 #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */