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