1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include <unobookmark.hxx> 28 #include <vos/mutex.hxx> 29 #include <vcl/svapp.hxx> 30 31 #include <TextCursorHelper.hxx> 32 #include <unotextrange.hxx> 33 #include <unomap.hxx> 34 #include <unoprnms.hxx> 35 #include <unoevtlstnr.hxx> 36 #include <IMark.hxx> 37 #include <crossrefbookmark.hxx> 38 #include <doc.hxx> 39 #include <IDocumentUndoRedo.hxx> 40 #include <docary.hxx> 41 #include <swundo.hxx> 42 #include <comcore.hrc> 43 #include <SwRewriter.hxx> 44 #include <docsh.hxx> 45 46 47 using namespace ::sw::mark; 48 using namespace ::com::sun::star; 49 using ::rtl::OUString; 50 51 52 namespace 53 { 54 static OUString lcl_QuoteName(const OUString& rName) 55 { 56 static const OUString sStart = OUString(String(SW_RES(STR_START_QUOTE))); 57 static const OUString sEnd = OUString(String(SW_RES(STR_END_QUOTE))); 58 ::rtl::OUStringBuffer sBuf(64); 59 return sBuf.append(sStart).append(rName).append(sEnd).makeStringAndClear(); 60 } 61 } 62 63 /****************************************************************** 64 * SwXBookmark 65 ******************************************************************/ 66 67 class SwXBookmark::Impl 68 : public SwClient 69 { 70 71 public: 72 SwEventListenerContainer m_ListenerContainer; 73 SwDoc * m_pDoc; 74 ::sw::mark::IMark * m_pRegisteredBookmark; 75 ::rtl::OUString m_sMarkName; 76 77 78 Impl( SwXBookmark & rThis, 79 SwDoc *const pDoc, ::sw::mark::IMark *const /*pBookmark*/) 80 : SwClient() 81 , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) 82 , m_pDoc(pDoc) 83 , m_pRegisteredBookmark(0) 84 { 85 // DO NOT regiserInMark here! (because SetXBookmark would delete rThis) 86 } 87 88 void registerInMark(SwXBookmark & rThis, ::sw::mark::IMark *const pBkmk); 89 protected: 90 // SwClient 91 virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew); 92 93 }; 94 95 void SwXBookmark::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) 96 { 97 ClientModify(this, pOld, pNew); 98 if (!GetRegisteredIn()) 99 { 100 m_pRegisteredBookmark = NULL; 101 m_pDoc = NULL; 102 m_ListenerContainer.Disposing(); 103 } 104 } 105 106 void SwXBookmark::Impl::registerInMark( 107 SwXBookmark & rThis, 108 ::sw::mark::IMark *const pBkmk) 109 { 110 if (pBkmk) 111 { 112 pBkmk->Add(this); 113 ::sw::mark::MarkBase *const pMarkBase( 114 dynamic_cast< ::sw::mark::MarkBase * >(pBkmk)); 115 OSL_ENSURE(pMarkBase, "registerInMark: no MarkBase?"); 116 if (pMarkBase) 117 { 118 const uno::Reference<text::XTextContent> xBookmark(& rThis); 119 pMarkBase->SetXBookmark(xBookmark); 120 } 121 } 122 else if (m_pRegisteredBookmark) 123 { 124 m_sMarkName = m_pRegisteredBookmark->GetName(); 125 m_pRegisteredBookmark->Remove(this); 126 } 127 m_pRegisteredBookmark = pBkmk; 128 } 129 130 131 const ::sw::mark::IMark* SwXBookmark::GetBookmark() const 132 { 133 return m_pImpl->m_pRegisteredBookmark; 134 } 135 136 SwXBookmark::SwXBookmark(::sw::mark::IMark *const pBkmk, SwDoc *const pDoc) 137 : m_pImpl( new SwXBookmark::Impl(*this, pDoc, pBkmk) ) 138 { 139 } 140 141 SwXBookmark::SwXBookmark() 142 : m_pImpl( new SwXBookmark::Impl(*this, 0, 0) ) 143 { 144 } 145 146 SwXBookmark::~SwXBookmark() 147 { 148 } 149 150 uno::Reference<text::XTextContent> 151 SwXBookmark::CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark) 152 { 153 // #i105557#: do not iterate over the registered clients: race condition 154 ::sw::mark::MarkBase *const pMarkBase( 155 dynamic_cast< ::sw::mark::MarkBase * >(&rBookmark)); 156 OSL_ENSURE(pMarkBase, "CreateXBookmark: no MarkBase?"); 157 if (!pMarkBase) { return 0; } 158 uno::Reference<text::XTextContent> xBookmark(pMarkBase->GetXBookmark()); 159 if (!xBookmark.is()) 160 { 161 OSL_ENSURE( 162 dynamic_cast< ::sw::mark::IBookmark* >(&rBookmark), 163 "<SwXBookmark::GetObject(..)>" 164 "SwXBookmark requested for non-bookmark mark."); 165 SwXBookmark *const pXBookmark = new SwXBookmark(&rBookmark, &rDoc); 166 xBookmark.set(pXBookmark); 167 pXBookmark->registerInMark( pMarkBase); 168 } 169 return xBookmark; 170 } 171 172 173 void SwXBookmark::registerInMark( ::sw::mark::IMark *const pBkmk ) 174 { 175 m_pImpl->registerInMark( *this, pBkmk ); 176 } 177 178 ::sw::mark::IMark const* SwXBookmark::GetBookmarkInDoc(SwDoc const*const pDoc, 179 const uno::Reference< lang::XUnoTunnel> & xUT) 180 { 181 SwXBookmark *const pXBkm( 182 ::sw::UnoTunnelGetImplementation<SwXBookmark>(xUT)); 183 if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc)) 184 { 185 return pXBkm->m_pImpl->m_pRegisteredBookmark; 186 } 187 return 0; 188 } 189 190 const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId() 191 { 192 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 193 return aSeq; 194 } 195 196 sal_Int64 SAL_CALL 197 SwXBookmark::getSomething(const uno::Sequence< sal_Int8 >& rId) 198 throw (uno::RuntimeException) 199 { 200 return ::sw::UnoTunnelImpl<SwXBookmark>(rId, this); 201 } 202 203 void SwXBookmark::attachToRangeEx( 204 const uno::Reference< text::XTextRange > & xTextRange, 205 IDocumentMarkAccess::MarkType eType) 206 throw (lang::IllegalArgumentException, uno::RuntimeException) 207 { 208 if (m_pImpl->m_pRegisteredBookmark) 209 { 210 throw uno::RuntimeException(); 211 } 212 213 const uno::Reference<lang::XUnoTunnel> xRangeTunnel( 214 xTextRange, uno::UNO_QUERY); 215 SwXTextRange* pRange = 0; 216 OTextCursorHelper* pCursor = 0; 217 if(xRangeTunnel.is()) 218 { 219 pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel); 220 pCursor = 221 ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel); 222 } 223 224 SwDoc *const pDoc = 225 (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0); 226 if (!pDoc) 227 { 228 throw lang::IllegalArgumentException(); 229 } 230 231 m_pImpl->m_pDoc = pDoc; 232 SwUnoInternalPaM aPam(*m_pImpl->m_pDoc); 233 ::sw::XTextRangeToSwPaM(aPam, xTextRange); 234 UnoActionContext aCont(m_pImpl->m_pDoc); 235 if (!m_pImpl->m_sMarkName.getLength()) 236 { 237 m_pImpl->m_sMarkName = OUString::createFromAscii("Bookmark"); 238 } 239 if ((eType == IDocumentMarkAccess::BOOKMARK) && 240 ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName)) 241 { 242 eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK; 243 } 244 else if ((eType == IDocumentMarkAccess::BOOKMARK) && 245 ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName) && 246 IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( aPam ) ) 247 { 248 eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK; 249 } 250 registerInMark( m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark( aPam, m_pImpl->m_sMarkName, eType ) ); 251 // Check, if bookmark has been created. 252 // E.g., the creation of a cross-reference bookmark is suppress, 253 // if the PaM isn't a valid one for cross-reference bookmarks. 254 if (!m_pImpl->m_pRegisteredBookmark) 255 { 256 OSL_ENSURE(false, 257 "<SwXBookmark::attachToRange(..)>" 258 " - could not create Mark."); 259 throw lang::IllegalArgumentException(); 260 } 261 } 262 263 void SwXBookmark::attachToRange( 264 const uno::Reference< text::XTextRange > & xTextRange) 265 throw (lang::IllegalArgumentException, uno::RuntimeException) 266 { 267 attachToRangeEx(xTextRange, IDocumentMarkAccess::BOOKMARK); 268 } 269 270 void SAL_CALL 271 SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange) 272 throw (lang::IllegalArgumentException, uno::RuntimeException) 273 { 274 vos::OGuard aGuard(Application::GetSolarMutex()); 275 attachToRange( xTextRange ); 276 } 277 278 uno::Reference< text::XTextRange > SAL_CALL 279 SwXBookmark::getAnchor() throw (uno::RuntimeException) 280 { 281 vos::OGuard aGuard(Application::GetSolarMutex()); 282 283 if (!m_pImpl->m_pRegisteredBookmark) 284 { 285 throw uno::RuntimeException(); 286 } 287 return SwXTextRange::CreateXTextRange( 288 *m_pImpl->m_pDoc, 289 m_pImpl->m_pRegisteredBookmark->GetMarkPos(), 290 (m_pImpl->m_pRegisteredBookmark->IsExpanded()) 291 ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : NULL); 292 } 293 294 void SAL_CALL SwXBookmark::dispose() throw (uno::RuntimeException) 295 { 296 vos::OGuard aGuard(Application::GetSolarMutex()); 297 if (m_pImpl->m_pRegisteredBookmark) 298 { 299 m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark( 300 m_pImpl->m_pRegisteredBookmark); 301 } 302 } 303 304 void SAL_CALL SwXBookmark::addEventListener( 305 const uno::Reference< lang::XEventListener > & xListener) 306 throw (uno::RuntimeException) 307 { 308 vos::OGuard g(Application::GetSolarMutex()); 309 310 if (!m_pImpl->m_pRegisteredBookmark) 311 { 312 throw uno::RuntimeException(); 313 } 314 m_pImpl->m_ListenerContainer.AddListener(xListener); 315 } 316 317 void SAL_CALL SwXBookmark::removeEventListener( 318 const uno::Reference< lang::XEventListener > & xListener) 319 throw (uno::RuntimeException) 320 { 321 vos::OGuard g(Application::GetSolarMutex()); 322 323 if (!m_pImpl->m_pRegisteredBookmark || 324 !m_pImpl->m_ListenerContainer.RemoveListener(xListener)) 325 { 326 throw uno::RuntimeException(); 327 } 328 } 329 330 OUString SAL_CALL SwXBookmark::getName() 331 throw (uno::RuntimeException) 332 { 333 vos::OGuard aGuard(Application::GetSolarMutex()); 334 335 return (m_pImpl->m_pRegisteredBookmark) 336 ? m_pImpl->m_pRegisteredBookmark->GetName() 337 : m_pImpl->m_sMarkName; 338 } 339 340 void SAL_CALL SwXBookmark::setName(const OUString& rName) 341 throw (uno::RuntimeException) 342 { 343 vos::OGuard aGuard(Application::GetSolarMutex()); 344 345 if (!m_pImpl->m_pRegisteredBookmark) 346 { 347 m_pImpl->m_sMarkName = rName; 348 } 349 if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName)) 350 { 351 return; 352 } 353 IDocumentMarkAccess *const pMarkAccess = 354 m_pImpl->m_pDoc->getIDocumentMarkAccess(); 355 if(pMarkAccess->findMark(rName) != pMarkAccess->getMarksEnd()) 356 { 357 throw uno::RuntimeException(); 358 } 359 360 SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos()); 361 if (m_pImpl->m_pRegisteredBookmark->IsExpanded()) 362 { 363 aPam.SetMark(); 364 *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos(); 365 } 366 367 SwRewriter aRewriter; 368 aRewriter.AddRule(UNDO_ARG1, lcl_QuoteName(getName())); 369 aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS)); 370 aRewriter.AddRule(UNDO_ARG3, lcl_QuoteName(rName)); 371 372 m_pImpl->m_pDoc->GetIDocumentUndoRedo().StartUndo( 373 UNDO_BOOKMARK_RENAME, &aRewriter); 374 pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName); 375 m_pImpl->m_pDoc->GetIDocumentUndoRedo().EndUndo( 376 UNDO_BOOKMARK_RENAME, &aRewriter); 377 } 378 379 OUString SAL_CALL 380 SwXBookmark::getImplementationName() throw (uno::RuntimeException) 381 { 382 return OUString::createFromAscii("SwXBookmark"); 383 } 384 385 static char const*const g_ServicesBookmark[] = 386 { 387 "com.sun.star.text.TextContent", 388 "com.sun.star.text.Bookmark", 389 "com.sun.star.document.LinkTarget", 390 }; 391 static const size_t g_nServicesBookmark( 392 sizeof(g_ServicesBookmark)/sizeof(g_ServicesBookmark[0])); 393 394 sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName) 395 throw (uno::RuntimeException) 396 { 397 return ::sw::SupportsServiceImpl( 398 g_nServicesBookmark, g_ServicesBookmark, rServiceName); 399 } 400 401 uno::Sequence< OUString > SAL_CALL 402 SwXBookmark::getSupportedServiceNames() throw (uno::RuntimeException) 403 { 404 return ::sw::GetSupportedServiceNamesImpl( 405 g_nServicesBookmark, g_ServicesBookmark); 406 } 407 408 // MetadatableMixin 409 ::sfx2::Metadatable* SwXBookmark::GetCoreObject() 410 { 411 return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark); 412 } 413 414 uno::Reference<frame::XModel> SwXBookmark::GetModel() 415 { 416 if (m_pImpl->m_pDoc) 417 { 418 SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() ); 419 return (pShell) ? pShell->GetModel() : 0; 420 } 421 return 0; 422 } 423 424 425 uno::Reference< beans::XPropertySetInfo > SAL_CALL 426 SwXBookmark::getPropertySetInfo() throw (uno::RuntimeException) 427 { 428 vos::OGuard g(Application::GetSolarMutex()); 429 430 static uno::Reference< beans::XPropertySetInfo > xRef( 431 aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK) 432 ->getPropertySetInfo() ); 433 return xRef; 434 } 435 436 void SAL_CALL 437 SwXBookmark::setPropertyValue(const OUString& PropertyName, 438 const uno::Any& /*rValue*/) 439 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 440 lang::IllegalArgumentException, lang::WrappedTargetException, 441 uno::RuntimeException) 442 { 443 // nothing to set here 444 throw lang::IllegalArgumentException( ::rtl::OUString( 445 RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) 446 + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 ); 447 } 448 449 uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName) 450 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 451 uno::RuntimeException) 452 { 453 vos::OGuard g(Application::GetSolarMutex()); 454 455 uno::Any aRet; 456 if (! ::sw::GetDefaultTextContentValue(aRet, rPropertyName)) 457 { 458 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME))) 459 { 460 aRet <<= getName(); 461 } 462 } 463 return aRet; 464 } 465 466 void SAL_CALL 467 SwXBookmark::addPropertyChangeListener( 468 const ::rtl::OUString& /*rPropertyName*/, 469 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 470 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 471 uno::RuntimeException) 472 { 473 OSL_ENSURE(false, 474 "SwXBookmark::addPropertyChangeListener(): not implemented"); 475 } 476 477 void SAL_CALL 478 SwXBookmark::removePropertyChangeListener( 479 const ::rtl::OUString& /*rPropertyName*/, 480 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 481 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 482 uno::RuntimeException) 483 { 484 OSL_ENSURE(false, 485 "SwXBookmark::removePropertyChangeListener(): not implemented"); 486 } 487 488 void SAL_CALL 489 SwXBookmark::addVetoableChangeListener( 490 const ::rtl::OUString& /*rPropertyName*/, 491 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 492 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 493 uno::RuntimeException) 494 { 495 OSL_ENSURE(false, 496 "SwXBookmark::addVetoableChangeListener(): not implemented"); 497 } 498 499 void SAL_CALL 500 SwXBookmark::removeVetoableChangeListener( 501 const ::rtl::OUString& /*rPropertyName*/, 502 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 503 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 504 uno::RuntimeException) 505 { 506 OSL_ENSURE(false, 507 "SwXBookmark::removeVetoableChangeListener(): not implemented"); 508 } 509 510 /****************************************************************** 511 * SwXFieldmark 512 ******************************************************************/ 513 514 SwXFieldmark::SwXFieldmark( bool _isReplacementObject ) 515 : SwXFieldmark_Base() 516 , isReplacementObject(_isReplacementObject) 517 { 518 } 519 520 521 SwXFieldmark::SwXFieldmark( 522 bool _isReplacementObject, 523 ::sw::mark::IMark *const pMark, 524 SwDoc *const pDoc ) 525 : SwXFieldmark_Base( pMark, pDoc ) 526 , isReplacementObject( _isReplacementObject ) 527 { 528 } 529 530 531 uno::Reference<text::XTextContent> SwXFieldmark::CreateXFieldmark( 532 SwDoc & rDoc, 533 ::sw::mark::IMark & rBookmark ) 534 { 535 // do not iterate over the registered clients: race condition 536 ::sw::mark::MarkBase *const pMarkBase( dynamic_cast< ::sw::mark::MarkBase * >(&rBookmark)); 537 OSL_ENSURE(pMarkBase, "CreateXFieldmark: no MarkBase?"); 538 if (!pMarkBase) { return 0; } 539 540 uno::Reference<text::XTextContent> xBookmark(pMarkBase->GetXBookmark()); 541 if (!xBookmark.is()) 542 { 543 SwXFieldmark* pXFieldmark = NULL; 544 if ( dynamic_cast< ::sw::mark::TextFieldmark* >(&rBookmark) ) 545 { 546 pXFieldmark = new SwXFieldmark( false, &rBookmark, &rDoc ); 547 } 548 else if ( dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBookmark) ) 549 { 550 pXFieldmark = new SwXFieldmark( true, &rBookmark, &rDoc ); 551 } 552 if ( pXFieldmark != NULL ) 553 { 554 xBookmark.set( pXFieldmark ); 555 pXFieldmark->registerInMark( pMarkBase ); 556 } 557 } 558 return xBookmark; 559 } 560 561 562 void SwXFieldmarkParameters::insertByName(const OUString& aName, const uno::Any& aElement) 563 throw (lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException) 564 { 565 vos::OGuard aGuard(Application::GetSolarMutex()); 566 IFieldmark::parameter_map_t* pParameters = getCoreParameters(); 567 if(pParameters->find(aName) != pParameters->end()) 568 throw container::ElementExistException(); 569 (*pParameters)[aName] = aElement; 570 } 571 572 void SwXFieldmarkParameters::removeByName(const OUString& aName) 573 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 574 { 575 vos::OGuard aGuard(Application::GetSolarMutex()); 576 if(!getCoreParameters()->erase(aName)) 577 throw container::NoSuchElementException(); 578 } 579 580 void SwXFieldmarkParameters::replaceByName(const OUString& aName, const uno::Any& aElement) 581 throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 582 { 583 vos::OGuard aGuard(Application::GetSolarMutex()); 584 IFieldmark::parameter_map_t* pParameters = getCoreParameters(); 585 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName); 586 if(pEntry == pParameters->end()) 587 throw container::NoSuchElementException(); 588 pEntry->second = aElement; 589 } 590 591 uno::Any SwXFieldmarkParameters::getByName(const OUString& aName) 592 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 593 { 594 vos::OGuard aGuard(Application::GetSolarMutex()); 595 IFieldmark::parameter_map_t* pParameters = getCoreParameters(); 596 IFieldmark::parameter_map_t::iterator pEntry = pParameters->find(aName); 597 if(pEntry == pParameters->end()) 598 throw container::NoSuchElementException(); 599 return pEntry->second; 600 } 601 602 uno::Sequence<OUString> SwXFieldmarkParameters::getElementNames() 603 throw (uno::RuntimeException) 604 { 605 vos::OGuard aGuard(Application::GetSolarMutex()); 606 IFieldmark::parameter_map_t* pParameters = getCoreParameters(); 607 uno::Sequence<OUString> vResult(pParameters->size()); 608 OUString* pOutEntry = vResult.getArray(); 609 for(IFieldmark::parameter_map_t::iterator pEntry = pParameters->begin(); pEntry!=pParameters->end(); ++pEntry, ++pOutEntry) 610 *pOutEntry = pEntry->first; 611 return vResult; 612 } 613 614 ::sal_Bool SwXFieldmarkParameters::hasByName(const OUString& aName) 615 throw (uno::RuntimeException) 616 { 617 vos::OGuard aGuard(Application::GetSolarMutex()); 618 IFieldmark::parameter_map_t* pParameters = getCoreParameters(); 619 return (pParameters->find(aName) != pParameters->end()); 620 } 621 622 uno::Type SwXFieldmarkParameters::getElementType() 623 throw (uno::RuntimeException) 624 { 625 return ::cppu::UnoType< ::cppu::UnoVoidType>::get(); 626 } 627 628 ::sal_Bool SwXFieldmarkParameters::hasElements() 629 throw (uno::RuntimeException) 630 { 631 vos::OGuard aGuard(Application::GetSolarMutex()); 632 return !getCoreParameters()->empty(); 633 } 634 635 void SwXFieldmarkParameters::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) 636 { 637 ClientModify(this, pOld, pNew); 638 } 639 640 641 IFieldmark::parameter_map_t* SwXFieldmarkParameters::getCoreParameters() 642 throw (uno::RuntimeException) 643 { 644 const IFieldmark* pFieldmark = dynamic_cast< const IFieldmark* >(GetRegisteredIn()); 645 if(!pFieldmark) 646 throw uno::RuntimeException(); 647 return const_cast< IFieldmark* >(pFieldmark)->GetParameters(); 648 } 649 650 651 void SwXFieldmark::attachToRange( const uno::Reference < text::XTextRange >& xTextRange ) 652 throw(lang::IllegalArgumentException, uno::RuntimeException) 653 { 654 attachToRangeEx( xTextRange, 655 ( isReplacementObject ? IDocumentMarkAccess::CHECKBOX_FIELDMARK : IDocumentMarkAccess::TEXT_FIELDMARK ) ); 656 } 657 658 ::rtl::OUString SwXFieldmark::getFieldType(void) 659 throw(uno::RuntimeException) 660 { 661 vos::OGuard aGuard(Application::GetSolarMutex()); 662 const IFieldmark *pBkm = dynamic_cast<const IFieldmark*>(GetBookmark()); 663 if(!pBkm) 664 throw uno::RuntimeException(); 665 return pBkm->GetFieldname(); 666 } 667 668 void SwXFieldmark::setFieldType(const::rtl::OUString & fieldType) 669 throw(uno::RuntimeException) 670 { 671 vos::OGuard aGuard(Application::GetSolarMutex()); 672 IFieldmark *pBkm = const_cast<IFieldmark*>( 673 dynamic_cast<const IFieldmark*>(GetBookmark())); 674 if(!pBkm) 675 throw uno::RuntimeException(); 676 pBkm->SetFieldname(fieldType); 677 } 678 679 uno::Reference<container::XNameContainer> SwXFieldmark::getParameters() 680 throw (uno::RuntimeException) 681 { 682 vos::OGuard aGuard(Application::GetSolarMutex()); 683 IFieldmark *pBkm = const_cast<IFieldmark*>( 684 dynamic_cast<const IFieldmark*>(GetBookmark())); 685 if(!pBkm) 686 throw uno::RuntimeException(); 687 return uno::Reference<container::XNameContainer>(new SwXFieldmarkParameters(pBkm)); 688 } 689 690