1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <com/sun/star/beans/PropertyAttribute.hpp> 32 #include <com/sun/star/container/XIndexReplace.hpp> 33 #include <com/sun/star/frame/XModel.hpp> 34 #include <com/sun/star/text/ChapterFormat.hpp> 35 #include <com/sun/star/text/ReferenceFieldPart.hpp> 36 #include <com/sun/star/text/BibliographyDataField.hpp> 37 #include <com/sun/star/text/XTextDocument.hpp> 38 39 #include <tools/debug.hxx> 40 #include <vos/mutex.hxx> 41 #include <vcl/svapp.hxx> 42 #include <editeng/unolingu.hxx> 43 #include <com/sun/star/text/ChapterFormat.hpp> 44 #include <com/sun/star/text/ReferenceFieldPart.hpp> 45 #include <com/sun/star/text/BibliographyDataField.hpp> 46 #include <com/sun/star/frame/XModel.hpp> 47 #include <com/sun/star/text/XTextDocument.hpp> 48 #include <com/sun/star/beans/PropertyAttribute.hpp> 49 #include <hints.hxx> 50 #include <cmdid.h> 51 #include <swtypes.hxx> 52 #include <shellres.hxx> 53 #include <viewsh.hxx> 54 #include <doc.hxx> 55 #include <docary.hxx> 56 #include <poolfmt.hxx> 57 #include <poolfmt.hrc> 58 #include <pagedesc.hxx> 59 #include <fmtcntnt.hxx> 60 #include <unomap.hxx> 61 #include <unotextrange.hxx> 62 #include <unotextcursor.hxx> 63 #include <unosection.hxx> 64 #include <doctxm.hxx> 65 #include <txttxmrk.hxx> 66 #include <unocrsr.hxx> 67 #include <unostyle.hxx> 68 #include <ndtxt.hxx> 69 #include <unoidx.hxx> 70 #include <docsh.hxx> 71 #include <chpfld.hxx> 72 #include <SwStyleNameMapper.hxx> 73 #include <unoevtlstnr.hxx> 74 75 76 using namespace ::com::sun::star; 77 using ::rtl::OUString; 78 79 //----------------------------------------------------------------------------- 80 static OUString 81 lcl_AnyToString(uno::Any const& rVal) throw (lang::IllegalArgumentException) 82 { 83 OUString sRet; 84 if(!(rVal >>= sRet)) 85 { 86 throw lang::IllegalArgumentException(); 87 } 88 return sRet; 89 } 90 //----------------------------------------------------------------------------- 91 static sal_Int16 92 lcl_AnyToInt16(uno::Any const& rVal) throw (lang::IllegalArgumentException) 93 { 94 sal_Int16 nRet = 0; 95 if(!(rVal >>= nRet)) 96 { 97 throw lang::IllegalArgumentException(); 98 } 99 return nRet; 100 } 101 //----------------------------------------------------------------------------- 102 static sal_Bool 103 lcl_AnyToBool(uno::Any const& rVal) throw (lang::IllegalArgumentException) 104 { 105 sal_Bool bRet = sal_False; 106 if(!(rVal >>= bRet)) 107 { 108 throw lang::IllegalArgumentException(); 109 } 110 return bRet; 111 } 112 113 static void 114 lcl_AnyToBitMask(uno::Any const& rValue, 115 sal_uInt16 & rBitMask, const sal_uInt16 nBit) 116 throw (lang::IllegalArgumentException) 117 { 118 rBitMask = lcl_AnyToBool(rValue) 119 ? (rBitMask | nBit) 120 : (rBitMask & ~nBit); 121 } 122 static void 123 lcl_BitMaskToAny(uno::Any & o_rValue, 124 const sal_uInt16 nBitMask, const sal_uInt16 nBit) 125 { 126 const sal_Bool bRet = 0 != (nBitMask & nBit); 127 o_rValue <<= bRet; 128 } 129 130 //----------------------------------------------------------------------------- 131 static void 132 lcl_ReAssignTOXType(SwDoc* pDoc, SwTOXBase& rTOXBase, const OUString& rNewName) 133 { 134 const sal_uInt16 nUserCount = pDoc->GetTOXTypeCount( TOX_USER ); 135 const SwTOXType* pNewType = 0; 136 for(sal_uInt16 nUser = 0; nUser < nUserCount; nUser++) 137 { 138 const SwTOXType* pType = pDoc->GetTOXType( TOX_USER, nUser ); 139 if(pType->GetTypeName().Equals((String)rNewName)) 140 { 141 pNewType = pType; 142 break; 143 } 144 } 145 if(!pNewType) 146 { 147 SwTOXType aNewType(TOX_USER, rNewName); 148 pNewType = pDoc->InsertTOXType( aNewType ); 149 } 150 151 rTOXBase.RegisterToTOXType( *((SwTOXType*)pNewType) ); 152 } 153 //----------------------------------------------------------------------------- 154 static const char cUserDefined[] = "User-Defined"; 155 static const char cUserSuffix[] = " (user)"; 156 #define USER_LEN 12 157 #define USER_AND_SUFFIXLEN 19 158 159 void lcl_ConvertTOUNameToProgrammaticName(OUString& rTmp) 160 { 161 ShellResource* pShellRes = ViewShell::GetShellRes(); 162 163 if(rTmp.equals(pShellRes->aTOXUserName)) 164 { 165 rTmp = OUString(C2U(cUserDefined)); 166 } 167 // if the version is not English but the alternative index's name is 168 // "User-Defined" a " (user)" is appended 169 else if(rTmp.equalsAscii(cUserDefined)) 170 { 171 rTmp += C2U(cUserSuffix); 172 } 173 } 174 //----------------------------------------------------------------------------- 175 static void 176 lcl_ConvertTOUNameToUserName(OUString& rTmp) 177 { 178 ShellResource* pShellRes = ViewShell::GetShellRes(); 179 if(rTmp.equalsAscii(cUserDefined)) 180 { 181 rTmp = pShellRes->aTOXUserName; 182 } 183 else if(!pShellRes->aTOXUserName.EqualsAscii(cUserDefined) && 184 USER_AND_SUFFIXLEN == rTmp.getLength()) 185 { 186 //make sure that in non-English versions the " (user)" suffix is removed 187 if (rTmp.matchAsciiL(cUserDefined, sizeof(cUserDefined)) && 188 rTmp.matchAsciiL(cUserSuffix, sizeof(cUserSuffix), USER_LEN)) 189 { 190 rTmp = C2U(cUserDefined); 191 } 192 } 193 } 194 195 /* -----------------13.09.99 16:39------------------- 196 197 --------------------------------------------------*/ 198 typedef ::cppu::WeakImplHelper2 199 < lang::XServiceInfo 200 , container::XIndexReplace 201 > SwXDocumentIndexStyleAccess_Base; 202 203 class SwXDocumentIndex::StyleAccess_Impl 204 : public SwXDocumentIndexStyleAccess_Base 205 { 206 207 private: 208 /// can be destroyed threadsafely, so no UnoImplPtr here 209 ::rtl::Reference<SwXDocumentIndex> m_xParent; 210 211 virtual ~StyleAccess_Impl(); 212 213 public: 214 StyleAccess_Impl(SwXDocumentIndex& rParentIdx); 215 216 // XServiceInfo 217 virtual ::rtl::OUString SAL_CALL getImplementationName() 218 throw (uno::RuntimeException); 219 virtual sal_Bool SAL_CALL 220 supportsService(const ::rtl::OUString& rServiceName) 221 throw (uno::RuntimeException); 222 virtual uno::Sequence< ::rtl::OUString > SAL_CALL 223 getSupportedServiceNames() throw (uno::RuntimeException); 224 225 // XElementAccess 226 virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); 227 virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); 228 229 // XIndexAccess 230 virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); 231 virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) 232 throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, 233 uno::RuntimeException); 234 235 // XIndexReplace 236 virtual void SAL_CALL 237 replaceByIndex(sal_Int32 Index, const uno::Any& rElement) 238 throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, 239 lang::WrappedTargetException, uno::RuntimeException); 240 241 }; 242 243 /* -----------------13.09.99 16:39------------------- 244 245 --------------------------------------------------*/ 246 typedef ::cppu::WeakImplHelper2 247 < lang::XServiceInfo 248 , container::XIndexReplace 249 > SwXDocumentIndexTokenAccess_Base; 250 251 class SwXDocumentIndex::TokenAccess_Impl 252 : public SwXDocumentIndexTokenAccess_Base 253 { 254 255 private: 256 /// can be destroyed threadsafely, so no UnoImplPtr here 257 ::rtl::Reference<SwXDocumentIndex> m_xParent; 258 259 virtual ~TokenAccess_Impl(); 260 261 public: 262 263 TokenAccess_Impl(SwXDocumentIndex& rParentIdx); 264 265 // XServiceInfo 266 virtual ::rtl::OUString SAL_CALL getImplementationName() 267 throw (uno::RuntimeException); 268 virtual sal_Bool SAL_CALL 269 supportsService(const ::rtl::OUString& rServiceName) 270 throw (uno::RuntimeException); 271 virtual uno::Sequence< ::rtl::OUString > SAL_CALL 272 getSupportedServiceNames() throw (uno::RuntimeException); 273 274 // XElementAccess 275 virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); 276 virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); 277 278 // XIndexAccess 279 virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); 280 virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) 281 throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, 282 uno::RuntimeException); 283 284 // XIndexReplace 285 virtual void SAL_CALL 286 replaceByIndex(sal_Int32 Index, const uno::Any& rElement) 287 throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, 288 lang::WrappedTargetException, uno::RuntimeException); 289 290 }; 291 292 293 /****************************************************************** 294 * SwXDocumentIndex 295 ******************************************************************/ 296 297 /* -----------------20.06.98 11:06------------------- 298 * 299 * --------------------------------------------------*/ 300 class SwDocIndexDescriptorProperties_Impl 301 { 302 private: 303 ::std::auto_ptr<SwTOXBase> m_pTOXBase; 304 OUString m_sUserTOXTypeName; 305 306 public: 307 SwDocIndexDescriptorProperties_Impl(SwTOXType const*const pType); 308 309 SwTOXBase & GetTOXBase() { return *m_pTOXBase; } 310 const OUString& GetTypeName() const { return m_sUserTOXTypeName; } 311 void SetTypeName(const OUString& rSet) { m_sUserTOXTypeName = rSet; } 312 }; 313 /* -----------------20.06.98 11:41------------------- 314 * 315 * --------------------------------------------------*/ 316 SwDocIndexDescriptorProperties_Impl::SwDocIndexDescriptorProperties_Impl( 317 SwTOXType const*const pType) 318 { 319 SwForm aForm(pType->GetType()); 320 m_pTOXBase.reset(new SwTOXBase(pType, aForm, 321 nsSwTOXElement::TOX_MARK, pType->GetTypeName())); 322 if(pType->GetType() == TOX_CONTENT || pType->GetType() == TOX_USER) 323 { 324 m_pTOXBase->SetLevel(MAXLEVEL); 325 } 326 m_sUserTOXTypeName = pType->GetTypeName(); 327 } 328 329 static sal_uInt16 330 lcl_TypeToPropertyMap_Index(const TOXTypes eType) 331 { 332 switch (eType) 333 { 334 case TOX_INDEX: return PROPERTY_MAP_INDEX_IDX; 335 case TOX_CONTENT: return PROPERTY_MAP_INDEX_CNTNT; 336 case TOX_TABLES: return PROPERTY_MAP_INDEX_TABLES; 337 case TOX_ILLUSTRATIONS: return PROPERTY_MAP_INDEX_ILLUSTRATIONS; 338 case TOX_OBJECTS: return PROPERTY_MAP_INDEX_OBJECTS; 339 case TOX_AUTHORITIES: return PROPERTY_MAP_BIBLIOGRAPHY; 340 //case TOX_USER: 341 default: 342 return PROPERTY_MAP_INDEX_USER; 343 } 344 } 345 346 class SwXDocumentIndex::Impl 347 : public SwClient 348 { 349 350 public: 351 352 SfxItemPropertySet const& m_rPropSet; 353 const TOXTypes m_eTOXType; 354 SwEventListenerContainer m_ListenerContainer; 355 bool m_bIsDescriptor; 356 SwDoc * m_pDoc; 357 ::std::auto_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps; 358 uno::WeakReference<container::XIndexReplace> m_wStyleAccess; 359 uno::WeakReference<container::XIndexReplace> m_wTokenAccess; 360 361 Impl( SwXDocumentIndex & rThis, 362 SwDoc & rDoc, 363 const TOXTypes eType, 364 SwTOXBaseSection const*const pBaseSection) 365 : SwClient((pBaseSection) ? pBaseSection->GetFmt() : 0) 366 , m_rPropSet( 367 *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType))) 368 , m_eTOXType(eType) 369 , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) 370 // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code 371 , m_bIsDescriptor((0 == pBaseSection) ? true : false) 372 , m_pDoc(&rDoc) 373 , m_pProps((m_bIsDescriptor) 374 ? new SwDocIndexDescriptorProperties_Impl(rDoc.GetTOXType(eType, 0)) 375 : 0) 376 { 377 } 378 379 SwSectionFmt * GetSectionFmt() const { 380 return static_cast<SwSectionFmt *>( 381 const_cast<SwModify *>(GetRegisteredIn())); 382 } 383 384 SwTOXBase & GetTOXSectionOrThrow() const 385 { 386 SwSectionFmt *const pSectionFmt(GetSectionFmt()); 387 SwTOXBase *const pTOXSection( (m_bIsDescriptor) 388 ? &m_pProps->GetTOXBase() 389 : ((pSectionFmt) 390 ? static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()) 391 : 0)); 392 if (!pTOXSection) 393 { 394 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 395 "SwXDocumentIndex: disposed or invalid")), 0); 396 } 397 return *pTOXSection; 398 } 399 400 sal_Int32 GetFormMax() const 401 { 402 SwTOXBase & rSection( GetTOXSectionOrThrow() ); 403 return (m_bIsDescriptor) 404 ? SwForm::GetFormMaxLevel(m_eTOXType) 405 : rSection.GetTOXForm().GetFormMax(); 406 } 407 protected: 408 // SwClient 409 virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew); 410 411 }; 412 413 /*-- 14.12.98 09:35:07--------------------------------------------------- 414 415 -----------------------------------------------------------------------*/ 416 void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) 417 { 418 ClientModify(this, pOld, pNew); 419 420 if (!GetRegisteredIn()) 421 { 422 m_ListenerContainer.Disposing(); 423 } 424 } 425 426 /*-- 14.12.98 09:35:03--------------------------------------------------- 427 428 -----------------------------------------------------------------------*/ 429 SwXDocumentIndex::SwXDocumentIndex( 430 SwTOXBaseSection const& rBaseSection, SwDoc & rDoc) 431 : m_pImpl( new SwXDocumentIndex::Impl( *this, 432 rDoc, rBaseSection.SwTOXBase::GetType(), & rBaseSection) ) 433 { 434 } 435 /* -----------------15.01.99 14:59------------------- 436 * 437 * --------------------------------------------------*/ 438 SwXDocumentIndex::SwXDocumentIndex(const TOXTypes eType, SwDoc& rDoc) 439 : m_pImpl( new SwXDocumentIndex::Impl( *this, rDoc, eType, 0) ) 440 { 441 } 442 443 /*-- 14.12.98 09:35:04--------------------------------------------------- 444 445 -----------------------------------------------------------------------*/ 446 SwXDocumentIndex::~SwXDocumentIndex() 447 { 448 } 449 450 uno::Reference<text::XDocumentIndex> 451 SwXDocumentIndex::CreateXDocumentIndex( 452 SwDoc & rDoc, SwTOXBaseSection const& rSection) 453 { 454 // re-use existing SwXDocumentIndex 455 // #i105557#: do not iterate over the registered clients: race condition 456 SwSectionFmt *const pFmt = rSection.GetFmt(); 457 uno::Reference<text::XDocumentIndex> xIndex(pFmt->GetXObject(), 458 uno::UNO_QUERY); 459 if (!xIndex.is()) 460 { 461 SwXDocumentIndex *const pIndex(new SwXDocumentIndex(rSection, rDoc)); 462 xIndex.set(pIndex); 463 pFmt->SetXObject(uno::Reference<uno::XInterface>(xIndex)); 464 } 465 return xIndex; 466 } 467 468 /* -----------------------------10.03.00 18:02-------------------------------- 469 470 ---------------------------------------------------------------------------*/ 471 const uno::Sequence< sal_Int8 > & SwXDocumentIndex::getUnoTunnelId() 472 { 473 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 474 return aSeq; 475 } 476 /* -----------------------------10.03.00 18:04-------------------------------- 477 478 ---------------------------------------------------------------------------*/ 479 sal_Int64 SAL_CALL 480 SwXDocumentIndex::getSomething(const uno::Sequence< sal_Int8 >& rId) 481 throw (uno::RuntimeException) 482 { 483 return ::sw::UnoTunnelImpl<SwXDocumentIndex>(rId, this); 484 } 485 486 /* -----------------------------06.04.00 15:01-------------------------------- 487 488 ---------------------------------------------------------------------------*/ 489 OUString SAL_CALL 490 SwXDocumentIndex::getImplementationName() throw (uno::RuntimeException) 491 { 492 return C2U("SwXDocumentIndex"); 493 } 494 /* -----------------------------06.04.00 15:01-------------------------------- 495 496 ---------------------------------------------------------------------------*/ 497 sal_Bool SAL_CALL 498 SwXDocumentIndex::supportsService(const OUString& rServiceName) 499 throw (uno::RuntimeException) 500 { 501 vos::OGuard g(Application::GetSolarMutex()); 502 503 return C2U("com.sun.star.text.BaseIndex") == rServiceName 504 || ((TOX_INDEX == m_pImpl->m_eTOXType) && 505 rServiceName.equalsAscii("com.sun.star.text.DocumentIndex")) 506 || ((TOX_CONTENT == m_pImpl->m_eTOXType) && 507 rServiceName.equalsAscii("com.sun.star.text.ContentIndex")) 508 || ((TOX_USER == m_pImpl->m_eTOXType) && 509 rServiceName.equalsAscii("com.sun.star.text.UserDefinedIndex")) 510 || ((TOX_ILLUSTRATIONS == m_pImpl->m_eTOXType) && 511 rServiceName.equalsAscii("com.sun.star.text.IllustrationsIndex")) 512 || ((TOX_TABLES == m_pImpl->m_eTOXType) && 513 rServiceName.equalsAscii("com.sun.star.text.TableIndex")) 514 || ((TOX_OBJECTS == m_pImpl->m_eTOXType) && 515 rServiceName.equalsAscii("com.sun.star.text.ObjectIndex")) 516 || ((TOX_AUTHORITIES == m_pImpl->m_eTOXType) && 517 rServiceName.equalsAscii("com.sun.star.text.Bibliography")); 518 } 519 /* -----------------------------06.04.00 15:01-------------------------------- 520 521 ---------------------------------------------------------------------------*/ 522 uno::Sequence< OUString > SAL_CALL 523 SwXDocumentIndex::getSupportedServiceNames() throw (uno::RuntimeException) 524 { 525 vos::OGuard g(Application::GetSolarMutex()); 526 527 uno::Sequence< OUString > aRet(2); 528 OUString* pArray = aRet.getArray(); 529 pArray[0] = C2U("com.sun.star.text.BaseIndex"); 530 switch (m_pImpl->m_eTOXType) 531 { 532 case TOX_INDEX: 533 pArray[1] = C2U("com.sun.star.text.DocumentIndex"); 534 break; 535 case TOX_CONTENT: 536 pArray[1] = C2U("com.sun.star.text.ContentIndex"); 537 break; 538 case TOX_TABLES: 539 pArray[1] = C2U("com.sun.star.text.TableIndex"); 540 break; 541 case TOX_ILLUSTRATIONS: 542 pArray[1] = C2U("com.sun.star.text.IllustrationsIndex"); 543 break; 544 case TOX_OBJECTS: 545 pArray[1] = C2U("com.sun.star.text.ObjectIndex"); 546 break; 547 case TOX_AUTHORITIES: 548 pArray[1] = C2U("com.sun.star.text.Bibliography"); 549 break; 550 //case TOX_USER: 551 default: 552 pArray[1] = C2U("com.sun.star.text.UserDefinedIndex"); 553 } 554 return aRet; 555 } 556 557 /*-- 14.12.98 09:35:05--------------------------------------------------- 558 559 -----------------------------------------------------------------------*/ 560 OUString SAL_CALL SwXDocumentIndex::getServiceName() 561 throw (uno::RuntimeException) 562 { 563 vos::OGuard g(Application::GetSolarMutex()); 564 565 sal_uInt16 nObjectType = SW_SERVICE_TYPE_INDEX; 566 switch (m_pImpl->m_eTOXType) 567 { 568 // case TOX_INDEX: break; 569 case TOX_USER: nObjectType = SW_SERVICE_USER_INDEX; 570 break; 571 case TOX_CONTENT: nObjectType = SW_SERVICE_CONTENT_INDEX; 572 break; 573 case TOX_ILLUSTRATIONS: nObjectType = SW_SERVICE_INDEX_ILLUSTRATIONS; 574 break; 575 case TOX_OBJECTS: nObjectType = SW_SERVICE_INDEX_OBJECTS; 576 break; 577 case TOX_TABLES: nObjectType = SW_SERVICE_INDEX_TABLES; 578 break; 579 case TOX_AUTHORITIES: nObjectType = SW_SERVICE_INDEX_BIBLIOGRAPHY; 580 break; 581 default: 582 break; 583 } 584 return SwXServiceProvider::GetProviderName(nObjectType); 585 } 586 587 /*-- 14.12.98 09:35:05--------------------------------------------------- 588 589 -----------------------------------------------------------------------*/ 590 void SAL_CALL SwXDocumentIndex::update() throw (uno::RuntimeException) 591 { 592 vos::OGuard aGuard(Application::GetSolarMutex()); 593 594 SwSectionFmt *const pFmt = m_pImpl->GetSectionFmt(); 595 SwTOXBaseSection *const pTOXBase = (pFmt) ? 596 static_cast<SwTOXBaseSection*>(pFmt->GetSection()) : 0; 597 if(!pTOXBase) 598 { 599 throw uno::RuntimeException(); 600 } 601 pTOXBase->Update(); 602 // page numbers 603 pTOXBase->UpdatePageNum(); 604 } 605 606 /*-- 14.12.98 09:35:05--------------------------------------------------- 607 608 -----------------------------------------------------------------------*/ 609 uno::Reference< beans::XPropertySetInfo > SAL_CALL 610 SwXDocumentIndex::getPropertySetInfo() throw (uno::RuntimeException) 611 { 612 vos::OGuard g(Application::GetSolarMutex()); 613 614 const uno::Reference< beans::XPropertySetInfo > xRef = 615 m_pImpl->m_rPropSet.getPropertySetInfo(); 616 return xRef; 617 } 618 619 /*-- 14.12.98 09:35:05--------------------------------------------------- 620 621 -----------------------------------------------------------------------*/ 622 void SAL_CALL 623 SwXDocumentIndex::setPropertyValue( 624 const OUString& rPropertyName, const uno::Any& rValue) 625 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 626 lang::IllegalArgumentException, lang::WrappedTargetException, 627 uno::RuntimeException) 628 { 629 vos::OGuard aGuard(Application::GetSolarMutex()); 630 631 SfxItemPropertySimpleEntry const*const pEntry = 632 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 633 if (!pEntry) 634 { 635 throw beans::UnknownPropertyException( 636 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 637 + rPropertyName, 638 static_cast<cppu::OWeakObject *>(this)); 639 } 640 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 641 { 642 throw beans::PropertyVetoException( 643 OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: " )) 644 + rPropertyName, 645 static_cast<cppu::OWeakObject *>(this)); 646 } 647 648 SwSectionFmt *const pSectionFmt(m_pImpl->GetSectionFmt()); 649 SwTOXBase & rTOXBase( m_pImpl->GetTOXSectionOrThrow() ); 650 651 sal_uInt16 nCreate = rTOXBase.GetCreateType(); 652 sal_uInt16 nTOIOptions = 0; 653 sal_uInt16 nOLEOptions = rTOXBase.GetOLEOptions(); 654 const TOXTypes eTxBaseType = rTOXBase.GetTOXType()->GetType(); 655 if (eTxBaseType == TOX_INDEX) 656 { 657 nTOIOptions = rTOXBase.GetOptions(); 658 } 659 SwForm aForm(rTOXBase.GetTOXForm()); 660 sal_Bool bForm = sal_False; 661 switch (pEntry->nWID) 662 { 663 case WID_IDX_TITLE: 664 { 665 OUString sNewName; 666 if (!(rValue >>= sNewName)) 667 { 668 throw lang::IllegalArgumentException(); 669 } 670 rTOXBase.SetTitle(sNewName); 671 } 672 break; 673 case WID_IDX_NAME: 674 { 675 OUString sNewName; 676 if (!(rValue >>= sNewName)) 677 { 678 throw lang::IllegalArgumentException(); 679 } 680 rTOXBase.SetTOXName(sNewName); 681 } 682 break; 683 case WID_USER_IDX_NAME: 684 { 685 OUString sNewName; 686 if (!(rValue >>= sNewName)) 687 { 688 throw lang::IllegalArgumentException(); 689 } 690 lcl_ConvertTOUNameToUserName(sNewName); 691 DBG_ASSERT(TOX_USER == eTxBaseType, 692 "tox type name can only be changed for user indexes"); 693 if (pSectionFmt) 694 { 695 OUString sTmp = rTOXBase.GetTOXType()->GetTypeName(); 696 if (sTmp != sNewName) 697 { 698 lcl_ReAssignTOXType(pSectionFmt->GetDoc(), 699 rTOXBase, sNewName); 700 } 701 } 702 else 703 { 704 m_pImpl->m_pProps->SetTypeName(sNewName); 705 } 706 } 707 break; 708 case WID_IDX_LOCALE: 709 { 710 lang::Locale aLocale; 711 if (!(rValue>>= aLocale)) 712 { 713 throw lang::IllegalArgumentException(); 714 } 715 rTOXBase.SetLanguage(SvxLocaleToLanguage(aLocale)); 716 } 717 break; 718 case WID_IDX_SORT_ALGORITHM: 719 { 720 OUString sTmp; 721 if (!(rValue >>= sTmp)) 722 { 723 throw lang::IllegalArgumentException(); 724 } 725 rTOXBase.SetSortAlgorithm(sTmp); 726 } 727 break; 728 case WID_LEVEL: 729 { 730 rTOXBase.SetLevel(lcl_AnyToInt16(rValue)); 731 } 732 break; 733 case WID_CREATE_FROM_MARKS: 734 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_MARK); 735 break; 736 case WID_CREATE_FROM_OUTLINE: 737 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OUTLINELEVEL); 738 break; 739 // case WID_PARAGRAPH_STYLE_NAMES :DBG_ERROR("not implemented") 740 // break; 741 case WID_CREATE_FROM_CHAPTER: 742 rTOXBase.SetFromChapter(lcl_AnyToBool(rValue)); 743 break; 744 case WID_CREATE_FROM_LABELS: 745 rTOXBase.SetFromObjectNames(! lcl_AnyToBool(rValue)); 746 break; 747 case WID_PROTECTED: 748 { 749 sal_Bool bSet = lcl_AnyToBool(rValue); 750 rTOXBase.SetProtected(bSet); 751 if (pSectionFmt) 752 { 753 static_cast<SwTOXBaseSection &>(rTOXBase).SetProtect(bSet); 754 } 755 } 756 break; 757 case WID_USE_ALPHABETICAL_SEPARATORS: 758 lcl_AnyToBitMask(rValue, nTOIOptions, 759 nsSwTOIOptions::TOI_ALPHA_DELIMITTER); 760 break; 761 case WID_USE_KEY_AS_ENTRY: 762 lcl_AnyToBitMask(rValue, nTOIOptions, 763 nsSwTOIOptions::TOI_KEY_AS_ENTRY); 764 break; 765 case WID_USE_COMBINED_ENTRIES: 766 lcl_AnyToBitMask(rValue, nTOIOptions, 767 nsSwTOIOptions::TOI_SAME_ENTRY); 768 break; 769 case WID_IS_CASE_SENSITIVE: 770 lcl_AnyToBitMask(rValue, nTOIOptions, 771 nsSwTOIOptions::TOI_CASE_SENSITIVE); 772 break; 773 case WID_USE_P_P: 774 lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_FF); 775 break; 776 case WID_USE_DASH: 777 lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_DASH); 778 break; 779 case WID_USE_UPPER_CASE: 780 lcl_AnyToBitMask(rValue, nTOIOptions, 781 nsSwTOIOptions::TOI_INITIAL_CAPS); 782 break; 783 case WID_IS_COMMA_SEPARATED: 784 bForm = sal_True; 785 aForm.SetCommaSeparated(lcl_AnyToBool(rValue)); 786 break; 787 case WID_LABEL_CATEGORY: 788 { 789 // convert file-format/API/external programmatic english name 790 // to internal UI name before usage 791 String aName( SwStyleNameMapper::GetSpecialExtraUIName( 792 lcl_AnyToString(rValue) ) ); 793 rTOXBase.SetSequenceName( aName ); 794 } 795 break; 796 case WID_LABEL_DISPLAY_TYPE: 797 { 798 const sal_Int16 nVal = lcl_AnyToInt16(rValue); 799 sal_uInt16 nSet = CAPTION_COMPLETE; 800 switch (nVal) 801 { 802 case text::ReferenceFieldPart::TEXT: 803 nSet = CAPTION_COMPLETE; 804 break; 805 case text::ReferenceFieldPart::CATEGORY_AND_NUMBER: 806 nSet = CAPTION_NUMBER; 807 break; 808 case text::ReferenceFieldPart::ONLY_CAPTION: 809 nSet = CAPTION_TEXT; 810 break; 811 default: 812 throw lang::IllegalArgumentException(); 813 } 814 rTOXBase.SetCaptionDisplay(static_cast<SwCaptionDisplay>(nSet)); 815 } 816 break; 817 case WID_USE_LEVEL_FROM_SOURCE: 818 rTOXBase.SetLevelFromChapter(lcl_AnyToBool(rValue)); 819 break; 820 case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME: 821 { 822 String aString; 823 SwStyleNameMapper::FillUIName(lcl_AnyToString(rValue), 824 aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True); 825 rTOXBase.SetMainEntryCharStyle( aString ); 826 } 827 break; 828 case WID_CREATE_FROM_TABLES: 829 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TABLE); 830 break; 831 case WID_CREATE_FROM_TEXT_FRAMES: 832 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_FRAME); 833 break; 834 case WID_CREATE_FROM_GRAPHIC_OBJECTS: 835 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_GRAPHIC); 836 break; 837 case WID_CREATE_FROM_EMBEDDED_OBJECTS: 838 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OLE); 839 break; 840 case WID_CREATE_FROM_STAR_MATH: 841 lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_MATH); 842 break; 843 case WID_CREATE_FROM_STAR_CHART: 844 lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CHART); 845 break; 846 case WID_CREATE_FROM_STAR_CALC: 847 lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CALC); 848 break; 849 case WID_CREATE_FROM_STAR_DRAW: 850 lcl_AnyToBitMask(rValue, nOLEOptions, 851 nsSwTOOElements::TOO_DRAW_IMPRESS); 852 break; 853 case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS: 854 lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_OTHER); 855 break; 856 case WID_PARA_HEAD: 857 { 858 String aString; 859 SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue), 860 aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True); 861 bForm = sal_True; 862 // Header is on Pos 0 863 aForm.SetTemplate( 0, aString ); 864 } 865 break; 866 case WID_IS_RELATIVE_TABSTOPS: 867 bForm = sal_True; 868 aForm.SetRelTabPos(lcl_AnyToBool(rValue)); 869 break; 870 case WID_PARA_SEP: 871 { 872 String aString; 873 bForm = sal_True; 874 SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue), 875 aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True); 876 aForm.SetTemplate( 1, aString ); 877 } 878 break; 879 case WID_CREATE_FROM_PARAGRAPH_STYLES: 880 lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TEMPLATE); 881 break; 882 883 case WID_PARA_LEV1: 884 case WID_PARA_LEV2: 885 case WID_PARA_LEV3: 886 case WID_PARA_LEV4: 887 case WID_PARA_LEV5: 888 case WID_PARA_LEV6: 889 case WID_PARA_LEV7: 890 case WID_PARA_LEV8: 891 case WID_PARA_LEV9: 892 case WID_PARA_LEV10: 893 { 894 bForm = sal_True; 895 // in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1 896 const sal_uInt16 nLPos = rTOXBase.GetType() == TOX_INDEX ? 2 : 1; 897 String aString; 898 SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue), 899 aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True); 900 aForm.SetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1, aString ); 901 } 902 break; 903 default: 904 //this is for items only 905 if (WID_PRIMARY_KEY > pEntry->nWID) 906 { 907 const SwAttrSet& rSet = 908 m_pImpl->m_pDoc->GetTOXBaseAttrSet(rTOXBase); 909 SfxItemSet aAttrSet(rSet); 910 m_pImpl->m_rPropSet.setPropertyValue( 911 rPropertyName, rValue, aAttrSet); 912 913 const SwSectionFmts& rSects = m_pImpl->m_pDoc->GetSections(); 914 for (sal_uInt16 i = 0; i < rSects.Count(); i++) 915 { 916 const SwSectionFmt* pTmpFmt = rSects[ i ]; 917 if (pTmpFmt == pSectionFmt) 918 { 919 SwSectionData tmpData( 920 static_cast<SwTOXBaseSection&>(rTOXBase)); 921 m_pImpl->m_pDoc->UpdateSection(i, tmpData, & aAttrSet); 922 break; 923 } 924 } 925 } 926 } 927 rTOXBase.SetCreate(nCreate); 928 rTOXBase.SetOLEOptions(nOLEOptions); 929 if (rTOXBase.GetTOXType()->GetType() == TOX_INDEX) 930 { 931 rTOXBase.SetOptions(nTOIOptions); 932 } 933 if (bForm) 934 { 935 rTOXBase.SetTOXForm(aForm); 936 } 937 } 938 939 /*-- 14.12.98 09:35:05--------------------------------------------------- 940 941 -----------------------------------------------------------------------*/ 942 uno::Any SAL_CALL 943 SwXDocumentIndex::getPropertyValue(const OUString& rPropertyName) 944 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 945 uno::RuntimeException) 946 { 947 vos::OGuard aGuard(Application::GetSolarMutex()); 948 949 uno::Any aRet; 950 SfxItemPropertySimpleEntry const*const pEntry = 951 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 952 if (!pEntry) 953 { 954 throw beans::UnknownPropertyException( 955 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 956 + rPropertyName, 957 static_cast< cppu::OWeakObject * >(this)); 958 } 959 960 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 961 SwTOXBase* pTOXBase = 0; 962 if (pSectionFmt) 963 { 964 pTOXBase = static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()); 965 } 966 else if (m_pImpl->m_bIsDescriptor) 967 { 968 pTOXBase = &m_pImpl->m_pProps->GetTOXBase(); 969 } 970 if(pTOXBase) 971 { 972 const sal_uInt16 nCreate = pTOXBase->GetCreateType(); 973 const sal_uInt16 nOLEOptions = pTOXBase->GetOLEOptions(); 974 const sal_uInt16 nTOIOptions = 975 (pTOXBase->GetTOXType()->GetType() == TOX_INDEX) 976 ? pTOXBase->GetOptions() 977 : 0U; 978 const SwForm& rForm = pTOXBase->GetTOXForm(); 979 switch(pEntry->nWID) 980 { 981 case WID_IDX_CONTENT_SECTION: 982 case WID_IDX_HEADER_SECTION : 983 if(WID_IDX_CONTENT_SECTION == pEntry->nWID) 984 { 985 const uno::Reference <text::XTextSection> xContentSect = 986 SwXTextSection::CreateXTextSection( pSectionFmt ); 987 aRet <<= xContentSect; 988 } 989 else 990 { 991 SwSections aSectArr; 992 pSectionFmt->GetChildSections(aSectArr, 993 SORTSECT_NOT, sal_False); 994 for(sal_uInt16 i = 0; i < aSectArr.Count(); i++) 995 { 996 SwSection* pSect = aSectArr[i]; 997 if(pSect->GetType() == TOX_HEADER_SECTION) 998 { 999 const uno::Reference <text::XTextSection> xHeader = 1000 SwXTextSection::CreateXTextSection( 1001 pSect->GetFmt() ); 1002 aRet <<= xHeader; 1003 break; 1004 } 1005 } 1006 } 1007 break; 1008 case WID_IDX_TITLE : 1009 { 1010 OUString uRet(pTOXBase->GetTitle()); 1011 aRet <<= uRet; 1012 break; 1013 } 1014 case WID_IDX_NAME: 1015 aRet <<= OUString(pTOXBase->GetTOXName()); 1016 break; 1017 case WID_USER_IDX_NAME: 1018 { 1019 OUString sTmp; 1020 if (!m_pImpl->m_bIsDescriptor) 1021 { 1022 sTmp = pTOXBase->GetTOXType()->GetTypeName(); 1023 } 1024 else 1025 { 1026 sTmp = m_pImpl->m_pProps->GetTypeName(); 1027 } 1028 //I18N 1029 lcl_ConvertTOUNameToProgrammaticName(sTmp); 1030 aRet <<= sTmp; 1031 } 1032 break; 1033 case WID_IDX_LOCALE: 1034 aRet <<= SvxCreateLocale(pTOXBase->GetLanguage()); 1035 break; 1036 case WID_IDX_SORT_ALGORITHM: 1037 aRet <<= OUString(pTOXBase->GetSortAlgorithm()); 1038 break; 1039 case WID_LEVEL : 1040 aRet <<= static_cast<sal_Int16>(pTOXBase->GetLevel()); 1041 break; 1042 case WID_CREATE_FROM_MARKS: 1043 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_MARK); 1044 break; 1045 case WID_CREATE_FROM_OUTLINE: 1046 lcl_BitMaskToAny(aRet, nCreate, 1047 nsSwTOXElement::TOX_OUTLINELEVEL); 1048 break; 1049 case WID_CREATE_FROM_CHAPTER: 1050 { 1051 const sal_Bool bRet = pTOXBase->IsFromChapter(); 1052 aRet <<= bRet; 1053 } 1054 break; 1055 case WID_CREATE_FROM_LABELS: 1056 { 1057 const sal_Bool bRet = ! pTOXBase->IsFromObjectNames(); 1058 aRet <<= bRet; 1059 } 1060 break; 1061 case WID_PROTECTED: 1062 { 1063 const sal_Bool bRet = pTOXBase->IsProtected(); 1064 aRet <<= bRet; 1065 } 1066 break; 1067 case WID_USE_ALPHABETICAL_SEPARATORS: 1068 lcl_BitMaskToAny(aRet, nTOIOptions, 1069 nsSwTOIOptions::TOI_ALPHA_DELIMITTER); 1070 break; 1071 case WID_USE_KEY_AS_ENTRY: 1072 lcl_BitMaskToAny(aRet, nTOIOptions, 1073 nsSwTOIOptions::TOI_KEY_AS_ENTRY); 1074 break; 1075 case WID_USE_COMBINED_ENTRIES: 1076 lcl_BitMaskToAny(aRet, nTOIOptions, 1077 nsSwTOIOptions::TOI_SAME_ENTRY); 1078 break; 1079 case WID_IS_CASE_SENSITIVE: 1080 lcl_BitMaskToAny(aRet, nTOIOptions, 1081 nsSwTOIOptions::TOI_CASE_SENSITIVE); 1082 break; 1083 case WID_USE_P_P: 1084 lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_FF); 1085 break; 1086 case WID_USE_DASH: 1087 lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_DASH); 1088 break; 1089 case WID_USE_UPPER_CASE: 1090 lcl_BitMaskToAny(aRet, nTOIOptions, 1091 nsSwTOIOptions::TOI_INITIAL_CAPS); 1092 break; 1093 case WID_IS_COMMA_SEPARATED: 1094 { 1095 const sal_Bool bRet = rForm.IsCommaSeparated(); 1096 aRet <<= bRet; 1097 } 1098 break; 1099 case WID_LABEL_CATEGORY: 1100 { 1101 // convert internal UI name to 1102 // file-format/API/external programmatic english name 1103 // before usage 1104 String aName( SwStyleNameMapper::GetSpecialExtraProgName( 1105 pTOXBase->GetSequenceName() ) ); 1106 aRet <<= OUString( aName ); 1107 } 1108 break; 1109 case WID_LABEL_DISPLAY_TYPE: 1110 { 1111 sal_Int16 nSet = text::ReferenceFieldPart::TEXT; 1112 switch (pTOXBase->GetCaptionDisplay()) 1113 { 1114 case CAPTION_COMPLETE: 1115 nSet = text::ReferenceFieldPart::TEXT; 1116 break; 1117 case CAPTION_NUMBER: 1118 nSet = text::ReferenceFieldPart::CATEGORY_AND_NUMBER; 1119 break; 1120 case CAPTION_TEXT: 1121 nSet = text::ReferenceFieldPart::ONLY_CAPTION; 1122 break; 1123 } 1124 aRet <<= nSet; 1125 } 1126 break; 1127 case WID_USE_LEVEL_FROM_SOURCE: 1128 { 1129 const sal_Bool bRet = pTOXBase->IsLevelFromChapter(); 1130 aRet <<= bRet; 1131 } 1132 break; 1133 case WID_LEVEL_FORMAT: 1134 { 1135 uno::Reference< container::XIndexReplace > xTokenAccess( 1136 m_pImpl->m_wTokenAccess); 1137 if (!xTokenAccess.is()) 1138 { 1139 xTokenAccess = new TokenAccess_Impl(*this); 1140 m_pImpl->m_wTokenAccess = xTokenAccess; 1141 } 1142 aRet <<= xTokenAccess; 1143 } 1144 break; 1145 case WID_LEVEL_PARAGRAPH_STYLES: 1146 { 1147 uno::Reference< container::XIndexReplace > xStyleAccess( 1148 m_pImpl->m_wStyleAccess); 1149 if (!xStyleAccess.is()) 1150 { 1151 xStyleAccess = new StyleAccess_Impl(*this); 1152 m_pImpl->m_wStyleAccess = xStyleAccess; 1153 } 1154 aRet <<= xStyleAccess; 1155 } 1156 break; 1157 case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME: 1158 { 1159 String aString; 1160 SwStyleNameMapper::FillProgName( 1161 pTOXBase->GetMainEntryCharStyle(), 1162 aString, 1163 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, 1164 sal_True); 1165 aRet <<= OUString( aString ); 1166 } 1167 break; 1168 case WID_CREATE_FROM_TABLES: 1169 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TABLE); 1170 break; 1171 case WID_CREATE_FROM_TEXT_FRAMES: 1172 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_FRAME); 1173 break; 1174 case WID_CREATE_FROM_GRAPHIC_OBJECTS: 1175 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_GRAPHIC); 1176 break; 1177 case WID_CREATE_FROM_EMBEDDED_OBJECTS: 1178 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_OLE); 1179 break; 1180 case WID_CREATE_FROM_STAR_MATH: 1181 lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_MATH); 1182 break; 1183 case WID_CREATE_FROM_STAR_CHART: 1184 lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CHART); 1185 break; 1186 case WID_CREATE_FROM_STAR_CALC: 1187 lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CALC); 1188 break; 1189 case WID_CREATE_FROM_STAR_DRAW: 1190 lcl_BitMaskToAny(aRet, nOLEOptions, 1191 nsSwTOOElements::TOO_DRAW_IMPRESS); 1192 break; 1193 case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS: 1194 lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_OTHER); 1195 break; 1196 case WID_CREATE_FROM_PARAGRAPH_STYLES: 1197 lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TEMPLATE); 1198 break; 1199 case WID_PARA_HEAD: 1200 { 1201 //Header steht an Pos 0 1202 String aString; 1203 SwStyleNameMapper::FillProgName(rForm.GetTemplate( 0 ), aString, 1204 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True ); 1205 aRet <<= OUString( aString ); 1206 } 1207 break; 1208 case WID_PARA_SEP: 1209 { 1210 String aString; 1211 SwStyleNameMapper::FillProgName( 1212 rForm.GetTemplate( 1 ), 1213 aString, 1214 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, 1215 sal_True); 1216 aRet <<= OUString( aString ); 1217 } 1218 break; 1219 case WID_PARA_LEV1: 1220 case WID_PARA_LEV2: 1221 case WID_PARA_LEV3: 1222 case WID_PARA_LEV4: 1223 case WID_PARA_LEV5: 1224 case WID_PARA_LEV6: 1225 case WID_PARA_LEV7: 1226 case WID_PARA_LEV8: 1227 case WID_PARA_LEV9: 1228 case WID_PARA_LEV10: 1229 { 1230 // in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1 1231 sal_uInt16 nLPos = pTOXBase->GetType() == TOX_INDEX ? 2 : 1; 1232 String aString; 1233 SwStyleNameMapper::FillProgName( 1234 rForm.GetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1), 1235 aString, 1236 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, 1237 sal_True); 1238 aRet <<= OUString( aString ); 1239 } 1240 break; 1241 case WID_IS_RELATIVE_TABSTOPS: 1242 { 1243 const sal_Bool bRet = rForm.IsRelTabPos(); 1244 aRet <<= bRet; 1245 } 1246 break; 1247 case WID_INDEX_MARKS: 1248 { 1249 SwTOXMarks aMarks; 1250 const SwTOXType* pType = pTOXBase->GetTOXType(); 1251 SwTOXMark::InsertTOXMarks( aMarks, *pType ); 1252 uno::Sequence< uno::Reference<text::XDocumentIndexMark> > aXMarks(aMarks.Count()); 1253 uno::Reference<text::XDocumentIndexMark>* pxMarks = aXMarks.getArray(); 1254 for(sal_uInt16 i = 0; i < aMarks.Count(); i++) 1255 { 1256 SwTOXMark* pMark = aMarks.GetObject(i); 1257 pxMarks[i] = SwXDocumentIndexMark::CreateXDocumentIndexMark( 1258 *m_pImpl->m_pDoc, 1259 *const_cast<SwTOXType*>(pType), *pMark); 1260 } 1261 aRet <<= aXMarks; 1262 } 1263 break; 1264 default: 1265 //this is for items only 1266 if(WID_PRIMARY_KEY > pEntry->nWID) 1267 { 1268 const SwAttrSet& rSet = 1269 m_pImpl->m_pDoc->GetTOXBaseAttrSet(*pTOXBase); 1270 aRet = m_pImpl->m_rPropSet.getPropertyValue( 1271 rPropertyName, rSet); 1272 } 1273 } 1274 } 1275 return aRet; 1276 } 1277 1278 /*-- 14.12.98 09:35:06--------------------------------------------------- 1279 1280 -----------------------------------------------------------------------*/ 1281 void SAL_CALL 1282 SwXDocumentIndex::addPropertyChangeListener( 1283 const ::rtl::OUString& /*rPropertyName*/, 1284 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 1285 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 1286 uno::RuntimeException) 1287 { 1288 OSL_ENSURE(false, 1289 "SwXDocumentIndex::addPropertyChangeListener(): not implemented"); 1290 } 1291 1292 void SAL_CALL 1293 SwXDocumentIndex::removePropertyChangeListener( 1294 const ::rtl::OUString& /*rPropertyName*/, 1295 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 1296 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 1297 uno::RuntimeException) 1298 { 1299 OSL_ENSURE(false, 1300 "SwXDocumentIndex::removePropertyChangeListener(): not implemented"); 1301 } 1302 1303 void SAL_CALL 1304 SwXDocumentIndex::addVetoableChangeListener( 1305 const ::rtl::OUString& /*rPropertyName*/, 1306 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 1307 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 1308 uno::RuntimeException) 1309 { 1310 OSL_ENSURE(false, 1311 "SwXDocumentIndex::addVetoableChangeListener(): not implemented"); 1312 } 1313 1314 void SAL_CALL 1315 SwXDocumentIndex::removeVetoableChangeListener( 1316 const ::rtl::OUString& /*rPropertyName*/, 1317 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 1318 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 1319 uno::RuntimeException) 1320 { 1321 OSL_ENSURE(false, 1322 "SwXDocumentIndex::removeVetoableChangeListener(): not implemented"); 1323 } 1324 1325 /* -----------------18.02.99 13:39------------------- 1326 * 1327 * --------------------------------------------------*/ 1328 void SAL_CALL 1329 SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange) 1330 throw (lang::IllegalArgumentException, uno::RuntimeException) 1331 { 1332 vos::OGuard aGuard(Application::GetSolarMutex()); 1333 1334 if (!m_pImpl->m_bIsDescriptor) 1335 { 1336 throw uno::RuntimeException(); 1337 } 1338 const uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); 1339 SwXTextRange *const pRange = 1340 ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel); 1341 OTextCursorHelper *const pCursor = 1342 ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel); 1343 1344 SwDoc *const pDoc = 1345 (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0); 1346 if (!pDoc) 1347 { 1348 throw lang::IllegalArgumentException(); 1349 } 1350 1351 SwUnoInternalPaM aPam(*pDoc); 1352 //das muss jetzt sal_True liefern 1353 ::sw::XTextRangeToSwPaM(aPam, xTextRange); 1354 1355 const SwTOXBase* pOld = pDoc->GetCurTOX( *aPam.Start() ); 1356 if (pOld) 1357 { 1358 throw lang::IllegalArgumentException(); 1359 } 1360 1361 UnoActionContext aAction(pDoc); 1362 if (aPam.HasMark()) 1363 { 1364 pDoc->DeleteAndJoin(aPam); 1365 } 1366 1367 SwTOXBase & rTOXBase = m_pImpl->m_pProps->GetTOXBase(); 1368 SwTOXType const*const pTOXType = rTOXBase.GetTOXType(); 1369 if ((TOX_USER == pTOXType->GetType()) && 1370 !m_pImpl->m_pProps->GetTypeName().equals(pTOXType->GetTypeName())) 1371 { 1372 lcl_ReAssignTOXType(pDoc, rTOXBase, m_pImpl->m_pProps->GetTypeName()); 1373 } 1374 //TODO: apply Section attributes (columns and background) 1375 SwTOXBaseSection const*const pTOX = 1376 pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase, 0, sal_False ); 1377 1378 pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName()); 1379 1380 // update page numbers 1381 pTOX->GetFmt()->Add(m_pImpl.get()); 1382 pTOX->GetFmt()->SetXObject(static_cast< ::cppu::OWeakObject*>(this)); 1383 const_cast<SwTOXBaseSection*>(pTOX)->UpdatePageNum(); 1384 1385 m_pImpl->m_pProps.reset(); 1386 m_pImpl->m_pDoc = pDoc; 1387 m_pImpl->m_bIsDescriptor = sal_False; 1388 } 1389 1390 /*-- 15.01.99 14:23:56--------------------------------------------------- 1391 1392 -----------------------------------------------------------------------*/ 1393 uno::Reference< text::XTextRange > SAL_CALL 1394 SwXDocumentIndex::getAnchor() throw (uno::RuntimeException) 1395 { 1396 vos::OGuard aGuard(Application::GetSolarMutex()); 1397 1398 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1399 if (!pSectionFmt) 1400 { 1401 throw uno::RuntimeException(); 1402 } 1403 1404 uno::Reference< text::XTextRange > xRet; 1405 SwNodeIndex const*const pIdx( pSectionFmt->GetCntnt().GetCntntIdx() ); 1406 if (pIdx && pIdx->GetNode().GetNodes().IsDocNodes()) 1407 { 1408 SwPaM aPaM(*pIdx); 1409 aPaM.Move( fnMoveForward, fnGoCntnt ); 1410 aPaM.SetMark(); 1411 aPaM.GetPoint()->nNode = *pIdx->GetNode().EndOfSectionNode(); 1412 aPaM.Move( fnMoveBackward, fnGoCntnt ); 1413 xRet = SwXTextRange::CreateXTextRange(*pSectionFmt->GetDoc(), 1414 *aPaM.GetMark(), aPaM.GetPoint()); 1415 } 1416 return xRet; 1417 } 1418 1419 /*-- 15.01.99 15:46:48--------------------------------------------------- 1420 1421 -----------------------------------------------------------------------*/ 1422 void lcl_RemoveChildSections(SwSectionFmt& rParentFmt) 1423 { 1424 SwSections aTmpArr; 1425 SwDoc *const pDoc = rParentFmt.GetDoc(); 1426 const sal_uInt16 nCnt = rParentFmt.GetChildSections(aTmpArr, SORTSECT_POS); 1427 if( nCnt ) 1428 { 1429 for( sal_uInt16 n = 0; n < nCnt; ++n ) 1430 { 1431 if( aTmpArr[n]->GetFmt()->IsInNodesArr() ) 1432 { 1433 SwSectionFmt* pFmt = aTmpArr[n]->GetFmt(); 1434 lcl_RemoveChildSections(*pFmt); 1435 pDoc->DelSectionFmt( pFmt ); 1436 } 1437 } 1438 } 1439 } 1440 1441 void SAL_CALL SwXDocumentIndex::dispose() throw (uno::RuntimeException) 1442 { 1443 vos::OGuard aGuard(Application::GetSolarMutex()); 1444 1445 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1446 if (pSectionFmt) 1447 { 1448 pSectionFmt->GetDoc()->DeleteTOX( 1449 *static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()), 1450 sal_True); 1451 } 1452 } 1453 1454 /*-- 15.01.99 15:46:49--------------------------------------------------- 1455 1456 -----------------------------------------------------------------------*/ 1457 void SAL_CALL 1458 SwXDocumentIndex::addEventListener( 1459 const uno::Reference< lang::XEventListener > & xListener) 1460 throw (uno::RuntimeException) 1461 { 1462 vos::OGuard g(Application::GetSolarMutex()); 1463 1464 if (!m_pImpl->GetRegisteredIn()) 1465 { 1466 throw uno::RuntimeException(); 1467 } 1468 m_pImpl->m_ListenerContainer.AddListener(xListener); 1469 } 1470 /*-- 15.01.99 15:46:54--------------------------------------------------- 1471 1472 -----------------------------------------------------------------------*/ 1473 void SAL_CALL 1474 SwXDocumentIndex::removeEventListener( 1475 const uno::Reference< lang::XEventListener > & xListener) 1476 throw (uno::RuntimeException) 1477 { 1478 vos::OGuard g(Application::GetSolarMutex()); 1479 1480 if (!m_pImpl->GetRegisteredIn() || 1481 !m_pImpl->m_ListenerContainer.RemoveListener(xListener)) 1482 { 1483 throw uno::RuntimeException(); 1484 } 1485 } 1486 1487 /* -----------------30.07.99 11:28------------------- 1488 1489 --------------------------------------------------*/ 1490 OUString SAL_CALL SwXDocumentIndex::getName() throw (uno::RuntimeException) 1491 { 1492 vos::OGuard g(Application::GetSolarMutex()); 1493 1494 OUString uRet; 1495 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1496 if (m_pImpl->m_bIsDescriptor) 1497 { 1498 uRet = OUString(m_pImpl->m_pProps->GetTOXBase().GetTOXName()); 1499 } 1500 else if(pSectionFmt) 1501 { 1502 uRet = OUString(pSectionFmt->GetSection()->GetSectionName()); 1503 } 1504 else 1505 { 1506 throw uno::RuntimeException(); 1507 } 1508 return uRet; 1509 } 1510 /* -----------------30.07.99 11:28------------------- 1511 1512 --------------------------------------------------*/ 1513 void SAL_CALL 1514 SwXDocumentIndex::setName(const OUString& rName) throw (uno::RuntimeException) 1515 { 1516 vos::OGuard g(Application::GetSolarMutex()); 1517 1518 if (!rName.getLength()) 1519 { 1520 throw uno::RuntimeException(); 1521 } 1522 1523 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1524 if (m_pImpl->m_bIsDescriptor) 1525 { 1526 m_pImpl->m_pProps->GetTOXBase().SetTOXName(rName); 1527 } 1528 else if (pSectionFmt) 1529 { 1530 const bool bSuccess = pSectionFmt->GetDoc()->SetTOXBaseName( 1531 *static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()), rName); 1532 if (!bSuccess) 1533 { 1534 throw uno::RuntimeException(); 1535 } 1536 } 1537 else 1538 { 1539 throw uno::RuntimeException(); 1540 } 1541 } 1542 1543 // MetadatableMixin 1544 ::sfx2::Metadatable* SwXDocumentIndex::GetCoreObject() 1545 { 1546 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1547 return pSectionFmt; 1548 } 1549 1550 uno::Reference<frame::XModel> SwXDocumentIndex::GetModel() 1551 { 1552 SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() ); 1553 if (pSectionFmt) 1554 { 1555 SwDocShell const*const pShell( pSectionFmt->GetDoc()->GetDocShell() ); 1556 return (pShell) ? pShell->GetModel() : 0; 1557 } 1558 return 0; 1559 } 1560 1561 1562 /****************************************************************** 1563 * SwXDocumentIndexMark 1564 ******************************************************************/ 1565 /* -----------------21.04.99 09:36------------------- 1566 * 1567 * --------------------------------------------------*/ 1568 static sal_uInt16 1569 lcl_TypeToPropertyMap_Mark(const TOXTypes eType) 1570 { 1571 switch (eType) 1572 { 1573 case TOX_INDEX: return PROPERTY_MAP_INDEX_MARK; 1574 case TOX_CONTENT: return PROPERTY_MAP_CNTIDX_MARK; 1575 //case TOX_USER: 1576 default: 1577 return PROPERTY_MAP_USER_MARK; 1578 } 1579 } 1580 1581 class SwXDocumentIndexMark::Impl 1582 : public SwClient 1583 { 1584 private: 1585 bool m_bInReplaceMark; 1586 1587 public: 1588 1589 SfxItemPropertySet const& m_rPropSet; 1590 const TOXTypes m_eTOXType; 1591 SwEventListenerContainer m_ListenerContainer; 1592 bool m_bIsDescriptor; 1593 SwDepend m_TypeDepend; 1594 const SwTOXMark * m_pTOXMark; 1595 SwDoc * m_pDoc; 1596 1597 sal_Bool m_bMainEntry; 1598 sal_uInt16 m_nLevel; 1599 OUString m_sAltText; 1600 OUString m_sPrimaryKey; 1601 OUString m_sSecondaryKey; 1602 OUString m_sTextReading; 1603 OUString m_sPrimaryKeyReading; 1604 OUString m_sSecondaryKeyReading; 1605 OUString m_sUserIndexName; 1606 1607 Impl( SwXDocumentIndexMark & rThis, 1608 SwDoc *const pDoc, 1609 const enum TOXTypes eType, 1610 SwTOXType *const pType, SwTOXMark const*const pMark) 1611 : SwClient(const_cast<SwTOXMark*>(pMark)) 1612 , m_bInReplaceMark(false) 1613 , m_rPropSet( 1614 *aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType))) 1615 , m_eTOXType(eType) 1616 , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) 1617 // #i112513#: unxsols4 (Sun C++ 5.9 SunOS_sparc) generates wrong code for this 1618 // , m_bIsDescriptor(0 == pMark) 1619 , m_bIsDescriptor((0 == pMark) ? true : false) 1620 , m_TypeDepend(this, pType) 1621 , m_pTOXMark(pMark) 1622 , m_pDoc(pDoc) 1623 , m_bMainEntry(sal_False) 1624 , m_nLevel(0) 1625 { 1626 } 1627 1628 SwTOXType * GetTOXType() const { 1629 return static_cast<SwTOXType*>( 1630 const_cast<SwModify *>(m_TypeDepend.GetRegisteredIn())); 1631 } 1632 1633 void DeleteTOXMark() 1634 { 1635 m_pDoc->DeleteTOXMark(m_pTOXMark); // calls Invalidate() via Modify! 1636 m_pTOXMark = 0; 1637 } 1638 1639 void InsertTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam, 1640 SwXTextCursor const*const pTextCursor); 1641 1642 void ReplaceTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam) 1643 { 1644 m_bInReplaceMark = true; 1645 DeleteTOXMark(); 1646 m_bInReplaceMark = false; 1647 try { 1648 InsertTOXMark(rTOXType, rMark, rPam, 0); 1649 } catch (...) { 1650 OSL_ENSURE(false, "ReplaceTOXMark() failed!"); 1651 m_ListenerContainer.Disposing(); 1652 throw; 1653 } 1654 } 1655 1656 void Invalidate(); 1657 protected: 1658 // SwClient 1659 virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew); 1660 }; 1661 1662 /* -----------------------------16.10.00 11:24-------------------------------- 1663 1664 ---------------------------------------------------------------------------*/ 1665 void SwXDocumentIndexMark::Impl::Invalidate() 1666 { 1667 if (GetRegisteredIn()) 1668 { 1669 const_cast<SwModify*>(GetRegisteredIn())->Remove(this); 1670 if (m_TypeDepend.GetRegisteredIn()) 1671 { 1672 const_cast<SwModify*>(m_TypeDepend.GetRegisteredIn())->Remove( 1673 &m_TypeDepend); 1674 } 1675 } 1676 if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace! 1677 { 1678 m_ListenerContainer.Disposing(); 1679 } 1680 m_pDoc = 0; 1681 m_pTOXMark = 0; 1682 } 1683 1684 /*-- 14.12.98 10:25:47--------------------------------------------------- 1685 1686 -----------------------------------------------------------------------*/ 1687 void SwXDocumentIndexMark::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) 1688 { 1689 ClientModify(this, pOld, pNew); 1690 1691 if (!GetRegisteredIn()) // removed => dispose 1692 { 1693 Invalidate(); 1694 } 1695 } 1696 1697 /*-- 14.12.98 10:25:43--------------------------------------------------- 1698 1699 -----------------------------------------------------------------------*/ 1700 SwXDocumentIndexMark::SwXDocumentIndexMark(const TOXTypes eToxType) 1701 : m_pImpl( new SwXDocumentIndexMark::Impl(*this, 0, eToxType, 0, 0) ) 1702 { 1703 } 1704 /*-- 14.12.98 10:25:44--------------------------------------------------- 1705 1706 -----------------------------------------------------------------------*/ 1707 SwXDocumentIndexMark::SwXDocumentIndexMark(SwDoc & rDoc, 1708 SwTOXType & rType, SwTOXMark & rMark) 1709 : m_pImpl( new SwXDocumentIndexMark::Impl(*this, &rDoc, rType.GetType(), 1710 &rType, &rMark) ) 1711 { 1712 } 1713 /*-- 14.12.98 10:25:44--------------------------------------------------- 1714 1715 -----------------------------------------------------------------------*/ 1716 SwXDocumentIndexMark::~SwXDocumentIndexMark() 1717 { 1718 } 1719 1720 uno::Reference<text::XDocumentIndexMark> 1721 SwXDocumentIndexMark::CreateXDocumentIndexMark( 1722 SwDoc & rDoc, SwTOXType & rType, SwTOXMark & rMark) 1723 { 1724 // re-use existing SwXDocumentIndexMark 1725 // NB: xmloff depends on this caching to generate ID from the address! 1726 // #i105557#: do not iterate over the registered clients: race condition 1727 uno::Reference< text::XDocumentIndexMark > xTOXMark(rMark.GetXTOXMark()); 1728 if (!xTOXMark.is()) 1729 { 1730 SwXDocumentIndexMark *const pNew = 1731 new SwXDocumentIndexMark(rDoc, rType, rMark); 1732 xTOXMark.set(pNew); 1733 rMark.SetXTOXMark(xTOXMark); 1734 } 1735 return xTOXMark; 1736 } 1737 1738 /* -----------------------------10.03.00 18:02-------------------------------- 1739 1740 ---------------------------------------------------------------------------*/ 1741 const uno::Sequence< sal_Int8 > & SwXDocumentIndexMark::getUnoTunnelId() 1742 { 1743 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 1744 return aSeq; 1745 } 1746 /* -----------------------------10.03.00 18:04-------------------------------- 1747 1748 ---------------------------------------------------------------------------*/ 1749 sal_Int64 SAL_CALL 1750 SwXDocumentIndexMark::getSomething(const uno::Sequence< sal_Int8 >& rId) 1751 throw (uno::RuntimeException) 1752 { 1753 return ::sw::UnoTunnelImpl<SwXDocumentIndexMark>(rId, this); 1754 } 1755 1756 static const sal_Char cBaseMark[] = "com.sun.star.text.BaseIndexMark"; 1757 static const sal_Char cContentMark[] = "com.sun.star.text.ContentIndexMark"; 1758 static const sal_Char cIdxMark[] = "com.sun.star.text.DocumentIndexMark"; 1759 static const sal_Char cIdxMarkAsian[] = "com.sun.star.text.DocumentIndexMarkAsian"; 1760 static const sal_Char cUserMark[] = "com.sun.star.text.UserIndexMark"; 1761 static const sal_Char cTextContent[] = "com.sun.star.text.TextContent"; 1762 1763 /* -----------------------------06.04.00 15:07-------------------------------- 1764 1765 ---------------------------------------------------------------------------*/ 1766 OUString SAL_CALL 1767 SwXDocumentIndexMark::getImplementationName() throw (uno::RuntimeException) 1768 { 1769 return C2U("SwXDocumentIndexMark"); 1770 } 1771 /* -----------------------------06.04.00 15:07-------------------------------- 1772 1773 ---------------------------------------------------------------------------*/ 1774 sal_Bool SAL_CALL 1775 SwXDocumentIndexMark::supportsService(const OUString& rServiceName) 1776 throw (uno::RuntimeException) 1777 { 1778 vos::OGuard g(Application::GetSolarMutex()); 1779 1780 return rServiceName.equalsAscii(cBaseMark) 1781 || rServiceName.equalsAscii(cTextContent) 1782 || ((m_pImpl->m_eTOXType == TOX_USER) 1783 && rServiceName.equalsAscii(cUserMark)) 1784 || ((m_pImpl->m_eTOXType == TOX_CONTENT) 1785 && rServiceName.equalsAscii(cContentMark)) 1786 || ((m_pImpl->m_eTOXType == TOX_INDEX) 1787 && rServiceName.equalsAscii(cIdxMark)) 1788 || ((m_pImpl->m_eTOXType == TOX_INDEX) 1789 && rServiceName.equalsAscii(cIdxMarkAsian)); 1790 } 1791 /* -----------------------------06.04.00 15:07-------------------------------- 1792 1793 ---------------------------------------------------------------------------*/ 1794 uno::Sequence< OUString > SAL_CALL 1795 SwXDocumentIndexMark::getSupportedServiceNames() throw (uno::RuntimeException) 1796 { 1797 vos::OGuard g(Application::GetSolarMutex()); 1798 1799 const sal_Int32 nCnt = (m_pImpl->m_eTOXType == TOX_INDEX) ? 4 : 3; 1800 uno::Sequence< OUString > aRet(nCnt); 1801 OUString* pArray = aRet.getArray(); 1802 pArray[0] = C2U(cBaseMark); 1803 pArray[1] = C2U(cTextContent); 1804 switch (m_pImpl->m_eTOXType) 1805 { 1806 case TOX_USER: 1807 pArray[2] = C2U(cUserMark); 1808 break; 1809 case TOX_CONTENT: 1810 pArray[2] = C2U(cContentMark); 1811 break; 1812 case TOX_INDEX: 1813 pArray[2] = C2U(cIdxMark); 1814 pArray[3] = C2U(cIdxMarkAsian); 1815 break; 1816 1817 default: 1818 ; 1819 } 1820 return aRet; 1821 } 1822 1823 /*-- 14.12.98 10:25:45--------------------------------------------------- 1824 1825 -----------------------------------------------------------------------*/ 1826 OUString SAL_CALL 1827 SwXDocumentIndexMark::getMarkEntry() throw (uno::RuntimeException) 1828 { 1829 vos::OGuard aGuard(Application::GetSolarMutex()); 1830 1831 OUString sRet; 1832 SwTOXType *const pType = m_pImpl->GetTOXType(); 1833 if (pType && m_pImpl->m_pTOXMark) 1834 { 1835 sRet = OUString(m_pImpl->m_pTOXMark->GetAlternativeText()); 1836 } 1837 else if (m_pImpl->m_bIsDescriptor) 1838 { 1839 sRet = m_pImpl->m_sAltText; 1840 } 1841 else 1842 { 1843 throw uno::RuntimeException(); 1844 } 1845 return sRet; 1846 } 1847 /*-- 14.12.98 10:25:45--------------------------------------------------- 1848 1849 -----------------------------------------------------------------------*/ 1850 void SAL_CALL 1851 SwXDocumentIndexMark::setMarkEntry(const OUString& rIndexEntry) 1852 throw (uno::RuntimeException) 1853 { 1854 vos::OGuard aGuard(Application::GetSolarMutex()); 1855 1856 SwTOXType *const pType = m_pImpl->GetTOXType(); 1857 if (pType && m_pImpl->m_pTOXMark) 1858 { 1859 SwTOXMark aMark(*m_pImpl->m_pTOXMark); 1860 aMark.SetAlternativeText(rIndexEntry); 1861 SwTxtTOXMark const*const pTxtMark = 1862 m_pImpl->m_pTOXMark->GetTxtTOXMark(); 1863 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart()); 1864 aPam.SetMark(); 1865 if(pTxtMark->GetEnd()) 1866 { 1867 aPam.GetPoint()->nContent = *pTxtMark->GetEnd(); 1868 } 1869 else 1870 aPam.GetPoint()->nContent++; 1871 1872 m_pImpl->ReplaceTOXMark(*pType, aMark, aPam); 1873 } 1874 else if (m_pImpl->m_bIsDescriptor) 1875 { 1876 m_pImpl->m_sAltText = rIndexEntry; 1877 } 1878 else 1879 { 1880 throw uno::RuntimeException(); 1881 } 1882 } 1883 1884 /* -----------------18.02.99 13:40------------------- 1885 * 1886 * --------------------------------------------------*/ 1887 void SAL_CALL 1888 SwXDocumentIndexMark::attach( 1889 const uno::Reference< text::XTextRange > & xTextRange) 1890 throw (lang::IllegalArgumentException, uno::RuntimeException) 1891 { 1892 vos::OGuard aGuard(Application::GetSolarMutex()); 1893 1894 if (!m_pImpl->m_bIsDescriptor) 1895 { 1896 throw uno::RuntimeException(); 1897 } 1898 1899 const uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY); 1900 SwXTextRange *const pRange = 1901 ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel); 1902 OTextCursorHelper *const pCursor = 1903 ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel); 1904 SwDoc *const pDoc = 1905 (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0); 1906 if (!pDoc) 1907 { 1908 throw lang::IllegalArgumentException(); 1909 } 1910 1911 const SwTOXType* pTOXType = 0; 1912 switch (m_pImpl->m_eTOXType) 1913 { 1914 case TOX_INDEX: 1915 case TOX_CONTENT: 1916 pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 ); 1917 break; 1918 case TOX_USER: 1919 { 1920 if (!m_pImpl->m_sUserIndexName.getLength()) 1921 { 1922 pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 ); 1923 } 1924 else 1925 { 1926 const sal_uInt16 nCount = 1927 pDoc->GetTOXTypeCount(m_pImpl->m_eTOXType); 1928 for (sal_uInt16 i = 0; i < nCount; i++) 1929 { 1930 SwTOXType const*const pTemp = 1931 pDoc->GetTOXType( m_pImpl->m_eTOXType, i ); 1932 if (m_pImpl->m_sUserIndexName == 1933 OUString(pTemp->GetTypeName())) 1934 { 1935 pTOXType = pTemp; 1936 break; 1937 } 1938 } 1939 if (!pTOXType) 1940 { 1941 SwTOXType aUserType(TOX_USER, m_pImpl->m_sUserIndexName); 1942 pTOXType = pDoc->InsertTOXType(aUserType); 1943 } 1944 } 1945 } 1946 break; 1947 1948 default: 1949 break; 1950 } 1951 if (!pTOXType) 1952 { 1953 throw lang::IllegalArgumentException(); 1954 } 1955 1956 SwUnoInternalPaM aPam(*pDoc); 1957 //das muss jetzt sal_True liefern 1958 ::sw::XTextRangeToSwPaM(aPam, xTextRange); 1959 SwTOXMark aMark (pTOXType); 1960 if (m_pImpl->m_sAltText.getLength()) 1961 { 1962 aMark.SetAlternativeText(m_pImpl->m_sAltText); 1963 } 1964 switch (m_pImpl->m_eTOXType) 1965 { 1966 case TOX_INDEX: 1967 if (m_pImpl->m_sPrimaryKey.getLength()) 1968 { 1969 aMark.SetPrimaryKey(m_pImpl->m_sPrimaryKey); 1970 } 1971 if (m_pImpl->m_sSecondaryKey.getLength()) 1972 { 1973 aMark.SetSecondaryKey(m_pImpl->m_sSecondaryKey); 1974 } 1975 if (m_pImpl->m_sTextReading.getLength()) 1976 { 1977 aMark.SetTextReading(m_pImpl->m_sTextReading); 1978 } 1979 if (m_pImpl->m_sPrimaryKeyReading.getLength()) 1980 { 1981 aMark.SetPrimaryKeyReading(m_pImpl->m_sPrimaryKeyReading); 1982 } 1983 if (m_pImpl->m_sSecondaryKeyReading.getLength()) 1984 { 1985 aMark.SetSecondaryKeyReading(m_pImpl->m_sSecondaryKeyReading); 1986 } 1987 aMark.SetMainEntry(m_pImpl->m_bMainEntry); 1988 break; 1989 case TOX_USER: 1990 case TOX_CONTENT: 1991 if (USHRT_MAX != m_pImpl->m_nLevel) 1992 { 1993 aMark.SetLevel(m_pImpl->m_nLevel+1); 1994 } 1995 break; 1996 1997 default: 1998 break; 1999 } 2000 2001 m_pImpl->InsertTOXMark(*const_cast<SwTOXType *>(pTOXType), aMark, aPam, 2002 dynamic_cast<SwXTextCursor const*>(pCursor)); 2003 2004 m_pImpl->m_bIsDescriptor = sal_False; 2005 } 2006 2007 template<typename T> struct NotContainedIn 2008 { 2009 ::std::vector<T> const& m_rVector; 2010 explicit NotContainedIn(::std::vector<T> const& rVector) 2011 : m_rVector(rVector) { } 2012 bool operator() (T const& rT) { 2013 return ::std::find(m_rVector.begin(), m_rVector.end(), rT) 2014 == m_rVector.end(); 2015 } 2016 }; 2017 2018 void SwXDocumentIndexMark::Impl::InsertTOXMark( 2019 SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam, 2020 SwXTextCursor const*const pTextCursor) 2021 { 2022 SwDoc *const pDoc( rPam.GetDoc() ); 2023 UnoActionContext aAction(pDoc); 2024 bool bMark = *rPam.GetPoint() != *rPam.GetMark(); 2025 // n.b.: toxmarks must have either alternative text or an extent 2026 if (bMark && rMark.GetAlternativeText().Len()) 2027 { 2028 rPam.Normalize(sal_True); 2029 rPam.DeleteMark(); 2030 bMark = false; 2031 } 2032 // Marks ohne Alternativtext ohne selektierten Text koennen nicht eingefuegt werden, 2033 // deshalb hier ein Leerzeichen - ob das die ideale Loesung ist? 2034 if (!bMark && !rMark.GetAlternativeText().Len()) 2035 { 2036 rMark.SetAlternativeText( String(' ') ); 2037 } 2038 2039 const bool bForceExpandHints( (!bMark && pTextCursor) 2040 ? pTextCursor->IsAtEndOfMeta() : false ); 2041 const SetAttrMode nInsertFlags = (bForceExpandHints) 2042 ? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND 2043 | nsSetAttrMode::SETATTR_DONTEXPAND) 2044 : nsSetAttrMode::SETATTR_DONTEXPAND; 2045 2046 ::std::vector<SwTxtAttr *> oldMarks; 2047 if (bMark) 2048 { 2049 oldMarks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt( 2050 rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK); 2051 } 2052 2053 pDoc->InsertPoolItem(rPam, rMark, nInsertFlags); 2054 if (bMark && *rPam.GetPoint() > *rPam.GetMark()) 2055 { 2056 rPam.Exchange(); 2057 } 2058 2059 // rMark was copied into the document pool; now retrieve real format... 2060 SwTxtAttr * pTxtAttr(0); 2061 if (bMark) 2062 { 2063 // #i107672# 2064 // ensure that we do not retrieve a different mark at the same position 2065 ::std::vector<SwTxtAttr *> const newMarks( 2066 rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt( 2067 rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK)); 2068 ::std::vector<SwTxtAttr *>::const_iterator const iter( 2069 ::std::find_if(newMarks.begin(), newMarks.end(), 2070 NotContainedIn<SwTxtAttr *>(oldMarks))); 2071 OSL_ASSERT(newMarks.end() != iter); 2072 if (newMarks.end() != iter) 2073 { 2074 pTxtAttr = *iter; 2075 } 2076 } 2077 else 2078 { 2079 pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt( 2080 rPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_TOXMARK ); 2081 } 2082 2083 if (!pTxtAttr) 2084 { 2085 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 2086 "SwXDocumentIndexMark::InsertTOXMark(): cannot insert attribute")), 2087 0); 2088 } 2089 2090 m_pDoc = pDoc; 2091 m_pTOXMark = & pTxtAttr->GetTOXMark(); 2092 const_cast<SwTOXMark*>(m_pTOXMark)->Add(this); 2093 const_cast<SwTOXType &>(rTOXType).Add(& m_TypeDepend); 2094 } 2095 2096 /*-- 14.12.98 10:25:45--------------------------------------------------- 2097 2098 -----------------------------------------------------------------------*/ 2099 uno::Reference< text::XTextRange > SAL_CALL 2100 SwXDocumentIndexMark::getAnchor() throw (uno::RuntimeException) 2101 { 2102 vos::OGuard aGuard(Application::GetSolarMutex()); 2103 2104 SwTOXType *const pType = m_pImpl->GetTOXType(); 2105 if (!pType || !m_pImpl->m_pTOXMark) 2106 { 2107 throw uno::RuntimeException(); 2108 } 2109 if (!m_pImpl->m_pTOXMark->GetTxtTOXMark()) 2110 { 2111 throw uno::RuntimeException(); 2112 } 2113 const SwTxtTOXMark* pTxtMark = m_pImpl->m_pTOXMark->GetTxtTOXMark(); 2114 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart()); 2115 aPam.SetMark(); 2116 if(pTxtMark->GetEnd()) 2117 { 2118 aPam.GetPoint()->nContent = *pTxtMark->GetEnd(); 2119 } 2120 else 2121 { 2122 aPam.GetPoint()->nContent++; 2123 } 2124 const uno::Reference< frame::XModel > xModel = 2125 m_pImpl->m_pDoc->GetDocShell()->GetBaseModel(); 2126 const uno::Reference< text::XTextDocument > xTDoc(xModel, uno::UNO_QUERY); 2127 const uno::Reference< text::XTextRange > xRet = 2128 new SwXTextRange(aPam, xTDoc->getText()); 2129 2130 return xRet; 2131 } 2132 2133 /*-- 14.12.98 10:25:45--------------------------------------------------- 2134 2135 -----------------------------------------------------------------------*/ 2136 void SAL_CALL 2137 SwXDocumentIndexMark::dispose() throw (uno::RuntimeException) 2138 { 2139 vos::OGuard aGuard(Application::GetSolarMutex()); 2140 2141 SwTOXType *const pType = m_pImpl->GetTOXType(); 2142 if (pType && m_pImpl->m_pTOXMark) 2143 { 2144 m_pImpl->DeleteTOXMark(); // call Invalidate() via modify! 2145 } 2146 } 2147 /*-- 14.12.98 10:25:45--------------------------------------------------- 2148 2149 -----------------------------------------------------------------------*/ 2150 void SAL_CALL 2151 SwXDocumentIndexMark::addEventListener( 2152 const uno::Reference< lang::XEventListener > & xListener) 2153 throw (uno::RuntimeException) 2154 { 2155 vos::OGuard g(Application::GetSolarMutex()); 2156 2157 if (!m_pImpl->GetRegisteredIn()) 2158 { 2159 throw uno::RuntimeException(); 2160 } 2161 m_pImpl->m_ListenerContainer.AddListener(xListener); 2162 } 2163 /*-- 14.12.98 10:25:46--------------------------------------------------- 2164 2165 -----------------------------------------------------------------------*/ 2166 void SAL_CALL 2167 SwXDocumentIndexMark::removeEventListener( 2168 const uno::Reference< lang::XEventListener > & xListener) 2169 throw (uno::RuntimeException) 2170 { 2171 vos::OGuard g(Application::GetSolarMutex()); 2172 2173 if (!m_pImpl->GetRegisteredIn() || 2174 !m_pImpl->m_ListenerContainer.RemoveListener(xListener)) 2175 { 2176 throw uno::RuntimeException(); 2177 } 2178 } 2179 2180 /*-- 14.12.98 10:25:46--------------------------------------------------- 2181 2182 -----------------------------------------------------------------------*/ 2183 uno::Reference< beans::XPropertySetInfo > SAL_CALL 2184 SwXDocumentIndexMark::getPropertySetInfo() throw (uno::RuntimeException) 2185 { 2186 vos::OGuard g(Application::GetSolarMutex()); 2187 2188 static uno::Reference< beans::XPropertySetInfo > xInfos[3]; 2189 int nPos = 0; 2190 switch (m_pImpl->m_eTOXType) 2191 { 2192 case TOX_INDEX: nPos = 0; break; 2193 case TOX_CONTENT: nPos = 1; break; 2194 case TOX_USER: nPos = 2; break; 2195 default: 2196 ; 2197 } 2198 if(!xInfos[nPos].is()) 2199 { 2200 const uno::Reference< beans::XPropertySetInfo > xInfo = 2201 m_pImpl->m_rPropSet.getPropertySetInfo(); 2202 // extend PropertySetInfo! 2203 const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties(); 2204 xInfos[nPos] = new SfxExtItemPropertySetInfo( 2205 aSwMapProvider.GetPropertyMapEntries( 2206 PROPERTY_MAP_PARAGRAPH_EXTENSIONS), 2207 aPropSeq ); 2208 } 2209 return xInfos[nPos]; 2210 } 2211 2212 /*-- 14.12.98 10:25:46--------------------------------------------------- 2213 2214 -----------------------------------------------------------------------*/ 2215 void SAL_CALL 2216 SwXDocumentIndexMark::setPropertyValue( 2217 const OUString& rPropertyName, const uno::Any& rValue) 2218 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 2219 lang::IllegalArgumentException, lang::WrappedTargetException, 2220 uno::RuntimeException) 2221 { 2222 vos::OGuard aGuard(Application::GetSolarMutex()); 2223 2224 SfxItemPropertySimpleEntry const*const pEntry = 2225 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 2226 if (!pEntry) 2227 { 2228 throw beans::UnknownPropertyException( 2229 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2230 + rPropertyName, 2231 static_cast<cppu::OWeakObject *>(this)); 2232 } 2233 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 2234 { 2235 throw beans::PropertyVetoException( 2236 OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) 2237 + rPropertyName, 2238 static_cast<cppu::OWeakObject *>(this)); 2239 } 2240 2241 SwTOXType *const pType = m_pImpl->GetTOXType(); 2242 if (pType && m_pImpl->m_pTOXMark) 2243 { 2244 SwTOXMark aMark(*m_pImpl->m_pTOXMark); 2245 switch(pEntry->nWID) 2246 { 2247 case WID_ALT_TEXT: 2248 aMark.SetAlternativeText(lcl_AnyToString(rValue)); 2249 break; 2250 case WID_LEVEL: 2251 aMark.SetLevel(Min( static_cast<sal_Int8>( MAXLEVEL ), 2252 static_cast<sal_Int8>(lcl_AnyToInt16(rValue)+1))); 2253 break; 2254 case WID_PRIMARY_KEY : 2255 aMark.SetPrimaryKey(lcl_AnyToString(rValue)); 2256 break; 2257 case WID_SECONDARY_KEY: 2258 aMark.SetSecondaryKey(lcl_AnyToString(rValue)); 2259 break; 2260 case WID_MAIN_ENTRY: 2261 aMark.SetMainEntry(lcl_AnyToBool(rValue)); 2262 break; 2263 case WID_TEXT_READING: 2264 aMark.SetTextReading(lcl_AnyToString(rValue)); 2265 break; 2266 case WID_PRIMARY_KEY_READING: 2267 aMark.SetPrimaryKeyReading(lcl_AnyToString(rValue)); 2268 break; 2269 case WID_SECONDARY_KEY_READING: 2270 aMark.SetSecondaryKeyReading(lcl_AnyToString(rValue)); 2271 break; 2272 } 2273 SwTxtTOXMark const*const pTxtMark = 2274 m_pImpl->m_pTOXMark->GetTxtTOXMark(); 2275 SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart()); 2276 aPam.SetMark(); 2277 if(pTxtMark->GetEnd()) 2278 { 2279 aPam.GetPoint()->nContent = *pTxtMark->GetEnd(); 2280 } 2281 else 2282 { 2283 aPam.GetPoint()->nContent++; 2284 } 2285 2286 m_pImpl->ReplaceTOXMark(*pType, aMark, aPam); 2287 } 2288 else if (m_pImpl->m_bIsDescriptor) 2289 { 2290 switch(pEntry->nWID) 2291 { 2292 case WID_ALT_TEXT: 2293 m_pImpl->m_sAltText = lcl_AnyToString(rValue); 2294 break; 2295 case WID_LEVEL: 2296 { 2297 const sal_Int16 nVal = lcl_AnyToInt16(rValue); 2298 if(nVal >= 0 && nVal < MAXLEVEL) 2299 { 2300 m_pImpl->m_nLevel = nVal; 2301 } 2302 else 2303 { 2304 throw lang::IllegalArgumentException(); 2305 } 2306 } 2307 break; 2308 case WID_PRIMARY_KEY: 2309 m_pImpl->m_sPrimaryKey = lcl_AnyToString(rValue); 2310 break; 2311 case WID_SECONDARY_KEY: 2312 m_pImpl->m_sSecondaryKey = lcl_AnyToString(rValue); 2313 break; 2314 case WID_TEXT_READING: 2315 m_pImpl->m_sTextReading = lcl_AnyToString(rValue); 2316 break; 2317 case WID_PRIMARY_KEY_READING: 2318 m_pImpl->m_sPrimaryKeyReading = lcl_AnyToString(rValue); 2319 break; 2320 case WID_SECONDARY_KEY_READING: 2321 m_pImpl->m_sSecondaryKeyReading = lcl_AnyToString(rValue); 2322 break; 2323 case WID_USER_IDX_NAME: 2324 { 2325 OUString sTmp(lcl_AnyToString(rValue)); 2326 lcl_ConvertTOUNameToUserName(sTmp); 2327 m_pImpl->m_sUserIndexName = sTmp; 2328 } 2329 break; 2330 case WID_MAIN_ENTRY: 2331 m_pImpl->m_bMainEntry = lcl_AnyToBool(rValue); 2332 break; 2333 } 2334 } 2335 else 2336 { 2337 throw uno::RuntimeException(); 2338 } 2339 } 2340 2341 /*-- 14.12.98 10:25:46--------------------------------------------------- 2342 2343 -----------------------------------------------------------------------*/ 2344 uno::Any SAL_CALL 2345 SwXDocumentIndexMark::getPropertyValue(const OUString& rPropertyName) 2346 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2347 uno::RuntimeException) 2348 { 2349 vos::OGuard aGuard(Application::GetSolarMutex()); 2350 2351 uno::Any aRet; 2352 SfxItemPropertySimpleEntry const*const pEntry = 2353 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 2354 if (!pEntry) 2355 { 2356 throw beans::UnknownPropertyException( 2357 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 2358 + rPropertyName, 2359 static_cast<cppu::OWeakObject *>(this)); 2360 } 2361 if (::sw::GetDefaultTextContentValue(aRet, rPropertyName, pEntry->nWID)) 2362 { 2363 return aRet; 2364 } 2365 2366 SwTOXType *const pType = m_pImpl->GetTOXType(); 2367 if (pType && m_pImpl->m_pTOXMark) 2368 { 2369 switch(pEntry->nWID) 2370 { 2371 case WID_ALT_TEXT: 2372 aRet <<= OUString(m_pImpl->m_pTOXMark->GetAlternativeText()); 2373 break; 2374 case WID_LEVEL: 2375 aRet <<= static_cast<sal_Int16>( 2376 m_pImpl->m_pTOXMark->GetLevel() - 1); 2377 break; 2378 case WID_PRIMARY_KEY : 2379 aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKey()); 2380 break; 2381 case WID_SECONDARY_KEY: 2382 aRet <<= OUString(m_pImpl->m_pTOXMark->GetSecondaryKey()); 2383 break; 2384 case WID_TEXT_READING: 2385 aRet <<= OUString(m_pImpl->m_pTOXMark->GetTextReading()); 2386 break; 2387 case WID_PRIMARY_KEY_READING: 2388 aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKeyReading()); 2389 break; 2390 case WID_SECONDARY_KEY_READING: 2391 aRet <<= OUString( 2392 m_pImpl->m_pTOXMark->GetSecondaryKeyReading()); 2393 break; 2394 case WID_USER_IDX_NAME : 2395 { 2396 OUString sTmp(pType->GetTypeName()); 2397 lcl_ConvertTOUNameToProgrammaticName(sTmp); 2398 aRet <<= sTmp; 2399 } 2400 break; 2401 case WID_MAIN_ENTRY: 2402 { 2403 const sal_Bool bTemp = m_pImpl->m_pTOXMark->IsMainEntry(); 2404 aRet <<= bTemp; 2405 } 2406 break; 2407 } 2408 } 2409 else if (m_pImpl->m_bIsDescriptor) 2410 { 2411 switch(pEntry->nWID) 2412 { 2413 case WID_ALT_TEXT: 2414 aRet <<= m_pImpl->m_sAltText; 2415 break; 2416 case WID_LEVEL: 2417 aRet <<= static_cast<sal_Int16>(m_pImpl->m_nLevel); 2418 break; 2419 case WID_PRIMARY_KEY: 2420 aRet <<= m_pImpl->m_sPrimaryKey; 2421 break; 2422 case WID_SECONDARY_KEY: 2423 aRet <<= m_pImpl->m_sSecondaryKey; 2424 break; 2425 case WID_TEXT_READING: 2426 aRet <<= m_pImpl->m_sTextReading; 2427 break; 2428 case WID_PRIMARY_KEY_READING: 2429 aRet <<= m_pImpl->m_sPrimaryKeyReading; 2430 break; 2431 case WID_SECONDARY_KEY_READING: 2432 aRet <<= m_pImpl->m_sSecondaryKeyReading; 2433 break; 2434 case WID_USER_IDX_NAME : 2435 aRet <<= m_pImpl->m_sUserIndexName; 2436 break; 2437 case WID_MAIN_ENTRY: 2438 { 2439 aRet <<= static_cast<sal_Bool>(m_pImpl->m_bMainEntry); 2440 } 2441 break; 2442 } 2443 } 2444 else 2445 { 2446 throw uno::RuntimeException(); 2447 } 2448 return aRet; 2449 } 2450 2451 /*-- 14.12.98 10:25:46--------------------------------------------------- 2452 2453 -----------------------------------------------------------------------*/ 2454 void SAL_CALL 2455 SwXDocumentIndexMark::addPropertyChangeListener( 2456 const ::rtl::OUString& /*rPropertyName*/, 2457 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 2458 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2459 uno::RuntimeException) 2460 { 2461 OSL_ENSURE(false, 2462 "SwXDocumentIndexMark::addPropertyChangeListener(): not implemented"); 2463 } 2464 2465 void SAL_CALL 2466 SwXDocumentIndexMark::removePropertyChangeListener( 2467 const ::rtl::OUString& /*rPropertyName*/, 2468 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 2469 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2470 uno::RuntimeException) 2471 { 2472 OSL_ENSURE(false, 2473 "SwXDocumentIndexMark::removePropertyChangeListener(): not implemented"); 2474 } 2475 2476 void SAL_CALL 2477 SwXDocumentIndexMark::addVetoableChangeListener( 2478 const ::rtl::OUString& /*rPropertyName*/, 2479 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 2480 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2481 uno::RuntimeException) 2482 { 2483 OSL_ENSURE(false, 2484 "SwXDocumentIndexMark::addVetoableChangeListener(): not implemented"); 2485 } 2486 2487 void SAL_CALL 2488 SwXDocumentIndexMark::removeVetoableChangeListener( 2489 const ::rtl::OUString& /*rPropertyName*/, 2490 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 2491 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 2492 uno::RuntimeException) 2493 { 2494 OSL_ENSURE(false, 2495 "SwXDocumentIndexMark::removeVetoableChangeListener(): not implemented"); 2496 } 2497 2498 2499 /****************************************************************** 2500 * SwXDocumentIndexes 2501 ******************************************************************/ 2502 /*-- 05.05.99 13:14:59--------------------------------------------------- 2503 2504 -----------------------------------------------------------------------*/ 2505 SwXDocumentIndexes::SwXDocumentIndexes(SwDoc *const _pDoc) 2506 : SwUnoCollection(_pDoc) 2507 { 2508 } 2509 /*-- 05.05.99 13:15:00--------------------------------------------------- 2510 2511 -----------------------------------------------------------------------*/ 2512 SwXDocumentIndexes::~SwXDocumentIndexes() 2513 { 2514 } 2515 2516 /* -----------------------------06.04.00 15:08-------------------------------- 2517 2518 ---------------------------------------------------------------------------*/ 2519 OUString SAL_CALL 2520 SwXDocumentIndexes::getImplementationName() throw (uno::RuntimeException) 2521 { 2522 return C2U("SwXDocumentIndexes"); 2523 } 2524 2525 static char const*const g_ServicesDocumentIndexes[] = 2526 { 2527 "com.sun.star.text.DocumentIndexes", 2528 }; 2529 static const size_t g_nServicesDocumentIndexes( 2530 sizeof(g_ServicesDocumentIndexes)/sizeof(g_ServicesDocumentIndexes[0])); 2531 2532 sal_Bool SAL_CALL 2533 SwXDocumentIndexes::supportsService(const OUString& rServiceName) 2534 throw (uno::RuntimeException) 2535 { 2536 return ::sw::SupportsServiceImpl( 2537 g_nServicesDocumentIndexes, g_ServicesDocumentIndexes, rServiceName); 2538 } 2539 2540 uno::Sequence< OUString > SAL_CALL 2541 SwXDocumentIndexes::getSupportedServiceNames() throw (uno::RuntimeException) 2542 { 2543 return ::sw::GetSupportedServiceNamesImpl( 2544 g_nServicesDocumentIndexes, g_ServicesDocumentIndexes); 2545 } 2546 2547 /*-- 05.05.99 13:15:01--------------------------------------------------- 2548 2549 -----------------------------------------------------------------------*/ 2550 sal_Int32 SAL_CALL 2551 SwXDocumentIndexes::getCount() throw (uno::RuntimeException) 2552 { 2553 vos::OGuard aGuard(Application::GetSolarMutex()); 2554 2555 if(!IsValid()) 2556 throw uno::RuntimeException(); 2557 2558 sal_uInt32 nRet = 0; 2559 const SwSectionFmts& rFmts = GetDoc()->GetSections(); 2560 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n ) 2561 { 2562 const SwSection* pSect = rFmts[ n ]->GetSection(); 2563 if( TOX_CONTENT_SECTION == pSect->GetType() && 2564 pSect->GetFmt()->GetSectionNode() ) 2565 { 2566 ++nRet; 2567 } 2568 } 2569 return nRet; 2570 } 2571 2572 /*-- 05.05.99 13:15:01--------------------------------------------------- 2573 2574 -----------------------------------------------------------------------*/ 2575 uno::Any SAL_CALL 2576 SwXDocumentIndexes::getByIndex(sal_Int32 nIndex) 2577 throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, 2578 uno::RuntimeException) 2579 { 2580 vos::OGuard aGuard(Application::GetSolarMutex()); 2581 2582 if(!IsValid()) 2583 throw uno::RuntimeException(); 2584 2585 sal_Int32 nIdx = 0; 2586 2587 const SwSectionFmts& rFmts = GetDoc()->GetSections(); 2588 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n ) 2589 { 2590 const SwSection* pSect = rFmts[ n ]->GetSection(); 2591 if( TOX_CONTENT_SECTION == pSect->GetType() && 2592 pSect->GetFmt()->GetSectionNode() && 2593 nIdx++ == nIndex ) 2594 { 2595 const uno::Reference< text::XDocumentIndex > xTmp = 2596 SwXDocumentIndex::CreateXDocumentIndex( 2597 *GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect)); 2598 uno::Any aRet; 2599 aRet <<= xTmp; 2600 return aRet; 2601 } 2602 } 2603 2604 throw lang::IndexOutOfBoundsException(); 2605 } 2606 2607 /*-- 31.01.00 10:12:31--------------------------------------------------- 2608 2609 -----------------------------------------------------------------------*/ 2610 uno::Any SAL_CALL 2611 SwXDocumentIndexes::getByName(const OUString& rName) 2612 throw (container::NoSuchElementException, lang::WrappedTargetException, 2613 uno::RuntimeException) 2614 { 2615 vos::OGuard aGuard(Application::GetSolarMutex()); 2616 2617 if(!IsValid()) 2618 throw uno::RuntimeException(); 2619 2620 String sToFind(rName); 2621 const SwSectionFmts& rFmts = GetDoc()->GetSections(); 2622 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n ) 2623 { 2624 const SwSection* pSect = rFmts[ n ]->GetSection(); 2625 if( TOX_CONTENT_SECTION == pSect->GetType() && 2626 pSect->GetFmt()->GetSectionNode() && 2627 (static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName() 2628 == sToFind)) 2629 { 2630 const uno::Reference< text::XDocumentIndex > xTmp = 2631 SwXDocumentIndex::CreateXDocumentIndex( 2632 *GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect)); 2633 uno::Any aRet; 2634 aRet <<= xTmp; 2635 return aRet; 2636 } 2637 } 2638 throw container::NoSuchElementException(); 2639 } 2640 2641 /*-- 31.01.00 10:12:31--------------------------------------------------- 2642 2643 -----------------------------------------------------------------------*/ 2644 uno::Sequence< OUString > SAL_CALL 2645 SwXDocumentIndexes::getElementNames() throw (uno::RuntimeException) 2646 { 2647 vos::OGuard aGuard(Application::GetSolarMutex()); 2648 2649 if(!IsValid()) 2650 throw uno::RuntimeException(); 2651 2652 const SwSectionFmts& rFmts = GetDoc()->GetSections(); 2653 sal_Int32 nCount = 0; 2654 sal_uInt16 n; 2655 for( n = 0; n < rFmts.Count(); ++n ) 2656 { 2657 SwSection const*const pSect = rFmts[ n ]->GetSection(); 2658 if( TOX_CONTENT_SECTION == pSect->GetType() && 2659 pSect->GetFmt()->GetSectionNode() ) 2660 { 2661 ++nCount; 2662 } 2663 } 2664 2665 uno::Sequence< OUString > aRet(nCount); 2666 OUString* pArray = aRet.getArray(); 2667 sal_uInt16 nCnt; 2668 for( n = 0, nCnt = 0; n < rFmts.Count(); ++n ) 2669 { 2670 SwSection const*const pSect = rFmts[ n ]->GetSection(); 2671 if( TOX_CONTENT_SECTION == pSect->GetType() && 2672 pSect->GetFmt()->GetSectionNode()) 2673 { 2674 pArray[nCnt++] = OUString( 2675 static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName()); 2676 } 2677 } 2678 return aRet; 2679 } 2680 2681 /*-- 31.01.00 10:12:31--------------------------------------------------- 2682 2683 -----------------------------------------------------------------------*/ 2684 sal_Bool SAL_CALL 2685 SwXDocumentIndexes::hasByName(const OUString& rName) 2686 throw (uno::RuntimeException) 2687 { 2688 vos::OGuard aGuard(Application::GetSolarMutex()); 2689 2690 if(!IsValid()) 2691 throw uno::RuntimeException(); 2692 2693 String sToFind(rName); 2694 const SwSectionFmts& rFmts = GetDoc()->GetSections(); 2695 for( sal_uInt16 n = 0; n < rFmts.Count(); ++n ) 2696 { 2697 SwSection const*const pSect = rFmts[ n ]->GetSection(); 2698 if( TOX_CONTENT_SECTION == pSect->GetType() && 2699 pSect->GetFmt()->GetSectionNode()) 2700 { 2701 if (static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName() 2702 == sToFind) 2703 { 2704 return sal_True; 2705 } 2706 } 2707 } 2708 return sal_False; 2709 } 2710 2711 /*-- 05.05.99 13:15:01--------------------------------------------------- 2712 2713 -----------------------------------------------------------------------*/ 2714 uno::Type SAL_CALL 2715 SwXDocumentIndexes::getElementType() throw (uno::RuntimeException) 2716 { 2717 return text::XDocumentIndex::static_type(); 2718 } 2719 /*-- 05.05.99 13:15:02--------------------------------------------------- 2720 2721 -----------------------------------------------------------------------*/ 2722 sal_Bool SAL_CALL 2723 SwXDocumentIndexes::hasElements() throw (uno::RuntimeException) 2724 { 2725 return 0 != getCount(); 2726 } 2727 2728 /****************************************************************** 2729 * SwXDocumentIndex::StyleAccess_Impl 2730 ******************************************************************/ 2731 2732 /*-- 13.09.99 16:52:28--------------------------------------------------- 2733 2734 -----------------------------------------------------------------------*/ 2735 SwXDocumentIndex::StyleAccess_Impl::StyleAccess_Impl( 2736 SwXDocumentIndex& rParentIdx) 2737 : m_xParent(&rParentIdx) 2738 { 2739 } 2740 /*-- 13.09.99 16:52:29--------------------------------------------------- 2741 2742 -----------------------------------------------------------------------*/ 2743 SwXDocumentIndex::StyleAccess_Impl::~StyleAccess_Impl() 2744 { 2745 } 2746 2747 /* -----------------------------06.04.00 15:08-------------------------------- 2748 2749 ---------------------------------------------------------------------------*/ 2750 OUString SAL_CALL 2751 SwXDocumentIndex::StyleAccess_Impl::getImplementationName() 2752 throw (uno::RuntimeException) 2753 { 2754 return C2U("SwXDocumentIndex::StyleAccess_Impl"); 2755 } 2756 2757 static char const*const g_ServicesIndexStyleAccess[] = 2758 { 2759 "com.sun.star.text.DocumentIndexParagraphStyles", 2760 }; 2761 static const size_t g_nServicesIndexStyleAccess( 2762 sizeof(g_ServicesIndexStyleAccess)/sizeof(g_ServicesIndexStyleAccess[0])); 2763 2764 sal_Bool SAL_CALL 2765 SwXDocumentIndex::StyleAccess_Impl::supportsService( 2766 const OUString& rServiceName) 2767 throw (uno::RuntimeException) 2768 { 2769 return ::sw::SupportsServiceImpl( 2770 g_nServicesIndexStyleAccess, g_ServicesIndexStyleAccess, rServiceName); 2771 } 2772 2773 uno::Sequence< OUString > SAL_CALL 2774 SwXDocumentIndex::StyleAccess_Impl::getSupportedServiceNames() 2775 throw (uno::RuntimeException) 2776 { 2777 return ::sw::GetSupportedServiceNamesImpl( 2778 g_nServicesIndexStyleAccess, g_ServicesIndexStyleAccess); 2779 } 2780 2781 /*-- 13.09.99 16:52:29--------------------------------------------------- 2782 2783 -----------------------------------------------------------------------*/ 2784 void SAL_CALL 2785 SwXDocumentIndex::StyleAccess_Impl::replaceByIndex( 2786 sal_Int32 nIndex, const uno::Any& rElement) 2787 throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, 2788 lang::WrappedTargetException, uno::RuntimeException) 2789 { 2790 vos::OGuard aGuard(Application::GetSolarMutex()); 2791 2792 if(nIndex < 0 || nIndex > MAXLEVEL) 2793 { 2794 throw lang::IndexOutOfBoundsException(); 2795 } 2796 2797 SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() ); 2798 2799 uno::Sequence<OUString> aSeq; 2800 if(!(rElement >>= aSeq)) 2801 { 2802 throw lang::IllegalArgumentException(); 2803 } 2804 2805 const sal_Int32 nStyles = aSeq.getLength(); 2806 const OUString* pStyles = aSeq.getConstArray(); 2807 String sSetStyles; 2808 String aString; 2809 for(sal_Int32 i = 0; i < nStyles; i++) 2810 { 2811 if(i) 2812 { 2813 sSetStyles += TOX_STYLE_DELIMITER; 2814 } 2815 SwStyleNameMapper::FillUIName(pStyles[i], aString, 2816 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True); 2817 sSetStyles += aString; 2818 } 2819 rTOXBase.SetStyleNames(sSetStyles, static_cast<sal_uInt16>(nIndex)); 2820 } 2821 /*-- 13.09.99 16:52:29--------------------------------------------------- 2822 2823 -----------------------------------------------------------------------*/ 2824 sal_Int32 SAL_CALL 2825 SwXDocumentIndex::StyleAccess_Impl::getCount() throw (uno::RuntimeException) 2826 { 2827 return MAXLEVEL; 2828 } 2829 /*-- 13.09.99 16:52:30--------------------------------------------------- 2830 2831 -----------------------------------------------------------------------*/ 2832 uno::Any SAL_CALL 2833 SwXDocumentIndex::StyleAccess_Impl::getByIndex(sal_Int32 nIndex) 2834 throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, 2835 uno::RuntimeException) 2836 { 2837 vos::OGuard aGuard(Application::GetSolarMutex()); 2838 2839 if(nIndex < 0 || nIndex > MAXLEVEL) 2840 { 2841 throw lang::IndexOutOfBoundsException(); 2842 } 2843 2844 SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() ); 2845 2846 const String& rStyles = 2847 rTOXBase.GetStyleNames(static_cast<sal_uInt16>(nIndex)); 2848 const sal_uInt16 nStyles = rStyles.GetTokenCount(TOX_STYLE_DELIMITER); 2849 uno::Sequence<OUString> aStyles(nStyles); 2850 OUString* pStyles = aStyles.getArray(); 2851 String aString; 2852 for(sal_uInt16 i = 0; i < nStyles; i++) 2853 { 2854 SwStyleNameMapper::FillProgName( 2855 rStyles.GetToken(i, TOX_STYLE_DELIMITER), 2856 aString, 2857 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, 2858 sal_True); 2859 pStyles[i] = OUString( aString ); 2860 } 2861 uno::Any aRet(&aStyles, ::getCppuType((uno::Sequence<OUString>*)0)); 2862 return aRet; 2863 } 2864 /*-- 13.09.99 16:52:30--------------------------------------------------- 2865 2866 -----------------------------------------------------------------------*/ 2867 uno::Type SAL_CALL 2868 SwXDocumentIndex::StyleAccess_Impl::getElementType() 2869 throw (uno::RuntimeException) 2870 { 2871 return ::getCppuType((uno::Sequence<OUString>*)0); 2872 } 2873 /*-- 13.09.99 16:52:30--------------------------------------------------- 2874 2875 -----------------------------------------------------------------------*/ 2876 sal_Bool SAL_CALL 2877 SwXDocumentIndex::StyleAccess_Impl::hasElements() throw (uno::RuntimeException) 2878 { 2879 return sal_True; 2880 } 2881 2882 /****************************************************************** 2883 * SwXDocumentIndex::TokenAccess_Impl 2884 ******************************************************************/ 2885 /*-- 13.09.99 16:52:28--------------------------------------------------- 2886 2887 -----------------------------------------------------------------------*/ 2888 SwXDocumentIndex::TokenAccess_Impl::TokenAccess_Impl( 2889 SwXDocumentIndex& rParentIdx) 2890 : m_xParent(&rParentIdx) 2891 { 2892 } 2893 /*-- 13.09.99 16:52:29--------------------------------------------------- 2894 2895 -----------------------------------------------------------------------*/ 2896 SwXDocumentIndex::TokenAccess_Impl::~TokenAccess_Impl() 2897 { 2898 } 2899 2900 /* -----------------------------06.04.00 15:08-------------------------------- 2901 2902 ---------------------------------------------------------------------------*/ 2903 OUString SAL_CALL 2904 SwXDocumentIndex::TokenAccess_Impl::getImplementationName() 2905 throw (uno::RuntimeException) 2906 { 2907 return C2U("SwXDocumentIndex::TokenAccess_Impl"); 2908 } 2909 2910 static char const*const g_ServicesIndexTokenAccess[] = 2911 { 2912 "com.sun.star.text.DocumentIndexLevelFormat", 2913 }; 2914 static const size_t g_nServicesIndexTokenAccess( 2915 sizeof(g_ServicesIndexTokenAccess)/sizeof(g_ServicesIndexTokenAccess[0])); 2916 2917 sal_Bool SAL_CALL 2918 SwXDocumentIndex::TokenAccess_Impl::supportsService( 2919 const OUString& rServiceName) 2920 throw (uno::RuntimeException) 2921 { 2922 return ::sw::SupportsServiceImpl( 2923 g_nServicesIndexTokenAccess, g_ServicesIndexTokenAccess, rServiceName); 2924 } 2925 2926 uno::Sequence< OUString > SAL_CALL 2927 SwXDocumentIndex::TokenAccess_Impl::getSupportedServiceNames() 2928 throw (uno::RuntimeException) 2929 { 2930 return ::sw::GetSupportedServiceNamesImpl( 2931 g_nServicesIndexTokenAccess, g_ServicesIndexTokenAccess); 2932 } 2933 2934 struct TokenType { 2935 const char *pName; 2936 const enum FormTokenType eTokenType; 2937 }; 2938 2939 static const struct TokenType g_TokenTypes[] = 2940 { 2941 { "TokenEntryNumber", TOKEN_ENTRY_NO }, 2942 { "TokenEntryText", TOKEN_ENTRY_TEXT }, 2943 { "TokenTabStop", TOKEN_TAB_STOP }, 2944 { "TokenText", TOKEN_TEXT }, 2945 { "TokenPageNumber", TOKEN_PAGE_NUMS }, 2946 { "TokenChapterInfo", TOKEN_CHAPTER_INFO }, 2947 { "TokenHyperlinkStart", TOKEN_LINK_START }, 2948 { "TokenHyperlinkEnd", TOKEN_LINK_END }, 2949 { "TokenBibliographyDataField", TOKEN_AUTHORITY }, 2950 { 0, static_cast<enum FormTokenType>(0) } 2951 }; 2952 2953 /*-- 13.09.99 16:52:29--------------------------------------------------- 2954 2955 -----------------------------------------------------------------------*/ 2956 void SAL_CALL 2957 SwXDocumentIndex::TokenAccess_Impl::replaceByIndex( 2958 sal_Int32 nIndex, const uno::Any& rElement) 2959 throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, 2960 lang::WrappedTargetException, uno::RuntimeException) 2961 { 2962 vos::OGuard aGuard(Application::GetSolarMutex()); 2963 2964 SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() ); 2965 2966 if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax())) 2967 { 2968 throw lang::IndexOutOfBoundsException(); 2969 } 2970 2971 uno::Sequence<beans::PropertyValues> aSeq; 2972 if(!(rElement >>= aSeq)) 2973 { 2974 throw lang::IllegalArgumentException(); 2975 } 2976 2977 String sPattern; 2978 const sal_Int32 nTokens = aSeq.getLength(); 2979 const beans::PropertyValues* pTokens = aSeq.getConstArray(); 2980 for(sal_Int32 i = 0; i < nTokens; i++) 2981 { 2982 const beans::PropertyValue* pProperties = pTokens[i].getConstArray(); 2983 const sal_Int32 nProperties = pTokens[i].getLength(); 2984 //create an invalid token 2985 SwFormToken aToken(TOKEN_END); 2986 for(sal_Int32 j = 0; j < nProperties; j++) 2987 { 2988 if (pProperties[j].Name.equalsAscii("TokenType")) 2989 { 2990 const OUString sTokenType = 2991 lcl_AnyToString(pProperties[j].Value); 2992 for (TokenType const* pTokenType = g_TokenTypes; 2993 pTokenType->pName; ++pTokenType) 2994 { 2995 if (sTokenType.equalsAscii(pTokenType->pName)) 2996 { 2997 aToken.eTokenType = pTokenType->eTokenType; 2998 break; 2999 } 3000 } 3001 } 3002 else if (pProperties[j].Name.equalsAsciiL( 3003 RTL_CONSTASCII_STRINGPARAM("CharacterStyleName"))) 3004 { 3005 String sCharStyleName; 3006 SwStyleNameMapper::FillUIName( 3007 lcl_AnyToString(pProperties[j].Value), 3008 sCharStyleName, 3009 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, 3010 sal_True); 3011 aToken.sCharStyleName = sCharStyleName; 3012 aToken.nPoolId = SwStyleNameMapper::GetPoolIdFromUIName ( 3013 sCharStyleName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT ); 3014 } 3015 else if (pProperties[j].Name.equalsAsciiL( 3016 RTL_CONSTASCII_STRINGPARAM("TabStopRightAligned"))) 3017 { 3018 const sal_Bool bRight = lcl_AnyToBool(pProperties[j].Value); 3019 aToken.eTabAlign = bRight ? 3020 SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT; 3021 } 3022 else if (pProperties[j].Name.equalsAsciiL( 3023 RTL_CONSTASCII_STRINGPARAM("TabStopPosition"))) 3024 { 3025 sal_Int32 nPosition = 0; 3026 if (!(pProperties[j].Value >>= nPosition)) 3027 { 3028 throw lang::IllegalArgumentException(); 3029 } 3030 nPosition = MM100_TO_TWIP(nPosition); 3031 if(nPosition < 0) 3032 { 3033 throw lang::IllegalArgumentException(); 3034 } 3035 aToken.nTabStopPosition = nPosition; 3036 } 3037 else if (pProperties[j].Name.equalsAsciiL( 3038 RTL_CONSTASCII_STRINGPARAM("TabStopFillCharacter"))) 3039 { 3040 const OUString sFillChar = 3041 lcl_AnyToString(pProperties[j].Value); 3042 if (sFillChar.getLength() > 1) 3043 { 3044 throw lang::IllegalArgumentException(); 3045 } 3046 aToken.cTabFillChar = 3047 (sFillChar.getLength()) ? sFillChar[0] : ' '; 3048 } 3049 else if (pProperties[j].Name.equalsAsciiL( 3050 RTL_CONSTASCII_STRINGPARAM("Text"))) 3051 { 3052 const OUString sText = lcl_AnyToString(pProperties[j].Value); 3053 aToken.sText = sText; 3054 } 3055 else if (pProperties[j].Name.equalsAsciiL( 3056 RTL_CONSTASCII_STRINGPARAM("ChapterFormat"))) 3057 { 3058 sal_Int16 nFormat = lcl_AnyToInt16(pProperties[j].Value); 3059 switch(nFormat) 3060 { 3061 case text::ChapterFormat::NUMBER: 3062 nFormat = CF_NUMBER; 3063 break; 3064 case text::ChapterFormat::NAME: 3065 nFormat = CF_TITLE; 3066 break; 3067 case text::ChapterFormat::NAME_NUMBER: 3068 nFormat = CF_NUM_TITLE; 3069 break; 3070 case text::ChapterFormat::NO_PREFIX_SUFFIX: 3071 nFormat = CF_NUMBER_NOPREPST; 3072 break; 3073 case text::ChapterFormat::DIGIT: 3074 nFormat = CF_NUM_NOPREPST_TITLE; 3075 break; 3076 default: 3077 throw lang::IllegalArgumentException(); 3078 } 3079 aToken.nChapterFormat = nFormat; 3080 } 3081 //--->i53420 3082 else if (pProperties[j].Name.equalsAsciiL( 3083 RTL_CONSTASCII_STRINGPARAM("ChapterLevel"))) 3084 { 3085 const sal_Int16 nLevel = lcl_AnyToInt16(pProperties[j].Value); 3086 if( nLevel < 1 || nLevel > MAXLEVEL ) 3087 { 3088 throw lang::IllegalArgumentException(); 3089 } 3090 aToken.nOutlineLevel = nLevel; 3091 } 3092 //<--- 3093 else if (pProperties[j].Name.equalsAsciiL( 3094 RTL_CONSTASCII_STRINGPARAM("BibliographyDataField"))) 3095 { 3096 sal_Int16 nType = 0; 3097 pProperties[j].Value >>= nType; 3098 if(nType < 0 || nType > text::BibliographyDataField::ISBN) 3099 { 3100 lang::IllegalArgumentException aExcept; 3101 aExcept.Message = C2U("BibliographyDataField - wrong value"); 3102 aExcept.ArgumentPosition = static_cast< sal_Int16 >(j); 3103 throw aExcept; 3104 } 3105 aToken.nAuthorityField = nType; 3106 } 3107 // #i21237# 3108 else if (pProperties[j].Name.equalsAsciiL( 3109 RTL_CONSTASCII_STRINGPARAM("WithTab"))) 3110 { 3111 aToken.bWithTab = lcl_AnyToBool(pProperties[j].Value); 3112 } 3113 3114 } 3115 //exception if wrong TokenType 3116 if(TOKEN_END <= aToken.eTokenType ) 3117 { 3118 throw lang::IllegalArgumentException(); 3119 } 3120 // set TokenType from TOKEN_ENTRY_TEXT to TOKEN_ENTRY if it is 3121 // not a content index 3122 if(TOKEN_ENTRY_TEXT == aToken.eTokenType && 3123 (TOX_CONTENT != rTOXBase.GetType())) 3124 { 3125 aToken.eTokenType = TOKEN_ENTRY; 3126 } 3127 //---> i53420 3128 // check for chapter format allowed values if it was TOKEN_ENTRY_NO type 3129 // only allowed value are CF_NUMBER and CF_NUM_NOPREPST_TITLE 3130 // reading from file 3131 if( TOKEN_ENTRY_NO == aToken.eTokenType ) 3132 { 3133 switch(aToken.nChapterFormat) 3134 { 3135 case CF_NUMBER: 3136 case CF_NUM_NOPREPST_TITLE: 3137 break; 3138 default: 3139 throw lang::IllegalArgumentException(); 3140 } 3141 } 3142 //<--- 3143 sPattern += aToken.GetString(); 3144 } 3145 SwForm aForm(rTOXBase.GetTOXForm()); 3146 aForm.SetPattern(static_cast<sal_uInt16>(nIndex), sPattern); 3147 rTOXBase.SetTOXForm(aForm); 3148 } 3149 3150 /*-- 13.09.99 16:52:29--------------------------------------------------- 3151 3152 -----------------------------------------------------------------------*/ 3153 sal_Int32 SAL_CALL 3154 SwXDocumentIndex::TokenAccess_Impl::getCount() throw (uno::RuntimeException) 3155 { 3156 vos::OGuard aGuard(Application::GetSolarMutex()); 3157 3158 const sal_Int32 nRet = m_xParent->m_pImpl->GetFormMax(); 3159 return nRet; 3160 } 3161 3162 /*-- 13.09.99 16:52:30--------------------------------------------------- 3163 3164 -----------------------------------------------------------------------*/ 3165 uno::Any SAL_CALL 3166 SwXDocumentIndex::TokenAccess_Impl::getByIndex(sal_Int32 nIndex) 3167 throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, 3168 uno::RuntimeException) 3169 { 3170 vos::OGuard aGuard(Application::GetSolarMutex()); 3171 3172 SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() ); 3173 3174 if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax())) 3175 { 3176 throw lang::IndexOutOfBoundsException(); 3177 } 3178 3179 // #i21237# 3180 SwFormTokens aPattern = rTOXBase.GetTOXForm(). 3181 GetPattern(static_cast<sal_uInt16>(nIndex)); 3182 SwFormTokens::iterator aIt = aPattern.begin(); 3183 3184 sal_uInt16 nTokenCount = 0; 3185 uno::Sequence< beans::PropertyValues > aRetSeq; 3186 String aString; 3187 while(aIt != aPattern.end()) // #i21237# 3188 { 3189 nTokenCount++; 3190 aRetSeq.realloc(nTokenCount); 3191 beans::PropertyValues* pTokenProps = aRetSeq.getArray(); 3192 SwFormToken aToken = *aIt; // #i21237# 3193 3194 uno::Sequence< beans::PropertyValue >& rCurTokenSeq = 3195 pTokenProps[nTokenCount-1]; 3196 SwStyleNameMapper::FillProgName( 3197 aToken.sCharStyleName, 3198 aString, 3199 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, 3200 sal_True ); 3201 const OUString aProgCharStyle( aString ); 3202 switch(aToken.eTokenType) 3203 { 3204 case TOKEN_ENTRY_NO: 3205 { 3206 //--->i53420 3207 // writing to file (from doc to properties) 3208 sal_Int32 nElements = 2; 3209 sal_Int32 nCurrentElement = 0; 3210 3211 // check for default value 3212 if (aToken.nChapterFormat != CF_NUMBER) 3213 { 3214 nElements++;//we need the element 3215 } 3216 if( aToken.nOutlineLevel != MAXLEVEL ) 3217 { 3218 nElements++; 3219 } 3220 3221 rCurTokenSeq.realloc( nElements ); 3222 3223 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3224 3225 pArr[nCurrentElement].Name = C2U("TokenType"); 3226 pArr[nCurrentElement++].Value <<= 3227 OUString::createFromAscii("TokenEntryNumber"); 3228 3229 pArr[nCurrentElement].Name = C2U("CharacterStyleName"); 3230 pArr[nCurrentElement++].Value <<= aProgCharStyle; 3231 if( aToken.nChapterFormat != CF_NUMBER ) 3232 { 3233 pArr[nCurrentElement].Name = C2U("ChapterFormat"); 3234 sal_Int16 nVal; 3235 // the allowed values for chapter format, when used as entry number, 3236 // are CF_NUMBER and CF_NUM_NOPREPST_TITLE only, all else forced to 3237 //CF_NUMBER 3238 switch(aToken.nChapterFormat) 3239 { 3240 default: 3241 case CF_NUMBER: 3242 nVal = text::ChapterFormat::NUMBER; 3243 break; 3244 case CF_NUM_NOPREPST_TITLE: 3245 nVal = text::ChapterFormat::DIGIT; 3246 break; 3247 } 3248 pArr[nCurrentElement++].Value <<= nVal; 3249 } 3250 3251 // only a ChapterLevel != MAXLEVEL is registered 3252 if (aToken.nOutlineLevel != MAXLEVEL) 3253 { 3254 pArr[nCurrentElement].Name = C2U("ChapterLevel"); 3255 pArr[nCurrentElement].Value <<= aToken.nOutlineLevel; 3256 } 3257 //<--- 3258 } 3259 break; 3260 case TOKEN_ENTRY: // no difference between Entry and Entry Text 3261 case TOKEN_ENTRY_TEXT: 3262 { 3263 rCurTokenSeq.realloc( 2 ); 3264 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3265 3266 pArr[0].Name = C2U("TokenType"); 3267 pArr[0].Value <<= OUString::createFromAscii("TokenEntryText"); 3268 3269 pArr[1].Name = C2U("CharacterStyleName"); 3270 pArr[1].Value <<= aProgCharStyle; 3271 } 3272 break; 3273 case TOKEN_TAB_STOP: 3274 { 3275 rCurTokenSeq.realloc(5); // #i21237# 3276 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3277 3278 pArr[0].Name = C2U("TokenType"); 3279 pArr[0].Value <<= OUString::createFromAscii("TokenTabStop"); 3280 3281 if(SVX_TAB_ADJUST_END == aToken.eTabAlign) 3282 { 3283 pArr[1].Name = C2U("TabStopRightAligned"); 3284 sal_Bool bTemp = sal_True; 3285 pArr[1].Value.setValue(&bTemp, ::getCppuBooleanType()); 3286 } 3287 else 3288 { 3289 pArr[1].Name = C2U("TabStopPosition"); 3290 sal_Int32 nPos = (TWIP_TO_MM100(aToken.nTabStopPosition)); 3291 if(nPos < 0) 3292 nPos = 0; 3293 pArr[1].Value <<= (sal_Int32)nPos; 3294 } 3295 pArr[2].Name = C2U("TabStopFillCharacter"); 3296 pArr[2].Value <<= OUString(aToken.cTabFillChar); 3297 pArr[3].Name = C2U("CharacterStyleName"); 3298 pArr[3].Value <<= aProgCharStyle; 3299 // #i21237# 3300 pArr[4].Name = C2U("WithTab"); 3301 pArr[4].Value <<= static_cast<sal_Bool>(aToken.bWithTab); 3302 } 3303 break; 3304 case TOKEN_TEXT: 3305 { 3306 rCurTokenSeq.realloc( 3 ); 3307 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3308 3309 pArr[0].Name = C2U("TokenType"); 3310 pArr[0].Value <<= OUString::createFromAscii("TokenText"); 3311 3312 pArr[1].Name = C2U("CharacterStyleName"); 3313 pArr[1].Value <<= aProgCharStyle; 3314 3315 pArr[2].Name = C2U("Text"); 3316 pArr[2].Value <<= OUString(aToken.sText); 3317 } 3318 break; 3319 case TOKEN_PAGE_NUMS: 3320 { 3321 rCurTokenSeq.realloc( 2 ); 3322 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3323 3324 pArr[0].Name = C2U("TokenType"); 3325 pArr[0].Value <<= OUString::createFromAscii("TokenPageNumber"); 3326 3327 pArr[1].Name = C2U("CharacterStyleName"); 3328 pArr[1].Value <<= aProgCharStyle; 3329 } 3330 break; 3331 case TOKEN_CHAPTER_INFO: 3332 { 3333 rCurTokenSeq.realloc( 4 ); 3334 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3335 3336 pArr[0].Name = C2U("TokenType"); 3337 pArr[0].Value <<= OUString::createFromAscii("TokenChapterInfo"); 3338 3339 pArr[1].Name = C2U("CharacterStyleName"); 3340 pArr[1].Value <<= aProgCharStyle; 3341 3342 pArr[2].Name = C2U("ChapterFormat"); 3343 sal_Int16 nVal = text::ChapterFormat::NUMBER; 3344 switch(aToken.nChapterFormat) 3345 { 3346 case CF_NUMBER: 3347 nVal = text::ChapterFormat::NUMBER; 3348 break; 3349 case CF_TITLE: 3350 nVal = text::ChapterFormat::NAME; 3351 break; 3352 case CF_NUM_TITLE: 3353 nVal = text::ChapterFormat::NAME_NUMBER; 3354 break; 3355 case CF_NUMBER_NOPREPST: 3356 nVal = text::ChapterFormat::NO_PREFIX_SUFFIX; 3357 break; 3358 case CF_NUM_NOPREPST_TITLE: 3359 nVal = text::ChapterFormat::DIGIT; 3360 break; 3361 } 3362 pArr[2].Value <<= nVal; 3363 //--->i53420 3364 pArr[3].Name = C2U("ChapterLevel"); 3365 // 3366 pArr[3].Value <<= aToken.nOutlineLevel; 3367 //<--- 3368 } 3369 break; 3370 case TOKEN_LINK_START: 3371 { 3372 rCurTokenSeq.realloc( 2 ); 3373 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3374 3375 pArr[0].Name = C2U("TokenType"); 3376 pArr[0].Value <<= 3377 OUString::createFromAscii("TokenHyperlinkStart"); 3378 pArr[1].Name = C2U("CharacterStyleName"); 3379 pArr[1].Value <<= aProgCharStyle; 3380 } 3381 break; 3382 case TOKEN_LINK_END: 3383 { 3384 rCurTokenSeq.realloc( 1 ); 3385 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3386 3387 pArr[0].Name = C2U("TokenType"); 3388 pArr[0].Value <<= 3389 OUString::createFromAscii("TokenHyperlinkEnd"); 3390 } 3391 break; 3392 case TOKEN_AUTHORITY: 3393 { 3394 rCurTokenSeq.realloc( 3 ); 3395 beans::PropertyValue* pArr = rCurTokenSeq.getArray(); 3396 3397 pArr[0].Name = C2U("TokenType"); 3398 pArr[0].Value <<= 3399 OUString::createFromAscii("TokenBibliographyDataField"); 3400 3401 pArr[1].Name = C2U("CharacterStyleName"); 3402 pArr[1].Value <<= aProgCharStyle; 3403 3404 pArr[2].Name = C2U("BibliographyDataField"); 3405 pArr[2].Value <<= sal_Int16(aToken.nAuthorityField); 3406 } 3407 break; 3408 3409 default: 3410 ; 3411 } 3412 3413 aIt++; // #i21237# 3414 } 3415 3416 uno::Any aRet; 3417 aRet <<= aRetSeq; 3418 return aRet; 3419 } 3420 3421 /*-- 13.09.99 16:52:30--------------------------------------------------- 3422 3423 -----------------------------------------------------------------------*/ 3424 uno::Type SAL_CALL 3425 SwXDocumentIndex::TokenAccess_Impl::getElementType() 3426 throw (uno::RuntimeException) 3427 { 3428 return ::getCppuType((uno::Sequence< beans::PropertyValues >*)0); 3429 } 3430 /*-- 13.09.99 16:52:30--------------------------------------------------- 3431 3432 -----------------------------------------------------------------------*/ 3433 sal_Bool SAL_CALL 3434 SwXDocumentIndex::TokenAccess_Impl::hasElements() 3435 throw (uno::RuntimeException) 3436 { 3437 return sal_True; 3438 } 3439 3440