xref: /aoo41x/main/sw/source/core/access/accpara.hxx (revision 1d2dbeb0)
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 #ifndef _ACCPARA_HXX
24 #define _ACCPARA_HXX
25 
26 #include <acccontext.hxx>
27 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
28 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
29 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
30 #include <com/sun/star/accessibility/XAccessibleTextMarkup.hpp>
31 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
32 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
33 #include <hash_map>
34 #include <accselectionhelper.hxx>
35 // --> OD 2010-02-19 #i108125#
36 #include <calbck.hxx>
37 // <--
38 
39 class SwTxtFrm;
40 class SwTxtNode;
41 class SwPaM;
42 class SwAccessiblePortionData;
43 class SwAccessibleHyperTextData;
44 class SwXTextPortion;
45 // --> OD 2010-02-19 #i108125#
46 class SwParaChangeTrackingInfo;
47 // <--
48 
49 namespace rtl { class OUString; }
50 namespace com { namespace sun { namespace star {
51     namespace i18n { struct Boundary; }
52     namespace accessibility { class XAccessibleHyperlink; }
53 } } }
54 
55 typedef ::std::hash_map< ::rtl::OUString,
56                          ::com::sun::star::beans::PropertyValue,
57                          ::rtl::OUStringHash,
58                          ::std::equal_to< ::rtl::OUString > > tAccParaPropValMap;
59 
60 class SwAccessibleParagraph :
61         // --> OD 2010-02-19 #i108125#
62         public SwClient,
63         // <--
64         public SwAccessibleContext,
65 		public ::com::sun::star::accessibility::XAccessibleEditableText,
66 	    public com::sun::star::accessibility::XAccessibleSelection,
67         public com::sun::star::accessibility::XAccessibleHypertext,
68         public com::sun::star::accessibility::XAccessibleTextMarkup,
69         public com::sun::star::accessibility::XAccessibleMultiLineText,
70         public ::com::sun::star::accessibility::XAccessibleTextAttributes
71 {
72 	friend class SwAccessibleHyperlink;
73 
74 	::rtl::OUString sDesc;	// protected by base classes mutex
75 
76     /// data for this paragraph's text portions; this contains the
77     /// mapping from the core 'model string' to the accessible text
78     /// string.
79     /// pPortionData may be NULL; it should only be accessed through the
80     /// Get/Clear/Has/UpdatePortionData() methods
81     SwAccessiblePortionData* pPortionData;
82 	SwAccessibleHyperTextData *pHyperTextData;
83 
84 	sal_Int32 nOldCaretPos;	// The 'old' caret pos. It's only valid as long
85 							// as the cursor is inside this object (protected by
86 							// mutex)
87 
88 	sal_Bool bIsHeading;	// protected by base classes mutex
89 
90     // implementation for XAccessibleSelection
91     SwAccessibleSelectionHelper aSelectionHelper;
92 
93     // --> OD 2010-02-19 #i108125#
94     SwParaChangeTrackingInfo* mpParaChangeTrackInfo;
95     // <--
96 
97     /// get the SwTxtNode (requires frame; check before)
98     const SwTxtNode* GetTxtNode() const;
99 
100     /// get the (accessible) text string (requires frame; check before)
101     ::rtl::OUString GetString();
102 
103 	::rtl::OUString GetDescription();
104 
105 	// get the current care position
106 	sal_Int32 GetCaretPos();
107 
108     /// determine the current selection. Fill the values with
109     /// -1 if there is no selection in the this paragraph
110     sal_Bool GetSelection(sal_Int32& nStart, sal_Int32& nEnd);
111 
112     // helper for GetSelection and getCaretPosition
113     // --> OD 2005-12-20 #i27301#
114     // - add parameter <_bForSelection>, which indicates, if the cursor is
115     //   retrieved for selection or for caret position.
116     SwPaM* GetCursor( const bool _bForSelection );
117 
118     /// for cut/copy/paste: execute a particular slot at the view shell
119     void ExecuteAtViewShell( sal_uInt16 nSlot );
120 
121     /// helper method for get/setAttributes
122     /// (for the special case of (nEndIndex==-1) a single character will
123     ///  be selected)
124     SwXTextPortion* CreateUnoPortion( sal_Int32 nStart, sal_Int32 nEnd );
125 
126 
127     // methods for checking the parameter range:
128 
129     /// does nPos point to a char?
130     sal_Bool IsValidChar(sal_Int32 nPos, sal_Int32 nLength);
131 
132     /// does nPos point to a position? (may be behind the last character)
133     sal_Bool IsValidPosition(sal_Int32 nPos, sal_Int32 nLength);
134 
135     /// is nBegin...nEnd a valid range? (nEnd points past the last character)
136     sal_Bool IsValidRange(sal_Int32 nBegin, sal_Int32 nEnd, sal_Int32 nLength);
137 
138     /// Ensure ordered range (i.e. nBegin is smaller then nEnd)
139     inline void OrderRange(sal_Int32& nBegin, sal_Int32& nEnd)
140     {
141         if( nBegin > nEnd )
142         {
143             sal_Int32 nTmp = nBegin; nBegin = nEnd; nEnd = nTmp;
144         }
145     }
146 
147     // --> OD 2006-07-13 #i63870#
148     void _getDefaultAttributesImpl(
149             const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes,
150             tAccParaPropValMap& rDefAttrSeq,
151             const bool bOnlyCharAttrs = false );
152     void _getRunAttributesImpl(
153             const sal_Int32 nIndex,
154             const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes,
155             tAccParaPropValMap& rRunAttrSeq );
156     // <--
157 
158 public:
159 
160 	sal_Bool IsHeading() const;
161 
162 protected:
163 
164 	// Set states for getAccessibleStateSet.
165 	// This drived class additinaly sets MULTILINE(1), MULTISELECTABLE(+),
166 	// FOCUSABLE(+) and FOCUSED(+)
167 	virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet );
168 
169 	virtual void _InvalidateContent( sal_Bool bVisibleDataFired );
170 
171 	virtual void _InvalidateCursorPos();
172 	virtual void _InvalidateFocus();
173 
174 	virtual ~SwAccessibleParagraph();
175 
176 	//=====  handling of data for the text portions ===========================
177 
178     /// force update of new portion data
179     void UpdatePortionData()
180         throw( com::sun::star::uno::RuntimeException );
181 
182     /// remove the current portion data
183     void ClearPortionData();
184 
185     /// get portion data; update if necesary
186     SwAccessiblePortionData& GetPortionData()
187         throw( com::sun::star::uno::RuntimeException )
188     {
189         if( pPortionData == NULL )
190             UpdatePortionData();
191         return *pPortionData;
192     }
193 
194     /// determine if portion data is currently available
195     sal_Bool HasPortionData()   { return (pPortionData != NULL); }
196 
197 
198 	//=====  helpers for word boundaries  ====================================
199 
200     sal_Bool GetCharBoundary( com::sun::star::i18n::Boundary& rBound,
201                               const rtl::OUString& rText,
202                               sal_Int32 nPos );
203     sal_Bool GetWordBoundary( com::sun::star::i18n::Boundary& rBound,
204                               const rtl::OUString& rText,
205                               sal_Int32 nPos );
206     sal_Bool GetSentenceBoundary( com::sun::star::i18n::Boundary& rBound,
207                                   const rtl::OUString& rText,
208                                   sal_Int32 nPos );
209     sal_Bool GetLineBoundary( com::sun::star::i18n::Boundary& rBound,
210                               const rtl::OUString& rText,
211                               sal_Int32 nPos );
212     sal_Bool GetParagraphBoundary( com::sun::star::i18n::Boundary& rBound,
213                                    const rtl::OUString& rText,
214                                    sal_Int32 nPos );
215     sal_Bool GetAttributeBoundary( com::sun::star::i18n::Boundary& rBound,
216                                    const rtl::OUString& rText,
217                                    sal_Int32 nPos );
218     sal_Bool GetGlyphBoundary( com::sun::star::i18n::Boundary& rBound,
219                                const rtl::OUString& rText,
220                                sal_Int32 nPos );
221 
222     /// get boundaries of word/sentence/etc. for specified text type
223     /// Does all argument checking, and then delegates to helper methods above.
224     sal_Bool GetTextBoundary( com::sun::star::i18n::Boundary& rBound,
225                               const rtl::OUString& rText,
226                               sal_Int32 nPos,
227                               sal_Int16 aTextType )
228         throw (
229             ::com::sun::star::lang::IndexOutOfBoundsException,
230             ::com::sun::star::lang::IllegalArgumentException,
231             ::com::sun::star::uno::RuntimeException);
232 
233     virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew);
234 
235 public:
236 
237     SwAccessibleParagraph( SwAccessibleMap& rInitMap,
238                            const SwTxtFrm& rTxtFrm );
239 
240 	inline operator ::com::sun::star::accessibility::XAccessibleText *();
241 
242 	virtual sal_Bool HasCursor();	// required by map to remember that object
243 
244     //=====  XAccessibleContext  ==============================================
245 
246     ///	Return this object's description.
247 	virtual ::rtl::OUString SAL_CALL
248     	getAccessibleDescription (void)
249         throw (com::sun::star::uno::RuntimeException);
250 
251 	/**	Return the parents locale or throw exception if this object has no
252     	parent yet/anymore.
253     */
254 	virtual ::com::sun::star::lang::Locale SAL_CALL
255     	getLocale (void)
256 		throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
257 
258     /** paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO
259 
260         OD 2005-12-02 #i27138#
261 
262         @author OD
263     */
264     virtual ::com::sun::star::uno::Reference<
265             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
266         getAccessibleRelationSet (void)
267         throw (::com::sun::star::uno::RuntimeException);
268 
269 	//=====  XAccessibleComponent  ============================================
270 
271     virtual void SAL_CALL grabFocus()
272 		throw (::com::sun::star::uno::RuntimeException);
273     // --> OD 2007-01-17 #i71385#
274     virtual sal_Int32 SAL_CALL getForeground()
275         throw (::com::sun::star::uno::RuntimeException);
276     virtual sal_Int32 SAL_CALL getBackground()
277         throw (::com::sun::star::uno::RuntimeException);
278     // <--
279 
280 	//=====  XServiceInfo  ====================================================
281 
282     /**	Returns an identifier for the implementation of this object.
283     */
284 	virtual ::rtl::OUString SAL_CALL
285     	getImplementationName (void)
286         throw (::com::sun::star::uno::RuntimeException);
287 
288     /**	Return whether the specified service is supported by this class.
289     */
290     virtual sal_Bool SAL_CALL
291     	supportsService (const ::rtl::OUString& sServiceName)
292         throw (::com::sun::star::uno::RuntimeException);
293 
294     /** Returns a list of all supported services.  In this case that is just
295     	the AccessibleContext service.
296     */
297 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
298     	getSupportedServiceNames (void)
299         throw (::com::sun::star::uno::RuntimeException);
300 
301 
302 	//=====  XInterface  ======================================================
303 
304     // (XInterface methods need to be implemented to disambiguate
305     // between those inherited through SwAcessibleContext and
306     // XAccessibleEditableText).
307 
308     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
309         const ::com::sun::star::uno::Type& aType )
310         throw (::com::sun::star::uno::RuntimeException);
311 
312     virtual void SAL_CALL acquire(  ) throw ()
313         { SwAccessibleContext::acquire(); };
314 
315     virtual void SAL_CALL release(  ) throw ()
316         { SwAccessibleContext::release(); };
317 
318 	//====== XTypeProvider ====================================================
319 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
320     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw(::com::sun::star::uno::RuntimeException);
321 
322 	//=====  XAccesibleText  ==================================================
323     virtual sal_Int32 SAL_CALL getCaretPosition(  ) throw (::com::sun::star::uno::RuntimeException);
324     virtual sal_Bool SAL_CALL setCaretPosition( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
325     virtual sal_Unicode SAL_CALL getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
326     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);
327     virtual ::com::sun::star::awt::Rectangle SAL_CALL getCharacterBounds( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
328     virtual sal_Int32 SAL_CALL getCharacterCount(  ) throw (::com::sun::star::uno::RuntimeException);
329     virtual sal_Int32 SAL_CALL getIndexAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
330     virtual ::rtl::OUString SAL_CALL getSelectedText(  ) throw (::com::sun::star::uno::RuntimeException);
331     virtual sal_Int32 SAL_CALL getSelectionStart(  ) throw (::com::sun::star::uno::RuntimeException);
332     virtual sal_Int32 SAL_CALL getSelectionEnd(  ) throw (::com::sun::star::uno::RuntimeException);
333     virtual sal_Bool SAL_CALL setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
334     virtual ::rtl::OUString SAL_CALL getText(  ) throw (::com::sun::star::uno::RuntimeException);
335     virtual ::rtl::OUString SAL_CALL getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
336     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);
337     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);
338     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);
339     virtual sal_Bool SAL_CALL copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
340 
341 	//=====  XAccesibleEditableText  ==========================================
342     virtual sal_Bool SAL_CALL cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
343     virtual sal_Bool SAL_CALL pasteText( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
344     virtual sal_Bool SAL_CALL deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
345     virtual sal_Bool SAL_CALL insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
346     virtual sal_Bool SAL_CALL replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::rtl::OUString& sReplacement ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
347     virtual sal_Bool SAL_CALL setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aAttributeSet ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
348     virtual sal_Bool SAL_CALL setText( const ::rtl::OUString& sText ) throw (::com::sun::star::uno::RuntimeException);
349 
350 	//=====  XAccessibleSelection  ============================================
351     virtual void SAL_CALL selectAccessibleChild(
352         sal_Int32 nChildIndex )
353         throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
354                 ::com::sun::star::uno::RuntimeException );
355 
356     virtual sal_Bool SAL_CALL isAccessibleChildSelected(
357         sal_Int32 nChildIndex )
358         throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
359                 ::com::sun::star::uno::RuntimeException );
360     virtual void SAL_CALL clearAccessibleSelection(  )
361         throw ( ::com::sun::star::uno::RuntimeException );
362     virtual void SAL_CALL selectAllAccessibleChildren(  )
363         throw ( ::com::sun::star::uno::RuntimeException );
364     virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount(  )
365         throw ( ::com::sun::star::uno::RuntimeException );
366     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(
367         sal_Int32 nSelectedChildIndex )
368         throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
369                 ::com::sun::star::uno::RuntimeException);
370 
371     // --> OD 2004-11-16 #111714# - index has to be treated as global child index.
372     virtual void SAL_CALL deselectAccessibleChild(
373         sal_Int32 nChildIndex )
374         throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
375                 ::com::sun::star::uno::RuntimeException );
376 
377     //=====  XAccessibleHypertext  ============================================
378     virtual sal_Int32 SAL_CALL getHyperLinkCount()
379         throw (::com::sun::star::uno::RuntimeException);
380     virtual ::com::sun::star::uno::Reference<
381             ::com::sun::star::accessibility::XAccessibleHyperlink >
382         SAL_CALL getHyperLink( sal_Int32 nLinkIndex )
383         throw (::com::sun::star::lang::IndexOutOfBoundsException,
384                 ::com::sun::star::uno::RuntimeException);
385     virtual sal_Int32 SAL_CALL getHyperLinkIndex( sal_Int32 nCharIndex )
386         throw (::com::sun::star::lang::IndexOutOfBoundsException,
387                 ::com::sun::star::uno::RuntimeException);
388 
389     // --> OD 2008-05-19 #i71360#
390     //=====  XAccesibleTextMarkup  ============================================
391     virtual sal_Int32 SAL_CALL getTextMarkupCount( sal_Int32 nTextMarkupType )
392             throw (::com::sun::star::lang::IllegalArgumentException,
393                    ::com::sun::star::uno::RuntimeException);
394 
395     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
396             getTextMarkup( sal_Int32 nTextMarkupIndex,
397                            sal_Int32 nTextMarkupType )
398             throw (::com::sun::star::lang::IndexOutOfBoundsException,
399                    ::com::sun::star::lang::IllegalArgumentException,
400                    ::com::sun::star::uno::RuntimeException);
401 
402     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::accessibility::TextSegment > SAL_CALL
403             getTextMarkupAtIndex( sal_Int32 nCharIndex,
404                                   sal_Int32 nTextMarkupType )
405             throw (::com::sun::star::lang::IndexOutOfBoundsException,
406                    ::com::sun::star::lang::IllegalArgumentException,
407                    ::com::sun::star::uno::RuntimeException);
408     // <--
409 
410     // --> OD 2008-05-29 #i89175#
411     //=====  XAccessibleMultiLineText  ========================================
412     virtual sal_Int32 SAL_CALL getLineNumberAtIndex( sal_Int32 nIndex )
413             throw (::com::sun::star::lang::IndexOutOfBoundsException,
414                    ::com::sun::star::uno::RuntimeException);
415 
416     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
417             getTextAtLineNumber( sal_Int32 nLineNo )
418             throw (::com::sun::star::lang::IndexOutOfBoundsException,
419                    ::com::sun::star::uno::RuntimeException);
420 
421     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
422             getTextAtLineWithCaret()
423             throw (::com::sun::star::uno::RuntimeException);
424 
425     virtual sal_Int32 SAL_CALL getNumberOfLineWithCaret()
426             throw (::com::sun::star::uno::RuntimeException);
427     // <--
428 
429     // --> OD 2006-07-11 #i63870#
430     //=====  XAccesibleTextAttributes  ========================================
431     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getDefaultAttributes( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (::com::sun::star::uno::RuntimeException);
432     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getRunAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
433     // <--
434 };
435 
436 inline SwAccessibleParagraph::operator ::com::sun::star::accessibility::XAccessibleText *()
437 {
438 	return static_cast<
439 		::com::sun::star::accessibility::XAccessibleEditableText * >( this );
440 }
441 
442 #endif
443 
444