Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
21 : #define INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
22 :
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>
30 :
31 :
32 :
33 : namespace comphelper
34 : {
35 :
36 :
37 :
38 : // OCommonAccessibleText
39 :
40 : /** base class encapsulating common functionality for the helper classes implementing
41 : the XAccessibleText
42 : */
43 : class COMPHELPER_DLLPUBLIC OCommonAccessibleText
44 : {
45 : private:
46 : ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > m_xBreakIter;
47 : ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification > m_xCharClass;
48 :
49 : protected:
50 : OCommonAccessibleText();
51 : virtual ~OCommonAccessibleText();
52 :
53 : ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator > implGetBreakIterator();
54 : ::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification > implGetCharacterClassification();
55 : bool implIsValidBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nLength );
56 : virtual bool implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
57 : virtual bool implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
58 : virtual OUString implGetText() = 0;
59 : virtual ::com::sun::star::lang::Locale implGetLocale() = 0;
60 : virtual void implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
61 : virtual void implGetGlyphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
62 : virtual bool implGetWordBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
63 : virtual void implGetSentenceBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
64 : virtual void implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
65 : virtual void implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
66 :
67 : /** non-virtual versions of the methods
68 : */
69 : sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
70 : sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException);
71 : OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException);
72 : sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException);
73 : sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException);
74 : OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException);
75 : OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
76 : ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
77 : ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
78 : ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
79 :
80 : public:
81 :
82 : /** Helper method, that detects the difference between
83 : two strings and returns the deleted selection and
84 : the inserted selection if available.
85 :
86 : @returns true if there are differences between the
87 : two strings and false if both are equal
88 :
89 : @see ::com::sun::star::accessibility::AccessibleEventId
90 : ::com::sun::star::accessibility::TextSegment
91 : */
92 : static bool implInitTextChangedEvent(
93 : const OUString& rOldString,
94 : const OUString& rNewString,
95 : /*out*/ ::com::sun::star::uno::Any& rDeleted,
96 : /*out*/ ::com::sun::star::uno::Any& rInserted); // throw()
97 : };
98 :
99 :
100 :
101 : // OAccessibleTextHelper
102 :
103 :
104 : typedef ::cppu::ImplHelper1 < ::com::sun::star::accessibility::XAccessibleText
105 : > OAccessibleTextHelper_Base;
106 :
107 : /** a helper class for implementing an AccessibleExtendedComponent which at the same time
108 : supports an XAccessibleText interface
109 : */
110 0 : class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public OAccessibleExtendedComponentHelper,
111 : public OCommonAccessibleText,
112 : public OAccessibleTextHelper_Base
113 : {
114 : protected:
115 : // see the respective base class ctor for an extensive comment on this, please
116 : OAccessibleTextHelper( IMutex* _pExternalLock );
117 :
118 : public:
119 : // XInterface
120 : DECLARE_XINTERFACE( )
121 :
122 : // XTypeProvider
123 : DECLARE_XTYPEPROVIDER( )
124 :
125 : // XAccessibleText
126 : virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 : virtual sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 : virtual OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 : virtual sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 : virtual sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 : virtual OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 : virtual OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
133 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
134 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 : virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
136 : };
137 :
138 :
139 : } // namespace comphelper
140 :
141 :
142 : #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
143 :
144 :
145 :
146 :
147 : // OAccessibleTextHelper is a helper class for implementing the
148 : // XAccessibleText interface.
149 :
150 : // The following methods have a default implementation:
151 :
152 : // getCharacter
153 : // getCharacterCount
154 : // getSelectedText
155 : // getSelectionStart
156 : // getSelectionEnd
157 : // getText
158 : // getTextRange
159 : // getTextAtIndex
160 : // getTextBeforeIndex
161 : // getTextBehindIndex
162 :
163 : // The following methods must be overridden by derived classes:
164 :
165 : // implGetText
166 : // implGetLocale
167 : // implGetSelection
168 : // getCaretPosition
169 : // setCaretPosition
170 : // getCharacterAttributes
171 : // getCharacterBounds
172 : // getIndexAtPoint
173 : // setSelection
174 : // copyText
175 :
176 :
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|