bump product version to 4.1.6.2
[LibreOffice.git] / editeng / source / uno / unotext.cxx
blobb3199216cd6c77b971cb93ab5e2e97e862195e2a
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/serviceinfohelper.hxx>
47 #include <comphelper/servicehelper.hxx>
49 #include "editeng/unonames.hxx"
51 #include <boost/scoped_ptr.hpp>
53 using namespace ::rtl;
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 == ::getCppuType((const uno::Reference< xint >*)0) ) \
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 {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD, &::getCppuType((const uno::Reference< text::XTextField >*)0), beans::PropertyAttribute::READONLY, 0 },
91 {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE, &::getCppuType((const OUString*)0), beans::PropertyAttribute::READONLY, 0 },
92 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
93 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
94 {0,0,0,0,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 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
120 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
121 {0,0,0,0,0,0}
124 return aSvxUnoOutlinerTextCursorPropertyMap;
126 const SfxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
128 static SfxItemPropertySet aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
129 return &aTextCursorSfxPropertySet;
132 // ====================================================================
133 // helper for Item/Property conversion
134 // ====================================================================
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() );
205 // ====================================================================
206 // class SvxUnoTextRangeBase
207 // ====================================================================
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(void)
310 throw( uno::RuntimeException )
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(void)
339 throw( uno::RuntimeException )
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(void)
367 throw( uno::RuntimeException )
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 )
388 SolarMutexGuard aGuard;
390 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
391 if( pForwarder )
393 CheckSelection( maSelection, pForwarder );
395 String 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_uInt16 nLen = aConverted.Len();
406 if (nLen)
407 GoRight( nLen, sal_True );
411 // Interface beans::XPropertySet
412 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextRangeBase::getPropertySetInfo(void)
413 throw( uno::RuntimeException )
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 )
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 sal_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 mpPropSet->setPropertyValue(pMap, rValue, rNewSet, false );
503 sal_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 sal_True;
516 break;
518 case EE_PARA_NUMBULLET:
520 uno::Reference< container::XIndexReplace > xRule;
521 if( !aValue.hasValue() || ((aValue >>= xRule) && !xRule.is()) )
522 return sal_True;
524 return sal_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 sal_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 sal_True;
557 break;
558 case WID_PARAISNUMBERINGRESTART:
560 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
561 if(pForwarder && pSelection)
563 sal_Bool bParaIsNumberingRestart = sal_False;
564 if( aValue >>= bParaIsNumberingRestart )
566 pForwarder->SetParaIsNumberingRestart( pSelection->nStartPara, bParaIsNumberingRestart );
567 return sal_True;
571 break;
572 case EE_PARA_BULLETSTATE:
574 sal_Bool bBullet = sal_True;
575 if( aValue >>= bBullet )
577 SfxBoolItem aItem( EE_PARA_BULLETSTATE, bBullet );
578 rNewSet.Put(aItem);
579 return sal_True;
582 break;
584 default:
585 return sal_False;
588 throw lang::IllegalArgumentException();
591 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyValue(const OUString& PropertyName)
592 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
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 ) throw( beans::UnknownPropertyException )
642 switch( pMap->nWID )
644 case EE_FEATURE_FIELD:
645 if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET )
647 SvxFieldItem* pItem = (SvxFieldItem*)rSet.GetItem( EE_FEATURE_FIELD );
648 const SvxFieldData* pData = pItem->GetField();
649 uno::Reference< text::XTextRange > xAnchor( this );
651 // get presentation string for field
652 Color* pTColor = NULL;
653 Color* pFColor = NULL;
655 SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder();
656 OUString aPresentation( pForwarder->CalcFieldValue( SvxFieldItem(*pData, EE_FEATURE_FIELD), maSelection.nStartPara, maSelection.nStartPos, pTColor, pFColor ) );
658 delete pTColor;
659 delete pFColor;
661 uno::Reference< text::XTextField > xField( new SvxUnoTextField( xAnchor, aPresentation, pData ) );
662 rAny <<= xField;
664 break;
666 case WID_PORTIONTYPE:
667 if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET )
669 OUString aType("TextField");
670 rAny <<= aType;
672 else
674 OUString aType("Text");
675 rAny <<= aType;
677 break;
679 default:
680 if(!GetPropertyValueHelper( *((SfxItemSet*)(&rSet)), pMap, rAny, &maSelection, GetEditSource() ))
681 rAny = mpPropSet->getPropertyValue(pMap, rSet, true, false );
685 sal_Bool SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet& rSet, const SfxItemPropertySimpleEntry* pMap, uno::Any& aAny, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL */ )
686 throw( uno::RuntimeException )
688 switch( pMap->nWID )
690 case WID_FONTDESC:
692 awt::FontDescriptor aDesc;
693 SvxUnoFontDescriptor::FillFromItemSet( rSet, aDesc );
694 aAny <<= aDesc;
696 break;
698 case EE_PARA_NUMBULLET:
700 if((rSet.GetItemState( EE_PARA_NUMBULLET, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT)) == 0)
701 throw uno::RuntimeException();
703 SvxNumBulletItem* pBulletItem = (SvxNumBulletItem*)rSet.GetItem( EE_PARA_NUMBULLET, sal_True );
705 if( pBulletItem == NULL )
706 throw uno::RuntimeException();
708 aAny <<= SvxCreateNumRule( pBulletItem->GetNumRule() );
710 break;
712 case WID_NUMLEVEL:
714 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
715 if(pForwarder && pSelection)
717 sal_Int16 nLevel = pForwarder->GetDepth( pSelection->nStartPara );
718 if( nLevel >= 0 )
719 aAny <<= nLevel;
722 break;
723 case WID_NUMBERINGSTARTVALUE:
725 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
726 if(pForwarder && pSelection)
727 aAny <<= pForwarder->GetNumberingStartValue( pSelection->nStartPara );
729 break;
730 case WID_PARAISNUMBERINGRESTART:
732 SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
733 if(pForwarder && pSelection)
734 aAny <<= pForwarder->IsParaIsNumberingRestart( pSelection->nStartPara );
736 break;
738 case EE_PARA_BULLETSTATE:
740 sal_Bool bState = sal_False;
741 if( rSet.GetItemState( EE_PARA_BULLETSTATE, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT))
743 SfxBoolItem* pItem = (SfxBoolItem*)rSet.GetItem( EE_PARA_BULLETSTATE, sal_True );
744 bState = pItem->GetValue() ? sal_True : sal_False;
747 aAny <<= bState;
749 break;
750 default:
752 return sal_False;
755 return sal_True;
758 // is not (yet) supported
759 void SAL_CALL SvxUnoTextRangeBase::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
760 void SAL_CALL SvxUnoTextRangeBase::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
761 void SAL_CALL SvxUnoTextRangeBase::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
762 void SAL_CALL SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
764 // XMultiPropertySet
765 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)
767 _setPropertyValues( aPropertyNames, aValues, -1 );
770 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)
772 SolarMutexGuard aGuard;
774 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
775 if( pForwarder )
777 CheckSelection( maSelection, pForwarder );
779 ESelection aSel( GetSelection() );
781 const OUString* pPropertyNames = aPropertyNames.getConstArray();
782 const uno::Any* pValues = aValues.getConstArray();
783 sal_Int32 nCount = aPropertyNames.getLength();
785 sal_Int32 nEndPara = nPara;
786 sal_Int32 nTempPara = nPara;
788 if( nTempPara == -1 )
790 nTempPara = aSel.nStartPara;
791 nEndPara = aSel.nEndPara;
794 SfxItemSet* pOldAttrSet = NULL;
795 SfxItemSet* pNewAttrSet = NULL;
797 SfxItemSet* pOldParaSet = NULL;
798 SfxItemSet* pNewParaSet = NULL;
800 for( ; nCount; nCount--, pPropertyNames++, pValues++ )
802 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
804 if( pMap )
806 sal_Bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END );
808 if( (nPara == -1) && !bParaAttrib )
810 if( NULL == pNewAttrSet )
812 const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) );
813 pOldAttrSet = new SfxItemSet( aSet );
814 pNewAttrSet = new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() );
817 setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet );
819 if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
821 const SfxPoolItem* pItem;
822 if( pNewAttrSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET )
824 pOldAttrSet->Put( *pItem );
828 else
830 if( NULL == pNewParaSet )
832 const SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) );
833 pOldParaSet = new SfxItemSet( aSet );
834 pNewParaSet = new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() );
837 setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet );
839 if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
841 const SfxPoolItem* pItem;
842 if( pNewParaSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET )
844 pOldParaSet->Put( *pItem );
852 sal_Bool bNeedsUpdate = sal_False;
854 if( pNewParaSet )
856 if( pNewParaSet->Count() )
858 while( nTempPara <= nEndPara )
860 SfxItemSet aSet( pForwarder->GetParaAttribs( nTempPara ) );
861 aSet.Put( *pNewParaSet );
862 pForwarder->SetParaAttribs( nTempPara, aSet );
863 nTempPara++;
865 bNeedsUpdate = sal_True;
868 delete pNewParaSet;
869 delete pOldParaSet;
872 if( pNewAttrSet )
874 if( pNewAttrSet->Count() )
876 pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() );
877 bNeedsUpdate = sal_True;
879 delete pNewAttrSet;
880 delete pOldAttrSet;
884 if( bNeedsUpdate )
885 GetEditSource()->UpdateData();
889 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence< OUString >& aPropertyNames ) throw (uno::RuntimeException)
891 return _getPropertyValues( aPropertyNames, -1 );
894 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence< OUString >& aPropertyNames, sal_Int32 nPara ) throw (uno::RuntimeException)
896 SolarMutexGuard aGuard;
898 sal_Int32 nCount = aPropertyNames.getLength();
901 uno::Sequence< uno::Any > aValues( nCount );
903 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
904 if( pForwarder )
906 SfxItemSet* pAttribs = NULL;
907 if( nPara != -1 )
908 pAttribs = pForwarder->GetParaAttribs( nPara ).Clone();
909 else
910 pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone();
912 pAttribs->ClearInvalidItems();
914 const OUString* pPropertyNames = aPropertyNames.getConstArray();
915 uno::Any* pValues = aValues.getArray();
917 for( ; nCount; nCount--, pPropertyNames++, pValues++ )
919 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
920 if( pMap )
922 getPropertyValue( pMap, *pValues, *pAttribs );
926 delete pAttribs;
930 return aValues;
933 void SAL_CALL SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
937 void SAL_CALL SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
941 void SAL_CALL SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
945 // beans::XPropertyState
946 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::getPropertyState( const OUString& PropertyName )
947 throw(beans::UnknownPropertyException, uno::RuntimeException)
949 return _getPropertyState( PropertyName, -1 );
952 static sal_uInt16 aSvxUnoFontDescriptorWhichMap[] = { EE_CHAR_FONTINFO, EE_CHAR_FONTHEIGHT, EE_CHAR_ITALIC,
953 EE_CHAR_UNDERLINE, EE_CHAR_WEIGHT, EE_CHAR_STRIKEOUT,
954 EE_CHAR_WLM, 0 };
956 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara)
957 throw( beans::UnknownPropertyException, uno::RuntimeException )
959 if ( pMap )
961 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
962 if( pForwarder )
964 SfxItemState eItemState = SFX_ITEM_UNKNOWN;
965 sal_uInt16 nWID = 0;
967 switch( pMap->nWID )
969 case WID_FONTDESC:
971 sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
972 SfxItemState eTempItemState;
973 while( *pWhichId )
975 if(nPara != -1)
976 eTempItemState = pForwarder->GetItemState( nPara, *pWhichId );
977 else
978 eTempItemState = pForwarder->GetItemState( GetSelection(), *pWhichId );
980 switch( eTempItemState )
982 case SFX_ITEM_DISABLED:
983 case SFX_ITEM_DONTCARE:
984 eItemState = SFX_ITEM_DONTCARE;
985 break;
987 case SFX_ITEM_DEFAULT:
988 if( eItemState != SFX_ITEM_DEFAULT )
990 if( eItemState == SFX_ITEM_UNKNOWN )
991 eItemState = SFX_ITEM_DEFAULT;
993 break;
995 case SFX_ITEM_READONLY:
996 case SFX_ITEM_SET:
997 if( eItemState != SFX_ITEM_SET )
999 if( eItemState == SFX_ITEM_UNKNOWN )
1000 eItemState = SFX_ITEM_SET;
1002 break;
1003 default:
1004 throw beans::UnknownPropertyException();
1007 pWhichId++;
1010 break;
1012 case WID_NUMLEVEL:
1013 case WID_NUMBERINGSTARTVALUE:
1014 case WID_PARAISNUMBERINGRESTART:
1015 eItemState = SFX_ITEM_SET;
1016 break;
1018 default:
1019 nWID = pMap->nWID;
1022 if( nWID != 0 )
1024 if( nPara != -1 )
1025 eItemState = pForwarder->GetItemState( nPara, nWID );
1026 else
1027 eItemState = pForwarder->GetItemState( GetSelection(), nWID );
1030 switch( eItemState )
1032 case SFX_ITEM_DONTCARE:
1033 case SFX_ITEM_DISABLED:
1034 return beans::PropertyState_AMBIGUOUS_VALUE;
1035 case SFX_ITEM_READONLY:
1036 case SFX_ITEM_SET:
1037 return beans::PropertyState_DIRECT_VALUE;
1038 case SFX_ITEM_DEFAULT:
1039 return beans::PropertyState_DEFAULT_VALUE;
1040 // case SFX_ITEM_UNKNOWN:
1044 throw beans::UnknownPropertyException();
1047 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1048 throw( beans::UnknownPropertyException, uno::RuntimeException )
1050 SolarMutexGuard aGuard;
1052 return _getPropertyState( mpPropSet->getPropertyMapEntry( PropertyName ), nPara);
1055 uno::Sequence< beans::PropertyState > SAL_CALL SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
1056 throw(beans::UnknownPropertyException, uno::RuntimeException)
1058 return _getPropertyStates( aPropertyName, -1 );
1061 uno::Sequence< beans::PropertyState > SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence< OUString >& PropertyName, sal_Int32 nPara /* = -1 */)
1062 throw( beans::UnknownPropertyException, uno::RuntimeException )
1064 const sal_Int32 nCount = PropertyName.getLength();
1065 const OUString* pNames = PropertyName.getConstArray();
1067 uno::Sequence< beans::PropertyState > aRet( nCount );
1068 beans::PropertyState* pState = aRet.getArray();
1070 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1071 if( pForwarder )
1073 SfxItemSet* pSet = NULL;
1074 if( nPara != -1 )
1076 pSet = new SfxItemSet( pForwarder->GetParaAttribs( nPara ) );
1078 else
1080 ESelection aSel( GetSelection() );
1081 CheckSelection( aSel, pForwarder );
1082 pSet = new SfxItemSet( pForwarder->GetAttribs( aSel, EditEngineAttribs_OnlyHard ) );
1085 sal_Bool bUnknownPropertyFound = sal_False;
1086 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++ )
1088 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pNames++ );
1089 if( NULL == pMap )
1091 bUnknownPropertyFound = sal_True;
1092 break;
1094 bUnknownPropertyFound = !_getOnePropertyStates(pSet, pMap, *pState++);
1097 delete pSet;
1099 if( bUnknownPropertyFound )
1100 throw beans::UnknownPropertyException();
1103 return aRet;
1106 sal_Bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const SfxItemPropertySimpleEntry* pMap, beans::PropertyState& rState)
1108 sal_Bool bUnknownPropertyFound = sal_False;
1109 if(pSet && pMap)
1111 SfxItemState eItemState = SFX_ITEM_UNKNOWN;
1112 sal_uInt16 nWID = 0;
1114 switch( pMap->nWID )
1116 case WID_FONTDESC:
1118 sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
1119 SfxItemState eTempItemState;
1120 while( *pWhichId )
1122 eTempItemState = pSet->GetItemState( *pWhichId );
1124 switch( eTempItemState )
1126 case SFX_ITEM_DISABLED:
1127 case SFX_ITEM_DONTCARE:
1128 eItemState = SFX_ITEM_DONTCARE;
1129 break;
1131 case SFX_ITEM_DEFAULT:
1132 if( eItemState != SFX_ITEM_DEFAULT )
1134 if( eItemState == SFX_ITEM_UNKNOWN )
1135 eItemState = SFX_ITEM_DEFAULT;
1137 break;
1139 case SFX_ITEM_READONLY:
1140 case SFX_ITEM_SET:
1141 if( eItemState != SFX_ITEM_SET )
1143 if( eItemState == SFX_ITEM_UNKNOWN )
1144 eItemState = SFX_ITEM_SET;
1146 break;
1147 default:
1148 bUnknownPropertyFound = sal_True;
1149 break;
1152 pWhichId++;
1155 break;
1157 case WID_NUMLEVEL:
1158 case WID_NUMBERINGSTARTVALUE:
1159 case WID_PARAISNUMBERINGRESTART:
1160 eItemState = SFX_ITEM_SET;
1161 break;
1163 default:
1164 nWID = pMap->nWID;
1167 if( bUnknownPropertyFound )
1168 return !bUnknownPropertyFound;
1170 if( nWID != 0 )
1171 eItemState = pSet->GetItemState( nWID, sal_False );
1173 switch( eItemState )
1175 case SFX_ITEM_READONLY:
1176 case SFX_ITEM_SET:
1177 rState = beans::PropertyState_DIRECT_VALUE;
1178 break;
1179 case SFX_ITEM_DEFAULT:
1180 rState = beans::PropertyState_DEFAULT_VALUE;
1181 break;
1182 // case SFX_ITEM_UNKNOWN:
1183 // case SFX_ITEM_DONTCARE:
1184 // case SFX_ITEM_DISABLED:
1185 default:
1186 rState = beans::PropertyState_AMBIGUOUS_VALUE;
1189 return !bUnknownPropertyFound;
1192 void SAL_CALL SvxUnoTextRangeBase::setPropertyToDefault( const OUString& PropertyName )
1193 throw(beans::UnknownPropertyException, uno::RuntimeException)
1195 _setPropertyToDefault( PropertyName, -1 );
1198 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1199 throw( beans::UnknownPropertyException, uno::RuntimeException )
1201 SolarMutexGuard aGuard;
1203 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1205 if( pForwarder )
1207 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( PropertyName );
1208 if ( pMap )
1210 CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1211 _setPropertyToDefault( pForwarder, pMap, nPara );
1212 return;
1216 throw beans::UnknownPropertyException();
1219 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder* pForwarder, const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara )
1220 throw( beans::UnknownPropertyException, uno::RuntimeException )
1224 SfxItemSet aSet( *pForwarder->GetPool(), sal_True );
1226 if( pMap->nWID == WID_FONTDESC )
1228 SvxUnoFontDescriptor::setPropertyToDefault( aSet );
1230 else if( pMap->nWID == WID_NUMLEVEL )
1232 // #101004# Call interface method instead of unsafe cast
1233 pForwarder->SetDepth( maSelection.nStartPara, -1 );
1234 return;
1236 else if( pMap->nWID == WID_NUMBERINGSTARTVALUE )
1238 pForwarder->SetNumberingStartValue( maSelection.nStartPara, -1 );
1240 else if( pMap->nWID == WID_PARAISNUMBERINGRESTART )
1242 pForwarder->SetParaIsNumberingRestart( maSelection.nStartPara, sal_False );
1244 else
1246 aSet.InvalidateItem( pMap->nWID );
1249 if(nPara != -1)
1250 pForwarder->SetParaAttribs( nPara, aSet );
1251 else
1252 pForwarder->QuickSetAttribs( aSet, GetSelection() );
1254 GetEditSource()->UpdateData();
1256 return;
1258 while(0);
1261 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyDefault( const OUString& aPropertyName )
1262 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1264 SolarMutexGuard aGuard;
1266 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1267 if( pForwarder )
1269 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( aPropertyName );
1270 if( pMap )
1272 SfxItemPool* pPool = pForwarder->GetPool();
1274 switch( pMap->nWID )
1276 case WID_FONTDESC:
1277 return SvxUnoFontDescriptor::getPropertyDefault( pPool );
1279 case WID_NUMLEVEL:
1281 uno::Any aAny;
1282 return aAny;
1285 case WID_NUMBERINGSTARTVALUE:
1286 return uno::Any( (sal_Int16)-1 );
1288 case WID_PARAISNUMBERINGRESTART:
1289 return uno::Any( (sal_Bool)sal_False );
1291 default:
1293 // Get Default from ItemPool
1294 if(pPool->IsWhich(pMap->nWID))
1296 SfxItemSet aSet( *pPool, pMap->nWID, pMap->nWID);
1297 aSet.Put(pPool->GetDefaultItem(pMap->nWID));
1298 return mpPropSet->getPropertyValue(pMap, aSet, true, false );
1304 throw beans::UnknownPropertyException();
1307 // beans::XMultiPropertyStates
1308 void SAL_CALL SvxUnoTextRangeBase::setAllPropertiesToDefault( ) throw (uno::RuntimeException)
1310 SolarMutexGuard aGuard;
1312 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1314 if( pForwarder )
1316 PropertyEntryVector_t aEntries = mpPropSet->getPropertyMap()->getPropertyEntries();
1317 PropertyEntryVector_t::const_iterator aIt = aEntries.begin();
1318 while( aIt != aEntries.end() )
1320 _setPropertyToDefault( pForwarder, &(*aIt), -1 );
1321 ++aIt;
1326 void SAL_CALL SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, uno::RuntimeException)
1328 sal_Int32 nCount = aPropertyNames.getLength();
1329 for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount-- )
1331 setPropertyToDefault( *pName );
1335 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1337 sal_Int32 nCount = aPropertyNames.getLength();
1338 uno::Sequence< uno::Any > ret( nCount );
1339 uno::Any* pDefaults = ret.getArray();
1341 for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount--, pDefaults++ )
1343 *pDefaults = getPropertyDefault( *pName );
1346 return ret;
1349 // internal
1350 void SvxUnoTextRangeBase::CollapseToStart(void) throw()
1352 CheckSelection( maSelection, mpEditSource );
1354 maSelection.nEndPara = maSelection.nStartPara;
1355 maSelection.nEndPos = maSelection.nStartPos;
1358 void SvxUnoTextRangeBase::CollapseToEnd(void) throw()
1360 CheckSelection( maSelection, mpEditSource );
1362 maSelection.nStartPara = maSelection.nEndPara;
1363 maSelection.nStartPos = maSelection.nEndPos;
1366 sal_Bool SvxUnoTextRangeBase::IsCollapsed(void) throw()
1368 CheckSelection( maSelection, mpEditSource );
1370 return ( maSelection.nStartPara == maSelection.nEndPara &&
1371 maSelection.nStartPos == maSelection.nEndPos );
1374 sal_Bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount, sal_Bool Expand) throw()
1376 CheckSelection( maSelection, mpEditSource );
1378 // #75098# use end position, as in Writer (start is anchor, end is cursor)
1379 sal_uInt16 nNewPos = maSelection.nEndPos;
1380 sal_Int32 nNewPar = maSelection.nEndPara;
1382 sal_Bool bOk = sal_True;
1383 SvxTextForwarder* pForwarder = NULL;
1384 while ( nCount > nNewPos && bOk )
1386 if ( nNewPar == 0 )
1387 bOk = sal_False;
1388 else
1390 if ( !pForwarder )
1391 pForwarder = mpEditSource->GetTextForwarder(); // first here, it it is necessary...
1393 --nNewPar;
1394 nCount -= nNewPos + 1;
1395 nNewPos = pForwarder->GetTextLen( nNewPar );
1399 if ( bOk )
1401 nNewPos = nNewPos - nCount;
1402 maSelection.nStartPara = nNewPar;
1403 maSelection.nStartPos = nNewPos;
1406 if (!Expand)
1407 CollapseToStart();
1409 return bOk;
1412 sal_Bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount, sal_Bool Expand) throw()
1414 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1415 if( pForwarder )
1417 CheckSelection( maSelection, pForwarder );
1419 sal_uInt16 nNewPos = maSelection.nEndPos + nCount; //! Overflow???
1420 sal_Int32 nNewPar = maSelection.nEndPara;
1422 sal_Bool bOk = sal_True;
1423 sal_Int32 nParCount = pForwarder->GetParagraphCount();
1424 sal_uInt16 nThisLen = pForwarder->GetTextLen( nNewPar );
1425 while ( nNewPos > nThisLen && bOk )
1427 if ( nNewPar + 1 >= nParCount )
1428 bOk = sal_False;
1429 else
1431 nNewPos -= nThisLen+1;
1432 ++nNewPar;
1433 nThisLen = pForwarder->GetTextLen( nNewPar );
1437 if (bOk)
1439 maSelection.nEndPara = nNewPar;
1440 maSelection.nEndPos = nNewPos;
1443 if (!Expand)
1444 CollapseToEnd();
1446 return bOk;
1448 return sal_False;
1451 void SvxUnoTextRangeBase::GotoStart(sal_Bool Expand) throw()
1453 maSelection.nStartPara = 0;
1454 maSelection.nStartPos = 0;
1456 if (!Expand)
1457 CollapseToStart();
1460 void SvxUnoTextRangeBase::GotoEnd(sal_Bool Expand) throw()
1462 CheckSelection( maSelection, mpEditSource );
1464 SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1465 if( pForwarder )
1468 sal_Int32 nPar = pForwarder->GetParagraphCount();
1469 if (nPar)
1470 --nPar;
1472 maSelection.nEndPara = nPar;
1473 maSelection.nEndPos = pForwarder->GetTextLen( nPar );
1475 if (!Expand)
1476 CollapseToEnd();
1480 // lang::XServiceInfo
1481 sal_Bool SAL_CALL SvxUnoTextRangeBase::supportsService( const OUString& ServiceName )
1482 throw(uno::RuntimeException)
1484 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
1487 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames()
1488 throw(uno::RuntimeException)
1490 return getSupportedServiceNames_Static();
1493 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1494 SAL_THROW(())
1496 uno::Sequence< OUString > aSeq;
1497 comphelper::ServiceInfoHelper::addToSequence( aSeq, 3, "com.sun.star.style.CharacterProperties",
1498 "com.sun.star.style.CharacterPropertiesComplex",
1499 "com.sun.star.style.CharacterPropertiesAsian");
1500 return aSeq;
1503 // XTextRangeCompare
1504 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException)
1506 SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1507 SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1509 if( (pR1 == 0) || (pR2 == 0) )
1510 throw lang::IllegalArgumentException();
1512 const ESelection& r1 = pR1->maSelection;
1513 const ESelection& r2 = pR2->maSelection;
1515 if( r1.nStartPara == r2.nStartPara )
1517 if( r1.nStartPos == r2.nStartPos )
1518 return 0;
1519 else
1520 return r1.nStartPos < r2.nStartPos ? 1 : -1;
1522 else
1524 return r1.nStartPara < r2.nStartPara ? 1 : -1;
1528 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException)
1530 SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1531 SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1533 if( (pR1 == 0) || (pR2 == 0) )
1534 throw lang::IllegalArgumentException();
1536 const ESelection& r1 = pR1->maSelection;
1537 const ESelection& r2 = pR2->maSelection;
1539 if( r1.nEndPara == r2.nEndPara )
1541 if( r1.nEndPos == r2.nEndPos )
1542 return 0;
1543 else
1544 return r1.nEndPos < r2.nEndPos ? 1 : -1;
1546 else
1548 return r1.nEndPara < r2.nEndPara ? 1 : -1;
1552 // ====================================================================
1553 // class SvxUnoTextRange
1554 // ====================================================================
1556 uno::Reference< uno::XInterface > SvxUnoTextRange_NewInstance()
1558 SvxUnoText aText;
1559 uno::Reference< text::XTextRange > xRange( new SvxUnoTextRange( aText ) );
1560 #ifndef _MSC_VER
1561 return xRange;
1562 #else
1563 return (uno::Reference< uno::XInterface >)xRange;
1564 #endif
1567 SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase& rParent, sal_Bool bPortion /* = sal_False */ ) throw()
1568 :SvxUnoTextRangeBase( rParent.GetEditSource(), bPortion ? ImplGetSvxTextPortionSvxPropertySet() : rParent.getPropertySet() ),
1569 mbPortion( bPortion )
1571 xParentText = (text::XText*)&rParent;
1574 SvxUnoTextRange::~SvxUnoTextRange() throw()
1578 uno::Any SAL_CALL SvxUnoTextRange::queryAggregation( const uno::Type & rType )
1579 throw(uno::RuntimeException)
1581 QUERYINT( text::XTextRange );
1582 else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertyStates >*)0) )
1583 return uno::makeAny(uno::Reference< beans::XMultiPropertyStates >(this));
1584 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
1585 return uno::makeAny(uno::Reference< beans::XPropertySet >(this));
1586 else QUERYINT( beans::XPropertyState );
1587 else QUERYINT( text::XTextRangeCompare );
1588 else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
1589 return uno::makeAny(uno::Reference< beans::XMultiPropertySet >(this));
1590 else QUERYINT( lang::XServiceInfo );
1591 else QUERYINT( lang::XTypeProvider );
1592 else QUERYINT( lang::XUnoTunnel );
1593 else
1594 return OWeakAggObject::queryAggregation( rType );
1597 uno::Any SAL_CALL SvxUnoTextRange::queryInterface( const uno::Type & rType )
1598 throw(uno::RuntimeException)
1600 return OWeakAggObject::queryInterface(rType);
1603 void SAL_CALL SvxUnoTextRange::acquire()
1604 throw( )
1606 OWeakAggObject::acquire();
1609 void SAL_CALL SvxUnoTextRange::release()
1610 throw( )
1612 OWeakAggObject::release();
1615 // XTypeProvider
1617 namespace
1619 struct theSvxUnoTextRangeTypes :
1620 public rtl::StaticWithInit<uno::Sequence<uno::Type>, theSvxUnoTextRangeTypes>
1622 uno::Sequence<uno::Type> operator () ()
1624 uno::Sequence< uno::Type > aTypeSequence;
1626 aTypeSequence.realloc( 9 ); // !DANGER! keep this updated
1627 uno::Type* pTypes = aTypeSequence.getArray();
1629 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRange >*)0);
1630 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
1631 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0);
1632 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0);
1633 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0);
1634 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
1635 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0);
1636 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
1637 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0);
1639 return aTypeSequence;
1644 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextRange::getTypes()
1645 throw (uno::RuntimeException)
1647 return theSvxUnoTextRangeTypes::get();
1650 namespace
1652 class theSvxUnoTextRangeImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextRangeImplementationId > {};
1655 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextRange::getImplementationId()
1656 throw (uno::RuntimeException)
1658 return theSvxUnoTextRangeImplementationId::get().getSeq();
1661 // XTextRange
1662 uno::Reference< text::XText > SAL_CALL SvxUnoTextRange::getText()
1663 throw(uno::RuntimeException)
1665 return xParentText;
1668 // lang::XServiceInfo
1669 OUString SAL_CALL SvxUnoTextRange::getImplementationName()
1670 throw(uno::RuntimeException)
1672 return OUString("SvxUnoTextRange");
1675 // ====================================================================
1676 // class SvxUnoText
1677 // ====================================================================
1679 SvxUnoTextBase::SvxUnoTextBase() throw()
1680 : SvxUnoTextRangeBase( NULL )
1685 SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet* _pSet ) throw()
1686 : SvxUnoTextRangeBase( _pSet )
1690 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
1691 : SvxUnoTextRangeBase( pSource, _pSet )
1693 xParentText = xParent;
1694 ESelection aSelection;
1695 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1696 SetSelection( aSelection );
1699 SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase& rText ) throw()
1700 : SvxUnoTextRangeBase( rText )
1701 , text::XTextAppend()
1702 , text::XTextCopy()
1703 , container::XEnumerationAccess()
1704 , text::XTextRangeMover()
1705 , lang::XTypeProvider()
1707 xParentText = rText.xParentText;
1710 SvxUnoTextBase::~SvxUnoTextBase() throw()
1714 // XInterface
1715 uno::Any SAL_CALL SvxUnoTextBase::queryAggregation( const uno::Type & rType )
1716 throw(uno::RuntimeException)
1718 QUERYINT( text::XText );
1719 QUERYINT( text::XSimpleText );
1720 if( rType == ::getCppuType((const uno::Reference< text::XTextRange >*)0) )
1721 return uno::makeAny(uno::Reference< text::XTextRange >((text::XText*)(this)));
1722 QUERYINT(container::XEnumerationAccess );
1723 QUERYINT( container::XElementAccess );
1724 QUERYINT( beans::XMultiPropertyStates );
1725 QUERYINT( beans::XPropertySet );
1726 QUERYINT( beans::XMultiPropertySet );
1727 QUERYINT( beans::XPropertyState );
1728 QUERYINT( text::XTextRangeCompare );
1729 QUERYINT( lang::XServiceInfo );
1730 QUERYINT( text::XTextRangeMover );
1731 QUERYINT( text::XTextCopy );
1732 QUERYINT( text::XTextAppend );
1733 QUERYINT( text::XParagraphAppend );
1734 QUERYINT( text::XTextPortionAppend );
1735 QUERYINT( lang::XTypeProvider );
1736 QUERYINT( lang::XUnoTunnel );
1738 return uno::Any();
1741 // XTypeProvider
1743 namespace
1745 struct theSvxUnoTextBaseTypes :
1746 public rtl::StaticWithInit<uno::Sequence<uno::Type>, theSvxUnoTextBaseTypes>
1748 uno::Sequence<uno::Type> operator () ()
1750 uno::Sequence< uno::Type > aTypeSequence;
1752 aTypeSequence.realloc( 15 ); // !DANGER! keep this updated
1753 uno::Type* pTypes = aTypeSequence.getArray();
1755 *pTypes++ = ::getCppuType(( const uno::Reference< text::XText >*)0);
1756 *pTypes++ = ::getCppuType(( const uno::Reference< container::XEnumerationAccess >*)0);
1757 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
1758 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0);
1759 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0);
1760 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0);
1761 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeMover >*)0);
1762 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextAppend >*)0);
1763 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextCopy >*)0);
1764 *pTypes++ = ::getCppuType(( const uno::Reference< text::XParagraphAppend >*)0);
1765 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextPortionAppend >*)0);
1766 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
1767 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0);
1768 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
1769 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0);
1771 return aTypeSequence;
1775 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getStaticTypes() throw()
1777 return theSvxUnoTextBaseTypes::get();
1780 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getTypes()
1781 throw (uno::RuntimeException)
1783 return getStaticTypes();
1786 namespace
1788 class theSvxUnoTextBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextBaseImplementationId > {};
1791 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextBase::getImplementationId()
1792 throw (uno::RuntimeException)
1794 return theSvxUnoTextBaseImplementationId::get().getSeq();
1797 uno::Reference< text::XTextCursor > SvxUnoTextBase::createTextCursorBySelection( const ESelection& rSel )
1799 SvxUnoTextCursor* pCursor = new SvxUnoTextCursor( *this );
1800 uno::Reference< text::XTextCursor > xCursor( pCursor );
1801 pCursor->SetSelection( rSel );
1802 return xCursor;
1805 // XSimpleText
1807 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursor()
1808 throw(uno::RuntimeException)
1810 SolarMutexGuard aGuard;
1811 return new SvxUnoTextCursor( *this );
1814 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursorByRange( const uno::Reference< text::XTextRange >& aTextPosition )
1815 throw(uno::RuntimeException)
1817 SolarMutexGuard aGuard;
1819 uno::Reference< text::XTextCursor > xCursor;
1821 if( aTextPosition.is() )
1823 SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
1824 if(pRange)
1825 xCursor = createTextCursorBySelection( pRange->GetSelection() );
1828 return xCursor;
1831 void SAL_CALL SvxUnoTextBase::insertString( const uno::Reference< text::XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb )
1832 throw(uno::RuntimeException)
1834 SolarMutexGuard aGuard;
1836 if( !xRange.is() )
1837 return;
1839 ESelection aSelection;
1840 if (GetEditSource())
1842 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1843 SetSelection( aSelection );
1846 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1847 if(pRange)
1849 // setString on SvxUnoTextRangeBase instead of itself QuickInsertText
1850 // and UpdateData, so that the selection will be adjusted to
1851 // SvxUnoTextRangeBase. Actually all cursor objects of this Text must
1852 // to be statement to be adapted!
1854 if (!bAbsorb) // do not replace -> append on tail
1855 pRange->CollapseToEnd();
1857 pRange->setString( aString );
1859 pRange->CollapseToEnd();
1863 void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text::XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1864 throw(lang::IllegalArgumentException, uno::RuntimeException)
1866 SolarMutexGuard aGuard;
1868 SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1870 if( pForwarder )
1872 ESelection aSelection;
1873 ::GetSelection( aSelection, pForwarder );
1874 SetSelection( aSelection );
1876 switch( nControlCharacter )
1878 case text::ControlCharacter::PARAGRAPH_BREAK:
1880 const OUString aText( (sal_Unicode)13 ); // '\r' does not work on Mac
1881 insertString( xRange, aText, bAbsorb );
1883 return;
1885 case text::ControlCharacter::LINE_BREAK:
1887 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1888 if(pRange)
1890 ESelection aRange = pRange->GetSelection();
1892 if( bAbsorb )
1894 const String aEmpty;
1895 pForwarder->QuickInsertText( aEmpty, aRange );
1897 aRange.nEndPos = aRange.nStartPos;
1898 aRange.nEndPara = aRange.nStartPara;
1900 else
1902 aRange.nStartPos = aRange.nEndPos;
1903 aRange.nStartPara = aRange.nStartPara;
1906 pForwarder->QuickInsertLineBreak( aRange );
1907 GetEditSource()->UpdateData();
1909 aRange.nEndPos += 1;
1910 if( !bAbsorb )
1911 aRange.nStartPos += 1;
1913 pRange->SetSelection( aRange );
1915 return;
1917 case text::ControlCharacter::APPEND_PARAGRAPH:
1919 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1920 if(pRange)
1922 ESelection aRange = pRange->GetSelection();
1923 // ESelection aOldSelection = aRange;
1925 aRange.nStartPos = pForwarder->GetTextLen( aRange.nStartPara );
1927 aRange.nEndPara = aRange.nStartPara;
1928 aRange.nEndPos = aRange.nStartPos;
1930 pRange->SetSelection( aRange );
1931 const OUString aText( (sal_Unicode)13 ); // '\r' geht auf'm Mac nicht
1932 pRange->setString( aText );
1934 aRange.nStartPos = 0;
1935 aRange.nStartPara += 1;
1936 aRange.nEndPos = 0;
1937 aRange.nEndPara += 1;
1939 pRange->SetSelection( aRange );
1941 return;
1944 default:
1945 throw lang::IllegalArgumentException();
1950 // XText
1951 void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTextRange >& xRange, const uno::Reference< text::XTextContent >& xContent, sal_Bool bAbsorb )
1952 throw(lang::IllegalArgumentException, uno::RuntimeException)
1954 SolarMutexGuard aGuard;
1956 SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1957 if (!pForwarder)
1958 return;
1960 uno::Reference<beans::XPropertySet> xPropSet(xRange, uno::UNO_QUERY);
1961 if (!xPropSet.is())
1962 throw lang::IllegalArgumentException();
1964 uno::Any aAny = xPropSet->getPropertyValue(UNO_TR_PROP_SELECTION);
1965 text::TextRangeSelection aSel = aAny.get<text::TextRangeSelection>();
1966 if (!bAbsorb)
1967 aSel.Start = aSel.End;
1969 boost::scoped_ptr<SvxFieldData> pFieldData(SvxFieldData::Create(xContent));
1970 if (!pFieldData)
1971 throw lang::IllegalArgumentException();
1973 SvxFieldItem aField( *pFieldData, EE_FEATURE_FIELD );
1974 pForwarder->QuickInsertField(aField, toESelection(aSel));
1975 GetEditSource()->UpdateData();
1977 uno::Reference<beans::XPropertySet> xPropSetContent(xContent, uno::UNO_QUERY);
1978 if (!xContent.is())
1979 throw lang::IllegalArgumentException();
1981 xPropSetContent->setPropertyValue(UNO_TC_PROP_ANCHOR, uno::makeAny(xRange));
1983 aSel.End.PositionInParagraph += 1;
1984 aSel.Start.PositionInParagraph = aSel.End.PositionInParagraph;
1985 xPropSet->setPropertyValue(UNO_TR_PROP_SELECTION, uno::makeAny(aSel));
1988 void SAL_CALL SvxUnoTextBase::removeTextContent( const uno::Reference< text::XTextContent >& ) throw(container::NoSuchElementException, uno::RuntimeException)
1992 // XTextRange
1994 uno::Reference< text::XText > SAL_CALL SvxUnoTextBase::getText()
1995 throw(uno::RuntimeException)
1997 SolarMutexGuard aGuard;
1999 if (GetEditSource())
2001 ESelection aSelection;
2002 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
2003 ((SvxUnoTextBase*)this)->SetSelection( aSelection );
2006 return (text::XText*)this;
2009 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getStart()
2010 throw(uno::RuntimeException)
2012 return SvxUnoTextRangeBase::getStart();
2015 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getEnd()
2016 throw(uno::RuntimeException)
2018 return SvxUnoTextRangeBase::getEnd();
2021 OUString SAL_CALL SvxUnoTextBase::getString() throw( uno::RuntimeException )
2023 return SvxUnoTextRangeBase::getString();
2026 void SAL_CALL SvxUnoTextBase::setString( const OUString& aString ) throw(uno::RuntimeException)
2028 SvxUnoTextRangeBase::setString(aString);
2032 // XEnumerationAccess
2033 uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextBase::createEnumeration()
2034 throw(uno::RuntimeException)
2036 SolarMutexGuard aGuard;
2038 ESelection aSelection;
2039 ::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
2040 SetSelection( aSelection );
2042 uno::Reference< container::XEnumeration > xEnum( (container::XEnumeration*) new SvxUnoTextContentEnumeration( *this ) );
2043 return xEnum;
2046 // XElementAccess ( container::XEnumerationAccess )
2047 uno::Type SAL_CALL SvxUnoTextBase::getElementType( ) throw(uno::RuntimeException)
2049 return ::getCppuType((const uno::Reference< text::XTextRange >*)0 );
2052 sal_Bool SAL_CALL SvxUnoTextBase::hasElements( ) throw(uno::RuntimeException)
2054 SolarMutexGuard aGuard;
2056 if(GetEditSource())
2058 SvxTextForwarder* pForwarder = GetEditSource()->GetTextForwarder();
2059 if(pForwarder)
2060 return pForwarder->GetParagraphCount() != 0;
2063 return sal_False;
2066 // text::XTextRangeMover
2067 void SAL_CALL SvxUnoTextBase::moveTextRange( const uno::Reference< text::XTextRange >&, sal_Int16 )
2068 throw(uno::RuntimeException)
2072 void SvxPropertyValuesToItemSet(
2073 SfxItemSet &rItemSet,
2074 const uno::Sequence< beans::PropertyValue > rPropertyVaules,
2075 const SfxItemPropertySet *pPropSet,
2076 SvxTextForwarder *pForwarder /*needed for WID_NUMLEVEL*/,
2077 sal_Int32 nPara /*needed for WID_NUMLEVEL*/)
2078 throw(lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2080 sal_Int32 nProps = rPropertyVaules.getLength();
2081 const beans::PropertyValue *pProps = rPropertyVaules.getConstArray();
2082 for (sal_Int32 i = 0; i < nProps; ++i)
2084 const SfxItemPropertySimpleEntry *pEntry = pPropSet->getPropertyMap().getByName( pProps[i].Name );
2085 if (pEntry)
2087 // Note: there is no need to take special care of the properties
2088 // TextField (EE_FEATURE_FIELD) and
2089 // TextPortionType (WID_PORTIONTYPE)
2090 // since they are read-only and thus are already taken care of below.
2092 if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2093 // should be PropertyVetoException which is not yet defined for the new import API's functions
2094 throw uno::RuntimeException( OUString( "Property is read-only: " ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2095 //throw PropertyVetoException ( OUString( "Property is read-only: " ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2097 if (pEntry->nWID == WID_FONTDESC)
2099 awt::FontDescriptor aDesc;
2100 if (pProps[i].Value >>= aDesc)
2101 SvxUnoFontDescriptor::FillItemSet( aDesc, rItemSet );
2103 else if (pEntry->nWID == WID_NUMLEVEL)
2105 if (pForwarder)
2107 sal_Int16 nLevel = -1;
2108 pProps[i].Value >>= nLevel;
2110 // #101004# Call interface method instead of unsafe cast
2111 if (!pForwarder->SetDepth( nPara, nLevel ))
2112 throw lang::IllegalArgumentException();
2115 else if (pEntry->nWID == WID_NUMBERINGSTARTVALUE )
2117 if( pForwarder )
2119 sal_Int16 nStartValue = -1;
2120 if( !(pProps[i].Value >>= nStartValue) )
2121 throw lang::IllegalArgumentException();
2123 pForwarder->SetNumberingStartValue( nPara, nStartValue );
2126 else if (pEntry->nWID == WID_PARAISNUMBERINGRESTART )
2128 if( pForwarder )
2130 sal_Bool bParaIsNumberingRestart = sal_False;
2131 if( !(pProps[i].Value >>= bParaIsNumberingRestart) )
2132 throw lang::IllegalArgumentException();
2134 pForwarder->SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart );
2137 else
2138 pPropSet->setPropertyValue( pProps[i].Name, pProps[i].Value, rItemSet );
2140 else
2141 throw beans::UnknownPropertyException(OUString( "Unknown property: " ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2145 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraphInsert(
2146 const uno::Sequence< beans::PropertyValue >& /*rCharAndParaProps*/,
2147 const uno::Reference< text::XTextRange >& /*rTextRange*/ )
2148 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2150 uno::Reference< text::XTextRange > xRet;
2151 return xRet;
2154 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraph(
2155 const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2156 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2158 SolarMutexGuard aGuard;
2160 uno::Reference< text::XTextRange > xRet;
2161 SvxEditSource *pEditSource = GetEditSource();
2162 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2163 if (pTextForwarder)
2165 sal_Int32 nParaCount = pTextForwarder->GetParagraphCount();
2166 DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2167 pTextForwarder->AppendParagraph();
2169 // set properties for the previously last paragraph
2170 sal_Int32 nPara = nParaCount - 1;
2171 ESelection aSel( nPara, 0, nPara, 0 );
2172 SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2173 SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2174 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder, nPara );
2175 pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2176 pEditSource->UpdateData();
2177 SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2178 xRet = pRange;
2179 pRange->SetSelection( aSel );
2181 return xRet;
2184 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::insertTextPortion(
2185 const OUString& /*rText*/,
2186 const uno::Sequence< beans::PropertyValue >& /*rCharAndParaProps*/,
2187 const uno::Reference< text::XTextRange>& /*rTextRange*/ )
2188 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2190 uno::Reference< text::XTextRange > xRet;
2191 return xRet;
2194 // com::sun::star::text::XTextPortionAppend (new import API)
2195 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendTextPortion(
2196 const OUString& rText,
2197 const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2198 throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2200 SolarMutexGuard aGuard;
2202 SvxEditSource *pEditSource = GetEditSource();
2203 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2204 uno::Reference< text::XTextRange > xRet;
2205 if (pTextForwarder)
2207 sal_Int32 nParaCount = pTextForwarder->GetParagraphCount();
2208 DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2209 sal_Int32 nPara = nParaCount - 1;
2210 SfxItemSet aSet( pTextForwarder->GetParaAttribs( nPara ) );
2211 xub_StrLen nStart = pTextForwarder->AppendTextPortion( nPara, rText, aSet );
2212 pEditSource->UpdateData();
2213 xub_StrLen nEnd = pTextForwarder->GetTextLen( nPara );
2215 // set properties for the new text portion
2216 ESelection aSel( nPara, nStart, nPara, nEnd );
2217 pTextForwarder->RemoveAttribs( aSel, sal_False, 0 );
2218 pEditSource->UpdateData();
2220 SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2221 SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2222 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder, nPara );
2223 pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2224 SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2225 xRet = pRange;
2226 pRange->SetSelection( aSel );
2227 const beans::PropertyValue* pProps = rCharAndParaProps.getConstArray();
2228 for( sal_Int32 nProp = 0; nProp < rCharAndParaProps.getLength(); ++nProp )
2229 pRange->setPropertyValue( pProps[nProp].Name, pProps[nProp].Value );
2231 return xRet;
2234 void SvxUnoTextBase::copyText(
2235 const uno::Reference< text::XTextCopy >& xSource ) throw ( uno::RuntimeException )
2237 SolarMutexGuard aGuard;
2238 uno::Reference< lang::XUnoTunnel > xUT( xSource, uno::UNO_QUERY );
2239 SvxEditSource *pEditSource = GetEditSource();
2240 SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2241 if( !pTextForwarder )
2242 return;
2243 if( xUT.is() )
2245 SvxUnoTextBase* pSource = reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(
2246 xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2247 SvxEditSource *pSourceEditSource = pSource->GetEditSource();
2248 SvxTextForwarder *pSourceTextForwarder = pSourceEditSource ? pSourceEditSource->GetTextForwarder() : 0;
2249 if( pSourceTextForwarder )
2251 pTextForwarder->CopyText( *pSourceTextForwarder );
2252 pEditSource->UpdateData();
2255 else
2257 uno::Reference< text::XText > xSourceText( xSource, uno::UNO_QUERY );
2258 if( xSourceText.is() )
2260 setString( xSourceText->getString() );
2265 // lang::XServiceInfo
2266 OUString SAL_CALL SvxUnoTextBase::getImplementationName()
2267 throw(uno::RuntimeException)
2269 return OUString("SvxUnoTextBase");
2272 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames( )
2273 throw(uno::RuntimeException)
2275 return getSupportedServiceNames_Static();
2278 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames_Static( )
2279 SAL_THROW(())
2281 uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() );
2282 comphelper::ServiceInfoHelper::addToSequence( aSeq, 1, "com.sun.star.text.Text" );
2283 return aSeq;
2286 namespace
2288 class theSvxUnoTextBaseUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextBaseUnoTunnelId > {};
2291 const uno::Sequence< sal_Int8 > & SvxUnoTextBase::getUnoTunnelId() throw()
2293 return theSvxUnoTextBaseUnoTunnelId::get().getSeq();
2296 SvxUnoTextBase* SvxUnoTextBase::getImplementation( const uno::Reference< uno::XInterface >& xInt )
2298 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2299 if( xUT.is() )
2300 return reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2301 else
2302 return NULL;
2305 sal_Int64 SAL_CALL SvxUnoTextBase::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \
2307 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2308 rId.getConstArray(), 16 ) )
2310 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2312 else
2314 return SvxUnoTextRangeBase::getSomething( rId );
2318 // --------------------------------------------------------------------
2320 SvxUnoText::SvxUnoText( ) throw()
2324 SvxUnoText::SvxUnoText( const SvxItemPropertySet* _pSet ) throw()
2325 : SvxUnoTextBase( _pSet )
2329 SvxUnoText::SvxUnoText( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
2330 : SvxUnoTextBase( pSource, _pSet, xParent )
2334 SvxUnoText::SvxUnoText( const SvxUnoText& rText ) throw()
2335 : SvxUnoTextBase( rText )
2336 , cppu::OWeakAggObject()
2340 SvxUnoText::~SvxUnoText() throw()
2344 uno::Sequence< uno::Type > SAL_CALL getStaticTypes() throw()
2346 return SvxUnoTextBase::getStaticTypes();
2349 // uno::XInterface
2350 uno::Any SAL_CALL SvxUnoText::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException )
2352 uno::Any aAny( SvxUnoTextBase::queryAggregation( rType ) );
2353 if( !aAny.hasValue() )
2354 aAny = OWeakAggObject::queryAggregation( rType );
2356 return aAny;
2359 uno::Any SAL_CALL SvxUnoText::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException )
2361 return OWeakAggObject::queryInterface( rType );
2364 void SAL_CALL SvxUnoText::acquire() throw( )
2366 OWeakAggObject::acquire();
2369 void SAL_CALL SvxUnoText::release() throw( )
2371 OWeakAggObject::release();
2374 // lang::XTypeProvider
2375 uno::Sequence< uno::Type > SAL_CALL SvxUnoText::getTypes( ) throw( uno::RuntimeException )
2377 return SvxUnoTextBase::getTypes();
2380 namespace
2382 class theSvxUnoTextImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextImplementationId > {};
2385 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoText::getImplementationId( ) throw( uno::RuntimeException )
2387 return theSvxUnoTextImplementationId::get().getSeq();
2390 namespace
2392 class theSvxUnoTextUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextUnoTunnelId > {};
2395 const uno::Sequence< sal_Int8 > & SvxUnoText::getUnoTunnelId() throw()
2397 return theSvxUnoTextUnoTunnelId::get().getSeq();
2400 sal_Int64 SAL_CALL SvxUnoText::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \
2402 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2403 rId.getConstArray(), 16 ) )
2405 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2407 else
2409 return SvxUnoTextBase::getSomething( rId );
2414 // --------------------------------------------------------------------
2416 SvxDummyTextSource::~SvxDummyTextSource()
2420 SvxEditSource* SvxDummyTextSource::Clone() const
2422 return new SvxDummyTextSource();
2425 SvxTextForwarder* SvxDummyTextSource::GetTextForwarder()
2427 return this;
2430 void SvxDummyTextSource::UpdateData()
2434 sal_Int32 SvxDummyTextSource::GetParagraphCount() const
2436 return 0;
2439 sal_uInt16 SvxDummyTextSource::GetTextLen( sal_Int32 ) const
2441 return 0;
2444 String SvxDummyTextSource::GetText( const ESelection& ) const
2446 return String();
2449 SfxItemSet SvxDummyTextSource::GetAttribs( const ESelection&, sal_Bool ) const
2451 // Very dangerous: The former implementation used a SfxItemPool created on the
2452 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2453 // a deleted Pool by design.
2454 return SfxItemSet(EditEngine::GetGlobalItemPool());
2457 SfxItemSet SvxDummyTextSource::GetParaAttribs( sal_Int32 ) const
2459 return GetAttribs(ESelection());
2462 void SvxDummyTextSource::SetParaAttribs( sal_Int32, const SfxItemSet& )
2466 void SvxDummyTextSource::RemoveAttribs( const ESelection& , sal_Bool , sal_uInt16 )
2470 void SvxDummyTextSource::GetPortions( sal_Int32, std::vector<sal_uInt16>& ) const
2474 sal_uInt16 SvxDummyTextSource::GetItemState( const ESelection&, sal_uInt16 ) const
2476 return 0;
2479 sal_uInt16 SvxDummyTextSource::GetItemState( sal_Int32, sal_uInt16 ) const
2481 return 0;
2484 SfxItemPool* SvxDummyTextSource::GetPool() const
2486 return NULL;
2489 void SvxDummyTextSource::QuickInsertText( const String&, const ESelection& )
2493 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem&, const ESelection& )
2497 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet&, const ESelection& )
2501 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection& )
2505 OUString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_uInt16, Color*&, Color*& )
2507 return OUString();
2510 void SvxDummyTextSource::FieldClicked( const SvxFieldItem&, sal_Int32, xub_StrLen )
2514 sal_Bool SvxDummyTextSource::IsValid() const
2516 return sal_False;
2519 void SvxDummyTextSource::SetNotifyHdl( const Link& )
2523 LanguageType SvxDummyTextSource::GetLanguage( sal_Int32, sal_uInt16 ) const
2525 return LANGUAGE_DONTKNOW;
2528 sal_uInt16 SvxDummyTextSource::GetFieldCount( sal_Int32 ) const
2530 return 0;
2533 EFieldInfo SvxDummyTextSource::GetFieldInfo( sal_Int32, sal_uInt16 ) const
2535 return EFieldInfo();
2538 EBulletInfo SvxDummyTextSource::GetBulletInfo( sal_Int32 ) const
2540 return EBulletInfo();
2543 Rectangle SvxDummyTextSource::GetCharBounds( sal_Int32, sal_uInt16 ) const
2545 return Rectangle();
2548 Rectangle SvxDummyTextSource::GetParaBounds( sal_Int32 ) const
2550 return Rectangle();
2553 MapMode SvxDummyTextSource::GetMapMode() const
2555 return MapMode();
2558 OutputDevice* SvxDummyTextSource::GetRefDevice() const
2560 return NULL;
2563 sal_Bool SvxDummyTextSource::GetIndexAtPoint( const Point&, sal_Int32&, sal_uInt16& ) const
2565 return sal_False;
2568 sal_Bool SvxDummyTextSource::GetWordIndices( sal_Int32, sal_uInt16, sal_uInt16&, sal_uInt16& ) const
2570 return sal_False;
2573 sal_Bool SvxDummyTextSource::GetAttributeRun( sal_uInt16&, sal_uInt16&, sal_Int32, sal_uInt16 ) const
2575 return sal_False;
2578 sal_uInt16 SvxDummyTextSource::GetLineCount( sal_Int32 ) const
2580 return 0;
2583 sal_uInt16 SvxDummyTextSource::GetLineLen( sal_Int32, sal_uInt16 ) const
2585 return 0;
2588 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_Int32 /*nParagraph*/, sal_uInt16 /*nLine*/ ) const
2590 rStart = rEnd = 0;
2593 sal_uInt16 SvxDummyTextSource::GetLineNumberAtIndex( sal_Int32 /*nPara*/, sal_uInt16 /*nIndex*/ ) const
2595 return 0;
2598 sal_Bool SvxDummyTextSource::QuickFormatDoc( sal_Bool )
2600 return sal_False;
2603 sal_Int16 SvxDummyTextSource::GetDepth( sal_Int32 ) const
2605 return -1;
2608 sal_Bool SvxDummyTextSource::SetDepth( sal_Int32, sal_Int16 nNewDepth )
2610 return nNewDepth == 0 ? sal_True : sal_False;
2613 sal_Bool SvxDummyTextSource::Delete( const ESelection& )
2615 return sal_False;
2618 sal_Bool SvxDummyTextSource::InsertText( const String&, const ESelection& )
2620 return sal_False;
2623 const SfxItemSet * SvxDummyTextSource::GetEmptyItemSetPtr()
2625 return 0;
2628 void SvxDummyTextSource::AppendParagraph()
2632 xub_StrLen SvxDummyTextSource::AppendTextPortion( sal_Int32, const String &, const SfxItemSet & )
2634 return 0;
2637 void SvxDummyTextSource::CopyText(const SvxTextForwarder& )
2641 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */