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