1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accpara.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _ACCCONTEXT_HXX
33 #include "acccontext.hxx"
35 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
36 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
37 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
38 // --> OD 2008-05-19 #i71360#
39 #include <com/sun/star/accessibility/XAccessibleTextMarkup.hpp>
41 // --> OD 2008-05-29 #i89175#
42 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
45 // --> OD 2006-07-11 #i63870#
46 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
49 #include "accselectionhelper.hxx"
54 class SwAccessiblePortionData
;
55 class SwAccessibleHyperTextData
;
57 namespace rtl
{ class OUString
; }
58 namespace com
{ namespace sun
{ namespace star
{
59 namespace i18n
{ struct Boundary
; }
60 namespace accessibility
{ class XAccessibleHyperlink
; }
63 typedef ::std::hash_map
< ::rtl::OUString
,
64 ::com::sun::star::beans::PropertyValue
,
66 ::std::equal_to
< ::rtl::OUString
> > tAccParaPropValMap
;
68 class SwAccessibleParagraph
:
69 public SwAccessibleContext
,
70 public ::com::sun::star::accessibility::XAccessibleEditableText
,
71 public com::sun::star::accessibility::XAccessibleSelection
,
72 public com::sun::star::accessibility::XAccessibleHypertext
,
73 // --> OD 2008-05-19 #i71360#
74 public com::sun::star::accessibility::XAccessibleTextMarkup
,
76 // --> OD 2008-05-29 #i89175#
77 public com::sun::star::accessibility::XAccessibleMultiLineText
,
79 // --> OD 2006-07-11 #i63870#
80 public ::com::sun::star::accessibility::XAccessibleTextAttributes
83 friend class SwAccessibleHyperlink
;
85 ::rtl::OUString sDesc
; // protected by base classes mutex
87 /// data for this paragraph's text portions; this contains the
88 /// mapping from the core 'model string' to the accessible text
90 /// pPortionData may be NULL; it should only be accessed through the
91 /// Get/Clear/Has/UpdatePortionData() methods
92 SwAccessiblePortionData
* pPortionData
;
93 SwAccessibleHyperTextData
*pHyperTextData
;
95 sal_Int32 nOldCaretPos
; // The 'old' caret pos. It's only valid as long
96 // as the cursor is inside this object (protected by
99 sal_Bool bIsHeading
; // protected by base classes mutex
101 // implementation for XAccessibleSelection
102 SwAccessibleSelectionHelper aSelectionHelper
;
105 /// get the SwTxtNode (requires frame; check before)
106 const SwTxtNode
* GetTxtNode() const;
108 /// get the (accessible) text string (requires frame; check before)
109 ::rtl::OUString
GetString();
111 ::rtl::OUString
GetDescription();
113 // get the current care position
114 sal_Int32
GetCaretPos();
116 /// determine the current selection. Fill the values with
117 /// -1 if there is no selection in the this paragraph
118 sal_Bool
GetSelection(sal_Int32
& nStart
, sal_Int32
& nEnd
);
120 // helper for GetSelection and getCaretPosition
121 // --> OD 2005-12-20 #i27301#
122 // - add parameter <_bForSelection>, which indicates, if the cursor is
123 // retrieved for selection or for caret position.
124 SwPaM
* GetCursor( const bool _bForSelection
);
126 /// for cut/copy/paste: execute a particular slot at the view shell
127 void ExecuteAtViewShell( UINT16 nSlot
);
129 /// helper method for get/setAttributes
130 /// (for the special case of (nEndIndex==-1) a single character will
132 SwXTextPortion
* CreateUnoPortion( sal_Int32 nStart
, sal_Int32 nEnd
);
135 // methods for checking the parameter range:
137 /// does nPos point to a char?
138 sal_Bool
IsValidChar(sal_Int32 nPos
, sal_Int32 nLength
);
140 /// does nPos point to a position? (may be behind the last character)
141 sal_Bool
IsValidPosition(sal_Int32 nPos
, sal_Int32 nLength
);
143 /// is nBegin...nEnd a valid range? (nEnd points past the last character)
144 sal_Bool
IsValidRange(sal_Int32 nBegin
, sal_Int32 nEnd
, sal_Int32 nLength
);
146 /// Ensure ordered range (i.e. nBegin is smaller then nEnd)
147 inline void OrderRange(sal_Int32
& nBegin
, sal_Int32
& nEnd
)
151 sal_Int32 nTmp
= nBegin
; nBegin
= nEnd
; nEnd
= nTmp
;
155 // --> OD 2006-07-13 #i63870#
156 void _getDefaultAttributesImpl(
157 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& aRequestedAttributes
,
158 tAccParaPropValMap
& rDefAttrSeq
,
159 const bool bOnlyCharAttrs
= false );
160 void _getRunAttributesImpl(
161 const sal_Int32 nIndex
,
162 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& aRequestedAttributes
,
163 tAccParaPropValMap
& rRunAttrSeq
);
168 sal_Bool
IsHeading() const;
172 // Set states for getAccessibleStateSet.
173 // This drived class additinaly sets MULTILINE(1), MULTISELECTABLE(+),
174 // FOCUSABLE(+) and FOCUSED(+)
175 virtual void GetStates( ::utl::AccessibleStateSetHelper
& rStateSet
);
177 virtual void _InvalidateContent( sal_Bool bVisibleDataFired
);
179 virtual void _InvalidateCursorPos();
180 virtual void _InvalidateFocus();
182 virtual ~SwAccessibleParagraph();
184 //===== handling of data for the text portions ===========================
186 /// force update of new portion data
187 void UpdatePortionData()
188 throw( com::sun::star::uno::RuntimeException
);
190 /// remove the current portion data
191 void ClearPortionData();
193 /// get portion data; update if necesary
194 SwAccessiblePortionData
& GetPortionData()
195 throw( com::sun::star::uno::RuntimeException
)
197 if( pPortionData
== NULL
)
199 return *pPortionData
;
202 /// determine if portion data is currently available
203 sal_Bool
HasPortionData() { return (pPortionData
!= NULL
); }
206 //===== helpers for word boundaries ====================================
208 sal_Bool
GetCharBoundary( com::sun::star::i18n::Boundary
& rBound
,
209 const rtl::OUString
& rText
,
211 sal_Bool
GetWordBoundary( com::sun::star::i18n::Boundary
& rBound
,
212 const rtl::OUString
& rText
,
214 sal_Bool
GetSentenceBoundary( com::sun::star::i18n::Boundary
& rBound
,
215 const rtl::OUString
& rText
,
217 sal_Bool
GetLineBoundary( com::sun::star::i18n::Boundary
& rBound
,
218 const rtl::OUString
& rText
,
220 sal_Bool
GetParagraphBoundary( com::sun::star::i18n::Boundary
& rBound
,
221 const rtl::OUString
& rText
,
223 sal_Bool
GetAttributeBoundary( com::sun::star::i18n::Boundary
& rBound
,
224 const rtl::OUString
& rText
,
226 sal_Bool
GetGlyphBoundary( com::sun::star::i18n::Boundary
& rBound
,
227 const rtl::OUString
& rText
,
230 /// get boundaries of word/sentence/etc. for specified text type
231 /// Does all argument checking, and then delegates to helper methods above.
232 sal_Bool
GetTextBoundary( com::sun::star::i18n::Boundary
& rBound
,
233 const rtl::OUString
& rText
,
235 sal_Int16 aTextType
)
237 ::com::sun::star::lang::IndexOutOfBoundsException
,
238 ::com::sun::star::lang::IllegalArgumentException
,
239 ::com::sun::star::uno::RuntimeException
);
243 SwAccessibleParagraph( SwAccessibleMap
* pInitMap
,
244 const SwTxtFrm
*pTxtFrm
);
246 inline operator ::com::sun::star::accessibility::XAccessibleText
*();
248 virtual sal_Bool
HasCursor(); // required by map to remember that object
250 //===== XAccessibleContext ==============================================
252 /// Return this object's description.
253 virtual ::rtl::OUString SAL_CALL
254 getAccessibleDescription (void)
255 throw (com::sun::star::uno::RuntimeException
);
257 /** Return the parents locale or throw exception if this object has no
260 virtual ::com::sun::star::lang::Locale SAL_CALL
262 throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
264 /** paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO
266 OD 2005-12-02 #i27138#
270 virtual ::com::sun::star::uno::Reference
<
271 ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
272 getAccessibleRelationSet (void)
273 throw (::com::sun::star::uno::RuntimeException
);
275 //===== XAccessibleComponent ============================================
277 virtual void SAL_CALL
grabFocus()
278 throw (::com::sun::star::uno::RuntimeException
);
279 // --> OD 2007-01-17 #i71385#
280 virtual sal_Int32 SAL_CALL
getForeground()
281 throw (::com::sun::star::uno::RuntimeException
);
282 virtual sal_Int32 SAL_CALL
getBackground()
283 throw (::com::sun::star::uno::RuntimeException
);
286 //===== XServiceInfo ====================================================
288 /** Returns an identifier for the implementation of this object.
290 virtual ::rtl::OUString SAL_CALL
291 getImplementationName (void)
292 throw (::com::sun::star::uno::RuntimeException
);
294 /** Return whether the specified service is supported by this class.
296 virtual sal_Bool SAL_CALL
297 supportsService (const ::rtl::OUString
& sServiceName
)
298 throw (::com::sun::star::uno::RuntimeException
);
300 /** Returns a list of all supported services. In this case that is just
301 the AccessibleContext service.
303 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
304 getSupportedServiceNames (void)
305 throw (::com::sun::star::uno::RuntimeException
);
308 //===== XInterface ======================================================
310 // (XInterface methods need to be implemented to disambiguate
311 // between those inherited through SwAcessibleContext and
312 // XAccessibleEditableText).
314 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(
315 const ::com::sun::star::uno::Type
& aType
)
316 throw (::com::sun::star::uno::RuntimeException
);
318 virtual void SAL_CALL
acquire( ) throw ()
319 { SwAccessibleContext::acquire(); };
321 virtual void SAL_CALL
release( ) throw ()
322 { SwAccessibleContext::release(); };
324 //====== XTypeProvider ====================================================
325 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
326 virtual ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) throw(::com::sun::star::uno::RuntimeException
);
328 //===== XAccesibleText ==================================================
329 virtual sal_Int32 SAL_CALL
getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException
);
330 virtual sal_Bool SAL_CALL
setCaretPosition( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
331 virtual sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
332 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
);
333 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getCharacterBounds( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
334 virtual sal_Int32 SAL_CALL
getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException
);
335 virtual sal_Int32 SAL_CALL
getIndexAtPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
336 virtual ::rtl::OUString SAL_CALL
getSelectedText( ) throw (::com::sun::star::uno::RuntimeException
);
337 virtual sal_Int32 SAL_CALL
getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException
);
338 virtual sal_Int32 SAL_CALL
getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException
);
339 virtual sal_Bool SAL_CALL
setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
340 virtual ::rtl::OUString SAL_CALL
getText( ) throw (::com::sun::star::uno::RuntimeException
);
341 virtual ::rtl::OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
342 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
);
343 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
);
344 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
);
345 virtual sal_Bool SAL_CALL
copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
347 //===== XAccesibleEditableText ==========================================
348 virtual sal_Bool SAL_CALL
cutText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
349 virtual sal_Bool SAL_CALL
pasteText( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
350 virtual sal_Bool SAL_CALL
deleteText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
351 virtual sal_Bool SAL_CALL
insertText( const ::rtl::OUString
& sText
, sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
352 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
);
353 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
);
354 virtual sal_Bool SAL_CALL
setText( const ::rtl::OUString
& sText
) throw (::com::sun::star::uno::RuntimeException
);
356 //===== XAccessibleSelection ============================================
357 virtual void SAL_CALL
selectAccessibleChild(
358 sal_Int32 nChildIndex
)
359 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
360 ::com::sun::star::uno::RuntimeException
);
362 virtual sal_Bool SAL_CALL
isAccessibleChildSelected(
363 sal_Int32 nChildIndex
)
364 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
365 ::com::sun::star::uno::RuntimeException
);
366 virtual void SAL_CALL
clearAccessibleSelection( )
367 throw ( ::com::sun::star::uno::RuntimeException
);
368 virtual void SAL_CALL
selectAllAccessibleChildren( )
369 throw ( ::com::sun::star::uno::RuntimeException
);
370 virtual sal_Int32 SAL_CALL
getSelectedAccessibleChildCount( )
371 throw ( ::com::sun::star::uno::RuntimeException
);
372 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getSelectedAccessibleChild(
373 sal_Int32 nSelectedChildIndex
)
374 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
375 ::com::sun::star::uno::RuntimeException
);
377 // --> OD 2004-11-16 #111714# - index has to be treated as global child index.
378 virtual void SAL_CALL
deselectAccessibleChild(
379 sal_Int32 nChildIndex
)
380 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
381 ::com::sun::star::uno::RuntimeException
);
383 //===== XAccessibleHypertext ============================================
384 virtual sal_Int32 SAL_CALL
getHyperLinkCount()
385 throw (::com::sun::star::uno::RuntimeException
);
386 virtual ::com::sun::star::uno::Reference
<
387 ::com::sun::star::accessibility::XAccessibleHyperlink
>
388 SAL_CALL
getHyperLink( sal_Int32 nLinkIndex
)
389 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
390 ::com::sun::star::uno::RuntimeException
);
391 virtual sal_Int32 SAL_CALL
getHyperLinkIndex( sal_Int32 nCharIndex
)
392 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
393 ::com::sun::star::uno::RuntimeException
);
395 // --> OD 2008-05-19 #i71360#
396 //===== XAccesibleTextMarkup ============================================
397 virtual sal_Int32 SAL_CALL
getTextMarkupCount( sal_Int32 nTextMarkupType
)
398 throw (::com::sun::star::lang::IllegalArgumentException
,
399 ::com::sun::star::uno::RuntimeException
);
401 virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
402 getTextMarkup( sal_Int32 nTextMarkupIndex
,
403 sal_Int32 nTextMarkupType
)
404 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
405 ::com::sun::star::lang::IllegalArgumentException
,
406 ::com::sun::star::uno::RuntimeException
);
408 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::accessibility::TextSegment
> SAL_CALL
409 getTextMarkupAtIndex( sal_Int32 nCharIndex
,
410 sal_Int32 nTextMarkupType
)
411 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
412 ::com::sun::star::lang::IllegalArgumentException
,
413 ::com::sun::star::uno::RuntimeException
);
416 // --> OD 2008-05-29 #i89175#
417 //===== XAccessibleMultiLineText ========================================
418 virtual sal_Int32 SAL_CALL
getLineNumberAtIndex( sal_Int32 nIndex
)
419 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
420 ::com::sun::star::uno::RuntimeException
);
422 virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
423 getTextAtLineNumber( sal_Int32 nLineNo
)
424 throw (::com::sun::star::lang::IndexOutOfBoundsException
,
425 ::com::sun::star::uno::RuntimeException
);
427 virtual ::com::sun::star::accessibility::TextSegment SAL_CALL
428 getTextAtLineWithCaret()
429 throw (::com::sun::star::uno::RuntimeException
);
431 virtual sal_Int32 SAL_CALL
getNumberOfLineWithCaret()
432 throw (::com::sun::star::uno::RuntimeException
);
435 // --> OD 2006-07-11 #i63870#
436 //===== XAccesibleTextAttributes ========================================
437 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
);
438 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
);
442 inline SwAccessibleParagraph::operator ::com::sun::star::accessibility::XAccessibleText
*()
445 ::com::sun::star::accessibility::XAccessibleEditableText
* >( this );