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 <com/sun/star/table/TableSortField.hpp> 28 29 #include <osl/endian.h> 30 #include <rtl/ustrbuf.hxx> 31 #include <unotools/collatorwrapper.hxx> 32 #include <swtypes.hxx> 33 #include <hintids.hxx> 34 #include <cmdid.h> 35 #include <hints.hxx> 36 #include <IMark.hxx> 37 #include <frmfmt.hxx> 38 #include <doc.hxx> 39 #include <IDocumentUndoRedo.hxx> 40 #include <istyleaccess.hxx> 41 #include <ndtxt.hxx> 42 #include <ndnotxt.hxx> 43 #include <unocrsr.hxx> 44 #include <unocrsrhelper.hxx> 45 #include <swundo.hxx> 46 #include <rootfrm.hxx> 47 #include <flyfrm.hxx> 48 #include <ftnidx.hxx> 49 #include <sfx2/linkmgr.hxx> 50 #include <docary.hxx> 51 #include <paratr.hxx> 52 #include <tools/urlobj.hxx> 53 #include <pam.hxx> 54 #include <tools/cachestr.hxx> 55 #include <shellio.hxx> 56 #include <swerror.h> 57 #include <swtblfmt.hxx> 58 #include <fmtruby.hxx> 59 #include <docsh.hxx> 60 #include <docstyle.hxx> 61 #include <charfmt.hxx> 62 #include <txtfld.hxx> 63 #include <fmtfld.hxx> 64 #include <fmtpdsc.hxx> 65 #include <pagedesc.hxx> 66 #include <poolfmt.hrc> 67 #include <poolfmt.hxx> 68 #include <edimp.hxx> 69 #include <fchrfmt.hxx> 70 #include <fmtautofmt.hxx> 71 #include <cntfrm.hxx> 72 #include <pagefrm.hxx> 73 #include <doctxm.hxx> 74 #include <sfx2/docfilt.hxx> 75 #include <sfx2/docfile.hxx> 76 #include <sfx2/fcontnr.hxx> 77 #include <fmtrfmrk.hxx> 78 #include <txtrfmrk.hxx> 79 #include <unotextrange.hxx> 80 #include <unotextcursor.hxx> 81 #include <unomap.hxx> 82 #include <unosett.hxx> 83 #include <unoprnms.hxx> 84 #include <unotbl.hxx> 85 #include <unodraw.hxx> 86 #include <unocoll.hxx> 87 #include <unostyle.hxx> 88 #include <unofield.hxx> 89 #include <unometa.hxx> 90 #include <fmtanchr.hxx> 91 #include <editeng/flstitem.hxx> 92 #include <svtools/ctrltool.hxx> 93 #include <flypos.hxx> 94 #include <txtftn.hxx> 95 #include <fmtftn.hxx> 96 #include <com/sun/star/text/WrapTextMode.hpp> 97 #include <com/sun/star/text/TextContentAnchorType.hpp> 98 #include <com/sun/star/style/PageStyleLayout.hpp> 99 #include <com/sun/star/text/XTextDocument.hpp> 100 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 101 #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 102 #include <com/sun/star/text/TextMarkupType.hpp> 103 #include <unoidx.hxx> 104 #include <unoframe.hxx> 105 #include <fmthdft.hxx> 106 #include <vos/mutex.hxx> 107 #include <vcl/svapp.hxx> 108 #include <fmtflcnt.hxx> 109 #define _SVSTDARR_USHORTS 110 #define _SVSTDARR_USHORTSSORT 111 #include <svl/svstdarr.hxx> 112 #include <editeng/brshitem.hxx> 113 #include <editeng/unolingu.hxx> 114 #include <fmtclds.hxx> 115 #include <dcontact.hxx> 116 #include <SwStyleNameMapper.hxx> 117 #include <crsskip.hxx> 118 #include <sortopt.hxx> 119 #include <com/sun/star/beans/PropertyAttribute.hpp> 120 #include <memory> 121 #include <unoparaframeenum.hxx> 122 #include <unoparagraph.hxx> 123 124 125 using namespace ::com::sun::star; 126 using ::rtl::OUString; 127 using ::rtl::OUStringBuffer; 128 129 130 /**************************************************************************** 131 static methods 132 ****************************************************************************/ 133 uno::Sequence< sal_Int8 > CreateUnoTunnelId() 134 { 135 static osl::Mutex aCreateMutex; 136 osl::Guard<osl::Mutex> aGuard( aCreateMutex ); 137 uno::Sequence< sal_Int8 > aSeq( 16 ); 138 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 139 return aSeq; 140 } 141 /**************************************************************************** 142 Hilfsklassen 143 ****************************************************************************/ 144 145 /* -----------------13.05.98 12:15------------------- 146 * 147 * --------------------------------------------------*/ 148 SwUnoInternalPaM::SwUnoInternalPaM(SwDoc& rDoc) : 149 SwPaM(rDoc.GetNodes()) 150 { 151 } 152 SwUnoInternalPaM::~SwUnoInternalPaM() 153 { 154 while( GetNext() != this) 155 { 156 delete GetNext(); 157 } 158 } 159 160 SwUnoInternalPaM& SwUnoInternalPaM::operator=(const SwPaM& rPaM) 161 { 162 const SwPaM* pTmp = &rPaM; 163 *GetPoint() = *rPaM.GetPoint(); 164 if(rPaM.HasMark()) 165 { 166 SetMark(); 167 *GetMark() = *rPaM.GetMark(); 168 } 169 else 170 DeleteMark(); 171 while(&rPaM != (pTmp = (const SwPaM*)pTmp->GetNext())) 172 { 173 if(pTmp->HasMark()) 174 new SwPaM(*pTmp->GetMark(), *pTmp->GetPoint(), this); 175 else 176 new SwPaM(*pTmp->GetPoint(), this); 177 } 178 return *this; 179 } 180 181 /*-----------------09.03.98 08:29------------------- 182 183 --------------------------------------------------*/ 184 void SwUnoCursorHelper::SelectPam(SwPaM & rPam, const bool bExpand) 185 { 186 if (bExpand) 187 { 188 if (!rPam.HasMark()) 189 { 190 rPam.SetMark(); 191 } 192 } 193 else if (rPam.HasMark()) 194 { 195 rPam.DeleteMark(); 196 } 197 } 198 199 /* -----------------20.05.98 14:59------------------- 200 * 201 * --------------------------------------------------*/ 202 void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer) 203 { 204 if (!rPam.HasMark()) 205 { 206 return; 207 } 208 SvCacheStream aStream( 20480 ); 209 #ifdef OSL_BIGENDIAN 210 aStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN ); 211 #else 212 aStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN ); 213 #endif 214 WriterRef xWrt; 215 // TODO/MBA: looks like a BaseURL doesn't make sense here 216 SwReaderWriter::GetWriter( C2S(FILTER_TEXT_DLG), String(), xWrt ); 217 if( xWrt.Is() ) 218 { 219 SwWriter aWriter( aStream, rPam ); 220 xWrt->bASCII_NoLastLineEnd = sal_True; 221 xWrt->bExportPargraphNumbering = sal_False; 222 SwAsciiOptions aOpt = xWrt->GetAsciiOptions(); 223 aOpt.SetCharSet( RTL_TEXTENCODING_UNICODE ); 224 xWrt->SetAsciiOptions( aOpt ); 225 xWrt->bUCS2_WithStartChar = sal_False; 226 // --> FME #i68522# 227 const sal_Bool bOldShowProgress = xWrt->bShowProgress; 228 xWrt->bShowProgress = sal_False; 229 // <-- 230 231 long lLen; 232 if( !IsError( aWriter.Write( xWrt ) ) && 233 0x7ffffff > (( lLen = aStream.GetSize() ) 234 / sizeof( sal_Unicode )) + 1 ) 235 { 236 aStream << (sal_Unicode)'\0'; 237 238 long lUniLen = (lLen / sizeof( sal_Unicode )); 239 ::rtl::OUStringBuffer aStrBuffer( lUniLen ); 240 aStream.Seek( 0 ); 241 aStream.ResetError(); 242 while(lUniLen) 243 { 244 String sBuf; 245 sal_Int32 nLocalLen = 0; 246 if( lUniLen >= STRING_MAXLEN ) 247 { 248 nLocalLen = STRING_MAXLEN - 1; 249 } 250 else 251 { 252 nLocalLen = lUniLen; 253 } 254 sal_Unicode *const pStrBuf = 255 sBuf.AllocBuffer( xub_StrLen( nLocalLen + 1)); 256 aStream.Read( pStrBuf, 2 * nLocalLen ); 257 pStrBuf[ nLocalLen ] = '\0'; 258 aStrBuffer.append( pStrBuf, nLocalLen ); 259 lUniLen -= nLocalLen; 260 } 261 rBuffer = aStrBuffer.makeStringAndClear(); 262 } 263 xWrt->bShowProgress = bOldShowProgress; 264 } 265 } 266 267 /* -----------------06.07.98 07:33------------------- 268 * 269 * --------------------------------------------------*/ 270 static void 271 lcl_setCharStyle(SwDoc *const pDoc, const uno::Any & rValue, SfxItemSet & rSet) 272 throw (lang::IllegalArgumentException) 273 { 274 SwDocShell *const pDocSh = pDoc->GetDocShell(); 275 if(pDocSh) 276 { 277 OUString uStyle; 278 if (!(rValue >>= uStyle)) 279 { 280 throw lang::IllegalArgumentException(); 281 } 282 String sStyle; 283 SwStyleNameMapper::FillUIName(uStyle, sStyle, 284 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True); 285 SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>( 286 pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR)); 287 if (!pStyle) 288 { 289 throw lang::IllegalArgumentException(); 290 } 291 const SwFmtCharFmt aFmt(pStyle->GetCharFmt()); 292 rSet.Put(aFmt); 293 } 294 }; 295 /* -----------------08.06.06 10:43------------------- 296 * 297 * --------------------------------------------------*/ 298 static void 299 lcl_setAutoStyle(IStyleAccess & rStyleAccess, const uno::Any & rValue, 300 SfxItemSet & rSet, const bool bPara) 301 throw (lang::IllegalArgumentException) 302 { 303 OUString uStyle; 304 if (!(rValue >>= uStyle)) 305 { 306 throw lang::IllegalArgumentException(); 307 } 308 StylePool::SfxItemSet_Pointer_t pStyle = bPara ? 309 rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_PARA ): 310 rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_CHAR ); 311 if(pStyle.get()) 312 { 313 SwFmtAutoFmt aFmt( (bPara) 314 ? sal::static_int_cast< sal_uInt16 >(RES_AUTO_STYLE) 315 : sal::static_int_cast< sal_uInt16 >(RES_TXTATR_AUTOFMT) ); 316 aFmt.SetStyleHandle( pStyle ); 317 rSet.Put(aFmt); 318 } 319 else 320 { 321 throw lang::IllegalArgumentException(); 322 } 323 }; 324 /* -----------------30.06.98 08:46------------------- 325 * 326 * --------------------------------------------------*/ 327 void 328 SwUnoCursorHelper::SetTxtFmtColl(const uno::Any & rAny, SwPaM & rPaM) 329 throw (lang::IllegalArgumentException) 330 { 331 SwDoc *const pDoc = rPaM.GetDoc(); 332 SwDocShell *const pDocSh = pDoc->GetDocShell(); 333 if(!pDocSh) 334 return; 335 OUString uStyle; 336 rAny >>= uStyle; 337 String sStyle; 338 SwStyleNameMapper::FillUIName(uStyle, sStyle, 339 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True ); 340 SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>( 341 pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_PARA)); 342 if (!pStyle) 343 { 344 throw lang::IllegalArgumentException(); 345 } 346 347 SwTxtFmtColl *const pLocal = pStyle->GetCollection(); 348 UnoActionContext aAction(pDoc); 349 pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL ); 350 SwPaM *pTmpCrsr = &rPaM; 351 do { 352 pDoc->SetTxtFmtColl(*pTmpCrsr, pLocal); 353 pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext()); 354 } while ( pTmpCrsr != &rPaM ); 355 pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL ); 356 } 357 358 /* -----------------06.07.98 07:38------------------- 359 * 360 * --------------------------------------------------*/ 361 bool 362 SwUnoCursorHelper::SetPageDesc( 363 const uno::Any& rValue, SwDoc & rDoc, SfxItemSet & rSet) 364 { 365 OUString uDescName; 366 if (!(rValue >>= uDescName)) 367 { 368 return false; 369 } 370 ::std::auto_ptr<SwFmtPageDesc> pNewDesc; 371 const SfxPoolItem* pItem; 372 if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) ) 373 { 374 pNewDesc.reset(new SwFmtPageDesc( 375 *static_cast<const SwFmtPageDesc*>(pItem))); 376 } 377 if (!pNewDesc.get()) 378 { 379 pNewDesc.reset(new SwFmtPageDesc()); 380 } 381 String sDescName; 382 SwStyleNameMapper::FillUIName(uDescName, sDescName, 383 nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True); 384 if (!pNewDesc->GetPageDesc() || 385 (pNewDesc->GetPageDesc()->GetName() != sDescName)) 386 { 387 sal_Bool bPut = sal_False; 388 if(sDescName.Len()) 389 { 390 SwPageDesc *const pPageDesc = 391 ::GetPageDescByName_Impl(rDoc, sDescName); 392 if (!pPageDesc) 393 { 394 throw lang::IllegalArgumentException(); 395 } 396 pNewDesc.get()->RegisterToPageDesc( *pPageDesc ); 397 bPut = sal_True; 398 } 399 if(!bPut) 400 { 401 rSet.ClearItem(RES_BREAK); 402 rSet.Put(SwFmtPageDesc()); 403 } 404 else 405 { 406 rSet.Put(*pNewDesc); 407 } 408 } 409 return true; 410 } 411 412 /* -----------------30.06.98 10:29------------------- 413 * 414 * --------------------------------------------------*/ 415 static void 416 lcl_SetNodeNumStart(SwPaM & rCrsr, uno::Any const& rValue) 417 { 418 sal_Int16 nTmp = 1; 419 rValue >>= nTmp; 420 sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : (sal_uInt16)nTmp); 421 SwDoc* pDoc = rCrsr.GetDoc(); 422 UnoActionContext aAction(pDoc); 423 424 if( rCrsr.GetNext() != &rCrsr ) // Mehrfachselektion ? 425 { 426 pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL ); 427 SwPamRanges aRangeArr( rCrsr ); 428 SwPaM aPam( *rCrsr.GetPoint() ); 429 for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n ) 430 { 431 pDoc->SetNumRuleStart(*aRangeArr.SetPam( n, aPam ).GetPoint()); 432 pDoc->SetNodeNumStart(*aRangeArr.SetPam( n, aPam ).GetPoint(), 433 nStt ); 434 } 435 pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL ); 436 } 437 else 438 { 439 pDoc->SetNumRuleStart( *rCrsr.GetPoint()); 440 pDoc->SetNodeNumStart( *rCrsr.GetPoint(), nStt ); 441 } 442 } 443 444 static bool 445 lcl_setCharFmtSequence(SwPaM & rPam, uno::Any const& rValue) 446 { 447 uno::Sequence<OUString> aCharStyles; 448 if (!(rValue >>= aCharStyles)) 449 { 450 return false; 451 } 452 453 for (sal_Int32 nStyle = 0; nStyle < aCharStyles.getLength(); nStyle++) 454 { 455 uno::Any aStyle; 456 rPam.GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_START, NULL); 457 aStyle <<= aCharStyles.getConstArray()[nStyle]; 458 // create a local set and apply each format directly 459 SfxItemSet aSet(rPam.GetDoc()->GetAttrPool(), 460 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT); 461 lcl_setCharStyle(rPam.GetDoc(), aStyle, aSet); 462 // the first style should replace the current attributes, 463 // all other have to be added 464 SwUnoCursorHelper::SetCrsrAttr(rPam, aSet, (nStyle) 465 ? nsSetAttrMode::SETATTR_DONTREPLACE 466 : nsSetAttrMode::SETATTR_DEFAULT); 467 rPam.GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_START, NULL); 468 } 469 return true; 470 } 471 472 static void 473 lcl_setDropcapCharStyle(SwPaM & rPam, SfxItemSet & rItemSet, 474 uno::Any const& rValue) 475 { 476 OUString uStyle; 477 if (!(rValue >>= uStyle)) 478 { 479 throw lang::IllegalArgumentException(); 480 } 481 String sStyle; 482 SwStyleNameMapper::FillUIName(uStyle, sStyle, 483 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True); 484 SwDoc *const pDoc = rPam.GetDoc(); 485 //default character style must not be set as default format 486 SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>( 487 pDoc->GetDocShell() 488 ->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR)); 489 if (!pStyle || 490 (static_cast<SwDocStyleSheet*>(pStyle)->GetCharFmt() == 491 pDoc->GetDfltCharFmt())) 492 { 493 throw lang::IllegalArgumentException(); 494 } 495 ::std::auto_ptr<SwFmtDrop> pDrop; 496 SfxPoolItem const* pItem(0); 497 if (SFX_ITEM_SET == 498 rItemSet.GetItemState(RES_PARATR_DROP, sal_True, &pItem)) 499 { 500 pDrop.reset(new SwFmtDrop(*static_cast<const SwFmtDrop*>(pItem))); 501 } 502 if (!pDrop.get()) 503 { 504 pDrop.reset(new SwFmtDrop); 505 } 506 const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*pStyle)); 507 pDrop->SetCharFmt(xStyle->GetCharFmt()); 508 rItemSet.Put(*pDrop); 509 } 510 511 static void 512 lcl_setRubyCharstyle(SfxItemSet & rItemSet, uno::Any const& rValue) 513 { 514 OUString sTmp; 515 if (!(rValue >>= sTmp)) 516 { 517 throw lang::IllegalArgumentException(); 518 } 519 520 ::std::auto_ptr<SwFmtRuby> pRuby; 521 const SfxPoolItem* pItem; 522 if (SFX_ITEM_SET == 523 rItemSet.GetItemState(RES_TXTATR_CJK_RUBY, sal_True, &pItem)) 524 { 525 pRuby.reset(new SwFmtRuby(*static_cast<const SwFmtRuby*>(pItem))); 526 } 527 if (!pRuby.get()) 528 { 529 pRuby.reset(new SwFmtRuby(aEmptyStr)); 530 } 531 String sStyle; 532 SwStyleNameMapper::FillUIName(sTmp, sStyle, 533 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True ); 534 pRuby->SetCharFmtName(sStyle); 535 pRuby->SetCharFmtId(0); 536 if (sStyle.Len() > 0) 537 { 538 const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( 539 sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT); 540 pRuby->SetCharFmtId(nId); 541 } 542 rItemSet.Put(*pRuby); 543 } 544 545 /* -----------------17.09.98 09:44------------------- 546 * 547 * --------------------------------------------------*/ 548 bool 549 SwUnoCursorHelper::SetCursorPropertyValue( 550 SfxItemPropertySimpleEntry const& rEntry, const uno::Any& rValue, 551 SwPaM & rPam, SfxItemSet & rItemSet) 552 throw (lang::IllegalArgumentException) 553 { 554 if (!(rEntry.nFlags & beans::PropertyAttribute::MAYBEVOID) && 555 (rValue.getValueType() == ::getCppuVoidType())) 556 { 557 return false; 558 } 559 bool bRet = true; 560 switch (rEntry.nWID) 561 { 562 case RES_TXTATR_CHARFMT: 563 lcl_setCharStyle(rPam.GetDoc(), rValue, rItemSet); 564 break; 565 case RES_TXTATR_AUTOFMT: 566 lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(), 567 rValue, rItemSet, false); 568 break; 569 case FN_UNO_CHARFMT_SEQUENCE: 570 lcl_setCharFmtSequence(rPam, rValue); 571 break; 572 case FN_UNO_PARA_STYLE : 573 SwUnoCursorHelper::SetTxtFmtColl(rValue, rPam); 574 break; 575 case RES_AUTO_STYLE: 576 lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(), 577 rValue, rItemSet, true); 578 break; 579 case FN_UNO_PAGE_STYLE: 580 //FIXME nothing here? 581 break; 582 case FN_UNO_NUM_START_VALUE: 583 lcl_SetNodeNumStart( rPam, rValue ); 584 break; 585 case FN_UNO_NUM_LEVEL: 586 // --> OD 2008-07-14 #i91601# 587 case FN_UNO_LIST_ID: 588 // <-- 589 case FN_UNO_IS_NUMBER: 590 { 591 // multi selection is not considered 592 SwTxtNode *const pTxtNd = rPam.GetNode()->GetTxtNode(); 593 // --> OD 2008-05-14 #refactorlists# - check on list style not needed 594 // const SwNumRule* pRule = pTxtNd->GetNumRule(); 595 // if( FN_UNO_NUM_LEVEL == rEntry.nWID && pRule != NULL ) 596 if (FN_UNO_NUM_LEVEL == rEntry.nWID) 597 // <-- 598 { 599 sal_Int16 nLevel = 0; 600 if (rValue >>= nLevel) 601 { 602 pTxtNd->SetAttrListLevel(nLevel); 603 } 604 } 605 // --> OD 2008-07-14 #i91601# 606 else if (FN_UNO_LIST_ID == rEntry.nWID) 607 { 608 ::rtl::OUString sListId; 609 if (rValue >>= sListId) 610 { 611 pTxtNd->SetListId( sListId ); 612 } 613 } 614 // <-- 615 else if (FN_UNO_IS_NUMBER == rEntry.nWID) 616 { 617 sal_Bool bIsNumber(sal_False); 618 if (rValue >>= bIsNumber) 619 { 620 if (!bIsNumber) 621 { 622 pTxtNd->SetCountedInList( false ); 623 } 624 } 625 } 626 //PROPERTY_MAYBEVOID! 627 } 628 break; 629 case FN_NUMBER_NEWSTART: 630 { 631 sal_Bool bVal = sal_False; 632 if (!(rValue >>= bVal)) 633 { 634 throw lang::IllegalArgumentException(); 635 } 636 rPam.GetDoc()->SetNumRuleStart(*rPam.GetPoint(), bVal); 637 } 638 break; 639 case FN_UNO_NUM_RULES: 640 SwUnoCursorHelper::setNumberingProperty(rValue, rPam); 641 break; 642 case RES_PARATR_DROP: 643 { 644 if (MID_DROPCAP_CHAR_STYLE_NAME == rEntry.nMemberId) 645 { 646 lcl_setDropcapCharStyle(rPam, rItemSet, rValue); 647 } 648 else 649 { 650 bRet = false; 651 } 652 } 653 break; 654 case RES_TXTATR_CJK_RUBY: 655 { 656 if (MID_RUBY_CHARSTYLE == rEntry.nMemberId) 657 { 658 lcl_setRubyCharstyle(rItemSet, rValue); 659 } 660 else 661 { 662 bRet = false; 663 } 664 } 665 break; 666 case RES_PAGEDESC: 667 { 668 if (MID_PAGEDESC_PAGEDESCNAME == rEntry.nMemberId) 669 { 670 SwUnoCursorHelper::SetPageDesc( 671 rValue, *rPam.GetDoc(), rItemSet); 672 } 673 else 674 { 675 bRet = false; 676 } 677 } 678 break; 679 default: 680 bRet = false; 681 } 682 return bRet; 683 } 684 685 /* -----------------30.06.98 08:39------------------- 686 * 687 * --------------------------------------------------*/ 688 SwFmtColl * 689 SwUnoCursorHelper::GetCurTxtFmtColl(SwPaM & rPaM, const bool bConditional) 690 { 691 static const sal_uInt16 nMaxLookup = 1000; 692 SwFmtColl *pFmt = 0; 693 694 // if ( GetCrsrCnt() > nMaxLookup ) 695 // return 0; 696 bool bError = false; 697 SwPaM *pTmpCrsr = &rPaM; 698 do 699 { 700 const sal_uLong nSttNd = pTmpCrsr->Start()->nNode.GetIndex(); 701 const sal_uLong nEndNd = pTmpCrsr->End()->nNode.GetIndex(); 702 703 if( nEndNd - nSttNd >= nMaxLookup ) 704 { 705 pFmt = 0; 706 break; 707 } 708 709 const SwNodes& rNds = rPaM.GetDoc()->GetNodes(); 710 for( sal_uLong n = nSttNd; n <= nEndNd; ++n ) 711 { 712 SwTxtNode const*const pNd = rNds[ n ]->GetTxtNode(); 713 if( pNd ) 714 { 715 SwFmtColl *const pNdFmt = (bConditional) 716 ? pNd->GetFmtColl() : &pNd->GetAnyFmtColl(); 717 if( !pFmt ) 718 { 719 pFmt = pNdFmt; 720 } 721 else if( pFmt != pNdFmt ) 722 { 723 bError = true; 724 break; 725 } 726 } 727 } 728 729 pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext()); 730 } while ( pTmpCrsr != &rPaM ); 731 return (bError) ? 0 : pFmt; 732 } 733 734 /* -----------------26.06.98 16:20------------------- 735 * Hilfsfunktion fuer PageDesc 736 * --------------------------------------------------*/ 737 SwPageDesc* GetPageDescByName_Impl(SwDoc& rDoc, const String& rName) 738 { 739 SwPageDesc* pRet = 0; 740 sal_uInt16 nDCount = rDoc.GetPageDescCnt(); 741 sal_uInt16 i; 742 743 for( i = 0; i < nDCount; i++ ) 744 { 745 SwPageDesc* pDsc = &rDoc._GetPageDesc( i ); 746 if(pDsc->GetName() == rName) 747 { 748 pRet = pDsc; 749 break; 750 } 751 } 752 if(!pRet) 753 { 754 for(i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i) 755 { 756 const String aFmtName(SW_RES(i)); 757 if(aFmtName == rName) 758 { 759 pRet = rDoc.GetPageDescFromPool( static_cast< sal_uInt16 >( 760 RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN) ); 761 break; 762 } 763 } 764 } 765 766 return pRet; 767 } 768 769 /****************************************************************** 770 * SwXTextCursor 771 ******************************************************************/ 772 773 class SwXTextCursor::Impl 774 : public SwClient 775 { 776 777 public: 778 779 const SfxItemPropertySet & m_rPropSet; 780 const enum CursorType m_eType; 781 const uno::Reference< text::XText > m_xParentText; 782 SwEventListenerContainer m_ListenerContainer; 783 bool m_bIsDisposed; 784 785 Impl( SwXTextCursor & rThis, 786 SwDoc & rDoc, 787 const enum CursorType eType, 788 uno::Reference<text::XText> xParent, 789 SwPosition const& rPoint, SwPosition const*const pMark) 790 : SwClient(rDoc.CreateUnoCrsr(rPoint, sal_False)) 791 , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)) 792 , m_eType(eType) 793 , m_xParentText(xParent) 794 , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) 795 , m_bIsDisposed(false) 796 { 797 if (pMark) 798 { 799 GetCursor()->SetMark(); 800 *GetCursor()->GetMark() = *pMark; 801 } 802 } 803 804 ~Impl() { 805 // Impl owns the cursor; delete it here: SolarMutex is locked 806 delete GetRegisteredIn(); 807 } 808 809 SwUnoCrsr * GetCursor() { 810 return (m_bIsDisposed) ? 0 : 811 static_cast<SwUnoCrsr*>(const_cast<SwModify*>(GetRegisteredIn())); 812 } 813 814 SwUnoCrsr & GetCursorOrThrow() { 815 SwUnoCrsr *const pUnoCursor( GetCursor() ); 816 if (!pUnoCursor) { 817 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 818 "SwXTextCursor: disposed or invalid")), 0); 819 } 820 return *pUnoCursor; 821 } 822 823 void Invalidate() { 824 m_bIsDisposed = true; 825 m_ListenerContainer.Disposing(); 826 } 827 protected: 828 // SwClient 829 virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew); 830 831 }; 832 833 void SwXTextCursor::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) 834 { 835 ClientModify(this, pOld, pNew); 836 837 if (!GetRegisteredIn() || 838 // if the cursor leaves its designated section, it becomes invalid 839 ((pOld != NULL) && (pOld->Which() == RES_UNOCURSOR_LEAVES_SECTION))) 840 { 841 Invalidate(); 842 } 843 } 844 845 846 SwUnoCrsr const* SwXTextCursor::GetCursor() const 847 { 848 return m_pImpl->GetCursor(); 849 } 850 851 SwUnoCrsr * SwXTextCursor::GetCursor() 852 { 853 return m_pImpl->GetCursor(); 854 } 855 856 /*-- 09.12.98 14:19:01--------------------------------------------------- 857 858 -----------------------------------------------------------------------*/ 859 SwPaM const* SwXTextCursor::GetPaM() const 860 { 861 return m_pImpl->GetCursor(); 862 } 863 864 SwPaM * SwXTextCursor::GetPaM() 865 { 866 return m_pImpl->GetCursor(); 867 } 868 869 /*-- 09.12.98 14:19:02--------------------------------------------------- 870 871 -----------------------------------------------------------------------*/ 872 SwDoc const* SwXTextCursor::GetDoc() const 873 { 874 return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0; 875 } 876 /* -----------------22.07.99 13:52------------------- 877 878 --------------------------------------------------*/ 879 SwDoc * SwXTextCursor::GetDoc() 880 { 881 return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0; 882 } 883 884 885 /*-- 09.12.98 14:19:19--------------------------------------------------- 886 887 -----------------------------------------------------------------------*/ 888 SwXTextCursor::SwXTextCursor( 889 SwDoc & rDoc, 890 uno::Reference< text::XText > const& xParent, 891 const enum CursorType eType, 892 const SwPosition& rPos, 893 SwPosition const*const pMark) 894 : m_pImpl( new SwXTextCursor::Impl(*this, rDoc, eType, xParent, 895 rPos, pMark ) ) 896 { 897 } 898 899 /* -----------------04.03.99 09:02------------------- 900 * 901 * --------------------------------------------------*/ 902 SwXTextCursor::SwXTextCursor(uno::Reference< text::XText > const& xParent, 903 SwPaM const& rSourceCursor, const enum CursorType eType) 904 : m_pImpl( new SwXTextCursor::Impl(*this, *rSourceCursor.GetDoc(), eType, 905 xParent, *rSourceCursor.GetPoint(), 906 rSourceCursor.HasMark() ? rSourceCursor.GetMark() : 0) ) 907 { 908 } 909 910 /*-- 09.12.98 14:19:20--------------------------------------------------- 911 912 -----------------------------------------------------------------------*/ 913 SwXTextCursor::~SwXTextCursor() 914 { 915 } 916 917 /*-- 09.12.98 14:19:18--------------------------------------------------- 918 919 -----------------------------------------------------------------------*/ 920 void SwXTextCursor::DeleteAndInsert(const ::rtl::OUString& rText, 921 const bool bForceExpandHints) 922 { 923 SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor(); 924 if(pUnoCrsr) 925 { 926 // Start/EndAction 927 SwDoc* pDoc = pUnoCrsr->GetDoc(); 928 UnoActionContext aAction(pDoc); 929 const xub_StrLen nTxtLen = rText.getLength(); 930 pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL); 931 SwCursor * pCurrent = pUnoCrsr; 932 do 933 { 934 if (pCurrent->HasMark()) 935 { 936 pDoc->DeleteAndJoin(*pCurrent); 937 } 938 if(nTxtLen) 939 { 940 const bool bSuccess( 941 SwUnoCursorHelper::DocInsertStringSplitCR( 942 *pDoc, *pCurrent, rText, bForceExpandHints ) ); 943 DBG_ASSERT( bSuccess, "Doc->Insert(Str) failed." ); 944 (void) bSuccess; 945 946 SwUnoCursorHelper::SelectPam(*pUnoCrsr, true); 947 pCurrent->Left(rText.getLength(), 948 CRSR_SKIP_CHARS, sal_False, sal_False); 949 } 950 pCurrent = static_cast<SwCursor *>(pCurrent->GetNext()); 951 } while (pCurrent != pUnoCrsr); 952 pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL); 953 } 954 } 955 956 957 enum ForceIntoMetaMode { META_CHECK_BOTH, META_INIT_START, META_INIT_END }; 958 959 static sal_Bool 960 lcl_ForceIntoMeta(SwPaM & rCursor, 961 uno::Reference<text::XText> const & xParentText, 962 const enum ForceIntoMetaMode eMode) 963 { 964 sal_Bool bRet( sal_True ); // means not forced in META_CHECK_BOTH 965 SwXMeta const * const pXMeta( dynamic_cast<SwXMeta*>(xParentText.get()) ); 966 ASSERT(pXMeta, "no parent?"); 967 if (!pXMeta) 968 throw uno::RuntimeException(); 969 SwTxtNode * pTxtNode; 970 xub_StrLen nStart; 971 xub_StrLen nEnd; 972 const bool bSuccess( pXMeta->SetContentRange(pTxtNode, nStart, nEnd) ); 973 ASSERT(bSuccess, "no pam?"); 974 if (!bSuccess) 975 throw uno::RuntimeException(); 976 // force the cursor back into the meta if it has moved outside 977 SwPosition start(*pTxtNode, nStart); 978 SwPosition end(*pTxtNode, nEnd); 979 switch (eMode) 980 { 981 case META_INIT_START: 982 *rCursor.GetPoint() = start; 983 break; 984 case META_INIT_END: 985 *rCursor.GetPoint() = end; 986 break; 987 case META_CHECK_BOTH: 988 if (*rCursor.Start() < start) 989 { 990 *rCursor.Start() = start; 991 bRet = sal_False; 992 } 993 if (*rCursor.End() > end) 994 { 995 *rCursor.End() = end; 996 bRet = sal_False; 997 } 998 break; 999 } 1000 return bRet; 1001 } 1002 1003 bool SwXTextCursor::IsAtEndOfMeta() const 1004 { 1005 if (CURSOR_META == m_pImpl->m_eType) 1006 { 1007 SwUnoCrsr const * const pCursor( m_pImpl->GetCursor() ); 1008 SwXMeta const*const pXMeta( 1009 dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get()) ); 1010 ASSERT(pXMeta, "no meta?"); 1011 if (pCursor && pXMeta) 1012 { 1013 SwTxtNode * pTxtNode; 1014 xub_StrLen nStart; 1015 xub_StrLen nEnd; 1016 const bool bSuccess( 1017 pXMeta->SetContentRange(pTxtNode, nStart, nEnd) ); 1018 ASSERT(bSuccess, "no pam?"); 1019 if (bSuccess) 1020 { 1021 const SwPosition end(*pTxtNode, nEnd); 1022 if ( (*pCursor->GetPoint() == end) 1023 || (*pCursor->GetMark() == end)) 1024 { 1025 return true; 1026 } 1027 } 1028 } 1029 } 1030 return false; 1031 } 1032 1033 /*-- 09.12.98 14:19:19--------------------------------------------------- 1034 1035 -----------------------------------------------------------------------*/ 1036 OUString SwXTextCursor::getImplementationName() throw (uno::RuntimeException) 1037 { 1038 return C2U("SwXTextCursor"); 1039 } 1040 1041 /*-- 09.12.98 14:19:19--------------------------------------------------- 1042 1043 -----------------------------------------------------------------------*/ 1044 static char const*const g_ServicesTextCursor[] = 1045 { 1046 "com.sun.star.text.TextCursor", 1047 "com.sun.star.style.CharacterProperties", 1048 "com.sun.star.style.CharacterPropertiesAsian", 1049 "com.sun.star.style.CharacterPropertiesComplex", 1050 "com.sun.star.style.ParagraphProperties", 1051 "com.sun.star.style.ParagraphPropertiesAsian", 1052 "com.sun.star.style.ParagraphPropertiesComplex", 1053 "com.sun.star.text.TextSortable", 1054 }; 1055 static const size_t g_nServicesTextCursor( 1056 sizeof(g_ServicesTextCursor)/sizeof(g_ServicesTextCursor[0])); 1057 1058 sal_Bool SAL_CALL SwXTextCursor::supportsService(const OUString& rServiceName) 1059 throw (uno::RuntimeException) 1060 { 1061 return ::sw::SupportsServiceImpl( 1062 g_nServicesTextCursor, g_ServicesTextCursor, rServiceName); 1063 } 1064 1065 uno::Sequence< OUString > SAL_CALL 1066 SwXTextCursor::getSupportedServiceNames() throw (uno::RuntimeException) 1067 { 1068 return ::sw::GetSupportedServiceNamesImpl( 1069 g_nServicesTextCursor, g_ServicesTextCursor); 1070 } 1071 1072 /* -----------------------------10.03.00 18:02-------------------------------- 1073 1074 ---------------------------------------------------------------------------*/ 1075 const uno::Sequence< sal_Int8 > & SwXTextCursor::getUnoTunnelId() 1076 { 1077 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 1078 return aSeq; 1079 } 1080 /* -----------------------------10.03.00 18:04-------------------------------- 1081 1082 ---------------------------------------------------------------------------*/ 1083 sal_Int64 SAL_CALL 1084 SwXTextCursor::getSomething(const uno::Sequence< sal_Int8 >& rId) 1085 throw (uno::RuntimeException) 1086 { 1087 const sal_Int64 nRet( ::sw::UnoTunnelImpl<SwXTextCursor>(rId, this) ); 1088 return (nRet) ? nRet : OTextCursorHelper::getSomething(rId); 1089 } 1090 1091 /*-- 09.12.98 14:18:12--------------------------------------------------- 1092 1093 -----------------------------------------------------------------------*/ 1094 void SAL_CALL SwXTextCursor::collapseToStart() throw (uno::RuntimeException) 1095 { 1096 vos::OGuard aGuard(Application::GetSolarMutex()); 1097 1098 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1099 1100 if (rUnoCursor.HasMark()) 1101 { 1102 if (*rUnoCursor.GetPoint() > *rUnoCursor.GetMark()) 1103 { 1104 rUnoCursor.Exchange(); 1105 } 1106 rUnoCursor.DeleteMark(); 1107 } 1108 } 1109 /*-- 09.12.98 14:18:14--------------------------------------------------- 1110 1111 -----------------------------------------------------------------------*/ 1112 void SAL_CALL SwXTextCursor::collapseToEnd() throw (uno::RuntimeException) 1113 { 1114 vos::OGuard aGuard(Application::GetSolarMutex()); 1115 1116 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1117 1118 if (rUnoCursor.HasMark()) 1119 { 1120 if (*rUnoCursor.GetPoint() < *rUnoCursor.GetMark()) 1121 { 1122 rUnoCursor.Exchange(); 1123 } 1124 rUnoCursor.DeleteMark(); 1125 } 1126 } 1127 /*-- 09.12.98 14:18:41--------------------------------------------------- 1128 1129 -----------------------------------------------------------------------*/ 1130 sal_Bool SAL_CALL SwXTextCursor::isCollapsed() throw (uno::RuntimeException) 1131 { 1132 vos::OGuard aGuard(Application::GetSolarMutex()); 1133 1134 sal_Bool bRet = sal_True; 1135 SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor(); 1136 if(pUnoCrsr && pUnoCrsr->GetMark()) 1137 { 1138 bRet = (*pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark()); 1139 } 1140 return bRet; 1141 } 1142 1143 /*-- 09.12.98 14:18:42--------------------------------------------------- 1144 1145 -----------------------------------------------------------------------*/ 1146 sal_Bool SAL_CALL 1147 SwXTextCursor::goLeft(sal_Int16 nCount, sal_Bool Expand) 1148 throw (uno::RuntimeException) 1149 { 1150 vos::OGuard aGuard(Application::GetSolarMutex()); 1151 1152 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1153 1154 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1155 sal_Bool bRet = rUnoCursor.Left( nCount, CRSR_SKIP_CHARS, sal_False, sal_False); 1156 if (CURSOR_META == m_pImpl->m_eType) 1157 { 1158 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1159 META_CHECK_BOTH) 1160 && bRet; 1161 } 1162 return bRet; 1163 } 1164 /*-- 09.12.98 14:18:42--------------------------------------------------- 1165 1166 -----------------------------------------------------------------------*/ 1167 sal_Bool SAL_CALL 1168 SwXTextCursor::goRight(sal_Int16 nCount, sal_Bool Expand) 1169 throw (uno::RuntimeException) 1170 { 1171 vos::OGuard aGuard(Application::GetSolarMutex()); 1172 1173 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1174 1175 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1176 sal_Bool bRet = rUnoCursor.Right(nCount, CRSR_SKIP_CHARS, sal_False, sal_False); 1177 if (CURSOR_META == m_pImpl->m_eType) 1178 { 1179 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1180 META_CHECK_BOTH) 1181 && bRet; 1182 } 1183 return bRet; 1184 } 1185 1186 /*-- 09.12.98 14:18:43--------------------------------------------------- 1187 1188 -----------------------------------------------------------------------*/ 1189 void SAL_CALL 1190 SwXTextCursor::gotoStart(sal_Bool Expand) throw (uno::RuntimeException) 1191 { 1192 vos::OGuard aGuard(Application::GetSolarMutex()); 1193 1194 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1195 1196 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1197 if (CURSOR_BODY == m_pImpl->m_eType) 1198 { 1199 rUnoCursor.Move( fnMoveBackward, fnGoDoc ); 1200 //check, that the cursor is not in a table 1201 SwTableNode * pTblNode = rUnoCursor.GetNode()->FindTableNode(); 1202 SwCntntNode * pCNode = 0; 1203 while (pTblNode) 1204 { 1205 rUnoCursor.GetPoint()->nNode = *pTblNode->EndOfSectionNode(); 1206 pCNode = GetDoc()->GetNodes().GoNext(&rUnoCursor.GetPoint()->nNode); 1207 pTblNode = (pCNode) ? pCNode->FindTableNode() : 0; 1208 } 1209 if (pCNode) 1210 { 1211 rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0); 1212 } 1213 SwStartNode const*const pTmp = 1214 rUnoCursor.GetNode()->StartOfSectionNode(); 1215 if (pTmp->IsSectionNode()) 1216 { 1217 SwSectionNode const*const pSectionStartNode = 1218 static_cast<SwSectionNode const*>(pTmp); 1219 if (pSectionStartNode->GetSection().IsHiddenFlag()) 1220 { 1221 pCNode = GetDoc()->GetNodes().GoNextSection( 1222 &rUnoCursor.GetPoint()->nNode, sal_True, sal_False); 1223 if (pCNode) 1224 { 1225 rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0); 1226 } 1227 } 1228 } 1229 } 1230 else if ( (CURSOR_FRAME == m_pImpl->m_eType) 1231 || (CURSOR_TBLTEXT == m_pImpl->m_eType) 1232 || (CURSOR_HEADER == m_pImpl->m_eType) 1233 || (CURSOR_FOOTER == m_pImpl->m_eType) 1234 || (CURSOR_FOOTNOTE== m_pImpl->m_eType) 1235 || (CURSOR_REDLINE == m_pImpl->m_eType)) 1236 { 1237 rUnoCursor.MoveSection(fnSectionCurr, fnSectionStart); 1238 } 1239 else if (CURSOR_META == m_pImpl->m_eType) 1240 { 1241 lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_START); 1242 } 1243 } 1244 /*-- 09.12.98 14:18:43--------------------------------------------------- 1245 1246 -----------------------------------------------------------------------*/ 1247 void SAL_CALL 1248 SwXTextCursor::gotoEnd(sal_Bool Expand) throw (uno::RuntimeException) 1249 { 1250 vos::OGuard aGuard(Application::GetSolarMutex()); 1251 1252 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1253 1254 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1255 if (CURSOR_BODY == m_pImpl->m_eType) 1256 { 1257 rUnoCursor.Move( fnMoveForward, fnGoDoc ); 1258 } 1259 else if ( (CURSOR_FRAME == m_pImpl->m_eType) 1260 || (CURSOR_TBLTEXT == m_pImpl->m_eType) 1261 || (CURSOR_HEADER == m_pImpl->m_eType) 1262 || (CURSOR_FOOTER == m_pImpl->m_eType) 1263 || (CURSOR_FOOTNOTE== m_pImpl->m_eType) 1264 || (CURSOR_REDLINE == m_pImpl->m_eType)) 1265 { 1266 rUnoCursor.MoveSection( fnSectionCurr, fnSectionEnd); 1267 } 1268 else if (CURSOR_META == m_pImpl->m_eType) 1269 { 1270 lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_END); 1271 } 1272 } 1273 1274 void SAL_CALL 1275 SwXTextCursor::gotoRange( 1276 const uno::Reference< text::XTextRange > & xRange, sal_Bool bExpand) 1277 throw (uno::RuntimeException) 1278 { 1279 vos::OGuard aGuard(Application::GetSolarMutex()); 1280 1281 if (!xRange.is()) 1282 { 1283 throw uno::RuntimeException(); 1284 } 1285 1286 SwUnoCrsr & rOwnCursor( m_pImpl->GetCursorOrThrow() ); 1287 1288 uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY); 1289 SwXTextRange* pRange = 0; 1290 OTextCursorHelper* pCursor = 0; 1291 if(xRangeTunnel.is()) 1292 { 1293 pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel); 1294 pCursor = 1295 ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel); 1296 } 1297 1298 if (!pRange && !pCursor) 1299 { 1300 throw uno::RuntimeException(); 1301 } 1302 1303 SwStartNodeType eSearchNodeType = SwNormalStartNode; 1304 switch (m_pImpl->m_eType) 1305 { 1306 case CURSOR_FRAME: eSearchNodeType = SwFlyStartNode; break; 1307 case CURSOR_TBLTEXT: eSearchNodeType = SwTableBoxStartNode; break; 1308 case CURSOR_FOOTNOTE: eSearchNodeType = SwFootnoteStartNode; break; 1309 case CURSOR_HEADER: eSearchNodeType = SwHeaderStartNode; break; 1310 case CURSOR_FOOTER: eSearchNodeType = SwFooterStartNode; break; 1311 //case CURSOR_INVALID: 1312 //case CURSOR_BODY: 1313 default: 1314 ; 1315 } 1316 const SwStartNode* pOwnStartNode = 1317 rOwnCursor.GetNode()->FindSttNodeByType(eSearchNodeType); 1318 1319 SwPaM aPam(GetDoc()->GetNodes()); 1320 const SwPaM * pPam(0); 1321 if (pCursor) 1322 { 1323 pPam = pCursor->GetPaM(); 1324 } 1325 else if (pRange) 1326 { 1327 if (pRange->GetPositions(aPam)) 1328 { 1329 pPam = & aPam; 1330 } 1331 } 1332 1333 if (!pPam) 1334 { 1335 throw uno::RuntimeException(); 1336 } 1337 const SwStartNode* pTmp = 1338 pPam->GetNode()->FindSttNodeByType(eSearchNodeType); 1339 1340 //SectionNodes ueberspringen 1341 while(pTmp && pTmp->IsSectionNode()) 1342 { 1343 pTmp = pTmp->StartOfSectionNode(); 1344 } 1345 while(pOwnStartNode && pOwnStartNode->IsSectionNode()) 1346 { 1347 pOwnStartNode = pOwnStartNode->StartOfSectionNode(); 1348 } 1349 if(pOwnStartNode != pTmp) 1350 { 1351 throw uno::RuntimeException(); 1352 } 1353 1354 if (CURSOR_META == m_pImpl->m_eType) 1355 { 1356 SwPaM CopyPam(*pPam->GetMark(), *pPam->GetPoint()); 1357 const bool bNotForced( lcl_ForceIntoMeta( 1358 CopyPam, m_pImpl->m_xParentText, META_CHECK_BOTH) ); 1359 if (!bNotForced) 1360 { 1361 throw uno::RuntimeException( 1362 C2U("gotoRange: parameter range not contained in nesting" 1363 " text content for which this cursor was created"), 1364 static_cast<text::XWordCursor*>(this)); 1365 } 1366 } 1367 1368 //jetzt muss die Selektion erweitert werden 1369 if(bExpand) 1370 { 1371 // der Cursor soll alles einschliessen, was bisher von ihm und dem uebergebenen 1372 // Range eingeschlossen wurde 1373 const SwPosition aOwnLeft(*rOwnCursor.Start()); 1374 const SwPosition aOwnRight(*rOwnCursor.End()); 1375 SwPosition const& rParamLeft = *pPam->Start(); 1376 SwPosition const& rParamRight = *pPam->End(); 1377 1378 // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche? 1379 *rOwnCursor.GetPoint() = (aOwnRight > rParamRight) 1380 ? aOwnRight : *rOwnCursor.GetPoint() = rParamRight; 1381 rOwnCursor.SetMark(); 1382 *rOwnCursor.GetMark() = (aOwnLeft < rParamLeft) 1383 ? aOwnLeft : *rOwnCursor.GetMark() = rParamLeft; 1384 } 1385 else 1386 { 1387 // cursor should be the given range 1388 *rOwnCursor.GetPoint() = *pPam->GetPoint(); 1389 if (pPam->HasMark()) 1390 { 1391 rOwnCursor.SetMark(); 1392 *rOwnCursor.GetMark() = *pPam->GetMark(); 1393 } 1394 else 1395 { 1396 rOwnCursor.DeleteMark(); 1397 } 1398 } 1399 } 1400 1401 /*-- 09.12.98 14:18:44--------------------------------------------------- 1402 1403 -----------------------------------------------------------------------*/ 1404 sal_Bool SAL_CALL SwXTextCursor::isStartOfWord() throw (uno::RuntimeException) 1405 { 1406 vos::OGuard aGuard(Application::GetSolarMutex()); 1407 1408 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1409 1410 const sal_Bool bRet = 1411 rUnoCursor.IsStartWordWT( i18n::WordType::DICTIONARY_WORD ); 1412 return bRet; 1413 } 1414 /*-- 09.12.98 14:18:44--------------------------------------------------- 1415 1416 -----------------------------------------------------------------------*/ 1417 sal_Bool SAL_CALL SwXTextCursor::isEndOfWord() throw (uno::RuntimeException) 1418 { 1419 vos::OGuard aGuard(Application::GetSolarMutex()); 1420 1421 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1422 1423 const sal_Bool bRet = 1424 rUnoCursor.IsEndWordWT( i18n::WordType::DICTIONARY_WORD ); 1425 return bRet; 1426 } 1427 1428 /*-- 09.12.98 14:18:44--------------------------------------------------- 1429 1430 -----------------------------------------------------------------------*/ 1431 sal_Bool SAL_CALL 1432 SwXTextCursor::gotoNextWord(sal_Bool Expand) throw (uno::RuntimeException) 1433 { 1434 vos::OGuard aGuard(Application::GetSolarMutex()); 1435 1436 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1437 1438 //Probleme gibt's noch mit einem Absatzanfang, an dem kein Wort beginnt. 1439 sal_Bool bRet = sal_False; 1440 // remember old position to check if cursor has moved 1441 // since the called functions are sometimes a bit unreliable 1442 // in specific cases... 1443 SwPosition *const pPoint = rUnoCursor.GetPoint(); 1444 SwNode *const pOldNode = &pPoint->nNode.GetNode(); 1445 xub_StrLen const nOldIndex = pPoint->nContent.GetIndex(); 1446 1447 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1448 // end of paragraph 1449 if (rUnoCursor.GetCntntNode() && 1450 (pPoint->nContent == rUnoCursor.GetCntntNode()->Len())) 1451 { 1452 rUnoCursor.Right(1, CRSR_SKIP_CHARS, sal_False, sal_False); 1453 } 1454 else 1455 { 1456 const bool bTmp = 1457 rUnoCursor.GoNextWordWT( i18n::WordType::DICTIONARY_WORD ); 1458 // if there is no next word within the current paragraph 1459 // try to go to the start of the next paragraph 1460 if (!bTmp) 1461 { 1462 rUnoCursor.MovePara(fnParaNext, fnParaStart); 1463 } 1464 } 1465 1466 // return true if cursor has moved 1467 bRet = (&pPoint->nNode.GetNode() != pOldNode) || 1468 (pPoint->nContent.GetIndex() != nOldIndex); 1469 if (bRet && (CURSOR_META == m_pImpl->m_eType)) 1470 { 1471 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1472 META_CHECK_BOTH); 1473 } 1474 1475 return bRet; 1476 } 1477 1478 /*-- 09.12.98 14:18:45--------------------------------------------------- 1479 1480 -----------------------------------------------------------------------*/ 1481 sal_Bool SAL_CALL 1482 SwXTextCursor::gotoPreviousWord(sal_Bool Expand) throw (uno::RuntimeException) 1483 { 1484 vos::OGuard aGuard(Application::GetSolarMutex()); 1485 1486 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1487 1488 // hier machen Leerzeichen am Absatzanfang Probleme 1489 sal_Bool bRet = sal_False; 1490 SwPosition *const pPoint = rUnoCursor.GetPoint(); 1491 SwNode *const pOldNode = &pPoint->nNode.GetNode(); 1492 xub_StrLen const nOldIndex = pPoint->nContent.GetIndex(); 1493 1494 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1495 // start of paragraph? 1496 if (pPoint->nContent == 0) 1497 { 1498 rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False); 1499 } 1500 else 1501 { 1502 rUnoCursor.GoPrevWordWT( i18n::WordType::DICTIONARY_WORD ); 1503 if (pPoint->nContent == 0) 1504 { 1505 rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False); 1506 } 1507 } 1508 1509 // return true if cursor has moved 1510 bRet = (&pPoint->nNode.GetNode() != pOldNode) || 1511 (pPoint->nContent.GetIndex() != nOldIndex); 1512 if (bRet && (CURSOR_META == m_pImpl->m_eType)) 1513 { 1514 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1515 META_CHECK_BOTH); 1516 } 1517 1518 return bRet; 1519 } 1520 1521 /*-- 09.12.98 14:18:45--------------------------------------------------- 1522 1523 -----------------------------------------------------------------------*/ 1524 sal_Bool SAL_CALL 1525 SwXTextCursor::gotoEndOfWord(sal_Bool Expand) throw (uno::RuntimeException) 1526 { 1527 vos::OGuard aGuard(Application::GetSolarMutex()); 1528 1529 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1530 1531 sal_Bool bRet = sal_False; 1532 SwPosition *const pPoint = rUnoCursor.GetPoint(); 1533 SwNode & rOldNode = pPoint->nNode.GetNode(); 1534 xub_StrLen const nOldIndex = pPoint->nContent.GetIndex(); 1535 1536 const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD; 1537 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1538 if (!rUnoCursor.IsEndWordWT( nWordType )) 1539 { 1540 rUnoCursor.GoEndWordWT( nWordType ); 1541 } 1542 1543 // restore old cursor if we are not at the end of a word by now 1544 // otherwise use current one 1545 bRet = rUnoCursor.IsEndWordWT( nWordType ); 1546 if (!bRet) 1547 { 1548 pPoint->nNode = rOldNode; 1549 pPoint->nContent = nOldIndex; 1550 } 1551 else if (CURSOR_META == m_pImpl->m_eType) 1552 { 1553 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1554 META_CHECK_BOTH); 1555 } 1556 1557 return bRet; 1558 } 1559 /*-- 09.12.98 14:18:46--------------------------------------------------- 1560 1561 -----------------------------------------------------------------------*/ 1562 sal_Bool SAL_CALL 1563 SwXTextCursor::gotoStartOfWord(sal_Bool Expand) throw (uno::RuntimeException) 1564 { 1565 vos::OGuard aGuard(Application::GetSolarMutex()); 1566 1567 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1568 1569 sal_Bool bRet = sal_False; 1570 SwPosition *const pPoint = rUnoCursor.GetPoint(); 1571 SwNode & rOldNode = pPoint->nNode.GetNode(); 1572 xub_StrLen const nOldIndex = pPoint->nContent.GetIndex(); 1573 1574 const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD; 1575 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1576 if (!rUnoCursor.IsStartWordWT( nWordType )) 1577 { 1578 rUnoCursor.GoStartWordWT( nWordType ); 1579 } 1580 1581 // restore old cursor if we are not at the start of a word by now 1582 // otherwise use current one 1583 bRet = rUnoCursor.IsStartWordWT( nWordType ); 1584 if (!bRet) 1585 { 1586 pPoint->nNode = rOldNode; 1587 pPoint->nContent = nOldIndex; 1588 } 1589 else if (CURSOR_META == m_pImpl->m_eType) 1590 { 1591 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1592 META_CHECK_BOTH); 1593 } 1594 1595 return bRet; 1596 } 1597 1598 /*-- 09.12.98 14:18:46--------------------------------------------------- 1599 1600 -----------------------------------------------------------------------*/ 1601 sal_Bool SAL_CALL 1602 SwXTextCursor::isStartOfSentence() throw (uno::RuntimeException) 1603 { 1604 vos::OGuard aGuard(Application::GetSolarMutex()); 1605 1606 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1607 1608 // start of paragraph? 1609 sal_Bool bRet = rUnoCursor.GetPoint()->nContent == 0; 1610 // with mark ->no sentence start 1611 // (check if cursor is no selection, i.e. it does not have 1612 // a mark or else point and mark are identical) 1613 if (!bRet && (!rUnoCursor.HasMark() || 1614 *rUnoCursor.GetPoint() == *rUnoCursor.GetMark())) 1615 { 1616 SwCursor aCrsr(*rUnoCursor.GetPoint(),0,false); 1617 SwPosition aOrigPos = *aCrsr.GetPoint(); 1618 aCrsr.GoSentence(SwCursor::START_SENT ); 1619 bRet = aOrigPos == *aCrsr.GetPoint(); 1620 } 1621 return bRet; 1622 } 1623 /*-- 09.12.98 14:18:47--------------------------------------------------- 1624 1625 -----------------------------------------------------------------------*/ 1626 sal_Bool SAL_CALL 1627 SwXTextCursor::isEndOfSentence() throw (uno::RuntimeException) 1628 { 1629 vos::OGuard aGuard(Application::GetSolarMutex()); 1630 1631 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1632 1633 // end of paragraph? 1634 sal_Bool bRet = rUnoCursor.GetCntntNode() && 1635 (rUnoCursor.GetPoint()->nContent == rUnoCursor.GetCntntNode()->Len()); 1636 // with mark->no sentence end 1637 // (check if cursor is no selection, i.e. it does not have 1638 // a mark or else point and mark are identical) 1639 if (!bRet && (!rUnoCursor.HasMark() || 1640 *rUnoCursor.GetPoint() == *rUnoCursor.GetMark())) 1641 { 1642 SwCursor aCrsr(*rUnoCursor.GetPoint(), 0, false); 1643 SwPosition aOrigPos = *aCrsr.GetPoint(); 1644 aCrsr.GoSentence(SwCursor::END_SENT); 1645 bRet = aOrigPos == *aCrsr.GetPoint(); 1646 } 1647 return bRet; 1648 } 1649 1650 /*-- 09.12.98 14:18:47--------------------------------------------------- 1651 1652 -----------------------------------------------------------------------*/ 1653 sal_Bool SAL_CALL 1654 SwXTextCursor::gotoNextSentence(sal_Bool Expand) throw (uno::RuntimeException) 1655 { 1656 vos::OGuard aGuard(Application::GetSolarMutex()); 1657 1658 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1659 1660 const bool bWasEOS = isEndOfSentence(); 1661 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1662 sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::NEXT_SENT); 1663 if (!bRet) 1664 { 1665 bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart); 1666 } 1667 1668 // if at the end of the sentence (i.e. at the space after the '.') 1669 // advance to next word in order for GoSentence to work properly 1670 // next time and have isStartOfSentence return true after this call 1671 if (!rUnoCursor.IsStartWord()) 1672 { 1673 const bool bNextWord = rUnoCursor.GoNextWord(); 1674 if (bWasEOS && !bNextWord) 1675 { 1676 bRet = sal_False; 1677 } 1678 } 1679 if (CURSOR_META == m_pImpl->m_eType) 1680 { 1681 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1682 META_CHECK_BOTH) 1683 && bRet; 1684 } 1685 return bRet; 1686 } 1687 /*-- 09.12.98 14:18:47--------------------------------------------------- 1688 1689 -----------------------------------------------------------------------*/ 1690 sal_Bool SAL_CALL 1691 SwXTextCursor::gotoPreviousSentence(sal_Bool Expand) 1692 throw (uno::RuntimeException) 1693 { 1694 vos::OGuard aGuard(Application::GetSolarMutex()); 1695 1696 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1697 1698 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1699 sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::PREV_SENT); 1700 if (!bRet) 1701 { 1702 bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart); 1703 if (bRet) 1704 { 1705 rUnoCursor.MovePara(fnParaCurr, fnParaEnd); 1706 // at the end of a paragraph move to the sentence end again 1707 rUnoCursor.GoSentence(SwCursor::PREV_SENT); 1708 } 1709 } 1710 if (CURSOR_META == m_pImpl->m_eType) 1711 { 1712 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1713 META_CHECK_BOTH) 1714 && bRet; 1715 } 1716 return bRet; 1717 } 1718 1719 /* -----------------15.10.99 08:24------------------- 1720 1721 --------------------------------------------------*/ 1722 sal_Bool SAL_CALL 1723 SwXTextCursor::gotoStartOfSentence(sal_Bool Expand) 1724 throw (uno::RuntimeException) 1725 { 1726 vos::OGuard aGuard(Application::GetSolarMutex()); 1727 1728 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1729 1730 sal_Bool bRet = sal_False; 1731 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1732 // if we're at the para start then we wont move 1733 // but bRet is also true if GoSentence failed but 1734 // the start of the sentence is reached 1735 bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor) 1736 || rUnoCursor.GoSentence(SwCursor::START_SENT) 1737 || SwUnoCursorHelper::IsStartOfPara(rUnoCursor); 1738 if (CURSOR_META == m_pImpl->m_eType) 1739 { 1740 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1741 META_CHECK_BOTH) 1742 && bRet; 1743 } 1744 return bRet; 1745 } 1746 /* -----------------15.10.99 08:24------------------- 1747 1748 --------------------------------------------------*/ 1749 sal_Bool SAL_CALL 1750 SwXTextCursor::gotoEndOfSentence(sal_Bool Expand) throw (uno::RuntimeException) 1751 { 1752 vos::OGuard aGuard(Application::GetSolarMutex()); 1753 1754 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1755 1756 sal_Bool bRet = sal_False; 1757 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1758 // bRet is true if GoSentence() succeeded or if the 1759 // MovePara() succeeded while the end of the para is 1760 // not reached already 1761 sal_Bool bAlreadyParaEnd = SwUnoCursorHelper::IsEndOfPara(rUnoCursor); 1762 bRet = !bAlreadyParaEnd 1763 && (rUnoCursor.GoSentence(SwCursor::END_SENT) 1764 || rUnoCursor.MovePara(fnParaCurr, fnParaEnd)); 1765 if (CURSOR_META == m_pImpl->m_eType) 1766 { 1767 bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, 1768 META_CHECK_BOTH) 1769 && bRet; 1770 } 1771 return bRet; 1772 } 1773 1774 /*-- 09.12.98 14:18:48--------------------------------------------------- 1775 1776 -----------------------------------------------------------------------*/ 1777 sal_Bool SAL_CALL 1778 SwXTextCursor::isStartOfParagraph() throw (uno::RuntimeException) 1779 { 1780 vos::OGuard aGuard(Application::GetSolarMutex()); 1781 1782 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1783 1784 const sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor); 1785 return bRet; 1786 } 1787 /*-- 09.12.98 14:18:48--------------------------------------------------- 1788 1789 -----------------------------------------------------------------------*/ 1790 sal_Bool SAL_CALL 1791 SwXTextCursor::isEndOfParagraph() throw (uno::RuntimeException) 1792 { 1793 vos::OGuard aGuard(Application::GetSolarMutex()); 1794 1795 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1796 1797 const sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor); 1798 return bRet; 1799 } 1800 1801 /*-- 09.12.98 14:18:49--------------------------------------------------- 1802 1803 -----------------------------------------------------------------------*/ 1804 sal_Bool SAL_CALL 1805 SwXTextCursor::gotoStartOfParagraph(sal_Bool Expand) 1806 throw (uno::RuntimeException) 1807 { 1808 vos::OGuard aGuard(Application::GetSolarMutex()); 1809 1810 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1811 1812 if (CURSOR_META == m_pImpl->m_eType) 1813 { 1814 return sal_False; 1815 } 1816 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1817 sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor); 1818 if (!bRet) 1819 { 1820 bRet = rUnoCursor.MovePara(fnParaCurr, fnParaStart); 1821 } 1822 1823 // since MovePara(fnParaCurr, fnParaStart) only returns false 1824 // if we were already at the start of the paragraph this function 1825 // should always complete successfully. 1826 DBG_ASSERT( bRet, "gotoStartOfParagraph failed" ); 1827 return bRet; 1828 } 1829 /*-- 09.12.98 14:18:49--------------------------------------------------- 1830 1831 -----------------------------------------------------------------------*/ 1832 sal_Bool SAL_CALL 1833 SwXTextCursor::gotoEndOfParagraph(sal_Bool Expand) throw (uno::RuntimeException) 1834 { 1835 vos::OGuard aGuard(Application::GetSolarMutex()); 1836 1837 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1838 1839 if (CURSOR_META == m_pImpl->m_eType) 1840 { 1841 return sal_False; 1842 } 1843 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1844 sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor); 1845 if (!bRet) 1846 { 1847 bRet = rUnoCursor.MovePara(fnParaCurr, fnParaEnd); 1848 } 1849 1850 // since MovePara(fnParaCurr, fnParaEnd) only returns false 1851 // if we were already at the end of the paragraph this function 1852 // should always complete successfully. 1853 DBG_ASSERT( bRet, "gotoEndOfParagraph failed" ); 1854 return bRet; 1855 } 1856 1857 /*-- 09.12.98 14:18:50--------------------------------------------------- 1858 1859 -----------------------------------------------------------------------*/ 1860 sal_Bool SAL_CALL 1861 SwXTextCursor::gotoNextParagraph(sal_Bool Expand) throw (uno::RuntimeException) 1862 { 1863 vos::OGuard aGuard(Application::GetSolarMutex()); 1864 1865 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1866 1867 if (CURSOR_META == m_pImpl->m_eType) 1868 { 1869 return sal_False; 1870 } 1871 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1872 const sal_Bool bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart); 1873 return bRet; 1874 } 1875 /*-- 09.12.98 14:18:50--------------------------------------------------- 1876 1877 -----------------------------------------------------------------------*/ 1878 sal_Bool SAL_CALL 1879 SwXTextCursor::gotoPreviousParagraph(sal_Bool Expand) 1880 throw (uno::RuntimeException) 1881 { 1882 vos::OGuard aGuard(Application::GetSolarMutex()); 1883 1884 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1885 1886 if (CURSOR_META == m_pImpl->m_eType) 1887 { 1888 return sal_False; 1889 } 1890 SwUnoCursorHelper::SelectPam(rUnoCursor, Expand); 1891 const sal_Bool bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart); 1892 return bRet; 1893 } 1894 1895 /*-- 09.12.98 14:18:50--------------------------------------------------- 1896 1897 -----------------------------------------------------------------------*/ 1898 uno::Reference< text::XText > SAL_CALL 1899 SwXTextCursor::getText() throw (uno::RuntimeException) 1900 { 1901 vos::OGuard g(Application::GetSolarMutex()); 1902 1903 return m_pImpl->m_xParentText; 1904 } 1905 1906 /*-- 09.12.98 14:18:50--------------------------------------------------- 1907 1908 -----------------------------------------------------------------------*/ 1909 uno::Reference< text::XTextRange > SAL_CALL 1910 SwXTextCursor::getStart() throw (uno::RuntimeException) 1911 { 1912 vos::OGuard aGuard(Application::GetSolarMutex()); 1913 1914 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1915 1916 uno::Reference< text::XTextRange > xRet; 1917 SwPaM aPam(*rUnoCursor.Start()); 1918 const uno::Reference< text::XText > xParent = getText(); 1919 if (CURSOR_META == m_pImpl->m_eType) 1920 { 1921 // return cursor to prevent modifying SwXTextRange for META 1922 SwXTextCursor * const pXCursor( 1923 new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META, 1924 *rUnoCursor.GetPoint()) ); 1925 pXCursor->gotoStart(sal_False); 1926 xRet = static_cast<text::XWordCursor*>(pXCursor); 1927 } 1928 else 1929 { 1930 xRet = new SwXTextRange(aPam, xParent); 1931 } 1932 return xRet; 1933 } 1934 /*-- 09.12.98 14:18:51--------------------------------------------------- 1935 1936 -----------------------------------------------------------------------*/ 1937 uno::Reference< text::XTextRange > SAL_CALL 1938 SwXTextCursor::getEnd() throw (uno::RuntimeException) 1939 { 1940 vos::OGuard aGuard(Application::GetSolarMutex()); 1941 1942 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1943 1944 uno::Reference< text::XTextRange > xRet; 1945 SwPaM aPam(*rUnoCursor.End()); 1946 const uno::Reference< text::XText > xParent = getText(); 1947 if (CURSOR_META == m_pImpl->m_eType) 1948 { 1949 // return cursor to prevent modifying SwXTextRange for META 1950 SwXTextCursor * const pXCursor( 1951 new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META, 1952 *rUnoCursor.GetPoint()) ); 1953 pXCursor->gotoEnd(sal_False); 1954 xRet = static_cast<text::XWordCursor*>(pXCursor); 1955 } 1956 else 1957 { 1958 xRet = new SwXTextRange(aPam, xParent); 1959 } 1960 return xRet; 1961 } 1962 1963 /*-- 09.12.98 14:18:51--------------------------------------------------- 1964 1965 -----------------------------------------------------------------------*/ 1966 OUString SAL_CALL SwXTextCursor::getString() throw (uno::RuntimeException) 1967 { 1968 vos::OGuard aGuard(Application::GetSolarMutex()); 1969 1970 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1971 1972 OUString aTxt; 1973 SwUnoCursorHelper::GetTextFromPam(rUnoCursor, aTxt); 1974 return aTxt; 1975 } 1976 /*-- 09.12.98 14:18:52--------------------------------------------------- 1977 1978 -----------------------------------------------------------------------*/ 1979 void SAL_CALL 1980 SwXTextCursor::setString(const OUString& aString) throw (uno::RuntimeException) 1981 { 1982 vos::OGuard aGuard(Application::GetSolarMutex()); 1983 1984 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 1985 (void) rUnoCursor; // just to check if valid 1986 1987 const bool bForceExpandHints( (CURSOR_META != m_pImpl->m_eType) 1988 ? false 1989 : dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get()) 1990 ->CheckForOwnMemberMeta(*GetPaM(), true) ); 1991 DeleteAndInsert(aString, bForceExpandHints); 1992 } 1993 1994 /* -----------------------------03.05.00 12:56-------------------------------- 1995 1996 ---------------------------------------------------------------------------*/ 1997 uno::Any SwUnoCursorHelper::GetPropertyValue( 1998 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 1999 const OUString& rPropertyName) 2000 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2001 uno::RuntimeException) 2002 { 2003 uno::Any aAny; 2004 SfxItemPropertySimpleEntry const*const pEntry = 2005 rPropSet.getPropertyMap()->getByName(rPropertyName); 2006 2007 if (!pEntry) 2008 { 2009 throw beans::UnknownPropertyException( 2010 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2011 + rPropertyName, static_cast<cppu::OWeakObject *>(0)); 2012 } 2013 2014 beans::PropertyState eTemp; 2015 const sal_Bool bDone = SwUnoCursorHelper::getCrsrPropertyValue( 2016 *pEntry, rPaM, &aAny, eTemp ); 2017 2018 if (!bDone) 2019 { 2020 SfxItemSet aSet(rPaM.GetDoc()->GetAttrPool(), 2021 RES_CHRATR_BEGIN, RES_FRMATR_END - 1, 2022 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, 2023 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, 2024 0L); 2025 SwUnoCursorHelper::GetCrsrAttr(rPaM, aSet); 2026 2027 rPropSet.getPropertyValue(*pEntry, aSet, aAny); 2028 } 2029 2030 return aAny; 2031 } 2032 /* -----------------------------03.05.00 12:57-------------------------------- 2033 2034 ---------------------------------------------------------------------------*/ 2035 void SwUnoCursorHelper::SetPropertyValue( 2036 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 2037 const OUString& rPropertyName, 2038 const uno::Any& rValue, 2039 const SetAttrMode nAttrMode, const bool bTableMode) 2040 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 2041 lang::IllegalArgumentException, lang::WrappedTargetException, 2042 uno::RuntimeException) 2043 { 2044 SwDoc *const pDoc = rPaM.GetDoc(); 2045 SfxItemPropertySimpleEntry const*const pEntry = 2046 rPropSet.getPropertyMap()->getByName(rPropertyName); 2047 if (!pEntry) 2048 { 2049 throw beans::UnknownPropertyException( 2050 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2051 + rPropertyName, 2052 static_cast<cppu::OWeakObject *>(0)); 2053 } 2054 2055 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 2056 { 2057 throw beans::PropertyVetoException( 2058 OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) 2059 + rPropertyName, 2060 static_cast<cppu::OWeakObject *>(0)); 2061 } 2062 2063 SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID ); 2064 SwUnoCursorHelper::GetCrsrAttr( rPaM, aItemSet ); 2065 2066 if (!SwUnoCursorHelper::SetCursorPropertyValue( 2067 *pEntry, rValue, rPaM, aItemSet)) 2068 { 2069 rPropSet.setPropertyValue(*pEntry, rValue, aItemSet ); 2070 } 2071 SwUnoCursorHelper::SetCrsrAttr(rPaM, aItemSet, nAttrMode, bTableMode); 2072 } 2073 2074 /* -----------------------------03.05.00 13:16-------------------------------- 2075 2076 ---------------------------------------------------------------------------*/ 2077 uno::Sequence< beans::PropertyState > 2078 SwUnoCursorHelper::GetPropertyStates( 2079 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 2080 const uno::Sequence< OUString >& rPropertyNames, 2081 const SwGetPropertyStatesCaller eCaller) 2082 throw (beans::UnknownPropertyException, uno::RuntimeException) 2083 { 2084 const OUString* pNames = rPropertyNames.getConstArray(); 2085 uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength()); 2086 beans::PropertyState* pStates = aRet.getArray(); 2087 SfxItemPropertyMap const*const pMap = rPropSet.getPropertyMap(); 2088 ::std::auto_ptr<SfxItemSet> pSet; 2089 ::std::auto_ptr<SfxItemSet> pSetParent; 2090 2091 for (sal_Int32 i = 0, nEnd = rPropertyNames.getLength(); i < nEnd; i++) 2092 { 2093 SfxItemPropertySimpleEntry const*const pEntry = 2094 pMap->getByName( pNames[i] ); 2095 if(!pEntry) 2096 { 2097 if (pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) || 2098 pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT))) 2099 { 2100 pStates[i] = beans::PropertyState_DEFAULT_VALUE; 2101 continue; 2102 } 2103 else if (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT == 2104 eCaller) 2105 { 2106 //this values marks the element as unknown property 2107 pStates[i] = beans::PropertyState_MAKE_FIXED_SIZE; 2108 continue; 2109 } 2110 else 2111 { 2112 throw beans::UnknownPropertyException( 2113 OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2114 + pNames[i], 2115 static_cast<cppu::OWeakObject *>(0)); 2116 } 2117 } 2118 if (((SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION == eCaller) || 2119 (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT == eCaller)) && 2120 pEntry->nWID < FN_UNO_RANGE_BEGIN && 2121 pEntry->nWID > FN_UNO_RANGE_END && 2122 pEntry->nWID < RES_CHRATR_BEGIN && 2123 pEntry->nWID > RES_TXTATR_END ) 2124 { 2125 pStates[i] = beans::PropertyState_DEFAULT_VALUE; 2126 } 2127 else 2128 { 2129 if ( pEntry->nWID >= FN_UNO_RANGE_BEGIN && 2130 pEntry->nWID <= FN_UNO_RANGE_END ) 2131 { 2132 SwUnoCursorHelper::getCrsrPropertyValue( 2133 *pEntry, rPaM, 0, pStates[i] ); 2134 } 2135 else 2136 { 2137 if (!pSet.get()) 2138 { 2139 switch ( eCaller ) 2140 { 2141 case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT: 2142 case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION: 2143 pSet.reset( 2144 new SfxItemSet( rPaM.GetDoc()->GetAttrPool(), 2145 RES_CHRATR_BEGIN, RES_TXTATR_END )); 2146 break; 2147 case SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY: 2148 pSet.reset( 2149 new SfxItemSet( rPaM.GetDoc()->GetAttrPool(), 2150 pEntry->nWID, pEntry->nWID )); 2151 break; 2152 default: 2153 pSet.reset( new SfxItemSet( 2154 rPaM.GetDoc()->GetAttrPool(), 2155 RES_CHRATR_BEGIN, RES_FRMATR_END - 1, 2156 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, 2157 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, 2158 0L )); 2159 } 2160 // --> OD 2006-07-12 #i63870# 2161 SwUnoCursorHelper::GetCrsrAttr( rPaM, *pSet ); 2162 // <-- 2163 } 2164 2165 pStates[i] = ( pSet->Count() ) 2166 ? rPropSet.getPropertyState( *pEntry, *pSet ) 2167 : beans::PropertyState_DEFAULT_VALUE; 2168 2169 //try again to find out if a value has been inherited 2170 if( beans::PropertyState_DIRECT_VALUE == pStates[i] ) 2171 { 2172 if (!pSetParent.get()) 2173 { 2174 pSetParent.reset( pSet->Clone( sal_False ) ); 2175 // --> OD 2006-07-12 #i63870# 2176 SwUnoCursorHelper::GetCrsrAttr( 2177 rPaM, *pSetParent, sal_True, sal_False ); 2178 // <-- 2179 } 2180 2181 pStates[i] = ( (pSetParent)->Count() ) 2182 ? rPropSet.getPropertyState( *pEntry, *pSetParent ) 2183 : beans::PropertyState_DEFAULT_VALUE; 2184 } 2185 } 2186 } 2187 } 2188 return aRet; 2189 } 2190 /* -----------------------------03.05.00 13:17-------------------------------- 2191 2192 ---------------------------------------------------------------------------*/ 2193 beans::PropertyState SwUnoCursorHelper::GetPropertyState( 2194 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 2195 const OUString& rPropertyName) 2196 throw (beans::UnknownPropertyException, uno::RuntimeException) 2197 { 2198 uno::Sequence< OUString > aStrings ( 1 ); 2199 aStrings[0] = rPropertyName; 2200 uno::Sequence< beans::PropertyState > aSeq = 2201 GetPropertyStates(rPaM, rPropSet, aStrings, 2202 SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY ); 2203 return aSeq[0]; 2204 } 2205 /* -----------------------------03.05.00 13:20-------------------------------- 2206 2207 ---------------------------------------------------------------------------*/ 2208 static void 2209 lcl_SelectParaAndReset( SwPaM &rPaM, SwDoc & rDoc, 2210 SvUShortsSort const*const pWhichIds = 0 ) 2211 { 2212 // if we are reseting paragraph attributes, we need to select the full paragraph first 2213 SwPosition aStart = *rPaM.Start(); 2214 SwPosition aEnd = *rPaM.End(); 2215 ::std::auto_ptr< SwUnoCrsr > pTemp ( rDoc.CreateUnoCrsr(aStart, sal_False) ); 2216 if(!SwUnoCursorHelper::IsStartOfPara(*pTemp)) 2217 { 2218 pTemp->MovePara(fnParaCurr, fnParaStart); 2219 } 2220 pTemp->SetMark(); 2221 *pTemp->GetPoint() = aEnd; 2222 SwUnoCursorHelper::SelectPam(*pTemp, true); 2223 if(!SwUnoCursorHelper::IsEndOfPara(*pTemp)) 2224 { 2225 pTemp->MovePara(fnParaCurr, fnParaEnd); 2226 } 2227 rDoc.ResetAttrs(*pTemp, sal_True, pWhichIds); 2228 } 2229 2230 2231 void SwUnoCursorHelper::SetPropertyToDefault( 2232 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 2233 const OUString& rPropertyName) 2234 throw (beans::UnknownPropertyException, uno::RuntimeException) 2235 { 2236 SwDoc & rDoc = *rPaM.GetDoc(); 2237 SfxItemPropertySimpleEntry const*const pEntry = 2238 rPropSet.getPropertyMap()->getByName(rPropertyName); 2239 if (!pEntry) 2240 { 2241 throw beans::UnknownPropertyException( 2242 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2243 + rPropertyName, static_cast<cppu::OWeakObject *>(0)); 2244 } 2245 2246 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 2247 { 2248 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 2249 "setPropertyToDefault: property is read-only: ")) 2250 + rPropertyName, 0); 2251 } 2252 2253 if (pEntry->nWID < RES_FRMATR_END) 2254 { 2255 SvUShortsSort aWhichIds; 2256 aWhichIds.Insert(pEntry->nWID); 2257 if (pEntry->nWID < RES_PARATR_BEGIN) 2258 { 2259 rDoc.ResetAttrs(rPaM, sal_True, &aWhichIds); 2260 } 2261 else 2262 { 2263 lcl_SelectParaAndReset ( rPaM, rDoc, &aWhichIds ); 2264 } 2265 } 2266 else 2267 { 2268 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rPaM); 2269 } 2270 } 2271 2272 /* -----------------------------03.05.00 13:19-------------------------------- 2273 2274 ---------------------------------------------------------------------------*/ 2275 uno::Any SwUnoCursorHelper::GetPropertyDefault( 2276 SwPaM& rPaM, const SfxItemPropertySet& rPropSet, 2277 const OUString& rPropertyName) 2278 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2279 uno::RuntimeException) 2280 { 2281 SfxItemPropertySimpleEntry const*const pEntry = 2282 rPropSet.getPropertyMap()->getByName(rPropertyName); 2283 if (!pEntry) 2284 { 2285 throw beans::UnknownPropertyException( 2286 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2287 + rPropertyName, static_cast<cppu::OWeakObject *>(0)); 2288 } 2289 2290 uno::Any aRet; 2291 if (pEntry->nWID < RES_FRMATR_END) 2292 { 2293 SwDoc & rDoc = *rPaM.GetDoc(); 2294 const SfxPoolItem& rDefItem = 2295 rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID); 2296 rDefItem.QueryValue(aRet, pEntry->nMemberId); 2297 } 2298 return aRet; 2299 } 2300 2301 /*-- 09.12.98 14:18:54--------------------------------------------------- 2302 2303 -----------------------------------------------------------------------*/ 2304 uno::Reference< beans::XPropertySetInfo > SAL_CALL 2305 SwXTextCursor::getPropertySetInfo() throw (uno::RuntimeException) 2306 { 2307 vos::OGuard g(Application::GetSolarMutex()); 2308 2309 static uno::Reference< beans::XPropertySetInfo > xRef; 2310 if(!xRef.is()) 2311 { 2312 static SfxItemPropertyMapEntry aCrsrExtMap_Impl[] = 2313 { 2314 { SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT), FN_SKIP_HIDDEN_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0}, 2315 { SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT), FN_SKIP_PROTECTED_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0}, 2316 {0,0,0,0,0,0} 2317 }; 2318 const uno::Reference< beans::XPropertySetInfo > xInfo = 2319 m_pImpl->m_rPropSet.getPropertySetInfo(); 2320 // PropertySetInfo verlaengern! 2321 const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties(); 2322 xRef = new SfxExtItemPropertySetInfo( 2323 aCrsrExtMap_Impl, 2324 aPropSeq ); 2325 } 2326 return xRef; 2327 } 2328 2329 /*-- 09.12.98 14:18:54--------------------------------------------------- 2330 2331 -----------------------------------------------------------------------*/ 2332 void SAL_CALL 2333 SwXTextCursor::setPropertyValue( 2334 const OUString& rPropertyName, const uno::Any& rValue) 2335 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 2336 lang::IllegalArgumentException, lang::WrappedTargetException, 2337 uno::RuntimeException) 2338 { 2339 vos::OGuard aGuard(Application::GetSolarMutex()); 2340 2341 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2342 2343 if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT))) 2344 { 2345 sal_Bool bSet(sal_False); 2346 if (!(rValue >>= bSet)) 2347 { 2348 throw lang::IllegalArgumentException(); 2349 } 2350 rUnoCursor.SetSkipOverHiddenSections(bSet); 2351 } 2352 else if (rPropertyName.equalsAsciiL( 2353 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT))) 2354 { 2355 sal_Bool bSet(sal_False); 2356 if (!(rValue >>= bSet)) 2357 { 2358 throw lang::IllegalArgumentException(); 2359 } 2360 rUnoCursor.SetSkipOverProtectSections(bSet); 2361 } 2362 else 2363 { 2364 SwUnoCursorHelper::SetPropertyValue(rUnoCursor, 2365 m_pImpl->m_rPropSet, rPropertyName, rValue); 2366 } 2367 } 2368 2369 /*-- 09.12.98 14:18:55--------------------------------------------------- 2370 2371 -----------------------------------------------------------------------*/ 2372 uno::Any SAL_CALL 2373 SwXTextCursor::getPropertyValue(const OUString& rPropertyName) 2374 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2375 uno::RuntimeException) 2376 { 2377 vos::OGuard aGuard(Application::GetSolarMutex()); 2378 2379 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2380 2381 uno::Any aAny; 2382 if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT))) 2383 { 2384 const sal_Bool bSet = rUnoCursor.IsSkipOverHiddenSections(); 2385 aAny <<= bSet; 2386 } 2387 else if (rPropertyName.equalsAsciiL( 2388 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT))) 2389 { 2390 const sal_Bool bSet = rUnoCursor.IsSkipOverProtectSections(); 2391 aAny <<= bSet; 2392 } 2393 else 2394 { 2395 aAny = SwUnoCursorHelper::GetPropertyValue(rUnoCursor, 2396 m_pImpl->m_rPropSet, rPropertyName); 2397 } 2398 return aAny; 2399 } 2400 2401 /*-- 09.12.98 14:18:55--------------------------------------------------- 2402 2403 -----------------------------------------------------------------------*/ 2404 void SAL_CALL 2405 SwXTextCursor::addPropertyChangeListener( 2406 const ::rtl::OUString& /*rPropertyName*/, 2407 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 2408 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2409 uno::RuntimeException) 2410 { 2411 OSL_ENSURE(false, 2412 "SwXTextCursor::addPropertyChangeListener(): not implemented"); 2413 } 2414 2415 /*-- 09.12.98 14:18:57--------------------------------------------------- 2416 2417 -----------------------------------------------------------------------*/ 2418 void SAL_CALL 2419 SwXTextCursor::removePropertyChangeListener( 2420 const ::rtl::OUString& /*rPropertyName*/, 2421 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 2422 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2423 uno::RuntimeException) 2424 { 2425 OSL_ENSURE(false, 2426 "SwXTextCursor::removePropertyChangeListener(): not implemented"); 2427 } 2428 2429 /*-- 09.12.98 14:18:57--------------------------------------------------- 2430 2431 -----------------------------------------------------------------------*/ 2432 void SAL_CALL 2433 SwXTextCursor::addVetoableChangeListener( 2434 const ::rtl::OUString& /*rPropertyName*/, 2435 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 2436 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2437 uno::RuntimeException) 2438 { 2439 OSL_ENSURE(false, 2440 "SwXTextCursor::addVetoableChangeListener(): not implemented"); 2441 } 2442 2443 /*-- 09.12.98 14:18:58--------------------------------------------------- 2444 2445 -----------------------------------------------------------------------*/ 2446 void SAL_CALL 2447 SwXTextCursor::removeVetoableChangeListener( 2448 const ::rtl::OUString& /*rPropertyName*/, 2449 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 2450 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2451 uno::RuntimeException) 2452 { 2453 OSL_ENSURE(false, 2454 "SwXTextCursor::removeVetoableChangeListener(): not implemented"); 2455 } 2456 2457 /*-- 05.03.99 11:36:11--------------------------------------------------- 2458 2459 -----------------------------------------------------------------------*/ 2460 beans::PropertyState SAL_CALL 2461 SwXTextCursor::getPropertyState(const OUString& rPropertyName) 2462 throw (beans::UnknownPropertyException, uno::RuntimeException) 2463 { 2464 vos::OGuard aGuard(Application::GetSolarMutex()); 2465 2466 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2467 2468 const beans::PropertyState eRet = SwUnoCursorHelper::GetPropertyState( 2469 rUnoCursor, m_pImpl->m_rPropSet, rPropertyName); 2470 return eRet; 2471 } 2472 /*-- 05.03.99 11:36:11--------------------------------------------------- 2473 2474 -----------------------------------------------------------------------*/ 2475 uno::Sequence< beans::PropertyState > SAL_CALL 2476 SwXTextCursor::getPropertyStates( 2477 const uno::Sequence< OUString >& rPropertyNames) 2478 throw (beans::UnknownPropertyException, uno::RuntimeException) 2479 { 2480 vos::OGuard aGuard(Application::GetSolarMutex()); 2481 2482 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2483 2484 return SwUnoCursorHelper::GetPropertyStates( 2485 rUnoCursor, m_pImpl->m_rPropSet, rPropertyNames); 2486 } 2487 2488 /*-- 05.03.99 11:36:12--------------------------------------------------- 2489 2490 -----------------------------------------------------------------------*/ 2491 void SAL_CALL 2492 SwXTextCursor::setPropertyToDefault(const OUString& rPropertyName) 2493 throw (beans::UnknownPropertyException, uno::RuntimeException) 2494 { 2495 // forward: need no solar mutex here 2496 uno::Sequence < OUString > aSequence ( &rPropertyName, 1 ); 2497 setPropertiesToDefault ( aSequence ); 2498 } 2499 /*-- 05.03.99 11:36:12--------------------------------------------------- 2500 2501 -----------------------------------------------------------------------*/ 2502 uno::Any SAL_CALL 2503 SwXTextCursor::getPropertyDefault(const OUString& rPropertyName) 2504 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2505 uno::RuntimeException) 2506 { 2507 // forward: need no solar mutex here 2508 const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 ); 2509 return getPropertyDefaults ( aSequence ).getConstArray()[0]; 2510 } 2511 2512 // para specific attribut ranges 2513 static sal_uInt16 g_ParaResetableSetRange[] = { 2514 RES_FRMATR_BEGIN, RES_FRMATR_END-1, 2515 RES_PARATR_BEGIN, RES_PARATR_END-1, 2516 // --> OD 2008-02-25 #refactorlists# 2517 RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1, 2518 // <-- 2519 RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, 2520 0 2521 }; 2522 2523 // selection specific attribut ranges 2524 static sal_uInt16 g_ResetableSetRange[] = { 2525 RES_CHRATR_BEGIN, RES_CHRATR_END-1, 2526 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, 2527 RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT, 2528 RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY, 2529 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER, 2530 0 2531 }; 2532 2533 static void 2534 lcl_EnumerateIds(sal_uInt16 const* pIdRange, SvUShortsSort & rWhichIds) 2535 { 2536 while (*pIdRange) 2537 { 2538 const sal_uInt16 nStart = sal::static_int_cast<sal_uInt16>(*pIdRange++); 2539 const sal_uInt16 nEnd = sal::static_int_cast<sal_uInt16>(*pIdRange++); 2540 for (sal_uInt16 nId = nStart + 1; nId <= nEnd; ++nId) 2541 { 2542 rWhichIds.Insert( nId ); 2543 } 2544 } 2545 } 2546 2547 void SAL_CALL 2548 SwXTextCursor::setAllPropertiesToDefault() 2549 throw (uno::RuntimeException) 2550 { 2551 vos::OGuard aGuard(Application::GetSolarMutex()); 2552 2553 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2554 2555 SvUShortsSort aParaWhichIds; 2556 SvUShortsSort aWhichIds; 2557 lcl_EnumerateIds(g_ParaResetableSetRange, aParaWhichIds); 2558 lcl_EnumerateIds(g_ResetableSetRange, aWhichIds); 2559 if (aParaWhichIds.Count()) 2560 { 2561 lcl_SelectParaAndReset(rUnoCursor, *rUnoCursor.GetDoc(), 2562 &aParaWhichIds); 2563 } 2564 if (aWhichIds.Count()) 2565 { 2566 rUnoCursor.GetDoc()->ResetAttrs(rUnoCursor, sal_True, &aWhichIds); 2567 } 2568 } 2569 2570 void SAL_CALL 2571 SwXTextCursor::setPropertiesToDefault( 2572 const uno::Sequence< OUString >& rPropertyNames) 2573 throw (beans::UnknownPropertyException, uno::RuntimeException) 2574 { 2575 vos::OGuard aGuard(Application::GetSolarMutex()); 2576 2577 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2578 2579 const sal_Int32 nCount = rPropertyNames.getLength(); 2580 if ( nCount ) 2581 { 2582 SwDoc & rDoc = *rUnoCursor.GetDoc(); 2583 const OUString * pNames = rPropertyNames.getConstArray(); 2584 SvUShortsSort aWhichIds; 2585 SvUShortsSort aParaWhichIds; 2586 for (sal_Int32 i = 0; i < nCount; i++) 2587 { 2588 SfxItemPropertySimpleEntry const*const pEntry = 2589 m_pImpl->m_rPropSet.getPropertyMap()->getByName( pNames[i] ); 2590 if (!pEntry) 2591 { 2592 if (pNames[i].equalsAsciiL( 2593 SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) || 2594 pNames[i].equalsAsciiL( 2595 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT))) 2596 { 2597 continue; 2598 } 2599 throw beans::UnknownPropertyException( 2600 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2601 + pNames[i], 2602 static_cast<cppu::OWeakObject *>(this)); 2603 } 2604 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 2605 { 2606 throw uno::RuntimeException( 2607 OUString(RTL_CONSTASCII_USTRINGPARAM( 2608 "setPropertiesToDefault: property is read-only: ")) 2609 + pNames[i], 2610 static_cast<cppu::OWeakObject *>(this)); 2611 } 2612 2613 if (pEntry->nWID < RES_FRMATR_END) 2614 { 2615 if (pEntry->nWID < RES_PARATR_BEGIN) 2616 { 2617 aWhichIds.Insert(pEntry->nWID); 2618 } 2619 else 2620 { 2621 aParaWhichIds.Insert(pEntry->nWID); 2622 } 2623 } 2624 else if (pEntry->nWID == FN_UNO_NUM_START_VALUE) 2625 { 2626 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rUnoCursor); 2627 } 2628 } 2629 2630 if (aParaWhichIds.Count()) 2631 { 2632 lcl_SelectParaAndReset(rUnoCursor, rDoc, &aParaWhichIds); 2633 } 2634 if (aWhichIds.Count()) 2635 { 2636 rDoc.ResetAttrs(rUnoCursor, sal_True, &aWhichIds); 2637 } 2638 } 2639 } 2640 2641 uno::Sequence< uno::Any > SAL_CALL 2642 SwXTextCursor::getPropertyDefaults( 2643 const uno::Sequence< OUString >& rPropertyNames) 2644 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2645 uno::RuntimeException) 2646 { 2647 vos::OGuard aGuard(Application::GetSolarMutex()); 2648 2649 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2650 2651 const sal_Int32 nCount = rPropertyNames.getLength(); 2652 uno::Sequence< uno::Any > aRet(nCount); 2653 if ( nCount ) 2654 { 2655 SwDoc & rDoc = *rUnoCursor.GetDoc(); 2656 const OUString *pNames = rPropertyNames.getConstArray(); 2657 uno::Any *pAny = aRet.getArray(); 2658 for (sal_Int32 i = 0; i < nCount; i++) 2659 { 2660 SfxItemPropertySimpleEntry const*const pEntry = 2661 m_pImpl->m_rPropSet.getPropertyMap()->getByName( pNames[i] ); 2662 if (!pEntry) 2663 { 2664 if (pNames[i].equalsAsciiL( 2665 SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) || 2666 pNames[i].equalsAsciiL( 2667 SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT))) 2668 { 2669 continue; 2670 } 2671 throw beans::UnknownPropertyException( 2672 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2673 + pNames[i], 2674 static_cast<cppu::OWeakObject *>(0)); 2675 } 2676 if (pEntry->nWID < RES_FRMATR_END) 2677 { 2678 const SfxPoolItem& rDefItem = 2679 rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID); 2680 rDefItem.QueryValue(pAny[i], pEntry->nMemberId); 2681 } 2682 } 2683 } 2684 return aRet; 2685 } 2686 2687 void SAL_CALL SwXTextCursor::invalidateMarkings(::sal_Int32 nType) 2688 throw (uno::RuntimeException) 2689 { 2690 vos::OGuard aGuard(Application::GetSolarMutex()); 2691 2692 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2693 2694 SwNode* node = rUnoCursor.GetNode(); 2695 2696 if (node == 0) return; 2697 2698 SwTxtNode* txtNode = node->GetTxtNode(); 2699 2700 if (txtNode == 0) return; 2701 2702 if ( text::TextMarkupType::SPELLCHECK == nType ) 2703 { 2704 txtNode->SetWrongDirty(true); 2705 txtNode->SetWrong(0, true); 2706 } 2707 else if( text::TextMarkupType::PROOFREADING == nType ) 2708 { 2709 txtNode->SetGrammarCheckDirty(true); 2710 txtNode->SetGrammarCheck(0,true); 2711 } 2712 else if ( text::TextMarkupType::SMARTTAG == nType ) 2713 { 2714 txtNode->SetSmartTagDirty(true); 2715 txtNode->SetSmartTags (0, true); 2716 } 2717 else return; 2718 2719 SwFmtColl* fmtColl=txtNode->GetFmtColl(); 2720 2721 if (fmtColl == 0) return; 2722 2723 SwFmtChg aNew( fmtColl ); 2724 txtNode->NotifyClients( 0, &aNew ); 2725 } 2726 2727 2728 /*-- 10.03.2008 09:58:47--------------------------------------------------- 2729 2730 -----------------------------------------------------------------------*/ 2731 void SAL_CALL 2732 SwXTextCursor::makeRedline( 2733 const ::rtl::OUString& rRedlineType, 2734 const uno::Sequence< beans::PropertyValue >& rRedlineProperties) 2735 throw (lang::IllegalArgumentException, uno::RuntimeException) 2736 { 2737 vos::OGuard aGuard(Application::GetSolarMutex()); 2738 2739 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2740 2741 SwUnoCursorHelper::makeRedline(rUnoCursor, rRedlineType, rRedlineProperties); 2742 } 2743 2744 /*-- 09.12.98 14:18:58--------------------------------------------------- 2745 2746 -----------------------------------------------------------------------*/ 2747 void SAL_CALL SwXTextCursor::insertDocumentFromURL(const OUString& rURL, 2748 const uno::Sequence< beans::PropertyValue >& rOptions) 2749 throw (lang::IllegalArgumentException, io::IOException, 2750 uno::RuntimeException) 2751 { 2752 vos::OGuard aGuard(Application::GetSolarMutex()); 2753 2754 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 2755 2756 SwUnoCursorHelper::InsertFile(&rUnoCursor, rURL, rOptions); 2757 } 2758 2759 /* -----------------------------15.12.00 14:01-------------------------------- 2760 2761 ---------------------------------------------------------------------------*/ 2762 uno::Sequence< beans::PropertyValue > 2763 SwUnoCursorHelper::CreateSortDescriptor(const bool bFromTable) 2764 { 2765 uno::Sequence< beans::PropertyValue > aRet(5); 2766 beans::PropertyValue* pArray = aRet.getArray(); 2767 2768 uno::Any aVal; 2769 aVal.setValue( &bFromTable, ::getCppuBooleanType()); 2770 pArray[0] = beans::PropertyValue(C2U("IsSortInTable"), -1, aVal, 2771 beans::PropertyState_DIRECT_VALUE); 2772 2773 aVal <<= sal_Unicode(' '); 2774 pArray[1] = beans::PropertyValue(C2U("Delimiter"), -1, aVal, 2775 beans::PropertyState_DIRECT_VALUE); 2776 2777 aVal <<= (sal_Bool) sal_False; 2778 pArray[2] = beans::PropertyValue(C2U("IsSortColumns"), -1, aVal, 2779 beans::PropertyState_DIRECT_VALUE); 2780 2781 aVal <<= (sal_Int32) 3; 2782 pArray[3] = beans::PropertyValue(C2U("MaxSortFieldsCount"), -1, aVal, 2783 beans::PropertyState_DIRECT_VALUE); 2784 2785 uno::Sequence< table::TableSortField > aFields(3); 2786 table::TableSortField* pFields = aFields.getArray(); 2787 2788 lang::Locale aLang( SvxCreateLocale( LANGUAGE_SYSTEM ) ); 2789 // get collator algorithm to be used for the locale 2790 uno::Sequence< OUString > aSeq( 2791 GetAppCollator().listCollatorAlgorithms( aLang ) ); 2792 const sal_Int32 nLen = aSeq.getLength(); 2793 DBG_ASSERT( nLen > 0, "list of collator algorithms is empty!"); 2794 OUString aCollAlg; 2795 if (nLen > 0) 2796 { 2797 aCollAlg = aSeq.getConstArray()[0]; 2798 } 2799 2800 #if OSL_DEBUG_LEVEL > 1 2801 const OUString *pTxt = aSeq.getConstArray(); 2802 (void)pTxt; 2803 #endif 2804 2805 pFields[0].Field = 1; 2806 pFields[0].IsAscending = sal_True; 2807 pFields[0].IsCaseSensitive = sal_False; 2808 pFields[0].FieldType = table::TableSortFieldType_ALPHANUMERIC; 2809 pFields[0].CollatorLocale = aLang; 2810 pFields[0].CollatorAlgorithm = aCollAlg; 2811 2812 pFields[1].Field = 1; 2813 pFields[1].IsAscending = sal_True; 2814 pFields[1].IsCaseSensitive = sal_False; 2815 pFields[1].FieldType = table::TableSortFieldType_ALPHANUMERIC; 2816 pFields[1].CollatorLocale = aLang; 2817 pFields[1].CollatorAlgorithm = aCollAlg; 2818 2819 pFields[2].Field = 1; 2820 pFields[2].IsAscending = sal_True; 2821 pFields[2].IsCaseSensitive = sal_False; 2822 pFields[2].FieldType = table::TableSortFieldType_ALPHANUMERIC; 2823 pFields[2].CollatorLocale = aLang; 2824 pFields[2].CollatorAlgorithm = aCollAlg; 2825 2826 aVal <<= aFields; 2827 pArray[4] = beans::PropertyValue(C2U("SortFields"), -1, aVal, 2828 beans::PropertyState_DIRECT_VALUE); 2829 2830 return aRet; 2831 } 2832 2833 /*-- 09.12.98 14:18:58--------------------------------------------------- 2834 2835 -----------------------------------------------------------------------*/ 2836 uno::Sequence< beans::PropertyValue > SAL_CALL 2837 SwXTextCursor::createSortDescriptor() throw (uno::RuntimeException) 2838 { 2839 vos::OGuard aGuard(Application::GetSolarMutex()); 2840 2841 return SwUnoCursorHelper::CreateSortDescriptor(false); 2842 } 2843 2844 /* -----------------------------15.12.00 14:06-------------------------------- 2845 2846 ---------------------------------------------------------------------------*/ 2847 sal_Bool SwUnoCursorHelper::ConvertSortProperties( 2848 const uno::Sequence< beans::PropertyValue >& rDescriptor, 2849 SwSortOptions& rSortOpt) 2850 { 2851 sal_Bool bRet = sal_True; 2852 const beans::PropertyValue* pProperties = rDescriptor.getConstArray(); 2853 2854 rSortOpt.bTable = sal_False; 2855 rSortOpt.cDeli = ' '; 2856 rSortOpt.eDirection = SRT_COLUMNS; //!! UI text may be contrary though !! 2857 2858 SwSortKey* pKey1 = new SwSortKey; 2859 pKey1->nColumnId = USHRT_MAX; 2860 pKey1->bIsNumeric = sal_True; 2861 pKey1->eSortOrder = SRT_ASCENDING; 2862 2863 SwSortKey* pKey2 = new SwSortKey; 2864 pKey2->nColumnId = USHRT_MAX; 2865 pKey2->bIsNumeric = sal_True; 2866 pKey2->eSortOrder = SRT_ASCENDING; 2867 2868 SwSortKey* pKey3 = new SwSortKey; 2869 pKey3->nColumnId = USHRT_MAX; 2870 pKey3->bIsNumeric = sal_True; 2871 pKey3->eSortOrder = SRT_ASCENDING; 2872 SwSortKey* aKeys[3] = {pKey1, pKey2, pKey3}; 2873 2874 sal_Bool bOldSortdescriptor(sal_False); 2875 sal_Bool bNewSortdescriptor(sal_False); 2876 2877 for (sal_Int32 n = 0; n < rDescriptor.getLength(); ++n) 2878 { 2879 uno::Any aValue( pProperties[n].Value ); 2880 // String sPropName = pProperties[n].Name; 2881 const OUString& rPropName = pProperties[n].Name; 2882 2883 // old and new sortdescriptor 2884 if (rPropName.equalsAscii("IsSortInTable")) 2885 { 2886 if (aValue.getValueType() == ::getBooleanCppuType()) 2887 { 2888 rSortOpt.bTable = *(sal_Bool*)aValue.getValue(); 2889 } 2890 else 2891 { 2892 bRet = sal_False; 2893 } 2894 } 2895 else if (rPropName.equalsAscii("Delimiter")) 2896 { 2897 sal_Unicode uChar = sal_Unicode(); 2898 if (aValue >>= uChar) 2899 { 2900 rSortOpt.cDeli = uChar; 2901 } 2902 else 2903 { 2904 bRet = sal_False; 2905 } 2906 } 2907 // old sortdescriptor 2908 else if (rPropName.equalsAscii("SortColumns")) 2909 { 2910 bOldSortdescriptor = sal_True; 2911 sal_Bool bTemp(sal_False); 2912 if (aValue >>= bTemp) 2913 { 2914 rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS; 2915 } 2916 else 2917 { 2918 bRet = sal_False; 2919 } 2920 } 2921 else if ( rPropName.equalsAscii("IsCaseSensitive")) 2922 { 2923 bOldSortdescriptor = sal_True; 2924 sal_Bool bTemp(sal_False); 2925 if (aValue >>= bTemp) 2926 { 2927 rSortOpt.bIgnoreCase = !bTemp; 2928 } 2929 else 2930 { 2931 bRet = sal_False; 2932 } 2933 } 2934 else if (rPropName.equalsAscii("CollatorLocale")) 2935 { 2936 bOldSortdescriptor = sal_True; 2937 lang::Locale aLocale; 2938 if (aValue >>= aLocale) 2939 { 2940 rSortOpt.nLanguage = SvxLocaleToLanguage( aLocale ); 2941 } 2942 else 2943 { 2944 bRet = sal_False; 2945 } 2946 } 2947 else if (rPropName.matchAsciiL("CollatorAlgorithm", 17) && 2948 rPropName.getLength() == 18 && 2949 (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9')) 2950 { 2951 bOldSortdescriptor = sal_True; 2952 sal_uInt16 nIndex = rPropName.getStr()[17]; 2953 nIndex -= '0'; 2954 OUString aTxt; 2955 if ((aValue >>= aTxt) && nIndex < 3) 2956 { 2957 aKeys[nIndex]->sSortType = aTxt; 2958 } 2959 else 2960 { 2961 bRet = sal_False; 2962 } 2963 } 2964 else if (rPropName.matchAsciiL("SortRowOrColumnNo", 17) && 2965 rPropName.getLength() == 18 && 2966 (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9')) 2967 { 2968 bOldSortdescriptor = sal_True; 2969 sal_uInt16 nIndex = rPropName.getStr()[17]; 2970 nIndex -= '0'; 2971 sal_Int16 nCol = -1; 2972 if (aValue.getValueType() == ::getCppuType((const sal_Int16*)0) 2973 && nIndex < 3) 2974 { 2975 aValue >>= nCol; 2976 } 2977 if (nCol >= 0) 2978 { 2979 aKeys[nIndex]->nColumnId = nCol; 2980 } 2981 else 2982 { 2983 bRet = sal_False; 2984 } 2985 } 2986 else if (0 == rPropName.indexOf(C2U("IsSortNumeric")) && 2987 rPropName.getLength() == 14 && 2988 (rPropName.getStr()[13] >= '0' && rPropName.getStr()[13] <= '9')) 2989 { 2990 bOldSortdescriptor = sal_True; 2991 sal_uInt16 nIndex = rPropName.getStr()[13]; 2992 nIndex = nIndex - '0'; 2993 if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3) 2994 { 2995 sal_Bool bTemp = *(sal_Bool*)aValue.getValue(); 2996 aKeys[nIndex]->bIsNumeric = bTemp; 2997 } 2998 else 2999 { 3000 bRet = sal_False; 3001 } 3002 } 3003 else if (0 == rPropName.indexOf(C2U("IsSortAscending")) && 3004 rPropName.getLength() == 16 && 3005 (rPropName.getStr()[15] >= '0' && rPropName.getStr()[15] <= '9')) 3006 { 3007 bOldSortdescriptor = sal_True; 3008 sal_uInt16 nIndex = rPropName.getStr()[15]; 3009 nIndex -= '0'; 3010 if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3) 3011 { 3012 sal_Bool bTemp = *(sal_Bool*)aValue.getValue(); 3013 aKeys[nIndex]->eSortOrder = (bTemp) 3014 ? SRT_ASCENDING : SRT_DESCENDING; 3015 } 3016 else 3017 { 3018 bRet = sal_False; 3019 } 3020 } 3021 // new sortdescriptor 3022 else if (rPropName.equalsAscii("IsSortColumns")) 3023 { 3024 bNewSortdescriptor = sal_True; 3025 if (aValue.getValueType() == ::getBooleanCppuType()) 3026 { 3027 sal_Bool bTemp = *(sal_Bool*)aValue.getValue(); 3028 rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS; 3029 } 3030 else 3031 { 3032 bRet = sal_False; 3033 } 3034 } 3035 else if (rPropName.equalsAscii("SortFields")) 3036 { 3037 bNewSortdescriptor = sal_True; 3038 uno::Sequence < table::TableSortField > aFields; 3039 if (aValue >>= aFields) 3040 { 3041 sal_Int32 nCount(aFields.getLength()); 3042 if (nCount <= 3) 3043 { 3044 table::TableSortField* pFields = aFields.getArray(); 3045 for (sal_Int32 i = 0; i < nCount; ++i) 3046 { 3047 rSortOpt.bIgnoreCase = !pFields[i].IsCaseSensitive; 3048 rSortOpt.nLanguage = 3049 SvxLocaleToLanguage( pFields[i].CollatorLocale ); 3050 aKeys[i]->sSortType = pFields[i].CollatorAlgorithm; 3051 aKeys[i]->nColumnId = 3052 static_cast<sal_uInt16>(pFields[i].Field); 3053 aKeys[i]->bIsNumeric = (pFields[i].FieldType == 3054 table::TableSortFieldType_NUMERIC); 3055 aKeys[i]->eSortOrder = (pFields[i].IsAscending) 3056 ? SRT_ASCENDING : SRT_DESCENDING; 3057 } 3058 } 3059 else 3060 { 3061 bRet = sal_False; 3062 } 3063 } 3064 else 3065 { 3066 bRet = sal_False; 3067 } 3068 } 3069 } 3070 3071 if (bNewSortdescriptor && bOldSortdescriptor) 3072 { 3073 DBG_ERROR("someone tried to set the old deprecated and " 3074 "the new sortdescriptor"); 3075 bRet = sal_False; 3076 } 3077 3078 if (pKey1->nColumnId != USHRT_MAX) 3079 { 3080 rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey1, rSortOpt.aKeys.Count()); 3081 } 3082 if (pKey2->nColumnId != USHRT_MAX) 3083 { 3084 rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey2, rSortOpt.aKeys.Count()); 3085 } 3086 if (pKey3->nColumnId != USHRT_MAX) 3087 { 3088 rSortOpt.aKeys.C40_INSERT(SwSortKey, pKey3, rSortOpt.aKeys.Count()); 3089 } 3090 3091 return bRet && rSortOpt.aKeys.Count() > 0; 3092 } 3093 3094 /*-- 09.12.98 14:19:00--------------------------------------------------- 3095 3096 -----------------------------------------------------------------------*/ 3097 void SAL_CALL 3098 SwXTextCursor::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor) 3099 throw (uno::RuntimeException) 3100 { 3101 vos::OGuard aGuard(Application::GetSolarMutex()); 3102 3103 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 3104 3105 if (rUnoCursor.HasMark()) 3106 { 3107 SwSortOptions aSortOpt; 3108 if (!SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt)) 3109 { 3110 throw uno::RuntimeException(); 3111 } 3112 UnoActionContext aContext( rUnoCursor.GetDoc() ); 3113 3114 SwPosition & rStart = *rUnoCursor.Start(); 3115 SwPosition & rEnd = *rUnoCursor.End(); 3116 3117 SwNodeIndex aPrevIdx( rStart.nNode, -1 ); 3118 const sal_uLong nOffset = rEnd.nNode.GetIndex() - rStart.nNode.GetIndex(); 3119 const xub_StrLen nCntStt = rStart.nContent.GetIndex(); 3120 3121 rUnoCursor.GetDoc()->SortText(rUnoCursor, aSortOpt); 3122 3123 // Selektion wieder setzen 3124 rUnoCursor.DeleteMark(); 3125 rUnoCursor.GetPoint()->nNode.Assign( aPrevIdx.GetNode(), +1 ); 3126 SwCntntNode *const pCNd = rUnoCursor.GetCntntNode(); 3127 xub_StrLen nLen = pCNd->Len(); 3128 if (nLen > nCntStt) 3129 { 3130 nLen = nCntStt; 3131 } 3132 rUnoCursor.GetPoint()->nContent.Assign(pCNd, nLen ); 3133 rUnoCursor.SetMark(); 3134 3135 rUnoCursor.GetPoint()->nNode += nOffset; 3136 SwCntntNode *const pCNd2 = rUnoCursor.GetCntntNode(); 3137 rUnoCursor.GetPoint()->nContent.Assign( pCNd2, pCNd2->Len() ); 3138 } 3139 } 3140 3141 /* -----------------------------03.04.00 09:11-------------------------------- 3142 3143 ---------------------------------------------------------------------------*/ 3144 uno::Reference< container::XEnumeration > SAL_CALL 3145 SwXTextCursor::createContentEnumeration(const OUString& rServiceName) 3146 throw (uno::RuntimeException) 3147 { 3148 vos::OGuard g(Application::GetSolarMutex()); 3149 3150 if (!rServiceName.equalsAscii("com.sun.star.text.TextContent")) 3151 { 3152 throw uno::RuntimeException(); 3153 } 3154 3155 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 3156 3157 uno::Reference< container::XEnumeration > xRet = 3158 new SwXParaFrameEnumeration(rUnoCursor, PARAFRAME_PORTION_TEXTRANGE); 3159 return xRet; 3160 } 3161 3162 /* -----------------------------07.03.01 14:53-------------------------------- 3163 3164 ---------------------------------------------------------------------------*/ 3165 uno::Reference< container::XEnumeration > SAL_CALL 3166 SwXTextCursor::createEnumeration() throw (uno::RuntimeException) 3167 { 3168 vos::OGuard g(Application::GetSolarMutex()); 3169 3170 SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() ); 3171 3172 const uno::Reference<lang::XUnoTunnel> xTunnel( 3173 m_pImpl->m_xParentText, uno::UNO_QUERY); 3174 SwXText* pParentText = 0; 3175 if (xTunnel.is()) 3176 { 3177 pParentText = ::sw::UnoTunnelGetImplementation<SwXText>(xTunnel); 3178 } 3179 DBG_ASSERT(pParentText, "parent is not a SwXText"); 3180 if (!pParentText) 3181 { 3182 throw uno::RuntimeException(); 3183 } 3184 3185 ::std::auto_ptr<SwUnoCrsr> pNewCrsr( 3186 rUnoCursor.GetDoc()->CreateUnoCrsr(*rUnoCursor.GetPoint()) ); 3187 if (rUnoCursor.HasMark()) 3188 { 3189 pNewCrsr->SetMark(); 3190 *pNewCrsr->GetMark() = *rUnoCursor.GetMark(); 3191 } 3192 const CursorType eSetType = (CURSOR_TBLTEXT == m_pImpl->m_eType) 3193 ? CURSOR_SELECTION_IN_TABLE : CURSOR_SELECTION; 3194 SwTableNode const*const pStartNode( (CURSOR_TBLTEXT == m_pImpl->m_eType) 3195 ? rUnoCursor.GetPoint()->nNode.GetNode().FindTableNode() 3196 : 0); 3197 SwTable const*const pTable( 3198 (pStartNode) ? & pStartNode->GetTable() : 0 ); 3199 const uno::Reference< container::XEnumeration > xRet = 3200 new SwXParagraphEnumeration( 3201 pParentText, pNewCrsr, eSetType, pStartNode, pTable); 3202 3203 return xRet; 3204 } 3205 3206 /* -----------------------------07.03.01 15:43-------------------------------- 3207 3208 ---------------------------------------------------------------------------*/ 3209 uno::Type SAL_CALL 3210 SwXTextCursor::getElementType() throw (uno::RuntimeException) 3211 { 3212 return text::XTextRange::static_type(); 3213 } 3214 3215 /* -----------------------------07.03.01 15:43-------------------------------- 3216 3217 ---------------------------------------------------------------------------*/ 3218 sal_Bool SAL_CALL SwXTextCursor::hasElements() throw (uno::RuntimeException) 3219 { 3220 return sal_True; 3221 } 3222 3223 /* -----------------------------03.04.00 09:11-------------------------------- 3224 3225 ---------------------------------------------------------------------------*/ 3226 uno::Sequence< OUString > SAL_CALL 3227 SwXTextCursor::getAvailableServiceNames() throw (uno::RuntimeException) 3228 { 3229 uno::Sequence< OUString > aRet(1); 3230 OUString* pArray = aRet.getArray(); 3231 pArray[0] = OUString::createFromAscii("com.sun.star.text.TextContent"); 3232 return aRet; 3233 } 3234 3235 // --------------------------------------------------------------------------- 3236 IMPLEMENT_FORWARD_REFCOUNT( SwXTextCursor,SwXTextCursor_Base ) 3237 3238 uno::Any SAL_CALL 3239 SwXTextCursor::queryInterface(const uno::Type& rType) 3240 throw (uno::RuntimeException) 3241 { 3242 return (rType == lang::XUnoTunnel::static_type()) 3243 ? OTextCursorHelper::queryInterface(rType) 3244 : SwXTextCursor_Base::queryInterface(rType); 3245 } 3246 3247