1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX
25 #define COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX
26 
27 #include <com/sun/star/accessibility/XAccessibleText.hpp>
28 #include <com/sun/star/accessibility/TextSegment.hpp>
29 #include <com/sun/star/i18n/XBreakIterator.hpp>
30 #include <com/sun/star/i18n/XCharacterClassification.hpp>
31 #include <comphelper/accessiblecomponenthelper.hxx>
32 #include <cppuhelper/implbase1.hxx>
33 #include "comphelper/comphelperdllapi.h"
34 
35 
36 //..............................................................................
37 namespace comphelper
38 {
39 //..............................................................................
40 
41 	//==============================================================================
42 	// OCommonAccessibleText
43 	//==============================================================================
44 	/** base class encapsulating common functionality for the helper classes implementing
45 		the XAccessibleText
46 	*/
47 	class COMPHELPER_DLLPUBLIC OCommonAccessibleText
48 	{
49 	private:
50 		::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator >				m_xBreakIter;
51 		::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification >	m_xCharClass;
52 
53 	protected:
54 		OCommonAccessibleText();
55 		virtual ~OCommonAccessibleText();
56 
57 		::com::sun::star::uno::Reference < ::com::sun::star::i18n::XBreakIterator >				implGetBreakIterator();
58 		::com::sun::star::uno::Reference < ::com::sun::star::i18n::XCharacterClassification >	implGetCharacterClassification();
59 		sal_Bool								implIsValidBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nLength );
60 		virtual sal_Bool						implIsValidIndex( sal_Int32 nIndex, sal_Int32 nLength );
61 		virtual sal_Bool						implIsValidRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex, sal_Int32 nLength );
62 		virtual ::rtl::OUString					implGetText() = 0;
63 		virtual ::com::sun::star::lang::Locale	implGetLocale() = 0;
64 		virtual void							implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) = 0;
65 		virtual void							implGetGlyphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
66 		virtual sal_Bool						implGetWordBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
67 		virtual void							implGetSentenceBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
68 		virtual void							implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
69 		virtual void							implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex );
70 
71 		/** non-virtual versions of the methods
72 		*/
73 		sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
74 		sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException);
75 		::rtl::OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException);
76 		sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException);
77 		sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException);
78 		::rtl::OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException);
79 		::rtl::OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
80         ::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);
81         ::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);
82         ::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);
83 
84     public:
85 
86         /** Helper method, that detects the difference between
87             two strings and returns the deleted selection and
88             the inserted selection if available.
89 
90             @returns true if there are differences between the
91             two strings and false if both are equal
92 
93             @see ::com::sun::star::accessibility::AccessibleEventId
94                  ::com::sun::star::accessibility::TextSegment
95         */
96         static bool implInitTextChangedEvent(
97             const rtl::OUString& rOldString,
98             const rtl::OUString& rNewString,
99             /*out*/ ::com::sun::star::uno::Any& rDeleted,
100             /*out*/ ::com::sun::star::uno::Any& rInserted); // throw()
101 	};
102 
103 
104 	//==============================================================================
105 	// OAccessibleTextHelper
106 	//==============================================================================
107 
108 	typedef	::cppu::ImplHelper1 <	::com::sun::star::accessibility::XAccessibleText
109 								>	OAccessibleTextHelper_Base;
110 
111 	/** a helper class for implementing an AccessibleExtendedComponent which at the same time
112 		supports an XAccessibleText interface
113 	*/
114 	class COMPHELPER_DLLPUBLIC OAccessibleTextHelper : public OAccessibleExtendedComponentHelper,
115 								  public OCommonAccessibleText,
116 								  public OAccessibleTextHelper_Base
117 	{
118 	protected:
119 		OAccessibleTextHelper();
120 		// see the respective base class ctor for an extensive comment on this, please
121 		OAccessibleTextHelper( IMutex* _pExternalLock );
122 
123 	public:
124 		// XInterface
125 		DECLARE_XINTERFACE( )
126 
127 		// XTypeProvider
128 		DECLARE_XTYPEPROVIDER( )
129 
130 		// XAccessibleText
131 		virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
132 		virtual sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException);
133 		virtual ::rtl::OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException);
134 		virtual sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException);
135 		virtual sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException);
136 		virtual ::rtl::OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException);
137 		virtual ::rtl::OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
138         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);
139         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);
140         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);
141 	};
142 
143 //..............................................................................
144 }	// namespace comphelper
145 //..............................................................................
146 
147 #endif // COMPHELPER_ACCESSIBLE_TEXT_HELPER_HXX
148 
149 
150 // -----------------------------------------------------------------------------
151 //
152 //	OAccessibleTextHelper is a helper class for implementing the
153 //  XAccessibleText interface.
154 //
155 //	The following methods have a default implementation:
156 //
157 //		getCharacter
158 //		getCharacterCount
159 //		getSelectedText
160 //		getSelectionStart
161 //		getSelectionEnd
162 //		getText
163 //		getTextRange
164 //		getTextAtIndex
165 //		getTextBeforeIndex
166 //		getTextBehindIndex
167 //
168 //	The following methods must be overriden by derived classes:
169 //
170 //		implGetText
171 //		implGetLocale
172 //		implGetSelection
173 //		getCaretPosition
174 //		setCaretPosition
175 //		getCharacterAttributes
176 //		getCharacterBounds
177 //		getIndexAtPoint
178 //		setSelection
179 //		copyText
180 //
181 // -----------------------------------------------------------------------------
182