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