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