1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <vcl/svapp.hxx>
30 #include <com/sun/star/style/LineSpacing.hpp>
31 #include <com/sun/star/text/ControlCharacter.hpp>
32 #include <com/sun/star/text/XTextField.hpp>
33 #include <com/sun/star/text/TextRangeSelection.hpp>
35 #include <osl/mutex.hxx>
36 #include <svl/itemset.hxx>
37 #include <svl/itempool.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/eitem.hxx>
40 #include <rtl/instance.hxx>
42 #include <editeng/fontitem.hxx>
43 #include <editeng/tstpitem.hxx>
44 #include <editeng/unoprnms.hxx>
45 #include <editeng/unotext.hxx>
46 #include <editeng/unoedsrc.hxx>
47 #include <editeng/unonrule.hxx>
48 #include <editeng/unofdesc.hxx>
49 #include <editeng/unofield.hxx>
50 #include <editeng/flditem.hxx>
51 #include <editeng/numitem.hxx>
52 #include <editeng/editeng.hxx>
53 #include <editeng/outliner.hxx>
54 #include <editeng/unoipset.hxx>
55 #include <comphelper/serviceinfohelper.hxx>
56 #include <comphelper/servicehelper.hxx>
58 #include "editeng/unonames.hxx"
60 #include <boost/scoped_ptr.hpp>
62 using namespace ::rtl
;
63 using namespace ::cppu
;
64 using namespace ::com::sun::star
;
68 ESelection
toESelection(const text::TextRangeSelection
& rSel
)
71 aESel
.nStartPara
= rSel
.Start
.Paragraph
;
72 aESel
.nStartPos
= rSel
.Start
.PositionInParagraph
;
73 aESel
.nEndPara
= rSel
.End
.Paragraph
;
74 aESel
.nEndPos
= rSel
.End
.PositionInParagraph
;
80 const SvxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet()
82 static SvxItemPropertySet
aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() );
83 return &aTextCursorSvxPropertySet
;
86 const SfxItemPropertyMapEntry
* ImplGetSvxTextPortionPropertyMap()
88 // Propertymap for an Outliner Text
89 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap
[] =
91 SVX_UNOEDIT_CHAR_PROPERTIES
,
92 SVX_UNOEDIT_FONT_PROPERTIES
,
93 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
94 SVX_UNOEDIT_PARA_PROPERTIES
,
95 {MAP_CHAR_LEN("TextField"), EE_FEATURE_FIELD
, &::getCppuType((const uno::Reference
< text::XTextField
>*)0), beans::PropertyAttribute::READONLY
, 0 },
96 {MAP_CHAR_LEN("TextPortionType"), WID_PORTIONTYPE
, &::getCppuType((const ::rtl::OUString
*)0), beans::PropertyAttribute::READONLY
, 0 },
97 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS
, &::getCppuType((const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>*)0) , 0, 0},
98 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS
, &::getCppuType((const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>*)0) , 0, 0},
101 return aSvxTextPortionPropertyMap
;
103 const SvxItemPropertySet
* ImplGetSvxTextPortionSvxPropertySet()
105 static SvxItemPropertySet
aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() );
106 return &aSvxTextPortionPropertySet
;
109 const SfxItemPropertySet
* ImplGetSvxTextPortionSfxPropertySet()
111 static SfxItemPropertySet
aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() );
112 return &aSvxTextPortionSfxPropertySet
;
115 const SfxItemPropertyMapEntry
* ImplGetSvxUnoOutlinerTextCursorPropertyMap()
117 // Propertymap for an Outliner Text
118 static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap
[] =
120 SVX_UNOEDIT_CHAR_PROPERTIES
,
121 SVX_UNOEDIT_FONT_PROPERTIES
,
122 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
123 SVX_UNOEDIT_PARA_PROPERTIES
,
124 {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS
, &::getCppuType((const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>*)0) , 0, 0},
125 {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS
, &::getCppuType((const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>*)0) , 0, 0},
129 return aSvxUnoOutlinerTextCursorPropertyMap
;
131 const SfxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
133 static SfxItemPropertySet
aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
134 return &aTextCursorSfxPropertySet
;
137 // ====================================================================
138 // helper for Item/Property conversion
139 // ====================================================================
141 void GetSelection( struct ESelection
& rSel
, SvxTextForwarder
* pForwarder
) throw()
143 DBG_ASSERT( pForwarder
, "I need a valid SvxTextForwarder!" );
146 sal_Int16 nParaCount
= pForwarder
->GetParagraphCount();
150 rSel
= ESelection( 0,0, nParaCount
, pForwarder
->GetTextLen( nParaCount
));
154 void CheckSelection( struct ESelection
& rSel
, SvxTextForwarder
* pForwarder
) throw()
156 DBG_ASSERT( pForwarder
, "I need a valid SvxTextForwarder!" );
159 if( rSel
.nStartPara
== 0xffff )
161 ::GetSelection( rSel
, pForwarder
);
165 ESelection aMaxSelection
;
166 GetSelection( aMaxSelection
, pForwarder
);
168 // check start position
169 if( rSel
.nStartPara
< aMaxSelection
.nStartPara
)
171 rSel
.nStartPara
= aMaxSelection
.nStartPara
;
172 rSel
.nStartPos
= aMaxSelection
.nStartPos
;
174 else if( rSel
.nStartPara
> aMaxSelection
.nEndPara
)
176 rSel
.nStartPara
= aMaxSelection
.nEndPara
;
177 rSel
.nStartPos
= aMaxSelection
.nEndPos
;
179 else if( rSel
.nStartPos
> pForwarder
->GetTextLen( rSel
.nStartPara
) )
181 rSel
.nStartPos
= pForwarder
->GetTextLen( rSel
.nStartPara
);
184 // check end position
185 if( rSel
.nEndPara
< aMaxSelection
.nStartPara
)
187 rSel
.nEndPara
= aMaxSelection
.nStartPara
;
188 rSel
.nEndPos
= aMaxSelection
.nStartPos
;
190 else if( rSel
.nEndPara
> aMaxSelection
.nEndPara
)
192 rSel
.nEndPara
= aMaxSelection
.nEndPara
;
193 rSel
.nEndPos
= aMaxSelection
.nEndPos
;
195 else if( rSel
.nEndPos
> pForwarder
->GetTextLen( rSel
.nEndPara
) )
197 rSel
.nEndPos
= pForwarder
->GetTextLen( rSel
.nEndPara
);
203 void CheckSelection( struct ESelection
& rSel
, SvxEditSource
*pEdit
) throw()
207 CheckSelection( rSel
, pEdit
->GetTextForwarder() );
210 // ====================================================================
211 // class SvxUnoTextRangeBase
212 // ====================================================================
214 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase
);
216 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxItemPropertySet
* _pSet
) throw()
217 : mpEditSource(NULL
) , mpPropSet(_pSet
)
221 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
) throw()
224 SolarMutexGuard aGuard
;
226 DBG_ASSERT(pSource
,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
228 mpEditSource
= pSource
->Clone();
229 if (mpEditSource
!= NULL
)
231 ESelection aSelection
;
232 ::GetSelection( aSelection
, mpEditSource
->GetTextForwarder() );
233 SetSelection( aSelection
);
235 mpEditSource
->addRange( this );
239 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxUnoTextRangeBase
& rRange
) throw()
240 : SvxUnoTextRangeBase_Base()
241 , osl::DebugBase
<SvxUnoTextRangeBase
>()
242 , mpPropSet(rRange
.getPropertySet())
244 SolarMutexGuard aGuard
;
246 mpEditSource
= rRange
.mpEditSource
? rRange
.mpEditSource
->Clone() : NULL
;
248 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
251 maSelection
= rRange
.maSelection
;
252 CheckSelection( maSelection
, pForwarder
);
256 mpEditSource
->addRange( this );
259 SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw()
262 mpEditSource
->removeRange( this );
267 void SvxUnoTextRangeBase::SetEditSource( SvxEditSource
* pSource
) throw()
269 DBG_ASSERT(pSource
,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
270 DBG_ASSERT(mpEditSource
==NULL
,"SvxUnoTextRangeBase::SetEditSource called while SvxEditSource already set" );
272 mpEditSource
= pSource
;
274 maSelection
.nStartPara
= 0xffff;
277 mpEditSource
->addRange( this );
280 /** puts a field item with a copy of the given FieldData into the itemset
281 corresponding with this range */
282 void SvxUnoTextRangeBase::attachField( const SvxFieldData
* pData
) throw()
284 SolarMutexGuard aGuard
;
288 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
291 SvxFieldItem
aField( *pData
, EE_FEATURE_FIELD
);
292 pForwarder
->QuickInsertField( aField
, maSelection
);
297 void SvxUnoTextRangeBase::SetSelection( const ESelection
& rSelection
) throw()
299 SolarMutexGuard aGuard
;
301 maSelection
= rSelection
;
302 CheckSelection( maSelection
, mpEditSource
);
305 // Interface XTextRange ( XText )
307 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getStart(void)
308 throw( uno::RuntimeException
)
310 SolarMutexGuard aGuard
;
312 uno::Reference
< text::XTextRange
> xRange
;
314 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
317 CheckSelection( maSelection
, pForwarder
);
319 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( getText() );
322 throw uno::RuntimeException();
324 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *pText
);
327 ESelection aNewSel
= maSelection
;
328 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
329 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
330 pRange
->SetSelection( aNewSel
);
336 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getEnd(void)
337 throw( uno::RuntimeException
)
339 SolarMutexGuard aGuard
;
341 uno::Reference
< text::XTextRange
> xRet
;
343 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
346 CheckSelection( maSelection
, pForwarder
);
348 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( getText() );
351 throw uno::RuntimeException();
353 SvxUnoTextRange
* pNew
= new SvxUnoTextRange( *pText
);
356 ESelection aNewSel
= maSelection
;
357 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
358 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
359 pNew
->SetSelection( aNewSel
);
364 OUString SAL_CALL
SvxUnoTextRangeBase::getString(void)
365 throw( uno::RuntimeException
)
367 SolarMutexGuard aGuard
;
369 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
372 CheckSelection( maSelection
, pForwarder
);
374 return pForwarder
->GetText( maSelection
);
378 const OUString aEmpty
;
383 void SAL_CALL
SvxUnoTextRangeBase::setString(const OUString
& aString
)
384 throw( uno::RuntimeException
)
386 SolarMutexGuard aGuard
;
388 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
391 CheckSelection( maSelection
, pForwarder
);
393 String
aConverted(convertLineEnd(aString
, LINEEND_LF
)); // Simply count the number of line endings
395 pForwarder
->QuickInsertText( aConverted
, maSelection
);
396 mpEditSource
->UpdateData();
399 //! It would be easier if the EditEngine would return the selection
400 //! on QuickInsertText...
403 sal_uInt16 nLen
= aConverted
.Len();
405 GoRight( nLen
, sal_True
);
409 // Interface beans::XPropertySet
410 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SvxUnoTextRangeBase::getPropertySetInfo(void)
411 throw( uno::RuntimeException
)
413 return mpPropSet
->getPropertySetInfo();
416 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValue(const OUString
& PropertyName
, const uno::Any
& aValue
)
417 throw( beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
419 if (PropertyName
== UNO_TR_PROP_SELECTION
)
421 text::TextRangeSelection aSel
= aValue
.get
<text::TextRangeSelection
>();
422 SetSelection(toESelection(aSel
));
427 _setPropertyValue( PropertyName
, aValue
, -1 );
430 void SAL_CALL
SvxUnoTextRangeBase::_setPropertyValue( const OUString
& PropertyName
, const uno::Any
& aValue
, sal_Int32 nPara
)
431 throw( beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
433 SolarMutexGuard aGuard
;
435 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
438 CheckSelection( maSelection
, pForwarder
);
440 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
443 ESelection
aSel( GetSelection() );
444 sal_Bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
446 if( nPara
== -1 && !bParaAttrib
)
448 SfxItemSet
aOldSet( pForwarder
->GetAttribs( aSel
) );
449 // we have a selection and no para attribute
450 SfxItemSet
aNewSet( *aOldSet
.GetPool(), aOldSet
.GetRanges() );
452 setPropertyValue( pMap
, aValue
, maSelection
, aOldSet
, aNewSet
);
455 pForwarder
->QuickSetAttribs( aNewSet
, GetSelection() );
463 nPara
= aSel
.nStartPara
;
464 nEndPara
= aSel
.nEndPara
;
468 // only one paragraph
472 while( nPara
<= nEndPara
)
474 // we have a paragraph
475 SfxItemSet
aSet( pForwarder
->GetParaAttribs( (sal_uInt16
)nPara
) );
476 setPropertyValue( pMap
, aValue
, maSelection
, aSet
, aSet
);
477 pForwarder
->SetParaAttribs( (sal_uInt16
)nPara
, aSet
);
482 GetEditSource()->UpdateData();
487 throw beans::UnknownPropertyException();
490 void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& rValue
, const ESelection
& rSelection
, const SfxItemSet
& rOldSet
, SfxItemSet
& rNewSet
) throw( beans::UnknownPropertyException
, lang::IllegalArgumentException
)
492 if(!SetPropertyValueHelper( rOldSet
, pMap
, rValue
, rNewSet
, &rSelection
, GetEditSource() ))
494 // For parts of composite items with multiple properties (eg background)
495 // must be taken from the document before the old item.
496 rNewSet
.Put(rOldSet
.Get(pMap
->nWID
)); // Old Item in new Set
497 mpPropSet
->setPropertyValue(pMap
, rValue
, rNewSet
, false );
501 sal_Bool
SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemSet
&, const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& aValue
, SfxItemSet
& rNewSet
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL*/ ) throw( uno::RuntimeException
)
507 awt::FontDescriptor aDesc
;
510 SvxUnoFontDescriptor::FillItemSet( aDesc
, rNewSet
);
516 case EE_PARA_NUMBULLET
:
518 uno::Reference
< container::XIndexReplace
> xRule
;
519 if( !aValue
.hasValue() || ((aValue
>>= xRule
) && !xRule
.is()) )
527 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
528 if(pForwarder
&& pSelection
)
530 sal_Int16 nLevel
= sal_Int16();
531 if( aValue
>>= nLevel
)
533 // #101004# Call interface method instead of unsafe cast
534 if(! pForwarder
->SetDepth( pSelection
->nStartPara
, nLevel
) )
535 throw lang::IllegalArgumentException();
542 case WID_NUMBERINGSTARTVALUE
:
544 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
545 if(pForwarder
&& pSelection
)
547 sal_Int16 nStartValue
= -1;
548 if( aValue
>>= nStartValue
)
550 pForwarder
->SetNumberingStartValue( pSelection
->nStartPara
, nStartValue
);
556 case WID_PARAISNUMBERINGRESTART
:
558 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
559 if(pForwarder
&& pSelection
)
561 sal_Bool bParaIsNumberingRestart
= sal_False
;
562 if( aValue
>>= bParaIsNumberingRestart
)
564 pForwarder
->SetParaIsNumberingRestart( pSelection
->nStartPara
, bParaIsNumberingRestart
);
570 case EE_PARA_BULLETSTATE
:
572 sal_Bool bBullet
= sal_True
;
573 if( aValue
>>= bBullet
)
575 SfxBoolItem
aItem( EE_PARA_BULLETSTATE
, bBullet
);
586 throw lang::IllegalArgumentException();
589 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyValue(const OUString
& PropertyName
)
590 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
592 if (PropertyName
== UNO_TR_PROP_SELECTION
)
594 const ESelection
& rSel
= GetSelection();
595 text::TextRangeSelection aSel
;
596 aSel
.Start
.Paragraph
= static_cast<sal_Int32
>(rSel
.nStartPara
);
597 aSel
.Start
.PositionInParagraph
= static_cast<sal_Int32
>(rSel
.nStartPos
);
598 aSel
.End
.Paragraph
= static_cast<sal_Int32
>(rSel
.nEndPara
);
599 aSel
.End
.PositionInParagraph
= static_cast<sal_Int32
>(rSel
.nEndPos
);
600 return uno::makeAny(aSel
);
603 return _getPropertyValue( PropertyName
, -1 );
606 uno::Any SAL_CALL
SvxUnoTextRangeBase::_getPropertyValue(const OUString
& PropertyName
, sal_Int32 nPara
)
607 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
609 SolarMutexGuard aGuard
;
613 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
616 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
619 SfxItemSet
* pAttribs
= NULL
;
621 pAttribs
= pForwarder
->GetParaAttribs( (sal_uInt16
)nPara
).Clone();
623 pAttribs
= pForwarder
->GetAttribs( GetSelection() ).Clone();
625 // Replace Dontcare with Default, so that one always has a mirror
626 pAttribs
->ClearInvalidItems();
628 getPropertyValue( pMap
, aAny
, *pAttribs
);
635 throw beans::UnknownPropertyException();
638 void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& rAny
, const SfxItemSet
& rSet
) throw( beans::UnknownPropertyException
)
642 case EE_FEATURE_FIELD
:
643 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, sal_False
) == SFX_ITEM_SET
)
645 SvxFieldItem
* pItem
= (SvxFieldItem
*)rSet
.GetItem( EE_FEATURE_FIELD
);
646 const SvxFieldData
* pData
= pItem
->GetField();
647 uno::Reference
< text::XTextRange
> xAnchor( this );
649 // get presentation string for field
650 Color
* pTColor
= NULL
;
651 Color
* pFColor
= NULL
;
653 SvxTextForwarder
* pForwarder
= mpEditSource
->GetTextForwarder();
654 OUString
aPresentation( pForwarder
->CalcFieldValue( SvxFieldItem(*pData
, EE_FEATURE_FIELD
), maSelection
.nStartPara
, maSelection
.nStartPos
, pTColor
, pFColor
) );
659 uno::Reference
< text::XTextField
> xField( new SvxUnoTextField( xAnchor
, aPresentation
, pData
) );
664 case WID_PORTIONTYPE
:
665 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, sal_False
) == SFX_ITEM_SET
)
667 OUString
aType( RTL_CONSTASCII_USTRINGPARAM("TextField") );
672 OUString
aType( RTL_CONSTASCII_USTRINGPARAM("Text") );
678 if(!GetPropertyValueHelper( *((SfxItemSet
*)(&rSet
)), pMap
, rAny
, &maSelection
, GetEditSource() ))
679 rAny
= mpPropSet
->getPropertyValue(pMap
, rSet
, true, false );
683 sal_Bool
SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet
& rSet
, const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& aAny
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL */ )
684 throw( uno::RuntimeException
)
690 awt::FontDescriptor aDesc
;
691 SvxUnoFontDescriptor::FillFromItemSet( rSet
, aDesc
);
696 case EE_PARA_NUMBULLET
:
698 if((rSet
.GetItemState( EE_PARA_NUMBULLET
, sal_True
) & (SFX_ITEM_SET
|SFX_ITEM_DEFAULT
)) == 0)
699 throw uno::RuntimeException();
701 SvxNumBulletItem
* pBulletItem
= (SvxNumBulletItem
*)rSet
.GetItem( EE_PARA_NUMBULLET
, sal_True
);
703 if( pBulletItem
== NULL
)
704 throw uno::RuntimeException();
706 aAny
<<= SvxCreateNumRule( pBulletItem
->GetNumRule() );
712 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
713 if(pForwarder
&& pSelection
)
715 sal_Int16 nLevel
= pForwarder
->GetDepth( pSelection
->nStartPara
);
721 case WID_NUMBERINGSTARTVALUE
:
723 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
724 if(pForwarder
&& pSelection
)
725 aAny
<<= pForwarder
->GetNumberingStartValue( pSelection
->nStartPara
);
728 case WID_PARAISNUMBERINGRESTART
:
730 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
731 if(pForwarder
&& pSelection
)
732 aAny
<<= pForwarder
->IsParaIsNumberingRestart( pSelection
->nStartPara
);
736 case EE_PARA_BULLETSTATE
:
738 sal_Bool bState
= sal_False
;
739 if( rSet
.GetItemState( EE_PARA_BULLETSTATE
, sal_True
) & (SFX_ITEM_SET
|SFX_ITEM_DEFAULT
))
741 SfxBoolItem
* pItem
= (SfxBoolItem
*)rSet
.GetItem( EE_PARA_BULLETSTATE
, sal_True
);
742 bState
= pItem
->GetValue() ? sal_True
: sal_False
;
756 // is not (yet) supported
757 void SAL_CALL
SvxUnoTextRangeBase::addPropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
758 void SAL_CALL
SvxUnoTextRangeBase::removePropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
759 void SAL_CALL
SvxUnoTextRangeBase::addVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
760 void SAL_CALL
SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
763 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence
< ::rtl::OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
) throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
765 _setPropertyValues( aPropertyNames
, aValues
, -1 );
768 void SAL_CALL
SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence
< ::rtl::OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
, sal_Int32 nPara
) throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
770 SolarMutexGuard aGuard
;
772 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
775 CheckSelection( maSelection
, pForwarder
);
777 ESelection
aSel( GetSelection() );
779 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
780 const uno::Any
* pValues
= aValues
.getConstArray();
781 sal_Int32 nCount
= aPropertyNames
.getLength();
783 sal_Int32 nEndPara
= nPara
;
784 sal_Int32 nTempPara
= nPara
;
786 if( nTempPara
== -1 )
788 nTempPara
= aSel
.nStartPara
;
789 nEndPara
= aSel
.nEndPara
;
792 SfxItemSet
* pOldAttrSet
= NULL
;
793 SfxItemSet
* pNewAttrSet
= NULL
;
795 SfxItemSet
* pOldParaSet
= NULL
;
796 SfxItemSet
* pNewParaSet
= NULL
;
798 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
800 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
804 sal_Bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
806 if( (nPara
== -1) && !bParaAttrib
)
808 if( NULL
== pNewAttrSet
)
810 const SfxItemSet
aSet( pForwarder
->GetAttribs( aSel
) );
811 pOldAttrSet
= new SfxItemSet( aSet
);
812 pNewAttrSet
= new SfxItemSet( *pOldAttrSet
->GetPool(), pOldAttrSet
->GetRanges() );
815 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldAttrSet
, *pNewAttrSet
);
817 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
819 const SfxPoolItem
* pItem
;
820 if( pNewAttrSet
->GetItemState( pMap
->nWID
, sal_True
, &pItem
) == SFX_ITEM_SET
)
822 pOldAttrSet
->Put( *pItem
);
828 if( NULL
== pNewParaSet
)
830 const SfxItemSet
aSet( pForwarder
->GetParaAttribs( (sal_uInt16
)nTempPara
) );
831 pOldParaSet
= new SfxItemSet( aSet
);
832 pNewParaSet
= new SfxItemSet( *pOldParaSet
->GetPool(), pOldParaSet
->GetRanges() );
835 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldParaSet
, *pNewParaSet
);
837 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
839 const SfxPoolItem
* pItem
;
840 if( pNewParaSet
->GetItemState( pMap
->nWID
, sal_True
, &pItem
) == SFX_ITEM_SET
)
842 pOldParaSet
->Put( *pItem
);
850 sal_Bool bNeedsUpdate
= sal_False
;
854 if( pNewParaSet
->Count() )
856 while( nTempPara
<= nEndPara
)
858 SfxItemSet
aSet( pForwarder
->GetParaAttribs( (sal_uInt16
)nTempPara
) );
859 aSet
.Put( *pNewParaSet
);
860 pForwarder
->SetParaAttribs( (sal_uInt16
)nTempPara
, aSet
);
863 bNeedsUpdate
= sal_True
;
872 if( pNewAttrSet
->Count() )
874 pForwarder
->QuickSetAttribs( *pNewAttrSet
, GetSelection() );
875 bNeedsUpdate
= sal_True
;
883 GetEditSource()->UpdateData();
887 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence
< ::rtl::OUString
>& aPropertyNames
) throw (uno::RuntimeException
)
889 return _getPropertyValues( aPropertyNames
, -1 );
892 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence
< ::rtl::OUString
>& aPropertyNames
, sal_Int32 nPara
) throw (uno::RuntimeException
)
894 SolarMutexGuard aGuard
;
896 sal_Int32 nCount
= aPropertyNames
.getLength();
899 uno::Sequence
< uno::Any
> aValues( nCount
);
901 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
904 SfxItemSet
* pAttribs
= NULL
;
906 pAttribs
= pForwarder
->GetParaAttribs( (sal_uInt16
)nPara
).Clone();
908 pAttribs
= pForwarder
->GetAttribs( GetSelection() ).Clone();
910 pAttribs
->ClearInvalidItems();
912 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
913 uno::Any
* pValues
= aValues
.getArray();
915 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
917 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
920 getPropertyValue( pMap
, *pValues
, *pAttribs
);
931 void SAL_CALL
SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence
< ::rtl::OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
)
935 void SAL_CALL
SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
)
939 void SAL_CALL
SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence
< ::rtl::OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
)
943 // beans::XPropertyState
944 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::getPropertyState( const OUString
& PropertyName
)
945 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
947 return _getPropertyState( PropertyName
, -1 );
950 static sal_uInt16 aSvxUnoFontDescriptorWhichMap
[] = { EE_CHAR_FONTINFO
, EE_CHAR_FONTHEIGHT
, EE_CHAR_ITALIC
,
951 EE_CHAR_UNDERLINE
, EE_CHAR_WEIGHT
, EE_CHAR_STRIKEOUT
,
954 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
955 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
959 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
962 SfxItemState eItemState
= SFX_ITEM_UNKNOWN
;
969 sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
970 SfxItemState eTempItemState
;
974 eTempItemState
= pForwarder
->GetItemState( (sal_uInt16
)nPara
, *pWhichId
);
976 eTempItemState
= pForwarder
->GetItemState( GetSelection(), *pWhichId
);
978 switch( eTempItemState
)
980 case SFX_ITEM_DISABLED
:
981 case SFX_ITEM_DONTCARE
:
982 eItemState
= SFX_ITEM_DONTCARE
;
985 case SFX_ITEM_DEFAULT
:
986 if( eItemState
!= SFX_ITEM_DEFAULT
)
988 if( eItemState
== SFX_ITEM_UNKNOWN
)
989 eItemState
= SFX_ITEM_DEFAULT
;
993 case SFX_ITEM_READONLY
:
995 if( eItemState
!= SFX_ITEM_SET
)
997 if( eItemState
== SFX_ITEM_UNKNOWN
)
998 eItemState
= SFX_ITEM_SET
;
1002 throw beans::UnknownPropertyException();
1011 case WID_NUMBERINGSTARTVALUE
:
1012 case WID_PARAISNUMBERINGRESTART
:
1013 eItemState
= SFX_ITEM_SET
;
1023 eItemState
= pForwarder
->GetItemState( (sal_uInt16
)nPara
, nWID
);
1025 eItemState
= pForwarder
->GetItemState( GetSelection(), nWID
);
1028 switch( eItemState
)
1030 case SFX_ITEM_DONTCARE
:
1031 case SFX_ITEM_DISABLED
:
1032 return beans::PropertyState_AMBIGUOUS_VALUE
;
1033 case SFX_ITEM_READONLY
:
1035 return beans::PropertyState_DIRECT_VALUE
;
1036 case SFX_ITEM_DEFAULT
:
1037 return beans::PropertyState_DEFAULT_VALUE
;
1038 // case SFX_ITEM_UNKNOWN:
1042 throw beans::UnknownPropertyException();
1045 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::_getPropertyState(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1046 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1048 SolarMutexGuard aGuard
;
1050 return _getPropertyState( mpPropSet
->getPropertyMapEntry( PropertyName
), nPara
);
1053 uno::Sequence
< beans::PropertyState
> SAL_CALL
SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence
< OUString
>& aPropertyName
)
1054 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
1056 return _getPropertyStates( aPropertyName
, -1 );
1059 uno::Sequence
< beans::PropertyState
> SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence
< OUString
>& PropertyName
, sal_Int32 nPara
/* = -1 */)
1060 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1062 const sal_Int32 nCount
= PropertyName
.getLength();
1063 const OUString
* pNames
= PropertyName
.getConstArray();
1065 uno::Sequence
< beans::PropertyState
> aRet( nCount
);
1066 beans::PropertyState
* pState
= aRet
.getArray();
1068 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1071 SfxItemSet
* pSet
= NULL
;
1074 pSet
= new SfxItemSet( pForwarder
->GetParaAttribs( (sal_uInt16
)nPara
) );
1078 ESelection
aSel( GetSelection() );
1079 CheckSelection( aSel
, pForwarder
);
1080 pSet
= new SfxItemSet( pForwarder
->GetAttribs( aSel
, EditEngineAttribs_OnlyHard
) );
1083 sal_Bool bUnknownPropertyFound
= sal_False
;
1084 for( sal_Int32 nIdx
= 0; nIdx
< nCount
; nIdx
++ )
1086 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pNames
++ );
1089 bUnknownPropertyFound
= sal_True
;
1092 bUnknownPropertyFound
= !_getOnePropertyStates(pSet
, pMap
, *pState
++);
1097 if( bUnknownPropertyFound
)
1098 throw beans::UnknownPropertyException();
1104 sal_Bool
SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet
* pSet
, const SfxItemPropertySimpleEntry
* pMap
, beans::PropertyState
& rState
)
1106 sal_Bool bUnknownPropertyFound
= sal_False
;
1109 SfxItemState eItemState
= SFX_ITEM_UNKNOWN
;
1110 sal_uInt16 nWID
= 0;
1112 switch( pMap
->nWID
)
1116 sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
1117 SfxItemState eTempItemState
;
1120 eTempItemState
= pSet
->GetItemState( *pWhichId
);
1122 switch( eTempItemState
)
1124 case SFX_ITEM_DISABLED
:
1125 case SFX_ITEM_DONTCARE
:
1126 eItemState
= SFX_ITEM_DONTCARE
;
1129 case SFX_ITEM_DEFAULT
:
1130 if( eItemState
!= SFX_ITEM_DEFAULT
)
1132 if( eItemState
== SFX_ITEM_UNKNOWN
)
1133 eItemState
= SFX_ITEM_DEFAULT
;
1137 case SFX_ITEM_READONLY
:
1139 if( eItemState
!= SFX_ITEM_SET
)
1141 if( eItemState
== SFX_ITEM_UNKNOWN
)
1142 eItemState
= SFX_ITEM_SET
;
1146 bUnknownPropertyFound
= sal_True
;
1156 case WID_NUMBERINGSTARTVALUE
:
1157 case WID_PARAISNUMBERINGRESTART
:
1158 eItemState
= SFX_ITEM_SET
;
1165 if( bUnknownPropertyFound
)
1166 return !bUnknownPropertyFound
;
1169 eItemState
= pSet
->GetItemState( nWID
, sal_False
);
1171 switch( eItemState
)
1173 case SFX_ITEM_READONLY
:
1175 rState
= beans::PropertyState_DIRECT_VALUE
;
1177 case SFX_ITEM_DEFAULT
:
1178 rState
= beans::PropertyState_DEFAULT_VALUE
;
1180 // case SFX_ITEM_UNKNOWN:
1181 // case SFX_ITEM_DONTCARE:
1182 // case SFX_ITEM_DISABLED:
1184 rState
= beans::PropertyState_AMBIGUOUS_VALUE
;
1187 return !bUnknownPropertyFound
;
1190 void SAL_CALL
SvxUnoTextRangeBase::setPropertyToDefault( const OUString
& PropertyName
)
1191 throw(beans::UnknownPropertyException
, uno::RuntimeException
)
1193 _setPropertyToDefault( PropertyName
, -1 );
1196 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1197 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1199 SolarMutexGuard aGuard
;
1201 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1205 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( PropertyName
);
1208 CheckSelection( maSelection
, mpEditSource
->GetTextForwarder() );
1209 _setPropertyToDefault( pForwarder
, pMap
, nPara
);
1214 throw beans::UnknownPropertyException();
1217 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder
* pForwarder
, const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
1218 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1222 SfxItemSet
aSet( *pForwarder
->GetPool(), sal_True
);
1224 if( pMap
->nWID
== WID_FONTDESC
)
1226 SvxUnoFontDescriptor::setPropertyToDefault( aSet
);
1228 else if( pMap
->nWID
== WID_NUMLEVEL
)
1230 // #101004# Call interface method instead of unsafe cast
1231 pForwarder
->SetDepth( maSelection
.nStartPara
, -1 );
1234 else if( pMap
->nWID
== WID_NUMBERINGSTARTVALUE
)
1236 pForwarder
->SetNumberingStartValue( maSelection
.nStartPara
, -1 );
1238 else if( pMap
->nWID
== WID_PARAISNUMBERINGRESTART
)
1240 pForwarder
->SetParaIsNumberingRestart( maSelection
.nStartPara
, sal_False
);
1244 aSet
.InvalidateItem( pMap
->nWID
);
1248 pForwarder
->SetParaAttribs( (sal_uInt16
)nPara
, aSet
);
1250 pForwarder
->QuickSetAttribs( aSet
, GetSelection() );
1252 GetEditSource()->UpdateData();
1259 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyDefault( const OUString
& aPropertyName
)
1260 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
1262 SolarMutexGuard aGuard
;
1264 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1267 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( aPropertyName
);
1270 SfxItemPool
* pPool
= pForwarder
->GetPool();
1272 switch( pMap
->nWID
)
1275 return SvxUnoFontDescriptor::getPropertyDefault( pPool
);
1283 case WID_NUMBERINGSTARTVALUE
:
1284 return uno::Any( (sal_Int16
)-1 );
1286 case WID_PARAISNUMBERINGRESTART
:
1287 return uno::Any( (sal_Bool
)sal_False
);
1291 // Get Default from ItemPool
1292 if(pPool
->IsWhich(pMap
->nWID
))
1294 SfxItemSet
aSet( *pPool
, pMap
->nWID
, pMap
->nWID
);
1295 aSet
.Put(pPool
->GetDefaultItem(pMap
->nWID
));
1296 return mpPropSet
->getPropertyValue(pMap
, aSet
, true, false );
1302 throw beans::UnknownPropertyException();
1305 // beans::XMultiPropertyStates
1306 void SAL_CALL
SvxUnoTextRangeBase::setAllPropertiesToDefault( ) throw (uno::RuntimeException
)
1308 SolarMutexGuard aGuard
;
1310 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1314 PropertyEntryVector_t aEntries
= mpPropSet
->getPropertyMap()->getPropertyEntries();
1315 PropertyEntryVector_t::const_iterator aIt
= aEntries
.begin();
1316 while( aIt
!= aEntries
.end() )
1318 _setPropertyToDefault( pForwarder
, &(*aIt
), -1 );
1324 void SAL_CALL
SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence
< OUString
>& aPropertyNames
) throw (beans::UnknownPropertyException
, uno::RuntimeException
)
1326 sal_Int32 nCount
= aPropertyNames
.getLength();
1327 for( const OUString
* pName
= aPropertyNames
.getConstArray(); nCount
; pName
++, nCount
-- )
1329 setPropertyToDefault( *pName
);
1333 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence
< OUString
>& aPropertyNames
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
1335 sal_Int32 nCount
= aPropertyNames
.getLength();
1336 uno::Sequence
< uno::Any
> ret( nCount
);
1337 uno::Any
* pDefaults
= ret
.getArray();
1339 for( const OUString
* pName
= aPropertyNames
.getConstArray(); nCount
; pName
++, nCount
--, pDefaults
++ )
1341 *pDefaults
= getPropertyDefault( *pName
);
1348 void SvxUnoTextRangeBase::CollapseToStart(void) throw()
1350 CheckSelection( maSelection
, mpEditSource
);
1352 maSelection
.nEndPara
= maSelection
.nStartPara
;
1353 maSelection
.nEndPos
= maSelection
.nStartPos
;
1356 void SvxUnoTextRangeBase::CollapseToEnd(void) throw()
1358 CheckSelection( maSelection
, mpEditSource
);
1360 maSelection
.nStartPara
= maSelection
.nEndPara
;
1361 maSelection
.nStartPos
= maSelection
.nEndPos
;
1364 sal_Bool
SvxUnoTextRangeBase::IsCollapsed(void) throw()
1366 CheckSelection( maSelection
, mpEditSource
);
1368 return ( maSelection
.nStartPara
== maSelection
.nEndPara
&&
1369 maSelection
.nStartPos
== maSelection
.nEndPos
);
1372 sal_Bool
SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount
, sal_Bool Expand
) throw()
1374 CheckSelection( maSelection
, mpEditSource
);
1376 // #75098# use end position, as in Writer (start is anchor, end is cursor)
1377 sal_uInt16 nNewPos
= maSelection
.nEndPos
;
1378 sal_uInt16 nNewPar
= maSelection
.nEndPara
;
1380 sal_Bool bOk
= sal_True
;
1381 SvxTextForwarder
* pForwarder
= NULL
;
1382 while ( nCount
> nNewPos
&& bOk
)
1389 pForwarder
= mpEditSource
->GetTextForwarder(); // first here, it it is necessary...
1392 nCount
-= nNewPos
+ 1;
1393 nNewPos
= pForwarder
->GetTextLen( nNewPar
);
1399 nNewPos
= nNewPos
- nCount
;
1400 maSelection
.nStartPara
= nNewPar
;
1401 maSelection
.nStartPos
= nNewPos
;
1410 sal_Bool
SvxUnoTextRangeBase::GoRight(sal_Int16 nCount
, sal_Bool Expand
) throw()
1412 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1415 CheckSelection( maSelection
, pForwarder
);
1417 sal_uInt16 nNewPos
= maSelection
.nEndPos
+ nCount
; //! Overflow???
1418 sal_uInt16 nNewPar
= maSelection
.nEndPara
;
1420 sal_Bool bOk
= sal_True
;
1421 sal_uInt16 nParCount
= pForwarder
->GetParagraphCount();
1422 sal_uInt16 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1423 while ( nNewPos
> nThisLen
&& bOk
)
1425 if ( nNewPar
+ 1 >= nParCount
)
1429 nNewPos
-= nThisLen
+1;
1431 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1437 maSelection
.nEndPara
= nNewPar
;
1438 maSelection
.nEndPos
= nNewPos
;
1449 void SvxUnoTextRangeBase::GotoStart(sal_Bool Expand
) throw()
1451 maSelection
.nStartPara
= 0;
1452 maSelection
.nStartPos
= 0;
1458 void SvxUnoTextRangeBase::GotoEnd(sal_Bool Expand
) throw()
1460 CheckSelection( maSelection
, mpEditSource
);
1462 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1466 sal_uInt16 nPar
= pForwarder
->GetParagraphCount();
1470 maSelection
.nEndPara
= nPar
;
1471 maSelection
.nEndPos
= pForwarder
->GetTextLen( nPar
);
1478 // lang::XServiceInfo
1479 sal_Bool SAL_CALL
SvxUnoTextRangeBase::supportsService( const OUString
& ServiceName
)
1480 throw(uno::RuntimeException
)
1482 return comphelper::ServiceInfoHelper::supportsService( ServiceName
, getSupportedServiceNames() );
1485 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextRangeBase::getSupportedServiceNames()
1486 throw(uno::RuntimeException
)
1488 return getSupportedServiceNames_Static();
1491 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1494 uno::Sequence
< OUString
> aSeq
;
1495 comphelper::ServiceInfoHelper::addToSequence( aSeq
, 3, "com.sun.star.style.CharacterProperties",
1496 "com.sun.star.style.CharacterPropertiesComplex",
1497 "com.sun.star.style.CharacterPropertiesAsian");
1501 // XTextRangeCompare
1502 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1504 SvxUnoTextRangeBase
* pR1
= SvxUnoTextRangeBase::getImplementation( xR1
);
1505 SvxUnoTextRangeBase
* pR2
= SvxUnoTextRangeBase::getImplementation( xR2
);
1507 if( (pR1
== 0) || (pR2
== 0) )
1508 throw lang::IllegalArgumentException();
1510 const ESelection
& r1
= pR1
->maSelection
;
1511 const ESelection
& r2
= pR2
->maSelection
;
1513 if( r1
.nStartPara
== r2
.nStartPara
)
1515 if( r1
.nStartPos
== r2
.nStartPos
)
1518 return r1
.nStartPos
< r2
.nStartPos
? 1 : -1;
1522 return r1
.nStartPara
< r2
.nStartPara
? 1 : -1;
1526 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
) throw (lang::IllegalArgumentException
, uno::RuntimeException
)
1528 SvxUnoTextRangeBase
* pR1
= SvxUnoTextRangeBase::getImplementation( xR1
);
1529 SvxUnoTextRangeBase
* pR2
= SvxUnoTextRangeBase::getImplementation( xR2
);
1531 if( (pR1
== 0) || (pR2
== 0) )
1532 throw lang::IllegalArgumentException();
1534 const ESelection
& r1
= pR1
->maSelection
;
1535 const ESelection
& r2
= pR2
->maSelection
;
1537 if( r1
.nEndPara
== r2
.nEndPara
)
1539 if( r1
.nEndPos
== r2
.nEndPos
)
1542 return r1
.nEndPos
< r2
.nEndPos
? 1 : -1;
1546 return r1
.nEndPara
< r2
.nEndPara
? 1 : -1;
1550 // ====================================================================
1551 // class SvxUnoTextRange
1552 // ====================================================================
1554 uno::Reference
< uno::XInterface
> SvxUnoTextRange_NewInstance()
1557 uno::Reference
< text::XTextRange
> xRange( new SvxUnoTextRange( aText
) );
1558 #if (_MSC_VER < 1300)
1561 return (uno::Reference
< uno::XInterface
>)xRange
;
1565 SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase
& rParent
, sal_Bool bPortion
/* = sal_False */ ) throw()
1566 :SvxUnoTextRangeBase( rParent
.GetEditSource(), bPortion
? ImplGetSvxTextPortionSvxPropertySet() : rParent
.getPropertySet() ),
1567 mbPortion( bPortion
)
1569 xParentText
= (text::XText
*)&rParent
;
1572 SvxUnoTextRange::~SvxUnoTextRange() throw()
1577 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextRange::getText()
1578 throw(uno::RuntimeException
)
1583 // lang::XServiceInfo
1584 OUString SAL_CALL
SvxUnoTextRange::getImplementationName()
1585 throw(uno::RuntimeException
)
1587 return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextRange"));
1590 // ====================================================================
1592 // ====================================================================
1594 SvxUnoTextBase_Base::SvxUnoTextBase_Base(SvxUnoTextBase_Base
const & base
)
1596 SvxUnoTextBase_Base0(base
)
1599 SvxUnoTextBase_Base::SvxUnoTextBase_Base(SvxItemPropertySet
const * set
)
1601 SvxUnoTextBase_Base0(set
)
1604 SvxUnoTextBase_Base::SvxUnoTextBase_Base(
1605 SvxEditSource
const * source
, SvxItemPropertySet
const * set
) throw ():
1606 SvxUnoTextBase_Base0(source
, set
)
1609 SvxUnoTextBase_Base::~SvxUnoTextBase_Base() throw () {}
1611 SvxUnoTextBase::SvxUnoTextBase() throw()
1612 : SvxUnoTextBase_Base( static_cast< SvxItemPropertySet
* >(NULL
) )
1617 SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet
* _pSet
) throw()
1618 : SvxUnoTextBase_Base( _pSet
)
1622 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> xParent
) throw()
1623 : SvxUnoTextBase_Base( pSource
, _pSet
)
1625 xParentText
= xParent
;
1626 ESelection aSelection
;
1627 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1628 SetSelection( aSelection
);
1631 SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase
& rText
) throw()
1632 : SvxUnoTextBase_Base( rText
)
1634 xParentText
= rText
.xParentText
;
1637 SvxUnoTextBase::~SvxUnoTextBase() throw()
1641 uno::Reference
< text::XTextCursor
> SvxUnoTextBase::createTextCursorBySelection( const ESelection
& rSel
)
1643 SvxUnoTextCursor
* pCursor
= new SvxUnoTextCursor( *this );
1644 uno::Reference
< text::XTextCursor
> xCursor( pCursor
);
1645 pCursor
->SetSelection( rSel
);
1651 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursor()
1652 throw(uno::RuntimeException
)
1654 SolarMutexGuard aGuard
;
1655 return new SvxUnoTextCursor( *this );
1658 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursorByRange( const uno::Reference
< text::XTextRange
>& aTextPosition
)
1659 throw(uno::RuntimeException
)
1661 SolarMutexGuard aGuard
;
1663 uno::Reference
< text::XTextCursor
> xCursor
;
1665 if( aTextPosition
.is() )
1667 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRangeBase::getImplementation( aTextPosition
);
1669 xCursor
= createTextCursorBySelection( pRange
->GetSelection() );
1675 void SAL_CALL
SvxUnoTextBase::insertString( const uno::Reference
< text::XTextRange
>& xRange
, const OUString
& aString
, sal_Bool bAbsorb
)
1676 throw(uno::RuntimeException
)
1678 SolarMutexGuard aGuard
;
1683 ESelection aSelection
;
1684 if (GetEditSource())
1686 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1687 SetSelection( aSelection
);
1690 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1693 // setString on SvxUnoTextRangeBase instead of itself QuickInsertText
1694 // and UpdateData, so that the selection will be adjusted to
1695 // SvxUnoTextRangeBase. Actually all cursor objects of this Text must
1696 // to be statement to be adapted!
1698 if (!bAbsorb
) // do not replace -> append on tail
1699 pRange
->CollapseToEnd();
1701 pRange
->setString( aString
);
1703 pRange
->CollapseToEnd();
1707 void SAL_CALL
SvxUnoTextBase::insertControlCharacter( const uno::Reference
< text::XTextRange
>& xRange
, sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
1708 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1710 SolarMutexGuard aGuard
;
1712 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL
;
1716 ESelection aSelection
;
1717 ::GetSelection( aSelection
, pForwarder
);
1718 SetSelection( aSelection
);
1720 switch( nControlCharacter
)
1722 case text::ControlCharacter::PARAGRAPH_BREAK
:
1724 const String
aText( (sal_Unicode
)13 ); // '\r' does not work on Mac
1725 insertString( xRange
, aText
, bAbsorb
);
1729 case text::ControlCharacter::LINE_BREAK
:
1731 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1734 ESelection aRange
= pRange
->GetSelection();
1738 const String aEmpty
;
1739 pForwarder
->QuickInsertText( aEmpty
, aRange
);
1741 aRange
.nEndPos
= aRange
.nStartPos
;
1742 aRange
.nEndPara
= aRange
.nStartPara
;
1746 aRange
.nStartPos
= aRange
.nEndPos
;
1747 aRange
.nStartPara
= aRange
.nStartPara
;
1750 pForwarder
->QuickInsertLineBreak( aRange
);
1751 GetEditSource()->UpdateData();
1753 aRange
.nEndPos
+= 1;
1755 aRange
.nStartPos
+= 1;
1757 pRange
->SetSelection( aRange
);
1761 case text::ControlCharacter::APPEND_PARAGRAPH
:
1763 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1766 ESelection aRange
= pRange
->GetSelection();
1767 // ESelection aOldSelection = aRange;
1769 aRange
.nStartPos
= pForwarder
->GetTextLen( aRange
.nStartPara
);
1771 aRange
.nEndPara
= aRange
.nStartPara
;
1772 aRange
.nEndPos
= aRange
.nStartPos
;
1774 pRange
->SetSelection( aRange
);
1775 const String
aText( (sal_Unicode
)13 ); // '\r' geht auf'm Mac nicht
1776 pRange
->setString( aText
);
1778 aRange
.nStartPos
= 0;
1779 aRange
.nStartPara
+= 1;
1781 aRange
.nEndPara
+= 1;
1783 pRange
->SetSelection( aRange
);
1789 throw lang::IllegalArgumentException();
1795 void SAL_CALL
SvxUnoTextBase::insertTextContent( const uno::Reference
< text::XTextRange
>& xRange
, const uno::Reference
< text::XTextContent
>& xContent
, sal_Bool bAbsorb
)
1796 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
1798 SolarMutexGuard aGuard
;
1800 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL
;
1804 uno::Reference
<beans::XPropertySet
> xPropSet(xRange
, uno::UNO_QUERY
);
1806 throw lang::IllegalArgumentException();
1808 uno::Any aAny
= xPropSet
->getPropertyValue(UNO_TR_PROP_SELECTION
);
1809 text::TextRangeSelection aSel
= aAny
.get
<text::TextRangeSelection
>();
1811 aSel
.Start
= aSel
.End
;
1813 boost::scoped_ptr
<SvxFieldData
> pFieldData(SvxFieldData::Create(xContent
));
1815 throw lang::IllegalArgumentException();
1817 SvxFieldItem
aField( *pFieldData
, EE_FEATURE_FIELD
);
1818 pForwarder
->QuickInsertField(aField
, toESelection(aSel
));
1819 GetEditSource()->UpdateData();
1821 uno::Reference
<beans::XPropertySet
> xPropSetContent(xContent
, uno::UNO_QUERY
);
1823 throw lang::IllegalArgumentException();
1825 xPropSetContent
->setPropertyValue(UNO_TC_PROP_ANCHOR
, uno::makeAny(xRange
));
1827 aSel
.End
.PositionInParagraph
+= 1;
1828 aSel
.Start
.PositionInParagraph
= aSel
.End
.PositionInParagraph
;
1829 xPropSet
->setPropertyValue(UNO_TR_PROP_SELECTION
, uno::makeAny(aSel
));
1832 void SAL_CALL
SvxUnoTextBase::removeTextContent( const uno::Reference
< text::XTextContent
>& ) throw(container::NoSuchElementException
, uno::RuntimeException
)
1838 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextBase::getText()
1839 throw(uno::RuntimeException
)
1841 SolarMutexGuard aGuard
;
1843 if (GetEditSource())
1845 ESelection aSelection
;
1846 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1847 ((SvxUnoTextBase
*)this)->SetSelection( aSelection
);
1850 return (text::XText
*)this;
1853 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getStart()
1854 throw(uno::RuntimeException
)
1856 return SvxUnoTextRangeBase::getStart();
1859 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getEnd()
1860 throw(uno::RuntimeException
)
1862 return SvxUnoTextRangeBase::getEnd();
1865 OUString SAL_CALL
SvxUnoTextBase::getString() throw( uno::RuntimeException
)
1867 return SvxUnoTextRangeBase::getString();
1870 void SAL_CALL
SvxUnoTextBase::setString( const OUString
& aString
) throw(uno::RuntimeException
)
1872 SvxUnoTextRangeBase::setString(aString
);
1876 // XEnumerationAccess
1877 uno::Reference
< container::XEnumeration
> SAL_CALL
SvxUnoTextBase::createEnumeration()
1878 throw(uno::RuntimeException
)
1880 SolarMutexGuard aGuard
;
1882 ESelection aSelection
;
1883 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1884 SetSelection( aSelection
);
1886 uno::Reference
< container::XEnumeration
> xEnum( (container::XEnumeration
*) new SvxUnoTextContentEnumeration( *this ) );
1890 // XElementAccess ( container::XEnumerationAccess )
1891 uno::Type SAL_CALL
SvxUnoTextBase::getElementType( ) throw(uno::RuntimeException
)
1893 return ::getCppuType((const uno::Reference
< text::XTextRange
>*)0 );
1896 sal_Bool SAL_CALL
SvxUnoTextBase::hasElements( ) throw(uno::RuntimeException
)
1898 SolarMutexGuard aGuard
;
1902 SvxTextForwarder
* pForwarder
= GetEditSource()->GetTextForwarder();
1904 return pForwarder
->GetParagraphCount() != 0;
1910 // text::XTextRangeMover
1911 void SAL_CALL
SvxUnoTextBase::moveTextRange( const uno::Reference
< text::XTextRange
>&, sal_Int16
)
1912 throw(uno::RuntimeException
)
1916 void SvxPropertyValuesToItemSet(
1917 SfxItemSet
&rItemSet
,
1918 const uno::Sequence
< beans::PropertyValue
> rPropertyVaules
,
1919 const SfxItemPropertySet
*pPropSet
,
1920 SvxTextForwarder
*pForwarder
/*needed for WID_NUMLEVEL*/,
1921 sal_uInt16 nPara
/*needed for WID_NUMLEVEL*/)
1922 throw(lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
)
1924 sal_Int32 nProps
= rPropertyVaules
.getLength();
1925 const beans::PropertyValue
*pProps
= rPropertyVaules
.getConstArray();
1926 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
1928 const SfxItemPropertySimpleEntry
*pEntry
= pPropSet
->getPropertyMap().getByName( pProps
[i
].Name
);
1931 // Note: there is no need to take special care of the properties
1932 // TextField (EE_FEATURE_FIELD) and
1933 // TextPortionType (WID_PORTIONTYPE)
1934 // since they are read-only and thus are already taken care of below.
1936 if (pEntry
->nFlags
& beans::PropertyAttribute::READONLY
)
1937 // should be PropertyVetoException which is not yet defined for the new import API's functions
1938 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps
[i
].Name
, static_cast < cppu::OWeakObject
* > ( 0 ) );
1939 //throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
1941 if (pEntry
->nWID
== WID_FONTDESC
)
1943 awt::FontDescriptor aDesc
;
1944 if (pProps
[i
].Value
>>= aDesc
)
1945 SvxUnoFontDescriptor::FillItemSet( aDesc
, rItemSet
);
1947 else if (pEntry
->nWID
== WID_NUMLEVEL
)
1951 sal_Int16 nLevel
= -1;
1952 pProps
[i
].Value
>>= nLevel
;
1954 // #101004# Call interface method instead of unsafe cast
1955 if (!pForwarder
->SetDepth( nPara
, nLevel
))
1956 throw lang::IllegalArgumentException();
1959 else if (pEntry
->nWID
== WID_NUMBERINGSTARTVALUE
)
1963 sal_Int16 nStartValue
= -1;
1964 if( !(pProps
[i
].Value
>>= nStartValue
) )
1965 throw lang::IllegalArgumentException();
1967 pForwarder
->SetNumberingStartValue( nPara
, nStartValue
);
1970 else if (pEntry
->nWID
== WID_PARAISNUMBERINGRESTART
)
1974 sal_Bool bParaIsNumberingRestart
= sal_False
;
1975 if( !(pProps
[i
].Value
>>= bParaIsNumberingRestart
) )
1976 throw lang::IllegalArgumentException();
1978 pForwarder
->SetParaIsNumberingRestart( nPara
, bParaIsNumberingRestart
);
1982 pPropSet
->setPropertyValue( pProps
[i
].Name
, pProps
[i
].Value
, rItemSet
);
1985 throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pProps
[i
].Name
, static_cast < cppu::OWeakObject
* > ( 0 ) );
1989 // com::sun::star::text::XParagraphAppend (new import API)
1990 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::appendParagraph(
1991 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
1992 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
)
1994 SolarMutexGuard aGuard
;
1995 uno::Reference
< text::XTextRange
> xRet
;
1996 SvxEditSource
*pEditSource
= GetEditSource();
1997 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2000 sal_uInt16 nParaCount
= pTextForwarder
->GetParagraphCount();
2001 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2002 pTextForwarder
->AppendParagraph();
2004 // set properties for new appended (now last) paragraph
2005 ESelection
aSel( nParaCount
, 0, nParaCount
, 0 );
2006 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2007 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2008 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(),
2011 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2012 pEditSource
->UpdateData();
2013 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2015 pRange
->SetSelection( aSel
);
2020 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::finishParagraph(
2021 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2022 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
)
2024 SolarMutexGuard aGuard
;
2026 uno::Reference
< text::XTextRange
> xRet
;
2027 SvxEditSource
*pEditSource
= GetEditSource();
2028 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2031 sal_uInt16 nParaCount
= pTextForwarder
->GetParagraphCount();
2032 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2033 pTextForwarder
->AppendParagraph();
2035 // set properties for the previously last paragraph
2036 sal_uInt16 nPara
= nParaCount
- 1;
2037 ESelection
aSel( nPara
, 0, nPara
, 0 );
2038 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2039 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2040 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder
, nPara
);
2041 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2042 pEditSource
->UpdateData();
2043 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2045 pRange
->SetSelection( aSel
);
2050 // com::sun::star::text::XTextPortionAppend (new import API)
2051 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::appendTextPortion(
2052 const ::rtl::OUString
& rText
,
2053 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2054 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
)
2056 SolarMutexGuard aGuard
;
2058 SvxEditSource
*pEditSource
= GetEditSource();
2059 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2060 uno::Reference
< text::XTextRange
> xRet
;
2063 sal_uInt16 nParaCount
= pTextForwarder
->GetParagraphCount();
2064 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2065 sal_uInt16 nPara
= nParaCount
- 1;
2066 SfxItemSet
aSet( pTextForwarder
->GetParaAttribs( nPara
) );
2067 xub_StrLen nStart
= pTextForwarder
->AppendTextPortion( nPara
, rText
, aSet
);
2068 pEditSource
->UpdateData();
2069 xub_StrLen nEnd
= pTextForwarder
->GetTextLen( nPara
);
2071 // set properties for the new text portion
2072 ESelection
aSel( nPara
, nStart
, nPara
, nEnd
);
2073 pTextForwarder
->RemoveAttribs( aSel
, sal_False
, 0 );
2074 pEditSource
->UpdateData();
2076 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2077 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2078 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder
, nPara
);
2079 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2080 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2082 pRange
->SetSelection( aSel
);
2083 const beans::PropertyValue
* pProps
= rCharAndParaProps
.getConstArray();
2084 for( sal_Int32 nProp
= 0; nProp
< rCharAndParaProps
.getLength(); ++nProp
)
2085 pRange
->setPropertyValue( pProps
[nProp
].Name
, pProps
[nProp
].Value
);
2090 void SvxUnoTextBase::copyText(
2091 const uno::Reference
< text::XTextCopy
>& xSource
) throw ( uno::RuntimeException
)
2093 SolarMutexGuard aGuard
;
2094 uno::Reference
< lang::XUnoTunnel
> xUT( xSource
, uno::UNO_QUERY
);
2095 SvxEditSource
*pEditSource
= GetEditSource();
2096 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2097 if( !pTextForwarder
)
2101 SvxUnoTextBase
* pSource
= reinterpret_cast<SvxUnoTextBase
*>(sal::static_int_cast
<sal_uIntPtr
>(
2102 xUT
->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2103 SvxEditSource
*pSourceEditSource
= pSource
->GetEditSource();
2104 SvxTextForwarder
*pSourceTextForwarder
= pSourceEditSource
? pSourceEditSource
->GetTextForwarder() : 0;
2105 if( pSourceTextForwarder
)
2107 pTextForwarder
->CopyText( *pSourceTextForwarder
);
2108 pEditSource
->UpdateData();
2113 uno::Reference
< text::XText
> xSourceText( xSource
, uno::UNO_QUERY
);
2114 if( xSourceText
.is() )
2116 setString( xSourceText
->getString() );
2121 // lang::XServiceInfo
2122 OUString SAL_CALL
SvxUnoTextBase::getImplementationName()
2123 throw(uno::RuntimeException
)
2125 return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextBase"));
2128 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames( )
2129 throw(uno::RuntimeException
)
2131 return getSupportedServiceNames_Static();
2134 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames_Static( )
2137 uno::Sequence
< OUString
> aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() );
2138 comphelper::ServiceInfoHelper::addToSequence( aSeq
, 1, "com.sun.star.text.Text" );
2144 class theSvxUnoTextBaseUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextBaseUnoTunnelId
> {};
2147 const uno::Sequence
< sal_Int8
> & SvxUnoTextBase::getUnoTunnelId() throw()
2149 return theSvxUnoTextBaseUnoTunnelId::get().getSeq();
2152 SvxUnoTextBase
* SvxUnoTextBase::getImplementation( const uno::Reference
< uno::XInterface
>& xInt
)
2154 uno::Reference
< lang::XUnoTunnel
> xUT( xInt
, uno::UNO_QUERY
);
2156 return reinterpret_cast<SvxUnoTextBase
*>(sal::static_int_cast
<sal_uIntPtr
>(xUT
->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2161 sal_Int64 SAL_CALL
SvxUnoTextBase::getSomething( const uno::Sequence
< sal_Int8
>& rId
) throw(uno::RuntimeException
) \
2163 if( rId
.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2164 rId
.getConstArray(), 16 ) )
2166 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2170 return SvxUnoTextRangeBase::getSomething( rId
);
2174 // --------------------------------------------------------------------
2176 SvxUnoText::SvxUnoText( ) throw()
2180 SvxUnoText::SvxUnoText( const SvxItemPropertySet
* _pSet
) throw()
2181 : SvxUnoTextBase( _pSet
)
2185 SvxUnoText::SvxUnoText( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> xParent
) throw()
2186 : SvxUnoTextBase( pSource
, _pSet
, xParent
)
2190 SvxUnoText::SvxUnoText( const SvxUnoText
& rText
) throw()
2191 : SvxUnoTextBase( rText
)
2195 SvxUnoText::~SvxUnoText() throw()
2201 class theSvxUnoTextUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextUnoTunnelId
> {};
2204 const uno::Sequence
< sal_Int8
> & SvxUnoText::getUnoTunnelId() throw()
2206 return theSvxUnoTextUnoTunnelId::get().getSeq();
2209 sal_Int64 SAL_CALL
SvxUnoText::getSomething( const uno::Sequence
< sal_Int8
>& rId
) throw(uno::RuntimeException
) \
2211 if( rId
.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2212 rId
.getConstArray(), 16 ) )
2214 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2218 return SvxUnoTextBase::getSomething( rId
);
2223 // --------------------------------------------------------------------
2225 SvxDummyTextSource::~SvxDummyTextSource()
2229 SvxEditSource
* SvxDummyTextSource::Clone() const
2231 return new SvxDummyTextSource();
2234 SvxTextForwarder
* SvxDummyTextSource::GetTextForwarder()
2239 void SvxDummyTextSource::UpdateData()
2243 sal_uInt16
SvxDummyTextSource::GetParagraphCount() const
2248 sal_uInt16
SvxDummyTextSource::GetTextLen( sal_uInt16
) const
2253 String
SvxDummyTextSource::GetText( const ESelection
& ) const
2258 SfxItemSet
SvxDummyTextSource::GetAttribs( const ESelection
&, sal_Bool
) const
2260 // Very dangerous: The former implementation used a SfxItemPool created on the
2261 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2262 // a deleted Pool by design.
2263 return SfxItemSet(EditEngine::GetGlobalItemPool());
2266 SfxItemSet
SvxDummyTextSource::GetParaAttribs( sal_uInt16
) const
2268 return GetAttribs(ESelection());
2271 void SvxDummyTextSource::SetParaAttribs( sal_uInt16
, const SfxItemSet
& )
2275 void SvxDummyTextSource::RemoveAttribs( const ESelection
& , sal_Bool
, sal_uInt16
)
2279 void SvxDummyTextSource::GetPortions( sal_uInt16
, std::vector
<sal_uInt16
>& ) const
2283 sal_uInt16
SvxDummyTextSource::GetItemState( const ESelection
&, sal_uInt16
) const
2288 sal_uInt16
SvxDummyTextSource::GetItemState( sal_uInt16
, sal_uInt16
) const
2293 SfxItemPool
* SvxDummyTextSource::GetPool() const
2298 void SvxDummyTextSource::QuickInsertText( const String
&, const ESelection
& )
2302 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem
&, const ESelection
& )
2306 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet
&, const ESelection
& )
2310 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection
& )
2314 XubString
SvxDummyTextSource::CalcFieldValue( const SvxFieldItem
&, sal_uInt16
, sal_uInt16
, Color
*&, Color
*& )
2319 void SvxDummyTextSource::FieldClicked( const SvxFieldItem
&, sal_uInt16
, xub_StrLen
)
2323 sal_Bool
SvxDummyTextSource::IsValid() const
2328 void SvxDummyTextSource::SetNotifyHdl( const Link
& )
2332 LanguageType
SvxDummyTextSource::GetLanguage( sal_uInt16
, sal_uInt16
) const
2334 return LANGUAGE_DONTKNOW
;
2337 sal_uInt16
SvxDummyTextSource::GetFieldCount( sal_uInt16
) const
2342 EFieldInfo
SvxDummyTextSource::GetFieldInfo( sal_uInt16
, sal_uInt16
) const
2344 return EFieldInfo();
2347 EBulletInfo
SvxDummyTextSource::GetBulletInfo( sal_uInt16
) const
2349 return EBulletInfo();
2352 Rectangle
SvxDummyTextSource::GetCharBounds( sal_uInt16
, sal_uInt16
) const
2357 Rectangle
SvxDummyTextSource::GetParaBounds( sal_uInt16
) const
2362 MapMode
SvxDummyTextSource::GetMapMode() const
2367 OutputDevice
* SvxDummyTextSource::GetRefDevice() const
2372 sal_Bool
SvxDummyTextSource::GetIndexAtPoint( const Point
&, sal_uInt16
&, sal_uInt16
& ) const
2377 sal_Bool
SvxDummyTextSource::GetWordIndices( sal_uInt16
, sal_uInt16
, sal_uInt16
&, sal_uInt16
& ) const
2382 sal_Bool
SvxDummyTextSource::GetAttributeRun( sal_uInt16
&, sal_uInt16
&, sal_uInt16
, sal_uInt16
) const
2387 sal_uInt16
SvxDummyTextSource::GetLineCount( sal_uInt16
) const
2392 sal_uInt16
SvxDummyTextSource::GetLineLen( sal_uInt16
, sal_uInt16
) const
2397 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_uInt16
&rStart
, /*out*/sal_uInt16
&rEnd
, sal_uInt16
/*nParagraph*/, sal_uInt16
/*nLine*/ ) const
2402 sal_uInt16
SvxDummyTextSource::GetLineNumberAtIndex( sal_uInt16
/*nPara*/, sal_uInt16
/*nIndex*/ ) const
2407 sal_Bool
SvxDummyTextSource::QuickFormatDoc( sal_Bool
)
2412 sal_Int16
SvxDummyTextSource::GetDepth( sal_uInt16
) const
2417 sal_Bool
SvxDummyTextSource::SetDepth( sal_uInt16
, sal_Int16 nNewDepth
)
2419 return nNewDepth
== 0 ? sal_True
: sal_False
;
2422 sal_Bool
SvxDummyTextSource::Delete( const ESelection
& )
2427 sal_Bool
SvxDummyTextSource::InsertText( const String
&, const ESelection
& )
2432 const SfxItemSet
* SvxDummyTextSource::GetEmptyItemSetPtr()
2437 void SvxDummyTextSource::AppendParagraph()
2441 xub_StrLen
SvxDummyTextSource::AppendTextPortion( sal_uInt16
, const String
&, const SfxItemSet
& )
2446 void SvxDummyTextSource::CopyText(const SvxTextForwarder
& )
2450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */