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_sw.hxx" 26 27 #include <txtfrm.hxx> 28 #include <flyfrm.hxx> 29 #include <ndtxt.hxx> 30 #include <pam.hxx> 31 #include <unotextrange.hxx> 32 #include <unocrsrhelper.hxx> 33 #include <crstate.hxx> 34 #include <accmap.hxx> 35 #include <fesh.hxx> 36 #include <viewopt.hxx> 37 #include <vos/mutex.hxx> 38 #include <vcl/svapp.hxx> 39 #include <vcl/window.hxx> 40 #include <rtl/ustrbuf.hxx> 41 #include <com/sun/star/accessibility/AccessibleRole.hpp> 42 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 43 #include <com/sun/star/accessibility/AccessibleTextType.hpp> 44 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 45 #include <unotools/accessiblestatesethelper.hxx> 46 #include <com/sun/star/i18n/CharacterIteratorMode.hpp> 47 #include <com/sun/star/i18n/WordType.hpp> 48 #include <com/sun/star/i18n/XBreakIterator.hpp> 49 #include <com/sun/star/beans/UnknownPropertyException.hpp> 50 #include <breakit.hxx> 51 #include <accpara.hxx> 52 #include <access.hrc> 53 #include <accportions.hxx> 54 #include <sfx2/viewsh.hxx> // for ExecuteAtViewShell(...) 55 #include <sfx2/viewfrm.hxx> // for ExecuteAtViewShell(...) 56 #include <sfx2/dispatch.hxx> // for ExecuteAtViewShell(...) 57 #include <unotools/charclass.hxx> // for GetWordBoundary 58 // for get/setCharacterAttribute(...) 59 60 #include <reffld.hxx> 61 #include <docufld.hxx> 62 #include <expfld.hxx> 63 #include <flddat.hxx> 64 #include <fldui.hrc> 65 #include "../../ui/inc/fldmgr.hxx" 66 #include "fldbas.hxx" // SwField 67 #include <svl/svstdarr.hxx> 68 #include <unocrsr.hxx> 69 //#include <unoobj.hxx> 70 #include <unoport.hxx> 71 #include <doc.hxx> 72 #include <crsskip.hxx> 73 #include <txtatr.hxx> 74 #include <acchyperlink.hxx> 75 #include <acchypertextdata.hxx> 76 #include <unotools/accessiblerelationsethelper.hxx> 77 #include <com/sun/star/accessibility/AccessibleRelationType.hpp> 78 #include <section.hxx> 79 #include <doctxm.hxx> 80 #include <comphelper/accessibletexthelper.hxx> 81 #include <algorithm> 82 #include <docufld.hxx> 83 #include <txtfld.hxx> 84 #include <fmtfld.hxx> 85 #include <modcfg.hxx> 86 //#include "accnote.hxx" 87 #include <com/sun/star/beans/XPropertySet.hpp> 88 #include "swmodule.hxx" 89 #include "redline.hxx" 90 #include <com/sun/star/awt/FontWeight.hpp> 91 #include <com/sun/star/awt/FontStrikeout.hpp> 92 #include <com/sun/star/awt/FontSlant.hpp> 93 #include <wrong.hxx> 94 #include <editeng/brshitem.hxx> 95 #include <swatrset.hxx> 96 #include <frmatr.hxx> 97 #include <unosett.hxx> 98 #include <paratr.hxx> 99 #include <com/sun/star/container/XIndexReplace.hpp> 100 // --> OD 2006-07-12 #i63870# 101 #include <unomap.hxx> 102 #include <unoprnms.hxx> 103 #include <com/sun/star/text/WritingMode2.hpp> 104 #include <editeng/brshitem.hxx> 105 #include <viewimp.hxx> 106 #include <boost/scoped_ptr.hpp> 107 #include <textmarkuphelper.hxx> 108 // --> OD 2010-02-22 #i10825# 109 #include <parachangetrackinginfo.hxx> 110 #include <com/sun/star/text/TextMarkupType.hpp> 111 // <-- 112 // --> OD 2010-03-08 #i92233# 113 #include <comphelper/stlunosequence.hxx> 114 // <-- 115 116 #include <algorithm> 117 118 using namespace ::com::sun::star; 119 using namespace ::com::sun::star::accessibility; 120 using namespace ::com::sun::star::container; 121 using ::rtl::OUString; 122 123 using beans::PropertyValue; 124 using beans::XMultiPropertySet; 125 using beans::UnknownPropertyException; 126 using beans::PropertyState_DIRECT_VALUE; 127 128 using std::max; 129 using std::min; 130 using std::sort; 131 132 namespace com { namespace sun { namespace star { 133 namespace text { 134 class XText; 135 } 136 } } } 137 138 139 const sal_Char sServiceName[] = "com.sun.star.text.AccessibleParagraphView"; 140 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleParagraphView"; 141 const xub_StrLen MAX_DESC_TEXT_LEN = 40; 142 const SwTxtNode* SwAccessibleParagraph::GetTxtNode() const 143 { 144 const SwFrm* pFrm = GetFrm(); 145 DBG_ASSERT( pFrm->IsTxtFrm(), "The text frame has mutated!" ); 146 147 const SwTxtNode* pNode = static_cast<const SwTxtFrm*>(pFrm)->GetTxtNode(); 148 DBG_ASSERT( pNode != NULL, "A text frame without a text node." ); 149 150 return pNode; 151 } 152 153 ::rtl::OUString SwAccessibleParagraph::GetString() 154 { 155 return GetPortionData().GetAccessibleString(); 156 } 157 158 ::rtl::OUString SwAccessibleParagraph::GetDescription() 159 { 160 // --> OD 2004-09-29 #117933# - provide empty description for paragraphs 161 return ::rtl::OUString(); 162 // <-- 163 } 164 165 sal_Int32 SwAccessibleParagraph::GetCaretPos() 166 { 167 sal_Int32 nRet = -1; 168 169 // get the selection's point, and test whether it's in our node 170 // --> OD 2005-12-20 #i27301# - consider adjusted method signature 171 SwPaM* pCaret = GetCursor( false ); // caret is first PaM in PaM-ring 172 // <-- 173 if( pCaret != NULL ) 174 { 175 const SwTxtNode* pNode = GetTxtNode(); 176 177 // check whether the point points into 'our' node 178 SwPosition* pPoint = pCaret->GetPoint(); 179 if( pNode->GetIndex() == pPoint->nNode.GetIndex() ) 180 { 181 // same node? Then check whether it's also within 'our' part 182 // of the paragraph 183 sal_uInt16 nIndex = pPoint->nContent.GetIndex(); 184 if(!GetPortionData().IsValidCorePosition( nIndex ) || 185 ( GetPortionData().IsZeroCorePositionData() && nIndex== 0) ) 186 { 187 SwTxtFrm *pTxtFrm = PTR_CAST( SwTxtFrm, GetFrm() ); 188 bool bFormat = (pTxtFrm && pTxtFrm->HasPara()); 189 if(bFormat) 190 { 191 ClearPortionData(); 192 UpdatePortionData(); 193 } 194 } 195 if( GetPortionData().IsValidCorePosition( nIndex ) ) 196 { 197 // Yes, it's us! 198 // --> OD 2006-10-19 #70538# 199 // consider that cursor/caret is in front of the list label 200 if ( pCaret->IsInFrontOfLabel() ) 201 { 202 nRet = 0; 203 } 204 else 205 { 206 nRet = GetPortionData().GetAccessiblePosition( nIndex ); 207 } 208 // <-- 209 210 DBG_ASSERT( nRet >= 0, "invalid cursor?" ); 211 DBG_ASSERT( nRet <= GetPortionData().GetAccessibleString(). 212 getLength(), "invalid cursor?" ); 213 } 214 // else: in this paragraph, but in different frame 215 } 216 // else: not in this paragraph 217 } 218 // else: no cursor -> no caret 219 220 return nRet; 221 } 222 223 sal_Bool SwAccessibleParagraph::GetSelection( 224 sal_Int32& nStart, sal_Int32& nEnd) 225 { 226 sal_Bool bRet = sal_False; 227 nStart = -1; 228 nEnd = -1; 229 230 // get the selection, and test whether it affects our text node 231 // --> OD 2005-12-20 #i27301# - consider adjusted method signature 232 SwPaM* pCrsr = GetCursor( true ); 233 // <-- 234 if( pCrsr != NULL ) 235 { 236 // get SwPosition for my node 237 const SwTxtNode* pNode = GetTxtNode(); 238 sal_uLong nHere = pNode->GetIndex(); 239 240 // iterate over ring 241 SwPaM* pRingStart = pCrsr; 242 do 243 { 244 // ignore, if no mark 245 if( pCrsr->HasMark() ) 246 { 247 // check whether nHere is 'inside' pCrsr 248 SwPosition* pStart = pCrsr->Start(); 249 sal_uLong nStartIndex = pStart->nNode.GetIndex(); 250 SwPosition* pEnd = pCrsr->End(); 251 sal_uLong nEndIndex = pEnd->nNode.GetIndex(); 252 if( ( nHere >= nStartIndex ) && 253 ( nHere <= nEndIndex ) ) 254 { 255 // translate start and end positions 256 257 // start position 258 sal_Int32 nLocalStart = -1; 259 if( nHere > nStartIndex ) 260 { 261 // selection starts in previous node: 262 // then our local selection starts with the paragraph 263 nLocalStart = 0; 264 } 265 else 266 { 267 DBG_ASSERT( nHere == nStartIndex, 268 "miscalculated index" ); 269 270 // selection starts in this node: 271 // then check whether it's before or inside our part of 272 // the paragraph, and if so, get the proper position 273 sal_uInt16 nCoreStart = pStart->nContent.GetIndex(); 274 if( nCoreStart < 275 GetPortionData().GetFirstValidCorePosition() ) 276 { 277 nLocalStart = 0; 278 } 279 else if( nCoreStart <= 280 GetPortionData().GetLastValidCorePosition() ) 281 { 282 DBG_ASSERT( 283 GetPortionData().IsValidCorePosition( 284 nCoreStart ), 285 "problem determining valid core position" ); 286 287 nLocalStart = 288 GetPortionData().GetAccessiblePosition( 289 nCoreStart ); 290 } 291 } 292 293 // end position 294 sal_Int32 nLocalEnd = -1; 295 if( nHere < nEndIndex ) 296 { 297 // selection ends in following node: 298 // then our local selection extends to the end 299 nLocalEnd = GetPortionData().GetAccessibleString(). 300 getLength(); 301 } 302 else 303 { 304 DBG_ASSERT( nHere == nEndIndex, 305 "miscalculated index" ); 306 307 // selection ends in this node: then select everything 308 // before our part of the node 309 sal_uInt16 nCoreEnd = pEnd->nContent.GetIndex(); 310 if( nCoreEnd > 311 GetPortionData().GetLastValidCorePosition() ) 312 { 313 // selection extends beyond out part of this para 314 nLocalEnd = GetPortionData().GetAccessibleString(). 315 getLength(); 316 } 317 else if( nCoreEnd >= 318 GetPortionData().GetFirstValidCorePosition() ) 319 { 320 // selection is inside our part of this para 321 DBG_ASSERT( 322 GetPortionData().IsValidCorePosition( 323 nCoreEnd ), 324 "problem determining valid core position" ); 325 326 nLocalEnd = GetPortionData().GetAccessiblePosition( 327 nCoreEnd ); 328 } 329 } 330 331 if( ( nLocalStart != -1 ) && ( nLocalEnd != -1 ) ) 332 { 333 nStart = nLocalStart; 334 nEnd = nLocalEnd; 335 bRet = sal_True; 336 } 337 } 338 // else: this PaM doesn't point to this paragraph 339 } 340 // else: this PaM is collapsed and doesn't select anything 341 342 // next PaM in ring 343 pCrsr = static_cast<SwPaM*>( pCrsr->GetNext() ); 344 } 345 while( !bRet && (pCrsr != pRingStart) ); 346 } 347 // else: nocursor -> no selection 348 349 return bRet; 350 } 351 352 // --> OD 2005-12-20 #i27301# - new parameter <_bForSelection> 353 SwPaM* SwAccessibleParagraph::GetCursor( const bool _bForSelection ) 354 { 355 // get the cursor shell; if we don't have any, we don't have a 356 // cursor/selection either 357 SwPaM* pCrsr = NULL; 358 SwCrsrShell* pCrsrShell = SwAccessibleParagraph::GetCrsrShell(); 359 // --> OD 2005-12-20 #i27301# 360 // - if cursor is retrieved for selection, the cursors for a table selection 361 // has to be returned. 362 if ( pCrsrShell != NULL && 363 ( _bForSelection || !pCrsrShell->IsTableMode() ) ) 364 // <-- 365 { 366 SwFEShell *pFESh = pCrsrShell->ISA( SwFEShell ) 367 ? static_cast< SwFEShell * >( pCrsrShell ) : 0; 368 if( !pFESh || 369 !(pFESh->IsFrmSelected() || pFESh->IsObjSelected() > 0) ) 370 { 371 // get the selection, and test whether it affects our text node 372 pCrsr = pCrsrShell->GetCrsr( sal_False /* ??? */ ); 373 } 374 } 375 376 return pCrsr; 377 } 378 379 sal_Bool SwAccessibleParagraph::IsHeading() const 380 { 381 const SwTxtNode *pTxtNd = GetTxtNode(); 382 return pTxtNd->IsOutline(); 383 } 384 385 void SwAccessibleParagraph::GetStates( 386 ::utl::AccessibleStateSetHelper& rStateSet ) 387 { 388 SwAccessibleContext::GetStates( rStateSet ); 389 390 // MULTILINE 391 rStateSet.AddState( AccessibleStateType::MULTI_LINE ); 392 393 // MULTISELECTABLE 394 SwCrsrShell *pCrsrSh = GetCrsrShell(); 395 if( pCrsrSh ) 396 rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE ); 397 398 // FOCUSABLE 399 if( pCrsrSh ) 400 rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 401 402 // FOCUSED (simulates node index of cursor) 403 // --> OD 2005-12-20 #i27301# - consider adjusted method signature 404 SwPaM* pCaret = GetCursor( false ); 405 // <-- 406 const SwTxtNode* pTxtNd = GetTxtNode(); 407 if( pCaret != 0 && pTxtNd != 0 && 408 pTxtNd->GetIndex() == pCaret->GetPoint()->nNode.GetIndex() && 409 nOldCaretPos != -1) 410 { 411 Window *pWin = GetWindow(); 412 if( pWin && pWin->HasFocus() ) 413 rStateSet.AddState( AccessibleStateType::FOCUSED ); 414 ::vos::ORef < SwAccessibleContext > xThis( this ); 415 GetMap()->SetCursorContext( xThis ); 416 } 417 } 418 419 void SwAccessibleParagraph::_InvalidateContent( sal_Bool bVisibleDataFired ) 420 { 421 ::rtl::OUString sOldText( GetString() ); 422 423 ClearPortionData(); 424 425 const ::rtl::OUString& rText = GetString(); 426 427 if( rText != sOldText ) 428 { 429 // The text is changed 430 AccessibleEventObject aEvent; 431 aEvent.EventId = AccessibleEventId::TEXT_CHANGED; 432 433 // determine exact changes between sOldText and rText 434 comphelper::OCommonAccessibleText::implInitTextChangedEvent( 435 sOldText, rText, 436 aEvent.OldValue, aEvent.NewValue ); 437 438 FireAccessibleEvent( aEvent ); 439 uno::Reference< XAccessible > xparent = getAccessibleParent(); 440 uno::Reference< XAccessibleContext > xAccContext(xparent,uno::UNO_QUERY); 441 if (xAccContext.is() && xAccContext->getAccessibleRole() == AccessibleRole::TABLE_CELL) 442 { 443 SwAccessibleContext* pPara = static_cast< SwAccessibleContext* >(xparent.get()); 444 if(pPara) 445 { 446 AccessibleEventObject aParaEvent; 447 aParaEvent.EventId = AccessibleEventId::VALUE_CHANGED; 448 pPara->FireAccessibleEvent(aParaEvent); 449 } 450 } 451 } 452 else if( !bVisibleDataFired ) 453 { 454 FireVisibleDataEvent(); 455 } 456 457 sal_Bool bNewIsHeading = IsHeading(); 458 //Get the real heading level, Heading1 ~ Heading10 459 nHeadingLevel = GetRealHeadingLevel(); 460 sal_Bool bOldIsHeading; 461 { 462 vos::OGuard aGuard( aMutex ); 463 bOldIsHeading = bIsHeading; 464 if( bIsHeading != bNewIsHeading ) 465 bIsHeading = bNewIsHeading; 466 } 467 468 469 if( bNewIsHeading != bOldIsHeading || rText != sOldText ) 470 { 471 ::rtl::OUString sNewDesc( GetDescription() ); 472 ::rtl::OUString sOldDesc; 473 { 474 vos::OGuard aGuard( aMutex ); 475 sOldDesc = sDesc; 476 if( sDesc != sNewDesc ) 477 sDesc = sNewDesc; 478 } 479 480 if( sNewDesc != sOldDesc ) 481 { 482 // The text is changed 483 AccessibleEventObject aEvent; 484 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED; 485 aEvent.OldValue <<= sOldDesc; 486 aEvent.NewValue <<= sNewDesc; 487 488 FireAccessibleEvent( aEvent ); 489 } 490 } 491 } 492 493 void SwAccessibleParagraph::_InvalidateCursorPos() 494 { 495 // The text is changed 496 sal_Int32 nNew = GetCaretPos(); 497 sal_Int32 nOld; 498 { 499 vos::OGuard aGuard( aMutex ); 500 nOld = nOldCaretPos; 501 nOldCaretPos = nNew; 502 } 503 if( -1 != nNew ) 504 { 505 // remember that object as the one that has the caret. This is 506 // neccessary to notify that object if the cursor leaves it. 507 ::vos::ORef < SwAccessibleContext > xThis( this ); 508 GetMap()->SetCursorContext( xThis ); 509 } 510 511 Window *pWin = GetWindow(); 512 if( nOld != nNew ) 513 { 514 // The cursor's node position is sumilated by the focus! 515 if( pWin && pWin->HasFocus() && -1 == nOld ) 516 FireStateChangedEvent( AccessibleStateType::FOCUSED, sal_True ); 517 518 519 AccessibleEventObject aEvent; 520 aEvent.EventId = AccessibleEventId::CARET_CHANGED; 521 aEvent.OldValue <<= nOld; 522 aEvent.NewValue <<= nNew; 523 524 FireAccessibleEvent( aEvent ); 525 526 if( pWin && pWin->HasFocus() && -1 == nNew ) 527 FireStateChangedEvent( AccessibleStateType::FOCUSED, sal_False ); 528 //To send TEXT_SELECTION_CHANGED event 529 sal_Int32 nStart=0; 530 sal_Int32 nEnd =0; 531 sal_Bool bCurSelection=GetSelection(nStart,nEnd); 532 if(m_bLastHasSelection || bCurSelection ) 533 { 534 aEvent.EventId = AccessibleEventId::TEXT_SELECTION_CHANGED; 535 aEvent.OldValue <<= uno::Any(); 536 aEvent.NewValue <<= uno::Any(); 537 FireAccessibleEvent(aEvent); 538 } 539 m_bLastHasSelection =bCurSelection; 540 } 541 } 542 543 void SwAccessibleParagraph::_InvalidateFocus() 544 { 545 Window *pWin = GetWindow(); 546 if( pWin ) 547 { 548 sal_Int32 nPos; 549 { 550 vos::OGuard aGuard( aMutex ); 551 nPos = nOldCaretPos; 552 } 553 ASSERT( nPos != -1, "focus object should be selected" ); 554 555 FireStateChangedEvent( AccessibleStateType::FOCUSED, 556 pWin->HasFocus() && nPos != -1 ); 557 } 558 } 559 560 SwAccessibleParagraph::SwAccessibleParagraph( 561 SwAccessibleMap& rInitMap, 562 const SwTxtFrm& rTxtFrm ) 563 // --> OD 2010-02-24 #i108125# 564 : SwClient( const_cast<SwTxtNode*>(rTxtFrm.GetTxtNode()) ) 565 // <-- 566 , SwAccessibleContext( &rInitMap, AccessibleRole::PARAGRAPH, &rTxtFrm ) 567 , sDesc() 568 , pPortionData( NULL ) 569 , pHyperTextData( NULL ) 570 , nOldCaretPos( -1 ) 571 , bIsHeading( sal_False ) 572 //Get the real heading level, Heading1 ~ Heading10 573 , nHeadingLevel (-1) 574 , aSelectionHelper( *this ) 575 // --> OD 2010-02-19 #i108125# 576 , mpParaChangeTrackInfo( new SwParaChangeTrackingInfo( rTxtFrm ) ) 577 // <-- 578 , m_bLastHasSelection(false) //To add TEXT_SELECTION_CHANGED event 579 { 580 vos::OGuard aGuard(Application::GetSolarMutex()); 581 582 bIsHeading = IsHeading(); 583 //Get the real heading level, Heading1 ~ Heading10 584 nHeadingLevel = GetRealHeadingLevel(); 585 // --> OD 2004-09-27 #117970# - set an empty accessibility name for paragraphs 586 SetName( ::rtl::OUString() ); 587 // <-- 588 589 // If this object has the focus, then it is remembered by the map itself. 590 // not necessary to remember this pos here. Generally, the pos will be updated in invalidateXXX method, which may fire the 591 //Focus event based on the difference of new & old caret pos. 592 //nOldCaretPos = GetCaretPos(); 593 } 594 595 SwAccessibleParagraph::~SwAccessibleParagraph() 596 { 597 if(Application::GetUnoWrapper()) 598 vos::OGuard aGuard(Application::GetSolarMutex()); 599 600 delete pPortionData; 601 delete pHyperTextData; 602 // --> OD 2010-02-22 #i108125# 603 delete mpParaChangeTrackInfo; 604 // <-- 605 } 606 607 sal_Bool SwAccessibleParagraph::HasCursor() 608 { 609 vos::OGuard aGuard( aMutex ); 610 return nOldCaretPos != -1; 611 } 612 613 void SwAccessibleParagraph::UpdatePortionData() 614 throw( uno::RuntimeException ) 615 { 616 // obtain the text frame 617 DBG_ASSERT( GetFrm() != NULL, "The text frame has vanished!" ); 618 DBG_ASSERT( GetFrm()->IsTxtFrm(), "The text frame has mutated!" ); 619 const SwTxtFrm* pFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 620 621 // build new portion data 622 delete pPortionData; 623 pPortionData = new SwAccessiblePortionData( 624 pFrm->GetTxtNode(), GetMap()->GetShell()->GetViewOptions() ); 625 pFrm->VisitPortions( *pPortionData ); 626 627 DBG_ASSERT( pPortionData != NULL, "UpdatePortionData() failed" ); 628 } 629 630 void SwAccessibleParagraph::ClearPortionData() 631 { 632 delete pPortionData; 633 pPortionData = NULL; 634 635 delete pHyperTextData; 636 pHyperTextData = 0; 637 } 638 639 640 void SwAccessibleParagraph::ExecuteAtViewShell( sal_uInt16 nSlot ) 641 { 642 DBG_ASSERT( GetMap() != NULL, "no map?" ); 643 ViewShell* pViewShell = GetMap()->GetShell(); 644 645 DBG_ASSERT( pViewShell != NULL, "View shell exptected!" ); 646 SfxViewShell* pSfxShell = pViewShell->GetSfxViewShell(); 647 648 DBG_ASSERT( pSfxShell != NULL, "SfxViewShell shell exptected!" ); 649 if( !pSfxShell ) 650 return; 651 652 SfxViewFrame *pFrame = pSfxShell->GetViewFrame(); 653 DBG_ASSERT( pFrame != NULL, "View frame exptected!" ); 654 if( !pFrame ) 655 return; 656 657 SfxDispatcher *pDispatcher = pFrame->GetDispatcher(); 658 DBG_ASSERT( pDispatcher != NULL, "Dispatcher exptected!" ); 659 if( !pDispatcher ) 660 return; 661 662 pDispatcher->Execute( nSlot ); 663 } 664 665 SwXTextPortion* SwAccessibleParagraph::CreateUnoPortion( 666 sal_Int32 nStartIndex, 667 sal_Int32 nEndIndex ) 668 { 669 DBG_ASSERT( (IsValidChar(nStartIndex, GetString().getLength()) && 670 (nEndIndex == -1)) || 671 IsValidRange(nStartIndex, nEndIndex, GetString().getLength()), 672 "please check parameters before calling this method" ); 673 674 sal_uInt16 nStart = GetPortionData().GetModelPosition( nStartIndex ); 675 sal_uInt16 nEnd = (nEndIndex == -1) ? (nStart + 1) : 676 GetPortionData().GetModelPosition( nEndIndex ); 677 678 // create UNO cursor 679 SwTxtNode* pTxtNode = const_cast<SwTxtNode*>( GetTxtNode() ); 680 SwIndex aIndex( pTxtNode, nStart ); 681 SwPosition aStartPos( *pTxtNode, aIndex ); 682 SwUnoCrsr* pUnoCursor = pTxtNode->GetDoc()->CreateUnoCrsr( aStartPos ); 683 pUnoCursor->SetMark(); 684 pUnoCursor->GetMark()->nContent = nEnd; 685 686 // create a (dummy) text portion to be returned 687 uno::Reference<text::XText> aEmpty; 688 SwXTextPortion* pPortion = 689 new SwXTextPortion ( pUnoCursor, aEmpty, PORTION_TEXT); 690 delete pUnoCursor; 691 692 return pPortion; 693 } 694 695 696 // 697 // range checking for parameter 698 // 699 700 sal_Bool SwAccessibleParagraph::IsValidChar( 701 sal_Int32 nPos, sal_Int32 nLength) 702 { 703 return (nPos >= 0) && (nPos < nLength); 704 } 705 706 sal_Bool SwAccessibleParagraph::IsValidPosition( 707 sal_Int32 nPos, sal_Int32 nLength) 708 { 709 return (nPos >= 0) && (nPos <= nLength); 710 } 711 712 sal_Bool SwAccessibleParagraph::IsValidRange( 713 sal_Int32 nBegin, sal_Int32 nEnd, sal_Int32 nLength) 714 { 715 return IsValidPosition(nBegin, nLength) && IsValidPosition(nEnd, nLength); 716 } 717 SwTOXSortTabBase* SwAccessibleParagraph::GetTOXSortTabBase() 718 { 719 const SwTxtNode* pTxtNd = GetTxtNode(); 720 if( pTxtNd ) 721 { 722 const SwSectionNode * pSectNd = pTxtNd->FindSectionNode(); 723 if( pSectNd ) 724 { 725 const SwSection * pSect = &pSectNd->GetSection(); 726 SwTOXBaseSection *pTOXBaseSect = (SwTOXBaseSection *)pSect; 727 if( pSect->GetType() == TOX_CONTENT_SECTION ) 728 { 729 SwTOXSortTabBase* pSortBase = 0; 730 int nSize = pTOXBaseSect->GetTOXSortTabBases()->Count(); 731 732 for(int nIndex = 0; nIndex<nSize; nIndex++ ) 733 { 734 pSortBase = (*(pTOXBaseSect->GetTOXSortTabBases()))[nIndex]; 735 if( pSortBase->pTOXNd == pTxtNd ) 736 break; 737 } 738 739 if (pSortBase) 740 { 741 return pSortBase; 742 } 743 } 744 } 745 } 746 return NULL; 747 } 748 749 short SwAccessibleParagraph::GetTOCLevel() 750 { 751 SwTOXSortTabBase* pToxBase = GetTOXSortTabBase(); 752 if( pToxBase ) 753 { 754 const SwCntntNode* pNd = pToxBase->aTOXSources[0].pNd; 755 if( pNd ) 756 return pToxBase->GetLevel(); 757 else 758 return -1; 759 } 760 else 761 return -1; 762 } 763 764 //the function is to check whether the position is in a redline range. 765 const SwRedline* SwAccessibleParagraph::GetRedlineAtIndex( sal_Int32 ) 766 { 767 const SwRedline* pRedline = NULL; 768 SwPaM* pCrSr = GetCursor( true ); 769 if ( pCrSr ) 770 { 771 SwPosition* pStart = pCrSr->Start(); 772 const SwTxtNode* pNode = GetTxtNode(); 773 if ( pNode ) 774 { 775 const SwDoc* pDoc = pNode->GetDoc(); 776 if ( pDoc ) 777 { 778 pRedline = pDoc->GetRedline( *pStart, NULL ); 779 } 780 } 781 } 782 783 return pRedline; 784 } 785 786 // 787 // text boundaries 788 // 789 790 791 sal_Bool SwAccessibleParagraph::GetCharBoundary( 792 i18n::Boundary& rBound, 793 const ::rtl::OUString&, 794 sal_Int32 nPos ) 795 { 796 if( GetPortionData().FillBoundaryIFDateField( rBound, nPos) ) 797 return sal_True; 798 799 rBound.startPos = nPos; 800 rBound.endPos = nPos+1; 801 return sal_True; 802 } 803 804 sal_Bool SwAccessibleParagraph::GetWordBoundary( 805 i18n::Boundary& rBound, 806 const ::rtl::OUString& rText, 807 sal_Int32 nPos ) 808 { 809 sal_Bool bRet = sal_False; 810 811 // now ask the Break-Iterator for the word 812 DBG_ASSERT( pBreakIt != NULL, "We always need a break." ); 813 DBG_ASSERT( pBreakIt->GetBreakIter().is(), "No break-iterator." ); 814 if( pBreakIt->GetBreakIter().is() ) 815 { 816 // get locale for this position 817 sal_uInt16 nModelPos = GetPortionData().GetModelPosition( nPos ); 818 lang::Locale aLocale = pBreakIt->GetLocale( 819 GetTxtNode()->GetLang( nModelPos ) ); 820 821 // which type of word are we interested in? 822 // (DICTIONARY_WORD includes punctuation, ANY_WORD doesn't.) 823 const sal_uInt16 nWordType = i18n::WordType::ANY_WORD; 824 825 /* 826 // get word boundary, as the Break-Iterator sees fit. 827 sal_Unicode SpaceChar(' '); 828 if (rText.getCodePointAt(nPos) == SpaceChar) 829 { 830 int nStartPos = nPos; 831 int nEndPos = nPos+1; 832 while (nStartPos >= 0 && rText.getCodePointAt(nStartPos) == SpaceChar) 833 --nStartPos; 834 while (nEndPos < rText.getLength() && rText.getCodePointAt(nEndPos) == SpaceChar) 835 ++nEndPos; 836 //Get the previous word boundary + the followed space characters 837 if (nStartPos >= 0) 838 { 839 rBound = pBreakIt->xBreak->getWordBoundary( rText, nStartPos, aLocale, nWordType, sal_True ); 840 rBound.endPos += (nEndPos-nStartPos - 1); 841 } 842 //When the frontal characters are whitespace, return the all space characters directly. 843 else 844 { 845 rBound.startPos = 0; 846 rBound.endPos = nEndPos; 847 } 848 } 849 // add the " " into the word boundry 850 else 851 { 852 rBound = pBreakIt->xBreak->getWordBoundary(rText, nPos, aLocale, nWordType, sal_True ); 853 sal_Int32 nEndPos = rBound.endPos, nLength = rText.getLength(); 854 while ( nEndPos < nLength && rText.getCodePointAt(nEndPos) == SpaceChar ) 855 nEndPos++; 856 rBound.endPos = nEndPos; 857 } 858 tabCharInWord( nPos, rBound); 859 if( GetPortionData().FillBoundaryIFDateField( rBound, rBound.startPos) ) 860 return sal_True; 861 return sal_True; // MT: So why do we need the return TRUE above??? 862 */ 863 // get word boundary, as the Break-Iterator sees fit. 864 rBound = pBreakIt->GetBreakIter()->getWordBoundary( 865 rText, nPos, aLocale, nWordType, sal_True ); 866 867 // It's a word if the first character is an alpha-numeric character. 868 bRet = GetAppCharClass().isLetterNumeric( 869 rText.getStr()[ rBound.startPos ] ); 870 } 871 else 872 { 873 // no break Iterator -> no word 874 rBound.startPos = nPos; 875 rBound.endPos = nPos; 876 } 877 878 return bRet; 879 } 880 881 sal_Bool SwAccessibleParagraph::GetSentenceBoundary( 882 i18n::Boundary& rBound, 883 const ::rtl::OUString& rText, 884 sal_Int32 nPos ) 885 { 886 const sal_Unicode* pStr = rText.getStr(); 887 if (pStr) 888 { 889 while( pStr[nPos] == sal_Unicode(' ') && nPos < rText.getLength()) 890 nPos++; 891 } 892 GetPortionData().GetSentenceBoundary( rBound, nPos ); 893 return sal_True; 894 } 895 896 sal_Bool SwAccessibleParagraph::GetLineBoundary( 897 i18n::Boundary& rBound, 898 const ::rtl::OUString& rText, 899 sal_Int32 nPos ) 900 { 901 if( rText.getLength() == nPos ) 902 GetPortionData().GetLastLineBoundary( rBound ); 903 else 904 GetPortionData().GetLineBoundary( rBound, nPos ); 905 return sal_True; 906 } 907 908 sal_Bool SwAccessibleParagraph::GetParagraphBoundary( 909 i18n::Boundary& rBound, 910 const ::rtl::OUString& rText, 911 sal_Int32 ) 912 { 913 rBound.startPos = 0; 914 rBound.endPos = rText.getLength(); 915 return sal_True; 916 } 917 918 sal_Bool SwAccessibleParagraph::GetAttributeBoundary( 919 i18n::Boundary& rBound, 920 const ::rtl::OUString&, 921 sal_Int32 nPos ) 922 { 923 GetPortionData().GetAttributeBoundary( rBound, nPos ); 924 return sal_True; 925 } 926 927 sal_Bool SwAccessibleParagraph::GetGlyphBoundary( 928 i18n::Boundary& rBound, 929 const ::rtl::OUString& rText, 930 sal_Int32 nPos ) 931 { 932 sal_Bool bRet = sal_False; 933 934 // ask the Break-Iterator for the glyph by moving one cell 935 // forward, and then one cell back 936 DBG_ASSERT( pBreakIt != NULL, "We always need a break." ); 937 DBG_ASSERT( pBreakIt->GetBreakIter().is(), "No break-iterator." ); 938 if( pBreakIt->GetBreakIter().is() ) 939 { 940 // get locale for this position 941 sal_uInt16 nModelPos = GetPortionData().GetModelPosition( nPos ); 942 lang::Locale aLocale = pBreakIt->GetLocale( 943 GetTxtNode()->GetLang( nModelPos ) ); 944 945 // get word boundary, as the Break-Iterator sees fit. 946 const sal_uInt16 nIterMode = i18n::CharacterIteratorMode::SKIPCELL; 947 sal_Int32 nDone = 0; 948 rBound.endPos = pBreakIt->GetBreakIter()->nextCharacters( 949 rText, nPos, aLocale, nIterMode, 1, nDone ); 950 rBound.startPos = pBreakIt->GetBreakIter()->previousCharacters( 951 rText, rBound.endPos, aLocale, nIterMode, 1, nDone ); 952 953 bRet = ((rBound.startPos <= nPos) && (nPos <= rBound.endPos)); 954 DBG_ASSERT( rBound.startPos <= nPos, "start pos too high" ); 955 DBG_ASSERT( rBound.endPos >= nPos, "end pos too low" ); 956 } 957 else 958 { 959 // no break Iterator -> no glyph 960 rBound.startPos = nPos; 961 rBound.endPos = nPos; 962 } 963 964 return bRet; 965 } 966 967 968 sal_Bool SwAccessibleParagraph::GetTextBoundary( 969 i18n::Boundary& rBound, 970 const ::rtl::OUString& rText, 971 sal_Int32 nPos, 972 sal_Int16 nTextType ) 973 throw ( 974 lang::IndexOutOfBoundsException, 975 lang::IllegalArgumentException, 976 uno::RuntimeException) 977 { 978 // error checking 979 if( !( AccessibleTextType::LINE == nTextType 980 ? IsValidPosition( nPos, rText.getLength() ) 981 : IsValidChar( nPos, rText.getLength() ) ) ) 982 throw lang::IndexOutOfBoundsException(); 983 984 sal_Bool bRet; 985 986 switch( nTextType ) 987 { 988 case AccessibleTextType::WORD: 989 bRet = GetWordBoundary( rBound, rText, nPos ); 990 break; 991 992 case AccessibleTextType::SENTENCE: 993 bRet = GetSentenceBoundary( rBound, rText, nPos ); 994 break; 995 996 case AccessibleTextType::PARAGRAPH: 997 bRet = GetParagraphBoundary( rBound, rText, nPos ); 998 break; 999 1000 case AccessibleTextType::CHARACTER: 1001 bRet = GetCharBoundary( rBound, rText, nPos ); 1002 break; 1003 1004 case AccessibleTextType::LINE: 1005 //Solve the problem of returning wrong LINE and PARAGRAPH 1006 if((nPos == rText.getLength()) && nPos > 0) 1007 bRet = GetLineBoundary( rBound, rText, nPos - 1); 1008 else 1009 bRet = GetLineBoundary( rBound, rText, nPos ); 1010 break; 1011 1012 case AccessibleTextType::ATTRIBUTE_RUN: 1013 bRet = GetAttributeBoundary( rBound, rText, nPos ); 1014 if(bRet) 1015 { 1016 SwCrsrShell* pCrsrShell = GetCrsrShell(); 1017 if( pCrsrShell != NULL && pCrsrShell->GetViewOptions() && pCrsrShell->GetViewOptions()->IsOnlineSpell()) 1018 { 1019 SwTxtNode* pTxtNode = const_cast<SwTxtNode*>( GetTxtNode() ); 1020 if(pTxtNode) 1021 { 1022 const SwWrongList* pWrongList = pTxtNode->GetWrong(); 1023 if( NULL != pWrongList ) 1024 { 1025 xub_StrLen nBegin = nPos; 1026 xub_StrLen nLen = 1; 1027 const xub_StrLen nNext = pWrongList->NextWrong(nBegin); 1028 xub_StrLen nLast; 1029 xub_StrLen nWrongPos = pWrongList->GetWrongPos( nBegin ); 1030 if ( nWrongPos >= pWrongList->Count() || 1031 ( nLast = pWrongList->Pos( nWrongPos ) ) >= nBegin ) 1032 { 1033 nLast = nWrongPos 1034 ? pWrongList->Pos( --nWrongPos ) 1035 : STRING_LEN; 1036 } 1037 if ( nBegin > pWrongList->GetBeginInv() && 1038 ( nLast == STRING_LEN || nLast < pWrongList->GetEndInv() ) ) 1039 { 1040 nLast = nBegin > pWrongList->GetEndInv() 1041 ? pWrongList->GetEndInv() 1042 : nBegin; 1043 } 1044 else if ( nLast < STRING_LEN ) 1045 { 1046 nLast += pWrongList->Len( nWrongPos ); 1047 } 1048 // 1049 sal_Bool bIn = pWrongList->InWrongWord(nBegin,nLen); // && !pTxtNode->IsSymbol(nBegin) ) 1050 if(bIn) 1051 { 1052 rBound.startPos = max(nNext,(xub_StrLen)rBound.startPos); 1053 rBound.endPos = min(xub_StrLen(nNext + nLen),(xub_StrLen)rBound.endPos); 1054 } 1055 else 1056 { 1057 if (STRING_LEN == nLast)//first 1058 { 1059 rBound.endPos = min(nNext,(xub_StrLen)rBound.endPos); 1060 } 1061 else if(STRING_LEN == nNext) 1062 { 1063 rBound.startPos = max(nLast,(xub_StrLen)rBound.startPos); 1064 } 1065 else 1066 { 1067 rBound.startPos = max(nLast,(xub_StrLen)rBound.startPos); 1068 rBound.endPos = min(nNext,(xub_StrLen)rBound.endPos); 1069 } 1070 } 1071 } 1072 } 1073 } 1074 } 1075 break; 1076 1077 case AccessibleTextType::GLYPH: 1078 bRet = GetGlyphBoundary( rBound, rText, nPos ); 1079 break; 1080 1081 default: 1082 throw lang::IllegalArgumentException( ); 1083 } 1084 1085 return bRet; 1086 } 1087 1088 ::rtl::OUString SAL_CALL SwAccessibleParagraph::getAccessibleDescription (void) 1089 throw (uno::RuntimeException) 1090 { 1091 vos::OGuard aGuard(Application::GetSolarMutex()); 1092 1093 CHECK_FOR_DEFUNC( XAccessibleContext ); 1094 1095 vos::OGuard aGuard2( aMutex ); 1096 if( !sDesc.getLength() ) 1097 sDesc = GetDescription(); 1098 1099 return sDesc; 1100 } 1101 1102 lang::Locale SAL_CALL SwAccessibleParagraph::getLocale (void) 1103 throw (IllegalAccessibleComponentStateException, uno::RuntimeException) 1104 { 1105 vos::OGuard aGuard(Application::GetSolarMutex()); 1106 1107 SwTxtFrm *pTxtFrm = PTR_CAST( SwTxtFrm, GetFrm() ); 1108 if( !pTxtFrm ) 1109 { 1110 THROW_RUNTIME_EXCEPTION( XAccessibleContext, "internal error (no text frame)" ); 1111 } 1112 1113 const SwTxtNode *pTxtNd = pTxtFrm->GetTxtNode(); 1114 lang::Locale aLoc( pBreakIt->GetLocale( pTxtNd->GetLang( 0 ) ) ); 1115 1116 return aLoc; 1117 } 1118 1119 /** paragraphs are in relation CONTENT_FLOWS_FROM and/or CONTENT_FLOWS_TO 1120 1121 OD 2005-12-02 #i27138# 1122 1123 @author OD 1124 */ 1125 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleParagraph::getAccessibleRelationSet() 1126 throw ( uno::RuntimeException ) 1127 { 1128 vos::OGuard aGuard(Application::GetSolarMutex()); 1129 CHECK_FOR_DEFUNC( XAccessibleContext ); 1130 1131 utl::AccessibleRelationSetHelper* pHelper = new utl::AccessibleRelationSetHelper(); 1132 1133 const SwTxtFrm* pTxtFrm = dynamic_cast<const SwTxtFrm*>(GetFrm()); 1134 ASSERT( pTxtFrm, 1135 "<SwAccessibleParagraph::getAccessibleRelationSet()> - missing text frame"); 1136 if ( pTxtFrm ) 1137 { 1138 const SwCntntFrm* pPrevCntFrm( pTxtFrm->FindPrevCnt( true ) ); 1139 if ( pPrevCntFrm ) 1140 { 1141 uno::Sequence< uno::Reference<XInterface> > aSequence(1); 1142 aSequence[0] = GetMap()->GetContext( pPrevCntFrm ); 1143 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_FROM, 1144 aSequence ); 1145 pHelper->AddRelation( aAccRel ); 1146 } 1147 1148 const SwCntntFrm* pNextCntFrm( pTxtFrm->FindNextCnt( true ) ); 1149 if ( pNextCntFrm ) 1150 { 1151 uno::Sequence< uno::Reference<XInterface> > aSequence(1); 1152 aSequence[0] = GetMap()->GetContext( pNextCntFrm ); 1153 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_TO, 1154 aSequence ); 1155 pHelper->AddRelation( aAccRel ); 1156 } 1157 } 1158 1159 return pHelper; 1160 } 1161 1162 void SAL_CALL SwAccessibleParagraph::grabFocus() 1163 throw (uno::RuntimeException) 1164 { 1165 vos::OGuard aGuard(Application::GetSolarMutex()); 1166 1167 CHECK_FOR_DEFUNC( XAccessibleContext ); 1168 1169 // get cursor shell 1170 SwCrsrShell *pCrsrSh = GetCrsrShell(); 1171 // --> OD 2005-12-20 #i27301# - consider new method signature 1172 SwPaM *pCrsr = GetCursor( false ); 1173 // <-- 1174 const SwTxtFrm *pTxtFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 1175 const SwTxtNode* pTxtNd = pTxtFrm->GetTxtNode(); 1176 1177 if( pCrsrSh != 0 && pTxtNd != 0 && 1178 ( pCrsr == 0 || 1179 pCrsr->GetPoint()->nNode.GetIndex() != pTxtNd->GetIndex() || 1180 !pTxtFrm->IsInside( pCrsr->GetPoint()->nContent.GetIndex()) ) ) 1181 { 1182 // create pam for selection 1183 SwIndex aIndex( const_cast< SwTxtNode * >( pTxtNd ), 1184 pTxtFrm->GetOfst() ); 1185 SwPosition aStartPos( *pTxtNd, aIndex ); 1186 SwPaM aPaM( aStartPos ); 1187 1188 // set PaM at cursor shell 1189 Select( aPaM ); 1190 1191 1192 } 1193 1194 /* ->#i13955# */ 1195 Window * pWindow = GetWindow(); 1196 1197 if (pWindow != NULL) 1198 pWindow->GrabFocus(); 1199 /* <-#i13955# */ 1200 } 1201 1202 // --> OD 2007-01-17 #i71385# 1203 bool lcl_GetBackgroundColor( Color & rColor, 1204 const SwFrm* pFrm, 1205 SwCrsrShell* pCrsrSh ) 1206 { 1207 const SvxBrushItem* pBackgrdBrush = 0; 1208 const Color* pSectionTOXColor = 0; 1209 SwRect aDummyRect; 1210 1211 //UUUU 1212 FillAttributesPtr aFillAttributes; 1213 1214 if ( pFrm && 1215 pFrm->GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false ) ) 1216 { 1217 if ( pSectionTOXColor ) 1218 { 1219 rColor = *pSectionTOXColor; 1220 return true; 1221 } 1222 else 1223 { 1224 rColor = pBackgrdBrush->GetColor(); 1225 return true; 1226 } 1227 } 1228 else if ( pCrsrSh ) 1229 { 1230 rColor = pCrsrSh->Imp()->GetRetoucheColor(); 1231 return true; 1232 } 1233 1234 return false; 1235 } 1236 1237 sal_Int32 SAL_CALL SwAccessibleParagraph::getForeground() 1238 throw (uno::RuntimeException) 1239 { 1240 Color aBackgroundCol; 1241 1242 if ( lcl_GetBackgroundColor( aBackgroundCol, GetFrm(), GetCrsrShell() ) ) 1243 { 1244 if ( aBackgroundCol.IsDark() ) 1245 { 1246 return COL_WHITE; 1247 } 1248 else 1249 { 1250 return COL_BLACK; 1251 } 1252 } 1253 1254 return SwAccessibleContext::getForeground(); 1255 } 1256 1257 sal_Int32 SAL_CALL SwAccessibleParagraph::getBackground() 1258 throw (uno::RuntimeException) 1259 { 1260 Color aBackgroundCol; 1261 1262 if ( lcl_GetBackgroundColor( aBackgroundCol, GetFrm(), GetCrsrShell() ) ) 1263 { 1264 return aBackgroundCol.GetColor(); 1265 } 1266 1267 return SwAccessibleContext::getBackground(); 1268 } 1269 // <-- 1270 1271 ::rtl::OUString SAL_CALL SwAccessibleParagraph::getImplementationName() 1272 throw( uno::RuntimeException ) 1273 { 1274 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName)); 1275 } 1276 1277 sal_Bool SAL_CALL SwAccessibleParagraph::supportsService( 1278 const ::rtl::OUString& sTestServiceName) 1279 throw (uno::RuntimeException) 1280 { 1281 return sTestServiceName.equalsAsciiL( sServiceName, 1282 sizeof(sServiceName)-1 ) || 1283 sTestServiceName.equalsAsciiL( sAccessibleServiceName, 1284 sizeof(sAccessibleServiceName)-1 ); 1285 } 1286 1287 uno::Sequence< ::rtl::OUString > SAL_CALL SwAccessibleParagraph::getSupportedServiceNames() 1288 throw( uno::RuntimeException ) 1289 { 1290 uno::Sequence< ::rtl::OUString > aRet(2); 1291 ::rtl::OUString* pArray = aRet.getArray(); 1292 pArray[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) ); 1293 pArray[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) ); 1294 return aRet; 1295 } 1296 1297 uno::Sequence< ::rtl::OUString > getAttributeNames() 1298 { 1299 static uno::Sequence< ::rtl::OUString >* pNames = NULL; 1300 1301 if( pNames == NULL ) 1302 { 1303 // Add the font name to attribute list 1304 uno::Sequence< ::rtl::OUString >* pSeq = new uno::Sequence< ::rtl::OUString >( 13 ); 1305 1306 ::rtl::OUString* pStrings = pSeq->getArray(); 1307 1308 // sorted list of strings 1309 sal_Int32 i = 0; 1310 1311 #define STR(x) pStrings[i++] = OUString::createFromAscii(x) 1312 STR( GetPropName( UNO_NAME_CHAR_BACK_COLOR ).pName ); 1313 STR( GetPropName( UNO_NAME_CHAR_COLOR ).pName ); 1314 STR( GetPropName( UNO_NAME_CHAR_CONTOURED ).pName ); 1315 STR( GetPropName( UNO_NAME_CHAR_EMPHASIS ).pName ); 1316 STR( GetPropName( UNO_NAME_CHAR_ESCAPEMENT ).pName ); 1317 STR( GetPropName( UNO_NAME_CHAR_FONT_NAME ).pName ); 1318 STR( GetPropName( UNO_NAME_CHAR_HEIGHT ).pName ); 1319 STR( GetPropName( UNO_NAME_CHAR_POSTURE ).pName ); 1320 STR( GetPropName( UNO_NAME_CHAR_SHADOWED ).pName ); 1321 STR( GetPropName( UNO_NAME_CHAR_STRIKEOUT ).pName ); 1322 STR( GetPropName( UNO_NAME_CHAR_UNDERLINE ).pName ); 1323 STR( GetPropName( UNO_NAME_CHAR_UNDERLINE_COLOR ).pName ); 1324 STR( GetPropName( UNO_NAME_CHAR_WEIGHT ).pName ); 1325 #undef STR 1326 DBG_ASSERT( i == pSeq->getLength(), "Please adjust length" ); 1327 if( i != pSeq->getLength() ) 1328 pSeq->realloc( i ); 1329 pNames = pSeq; 1330 } 1331 return *pNames; 1332 } 1333 1334 uno::Sequence< ::rtl::OUString > getSupplementalAttributeNames() 1335 { 1336 static uno::Sequence< ::rtl::OUString >* pNames = NULL; 1337 1338 if( pNames == NULL ) 1339 { 1340 uno::Sequence< ::rtl::OUString >* pSeq = new uno::Sequence< ::rtl::OUString >( 9 ); 1341 1342 ::rtl::OUString* pStrings = pSeq->getArray(); 1343 1344 // sorted list of strings 1345 sal_Int32 i = 0; 1346 1347 #define STR(x) pStrings[i++] = OUString::createFromAscii(x) 1348 STR( GetPropName( UNO_NAME_NUMBERING_LEVEL ).pName ); 1349 STR( GetPropName( UNO_NAME_NUMBERING_RULES ).pName ); 1350 STR( GetPropName( UNO_NAME_PARA_ADJUST ).pName ); 1351 STR( GetPropName( UNO_NAME_PARA_BOTTOM_MARGIN ).pName ); 1352 STR( GetPropName( UNO_NAME_PARA_FIRST_LINE_INDENT ).pName ); 1353 STR( GetPropName( UNO_NAME_PARA_LEFT_MARGIN ).pName ); 1354 STR( GetPropName( UNO_NAME_PARA_LINE_SPACING ).pName ); 1355 STR( GetPropName( UNO_NAME_PARA_RIGHT_MARGIN ).pName ); 1356 STR( GetPropName( UNO_NAME_TABSTOPS ).pName ); 1357 #undef STR 1358 DBG_ASSERT( i == pSeq->getLength(), "Please adjust length" ); 1359 if( i != pSeq->getLength() ) 1360 pSeq->realloc( i ); 1361 pNames = pSeq; 1362 } 1363 return *pNames; 1364 } 1365 // 1366 //===== XInterface ======================================================= 1367 // 1368 1369 uno::Any SwAccessibleParagraph::queryInterface( const uno::Type& rType ) 1370 throw (uno::RuntimeException) 1371 { 1372 uno::Any aRet; 1373 if ( rType == ::getCppuType((uno::Reference<XAccessibleText> *)0) ) 1374 { 1375 uno::Reference<XAccessibleText> aAccText = (XAccessibleText *) *this; // resolve ambiguity 1376 aRet <<= aAccText; 1377 } 1378 else if ( rType == ::getCppuType((uno::Reference<XAccessibleEditableText> *)0) ) 1379 { 1380 uno::Reference<XAccessibleEditableText> aAccEditText = this; 1381 aRet <<= aAccEditText; 1382 } 1383 else if ( rType == ::getCppuType((uno::Reference<XAccessibleSelection> *)0) ) 1384 { 1385 uno::Reference<XAccessibleSelection> aAccSel = this; 1386 aRet <<= aAccSel; 1387 } 1388 else if ( rType == ::getCppuType((uno::Reference<XAccessibleHypertext> *)0) ) 1389 { 1390 uno::Reference<XAccessibleHypertext> aAccHyp = this; 1391 aRet <<= aAccHyp; 1392 } 1393 // --> OD 2006-07-13 #i63870# 1394 // add interface com::sun:star:accessibility::XAccessibleTextAttributes 1395 else if ( rType == ::getCppuType((uno::Reference<XAccessibleTextAttributes> *)0) ) 1396 { 1397 uno::Reference<XAccessibleTextAttributes> aAccTextAttr = this; 1398 aRet <<= aAccTextAttr; 1399 } 1400 // <-- 1401 // --> OD 2008-06-10 #i89175# 1402 // add interface com::sun:star:accessibility::XAccessibleTextMarkup 1403 else if ( rType == ::getCppuType((uno::Reference<XAccessibleTextMarkup> *)0) ) 1404 { 1405 uno::Reference<XAccessibleTextMarkup> aAccTextMarkup = this; 1406 aRet <<= aAccTextMarkup; 1407 } 1408 // add interface com::sun:star:accessibility::XAccessibleMultiLineText 1409 else if ( rType == ::getCppuType((uno::Reference<XAccessibleMultiLineText> *)0) ) 1410 { 1411 uno::Reference<XAccessibleMultiLineText> aAccMultiLineText = this; 1412 aRet <<= aAccMultiLineText; 1413 } 1414 // <-- 1415 //MSAA Extension Implementation in app module 1416 else if ( rType == ::getCppuType((uno::Reference<XAccessibleTextSelection> *)NULL) ) 1417 { 1418 uno::Reference< com::sun::star::accessibility::XAccessibleTextSelection > aTextExtension = this; 1419 aRet <<= aTextExtension; 1420 } 1421 else if ( rType == ::getCppuType((uno::Reference<XAccessibleExtendedAttributes> *)NULL) ) 1422 { 1423 uno::Reference<XAccessibleExtendedAttributes> xAttr = this; 1424 aRet <<= xAttr; 1425 } 1426 else 1427 { 1428 aRet = SwAccessibleContext::queryInterface(rType); 1429 } 1430 1431 return aRet; 1432 } 1433 1434 //====== XTypeProvider ==================================================== 1435 uno::Sequence< uno::Type > SAL_CALL SwAccessibleParagraph::getTypes() throw(uno::RuntimeException) 1436 { 1437 uno::Sequence< uno::Type > aTypes( SwAccessibleContext::getTypes() ); 1438 1439 sal_Int32 nIndex = aTypes.getLength(); 1440 // --> OD 2006-07-13 #i63870# 1441 // add type accessibility::XAccessibleTextAttributes 1442 // --> OD 2008-06-10 #i89175# 1443 // add type accessibility::XAccessibleTextMarkup and accessibility::XAccessibleMultiLineText 1444 aTypes.realloc( nIndex + 6 ); 1445 1446 uno::Type* pTypes = aTypes.getArray(); 1447 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleEditableText > * >( 0 ) ); 1448 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleTextAttributes > * >( 0 ) ); 1449 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) ); 1450 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleTextMarkup > * >( 0 ) ); 1451 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleMultiLineText > * >( 0 ) ); 1452 pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleHypertext > * >( 0 ) ); 1453 // <-- 1454 1455 return aTypes; 1456 } 1457 1458 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleParagraph::getImplementationId() 1459 throw(uno::RuntimeException) 1460 { 1461 vos::OGuard aGuard(Application::GetSolarMutex()); 1462 static uno::Sequence< sal_Int8 > aId( 16 ); 1463 static sal_Bool bInit = sal_False; 1464 if(!bInit) 1465 { 1466 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True ); 1467 bInit = sal_True; 1468 } 1469 return aId; 1470 } 1471 1472 1473 // 1474 //===== XAccesibleText =================================================== 1475 // 1476 1477 sal_Int32 SwAccessibleParagraph::getCaretPosition() 1478 throw (uno::RuntimeException) 1479 { 1480 vos::OGuard aGuard(Application::GetSolarMutex()); 1481 1482 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 1483 1484 sal_Int32 nRet = GetCaretPos(); 1485 { 1486 vos::OGuard aOldCaretPosGuard( aMutex ); 1487 ASSERT( nRet == nOldCaretPos, "caret pos out of sync" ); 1488 nOldCaretPos = nRet; 1489 } 1490 if( -1 != nRet ) 1491 { 1492 ::vos::ORef < SwAccessibleContext > xThis( this ); 1493 GetMap()->SetCursorContext( xThis ); 1494 } 1495 1496 return nRet; 1497 } 1498 1499 sal_Bool SAL_CALL SwAccessibleParagraph::setCaretPosition( sal_Int32 nIndex ) 1500 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1501 { 1502 vos::OGuard aGuard(Application::GetSolarMutex()); 1503 1504 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 1505 1506 // parameter checking 1507 sal_Int32 nLength = GetString().getLength(); 1508 if ( ! IsValidPosition( nIndex, nLength ) ) 1509 { 1510 throw lang::IndexOutOfBoundsException(); 1511 } 1512 1513 sal_Bool bRet = sal_False; 1514 1515 // get cursor shell 1516 SwCrsrShell* pCrsrShell = GetCrsrShell(); 1517 if( pCrsrShell != NULL ) 1518 { 1519 // create pam for selection 1520 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 1521 SwIndex aIndex( pNode, GetPortionData().GetModelPosition(nIndex)); 1522 SwPosition aStartPos( *pNode, aIndex ); 1523 SwPaM aPaM( aStartPos ); 1524 1525 // set PaM at cursor shell 1526 bRet = Select( aPaM ); 1527 } 1528 1529 return bRet; 1530 } 1531 1532 sal_Unicode SwAccessibleParagraph::getCharacter( sal_Int32 nIndex ) 1533 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1534 { 1535 vos::OGuard aGuard(Application::GetSolarMutex()); 1536 1537 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 1538 1539 ::rtl::OUString sText( GetString() ); 1540 1541 // return character (if valid) 1542 if( IsValidChar(nIndex, sText.getLength() ) ) 1543 { 1544 return sText.getStr()[nIndex]; 1545 } 1546 else 1547 throw lang::IndexOutOfBoundsException(); 1548 } 1549 1550 com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop > SwAccessibleParagraph::GetCurrentTabStop( sal_Int32 nIndex ) 1551 { 1552 vos::OGuard aGuard(Application::GetSolarMutex()); 1553 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 1554 1555 1556 1557 /* #i12332# The position after the string needs special treatment. 1558 IsValidChar -> IsValidPosition 1559 */ 1560 if( ! (IsValidPosition( nIndex, GetString().getLength() ) ) ) 1561 throw lang::IndexOutOfBoundsException(); 1562 1563 /* #i12332# */ 1564 sal_Bool bBehindText = sal_False; 1565 if ( nIndex == GetString().getLength() ) 1566 bBehindText = sal_True; 1567 1568 // get model position & prepare GetCharRect() arguments 1569 SwCrsrMoveState aMoveState; 1570 aMoveState.bRealHeight = sal_True; 1571 aMoveState.bRealWidth = sal_True; 1572 SwSpecialPos aSpecialPos; 1573 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 1574 1575 sal_uInt16 nPos = 0; 1576 1577 /* #i12332# FillSpecialPos does not accept nIndex == 1578 GetString().getLength(). In that case nPos is set to the 1579 length of the string in the core. This way GetCharRect 1580 returns the rectangle for a cursor at the end of the 1581 paragraph. */ 1582 if (bBehindText) 1583 { 1584 nPos = pNode->GetTxt().Len(); 1585 } 1586 else 1587 nPos = GetPortionData().FillSpecialPos 1588 (nIndex, aSpecialPos, aMoveState.pSpecialPos ); 1589 1590 // call GetCharRect 1591 SwRect aCoreRect; 1592 SwIndex aIndex( pNode, nPos ); 1593 SwPosition aPosition( *pNode, aIndex ); 1594 GetFrm()->GetCharRect( aCoreRect, aPosition, &aMoveState ); 1595 1596 // already get the caret postion 1597 1598 /*SwFrm* pTFrm = const_cast<SwFrm*>(GetFrm()); 1599 com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop > tabs = 1600 pTFrm->GetTabStopInfo(aCoreRect.Left());*/ 1601 1602 com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop > tabs; 1603 const xub_StrLen nStrLen = GetTxtNode()->GetTxt().Len(); 1604 if( nStrLen > 0 ) 1605 { 1606 SwFrm* pTFrm = const_cast<SwFrm*>(GetFrm()); 1607 tabs = pTFrm->GetTabStopInfo(aCoreRect.Left()); 1608 } 1609 1610 if( tabs.hasElements() ) 1611 { 1612 // translate core coordinates into accessibility coordinates 1613 Window *pWin = GetWindow(); 1614 CHECK_FOR_WINDOW( XAccessibleComponent, pWin ); 1615 1616 SwRect aTmpRect(0, 0, tabs[0].Position, 0); 1617 1618 Rectangle aScreenRect( GetMap()->CoreToPixel( aTmpRect.SVRect() )); 1619 SwRect aFrmLogBounds( GetBounds( *(GetMap()) ) ); // twip rel to doc root 1620 1621 Point aFrmPixPos( GetMap()->CoreToPixel( aFrmLogBounds.SVRect() ).TopLeft() ); 1622 aScreenRect.Move( -aFrmPixPos.X(), -aFrmPixPos.Y() ); 1623 1624 tabs[0].Position = aScreenRect.GetWidth(); 1625 } 1626 1627 return tabs; 1628 } 1629 1630 struct IndexCompare 1631 { 1632 const PropertyValue* pValues; 1633 IndexCompare( const PropertyValue* pVals ) : pValues(pVals) {} 1634 bool operator() ( const sal_Int32& a, const sal_Int32& b ) const 1635 { 1636 return (pValues[a].Name < pValues[b].Name) ? true : false; 1637 } 1638 }; 1639 1640 String SwAccessibleParagraph::GetFieldTypeNameAtIndex(sal_Int32 nIndex) 1641 { 1642 String strTypeName; 1643 SwFldMgr aMgr; 1644 SwTxtFld* pTxtFld = NULL; 1645 SwTxtNode* pTxtNd = const_cast<SwTxtNode*>( GetTxtNode() ); 1646 SwIndex fldIndex( pTxtNd, nIndex ); 1647 sal_Int32 nFldIndex = GetPortionData().GetFieldIndex(nIndex); 1648 if (nFldIndex >= 0) 1649 { 1650 const SwpHints* pSwpHints = GetTxtNode()->GetpSwpHints(); 1651 if (pSwpHints) 1652 { 1653 const sal_uInt16 nSize = pSwpHints ? pSwpHints->Count() : 0; 1654 for( sal_uInt16 i = 0; i < nSize; ++i ) 1655 { 1656 const SwTxtAttr* pHt = (*pSwpHints)[i]; 1657 if ( ( pHt->Which() == RES_TXTATR_FIELD 1658 || pHt->Which() == RES_TXTATR_ANNOTATION 1659 || pHt->Which() == RES_TXTATR_INPUTFIELD ) 1660 && (nFldIndex-- == 0)) 1661 { 1662 pTxtFld = (SwTxtFld *)pHt; 1663 break; 1664 } 1665 else if ( pHt->Which() == RES_TXTATR_REFMARK 1666 && (nFldIndex-- == 0) ) 1667 strTypeName = String(OUString(RTL_CONSTASCII_USTRINGPARAM("set reference"))); 1668 } 1669 } 1670 } 1671 if (pTxtFld) 1672 { 1673 const SwField* pField = (pTxtFld->GetFmtFld()).GetField(); 1674 if (pField) 1675 { 1676 strTypeName = pField->GetTyp()->GetTypeStr(pField->GetTypeId()); 1677 sal_uInt16 nWhich = pField->GetTyp()->Which(); 1678 rtl::OUString sEntry; 1679 sal_Int32 subType = 0; 1680 switch (nWhich) 1681 { 1682 case RES_DOCSTATFLD: 1683 subType = ((SwDocStatField*)pField)->GetSubType(); 1684 break; 1685 case RES_GETREFFLD: 1686 { 1687 sal_uInt16 nSub = pField->GetSubType(); 1688 switch( nSub ) 1689 { 1690 case REF_BOOKMARK: 1691 { 1692 const SwGetRefField* pRefFld = dynamic_cast<const SwGetRefField*>(pField); 1693 if ( pRefFld && pRefFld->IsRefToHeadingCrossRefBookmark() ) 1694 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Headings")); 1695 else if ( pRefFld && pRefFld->IsRefToNumItemCrossRefBookmark() ) 1696 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Numbered Paragraphs")); 1697 else 1698 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Bookmarks")); 1699 } 1700 break; 1701 case REF_FOOTNOTE: 1702 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Footnotes")); 1703 break; 1704 case REF_ENDNOTE: 1705 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Endnotes")); 1706 break; 1707 case REF_SETREFATTR: 1708 sEntry = OUString(RTL_CONSTASCII_USTRINGPARAM("Insert Reference")); 1709 break; 1710 case REF_SEQUENCEFLD: 1711 sEntry = ((SwGetRefField*)pField)->GetSetRefName(); 1712 break; 1713 } 1714 //Get format string 1715 strTypeName = sEntry; 1716 // <pField->GetFormat() >= 0> is always true as <pField->GetFormat()> is unsigned 1717 // if (pField->GetFormat() >= 0) 1718 { 1719 sEntry = aMgr.GetFormatStr( pField->GetTypeId(), pField->GetFormat() ); 1720 if (sEntry.getLength() > 0) 1721 { 1722 strTypeName.AppendAscii("-"); 1723 strTypeName += String(sEntry); 1724 } 1725 } 1726 } 1727 break; 1728 case RES_DATETIMEFLD: 1729 subType = ((SwDateTimeField*)pField)->GetSubType(); 1730 break; 1731 case RES_JUMPEDITFLD: 1732 { 1733 sal_uInt16 nFormat= pField->GetFormat(); 1734 sal_uInt16 nSize = aMgr.GetFormatCount(pField->GetTypeId(), sal_False); 1735 if (nFormat < nSize) 1736 { 1737 sEntry = aMgr.GetFormatStr(pField->GetTypeId(), nFormat); 1738 if (sEntry.getLength() > 0) 1739 { 1740 strTypeName.AppendAscii("-"); 1741 strTypeName += String(sEntry); 1742 } 1743 } 1744 } 1745 break; 1746 case RES_EXTUSERFLD: 1747 subType = ((SwExtUserField*)pField)->GetSubType(); 1748 break; 1749 case RES_HIDDENTXTFLD: 1750 case RES_SETEXPFLD: 1751 { 1752 sEntry = pField->GetTyp()->GetName(); 1753 if (sEntry.getLength() > 0) 1754 { 1755 strTypeName.AppendAscii("-"); 1756 strTypeName += String(sEntry); 1757 } 1758 } 1759 break; 1760 case RES_DOCINFOFLD: 1761 subType = pField->GetSubType(); 1762 subType &= 0x00ff; 1763 break; 1764 case RES_REFPAGESETFLD: 1765 { 1766 SwRefPageSetField* pRPld = (SwRefPageSetField*)pField; 1767 sal_Bool bOn = pRPld->IsOn(); 1768 strTypeName.AppendAscii("-"); 1769 if (bOn) 1770 strTypeName += String(OUString(RTL_CONSTASCII_USTRINGPARAM("on"))); 1771 else 1772 strTypeName += String(OUString(RTL_CONSTASCII_USTRINGPARAM("off"))); 1773 } 1774 break; 1775 case RES_AUTHORFLD: 1776 { 1777 strTypeName.AppendAscii("-"); 1778 strTypeName += aMgr.GetFormatStr(pField->GetTypeId(), pField->GetFormat() & 0xff); 1779 } 1780 break; 1781 } 1782 if (subType > 0 || (subType == 0 && (nWhich == RES_DOCINFOFLD || nWhich == RES_EXTUSERFLD || nWhich == RES_DOCSTATFLD))) 1783 { 1784 SvStringsDtor aLst; 1785 aMgr.GetSubTypes(pField->GetTypeId(), aLst); 1786 if (subType < aLst.Count()) 1787 sEntry = *aLst[subType]; 1788 if (sEntry.getLength() > 0) 1789 { 1790 if (nWhich == RES_DOCINFOFLD) 1791 { 1792 strTypeName = String(sEntry); 1793 sal_uInt32 nSize = aMgr.GetFormatCount(pField->GetTypeId(), sal_False); 1794 sal_uInt16 nExSub = pField->GetSubType() & 0xff00; 1795 if (nSize > 0 && nExSub > 0) 1796 { 1797 //Get extra subtype string 1798 strTypeName.AppendAscii("-"); 1799 sEntry = aMgr.GetFormatStr(pField->GetTypeId(), nExSub/0x0100-1); 1800 strTypeName += String(sEntry); 1801 } 1802 } 1803 else 1804 { 1805 strTypeName.AppendAscii("-"); 1806 strTypeName += String(sEntry); 1807 } 1808 } 1809 } 1810 } 1811 } 1812 return strTypeName; 1813 } 1814 // --> OD 2006-07-20 #i63870# 1815 // re-implement method on behalf of methods <_getDefaultAttributesImpl(..)> and 1816 // <_getRunAttributesImpl(..)> 1817 uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( 1818 sal_Int32 nIndex, 1819 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) 1820 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 1821 { 1822 1823 vos::OGuard aGuard(Application::GetSolarMutex()); 1824 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 1825 1826 const ::rtl::OUString& rText = GetString(); 1827 1828 if( ! IsValidChar( nIndex, rText.getLength()+1 ) ) 1829 throw lang::IndexOutOfBoundsException(); 1830 1831 bool bSupplementalMode = false; 1832 uno::Sequence< ::rtl::OUString > aNames = aRequestedAttributes; 1833 if (aNames.getLength() == 0) 1834 { 1835 bSupplementalMode = true; 1836 aNames = getAttributeNames(); 1837 } 1838 // retrieve default character attributes 1839 tAccParaPropValMap aDefAttrSeq; 1840 _getDefaultAttributesImpl( aNames, aDefAttrSeq, true ); 1841 1842 // retrieved run character attributes 1843 tAccParaPropValMap aRunAttrSeq; 1844 _getRunAttributesImpl( nIndex, aNames, aRunAttrSeq ); 1845 1846 // merge default and run attributes 1847 uno::Sequence< PropertyValue > aValues( aDefAttrSeq.size() ); 1848 PropertyValue* pValues = aValues.getArray(); 1849 sal_Int32 i = 0; 1850 for ( tAccParaPropValMap::const_iterator aDefIter = aDefAttrSeq.begin(); 1851 aDefIter != aDefAttrSeq.end(); 1852 ++aDefIter ) 1853 { 1854 tAccParaPropValMap::const_iterator aRunIter = 1855 aRunAttrSeq.find( aDefIter->first ); 1856 if ( aRunIter != aRunAttrSeq.end() ) 1857 { 1858 pValues[i] = aRunIter->second; 1859 } 1860 else 1861 { 1862 pValues[i] = aDefIter->second; 1863 } 1864 ++i; 1865 } 1866 if( bSupplementalMode ) 1867 { 1868 uno::Sequence< ::rtl::OUString > aSupplementalNames = aRequestedAttributes; 1869 if (aSupplementalNames.getLength() == 0) 1870 aSupplementalNames = getSupplementalAttributeNames(); 1871 1872 tAccParaPropValMap aSupplementalAttrSeq; 1873 _getSupplementalAttributesImpl( nIndex, aSupplementalNames, aSupplementalAttrSeq ); 1874 1875 aValues.realloc( aValues.getLength() + aSupplementalAttrSeq.size() ); 1876 pValues = aValues.getArray(); 1877 1878 for ( tAccParaPropValMap::const_iterator aSupplementalIter = aSupplementalAttrSeq.begin(); 1879 aSupplementalIter != aSupplementalAttrSeq.end(); 1880 ++aSupplementalIter ) 1881 { 1882 pValues[i] = aSupplementalIter->second; 1883 ++i; 1884 } 1885 1886 _correctValues( nIndex, aValues ); 1887 1888 aValues.realloc( aValues.getLength() + 1 ); 1889 1890 pValues = aValues.getArray(); 1891 1892 const SwTxtNode* pTxtNode( GetTxtNode() ); 1893 PropertyValue& rValue = pValues[aValues.getLength() - 1 ]; 1894 rValue.Name = OUString::createFromAscii("NumberingPrefix"); 1895 OUString sNumBullet = pTxtNode->GetNumString(); 1896 rValue.Value <<= sNumBullet; 1897 rValue.Handle = -1; 1898 rValue.State = PropertyState_DIRECT_VALUE; 1899 1900 String strTypeName = GetFieldTypeNameAtIndex(nIndex); 1901 if (strTypeName.Len() > 0) 1902 { 1903 aValues.realloc( aValues.getLength() + 1 ); 1904 pValues = aValues.getArray(); 1905 rValue = pValues[aValues.getLength() - 1]; 1906 rValue.Name = OUString::createFromAscii("FieldType"); 1907 rValue.Value <<= rtl::OUString(strTypeName.ToLowerAscii()); 1908 rValue.Handle = -1; 1909 rValue.State = PropertyState_DIRECT_VALUE; 1910 } 1911 1912 //sort property values 1913 // build sorted index array 1914 sal_Int32 nLength = aValues.getLength(); 1915 const PropertyValue* pPairs = aValues.getConstArray(); 1916 sal_Int32* pIndices = new sal_Int32[nLength]; 1917 for( i = 0; i < nLength; i++ ) 1918 pIndices[i] = i; 1919 sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); 1920 // create sorted sequences accoring to index array 1921 uno::Sequence<PropertyValue> aNewValues( nLength ); 1922 PropertyValue* pNewValues = aNewValues.getArray(); 1923 for( i = 0; i < nLength; i++ ) 1924 { 1925 pNewValues[i] = pPairs[pIndices[i]]; 1926 } 1927 delete[] pIndices; 1928 return aNewValues; 1929 } 1930 1931 // // create a (dummy) text portion for the sole purpose of calling 1932 // // getPropertyValues on it 1933 // Reference<XMultiPropertySet> xPortion = CreateUnoPortion( nIndex, nIndex + 1 ); 1934 1935 // // get values 1936 // Sequence<OUString> aNames = getAttributeNames(); 1937 // sal_Int32 nLength = aNames.getLength(); 1938 // Sequence<Any> aAnys( nLength ); 1939 // aAnys = xPortion->getPropertyValues( aNames ); 1940 1941 // // copy names + anys into return sequence 1942 // Sequence<PropertyValue> aValues( aNames.getLength() ); 1943 // const OUString* pNames = aNames.getConstArray(); 1944 // const Any* pAnys = aAnys.getConstArray(); 1945 // PropertyValue* pValues = aValues.getArray(); 1946 // for( sal_Int32 i = 0; i < nLength; i++ ) 1947 // { 1948 // PropertyValue& rValue = pValues[i]; 1949 // rValue.Name = pNames[i]; 1950 // rValue.Value = pAnys[i]; 1951 // rValue.Handle = -1; // handle not supported 1952 // rValue.State = PropertyState_DIRECT_VALUE; // states not supported 1953 // } 1954 1955 // // adjust background color if we're in a gray portion 1956 // DBG_ASSERT( pValues[CHAR_BACK_COLOR_POS].Name. 1957 // equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("CharBackColor")), 1958 // "Please adjust CHAR_BACK_COLOR_POS constant." ); 1959 // if( GetPortionData().IsInGrayPortion( nIndex ) ) 1960 // pValues[CHAR_BACK_COLOR_POS].Value <<= SwViewOption::GetFieldShadingsColor().GetColor(); 1961 1962 return aValues; 1963 } 1964 1965 // --> OD 2006-07-11 #i63870# 1966 void SwAccessibleParagraph::_getDefaultAttributesImpl( 1967 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes, 1968 tAccParaPropValMap& rDefAttrSeq, 1969 const bool bOnlyCharAttrs ) 1970 { 1971 // retrieve default attributes 1972 const SwTxtNode* pTxtNode( GetTxtNode() ); 1973 ::boost::scoped_ptr<SfxItemSet> pSet; 1974 if ( !bOnlyCharAttrs ) 1975 { 1976 pSet.reset( new SfxItemSet( const_cast<SwAttrPool&>(pTxtNode->GetDoc()->GetAttrPool()), 1977 RES_CHRATR_BEGIN, RES_CHRATR_END - 1, 1978 RES_PARATR_BEGIN, RES_PARATR_END - 1, 1979 RES_FRMATR_BEGIN, RES_FRMATR_END - 1, 1980 0 ) ); 1981 } 1982 else 1983 { 1984 pSet.reset( new SfxItemSet( const_cast<SwAttrPool&>(pTxtNode->GetDoc()->GetAttrPool()), 1985 RES_CHRATR_BEGIN, RES_CHRATR_END - 1, 1986 0 ) ); 1987 } 1988 // --> OD 2007-11-12 #i82637# 1989 // From the perspective of the a11y API the default character attributes 1990 // are the character attributes, which are set at the paragraph style 1991 // of the paragraph. The character attributes set at the automatic paragraph 1992 // style of the paragraph are treated as run attributes. 1993 // pTxtNode->SwCntntNode::GetAttr( *pSet ); 1994 // get default paragraph attributes, if needed, and merge these into <pSet> 1995 if ( !bOnlyCharAttrs ) 1996 { 1997 SfxItemSet aParaSet( const_cast<SwAttrPool&>(pTxtNode->GetDoc()->GetAttrPool()), 1998 RES_PARATR_BEGIN, RES_PARATR_END - 1, 1999 RES_FRMATR_BEGIN, RES_FRMATR_END - 1, 2000 0 ); 2001 pTxtNode->SwCntntNode::GetAttr( aParaSet ); 2002 pSet->Put( aParaSet ); 2003 } 2004 // get default character attributes and merge these into <pSet> 2005 ASSERT( pTxtNode->GetTxtColl(), 2006 "<SwAccessibleParagraph::_getDefaultAttributesImpl(..)> - missing paragraph style. Serious defect, please inform OD!" ); 2007 if ( pTxtNode->GetTxtColl() ) 2008 { 2009 SfxItemSet aCharSet( const_cast<SwAttrPool&>(pTxtNode->GetDoc()->GetAttrPool()), 2010 RES_CHRATR_BEGIN, RES_CHRATR_END - 1, 2011 0 ); 2012 aCharSet.Put( pTxtNode->GetTxtColl()->GetAttrSet() ); 2013 pSet->Put( aCharSet ); 2014 } 2015 // <-- 2016 2017 // build-up sequence containing the run attributes <rDefAttrSeq> 2018 tAccParaPropValMap aDefAttrSeq; 2019 { 2020 const SfxItemPropertyMap* pPropMap = 2021 aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_CURSOR )->getPropertyMap(); 2022 PropertyEntryVector_t aPropertyEntries = pPropMap->getPropertyEntries(); 2023 PropertyEntryVector_t::const_iterator aPropIt = aPropertyEntries.begin(); 2024 while ( aPropIt != aPropertyEntries.end() ) 2025 { 2026 const SfxPoolItem* pItem = pSet->GetItem( aPropIt->nWID ); 2027 if ( pItem ) 2028 { 2029 uno::Any aVal; 2030 pItem->QueryValue( aVal, aPropIt->nMemberId ); 2031 2032 PropertyValue rPropVal; 2033 rPropVal.Name = aPropIt->sName; 2034 rPropVal.Value = aVal; 2035 rPropVal.Handle = -1; 2036 rPropVal.State = beans::PropertyState_DEFAULT_VALUE; 2037 2038 aDefAttrSeq[rPropVal.Name] = rPropVal; 2039 } 2040 ++aPropIt; 2041 } 2042 2043 // --> OD 2007-01-15 #i72800# 2044 // add property value entry for the paragraph style 2045 if ( !bOnlyCharAttrs && pTxtNode->GetTxtColl() ) 2046 { 2047 const ::rtl::OUString sParaStyleName = 2048 ::rtl::OUString::createFromAscii( 2049 GetPropName( UNO_NAME_PARA_STYLE_NAME ).pName ); 2050 if ( aDefAttrSeq.find( sParaStyleName ) == aDefAttrSeq.end() ) 2051 { 2052 PropertyValue rPropVal; 2053 rPropVal.Name = sParaStyleName; 2054 uno::Any aVal( uno::makeAny( ::rtl::OUString( pTxtNode->GetTxtColl()->GetName() ) ) ); 2055 rPropVal.Value = aVal; 2056 rPropVal.Handle = -1; 2057 rPropVal.State = beans::PropertyState_DEFAULT_VALUE; 2058 2059 aDefAttrSeq[rPropVal.Name] = rPropVal; 2060 } 2061 } 2062 // <-- 2063 2064 // --> OD 2007-01-15 #i73371# 2065 // resolve value text::WritingMode2::PAGE of property value entry WritingMode 2066 if ( !bOnlyCharAttrs && GetFrm() ) 2067 { 2068 const ::rtl::OUString sWritingMode = 2069 ::rtl::OUString::createFromAscii( 2070 GetPropName( UNO_NAME_WRITING_MODE ).pName ); 2071 tAccParaPropValMap::iterator aIter = aDefAttrSeq.find( sWritingMode ); 2072 if ( aIter != aDefAttrSeq.end() ) 2073 { 2074 PropertyValue rPropVal( aIter->second ); 2075 sal_Int16 nVal = rPropVal.Value.get<sal_Int16>(); 2076 if ( nVal == text::WritingMode2::PAGE ) 2077 { 2078 const SwFrm* pUpperFrm( GetFrm()->GetUpper() ); 2079 while ( pUpperFrm ) 2080 { 2081 if ( pUpperFrm->GetType() & 2082 ( FRM_PAGE | FRM_FLY | FRM_SECTION | FRM_TAB | FRM_CELL ) ) 2083 { 2084 if ( pUpperFrm->IsVertical() ) 2085 { 2086 nVal = text::WritingMode2::TB_RL; 2087 } 2088 else if ( pUpperFrm->IsRightToLeft() ) 2089 { 2090 nVal = text::WritingMode2::RL_TB; 2091 } 2092 else 2093 { 2094 nVal = text::WritingMode2::LR_TB; 2095 } 2096 rPropVal.Value <<= nVal; 2097 aDefAttrSeq[rPropVal.Name] = rPropVal; 2098 break; 2099 } 2100 2101 if ( dynamic_cast<const SwFlyFrm*>(pUpperFrm) ) 2102 { 2103 pUpperFrm = dynamic_cast<const SwFlyFrm*>(pUpperFrm)->GetAnchorFrm(); 2104 } 2105 else 2106 { 2107 pUpperFrm = pUpperFrm->GetUpper(); 2108 } 2109 } 2110 } 2111 } 2112 } 2113 // <-- 2114 } 2115 2116 if ( aRequestedAttributes.getLength() == 0 ) 2117 { 2118 rDefAttrSeq = aDefAttrSeq; 2119 } 2120 else 2121 { 2122 const ::rtl::OUString* pReqAttrs = aRequestedAttributes.getConstArray(); 2123 const sal_Int32 nLength = aRequestedAttributes.getLength(); 2124 for( sal_Int32 i = 0; i < nLength; ++i ) 2125 { 2126 tAccParaPropValMap::const_iterator const aIter = aDefAttrSeq.find( pReqAttrs[i] ); 2127 if ( aIter != aDefAttrSeq.end() ) 2128 { 2129 rDefAttrSeq[ aIter->first ] = aIter->second; 2130 } 2131 } 2132 } 2133 } 2134 2135 uno::Sequence< PropertyValue > SwAccessibleParagraph::getDefaultAttributes( 2136 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) 2137 throw ( uno::RuntimeException ) 2138 { 2139 vos::OGuard aGuard(Application::GetSolarMutex()); 2140 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2141 2142 tAccParaPropValMap aDefAttrSeq; 2143 _getDefaultAttributesImpl( aRequestedAttributes, aDefAttrSeq ); 2144 2145 // --> OD 2010-03-08 #i92233# 2146 static rtl::OUString sMMToPixelRatio( rtl::OUString::createFromAscii( "MMToPixelRatio" ) ); 2147 bool bProvideMMToPixelRatio( false ); 2148 { 2149 if ( aRequestedAttributes.getLength() == 0 ) 2150 { 2151 bProvideMMToPixelRatio = true; 2152 } 2153 else 2154 { 2155 const rtl::OUString* aRequestedAttrIter = 2156 ::std::find( ::comphelper::stl_begin( aRequestedAttributes ), 2157 ::comphelper::stl_end( aRequestedAttributes ), 2158 sMMToPixelRatio ); 2159 if ( aRequestedAttrIter != ::comphelper::stl_end( aRequestedAttributes ) ) 2160 { 2161 bProvideMMToPixelRatio = true; 2162 } 2163 } 2164 } 2165 // <-- 2166 2167 uno::Sequence< PropertyValue > aValues( aDefAttrSeq.size() + 2168 ( bProvideMMToPixelRatio ? 1 : 0 ) ); 2169 PropertyValue* pValues = aValues.getArray(); 2170 sal_Int32 i = 0; 2171 for ( tAccParaPropValMap::const_iterator aIter = aDefAttrSeq.begin(); 2172 aIter != aDefAttrSeq.end(); 2173 ++aIter ) 2174 { 2175 pValues[i] = aIter->second; 2176 ++i; 2177 } 2178 2179 // --> OD 2010-03-08 #i92233# 2180 if ( bProvideMMToPixelRatio ) 2181 { 2182 PropertyValue rPropVal; 2183 rPropVal.Name = sMMToPixelRatio; 2184 const Size a100thMMSize( 1000, 1000 ); 2185 const Size aPixelSize = GetMap()->LogicToPixel( a100thMMSize ); 2186 const float fRatio = ((float)a100thMMSize.Width()/100)/aPixelSize.Width(); 2187 rPropVal.Value = uno::makeAny( fRatio ); 2188 rPropVal.Handle = -1; 2189 rPropVal.State = beans::PropertyState_DEFAULT_VALUE; 2190 pValues[ aValues.getLength() - 1 ] = rPropVal; 2191 } 2192 // <-- 2193 2194 return aValues; 2195 } 2196 2197 void SwAccessibleParagraph::_getRunAttributesImpl( 2198 const sal_Int32 nIndex, 2199 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes, 2200 tAccParaPropValMap& rRunAttrSeq ) 2201 { 2202 // create PaM for character at position <nIndex> 2203 SwPaM* pPaM( 0 ); 2204 { 2205 const SwTxtNode* pTxtNode( GetTxtNode() ); 2206 SwPosition* pStartPos = new SwPosition( *pTxtNode ); 2207 pStartPos->nContent.Assign( const_cast<SwTxtNode*>(pTxtNode), static_cast<sal_uInt16>(nIndex) ); 2208 SwPosition* pEndPos = new SwPosition( *pTxtNode ); 2209 pEndPos->nContent.Assign( const_cast<SwTxtNode*>(pTxtNode), static_cast<sal_uInt16>(nIndex+1) ); 2210 2211 pPaM = new SwPaM( *pStartPos, *pEndPos ); 2212 2213 delete pStartPos; 2214 delete pEndPos; 2215 } 2216 2217 // retrieve character attributes for the created PaM <pPaM> 2218 SfxItemSet aSet( pPaM->GetDoc()->GetAttrPool(), 2219 RES_CHRATR_BEGIN, RES_CHRATR_END -1, 2220 0 ); 2221 // --> OD 2007-11-12 #i82637# 2222 // From the perspective of the a11y API the character attributes, which 2223 // are set at the automatic paragraph style of the paragraph are treated 2224 // as run attributes. 2225 // SwXTextCursor::GetCrsrAttr( *pPaM, aSet, sal_True, sal_True ); 2226 // get character attributes from automatic paragraph style and merge these into <aSet> 2227 { 2228 const SwTxtNode* pTxtNode( GetTxtNode() ); 2229 if ( pTxtNode->HasSwAttrSet() ) 2230 { 2231 SfxItemSet aAutomaticParaStyleCharAttrs( pPaM->GetDoc()->GetAttrPool(), 2232 RES_CHRATR_BEGIN, RES_CHRATR_END -1, 2233 0 ); 2234 aAutomaticParaStyleCharAttrs.Put( *(pTxtNode->GetpSwAttrSet()), sal_False ); 2235 aSet.Put( aAutomaticParaStyleCharAttrs ); 2236 } 2237 } 2238 // get character attributes at <pPaM> and merge these into <aSet> 2239 { 2240 SfxItemSet aCharAttrsAtPaM( pPaM->GetDoc()->GetAttrPool(), 2241 RES_CHRATR_BEGIN, RES_CHRATR_END -1, 2242 0 ); 2243 SwUnoCursorHelper::GetCrsrAttr(*pPaM, aCharAttrsAtPaM, sal_True, sal_True); 2244 aSet.Put( aCharAttrsAtPaM ); 2245 } 2246 // <-- 2247 2248 // build-up sequence containing the run attributes <rRunAttrSeq> 2249 { 2250 tAccParaPropValMap aRunAttrSeq; 2251 { 2252 // --> OD 2007-11-12 #i82637# 2253 tAccParaPropValMap aDefAttrSeq; 2254 uno::Sequence< ::rtl::OUString > aDummy; 2255 _getDefaultAttributesImpl( aDummy, aDefAttrSeq, true ); 2256 // <-- 2257 2258 const SfxItemPropertyMap* pPropMap = 2259 aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_CURSOR )->getPropertyMap(); 2260 PropertyEntryVector_t aPropertyEntries = pPropMap->getPropertyEntries(); 2261 PropertyEntryVector_t::const_iterator aPropIt = aPropertyEntries.begin(); 2262 while ( aPropIt != aPropertyEntries.end() ) 2263 { 2264 const SfxPoolItem* pItem( 0 ); 2265 // --> OD 2007-11-12 #i82637# 2266 // Found character attributes, whose value equals the value of 2267 // the corresponding default character attributes, are excluded. 2268 if ( aSet.GetItemState( aPropIt->nWID, sal_True, &pItem ) == SFX_ITEM_SET ) 2269 { 2270 uno::Any aVal; 2271 pItem->QueryValue( aVal, aPropIt->nMemberId ); 2272 2273 PropertyValue rPropVal; 2274 rPropVal.Name = aPropIt->sName; 2275 rPropVal.Value = aVal; 2276 rPropVal.Handle = -1; 2277 rPropVal.State = PropertyState_DIRECT_VALUE; 2278 2279 tAccParaPropValMap::const_iterator aDefIter = 2280 aDefAttrSeq.find( rPropVal.Name ); 2281 if ( aDefIter == aDefAttrSeq.end() || 2282 rPropVal.Value != aDefIter->second.Value ) 2283 { 2284 aRunAttrSeq[rPropVal.Name] = rPropVal; 2285 } 2286 } 2287 2288 ++aPropIt; 2289 } 2290 } 2291 2292 if ( aRequestedAttributes.getLength() == 0 ) 2293 { 2294 rRunAttrSeq = aRunAttrSeq; 2295 } 2296 else 2297 { 2298 const ::rtl::OUString* pReqAttrs = aRequestedAttributes.getConstArray(); 2299 const sal_Int32 nLength = aRequestedAttributes.getLength(); 2300 for( sal_Int32 i = 0; i < nLength; ++i ) 2301 { 2302 tAccParaPropValMap::iterator aIter = aRunAttrSeq.find( pReqAttrs[i] ); 2303 if ( aIter != aRunAttrSeq.end() ) 2304 { 2305 rRunAttrSeq[ (*aIter).first ] = (*aIter).second; 2306 } 2307 } 2308 } 2309 } 2310 2311 delete pPaM; 2312 } 2313 2314 uno::Sequence< PropertyValue > SwAccessibleParagraph::getRunAttributes( 2315 sal_Int32 nIndex, 2316 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) 2317 throw ( lang::IndexOutOfBoundsException, 2318 uno::RuntimeException ) 2319 { 2320 vos::OGuard aGuard(Application::GetSolarMutex()); 2321 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2322 2323 { 2324 const ::rtl::OUString& rText = GetString(); 2325 if ( !IsValidChar( nIndex, rText.getLength() ) ) 2326 { 2327 throw lang::IndexOutOfBoundsException(); 2328 } 2329 } 2330 2331 tAccParaPropValMap aRunAttrSeq; 2332 _getRunAttributesImpl( nIndex, aRequestedAttributes, aRunAttrSeq ); 2333 2334 uno::Sequence< PropertyValue > aValues( aRunAttrSeq.size() ); 2335 PropertyValue* pValues = aValues.getArray(); 2336 sal_Int32 i = 0; 2337 for ( tAccParaPropValMap::const_iterator aIter = aRunAttrSeq.begin(); 2338 aIter != aRunAttrSeq.end(); 2339 ++aIter ) 2340 { 2341 pValues[i] = aIter->second; 2342 ++i; 2343 } 2344 2345 return aValues; 2346 } 2347 // <-- 2348 void SwAccessibleParagraph::_getSupplementalAttributesImpl( 2349 const sal_Int32, 2350 const uno::Sequence< ::rtl::OUString >& aRequestedAttributes, 2351 tAccParaPropValMap& rSupplementalAttrSeq ) 2352 { 2353 const SwTxtNode* pTxtNode( GetTxtNode() ); 2354 ::boost::scoped_ptr<SfxItemSet> pSet; 2355 pSet.reset( new SfxItemSet( const_cast<SwAttrPool&>(pTxtNode->GetDoc()->GetAttrPool()), 2356 RES_PARATR_ADJUST, RES_PARATR_ADJUST, 2357 RES_PARATR_TABSTOP, RES_PARATR_TABSTOP, 2358 RES_PARATR_LINESPACING, RES_PARATR_LINESPACING, 2359 RES_UL_SPACE, RES_UL_SPACE, 2360 RES_LR_SPACE, RES_LR_SPACE, 2361 RES_PARATR_NUMRULE, RES_PARATR_NUMRULE, 2362 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1, 2363 0 ) ); 2364 2365 if ( pTxtNode->HasBullet() || pTxtNode->HasNumber() ) 2366 { 2367 pSet->Put( pTxtNode->GetAttr(RES_PARATR_LIST_LEVEL, RES_PARATR_LIST_LEVEL) ); 2368 } 2369 pSet->Put( pTxtNode->SwCntntNode::GetAttr(RES_UL_SPACE) ); 2370 pSet->Put( pTxtNode->SwCntntNode::GetAttr(RES_LR_SPACE) ); 2371 pSet->Put( pTxtNode->SwCntntNode::GetAttr(RES_PARATR_ADJUST) ); 2372 2373 tAccParaPropValMap aSupplementalAttrSeq; 2374 { 2375 // const SfxItemPropertySet& rPropSet = 2376 // aSwMapProvider.GetPropertyMap( PROPERTY_MAP_ACCESSIBILITY_TEXT_ATTRIBUTE ); 2377 // const SfxItemPropertyMap* pPropMap( rPropSet.getPropertyMap() ); 2378 const SfxItemPropertyMapEntry* pPropMap( 2379 aSwMapProvider.GetPropertyMapEntries( PROPERTY_MAP_ACCESSIBILITY_TEXT_ATTRIBUTE ) ); 2380 while ( pPropMap->pName ) 2381 { 2382 const SfxPoolItem* pItem = pSet->GetItem( pPropMap->nWID ); 2383 if ( pItem ) 2384 { 2385 uno::Any aVal; 2386 pItem->QueryValue( aVal, pPropMap->nMemberId ); 2387 2388 PropertyValue rPropVal; 2389 rPropVal.Name = OUString::createFromAscii( pPropMap->pName ); 2390 rPropVal.Value = aVal; 2391 rPropVal.Handle = -1; 2392 rPropVal.State = beans::PropertyState_DEFAULT_VALUE; 2393 2394 aSupplementalAttrSeq[rPropVal.Name] = rPropVal; 2395 } 2396 2397 ++pPropMap; 2398 } 2399 } 2400 2401 const OUString* pSupplementalAttrs = aRequestedAttributes.getConstArray(); 2402 const sal_Int32 nSupplementalLength = aRequestedAttributes.getLength(); 2403 2404 for( sal_Int32 index = 0; index < nSupplementalLength; ++index ) 2405 { 2406 tAccParaPropValMap::const_iterator const aIter = aSupplementalAttrSeq.find( pSupplementalAttrs[index] ); 2407 if ( aIter != aSupplementalAttrSeq.end() ) 2408 { 2409 rSupplementalAttrSeq[ aIter->first ] = aIter->second; 2410 } 2411 } 2412 } 2413 2414 void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex, 2415 uno::Sequence< PropertyValue >& rValues) 2416 { 2417 PropertyValue ChangeAttr, ChangeAttrColor; 2418 2419 const SwRedline* pRedline = GetRedlineAtIndex( nIndex ); 2420 if ( pRedline ) 2421 { 2422 2423 const SwModuleOptions *pOpt = SW_MOD()->GetModuleConfig(); 2424 AuthorCharAttr aChangeAttr; 2425 if ( pOpt ) 2426 { 2427 switch( pRedline->GetType()) 2428 { 2429 case nsRedlineType_t::REDLINE_INSERT: 2430 aChangeAttr = pOpt->GetInsertAuthorAttr(); 2431 break; 2432 case nsRedlineType_t::REDLINE_DELETE: 2433 aChangeAttr = pOpt->GetDeletedAuthorAttr(); 2434 break; 2435 case nsRedlineType_t::REDLINE_FORMAT: 2436 aChangeAttr = pOpt->GetFormatAuthorAttr(); 2437 break; 2438 } 2439 } 2440 switch( aChangeAttr.nItemId ) 2441 { 2442 case SID_ATTR_CHAR_WEIGHT: 2443 ChangeAttr.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_WEIGHT).pName ); 2444 ChangeAttr.Value <<= awt::FontWeight::BOLD; 2445 break; 2446 case SID_ATTR_CHAR_POSTURE: 2447 ChangeAttr.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_POSTURE).pName ); 2448 ChangeAttr.Value <<= awt::FontSlant_ITALIC; //char posture 2449 break; 2450 case SID_ATTR_CHAR_STRIKEOUT: 2451 ChangeAttr.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_STRIKEOUT).pName ); 2452 ChangeAttr.Value <<= awt::FontStrikeout::SINGLE; //char strikeout 2453 break; 2454 case SID_ATTR_CHAR_UNDERLINE: 2455 ChangeAttr.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_UNDERLINE).pName ); 2456 ChangeAttr.Value <<= aChangeAttr.nAttr; //underline line 2457 break; 2458 } 2459 if( aChangeAttr.nColor != COL_NONE ) 2460 { 2461 if( aChangeAttr.nItemId == SID_ATTR_BRUSH ) 2462 { 2463 ChangeAttrColor.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_BACK_COLOR).pName ); 2464 if( aChangeAttr.nColor == COL_TRANSPARENT )//char backcolor 2465 ChangeAttrColor.Value <<= COL_BLUE; 2466 else 2467 ChangeAttrColor.Value <<= aChangeAttr.nColor; 2468 } 2469 else 2470 { 2471 ChangeAttrColor.Name = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_COLOR ).pName ); 2472 if( aChangeAttr.nColor == COL_TRANSPARENT )//char color 2473 ChangeAttrColor.Value <<= COL_BLUE; 2474 else 2475 ChangeAttrColor.Value <<= aChangeAttr.nColor; 2476 } 2477 } 2478 } 2479 2480 PropertyValue* pValues = rValues.getArray(); 2481 2482 const SwTxtNode* pTxtNode( GetTxtNode() ); 2483 2484 sal_Int32 nValues = rValues.getLength(); 2485 for (sal_Int32 i = 0; i < nValues; ++i) 2486 { 2487 PropertyValue& rValue = pValues[i]; 2488 2489 if (rValue.Name.compareTo( ChangeAttr.Name )==0) 2490 { 2491 rValue.Value = ChangeAttr.Value; 2492 continue; 2493 } 2494 2495 if (rValue.Name.compareTo( ChangeAttrColor.Name )==0) 2496 { 2497 rValue.Value = ChangeAttr.Value; 2498 continue; 2499 } 2500 2501 //back color 2502 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_BACK_COLOR ).pName ) )==0) 2503 { 2504 uno::Any &anyChar = rValue.Value; 2505 sal_uInt32 crBack = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>(anyChar.pReserved)); 2506 if (COL_AUTO == crBack) 2507 { 2508 uno::Reference<XAccessibleComponent> xComponent(this); 2509 if (xComponent.is()) 2510 { 2511 crBack = (sal_uInt32)xComponent->getBackground(); 2512 } 2513 rValue.Value <<= crBack; 2514 } 2515 continue; 2516 } 2517 2518 //char color 2519 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_COLOR ).pName ) )==0) 2520 { 2521 if( GetPortionData().IsInGrayPortion( nIndex ) ) 2522 rValue.Value <<= SwViewOption::GetFieldShadingsColor().GetColor(); 2523 uno::Any &anyChar = rValue.Value; 2524 sal_uInt32 crChar = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>(anyChar.pReserved)); 2525 2526 if( COL_AUTO == crChar ) 2527 { 2528 uno::Reference<XAccessibleComponent> xComponent(this); 2529 if (xComponent.is()) 2530 { 2531 Color cr(xComponent->getBackground()); 2532 crChar = cr.IsDark() ? COL_WHITE : COL_BLACK; 2533 rValue.Value <<= crChar; 2534 } 2535 } 2536 continue; 2537 } 2538 2539 // UnderLine 2540 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_UNDERLINE ).pName ) )==0) 2541 { 2542 //misspelled word 2543 SwCrsrShell* pCrsrShell = GetCrsrShell(); 2544 if( pCrsrShell != NULL && pCrsrShell->GetViewOptions() && pCrsrShell->GetViewOptions()->IsOnlineSpell()) 2545 { 2546 const SwWrongList* pWrongList = pTxtNode->GetWrong(); 2547 if( NULL != pWrongList ) 2548 { 2549 xub_StrLen nBegin = nIndex; 2550 xub_StrLen nLen = 1; 2551 if( pWrongList->InWrongWord(nBegin,nLen) && !pTxtNode->IsSymbol(nBegin) ) 2552 { 2553 rValue.Value <<= (sal_uInt16)UNDERLINE_WAVE; 2554 } 2555 } 2556 } 2557 continue; 2558 } 2559 2560 // UnderLineColor 2561 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_UNDERLINE_COLOR ).pName ) )==0) 2562 { 2563 //misspelled word 2564 SwCrsrShell* pCrsrShell = GetCrsrShell(); 2565 if( pCrsrShell != NULL && pCrsrShell->GetViewOptions() && pCrsrShell->GetViewOptions()->IsOnlineSpell()) 2566 { 2567 const SwWrongList* pWrongList = pTxtNode->GetWrong(); 2568 if( NULL != pWrongList ) 2569 { 2570 xub_StrLen nBegin = nIndex; 2571 xub_StrLen nLen = 1; 2572 if( pWrongList->InWrongWord(nBegin,nLen) && !pTxtNode->IsSymbol(nBegin) ) 2573 { 2574 rValue.Value <<= (sal_Int32)0x00ff0000; 2575 continue; 2576 } 2577 } 2578 } 2579 2580 uno::Any &anyChar = rValue.Value; 2581 sal_uInt32 crUnderline = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>(anyChar.pReserved)); 2582 if ( COL_AUTO == crUnderline ) 2583 { 2584 uno::Reference<XAccessibleComponent> xComponent(this); 2585 if (xComponent.is()) 2586 { 2587 Color cr(xComponent->getBackground()); 2588 crUnderline = cr.IsDark() ? COL_WHITE : COL_BLACK; 2589 rValue.Value <<= crUnderline; 2590 } 2591 } 2592 2593 continue; 2594 } 2595 2596 //tab stop 2597 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_TABSTOPS ).pName ) )==0) 2598 { 2599 com::sun::star::uno::Sequence< ::com::sun::star::style::TabStop > tabs = GetCurrentTabStop( nIndex ); 2600 if( !tabs.hasElements() ) 2601 { 2602 tabs.realloc(1); 2603 ::com::sun::star::style::TabStop ts; 2604 com::sun::star::awt::Rectangle rc0 = getCharacterBounds(0); 2605 com::sun::star::awt::Rectangle rc1 = getCharacterBounds(nIndex); 2606 if( rc1.X - rc0.X >= 48 ) 2607 ts.Position = (rc1.X - rc0.X) - (rc1.X - rc0.X - 48)% 47 + 47; 2608 else 2609 ts.Position = 48; 2610 ts.DecimalChar = ' '; 2611 ts.FillChar = ' '; 2612 ts.Alignment = ::com::sun::star::style::TabAlign_LEFT; 2613 tabs[0] = ts; 2614 } 2615 rValue.Value <<= tabs; 2616 continue; 2617 } 2618 2619 //number bullet 2620 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_NUMBERING_RULES ).pName ) )==0) 2621 { 2622 if ( pTxtNode->HasBullet() || pTxtNode->HasNumber() ) 2623 { 2624 uno::Any aVal; 2625 SwNumRule* pNumRule = pTxtNode->GetNumRule(); 2626 if (pNumRule) 2627 { 2628 uno::Reference< container::XIndexReplace > xNum = new SwXNumberingRules(*pNumRule); 2629 aVal.setValue(&xNum, ::getCppuType((const uno::Reference< container::XIndexReplace >*)0)); 2630 } 2631 rValue.Value <<= aVal; 2632 } 2633 continue; 2634 } 2635 2636 //footnote & endnote 2637 if (rValue.Name.compareTo(::rtl::OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_ESCAPEMENT ).pName ) )==0) 2638 { 2639 if ( GetPortionData().IsIndexInFootnode(nIndex) ) 2640 { 2641 const OUString sEscapmentName = OUString::createFromAscii( GetPropName( UNO_NAME_CHAR_ESCAPEMENT ).pName ); 2642 rValue.Value <<= (sal_Int32)101; 2643 } 2644 continue; 2645 } 2646 } 2647 } 2648 2649 awt::Rectangle SwAccessibleParagraph::getCharacterBounds( 2650 sal_Int32 nIndex ) 2651 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2652 { 2653 vos::OGuard aGuard(Application::GetSolarMutex()); 2654 2655 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2656 2657 2658 /* #i12332# The position after the string needs special treatment. 2659 IsValidChar -> IsValidPosition 2660 */ 2661 if( ! (IsValidPosition( nIndex, GetString().getLength() ) ) ) 2662 throw lang::IndexOutOfBoundsException(); 2663 2664 /* #i12332# */ 2665 sal_Bool bBehindText = sal_False; 2666 if ( nIndex == GetString().getLength() ) 2667 bBehindText = sal_True; 2668 2669 // get model position & prepare GetCharRect() arguments 2670 SwCrsrMoveState aMoveState; 2671 aMoveState.bRealHeight = sal_True; 2672 aMoveState.bRealWidth = sal_True; 2673 SwSpecialPos aSpecialPos; 2674 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 2675 2676 sal_uInt16 nPos = 0; 2677 2678 /* #i12332# FillSpecialPos does not accept nIndex == 2679 GetString().getLength(). In that case nPos is set to the 2680 length of the string in the core. This way GetCharRect 2681 returns the rectangle for a cursor at the end of the 2682 paragraph. */ 2683 if (bBehindText) 2684 { 2685 nPos = pNode->GetTxt().Len(); 2686 } 2687 else 2688 nPos = GetPortionData().FillSpecialPos 2689 (nIndex, aSpecialPos, aMoveState.pSpecialPos ); 2690 2691 // call GetCharRect 2692 SwRect aCoreRect; 2693 SwIndex aIndex( pNode, nPos ); 2694 SwPosition aPosition( *pNode, aIndex ); 2695 GetFrm()->GetCharRect( aCoreRect, aPosition, &aMoveState ); 2696 2697 // translate core coordinates into accessibility coordinates 2698 Window *pWin = GetWindow(); 2699 CHECK_FOR_WINDOW( XAccessibleComponent, pWin ); 2700 2701 Rectangle aScreenRect( GetMap()->CoreToPixel( aCoreRect.SVRect() )); 2702 SwRect aFrmLogBounds( GetBounds( *(GetMap()) ) ); // twip rel to doc root 2703 2704 Point aFrmPixPos( GetMap()->CoreToPixel( aFrmLogBounds.SVRect() ).TopLeft() ); 2705 aScreenRect.Move( -aFrmPixPos.X(), -aFrmPixPos.Y() ); 2706 2707 // convert into AWT Rectangle 2708 return awt::Rectangle( 2709 aScreenRect.Left(), aScreenRect.Top(), 2710 aScreenRect.GetWidth(), aScreenRect.GetHeight() ); 2711 } 2712 2713 sal_Int32 SwAccessibleParagraph::getCharacterCount() 2714 throw (uno::RuntimeException) 2715 { 2716 vos::OGuard aGuard(Application::GetSolarMutex()); 2717 2718 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2719 2720 return GetString().getLength(); 2721 } 2722 2723 sal_Int32 SwAccessibleParagraph::getIndexAtPoint( const awt::Point& rPoint ) 2724 throw (uno::RuntimeException) 2725 { 2726 vos::OGuard aGuard(Application::GetSolarMutex()); 2727 2728 2729 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2730 2731 // construct SwPosition (where GetCrsrOfst() will put the result into) 2732 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 2733 SwIndex aIndex( pNode, 0); 2734 SwPosition aPos( *pNode, aIndex ); 2735 2736 // construct Point (translate into layout coordinates) 2737 Window *pWin = GetWindow(); 2738 CHECK_FOR_WINDOW( XAccessibleComponent, pWin ); 2739 Point aPoint( rPoint.X, rPoint.Y ); 2740 SwRect aLogBounds( GetBounds( *(GetMap()), GetFrm() ) ); // twip rel to doc root 2741 Point aPixPos( GetMap()->CoreToPixel( aLogBounds.SVRect() ).TopLeft() ); 2742 aPoint.X() += aPixPos.X(); 2743 aPoint.Y() += aPixPos.Y(); 2744 MapMode aMapMode = pWin->GetMapMode(); 2745 Point aCorePoint( GetMap()->PixelToCore( aPoint ) ); 2746 if( !aLogBounds.IsInside( aCorePoint ) ) 2747 { 2748 /* #i12332# rPoint is may also be in rectangle returned by 2749 getCharacterBounds(getCharacterCount() */ 2750 2751 awt::Rectangle aRectEndPos = 2752 getCharacterBounds(getCharacterCount()); 2753 2754 if (rPoint.X - aRectEndPos.X >= 0 && 2755 rPoint.X - aRectEndPos.X < aRectEndPos.Width && 2756 rPoint.Y - aRectEndPos.Y >= 0 && 2757 rPoint.Y - aRectEndPos.Y < aRectEndPos.Height) 2758 return getCharacterCount(); 2759 2760 return -1; 2761 } 2762 2763 // ask core for position 2764 DBG_ASSERT( GetFrm() != NULL, "The text frame has vanished!" ); 2765 DBG_ASSERT( GetFrm()->IsTxtFrm(), "The text frame has mutated!" ); 2766 const SwTxtFrm* pFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 2767 SwCrsrMoveState aMoveState; 2768 aMoveState.bPosMatchesBounds = sal_True; 2769 sal_Bool bSuccess = pFrm->GetCrsrOfst( &aPos, aCorePoint, &aMoveState ); 2770 2771 SwIndex aCntntIdx = aPos.nContent; 2772 const xub_StrLen nIndex = aCntntIdx.GetIndex(); 2773 if ( nIndex > 0 ) 2774 { 2775 SwRect aResultRect; 2776 pFrm->GetCharRect( aResultRect, aPos ); 2777 bool bVert = pFrm->IsVertical(); 2778 bool bR2L = pFrm->IsRightToLeft(); 2779 2780 if ( (!bVert && aResultRect.Pos().X() > aCorePoint.X()) || 2781 ( bVert && aResultRect.Pos().Y() > aCorePoint.Y()) || 2782 ( bR2L && aResultRect.Right() < aCorePoint.X()) ) 2783 { 2784 SwIndex aIdxPrev( pNode, nIndex - 1); 2785 SwPosition aPosPrev( *pNode, aIdxPrev ); 2786 SwRect aResultRectPrev; 2787 pFrm->GetCharRect( aResultRectPrev, aPosPrev ); 2788 if ( (!bVert && aResultRectPrev.Pos().X() < aCorePoint.X() && aResultRect.Pos().Y() == aResultRectPrev.Pos().Y()) || 2789 ( bVert && aResultRectPrev.Pos().Y() < aCorePoint.Y() && aResultRect.Pos().X() == aResultRectPrev.Pos().X()) || 2790 ( bR2L && aResultRectPrev.Right() > aCorePoint.X() && aResultRect.Pos().Y() == aResultRectPrev.Pos().Y()) ) 2791 aPos = aPosPrev; 2792 } 2793 } 2794 2795 return bSuccess ? 2796 GetPortionData().GetAccessiblePosition( aPos.nContent.GetIndex() ) 2797 : -1L; 2798 } 2799 2800 ::rtl::OUString SwAccessibleParagraph::getSelectedText() 2801 throw (uno::RuntimeException) 2802 { 2803 vos::OGuard aGuard(Application::GetSolarMutex()); 2804 2805 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2806 2807 sal_Int32 nStart, nEnd; 2808 sal_Bool bSelected = GetSelection( nStart, nEnd ); 2809 return bSelected 2810 ? GetString().copy( nStart, nEnd - nStart ) 2811 : ::rtl::OUString(); 2812 } 2813 2814 sal_Int32 SwAccessibleParagraph::getSelectionStart() 2815 throw (uno::RuntimeException) 2816 { 2817 vos::OGuard aGuard(Application::GetSolarMutex()); 2818 2819 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2820 2821 sal_Int32 nStart, nEnd; 2822 GetSelection( nStart, nEnd ); 2823 return nStart; 2824 } 2825 2826 sal_Int32 SwAccessibleParagraph::getSelectionEnd() 2827 throw (uno::RuntimeException) 2828 { 2829 vos::OGuard aGuard(Application::GetSolarMutex()); 2830 2831 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2832 2833 sal_Int32 nStart, nEnd; 2834 GetSelection( nStart, nEnd ); 2835 return nEnd; 2836 } 2837 2838 sal_Bool SwAccessibleParagraph::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 2839 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2840 { 2841 vos::OGuard aGuard(Application::GetSolarMutex()); 2842 2843 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2844 2845 // parameter checking 2846 sal_Int32 nLength = GetString().getLength(); 2847 if ( ! IsValidRange( nStartIndex, nEndIndex, nLength ) ) 2848 { 2849 throw lang::IndexOutOfBoundsException(); 2850 } 2851 2852 sal_Bool bRet = sal_False; 2853 2854 // get cursor shell 2855 SwCrsrShell* pCrsrShell = GetCrsrShell(); 2856 if( pCrsrShell != NULL ) 2857 { 2858 // create pam for selection 2859 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 2860 SwIndex aIndex( pNode, GetPortionData().GetModelPosition(nStartIndex)); 2861 SwPosition aStartPos( *pNode, aIndex ); 2862 SwPaM aPaM( aStartPos ); 2863 aPaM.SetMark(); 2864 aPaM.GetPoint()->nContent = 2865 GetPortionData().GetModelPosition(nEndIndex); 2866 2867 // set PaM at cursor shell 2868 bRet = Select( aPaM ); 2869 } 2870 2871 return bRet; 2872 } 2873 2874 ::rtl::OUString SwAccessibleParagraph::getText() 2875 throw (uno::RuntimeException) 2876 { 2877 vos::OGuard aGuard(Application::GetSolarMutex()); 2878 2879 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2880 2881 return GetString(); 2882 } 2883 2884 ::rtl::OUString SwAccessibleParagraph::getTextRange( 2885 sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 2886 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 2887 { 2888 vos::OGuard aGuard(Application::GetSolarMutex()); 2889 2890 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2891 2892 ::rtl::OUString sText( GetString() ); 2893 2894 if ( IsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) 2895 { 2896 OrderRange( nStartIndex, nEndIndex ); 2897 return sText.copy(nStartIndex, nEndIndex-nStartIndex ); 2898 } 2899 else 2900 throw lang::IndexOutOfBoundsException(); 2901 } 2902 2903 /*accessibility::*/TextSegment SwAccessibleParagraph::getTextAtIndex( sal_Int32 nIndex, sal_Int16 nTextType ) throw (lang::IndexOutOfBoundsException, lang::IllegalArgumentException, uno::RuntimeException) 2904 { 2905 vos::OGuard aGuard(Application::GetSolarMutex()); 2906 2907 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2908 2909 /*accessibility::*/TextSegment aResult; 2910 aResult.SegmentStart = -1; 2911 aResult.SegmentEnd = -1; 2912 2913 const ::rtl::OUString rText = GetString(); 2914 // implement the silly specification that first position after 2915 // text must return an empty string, rather than throwing an 2916 // IndexOutOfBoundsException, except for LINE, where the last 2917 // line is returned 2918 if( nIndex == rText.getLength() && AccessibleTextType::LINE != nTextType ) 2919 return aResult; 2920 2921 // with error checking 2922 i18n::Boundary aBound; 2923 sal_Bool bWord = GetTextBoundary( aBound, rText, nIndex, nTextType ); 2924 2925 DBG_ASSERT( aBound.startPos >= 0, "illegal boundary" ); 2926 DBG_ASSERT( aBound.startPos <= aBound.endPos, "illegal boundary" ); 2927 2928 // return word (if present) 2929 if ( bWord ) 2930 { 2931 aResult.SegmentText = rText.copy( aBound.startPos, aBound.endPos - aBound.startPos ); 2932 aResult.SegmentStart = aBound.startPos; 2933 aResult.SegmentEnd = aBound.endPos; 2934 } 2935 2936 return aResult; 2937 } 2938 2939 /*accessibility::*/TextSegment SwAccessibleParagraph::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 nTextType ) throw (lang::IndexOutOfBoundsException, lang::IllegalArgumentException, uno::RuntimeException) 2940 { 2941 vos::OGuard aGuard(Application::GetSolarMutex()); 2942 2943 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 2944 2945 const ::rtl::OUString rText = GetString(); 2946 2947 /*accessibility::*/TextSegment aResult; 2948 aResult.SegmentStart = -1; 2949 aResult.SegmentEnd = -1; 2950 //If nIndex = 0, then nobefore text so return -1 directly. 2951 if( nIndex == 0 ) 2952 return aResult; 2953 //Tab will be return when call WORDTYPE 2954 2955 // get starting pos 2956 i18n::Boundary aBound; 2957 if (nIndex == rText.getLength()) 2958 aBound.startPos = aBound.endPos = nIndex; 2959 else 2960 { 2961 sal_Bool bTmp = GetTextBoundary( aBound, rText, nIndex, nTextType ); 2962 2963 if ( ! bTmp ) 2964 aBound.startPos = aBound.endPos = nIndex; 2965 } 2966 2967 // now skip to previous word 2968 if (nTextType==2 || nTextType == 3) 2969 { 2970 i18n::Boundary preBound = aBound; 2971 while(preBound.startPos==aBound.startPos && nIndex > 0) 2972 { 2973 nIndex = min( nIndex, preBound.startPos ) - 1; 2974 if( nIndex < 0 ) break; 2975 GetTextBoundary( preBound, rText, nIndex, nTextType ); 2976 } 2977 //if (nIndex>0) 2978 if (nIndex>=0) 2979 //Tab will be return when call WORDTYPE 2980 { 2981 aResult.SegmentText = rText.copy( preBound.startPos, preBound.endPos - preBound.startPos ); 2982 aResult.SegmentStart = preBound.startPos; 2983 aResult.SegmentEnd = preBound.endPos; 2984 } 2985 } 2986 else 2987 { 2988 sal_Bool bWord = sal_False; 2989 while( !bWord ) 2990 { 2991 nIndex = min( nIndex, aBound.startPos ) - 1; 2992 if( nIndex >= 0 ) 2993 { 2994 bWord = GetTextBoundary( aBound, rText, nIndex, nTextType ); 2995 } 2996 else 2997 break; // exit if beginning of string is reached 2998 } 2999 3000 if (bWord && nIndex<rText.getLength()) 3001 { 3002 aResult.SegmentText = rText.copy( aBound.startPos, aBound.endPos - aBound.startPos ); 3003 aResult.SegmentStart = aBound.startPos; 3004 aResult.SegmentEnd = aBound.endPos; 3005 } 3006 } 3007 return aResult; 3008 } 3009 3010 /*accessibility::*/TextSegment SwAccessibleParagraph::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 nTextType ) throw (lang::IndexOutOfBoundsException, lang::IllegalArgumentException, uno::RuntimeException) 3011 { 3012 vos::OGuard aGuard(Application::GetSolarMutex()); 3013 3014 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 3015 3016 /*accessibility::*/TextSegment aResult; 3017 aResult.SegmentStart = -1; 3018 aResult.SegmentEnd = -1; 3019 const ::rtl::OUString rText = GetString(); 3020 3021 // implement the silly specification that first position after 3022 // text must return an empty string, rather than throwing an 3023 // IndexOutOfBoundsException 3024 if( nIndex == rText.getLength() ) 3025 return aResult; 3026 3027 3028 // get first word, then skip to next word 3029 i18n::Boundary aBound; 3030 GetTextBoundary( aBound, rText, nIndex, nTextType ); 3031 sal_Bool bWord = sal_False; 3032 while( !bWord ) 3033 { 3034 nIndex = max( sal_Int32(nIndex+1), aBound.endPos ); 3035 if( nIndex < rText.getLength() ) 3036 bWord = GetTextBoundary( aBound, rText, nIndex, nTextType ); 3037 else 3038 break; // exit if end of string is reached 3039 } 3040 3041 if ( bWord ) 3042 { 3043 aResult.SegmentText = rText.copy( aBound.startPos, aBound.endPos - aBound.startPos ); 3044 aResult.SegmentStart = aBound.startPos; 3045 aResult.SegmentEnd = aBound.endPos; 3046 } 3047 3048 /* 3049 sal_Bool bWord = sal_False; 3050 bWord = GetTextBoundary( aBound, rText, nIndex, nTextType ); 3051 3052 if (nTextType==2) 3053 { 3054 Boundary nexBound=aBound; 3055 3056 // real current word 3057 if( nIndex <= aBound.endPos && nIndex >= aBound.startPos ) 3058 { 3059 while(nexBound.endPos==aBound.endPos&&nIndex<rText.getLength()) 3060 { 3061 // nIndex = max( (sal_Int32)(nIndex), nexBound.endPos) + 1; 3062 nIndex = max( (sal_Int32)(nIndex), nexBound.endPos) ; 3063 const sal_Unicode* pStr = rText.getStr(); 3064 if (pStr) 3065 { 3066 if( pStr[nIndex] == sal_Unicode(' ') ) 3067 nIndex++; 3068 } 3069 if( nIndex < rText.getLength() ) 3070 { 3071 bWord = GetTextBoundary( nexBound, rText, nIndex, nTextType ); 3072 } 3073 } 3074 } 3075 3076 if (bWord && nIndex<rText.getLength()) 3077 { 3078 aResult.SegmentText = rText.copy( nexBound.startPos, nexBound.endPos - nexBound.startPos ); 3079 aResult.SegmentStart = nexBound.startPos; 3080 aResult.SegmentEnd = nexBound.endPos; 3081 } 3082 3083 } 3084 else 3085 { 3086 bWord = sal_False; 3087 while( !bWord ) 3088 { 3089 nIndex = max( (sal_Int32)(nIndex+1), aBound.endPos ); 3090 if( nIndex < rText.getLength() ) 3091 { 3092 bWord = GetTextBoundary( aBound, rText, nIndex, nTextType ); 3093 } 3094 else 3095 break; // exit if end of string is reached 3096 } 3097 if (bWord && nIndex<rText.getLength()) 3098 { 3099 aResult.SegmentText = rText.copy( aBound.startPos, aBound.endPos - aBound.startPos ); 3100 aResult.SegmentStart = aBound.startPos; 3101 aResult.SegmentEnd = aBound.endPos; 3102 } 3103 } 3104 */ 3105 return aResult; 3106 } 3107 3108 sal_Bool SwAccessibleParagraph::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 3109 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3110 { 3111 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 3112 vos::OGuard aGuard(Application::GetSolarMutex()); 3113 3114 // select and copy (through dispatch mechanism) 3115 setSelection( nStartIndex, nEndIndex ); 3116 ExecuteAtViewShell( SID_COPY ); 3117 return sal_True; 3118 } 3119 3120 3121 // 3122 //===== XAccesibleEditableText ========================================== 3123 // 3124 3125 sal_Bool SwAccessibleParagraph::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 3126 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3127 { 3128 CHECK_FOR_DEFUNC( XAccessibleEditableText ); 3129 vos::OGuard aGuard(Application::GetSolarMutex()); 3130 3131 if( !IsEditableState() ) 3132 return sal_False; 3133 3134 // select and cut (through dispatch mechanism) 3135 setSelection( nStartIndex, nEndIndex ); 3136 ExecuteAtViewShell( SID_CUT ); 3137 return sal_True; 3138 } 3139 3140 sal_Bool SwAccessibleParagraph::pasteText( sal_Int32 nIndex ) 3141 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3142 { 3143 CHECK_FOR_DEFUNC( XAccessibleEditableText ); 3144 vos::OGuard aGuard(Application::GetSolarMutex()); 3145 3146 if( !IsEditableState() ) 3147 return sal_False; 3148 3149 // select and paste (through dispatch mechanism) 3150 setSelection( nIndex, nIndex ); 3151 ExecuteAtViewShell( SID_PASTE ); 3152 return sal_True; 3153 } 3154 3155 sal_Bool SwAccessibleParagraph::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 3156 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3157 { 3158 return replaceText( nStartIndex, nEndIndex, ::rtl::OUString() ); 3159 } 3160 3161 sal_Bool SwAccessibleParagraph::insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) 3162 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3163 { 3164 return replaceText( nIndex, nIndex, sText ); 3165 } 3166 3167 sal_Bool SwAccessibleParagraph::replaceText( 3168 sal_Int32 nStartIndex, sal_Int32 nEndIndex, 3169 const ::rtl::OUString& sReplacement ) 3170 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3171 { 3172 vos::OGuard aGuard(Application::GetSolarMutex()); 3173 3174 CHECK_FOR_DEFUNC( XAccessibleEditableText ); 3175 3176 const ::rtl::OUString& rText = GetString(); 3177 3178 if( IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) 3179 { 3180 if( !IsEditableState() ) 3181 return sal_False; 3182 3183 SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 3184 3185 // translate positions 3186 sal_uInt16 nStart, nEnd; 3187 sal_Bool bSuccess = GetPortionData().GetEditableRange( 3188 nStartIndex, nEndIndex, nStart, nEnd ); 3189 3190 // edit only if the range is editable 3191 if( bSuccess ) 3192 { 3193 // create SwPosition for nStartIndex 3194 SwIndex aIndex( pNode, nStart ); 3195 SwPosition aStartPos( *pNode, aIndex ); 3196 3197 // create SwPosition for nEndIndex 3198 SwPosition aEndPos( aStartPos ); 3199 aEndPos.nContent = nEnd; 3200 3201 // now create XTextRange as helper and set string 3202 const uno::Reference<text::XTextRange> xRange( 3203 SwXTextRange::CreateXTextRange( 3204 *pNode->GetDoc(), aStartPos, &aEndPos)); 3205 xRange->setString(sReplacement); 3206 3207 // delete portion data 3208 ClearPortionData(); 3209 } 3210 3211 return bSuccess; 3212 } 3213 else 3214 throw lang::IndexOutOfBoundsException(); 3215 } 3216 3217 3218 sal_Bool SwAccessibleParagraph::setAttributes( 3219 sal_Int32 nStartIndex, 3220 sal_Int32 nEndIndex, 3221 const uno::Sequence<PropertyValue>& rAttributeSet ) 3222 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3223 { 3224 vos::OGuard aGuard(Application::GetSolarMutex()); 3225 CHECK_FOR_DEFUNC( XAccessibleEditableText ); 3226 3227 const ::rtl::OUString& rText = GetString(); 3228 3229 if( ! IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) 3230 throw lang::IndexOutOfBoundsException(); 3231 3232 if( !IsEditableState() ) 3233 return sal_False; 3234 3235 3236 // create a (dummy) text portion for the sole purpose of calling 3237 // setPropertyValue on it 3238 uno::Reference<XMultiPropertySet> xPortion = CreateUnoPortion( nStartIndex, 3239 nEndIndex ); 3240 3241 // build sorted index array 3242 sal_Int32 nLength = rAttributeSet.getLength(); 3243 const PropertyValue* pPairs = rAttributeSet.getConstArray(); 3244 sal_Int32* pIndices = new sal_Int32[nLength]; 3245 sal_Int32 i; 3246 for( i = 0; i < nLength; i++ ) 3247 pIndices[i] = i; 3248 sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); 3249 3250 // create sorted sequences accoring to index array 3251 uno::Sequence< ::rtl::OUString > aNames( nLength ); 3252 ::rtl::OUString* pNames = aNames.getArray(); 3253 uno::Sequence< uno::Any > aValues( nLength ); 3254 uno::Any* pValues = aValues.getArray(); 3255 for( i = 0; i < nLength; i++ ) 3256 { 3257 const PropertyValue& rVal = pPairs[pIndices[i]]; 3258 pNames[i] = rVal.Name; 3259 pValues[i] = rVal.Value; 3260 } 3261 delete[] pIndices; 3262 3263 // now set the values 3264 sal_Bool bRet = sal_True; 3265 try 3266 { 3267 xPortion->setPropertyValues( aNames, aValues ); 3268 } 3269 catch( UnknownPropertyException e ) 3270 { 3271 // error handling through return code! 3272 bRet = sal_False; 3273 } 3274 3275 return bRet; 3276 } 3277 3278 sal_Bool SwAccessibleParagraph::setText( const ::rtl::OUString& sText ) 3279 throw (uno::RuntimeException) 3280 { 3281 return replaceText(0, GetString().getLength(), sText); 3282 } 3283 3284 //===== XAccessibleSelection ============================================ 3285 3286 void SwAccessibleParagraph::selectAccessibleChild( 3287 sal_Int32 nChildIndex ) 3288 throw ( lang::IndexOutOfBoundsException, 3289 uno::RuntimeException ) 3290 { 3291 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3292 3293 aSelectionHelper.selectAccessibleChild(nChildIndex); 3294 } 3295 3296 sal_Bool SwAccessibleParagraph::isAccessibleChildSelected( 3297 sal_Int32 nChildIndex ) 3298 throw ( lang::IndexOutOfBoundsException, 3299 uno::RuntimeException ) 3300 { 3301 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3302 3303 return aSelectionHelper.isAccessibleChildSelected(nChildIndex); 3304 } 3305 3306 void SwAccessibleParagraph::clearAccessibleSelection( ) 3307 throw ( uno::RuntimeException ) 3308 { 3309 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3310 3311 aSelectionHelper.clearAccessibleSelection(); 3312 } 3313 3314 void SwAccessibleParagraph::selectAllAccessibleChildren( ) 3315 throw ( uno::RuntimeException ) 3316 { 3317 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3318 3319 aSelectionHelper.selectAllAccessibleChildren(); 3320 } 3321 3322 sal_Int32 SwAccessibleParagraph::getSelectedAccessibleChildCount( ) 3323 throw ( uno::RuntimeException ) 3324 { 3325 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3326 3327 return aSelectionHelper.getSelectedAccessibleChildCount(); 3328 } 3329 3330 uno::Reference<XAccessible> SwAccessibleParagraph::getSelectedAccessibleChild( 3331 sal_Int32 nSelectedChildIndex ) 3332 throw ( lang::IndexOutOfBoundsException, 3333 uno::RuntimeException) 3334 { 3335 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3336 3337 return aSelectionHelper.getSelectedAccessibleChild(nSelectedChildIndex); 3338 } 3339 3340 // --> OD 2004-11-16 #111714# - index has to be treated as global child index. 3341 void SwAccessibleParagraph::deselectAccessibleChild( 3342 sal_Int32 nChildIndex ) 3343 throw ( lang::IndexOutOfBoundsException, 3344 uno::RuntimeException ) 3345 { 3346 CHECK_FOR_DEFUNC( XAccessibleSelection ); 3347 3348 aSelectionHelper.deselectAccessibleChild( nChildIndex ); 3349 } 3350 3351 //===== XAccessibleHypertext ============================================ 3352 3353 class SwHyperlinkIter_Impl 3354 { 3355 const SwpHints *pHints; 3356 xub_StrLen nStt; 3357 xub_StrLen nEnd; 3358 sal_uInt16 nPos; 3359 3360 public: 3361 SwHyperlinkIter_Impl( const SwTxtFrm *pTxtFrm ); 3362 const SwTxtAttr *next(); 3363 sal_uInt16 getCurrHintPos() const { return nPos-1; } 3364 3365 xub_StrLen startIdx() const { return nStt; } 3366 xub_StrLen endIdx() const { return nEnd; } 3367 }; 3368 3369 SwHyperlinkIter_Impl::SwHyperlinkIter_Impl( const SwTxtFrm *pTxtFrm ) : 3370 pHints( pTxtFrm->GetTxtNode()->GetpSwpHints() ), 3371 nStt( pTxtFrm->GetOfst() ), 3372 nPos( 0 ) 3373 { 3374 const SwTxtFrm *pFollFrm = pTxtFrm->GetFollow(); 3375 nEnd = pFollFrm ? pFollFrm->GetOfst() : pTxtFrm->GetTxtNode()->Len(); 3376 } 3377 3378 const SwTxtAttr *SwHyperlinkIter_Impl::next() 3379 { 3380 const SwTxtAttr *pAttr = 0; 3381 if( pHints ) 3382 { 3383 while( !pAttr && nPos < pHints->Count() ) 3384 { 3385 const SwTxtAttr *pHt = (*pHints)[nPos]; 3386 if( RES_TXTATR_INETFMT == pHt->Which() ) 3387 { 3388 xub_StrLen nHtStt = *pHt->GetStart(); 3389 xub_StrLen nHtEnd = *pHt->GetAnyEnd(); 3390 if( nHtEnd > nHtStt && 3391 ( (nHtStt >= nStt && nHtStt < nEnd) || 3392 (nHtEnd > nStt && nHtEnd <= nEnd) ) ) 3393 { 3394 pAttr = pHt; 3395 } 3396 } 3397 ++nPos; 3398 } 3399 } 3400 3401 return pAttr; 3402 }; 3403 3404 sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkCount() 3405 throw (uno::RuntimeException) 3406 { 3407 vos::OGuard aGuard(Application::GetSolarMutex()); 3408 3409 CHECK_FOR_DEFUNC( XAccessibleHypertext ); 3410 3411 sal_Int32 nCount = 0; 3412 // --> OD 2007-06-27 #i77108# - provide hyperlinks also in editable documents. 3413 // if( !IsEditableState() ) 3414 // <-- 3415 { 3416 const SwTxtFrm *pTxtFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 3417 SwHyperlinkIter_Impl aIter( pTxtFrm ); 3418 while( aIter.next() ) 3419 nCount++; 3420 } 3421 3422 /* Can't fin the function "GetTOCFirstWordEndIndex" declaration in sym2.0 (Added by yanjun) 3423 if( GetTOXSortTabBase() ) 3424 { 3425 SwTxtNode* pNode = const_cast<SwTxtNode*>(GetTxtNode()); 3426 if(pNode && pNode->GetTOCFirstWordEndIndex() > 0) 3427 nCount++; 3428 } 3429 */ 3430 return nCount; 3431 } 3432 3433 uno::Reference< XAccessibleHyperlink > SAL_CALL 3434 SwAccessibleParagraph::getHyperLink( sal_Int32 nLinkIndex ) 3435 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3436 { 3437 vos::OGuard aGuard(Application::GetSolarMutex()); 3438 CHECK_FOR_DEFUNC( XAccessibleHypertext ); 3439 3440 uno::Reference< XAccessibleHyperlink > xRet; 3441 3442 // --> OD 2007-06-27 #i77108# - provide hyperlinks also in editable documents. 3443 // if( !IsEditableState() ) 3444 const SwTxtFrm *pTxtFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 3445 SwHyperlinkIter_Impl aHIter( pTxtFrm ); 3446 //SwAccessibleAutoRecognizerHelper_Impl aARHelper( pTxtFrm ); 3447 sal_Int32 nARCount = 0; 3448 sal_Int32 nARIndex = 0; 3449 sal_Int32 nTIndex = -1; 3450 sal_Int32 nTOCEndIndex = -1; 3451 SwTxtNode* pNode = NULL; 3452 SwTOXSortTabBase* pTBase = GetTOXSortTabBase(); 3453 if( pTBase ) 3454 { 3455 pNode = const_cast<SwTxtNode*>(GetTxtNode()); 3456 } 3457 nTOCEndIndex = -1; 3458 //if(pNode) 3459 // nTOCEndIndex = pNode->GetTOCFirstWordEndIndex(); 3460 SwTxtAttr* pHt = (SwTxtAttr*)(aHIter.next()); 3461 while( (nLinkIndex < getHyperLinkCount()) && nTIndex < nLinkIndex) 3462 { 3463 // no candidates, exit 3464 //if( (!pHt) && (nARIndex >= nARCount) && nTOCEndIndex <= 0) 3465 // break; 3466 3467 sal_Int32 nHStt = -1; 3468 sal_Int32 nAStt = -1; 3469 sal_Bool bH = sal_False; 3470 sal_Bool bA = sal_False; 3471 3472 3473 if( pHt ) 3474 nHStt = *pHt->GetStart(); 3475 if( nARIndex < nARCount ) 3476 { 3477 /* 3478 sal_Int32 nAEnd; 3479 aARHelper.getPosition( nARIndex, nAStt, nAEnd ); 3480 */ 3481 } 3482 sal_Bool bTOC = sal_False; 3483 // Inside TOC & get the first link 3484 if( pTBase && nTIndex == -1 ) 3485 { 3486 nTIndex++; 3487 bTOC = sal_True; 3488 } 3489 else 3490 { 3491 if( nHStt >=0 && nAStt >=0 ) 3492 { // both hyperlink and smart tag available 3493 nTIndex++; 3494 if( nHStt <= nAStt ) 3495 bH = sal_True; 3496 else 3497 bA = sal_True; 3498 } 3499 else if( nHStt >= 0 ) 3500 { // only hyperlink available 3501 nTIndex++; 3502 bH = sal_True; 3503 } 3504 else if( nAStt >= 0 ) 3505 { // only smart tag available 3506 nTIndex++; 3507 bA = sal_True; 3508 } 3509 } 3510 3511 if( nTIndex == nLinkIndex ) 3512 { // found 3513 if( bH ) 3514 { // it's a hyperlink 3515 if( pHt ) 3516 { 3517 // const SwField* pFFld = pHt->GetFld().GetFld(); 3518 { 3519 if( !pHyperTextData ) 3520 pHyperTextData = new SwAccessibleHyperTextData; 3521 SwAccessibleHyperTextData::iterator aIter = 3522 pHyperTextData ->find( pHt ); 3523 if( aIter != pHyperTextData->end() ) 3524 { 3525 xRet = (*aIter).second; 3526 } 3527 if( !xRet.is() ) 3528 { 3529 { 3530 const sal_Int32 nTmpHStt= GetPortionData().GetAccessiblePosition( 3531 max( aHIter.startIdx(), *pHt->GetStart() ) ); 3532 const sal_Int32 nTmpHEnd= GetPortionData().GetAccessiblePosition( 3533 min( aHIter.endIdx(), *pHt->GetAnyEnd() ) ); 3534 xRet = new SwAccessibleHyperlink( aHIter.getCurrHintPos(), 3535 this, nTmpHStt, nTmpHEnd ); 3536 } 3537 if( aIter != pHyperTextData->end() ) 3538 { 3539 (*aIter).second = xRet; 3540 } 3541 else 3542 { 3543 SwAccessibleHyperTextData::value_type aEntry( pHt, xRet ); 3544 pHyperTextData->insert( aEntry ); 3545 } 3546 } 3547 } 3548 } 3549 } 3550 else if( bTOC ) 3551 { 3552 //xRet = new SwAccessibleTOCLink( this ); 3553 } 3554 else if( bA ) 3555 { 3556 /* 3557 // it's a smart tag 3558 if( !pAutoRecognizerData ) 3559 pAutoRecognizerData = new SwAccessibleAutoRecognizerData; 3560 SwAccessibleAutoRecognizerData::iterator aIter = 3561 pAutoRecognizerData ->find( nARIndex ); 3562 if( aIter != pAutoRecognizerData->end() ) 3563 { 3564 xRet = (*aIter).second; 3565 } 3566 if( !xRet.is() ) 3567 { 3568 sal_Int32 nAStt = 0; 3569 sal_Int32 nAEnd = 0; 3570 //aARHelper.getPosition( nARIndex, nAStt, nAEnd ); 3571 xRet = new SwAccessibleAutoRecognizer( this, nAStt, nAEnd ); 3572 if( aIter != pAutoRecognizerData->end() ) 3573 { 3574 (*aIter).second = xRet; 3575 } 3576 else 3577 { 3578 SwAccessibleAutoRecognizerData::value_type aEntry( nARIndex, xRet ); 3579 pAutoRecognizerData->insert( aEntry ); 3580 } 3581 } 3582 */ 3583 } 3584 break; 3585 } 3586 3587 // iterate next 3588 if( bH ) 3589 // iterate next hyperlink 3590 pHt = (SwTxtAttr*)(aHIter.next()); 3591 else if( bA ) 3592 // iterate next smart tag 3593 nARIndex++; 3594 else if(bTOC) 3595 continue; 3596 else 3597 // no candidate, exit 3598 break; 3599 } 3600 /* 3601 const SwTxtFrm *pTxtFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 3602 SwHyperlinkIter_Impl aHIter( pTxtFrm ); 3603 while( nLinkIndex-- ) 3604 aHIter.next(); 3605 3606 const SwTxtAttr *pHt = aHIter.next(); 3607 if( pHt ) 3608 { 3609 if( !pHyperTextData ) 3610 pHyperTextData = new SwAccessibleHyperTextData; 3611 SwAccessibleHyperTextData::iterator aIter = 3612 pHyperTextData ->find( pHt ); 3613 if( aIter != pHyperTextData->end() ) 3614 { 3615 xRet = (*aIter).second; 3616 } 3617 if( !xRet.is() ) 3618 { 3619 sal_Int32 nHStt= GetPortionData().GetAccessiblePosition( 3620 max( aHIter.startIdx(), *pHt->GetStart() ) ); 3621 sal_Int32 nHEnd= GetPortionData().GetAccessiblePosition( 3622 min( aHIter.endIdx(), *pHt->GetAnyEnd() ) ); 3623 xRet = new SwAccessibleHyperlink( aHIter.getCurrHintPos(), 3624 this, nHStt, nHEnd ); 3625 if( aIter != pHyperTextData->end() ) 3626 { 3627 (*aIter).second = xRet; 3628 } 3629 else 3630 { 3631 SwAccessibleHyperTextData::value_type aEntry( pHt, xRet ); 3632 pHyperTextData->insert( aEntry ); 3633 } 3634 } 3635 } 3636 } 3637 */ 3638 if( !xRet.is() ) 3639 throw lang::IndexOutOfBoundsException(); 3640 3641 return xRet; 3642 } 3643 3644 sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkIndex( sal_Int32 nCharIndex ) 3645 throw (lang::IndexOutOfBoundsException, uno::RuntimeException) 3646 { 3647 vos::OGuard aGuard(Application::GetSolarMutex()); 3648 CHECK_FOR_DEFUNC( XAccessibleHypertext ); 3649 3650 // parameter checking 3651 sal_Int32 nLength = GetString().getLength(); 3652 if ( ! IsValidPosition( nCharIndex, nLength ) ) 3653 { 3654 throw lang::IndexOutOfBoundsException(); 3655 } 3656 3657 sal_Int32 nRet = -1; 3658 // --> OD 2007-06-27 #i77108# - provide hyperlinks also in editable documents. 3659 // if( !IsEditableState() ) 3660 // <-- 3661 { 3662 const SwTxtFrm *pTxtFrm = static_cast<const SwTxtFrm*>( GetFrm() ); 3663 SwHyperlinkIter_Impl aHIter( pTxtFrm ); 3664 3665 xub_StrLen nIdx = GetPortionData().GetModelPosition( nCharIndex ); 3666 sal_Int32 nPos = 0; 3667 const SwTxtAttr *pHt = aHIter.next(); 3668 while( pHt && !(nIdx >= *pHt->GetStart() && nIdx < *pHt->GetAnyEnd()) ) 3669 { 3670 pHt = aHIter.next(); 3671 nPos++; 3672 } 3673 3674 if( pHt ) 3675 nRet = nPos; 3676 } 3677 /* Added by yanjun for acc miagration 3678 if( nRet == -1 && GetTOXSortTabBase() ) 3679 { 3680 SwTxtNode* pNode = const_cast<SwTxtNode*>(GetTxtNode()); 3681 if( nCharIndex >= 0 && nCharIndex < pNode->GetTOCFirstWordEndIndex()) 3682 nRet = 0; 3683 } 3684 */ 3685 3686 if (nRet == -1) 3687 throw lang::IndexOutOfBoundsException(); 3688 else 3689 return nRet; 3690 //return nRet; 3691 } 3692 3693 // --> OD 2008-05-26 #i71360# 3694 // --> OD 2010-02-22 #i108125# - adjustments for change tracking text markup 3695 sal_Int32 SAL_CALL SwAccessibleParagraph::getTextMarkupCount( sal_Int32 nTextMarkupType ) 3696 throw (lang::IllegalArgumentException, 3697 uno::RuntimeException) 3698 { 3699 std::auto_ptr<SwTextMarkupHelper> pTextMarkupHelper; 3700 switch ( nTextMarkupType ) 3701 { 3702 case text::TextMarkupType::TRACK_CHANGE_INSERTION: 3703 case text::TextMarkupType::TRACK_CHANGE_DELETION: 3704 case text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE: 3705 { 3706 pTextMarkupHelper.reset( new SwTextMarkupHelper( 3707 GetPortionData(), 3708 *(mpParaChangeTrackInfo->getChangeTrackingTextMarkupList( nTextMarkupType ) )) ); 3709 } 3710 break; 3711 default: 3712 { 3713 pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTxtNode() ) ); 3714 } 3715 } 3716 3717 return pTextMarkupHelper->getTextMarkupCount( nTextMarkupType ); 3718 } 3719 //MSAA Extension Implementation in app module 3720 sal_Bool SAL_CALL SwAccessibleParagraph::scrollToPosition( const ::com::sun::star::awt::Point&, sal_Bool ) 3721 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 3722 { 3723 return sal_False; 3724 } 3725 3726 sal_Int32 SAL_CALL SwAccessibleParagraph::getSelectedPortionCount( ) 3727 throw (::com::sun::star::uno::RuntimeException) 3728 { 3729 sal_Int32 nSeleted = 0; 3730 SwPaM* pCrsr = GetCursor( true ); 3731 if( pCrsr != NULL ) 3732 { 3733 // get SwPosition for my node 3734 const SwTxtNode* pNode = GetTxtNode(); 3735 sal_uLong nHere = pNode->GetIndex(); 3736 3737 // iterate over ring 3738 SwPaM* pRingStart = pCrsr; 3739 do 3740 { 3741 // ignore, if no mark 3742 if( pCrsr->HasMark() ) 3743 { 3744 // check whether nHere is 'inside' pCrsr 3745 SwPosition* pStart = pCrsr->Start(); 3746 sal_uLong nStartIndex = pStart->nNode.GetIndex(); 3747 SwPosition* pEnd = pCrsr->End(); 3748 sal_uLong nEndIndex = pEnd->nNode.GetIndex(); 3749 if( ( nHere >= nStartIndex ) && 3750 ( nHere <= nEndIndex ) ) 3751 { 3752 nSeleted++; 3753 } 3754 // else: this PaM doesn't point to this paragraph 3755 } 3756 // else: this PaM is collapsed and doesn't select anything 3757 3758 // next PaM in ring 3759 pCrsr = static_cast<SwPaM*>( pCrsr->GetNext() ); 3760 } 3761 while( pCrsr != pRingStart ); 3762 } 3763 return nSeleted; 3764 3765 } 3766 3767 sal_Int32 SAL_CALL SwAccessibleParagraph::getSeletedPositionStart( sal_Int32 nSelectedPortionIndex ) 3768 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 3769 { 3770 vos::OGuard aGuard(Application::GetSolarMutex()); 3771 3772 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 3773 3774 sal_Int32 nStart, nEnd; 3775 /*sal_Bool bSelected = */GetSelectionAtIndex(nSelectedPortionIndex, nStart, nEnd ); 3776 return nStart; 3777 } 3778 3779 sal_Int32 SAL_CALL SwAccessibleParagraph::getSeletedPositionEnd( sal_Int32 nSelectedPortionIndex ) 3780 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 3781 { 3782 vos::OGuard aGuard(Application::GetSolarMutex()); 3783 3784 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 3785 3786 sal_Int32 nStart, nEnd; 3787 /*sal_Bool bSelected = */GetSelectionAtIndex(nSelectedPortionIndex, nStart, nEnd ); 3788 return nEnd; 3789 } 3790 3791 sal_Bool SAL_CALL SwAccessibleParagraph::removeSelection( sal_Int32 selectionIndex ) 3792 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 3793 { 3794 if(selectionIndex < 0) return sal_False; 3795 3796 sal_Bool bRet = sal_False; 3797 sal_Int32 nSelected = selectionIndex; 3798 3799 // get the selection, and test whether it affects our text node 3800 SwPaM* pCrsr = GetCursor( true ); 3801 // SwPaM* pFirst = pCrsr; 3802 SwPaM* pPrev = pCrsr; 3803 3804 if( pCrsr != NULL ) 3805 { 3806 // get SwPosition for my node 3807 const SwTxtNode* pNode = GetTxtNode(); 3808 sal_uLong nHere = pNode->GetIndex(); 3809 3810 // iterate over ring 3811 SwPaM* pRingStart = pCrsr; 3812 do 3813 { 3814 // ignore, if no mark 3815 if( pCrsr->HasMark() ) 3816 { 3817 // check whether nHere is 'inside' pCrsr 3818 SwPosition* pStart = pCrsr->Start(); 3819 sal_uLong nStartIndex = pStart->nNode.GetIndex(); 3820 SwPosition* pEnd = pCrsr->End(); 3821 sal_uLong nEndIndex = pEnd->nNode.GetIndex(); 3822 if( ( nHere >= nStartIndex ) && 3823 ( nHere <= nEndIndex ) ) 3824 { 3825 if( nSelected == 0 ) 3826 { 3827 pCrsr->MoveTo((Ring*)0); 3828 delete pCrsr; 3829 bRet = sal_True; 3830 } 3831 else 3832 { 3833 nSelected--; 3834 } 3835 } 3836 } 3837 // else: this PaM is collapsed and doesn't select anything 3838 pPrev = pCrsr; 3839 pCrsr = static_cast<SwPaM*>( pCrsr->GetNext() ); 3840 } 3841 while( !bRet && (pCrsr != pRingStart) ); 3842 } 3843 return sal_True; 3844 } 3845 3846 sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection( sal_Int32, sal_Int32 startOffset, sal_Int32 endOffset) 3847 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 3848 { 3849 vos::OGuard aGuard(Application::GetSolarMutex()); 3850 3851 CHECK_FOR_DEFUNC_THIS( XAccessibleText, *this ); 3852 3853 // parameter checking 3854 sal_Int32 nLength = GetString().getLength(); 3855 if ( ! IsValidRange( startOffset, endOffset, nLength ) ) 3856 { 3857 throw lang::IndexOutOfBoundsException(); 3858 } 3859 3860 sal_Int32 nSelectedCount = getSelectedPortionCount(); 3861 for ( sal_Int32 i = nSelectedCount ; i >= 0 ; i--) 3862 { 3863 sal_Int32 nStart, nEnd; 3864 sal_Bool bSelected = GetSelectionAtIndex(i, nStart, nEnd ); 3865 if(bSelected) 3866 { 3867 if(nStart <= nEnd ) 3868 { 3869 if (( startOffset>=nStart && startOffset <=nEnd ) || //startOffset in a selection 3870 ( endOffset>=nStart && endOffset <=nEnd ) || //endOffset in a selection 3871 ( startOffset <= nStart && endOffset >=nEnd) || //start and end include the old selection 3872 ( startOffset >= nStart && endOffset <=nEnd) ) 3873 { 3874 removeSelection(i); 3875 } 3876 3877 } 3878 else 3879 { 3880 if (( startOffset>=nEnd && startOffset <=nStart ) || //startOffset in a selection 3881 ( endOffset>=nEnd && endOffset <=nStart ) || //endOffset in a selection 3882 ( startOffset <= nStart && endOffset >=nEnd) || //start and end include the old selection 3883 ( startOffset >= nStart && endOffset <=nEnd) ) 3884 3885 { 3886 removeSelection(i); 3887 } 3888 } 3889 } 3890 3891 } 3892 3893 sal_Bool bRet = sal_False; 3894 3895 // get cursor shell 3896 SwCrsrShell* pCrsrShell = GetCrsrShell(); 3897 if( pCrsrShell != NULL ) 3898 { 3899 // create pam for selection 3900 pCrsrShell->StartAction(); 3901 // SwTxtNode* pNode = const_cast<SwTxtNode*>( GetTxtNode() ); 3902 SwPaM* aPaM = pCrsrShell->CreateCrsr(); 3903 aPaM->SetMark(); 3904 aPaM->GetPoint()->nContent = GetPortionData().GetModelPosition(startOffset); 3905 aPaM->GetMark()->nContent = GetPortionData().GetModelPosition(endOffset); 3906 //pCrsrShell->ShowCrsr(); 3907 pCrsrShell->EndAction(); 3908 // set PaM at cursor shell 3909 //bRet = Select( aPaM ); 3910 } 3911 3912 return bRet; 3913 } 3914 3915 /*accessibility::*/TextSegment SAL_CALL 3916 SwAccessibleParagraph::getTextMarkup( sal_Int32 nTextMarkupIndex, 3917 sal_Int32 nTextMarkupType ) 3918 throw (lang::IndexOutOfBoundsException, 3919 lang::IllegalArgumentException, 3920 uno::RuntimeException) 3921 { 3922 std::auto_ptr<SwTextMarkupHelper> pTextMarkupHelper; 3923 switch ( nTextMarkupType ) 3924 { 3925 case text::TextMarkupType::TRACK_CHANGE_INSERTION: 3926 case text::TextMarkupType::TRACK_CHANGE_DELETION: 3927 case text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE: 3928 { 3929 pTextMarkupHelper.reset( new SwTextMarkupHelper( 3930 GetPortionData(), 3931 *(mpParaChangeTrackInfo->getChangeTrackingTextMarkupList( nTextMarkupType ) )) ); 3932 } 3933 break; 3934 default: 3935 { 3936 pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTxtNode() ) ); 3937 } 3938 } 3939 3940 return pTextMarkupHelper->getTextMarkup( nTextMarkupIndex, nTextMarkupType ); 3941 } 3942 3943 uno::Sequence< /*accessibility::*/TextSegment > SAL_CALL 3944 SwAccessibleParagraph::getTextMarkupAtIndex( sal_Int32 nCharIndex, 3945 sal_Int32 nTextMarkupType ) 3946 throw (lang::IndexOutOfBoundsException, 3947 lang::IllegalArgumentException, 3948 uno::RuntimeException) 3949 { 3950 // parameter checking 3951 const sal_Int32 nLength = GetString().getLength(); 3952 if ( ! IsValidPosition( nCharIndex, nLength ) ) 3953 { 3954 throw lang::IndexOutOfBoundsException(); 3955 } 3956 3957 std::auto_ptr<SwTextMarkupHelper> pTextMarkupHelper; 3958 switch ( nTextMarkupType ) 3959 { 3960 case text::TextMarkupType::TRACK_CHANGE_INSERTION: 3961 case text::TextMarkupType::TRACK_CHANGE_DELETION: 3962 case text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE: 3963 { 3964 pTextMarkupHelper.reset( new SwTextMarkupHelper( 3965 GetPortionData(), 3966 *(mpParaChangeTrackInfo->getChangeTrackingTextMarkupList( nTextMarkupType ) )) ); 3967 } 3968 break; 3969 default: 3970 { 3971 pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTxtNode() ) ); 3972 } 3973 } 3974 3975 return pTextMarkupHelper->getTextMarkupAtIndex( nCharIndex, nTextMarkupType ); 3976 } 3977 // <-- 3978 3979 // --> OD 2008-05-29 #i89175# 3980 sal_Int32 SAL_CALL SwAccessibleParagraph::getLineNumberAtIndex( sal_Int32 nIndex ) 3981 throw (lang::IndexOutOfBoundsException, 3982 uno::RuntimeException) 3983 { 3984 // parameter checking 3985 const sal_Int32 nLength = GetString().getLength(); 3986 if ( ! IsValidPosition( nIndex, nLength ) ) 3987 { 3988 throw lang::IndexOutOfBoundsException(); 3989 } 3990 3991 const sal_Int32 nLineNo = GetPortionData().GetLineNo( nIndex ); 3992 return nLineNo; 3993 } 3994 3995 /*accessibility::*/TextSegment SAL_CALL 3996 SwAccessibleParagraph::getTextAtLineNumber( sal_Int32 nLineNo ) 3997 throw (lang::IndexOutOfBoundsException, 3998 uno::RuntimeException) 3999 { 4000 // parameter checking 4001 if ( nLineNo < 0 || 4002 nLineNo >= GetPortionData().GetLineCount() ) 4003 { 4004 throw lang::IndexOutOfBoundsException(); 4005 } 4006 4007 i18n::Boundary aLineBound; 4008 GetPortionData().GetBoundaryOfLine( nLineNo, aLineBound ); 4009 4010 /*accessibility::*/TextSegment aTextAtLine; 4011 const ::rtl::OUString rText = GetString(); 4012 aTextAtLine.SegmentText = rText.copy( aLineBound.startPos, 4013 aLineBound.endPos - aLineBound.startPos ); 4014 aTextAtLine.SegmentStart = aLineBound.startPos; 4015 aTextAtLine.SegmentEnd = aLineBound.endPos; 4016 4017 return aTextAtLine; 4018 } 4019 4020 /*accessibility::*/TextSegment SAL_CALL SwAccessibleParagraph::getTextAtLineWithCaret() 4021 throw (uno::RuntimeException) 4022 { 4023 const sal_Int32 nLineNoOfCaret = getNumberOfLineWithCaret(); 4024 4025 if ( nLineNoOfCaret >= 0 && 4026 nLineNoOfCaret < GetPortionData().GetLineCount() ) 4027 { 4028 return getTextAtLineNumber( nLineNoOfCaret ); 4029 } 4030 4031 return /*accessibility::*/TextSegment(); 4032 } 4033 4034 sal_Int32 SAL_CALL SwAccessibleParagraph::getNumberOfLineWithCaret() 4035 throw (uno::RuntimeException) 4036 { 4037 const sal_Int32 nCaretPos = getCaretPosition(); 4038 const sal_Int32 nLength = GetString().getLength(); 4039 if ( !IsValidPosition( nCaretPos, nLength ) ) 4040 { 4041 return -1; 4042 } 4043 4044 sal_Int32 nLineNo = GetPortionData().GetLineNo( nCaretPos ); 4045 4046 // special handling for cursor positioned at end of text line via End key 4047 if ( nCaretPos != 0 ) 4048 { 4049 i18n::Boundary aLineBound; 4050 GetPortionData().GetBoundaryOfLine( nLineNo, aLineBound ); 4051 if ( nCaretPos == aLineBound.startPos ) 4052 { 4053 SwCrsrShell* pCrsrShell = SwAccessibleParagraph::GetCrsrShell(); 4054 if ( pCrsrShell != 0 ) 4055 { 4056 const awt::Rectangle aCharRect = getCharacterBounds( nCaretPos ); 4057 4058 const SwRect& aCursorCoreRect = pCrsrShell->GetCharRect(); 4059 // translate core coordinates into accessibility coordinates 4060 Window *pWin = GetWindow(); 4061 CHECK_FOR_WINDOW( XAccessibleComponent, pWin ); 4062 4063 Rectangle aScreenRect( GetMap()->CoreToPixel( aCursorCoreRect.SVRect() )); 4064 4065 SwRect aFrmLogBounds( GetBounds( *(GetMap()) ) ); // twip rel to doc root 4066 Point aFrmPixPos( GetMap()->CoreToPixel( aFrmLogBounds.SVRect() ).TopLeft() ); 4067 aScreenRect.Move( -aFrmPixPos.X(), -aFrmPixPos.Y() ); 4068 4069 // convert into AWT Rectangle 4070 const awt::Rectangle aCursorRect( aScreenRect.Left(), 4071 aScreenRect.Top(), 4072 aScreenRect.GetWidth(), 4073 aScreenRect.GetHeight() ); 4074 4075 if ( aCharRect.X != aCursorRect.X || 4076 aCharRect.Y != aCursorRect.Y ) 4077 { 4078 --nLineNo; 4079 } 4080 } 4081 } 4082 } 4083 4084 return nLineNo; 4085 } 4086 4087 // --> OD 2010-02-19 #i108125# 4088 void SwAccessibleParagraph::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) 4089 { 4090 mpParaChangeTrackInfo->reset(); 4091 4092 CheckRegistration( pOld, pNew ); 4093 } 4094 // <-- 4095 4096 sal_Bool SwAccessibleParagraph::GetSelectionAtIndex( 4097 sal_Int32& nIndex, sal_Int32& nStart, sal_Int32& nEnd) 4098 { 4099 if(nIndex < 0) return sal_False; 4100 4101 4102 sal_Bool bRet = sal_False; 4103 nStart = -1; 4104 nEnd = -1; 4105 sal_Int32 nSelected = nIndex; 4106 4107 // get the selection, and test whether it affects our text node 4108 SwPaM* pCrsr = GetCursor( true ); 4109 if( pCrsr != NULL ) 4110 { 4111 // get SwPosition for my node 4112 const SwTxtNode* pNode = GetTxtNode(); 4113 sal_uLong nHere = pNode->GetIndex(); 4114 4115 // iterate over ring 4116 SwPaM* pRingStart = pCrsr; 4117 do 4118 { 4119 // ignore, if no mark 4120 if( pCrsr->HasMark() ) 4121 { 4122 // check whether nHere is 'inside' pCrsr 4123 SwPosition* pStart = pCrsr->Start(); 4124 sal_uLong nStartIndex = pStart->nNode.GetIndex(); 4125 SwPosition* pEnd = pCrsr->End(); 4126 sal_uLong nEndIndex = pEnd->nNode.GetIndex(); 4127 if( ( nHere >= nStartIndex ) && 4128 ( nHere <= nEndIndex ) ) 4129 { 4130 if( nSelected == 0 ) 4131 { 4132 // translate start and end positions 4133 4134 // start position 4135 sal_Int32 nLocalStart = -1; 4136 if( nHere > nStartIndex ) 4137 { 4138 // selection starts in previous node: 4139 // then our local selection starts with the paragraph 4140 nLocalStart = 0; 4141 } 4142 else 4143 { 4144 DBG_ASSERT( nHere == nStartIndex, 4145 "miscalculated index" ); 4146 4147 // selection starts in this node: 4148 // then check whether it's before or inside our part of 4149 // the paragraph, and if so, get the proper position 4150 sal_uInt16 nCoreStart = pStart->nContent.GetIndex(); 4151 if( nCoreStart < 4152 GetPortionData().GetFirstValidCorePosition() ) 4153 { 4154 nLocalStart = 0; 4155 } 4156 else if( nCoreStart <= 4157 GetPortionData().GetLastValidCorePosition() ) 4158 { 4159 DBG_ASSERT( 4160 GetPortionData().IsValidCorePosition( 4161 nCoreStart ), 4162 "problem determining valid core position" ); 4163 4164 nLocalStart = 4165 GetPortionData().GetAccessiblePosition( 4166 nCoreStart ); 4167 } 4168 } 4169 4170 // end position 4171 sal_Int32 nLocalEnd = -1; 4172 if( nHere < nEndIndex ) 4173 { 4174 // selection ends in following node: 4175 // then our local selection extends to the end 4176 nLocalEnd = GetPortionData().GetAccessibleString(). 4177 getLength(); 4178 } 4179 else 4180 { 4181 DBG_ASSERT( nHere == nStartIndex, 4182 "miscalculated index" ); 4183 4184 // selection ends in this node: then select everything 4185 // before our part of the node 4186 sal_uInt16 nCoreEnd = pEnd->nContent.GetIndex(); 4187 if( nCoreEnd > 4188 GetPortionData().GetLastValidCorePosition() ) 4189 { 4190 // selection extends beyond out part of this para 4191 nLocalEnd = GetPortionData().GetAccessibleString(). 4192 getLength(); 4193 } 4194 else if( nCoreEnd >= 4195 GetPortionData().GetFirstValidCorePosition() ) 4196 { 4197 // selection is inside our part of this para 4198 DBG_ASSERT( 4199 GetPortionData().IsValidCorePosition( 4200 nCoreEnd ), 4201 "problem determining valid core position" ); 4202 4203 nLocalEnd = GetPortionData().GetAccessiblePosition( 4204 nCoreEnd ); 4205 } 4206 } 4207 4208 if( ( nLocalStart != -1 ) && ( nLocalEnd != -1 ) ) 4209 { 4210 nStart = nLocalStart; 4211 nEnd = nLocalEnd; 4212 bRet = sal_True; 4213 } 4214 } // if hit the index 4215 else 4216 { 4217 nSelected--; 4218 } 4219 } 4220 // else: this PaM doesn't point to this paragraph 4221 } 4222 // else: this PaM is collapsed and doesn't select anything 4223 4224 // next PaM in ring 4225 pCrsr = static_cast<SwPaM*>( pCrsr->GetNext() ); 4226 } 4227 while( !bRet && (pCrsr != pRingStart) ); 4228 } 4229 // else: nocursor -> no selection 4230 4231 if( bRet ) 4232 { 4233 sal_Int32 nCaretPos = GetCaretPos(); 4234 if( nStart == nCaretPos ) 4235 { 4236 sal_Int32 tmp = nStart; 4237 nStart = nEnd; 4238 nEnd = tmp; 4239 } 4240 } 4241 return bRet; 4242 } 4243 4244 sal_Int16 SAL_CALL SwAccessibleParagraph::getAccessibleRole (void) throw (::com::sun::star::uno::RuntimeException) 4245 { 4246 //Get the real heading level, Heading1 ~ Heading10 4247 if (nHeadingLevel > 0) 4248 { 4249 return AccessibleRole::HEADING; 4250 } 4251 else 4252 { 4253 return AccessibleRole::PARAGRAPH; 4254 } 4255 } 4256 4257 // End Add 4258 4259 4260 /* This funcion is already defined in accpara.cxx(Added by yanjun) 4261 sal_Int32 SAL_CALL SwAccessibleParagraph::getBackground() 4262 throw (::com::sun::star::uno::RuntimeException) 4263 { 4264 // Test Code 4265 // Sequence<OUString> seNames(1); 4266 // OUString* pStrings = seNames.getArray(); 4267 // pStrings[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("ParaBackColor")); 4268 // 4269 // Sequence<Any> aAnys(1); 4270 // Reference<XMultiPropertySet> xPortion = CreateUnoPortion( 0, 0 ); 4271 // aAnys = xPortion->getPropertyValues( seNames ); 4272 // const Any* pAnys = aAnys.getConstArray(); 4273 // 4274 // sal_uInt32 crColorT=0; 4275 // pAnys[0] >>= crColorT; 4276 // End Test Code 4277 4278 const SvxBrushItem &rBack = GetFrm()->GetAttrSet()->GetBackground(); 4279 sal_uInt32 crBack = rBack.GetColor().GetColor(); 4280 4281 if (COL_AUTO == crBack) 4282 { 4283 Reference<XAccessible> xAccDoc = getAccessibleParent(); 4284 if (xAccDoc.is()) 4285 { 4286 Reference<XAccessibleComponent> xCompoentDoc(xAccDoc,UNO_QUERY); 4287 if (xCompoentDoc.is()) 4288 { 4289 crBack = (sal_uInt32)xCompoentDoc->getBackground(); 4290 } 4291 } 4292 } 4293 return crBack; 4294 } 4295 */ 4296 4297 //Get the real heading level, Heading1 ~ Heading10 4298 sal_Int32 SwAccessibleParagraph::GetRealHeadingLevel() 4299 { 4300 uno::Reference< ::com::sun::star::beans::XPropertySet > xPortion = CreateUnoPortion( 0, 0 ); 4301 ::rtl::OUString pString = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")); 4302 uno::Any styleAny = xPortion->getPropertyValue( pString ); 4303 ::rtl::OUString sValue; 4304 if (styleAny >>= sValue) 4305 { 4306 //Modified by yanjun for acc migration 4307 sal_Int32 length = sValue.getLength/*GetCharCount*/(); 4308 if (length == 9 || length == 10) 4309 { 4310 ::rtl::OUString headStr = sValue.copy(0, 7); 4311 if (headStr.equals(::rtl::OUString::createFromAscii("Heading"))) 4312 { 4313 ::rtl::OUString intStr = sValue.copy(8); 4314 sal_Int32 headingLevel = intStr.toInt32(10); 4315 return headingLevel; 4316 } 4317 } 4318 } 4319 return -1; 4320 } 4321 4322 uno::Any SAL_CALL SwAccessibleParagraph::getExtendedAttributes() 4323 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 4324 { 4325 uno::Any Ret; 4326 ::rtl::OUString strHeading(::rtl::OUString::createFromAscii("heading-level:")); 4327 if( nHeadingLevel >= 0 ) 4328 strHeading += OUString::valueOf(nHeadingLevel, 10); 4329 strHeading += OUString::createFromAscii(";"); 4330 4331 Ret <<= strHeading; 4332 4333 return Ret; 4334 } 4335 4336 //Tab will be return when call WORDTYPE 4337 sal_Bool SwAccessibleParagraph::tabCharInWord( sal_Int32 nIndex, i18n::Boundary& aBound) 4338 { 4339 sal_Bool bFind = sal_False; 4340 if( aBound.startPos != nIndex) 4341 { 4342 OUString tabStr; 4343 if(aBound.startPos>nIndex) 4344 tabStr = GetString().copy(nIndex,(aBound.startPos - nIndex) ); 4345 4346 sal_Unicode tabChar('\t'); 4347 sal_Int32 tabIndex = tabStr.indexOf(tabChar); 4348 if( tabIndex > -1 ) 4349 { 4350 aBound.startPos = nIndex + tabIndex ; 4351 aBound.endPos = aBound.startPos + 1; 4352 bFind = sal_True; 4353 } 4354 } 4355 return bFind; 4356 } 4357