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