Update ooo320-m1
[ooovba.git] / sw / source / core / unocore / unoport.cxx
blob8671230214526c955509b3ff1ef51b70e1b08f86
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoport.cxx,v $
10 * $Revision: 1.43 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <cmdid.h>
36 #include <vos/mutex.hxx>
37 #include <vcl/svapp.hxx>
38 #include <svtools/itemprop.hxx>
39 #include <unocrsrhelper.hxx>
40 #include <unoport.hxx>
41 #include <unoobj.hxx>
42 #include <unomap.hxx>
43 #include <unoprnms.hxx>
44 #include <unomid.h>
45 #include <txtatr.hxx>
46 #include <txtfld.hxx>
47 #include <ndtxt.hxx>
48 #include <doc.hxx>
49 #include <fmtflcnt.hxx>
50 #include <fmtfld.hxx>
52 #include <com/sun/star/beans/PropertyAttribute.hpp>
53 #include <com/sun/star/beans/SetPropertyTolerantFailed.hpp>
54 #include <com/sun/star/beans/GetPropertyTolerantResult.hpp>
55 #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
58 using namespace ::com::sun::star;
59 using ::rtl::OUString;
62 /******************************************************************
63 * SwXTextPortion
64 ******************************************************************/
66 static void init(SwXTextPortion & rPortion, const SwUnoCrsr* pPortionCursor)
68 SwUnoCrsr* pUnoCursor =
69 pPortionCursor->GetDoc()->CreateUnoCrsr(*pPortionCursor->GetPoint());
70 if (pPortionCursor->HasMark())
72 pUnoCursor->SetMark();
73 *pUnoCursor->GetMark() = *pPortionCursor->GetMark();
75 pUnoCursor->Add(& rPortion);
78 /*-- 11.12.98 09:56:55---------------------------------------------------
80 -----------------------------------------------------------------------*/
81 SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
82 uno::Reference< text::XText > const& rParent,
83 SwTextPortionType eType)
84 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
85 , m_pPropSet(aSwMapProvider.GetPropertySet(
86 (PORTION_REDLINE_START == eType ||
87 PORTION_REDLINE_END == eType)
88 ? PROPERTY_MAP_REDLINE_PORTION
89 : PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
90 , m_xParentText(rParent)
91 , m_pRubyText(0)
92 , m_pRubyStyle(0)
93 , m_pRubyAdjust(0)
94 , m_pRubyIsAbove(0)
95 , m_FrameDepend(this, 0)
96 , m_pFrameFmt(0)
97 , m_ePortionType(eType)
98 , m_bIsCollapsed(false)
100 init(*this, pPortionCrsr);
103 /* -----------------24.03.99 16:30-------------------
105 * --------------------------------------------------*/
106 SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
107 uno::Reference< text::XText > const& rParent,
108 SwFrmFmt& rFmt )
109 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
110 , m_pPropSet(aSwMapProvider.GetPropertySet(
111 PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
112 , m_xParentText(rParent)
113 , m_pRubyText(0)
114 , m_pRubyStyle(0)
115 , m_pRubyAdjust(0)
116 , m_pRubyIsAbove(0)
117 , m_FrameDepend(this, &rFmt)
118 , m_pFrameFmt(&rFmt)
119 , m_ePortionType(PORTION_FRAME)
120 , m_bIsCollapsed(false)
122 init(*this, pPortionCrsr);
125 /* -----------------------------19.02.01 10:52--------------------------------
127 ---------------------------------------------------------------------------*/
128 SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
129 SwTxtRuby const& rAttr,
130 uno::Reference< text::XText > const& xParent,
131 sal_Bool bIsEnd )
132 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
133 , m_pPropSet(aSwMapProvider.GetPropertySet(
134 PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
135 , m_xParentText(xParent)
136 , m_pRubyText ( bIsEnd ? 0 : new uno::Any )
137 , m_pRubyStyle ( bIsEnd ? 0 : new uno::Any )
138 , m_pRubyAdjust ( bIsEnd ? 0 : new uno::Any )
139 , m_pRubyIsAbove( bIsEnd ? 0 : new uno::Any )
140 , m_FrameDepend(this, 0)
141 , m_pFrameFmt(0)
142 , m_ePortionType( bIsEnd ? PORTION_RUBY_END : PORTION_RUBY_START )
143 , m_bIsCollapsed(false)
145 init(*this, pPortionCrsr);
147 if (!bIsEnd)
149 const SfxPoolItem& rItem = rAttr.GetAttr();
150 rItem.QueryValue(*m_pRubyText, MID_RUBY_TEXT);
151 rItem.QueryValue(*m_pRubyStyle, MID_RUBY_CHARSTYLE);
152 rItem.QueryValue(*m_pRubyAdjust, MID_RUBY_ADJUST);
153 rItem.QueryValue(*m_pRubyIsAbove, MID_RUBY_ABOVE);
157 /*-- 11.12.98 09:56:55---------------------------------------------------
159 -----------------------------------------------------------------------*/
160 SwXTextPortion::~SwXTextPortion()
162 vos::OGuard aGuard(Application::GetSolarMutex());
163 SwUnoCrsr* pUnoCrsr = GetCursor();
164 delete pUnoCrsr;
166 /*-- 11.12.98 09:56:56---------------------------------------------------
168 -----------------------------------------------------------------------*/
169 uno::Reference< text::XText > SwXTextPortion::getText()
170 throw( uno::RuntimeException )
172 return m_xParentText;
174 /*-- 11.12.98 09:56:56---------------------------------------------------
176 -----------------------------------------------------------------------*/
177 uno::Reference< text::XTextRange > SwXTextPortion::getStart()
178 throw( uno::RuntimeException )
180 vos::OGuard aGuard(Application::GetSolarMutex());
181 uno::Reference< text::XTextRange > xRet;
182 SwUnoCrsr* pUnoCrsr = GetCursor();
183 if (!pUnoCrsr)
184 throw uno::RuntimeException();
186 SwPaM aPam(*pUnoCrsr->Start());
187 uno::Reference< text::XText > xParent = getText();
188 xRet = new SwXTextRange(aPam, xParent);
189 return xRet;
191 /*-- 11.12.98 09:56:57---------------------------------------------------
193 -----------------------------------------------------------------------*/
194 uno::Reference< text::XTextRange > SwXTextPortion::getEnd()
195 throw( uno::RuntimeException )
197 vos::OGuard aGuard(Application::GetSolarMutex());
198 uno::Reference< text::XTextRange > xRet;
199 SwUnoCrsr* pUnoCrsr = GetCursor();
200 if (!pUnoCrsr)
201 throw uno::RuntimeException();
203 SwPaM aPam(*pUnoCrsr->End());
204 uno::Reference< text::XText > xParent = getText();
205 xRet = new SwXTextRange(aPam, xParent);
206 return xRet;
208 /*-- 11.12.98 09:56:57---------------------------------------------------
210 -----------------------------------------------------------------------*/
211 OUString SwXTextPortion::getString()
212 throw( uno::RuntimeException )
214 vos::OGuard aGuard(Application::GetSolarMutex());
215 OUString aTxt;
216 SwUnoCrsr* pUnoCrsr = GetCursor();
217 if (!pUnoCrsr)
218 throw uno::RuntimeException();
220 // TextPortions are always within a paragraph
221 SwTxtNode* pTxtNd = pUnoCrsr->GetNode()->GetTxtNode();
222 if ( pTxtNd )
224 xub_StrLen nStt = pUnoCrsr->Start()->nContent.GetIndex();
225 aTxt = pTxtNd->GetExpandTxt( nStt,
226 pUnoCrsr->End()->nContent.GetIndex() - nStt );
228 return aTxt;
230 /*-- 11.12.98 09:56:57---------------------------------------------------
232 -----------------------------------------------------------------------*/
233 void SwXTextPortion::setString(const OUString& aString) throw( uno::RuntimeException )
235 vos::OGuard aGuard(Application::GetSolarMutex());
236 SwUnoCrsr* pUnoCrsr = GetCursor();
237 if (!pUnoCrsr)
238 throw uno::RuntimeException();
240 SwXTextCursor::SetString(*pUnoCrsr, aString);
242 /*-- 11.12.98 09:56:57---------------------------------------------------
244 -----------------------------------------------------------------------*/
245 uno::Reference< beans::XPropertySetInfo > SwXTextPortion::getPropertySetInfo()
246 throw( uno::RuntimeException )
248 vos::OGuard aGuard(Application::GetSolarMutex());
249 //! PropertySetInfo for text portion extensions
250 static uno::Reference< beans::XPropertySetInfo >
251 xTxtPorExtRef = aSwMapProvider.GetPropertySet(
252 PROPERTY_MAP_TEXTPORTION_EXTENSIONS)->getPropertySetInfo();
253 //! PropertySetInfo for redline portions
254 static uno::Reference< beans::XPropertySetInfo >
255 xRedlPorRef = aSwMapProvider.GetPropertySet(
256 PROPERTY_MAP_REDLINE_PORTION)->getPropertySetInfo();
258 return (PORTION_REDLINE_START == m_ePortionType ||
259 PORTION_REDLINE_END == m_ePortionType) ? xRedlPorRef : xTxtPorExtRef;
261 /*-- 11.12.98 09:56:57---------------------------------------------------
263 -----------------------------------------------------------------------*/
264 void SwXTextPortion::setPropertyValue(const OUString& rPropertyName,
265 const uno::Any& aValue)
266 throw( beans::UnknownPropertyException,
267 beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
269 vos::OGuard aGuard(Application::GetSolarMutex());
270 SwUnoCrsr* pUnoCrsr = GetCursor();
271 if (!pUnoCrsr)
272 throw uno::RuntimeException();
274 SwXTextCursor::SetPropertyValue(*pUnoCrsr, *m_pPropSet,
275 rPropertyName, aValue);
277 /*-- 04.11.03 09:56:58---------------------------------------------------
279 -----------------------------------------------------------------------*/
280 void SwXTextPortion::GetPropertyValue(
281 uno::Any &rVal,
282 const SfxItemPropertySimpleEntry& rEntry,
283 SwUnoCrsr *pUnoCrsr,
284 SfxItemSet *&pSet )
286 DBG_ASSERT( pUnoCrsr, "UNO cursor missing" );
287 if (!pUnoCrsr)
288 return;
289 if(pUnoCrsr)
291 switch(rEntry.nWID)
293 case FN_UNO_TEXT_PORTION_TYPE:
295 const char* pRet;
296 switch (m_ePortionType)
298 case PORTION_TEXT: pRet = "Text";break;
299 case PORTION_FIELD: pRet = "TextField";break;
300 case PORTION_FRAME: pRet = "Frame";break;
301 case PORTION_FOOTNOTE: pRet = "Footnote";break;
302 case PORTION_REFMARK_START:
303 case PORTION_REFMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_REFERENCE_MARK);break;
304 case PORTION_TOXMARK_START:
305 case PORTION_TOXMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_DOCUMENT_INDEX_MARK);break;
306 case PORTION_BOOKMARK_START :
307 case PORTION_BOOKMARK_END : pRet = SW_PROP_NAME_STR(UNO_NAME_BOOKMARK);break;
308 case PORTION_REDLINE_START:
309 case PORTION_REDLINE_END: pRet = "Redline";break;
310 case PORTION_RUBY_START:
311 case PORTION_RUBY_END: pRet = "Ruby";break;
312 case PORTION_SOFT_PAGEBREAK:pRet = "SoftPageBreak";break;
313 case PORTION_META: pRet = SW_PROP_NAME_STR(UNO_NAME_META); break;
314 case PORTION_FIELD_START:pRet = "TextFieldStart";break;
315 case PORTION_FIELD_END:pRet = "TextFieldEnd";break;
316 case PORTION_FIELD_START_END:pRet = "TextFieldStartEnd";break;
317 default:
318 pRet = 0;
321 OUString sRet;
322 if( pRet )
323 sRet = C2U( pRet );
324 rVal <<= sRet;
326 break;
327 case FN_UNO_CONTROL_CHARACTER: // obsolete!
328 break;
329 case FN_UNO_DOCUMENT_INDEX_MARK:
330 rVal <<= m_xTOXMark;
331 break;
332 case FN_UNO_REFERENCE_MARK:
333 rVal <<= m_xRefMark;
334 break;
335 case FN_UNO_BOOKMARK:
336 rVal <<= m_xBookmark;
337 break;
338 case FN_UNO_FOOTNOTE:
339 rVal <<= m_xFootnote;
340 break;
341 case FN_UNO_TEXT_FIELD:
342 rVal <<= m_xTextField;
343 break;
344 case FN_UNO_META:
345 rVal <<= m_xMeta;
346 break;
347 case FN_UNO_IS_COLLAPSED:
349 switch (m_ePortionType)
351 case PORTION_REFMARK_START:
352 case PORTION_BOOKMARK_START :
353 case PORTION_TOXMARK_START:
354 case PORTION_REFMARK_END:
355 case PORTION_TOXMARK_END:
356 case PORTION_BOOKMARK_END :
357 case PORTION_REDLINE_START :
358 case PORTION_REDLINE_END :
359 case PORTION_RUBY_START:
360 case PORTION_RUBY_END:
361 case PORTION_FIELD_START:
362 case PORTION_FIELD_END:
363 rVal.setValue(&m_bIsCollapsed, ::getBooleanCppuType());
364 break;
365 default:
366 break;
369 break;
370 case FN_UNO_IS_START:
372 BOOL bStart = TRUE, bPut = TRUE;
373 switch (m_ePortionType)
375 case PORTION_REFMARK_START:
376 case PORTION_BOOKMARK_START:
377 case PORTION_TOXMARK_START:
378 case PORTION_REDLINE_START:
379 case PORTION_RUBY_START:
380 case PORTION_FIELD_START:
381 break;
383 case PORTION_REFMARK_END:
384 case PORTION_TOXMARK_END:
385 case PORTION_BOOKMARK_END:
386 case PORTION_REDLINE_END:
387 case PORTION_RUBY_END:
388 case PORTION_FIELD_END:
389 bStart = FALSE;
390 break;
391 default:
392 bPut = FALSE;
394 if(bPut)
395 rVal.setValue(&bStart, ::getBooleanCppuType());
397 break;
398 case RES_TXTATR_CJK_RUBY:
400 const uno::Any* pToSet = 0;
401 switch(rEntry.nMemberId)
403 case MID_RUBY_TEXT : pToSet = m_pRubyText.get(); break;
404 case MID_RUBY_ADJUST : pToSet = m_pRubyAdjust.get(); break;
405 case MID_RUBY_CHARSTYLE:pToSet = m_pRubyStyle.get(); break;
406 case MID_RUBY_ABOVE : pToSet = m_pRubyIsAbove.get();break;
408 if(pToSet)
409 rVal = *pToSet;
411 break;
412 default:
413 beans::PropertyState eTemp;
414 BOOL bDone = SwUnoCursorHelper::getCrsrPropertyValue(
415 rEntry, *pUnoCrsr, &(rVal), eTemp );
416 if(!bDone)
418 if(!pSet)
420 pSet = new SfxItemSet(pUnoCrsr->GetDoc()->GetAttrPool(),
421 RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
422 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
423 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
424 0L);
425 SwXTextCursor::GetCrsrAttr(*pUnoCrsr, *pSet);
427 m_pPropSet->getPropertyValue(rEntry, *pSet, rVal);
434 uno::Sequence< uno::Any > SAL_CALL SwXTextPortion::GetPropertyValues_Impl(
435 const uno::Sequence< OUString >& rPropertyNames )
436 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
438 sal_Int32 nLength = rPropertyNames.getLength();
439 const OUString *pPropertyNames = rPropertyNames.getConstArray();
440 uno::Sequence< uno::Any > aValues(rPropertyNames.getLength());
441 uno::Any *pValues = aValues.getArray();
442 SwUnoCrsr* pUnoCrsr = GetCursor();
443 if (!pUnoCrsr)
444 throw uno::RuntimeException();
447 SfxItemSet *pSet = 0;
448 // get startting pount fo the look-up, either the provided one or else
449 // from the beginning of the map
450 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
451 for(sal_Int32 nProp = 0; nProp < nLength; nProp++)
453 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
454 if(pEntry)
456 GetPropertyValue( pValues[nProp], *pEntry, pUnoCrsr, pSet );
458 else
459 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
461 delete pSet;
463 return aValues;
465 /*-- 11.12.98 09:56:58---------------------------------------------------
467 -----------------------------------------------------------------------*/
468 uno::Any SwXTextPortion::getPropertyValue(
469 const OUString& rPropertyName)
470 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
472 vos::OGuard aGuard(Application::GetSolarMutex());
473 uno::Sequence< ::rtl::OUString > aPropertyNames(1);
474 aPropertyNames.getArray()[0] = rPropertyName;
475 return GetPropertyValues_Impl(aPropertyNames).getConstArray()[0];
477 /* -----------------------------02.04.01 11:44--------------------------------
479 ---------------------------------------------------------------------------*/
480 void SAL_CALL SwXTextPortion::SetPropertyValues_Impl(
481 const uno::Sequence< OUString >& rPropertyNames,
482 const uno::Sequence< uno::Any >& rValues )
483 throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
484 lang::WrappedTargetException, uno::RuntimeException)
486 SwUnoCrsr* pUnoCrsr = GetCursor();
487 if (!pUnoCrsr)
488 throw uno::RuntimeException();
491 const OUString* pPropertyNames = rPropertyNames.getConstArray();
492 const uno::Any* pValues = rValues.getConstArray();
493 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
494 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++)
496 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
497 if (!pEntry)
498 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
499 if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
500 throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
502 SwXTextCursor::SetPropertyValue( *pUnoCrsr, *m_pPropSet,
503 pPropertyNames[nProp], pValues[nProp]);
508 void SwXTextPortion::setPropertyValues(
509 const uno::Sequence< OUString >& rPropertyNames,
510 const uno::Sequence< uno::Any >& rValues )
511 throw(beans::PropertyVetoException, lang::IllegalArgumentException,
512 lang::WrappedTargetException, uno::RuntimeException)
514 vos::OGuard aGuard(Application::GetSolarMutex());
516 // workaround for bad designed API
519 SetPropertyValues_Impl( rPropertyNames, rValues );
521 catch (beans::UnknownPropertyException &rException)
523 // wrap the original (here not allowed) exception in
524 // a lang::WrappedTargetException that gets thrown instead.
525 lang::WrappedTargetException aWExc;
526 aWExc.TargetException <<= rException;
527 throw aWExc;
530 /* -----------------------------02.04.01 11:44--------------------------------
532 ---------------------------------------------------------------------------*/
533 uno::Sequence< uno::Any > SwXTextPortion::getPropertyValues(
534 const uno::Sequence< OUString >& rPropertyNames )
535 throw(uno::RuntimeException)
537 vos::OGuard aGuard(Application::GetSolarMutex());
538 uno::Sequence< uno::Any > aValues;
540 // workaround for bad designed API
543 aValues = GetPropertyValues_Impl( rPropertyNames );
545 catch (beans::UnknownPropertyException &)
547 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property exception caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
549 catch (lang::WrappedTargetException &)
551 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "WrappedTargetException caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
554 return aValues;
556 /* -----------------------------29.09.03 11:44--------------------------------
558 ---------------------------------------------------------------------------*/
560 /* disabled for #i46921# */
562 uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL SwXTextPortion::setPropertyValuesTolerant(
563 const uno::Sequence< OUString >& rPropertyNames,
564 const uno::Sequence< uno::Any >& rValues )
565 throw (lang::IllegalArgumentException, uno::RuntimeException)
567 vos::OGuard aGuard(Application::GetSolarMutex());
569 if (rPropertyNames.getLength() != rValues.getLength())
570 throw lang::IllegalArgumentException();
571 SwUnoCrsr* pUnoCrsr = this->GetCursor();
572 if (!pUnoCrsr)
573 throw uno::RuntimeException();
575 sal_Int32 nProps = rPropertyNames.getLength();
576 const OUString *pProp = rPropertyNames.getConstArray();
578 //sal_Int32 nVals = rValues.getLength();
579 const uno::Any *pValue = rValues.getConstArray();
581 sal_Int32 nFailed = 0;
582 uno::Sequence< beans::SetPropertyTolerantFailed > aFailed( nProps );
583 beans::SetPropertyTolerantFailed *pFailed = aFailed.getArray();
585 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
587 OUString sTmp;
588 for (sal_Int32 i = 0; i < nProps; ++i)
592 pFailed[ nFailed ].Name = pProp[i];
594 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
595 if (!pEntry)
596 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
597 else
599 // set property value
600 // (compare to SwXTextPortion::setPropertyValues)
601 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
602 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
603 else
605 SwXTextCursor::SetPropertyValue(
606 *pUnoCrsr, *m_pPropSet, pProp[i], pValue[i] );
610 catch (beans::UnknownPropertyException &)
612 // should not occur because property was searched for before
613 DBG_ERROR( "unexpected exception catched" );
614 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
616 catch (lang::IllegalArgumentException &)
618 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
620 catch (beans::PropertyVetoException &)
622 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
624 catch (lang::WrappedTargetException &)
626 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
630 aFailed.realloc( nFailed );
631 return aFailed;
635 uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SwXTextPortion::getPropertyValuesTolerant(
636 const uno::Sequence< OUString >& rPropertyNames )
637 throw (uno::RuntimeException)
639 vos::OGuard aGuard( Application::GetSolarMutex() );
641 uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
642 GetPropertyValuesTolerant_Impl( rPropertyNames, sal_False ) );
643 const beans::GetDirectPropertyTolerantResult *pTmpRes = aTmpRes.getConstArray();
645 // copy temporary result to final result type
646 sal_Int32 nLen = aTmpRes.getLength();
647 uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen );
648 beans::GetPropertyTolerantResult *pRes = aRes.getArray();
649 for (sal_Int32 i = 0; i < nLen; i++)
650 *pRes++ = *pTmpRes++;
651 return aRes;
655 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::getDirectPropertyValuesTolerant(
656 const uno::Sequence< OUString >& rPropertyNames )
657 throw (uno::RuntimeException)
659 vos::OGuard aGuard( Application::GetSolarMutex() );
660 return GetPropertyValuesTolerant_Impl( rPropertyNames, sal_True );
664 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::GetPropertyValuesTolerant_Impl(
665 const uno::Sequence< OUString >& rPropertyNames,
666 sal_Bool bDirectValuesOnly )
667 throw (uno::RuntimeException)
669 vos::OGuard aGuard(Application::GetSolarMutex());
671 SwUnoCrsr* pUnoCrsr = this->GetCursor();
672 if(!pUnoCrsr)
673 throw uno::RuntimeException();
675 sal_Int32 nProps = rPropertyNames.getLength();
676 const OUString *pProp = rPropertyNames.getConstArray();
678 SfxItemSet *pSet = 0;
680 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
682 uno::Sequence< beans::PropertyState > aPropertyStates = SwXTextCursor::GetPropertyStates(
683 *pUnoCrsr, *m_pPropSet,
684 rPropertyNames,
685 SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT );
686 const beans::PropertyState* pPropertyStates = aPropertyStates.getConstArray();
688 std::vector< beans::GetDirectPropertyTolerantResult > aResultVector;
689 for (sal_Int32 i = 0; i < nProps; ++i)
691 beans::GetDirectPropertyTolerantResult aResult;
694 aResult.Name = pProp[i];
695 if(pPropertyStates[i] == beans::PropertyState_MAKE_FIXED_SIZE) // property unknown?
697 if( bDirectValuesOnly )
698 continue;
699 else
700 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
702 else
704 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
705 aResult.State = pPropertyStates[i];
707 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_FAILURE;
708 //#i104499# ruby portion attributes need special handling:
709 if( pEntry->nWID == RES_TXTATR_CJK_RUBY &&
710 m_ePortionType == PORTION_RUBY_START )
712 aResult.State = beans::PropertyState_DIRECT_VALUE;
714 if (!bDirectValuesOnly || beans::PropertyState_DIRECT_VALUE == aResult.State)
716 // get property value
717 // (compare to SwXTextPortion::getPropertyValue(s))
718 GetPropertyValue( aResult.Value, *pEntry, pUnoCrsr, pSet );
719 aResult.Result = beans::TolerantPropertySetResultType::SUCCESS;
720 aResultVector.push_back( aResult );
722 // this assertion should never occur!
723 DBG_ASSERT( !aResultVector.size() || aResult.Result != beans::TolerantPropertySetResultType::UNKNOWN_FAILURE,
724 "unknown failure while retrieving property" );
728 catch (beans::UnknownPropertyException &)
730 // should not occur because property was searched for before
731 DBG_ERROR( "unexpected exception catched" );
732 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
734 catch (lang::IllegalArgumentException &)
736 aResult.Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
738 catch (beans::PropertyVetoException &)
740 aResult.Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
742 catch (lang::WrappedTargetException &)
744 aResult.Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
747 delete pSet;
749 uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( aResultVector.size() );
750 std::vector< beans::GetDirectPropertyTolerantResult >::const_iterator aIt = aResultVector.begin();
751 beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray();
752 for( sal_Int32 nResult = 0; nResult < aResult.getLength(); ++nResult )
754 pResult[nResult] = *aIt;
755 ++aIt;
758 return aResult;
762 /* -----------------------------02.04.01 11:44--------------------------------
764 ---------------------------------------------------------------------------*/
765 void SwXTextPortion::addPropertiesChangeListener(
766 const uno::Sequence< OUString >& /*aPropertyNames*/,
767 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
768 throw(uno::RuntimeException)
770 /* -----------------------------02.04.01 11:44--------------------------------
772 ---------------------------------------------------------------------------*/
773 void SwXTextPortion::removePropertiesChangeListener(
774 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
775 throw(uno::RuntimeException)
777 /* -----------------------------02.04.01 11:44--------------------------------
779 ---------------------------------------------------------------------------*/
780 void SwXTextPortion::firePropertiesChangeEvent(
781 const uno::Sequence< OUString >& /*aPropertyNames*/,
782 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
783 throw(uno::RuntimeException)
785 /*-- 11.12.98 09:56:58---------------------------------------------------
787 -----------------------------------------------------------------------*/
788 void SwXTextPortion::addPropertyChangeListener(
789 const OUString& /*PropertyName*/,
790 const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
791 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
793 DBG_WARNING("not implemented");
795 /*-- 11.12.98 09:56:58---------------------------------------------------
797 -----------------------------------------------------------------------*/
798 void SwXTextPortion::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
800 DBG_WARNING("not implemented");
802 /*-- 11.12.98 09:56:58---------------------------------------------------
804 -----------------------------------------------------------------------*/
805 void SwXTextPortion::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
807 DBG_WARNING("not implemented");
809 /*-- 11.12.98 09:56:59---------------------------------------------------
811 -----------------------------------------------------------------------*/
812 void SwXTextPortion::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
814 DBG_WARNING("not implemented");
816 /*-- 08.03.99 09:41:43---------------------------------------------------
818 -----------------------------------------------------------------------*/
819 beans::PropertyState SwXTextPortion::getPropertyState(const OUString& rPropertyName)
820 throw( beans::UnknownPropertyException, uno::RuntimeException )
822 vos::OGuard aGuard(Application::GetSolarMutex());
823 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
824 SwUnoCrsr* pUnoCrsr = GetCursor();
825 if (!pUnoCrsr)
826 throw uno::RuntimeException();
828 if (GetTextPortionType() == PORTION_RUBY_START &&
829 !rPropertyName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
831 eRet = beans::PropertyState_DIRECT_VALUE;
833 else
835 eRet = SwXTextCursor::GetPropertyState(*pUnoCrsr, *m_pPropSet,
836 rPropertyName);
838 return eRet;
840 /*-- 08.03.99 09:41:47---------------------------------------------------
842 -----------------------------------------------------------------------*/
843 uno::Sequence< beans::PropertyState > SwXTextPortion::getPropertyStates(
844 const uno::Sequence< OUString >& rPropertyNames)
845 throw( beans::UnknownPropertyException, uno::RuntimeException )
847 vos::OGuard aGuard(Application::GetSolarMutex());
848 SwUnoCrsr* pUnoCrsr = GetCursor();
849 if(!pUnoCrsr)
850 throw uno::RuntimeException();
852 uno::Sequence< beans::PropertyState > aRet =
853 SwXTextCursor::GetPropertyStates(*pUnoCrsr, *m_pPropSet,
854 rPropertyNames, SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION);
856 if(GetTextPortionType() == PORTION_RUBY_START)
858 const OUString* pNames = rPropertyNames.getConstArray();
859 beans::PropertyState* pStates = aRet.getArray();
860 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength();nProp++)
862 if(!pNames[nProp].compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
863 pStates[nProp] = beans::PropertyState_DIRECT_VALUE;
866 return aRet;
868 /*-- 08.03.99 09:41:47---------------------------------------------------
870 -----------------------------------------------------------------------*/
871 void SwXTextPortion::setPropertyToDefault(const OUString& rPropertyName)
872 throw( beans::UnknownPropertyException, uno::RuntimeException )
874 vos::OGuard aGuard(Application::GetSolarMutex());
875 SwUnoCrsr* pUnoCrsr = GetCursor();
876 if (!pUnoCrsr)
877 throw uno::RuntimeException();
879 SwXTextCursor::SetPropertyToDefault(*pUnoCrsr, *m_pPropSet, rPropertyName);
881 /*-- 08.03.99 09:41:48---------------------------------------------------
883 -----------------------------------------------------------------------*/
884 uno::Any SwXTextPortion::getPropertyDefault(const OUString& rPropertyName)
885 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
887 vos::OGuard aGuard(Application::GetSolarMutex());
888 uno::Any aRet;
889 SwUnoCrsr* pUnoCrsr = GetCursor();
890 if (!pUnoCrsr)
891 throw uno::RuntimeException();
893 aRet = SwXTextCursor::GetPropertyDefault(*pUnoCrsr, *m_pPropSet,
894 rPropertyName);
895 return aRet;
898 /*-- 11.12.98 09:56:59---------------------------------------------------
900 -----------------------------------------------------------------------*/
901 void SwXTextPortion::attach(const uno::Reference< text::XTextRange > & /*xTextRange*/)
902 throw( lang::IllegalArgumentException, uno::RuntimeException )
904 vos::OGuard aGuard(Application::GetSolarMutex());
905 // SwXTextPortion cannot be created at the factory therefore
906 // they cannot be attached
907 throw uno::RuntimeException();
909 /*-- 11.12.98 09:57:00---------------------------------------------------
911 -----------------------------------------------------------------------*/
912 uno::Reference< text::XTextRange > SwXTextPortion::getAnchor()
913 throw( uno::RuntimeException )
915 vos::OGuard aGuard(Application::GetSolarMutex());
916 uno::Reference< text::XTextRange > aRet;
917 SwUnoCrsr* pUnoCrsr = GetCursor();
918 if (!pUnoCrsr)
919 throw uno::RuntimeException();
921 aRet = new SwXTextRange(*pUnoCrsr, m_xParentText);
922 return aRet;
924 /*-- 11.12.98 09:57:00---------------------------------------------------
926 -----------------------------------------------------------------------*/
927 void SwXTextPortion::dispose()
928 throw( uno::RuntimeException )
930 vos::OGuard aGuard(Application::GetSolarMutex());
931 SwUnoCrsr* pUnoCrsr = GetCursor();
932 if (!pUnoCrsr)
933 throw uno::RuntimeException();
935 setString(aEmptyStr);
936 pUnoCrsr->Remove(this);
938 /*-- 11.12.98 09:57:00---------------------------------------------------
940 -----------------------------------------------------------------------*/
941 void SwXTextPortion::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
943 vos::OGuard aGuard(Application::GetSolarMutex());
944 if(!GetRegisteredIn())
945 throw uno::RuntimeException();
947 m_ListenerContainer.AddListener(aListener);
949 /*-- 11.12.98 09:57:01---------------------------------------------------
951 -----------------------------------------------------------------------*/
952 void SwXTextPortion::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
954 vos::OGuard aGuard(Application::GetSolarMutex());
955 if (!GetRegisteredIn() || !m_ListenerContainer.RemoveListener(aListener))
956 throw uno::RuntimeException();
958 /* -----------------24.03.99 13:30-------------------
960 * --------------------------------------------------*/
961 uno::Reference< container::XEnumeration > SwXTextPortion::createContentEnumeration(const OUString& /*aServiceName*/)
962 throw( uno::RuntimeException )
964 vos::OGuard aGuard(Application::GetSolarMutex());
965 SwUnoCrsr* pUnoCrsr = GetCursor();
966 if(!pUnoCrsr)
967 throw uno::RuntimeException();
969 uno::Reference< container::XEnumeration > xRet =
970 new SwXParaFrameEnumeration(*pUnoCrsr, PARAFRAME_PORTION_CHAR,
971 m_pFrameFmt);
972 return xRet;
975 /* -----------------------------04.07.01 08:52--------------------------------
977 ---------------------------------------------------------------------------*/
978 const uno::Sequence< sal_Int8 > & SwXTextPortion::getUnoTunnelId()
980 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
981 return aSeq;
983 /* -----------------------------04.07.01 08:52--------------------------------
985 ---------------------------------------------------------------------------*/
986 sal_Int64 SwXTextPortion::getSomething( const uno::Sequence< sal_Int8 >& rId )
987 throw(uno::RuntimeException)
989 if( rId.getLength() == 16
990 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
991 rId.getConstArray(), 16 ) )
993 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
995 return 0;
997 /* -----------------24.03.99 13:30-------------------
999 * --------------------------------------------------*/
1000 uno::Sequence< OUString > SwXTextPortion::getAvailableServiceNames()
1001 throw( uno::RuntimeException )
1003 vos::OGuard aGuard(Application::GetSolarMutex());
1004 uno::Sequence< OUString > aRet(1);
1005 OUString* pArray = aRet.getArray();
1006 pArray[0] = C2U("com.sun.star.text.TextContent");
1007 return aRet;
1009 /* -----------------25.03.99 10:30-------------------
1011 * --------------------------------------------------*/
1012 OUString SwXTextPortion::getImplementationName()
1013 throw( uno::RuntimeException )
1015 return C2U("SwXTextPortion");
1017 /* -----------------25.03.99 10:30-------------------
1019 * --------------------------------------------------*/
1020 sal_Bool SwXTextPortion::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
1022 vos::OGuard aGuard(Application::GetSolarMutex());
1023 SwUnoCrsr* pUnoCrsr = GetCursor();
1024 if(!pUnoCrsr)
1025 throw uno::RuntimeException();
1027 sal_Bool bRet = sal_False;
1028 if(!rServiceName.compareToAscii("com.sun.star.text.TextPortion") ||
1029 !rServiceName.compareToAscii("com.sun.star.style.CharacterProperties") ||
1030 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesAsian") ||
1031 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesComplex") ||
1032 !rServiceName.compareToAscii("com.sun.star.style.ParagraphProperties") ||
1033 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesAsian") ||
1034 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesComplex"))
1036 bRet = sal_True;
1039 return bRet;
1041 /* ---------------------------------------------------------------------------
1043 ---------------------------------------------------------------------------*/
1044 uno::Sequence< OUString > SwXTextPortion::getSupportedServiceNames()
1045 throw( uno::RuntimeException )
1047 vos::OGuard aGuard(Application::GetSolarMutex());
1048 SwUnoCrsr* pUnoCrsr = GetCursor();
1049 if (!pUnoCrsr)
1050 throw uno::RuntimeException();
1052 uno::Sequence< OUString > aRet(7);
1053 OUString* pArray = aRet.getArray();
1054 pArray[0] = C2U("com.sun.star.text.TextPortion");
1055 pArray[1] = C2U("com.sun.star.style.CharacterProperties");
1056 pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
1057 pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
1058 pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
1059 pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
1060 pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
1061 return aRet;
1063 /*-- 11.12.98 09:57:01---------------------------------------------------
1065 -----------------------------------------------------------------------*/
1066 void SwXTextPortion::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
1068 ClientModify(this, pOld, pNew);
1069 if (!m_FrameDepend.GetRegisteredIn())
1071 m_pFrameFmt = 0;