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 _SVX_ACCESSILE_STATIC_TEXT_BASE_HXX_
25 #define _SVX_ACCESSILE_STATIC_TEXT_BASE_HXX_
26 
27 #include <memory>
28 #include <tools/gen.hxx>
29 #include <cppuhelper/implbase2.hxx>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/XAccessibleText.hpp>
34 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
35 #include <com/sun/star/accessibility/TextSegment.hpp>
36 #include "editeng/editengdllapi.h"
37 
38 
39 class SvxEditSource;
40 class SvxEditViewForwarder;
41 
42 namespace accessibility
43 {
44 
45     class AccessibleStaticTextBase_Impl;
46 
47     typedef ::cppu::ImplHelper2<
48         ::com::sun::star::accessibility::XAccessibleText,
49         ::com::sun::star::accessibility::XAccessibleTextAttributes > AccessibleStaticTextBase_BASE;
50 
51 	/** Helper class for objects containing EditEngine/Outliner text
52 
53 	    This class implements the XAccessibleText interface for static
54 	    text, somewhat similar to the children of the
55 	    AccessibleTextHelper class. Currently, there are no children,
56 	    i.e. the whole text is presented in one big chunk. This might
57 	    change in the future, if a need for image bullets should
58 	    arise. These, by convention, would be represented as children
59 	    of the text.
60 
61 		You have to implement the SvxEditSource, SvxTextForwarder,
62 		SvxViewForwarder and SvxEditViewForwarder interfaces in order
63 		to enable your object to cooperate with this
64 		class. SvxTextForwarder encapsulates the fact that text
65 		objects do not necessarily have an EditEngine at their
66 		disposal, SvxViewForwarder and SvxEditViewForwarder do the
67 		same for the document and the edit view. The three mentioned
68 		forwarder objects are not stored by the AccessibleTextHelper,
69 		but fetched every time from the SvxEditSource. So you are best
70 		off making your SvxEditSource::Get*Forwarder methods cache the
71 		current forwarder.
72 
73         As this class is intended for static (i.e. non-changing) text
74         only, no event broadcasting is necessary. You must handle
75         visibility by yourself, the bounding boxes returned by
76         getCharacterBounds() are relative to your accessibility
77         object.
78 
79 		@attention All public non-UNO methods (those are the uppercase
80 		ones) must not be called with any mutex hold, except when
81 		calling from the main thread (with holds the solar mutex),
82 		unless stated otherwise. This is because they themselves might
83 		need the solar mutex in addition to the object mutex, and the
84 		ordering of the locking must be: first solar mutex, then
85 		object mutex. Furthermore, state change events might be fired
86 		internally.
87 
88 		@derive Use this class as a base for objects containing static
89 		edit engine text. To avoid overwriting every interface method
90 		to intercept derived object defunc state, just set NULL as the
91 		edit source. Every interface method will then properly throw
92 		an exception.
93 	*/
94     class EDITENG_DLLPUBLIC AccessibleStaticTextBase : public AccessibleStaticTextBase_BASE
95     {
96 
97     public:
98         /** Create accessible text object for given edit source
99 
100 	        @param pEditSource
101 	        The edit source to use. Object ownership is transferred
102 	        from the caller to the callee. The object listens on the
103 	        SvxEditSource for object disposal, so no provisions have
104 	        to be taken if the caller destroys the data (e.g. the
105 	        model) contained in the given SvxEditSource.
106 
107         */
108         explicit AccessibleStaticTextBase( ::std::auto_ptr< SvxEditSource > pEditSource );
109         virtual ~AccessibleStaticTextBase();
110 
111     private:
112 
113         // declared, but not defined
114         EDITENG_DLLPRIVATE AccessibleStaticTextBase( const AccessibleStaticTextBase& );
115         // declared, but not defined
116         EDITENG_DLLPRIVATE AccessibleStaticTextBase& operator= ( const AccessibleStaticTextBase& );
117 
118     public:
119         /** Query the current edit source
120 
121         	@attention This method returns by reference, so you are
122         	responsible for serialization (typically, you aquired the
123         	solar mutex when calling this method). Thus, the method
124         	should only be called from the main office thread.
125 
126         */
127         virtual const SvxEditSource& GetEditSource() const SAL_THROW((::com::sun::star::uno::RuntimeException));
128 
129         /** Set the current edit source
130 
131         	@attention You are required to have the solar mutex
132         	locked, when calling this method. Thus, the method should
133         	only be called from the main office thread.
134 
135     	    The EditSource set here is required to broadcast out the
136     	    following hints: EDITSOURCE_HINT_PARASMOVED,
137     	    EDITSOURCE_HINT_SELECTIONCHANGED, TEXT_HINT_MODIFIED,
138     	    TEXT_HINT_PARAINSERTED, TEXT_HINT_PARAREMOVED,
139     	    TEXT_HINT_TEXTHEIGHTCHANGED,
140     	    TEXT_HINT_VIEWSCROLLED. Otherwise, not all state changes
141     	    will get noticed by the accessibility object. Further
142     	    more, when the corresponding core object or the model is
143     	    dying, either the edit source must be set to NULL or it
144     	    has to broadcast a SFX_HINT_DYING hint.
145 
146             This class does not have a dispose method, since it is not
147             a UNO component. Nevertheless, it holds C++ references to
148             several core objects, so you should issue a
149             SetEditSource(::std::auto_ptr<SvxEditSource>(NULL)) in
150             your dispose() method.
151 
152         	@param pEditSource
153 	        The new edit source to set. Object ownership is transferred
154     	    from the caller to the callee.
155         */
156         virtual void SetEditSource( ::std::auto_ptr< SvxEditSource > pEditSource ) SAL_THROW((::com::sun::star::uno::RuntimeException));
157 
158         /** Set the event source
159 
160         	@attention When setting a reference here, you should call
161         	Dispose() when you as the owner are disposing, since until
162         	then this object will hold that reference
163 
164         	@param rInterface
165             The interface that should be set as the source for
166             accessibility events sent by this object.
167          */
168         virtual void SetEventSource( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& rInterface );
169 
170         /** Get the event source
171 
172         	@return the interface that is set as the source for
173             accessibility events sent by this object.
174          */
175         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > GetEventSource() const;
176 
177         /** Set offset of EditEngine from parent
178 
179         	@attention You are required to have the solar mutex
180         	locked, when calling this method. Thus, the method should
181         	only be called from the main office thread.
182 
183 	    	If the origin of the underlying EditEngine does
184 	    	not correspond to the upper left corner of the object
185 	    	using this class, you have to specify the offset.
186 
187         	@param rPoint
188 	        The offset in screen coordinates (i.e. pixel)
189         */
190         virtual void SetOffset( const Point& rPoint );
191 
192         /** Query offset of EditEngine from parent
193 
194     		@return the offset in screen coordinates (i.e. pixel)
195         */
196         virtual Point GetOffset() const;
197 
198         /** Update the visible children
199 
200         	As this class currently does not represent any content
201         	using children, this does nothing at the moment.
202 
203         	@attention You are required to have the solar mutex
204         	locked, when calling this method. Thus, the method should
205         	only be called from the main office thread.
206 
207 	        This method reevaluates the visibility of all
208 	        childrens. Call this method if your visibility state has
209 	        changed somehow, e.g. if the visible area has changed and
210 	        the AccessibleStaticTextHelper isn't notified
211 	        internally. Normally, there should not be a need to call
212 	        this method.
213         */
214         virtual void UpdateChildren() SAL_THROW((::com::sun::star::uno::RuntimeException));
215 
216         /** Drop all references and enter disposed state
217 
218         	This method drops all references to external objects (also
219         	the event source reference set via SetEventSource()) and
220         	sets the object into the disposed state (i.e. the methods
221         	return default values or throw a uno::DisposedException
222         	exception).
223          */
224         virtual void Dispose();
225 
226         // XAccessibleText interface implementation
227         virtual sal_Int32 SAL_CALL getCaretPosition() throw (::com::sun::star::uno::RuntimeException);
228         virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
229         virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
230         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
231         virtual ::com::sun::star::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
232         virtual sal_Int32 SAL_CALL getCharacterCount() throw (::com::sun::star::uno::RuntimeException);
233         virtual sal_Int32 SAL_CALL getIndexAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
234         virtual ::rtl::OUString SAL_CALL getSelectedText() throw (::com::sun::star::uno::RuntimeException);
235         virtual sal_Int32 SAL_CALL getSelectionStart() throw (::com::sun::star::uno::RuntimeException);
236         virtual sal_Int32 SAL_CALL getSelectionEnd() throw (::com::sun::star::uno::RuntimeException);
237         /// This will only work with a functional SvxEditViewForwarder, i.e. an EditEngine/Outliner in edit mode
238         virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
239         virtual ::rtl::OUString SAL_CALL getText() throw (::com::sun::star::uno::RuntimeException);
240         virtual ::rtl::OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
241         /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
242         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);
243         /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
244         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);
245         /// Does not support AccessibleTextType::SENTENCE (missing feature in EditEngine)
246         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);
247         /// This will only work with a functional SvxEditViewForwarder, i.e. an EditEngine/Outliner in edit mode
248         virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
249 
250         // XAccessibleTextAttributes
251         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getDefaultAttributes( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& RequestedAttributes ) throw (::com::sun::star::uno::RuntimeException);
252         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getRunAttributes( sal_Int32 Index, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& RequestedAttributes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
253 
254         // child-related methods from XAccessibleContext
255         virtual sal_Int32 SAL_CALL getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
256         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
257 
258         // child-related methods from XAccessibleComponent
259         virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
260 
261     protected:
262         Rectangle GetParagraphBoundingBox() const;
263         sal_Int32 GetParagraphCount() const;
264         sal_Int32 GetParagraphIndex() const;
265         sal_Int32 GetLineCount( sal_Int32 nParagraph ) const;
266 
267     private:
268 
269         /// @dyn
270         const std::auto_ptr< AccessibleStaticTextBase_Impl > mpImpl;
271 
272     };
273 
274 } // end of namespace accessibility
275 
276 #endif /* _SVX_ACCESSILE_STATIC_TEXT_BASE_HXX_ */
277