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 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 31 //------------------------------------------------------------------------ 32 // 33 // Global header 34 // 35 //------------------------------------------------------------------------ 36 37 #include <limits.h> 38 #include <vector> 39 #include <algorithm> 40 #include <vos/mutex.hxx> 41 #include <vcl/window.hxx> 42 #include <vcl/svapp.hxx> 43 #include <editeng/flditem.hxx> 44 #include <com/sun/star/uno/Any.hxx> 45 #include <com/sun/star/uno/Reference.hxx> 46 #include <com/sun/star/awt/Point.hpp> 47 #include <com/sun/star/awt/Rectangle.hpp> 48 #include <com/sun/star/lang/DisposedException.hpp> 49 #include <com/sun/star/accessibility/AccessibleRole.hpp> 50 #include <com/sun/star/accessibility/AccessibleTextType.hpp> 51 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 52 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 53 #include <comphelper/accessibleeventnotifier.hxx> 54 #include <comphelper/sequenceashashmap.hxx> 55 #include <unotools/accessiblestatesethelper.hxx> 56 #include <unotools/accessiblerelationsethelper.hxx> 57 #include <com/sun/star/accessibility/AccessibleRelationType.hpp> 58 #include <vcl/unohelp.hxx> 59 #include <editeng/editeng.hxx> 60 #include <editeng/unoprnms.hxx> 61 #include <editeng/unoipset.hxx> 62 #include <editeng/outliner.hxx> 63 64 //------------------------------------------------------------------------ 65 // 66 // Project-local header 67 // 68 //------------------------------------------------------------------------ 69 70 #include <com/sun/star/beans/PropertyState.hpp> 71 72 //!!!#include <svx/unoshape.hxx> 73 //!!!#include <svx/dialmgr.hxx> 74 //!!!#include "accessibility.hrc" 75 76 #include <editeng/unolingu.hxx> 77 #include <editeng/unopracc.hxx> 78 #include "editeng/AccessibleEditableTextPara.hxx" 79 #include "AccessibleHyperlink.hxx" 80 81 #include <svtools/colorcfg.hxx> 82 83 84 using namespace ::com::sun::star; 85 using namespace ::com::sun::star::beans; 86 using namespace ::com::sun::star::accessibility; 87 88 89 //------------------------------------------------------------------------ 90 // 91 // AccessibleEditableTextPara implementation 92 // 93 //------------------------------------------------------------------------ 94 95 namespace accessibility 96 { 97 98 const SvxItemPropertySet* ImplGetSvxCharAndParaPropertiesSet() 99 { 100 // PropertyMap for character and paragraph properties 101 static const SfxItemPropertyMapEntry aPropMap[] = 102 { 103 SVX_UNOEDIT_CHAR_PROPERTIES, 104 SVX_UNOEDIT_PARA_PROPERTIES, 105 SVX_UNOEDIT_NUMBERING_PROPERTIE, 106 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 107 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0}, 108 {0,0,0,0,0,0} 109 }; 110 static SvxItemPropertySet aPropSet( aPropMap, EditEngine::GetGlobalItemPool() ); 111 return &aPropSet; 112 } 113 114 115 DBG_NAME( AccessibleEditableTextPara ) 116 117 // --> OD 2006-01-11 #i27138# - add parameter <_pParaManager> 118 AccessibleEditableTextPara::AccessibleEditableTextPara( 119 const uno::Reference< XAccessible >& rParent, 120 const AccessibleParaManager* _pParaManager ) 121 : AccessibleTextParaInterfaceBase( m_aMutex ), 122 mnParagraphIndex( 0 ), 123 mnIndexInParent( 0 ), 124 mpEditSource( NULL ), 125 maEEOffset( 0, 0 ), 126 mxParent( rParent ), 127 // well, that's strictly (UNO) exception safe, though not 128 // really robust. We rely on the fact that this member is 129 // constructed last, and that the constructor body catches 130 // exceptions, thus no chance for exceptions once the Id is 131 // fetched. Nevertheless, normally should employ RAII here... 132 mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient()), 133 // --> OD 2006-01-11 #i27138# 134 mpParaManager( _pParaManager ) 135 // <-- 136 { 137 #ifdef DBG_UTIL 138 DBG_CTOR( AccessibleEditableTextPara, NULL ); 139 OSL_TRACE( "AccessibleEditableTextPara received ID: %d\n", mnNotifierClientId ); 140 #endif 141 142 try 143 { 144 // Create the state set. 145 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper (); 146 mxStateSet = pStateSet; 147 148 // these are always on 149 pStateSet->AddState( AccessibleStateType::MULTI_LINE ); 150 pStateSet->AddState( AccessibleStateType::FOCUSABLE ); 151 pStateSet->AddState( AccessibleStateType::VISIBLE ); 152 pStateSet->AddState( AccessibleStateType::SHOWING ); 153 pStateSet->AddState( AccessibleStateType::ENABLED ); 154 pStateSet->AddState( AccessibleStateType::SENSITIVE ); 155 } 156 catch( const uno::Exception& ) {} 157 } 158 159 AccessibleEditableTextPara::~AccessibleEditableTextPara() 160 { 161 DBG_DTOR( AccessibleEditableTextPara, NULL ); 162 163 // sign off from event notifier 164 if( getNotifierClientId() != -1 ) 165 { 166 try 167 { 168 ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() ); 169 #ifdef DBG_UTIL 170 OSL_TRACE( "AccessibleEditableTextPara revoked ID: %d\n", mnNotifierClientId ); 171 #endif 172 } 173 catch( const uno::Exception& ) {} 174 } 175 } 176 177 ::rtl::OUString AccessibleEditableTextPara::implGetText() 178 { 179 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 180 181 return GetTextRange( 0, GetTextLen() ); 182 } 183 184 ::com::sun::star::lang::Locale AccessibleEditableTextPara::implGetLocale() 185 { 186 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 187 188 lang::Locale aLocale; 189 190 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 191 "AccessibleEditableTextPara::getLocale: paragraph index value overflow"); 192 193 // return locale of first character in the paragraph 194 return SvxLanguageToLocale(aLocale, GetTextForwarder().GetLanguage( static_cast< sal_uInt16 >( GetParagraphIndex() ), 0 )); 195 } 196 197 void AccessibleEditableTextPara::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 198 { 199 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 200 201 sal_uInt16 nStart, nEnd; 202 203 if( GetSelection( nStart, nEnd ) ) 204 { 205 nStartIndex = nStart; 206 nEndIndex = nEnd; 207 } 208 else 209 { 210 // #102234# No exception, just set to 'invalid' 211 nStartIndex = -1; 212 nEndIndex = -1; 213 } 214 } 215 216 void AccessibleEditableTextPara::implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 /*nIndex*/ ) 217 { 218 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 219 DBG_WARNING( "AccessibleEditableTextPara::implGetParagraphBoundary: only a base implementation, ignoring the index" ); 220 221 rBoundary.startPos = 0; 222 rBoundary.endPos = GetTextLen(); 223 } 224 225 void AccessibleEditableTextPara::implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex ) 226 { 227 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 228 229 SvxTextForwarder& rCacheTF = GetTextForwarder(); 230 const sal_Int32 nParaIndex = GetParagraphIndex(); 231 232 DBG_ASSERT(nParaIndex >= 0 && nParaIndex <= USHRT_MAX, 233 "AccessibleEditableTextPara::implGetLineBoundary: paragraph index value overflow"); 234 235 const sal_Int32 nTextLen = rCacheTF.GetTextLen( static_cast< sal_uInt16 >( nParaIndex ) ); 236 237 CheckPosition(nIndex); 238 239 rBoundary.startPos = rBoundary.endPos = -1; 240 241 const sal_uInt16 nLineCount=rCacheTF.GetLineCount( static_cast< sal_uInt16 >( nParaIndex ) ); 242 243 if( nIndex == nTextLen ) 244 { 245 // #i17014# Special-casing one-behind-the-end character 246 if( nLineCount <= 1 ) 247 rBoundary.startPos = 0; 248 else 249 rBoundary.startPos = nTextLen - rCacheTF.GetLineLen( static_cast< sal_uInt16 >( nParaIndex ), 250 nLineCount-1 ); 251 252 rBoundary.endPos = nTextLen; 253 } 254 else 255 { 256 // normal line search 257 sal_uInt16 nLine; 258 sal_Int32 nCurIndex; 259 for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine ) 260 { 261 nCurIndex += rCacheTF.GetLineLen( static_cast< sal_uInt16 >( nParaIndex ), nLine); 262 263 if( nCurIndex > nIndex ) 264 { 265 rBoundary.startPos = nCurIndex - rCacheTF.GetLineLen(static_cast< sal_uInt16 >( nParaIndex ), nLine); 266 rBoundary.endPos = nCurIndex; 267 break; 268 } 269 } 270 } 271 } 272 273 int AccessibleEditableTextPara::getNotifierClientId() const 274 { 275 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 276 277 return mnNotifierClientId; 278 } 279 280 void AccessibleEditableTextPara::SetIndexInParent( sal_Int32 nIndex ) 281 { 282 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 283 284 mnIndexInParent = nIndex; 285 } 286 287 sal_Int32 AccessibleEditableTextPara::GetIndexInParent() const 288 { 289 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 290 291 return mnIndexInParent; 292 } 293 294 void AccessibleEditableTextPara::SetParagraphIndex( sal_Int32 nIndex ) 295 { 296 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 297 298 sal_Int32 nOldIndex = mnParagraphIndex; 299 300 mnParagraphIndex = nIndex; 301 302 WeakBullet::HardRefType aChild( maImageBullet.get() ); 303 if( aChild.is() ) 304 aChild->SetParagraphIndex(mnParagraphIndex); 305 306 try 307 { 308 if( nOldIndex != nIndex ) 309 { 310 uno::Any aOldDesc; 311 uno::Any aOldName; 312 313 try 314 { 315 aOldDesc <<= getAccessibleDescription(); 316 aOldName <<= getAccessibleName(); 317 } 318 catch( const uno::Exception& ) {} // optional behaviour 319 // index and therefore description changed 320 FireEvent( AccessibleEventId::DESCRIPTION_CHANGED, uno::makeAny( getAccessibleDescription() ), aOldDesc ); 321 FireEvent( AccessibleEventId::NAME_CHANGED, uno::makeAny( getAccessibleName() ), aOldName ); 322 } 323 } 324 catch( const uno::Exception& ) {} // optional behaviour 325 } 326 327 sal_Int32 AccessibleEditableTextPara::GetParagraphIndex() const SAL_THROW((uno::RuntimeException)) 328 { 329 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 330 331 return mnParagraphIndex; 332 } 333 334 void AccessibleEditableTextPara::Dispose() 335 { 336 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 337 338 int nClientId( getNotifierClientId() ); 339 340 // #108212# drop all references before notifying dispose 341 mxParent = NULL; 342 mnNotifierClientId = -1; 343 mpEditSource = NULL; 344 345 // notify listeners 346 if( nClientId != -1 ) 347 { 348 try 349 { 350 uno::Reference < XAccessibleContext > xThis = getAccessibleContext(); 351 352 // #106234# Delegate to EventNotifier 353 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, xThis ); 354 #ifdef DBG_UTIL 355 OSL_TRACE( "Disposed ID: %d\n", nClientId ); 356 #endif 357 } 358 catch( const uno::Exception& ) {} 359 } 360 } 361 362 void AccessibleEditableTextPara::SetEditSource( SvxEditSourceAdapter* pEditSource ) 363 { 364 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 365 366 mpEditSource = pEditSource; 367 368 WeakBullet::HardRefType aChild( maImageBullet.get() ); 369 if( aChild.is() ) 370 aChild->SetEditSource(pEditSource); 371 372 if( !mpEditSource ) 373 { 374 // going defunc 375 UnSetState( AccessibleStateType::SHOWING ); 376 UnSetState( AccessibleStateType::VISIBLE ); 377 SetState( AccessibleStateType::INVALID ); 378 SetState( AccessibleStateType::DEFUNC ); 379 380 Dispose(); 381 } 382 383 // #108900# Init last text content 384 try 385 { 386 TextChanged(); 387 } 388 catch( const uno::RuntimeException& ) {} 389 } 390 391 ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex ) 392 { 393 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 394 395 // check overflow 396 DBG_ASSERT(nStartEEIndex >= 0 && nStartEEIndex <= USHRT_MAX && 397 nEndEEIndex >= 0 && nEndEEIndex <= USHRT_MAX && 398 GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 399 "AccessibleEditableTextPara::MakeSelection: index value overflow"); 400 401 sal_uInt16 nParaIndex = static_cast< sal_uInt16 >( GetParagraphIndex() ); 402 return ESelection( nParaIndex, static_cast< sal_uInt16 >( nStartEEIndex ), 403 nParaIndex, static_cast< sal_uInt16 >( nEndEEIndex ) ); 404 } 405 406 ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nEEIndex ) 407 { 408 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 409 410 return MakeSelection( nEEIndex, nEEIndex+1 ); 411 } 412 413 ESelection AccessibleEditableTextPara::MakeCursor( sal_Int32 nEEIndex ) 414 { 415 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 416 417 return MakeSelection( nEEIndex, nEEIndex ); 418 } 419 420 void AccessibleEditableTextPara::CheckIndex( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)) 421 { 422 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 423 424 if( nIndex < 0 || nIndex >= getCharacterCount() ) 425 throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleEditableTextPara: character index out of bounds")), 426 uno::Reference< uno::XInterface > 427 ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy 428 } 429 430 void AccessibleEditableTextPara::CheckPosition( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)) 431 { 432 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 433 434 if( nIndex < 0 || nIndex > getCharacterCount() ) 435 throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleEditableTextPara: character position out of bounds")), 436 uno::Reference< uno::XInterface > 437 ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy 438 } 439 440 void AccessibleEditableTextPara::CheckRange( sal_Int32 nStart, sal_Int32 nEnd ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException)) 441 { 442 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 443 444 CheckPosition( nStart ); 445 CheckPosition( nEnd ); 446 } 447 448 sal_Bool AccessibleEditableTextPara::GetSelection( sal_uInt16& nStartPos, sal_uInt16& nEndPos ) SAL_THROW((uno::RuntimeException)) 449 { 450 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 451 452 ESelection aSelection; 453 sal_uInt16 nPara = static_cast< sal_uInt16 > ( GetParagraphIndex() ); 454 if( !GetEditViewForwarder().GetSelection( aSelection ) ) 455 return sal_False; 456 457 if( aSelection.nStartPara < aSelection.nEndPara ) 458 { 459 if( aSelection.nStartPara > nPara || 460 aSelection.nEndPara < nPara ) 461 return sal_False; 462 463 if( nPara == aSelection.nStartPara ) 464 nStartPos = aSelection.nStartPos; 465 else 466 nStartPos = 0; 467 468 if( nPara == aSelection.nEndPara ) 469 nEndPos = aSelection.nEndPos; 470 else 471 nEndPos = GetTextLen(); 472 } 473 else 474 { 475 if( aSelection.nStartPara < nPara || 476 aSelection.nEndPara > nPara ) 477 return sal_False; 478 479 if( nPara == aSelection.nStartPara ) 480 nStartPos = aSelection.nStartPos; 481 else 482 nStartPos = GetTextLen(); 483 484 if( nPara == aSelection.nEndPara ) 485 nEndPos = aSelection.nEndPos; 486 else 487 nEndPos = 0; 488 } 489 490 return sal_True; 491 } 492 493 String AccessibleEditableTextPara::GetText( sal_Int32 nIndex ) SAL_THROW((uno::RuntimeException)) 494 { 495 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 496 497 return GetTextForwarder().GetText( MakeSelection(nIndex) ); 498 } 499 500 String AccessibleEditableTextPara::GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) SAL_THROW((uno::RuntimeException)) 501 { 502 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 503 504 return GetTextForwarder().GetText( MakeSelection(nStartIndex, nEndIndex) ); 505 } 506 507 sal_uInt16 AccessibleEditableTextPara::GetTextLen() const SAL_THROW((uno::RuntimeException)) 508 { 509 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 510 511 return GetTextForwarder().GetTextLen( static_cast< sal_uInt16 >( GetParagraphIndex() ) ); 512 } 513 514 sal_Bool AccessibleEditableTextPara::IsVisible() const 515 { 516 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 517 518 return mpEditSource ? sal_True : sal_False ; 519 } 520 521 uno::Reference< XAccessibleText > AccessibleEditableTextPara::GetParaInterface( sal_Int32 nIndex ) 522 { 523 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 524 525 uno::Reference< XAccessible > xParent = getAccessibleParent(); 526 if( xParent.is() ) 527 { 528 uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext(); 529 if( xParentContext.is() ) 530 { 531 uno::Reference< XAccessible > xPara = xParentContext->getAccessibleChild( nIndex ); 532 if( xPara.is() ) 533 { 534 return uno::Reference< XAccessibleText > ( xPara, uno::UNO_QUERY ); 535 } 536 } 537 } 538 539 return uno::Reference< XAccessibleText >(); 540 } 541 542 SvxEditSourceAdapter& AccessibleEditableTextPara::GetEditSource() const SAL_THROW((uno::RuntimeException)) 543 { 544 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 545 546 if( mpEditSource ) 547 return *mpEditSource; 548 else 549 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No edit source, object is defunct")), 550 uno::Reference< uno::XInterface > 551 ( static_cast< ::cppu::OWeakObject* > 552 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 553 } 554 555 SvxAccessibleTextAdapter& AccessibleEditableTextPara::GetTextForwarder() const SAL_THROW((uno::RuntimeException)) 556 { 557 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 558 559 SvxEditSourceAdapter& rEditSource = GetEditSource(); 560 SvxAccessibleTextAdapter* pTextForwarder = rEditSource.GetTextForwarderAdapter(); 561 562 if( !pTextForwarder ) 563 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch text forwarder, object is defunct")), 564 uno::Reference< uno::XInterface > 565 ( static_cast< ::cppu::OWeakObject* > 566 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 567 568 if( pTextForwarder->IsValid() ) 569 return *pTextForwarder; 570 else 571 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text forwarder is invalid, object is defunct")), 572 uno::Reference< uno::XInterface > 573 ( static_cast< ::cppu::OWeakObject* > 574 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 575 } 576 577 SvxViewForwarder& AccessibleEditableTextPara::GetViewForwarder() const SAL_THROW((uno::RuntimeException)) 578 { 579 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 580 581 SvxEditSource& rEditSource = GetEditSource(); 582 SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder(); 583 584 if( !pViewForwarder ) 585 { 586 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch view forwarder, object is defunct")), 587 uno::Reference< uno::XInterface > 588 ( static_cast< ::cppu::OWeakObject* > 589 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 590 } 591 592 if( pViewForwarder->IsValid() ) 593 return *pViewForwarder; 594 else 595 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object is defunct")), 596 uno::Reference< uno::XInterface > 597 ( static_cast< ::cppu::OWeakObject* > 598 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 599 } 600 601 SvxAccessibleTextEditViewAdapter& AccessibleEditableTextPara::GetEditViewForwarder( sal_Bool bCreate ) const SAL_THROW((uno::RuntimeException)) 602 { 603 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 604 605 SvxEditSourceAdapter& rEditSource = GetEditSource(); 606 SvxAccessibleTextEditViewAdapter* pTextEditViewForwarder = rEditSource.GetEditViewForwarderAdapter( bCreate ); 607 608 if( !pTextEditViewForwarder ) 609 { 610 if( bCreate ) 611 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch view forwarder, object is defunct")), 612 uno::Reference< uno::XInterface > 613 ( static_cast< ::cppu::OWeakObject* > 614 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 615 else 616 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No view forwarder, object not in edit mode")), 617 uno::Reference< uno::XInterface > 618 ( static_cast< ::cppu::OWeakObject* > 619 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 620 } 621 622 if( pTextEditViewForwarder->IsValid() ) 623 return *pTextEditViewForwarder; 624 else 625 { 626 if( bCreate ) 627 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object is defunct")), 628 uno::Reference< uno::XInterface > 629 ( static_cast< ::cppu::OWeakObject* > 630 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 631 else 632 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object not in edit mode")), 633 uno::Reference< uno::XInterface > 634 ( static_cast< ::cppu::OWeakObject* > 635 ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy 636 } 637 } 638 639 sal_Bool AccessibleEditableTextPara::HaveEditView() const 640 { 641 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 642 643 SvxEditSource& rEditSource = GetEditSource(); 644 SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder(); 645 646 if( !pViewForwarder ) 647 return sal_False; 648 649 if( !pViewForwarder->IsValid() ) 650 return sal_False; 651 652 return sal_True; 653 } 654 655 sal_Bool AccessibleEditableTextPara::HaveChildren() 656 { 657 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 658 659 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 660 "AccessibleEditableTextPara::HaveChildren: paragraph index value overflow"); 661 662 return GetTextForwarder().HaveImageBullet( static_cast< sal_uInt16 >(GetParagraphIndex()) ); 663 } 664 665 sal_Bool AccessibleEditableTextPara::IsActive() const SAL_THROW((uno::RuntimeException)) 666 { 667 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 668 669 SvxEditSource& rEditSource = GetEditSource(); 670 SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder(); 671 672 if( !pViewForwarder ) 673 return sal_False; 674 675 if( pViewForwarder->IsValid() ) 676 return sal_False; 677 else 678 return sal_True; 679 } 680 681 Rectangle AccessibleEditableTextPara::LogicToPixel( const Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder& rForwarder ) 682 { 683 // convert to screen coordinates 684 return Rectangle( rForwarder.LogicToPixel( rRect.TopLeft(), rMapMode ), 685 rForwarder.LogicToPixel( rRect.BottomRight(), rMapMode ) ); 686 } 687 688 const Point& AccessibleEditableTextPara::GetEEOffset() const 689 { 690 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 691 692 return maEEOffset; 693 } 694 695 void AccessibleEditableTextPara::SetEEOffset( const Point& rOffset ) 696 { 697 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 698 699 WeakBullet::HardRefType aChild( maImageBullet.get() ); 700 if( aChild.is() ) 701 aChild->SetEEOffset(rOffset); 702 703 maEEOffset = rOffset; 704 } 705 706 void AccessibleEditableTextPara::FireEvent(const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue) const 707 { 708 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 709 710 uno::Reference < XAccessibleContext > xThis( const_cast< AccessibleEditableTextPara* > (this)->getAccessibleContext() ); 711 712 AccessibleEventObject aEvent(xThis, nEventId, rNewValue, rOldValue); 713 714 // #102261# Call global queue for focus events 715 if( nEventId == AccessibleEventId::STATE_CHANGED ) 716 vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent ); 717 718 // #106234# Delegate to EventNotifier 719 if( getNotifierClientId() != -1 ) 720 ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(), 721 aEvent ); 722 } 723 724 void AccessibleEditableTextPara::GotPropertyEvent( const uno::Any& rNewValue, const sal_Int16 nEventId ) const 725 { 726 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 727 728 FireEvent( nEventId, rNewValue ); 729 } 730 731 void AccessibleEditableTextPara::LostPropertyEvent( const uno::Any& rOldValue, const sal_Int16 nEventId ) const 732 { 733 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 734 735 FireEvent( nEventId, uno::Any(), rOldValue ); 736 } 737 738 bool AccessibleEditableTextPara::HasState( const sal_Int16 nStateId ) 739 { 740 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 741 742 ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get()); 743 if( pStateSet != NULL ) 744 return pStateSet->contains(nStateId) ? true : false; 745 746 return false; 747 } 748 749 void AccessibleEditableTextPara::SetState( const sal_Int16 nStateId ) 750 { 751 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 752 753 ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get()); 754 if( pStateSet != NULL && 755 !pStateSet->contains(nStateId) ) 756 { 757 pStateSet->AddState( nStateId ); 758 GotPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED ); 759 } 760 } 761 762 void AccessibleEditableTextPara::UnSetState( const sal_Int16 nStateId ) 763 { 764 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 765 766 ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get()); 767 if( pStateSet != NULL && 768 pStateSet->contains(nStateId) ) 769 { 770 pStateSet->RemoveState( nStateId ); 771 LostPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED ); 772 } 773 } 774 775 void AccessibleEditableTextPara::TextChanged() 776 { 777 ::rtl::OUString aCurrentString( OCommonAccessibleText::getText() ); 778 uno::Any aDeleted; 779 uno::Any aInserted; 780 if( OCommonAccessibleText::implInitTextChangedEvent( maLastTextString, aCurrentString, 781 aDeleted, aInserted) ) 782 { 783 FireEvent( AccessibleEventId::TEXT_CHANGED, aInserted, aDeleted ); 784 maLastTextString = aCurrentString; 785 } 786 } 787 788 sal_Bool AccessibleEditableTextPara::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_Int32 nIndex ) 789 { 790 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 791 792 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX, 793 "AccessibleEditableTextPara::GetAttributeRun: index value overflow"); 794 795 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 796 "AccessibleEditableTextPara::getLocale: paragraph index value overflow"); 797 798 return GetTextForwarder().GetAttributeRun( nStartIndex, 799 nEndIndex, 800 static_cast< sal_uInt16 >(GetParagraphIndex()), 801 static_cast< sal_uInt16 >(nIndex) ); 802 } 803 804 uno::Any SAL_CALL AccessibleEditableTextPara::queryInterface (const uno::Type & rType) throw (uno::RuntimeException) 805 { 806 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 807 808 uno::Any aRet; 809 810 // must provide XAccesibleText by hand, since it comes publicly inherited by XAccessibleEditableText 811 if ( rType == ::getCppuType((uno::Reference< XAccessibleText > *)0) ) 812 { 813 uno::Reference< XAccessibleText > aAccText = static_cast< XAccessibleEditableText * >(this); 814 aRet <<= aAccText; 815 } 816 else if ( rType == ::getCppuType((uno::Reference< XAccessibleEditableText > *)0) ) 817 { 818 uno::Reference< XAccessibleEditableText > aAccEditText = this; 819 aRet <<= aAccEditText; 820 } 821 else if ( rType == ::getCppuType((uno::Reference< XAccessibleHypertext > *)0) ) 822 { 823 uno::Reference< XAccessibleHypertext > aAccHyperText = this; 824 aRet <<= aAccHyperText; 825 } 826 else 827 { 828 aRet = AccessibleTextParaInterfaceBase::queryInterface(rType); 829 } 830 831 return aRet; 832 } 833 834 // XAccessible 835 uno::Reference< XAccessibleContext > SAL_CALL AccessibleEditableTextPara::getAccessibleContext() throw (uno::RuntimeException) 836 { 837 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 838 839 // We implement the XAccessibleContext interface in the same object 840 return uno::Reference< XAccessibleContext > ( this ); 841 } 842 843 // XAccessibleContext 844 sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleChildCount() throw (uno::RuntimeException) 845 { 846 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 847 848 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 849 850 return HaveChildren() ? 1 : 0; 851 } 852 853 uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 854 { 855 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 856 857 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 858 859 if( !HaveChildren() ) 860 throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No childs available")), 861 uno::Reference< uno::XInterface > 862 ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy 863 864 if( i != 0 ) 865 throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid child index")), 866 uno::Reference< uno::XInterface > 867 ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy 868 869 WeakBullet::HardRefType aChild( maImageBullet.get() ); 870 871 if( !aChild.is() ) 872 { 873 // there is no hard reference available, create object then 874 AccessibleImageBullet* pChild = new AccessibleImageBullet( uno::Reference< XAccessible >( this ) ); 875 uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY ); 876 877 if( !xChild.is() ) 878 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Child creation failed")), 879 uno::Reference< uno::XInterface > 880 ( static_cast< ::cppu::OWeakObject* > (this) ) ); 881 882 aChild = WeakBullet::HardRefType( xChild, pChild ); 883 884 aChild->SetEditSource( &GetEditSource() ); 885 aChild->SetParagraphIndex( GetParagraphIndex() ); 886 aChild->SetIndexInParent( i ); 887 888 maImageBullet = aChild; 889 } 890 891 return aChild.getRef(); 892 } 893 894 uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleParent() throw (uno::RuntimeException) 895 { 896 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 897 898 #ifdef DBG_UTIL 899 if( !mxParent.is() ) 900 DBG_TRACE( "AccessibleEditableTextPara::getAccessibleParent: no frontend set, did somebody forgot to call AccessibleTextHelper::SetEventSource()?"); 901 #endif 902 903 return mxParent; 904 } 905 906 sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleIndexInParent() throw (uno::RuntimeException) 907 { 908 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 909 910 return mnIndexInParent; 911 } 912 913 sal_Int16 SAL_CALL AccessibleEditableTextPara::getAccessibleRole() throw (uno::RuntimeException) 914 { 915 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 916 917 return AccessibleRole::PARAGRAPH; 918 } 919 920 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getAccessibleDescription() throw (uno::RuntimeException) 921 { 922 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 923 924 // ::vos::OGuard aGuard( Application::GetSolarMutex() ); 925 926 return ::rtl::OUString(); 927 } 928 929 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getAccessibleName() throw (uno::RuntimeException) 930 { 931 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 932 933 // ::vos::OGuard aGuard( Application::GetSolarMutex() ); 934 935 return ::rtl::OUString(); 936 } 937 938 uno::Reference< XAccessibleRelationSet > SAL_CALL AccessibleEditableTextPara::getAccessibleRelationSet() throw (uno::RuntimeException) 939 { 940 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 941 942 // --> OD 2006-01-11 #i27138# - provide relations CONTENT_FLOWS_FROM 943 // and CONTENT_FLOWS_TO 944 if ( mpParaManager ) 945 { 946 utl::AccessibleRelationSetHelper* pAccRelSetHelper = 947 new utl::AccessibleRelationSetHelper(); 948 sal_Int32 nMyParaIndex( GetParagraphIndex() ); 949 // relation CONTENT_FLOWS_FROM 950 if ( nMyParaIndex > 0 && 951 mpParaManager->IsReferencable( nMyParaIndex - 1 ) ) 952 { 953 uno::Sequence<uno::Reference<XInterface> > aSequence(1); 954 aSequence[0] = 955 mpParaManager->GetChild( nMyParaIndex - 1 ).first.get().getRef(); 956 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_FROM, 957 aSequence ); 958 pAccRelSetHelper->AddRelation( aAccRel ); 959 } 960 961 // relation CONTENT_FLOWS_TO 962 if ( (nMyParaIndex + 1) < (sal_Int32)mpParaManager->GetNum() && 963 mpParaManager->IsReferencable( nMyParaIndex + 1 ) ) 964 { 965 uno::Sequence<uno::Reference<XInterface> > aSequence(1); 966 aSequence[0] = 967 mpParaManager->GetChild( nMyParaIndex + 1 ).first.get().getRef(); 968 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_TO, 969 aSequence ); 970 pAccRelSetHelper->AddRelation( aAccRel ); 971 } 972 973 return pAccRelSetHelper; 974 } 975 else 976 { 977 // no relations, therefore empty 978 return uno::Reference< XAccessibleRelationSet >(); 979 } 980 // <-- 981 } 982 983 uno::Reference< XAccessibleStateSet > SAL_CALL AccessibleEditableTextPara::getAccessibleStateSet() throw (uno::RuntimeException) 984 { 985 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 986 987 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 988 989 // Create a copy of the state set and return it. 990 ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get()); 991 992 if( !pStateSet ) 993 return uno::Reference<XAccessibleStateSet>(); 994 995 return uno::Reference<XAccessibleStateSet>( new ::utl::AccessibleStateSetHelper (*pStateSet) ); 996 } 997 998 lang::Locale SAL_CALL AccessibleEditableTextPara::getLocale() throw (IllegalAccessibleComponentStateException, uno::RuntimeException) 999 { 1000 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1001 1002 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1003 1004 return implGetLocale(); 1005 } 1006 1007 void SAL_CALL AccessibleEditableTextPara::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException) 1008 { 1009 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1010 1011 if( getNotifierClientId() != -1 ) 1012 ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener ); 1013 } 1014 1015 void SAL_CALL AccessibleEditableTextPara::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException) 1016 { 1017 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1018 1019 if( getNotifierClientId() != -1 ) 1020 ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener ); 1021 } 1022 1023 // XAccessibleComponent 1024 sal_Bool SAL_CALL AccessibleEditableTextPara::containsPoint( const awt::Point& aTmpPoint ) throw (uno::RuntimeException) 1025 { 1026 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1027 1028 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1029 1030 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1031 "AccessibleEditableTextPara::contains: index value overflow"); 1032 1033 awt::Rectangle aTmpRect = getBounds(); 1034 Rectangle aRect( Point(aTmpRect.X, aTmpRect.Y), Size(aTmpRect.Width, aTmpRect.Height) ); 1035 Point aPoint( aTmpPoint.X, aTmpPoint.Y ); 1036 1037 return aRect.IsInside( aPoint ); 1038 } 1039 1040 uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (uno::RuntimeException) 1041 { 1042 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1043 1044 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1045 1046 if( HaveChildren() ) 1047 { 1048 // #103862# No longer need to make given position relative 1049 Point aPoint( _aPoint.X, _aPoint.Y ); 1050 1051 // respect EditEngine offset to surrounding shape/cell 1052 aPoint -= GetEEOffset(); 1053 1054 // convert to EditEngine coordinate system 1055 SvxTextForwarder& rCacheTF = GetTextForwarder(); 1056 Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) ); 1057 1058 EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( static_cast< sal_uInt16 > (GetParagraphIndex()) ); 1059 1060 if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && 1061 aBulletInfo.bVisible && 1062 aBulletInfo.nType == SVX_NUM_BITMAP ) 1063 { 1064 Rectangle aRect = aBulletInfo.aBounds; 1065 1066 if( aRect.IsInside( aLogPoint ) ) 1067 return getAccessibleChild(0); 1068 } 1069 } 1070 1071 // no children at all, or none at given position 1072 return uno::Reference< XAccessible >(); 1073 } 1074 1075 awt::Rectangle SAL_CALL AccessibleEditableTextPara::getBounds() throw (uno::RuntimeException) 1076 { 1077 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1078 1079 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1080 1081 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1082 "AccessibleEditableTextPara::getBounds: index value overflow"); 1083 1084 SvxTextForwarder& rCacheTF = GetTextForwarder(); 1085 Rectangle aRect = rCacheTF.GetParaBounds( static_cast< sal_uInt16 >( GetParagraphIndex() ) ); 1086 1087 // convert to screen coordinates 1088 Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect, 1089 rCacheTF.GetMapMode(), 1090 GetViewForwarder() ); 1091 1092 // offset from shape/cell 1093 Point aOffset = GetEEOffset(); 1094 1095 return awt::Rectangle( aScreenRect.Left() + aOffset.X(), 1096 aScreenRect.Top() + aOffset.Y(), 1097 aScreenRect.GetSize().Width(), 1098 aScreenRect.GetSize().Height() ); 1099 } 1100 1101 awt::Point SAL_CALL AccessibleEditableTextPara::getLocation( ) throw (uno::RuntimeException) 1102 { 1103 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1104 1105 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1106 1107 awt::Rectangle aRect = getBounds(); 1108 1109 return awt::Point( aRect.X, aRect.Y ); 1110 } 1111 1112 awt::Point SAL_CALL AccessibleEditableTextPara::getLocationOnScreen( ) throw (uno::RuntimeException) 1113 { 1114 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1115 1116 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1117 1118 // relate us to parent 1119 uno::Reference< XAccessible > xParent = getAccessibleParent(); 1120 if( xParent.is() ) 1121 { 1122 uno::Reference< XAccessibleComponent > xParentComponent( xParent, uno::UNO_QUERY ); 1123 if( xParentComponent.is() ) 1124 { 1125 awt::Point aRefPoint = xParentComponent->getLocationOnScreen(); 1126 awt::Point aPoint = getLocation(); 1127 aPoint.X += aRefPoint.X; 1128 aPoint.Y += aRefPoint.Y; 1129 1130 return aPoint; 1131 } 1132 // --> OD 2009-12-16 #i88070# 1133 // fallback to parent's <XAccessibleContext> instance 1134 else 1135 { 1136 uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext(); 1137 if ( xParentContext.is() ) 1138 { 1139 uno::Reference< XAccessibleComponent > xParentContextComponent( xParentContext, uno::UNO_QUERY ); 1140 if( xParentContextComponent.is() ) 1141 { 1142 awt::Point aRefPoint = xParentContextComponent->getLocationOnScreen(); 1143 awt::Point aPoint = getLocation(); 1144 aPoint.X += aRefPoint.X; 1145 aPoint.Y += aRefPoint.Y; 1146 1147 return aPoint; 1148 } 1149 } 1150 } 1151 // <-- 1152 } 1153 1154 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot access parent")), 1155 uno::Reference< uno::XInterface > 1156 ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy 1157 } 1158 1159 awt::Size SAL_CALL AccessibleEditableTextPara::getSize( ) throw (uno::RuntimeException) 1160 { 1161 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1162 1163 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1164 1165 awt::Rectangle aRect = getBounds(); 1166 1167 return awt::Size( aRect.Width, aRect.Height ); 1168 } 1169 1170 void SAL_CALL AccessibleEditableTextPara::grabFocus( ) throw (uno::RuntimeException) 1171 { 1172 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1173 1174 // set cursor to this paragraph 1175 setSelection(0,0); 1176 } 1177 1178 sal_Int32 SAL_CALL AccessibleEditableTextPara::getForeground( ) throw (::com::sun::star::uno::RuntimeException) 1179 { 1180 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1181 1182 // #104444# Added to XAccessibleComponent interface 1183 svtools::ColorConfig aColorConfig; 1184 sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor; 1185 return static_cast<sal_Int32>(nColor); 1186 } 1187 1188 sal_Int32 SAL_CALL AccessibleEditableTextPara::getBackground( ) throw (::com::sun::star::uno::RuntimeException) 1189 { 1190 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1191 1192 // #104444# Added to XAccessibleComponent interface 1193 Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor() ); 1194 1195 // the background is transparent 1196 aColor.SetTransparency( 0xFF); 1197 1198 return static_cast<sal_Int32>( aColor.GetColor() ); 1199 } 1200 1201 // XAccessibleText 1202 sal_Int32 SAL_CALL AccessibleEditableTextPara::getCaretPosition() throw (uno::RuntimeException) 1203 { 1204 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1205 1206 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1207 1208 if( !HaveEditView() ) 1209 return -1; 1210 1211 ESelection aSelection; 1212 if( GetEditViewForwarder().GetSelection( aSelection ) && 1213 GetParagraphIndex() == aSelection.nEndPara ) 1214 { 1215 // caret is always nEndPara,nEndPos 1216 return aSelection.nEndPos; 1217 } 1218 1219 // not within this paragraph 1220 return -1; 1221 } 1222 1223 sal_Bool SAL_CALL AccessibleEditableTextPara::setCaretPosition( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1224 { 1225 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1226 1227 return setSelection(nIndex, nIndex); 1228 } 1229 1230 sal_Unicode SAL_CALL AccessibleEditableTextPara::getCharacter( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1231 { 1232 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1233 1234 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1235 1236 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1237 "AccessibleEditableTextPara::getCharacter: index value overflow"); 1238 1239 return OCommonAccessibleText::getCharacter( nIndex ); 1240 } 1241 1242 uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rRequestedAttributes ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1243 { 1244 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1245 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1246 1247 CheckIndex(nIndex); // may throw IndexOutOfBoundsException 1248 1249 // get default attribues... 1250 ::comphelper::SequenceAsHashMap aPropHashMap( getDefaultAttributes( rRequestedAttributes ) ); 1251 1252 // ... and override them with the direct attributes from the specific position 1253 uno::Sequence< beans::PropertyValue > aRunAttribs( getRunAttributes( nIndex, rRequestedAttributes ) ); 1254 sal_Int32 nRunAttribs = aRunAttribs.getLength(); 1255 const beans::PropertyValue *pRunAttrib = aRunAttribs.getConstArray(); 1256 for (sal_Int32 k = 0; k < nRunAttribs; ++k) 1257 { 1258 const beans::PropertyValue &rRunAttrib = pRunAttrib[k]; 1259 aPropHashMap[ rRunAttrib.Name ] = rRunAttrib.Value; //!! should not only be the value !! 1260 } 1261 #ifdef TL_DEBUG 1262 { 1263 uno::Sequence< rtl::OUString > aNames(1); 1264 aNames.getArray()[0] = rtl::OUString::createFromAscii("CharHeight"); 1265 const rtl::OUString *pNames = aNames.getConstArray(); 1266 const uno::Sequence< beans::PropertyValue > aAttribs( getRunAttributes( nIndex, aNames ) ); 1267 const beans::PropertyValue *pAttribs = aAttribs.getConstArray(); 1268 double d1 = -1.0; 1269 float f1 = -1.0; 1270 if (aAttribs.getLength()) 1271 { 1272 uno::Any aAny( pAttribs[0].Value ); 1273 aAny >>= d1; 1274 aAny >>= f1; 1275 } 1276 int i = 3; 1277 } 1278 #endif 1279 1280 // get resulting sequence 1281 uno::Sequence< beans::PropertyValue > aRes; 1282 aPropHashMap >> aRes; 1283 1284 // since SequenceAsHashMap ignores property handles and property state 1285 // we have to restore the property state here (property handles are 1286 // of no use to the accessibility API). 1287 sal_Int32 nRes = aRes.getLength(); 1288 beans::PropertyValue *pRes = aRes.getArray(); 1289 for (sal_Int32 i = 0; i < nRes; ++i) 1290 { 1291 beans::PropertyValue &rRes = pRes[i]; 1292 sal_Bool bIsDirectVal = sal_False; 1293 for (sal_Int32 k = 0; k < nRunAttribs && !bIsDirectVal; ++k) 1294 { 1295 if (rRes.Name == pRunAttrib[k].Name) 1296 bIsDirectVal = sal_True; 1297 } 1298 rRes.Handle = -1; 1299 rRes.State = bIsDirectVal ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE; 1300 } 1301 1302 return aRes; 1303 } 1304 1305 awt::Rectangle SAL_CALL AccessibleEditableTextPara::getCharacterBounds( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1306 { 1307 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1308 1309 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1310 1311 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1312 "AccessibleEditableTextPara::getCharacterBounds: index value overflow"); 1313 1314 // #108900# Have position semantics now for nIndex, as 1315 // one-past-the-end values are legal, too. 1316 CheckPosition( nIndex ); 1317 1318 SvxTextForwarder& rCacheTF = GetTextForwarder(); 1319 Rectangle aRect = rCacheTF.GetCharBounds( static_cast< sal_uInt16 >( GetParagraphIndex() ), static_cast< sal_uInt16 >( nIndex ) ); 1320 1321 // convert to screen 1322 Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect, 1323 rCacheTF.GetMapMode(), 1324 GetViewForwarder() ); 1325 // #109864# offset from parent (paragraph), but in screen 1326 // coordinates. This makes sure the internal text offset in 1327 // the outline view forwarder gets cancelled out here 1328 awt::Rectangle aParaRect( getBounds() ); 1329 aScreenRect.Move( -aParaRect.X, -aParaRect.Y ); 1330 1331 // offset from shape/cell 1332 Point aOffset = GetEEOffset(); 1333 1334 return awt::Rectangle( aScreenRect.Left() + aOffset.X(), 1335 aScreenRect.Top() + aOffset.Y(), 1336 aScreenRect.GetSize().Width(), 1337 aScreenRect.GetSize().Height() ); 1338 } 1339 1340 sal_Int32 SAL_CALL AccessibleEditableTextPara::getCharacterCount() throw (uno::RuntimeException) 1341 { 1342 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1343 1344 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1345 1346 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1347 "AccessibleEditableTextPara::getCharacterCount: index value overflow"); 1348 1349 return OCommonAccessibleText::getCharacterCount(); 1350 } 1351 1352 sal_Int32 SAL_CALL AccessibleEditableTextPara::getIndexAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException) 1353 { 1354 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1355 1356 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1357 1358 sal_uInt16 nPara, nIndex; 1359 1360 // offset from surrounding cell/shape 1361 Point aOffset( GetEEOffset() ); 1362 Point aPoint( rPoint.X - aOffset.X(), rPoint.Y - aOffset.Y() ); 1363 1364 // convert to logical coordinates 1365 SvxTextForwarder& rCacheTF = GetTextForwarder(); 1366 Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) ); 1367 1368 // re-offset to parent (paragraph) 1369 Rectangle aParaRect = rCacheTF.GetParaBounds( static_cast< sal_uInt16 >( GetParagraphIndex() ) ); 1370 aLogPoint.Move( aParaRect.Left(), aParaRect.Top() ); 1371 1372 if( rCacheTF.GetIndexAtPoint( aLogPoint, nPara, nIndex ) && 1373 GetParagraphIndex() == nPara ) 1374 { 1375 // #102259# Double-check if we're _really_ on the given character 1376 try 1377 { 1378 awt::Rectangle aRect1( getCharacterBounds(nIndex) ); 1379 Rectangle aRect2( aRect1.X, aRect1.Y, 1380 aRect1.Width + aRect1.X, aRect1.Height + aRect1.Y ); 1381 if( aRect2.IsInside( Point( rPoint.X, rPoint.Y ) ) ) 1382 return nIndex; 1383 else 1384 return -1; 1385 } 1386 catch( const lang::IndexOutOfBoundsException& ) 1387 { 1388 // #103927# Don't throw for invalid nIndex values 1389 return -1; 1390 } 1391 } 1392 else 1393 { 1394 // not within our paragraph 1395 return -1; 1396 } 1397 } 1398 1399 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getSelectedText() throw (uno::RuntimeException) 1400 { 1401 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1402 1403 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1404 1405 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1406 "AccessibleEditableTextPara::getSelectedText: index value overflow"); 1407 1408 if( !HaveEditView() ) 1409 return ::rtl::OUString(); 1410 1411 return OCommonAccessibleText::getSelectedText(); 1412 } 1413 1414 sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionStart() throw (uno::RuntimeException) 1415 { 1416 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1417 1418 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1419 1420 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1421 "AccessibleEditableTextPara::getSelectionStart: index value overflow"); 1422 1423 if( !HaveEditView() ) 1424 return -1; 1425 1426 return OCommonAccessibleText::getSelectionStart(); 1427 } 1428 1429 sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionEnd() throw (uno::RuntimeException) 1430 { 1431 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1432 1433 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1434 1435 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1436 "AccessibleEditableTextPara::getSelectionEnd: index value overflow"); 1437 1438 if( !HaveEditView() ) 1439 return -1; 1440 1441 return OCommonAccessibleText::getSelectionEnd(); 1442 } 1443 1444 sal_Bool SAL_CALL AccessibleEditableTextPara::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1445 { 1446 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1447 1448 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1449 1450 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1451 "AccessibleEditableTextPara::setSelection: paragraph index value overflow"); 1452 1453 CheckRange(nStartIndex, nEndIndex); 1454 1455 try 1456 { 1457 SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True ); 1458 return rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) ); 1459 } 1460 catch( const uno::RuntimeException& ) 1461 { 1462 return sal_False; 1463 } 1464 } 1465 1466 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getText() throw (uno::RuntimeException) 1467 { 1468 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1469 1470 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1471 1472 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1473 "AccessibleEditableTextPara::getText: paragraph index value overflow"); 1474 1475 return OCommonAccessibleText::getText(); 1476 } 1477 1478 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1479 { 1480 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1481 1482 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1483 1484 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1485 "AccessibleEditableTextPara::getTextRange: paragraph index value overflow"); 1486 1487 return OCommonAccessibleText::getTextRange(nStartIndex, nEndIndex); 1488 } 1489 1490 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1491 { 1492 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1493 1494 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1495 1496 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1497 "AccessibleEditableTextPara::getTextAtIndex: paragraph index value overflow"); 1498 1499 ::com::sun::star::accessibility::TextSegment aResult; 1500 aResult.SegmentStart = -1; 1501 aResult.SegmentEnd = -1; 1502 1503 switch( aTextType ) 1504 { 1505 // Not yet handled by OCommonAccessibleText. Missing 1506 // implGetAttributeRunBoundary() method there 1507 case AccessibleTextType::ATTRIBUTE_RUN: 1508 { 1509 const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( static_cast< sal_uInt16 >( GetParagraphIndex() ) ); 1510 1511 if( nIndex == nTextLen ) 1512 { 1513 // #i17014# Special-casing one-behind-the-end character 1514 aResult.SegmentStart = aResult.SegmentEnd = nTextLen; 1515 } 1516 else 1517 { 1518 sal_uInt16 nStartIndex, nEndIndex; 1519 1520 if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) ) 1521 { 1522 aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex); 1523 aResult.SegmentStart = nStartIndex; 1524 aResult.SegmentEnd = nEndIndex; 1525 } 1526 } 1527 break; 1528 } 1529 1530 default: 1531 aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType ); 1532 break; 1533 } /* end of switch( aTextType ) */ 1534 1535 return aResult; 1536 } 1537 1538 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1539 { 1540 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1541 1542 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1543 1544 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1545 "AccessibleEditableTextPara::getTextBeforeIndex: paragraph index value overflow"); 1546 1547 ::com::sun::star::accessibility::TextSegment aResult; 1548 aResult.SegmentStart = -1; 1549 aResult.SegmentEnd = -1; 1550 1551 switch( aTextType ) 1552 { 1553 // Not yet handled by OCommonAccessibleText. Missing 1554 // implGetAttributeRunBoundary() method there 1555 case AccessibleTextType::ATTRIBUTE_RUN: 1556 { 1557 const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( static_cast< sal_uInt16 >( GetParagraphIndex() ) ); 1558 sal_uInt16 nStartIndex, nEndIndex; 1559 1560 if( nIndex == nTextLen ) 1561 { 1562 // #i17014# Special-casing one-behind-the-end character 1563 if( nIndex > 0 && 1564 GetAttributeRun(nStartIndex, nEndIndex, nIndex-1) ) 1565 { 1566 aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex); 1567 aResult.SegmentStart = nStartIndex; 1568 aResult.SegmentEnd = nEndIndex; 1569 } 1570 } 1571 else 1572 { 1573 if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) ) 1574 { 1575 // already at the left border? If not, query 1576 // one index further left 1577 if( nStartIndex > 0 && 1578 GetAttributeRun(nStartIndex, nEndIndex, nStartIndex-1) ) 1579 { 1580 aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex); 1581 aResult.SegmentStart = nStartIndex; 1582 aResult.SegmentEnd = nEndIndex; 1583 } 1584 } 1585 } 1586 break; 1587 } 1588 1589 default: 1590 aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType ); 1591 break; 1592 } /* end of switch( aTextType ) */ 1593 1594 return aResult; 1595 } 1596 1597 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1598 { 1599 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1600 1601 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1602 1603 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1604 "AccessibleEditableTextPara::getTextBehindIndex: paragraph index value overflow"); 1605 1606 ::com::sun::star::accessibility::TextSegment aResult; 1607 aResult.SegmentStart = -1; 1608 aResult.SegmentEnd = -1; 1609 1610 switch( aTextType ) 1611 { 1612 case AccessibleTextType::ATTRIBUTE_RUN: 1613 { 1614 sal_uInt16 nStartIndex, nEndIndex; 1615 1616 if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) ) 1617 { 1618 // already at the right border? 1619 if( nEndIndex < GetTextLen() ) 1620 { 1621 if( GetAttributeRun(nStartIndex, nEndIndex, nEndIndex) ) 1622 { 1623 aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex); 1624 aResult.SegmentStart = nStartIndex; 1625 aResult.SegmentEnd = nEndIndex; 1626 } 1627 } 1628 } 1629 break; 1630 } 1631 1632 default: 1633 aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType ); 1634 break; 1635 } /* end of switch( aTextType ) */ 1636 1637 return aResult; 1638 } 1639 1640 sal_Bool SAL_CALL AccessibleEditableTextPara::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1641 { 1642 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1643 1644 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1645 1646 try 1647 { 1648 SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True ); 1649 #if OSL_DEBUG_LEVEL > 0 1650 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1651 (void)rCacheTF; 1652 #else 1653 GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1654 #endif 1655 1656 sal_Bool aRetVal; 1657 1658 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1659 "AccessibleEditableTextPara::copyText: index value overflow"); 1660 1661 CheckRange(nStartIndex, nEndIndex); 1662 1663 // save current selection 1664 ESelection aOldSelection; 1665 1666 rCacheVF.GetSelection( aOldSelection ); 1667 rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) ); 1668 aRetVal = rCacheVF.Copy(); 1669 rCacheVF.SetSelection( aOldSelection ); // restore 1670 1671 return aRetVal; 1672 } 1673 catch( const uno::RuntimeException& ) 1674 { 1675 return sal_False; 1676 } 1677 } 1678 1679 // XAccessibleEditableText 1680 sal_Bool SAL_CALL AccessibleEditableTextPara::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1681 { 1682 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1683 1684 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1685 1686 try 1687 { 1688 SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True ); 1689 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1690 1691 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1692 "AccessibleEditableTextPara::cutText: index value overflow"); 1693 1694 CheckRange(nStartIndex, nEndIndex); 1695 1696 if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) ) 1697 return sal_False; // non-editable area selected 1698 1699 // don't save selection, might become invalid after cut! 1700 rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) ); 1701 1702 return rCacheVF.Cut(); 1703 } 1704 catch( const uno::RuntimeException& ) 1705 { 1706 return sal_False; 1707 } 1708 } 1709 1710 sal_Bool SAL_CALL AccessibleEditableTextPara::pasteText( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1711 { 1712 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1713 1714 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1715 1716 try 1717 { 1718 SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True ); 1719 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1720 1721 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1722 "AccessibleEditableTextPara::pasteText: index value overflow"); 1723 1724 CheckPosition(nIndex); 1725 1726 if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) ) 1727 return sal_False; // non-editable area selected 1728 1729 // #104400# set empty selection (=> cursor) to given index 1730 rCacheVF.SetSelection( MakeCursor(nIndex) ); 1731 1732 return rCacheVF.Paste(); 1733 } 1734 catch( const uno::RuntimeException& ) 1735 { 1736 return sal_False; 1737 } 1738 } 1739 1740 sal_Bool SAL_CALL AccessibleEditableTextPara::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1741 { 1742 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1743 1744 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1745 1746 try 1747 { 1748 // #102710# Request edit view when doing changes 1749 // AccessibleEmptyEditSource relies on this behaviour 1750 GetEditViewForwarder( sal_True ); 1751 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1752 1753 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1754 "AccessibleEditableTextPara::deleteText: index value overflow"); 1755 1756 CheckRange(nStartIndex, nEndIndex); 1757 1758 if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) ) 1759 return sal_False; // non-editable area selected 1760 1761 sal_Bool bRet = rCacheTF.Delete( MakeSelection(nStartIndex, nEndIndex) ); 1762 1763 GetEditSource().UpdateData(); 1764 1765 return bRet; 1766 } 1767 catch( const uno::RuntimeException& ) 1768 { 1769 return sal_False; 1770 } 1771 } 1772 1773 sal_Bool SAL_CALL AccessibleEditableTextPara::insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1774 { 1775 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1776 1777 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1778 1779 try 1780 { 1781 // #102710# Request edit view when doing changes 1782 // AccessibleEmptyEditSource relies on this behaviour 1783 GetEditViewForwarder( sal_True ); 1784 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1785 1786 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1787 "AccessibleEditableTextPara::insertText: index value overflow"); 1788 1789 CheckPosition(nIndex); 1790 1791 if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) ) 1792 return sal_False; // non-editable area selected 1793 1794 // #104400# insert given text at empty selection (=> cursor) 1795 sal_Bool bRet = rCacheTF.InsertText( sText, MakeCursor(nIndex) ); 1796 1797 rCacheTF.QuickFormatDoc(); 1798 GetEditSource().UpdateData(); 1799 1800 return bRet; 1801 } 1802 catch( const uno::RuntimeException& ) 1803 { 1804 return sal_False; 1805 } 1806 } 1807 1808 sal_Bool SAL_CALL AccessibleEditableTextPara::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::rtl::OUString& sReplacement ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1809 { 1810 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1811 1812 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1813 1814 try 1815 { 1816 // #102710# Request edit view when doing changes 1817 // AccessibleEmptyEditSource relies on this behaviour 1818 GetEditViewForwarder( sal_True ); 1819 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1820 1821 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1822 "AccessibleEditableTextPara::replaceText: index value overflow"); 1823 1824 CheckRange(nStartIndex, nEndIndex); 1825 1826 if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) ) 1827 return sal_False; // non-editable area selected 1828 1829 // insert given text into given range => replace 1830 sal_Bool bRet = rCacheTF.InsertText( sReplacement, MakeSelection(nStartIndex, nEndIndex) ); 1831 1832 rCacheTF.QuickFormatDoc(); 1833 GetEditSource().UpdateData(); 1834 1835 return bRet; 1836 } 1837 catch( const uno::RuntimeException& ) 1838 { 1839 return sal_False; 1840 } 1841 } 1842 1843 sal_Bool SAL_CALL AccessibleEditableTextPara::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const uno::Sequence< beans::PropertyValue >& aAttributeSet ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1844 { 1845 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1846 1847 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1848 1849 try 1850 { 1851 // #102710# Request edit view when doing changes 1852 // AccessibleEmptyEditSource relies on this behaviour 1853 GetEditViewForwarder( sal_True ); 1854 SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs 1855 sal_uInt16 nPara = static_cast< sal_uInt16 >( GetParagraphIndex() ); 1856 1857 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1858 "AccessibleEditableTextPara::setAttributes: index value overflow"); 1859 1860 CheckRange(nStartIndex, nEndIndex); 1861 1862 if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) ) 1863 return sal_False; // non-editable area selected 1864 1865 // do the indices span the whole paragraph? Then use the outliner map 1866 // TODO: hold it as a member? 1867 SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), 1868 0 == nStartIndex && 1869 rCacheTF.GetTextLen(nPara) == nEndIndex ? 1870 ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() : 1871 ImplGetSvxTextPortionSvxPropertySet() ); 1872 1873 aPropSet.SetSelection( MakeSelection(nStartIndex, nEndIndex) ); 1874 1875 // convert from PropertyValue to Any 1876 sal_Int32 i, nLength( aAttributeSet.getLength() ); 1877 const beans::PropertyValue* pPropArray = aAttributeSet.getConstArray(); 1878 for(i=0; i<nLength; ++i) 1879 { 1880 try 1881 { 1882 aPropSet.setPropertyValue(pPropArray->Name, pPropArray->Value); 1883 } 1884 catch( const uno::Exception& ) 1885 { 1886 DBG_ERROR("AccessibleEditableTextPara::setAttributes exception in setPropertyValue"); 1887 } 1888 1889 ++pPropArray; 1890 } 1891 1892 rCacheTF.QuickFormatDoc(); 1893 GetEditSource().UpdateData(); 1894 1895 return sal_True; 1896 } 1897 catch( const uno::RuntimeException& ) 1898 { 1899 return sal_False; 1900 } 1901 } 1902 1903 sal_Bool SAL_CALL AccessibleEditableTextPara::setText( const ::rtl::OUString& sText ) throw (uno::RuntimeException) 1904 { 1905 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1906 1907 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1908 1909 return replaceText(0, getCharacterCount(), sText); 1910 } 1911 1912 // XAccessibleTextAttributes 1913 uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getDefaultAttributes( 1914 const uno::Sequence< ::rtl::OUString >& rRequestedAttributes ) 1915 throw (uno::RuntimeException) 1916 { 1917 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 1918 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 1919 1920 #if OSL_DEBUG_LEVEL > 0 1921 SvxAccessibleTextAdapter& rCacheTF = 1922 #endif 1923 GetTextForwarder(); 1924 1925 #if OSL_DEBUG_LEVEL > 0 1926 (void)rCacheTF; 1927 #endif 1928 1929 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 1930 "AccessibleEditableTextPara::getCharacterAttributes: index value overflow"); 1931 1932 // get XPropertySetInfo for paragraph attributes and 1933 // character attributes that span all the paragraphs text. 1934 SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), 1935 ImplGetSvxCharAndParaPropertiesSet() ); 1936 aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) ); 1937 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo(); 1938 if (!xPropSetInfo.is()) 1939 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot query XPropertySetInfo")), 1940 uno::Reference< uno::XInterface > 1941 ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy 1942 1943 // build sequence of available properties to check 1944 sal_Int32 nLenReqAttr = rRequestedAttributes.getLength(); 1945 uno::Sequence< beans::Property > aProperties; 1946 if (nLenReqAttr) 1947 { 1948 const rtl::OUString *pRequestedAttributes = rRequestedAttributes.getConstArray(); 1949 1950 aProperties.realloc( nLenReqAttr ); 1951 beans::Property *pProperties = aProperties.getArray(); 1952 sal_Int32 nCurLen = 0; 1953 for (sal_Int32 i = 0; i < nLenReqAttr; ++i) 1954 { 1955 beans::Property aProp; 1956 try 1957 { 1958 aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] ); 1959 } 1960 catch (beans::UnknownPropertyException &) 1961 { 1962 continue; 1963 } 1964 pProperties[ nCurLen++ ] = aProp; 1965 } 1966 aProperties.realloc( nCurLen ); 1967 } 1968 else 1969 aProperties = xPropSetInfo->getProperties(); 1970 1971 sal_Int32 nLength = aProperties.getLength(); 1972 const beans::Property *pProperties = aProperties.getConstArray(); 1973 1974 // build resulting sequence 1975 uno::Sequence< beans::PropertyValue > aOutSequence( nLength ); 1976 beans::PropertyValue* pOutSequence = aOutSequence.getArray(); 1977 sal_Int32 nOutLen = 0; 1978 for (sal_Int32 i = 0; i < nLength; ++i) 1979 { 1980 // calling implementation functions: 1981 // _getPropertyState and _getPropertyValue (see below) to provide 1982 // the proper paragraph number when retrieving paragraph attributes 1983 PropertyState eState = aPropSet._getPropertyState( pProperties->Name, mnParagraphIndex ); 1984 if ( eState == PropertyState_AMBIGUOUS_VALUE ) 1985 { 1986 OSL_ENSURE( false, "ambiguous property value encountered" ); 1987 } 1988 1989 //if (eState == PropertyState_DIRECT_VALUE) 1990 // per definition all paragraph properties and all character 1991 // properties spanning the whole paragraph should be returned 1992 // and declared as default value 1993 { 1994 pOutSequence->Name = pProperties->Name; 1995 pOutSequence->Handle = pProperties->Handle; 1996 pOutSequence->Value = aPropSet._getPropertyValue( pProperties->Name, mnParagraphIndex ); 1997 pOutSequence->State = PropertyState_DEFAULT_VALUE; 1998 1999 ++pOutSequence; 2000 ++nOutLen; 2001 } 2002 ++pProperties; 2003 } 2004 aOutSequence.realloc( nOutLen ); 2005 2006 return aOutSequence; 2007 } 2008 2009 2010 uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getRunAttributes( 2011 sal_Int32 nIndex, 2012 const uno::Sequence< ::rtl::OUString >& rRequestedAttributes ) 2013 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2014 { 2015 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2016 2017 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 2018 2019 #if OSL_DEBUG_LEVEL > 0 2020 SvxAccessibleTextAdapter& rCacheTF = 2021 #endif 2022 GetTextForwarder(); 2023 2024 #if OSL_DEBUG_LEVEL > 0 2025 (void)rCacheTF; 2026 #endif 2027 2028 DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX, 2029 "AccessibleEditableTextPara::getCharacterAttributes: index value overflow"); 2030 2031 CheckIndex(nIndex); 2032 2033 SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), 2034 ImplGetSvxCharAndParaPropertiesSet() ); 2035 aPropSet.SetSelection( MakeSelection( nIndex ) ); 2036 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo(); 2037 if (!xPropSetInfo.is()) 2038 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot query XPropertySetInfo")), 2039 uno::Reference< uno::XInterface > 2040 ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy 2041 2042 // build sequence of available properties to check 2043 sal_Int32 nLenReqAttr = rRequestedAttributes.getLength(); 2044 uno::Sequence< beans::Property > aProperties; 2045 if (nLenReqAttr) 2046 { 2047 const rtl::OUString *pRequestedAttributes = rRequestedAttributes.getConstArray(); 2048 2049 aProperties.realloc( nLenReqAttr ); 2050 beans::Property *pProperties = aProperties.getArray(); 2051 sal_Int32 nCurLen = 0; 2052 for (sal_Int32 i = 0; i < nLenReqAttr; ++i) 2053 { 2054 beans::Property aProp; 2055 try 2056 { 2057 aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] ); 2058 } 2059 catch (beans::UnknownPropertyException &) 2060 { 2061 continue; 2062 } 2063 pProperties[ nCurLen++ ] = aProp; 2064 } 2065 aProperties.realloc( nCurLen ); 2066 } 2067 else 2068 aProperties = xPropSetInfo->getProperties(); 2069 2070 sal_Int32 nLength = aProperties.getLength(); 2071 const beans::Property *pProperties = aProperties.getConstArray(); 2072 2073 // build resulting sequence 2074 uno::Sequence< beans::PropertyValue > aOutSequence( nLength ); 2075 beans::PropertyValue* pOutSequence = aOutSequence.getArray(); 2076 sal_Int32 nOutLen = 0; 2077 for (sal_Int32 i = 0; i < nLength; ++i) 2078 { 2079 // calling 'regular' functions that will operate on the selection 2080 PropertyState eState = aPropSet.getPropertyState( pProperties->Name ); 2081 if (eState == PropertyState_DIRECT_VALUE) 2082 { 2083 pOutSequence->Name = pProperties->Name; 2084 pOutSequence->Handle = pProperties->Handle; 2085 pOutSequence->Value = aPropSet.getPropertyValue( pProperties->Name ); 2086 pOutSequence->State = eState; 2087 2088 ++pOutSequence; 2089 ++nOutLen; 2090 } 2091 ++pProperties; 2092 } 2093 aOutSequence.realloc( nOutLen ); 2094 2095 return aOutSequence; 2096 } 2097 2098 // XAccessibleHypertext 2099 ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkCount( ) throw (::com::sun::star::uno::RuntimeException) 2100 { 2101 SvxAccessibleTextAdapter& rT = GetTextForwarder(); 2102 const sal_Int32 nPara = GetParagraphIndex(); 2103 2104 sal_uInt16 nHyperLinks = 0; 2105 sal_uInt16 nFields = rT.GetFieldCount( nPara ); 2106 for ( sal_uInt16 n = 0; n < nFields; n++ ) 2107 { 2108 EFieldInfo aField = rT.GetFieldInfo( nPara, n ); 2109 if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) ) 2110 nHyperLinks++; 2111 } 2112 return nHyperLinks; 2113 } 2114 2115 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > SAL_CALL AccessibleEditableTextPara::getHyperLink( ::sal_Int32 nLinkIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 2116 { 2117 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > xRef; 2118 2119 SvxAccessibleTextAdapter& rT = GetTextForwarder(); 2120 const sal_Int32 nPara = GetParagraphIndex(); 2121 2122 sal_uInt16 nHyperLink = 0; 2123 sal_uInt16 nFields = rT.GetFieldCount( nPara ); 2124 for ( sal_uInt16 n = 0; n < nFields; n++ ) 2125 { 2126 EFieldInfo aField = rT.GetFieldInfo( nPara, n ); 2127 if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) ) 2128 { 2129 if ( nHyperLink == nLinkIndex ) 2130 { 2131 sal_uInt16 nEEStart = aField.aPosition.nIndex; 2132 2133 // Translate EE Index to accessible index 2134 sal_uInt16 nStart = rT.CalcEditEngineIndex( nPara, nEEStart ); 2135 sal_uInt16 nEnd = nStart + aField.aCurrentText.Len(); 2136 xRef = new AccessibleHyperlink( rT, new SvxFieldItem( *aField.pFieldItem ), nPara, nEEStart, nStart, nEnd, aField.aCurrentText ); 2137 break; 2138 } 2139 nHyperLink++; 2140 } 2141 } 2142 2143 return xRef; 2144 } 2145 2146 ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkIndex( ::sal_Int32 nCharIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 2147 { 2148 const sal_Int32 nPara = GetParagraphIndex(); 2149 SvxAccessibleTextAdapter& rT = GetTextForwarder(); 2150 2151 // SvxAccessibleTextIndex aIndex; 2152 // aIndex.SetIndex(nPara, nCharIndex, rT); 2153 // const sal_uInt16 nEEIndex = aIndex.GetEEIndex(); 2154 2155 const sal_uInt16 nEEIndex = rT.CalcEditEngineIndex( nPara, nCharIndex ); 2156 sal_Int32 nHLIndex = 0; 2157 sal_uInt16 nHyperLink = 0; 2158 sal_uInt16 nFields = rT.GetFieldCount( nPara ); 2159 for ( sal_uInt16 n = 0; n < nFields; n++ ) 2160 { 2161 EFieldInfo aField = rT.GetFieldInfo( nPara, n ); 2162 if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) ) 2163 { 2164 if ( aField.aPosition.nIndex == nEEIndex ) 2165 { 2166 nHLIndex = nHyperLink; 2167 break; 2168 } 2169 nHyperLink++; 2170 } 2171 } 2172 2173 return nHLIndex; 2174 } 2175 2176 // XAccessibleMultiLineText 2177 sal_Int32 SAL_CALL AccessibleEditableTextPara::getLineNumberAtIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2178 { 2179 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2180 2181 sal_Int32 nRes = -1; 2182 sal_Int32 nPara = GetParagraphIndex(); 2183 2184 SvxTextForwarder &rCacheTF = GetTextForwarder(); 2185 const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount(); 2186 DBG_ASSERT( bValidPara, "getLineNumberAtIndex: current paragraph index out of range" ); 2187 if (bValidPara) 2188 { 2189 // we explicitly allow for the index to point at the character right behind the text 2190 if (0 <= nIndex && nIndex <= rCacheTF.GetTextLen( static_cast< sal_uInt16 >(nPara) )) 2191 nRes = rCacheTF.GetLineNumberAtIndex( static_cast< sal_uInt16 >(nPara), static_cast< sal_uInt16 >(nIndex) ); 2192 else 2193 throw lang::IndexOutOfBoundsException(); 2194 } 2195 return nRes; 2196 } 2197 2198 // XAccessibleMultiLineText 2199 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineNumber( sal_Int32 nLineNo ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2200 { 2201 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2202 2203 ::com::sun::star::accessibility::TextSegment aResult; 2204 sal_Int32 nPara = GetParagraphIndex(); 2205 SvxTextForwarder &rCacheTF = GetTextForwarder(); 2206 const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount(); 2207 DBG_ASSERT( bValidPara, "getTextAtLineNumber: current paragraph index out of range" ); 2208 if (bValidPara) 2209 { 2210 if (0 <= nLineNo && nLineNo < rCacheTF.GetLineCount( static_cast< sal_uInt16 >(nPara) )) 2211 { 2212 sal_uInt16 nStart = 0, nEnd = 0; 2213 rCacheTF.GetLineBoundaries( nStart, nEnd, static_cast< sal_uInt16 >(nPara), static_cast< sal_uInt16 >(nLineNo) ); 2214 if (nStart != 0xFFFF && nEnd != 0xFFFF) 2215 { 2216 try 2217 { 2218 aResult.SegmentText = getTextRange( nStart, nEnd ); 2219 aResult.SegmentStart = nStart; 2220 aResult.SegmentEnd = nEnd; 2221 } 2222 catch (lang::IndexOutOfBoundsException) 2223 { 2224 // this is not the exception that should be raised in this function ... 2225 DBG_ASSERT( 0, "unexpected exception" ); 2226 } 2227 } 2228 } 2229 else 2230 throw lang::IndexOutOfBoundsException(); 2231 } 2232 return aResult; 2233 } 2234 2235 // XAccessibleMultiLineText 2236 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineWithCaret( ) throw (uno::RuntimeException) 2237 { 2238 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2239 2240 ::com::sun::star::accessibility::TextSegment aResult; 2241 try 2242 { 2243 aResult = getTextAtLineNumber( getNumberOfLineWithCaret() ); 2244 } 2245 catch (lang::IndexOutOfBoundsException &) 2246 { 2247 // this one needs to be catched since this interface does not allow for it. 2248 } 2249 return aResult; 2250 } 2251 2252 // XAccessibleMultiLineText 2253 sal_Int32 SAL_CALL AccessibleEditableTextPara::getNumberOfLineWithCaret( ) throw (uno::RuntimeException) 2254 { 2255 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2256 2257 sal_Int32 nRes = -1; 2258 try 2259 { 2260 nRes = getLineNumberAtIndex( getCaretPosition() ); 2261 } 2262 catch (lang::IndexOutOfBoundsException &) 2263 { 2264 // this one needs to be catched since this interface does not allow for it. 2265 } 2266 return nRes; 2267 } 2268 2269 2270 // XServiceInfo 2271 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getImplementationName (void) throw (uno::RuntimeException) 2272 { 2273 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2274 2275 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("AccessibleEditableTextPara")); 2276 } 2277 2278 sal_Bool SAL_CALL AccessibleEditableTextPara::supportsService (const ::rtl::OUString& sServiceName) throw (uno::RuntimeException) 2279 { 2280 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2281 2282 // Iterate over all supported service names and return true if on of them 2283 // matches the given name. 2284 uno::Sequence< ::rtl::OUString> aSupportedServices ( 2285 getSupportedServiceNames ()); 2286 for (int i=0; i<aSupportedServices.getLength(); i++) 2287 if (sServiceName == aSupportedServices[i]) 2288 return sal_True; 2289 return sal_False; 2290 } 2291 2292 uno::Sequence< ::rtl::OUString> SAL_CALL AccessibleEditableTextPara::getSupportedServiceNames (void) throw (uno::RuntimeException) 2293 { 2294 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2295 2296 const ::rtl::OUString sServiceName( getServiceName() ); 2297 return uno::Sequence< ::rtl::OUString > (&sServiceName, 1); 2298 } 2299 2300 // XServiceName 2301 ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getServiceName (void) throw (uno::RuntimeException) 2302 { 2303 DBG_CHKTHIS( AccessibleEditableTextPara, NULL ); 2304 2305 // #105185# Using correct service now 2306 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AccessibleParagraphView")); 2307 } 2308 2309 } // end of namespace accessibility 2310 2311 //------------------------------------------------------------------------ 2312