update dev300-m58
[ooovba.git] / sw / source / core / unocore / unoport.cxx
blob1118509838ff9ba1bb29ab3a674b813cad116dbe
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 #ifndef _UNOMID_H
45 #include <unomid.h>
46 #endif
47 #include <txtatr.hxx>
48 #include <txtfld.hxx>
49 #include <ndtxt.hxx>
50 #include <doc.hxx>
51 #include <fmtflcnt.hxx>
52 #include <fmtfld.hxx>
53 #include <com/sun/star/beans/PropertyAttribute.hpp>
54 #include <com/sun/star/beans/SetPropertyTolerantFailed.hpp>
55 #include <com/sun/star/beans/GetPropertyTolerantResult.hpp>
56 #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
58 using namespace ::com::sun::star;
59 using ::rtl::OUString;
62 /******************************************************************
63 * SwXTextPortion
64 ******************************************************************/
66 /*-- 11.12.98 09:56:52---------------------------------------------------
68 -----------------------------------------------------------------------*/
69 SwFmtFld* SwXTextPortion::GetFldFmt(sal_Bool bInit)
71 SwFmtFld* pRet = 0;
72 // initial wird es immer gesucht, danach nur noch, wenn es bereits existierte
73 SwUnoCrsr* pUnoCrsr = GetCrsr();
74 if(pUnoCrsr && (bInit || pFmtFld))
76 SwTxtNode *pNode = pUnoCrsr->GetPoint()->nNode.GetNode().GetTxtNode();
77 SwTxtFld *pTxtFld = 0;
78 if( pNode )
79 pTxtFld = pNode->GetTxtFld( pUnoCrsr->Start()->nContent );
80 if(pTxtFld)
81 pFmtFld = pRet = (SwFmtFld*)&pTxtFld->GetFld();
83 return pRet;
85 /*-- 11.12.98 09:56:55---------------------------------------------------
87 -----------------------------------------------------------------------*/
88 SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
89 uno::Reference< text::XText > const& rParent,
90 SwTextPortionType eType) :
91 aLstnrCntnr( (text::XTextRange*)this),
92 m_pPropSet(aSwMapProvider.GetPropertySet(
93 (PORTION_REDLINE_START == eType ||
94 PORTION_REDLINE_END == eType) ?
95 PROPERTY_MAP_REDLINE_PORTION : PROPERTY_MAP_TEXTPORTION_EXTENSIONS)),
96 xParentText(rParent),
97 pRubyText(0),
98 pRubyStyle(0),
99 pRubyAdjust(0),
100 pRubyIsAbove(0),
101 pFmtFld(0),
102 aFrameDepend(this, 0),
103 pFrameFmt(0),
104 ePortionType(eType),
105 nControlChar(0),
106 bIsCollapsed(FALSE)
108 SwUnoCrsr* pUnoCrsr = pPortionCrsr->GetDoc()->CreateUnoCrsr(*pPortionCrsr->GetPoint());
109 if(pPortionCrsr->HasMark())
111 pUnoCrsr->SetMark();
112 *pUnoCrsr->GetMark() = *pPortionCrsr->GetMark();
114 pUnoCrsr->Add(this);
115 // erst nach ->Add()
116 if(ePortionType == PORTION_FIELD)
117 GetFldFmt(sal_True);
118 // else if(ePortionType == PORTION_FRAME)
119 // ...;
121 /* -----------------24.03.99 16:30-------------------
123 * --------------------------------------------------*/
124 SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
125 uno::Reference< text::XText > const& rParent,
126 SwFrmFmt& rFmt ) :
127 aLstnrCntnr( (text::XTextRange*)this),
128 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXTPORTION_EXTENSIONS)),
129 xParentText(rParent),
130 pRubyText(0),
131 pRubyStyle(0),
132 pRubyAdjust(0),
133 pRubyIsAbove(0),
134 pFmtFld(0),
135 aFrameDepend(this, &rFmt),
136 pFrameFmt(&rFmt),
137 ePortionType(PORTION_FRAME),
138 nControlChar(0),
139 bIsCollapsed(FALSE)
141 SwUnoCrsr* pUnoCrsr = pPortionCrsr->GetDoc()->CreateUnoCrsr(*pPortionCrsr->GetPoint());
142 if(pPortionCrsr->HasMark())
144 pUnoCrsr->SetMark();
145 *pUnoCrsr->GetMark() = *pPortionCrsr->GetMark();
147 pUnoCrsr->Add(this);
150 /*-- 11.12.98 09:56:55---------------------------------------------------
152 -----------------------------------------------------------------------*/
153 SwXTextPortion::~SwXTextPortion()
155 vos::OGuard aGuard(Application::GetSolarMutex());
156 SwUnoCrsr* pUnoCrsr = GetCrsr();
157 delete pUnoCrsr;
158 delete pRubyText;
159 delete pRubyStyle;
160 delete pRubyAdjust;
161 delete pRubyIsAbove;
163 /*-- 11.12.98 09:56:56---------------------------------------------------
165 -----------------------------------------------------------------------*/
166 uno::Reference< text::XText > SwXTextPortion::getText(void) throw( uno::RuntimeException )
168 return xParentText;
170 /*-- 11.12.98 09:56:56---------------------------------------------------
172 -----------------------------------------------------------------------*/
173 uno::Reference< text::XTextRange > SwXTextPortion::getStart(void) throw( uno::RuntimeException )
175 vos::OGuard aGuard(Application::GetSolarMutex());
176 uno::Reference< text::XTextRange > xRet;
177 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
178 if(pUnoCrsr)
180 SwPaM aPam(*pUnoCrsr->Start());
181 uno::Reference< text::XText > xParent = getText();
182 xRet = new SwXTextRange(aPam, xParent);
184 else
185 throw uno::RuntimeException();
186 return xRet;
188 /*-- 11.12.98 09:56:57---------------------------------------------------
190 -----------------------------------------------------------------------*/
191 uno::Reference< text::XTextRange > SwXTextPortion::getEnd(void) throw( uno::RuntimeException )
193 vos::OGuard aGuard(Application::GetSolarMutex());
194 uno::Reference< text::XTextRange > xRet;
195 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
196 if(pUnoCrsr)
198 SwPaM aPam(*pUnoCrsr->End());
199 uno::Reference< text::XText > xParent = getText();
200 xRet = new SwXTextRange(aPam, xParent);
202 else
203 throw uno::RuntimeException();
204 return xRet;
206 /*-- 11.12.98 09:56:57---------------------------------------------------
208 -----------------------------------------------------------------------*/
209 OUString SwXTextPortion::getString(void) throw( uno::RuntimeException )
211 vos::OGuard aGuard(Application::GetSolarMutex());
212 String aTxt;
213 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
214 if(pUnoCrsr)
216 //TextPortions liegen immer innerhalb eines Absatzes
217 SwTxtNode* pTxtNd = pUnoCrsr->GetNode()->GetTxtNode();
218 if( pTxtNd )
220 xub_StrLen nStt = pUnoCrsr->Start()->nContent.GetIndex();
221 aTxt = pTxtNd->GetExpandTxt( nStt,
222 pUnoCrsr->End()->nContent.GetIndex() - nStt );
225 else
226 throw uno::RuntimeException();
227 return aTxt;
229 /*-- 11.12.98 09:56:57---------------------------------------------------
231 -----------------------------------------------------------------------*/
232 void SwXTextPortion::setString(const OUString& aString) throw( uno::RuntimeException )
234 vos::OGuard aGuard(Application::GetSolarMutex());
235 SwUnoCrsr* pUnoCrsr = GetCrsr();
236 if(pUnoCrsr)
237 SwXTextCursor::SetString(*pUnoCrsr, aString);
238 else
239 throw uno::RuntimeException();
241 /*-- 11.12.98 09:56:57---------------------------------------------------
243 -----------------------------------------------------------------------*/
244 uno::Reference< beans::XPropertySetInfo > SwXTextPortion::getPropertySetInfo(void) throw( uno::RuntimeException )
246 //! PropertySetInfo for text portion extensions
247 static uno::Reference< beans::XPropertySetInfo >
248 xTxtPorExtRef = aSwMapProvider.GetPropertySet(
249 PROPERTY_MAP_TEXTPORTION_EXTENSIONS)->getPropertySetInfo();
250 //! PropertySetInfo for redline portions
251 static uno::Reference< beans::XPropertySetInfo >
252 xRedlPorRef = aSwMapProvider.GetPropertySet(
253 PROPERTY_MAP_REDLINE_PORTION)->getPropertySetInfo();
255 return (PORTION_REDLINE_START == ePortionType ||
256 PORTION_REDLINE_END == ePortionType) ? xRedlPorRef : xTxtPorExtRef;
258 /*-- 11.12.98 09:56:57---------------------------------------------------
260 -----------------------------------------------------------------------*/
261 void SwXTextPortion::setPropertyValue(const OUString& rPropertyName,
262 const uno::Any& aValue)
263 throw( beans::UnknownPropertyException,
264 beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
266 vos::OGuard aGuard(Application::GetSolarMutex());
267 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
268 if(pUnoCrsr)
270 SwXTextCursor::SetPropertyValue(*pUnoCrsr, *m_pPropSet, rPropertyName, aValue);
272 else
273 throw uno::RuntimeException();
275 /*-- 04.11.03 09:56:58---------------------------------------------------
277 -----------------------------------------------------------------------*/
278 void SwXTextPortion::GetPropertyValue(
279 uno::Any &rVal,
280 const SfxItemPropertySimpleEntry& rEntry,
281 SwUnoCrsr *pUnoCrsr,
282 SfxItemSet *&pSet )
284 DBG_ASSERT( pUnoCrsr, "UNO cursor missing" );
285 if (!pUnoCrsr)
286 return;
287 if(pUnoCrsr)
289 switch(rEntry.nWID)
291 case FN_UNO_TEXT_PORTION_TYPE:
293 const char* pRet;
294 switch (ePortionType)
296 case PORTION_TEXT: pRet = "Text";break;
297 case PORTION_FIELD: pRet = "TextField";break;
298 case PORTION_FRAME: pRet = "Frame";break;
299 case PORTION_FOOTNOTE: pRet = "Footnote";break;
300 case PORTION_CONTROL_CHAR: pRet = "ControlCharacter";break;
301 case PORTION_REFMARK_START:
302 case PORTION_REFMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_REFERENCE_MARK);break;
303 case PORTION_TOXMARK_START:
304 case PORTION_TOXMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_DOCUMENT_INDEX_MARK);break;
305 case PORTION_BOOKMARK_START :
306 case PORTION_BOOKMARK_END : pRet = SW_PROP_NAME_STR(UNO_NAME_BOOKMARK);break;
307 case PORTION_REDLINE_START:
308 case PORTION_REDLINE_END: pRet = "Redline";break;
309 case PORTION_RUBY_START:
310 case PORTION_RUBY_END: pRet = "Ruby";break;
311 case PORTION_SOFT_PAGEBREAK:pRet = "SoftPageBreak";break;
312 case PORTION_FIELD_START:pRet = "TextFieldStart";break;
313 case PORTION_FIELD_END:pRet = "TextFieldEnd";break;
314 case PORTION_FIELD_START_END:pRet = "TextFieldStartEnd";break;
315 default:
316 pRet = 0;
319 OUString sRet;
320 if( pRet )
321 sRet = C2U( pRet );
322 rVal <<= sRet;
324 break;
325 case FN_UNO_CONTROL_CHARACTER:
327 if(PORTION_CONTROL_CHAR == ePortionType)
328 rVal <<= (sal_Int16) nControlChar;
330 break;
331 case FN_UNO_DOCUMENT_INDEX_MARK:
332 rVal <<= xTOXMark;
333 break;
334 case FN_UNO_REFERENCE_MARK:
335 rVal <<= xRefMark;
336 break;
337 case FN_UNO_BOOKMARK:
338 rVal <<= xBookmark;
339 break;
340 case FN_UNO_FOOTNOTE:
341 rVal <<= xFootnote;
342 break;
343 case FN_UNO_IS_COLLAPSED:
345 BOOL bPut = TRUE;
346 switch (ePortionType)
348 case PORTION_REFMARK_START:
349 case PORTION_BOOKMARK_START :
350 case PORTION_TOXMARK_START:
351 case PORTION_REFMARK_END:
352 case PORTION_TOXMARK_END:
353 case PORTION_BOOKMARK_END :
354 case PORTION_REDLINE_START :
355 case PORTION_REDLINE_END :
356 case PORTION_RUBY_START:
357 case PORTION_RUBY_END:
358 case PORTION_FIELD_START:
359 case PORTION_FIELD_END:
360 rVal.setValue(&bIsCollapsed, ::getBooleanCppuType());
361 break;
362 default:
363 bPut = FALSE;
366 break;
367 case FN_UNO_IS_START:
369 BOOL bStart = TRUE, bPut = TRUE;
370 switch (ePortionType)
372 case PORTION_REFMARK_START:
373 case PORTION_BOOKMARK_START:
374 case PORTION_TOXMARK_START:
375 case PORTION_REDLINE_START:
376 case PORTION_RUBY_START:
377 case PORTION_FIELD_START:
378 break;
380 case PORTION_REFMARK_END:
381 case PORTION_TOXMARK_END:
382 case PORTION_BOOKMARK_END:
383 case PORTION_REDLINE_END:
384 case PORTION_RUBY_END:
385 case PORTION_FIELD_END:
386 bStart = FALSE;
387 break;
388 default:
389 bPut = FALSE;
391 if(bPut)
392 rVal.setValue(&bStart, ::getBooleanCppuType());
394 break;
395 case RES_TXTATR_CJK_RUBY:
397 uno::Any* pToSet = 0;
398 switch(rEntry.nMemberId)
400 case MID_RUBY_TEXT : pToSet = pRubyText; break;
401 case MID_RUBY_ADJUST : pToSet = pRubyAdjust; break;
402 case MID_RUBY_CHARSTYLE:pToSet = pRubyStyle; break;
403 case MID_RUBY_ABOVE : pToSet = pRubyIsAbove; break;
405 if(pToSet)
406 rVal = *pToSet;
408 break;
409 default:
410 beans::PropertyState eTemp;
411 BOOL bDone = SwUnoCursorHelper::getCrsrPropertyValue(
412 rEntry, *pUnoCrsr, &(rVal), eTemp );
413 if(!bDone)
415 if(!pSet)
417 pSet = new SfxItemSet(pUnoCrsr->GetDoc()->GetAttrPool(),
418 RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
419 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
420 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
421 0L);
422 SwXTextCursor::GetCrsrAttr(*pUnoCrsr, *pSet);
424 m_pPropSet->getPropertyValue(rEntry, *pSet, rVal);
431 uno::Sequence< uno::Any > SAL_CALL SwXTextPortion::GetPropertyValues_Impl(
432 const uno::Sequence< OUString >& rPropertyNames )
433 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
435 sal_Int32 nLength = rPropertyNames.getLength();
436 const OUString *pPropertyNames = rPropertyNames.getConstArray();
437 uno::Sequence< uno::Any > aValues(rPropertyNames.getLength());
438 uno::Any *pValues = aValues.getArray();
439 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
440 if(pUnoCrsr)
442 SfxItemSet *pSet = 0;
443 // get startting pount fo the look-up, either the provided one or else
444 // from the beginning of the map
445 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
446 for(sal_Int32 nProp = 0; nProp < nLength; nProp++)
448 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
449 if(pEntry)
451 GetPropertyValue( pValues[nProp], *pEntry, pUnoCrsr, pSet );
453 else
454 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
456 delete pSet;
458 else
459 throw uno::RuntimeException();
460 return aValues;
462 /*-- 11.12.98 09:56:58---------------------------------------------------
464 -----------------------------------------------------------------------*/
465 uno::Any SwXTextPortion::getPropertyValue(
466 const OUString& rPropertyName)
467 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
469 vos::OGuard aGuard(Application::GetSolarMutex());
470 uno::Sequence< ::rtl::OUString > aPropertyNames(1);
471 aPropertyNames.getArray()[0] = rPropertyName;
472 return GetPropertyValues_Impl(aPropertyNames).getConstArray()[0];
474 /* -----------------------------02.04.01 11:44--------------------------------
476 ---------------------------------------------------------------------------*/
477 void SAL_CALL SwXTextPortion::SetPropertyValues_Impl(
478 const uno::Sequence< OUString >& rPropertyNames,
479 const uno::Sequence< uno::Any >& rValues )
480 throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
481 lang::WrappedTargetException, uno::RuntimeException)
483 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
484 if(pUnoCrsr)
486 const OUString* pPropertyNames = rPropertyNames.getConstArray();
487 const uno::Any* pValues = rValues.getConstArray();
488 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
489 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++)
491 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
492 if (!pEntry)
493 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
494 if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
495 throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
497 SwXTextCursor::SetPropertyValue( *pUnoCrsr, *m_pPropSet, pPropertyNames[nProp], pValues[nProp]);
500 else
501 throw uno::RuntimeException();
504 void SwXTextPortion::setPropertyValues(
505 const uno::Sequence< OUString >& rPropertyNames,
506 const uno::Sequence< uno::Any >& rValues )
507 throw(beans::PropertyVetoException, lang::IllegalArgumentException,
508 lang::WrappedTargetException, uno::RuntimeException)
510 vos::OGuard aGuard(Application::GetSolarMutex());
512 // workaround for bad designed API
515 SetPropertyValues_Impl( rPropertyNames, rValues );
517 catch (beans::UnknownPropertyException &rException)
519 // wrap the original (here not allowed) exception in
520 // a lang::WrappedTargetException that gets thrown instead.
521 lang::WrappedTargetException aWExc;
522 aWExc.TargetException <<= rException;
523 throw aWExc;
526 /* -----------------------------02.04.01 11:44--------------------------------
528 ---------------------------------------------------------------------------*/
529 uno::Sequence< uno::Any > SwXTextPortion::getPropertyValues(
530 const uno::Sequence< OUString >& rPropertyNames )
531 throw(uno::RuntimeException)
533 vos::OGuard aGuard(Application::GetSolarMutex());
534 uno::Sequence< uno::Any > aValues;
536 // workaround for bad designed API
539 aValues = GetPropertyValues_Impl( rPropertyNames );
541 catch (beans::UnknownPropertyException &)
543 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property exception caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
545 catch (lang::WrappedTargetException &)
547 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "WrappedTargetException caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
550 return aValues;
552 /* -----------------------------29.09.03 11:44--------------------------------
554 ---------------------------------------------------------------------------*/
556 /* disabled for #i46921# */
558 uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL SwXTextPortion::setPropertyValuesTolerant(
559 const uno::Sequence< OUString >& rPropertyNames,
560 const uno::Sequence< uno::Any >& rValues )
561 throw (lang::IllegalArgumentException, uno::RuntimeException)
563 vos::OGuard aGuard(Application::GetSolarMutex());
565 if (rPropertyNames.getLength() != rValues.getLength())
566 throw lang::IllegalArgumentException();
567 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
568 if (!pUnoCrsr)
569 throw uno::RuntimeException();
571 sal_Int32 nProps = rPropertyNames.getLength();
572 const OUString *pProp = rPropertyNames.getConstArray();
574 //sal_Int32 nVals = rValues.getLength();
575 const uno::Any *pValue = rValues.getConstArray();
577 sal_Int32 nFailed = 0;
578 uno::Sequence< beans::SetPropertyTolerantFailed > aFailed( nProps );
579 beans::SetPropertyTolerantFailed *pFailed = aFailed.getArray();
581 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
583 OUString sTmp;
584 for (sal_Int32 i = 0; i < nProps; ++i)
588 pFailed[ nFailed ].Name = pProp[i];
590 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
591 if (!pEntry)
592 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
593 else
595 // set property value
596 // (compare to SwXTextPortion::setPropertyValues)
597 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
598 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
599 else
601 SwXTextCursor::SetPropertyValue(
602 *pUnoCrsr, *m_pPropSet, pProp[i], pValue[i] );
606 catch (beans::UnknownPropertyException &)
608 // should not occur because property was searched for before
609 DBG_ERROR( "unexpected exception catched" );
610 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
612 catch (lang::IllegalArgumentException &)
614 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
616 catch (beans::PropertyVetoException &)
618 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
620 catch (lang::WrappedTargetException &)
622 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
626 aFailed.realloc( nFailed );
627 return aFailed;
631 uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SwXTextPortion::getPropertyValuesTolerant(
632 const uno::Sequence< OUString >& rPropertyNames )
633 throw (uno::RuntimeException)
635 vos::OGuard aGuard( Application::GetSolarMutex() );
637 uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
638 GetPropertyValuesTolerant_Impl( rPropertyNames, sal_False ) );
639 const beans::GetDirectPropertyTolerantResult *pTmpRes = aTmpRes.getConstArray();
641 // copy temporary result to final result type
642 sal_Int32 nLen = aTmpRes.getLength();
643 uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen );
644 beans::GetPropertyTolerantResult *pRes = aRes.getArray();
645 for (sal_Int32 i = 0; i < nLen; i++)
646 *pRes++ = *pTmpRes++;
647 return aRes;
651 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::getDirectPropertyValuesTolerant(
652 const uno::Sequence< OUString >& rPropertyNames )
653 throw (uno::RuntimeException)
655 vos::OGuard aGuard( Application::GetSolarMutex() );
656 return GetPropertyValuesTolerant_Impl( rPropertyNames, sal_True );
660 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::GetPropertyValuesTolerant_Impl(
661 const uno::Sequence< OUString >& rPropertyNames,
662 sal_Bool bDirectValuesOnly )
663 throw (uno::RuntimeException)
665 vos::OGuard aGuard(Application::GetSolarMutex());
667 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
668 if(!pUnoCrsr)
669 throw uno::RuntimeException();
671 sal_Int32 nProps = rPropertyNames.getLength();
672 const OUString *pProp = rPropertyNames.getConstArray();
674 SfxItemSet *pSet = 0;
676 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
678 uno::Sequence< beans::PropertyState > aPropertyStates = SwXTextCursor::GetPropertyStates(
679 *pUnoCrsr, *m_pPropSet,
680 rPropertyNames,
681 SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT );
682 const beans::PropertyState* pPropertyStates = aPropertyStates.getConstArray();
684 std::vector< beans::GetDirectPropertyTolerantResult > aResultVector;
685 for (sal_Int32 i = 0; i < nProps; ++i)
687 beans::GetDirectPropertyTolerantResult aResult;
690 aResult.Name = pProp[i];
691 if(pPropertyStates[i] == beans::PropertyState_MAKE_FIXED_SIZE) // property unknown?
693 if( bDirectValuesOnly )
694 continue;
695 else
696 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
698 else
700 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
701 aResult.State = pPropertyStates[i];
703 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_FAILURE;
704 //#i104499# ruby portion attributes need special handling:
705 if( pEntry->nWID == RES_TXTATR_CJK_RUBY &&
706 ePortionType == PORTION_RUBY_START )
707 aResult.State = beans::PropertyState_DIRECT_VALUE;
708 if (!bDirectValuesOnly || beans::PropertyState_DIRECT_VALUE == aResult.State)
710 // get property value
711 // (compare to SwXTextPortion::getPropertyValue(s))
712 GetPropertyValue( aResult.Value, *pEntry, pUnoCrsr, pSet );
713 aResult.Result = beans::TolerantPropertySetResultType::SUCCESS;
714 aResultVector.push_back( aResult );
716 // this assertion should never occur!
717 DBG_ASSERT( !aResultVector.size() || aResult.Result != beans::TolerantPropertySetResultType::UNKNOWN_FAILURE,
718 "unknown failure while retrieving property" );
722 catch (beans::UnknownPropertyException &)
724 // should not occur because property was searched for before
725 DBG_ERROR( "unexpected exception catched" );
726 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
728 catch (lang::IllegalArgumentException &)
730 aResult.Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
732 catch (beans::PropertyVetoException &)
734 aResult.Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
736 catch (lang::WrappedTargetException &)
738 aResult.Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
741 delete pSet;
743 uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( aResultVector.size() );
744 std::vector< beans::GetDirectPropertyTolerantResult >::const_iterator aIt = aResultVector.begin();
745 beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray();
746 for( sal_Int32 nResult = 0; nResult < aResult.getLength(); ++nResult )
748 pResult[nResult] = *aIt;
749 ++aIt;
752 return aResult;
756 /* -----------------------------02.04.01 11:44--------------------------------
758 ---------------------------------------------------------------------------*/
759 void SwXTextPortion::addPropertiesChangeListener(
760 const uno::Sequence< OUString >& /*aPropertyNames*/,
761 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
762 throw(uno::RuntimeException)
764 /* -----------------------------02.04.01 11:44--------------------------------
766 ---------------------------------------------------------------------------*/
767 void SwXTextPortion::removePropertiesChangeListener(
768 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
769 throw(uno::RuntimeException)
771 /* -----------------------------02.04.01 11:44--------------------------------
773 ---------------------------------------------------------------------------*/
774 void SwXTextPortion::firePropertiesChangeEvent(
775 const uno::Sequence< OUString >& /*aPropertyNames*/,
776 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
777 throw(uno::RuntimeException)
779 /*-- 11.12.98 09:56:58---------------------------------------------------
781 -----------------------------------------------------------------------*/
782 void SwXTextPortion::addPropertyChangeListener(
783 const OUString& /*PropertyName*/,
784 const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
785 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
787 DBG_WARNING("not implemented");
789 /*-- 11.12.98 09:56:58---------------------------------------------------
791 -----------------------------------------------------------------------*/
792 void SwXTextPortion::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
794 DBG_WARNING("not implemented");
796 /*-- 11.12.98 09:56:58---------------------------------------------------
798 -----------------------------------------------------------------------*/
799 void SwXTextPortion::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
801 DBG_WARNING("not implemented");
803 /*-- 11.12.98 09:56:59---------------------------------------------------
805 -----------------------------------------------------------------------*/
806 void SwXTextPortion::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
808 DBG_WARNING("not implemented");
810 /*-- 08.03.99 09:41:43---------------------------------------------------
812 -----------------------------------------------------------------------*/
813 beans::PropertyState SwXTextPortion::getPropertyState(const OUString& rPropertyName)
814 throw( beans::UnknownPropertyException, uno::RuntimeException )
816 vos::OGuard aGuard(Application::GetSolarMutex());
817 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
818 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
819 if(pUnoCrsr)
821 if(GetTextPortionType() == PORTION_RUBY_START &&
822 !rPropertyName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
823 eRet = beans::PropertyState_DIRECT_VALUE;
824 else
825 eRet = SwXTextCursor::GetPropertyState(*pUnoCrsr, *m_pPropSet, rPropertyName);
827 else
828 throw uno::RuntimeException();
829 return eRet;
831 /*-- 08.03.99 09:41:47---------------------------------------------------
833 -----------------------------------------------------------------------*/
834 uno::Sequence< beans::PropertyState > SwXTextPortion::getPropertyStates(
835 const uno::Sequence< OUString >& rPropertyNames)
836 throw( beans::UnknownPropertyException, uno::RuntimeException )
838 vos::OGuard aGuard(Application::GetSolarMutex());
839 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
840 if(!pUnoCrsr)
841 throw uno::RuntimeException();
842 uno::Sequence< beans::PropertyState > aRet = SwXTextCursor::GetPropertyStates(*pUnoCrsr, *m_pPropSet, rPropertyNames, SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION);
844 if(GetTextPortionType() == PORTION_RUBY_START)
846 const OUString* pNames = rPropertyNames.getConstArray();
847 beans::PropertyState* pStates = aRet.getArray();
848 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength();nProp++)
850 if(!pNames[nProp].compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
851 pStates[nProp] = beans::PropertyState_DIRECT_VALUE;
854 return aRet;
856 /*-- 08.03.99 09:41:47---------------------------------------------------
858 -----------------------------------------------------------------------*/
859 void SwXTextPortion::setPropertyToDefault(const OUString& rPropertyName)
860 throw( beans::UnknownPropertyException, uno::RuntimeException )
862 vos::OGuard aGuard(Application::GetSolarMutex());
863 SwUnoCrsr* pUnoCrsr = GetCrsr();
864 if(pUnoCrsr)
866 SwXTextCursor::SetPropertyToDefault(*pUnoCrsr, *m_pPropSet, rPropertyName);
868 else
869 throw uno::RuntimeException();
871 /*-- 08.03.99 09:41:48---------------------------------------------------
873 -----------------------------------------------------------------------*/
874 uno::Any SwXTextPortion::getPropertyDefault(const OUString& rPropertyName)
875 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
877 uno::Any aRet;
878 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
879 if(pUnoCrsr)
881 aRet = SwXTextCursor::GetPropertyDefault(*pUnoCrsr, *m_pPropSet, rPropertyName);
883 else
884 throw uno::RuntimeException();
885 return aRet;
887 /*-- 11.12.98 09:56:59---------------------------------------------------
889 -----------------------------------------------------------------------*/
890 OUString SwXTextPortion::getPresentation(sal_Bool /*bShowCommand*/) throw( uno::RuntimeException )
892 vos::OGuard aGuard(Application::GetSolarMutex());
893 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
894 String sRet;
895 SwFmtFld* pFmt = 0;
896 if(pUnoCrsr && 0 != (pFmt = GetFldFmt()))
898 const SwField* pField = pFmt->GetFld();
899 DBG_ERROR("bShowCommand auswerten!");
900 sRet = pField->Expand();
902 return sRet;
904 /*-- 11.12.98 09:56:59---------------------------------------------------
906 -----------------------------------------------------------------------*/
907 void SwXTextPortion::attach(const uno::Reference< text::XTextRange > & /*xTextRange*/)
908 throw( lang::IllegalArgumentException, uno::RuntimeException )
910 vos::OGuard aGuard(Application::GetSolarMutex());
911 // SwXTextPortion cannot be created at the factory therefore
912 // they cannot be attached
913 throw uno::RuntimeException();
915 /*-- 11.12.98 09:57:00---------------------------------------------------
917 -----------------------------------------------------------------------*/
918 uno::Reference< text::XTextRange > SwXTextPortion::getAnchor(void) throw( uno::RuntimeException )
920 vos::OGuard aGuard(Application::GetSolarMutex());
921 uno::Reference< text::XTextRange > aRet;
922 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
923 if(pUnoCrsr)
924 aRet = new SwXTextRange(*pUnoCrsr, xParentText);
925 else
926 throw uno::RuntimeException();
927 return aRet;
929 /*-- 11.12.98 09:57:00---------------------------------------------------
931 -----------------------------------------------------------------------*/
932 void SwXTextPortion::dispose(void) throw( uno::RuntimeException )
934 vos::OGuard aGuard(Application::GetSolarMutex());
935 SwUnoCrsr* pUnoCrsr = ((SwXTextPortion*)this)->GetCrsr();
936 if(pUnoCrsr)
938 setString(aEmptyStr);
939 pUnoCrsr->Remove(this);
941 else
942 throw uno::RuntimeException();
944 /*-- 11.12.98 09:57:00---------------------------------------------------
946 -----------------------------------------------------------------------*/
947 void SwXTextPortion::addEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
949 vos::OGuard aGuard(Application::GetSolarMutex());
950 if(!GetRegisteredIn())
951 throw uno::RuntimeException();
952 aLstnrCntnr.AddListener(aListener);
954 /*-- 11.12.98 09:57:01---------------------------------------------------
956 -----------------------------------------------------------------------*/
957 void SwXTextPortion::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw( uno::RuntimeException )
959 vos::OGuard aGuard(Application::GetSolarMutex());
960 if(!GetRegisteredIn() || !aLstnrCntnr.RemoveListener(aListener))
961 throw uno::RuntimeException();
963 /* -----------------24.03.99 13:30-------------------
965 * --------------------------------------------------*/
966 uno::Reference< container::XEnumeration > SwXTextPortion::createContentEnumeration(const OUString& /*aServiceName*/)
967 throw( uno::RuntimeException )
969 vos::OGuard aGuard(Application::GetSolarMutex());
970 SwUnoCrsr* pUnoCrsr = GetCrsr();
971 if(!pUnoCrsr)
972 throw uno::RuntimeException();
973 uno::Reference< container::XEnumeration > xRet = new SwXParaFrameEnumeration(*pUnoCrsr, PARAFRAME_PORTION_CHAR, pFrameFmt);
974 return xRet;
977 /* -----------------------------04.07.01 08:52--------------------------------
979 ---------------------------------------------------------------------------*/
980 const uno::Sequence< sal_Int8 > & SwXTextPortion::getUnoTunnelId()
982 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
983 return aSeq;
985 /* -----------------------------04.07.01 08:52--------------------------------
987 ---------------------------------------------------------------------------*/
988 sal_Int64 SwXTextPortion::getSomething( const uno::Sequence< sal_Int8 >& rId )
989 throw(uno::RuntimeException)
991 if( rId.getLength() == 16
992 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
993 rId.getConstArray(), 16 ) )
995 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
997 return 0;
999 /* -----------------24.03.99 13:30-------------------
1001 * --------------------------------------------------*/
1002 uno::Sequence< OUString > SwXTextPortion::getAvailableServiceNames(void) throw( uno::RuntimeException )
1004 vos::OGuard aGuard(Application::GetSolarMutex());
1005 uno::Sequence< OUString > aRet(1);
1006 OUString* pArray = aRet.getArray();
1007 pArray[0] = C2U("com.sun.star.text.TextContent");
1008 return aRet;
1010 /* -----------------25.03.99 10:30-------------------
1012 * --------------------------------------------------*/
1013 OUString SwXTextPortion::getImplementationName(void) 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 = GetCrsr();
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"))
1035 bRet = sal_True;
1036 else if(COMPARE_EQUAL == rServiceName.compareToAscii("com.sun.star.text.TextField"))
1037 bRet = 0 != GetFldFmt();
1039 return bRet;
1041 /* ---------------------------------------------------------------------------
1043 ---------------------------------------------------------------------------*/
1044 uno::Sequence< OUString > SwXTextPortion::getSupportedServiceNames(void)
1045 throw( uno::RuntimeException )
1047 vos::OGuard aGuard(Application::GetSolarMutex());
1048 SwUnoCrsr* pUnoCrsr = GetCrsr();
1049 if(!pUnoCrsr)
1050 throw uno::RuntimeException();
1051 sal_Bool bField = 0 != GetFldFmt();
1052 sal_uInt16 nCount = bField ? 8 : 7;
1053 uno::Sequence< OUString > aRet(nCount);
1054 OUString* pArray = aRet.getArray();
1055 pArray[0] = C2U("com.sun.star.text.TextPortion");
1056 pArray[1] = C2U("com.sun.star.style.CharacterProperties");
1057 pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
1058 pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
1059 pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
1060 pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
1061 pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
1062 if(bField)
1063 pArray[7] = C2U("com.sun.star.text.TextField");
1064 return aRet;
1066 /*-- 11.12.98 09:57:01---------------------------------------------------
1068 -----------------------------------------------------------------------*/
1069 void SwXTextPortion::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
1071 ClientModify(this, pOld, pNew);
1072 if(!aFrameDepend.GetRegisteredIn())
1073 pFrameFmt = 0;
1075 /* -----------------------------19.02.01 10:52--------------------------------
1077 ---------------------------------------------------------------------------*/
1078 SwXRubyPortion::SwXRubyPortion(const SwUnoCrsr* pPortionCrsr,
1079 SwTxtRuby& rAttr,
1080 uno::Reference< text::XText > const& rParent,
1081 sal_Bool bEnd ) :
1082 SwXTextPortion(pPortionCrsr, rParent, bEnd ? PORTION_RUBY_END : PORTION_RUBY_START )
1084 if(!bEnd)
1086 const SfxPoolItem& rItem = rAttr.GetAttr();
1087 pRubyText = new uno::Any;
1088 pRubyStyle = new uno::Any;
1089 pRubyAdjust = new uno::Any;
1090 pRubyIsAbove = new uno::Any;
1091 rItem.QueryValue(*pRubyText, MID_RUBY_TEXT);
1092 rItem.QueryValue(*pRubyStyle, MID_RUBY_CHARSTYLE);
1093 rItem.QueryValue(*pRubyAdjust, MID_RUBY_ADJUST);
1094 rItem.QueryValue(*pRubyIsAbove, MID_RUBY_ABOVE);
1097 /* -----------------------------19.02.01 10:52--------------------------------
1099 ---------------------------------------------------------------------------*/
1100 SwXRubyPortion::~SwXRubyPortion()