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