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