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 <unoparagraph.hxx> 32 #include <cmdid.h> 33 #include <unomid.h> 34 #include <unoparaframeenum.hxx> 35 #include <unotext.hxx> 36 #include <unotextrange.hxx> 37 #include <unoport.hxx> 38 #include <unomap.hxx> 39 #include <unocrsr.hxx> 40 #include <unoprnms.hxx> 41 #include <unocrsrhelper.hxx> 42 #include <doc.hxx> 43 #include <ndtxt.hxx> 44 #include <vos/mutex.hxx> 45 #include <vcl/svapp.hxx> 46 #include <docsh.hxx> 47 48 #define _SVSTDARR_USHORTS 49 #define _SVSTDARR_USHORTSSORT 50 #include <svl/svstdarr.hxx> 51 52 #include <com/sun/star/beans/SetPropertyTolerantFailed.hpp> 53 #include <com/sun/star/beans/GetPropertyTolerantResult.hpp> 54 #include <com/sun/star/beans/TolerantPropertySetResultType.hpp> 55 #include <com/sun/star/beans/PropertyAttribute.hpp> 56 #include <com/sun/star/text/WrapTextMode.hpp> 57 #include <com/sun/star/text/TextContentAnchorType.hpp> 58 59 60 using namespace ::com::sun::star; 61 using ::rtl::OUString; 62 63 64 /* -----------------------------01.12.00 18:09-------------------------------- 65 66 ---------------------------------------------------------------------------*/ 67 class SwParaSelection 68 { 69 SwCursor & m_rCursor; 70 public: 71 SwParaSelection(SwCursor & rCursor); 72 ~SwParaSelection(); 73 }; 74 75 SwParaSelection::SwParaSelection(SwCursor & rCursor) 76 : m_rCursor(rCursor) 77 { 78 if (m_rCursor.HasMark()) 79 { 80 m_rCursor.DeleteMark(); 81 } 82 // is it at the start? 83 if (m_rCursor.GetPoint()->nContent != 0) 84 { 85 m_rCursor.MovePara(fnParaCurr, fnParaStart); 86 } 87 // or at the end already? 88 if (m_rCursor.GetPoint()->nContent != m_rCursor.GetCntntNode()->Len()) 89 { 90 m_rCursor.SetMark(); 91 m_rCursor.MovePara(fnParaCurr, fnParaEnd); 92 } 93 } 94 95 SwParaSelection::~SwParaSelection() 96 { 97 if (m_rCursor.GetPoint()->nContent != 0) 98 { 99 m_rCursor.DeleteMark(); 100 m_rCursor.MovePara(fnParaCurr, fnParaStart); 101 } 102 } 103 104 105 /****************************************************************** 106 * forward declarations 107 ******************************************************************/ 108 109 beans::PropertyState lcl_SwXParagraph_getPropertyState( 110 const SwTxtNode& rTxtNode, 111 const SwAttrSet** ppSet, 112 const SfxItemPropertySimpleEntry& rEntry, 113 sal_Bool &rAttrSetFetched ) 114 throw (beans::UnknownPropertyException); 115 116 /****************************************************************** 117 * SwXParagraph 118 ******************************************************************/ 119 120 class SwXParagraph::Impl 121 : public SwClient 122 { 123 124 public: 125 SwXParagraph & m_rThis; 126 SwEventListenerContainer m_ListenerContainer; 127 SfxItemPropertySet const& m_rPropSet; 128 bool m_bIsDescriptor; 129 sal_Int32 m_nSelectionStartPos; 130 sal_Int32 m_nSelectionEndPos; 131 ::rtl::OUString m_sText; 132 uno::Reference<text::XText> m_xParentText; 133 134 Impl( SwXParagraph & rThis, 135 SwTxtNode *const pTxtNode = 0, 136 uno::Reference< text::XText > const & xParent = 0, 137 const sal_Int32 nSelStart = -1, const sal_Int32 nSelEnd = -1) 138 : SwClient(pTxtNode) 139 , m_rThis(rThis) 140 , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis)) 141 , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH)) 142 // #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code 143 , m_bIsDescriptor((0 == pTxtNode) ? true : false) 144 , m_nSelectionStartPos(nSelStart) 145 , m_nSelectionEndPos(nSelEnd) 146 , m_xParentText(xParent) 147 { 148 } 149 150 const SwTxtNode * GetTxtNode() const { 151 return static_cast<const SwTxtNode*>(GetRegisteredIn()); 152 } 153 SwTxtNode * GetTxtNode() { 154 return static_cast<SwTxtNode*>(GetRegisteredInNonConst()); 155 } 156 157 SwTxtNode & GetTxtNodeOrThrow() { 158 SwTxtNode *const pTxtNode( GetTxtNode() ); 159 if (!pTxtNode) { 160 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 161 "SwXParagraph: disposed or invalid")), 0); 162 } 163 return *pTxtNode; 164 } 165 166 bool IsDescriptor() const { return m_bIsDescriptor; } 167 168 void SetPropertyValues_Impl( 169 const uno::Sequence< ::rtl::OUString >& rPropertyNames, 170 const uno::Sequence< uno::Any >& rValues) 171 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 172 lang::IllegalArgumentException, lang::WrappedTargetException, 173 uno::RuntimeException); 174 175 uno::Sequence< uno::Any > 176 GetPropertyValues_Impl( 177 const uno::Sequence< ::rtl::OUString >& rPropertyNames) 178 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 179 uno::RuntimeException); 180 181 uno::Sequence< beans::GetDirectPropertyTolerantResult > 182 GetPropertyValuesTolerant_Impl( 183 const uno::Sequence< ::rtl::OUString >& rPropertyNames, 184 bool bDirectValuesOnly) 185 throw (uno::RuntimeException); 186 protected: 187 // SwClient 188 virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew); 189 190 }; 191 192 /*-- 11.12.98 08:12:58--------------------------------------------------- 193 194 -----------------------------------------------------------------------*/ 195 void SwXParagraph::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew ) 196 { 197 ClientModify(this, pOld, pNew); 198 if (!GetRegisteredIn()) 199 { 200 m_ListenerContainer.Disposing(); 201 } 202 } 203 204 /*-- 11.12.98 08:12:47--------------------------------------------------- 205 206 -----------------------------------------------------------------------*/ 207 SwXParagraph::SwXParagraph() 208 : m_pImpl( new SwXParagraph::Impl(*this) ) 209 { 210 } 211 212 /*-- 11.12.98 08:12:47--------------------------------------------------- 213 214 -----------------------------------------------------------------------*/ 215 SwXParagraph::SwXParagraph( 216 uno::Reference< text::XText > const & xParent, 217 SwTxtNode & rTxtNode, 218 const sal_Int32 nSelStart, const sal_Int32 nSelEnd) 219 : m_pImpl( 220 new SwXParagraph::Impl(*this, &rTxtNode, xParent, nSelStart, nSelEnd)) 221 { 222 } 223 224 /*-- 11.12.98 08:12:48--------------------------------------------------- 225 226 -----------------------------------------------------------------------*/ 227 SwXParagraph::~SwXParagraph() 228 { 229 } 230 231 const SwTxtNode * SwXParagraph::GetTxtNode() const 232 { 233 return m_pImpl->GetTxtNode(); 234 } 235 236 bool SwXParagraph::IsDescriptor() const 237 { 238 return m_pImpl->IsDescriptor(); 239 } 240 241 uno::Reference<text::XTextContent> 242 SwXParagraph::CreateXParagraph(SwDoc & rDoc, SwTxtNode& rTxtNode, 243 uno::Reference< text::XText> const& i_xParent, 244 const sal_Int32 nSelStart, const sal_Int32 nSelEnd) 245 { 246 // re-use existing SwXParagraph 247 // #i105557#: do not iterate over the registered clients: race condition 248 uno::Reference<text::XTextContent> xParagraph; 249 if ((-1 == nSelStart) && (-1 == nSelEnd)) // only use cache if no selection! 250 { 251 xParagraph.set(rTxtNode.GetXParagraph()); 252 } 253 if (xParagraph.is()) 254 { 255 return xParagraph; 256 } 257 258 // create new SwXParagraph 259 uno::Reference<text::XText> xParentText(i_xParent); 260 if (!xParentText.is()) 261 { 262 SwPosition Pos( rTxtNode ); 263 xParentText.set(::sw::CreateParentXText( rDoc, Pos )); 264 } 265 SwXParagraph *const pXPara( 266 new SwXParagraph(xParentText, rTxtNode, nSelStart, nSelEnd) ); 267 // this is why the constructor is private: need to acquire pXPara here 268 xParagraph.set(pXPara); 269 // in order to initialize the weak pointer cache in the core object 270 if ((-1 == nSelStart) && (-1 == nSelEnd)) 271 { 272 rTxtNode.SetXParagraph(xParagraph); 273 } 274 return xParagraph; 275 } 276 277 bool SwXParagraph::SelectPaM(SwPaM & rPaM) 278 { 279 SwTxtNode const*const pTxtNode( GetTxtNode() ); 280 281 if (!pTxtNode) 282 { 283 return false; 284 } 285 286 *rPaM.GetPoint() = SwPosition( *pTxtNode ); 287 // set selection to the whole paragraph 288 rPaM.SetMark(); 289 rPaM.GetMark()->nContent = pTxtNode->GetTxt().Len(); 290 return true; 291 } 292 293 /* -----------------------------13.03.00 12:15-------------------------------- 294 295 ---------------------------------------------------------------------------*/ 296 const uno::Sequence< sal_Int8 > & SwXParagraph::getUnoTunnelId() 297 { 298 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId(); 299 return aSeq; 300 } 301 /* -----------------------------10.03.00 18:04-------------------------------- 302 303 ---------------------------------------------------------------------------*/ 304 sal_Int64 SAL_CALL 305 SwXParagraph::getSomething(const uno::Sequence< sal_Int8 >& rId) 306 throw (uno::RuntimeException) 307 { 308 return ::sw::UnoTunnelImpl<SwXParagraph>(rId, this); 309 } 310 311 /* -----------------------------06.04.00 16:37-------------------------------- 312 313 ---------------------------------------------------------------------------*/ 314 OUString SAL_CALL 315 SwXParagraph::getImplementationName() throw (uno::RuntimeException) 316 { 317 return C2U("SwXParagraph"); 318 } 319 /* -----------------------------06.04.00 16:37-------------------------------- 320 321 ---------------------------------------------------------------------------*/ 322 static char const*const g_ServicesParagraph[] = 323 { 324 "com.sun.star.text.TextContent", 325 "com.sun.star.text.Paragraph", 326 "com.sun.star.style.CharacterProperties", 327 "com.sun.star.style.CharacterPropertiesAsian", 328 "com.sun.star.style.CharacterPropertiesComplex", 329 "com.sun.star.style.ParagraphProperties", 330 "com.sun.star.style.ParagraphPropertiesAsian", 331 "com.sun.star.style.ParagraphPropertiesComplex", 332 }; 333 static const size_t g_nServicesParagraph( 334 sizeof(g_ServicesParagraph)/sizeof(g_ServicesParagraph[0])); 335 336 sal_Bool SAL_CALL 337 SwXParagraph::supportsService(const OUString& rServiceName) 338 throw (uno::RuntimeException) 339 { 340 return ::sw::SupportsServiceImpl( 341 g_nServicesParagraph, g_ServicesParagraph, rServiceName); 342 } 343 /* -----------------------------06.04.00 16:37-------------------------------- 344 345 ---------------------------------------------------------------------------*/ 346 uno::Sequence< OUString > SAL_CALL 347 SwXParagraph::getSupportedServiceNames() throw (uno::RuntimeException) 348 { 349 return ::sw::GetSupportedServiceNamesImpl( 350 g_nServicesParagraph, g_ServicesParagraph); 351 } 352 353 /* -----------------------------11.07.00 14:48-------------------------------- 354 355 ---------------------------------------------------------------------------*/ 356 void 357 SwXParagraph::attachToText(SwXText & rParent, SwTxtNode & rTxtNode) 358 { 359 DBG_ASSERT(m_pImpl->m_bIsDescriptor, "Paragraph is not a descriptor"); 360 if (m_pImpl->m_bIsDescriptor) 361 { 362 m_pImpl->m_bIsDescriptor = false; 363 rTxtNode.Add(m_pImpl.get()); 364 rTxtNode.SetXParagraph(uno::Reference<text::XTextContent>(this)); 365 m_pImpl->m_xParentText = &rParent; 366 if (m_pImpl->m_sText.getLength()) 367 { 368 try { setString(m_pImpl->m_sText); } 369 catch(...){} 370 m_pImpl->m_sText = OUString(); 371 } 372 } 373 } 374 375 /*-- 11.12.98 08:12:49--------------------------------------------------- 376 377 -----------------------------------------------------------------------*/ 378 uno::Reference< beans::XPropertySetInfo > SAL_CALL 379 SwXParagraph::getPropertySetInfo() 380 throw (uno::RuntimeException) 381 { 382 vos::OGuard g(Application::GetSolarMutex()); 383 384 static uno::Reference< beans::XPropertySetInfo > xRef = 385 m_pImpl->m_rPropSet.getPropertySetInfo(); 386 return xRef; 387 } 388 /*-- 11.12.98 08:12:49--------------------------------------------------- 389 390 -----------------------------------------------------------------------*/ 391 void SAL_CALL 392 SwXParagraph::setPropertyValue(const OUString& rPropertyName, 393 const uno::Any& rValue) 394 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 395 lang::IllegalArgumentException, lang::WrappedTargetException, 396 uno::RuntimeException ) 397 { 398 vos::OGuard aGuard(Application::GetSolarMutex()); 399 uno::Sequence<OUString> aPropertyNames(1); 400 aPropertyNames.getArray()[0] = rPropertyName; 401 uno::Sequence<uno::Any> aValues(1); 402 aValues.getArray()[0] = rValue; 403 m_pImpl->SetPropertyValues_Impl( aPropertyNames, aValues ); 404 } 405 406 /*-- 11.12.98 08:12:49--------------------------------------------------- 407 408 -----------------------------------------------------------------------*/ 409 uno::Any 410 SwXParagraph::getPropertyValue(const OUString& rPropertyName) 411 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 412 uno::RuntimeException ) 413 { 414 vos::OGuard aGuard(Application::GetSolarMutex()); 415 uno::Sequence<OUString> aPropertyNames(1); 416 aPropertyNames.getArray()[0] = rPropertyName; 417 const uno::Sequence< uno::Any > aRet = 418 m_pImpl->GetPropertyValues_Impl(aPropertyNames); 419 return aRet.getConstArray()[0]; 420 } 421 /* -----------------------------02.04.01 11:43-------------------------------- 422 423 ---------------------------------------------------------------------------*/ 424 void SwXParagraph::Impl::SetPropertyValues_Impl( 425 const uno::Sequence< OUString >& rPropertyNames, 426 const uno::Sequence< uno::Any >& rValues ) 427 throw (beans::UnknownPropertyException, beans::PropertyVetoException, 428 lang::IllegalArgumentException, lang::WrappedTargetException, 429 uno::RuntimeException) 430 { 431 SwTxtNode & rTxtNode(GetTxtNodeOrThrow()); 432 433 SwPosition aPos( rTxtNode ); 434 SwCursor aCursor( aPos, 0, false ); 435 const OUString* pPropertyNames = rPropertyNames.getConstArray(); 436 const uno::Any* pValues = rValues.getConstArray(); 437 SfxItemPropertyMap const*const pMap = m_rPropSet.getPropertyMap(); 438 SwParaSelection aParaSel( aCursor ); 439 for (sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++) 440 { 441 SfxItemPropertySimpleEntry const*const pEntry = 442 pMap->getByName( pPropertyNames[nProp] ); 443 if (!pEntry) 444 { 445 throw beans::UnknownPropertyException( 446 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 447 + pPropertyNames[nProp], 448 static_cast< cppu::OWeakObject * >(&m_rThis)); 449 } 450 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 451 { 452 throw beans::PropertyVetoException( 453 OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) 454 + pPropertyNames[nProp], 455 static_cast< cppu::OWeakObject * >(&m_rThis)); 456 } 457 SwUnoCursorHelper::SetPropertyValue(aCursor, m_rPropSet, 458 pPropertyNames[nProp], pValues[nProp]); 459 } 460 } 461 462 void SAL_CALL SwXParagraph::setPropertyValues( 463 const uno::Sequence< OUString >& rPropertyNames, 464 const uno::Sequence< uno::Any >& rValues ) 465 throw (beans::PropertyVetoException, lang::IllegalArgumentException, 466 lang::WrappedTargetException, uno::RuntimeException) 467 { 468 vos::OGuard aGuard(Application::GetSolarMutex()); 469 470 // workaround for bad designed API 471 try 472 { 473 m_pImpl->SetPropertyValues_Impl( rPropertyNames, rValues ); 474 } 475 catch (beans::UnknownPropertyException &rException) 476 { 477 // wrap the original (here not allowed) exception in 478 // a lang::WrappedTargetException that gets thrown instead. 479 lang::WrappedTargetException aWExc; 480 aWExc.TargetException <<= rException; 481 throw aWExc; 482 } 483 } 484 485 /* -----------------------------02.04.01 11:43-------------------------------- 486 487 ---------------------------------------------------------------------------*/ 488 uno::Sequence< uno::Any > SwXParagraph::Impl::GetPropertyValues_Impl( 489 const uno::Sequence< OUString > & rPropertyNames ) 490 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 491 uno::RuntimeException) 492 { 493 SwTxtNode & rTxtNode(GetTxtNodeOrThrow()); 494 495 uno::Sequence< uno::Any > aValues(rPropertyNames.getLength()); 496 SwPosition aPos( rTxtNode ); 497 SwPaM aPam( aPos ); 498 uno::Any* pValues = aValues.getArray(); 499 const OUString* pPropertyNames = rPropertyNames.getConstArray(); 500 SfxItemPropertyMap const*const pMap = m_rPropSet.getPropertyMap(); 501 const SwAttrSet& rAttrSet( rTxtNode.GetSwAttrSet() ); 502 for (sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++) 503 { 504 SfxItemPropertySimpleEntry const*const pEntry = 505 pMap->getByName( pPropertyNames[nProp] ); 506 if (!pEntry) 507 { 508 throw beans::UnknownPropertyException( 509 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 510 + pPropertyNames[nProp], 511 static_cast< cppu::OWeakObject * >(&m_rThis)); 512 } 513 if (! ::sw::GetDefaultTextContentValue( 514 pValues[nProp], pPropertyNames[nProp], pEntry->nWID)) 515 { 516 beans::PropertyState eTemp; 517 const bool bDone = SwUnoCursorHelper::getCrsrPropertyValue( 518 *pEntry, aPam, &(pValues[nProp]), eTemp, &rTxtNode ); 519 if (!bDone) 520 { 521 m_rPropSet.getPropertyValue( 522 *pEntry, rAttrSet, pValues[nProp]); 523 } 524 } 525 } 526 return aValues; 527 } 528 529 /* -----------------------------04.11.03 11:43-------------------------------- 530 531 ---------------------------------------------------------------------------*/ 532 uno::Sequence< uno::Any > SAL_CALL 533 SwXParagraph::getPropertyValues(const uno::Sequence< OUString >& rPropertyNames) 534 throw (uno::RuntimeException) 535 { 536 vos::OGuard aGuard(Application::GetSolarMutex()); 537 uno::Sequence< uno::Any > aValues; 538 539 // workaround for bad designed API 540 try 541 { 542 aValues = m_pImpl->GetPropertyValues_Impl( rPropertyNames ); 543 } 544 catch (beans::UnknownPropertyException &) 545 { 546 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 547 "Unknown property exception caught")), 548 static_cast<cppu::OWeakObject *>(this)); 549 } 550 catch (lang::WrappedTargetException &) 551 { 552 throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM( 553 "WrappedTargetException caught")), 554 static_cast<cppu::OWeakObject *>(this)); 555 } 556 557 return aValues; 558 } 559 560 /* -----------------------------02.04.01 11:43-------------------------------- 561 562 ---------------------------------------------------------------------------*/ 563 void SAL_CALL SwXParagraph::addPropertiesChangeListener( 564 const uno::Sequence< OUString >& /*aPropertyNames*/, 565 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 566 throw (uno::RuntimeException) 567 { 568 OSL_ENSURE(false, 569 "SwXParagraph::addPropertiesChangeListener(): not implemented"); 570 } 571 /* -----------------------------02.04.01 11:43-------------------------------- 572 573 ---------------------------------------------------------------------------*/ 574 void SAL_CALL SwXParagraph::removePropertiesChangeListener( 575 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 576 throw (uno::RuntimeException) 577 { 578 OSL_ENSURE(false, 579 "SwXParagraph::removePropertiesChangeListener(): not implemented"); 580 } 581 /* -----------------------------02.04.01 11:43-------------------------------- 582 583 ---------------------------------------------------------------------------*/ 584 void SAL_CALL SwXParagraph::firePropertiesChangeEvent( 585 const uno::Sequence< OUString >& /*aPropertyNames*/, 586 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) 587 throw(uno::RuntimeException) 588 { 589 OSL_ENSURE(false, 590 "SwXParagraph::firePropertiesChangeEvent(): not implemented"); 591 } 592 /* -----------------------------25.09.03 11:09-------------------------------- 593 594 ---------------------------------------------------------------------------*/ 595 596 /* disabled for #i46921# */ 597 598 uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL 599 SwXParagraph::setPropertyValuesTolerant( 600 const uno::Sequence< OUString >& rPropertyNames, 601 const uno::Sequence< uno::Any >& rValues ) 602 throw (lang::IllegalArgumentException, uno::RuntimeException) 603 { 604 vos::OGuard aGuard( Application::GetSolarMutex() ); 605 606 if (rPropertyNames.getLength() != rValues.getLength()) 607 { 608 throw lang::IllegalArgumentException(); 609 } 610 611 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 612 613 //SwNode& rTxtNode = pUnoCrsr->GetPoint()->nNode.GetNode(); 614 //const SwAttrSet& rAttrSet = ((SwTxtNode&)rTxtNode).GetSwAttrSet(); 615 //sal_uInt16 nAttrCount = rAttrSet.Count(); 616 617 const sal_Int32 nProps = rPropertyNames.getLength(); 618 const OUString *pProp = rPropertyNames.getConstArray(); 619 620 //sal_Int32 nVals = rValues.getLength(); 621 const uno::Any *pValue = rValues.getConstArray(); 622 623 sal_Int32 nFailed = 0; 624 uno::Sequence< beans::SetPropertyTolerantFailed > aFailed( nProps ); 625 beans::SetPropertyTolerantFailed *pFailed = aFailed.getArray(); 626 627 // get entry to start with 628 SfxItemPropertyMap const*const pPropMap = 629 m_pImpl->m_rPropSet.getPropertyMap(); 630 631 OUString sTmp; 632 SwPosition aPos( rTxtNode ); 633 SwCursor aCursor( aPos, 0, false ); 634 SwParaSelection aParaSel( aCursor ); 635 for (sal_Int32 i = 0; i < nProps; ++i) 636 { 637 try 638 { 639 pFailed[ nFailed ].Name = pProp[i]; 640 641 SfxItemPropertySimpleEntry const*const pEntry = 642 pPropMap->getByName( pProp[i] ); 643 if (!pEntry) 644 { 645 pFailed[ nFailed++ ].Result = 646 beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY; 647 } 648 else 649 { 650 // set property value 651 // (compare to SwXParagraph::setPropertyValues) 652 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 653 { 654 pFailed[ nFailed++ ].Result = 655 beans::TolerantPropertySetResultType::PROPERTY_VETO; 656 } 657 else 658 { 659 SwUnoCursorHelper::SetPropertyValue( 660 aCursor, m_pImpl->m_rPropSet, pProp[i], pValue[i]); 661 } 662 } 663 } 664 catch (beans::UnknownPropertyException &) 665 { 666 // should not occur because property was searched for before 667 DBG_ERROR( "unexpected exception catched" ); 668 pFailed[ nFailed++ ].Result = 669 beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY; 670 } 671 catch (lang::IllegalArgumentException &) 672 { 673 pFailed[ nFailed++ ].Result = 674 beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT; 675 } 676 catch (beans::PropertyVetoException &) 677 { 678 pFailed[ nFailed++ ].Result = 679 beans::TolerantPropertySetResultType::PROPERTY_VETO; 680 } 681 catch (lang::WrappedTargetException &) 682 { 683 pFailed[ nFailed++ ].Result = 684 beans::TolerantPropertySetResultType::WRAPPED_TARGET; 685 } 686 } 687 688 aFailed.realloc( nFailed ); 689 return aFailed; 690 } 691 692 693 uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL 694 SwXParagraph::getPropertyValuesTolerant( 695 const uno::Sequence< OUString >& rPropertyNames ) 696 throw (uno::RuntimeException) 697 { 698 vos::OGuard aGuard( Application::GetSolarMutex() ); 699 700 uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes( 701 m_pImpl->GetPropertyValuesTolerant_Impl( rPropertyNames, false ) ); 702 const beans::GetDirectPropertyTolerantResult *pTmpRes = 703 aTmpRes.getConstArray(); 704 705 // copy temporary result to final result type 706 const sal_Int32 nLen = aTmpRes.getLength(); 707 uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen ); 708 beans::GetPropertyTolerantResult *pRes = aRes.getArray(); 709 for (sal_Int32 i = 0; i < nLen; i++) 710 { 711 *pRes++ = *pTmpRes++; 712 } 713 return aRes; 714 } 715 716 717 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL 718 SwXParagraph::getDirectPropertyValuesTolerant( 719 const uno::Sequence< OUString >& rPropertyNames ) 720 throw (uno::RuntimeException) 721 { 722 vos::OGuard aGuard( Application::GetSolarMutex() ); 723 724 return m_pImpl->GetPropertyValuesTolerant_Impl( rPropertyNames, true ); 725 } 726 727 728 uno::Sequence< beans::GetDirectPropertyTolerantResult > 729 SwXParagraph::Impl::GetPropertyValuesTolerant_Impl( 730 const uno::Sequence< OUString >& rPropertyNames, 731 bool bDirectValuesOnly ) 732 throw (uno::RuntimeException) 733 { 734 vos::OGuard aGuard( Application::GetSolarMutex() ); 735 736 SwTxtNode & rTxtNode(GetTxtNodeOrThrow()); 737 738 // #i46786# Use SwAttrSet pointer for determining the state. 739 // Use the value SwAttrSet (from the paragraph OR the style) 740 // for determining the actual value(s). 741 const SwAttrSet* pAttrSet = rTxtNode.GetpSwAttrSet(); 742 const SwAttrSet& rValueAttrSet = rTxtNode.GetSwAttrSet(); 743 744 sal_Int32 nProps = rPropertyNames.getLength(); 745 const OUString *pProp = rPropertyNames.getConstArray(); 746 747 uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( nProps ); 748 beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray(); 749 sal_Int32 nIdx = 0; 750 751 // get entry to start with 752 SfxItemPropertyMap const*const pPropMap = m_rPropSet.getPropertyMap(); 753 754 for (sal_Int32 i = 0; i < nProps; ++i) 755 { 756 DBG_ASSERT( nIdx < nProps, "index out ouf bounds" ); 757 beans::GetDirectPropertyTolerantResult &rResult = pResult[nIdx]; 758 759 try 760 { 761 rResult.Name = pProp[i]; 762 763 SfxItemPropertySimpleEntry const*const pEntry = 764 pPropMap->getByName( pProp[i] ); 765 if (!pEntry) // property available? 766 { 767 rResult.Result = 768 beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY; 769 } 770 else 771 { 772 // get property state 773 // (compare to SwXParagraph::getPropertyState) 774 sal_Bool bAttrSetFetched = sal_True; 775 beans::PropertyState eState = lcl_SwXParagraph_getPropertyState( 776 rTxtNode, &pAttrSet, *pEntry, bAttrSetFetched ); 777 rResult.State = eState; 778 779 // if (bDirectValuesOnly && PropertyState_DIRECT_VALUE != eState) 780 // rResult.Result = beans::TolerantPropertySetResultType::NO_DIRECT_VALUE; 781 // else 782 rResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_FAILURE; 783 if (!bDirectValuesOnly || 784 (beans::PropertyState_DIRECT_VALUE == eState)) 785 { 786 // get property value 787 // (compare to SwXParagraph::getPropertyValue(s)) 788 uno::Any aValue; 789 if (! ::sw::GetDefaultTextContentValue( 790 aValue, pProp[i], pEntry->nWID ) ) 791 { 792 SwPosition aPos( rTxtNode ); 793 SwPaM aPam( aPos ); 794 // handle properties that are not part of the attribute 795 // and thus only pretendend to be paragraph attributes 796 beans::PropertyState eTemp; 797 const bool bDone = 798 SwUnoCursorHelper::getCrsrPropertyValue( 799 *pEntry, aPam, &aValue, eTemp, &rTxtNode ); 800 801 // if not found try the real paragraph attributes... 802 if (!bDone) 803 { 804 m_rPropSet.getPropertyValue( 805 *pEntry, rValueAttrSet, aValue ); 806 } 807 } 808 809 rResult.Value = aValue; 810 rResult.Result = beans::TolerantPropertySetResultType::SUCCESS; 811 812 nIdx++; 813 } 814 // this assertion should never occur! 815 DBG_ASSERT( nIdx < 1 || pResult[nIdx - 1].Result != beans::TolerantPropertySetResultType::UNKNOWN_FAILURE, 816 "unknown failure while retrieving property" ); 817 818 } 819 } 820 catch (beans::UnknownPropertyException &) 821 { 822 // should not occur because property was searched for before 823 DBG_ERROR( "unexpected exception caught" ); 824 rResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY; 825 } 826 catch (lang::IllegalArgumentException &) 827 { 828 rResult.Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT; 829 } 830 catch (beans::PropertyVetoException &) 831 { 832 rResult.Result = beans::TolerantPropertySetResultType::PROPERTY_VETO; 833 } 834 catch (lang::WrappedTargetException &) 835 { 836 rResult.Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET; 837 } 838 } 839 840 // resize to actually used size 841 aResult.realloc( nIdx ); 842 843 return aResult; 844 } 845 846 /* -----------------------------12.09.00 11:09-------------------------------- 847 848 ---------------------------------------------------------------------------*/ 849 bool ::sw::GetDefaultTextContentValue( 850 uno::Any& rAny, const OUString& rPropertyName, sal_uInt16 nWID) 851 { 852 if(!nWID) 853 { 854 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_ANCHOR_TYPE))) 855 nWID = FN_UNO_ANCHOR_TYPE; 856 else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_ANCHOR_TYPES))) 857 nWID = FN_UNO_ANCHOR_TYPES; 858 else if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_TEXT_WRAP))) 859 nWID = FN_UNO_TEXT_WRAP; 860 else 861 return sal_False; 862 } 863 864 switch(nWID) 865 { 866 case FN_UNO_TEXT_WRAP: rAny <<= text::WrapTextMode_NONE; break; 867 case FN_UNO_ANCHOR_TYPE: rAny <<= text::TextContentAnchorType_AT_PARAGRAPH; break; 868 case FN_UNO_ANCHOR_TYPES: 869 { uno::Sequence<text::TextContentAnchorType> aTypes(1); 870 text::TextContentAnchorType* pArray = aTypes.getArray(); 871 pArray[0] = text::TextContentAnchorType_AT_PARAGRAPH; 872 rAny.setValue(&aTypes, ::getCppuType((uno::Sequence<text::TextContentAnchorType>*)0)); 873 } 874 break; 875 default: 876 return sal_False; 877 } 878 return sal_True; 879 } 880 /*-- 11.12.98 08:12:50--------------------------------------------------- 881 882 -----------------------------------------------------------------------*/ 883 void SAL_CALL 884 SwXParagraph::addPropertyChangeListener( 885 const ::rtl::OUString& /*rPropertyName*/, 886 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 887 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 888 uno::RuntimeException) 889 { 890 OSL_ENSURE(false, 891 "SwXParagraph::addPropertyChangeListener(): not implemented"); 892 } 893 894 /*-- 11.12.98 08:12:50--------------------------------------------------- 895 896 -----------------------------------------------------------------------*/ 897 void SAL_CALL 898 SwXParagraph::removePropertyChangeListener( 899 const ::rtl::OUString& /*rPropertyName*/, 900 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/) 901 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 902 uno::RuntimeException) 903 { 904 OSL_ENSURE(false, 905 "SwXParagraph::removePropertyChangeListener(): not implemented"); 906 } 907 908 /*-- 11.12.98 08:12:50--------------------------------------------------- 909 910 -----------------------------------------------------------------------*/ 911 void SAL_CALL 912 SwXParagraph::addVetoableChangeListener( 913 const ::rtl::OUString& /*rPropertyName*/, 914 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 915 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 916 uno::RuntimeException) 917 { 918 OSL_ENSURE(false, 919 "SwXParagraph::addVetoableChangeListener(): not implemented"); 920 } 921 922 /*-- 11.12.98 08:12:51--------------------------------------------------- 923 924 -----------------------------------------------------------------------*/ 925 void SAL_CALL 926 SwXParagraph::removeVetoableChangeListener( 927 const ::rtl::OUString& /*rPropertyName*/, 928 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/) 929 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 930 uno::RuntimeException) 931 { 932 OSL_ENSURE(false, 933 "SwXParagraph::removeVetoableChangeListener(): not implemented"); 934 } 935 936 //----------------------------------------------------------------------------- 937 beans::PropertyState lcl_SwXParagraph_getPropertyState( 938 // SwUnoCrsr& rUnoCrsr, 939 const SwTxtNode& rTxtNode, 940 const SwAttrSet** ppSet, 941 const SfxItemPropertySimpleEntry& rEntry, 942 sal_Bool &rAttrSetFetched ) 943 throw (beans::UnknownPropertyException) 944 { 945 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE; 946 947 if(!(*ppSet) && !rAttrSetFetched ) 948 { 949 (*ppSet) = rTxtNode.GetpSwAttrSet(); 950 rAttrSetFetched = sal_True; 951 } 952 SwPosition aPos( rTxtNode ); 953 SwPaM aPam( aPos ); 954 switch( rEntry.nWID ) 955 { 956 case FN_UNO_NUM_RULES: 957 // if numbering is set, return it; else do nothing 958 SwUnoCursorHelper::getNumberingProperty( aPam, eRet, NULL ); 959 break; 960 case FN_UNO_ANCHOR_TYPES: 961 break; 962 case RES_ANCHOR: 963 if ( MID_SURROUND_SURROUNDTYPE != rEntry.nMemberId ) 964 goto lcl_SwXParagraph_getPropertyStateDEFAULT; 965 break; 966 case RES_SURROUND: 967 if ( MID_ANCHOR_ANCHORTYPE != rEntry.nMemberId ) 968 goto lcl_SwXParagraph_getPropertyStateDEFAULT; 969 break; 970 case FN_UNO_PARA_STYLE: 971 case FN_UNO_PARA_CONDITIONAL_STYLE_NAME: 972 { 973 SwFmtColl* pFmt = SwUnoCursorHelper::GetCurTxtFmtColl( 974 aPam, rEntry.nWID == FN_UNO_PARA_CONDITIONAL_STYLE_NAME); 975 eRet = pFmt ? beans::PropertyState_DIRECT_VALUE 976 : beans::PropertyState_AMBIGUOUS_VALUE; 977 } 978 break; 979 case FN_UNO_PAGE_STYLE: 980 { 981 String sVal; 982 SwUnoCursorHelper::GetCurPageStyle( aPam, sVal ); 983 eRet = sVal.Len() ? beans::PropertyState_DIRECT_VALUE 984 : beans::PropertyState_AMBIGUOUS_VALUE; 985 } 986 break; 987 lcl_SwXParagraph_getPropertyStateDEFAULT: 988 default: 989 if((*ppSet) && SFX_ITEM_SET == (*ppSet)->GetItemState(rEntry.nWID, sal_False)) 990 eRet = beans::PropertyState_DIRECT_VALUE; 991 break; 992 } 993 return eRet; 994 } 995 996 /*-- 05.03.99 11:37:30--------------------------------------------------- 997 998 -----------------------------------------------------------------------*/ 999 beans::PropertyState SAL_CALL 1000 SwXParagraph::getPropertyState(const OUString& rPropertyName) 1001 throw (beans::UnknownPropertyException, uno::RuntimeException) 1002 { 1003 vos::OGuard aGuard(Application::GetSolarMutex()); 1004 1005 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1006 1007 const SwAttrSet* pSet = 0; 1008 SfxItemPropertySimpleEntry const*const pEntry = 1009 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 1010 if (!pEntry) 1011 { 1012 throw beans::UnknownPropertyException( 1013 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 1014 + rPropertyName, 1015 static_cast<cppu::OWeakObject *>(this)); 1016 } 1017 sal_Bool bDummy = sal_False; 1018 const beans::PropertyState eRet = 1019 lcl_SwXParagraph_getPropertyState(rTxtNode, &pSet, *pEntry, bDummy); 1020 return eRet; 1021 } 1022 /*-- 05.03.99 11:37:32--------------------------------------------------- 1023 1024 -----------------------------------------------------------------------*/ 1025 1026 uno::Sequence< beans::PropertyState > SAL_CALL 1027 SwXParagraph::getPropertyStates( 1028 const uno::Sequence< OUString >& PropertyNames) 1029 throw (beans::UnknownPropertyException, uno::RuntimeException) 1030 { 1031 vos::OGuard aGuard(Application::GetSolarMutex()); 1032 1033 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1034 1035 const OUString* pNames = PropertyNames.getConstArray(); 1036 uno::Sequence< beans::PropertyState > aRet(PropertyNames.getLength()); 1037 beans::PropertyState* pStates = aRet.getArray(); 1038 SfxItemPropertyMap const*const pMap = m_pImpl->m_rPropSet.getPropertyMap(); 1039 const SwAttrSet* pSet = 0; 1040 sal_Bool bAttrSetFetched = sal_False; 1041 1042 for (sal_Int32 i = 0, nEnd = PropertyNames.getLength(); i < nEnd; 1043 ++i, ++pStates, ++pNames) 1044 { 1045 SfxItemPropertySimpleEntry const*const pEntry = 1046 pMap->getByName( *pNames ); 1047 if (!pEntry) 1048 { 1049 throw beans::UnknownPropertyException( 1050 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 1051 + *pNames, 1052 static_cast<cppu::OWeakObject *>(this)); 1053 } 1054 1055 if (bAttrSetFetched && !pSet && isATR(pEntry->nWID)) 1056 { 1057 *pStates = beans::PropertyState_DEFAULT_VALUE; 1058 } 1059 else 1060 { 1061 *pStates = lcl_SwXParagraph_getPropertyState( 1062 rTxtNode, &pSet, *pEntry, bAttrSetFetched ); 1063 } 1064 } 1065 1066 return aRet; 1067 } 1068 1069 /*-- 05.03.99 11:37:33--------------------------------------------------- 1070 1071 -----------------------------------------------------------------------*/ 1072 void SAL_CALL 1073 SwXParagraph::setPropertyToDefault(const OUString& rPropertyName) 1074 throw (beans::UnknownPropertyException, uno::RuntimeException) 1075 { 1076 vos::OGuard aGuard(Application::GetSolarMutex()); 1077 1078 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1079 1080 SwPosition aPos( rTxtNode ); 1081 SwCursor aCursor( aPos, 0, false ); 1082 if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_ANCHOR_TYPE)) || 1083 rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_ANCHOR_TYPES)) || 1084 rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_TEXT_WRAP))) 1085 { 1086 return; 1087 } 1088 1089 // select paragraph 1090 SwParaSelection aParaSel( aCursor ); 1091 SfxItemPropertySimpleEntry const*const pEntry = 1092 m_pImpl->m_rPropSet.getPropertyMap()->getByName( rPropertyName ); 1093 if (!pEntry) 1094 { 1095 throw beans::UnknownPropertyException( 1096 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 1097 + rPropertyName, 1098 static_cast<cppu::OWeakObject *>(this)); 1099 } 1100 1101 if (pEntry->nFlags & beans::PropertyAttribute::READONLY) 1102 { 1103 throw uno::RuntimeException( 1104 OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: ")) 1105 + rPropertyName, 1106 static_cast<cppu::OWeakObject *>(this)); 1107 } 1108 1109 if (pEntry->nWID < RES_FRMATR_END) 1110 { 1111 SvUShortsSort aWhichIds; 1112 aWhichIds.Insert(pEntry->nWID); 1113 if (pEntry->nWID < RES_PARATR_BEGIN) 1114 { 1115 aCursor.GetDoc()->ResetAttrs(aCursor, sal_True, &aWhichIds); 1116 } 1117 else 1118 { 1119 // for paragraph attributes the selection must be extended 1120 // to paragraph boundaries 1121 SwPosition aStart( *aCursor.Start() ); 1122 SwPosition aEnd ( *aCursor.End() ); 1123 ::std::auto_ptr<SwUnoCrsr> pTemp( 1124 aCursor.GetDoc()->CreateUnoCrsr(aStart, sal_False) ); 1125 if(!SwUnoCursorHelper::IsStartOfPara(*pTemp)) 1126 { 1127 pTemp->MovePara(fnParaCurr, fnParaStart); 1128 } 1129 pTemp->SetMark(); 1130 *pTemp->GetPoint() = aEnd; 1131 //pTemp->Exchange(); 1132 SwUnoCursorHelper::SelectPam(*pTemp, true); 1133 if (!SwUnoCursorHelper::IsEndOfPara(*pTemp)) 1134 { 1135 pTemp->MovePara(fnParaCurr, fnParaEnd); 1136 } 1137 pTemp->GetDoc()->ResetAttrs(*pTemp, sal_True, &aWhichIds); 1138 } 1139 } 1140 else 1141 { 1142 SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, aCursor); 1143 } 1144 } 1145 1146 /*-- 05.03.99 11:37:33--------------------------------------------------- 1147 1148 -----------------------------------------------------------------------*/ 1149 uno::Any SAL_CALL 1150 SwXParagraph::getPropertyDefault(const OUString& rPropertyName) 1151 throw (beans::UnknownPropertyException, lang::WrappedTargetException, 1152 uno::RuntimeException) 1153 { 1154 vos::OGuard g(Application::GetSolarMutex()); 1155 1156 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1157 1158 uno::Any aRet; 1159 if (::sw::GetDefaultTextContentValue(aRet, rPropertyName)) 1160 { 1161 return aRet; 1162 } 1163 1164 SfxItemPropertySimpleEntry const*const pEntry = 1165 m_pImpl->m_rPropSet.getPropertyMap()->getByName(rPropertyName); 1166 if (!pEntry) 1167 { 1168 throw beans::UnknownPropertyException( 1169 OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: ")) 1170 + rPropertyName, 1171 static_cast<cppu::OWeakObject *>(this)); 1172 } 1173 1174 if (pEntry->nWID < RES_FRMATR_END) 1175 { 1176 const SfxPoolItem& rDefItem = 1177 rTxtNode.GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID); 1178 rDefItem.QueryValue(aRet, pEntry->nMemberId); 1179 } 1180 1181 return aRet; 1182 } 1183 1184 /*-- 11.12.98 08:12:51--------------------------------------------------- 1185 1186 -----------------------------------------------------------------------*/ 1187 void SAL_CALL 1188 SwXParagraph::attach(const uno::Reference< text::XTextRange > & /*xTextRange*/) 1189 throw (lang::IllegalArgumentException, uno::RuntimeException) 1190 { 1191 vos::OGuard aGuard(Application::GetSolarMutex()); 1192 // SwXParagraph will only created in order to be inserted by 1193 // 'insertTextContentBefore' or 'insertTextContentAfter' therefore 1194 // they cannot be attached 1195 throw uno::RuntimeException(); 1196 } 1197 1198 /*-- 11.12.98 08:12:51--------------------------------------------------- 1199 1200 -----------------------------------------------------------------------*/ 1201 uno::Reference< text::XTextRange > SAL_CALL 1202 SwXParagraph::getAnchor() throw (uno::RuntimeException) 1203 { 1204 vos::OGuard aGuard(Application::GetSolarMutex()); 1205 1206 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1207 1208 SwPosition aPos( rTxtNode ); 1209 SwCursor aCursor( aPos, 0, false ); 1210 // select paragraph 1211 SwParaSelection aParaSel( aCursor ); 1212 const uno::Reference< text::XTextRange > xRet = 1213 new SwXTextRange(aCursor, m_pImpl->m_xParentText); 1214 return xRet; 1215 } 1216 1217 /*-- 11.12.98 08:12:52--------------------------------------------------- 1218 1219 -----------------------------------------------------------------------*/ 1220 void SAL_CALL SwXParagraph::dispose() throw (uno::RuntimeException) 1221 { 1222 vos::OGuard aGuard(Application::GetSolarMutex()); 1223 1224 SwTxtNode *const pTxtNode( m_pImpl->GetTxtNode() ); 1225 if (pTxtNode) 1226 { 1227 SwCursor aCursor( SwPosition( *pTxtNode ), 0, false ); 1228 // select paragraph 1229 { 1230 SwParaSelection aParaSel( aCursor ); 1231 pTxtNode->GetDoc()->DelFullPara(aCursor); 1232 } 1233 m_pImpl->m_ListenerContainer.Disposing(); 1234 } 1235 } 1236 1237 /*-- 11.12.98 08:12:52--------------------------------------------------- 1238 1239 -----------------------------------------------------------------------*/ 1240 void SAL_CALL SwXParagraph::addEventListener( 1241 const uno::Reference< lang::XEventListener > & xListener) 1242 throw (uno::RuntimeException) 1243 { 1244 vos::OGuard g(Application::GetSolarMutex()); 1245 1246 if (!m_pImpl->GetTxtNode()) 1247 { 1248 throw uno::RuntimeException(); 1249 } 1250 m_pImpl->m_ListenerContainer.AddListener(xListener); 1251 } 1252 /*-- 11.12.98 08:12:53--------------------------------------------------- 1253 1254 -----------------------------------------------------------------------*/ 1255 void SAL_CALL SwXParagraph::removeEventListener( 1256 const uno::Reference< lang::XEventListener > & xListener) 1257 throw (uno::RuntimeException) 1258 { 1259 vos::OGuard g(Application::GetSolarMutex()); 1260 1261 if (!m_pImpl->GetTxtNode() || 1262 !m_pImpl->m_ListenerContainer.RemoveListener(xListener)) 1263 { 1264 throw uno::RuntimeException(); 1265 } 1266 } 1267 1268 /*-- 11.12.98 08:12:53--------------------------------------------------- 1269 1270 -----------------------------------------------------------------------*/ 1271 uno::Reference< container::XEnumeration > SAL_CALL 1272 SwXParagraph::createEnumeration() throw (uno::RuntimeException) 1273 { 1274 vos::OGuard aGuard(Application::GetSolarMutex()); 1275 1276 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1277 1278 SwPosition aPos( rTxtNode ); 1279 SwPaM aPam ( aPos ); 1280 const uno::Reference< container::XEnumeration > xRef = 1281 new SwXTextPortionEnumeration(aPam, m_pImpl->m_xParentText, 1282 m_pImpl->m_nSelectionStartPos, m_pImpl->m_nSelectionEndPos); 1283 return xRef; 1284 } 1285 1286 /*-- 11.12.98 08:12:54--------------------------------------------------- 1287 1288 -----------------------------------------------------------------------*/ 1289 uno::Type SAL_CALL SwXParagraph::getElementType() throw (uno::RuntimeException) 1290 { 1291 return text::XTextRange::static_type(); 1292 } 1293 /*-- 11.12.98 08:12:54--------------------------------------------------- 1294 1295 -----------------------------------------------------------------------*/ 1296 sal_Bool SAL_CALL SwXParagraph::hasElements() throw (uno::RuntimeException) 1297 { 1298 vos::OGuard aGuard(Application::GetSolarMutex()); 1299 return (GetTxtNode()) ? sal_True : sal_False; 1300 } 1301 1302 /*-- 11.12.98 08:12:55--------------------------------------------------- 1303 1304 -----------------------------------------------------------------------*/ 1305 uno::Reference< text::XText > SAL_CALL 1306 SwXParagraph::getText() throw (uno::RuntimeException) 1307 { 1308 vos::OGuard g(Application::GetSolarMutex()); 1309 1310 return m_pImpl->m_xParentText; 1311 } 1312 1313 /*-- 11.12.98 08:12:55--------------------------------------------------- 1314 1315 -----------------------------------------------------------------------*/ 1316 uno::Reference< text::XTextRange > SAL_CALL 1317 SwXParagraph::getStart() throw (uno::RuntimeException) 1318 { 1319 vos::OGuard aGuard(Application::GetSolarMutex()); 1320 1321 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1322 1323 SwPosition aPos( rTxtNode ); 1324 SwCursor aCursor( aPos, 0, false ); 1325 SwParaSelection aParaSel( aCursor ); 1326 SwPaM aPam( *aCursor.Start() ); 1327 uno::Reference< text::XText > xParent = getText(); 1328 const uno::Reference< text::XTextRange > xRet = 1329 new SwXTextRange(aPam, xParent); 1330 return xRet; 1331 } 1332 /*-- 11.12.98 08:12:56--------------------------------------------------- 1333 1334 -----------------------------------------------------------------------*/ 1335 uno::Reference< text::XTextRange > SAL_CALL 1336 SwXParagraph::getEnd() throw (uno::RuntimeException) 1337 { 1338 vos::OGuard aGuard(Application::GetSolarMutex()); 1339 1340 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1341 1342 SwPosition aPos( rTxtNode ); 1343 SwCursor aCursor( aPos, 0, false ); 1344 SwParaSelection aParaSel( aCursor ); 1345 SwPaM aPam( *aCursor.End() ); 1346 uno::Reference< text::XText > xParent = getText(); 1347 const uno::Reference< text::XTextRange > xRet = 1348 new SwXTextRange(aPam, xParent); 1349 return xRet; 1350 } 1351 1352 /*-- 11.12.98 08:12:56--------------------------------------------------- 1353 1354 -----------------------------------------------------------------------*/ 1355 OUString SAL_CALL SwXParagraph::getString() throw (uno::RuntimeException) 1356 { 1357 vos::OGuard aGuard(Application::GetSolarMutex()); 1358 OUString aRet; 1359 SwTxtNode const*const pTxtNode( GetTxtNode() ); 1360 if (pTxtNode) 1361 { 1362 SwPosition aPos( *pTxtNode ); 1363 SwCursor aCursor( aPos, 0, false ); 1364 SwParaSelection aParaSel( aCursor ); 1365 SwUnoCursorHelper::GetTextFromPam(aCursor, aRet); 1366 } 1367 else if (m_pImpl->IsDescriptor()) 1368 { 1369 aRet = m_pImpl->m_sText; 1370 } 1371 else 1372 { 1373 throw uno::RuntimeException(); 1374 } 1375 return aRet; 1376 } 1377 /*-- 11.12.98 08:12:57--------------------------------------------------- 1378 1379 -----------------------------------------------------------------------*/ 1380 void SAL_CALL SwXParagraph::setString(const OUString& aString) 1381 throw (uno::RuntimeException) 1382 { 1383 vos::OGuard aGuard(Application::GetSolarMutex()); 1384 1385 SwTxtNode const*const pTxtNode( GetTxtNode() ); 1386 if (pTxtNode) 1387 { 1388 SwPosition aPos( *pTxtNode ); 1389 SwCursor aCursor( aPos, 0, false ); 1390 if (!SwUnoCursorHelper::IsStartOfPara(aCursor)) { 1391 aCursor.MovePara(fnParaCurr, fnParaStart); 1392 } 1393 SwUnoCursorHelper::SelectPam(aCursor, true); 1394 if (pTxtNode->GetTxt().Len()) { 1395 aCursor.MovePara(fnParaCurr, fnParaEnd); 1396 } 1397 SwUnoCursorHelper::SetString(aCursor, aString); 1398 SwUnoCursorHelper::SelectPam(aCursor, false); 1399 } 1400 else if (m_pImpl->IsDescriptor()) 1401 { 1402 m_pImpl->m_sText = aString; 1403 } 1404 else 1405 { 1406 throw uno::RuntimeException(); 1407 } 1408 } 1409 1410 /* -----------------23.03.99 12:49------------------- 1411 * 1412 * --------------------------------------------------*/ 1413 uno::Reference< container::XEnumeration > SAL_CALL 1414 SwXParagraph::createContentEnumeration(const OUString& rServiceName) 1415 throw (uno::RuntimeException) 1416 { 1417 vos::OGuard g(Application::GetSolarMutex()); 1418 1419 if (!rServiceName.equalsAscii("com.sun.star.text.TextContent")) 1420 { 1421 throw uno::RuntimeException(); 1422 } 1423 1424 SwTxtNode & rTxtNode(m_pImpl->GetTxtNodeOrThrow()); 1425 1426 SwPosition aPos( rTxtNode ); 1427 SwPaM aPam( aPos ); 1428 uno::Reference< container::XEnumeration > xRet = 1429 new SwXParaFrameEnumeration(aPam, PARAFRAME_PORTION_PARAGRAPH); 1430 return xRet; 1431 } 1432 /* -----------------23.03.99 12:49------------------- 1433 * 1434 * --------------------------------------------------*/ 1435 uno::Sequence< OUString > SAL_CALL 1436 SwXParagraph::getAvailableServiceNames() throw (uno::RuntimeException) 1437 { 1438 uno::Sequence< OUString > aRet(1); 1439 OUString* pArray = aRet.getArray(); 1440 pArray[0] = C2U("com.sun.star.text.TextContent"); 1441 return aRet; 1442 } 1443 1444 1445 // MetadatableMixin 1446 ::sfx2::Metadatable* SwXParagraph::GetCoreObject() 1447 { 1448 SwTxtNode *const pTxtNode( m_pImpl->GetTxtNode() ); 1449 return pTxtNode; 1450 } 1451 1452 uno::Reference<frame::XModel> SwXParagraph::GetModel() 1453 { 1454 SwTxtNode *const pTxtNode( m_pImpl->GetTxtNode() ); 1455 if (pTxtNode) 1456 { 1457 SwDocShell const*const pShell( pTxtNode->GetDoc()->GetDocShell() ); 1458 return (pShell) ? pShell->GetModel() : 0; 1459 } 1460 return 0; 1461 } 1462 1463