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