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