1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <cmdid.h>
29 #include <vos/mutex.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svl/itemprop.hxx>
32
33 #include <unocrsrhelper.hxx>
34 #include <unoport.hxx>
35 #include <unoparaframeenum.hxx>
36 #include <unotextrange.hxx>
37 #include <unomap.hxx>
38 #include <unoprnms.hxx>
39 #include <unomid.h>
40 #include <txtatr.hxx>
41 #include <txtfld.hxx>
42 #include <ndtxt.hxx>
43 #include <doc.hxx>
44 #include <fmtflcnt.hxx>
45 #include <fmtfld.hxx>
46 #include <frmfmt.hxx>
47
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/beans/SetPropertyTolerantFailed.hpp>
50 #include <com/sun/star/beans/GetPropertyTolerantResult.hpp>
51 #include <com/sun/star/beans/TolerantPropertySetResultType.hpp>
52
53
54 using namespace ::com::sun::star;
55 using ::rtl::OUString;
56
57
58 /******************************************************************
59 * SwXTextPortion
60 ******************************************************************/
61
init(const SwUnoCrsr * pPortionCursor)62 void SwXTextPortion::init(const SwUnoCrsr* pPortionCursor)
63 {
64 SwUnoCrsr* pUnoCursor =
65 pPortionCursor->GetDoc()->CreateUnoCrsr(*pPortionCursor->GetPoint());
66 if (pPortionCursor->HasMark())
67 {
68 pUnoCursor->SetMark();
69 *pUnoCursor->GetMark() = *pPortionCursor->GetMark();
70 }
71 pUnoCursor->Add(this);
72 }
73
74 /*-- 11.12.98 09:56:55---------------------------------------------------
75
76 -----------------------------------------------------------------------*/
SwXTextPortion(const SwUnoCrsr * pPortionCrsr,uno::Reference<text::XText> const & rParent,SwTextPortionType eType)77 SwXTextPortion::SwXTextPortion(
78 const SwUnoCrsr* pPortionCrsr,
79 uno::Reference< text::XText > const& rParent,
80 SwTextPortionType eType )
81 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
82 , m_pPropSet(aSwMapProvider.GetPropertySet(
83 (PORTION_REDLINE_START == eType ||
84 PORTION_REDLINE_END == eType)
85 ? PROPERTY_MAP_REDLINE_PORTION
86 : PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
87 , m_xParentText(rParent)
88 , m_pRubyText(0)
89 , m_pRubyStyle(0)
90 , m_pRubyAdjust(0)
91 , m_pRubyIsAbove(0)
92 , m_FrameDepend(this, 0)
93 , m_pFrameFmt(0)
94 , m_ePortionType(eType)
95 , m_bIsCollapsed(false)
96 {
97 init( pPortionCrsr);
98 }
99
100 /* -----------------24.03.99 16:30-------------------
101 *
102 * --------------------------------------------------*/
SwXTextPortion(const SwUnoCrsr * pPortionCrsr,uno::Reference<text::XText> const & rParent,SwFrmFmt & rFmt)103 SwXTextPortion::SwXTextPortion(
104 const SwUnoCrsr* pPortionCrsr,
105 uno::Reference< text::XText > const& rParent,
106 SwFrmFmt& rFmt )
107 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
108 , m_pPropSet(aSwMapProvider.GetPropertySet(
109 PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
110 , m_xParentText(rParent)
111 , m_pRubyText(0)
112 , m_pRubyStyle(0)
113 , m_pRubyAdjust(0)
114 , m_pRubyIsAbove(0)
115 , m_FrameDepend(this, &rFmt)
116 , m_pFrameFmt(&rFmt)
117 , m_ePortionType(PORTION_FRAME)
118 , m_bIsCollapsed(false)
119 {
120 init( pPortionCrsr);
121 }
122
123 /* -----------------------------19.02.01 10:52--------------------------------
124
125 ---------------------------------------------------------------------------*/
SwXTextPortion(const SwUnoCrsr * pPortionCrsr,SwTxtRuby const & rAttr,uno::Reference<text::XText> const & xParent,sal_Bool bIsEnd)126 SwXTextPortion::SwXTextPortion(
127 const SwUnoCrsr* pPortionCrsr,
128 SwTxtRuby const& rAttr,
129 uno::Reference< text::XText > const& xParent,
130 sal_Bool bIsEnd )
131 : m_ListenerContainer( static_cast<text::XTextRange*>(this) )
132 , m_pPropSet(aSwMapProvider.GetPropertySet(
133 PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
134 , m_xParentText(xParent)
135 , m_pRubyText ( bIsEnd ? 0 : new uno::Any )
136 , m_pRubyStyle ( bIsEnd ? 0 : new uno::Any )
137 , m_pRubyAdjust ( bIsEnd ? 0 : new uno::Any )
138 , m_pRubyIsAbove( bIsEnd ? 0 : new uno::Any )
139 , m_FrameDepend(this, 0)
140 , m_pFrameFmt(0)
141 , m_ePortionType( bIsEnd ? PORTION_RUBY_END : PORTION_RUBY_START )
142 , m_bIsCollapsed(false)
143 {
144 init( pPortionCrsr);
145
146 if (!bIsEnd)
147 {
148 const SfxPoolItem& rItem = rAttr.GetAttr();
149 rItem.QueryValue(*m_pRubyText, MID_RUBY_TEXT);
150 rItem.QueryValue(*m_pRubyStyle, MID_RUBY_CHARSTYLE);
151 rItem.QueryValue(*m_pRubyAdjust, MID_RUBY_ADJUST);
152 rItem.QueryValue(*m_pRubyIsAbove, MID_RUBY_ABOVE);
153 }
154 }
155
156 /*-- 11.12.98 09:56:55---------------------------------------------------
157
158 -----------------------------------------------------------------------*/
~SwXTextPortion()159 SwXTextPortion::~SwXTextPortion()
160 {
161 vos::OGuard aGuard(Application::GetSolarMutex());
162 SwUnoCrsr* pUnoCrsr = GetCursor();
163 delete pUnoCrsr;
164 }
165 /*-- 11.12.98 09:56:56---------------------------------------------------
166
167 -----------------------------------------------------------------------*/
getText()168 uno::Reference< text::XText > SwXTextPortion::getText()
169 {
170 return m_xParentText;
171 }
172 /*-- 11.12.98 09:56:56---------------------------------------------------
173
174 -----------------------------------------------------------------------*/
getStart()175 uno::Reference< text::XTextRange > SwXTextPortion::getStart()
176 {
177 vos::OGuard aGuard(Application::GetSolarMutex());
178 uno::Reference< text::XTextRange > xRet;
179 SwUnoCrsr* pUnoCrsr = GetCursor();
180 if (!pUnoCrsr)
181 throw uno::RuntimeException();
182
183 SwPaM aPam(*pUnoCrsr->Start());
184 uno::Reference< text::XText > xParent = getText();
185 xRet = new SwXTextRange(aPam, xParent);
186 return xRet;
187 }
188 /*-- 11.12.98 09:56:57---------------------------------------------------
189
190 -----------------------------------------------------------------------*/
getEnd()191 uno::Reference< text::XTextRange > SwXTextPortion::getEnd()
192 {
193 vos::OGuard aGuard(Application::GetSolarMutex());
194 uno::Reference< text::XTextRange > xRet;
195 SwUnoCrsr* pUnoCrsr = GetCursor();
196 if (!pUnoCrsr)
197 throw uno::RuntimeException();
198
199 SwPaM aPam(*pUnoCrsr->End());
200 uno::Reference< text::XText > xParent = getText();
201 xRet = new SwXTextRange(aPam, xParent);
202 return xRet;
203 }
204 /*-- 11.12.98 09:56:57---------------------------------------------------
205
206 -----------------------------------------------------------------------*/
getString()207 OUString SwXTextPortion::getString()
208 {
209 vos::OGuard aGuard(Application::GetSolarMutex());
210 OUString aTxt;
211 SwUnoCrsr* pUnoCrsr = GetCursor();
212 if (!pUnoCrsr)
213 throw uno::RuntimeException();
214
215 // TextPortions are always within a paragraph
216 SwTxtNode* pTxtNd = pUnoCrsr->GetNode()->GetTxtNode();
217 if ( pTxtNd )
218 {
219 xub_StrLen nStt = pUnoCrsr->Start()->nContent.GetIndex();
220 aTxt = pTxtNd->GetExpandTxt( nStt,
221 pUnoCrsr->End()->nContent.GetIndex() - nStt );
222 }
223 return aTxt;
224 }
225 /*-- 11.12.98 09:56:57---------------------------------------------------
226
227 -----------------------------------------------------------------------*/
setString(const OUString & aString)228 void SwXTextPortion::setString(const OUString& aString)
229 {
230 vos::OGuard aGuard(Application::GetSolarMutex());
231 SwUnoCrsr* pUnoCrsr = GetCursor();
232 if (!pUnoCrsr)
233 throw uno::RuntimeException();
234
235 SwUnoCursorHelper::SetString(*pUnoCrsr, aString);
236 }
237 /*-- 11.12.98 09:56:57---------------------------------------------------
238
239 -----------------------------------------------------------------------*/
getPropertySetInfo()240 uno::Reference< beans::XPropertySetInfo > SwXTextPortion::getPropertySetInfo()
241 {
242 vos::OGuard aGuard(Application::GetSolarMutex());
243 //! PropertySetInfo for text portion extensions
244 static uno::Reference< beans::XPropertySetInfo >
245 xTxtPorExtRef = aSwMapProvider.GetPropertySet(
246 PROPERTY_MAP_TEXTPORTION_EXTENSIONS)->getPropertySetInfo();
247 //! PropertySetInfo for redline portions
248 static uno::Reference< beans::XPropertySetInfo >
249 xRedlPorRef = aSwMapProvider.GetPropertySet(
250 PROPERTY_MAP_REDLINE_PORTION)->getPropertySetInfo();
251
252 return (PORTION_REDLINE_START == m_ePortionType ||
253 PORTION_REDLINE_END == m_ePortionType) ? xRedlPorRef : xTxtPorExtRef;
254 }
255 /*-- 11.12.98 09:56:57---------------------------------------------------
256
257 -----------------------------------------------------------------------*/
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)258 void SwXTextPortion::setPropertyValue(const OUString& rPropertyName,
259 const uno::Any& aValue)
260 {
261 vos::OGuard aGuard(Application::GetSolarMutex());
262 SwUnoCrsr* pUnoCrsr = GetCursor();
263 if (!pUnoCrsr)
264 throw uno::RuntimeException();
265
266 SwUnoCursorHelper::SetPropertyValue(*pUnoCrsr, *m_pPropSet,
267 rPropertyName, aValue);
268 }
269 /*-- 04.11.03 09:56:58---------------------------------------------------
270
271 -----------------------------------------------------------------------*/
GetPropertyValue(uno::Any & rVal,const SfxItemPropertySimpleEntry & rEntry,SwUnoCrsr * pUnoCrsr,SfxItemSet * & pSet)272 void SwXTextPortion::GetPropertyValue(
273 uno::Any &rVal,
274 const SfxItemPropertySimpleEntry& rEntry,
275 SwUnoCrsr *pUnoCrsr,
276 SfxItemSet *&pSet )
277 {
278 DBG_ASSERT( pUnoCrsr, "UNO cursor missing" );
279 if (!pUnoCrsr)
280 return;
281 if(pUnoCrsr)
282 {
283 switch(rEntry.nWID)
284 {
285 case FN_UNO_TEXT_PORTION_TYPE:
286 {
287 const char* pRet;
288 switch (m_ePortionType)
289 {
290 case PORTION_TEXT: pRet = "Text";break;
291 case PORTION_FIELD: pRet = "TextField";break;
292 case PORTION_FRAME: pRet = "Frame";break;
293 case PORTION_FOOTNOTE: pRet = "Footnote";break;
294 case PORTION_REFMARK_START:
295 case PORTION_REFMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_REFERENCE_MARK);break;
296 case PORTION_TOXMARK_START:
297 case PORTION_TOXMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_DOCUMENT_INDEX_MARK);break;
298 case PORTION_BOOKMARK_START :
299 case PORTION_BOOKMARK_END : pRet = SW_PROP_NAME_STR(UNO_NAME_BOOKMARK);break;
300 case PORTION_REDLINE_START:
301 case PORTION_REDLINE_END: pRet = "Redline";break;
302 case PORTION_RUBY_START:
303 case PORTION_RUBY_END: pRet = "Ruby";break;
304 case PORTION_SOFT_PAGEBREAK:pRet = "SoftPageBreak";break;
305 case PORTION_META: pRet = SW_PROP_NAME_STR(UNO_NAME_META); break;
306 case PORTION_FIELD_START:pRet = "TextFieldStart";break;
307 case PORTION_FIELD_END:pRet = "TextFieldEnd";break;
308 case PORTION_FIELD_START_END:pRet = "TextFieldStartEnd";break;
309 case PORTION_ANNOTATION:
310 pRet = "Annotation";
311 break;
312 case PORTION_ANNOTATION_END:
313 pRet = "AnnotationEnd";
314 break;
315 default:
316 pRet = 0;
317 }
318
319 OUString sRet;
320 if( pRet )
321 sRet = C2U( pRet );
322 rVal <<= sRet;
323 }
324 break;
325 case FN_UNO_CONTROL_CHARACTER: // obsolete!
326 break;
327 case FN_UNO_DOCUMENT_INDEX_MARK:
328 rVal <<= m_xTOXMark;
329 break;
330 case FN_UNO_REFERENCE_MARK:
331 rVal <<= m_xRefMark;
332 break;
333 case FN_UNO_BOOKMARK:
334 rVal <<= m_xBookmark;
335 break;
336 case FN_UNO_FOOTNOTE:
337 rVal <<= m_xFootnote;
338 break;
339 case FN_UNO_TEXT_FIELD:
340 rVal <<= m_xTextField;
341 break;
342 case FN_UNO_META:
343 rVal <<= m_xMeta;
344 break;
345 case FN_UNO_IS_COLLAPSED:
346 {
347 switch (m_ePortionType)
348 {
349 case PORTION_REFMARK_START:
350 case PORTION_BOOKMARK_START :
351 case PORTION_TOXMARK_START:
352 case PORTION_REFMARK_END:
353 case PORTION_TOXMARK_END:
354 case PORTION_BOOKMARK_END :
355 case PORTION_REDLINE_START :
356 case PORTION_REDLINE_END :
357 case PORTION_RUBY_START:
358 case PORTION_RUBY_END:
359 case PORTION_FIELD_START:
360 case PORTION_FIELD_END:
361 rVal.setValue(&m_bIsCollapsed, ::getBooleanCppuType());
362 break;
363 default:
364 break;
365 }
366 }
367 break;
368 case FN_UNO_IS_START:
369 {
370 sal_Bool bStart = sal_True, bPut = sal_True;
371 switch (m_ePortionType)
372 {
373 case PORTION_REFMARK_START:
374 case PORTION_BOOKMARK_START:
375 case PORTION_TOXMARK_START:
376 case PORTION_REDLINE_START:
377 case PORTION_RUBY_START:
378 case PORTION_FIELD_START:
379 break;
380
381 case PORTION_REFMARK_END:
382 case PORTION_TOXMARK_END:
383 case PORTION_BOOKMARK_END:
384 case PORTION_REDLINE_END:
385 case PORTION_RUBY_END:
386 case PORTION_FIELD_END:
387 bStart = sal_False;
388 break;
389 default:
390 bPut = sal_False;
391 }
392 if(bPut)
393 rVal.setValue(&bStart, ::getBooleanCppuType());
394 }
395 break;
396 case RES_TXTATR_CJK_RUBY:
397 {
398 const uno::Any* pToSet = 0;
399 switch(rEntry.nMemberId)
400 {
401 case MID_RUBY_TEXT : pToSet = m_pRubyText.get(); break;
402 case MID_RUBY_ADJUST : pToSet = m_pRubyAdjust.get(); break;
403 case MID_RUBY_CHARSTYLE:pToSet = m_pRubyStyle.get(); break;
404 case MID_RUBY_ABOVE : pToSet = m_pRubyIsAbove.get();break;
405 }
406 if(pToSet)
407 rVal = *pToSet;
408 }
409 break;
410 default:
411 beans::PropertyState eTemp;
412 sal_Bool bDone = SwUnoCursorHelper::getCrsrPropertyValue(
413 rEntry, *pUnoCrsr, &(rVal), eTemp );
414 if(!bDone)
415 {
416 if(!pSet)
417 {
418 pSet = new SfxItemSet(pUnoCrsr->GetDoc()->GetAttrPool(),
419 RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
420 RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
421 RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
422 0L);
423 SwUnoCursorHelper::GetCrsrAttr(*pUnoCrsr, *pSet);
424 }
425 m_pPropSet->getPropertyValue(rEntry, *pSet, rVal);
426 }
427 }
428 }
429 }
430
431
GetPropertyValues_Impl(const uno::Sequence<OUString> & rPropertyNames)432 uno::Sequence< uno::Any > SAL_CALL SwXTextPortion::GetPropertyValues_Impl(
433 const uno::Sequence< OUString >& rPropertyNames )
434 {
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 = GetCursor();
440 if (!pUnoCrsr)
441 throw uno::RuntimeException();
442
443 {
444 SfxItemSet *pSet = 0;
445 // get starting point for the look-up, either the provided one or else
446 // from the beginning of the map
447 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
448 for(sal_Int32 nProp = 0; nProp < nLength; nProp++)
449 {
450 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
451 if(pEntry)
452 {
453 GetPropertyValue( pValues[nProp], *pEntry, pUnoCrsr, pSet );
454 }
455 else
456 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
457 }
458 delete pSet;
459 }
460 return aValues;
461 }
462 /*-- 11.12.98 09:56:58---------------------------------------------------
463
464 -----------------------------------------------------------------------*/
getPropertyValue(const OUString & rPropertyName)465 uno::Any SwXTextPortion::getPropertyValue(
466 const OUString& rPropertyName)
467 {
468 vos::OGuard aGuard(Application::GetSolarMutex());
469 uno::Sequence< ::rtl::OUString > aPropertyNames(1);
470 aPropertyNames.getArray()[0] = rPropertyName;
471 return GetPropertyValues_Impl(aPropertyNames).getConstArray()[0];
472 }
473 /* -----------------------------02.04.01 11:44--------------------------------
474
475 ---------------------------------------------------------------------------*/
SetPropertyValues_Impl(const uno::Sequence<OUString> & rPropertyNames,const uno::Sequence<uno::Any> & rValues)476 void SAL_CALL SwXTextPortion::SetPropertyValues_Impl(
477 const uno::Sequence< OUString >& rPropertyNames,
478 const uno::Sequence< uno::Any >& rValues )
479 {
480 SwUnoCrsr* pUnoCrsr = GetCursor();
481 if (!pUnoCrsr)
482 throw uno::RuntimeException();
483
484 {
485 const OUString* pPropertyNames = rPropertyNames.getConstArray();
486 const uno::Any* pValues = rValues.getConstArray();
487 const SfxItemPropertyMap* pMap = m_pPropSet->getPropertyMap();
488 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++)
489 {
490 const SfxItemPropertySimpleEntry* pEntry = pMap->getByName(pPropertyNames[nProp]);
491 if (!pEntry)
492 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
493 if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
494 throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
495
496 SwUnoCursorHelper::SetPropertyValue( *pUnoCrsr, *m_pPropSet,
497 pPropertyNames[nProp], pValues[nProp]);
498 }
499 }
500 }
501
setPropertyValues(const uno::Sequence<OUString> & rPropertyNames,const uno::Sequence<uno::Any> & rValues)502 void SwXTextPortion::setPropertyValues(
503 const uno::Sequence< OUString >& rPropertyNames,
504 const uno::Sequence< uno::Any >& rValues )
505 {
506 vos::OGuard aGuard(Application::GetSolarMutex());
507
508 // workaround for bad designed API
509 try
510 {
511 SetPropertyValues_Impl( rPropertyNames, rValues );
512 }
513 catch (beans::UnknownPropertyException &rException)
514 {
515 // wrap the original (here not allowed) exception in
516 // a lang::WrappedTargetException that gets thrown instead.
517 lang::WrappedTargetException aWExc;
518 aWExc.TargetException <<= rException;
519 throw aWExc;
520 }
521 }
522 /* -----------------------------02.04.01 11:44--------------------------------
523
524 ---------------------------------------------------------------------------*/
getPropertyValues(const uno::Sequence<OUString> & rPropertyNames)525 uno::Sequence< uno::Any > SwXTextPortion::getPropertyValues(
526 const uno::Sequence< OUString >& rPropertyNames )
527 {
528 vos::OGuard aGuard(Application::GetSolarMutex());
529 uno::Sequence< uno::Any > aValues;
530
531 // workaround for bad designed API
532 try
533 {
534 aValues = GetPropertyValues_Impl( rPropertyNames );
535 }
536 catch (beans::UnknownPropertyException &)
537 {
538 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property exception caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
539 }
540 catch (lang::WrappedTargetException &)
541 {
542 throw uno::RuntimeException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "WrappedTargetException caught" ) ), static_cast < cppu::OWeakObject * > ( this ) );
543 }
544
545 return aValues;
546 }
547 /* -----------------------------29.09.03 11:44--------------------------------
548
549 ---------------------------------------------------------------------------*/
550
551 /* disabled for #i46921# */
552
setPropertyValuesTolerant(const uno::Sequence<OUString> & rPropertyNames,const uno::Sequence<uno::Any> & rValues)553 uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL SwXTextPortion::setPropertyValuesTolerant(
554 const uno::Sequence< OUString >& rPropertyNames,
555 const uno::Sequence< uno::Any >& rValues )
556 {
557 vos::OGuard aGuard(Application::GetSolarMutex());
558
559 if (rPropertyNames.getLength() != rValues.getLength())
560 throw lang::IllegalArgumentException();
561 SwUnoCrsr* pUnoCrsr = this->GetCursor();
562 if (!pUnoCrsr)
563 throw uno::RuntimeException();
564
565 sal_Int32 nProps = rPropertyNames.getLength();
566 const OUString *pProp = rPropertyNames.getConstArray();
567
568 //sal_Int32 nVals = rValues.getLength();
569 const uno::Any *pValue = rValues.getConstArray();
570
571 sal_Int32 nFailed = 0;
572 uno::Sequence< beans::SetPropertyTolerantFailed > aFailed( nProps );
573 beans::SetPropertyTolerantFailed *pFailed = aFailed.getArray();
574
575 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
576
577 OUString sTmp;
578 for (sal_Int32 i = 0; i < nProps; ++i)
579 {
580 try
581 {
582 pFailed[ nFailed ].Name = pProp[i];
583
584 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
585 if (!pEntry)
586 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
587 else
588 {
589 // set property value
590 // (compare to SwXTextPortion::setPropertyValues)
591 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
592 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
593 else
594 {
595 SwUnoCursorHelper::SetPropertyValue(
596 *pUnoCrsr, *m_pPropSet, pProp[i], pValue[i] );
597 }
598 }
599 }
600 catch (beans::UnknownPropertyException &)
601 {
602 // should not occur because property was searched for before
603 DBG_ERROR( "unexpected exception caught" );
604 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
605 }
606 catch (lang::IllegalArgumentException &)
607 {
608 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
609 }
610 catch (beans::PropertyVetoException &)
611 {
612 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
613 }
614 catch (lang::WrappedTargetException &)
615 {
616 pFailed[ nFailed++ ].Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
617 }
618 }
619
620 aFailed.realloc( nFailed );
621 return aFailed;
622 }
623
624
getPropertyValuesTolerant(const uno::Sequence<OUString> & rPropertyNames)625 uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SwXTextPortion::getPropertyValuesTolerant(
626 const uno::Sequence< OUString >& rPropertyNames )
627 {
628 vos::OGuard aGuard( Application::GetSolarMutex() );
629
630 uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
631 GetPropertyValuesTolerant_Impl( rPropertyNames, sal_False ) );
632 const beans::GetDirectPropertyTolerantResult *pTmpRes = aTmpRes.getConstArray();
633
634 // copy temporary result to final result type
635 sal_Int32 nLen = aTmpRes.getLength();
636 uno::Sequence< beans::GetPropertyTolerantResult > aRes( nLen );
637 beans::GetPropertyTolerantResult *pRes = aRes.getArray();
638 for (sal_Int32 i = 0; i < nLen; i++)
639 *pRes++ = *pTmpRes++;
640 return aRes;
641 }
642
643
getDirectPropertyValuesTolerant(const uno::Sequence<OUString> & rPropertyNames)644 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::getDirectPropertyValuesTolerant(
645 const uno::Sequence< OUString >& rPropertyNames )
646 {
647 vos::OGuard aGuard( Application::GetSolarMutex() );
648 return GetPropertyValuesTolerant_Impl( rPropertyNames, sal_True );
649 }
650
651
GetPropertyValuesTolerant_Impl(const uno::Sequence<OUString> & rPropertyNames,sal_Bool bDirectValuesOnly)652 uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::GetPropertyValuesTolerant_Impl(
653 const uno::Sequence< OUString >& rPropertyNames,
654 sal_Bool bDirectValuesOnly )
655 {
656 vos::OGuard aGuard(Application::GetSolarMutex());
657
658 SwUnoCrsr* pUnoCrsr = this->GetCursor();
659 if(!pUnoCrsr)
660 throw uno::RuntimeException();
661
662 sal_Int32 nProps = rPropertyNames.getLength();
663 const OUString *pProp = rPropertyNames.getConstArray();
664
665 SfxItemSet *pSet = 0;
666
667 const SfxItemPropertyMap* pPropMap = m_pPropSet->getPropertyMap();
668
669 uno::Sequence< beans::PropertyState > aPropertyStates =
670 SwUnoCursorHelper::GetPropertyStates(
671 *pUnoCrsr, *m_pPropSet,
672 rPropertyNames,
673 SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT );
674 const beans::PropertyState* pPropertyStates = aPropertyStates.getConstArray();
675
676 std::vector< beans::GetDirectPropertyTolerantResult > aResultVector;
677 for (sal_Int32 i = 0; i < nProps; ++i)
678 {
679 beans::GetDirectPropertyTolerantResult aResult;
680 try
681 {
682 aResult.Name = pProp[i];
683 if(pPropertyStates[i] == beans::PropertyState_MAKE_FIXED_SIZE) // property unknown?
684 {
685 if( bDirectValuesOnly )
686 continue;
687 else
688 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
689 }
690 else
691 {
692 const SfxItemPropertySimpleEntry* pEntry = pPropMap->getByName( pProp[i] );
693 aResult.State = pPropertyStates[i];
694
695 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_FAILURE;
696 //#i104499# ruby portion attributes need special handling:
697 if( pEntry->nWID == RES_TXTATR_CJK_RUBY &&
698 m_ePortionType == PORTION_RUBY_START )
699 {
700 aResult.State = beans::PropertyState_DIRECT_VALUE;
701 }
702 if (!bDirectValuesOnly || beans::PropertyState_DIRECT_VALUE == aResult.State)
703 {
704 // get property value
705 // (compare to SwXTextPortion::getPropertyValue(s))
706 GetPropertyValue( aResult.Value, *pEntry, pUnoCrsr, pSet );
707 aResult.Result = beans::TolerantPropertySetResultType::SUCCESS;
708 aResultVector.push_back( aResult );
709 }
710 }
711 }
712 catch (beans::UnknownPropertyException &)
713 {
714 // should not occur because property was searched for before
715 DBG_ERROR( "unexpected exception caught" );
716 aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
717 }
718 catch (lang::IllegalArgumentException &)
719 {
720 aResult.Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
721 }
722 catch (beans::PropertyVetoException &)
723 {
724 aResult.Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
725 }
726 catch (lang::WrappedTargetException &)
727 {
728 aResult.Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
729 }
730 }
731 delete pSet;
732
733 uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( aResultVector.size() );
734 std::vector< beans::GetDirectPropertyTolerantResult >::const_iterator aIt = aResultVector.begin();
735 beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray();
736 for( sal_Int32 nResult = 0; nResult < aResult.getLength(); ++nResult )
737 {
738 pResult[nResult] = *aIt;
739 ++aIt;
740 }
741
742 return aResult;
743 }
744
745
746 /* -----------------------------02.04.01 11:44--------------------------------
747
748 ---------------------------------------------------------------------------*/
addPropertiesChangeListener(const uno::Sequence<OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)749 void SwXTextPortion::addPropertiesChangeListener(
750 const uno::Sequence< OUString >& /*aPropertyNames*/,
751 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
752 {}
753 /* -----------------------------02.04.01 11:44--------------------------------
754
755 ---------------------------------------------------------------------------*/
removePropertiesChangeListener(const uno::Reference<beans::XPropertiesChangeListener> &)756 void SwXTextPortion::removePropertiesChangeListener(
757 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
758 {}
759 /* -----------------------------02.04.01 11:44--------------------------------
760
761 ---------------------------------------------------------------------------*/
firePropertiesChangeEvent(const uno::Sequence<OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)762 void SwXTextPortion::firePropertiesChangeEvent(
763 const uno::Sequence< OUString >& /*aPropertyNames*/,
764 const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
765 {}
766 /*-- 11.12.98 09:56:58---------------------------------------------------
767
768 -----------------------------------------------------------------------*/
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)769 void SwXTextPortion::addPropertyChangeListener(
770 const OUString& /*PropertyName*/,
771 const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
772 {
773 DBG_WARNING("not implemented");
774 }
775 /*-- 11.12.98 09:56:58---------------------------------------------------
776
777 -----------------------------------------------------------------------*/
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)778 void SwXTextPortion::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
779 {
780 DBG_WARNING("not implemented");
781 }
782 /*-- 11.12.98 09:56:58---------------------------------------------------
783
784 -----------------------------------------------------------------------*/
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)785 void SwXTextPortion::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
786 {
787 DBG_WARNING("not implemented");
788 }
789 /*-- 11.12.98 09:56:59---------------------------------------------------
790
791 -----------------------------------------------------------------------*/
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)792 void SwXTextPortion::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
793 {
794 DBG_WARNING("not implemented");
795 }
796 /*-- 08.03.99 09:41:43---------------------------------------------------
797
798 -----------------------------------------------------------------------*/
getPropertyState(const OUString & rPropertyName)799 beans::PropertyState SwXTextPortion::getPropertyState(const OUString& rPropertyName)
800 {
801 vos::OGuard aGuard(Application::GetSolarMutex());
802 beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
803 SwUnoCrsr* pUnoCrsr = GetCursor();
804 if (!pUnoCrsr)
805 throw uno::RuntimeException();
806
807 if (GetTextPortionType() == PORTION_RUBY_START &&
808 !rPropertyName.compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
809 {
810 eRet = beans::PropertyState_DIRECT_VALUE;
811 }
812 else
813 {
814 eRet = SwUnoCursorHelper::GetPropertyState(*pUnoCrsr, *m_pPropSet,
815 rPropertyName);
816 }
817 return eRet;
818 }
819 /*-- 08.03.99 09:41:47---------------------------------------------------
820
821 -----------------------------------------------------------------------*/
getPropertyStates(const uno::Sequence<OUString> & rPropertyNames)822 uno::Sequence< beans::PropertyState > SwXTextPortion::getPropertyStates(
823 const uno::Sequence< OUString >& rPropertyNames)
824 {
825 vos::OGuard aGuard(Application::GetSolarMutex());
826 SwUnoCrsr* pUnoCrsr = GetCursor();
827 if(!pUnoCrsr)
828 throw uno::RuntimeException();
829
830 uno::Sequence< beans::PropertyState > aRet =
831 SwUnoCursorHelper::GetPropertyStates(*pUnoCrsr, *m_pPropSet,
832 rPropertyNames, SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION);
833
834 if(GetTextPortionType() == PORTION_RUBY_START)
835 {
836 const OUString* pNames = rPropertyNames.getConstArray();
837 beans::PropertyState* pStates = aRet.getArray();
838 for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength();nProp++)
839 {
840 if(!pNames[nProp].compareToAscii( RTL_CONSTASCII_STRINGPARAM("Ruby") ))
841 pStates[nProp] = beans::PropertyState_DIRECT_VALUE;
842 }
843 }
844 return aRet;
845 }
846 /*-- 08.03.99 09:41:47---------------------------------------------------
847
848 -----------------------------------------------------------------------*/
setPropertyToDefault(const OUString & rPropertyName)849 void SwXTextPortion::setPropertyToDefault(const OUString& rPropertyName)
850 {
851 vos::OGuard aGuard(Application::GetSolarMutex());
852 SwUnoCrsr* pUnoCrsr = GetCursor();
853 if (!pUnoCrsr)
854 throw uno::RuntimeException();
855
856 SwUnoCursorHelper::SetPropertyToDefault(
857 *pUnoCrsr, *m_pPropSet, rPropertyName);
858 }
859 /*-- 08.03.99 09:41:48---------------------------------------------------
860
861 -----------------------------------------------------------------------*/
getPropertyDefault(const OUString & rPropertyName)862 uno::Any SwXTextPortion::getPropertyDefault(const OUString& rPropertyName)
863 {
864 vos::OGuard aGuard(Application::GetSolarMutex());
865 uno::Any aRet;
866 SwUnoCrsr* pUnoCrsr = GetCursor();
867 if (!pUnoCrsr)
868 throw uno::RuntimeException();
869
870 aRet = SwUnoCursorHelper::GetPropertyDefault(*pUnoCrsr, *m_pPropSet,
871 rPropertyName);
872 return aRet;
873 }
874
875 /*-- 11.12.98 09:56:59---------------------------------------------------
876
877 -----------------------------------------------------------------------*/
attach(const uno::Reference<text::XTextRange> &)878 void SwXTextPortion::attach(const uno::Reference< text::XTextRange > & /*xTextRange*/)
879 {
880 vos::OGuard aGuard(Application::GetSolarMutex());
881 // SwXTextPortion cannot be created at the factory therefore
882 // they cannot be attached
883 throw uno::RuntimeException();
884 }
885 /*-- 11.12.98 09:57:00---------------------------------------------------
886
887 -----------------------------------------------------------------------*/
getAnchor()888 uno::Reference< text::XTextRange > SwXTextPortion::getAnchor()
889 {
890 vos::OGuard aGuard(Application::GetSolarMutex());
891 uno::Reference< text::XTextRange > aRet;
892 SwUnoCrsr* pUnoCrsr = GetCursor();
893 if (!pUnoCrsr)
894 throw uno::RuntimeException();
895
896 aRet = new SwXTextRange(*pUnoCrsr, m_xParentText);
897 return aRet;
898 }
899 /*-- 11.12.98 09:57:00---------------------------------------------------
900
901 -----------------------------------------------------------------------*/
dispose()902 void SwXTextPortion::dispose()
903 {
904 vos::OGuard aGuard(Application::GetSolarMutex());
905 SwUnoCrsr* pUnoCrsr = GetCursor();
906 if (!pUnoCrsr)
907 throw uno::RuntimeException();
908
909 setString(aEmptyStr);
910 pUnoCrsr->Remove(this);
911 }
912 /*-- 11.12.98 09:57:00---------------------------------------------------
913
914 -----------------------------------------------------------------------*/
addEventListener(const uno::Reference<lang::XEventListener> & aListener)915 void SwXTextPortion::addEventListener(const uno::Reference< lang::XEventListener > & aListener)
916 {
917 vos::OGuard aGuard(Application::GetSolarMutex());
918 if(!GetRegisteredIn())
919 throw uno::RuntimeException();
920
921 m_ListenerContainer.AddListener(aListener);
922 }
923 /*-- 11.12.98 09:57:01---------------------------------------------------
924
925 -----------------------------------------------------------------------*/
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)926 void SwXTextPortion::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
927 {
928 vos::OGuard aGuard(Application::GetSolarMutex());
929 if (!GetRegisteredIn() || !m_ListenerContainer.RemoveListener(aListener))
930 throw uno::RuntimeException();
931 }
932 /* -----------------24.03.99 13:30-------------------
933 *
934 * --------------------------------------------------*/
createContentEnumeration(const OUString &)935 uno::Reference< container::XEnumeration > SwXTextPortion::createContentEnumeration(const OUString& /*aServiceName*/)
936 {
937 vos::OGuard aGuard(Application::GetSolarMutex());
938 SwUnoCrsr* pUnoCrsr = GetCursor();
939 if(!pUnoCrsr)
940 throw uno::RuntimeException();
941
942 uno::Reference< container::XEnumeration > xRet =
943 new SwXParaFrameEnumeration(*pUnoCrsr, PARAFRAME_PORTION_CHAR,
944 m_pFrameFmt);
945 return xRet;
946
947 }
948 /* -----------------------------04.07.01 08:52--------------------------------
949
950 ---------------------------------------------------------------------------*/
getUnoTunnelId()951 const uno::Sequence< sal_Int8 > & SwXTextPortion::getUnoTunnelId()
952 {
953 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
954 return aSeq;
955 }
956 /* -----------------------------04.07.01 08:52--------------------------------
957
958 ---------------------------------------------------------------------------*/
getSomething(const uno::Sequence<sal_Int8> & rId)959 sal_Int64 SwXTextPortion::getSomething( const uno::Sequence< sal_Int8 >& rId )
960 {
961 if( rId.getLength() == 16
962 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
963 rId.getConstArray(), 16 ) )
964 {
965 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
966 }
967 return 0;
968 }
969 /* -----------------24.03.99 13:30-------------------
970 *
971 * --------------------------------------------------*/
getAvailableServiceNames()972 uno::Sequence< OUString > SwXTextPortion::getAvailableServiceNames()
973 {
974 vos::OGuard aGuard(Application::GetSolarMutex());
975 uno::Sequence< OUString > aRet(1);
976 OUString* pArray = aRet.getArray();
977 pArray[0] = C2U("com.sun.star.text.TextContent");
978 return aRet;
979 }
980 /* -----------------25.03.99 10:30-------------------
981 *
982 * --------------------------------------------------*/
getImplementationName()983 OUString SwXTextPortion::getImplementationName()
984 {
985 return C2U("SwXTextPortion");
986 }
987 /* -----------------25.03.99 10:30-------------------
988 *
989 * --------------------------------------------------*/
supportsService(const OUString & rServiceName)990 sal_Bool SwXTextPortion::supportsService(const OUString& rServiceName)
991 {
992 vos::OGuard aGuard(Application::GetSolarMutex());
993 SwUnoCrsr* pUnoCrsr = GetCursor();
994 if(!pUnoCrsr)
995 throw uno::RuntimeException();
996
997 sal_Bool bRet = sal_False;
998 if(!rServiceName.compareToAscii("com.sun.star.text.TextPortion") ||
999 !rServiceName.compareToAscii("com.sun.star.style.CharacterProperties") ||
1000 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesAsian") ||
1001 !rServiceName.compareToAscii("com.sun.star.style.CharacterPropertiesComplex") ||
1002 !rServiceName.compareToAscii("com.sun.star.style.ParagraphProperties") ||
1003 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesAsian") ||
1004 !rServiceName.compareToAscii("com.sun.star.style.ParagraphPropertiesComplex"))
1005 {
1006 bRet = sal_True;
1007 }
1008
1009 return bRet;
1010 }
1011 /* ---------------------------------------------------------------------------
1012
1013 ---------------------------------------------------------------------------*/
getSupportedServiceNames()1014 uno::Sequence< OUString > SwXTextPortion::getSupportedServiceNames()
1015 {
1016 vos::OGuard aGuard(Application::GetSolarMutex());
1017 SwUnoCrsr* pUnoCrsr = GetCursor();
1018 if (!pUnoCrsr)
1019 throw uno::RuntimeException();
1020
1021 uno::Sequence< OUString > aRet(7);
1022 OUString* pArray = aRet.getArray();
1023 pArray[0] = C2U("com.sun.star.text.TextPortion");
1024 pArray[1] = C2U("com.sun.star.style.CharacterProperties");
1025 pArray[2] = C2U("com.sun.star.style.CharacterPropertiesAsian");
1026 pArray[3] = C2U("com.sun.star.style.CharacterPropertiesComplex");
1027 pArray[4] = C2U("com.sun.star.style.ParagraphProperties");
1028 pArray[5] = C2U("com.sun.star.style.ParagraphPropertiesAsian");
1029 pArray[6] = C2U("com.sun.star.style.ParagraphPropertiesComplex");
1030 return aRet;
1031 }
1032 /*-- 11.12.98 09:57:01---------------------------------------------------
1033
1034 -----------------------------------------------------------------------*/
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1035 void SwXTextPortion::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
1036 {
1037 ClientModify(this, pOld, pNew);
1038 if (!m_FrameDepend.GetRegisteredIn())
1039 {
1040 m_pFrameFmt = 0;
1041 }
1042 }
1043