bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / uno / unotext.cxx
blobed896e2e2ac834bb40496ab3b18d9be4ad33a080
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
21 #include <com/sun/star/style/LineSpacing.hpp>
22 #include <com/sun/star/text/ControlCharacter.hpp>
23 #include <com/sun/star/text/XTextField.hpp>
24 #include <com/sun/star/text/TextRangeSelection.hpp>
26 #include <osl/mutex.hxx>
27 #include <svl/itemset.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/intitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <rtl/instance.hxx>
33 #include <editeng/fontitem.hxx>
34 #include <editeng/tstpitem.hxx>
35 #include <editeng/unoprnms.hxx>
36 #include <editeng/unotext.hxx>
37 #include <editeng/unoedsrc.hxx>
38 #include <editeng/unonrule.hxx>
39 #include <editeng/unofdesc.hxx>
40 #include <editeng/unofield.hxx>
41 #include <editeng/flditem.hxx>
42 #include <editeng/numitem.hxx>
43 #include <editeng/editeng.hxx>
44 #include <editeng/outliner.hxx>
45 #include <editeng/unoipset.hxx>
46 #include <comphelper/servicehelper.hxx>
47 #include <comphelper/serviceinfohelper.hxx>
48 #include <cppuhelper/supportsservice.hxx>
50 #include "editeng/unonames.hxx"
52 #include <boost/scoped_ptr.hpp>
54 using namespace ::cppu;
55 using namespace ::com::sun::star;
57 namespace {
59 ESelection toESelection(const text::TextRangeSelection& rSel)
61 ESelection aESel;
62 aESel.nStartPara = rSel.Start.Paragraph;
63 aESel.nStartPos = rSel.Start.PositionInParagraph;
64 aESel.nEndPara = rSel.End.Paragraph;
65 aESel.nEndPos = rSel.End.PositionInParagraph;
66 return aESel;
71 #define QUERYINT( xint ) \
72 if( rType == cppu::UnoType<xint>::get() ) \
73 return uno::makeAny(uno::Reference< xint >(this))
75 const SvxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet()
77 static SvxItemPropertySet aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() );
78 return &aTextCursorSvxPropertySet;
81 const SfxItemPropertyMapEntry* ImplGetSvxTextPortionPropertyMap()
83 // Propertymap for an Outliner Text
84 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
86 SVX_UNOEDIT_CHAR_PROPERTIES,
87 SVX_UNOEDIT_FONT_PROPERTIES,
88 SVX_UNOEDIT_OUTLINER_PROPERTIES,
89 SVX_UNOEDIT_PARA_PROPERTIES,
90 {OUString("TextField"), EE_FEATURE_FIELD, cppu::UnoType<text::XTextField>::get(), beans::PropertyAttribute::READONLY, 0 },
91 {OUString("TextPortionType"), WID_PORTIONTYPE, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
92 {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
93 {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
94 { OUString(), 0, css::uno::Type(), 0, 0 }
96 return aSvxTextPortionPropertyMap;
98 const SvxItemPropertySet* ImplGetSvxTextPortionSvxPropertySet()
100 static SvxItemPropertySet aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() );
101 return &aSvxTextPortionPropertySet;
104 const SfxItemPropertySet* ImplGetSvxTextPortionSfxPropertySet()
106 static SfxItemPropertySet aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() );
107 return &aSvxTextPortionSfxPropertySet;
110 const SfxItemPropertyMapEntry* ImplGetSvxUnoOutlinerTextCursorPropertyMap()
112 // Propertymap for an Outliner Text
113 static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap[] =
115 SVX_UNOEDIT_CHAR_PROPERTIES,
116 SVX_UNOEDIT_FONT_PROPERTIES,
117 SVX_UNOEDIT_OUTLINER_PROPERTIES,
118 SVX_UNOEDIT_PARA_PROPERTIES,
119 {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
120 {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
121 { OUString(), 0, css::uno::Type(), 0, 0 }
124 return aSvxUnoOutlinerTextCursorPropertyMap;
126 const SfxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
128 static SfxItemPropertySet aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
129 return &aTextCursorSfxPropertySet;
133 // helper for Item/Property conversion
136 void GetSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw()
138 DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" );
139 if( pForwarder )
141 sal_Int32 nParaCount = pForwarder->GetParagraphCount();
142 if(nParaCount>0)
143 nParaCount--;
145 rSel = ESelection( 0,0, nParaCount, pForwarder->GetTextLen( nParaCount ));
149 void CheckSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw()
151 DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" );
152 if( pForwarder )
154 if( rSel.nStartPara == EE_PARA_MAX_COUNT )
156 ::GetSelection( rSel, pForwarder );
158 else
160 ESelection aMaxSelection;
161 GetSelection( aMaxSelection, pForwarder );
163 // check start position
164 if( rSel.nStartPara < aMaxSelection.nStartPara )
166 rSel.nStartPara = aMaxSelection.nStartPara;
167 rSel.nStartPos = aMaxSelection.nStartPos;
169 else if( rSel.nStartPara > aMaxSelection.nEndPara )
171 rSel.nStartPara = aMaxSelection.nEndPara;
172 rSel.nStartPos = aMaxSelection.nEndPos;
174 else if( rSel.nStartPos > pForwarder->GetTextLen( rSel.nStartPara ) )
176 rSel.nStartPos = pForwarder->GetTextLen( rSel.nStartPara );
179 // check end position
180 if( rSel.nEndPara < aMaxSelection.nStartPara )
182 rSel.nEndPara = aMaxSelection.nStartPara;
183 rSel.nEndPos = aMaxSelection.nStartPos;
185 else if( rSel.nEndPara > aMaxSelection.nEndPara )
187 rSel.nEndPara = aMaxSelection.nEndPara;
188 rSel.nEndPos = aMaxSelection.nEndPos;
190 else if( rSel.nEndPos > pForwarder->GetTextLen( rSel.nEndPara ) )
192 rSel.nEndPos = pForwarder->GetTextLen( rSel.nEndPara );
198 void CheckSelection( struct ESelection& rSel, SvxEditSource *pEdit ) throw()
200 if (!pEdit)
201 return;
202 CheckSelection( rSel, pEdit->GetTextForwarder() );
206 // class SvxUnoTextRangeBase
209 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase );
211 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxItemPropertySet* _pSet ) throw()
212 : mpEditSource(NULL) , mpPropSet(_pSet)
216 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet ) throw()
217 : mpPropSet(_pSet)
219 SolarMutexGuard aGuard;
221 DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
223 mpEditSource = pSource->Clone();
224 if (mpEditSource != NULL)
226 ESelection aSelection;
227 ::GetSelection( aSelection, mpEditSource->GetTextForwarder() );
228 SetSelection( aSelection );
230 mpEditSource->addRange( this );
234 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxUnoTextRangeBase& rRange ) throw()
235 : text::XTextRange()
236 , beans::XPropertySet()
237 , beans::XMultiPropertySet()
238 , beans::XMultiPropertyStates()
239 , beans::XPropertyState()
240 , lang::XServiceInfo()
241 , text::XTextRangeCompare()
242 , lang::XUnoTunnel()
243 , osl::DebugBase<SvxUnoTextRangeBase>()
244 , mpPropSet(rRange.getPropertySet())
246 SolarMutexGuard aGuard;
248 mpEditSource = rRange.mpEditSource ? rRange.mpEditSource->Clone() : NULL;
250 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
251 if( pForwarder )
253 maSelection = rRange.maSelection;
254 CheckSelection( maSelection, pForwarder );
257 if( mpEditSource )
258 mpEditSource->addRange( this );
261 SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw()
263 if( mpEditSource )
264 mpEditSource->removeRange( this );
266 delete mpEditSource;
269 void SvxUnoTextRangeBase::SetEditSource( SvxEditSource* pSource ) throw()
271 DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
272 DBG_ASSERT(mpEditSource==NULL,"SvxUnoTextRangeBase::SetEditSource called while SvxEditSource already set" );
274 mpEditSource = pSource;
276 maSelection.nStartPara = EE_PARA_MAX_COUNT;
278 if( mpEditSource )
279 mpEditSource->addRange( this );
282 /** puts a field item with a copy of the given FieldData into the itemset
283 corresponding with this range */
284 void SvxUnoTextRangeBase::attachField( const SvxFieldData* pData ) throw()
286 SolarMutexGuard aGuard;
288 if( pData )
290 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
291 if( pForwarder )
293 SvxFieldItem aField( *pData, EE_FEATURE_FIELD );
294 pForwarder->QuickInsertField( aField, maSelection );
299 void SvxUnoTextRangeBase::SetSelection( const ESelection& rSelection ) throw()
301 SolarMutexGuard aGuard;
303 maSelection = rSelection;
304 CheckSelection( maSelection, mpEditSource );
307 // Interface XTextRange ( XText )
309 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getStart()
310 throw( uno::RuntimeException, std::exception )
312 SolarMutexGuard aGuard;
314 uno::Reference< text::XTextRange > xRange;
316 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
317 if( pForwarder )
319 CheckSelection( maSelection, pForwarder );
321 SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() );
323 if(pText == NULL)
324 throw uno::RuntimeException();
326 SvxUnoTextRange* pRange = new SvxUnoTextRange( *pText );
327 xRange = pRange;
329 ESelection aNewSel = maSelection;
330 aNewSel.nEndPara = aNewSel.nStartPara;
331 aNewSel.nEndPos = aNewSel.nStartPos;
332 pRange->SetSelection( aNewSel );
335 return xRange;
338 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getEnd()
339 throw( uno::RuntimeException, std::exception )
341 SolarMutexGuard aGuard;
343 uno::Reference< text::XTextRange > xRet;
345 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
346 if( pForwarder )
348 CheckSelection( maSelection, pForwarder );
350 SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() );
352 if(pText == NULL)
353 throw uno::RuntimeException();
355 SvxUnoTextRange* pNew = new SvxUnoTextRange( *pText );
356 xRet = pNew;
358 ESelection aNewSel = maSelection;
359 aNewSel.nStartPara = aNewSel.nEndPara;
360 aNewSel.nStartPos = aNewSel.nEndPos;
361 pNew->SetSelection( aNewSel );
363 return xRet;
366 OUString SAL_CALL SvxUnoTextRangeBase::getString()
367 throw( uno::RuntimeException, std::exception )
369 SolarMutexGuard aGuard;
371 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
372 if( pForwarder )
374 CheckSelection( maSelection, pForwarder );
376 return pForwarder->GetText( maSelection );
378 else
380 const OUString aEmpty;
381 return aEmpty;
385 void SAL_CALL SvxUnoTextRangeBase::setString(const OUString& aString)
386 throw( uno::RuntimeException, std::exception )
388 SolarMutexGuard aGuard;
390 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
391 if( pForwarder )
393 CheckSelection( maSelection, pForwarder );
395 OUString aConverted(convertLineEnd(aString, LINEEND_LF)); // Simply count the number of line endings
397 pForwarder->QuickInsertText( aConverted, maSelection );
398 mpEditSource->UpdateData();
400 // Adapt selection
401 //! It would be easier if the EditEngine would return the selection
402 //! on QuickInsertText...
403 CollapseToStart();
405 sal_Int32 nLen = aConverted.getLength();
406 if (nLen)
407 GoRight( nLen, true );
411 // Interface beans::XPropertySet
412 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextRangeBase::getPropertySetInfo()
413 throw( uno::RuntimeException, std::exception )
415 return mpPropSet->getPropertySetInfo();
418 void SAL_CALL SvxUnoTextRangeBase::setPropertyValue(const OUString& PropertyName, const uno::Any& aValue)
419 throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
421 if (PropertyName == UNO_TR_PROP_SELECTION)
423 text::TextRangeSelection aSel = aValue.get<text::TextRangeSelection>();
424 SetSelection(toESelection(aSel));
426 return;
429 _setPropertyValue( PropertyName, aValue, -1 );
432 void SAL_CALL SvxUnoTextRangeBase::_setPropertyValue( const OUString& PropertyName, const uno::Any& aValue, sal_Int32 nPara )
433 throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
435 SolarMutexGuard aGuard;
437 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
438 if( pForwarder )
440 CheckSelection( maSelection, pForwarder );
442 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName );
443 if ( pMap )
445 ESelection aSel( GetSelection() );
446 bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END );
448 if( nPara == -1 && !bParaAttrib )
450 SfxItemSet aOldSet( pForwarder->GetAttribs( aSel ) );
451 // we have a selection and no para attribute
452 SfxItemSet aNewSet( *aOldSet.GetPool(), aOldSet.GetRanges() );
454 setPropertyValue( pMap, aValue, maSelection, aOldSet, aNewSet );
457 pForwarder->QuickSetAttribs( aNewSet, GetSelection() );
459 else
461 sal_Int32 nEndPara;
463 if( nPara == -1 )
465 nPara = aSel.nStartPara;
466 nEndPara = aSel.nEndPara;
468 else
470 // only one paragraph
471 nEndPara = nPara;
474 while( nPara <= nEndPara )
476 // we have a paragraph
477 SfxItemSet aSet( pForwarder->GetParaAttribs( nPara ) );
478 setPropertyValue( pMap, aValue, maSelection, aSet, aSet );
479 pForwarder->SetParaAttribs( nPara, aSet );
480 nPara++;
484 GetEditSource()->UpdateData();
485 return;
489 throw beans::UnknownPropertyException();
492 void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rValue, const ESelection& rSelection, const SfxItemSet& rOldSet, SfxItemSet& rNewSet ) throw( beans::UnknownPropertyException, lang::IllegalArgumentException )
494 if(!SetPropertyValueHelper( rOldSet, pMap, rValue, rNewSet, &rSelection, GetEditSource() ))
496 // For parts of composite items with multiple properties (eg background)
497 // must be taken from the document before the old item.
498 rNewSet.Put(rOldSet.Get(pMap->nWID)); // Old Item in new Set
499 SvxItemPropertySet::setPropertyValue(pMap, rValue, rNewSet, false );
503 bool SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemSet&, const SfxItemPropertySimpleEntry* pMap, const uno::Any& aValue, SfxItemSet& rNewSet, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL*/ )
505 switch( pMap->nWID )
507 case WID_FONTDESC:
509 awt::FontDescriptor aDesc;
510 if(aValue >>= aDesc)
512 SvxUnoFontDescriptor::FillItemSet( aDesc, rNewSet );
513 return true;
516 break;
518 case EE_PARA_NUMBULLET:
520 uno::Reference< container::XIndexReplace > xRule;
521 if( !aValue.hasValue() || ((aValue >>= xRule) && !xRule.is()) )
522 return true;
524 return false;
527 case WID_NUMLEVEL:
529 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
530 if(pForwarder && pSelection)
532 sal_Int16 nLevel = sal_Int16();
533 if( aValue >>= nLevel )
535 // #101004# Call interface method instead of unsafe cast
536 if(! pForwarder->SetDepth( pSelection->nStartPara, nLevel ) )
537 throw lang::IllegalArgumentException();
539 return true;
543 break;
544 case WID_NUMBERINGSTARTVALUE:
546 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
547 if(pForwarder && pSelection)
549 sal_Int16 nStartValue = -1;
550 if( aValue >>= nStartValue )
552 pForwarder->SetNumberingStartValue( pSelection->nStartPara, nStartValue );
553 return true;
557 break;
558 case WID_PARAISNUMBERINGRESTART:
560 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
561 if(pForwarder && pSelection)
563 bool bParaIsNumberingRestart = false;
564 if( aValue >>= bParaIsNumberingRestart )
566 pForwarder->SetParaIsNumberingRestart( pSelection->nStartPara, bParaIsNumberingRestart );
567 return true;
571 break;
572 case EE_PARA_BULLETSTATE:
574 bool bBullet = true;
575 if( aValue >>= bBullet )
577 SfxBoolItem aItem( EE_PARA_BULLETSTATE, bBullet );
578 rNewSet.Put(aItem);
579 return true;
582 break;
584 default:
585 return false;
588 throw lang::IllegalArgumentException();
591 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyValue(const OUString& PropertyName)
592 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
594 if (PropertyName == UNO_TR_PROP_SELECTION)
596 const ESelection& rSel = GetSelection();
597 text::TextRangeSelection aSel;
598 aSel.Start.Paragraph = rSel.nStartPara;
599 aSel.Start.PositionInParagraph = static_cast<sal_Int32>(rSel.nStartPos);
600 aSel.End.Paragraph = rSel.nEndPara;
601 aSel.End.PositionInParagraph = static_cast<sal_Int32>(rSel.nEndPos);
602 return uno::makeAny(aSel);
605 return _getPropertyValue( PropertyName, -1 );
608 uno::Any SAL_CALL SvxUnoTextRangeBase::_getPropertyValue(const OUString& PropertyName, sal_Int32 nPara )
609 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
611 SolarMutexGuard aGuard;
613 uno::Any aAny;
615 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
616 if( pForwarder )
618 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName );
619 if( pMap )
621 SfxItemSet* pAttribs = NULL;
622 if( nPara != -1 )
623 pAttribs = pForwarder->GetParaAttribs( nPara ).Clone();
624 else
625 pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone();
627 // Replace Dontcare with Default, so that one always has a mirror
628 pAttribs->ClearInvalidItems();
630 getPropertyValue( pMap, aAny, *pAttribs );
632 delete pAttribs;
633 return aAny;
637 throw beans::UnknownPropertyException();
640 void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry* pMap, uno::Any& rAny, const SfxItemSet& rSet )
641 throw (beans::UnknownPropertyException, uno::RuntimeException)
643 switch( pMap->nWID )
645 case EE_FEATURE_FIELD:
646 if ( rSet.GetItemState( EE_FEATURE_FIELD, false ) == SfxItemState::SET )
648 const SvxFieldItem* pItem = static_cast<const SvxFieldItem*>(rSet.GetItem( EE_FEATURE_FIELD ));
649 const SvxFieldData* pData = pItem->GetField();
650 uno::Reference< text::XTextRange > xAnchor( this );
652 // get presentation string for field
653 Color* pTColor = NULL;
654 Color* pFColor = NULL;
656 SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder();
657 OUString aPresentation( pForwarder->CalcFieldValue( SvxFieldItem(*pData, EE_FEATURE_FIELD), maSelection.nStartPara, maSelection.nStartPos, pTColor, pFColor ) );
659 delete pTColor;
660 delete pFColor;
662 uno::Reference< text::XTextField > xField( new SvxUnoTextField( xAnchor, aPresentation, pData ) );
663 rAny <<= xField;
665 break;
667 case WID_PORTIONTYPE:
668 if ( rSet.GetItemState( EE_FEATURE_FIELD, false ) == SfxItemState::SET )
670 OUString aType("TextField");
671 rAny <<= aType;
673 else
675 OUString aType("Text");
676 rAny <<= aType;
678 break;
680 default:
681 if(!GetPropertyValueHelper( *const_cast<SfxItemSet*>(&rSet), pMap, rAny, &maSelection, GetEditSource() ))
682 rAny = SvxItemPropertySet::getPropertyValue(pMap, rSet, true, false );
686 bool SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet& rSet, const SfxItemPropertySimpleEntry* pMap, uno::Any& aAny, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL */ )
687 throw( uno::RuntimeException )
689 switch( pMap->nWID )
691 case WID_FONTDESC:
693 awt::FontDescriptor aDesc;
694 SvxUnoFontDescriptor::FillFromItemSet( rSet, aDesc );
695 aAny <<= aDesc;
697 break;
699 case EE_PARA_NUMBULLET:
701 SfxItemState eState = rSet.GetItemState( EE_PARA_NUMBULLET, true );
702 if( eState != SfxItemState::SET && eState != SfxItemState::DEFAULT)
703 throw uno::RuntimeException();
705 const SvxNumBulletItem* pBulletItem = static_cast<const SvxNumBulletItem*>(rSet.GetItem( EE_PARA_NUMBULLET, true ));
707 if( pBulletItem == NULL )
708 throw uno::RuntimeException();
710 aAny <<= SvxCreateNumRule( pBulletItem->GetNumRule() );
712 break;
714 case WID_NUMLEVEL:
716 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
717 if(pForwarder && pSelection)
719 sal_Int16 nLevel = pForwarder->GetDepth( pSelection->nStartPara );
720 if( nLevel >= 0 )
721 aAny <<= nLevel;
724 break;
725 case WID_NUMBERINGSTARTVALUE:
727 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
728 if(pForwarder && pSelection)
729 aAny <<= pForwarder->GetNumberingStartValue( pSelection->nStartPara );
731 break;
732 case WID_PARAISNUMBERINGRESTART:
734 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
735 if(pForwarder && pSelection)
736 aAny <<= pForwarder->IsParaIsNumberingRestart( pSelection->nStartPara );
738 break;
740 case EE_PARA_BULLETSTATE:
742 bool bState = false;
743 SfxItemState eState = rSet.GetItemState( EE_PARA_BULLETSTATE, true );
744 if( eState == SfxItemState::SET || eState == SfxItemState::DEFAULT )
746 const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(rSet.GetItem( EE_PARA_BULLETSTATE, true ));
747 bState = pItem->GetValue();
750 aAny <<= bState;
752 break;
753 default:
755 return false;
758 return true;
761 // is not (yet) supported
762 void SAL_CALL SvxUnoTextRangeBase::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
763 void SAL_CALL SvxUnoTextRangeBase::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
764 void SAL_CALL SvxUnoTextRangeBase::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
765 void SAL_CALL SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
767 // XMultiPropertySet
768 void SAL_CALL SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence< OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
770 _setPropertyValues( aPropertyNames, aValues, -1 );
773 void SAL_CALL SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence< OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues, sal_Int32 nPara ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
775 SolarMutexGuard aGuard;
777 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
778 if( pForwarder )
780 CheckSelection( maSelection, pForwarder );
782 ESelection aSel( GetSelection() );
784 const OUString* pPropertyNames = aPropertyNames.getConstArray();
785 const uno::Any* pValues = aValues.getConstArray();
786 sal_Int32 nCount = aPropertyNames.getLength();
788 sal_Int32 nEndPara = nPara;
789 sal_Int32 nTempPara = nPara;
791 if( nTempPara == -1 )
793 nTempPara = aSel.nStartPara;
794 nEndPara = aSel.nEndPara;
797 SfxItemSet* pOldAttrSet = NULL;
798 SfxItemSet* pNewAttrSet = NULL;
800 SfxItemSet* pOldParaSet = NULL;
801 SfxItemSet* pNewParaSet = NULL;
803 for( ; nCount; nCount--, pPropertyNames++, pValues++ )
805 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
807 if( pMap )
809 bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END );
811 if( (nPara == -1) && !bParaAttrib )
813 if( NULL == pNewAttrSet )
815 const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) );
816 pOldAttrSet = new SfxItemSet( aSet );
817 pNewAttrSet = new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() );
820 setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet );
822 if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
824 const SfxPoolItem* pItem;
825 if( pNewAttrSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET )
827 pOldAttrSet->Put( *pItem );
831 else
833 if( NULL == pNewParaSet )
835 const SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) );
836 pOldParaSet = new SfxItemSet( aSet );
837 pNewParaSet = new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() );
840 setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet );
842 if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
844 const SfxPoolItem* pItem;
845 if( pNewParaSet->GetItemState( pMap->nWID, true, &pItem ) == SfxItemState::SET )
847 pOldParaSet->Put( *pItem );
855 bool bNeedsUpdate = false;
857 if( pNewParaSet )
859 if( pNewParaSet->Count() )
861 while( nTempPara <= nEndPara )
863 SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) );
864 aSet.Put( *pNewParaSet );
865 pForwarder->SetParaAttribs( nTempPara, aSet );
866 nTempPara++;
868 bNeedsUpdate = true;
871 delete pNewParaSet;
872 delete pOldParaSet;
875 if( pNewAttrSet )
877 if( pNewAttrSet->Count() )
879 pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() );
880 bNeedsUpdate = true;
882 delete pNewAttrSet;
883 delete pOldAttrSet;
887 if( bNeedsUpdate )
888 GetEditSource()->UpdateData();
892 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence< OUString >& aPropertyNames ) throw (uno::RuntimeException, std::exception)
894 return _getPropertyValues( aPropertyNames, -1 );
897 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence< OUString >& aPropertyNames, sal_Int32 nPara ) throw (uno::RuntimeException)
899 SolarMutexGuard aGuard;
901 sal_Int32 nCount = aPropertyNames.getLength();
904 uno::Sequence< uno::Any > aValues( nCount );
906 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
907 if( pForwarder )
909 SfxItemSet* pAttribs = NULL;
910 if( nPara != -1 )
911 pAttribs = pForwarder->GetParaAttribs( nPara ).Clone();
912 else
913 pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone();
915 pAttribs->ClearInvalidItems();
917 const OUString* pPropertyNames = aPropertyNames.getConstArray();
918 uno::Any* pValues = aValues.getArray();
920 for( ; nCount; nCount--, pPropertyNames++, pValues++ )
922 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
923 if( pMap )
925 getPropertyValue( pMap, *pValues, *pAttribs );
929 delete pAttribs;
933 return aValues;
936 void SAL_CALL SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException, std::exception)
940 void SAL_CALL SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException, std::exception)
944 void SAL_CALL SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException, std::exception)
948 // beans::XPropertyState
949 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::getPropertyState( const OUString& PropertyName )
950 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
952 return _getPropertyState( PropertyName, -1 );
955 static const sal_uInt16 aSvxUnoFontDescriptorWhichMap[] = { EE_CHAR_FONTINFO, EE_CHAR_FONTHEIGHT, EE_CHAR_ITALIC,
956 EE_CHAR_UNDERLINE, EE_CHAR_WEIGHT, EE_CHAR_STRIKEOUT, EE_CHAR_CASEMAP,
957 EE_CHAR_WLM, 0 };
959 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara)
960 throw( beans::UnknownPropertyException, uno::RuntimeException )
962 if ( pMap )
964 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
965 if( pForwarder )
967 SfxItemState eItemState = SfxItemState::UNKNOWN;
968 sal_uInt16 nWID = 0;
970 switch( pMap->nWID )
972 case WID_FONTDESC:
974 const sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
975 SfxItemState eTempItemState = SfxItemState::UNKNOWN;
976 while( *pWhichId )
978 if(nPara != -1)
979 eTempItemState = pForwarder->GetItemState( nPara, *pWhichId );
980 else
981 eTempItemState = pForwarder->GetItemState( GetSelection(), *pWhichId );
983 switch( eTempItemState )
985 case SfxItemState::DISABLED:
986 case SfxItemState::DONTCARE:
987 eItemState = SfxItemState::DONTCARE;
988 break;
990 case SfxItemState::DEFAULT:
991 if( eItemState != SfxItemState::DEFAULT )
993 if( eItemState == SfxItemState::UNKNOWN )
994 eItemState = SfxItemState::DEFAULT;
996 break;
998 case SfxItemState::READONLY:
999 case SfxItemState::SET:
1000 if( eItemState != SfxItemState::SET )
1002 if( eItemState == SfxItemState::UNKNOWN )
1003 eItemState = SfxItemState::SET;
1005 break;
1006 default:
1007 throw beans::UnknownPropertyException();
1010 pWhichId++;
1013 break;
1015 case WID_NUMLEVEL:
1016 case WID_NUMBERINGSTARTVALUE:
1017 case WID_PARAISNUMBERINGRESTART:
1018 eItemState = SfxItemState::SET;
1019 break;
1021 default:
1022 nWID = pMap->nWID;
1025 if( nWID != 0 )
1027 if( nPara != -1 )
1028 eItemState = pForwarder->GetItemState( nPara, nWID );
1029 else
1030 eItemState = pForwarder->GetItemState( GetSelection(), nWID );
1033 switch( eItemState )
1035 case SfxItemState::DONTCARE:
1036 case SfxItemState::DISABLED:
1037 return beans::PropertyState_AMBIGUOUS_VALUE;
1038 case SfxItemState::READONLY:
1039 case SfxItemState::SET:
1040 return beans::PropertyState_DIRECT_VALUE;
1041 case SfxItemState::DEFAULT:
1042 return beans::PropertyState_DEFAULT_VALUE;
1043 default: break;
1044 // case SfxItemState::UNKNOWN:
1048 throw beans::UnknownPropertyException();
1051 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1052 throw( beans::UnknownPropertyException, uno::RuntimeException )
1054 SolarMutexGuard aGuard;
1056 return _getPropertyState( mpPropSet->getPropertyMapEntry( PropertyName ), nPara);
1059 uno::Sequence< beans::PropertyState > SAL_CALL SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
1060 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1062 return _getPropertyStates( aPropertyName, -1 );
1065 uno::Sequence< beans::PropertyState > SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence< OUString >& PropertyName, sal_Int32 nPara /* = -1 */)
1066 throw( beans::UnknownPropertyException, uno::RuntimeException )
1068 const sal_Int32 nCount = PropertyName.getLength();
1069 const OUString* pNames = PropertyName.getConstArray();
1071 uno::Sequence< beans::PropertyState > aRet( nCount );
1072 beans::PropertyState* pState = aRet.getArray();
1074 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1075 if( pForwarder )
1077 SfxItemSet* pSet = NULL;
1078 if( nPara != -1 )
1080 pSet = new SfxItemSet( pForwarder->GetParaAttribs( nPara ) );
1082 else
1084 ESelection aSel( GetSelection() );
1085 CheckSelection( aSel, pForwarder );
1086 pSet = new SfxItemSet( pForwarder->GetAttribs( aSel, EditEngineAttribs_OnlyHard ) );
1089 bool bUnknownPropertyFound = false;
1090 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++ )
1092 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pNames++ );
1093 if( NULL == pMap )
1095 bUnknownPropertyFound = true;
1096 break;
1098 bUnknownPropertyFound = !_getOnePropertyStates(pSet, pMap, *pState++);
1101 delete pSet;
1103 if( bUnknownPropertyFound )
1104 throw beans::UnknownPropertyException();
1107 return aRet;
1110 bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const SfxItemPropertySimpleEntry* pMap, beans::PropertyState& rState)
1112 bool bUnknownPropertyFound = false;
1113 if(pSet && pMap)
1115 SfxItemState eItemState = SfxItemState::UNKNOWN;
1116 sal_uInt16 nWID = 0;
1118 switch( pMap->nWID )
1120 case WID_FONTDESC:
1122 const sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
1123 SfxItemState eTempItemState = SfxItemState::UNKNOWN;
1124 while( *pWhichId )
1126 eTempItemState = pSet->GetItemState( *pWhichId );
1128 switch( eTempItemState )
1130 case SfxItemState::DISABLED:
1131 case SfxItemState::DONTCARE:
1132 eItemState = SfxItemState::DONTCARE;
1133 break;
1135 case SfxItemState::DEFAULT:
1136 if( eItemState != SfxItemState::DEFAULT )
1138 if( eItemState == SfxItemState::UNKNOWN )
1139 eItemState = SfxItemState::DEFAULT;
1141 break;
1143 case SfxItemState::READONLY:
1144 case SfxItemState::SET:
1145 if( eItemState != SfxItemState::SET )
1147 if( eItemState == SfxItemState::UNKNOWN )
1148 eItemState = SfxItemState::SET;
1150 break;
1151 default:
1152 bUnknownPropertyFound = true;
1153 break;
1156 pWhichId++;
1159 break;
1161 case WID_NUMLEVEL:
1162 case WID_NUMBERINGSTARTVALUE:
1163 case WID_PARAISNUMBERINGRESTART:
1164 eItemState = SfxItemState::SET;
1165 break;
1167 default:
1168 nWID = pMap->nWID;
1171 if( bUnknownPropertyFound )
1172 return !bUnknownPropertyFound;
1174 if( nWID != 0 )
1175 eItemState = pSet->GetItemState( nWID, false );
1177 switch( eItemState )
1179 case SfxItemState::READONLY:
1180 case SfxItemState::SET:
1181 rState = beans::PropertyState_DIRECT_VALUE;
1182 break;
1183 case SfxItemState::DEFAULT:
1184 rState = beans::PropertyState_DEFAULT_VALUE;
1185 break;
1186 // case SfxItemState::UNKNOWN:
1187 // case SfxItemState::DONTCARE:
1188 // case SfxItemState::DISABLED:
1189 default:
1190 rState = beans::PropertyState_AMBIGUOUS_VALUE;
1193 return !bUnknownPropertyFound;
1196 void SAL_CALL SvxUnoTextRangeBase::setPropertyToDefault( const OUString& PropertyName )
1197 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1199 _setPropertyToDefault( PropertyName, -1 );
1202 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1203 throw( beans::UnknownPropertyException, uno::RuntimeException )
1205 SolarMutexGuard aGuard;
1207 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1209 if( pForwarder )
1211 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( PropertyName );
1212 if ( pMap )
1214 CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1215 _setPropertyToDefault( pForwarder, pMap, nPara );
1216 return;
1220 throw beans::UnknownPropertyException();
1223 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder* pForwarder, const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara )
1224 throw( beans::UnknownPropertyException, uno::RuntimeException )
1228 SfxItemSet aSet( *pForwarder->GetPool(), true );
1230 if( pMap->nWID == WID_FONTDESC )
1232 SvxUnoFontDescriptor::setPropertyToDefault( aSet );
1234 else if( pMap->nWID == WID_NUMLEVEL )
1236 // #101004# Call interface method instead of unsafe cast
1237 pForwarder->SetDepth( maSelection.nStartPara, -1 );
1238 return;
1240 else if( pMap->nWID == WID_NUMBERINGSTARTVALUE )
1242 pForwarder->SetNumberingStartValue( maSelection.nStartPara, -1 );
1244 else if( pMap->nWID == WID_PARAISNUMBERINGRESTART )
1246 pForwarder->SetParaIsNumberingRestart( maSelection.nStartPara, false );
1248 else
1250 aSet.InvalidateItem( pMap->nWID );
1253 if(nPara != -1)
1254 pForwarder->SetParaAttribs( nPara, aSet );
1255 else
1256 pForwarder->QuickSetAttribs( aSet, GetSelection() );
1258 GetEditSource()->UpdateData();
1260 return;
1262 while(false);
1265 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyDefault( const OUString& aPropertyName )
1266 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
1268 SolarMutexGuard aGuard;
1270 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1271 if( pForwarder )
1273 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( aPropertyName );
1274 if( pMap )
1276 SfxItemPool* pPool = pForwarder->GetPool();
1278 switch( pMap->nWID )
1280 case WID_FONTDESC:
1281 return SvxUnoFontDescriptor::getPropertyDefault( pPool );
1283 case WID_NUMLEVEL:
1285 uno::Any aAny;
1286 return aAny;
1289 case WID_NUMBERINGSTARTVALUE:
1290 return uno::Any( (sal_Int16)-1 );
1292 case WID_PARAISNUMBERINGRESTART:
1293 return uno::Any( false );
1295 default:
1297 // Get Default from ItemPool
1298 if(SfxItemPool::IsWhich(pMap->nWID))
1300 SfxItemSet aSet( *pPool, pMap->nWID, pMap->nWID);
1301 aSet.Put(pPool->GetDefaultItem(pMap->nWID));
1302 return SvxItemPropertySet::getPropertyValue(pMap, aSet, true, false );
1308 throw beans::UnknownPropertyException();
1311 // beans::XMultiPropertyStates
1312 void SAL_CALL SvxUnoTextRangeBase::setAllPropertiesToDefault()
1313 throw (uno::RuntimeException, std::exception)
1315 SolarMutexGuard aGuard;
1317 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1319 if( pForwarder )
1321 PropertyEntryVector_t aEntries = mpPropSet->getPropertyMap().getPropertyEntries();
1322 PropertyEntryVector_t::const_iterator aIt = aEntries.begin();
1323 while( aIt != aEntries.end() )
1325 _setPropertyToDefault( pForwarder, &(*aIt), -1 );
1326 ++aIt;
1331 void SAL_CALL SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1333 sal_Int32 nCount = aPropertyNames.getLength();
1334 for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount-- )
1336 setPropertyToDefault( *pName );
1340 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
1342 sal_Int32 nCount = aPropertyNames.getLength();
1343 uno::Sequence< uno::Any > ret( nCount );
1344 uno::Any* pDefaults = ret.getArray();
1346 for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount--, pDefaults++ )
1348 *pDefaults = getPropertyDefault( *pName );
1351 return ret;
1354 // internal
1355 void SvxUnoTextRangeBase::CollapseToStart() throw()
1357 CheckSelection( maSelection, mpEditSource );
1359 maSelection.nEndPara = maSelection.nStartPara;
1360 maSelection.nEndPos = maSelection.nStartPos;
1363 void SvxUnoTextRangeBase::CollapseToEnd() throw()
1365 CheckSelection( maSelection, mpEditSource );
1367 maSelection.nStartPara = maSelection.nEndPara;
1368 maSelection.nStartPos = maSelection.nEndPos;
1371 bool SvxUnoTextRangeBase::IsCollapsed() throw()
1373 CheckSelection( maSelection, mpEditSource );
1375 return ( maSelection.nStartPara == maSelection.nEndPara &&
1376 maSelection.nStartPos == maSelection.nEndPos );
1379 bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount, bool Expand) throw()
1381 CheckSelection( maSelection, mpEditSource );
1383 // #75098# use end position, as in Writer (start is anchor, end is cursor)
1384 sal_uInt16 nNewPos = maSelection.nEndPos;
1385 sal_Int32 nNewPar = maSelection.nEndPara;
1387 bool bOk = true;
1388 SvxTextForwarder* pForwarder = NULL;
1389 while ( nCount > nNewPos && bOk )
1391 if ( nNewPar == 0 )
1392 bOk = false;
1393 else
1395 if ( !pForwarder )
1396 pForwarder = mpEditSource->GetTextForwarder(); // first here, it is necessary...
1398 --nNewPar;
1399 nCount -= nNewPos + 1;
1400 nNewPos = pForwarder->GetTextLen( nNewPar );
1404 if ( bOk )
1406 nNewPos = nNewPos - nCount;
1407 maSelection.nStartPara = nNewPar;
1408 maSelection.nStartPos = nNewPos;
1411 if (!Expand)
1412 CollapseToStart();
1414 return bOk;
1417 bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount, bool Expand) throw()
1419 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1420 if( pForwarder )
1422 CheckSelection( maSelection, pForwarder );
1424 sal_Int32 nNewPos = maSelection.nEndPos + nCount; //! Overflow???
1425 sal_Int32 nNewPar = maSelection.nEndPara;
1427 bool bOk = true;
1428 sal_Int32 nParCount = pForwarder->GetParagraphCount();
1429 sal_Int32 nThisLen = pForwarder->GetTextLen( nNewPar );
1430 while ( nNewPos > nThisLen && bOk )
1432 if ( nNewPar + 1 >= nParCount )
1433 bOk = false;
1434 else
1436 nNewPos -= nThisLen+1;
1437 ++nNewPar;
1438 nThisLen = pForwarder->GetTextLen( nNewPar );
1442 if (bOk)
1444 maSelection.nEndPara = nNewPar;
1445 maSelection.nEndPos = nNewPos;
1448 if (!Expand)
1449 CollapseToEnd();
1451 return bOk;
1453 return false;
1456 void SvxUnoTextRangeBase::GotoStart(bool Expand) throw()
1458 maSelection.nStartPara = 0;
1459 maSelection.nStartPos = 0;
1461 if (!Expand)
1462 CollapseToStart();
1465 void SvxUnoTextRangeBase::GotoEnd(bool Expand) throw()
1467 CheckSelection( maSelection, mpEditSource );
1469 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1470 if( pForwarder )
1473 sal_Int32 nPar = pForwarder->GetParagraphCount();
1474 if (nPar)
1475 --nPar;
1477 maSelection.nEndPara = nPar;
1478 maSelection.nEndPos = pForwarder->GetTextLen( nPar );
1480 if (!Expand)
1481 CollapseToEnd();
1485 // lang::XServiceInfo
1486 sal_Bool SAL_CALL SvxUnoTextRangeBase::supportsService( const OUString& ServiceName )
1487 throw(uno::RuntimeException, std::exception)
1489 return cppu::supportsService( this, ServiceName );
1492 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames()
1493 throw(uno::RuntimeException, std::exception)
1495 return getSupportedServiceNames_Static();
1498 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1500 uno::Sequence< OUString > aSeq(3);
1501 aSeq[0] = "com.sun.star.style.CharacterProperties";
1502 aSeq[1] = "com.sun.star.style.CharacterPropertiesComplex";
1503 aSeq[2] = "com.sun.star.style.CharacterPropertiesAsian";
1504 return aSeq;
1507 // XTextRangeCompare
1508 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1510 SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1511 SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1513 if( (pR1 == 0) || (pR2 == 0) )
1514 throw lang::IllegalArgumentException();
1516 const ESelection& r1 = pR1->maSelection;
1517 const ESelection& r2 = pR2->maSelection;
1519 if( r1.nStartPara == r2.nStartPara )
1521 if( r1.nStartPos == r2.nStartPos )
1522 return 0;
1523 else
1524 return r1.nStartPos < r2.nStartPos ? 1 : -1;
1526 else
1528 return r1.nStartPara < r2.nStartPara ? 1 : -1;
1532 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1534 SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1535 SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1537 if( (pR1 == 0) || (pR2 == 0) )
1538 throw lang::IllegalArgumentException();
1540 const ESelection& r1 = pR1->maSelection;
1541 const ESelection& r2 = pR2->maSelection;
1543 if( r1.nEndPara == r2.nEndPara )
1545 if( r1.nEndPos == r2.nEndPos )
1546 return 0;
1547 else
1548 return r1.nEndPos < r2.nEndPos ? 1 : -1;
1550 else
1552 return r1.nEndPara < r2.nEndPara ? 1 : -1;
1556 SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase& rParent, bool bPortion /* = false */ ) throw()
1557 :SvxUnoTextRangeBase( rParent.GetEditSource(), bPortion ? ImplGetSvxTextPortionSvxPropertySet() : rParent.getPropertySet() ),
1558 mbPortion( bPortion )
1560 xParentText = (text::XText*)&rParent;
1563 SvxUnoTextRange::~SvxUnoTextRange() throw()
1567 uno::Any SAL_CALL SvxUnoTextRange::queryAggregation( const uno::Type & rType )
1568 throw(uno::RuntimeException, std::exception)
1570 QUERYINT( text::XTextRange );
1571 else if( rType == cppu::UnoType<beans::XMultiPropertyStates>::get())
1572 return uno::makeAny(uno::Reference< beans::XMultiPropertyStates >(this));
1573 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
1574 return uno::makeAny(uno::Reference< beans::XPropertySet >(this));
1575 else QUERYINT( beans::XPropertyState );
1576 else QUERYINT( text::XTextRangeCompare );
1577 else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
1578 return uno::makeAny(uno::Reference< beans::XMultiPropertySet >(this));
1579 else QUERYINT( lang::XServiceInfo );
1580 else QUERYINT( lang::XTypeProvider );
1581 else QUERYINT( lang::XUnoTunnel );
1582 else
1583 return OWeakAggObject::queryAggregation( rType );
1586 uno::Any SAL_CALL SvxUnoTextRange::queryInterface( const uno::Type & rType )
1587 throw(uno::RuntimeException, std::exception)
1589 return OWeakAggObject::queryInterface(rType);
1592 void SAL_CALL SvxUnoTextRange::acquire()
1593 throw( )
1595 OWeakAggObject::acquire();
1598 void SAL_CALL SvxUnoTextRange::release()
1599 throw( )
1601 OWeakAggObject::release();
1604 // XTypeProvider
1606 namespace
1608 struct theSvxUnoTextRangeTypes :
1609 public rtl::StaticWithInit<uno::Sequence<uno::Type>, theSvxUnoTextRangeTypes>
1611 uno::Sequence<uno::Type> operator () ()
1613 uno::Sequence< uno::Type > aTypeSequence;
1615 aTypeSequence.realloc( 9 ); // !DANGER! keep this updated
1616 uno::Type* pTypes = aTypeSequence.getArray();
1618 *pTypes++ = cppu::UnoType<text::XTextRange>::get();
1619 *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
1620 *pTypes++ = cppu::UnoType<beans::XMultiPropertySet>::get();
1621 *pTypes++ = cppu::UnoType<beans::XMultiPropertyStates>::get();
1622 *pTypes++ = cppu::UnoType<beans::XPropertyState>::get();
1623 *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
1624 *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
1625 *pTypes++ = cppu::UnoType<lang::XUnoTunnel>::get();
1626 *pTypes++ = cppu::UnoType<text::XTextRangeCompare>::get();
1628 return aTypeSequence;
1633 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextRange::getTypes()
1634 throw (uno::RuntimeException, std::exception)
1636 return theSvxUnoTextRangeTypes::get();
1639 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextRange::getImplementationId()
1640 throw (uno::RuntimeException, std::exception)
1642 return css::uno::Sequence<sal_Int8>();
1645 // XTextRange
1646 uno::Reference< text::XText > SAL_CALL SvxUnoTextRange::getText()
1647 throw(uno::RuntimeException, std::exception)
1649 return xParentText;
1652 // lang::XServiceInfo
1653 OUString SAL_CALL SvxUnoTextRange::getImplementationName()
1654 throw(uno::RuntimeException, std::exception)
1656 return OUString("SvxUnoTextRange");
1660 // class SvxUnoText
1663 SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet* _pSet ) throw()
1664 : SvxUnoTextRangeBase( _pSet )
1668 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
1669 : SvxUnoTextRangeBase( pSource, _pSet )
1671 xParentText = xParent;
1672 ESelection aSelection;
1673 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1674 SetSelection( aSelection );
1677 SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase& rText ) throw()
1678 : SvxUnoTextRangeBase( rText )
1679 , text::XTextAppend()
1680 , text::XTextCopy()
1681 , container::XEnumerationAccess()
1682 , text::XTextRangeMover()
1683 , lang::XTypeProvider()
1685 xParentText = rText.xParentText;
1688 SvxUnoTextBase::~SvxUnoTextBase() throw()
1692 // XInterface
1693 uno::Any SAL_CALL SvxUnoTextBase::queryAggregation( const uno::Type & rType )
1694 throw(uno::RuntimeException, std::exception)
1696 QUERYINT( text::XText );
1697 QUERYINT( text::XSimpleText );
1698 if( rType == cppu::UnoType<text::XTextRange>::get())
1699 return uno::makeAny(uno::Reference< text::XTextRange >((text::XText*)(this)));
1700 QUERYINT(container::XEnumerationAccess );
1701 QUERYINT( container::XElementAccess );
1702 QUERYINT( beans::XMultiPropertyStates );
1703 QUERYINT( beans::XPropertySet );
1704 QUERYINT( beans::XMultiPropertySet );
1705 QUERYINT( beans::XPropertyState );
1706 QUERYINT( text::XTextRangeCompare );
1707 QUERYINT( lang::XServiceInfo );
1708 QUERYINT( text::XTextRangeMover );
1709 QUERYINT( text::XTextCopy );
1710 QUERYINT( text::XTextAppend );
1711 QUERYINT( text::XParagraphAppend );
1712 QUERYINT( text::XTextPortionAppend );
1713 QUERYINT( lang::XTypeProvider );
1714 QUERYINT( lang::XUnoTunnel );
1716 return uno::Any();
1719 // XTypeProvider
1721 namespace
1723 struct theSvxUnoTextBaseTypes :
1724 public rtl::StaticWithInit<uno::Sequence<uno::Type>, theSvxUnoTextBaseTypes>
1726 uno::Sequence<uno::Type> operator () ()
1728 uno::Sequence< uno::Type > aTypeSequence;
1730 aTypeSequence.realloc( 15 ); // !DANGER! keep this updated
1731 uno::Type* pTypes = aTypeSequence.getArray();
1733 *pTypes++ = cppu::UnoType<text::XText>::get();
1734 *pTypes++ = cppu::UnoType<container::XEnumerationAccess>::get();
1735 *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
1736 *pTypes++ = cppu::UnoType<beans::XMultiPropertySet>::get();
1737 *pTypes++ = cppu::UnoType<beans::XMultiPropertyStates>::get();
1738 *pTypes++ = cppu::UnoType<beans::XPropertyState>::get();
1739 *pTypes++ = cppu::UnoType<text::XTextRangeMover>::get();
1740 *pTypes++ = cppu::UnoType<text::XTextAppend>::get();
1741 *pTypes++ = cppu::UnoType<text::XTextCopy>::get();
1742 *pTypes++ = cppu::UnoType<text::XParagraphAppend>::get();
1743 *pTypes++ = cppu::UnoType<text::XTextPortionAppend>::get();
1744 *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
1745 *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
1746 *pTypes++ = cppu::UnoType<lang::XUnoTunnel>::get();
1747 *pTypes++ = cppu::UnoType<text::XTextRangeCompare>::get();
1749 return aTypeSequence;
1753 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getStaticTypes() throw()
1755 return theSvxUnoTextBaseTypes::get();
1758 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getTypes()
1759 throw (uno::RuntimeException, std::exception)
1761 return getStaticTypes();
1764 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextBase::getImplementationId()
1765 throw (uno::RuntimeException, std::exception)
1767 return css::uno::Sequence<sal_Int8>();
1770 uno::Reference< text::XTextCursor > SvxUnoTextBase::createTextCursorBySelection( const ESelection& rSel )
1772 SvxUnoTextCursor* pCursor = new SvxUnoTextCursor( *this );
1773 uno::Reference< text::XTextCursor > xCursor( pCursor );
1774 pCursor->SetSelection( rSel );
1775 return xCursor;
1778 // XSimpleText
1780 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursor()
1781 throw(uno::RuntimeException, std::exception)
1783 SolarMutexGuard aGuard;
1784 return new SvxUnoTextCursor( *this );
1787 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursorByRange( const uno::Reference< text::XTextRange >& aTextPosition )
1788 throw(uno::RuntimeException, std::exception)
1790 SolarMutexGuard aGuard;
1792 uno::Reference< text::XTextCursor > xCursor;
1794 if( aTextPosition.is() )
1796 SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
1797 if(pRange)
1798 xCursor = createTextCursorBySelection( pRange->GetSelection() );
1801 return xCursor;
1804 void SAL_CALL SvxUnoTextBase::insertString( const uno::Reference< text::XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb )
1805 throw(uno::RuntimeException, std::exception)
1807 SolarMutexGuard aGuard;
1809 if( !xRange.is() )
1810 return;
1812 ESelection aSelection;
1813 if (GetEditSource())
1815 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1816 SetSelection( aSelection );
1819 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1820 if(pRange)
1822 // setString on SvxUnoTextRangeBase instead of itself QuickInsertText
1823 // and UpdateData, so that the selection will be adjusted to
1824 // SvxUnoTextRangeBase. Actually all cursor objects of this Text must
1825 // to be statement to be adapted!
1827 if (!bAbsorb) // do not replace -> append on tail
1828 pRange->CollapseToEnd();
1830 pRange->setString( aString );
1832 pRange->CollapseToEnd();
1836 void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text::XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1837 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1839 SolarMutexGuard aGuard;
1841 SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1843 if( pForwarder )
1845 ESelection aSelection;
1846 ::GetSelection( aSelection, pForwarder );
1847 SetSelection( aSelection );
1849 switch( nControlCharacter )
1851 case text::ControlCharacter::PARAGRAPH_BREAK:
1853 const OUString aText( (sal_Unicode)13 ); // '\r' does not work on Mac
1854 insertString( xRange, aText, bAbsorb );
1856 return;
1858 case text::ControlCharacter::LINE_BREAK:
1860 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1861 if(pRange)
1863 ESelection aRange = pRange->GetSelection();
1865 if( bAbsorb )
1867 const OUString aEmpty;
1868 pForwarder->QuickInsertText( aEmpty, aRange );
1870 aRange.nEndPos = aRange.nStartPos;
1871 aRange.nEndPara = aRange.nStartPara;
1873 else
1875 aRange.nStartPara = aRange.nEndPara;
1876 aRange.nStartPos = aRange.nEndPos;
1879 pForwarder->QuickInsertLineBreak( aRange );
1880 GetEditSource()->UpdateData();
1882 aRange.nEndPos += 1;
1883 if( !bAbsorb )
1884 aRange.nStartPos += 1;
1886 pRange->SetSelection( aRange );
1888 return;
1890 case text::ControlCharacter::APPEND_PARAGRAPH:
1892 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1893 if(pRange)
1895 ESelection aRange = pRange->GetSelection();
1896 // ESelection aOldSelection = aRange;
1898 aRange.nStartPos = pForwarder->GetTextLen( aRange.nStartPara );
1900 aRange.nEndPara = aRange.nStartPara;
1901 aRange.nEndPos = aRange.nStartPos;
1903 pRange->SetSelection( aRange );
1904 const OUString aText( (sal_Unicode)13 ); // '\r' geht auf'm Mac nicht
1905 pRange->setString( aText );
1907 aRange.nStartPos = 0;
1908 aRange.nStartPara += 1;
1909 aRange.nEndPos = 0;
1910 aRange.nEndPara += 1;
1912 pRange->SetSelection( aRange );
1914 return;
1917 default:
1918 throw lang::IllegalArgumentException();
1923 // XText
1924 void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTextRange >& xRange, const uno::Reference< text::XTextContent >& xContent, sal_Bool bAbsorb )
1925 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
1927 SolarMutexGuard aGuard;
1929 SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1930 if (!pForwarder)
1931 return;
1933 uno::Reference<beans::XPropertySet> xPropSet(xRange, uno::UNO_QUERY);
1934 if (!xPropSet.is())
1935 throw lang::IllegalArgumentException();
1937 uno::Any aAny = xPropSet->getPropertyValue(UNO_TR_PROP_SELECTION);
1938 text::TextRangeSelection aSel = aAny.get<text::TextRangeSelection>();
1939 if (!bAbsorb)
1940 aSel.Start = aSel.End;
1942 boost::scoped_ptr<SvxFieldData> pFieldData(SvxFieldData::Create(xContent));
1943 if (!pFieldData)
1944 throw lang::IllegalArgumentException();
1946 SvxFieldItem aField( *pFieldData, EE_FEATURE_FIELD );
1947 pForwarder->QuickInsertField(aField, toESelection(aSel));
1948 GetEditSource()->UpdateData();
1950 uno::Reference<beans::XPropertySet> xPropSetContent(xContent, uno::UNO_QUERY);
1951 if (!xContent.is())
1952 throw lang::IllegalArgumentException();
1954 xPropSetContent->setPropertyValue(UNO_TC_PROP_ANCHOR, uno::makeAny(xRange));
1956 aSel.End.PositionInParagraph += 1;
1957 aSel.Start.PositionInParagraph = aSel.End.PositionInParagraph;
1958 xPropSet->setPropertyValue(UNO_TR_PROP_SELECTION, uno::makeAny(aSel));
1961 void SAL_CALL SvxUnoTextBase::removeTextContent( const uno::Reference< text::XTextContent >& ) throw(container::NoSuchElementException, uno::RuntimeException, std::exception)
1965 // XTextRange
1967 uno::Reference< text::XText > SAL_CALL SvxUnoTextBase::getText()
1968 throw(uno::RuntimeException, std::exception)
1970 SolarMutexGuard aGuard;
1972 if (GetEditSource())
1974 ESelection aSelection;
1975 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1976 SetSelection( aSelection );
1979 return (text::XText*)this;
1982 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getStart()
1983 throw(uno::RuntimeException, std::exception)
1985 return SvxUnoTextRangeBase::getStart();
1988 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getEnd()
1989 throw(uno::RuntimeException, std::exception)
1991 return SvxUnoTextRangeBase::getEnd();
1994 OUString SAL_CALL SvxUnoTextBase::getString() throw( uno::RuntimeException, std::exception )
1996 return SvxUnoTextRangeBase::getString();
1999 void SAL_CALL SvxUnoTextBase::setString( const OUString& aString ) throw(uno::RuntimeException, std::exception)
2001 SvxUnoTextRangeBase::setString(aString);
2005 // XEnumerationAccess
2006 uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextBase::createEnumeration()
2007 throw(uno::RuntimeException, std::exception)
2009 SolarMutexGuard aGuard;
2011 ESelection aSelection;
2012 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
2013 SetSelection( aSelection );
2015 uno::Reference< container::XEnumeration > xEnum( (container::XEnumeration*) new SvxUnoTextContentEnumeration( *this ) );
2016 return xEnum;
2019 // XElementAccess ( container::XEnumerationAccess )
2020 uno::Type SAL_CALL SvxUnoTextBase::getElementType( ) throw(uno::RuntimeException, std::exception)
2022 return cppu::UnoType<text::XTextRange>::get();
2025 sal_Bool SAL_CALL SvxUnoTextBase::hasElements( ) throw(uno::RuntimeException, std::exception)
2027 SolarMutexGuard aGuard;
2029 if(GetEditSource())
2031 SvxTextForwarder* pForwarder = GetEditSource()->GetTextForwarder();
2032 if(pForwarder)
2033 return pForwarder->GetParagraphCount() != 0;
2036 return sal_False;
2039 // text::XTextRangeMover
2040 void SAL_CALL SvxUnoTextBase::moveTextRange( const uno::Reference< text::XTextRange >&, sal_Int16 )
2041 throw(uno::RuntimeException, std::exception)
2045 void SvxPropertyValuesToItemSet(
2046 SfxItemSet &rItemSet,
2047 const uno::Sequence< beans::PropertyValue >& rPropertyVaules,
2048 const SfxItemPropertySet *pPropSet,
2049 SvxTextForwarder *pForwarder /*needed for WID_NUMLEVEL*/,
2050 sal_Int32 nPara /*needed for WID_NUMLEVEL*/)
2051 throw(lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2053 sal_Int32 nProps = rPropertyVaules.getLength();
2054 const beans::PropertyValue *pProps = rPropertyVaules.getConstArray();
2055 for (sal_Int32 i = 0; i < nProps; ++i)
2057 const SfxItemPropertySimpleEntry *pEntry = pPropSet->getPropertyMap().getByName( pProps[i].Name );
2058 if (pEntry)
2060 // Note: there is no need to take special care of the properties
2061 // TextField (EE_FEATURE_FIELD) and
2062 // TextPortionType (WID_PORTIONTYPE)
2063 // since they are read-only and thus are already taken care of below.
2065 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2066 // should be PropertyVetoException which is not yet defined for the new import API's functions
2067 throw uno::RuntimeException("Property is read-only: " + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2068 //throw PropertyVetoException ("Property is read-only: " + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2070 if (pEntry->nWID == WID_FONTDESC)
2072 awt::FontDescriptor aDesc;
2073 if (pProps[i].Value >>= aDesc)
2074 SvxUnoFontDescriptor::FillItemSet( aDesc, rItemSet );
2076 else if (pEntry->nWID == WID_NUMLEVEL)
2078 if (pForwarder)
2080 sal_Int16 nLevel = -1;
2081 pProps[i].Value >>= nLevel;
2083 // #101004# Call interface method instead of unsafe cast
2084 if (!pForwarder->SetDepth( nPara, nLevel ))
2085 throw lang::IllegalArgumentException();
2088 else if (pEntry->nWID == WID_NUMBERINGSTARTVALUE )
2090 if( pForwarder )
2092 sal_Int16 nStartValue = -1;
2093 if( !(pProps[i].Value >>= nStartValue) )
2094 throw lang::IllegalArgumentException();
2096 pForwarder->SetNumberingStartValue( nPara, nStartValue );
2099 else if (pEntry->nWID == WID_PARAISNUMBERINGRESTART )
2101 if( pForwarder )
2103 bool bParaIsNumberingRestart = false;
2104 if( !(pProps[i].Value >>= bParaIsNumberingRestart) )
2105 throw lang::IllegalArgumentException();
2107 pForwarder->SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart );
2110 else
2111 pPropSet->setPropertyValue( pProps[i].Name, pProps[i].Value, rItemSet );
2113 else
2114 throw beans::UnknownPropertyException( "Unknown property: " + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2118 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraphInsert(
2119 const uno::Sequence< beans::PropertyValue >& /*rCharAndParaProps*/,
2120 const uno::Reference< text::XTextRange >& /*rTextRange*/ )
2121 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
2123 uno::Reference< text::XTextRange > xRet;
2124 return xRet;
2127 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraph(
2128 const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2129 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
2131 SolarMutexGuard aGuard;
2133 uno::Reference< text::XTextRange > xRet;
2134 SvxEditSource *pEditSource = GetEditSource();
2135 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2136 if (pTextForwarder)
2138 sal_Int32 nParaCount = pTextForwarder->GetParagraphCount();
2139 DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2140 pTextForwarder->AppendParagraph();
2142 // set properties for the previously last paragraph
2143 sal_Int32 nPara = nParaCount - 1;
2144 ESelection aSel( nPara, 0, nPara, 0 );
2145 SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2146 SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2147 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder, nPara );
2148 pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2149 pEditSource->UpdateData();
2150 SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2151 xRet = pRange;
2152 pRange->SetSelection( aSel );
2154 return xRet;
2157 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::insertTextPortion(
2158 const OUString& /*rText*/,
2159 const uno::Sequence< beans::PropertyValue >& /*rCharAndParaProps*/,
2160 const uno::Reference< text::XTextRange>& /*rTextRange*/ )
2161 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
2163 uno::Reference< text::XTextRange > xRet;
2164 return xRet;
2167 // com::sun::star::text::XTextPortionAppend (new import API)
2168 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendTextPortion(
2169 const OUString& rText,
2170 const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2171 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
2173 SolarMutexGuard aGuard;
2175 SvxEditSource *pEditSource = GetEditSource();
2176 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2177 uno::Reference< text::XTextRange > xRet;
2178 if (pTextForwarder)
2180 sal_Int32 nParaCount = pTextForwarder->GetParagraphCount();
2181 DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2182 sal_Int32 nPara = nParaCount - 1;
2183 SfxItemSet aSet( pTextForwarder->GetParaAttribs( nPara ) );
2184 sal_Int32 nStart = pTextForwarder->AppendTextPortion( nPara, rText, aSet );
2185 pEditSource->UpdateData();
2186 sal_Int32 nEnd = pTextForwarder->GetTextLen( nPara );
2188 // set properties for the new text portion
2189 ESelection aSel( nPara, nStart, nPara, nEnd );
2190 pTextForwarder->RemoveAttribs( aSel, false, 0 );
2191 pEditSource->UpdateData();
2193 SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2194 SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2195 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder, nPara );
2196 pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2197 SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2198 xRet = pRange;
2199 pRange->SetSelection( aSel );
2200 const beans::PropertyValue* pProps = rCharAndParaProps.getConstArray();
2201 for( sal_Int32 nProp = 0; nProp < rCharAndParaProps.getLength(); ++nProp )
2202 pRange->setPropertyValue( pProps[nProp].Name, pProps[nProp].Value );
2204 return xRet;
2207 void SvxUnoTextBase::copyText(
2208 const uno::Reference< text::XTextCopy >& xSource ) throw ( uno::RuntimeException, std::exception )
2210 SolarMutexGuard aGuard;
2211 uno::Reference< lang::XUnoTunnel > xUT( xSource, uno::UNO_QUERY );
2212 SvxEditSource *pEditSource = GetEditSource();
2213 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2214 if( !pTextForwarder )
2215 return;
2216 if( xUT.is() )
2218 SvxUnoTextBase* pSource = reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(
2219 xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2220 SvxEditSource *pSourceEditSource = pSource->GetEditSource();
2221 SvxTextForwarder *pSourceTextForwarder = pSourceEditSource ? pSourceEditSource->GetTextForwarder() : 0;
2222 if( pSourceTextForwarder )
2224 pTextForwarder->CopyText( *pSourceTextForwarder );
2225 pEditSource->UpdateData();
2228 else
2230 uno::Reference< text::XText > xSourceText( xSource, uno::UNO_QUERY );
2231 if( xSourceText.is() )
2233 setString( xSourceText->getString() );
2238 // lang::XServiceInfo
2239 OUString SAL_CALL SvxUnoTextBase::getImplementationName()
2240 throw(uno::RuntimeException, std::exception)
2242 return OUString("SvxUnoTextBase");
2245 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames( )
2246 throw(uno::RuntimeException, std::exception)
2248 return getSupportedServiceNames_Static();
2251 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames_Static( )
2253 uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() );
2254 comphelper::ServiceInfoHelper::addToSequence( aSeq, 1, "com.sun.star.text.Text" );
2255 return aSeq;
2258 namespace
2260 class theSvxUnoTextBaseUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextBaseUnoTunnelId > {};
2263 const uno::Sequence< sal_Int8 > & SvxUnoTextBase::getUnoTunnelId() throw()
2265 return theSvxUnoTextBaseUnoTunnelId::get().getSeq();
2268 SvxUnoTextBase* SvxUnoTextBase::getImplementation( const uno::Reference< uno::XInterface >& xInt )
2270 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2271 if( xUT.is() )
2272 return reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2273 else
2274 return NULL;
2277 sal_Int64 SAL_CALL SvxUnoTextBase::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception) \
2279 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2280 rId.getConstArray(), 16 ) )
2282 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2284 else
2286 return SvxUnoTextRangeBase::getSomething( rId );
2290 SvxUnoText::SvxUnoText( const SvxItemPropertySet* _pSet ) throw()
2291 : SvxUnoTextBase( _pSet )
2295 SvxUnoText::SvxUnoText( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
2296 : SvxUnoTextBase( pSource, _pSet, xParent )
2300 SvxUnoText::SvxUnoText( const SvxUnoText& rText ) throw()
2301 : SvxUnoTextBase( rText )
2302 , cppu::OWeakAggObject()
2306 SvxUnoText::~SvxUnoText() throw()
2310 // uno::XInterface
2311 uno::Any SAL_CALL SvxUnoText::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException, std::exception )
2313 uno::Any aAny( SvxUnoTextBase::queryAggregation( rType ) );
2314 if( !aAny.hasValue() )
2315 aAny = OWeakAggObject::queryAggregation( rType );
2317 return aAny;
2320 uno::Any SAL_CALL SvxUnoText::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException, std::exception )
2322 return OWeakAggObject::queryInterface( rType );
2325 void SAL_CALL SvxUnoText::acquire() throw( )
2327 OWeakAggObject::acquire();
2330 void SAL_CALL SvxUnoText::release() throw( )
2332 OWeakAggObject::release();
2335 // lang::XTypeProvider
2336 uno::Sequence< uno::Type > SAL_CALL SvxUnoText::getTypes( ) throw( uno::RuntimeException, std::exception )
2338 return SvxUnoTextBase::getTypes();
2341 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoText::getImplementationId( ) throw( uno::RuntimeException, std::exception )
2343 return css::uno::Sequence<sal_Int8>();
2346 namespace
2348 class theSvxUnoTextUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextUnoTunnelId > {};
2351 const uno::Sequence< sal_Int8 > & SvxUnoText::getUnoTunnelId() throw()
2353 return theSvxUnoTextUnoTunnelId::get().getSeq();
2356 sal_Int64 SAL_CALL SvxUnoText::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception) \
2358 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2359 rId.getConstArray(), 16 ) )
2361 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2363 else
2365 return SvxUnoTextBase::getSomething( rId );
2372 SvxDummyTextSource::~SvxDummyTextSource()
2376 SvxEditSource* SvxDummyTextSource::Clone() const
2378 return new SvxDummyTextSource();
2381 SvxTextForwarder* SvxDummyTextSource::GetTextForwarder()
2383 return this;
2386 void SvxDummyTextSource::UpdateData()
2390 sal_Int32 SvxDummyTextSource::GetParagraphCount() const
2392 return 0;
2395 sal_Int32 SvxDummyTextSource::GetTextLen( sal_Int32 ) const
2397 return 0;
2400 OUString SvxDummyTextSource::GetText( const ESelection& ) const
2402 return OUString();
2405 SfxItemSet SvxDummyTextSource::GetAttribs( const ESelection&, EditEngineAttribs ) const
2407 // Very dangerous: The former implementation used a SfxItemPool created on the
2408 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2409 // a deleted Pool by design.
2410 return SfxItemSet(EditEngine::GetGlobalItemPool());
2413 SfxItemSet SvxDummyTextSource::GetParaAttribs( sal_Int32 ) const
2415 return GetAttribs(ESelection());
2418 void SvxDummyTextSource::SetParaAttribs( sal_Int32, const SfxItemSet& )
2422 void SvxDummyTextSource::RemoveAttribs( const ESelection& , bool , sal_uInt16 )
2426 void SvxDummyTextSource::GetPortions( sal_Int32, std::vector<sal_Int32>& ) const
2430 SfxItemState SvxDummyTextSource::GetItemState( const ESelection&, sal_uInt16 ) const
2432 return SfxItemState::UNKNOWN;
2435 SfxItemState SvxDummyTextSource::GetItemState( sal_Int32, sal_uInt16 ) const
2437 return SfxItemState::UNKNOWN;
2440 SfxItemPool* SvxDummyTextSource::GetPool() const
2442 return NULL;
2445 void SvxDummyTextSource::QuickInsertText( const OUString&, const ESelection& )
2449 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem&, const ESelection& )
2453 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet&, const ESelection& )
2457 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection& )
2461 OUString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, Color*&, Color*& )
2463 return OUString();
2466 void SvxDummyTextSource::FieldClicked( const SvxFieldItem&, sal_Int32, sal_Int32 )
2470 bool SvxDummyTextSource::IsValid() const
2472 return false;
2475 LanguageType SvxDummyTextSource::GetLanguage( sal_Int32, sal_Int32 ) const
2477 return LANGUAGE_DONTKNOW;
2480 sal_Int32 SvxDummyTextSource::GetFieldCount( sal_Int32 ) const
2482 return 0;
2485 EFieldInfo SvxDummyTextSource::GetFieldInfo( sal_Int32, sal_uInt16 ) const
2487 return EFieldInfo();
2490 EBulletInfo SvxDummyTextSource::GetBulletInfo( sal_Int32 ) const
2492 return EBulletInfo();
2495 Rectangle SvxDummyTextSource::GetCharBounds( sal_Int32, sal_Int32 ) const
2497 return Rectangle();
2500 Rectangle SvxDummyTextSource::GetParaBounds( sal_Int32 ) const
2502 return Rectangle();
2505 MapMode SvxDummyTextSource::GetMapMode() const
2507 return MapMode();
2510 OutputDevice* SvxDummyTextSource::GetRefDevice() const
2512 return NULL;
2515 bool SvxDummyTextSource::GetIndexAtPoint( const Point&, sal_Int32&, sal_Int32& ) const
2517 return false;
2520 bool SvxDummyTextSource::GetWordIndices( sal_Int32, sal_Int32, sal_Int32&, sal_Int32& ) const
2522 return false;
2525 bool SvxDummyTextSource::GetAttributeRun( sal_Int32&, sal_Int32&, sal_Int32, sal_Int32, bool ) const
2527 return false;
2530 sal_Int32 SvxDummyTextSource::GetLineCount( sal_Int32 ) const
2532 return 0;
2535 sal_Int32 SvxDummyTextSource::GetLineLen( sal_Int32, sal_Int32 ) const
2537 return 0;
2540 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 /*nParagraph*/, sal_Int32 /*nLine*/ ) const
2542 rStart = rEnd = 0;
2545 sal_Int32 SvxDummyTextSource::GetLineNumberAtIndex( sal_Int32 /*nPara*/, sal_Int32 /*nIndex*/ ) const
2547 return 0;
2550 bool SvxDummyTextSource::QuickFormatDoc( bool )
2552 return false;
2555 sal_Int16 SvxDummyTextSource::GetDepth( sal_Int32 ) const
2557 return -1;
2560 bool SvxDummyTextSource::SetDepth( sal_Int32, sal_Int16 nNewDepth )
2562 return nNewDepth == 0;
2565 bool SvxDummyTextSource::Delete( const ESelection& )
2567 return false;
2570 bool SvxDummyTextSource::InsertText( const OUString&, const ESelection& )
2572 return false;
2575 const SfxItemSet * SvxDummyTextSource::GetEmptyItemSetPtr()
2577 return 0;
2580 void SvxDummyTextSource::AppendParagraph()
2584 sal_Int32 SvxDummyTextSource::AppendTextPortion( sal_Int32, const OUString &, const SfxItemSet & )
2586 return 0;
2589 void SvxDummyTextSource::CopyText(const SvxTextForwarder& )
2593 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */