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