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 :
50 : using namespace ::com::sun::star;
51 :
52 : /******************************************************************
53 : * SwXTextPortion
54 : ******************************************************************/
55 :
56 5627 : class SwXTextPortion::Impl
57 : {
58 : private:
59 : ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
60 :
61 : public:
62 : ::cppu::OInterfaceContainerHelper m_EventListeners;
63 :
64 5627 : Impl() : m_EventListeners(m_Mutex) { }
65 : };
66 :
67 5627 : void SwXTextPortion::init(const SwUnoCrsr* pPortionCursor)
68 : {
69 : SwUnoCrsr* pUnoCursor =
70 5627 : pPortionCursor->GetDoc()->CreateUnoCrsr(*pPortionCursor->GetPoint());
71 5627 : if (pPortionCursor->HasMark())
72 : {
73 5627 : pUnoCursor->SetMark();
74 5627 : *pUnoCursor->GetMark() = *pPortionCursor->GetMark();
75 : }
76 5627 : pUnoCursor->Add(this);
77 5627 : }
78 :
79 5358 : SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
80 : uno::Reference< text::XText > const& rParent,
81 : SwTextPortionType eType)
82 5358 : : m_pImpl(new Impl)
83 : , m_pPropSet(aSwMapProvider.GetPropertySet(
84 5338 : (PORTION_REDLINE_START == eType ||
85 : PORTION_REDLINE_END == eType)
86 : ? PROPERTY_MAP_REDLINE_PORTION
87 5398 : : 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 16074 : , m_bIsCollapsed(false)
97 : {
98 5358 : init( pPortionCrsr);
99 5358 : }
100 :
101 25 : SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
102 : uno::Reference< text::XText > const& rParent,
103 : SwFrmFmt& rFmt )
104 25 : : m_pImpl(new Impl)
105 : , m_pPropSet(aSwMapProvider.GetPropertySet(
106 25 : PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
107 : , m_xParentText(rParent)
108 : , m_pRubyText(0)
109 : , m_pRubyStyle(0)
110 : , m_pRubyAdjust(0)
111 : , m_pRubyIsAbove(0)
112 : , m_FrameDepend(this, &rFmt)
113 : , m_pFrameFmt(&rFmt)
114 : , m_ePortionType(PORTION_FRAME)
115 75 : , m_bIsCollapsed(false)
116 : {
117 25 : init( pPortionCrsr);
118 25 : }
119 :
120 244 : SwXTextPortion::SwXTextPortion(const SwUnoCrsr* pPortionCrsr,
121 : SwTxtRuby const& rAttr,
122 : uno::Reference< text::XText > const& xParent,
123 : sal_Bool bIsEnd )
124 244 : : m_pImpl(new Impl)
125 : , m_pPropSet(aSwMapProvider.GetPropertySet(
126 244 : PROPERTY_MAP_TEXTPORTION_EXTENSIONS))
127 : , m_xParentText(xParent)
128 122 : , m_pRubyText ( bIsEnd ? 0 : new uno::Any )
129 122 : , m_pRubyStyle ( bIsEnd ? 0 : new uno::Any )
130 122 : , m_pRubyAdjust ( bIsEnd ? 0 : new uno::Any )
131 122 : , m_pRubyIsAbove( bIsEnd ? 0 : new uno::Any )
132 : , m_FrameDepend(this, 0)
133 : , m_pFrameFmt(0)
134 : , m_ePortionType( bIsEnd ? PORTION_RUBY_END : PORTION_RUBY_START )
135 1220 : , m_bIsCollapsed(false)
136 : {
137 244 : init( pPortionCrsr);
138 :
139 244 : if (!bIsEnd)
140 : {
141 122 : const SfxPoolItem& rItem = rAttr.GetAttr();
142 122 : rItem.QueryValue(*m_pRubyText, MID_RUBY_TEXT);
143 122 : rItem.QueryValue(*m_pRubyStyle, MID_RUBY_CHARSTYLE);
144 122 : rItem.QueryValue(*m_pRubyAdjust, MID_RUBY_ADJUST);
145 122 : rItem.QueryValue(*m_pRubyIsAbove, MID_RUBY_ABOVE);
146 : }
147 244 : }
148 :
149 16841 : SwXTextPortion::~SwXTextPortion()
150 : {
151 5627 : SolarMutexGuard aGuard;
152 5627 : SwUnoCrsr* pUnoCrsr = GetCursor();
153 5627 : delete pUnoCrsr;
154 11214 : }
155 :
156 0 : uno::Reference< text::XText > SwXTextPortion::getText()
157 : throw( uno::RuntimeException )
158 : {
159 0 : return m_xParentText;
160 : }
161 :
162 0 : uno::Reference< text::XTextRange > SwXTextPortion::getStart()
163 : throw( uno::RuntimeException )
164 : {
165 0 : SolarMutexGuard aGuard;
166 0 : uno::Reference< text::XTextRange > xRet;
167 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
168 0 : if (!pUnoCrsr)
169 0 : throw uno::RuntimeException();
170 :
171 0 : SwPaM aPam(*pUnoCrsr->Start());
172 0 : uno::Reference< text::XText > xParent = getText();
173 0 : xRet = new SwXTextRange(aPam, xParent);
174 0 : return xRet;
175 : }
176 :
177 0 : uno::Reference< text::XTextRange > SwXTextPortion::getEnd()
178 : throw( uno::RuntimeException )
179 : {
180 0 : SolarMutexGuard aGuard;
181 0 : uno::Reference< text::XTextRange > xRet;
182 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
183 0 : if (!pUnoCrsr)
184 0 : throw uno::RuntimeException();
185 :
186 0 : SwPaM aPam(*pUnoCrsr->End());
187 0 : uno::Reference< text::XText > xParent = getText();
188 0 : xRet = new SwXTextRange(aPam, xParent);
189 0 : return xRet;
190 : }
191 :
192 2454 : OUString SwXTextPortion::getString()
193 : throw( uno::RuntimeException )
194 : {
195 2454 : SolarMutexGuard aGuard;
196 2454 : OUString aTxt;
197 2454 : SwUnoCrsr* pUnoCrsr = GetCursor();
198 2454 : if (!pUnoCrsr)
199 0 : throw uno::RuntimeException();
200 :
201 : // TextPortions are always within a paragraph
202 2454 : SwTxtNode* pTxtNd = pUnoCrsr->GetNode()->GetTxtNode();
203 2454 : if ( pTxtNd )
204 : {
205 2454 : xub_StrLen nStt = pUnoCrsr->Start()->nContent.GetIndex();
206 4908 : aTxt = pTxtNd->GetExpandTxt( nStt,
207 4908 : pUnoCrsr->End()->nContent.GetIndex() - nStt );
208 : }
209 2454 : return aTxt;
210 : }
211 :
212 0 : void SwXTextPortion::setString(const OUString& aString) throw( uno::RuntimeException )
213 : {
214 0 : SolarMutexGuard aGuard;
215 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
216 0 : if (!pUnoCrsr)
217 0 : throw uno::RuntimeException();
218 :
219 0 : SwUnoCursorHelper::SetString(*pUnoCrsr, aString);
220 0 : }
221 :
222 5875 : uno::Reference< beans::XPropertySetInfo > SwXTextPortion::getPropertySetInfo()
223 : throw( uno::RuntimeException )
224 : {
225 5875 : SolarMutexGuard aGuard;
226 : //! PropertySetInfo for text portion extensions
227 : static uno::Reference< beans::XPropertySetInfo >
228 : xTxtPorExtRef = aSwMapProvider.GetPropertySet(
229 5875 : PROPERTY_MAP_TEXTPORTION_EXTENSIONS)->getPropertySetInfo();
230 : //! PropertySetInfo for redline portions
231 : static uno::Reference< beans::XPropertySetInfo >
232 : xRedlPorRef = aSwMapProvider.GetPropertySet(
233 5875 : PROPERTY_MAP_REDLINE_PORTION)->getPropertySetInfo();
234 :
235 11750 : return (PORTION_REDLINE_START == m_ePortionType ||
236 5875 : PORTION_REDLINE_END == m_ePortionType) ? xRedlPorRef : xTxtPorExtRef;
237 : }
238 :
239 0 : void SwXTextPortion::setPropertyValue(const OUString& rPropertyName,
240 : const uno::Any& aValue)
241 : throw( beans::UnknownPropertyException,
242 : beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
243 : {
244 0 : SolarMutexGuard aGuard;
245 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
246 0 : if (!pUnoCrsr)
247 0 : throw uno::RuntimeException();
248 :
249 : SwUnoCursorHelper::SetPropertyValue(*pUnoCrsr, *m_pPropSet,
250 0 : rPropertyName, aValue);
251 0 : }
252 :
253 12208 : void SwXTextPortion::GetPropertyValue(
254 : uno::Any &rVal,
255 : const SfxItemPropertySimpleEntry& rEntry,
256 : SwUnoCrsr *pUnoCrsr,
257 : SfxItemSet *&pSet )
258 : {
259 : OSL_ENSURE( pUnoCrsr, "UNO cursor missing" );
260 12208 : if (!pUnoCrsr)
261 12208 : return;
262 12208 : if(pUnoCrsr)
263 : {
264 12208 : switch(rEntry.nWID)
265 : {
266 : case FN_UNO_TEXT_PORTION_TYPE:
267 : {
268 : const char* pRet;
269 5022 : switch (m_ePortionType)
270 : {
271 2452 : case PORTION_TEXT: pRet = "Text";break;
272 63 : case PORTION_FIELD: pRet = "TextField";break;
273 45 : case PORTION_FRAME: pRet = "Frame";break;
274 17 : case PORTION_FOOTNOTE: pRet = "Footnote";break;
275 : case PORTION_REFMARK_START:
276 46 : case PORTION_REFMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_REFERENCE_MARK);break;
277 : case PORTION_TOXMARK_START:
278 45 : case PORTION_TOXMARK_END: pRet = SW_PROP_NAME_STR(UNO_NAME_DOCUMENT_INDEX_MARK);break;
279 : case PORTION_BOOKMARK_START :
280 1938 : case PORTION_BOOKMARK_END : pRet = SW_PROP_NAME_STR(UNO_NAME_BOOKMARK);break;
281 : case PORTION_REDLINE_START:
282 0 : case PORTION_REDLINE_END: pRet = "Redline";break;
283 : case PORTION_RUBY_START:
284 244 : case PORTION_RUBY_END: pRet = "Ruby";break;
285 7 : case PORTION_SOFT_PAGEBREAK:pRet = "SoftPageBreak";break;
286 145 : case PORTION_META: pRet = SW_PROP_NAME_STR(UNO_NAME_META); break;
287 11 : case PORTION_FIELD_START:pRet = "TextFieldStart";break;
288 9 : case PORTION_FIELD_END:pRet = "TextFieldEnd";break;
289 0 : case PORTION_FIELD_START_END:pRet = "TextFieldStartEnd";break;
290 : default:
291 0 : pRet = 0;
292 : }
293 :
294 5022 : OUString sRet;
295 5022 : if( pRet )
296 5022 : sRet = OUString::createFromAscii( pRet );
297 5022 : rVal <<= sRet;
298 : }
299 16709 : break;
300 : case FN_UNO_CONTROL_CHARACTER: // obsolete!
301 0 : break;
302 : case FN_UNO_DOCUMENT_INDEX_MARK:
303 45 : rVal <<= m_xTOXMark;
304 45 : break;
305 : case FN_UNO_REFERENCE_MARK:
306 46 : rVal <<= m_xRefMark;
307 46 : break;
308 : case FN_UNO_BOOKMARK:
309 1955 : rVal <<= m_xBookmark;
310 1955 : break;
311 : case FN_UNO_FOOTNOTE:
312 18 : rVal <<= m_xFootnote;
313 18 : break;
314 : case FN_UNO_TEXT_FIELD:
315 61 : rVal <<= m_xTextField;
316 61 : break;
317 : case FN_UNO_META:
318 145 : rVal <<= m_xMeta;
319 145 : break;
320 : case FN_UNO_IS_COLLAPSED:
321 : {
322 2037 : switch (m_ePortionType)
323 : {
324 : case PORTION_REFMARK_START:
325 : case PORTION_BOOKMARK_START :
326 : case PORTION_TOXMARK_START:
327 : case PORTION_REFMARK_END:
328 : case PORTION_TOXMARK_END:
329 : case PORTION_BOOKMARK_END :
330 : case PORTION_REDLINE_START :
331 : case PORTION_REDLINE_END :
332 : case PORTION_RUBY_START:
333 : case PORTION_RUBY_END:
334 : case PORTION_FIELD_START:
335 : case PORTION_FIELD_END:
336 2037 : rVal.setValue(&m_bIsCollapsed, ::getBooleanCppuType());
337 2037 : break;
338 : default:
339 0 : break;
340 : }
341 : }
342 2037 : break;
343 : case FN_UNO_IS_START:
344 : {
345 2218 : sal_Bool bStart = sal_True, bPut = sal_True;
346 2218 : switch (m_ePortionType)
347 : {
348 : case PORTION_REFMARK_START:
349 : case PORTION_BOOKMARK_START:
350 : case PORTION_TOXMARK_START:
351 : case PORTION_REDLINE_START:
352 : case PORTION_RUBY_START:
353 : case PORTION_FIELD_START:
354 1109 : break;
355 :
356 : case PORTION_REFMARK_END:
357 : case PORTION_TOXMARK_END:
358 : case PORTION_BOOKMARK_END:
359 : case PORTION_REDLINE_END:
360 : case PORTION_RUBY_END:
361 : case PORTION_FIELD_END:
362 1109 : bStart = sal_False;
363 1109 : break;
364 : default:
365 0 : bPut = sal_False;
366 : }
367 2218 : if(bPut)
368 2218 : rVal.setValue(&bStart, ::getBooleanCppuType());
369 : }
370 2218 : break;
371 : case RES_TXTATR_CJK_RUBY:
372 : {
373 140 : const uno::Any* pToSet = 0;
374 140 : switch(rEntry.nMemberId)
375 : {
376 122 : case MID_RUBY_TEXT : pToSet = m_pRubyText.get(); break;
377 6 : case MID_RUBY_ADJUST : pToSet = m_pRubyAdjust.get(); break;
378 6 : case MID_RUBY_CHARSTYLE:pToSet = m_pRubyStyle.get(); break;
379 6 : case MID_RUBY_ABOVE : pToSet = m_pRubyIsAbove.get();break;
380 : }
381 140 : if(pToSet)
382 140 : rVal = *pToSet;
383 : }
384 140 : break;
385 : default:
386 : beans::PropertyState eTemp;
387 : bool bDone = SwUnoCursorHelper::getCrsrPropertyValue(
388 521 : rEntry, *pUnoCrsr, &(rVal), eTemp );
389 521 : if(!bDone)
390 : {
391 521 : if(!pSet)
392 : {
393 521 : pSet = new SfxItemSet(pUnoCrsr->GetDoc()->GetAttrPool(),
394 : RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
395 : RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
396 : RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
397 521 : 0L);
398 521 : SwUnoCursorHelper::GetCrsrAttr(*pUnoCrsr, *pSet);
399 : }
400 521 : m_pPropSet->getPropertyValue(rEntry, *pSet, rVal);
401 : }
402 : }
403 : }
404 : }
405 :
406 12192 : uno::Sequence< uno::Any > SAL_CALL SwXTextPortion::GetPropertyValues_Impl(
407 : const uno::Sequence< OUString >& rPropertyNames )
408 : throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
409 : {
410 12192 : sal_Int32 nLength = rPropertyNames.getLength();
411 12192 : const OUString *pPropertyNames = rPropertyNames.getConstArray();
412 12192 : uno::Sequence< uno::Any > aValues(rPropertyNames.getLength());
413 12192 : uno::Any *pValues = aValues.getArray();
414 12192 : SwUnoCrsr* pUnoCrsr = GetCursor();
415 12192 : if (!pUnoCrsr)
416 0 : throw uno::RuntimeException();
417 :
418 : {
419 12192 : SfxItemSet *pSet = 0;
420 : // get startting pount fo the look-up, either the provided one or else
421 : // from the beginning of the map
422 12192 : const SfxItemPropertyMap& rMap = m_pPropSet->getPropertyMap();
423 24384 : for(sal_Int32 nProp = 0; nProp < nLength; nProp++)
424 : {
425 12192 : const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(pPropertyNames[nProp]);
426 12192 : if(pEntry)
427 : {
428 12192 : GetPropertyValue( pValues[nProp], *pEntry, pUnoCrsr, pSet );
429 : }
430 : else
431 0 : throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
432 : }
433 12192 : delete pSet;
434 : }
435 12192 : return aValues;
436 : }
437 :
438 12192 : uno::Any SwXTextPortion::getPropertyValue(
439 : const OUString& rPropertyName)
440 : throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
441 : {
442 12192 : SolarMutexGuard aGuard;
443 24384 : uno::Sequence< OUString > aPropertyNames(1);
444 12192 : aPropertyNames.getArray()[0] = rPropertyName;
445 24384 : return GetPropertyValues_Impl(aPropertyNames).getConstArray()[0];
446 : }
447 :
448 0 : void SAL_CALL SwXTextPortion::SetPropertyValues_Impl(
449 : const uno::Sequence< OUString >& rPropertyNames,
450 : const uno::Sequence< uno::Any >& rValues )
451 : throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
452 : lang::WrappedTargetException, uno::RuntimeException)
453 : {
454 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
455 0 : if (!pUnoCrsr)
456 0 : throw uno::RuntimeException();
457 :
458 : {
459 0 : const OUString* pPropertyNames = rPropertyNames.getConstArray();
460 0 : const uno::Any* pValues = rValues.getConstArray();
461 0 : const SfxItemPropertyMap& rMap = m_pPropSet->getPropertyMap();
462 0 : for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); nProp++)
463 : {
464 0 : const SfxItemPropertySimpleEntry* pEntry = rMap.getByName(pPropertyNames[nProp]);
465 0 : if (!pEntry)
466 0 : throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
467 0 : if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
468 0 : throw beans::PropertyVetoException ("Property is read-only: " + pPropertyNames[nProp], static_cast < cppu::OWeakObject * > ( this ) );
469 :
470 : SwUnoCursorHelper::SetPropertyValue( *pUnoCrsr, *m_pPropSet,
471 0 : pPropertyNames[nProp], pValues[nProp]);
472 : }
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)
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)
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)
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)
598 : {
599 0 : SolarMutexGuard aGuard;
600 :
601 : uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
602 0 : GetPropertyValuesTolerant_Impl( rPropertyNames, sal_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 1962 : uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::getDirectPropertyValuesTolerant(
615 : const uno::Sequence< OUString >& rPropertyNames )
616 : throw (uno::RuntimeException)
617 : {
618 1962 : SolarMutexGuard aGuard;
619 1962 : return GetPropertyValuesTolerant_Impl( rPropertyNames, sal_True );
620 : }
621 :
622 1962 : uno::Sequence< beans::GetDirectPropertyTolerantResult > SAL_CALL SwXTextPortion::GetPropertyValuesTolerant_Impl(
623 : const uno::Sequence< OUString >& rPropertyNames,
624 : sal_Bool bDirectValuesOnly )
625 : throw (uno::RuntimeException)
626 : {
627 1962 : SolarMutexGuard aGuard;
628 :
629 1962 : SwUnoCrsr* pUnoCrsr = this->GetCursor();
630 1962 : if(!pUnoCrsr)
631 0 : throw uno::RuntimeException();
632 :
633 1962 : sal_Int32 nProps = rPropertyNames.getLength();
634 1962 : const OUString *pProp = rPropertyNames.getConstArray();
635 :
636 1962 : SfxItemSet *pSet = 0;
637 :
638 1962 : const SfxItemPropertyMap& rPropMap = m_pPropSet->getPropertyMap();
639 :
640 : uno::Sequence< beans::PropertyState > aPropertyStates =
641 : SwUnoCursorHelper::GetPropertyStates(
642 : *pUnoCrsr, *m_pPropSet,
643 : rPropertyNames,
644 3924 : SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT );
645 1962 : const beans::PropertyState* pPropertyStates = aPropertyStates.getConstArray();
646 :
647 3924 : std::vector< beans::GetDirectPropertyTolerantResult > aResultVector;
648 125202 : for (sal_Int32 i = 0; i < nProps; ++i)
649 : {
650 123240 : beans::GetDirectPropertyTolerantResult aResult;
651 : try
652 : {
653 123240 : aResult.Name = pProp[i];
654 123240 : if(pPropertyStates[i] == beans::PropertyState_MAKE_FIXED_SIZE) // property unknown?
655 : {
656 0 : if( bDirectValuesOnly )
657 0 : continue;
658 : else
659 0 : aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
660 : }
661 : else
662 : {
663 123240 : const SfxItemPropertySimpleEntry* pEntry = rPropMap.getByName( pProp[i] );
664 123240 : aResult.State = pPropertyStates[i];
665 :
666 123240 : aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_FAILURE;
667 : //#i104499# ruby portion attributes need special handling:
668 123252 : if( pEntry->nWID == RES_TXTATR_CJK_RUBY &&
669 12 : m_ePortionType == PORTION_RUBY_START )
670 : {
671 12 : aResult.State = beans::PropertyState_DIRECT_VALUE;
672 : }
673 123240 : if (!bDirectValuesOnly || beans::PropertyState_DIRECT_VALUE == aResult.State)
674 : {
675 : // get property value
676 : // (compare to SwXTextPortion::getPropertyValue(s))
677 16 : GetPropertyValue( aResult.Value, *pEntry, pUnoCrsr, pSet );
678 16 : aResult.Result = beans::TolerantPropertySetResultType::SUCCESS;
679 16 : aResultVector.push_back( aResult );
680 : }
681 : }
682 : }
683 0 : catch (beans::UnknownPropertyException &)
684 : {
685 : // should not occur because property was searched for before
686 : OSL_FAIL( "unexpected exception caught" );
687 0 : aResult.Result = beans::TolerantPropertySetResultType::UNKNOWN_PROPERTY;
688 : }
689 0 : catch (lang::IllegalArgumentException &)
690 : {
691 0 : aResult.Result = beans::TolerantPropertySetResultType::ILLEGAL_ARGUMENT;
692 : }
693 0 : catch (beans::PropertyVetoException &)
694 : {
695 0 : aResult.Result = beans::TolerantPropertySetResultType::PROPERTY_VETO;
696 : }
697 0 : catch (lang::WrappedTargetException &)
698 : {
699 0 : aResult.Result = beans::TolerantPropertySetResultType::WRAPPED_TARGET;
700 : }
701 123240 : }
702 1962 : delete pSet;
703 :
704 1962 : uno::Sequence< beans::GetDirectPropertyTolerantResult > aResult( aResultVector.size() );
705 1962 : std::vector< beans::GetDirectPropertyTolerantResult >::const_iterator aIt = aResultVector.begin();
706 1962 : beans::GetDirectPropertyTolerantResult *pResult = aResult.getArray();
707 1978 : for( sal_Int32 nResult = 0; nResult < aResult.getLength(); ++nResult )
708 : {
709 16 : pResult[nResult] = *aIt;
710 16 : ++aIt;
711 : }
712 :
713 3924 : return aResult;
714 : }
715 :
716 0 : void SwXTextPortion::addPropertiesChangeListener(
717 : const uno::Sequence< OUString >& /*aPropertyNames*/,
718 : const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
719 : throw(uno::RuntimeException)
720 0 : {}
721 :
722 0 : void SwXTextPortion::removePropertiesChangeListener(
723 : const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
724 : throw(uno::RuntimeException)
725 0 : {}
726 :
727 0 : void SwXTextPortion::firePropertiesChangeEvent(
728 : const uno::Sequence< OUString >& /*aPropertyNames*/,
729 : const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ )
730 : throw(uno::RuntimeException)
731 0 : {}
732 :
733 0 : void SwXTextPortion::addPropertyChangeListener(
734 : const OUString& /*PropertyName*/,
735 : const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
736 : throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
737 : {
738 : OSL_FAIL("not implemented");
739 0 : }
740 :
741 0 : void SwXTextPortion::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
742 : {
743 : OSL_FAIL("not implemented");
744 0 : }
745 :
746 0 : void SwXTextPortion::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
747 : {
748 : OSL_FAIL("not implemented");
749 0 : }
750 :
751 0 : void SwXTextPortion::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
752 : {
753 : OSL_FAIL("not implemented");
754 0 : }
755 :
756 0 : beans::PropertyState SwXTextPortion::getPropertyState(const OUString& rPropertyName)
757 : throw( beans::UnknownPropertyException, uno::RuntimeException )
758 : {
759 0 : SolarMutexGuard aGuard;
760 0 : beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
761 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
762 0 : if (!pUnoCrsr)
763 0 : throw uno::RuntimeException();
764 :
765 0 : if (GetTextPortionType() == PORTION_RUBY_START &&
766 0 : rPropertyName.startsWith("Ruby"))
767 : {
768 0 : eRet = beans::PropertyState_DIRECT_VALUE;
769 : }
770 : else
771 : {
772 : eRet = SwUnoCursorHelper::GetPropertyState(*pUnoCrsr, *m_pPropSet,
773 0 : rPropertyName);
774 : }
775 0 : return eRet;
776 : }
777 :
778 0 : uno::Sequence< beans::PropertyState > SwXTextPortion::getPropertyStates(
779 : const uno::Sequence< OUString >& rPropertyNames)
780 : throw( beans::UnknownPropertyException, uno::RuntimeException )
781 : {
782 0 : SolarMutexGuard aGuard;
783 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
784 0 : if(!pUnoCrsr)
785 0 : throw uno::RuntimeException();
786 :
787 : uno::Sequence< beans::PropertyState > aRet =
788 : SwUnoCursorHelper::GetPropertyStates(*pUnoCrsr, *m_pPropSet,
789 0 : rPropertyNames, SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION);
790 :
791 0 : if(GetTextPortionType() == PORTION_RUBY_START)
792 : {
793 0 : const OUString* pNames = rPropertyNames.getConstArray();
794 0 : beans::PropertyState* pStates = aRet.getArray();
795 0 : for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength();nProp++)
796 : {
797 0 : if (pNames[nProp].startsWith("Ruby"))
798 0 : pStates[nProp] = beans::PropertyState_DIRECT_VALUE;
799 : }
800 : }
801 0 : return aRet;
802 : }
803 :
804 0 : void SwXTextPortion::setPropertyToDefault(const OUString& rPropertyName)
805 : throw( beans::UnknownPropertyException, uno::RuntimeException )
806 : {
807 0 : SolarMutexGuard aGuard;
808 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
809 0 : if (!pUnoCrsr)
810 0 : throw uno::RuntimeException();
811 :
812 : SwUnoCursorHelper::SetPropertyToDefault(
813 0 : *pUnoCrsr, *m_pPropSet, rPropertyName);
814 0 : }
815 :
816 0 : uno::Any SwXTextPortion::getPropertyDefault(const OUString& rPropertyName)
817 : throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
818 : {
819 0 : SolarMutexGuard aGuard;
820 0 : uno::Any aRet;
821 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
822 0 : if (!pUnoCrsr)
823 0 : throw uno::RuntimeException();
824 :
825 0 : aRet = SwUnoCursorHelper::GetPropertyDefault(*pUnoCrsr, *m_pPropSet,
826 0 : rPropertyName);
827 0 : return aRet;
828 : }
829 :
830 0 : void SwXTextPortion::attach(const uno::Reference< text::XTextRange > & /*xTextRange*/)
831 : throw( lang::IllegalArgumentException, uno::RuntimeException )
832 : {
833 0 : SolarMutexGuard aGuard;
834 : // SwXTextPortion cannot be created at the factory therefore
835 : // they cannot be attached
836 0 : throw uno::RuntimeException();
837 : }
838 :
839 0 : uno::Reference< text::XTextRange > SwXTextPortion::getAnchor()
840 : throw( uno::RuntimeException )
841 : {
842 0 : SolarMutexGuard aGuard;
843 0 : uno::Reference< text::XTextRange > aRet;
844 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
845 0 : if (!pUnoCrsr)
846 0 : throw uno::RuntimeException();
847 :
848 0 : aRet = new SwXTextRange(*pUnoCrsr, m_xParentText);
849 0 : return aRet;
850 : }
851 :
852 0 : void SwXTextPortion::dispose()
853 : throw( uno::RuntimeException )
854 : {
855 0 : SolarMutexGuard aGuard;
856 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
857 0 : if (!pUnoCrsr)
858 0 : throw uno::RuntimeException();
859 :
860 0 : setString(aEmptyStr);
861 0 : pUnoCrsr->Remove(this);
862 0 : }
863 :
864 0 : void SAL_CALL SwXTextPortion::addEventListener(
865 : const uno::Reference<lang::XEventListener> & xListener)
866 : throw (uno::RuntimeException)
867 : {
868 : // no need to lock here as m_pImpl is const and container threadsafe
869 0 : m_pImpl->m_EventListeners.addInterface(xListener);
870 0 : }
871 :
872 0 : void SAL_CALL SwXTextPortion::removeEventListener(
873 : const uno::Reference<lang::XEventListener> & xListener)
874 : throw (uno::RuntimeException)
875 : {
876 : // no need to lock here as m_pImpl is const and container threadsafe
877 0 : m_pImpl->m_EventListeners.removeInterface(xListener);
878 0 : }
879 :
880 157 : uno::Reference< container::XEnumeration > SwXTextPortion::createContentEnumeration(const OUString& /*aServiceName*/)
881 : throw( uno::RuntimeException )
882 : {
883 157 : SolarMutexGuard aGuard;
884 157 : SwUnoCrsr* pUnoCrsr = GetCursor();
885 157 : if(!pUnoCrsr)
886 0 : throw uno::RuntimeException();
887 :
888 : uno::Reference< container::XEnumeration > xRet =
889 : new SwXParaFrameEnumeration(*pUnoCrsr, PARAFRAME_PORTION_CHAR,
890 157 : m_pFrameFmt);
891 157 : return xRet;
892 :
893 : }
894 :
895 : namespace
896 : {
897 : class theSwXTextPortionUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextPortionUnoTunnelId > {};
898 : }
899 :
900 9885 : const uno::Sequence< sal_Int8 > & SwXTextPortion::getUnoTunnelId()
901 : {
902 9885 : return theSwXTextPortionUnoTunnelId::get().getSeq();
903 : }
904 :
905 0 : sal_Int64 SwXTextPortion::getSomething( const uno::Sequence< sal_Int8 >& rId )
906 : throw(uno::RuntimeException)
907 : {
908 0 : if( rId.getLength() == 16
909 0 : && 0 == memcmp( getUnoTunnelId().getConstArray(),
910 0 : rId.getConstArray(), 16 ) )
911 : {
912 0 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
913 : }
914 0 : return 0;
915 : }
916 :
917 0 : uno::Sequence< OUString > SwXTextPortion::getAvailableServiceNames()
918 : throw( uno::RuntimeException )
919 : {
920 0 : SolarMutexGuard aGuard;
921 0 : uno::Sequence< OUString > aRet(1);
922 0 : OUString* pArray = aRet.getArray();
923 0 : pArray[0] = "com.sun.star.text.TextContent";
924 0 : return aRet;
925 : }
926 :
927 0 : OUString SwXTextPortion::getImplementationName()
928 : throw( uno::RuntimeException )
929 : {
930 0 : return OUString("SwXTextPortion");
931 : }
932 :
933 0 : sal_Bool SwXTextPortion::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
934 : {
935 0 : return cppu::supportsService(this, rServiceName);
936 : }
937 :
938 0 : uno::Sequence< OUString > SwXTextPortion::getSupportedServiceNames()
939 : throw( uno::RuntimeException )
940 : {
941 0 : SolarMutexGuard aGuard;
942 0 : SwUnoCrsr* pUnoCrsr = GetCursor();
943 0 : if (!pUnoCrsr)
944 0 : throw uno::RuntimeException();
945 :
946 0 : uno::Sequence< OUString > aRet(7);
947 0 : OUString* pArray = aRet.getArray();
948 0 : pArray[0] = "com.sun.star.text.TextPortion";
949 0 : pArray[1] = "com.sun.star.style.CharacterProperties";
950 0 : pArray[2] = "com.sun.star.style.CharacterPropertiesAsian";
951 0 : pArray[3] = "com.sun.star.style.CharacterPropertiesComplex";
952 0 : pArray[4] = "com.sun.star.style.ParagraphProperties";
953 0 : pArray[5] = "com.sun.star.style.ParagraphPropertiesAsian";
954 0 : pArray[6] = "com.sun.star.style.ParagraphPropertiesComplex";
955 0 : return aRet;
956 : }
957 :
958 5673 : void SwXTextPortion::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
959 : {
960 5673 : ClientModify(this, pOld, pNew);
961 5673 : if (!m_FrameDepend.GetRegisteredIn())
962 : {
963 5602 : m_pFrameFmt = 0;
964 : }
965 5772 : }
966 :
967 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|