1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/svapp.hxx>
21 #include <com/sun/star/style/LineSpacing.hpp>
22 #include <com/sun/star/text/ControlCharacter.hpp>
23 #include <com/sun/star/text/XTextField.hpp>
24 #include <com/sun/star/text/TextRangeSelection.hpp>
26 #include <osl/mutex.hxx>
27 #include <svl/itemset.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/intitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <rtl/instance.hxx>
33 #include <editeng/fontitem.hxx>
34 #include <editeng/tstpitem.hxx>
35 #include <editeng/unoprnms.hxx>
36 #include <editeng/unotext.hxx>
37 #include <editeng/unoedsrc.hxx>
38 #include <editeng/unonrule.hxx>
39 #include <editeng/unofdesc.hxx>
40 #include <editeng/unofield.hxx>
41 #include <editeng/flditem.hxx>
42 #include <editeng/numitem.hxx>
43 #include <editeng/editeng.hxx>
44 #include <editeng/outliner.hxx>
45 #include <editeng/unoipset.hxx>
46 #include <comphelper/servicehelper.hxx>
47 #include <comphelper/serviceinfohelper.hxx>
48 #include <cppuhelper/supportsservice.hxx>
50 #include "editeng/unonames.hxx"
52 #include <boost/scoped_ptr.hpp>
54 using namespace ::cppu
;
55 using namespace ::com::sun::star
;
59 ESelection
toESelection(const text::TextRangeSelection
& rSel
)
62 aESel
.nStartPara
= rSel
.Start
.Paragraph
;
63 aESel
.nStartPos
= rSel
.Start
.PositionInParagraph
;
64 aESel
.nEndPara
= rSel
.End
.Paragraph
;
65 aESel
.nEndPos
= rSel
.End
.PositionInParagraph
;
71 #define QUERYINT( xint ) \
72 if( rType == cppu::UnoType<xint>::get() ) \
73 return uno::makeAny(uno::Reference< xint >(this))
75 const SvxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet()
77 static SvxItemPropertySet
aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() );
78 return &aTextCursorSvxPropertySet
;
81 const SfxItemPropertyMapEntry
* ImplGetSvxTextPortionPropertyMap()
83 // Propertymap for an Outliner Text
84 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap
[] =
86 SVX_UNOEDIT_CHAR_PROPERTIES
,
87 SVX_UNOEDIT_FONT_PROPERTIES
,
88 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
89 SVX_UNOEDIT_PARA_PROPERTIES
,
90 {OUString("TextField"), EE_FEATURE_FIELD
, cppu::UnoType
<text::XTextField
>::get(), beans::PropertyAttribute::READONLY
, 0 },
91 {OUString("TextPortionType"), WID_PORTIONTYPE
, ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::READONLY
, 0 },
92 {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS
, cppu::UnoType
<com::sun::star::container::XNameContainer
>::get(), 0, 0},
93 {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS
, cppu::UnoType
<com::sun::star::container::XNameContainer
>::get(), 0, 0},
94 { OUString(), 0, css::uno::Type(), 0, 0 }
96 return aSvxTextPortionPropertyMap
;
98 const SvxItemPropertySet
* ImplGetSvxTextPortionSvxPropertySet()
100 static SvxItemPropertySet
aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() );
101 return &aSvxTextPortionPropertySet
;
104 const SfxItemPropertySet
* ImplGetSvxTextPortionSfxPropertySet()
106 static SfxItemPropertySet
aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() );
107 return &aSvxTextPortionSfxPropertySet
;
110 const SfxItemPropertyMapEntry
* ImplGetSvxUnoOutlinerTextCursorPropertyMap()
112 // Propertymap for an Outliner Text
113 static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap
[] =
115 SVX_UNOEDIT_CHAR_PROPERTIES
,
116 SVX_UNOEDIT_FONT_PROPERTIES
,
117 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
118 SVX_UNOEDIT_PARA_PROPERTIES
,
119 {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS
, cppu::UnoType
<com::sun::star::container::XNameContainer
>::get(), 0, 0},
120 {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS
, cppu::UnoType
<com::sun::star::container::XNameContainer
>::get(), 0, 0},
121 { OUString(), 0, css::uno::Type(), 0, 0 }
124 return aSvxUnoOutlinerTextCursorPropertyMap
;
126 const SfxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
128 static SfxItemPropertySet
aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
129 return &aTextCursorSfxPropertySet
;
133 // helper for Item/Property conversion
136 void GetSelection( struct ESelection
& rSel
, SvxTextForwarder
* pForwarder
) throw()
138 DBG_ASSERT( pForwarder
, "I need a valid SvxTextForwarder!" );
141 sal_Int32 nParaCount
= pForwarder
->GetParagraphCount();
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!" );
154 if( rSel
.nStartPara
== EE_PARA_MAX_COUNT
)
156 ::GetSelection( rSel
, pForwarder
);
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()
202 CheckSelection( rSel
, pEdit
->GetTextForwarder() );
206 // class SvxUnoTextRangeBase
209 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase
);
211 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxItemPropertySet
* _pSet
) throw()
212 : mpEditSource(NULL
) , mpPropSet(_pSet
)
216 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
) throw()
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()
236 , beans::XPropertySet()
237 , beans::XMultiPropertySet()
238 , beans::XMultiPropertyStates()
239 , beans::XPropertyState()
240 , lang::XServiceInfo()
241 , text::XTextRangeCompare()
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
;
253 maSelection
= rRange
.maSelection
;
254 CheckSelection( maSelection
, pForwarder
);
258 mpEditSource
->addRange( this );
261 SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw()
264 mpEditSource
->removeRange( this );
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
;
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
;
290 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
293 SvxFieldItem
aField( *pData
, EE_FEATURE_FIELD
);
294 pForwarder
->QuickInsertField( aField
, maSelection
);
299 void SvxUnoTextRangeBase::SetSelection( const ESelection
& rSelection
) throw()
301 SolarMutexGuard aGuard
;
303 maSelection
= rSelection
;
304 CheckSelection( maSelection
, mpEditSource
);
307 // Interface XTextRange ( XText )
309 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getStart()
310 throw( uno::RuntimeException
, std::exception
)
312 SolarMutexGuard aGuard
;
314 uno::Reference
< text::XTextRange
> xRange
;
316 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
319 CheckSelection( maSelection
, pForwarder
);
321 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( getText() );
324 throw uno::RuntimeException();
326 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *pText
);
329 ESelection aNewSel
= maSelection
;
330 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
331 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
332 pRange
->SetSelection( aNewSel
);
338 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getEnd()
339 throw( uno::RuntimeException
, std::exception
)
341 SolarMutexGuard aGuard
;
343 uno::Reference
< text::XTextRange
> xRet
;
345 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
348 CheckSelection( maSelection
, pForwarder
);
350 SvxUnoTextBase
* pText
= SvxUnoTextBase::getImplementation( getText() );
353 throw uno::RuntimeException();
355 SvxUnoTextRange
* pNew
= new SvxUnoTextRange( *pText
);
358 ESelection aNewSel
= maSelection
;
359 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
360 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
361 pNew
->SetSelection( aNewSel
);
366 OUString SAL_CALL
SvxUnoTextRangeBase::getString()
367 throw( uno::RuntimeException
, std::exception
)
369 SolarMutexGuard aGuard
;
371 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
374 CheckSelection( maSelection
, pForwarder
);
376 return pForwarder
->GetText( maSelection
);
380 const OUString aEmpty
;
385 void SAL_CALL
SvxUnoTextRangeBase::setString(const OUString
& aString
)
386 throw( uno::RuntimeException
, std::exception
)
388 SolarMutexGuard aGuard
;
390 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
393 CheckSelection( maSelection
, pForwarder
);
395 OUString
aConverted(convertLineEnd(aString
, LINEEND_LF
)); // Simply count the number of line endings
397 pForwarder
->QuickInsertText( aConverted
, maSelection
);
398 mpEditSource
->UpdateData();
401 //! It would be easier if the EditEngine would return the selection
402 //! on QuickInsertText...
405 sal_Int32 nLen
= aConverted
.getLength();
407 GoRight( nLen
, true );
411 // Interface beans::XPropertySet
412 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SvxUnoTextRangeBase::getPropertySetInfo()
413 throw( uno::RuntimeException
, std::exception
)
415 return mpPropSet
->getPropertySetInfo();
418 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValue(const OUString
& PropertyName
, const uno::Any
& aValue
)
419 throw( beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
421 if (PropertyName
== UNO_TR_PROP_SELECTION
)
423 text::TextRangeSelection aSel
= aValue
.get
<text::TextRangeSelection
>();
424 SetSelection(toESelection(aSel
));
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
;
440 CheckSelection( maSelection
, pForwarder
);
442 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
445 ESelection
aSel( GetSelection() );
446 bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
448 if( nPara
== -1 && !bParaAttrib
)
450 SfxItemSet
aOldSet( pForwarder
->GetAttribs( aSel
) );
451 // we have a selection and no para attribute
452 SfxItemSet
aNewSet( *aOldSet
.GetPool(), aOldSet
.GetRanges() );
454 setPropertyValue( pMap
, aValue
, maSelection
, aOldSet
, aNewSet
);
457 pForwarder
->QuickSetAttribs( aNewSet
, GetSelection() );
465 nPara
= aSel
.nStartPara
;
466 nEndPara
= aSel
.nEndPara
;
470 // only one paragraph
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
);
484 GetEditSource()->UpdateData();
489 throw beans::UnknownPropertyException();
492 void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& rValue
, const ESelection
& rSelection
, const SfxItemSet
& rOldSet
, SfxItemSet
& rNewSet
) throw( beans::UnknownPropertyException
, lang::IllegalArgumentException
)
494 if(!SetPropertyValueHelper( rOldSet
, pMap
, rValue
, rNewSet
, &rSelection
, GetEditSource() ))
496 // For parts of composite items with multiple properties (eg background)
497 // must be taken from the document before the old item.
498 rNewSet
.Put(rOldSet
.Get(pMap
->nWID
)); // Old Item in new Set
499 SvxItemPropertySet::setPropertyValue(pMap
, rValue
, rNewSet
, false );
503 bool SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemSet
&, const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& aValue
, SfxItemSet
& rNewSet
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL*/ )
509 awt::FontDescriptor aDesc
;
512 SvxUnoFontDescriptor::FillItemSet( aDesc
, rNewSet
);
518 case EE_PARA_NUMBULLET
:
520 uno::Reference
< container::XIndexReplace
> xRule
;
521 if( !aValue
.hasValue() || ((aValue
>>= xRule
) && !xRule
.is()) )
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();
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
);
558 case WID_PARAISNUMBERINGRESTART
:
560 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
561 if(pForwarder
&& pSelection
)
563 bool bParaIsNumberingRestart
= false;
564 if( aValue
>>= bParaIsNumberingRestart
)
566 pForwarder
->SetParaIsNumberingRestart( pSelection
->nStartPara
, bParaIsNumberingRestart
);
572 case EE_PARA_BULLETSTATE
:
575 if( aValue
>>= bBullet
)
577 SfxBoolItem
aItem( EE_PARA_BULLETSTATE
, bBullet
);
588 throw lang::IllegalArgumentException();
591 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyValue(const OUString
& PropertyName
)
592 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
594 if (PropertyName
== UNO_TR_PROP_SELECTION
)
596 const ESelection
& rSel
= GetSelection();
597 text::TextRangeSelection aSel
;
598 aSel
.Start
.Paragraph
= rSel
.nStartPara
;
599 aSel
.Start
.PositionInParagraph
= static_cast<sal_Int32
>(rSel
.nStartPos
);
600 aSel
.End
.Paragraph
= rSel
.nEndPara
;
601 aSel
.End
.PositionInParagraph
= static_cast<sal_Int32
>(rSel
.nEndPos
);
602 return uno::makeAny(aSel
);
605 return _getPropertyValue( PropertyName
, -1 );
608 uno::Any SAL_CALL
SvxUnoTextRangeBase::_getPropertyValue(const OUString
& PropertyName
, sal_Int32 nPara
)
609 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
611 SolarMutexGuard aGuard
;
615 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
618 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
621 SfxItemSet
* pAttribs
= NULL
;
623 pAttribs
= pForwarder
->GetParaAttribs( nPara
).Clone();
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
);
637 throw beans::UnknownPropertyException();
640 void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& rAny
, const SfxItemSet
& rSet
)
641 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
645 case EE_FEATURE_FIELD
:
646 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, false ) == SfxItemState::SET
)
648 const SvxFieldItem
* pItem
= static_cast<const SvxFieldItem
*>(rSet
.GetItem( EE_FEATURE_FIELD
));
649 const SvxFieldData
* pData
= pItem
->GetField();
650 uno::Reference
< text::XTextRange
> xAnchor( this );
652 // get presentation string for field
653 Color
* pTColor
= NULL
;
654 Color
* pFColor
= NULL
;
656 SvxTextForwarder
* pForwarder
= mpEditSource
->GetTextForwarder();
657 OUString
aPresentation( pForwarder
->CalcFieldValue( SvxFieldItem(*pData
, EE_FEATURE_FIELD
), maSelection
.nStartPara
, maSelection
.nStartPos
, pTColor
, pFColor
) );
662 uno::Reference
< text::XTextField
> xField( new SvxUnoTextField( xAnchor
, aPresentation
, pData
) );
667 case WID_PORTIONTYPE
:
668 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, false ) == SfxItemState::SET
)
670 OUString
aType("TextField");
675 OUString
aType("Text");
681 if(!GetPropertyValueHelper( *const_cast<SfxItemSet
*>(&rSet
), pMap
, rAny
, &maSelection
, GetEditSource() ))
682 rAny
= SvxItemPropertySet::getPropertyValue(pMap
, rSet
, true, false );
686 bool SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet
& rSet
, const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& aAny
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL */ )
687 throw( uno::RuntimeException
)
693 awt::FontDescriptor aDesc
;
694 SvxUnoFontDescriptor::FillFromItemSet( rSet
, aDesc
);
699 case EE_PARA_NUMBULLET
:
701 SfxItemState eState
= rSet
.GetItemState( EE_PARA_NUMBULLET
, true );
702 if( eState
!= SfxItemState::SET
&& eState
!= SfxItemState::DEFAULT
)
703 throw uno::RuntimeException();
705 const SvxNumBulletItem
* pBulletItem
= static_cast<const SvxNumBulletItem
*>(rSet
.GetItem( EE_PARA_NUMBULLET
, true ));
707 if( pBulletItem
== NULL
)
708 throw uno::RuntimeException();
710 aAny
<<= SvxCreateNumRule( pBulletItem
->GetNumRule() );
716 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
717 if(pForwarder
&& pSelection
)
719 sal_Int16 nLevel
= pForwarder
->GetDepth( pSelection
->nStartPara
);
725 case WID_NUMBERINGSTARTVALUE
:
727 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
728 if(pForwarder
&& pSelection
)
729 aAny
<<= pForwarder
->GetNumberingStartValue( pSelection
->nStartPara
);
732 case WID_PARAISNUMBERINGRESTART
:
734 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : NULL
;
735 if(pForwarder
&& pSelection
)
736 aAny
<<= pForwarder
->IsParaIsNumberingRestart( pSelection
->nStartPara
);
740 case EE_PARA_BULLETSTATE
:
743 SfxItemState eState
= rSet
.GetItemState( EE_PARA_BULLETSTATE
, true );
744 if( eState
== SfxItemState::SET
|| eState
== SfxItemState::DEFAULT
)
746 const SfxBoolItem
* pItem
= static_cast<const SfxBoolItem
*>(rSet
.GetItem( EE_PARA_BULLETSTATE
, true ));
747 bState
= pItem
->GetValue();
761 // is not (yet) supported
762 void SAL_CALL
SvxUnoTextRangeBase::addPropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
763 void SAL_CALL
SvxUnoTextRangeBase::removePropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
764 void SAL_CALL
SvxUnoTextRangeBase::addVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
765 void SAL_CALL
SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
768 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
) throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
770 _setPropertyValues( aPropertyNames
, aValues
, -1 );
773 void SAL_CALL
SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
, sal_Int32 nPara
) throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
775 SolarMutexGuard aGuard
;
777 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
780 CheckSelection( maSelection
, pForwarder
);
782 ESelection
aSel( GetSelection() );
784 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
785 const uno::Any
* pValues
= aValues
.getConstArray();
786 sal_Int32 nCount
= aPropertyNames
.getLength();
788 sal_Int32 nEndPara
= nPara
;
789 sal_Int32 nTempPara
= nPara
;
791 if( nTempPara
== -1 )
793 nTempPara
= aSel
.nStartPara
;
794 nEndPara
= aSel
.nEndPara
;
797 SfxItemSet
* pOldAttrSet
= NULL
;
798 SfxItemSet
* pNewAttrSet
= NULL
;
800 SfxItemSet
* pOldParaSet
= NULL
;
801 SfxItemSet
* pNewParaSet
= NULL
;
803 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
805 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
809 bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
811 if( (nPara
== -1) && !bParaAttrib
)
813 if( NULL
== pNewAttrSet
)
815 const SfxItemSet
aSet( pForwarder
->GetAttribs( aSel
) );
816 pOldAttrSet
= new SfxItemSet( aSet
);
817 pNewAttrSet
= new SfxItemSet( *pOldAttrSet
->GetPool(), pOldAttrSet
->GetRanges() );
820 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldAttrSet
, *pNewAttrSet
);
822 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
824 const SfxPoolItem
* pItem
;
825 if( pNewAttrSet
->GetItemState( pMap
->nWID
, true, &pItem
) == SfxItemState::SET
)
827 pOldAttrSet
->Put( *pItem
);
833 if( NULL
== pNewParaSet
)
835 const SfxItemSet
aSet( pForwarder
->GetParaAttribs( nTempPara
) );
836 pOldParaSet
= new SfxItemSet( aSet
);
837 pNewParaSet
= new SfxItemSet( *pOldParaSet
->GetPool(), pOldParaSet
->GetRanges() );
840 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldParaSet
, *pNewParaSet
);
842 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
844 const SfxPoolItem
* pItem
;
845 if( pNewParaSet
->GetItemState( pMap
->nWID
, true, &pItem
) == SfxItemState::SET
)
847 pOldParaSet
->Put( *pItem
);
855 bool bNeedsUpdate
= false;
859 if( pNewParaSet
->Count() )
861 while( nTempPara
<= nEndPara
)
863 SfxItemSet
aSet( pForwarder
->GetParaAttribs( nTempPara
) );
864 aSet
.Put( *pNewParaSet
);
865 pForwarder
->SetParaAttribs( nTempPara
, aSet
);
877 if( pNewAttrSet
->Count() )
879 pForwarder
->QuickSetAttribs( *pNewAttrSet
, GetSelection() );
888 GetEditSource()->UpdateData();
892 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
) throw (uno::RuntimeException
, std::exception
)
894 return _getPropertyValues( aPropertyNames
, -1 );
897 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, sal_Int32 nPara
) throw (uno::RuntimeException
)
899 SolarMutexGuard aGuard
;
901 sal_Int32 nCount
= aPropertyNames
.getLength();
904 uno::Sequence
< uno::Any
> aValues( nCount
);
906 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
909 SfxItemSet
* pAttribs
= NULL
;
911 pAttribs
= pForwarder
->GetParaAttribs( nPara
).Clone();
913 pAttribs
= pForwarder
->GetAttribs( GetSelection() ).Clone();
915 pAttribs
->ClearInvalidItems();
917 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
918 uno::Any
* pValues
= aValues
.getArray();
920 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
922 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
925 getPropertyValue( pMap
, *pValues
, *pAttribs
);
936 void SAL_CALL
SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence
< OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
, std::exception
)
940 void SAL_CALL
SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
, std::exception
)
944 void SAL_CALL
SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence
< OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& ) throw (uno::RuntimeException
, std::exception
)
948 // beans::XPropertyState
949 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::getPropertyState( const OUString
& PropertyName
)
950 throw(beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
952 return _getPropertyState( PropertyName
, -1 );
955 static const sal_uInt16 aSvxUnoFontDescriptorWhichMap
[] = { EE_CHAR_FONTINFO
, EE_CHAR_FONTHEIGHT
, EE_CHAR_ITALIC
,
956 EE_CHAR_UNDERLINE
, EE_CHAR_WEIGHT
, EE_CHAR_STRIKEOUT
, EE_CHAR_CASEMAP
,
959 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
960 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
964 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
967 SfxItemState eItemState
= SfxItemState::UNKNOWN
;
974 const sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
975 SfxItemState eTempItemState
= SfxItemState::UNKNOWN
;
979 eTempItemState
= pForwarder
->GetItemState( nPara
, *pWhichId
);
981 eTempItemState
= pForwarder
->GetItemState( GetSelection(), *pWhichId
);
983 switch( eTempItemState
)
985 case SfxItemState::DISABLED
:
986 case SfxItemState::DONTCARE
:
987 eItemState
= SfxItemState::DONTCARE
;
990 case SfxItemState::DEFAULT
:
991 if( eItemState
!= SfxItemState::DEFAULT
)
993 if( eItemState
== SfxItemState::UNKNOWN
)
994 eItemState
= SfxItemState::DEFAULT
;
998 case SfxItemState::READONLY
:
999 case SfxItemState::SET
:
1000 if( eItemState
!= SfxItemState::SET
)
1002 if( eItemState
== SfxItemState::UNKNOWN
)
1003 eItemState
= SfxItemState::SET
;
1007 throw beans::UnknownPropertyException();
1016 case WID_NUMBERINGSTARTVALUE
:
1017 case WID_PARAISNUMBERINGRESTART
:
1018 eItemState
= SfxItemState::SET
;
1028 eItemState
= pForwarder
->GetItemState( nPara
, nWID
);
1030 eItemState
= pForwarder
->GetItemState( GetSelection(), nWID
);
1033 switch( eItemState
)
1035 case SfxItemState::DONTCARE
:
1036 case SfxItemState::DISABLED
:
1037 return beans::PropertyState_AMBIGUOUS_VALUE
;
1038 case SfxItemState::READONLY
:
1039 case SfxItemState::SET
:
1040 return beans::PropertyState_DIRECT_VALUE
;
1041 case SfxItemState::DEFAULT
:
1042 return beans::PropertyState_DEFAULT_VALUE
;
1044 // case SfxItemState::UNKNOWN:
1048 throw beans::UnknownPropertyException();
1051 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::_getPropertyState(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1052 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1054 SolarMutexGuard aGuard
;
1056 return _getPropertyState( mpPropSet
->getPropertyMapEntry( PropertyName
), nPara
);
1059 uno::Sequence
< beans::PropertyState
> SAL_CALL
SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence
< OUString
>& aPropertyName
)
1060 throw(beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
1062 return _getPropertyStates( aPropertyName
, -1 );
1065 uno::Sequence
< beans::PropertyState
> SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence
< OUString
>& PropertyName
, sal_Int32 nPara
/* = -1 */)
1066 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1068 const sal_Int32 nCount
= PropertyName
.getLength();
1069 const OUString
* pNames
= PropertyName
.getConstArray();
1071 uno::Sequence
< beans::PropertyState
> aRet( nCount
);
1072 beans::PropertyState
* pState
= aRet
.getArray();
1074 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1077 SfxItemSet
* pSet
= NULL
;
1080 pSet
= new SfxItemSet( pForwarder
->GetParaAttribs( nPara
) );
1084 ESelection
aSel( GetSelection() );
1085 CheckSelection( aSel
, pForwarder
);
1086 pSet
= new SfxItemSet( pForwarder
->GetAttribs( aSel
, EditEngineAttribs_OnlyHard
) );
1089 bool bUnknownPropertyFound
= false;
1090 for( sal_Int32 nIdx
= 0; nIdx
< nCount
; nIdx
++ )
1092 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pNames
++ );
1095 bUnknownPropertyFound
= true;
1098 bUnknownPropertyFound
= !_getOnePropertyStates(pSet
, pMap
, *pState
++);
1103 if( bUnknownPropertyFound
)
1104 throw beans::UnknownPropertyException();
1110 bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet
* pSet
, const SfxItemPropertySimpleEntry
* pMap
, beans::PropertyState
& rState
)
1112 bool bUnknownPropertyFound
= false;
1115 SfxItemState eItemState
= SfxItemState::UNKNOWN
;
1116 sal_uInt16 nWID
= 0;
1118 switch( pMap
->nWID
)
1122 const sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
1123 SfxItemState eTempItemState
= SfxItemState::UNKNOWN
;
1126 eTempItemState
= pSet
->GetItemState( *pWhichId
);
1128 switch( eTempItemState
)
1130 case SfxItemState::DISABLED
:
1131 case SfxItemState::DONTCARE
:
1132 eItemState
= SfxItemState::DONTCARE
;
1135 case SfxItemState::DEFAULT
:
1136 if( eItemState
!= SfxItemState::DEFAULT
)
1138 if( eItemState
== SfxItemState::UNKNOWN
)
1139 eItemState
= SfxItemState::DEFAULT
;
1143 case SfxItemState::READONLY
:
1144 case SfxItemState::SET
:
1145 if( eItemState
!= SfxItemState::SET
)
1147 if( eItemState
== SfxItemState::UNKNOWN
)
1148 eItemState
= SfxItemState::SET
;
1152 bUnknownPropertyFound
= true;
1162 case WID_NUMBERINGSTARTVALUE
:
1163 case WID_PARAISNUMBERINGRESTART
:
1164 eItemState
= SfxItemState::SET
;
1171 if( bUnknownPropertyFound
)
1172 return !bUnknownPropertyFound
;
1175 eItemState
= pSet
->GetItemState( nWID
, false );
1177 switch( eItemState
)
1179 case SfxItemState::READONLY
:
1180 case SfxItemState::SET
:
1181 rState
= beans::PropertyState_DIRECT_VALUE
;
1183 case SfxItemState::DEFAULT
:
1184 rState
= beans::PropertyState_DEFAULT_VALUE
;
1186 // case SfxItemState::UNKNOWN:
1187 // case SfxItemState::DONTCARE:
1188 // case SfxItemState::DISABLED:
1190 rState
= beans::PropertyState_AMBIGUOUS_VALUE
;
1193 return !bUnknownPropertyFound
;
1196 void SAL_CALL
SvxUnoTextRangeBase::setPropertyToDefault( const OUString
& PropertyName
)
1197 throw(beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
1199 _setPropertyToDefault( PropertyName
, -1 );
1202 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1203 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1205 SolarMutexGuard aGuard
;
1207 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1211 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( PropertyName
);
1214 CheckSelection( maSelection
, mpEditSource
->GetTextForwarder() );
1215 _setPropertyToDefault( pForwarder
, pMap
, nPara
);
1220 throw beans::UnknownPropertyException();
1223 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder
* pForwarder
, const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
1224 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
1228 SfxItemSet
aSet( *pForwarder
->GetPool(), true );
1230 if( pMap
->nWID
== WID_FONTDESC
)
1232 SvxUnoFontDescriptor::setPropertyToDefault( aSet
);
1234 else if( pMap
->nWID
== WID_NUMLEVEL
)
1236 // #101004# Call interface method instead of unsafe cast
1237 pForwarder
->SetDepth( maSelection
.nStartPara
, -1 );
1240 else if( pMap
->nWID
== WID_NUMBERINGSTARTVALUE
)
1242 pForwarder
->SetNumberingStartValue( maSelection
.nStartPara
, -1 );
1244 else if( pMap
->nWID
== WID_PARAISNUMBERINGRESTART
)
1246 pForwarder
->SetParaIsNumberingRestart( maSelection
.nStartPara
, false );
1250 aSet
.InvalidateItem( pMap
->nWID
);
1254 pForwarder
->SetParaAttribs( nPara
, aSet
);
1256 pForwarder
->QuickSetAttribs( aSet
, GetSelection() );
1258 GetEditSource()->UpdateData();
1265 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyDefault( const OUString
& aPropertyName
)
1266 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1268 SolarMutexGuard aGuard
;
1270 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1273 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( aPropertyName
);
1276 SfxItemPool
* pPool
= pForwarder
->GetPool();
1278 switch( pMap
->nWID
)
1281 return SvxUnoFontDescriptor::getPropertyDefault( pPool
);
1289 case WID_NUMBERINGSTARTVALUE
:
1290 return uno::Any( (sal_Int16
)-1 );
1292 case WID_PARAISNUMBERINGRESTART
:
1293 return uno::Any( false );
1297 // Get Default from ItemPool
1298 if(SfxItemPool::IsWhich(pMap
->nWID
))
1300 SfxItemSet
aSet( *pPool
, pMap
->nWID
, pMap
->nWID
);
1301 aSet
.Put(pPool
->GetDefaultItem(pMap
->nWID
));
1302 return SvxItemPropertySet::getPropertyValue(pMap
, aSet
, true, false );
1308 throw beans::UnknownPropertyException();
1311 // beans::XMultiPropertyStates
1312 void SAL_CALL
SvxUnoTextRangeBase::setAllPropertiesToDefault()
1313 throw (uno::RuntimeException
, std::exception
)
1315 SolarMutexGuard aGuard
;
1317 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1321 PropertyEntryVector_t aEntries
= mpPropSet
->getPropertyMap().getPropertyEntries();
1322 PropertyEntryVector_t::const_iterator aIt
= aEntries
.begin();
1323 while( aIt
!= aEntries
.end() )
1325 _setPropertyToDefault( pForwarder
, &(*aIt
), -1 );
1331 void SAL_CALL
SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence
< OUString
>& aPropertyNames
) throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
1333 sal_Int32 nCount
= aPropertyNames
.getLength();
1334 for( const OUString
* pName
= aPropertyNames
.getConstArray(); nCount
; pName
++, nCount
-- )
1336 setPropertyToDefault( *pName
);
1340 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence
< OUString
>& aPropertyNames
) throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
1342 sal_Int32 nCount
= aPropertyNames
.getLength();
1343 uno::Sequence
< uno::Any
> ret( nCount
);
1344 uno::Any
* pDefaults
= ret
.getArray();
1346 for( const OUString
* pName
= aPropertyNames
.getConstArray(); nCount
; pName
++, nCount
--, pDefaults
++ )
1348 *pDefaults
= getPropertyDefault( *pName
);
1355 void SvxUnoTextRangeBase::CollapseToStart() throw()
1357 CheckSelection( maSelection
, mpEditSource
);
1359 maSelection
.nEndPara
= maSelection
.nStartPara
;
1360 maSelection
.nEndPos
= maSelection
.nStartPos
;
1363 void SvxUnoTextRangeBase::CollapseToEnd() throw()
1365 CheckSelection( maSelection
, mpEditSource
);
1367 maSelection
.nStartPara
= maSelection
.nEndPara
;
1368 maSelection
.nStartPos
= maSelection
.nEndPos
;
1371 bool SvxUnoTextRangeBase::IsCollapsed() throw()
1373 CheckSelection( maSelection
, mpEditSource
);
1375 return ( maSelection
.nStartPara
== maSelection
.nEndPara
&&
1376 maSelection
.nStartPos
== maSelection
.nEndPos
);
1379 bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount
, bool Expand
) throw()
1381 CheckSelection( maSelection
, mpEditSource
);
1383 // #75098# use end position, as in Writer (start is anchor, end is cursor)
1384 sal_uInt16 nNewPos
= maSelection
.nEndPos
;
1385 sal_Int32 nNewPar
= maSelection
.nEndPara
;
1388 SvxTextForwarder
* pForwarder
= NULL
;
1389 while ( nCount
> nNewPos
&& bOk
)
1396 pForwarder
= mpEditSource
->GetTextForwarder(); // first here, it is necessary...
1399 nCount
-= nNewPos
+ 1;
1400 nNewPos
= pForwarder
->GetTextLen( nNewPar
);
1406 nNewPos
= nNewPos
- nCount
;
1407 maSelection
.nStartPara
= nNewPar
;
1408 maSelection
.nStartPos
= nNewPos
;
1417 bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount
, bool Expand
) throw()
1419 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1422 CheckSelection( maSelection
, pForwarder
);
1424 sal_Int32 nNewPos
= maSelection
.nEndPos
+ nCount
; //! Overflow???
1425 sal_Int32 nNewPar
= maSelection
.nEndPara
;
1428 sal_Int32 nParCount
= pForwarder
->GetParagraphCount();
1429 sal_Int32 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1430 while ( nNewPos
> nThisLen
&& bOk
)
1432 if ( nNewPar
+ 1 >= nParCount
)
1436 nNewPos
-= nThisLen
+1;
1438 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1444 maSelection
.nEndPara
= nNewPar
;
1445 maSelection
.nEndPos
= nNewPos
;
1456 void SvxUnoTextRangeBase::GotoStart(bool Expand
) throw()
1458 maSelection
.nStartPara
= 0;
1459 maSelection
.nStartPos
= 0;
1465 void SvxUnoTextRangeBase::GotoEnd(bool Expand
) throw()
1467 CheckSelection( maSelection
, mpEditSource
);
1469 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : NULL
;
1473 sal_Int32 nPar
= pForwarder
->GetParagraphCount();
1477 maSelection
.nEndPara
= nPar
;
1478 maSelection
.nEndPos
= pForwarder
->GetTextLen( nPar
);
1485 // lang::XServiceInfo
1486 sal_Bool SAL_CALL
SvxUnoTextRangeBase::supportsService( const OUString
& ServiceName
)
1487 throw(uno::RuntimeException
, std::exception
)
1489 return cppu::supportsService( this, ServiceName
);
1492 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextRangeBase::getSupportedServiceNames()
1493 throw(uno::RuntimeException
, std::exception
)
1495 return getSupportedServiceNames_Static();
1498 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1500 uno::Sequence
< OUString
> aSeq(3);
1501 aSeq
[0] = "com.sun.star.style.CharacterProperties";
1502 aSeq
[1] = "com.sun.star.style.CharacterPropertiesComplex";
1503 aSeq
[2] = "com.sun.star.style.CharacterPropertiesAsian";
1507 // XTextRangeCompare
1508 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
) throw (lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1510 SvxUnoTextRangeBase
* pR1
= SvxUnoTextRangeBase::getImplementation( xR1
);
1511 SvxUnoTextRangeBase
* pR2
= SvxUnoTextRangeBase::getImplementation( xR2
);
1513 if( (pR1
== 0) || (pR2
== 0) )
1514 throw lang::IllegalArgumentException();
1516 const ESelection
& r1
= pR1
->maSelection
;
1517 const ESelection
& r2
= pR2
->maSelection
;
1519 if( r1
.nStartPara
== r2
.nStartPara
)
1521 if( r1
.nStartPos
== r2
.nStartPos
)
1524 return r1
.nStartPos
< r2
.nStartPos
? 1 : -1;
1528 return r1
.nStartPara
< r2
.nStartPara
? 1 : -1;
1532 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
) throw (lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1534 SvxUnoTextRangeBase
* pR1
= SvxUnoTextRangeBase::getImplementation( xR1
);
1535 SvxUnoTextRangeBase
* pR2
= SvxUnoTextRangeBase::getImplementation( xR2
);
1537 if( (pR1
== 0) || (pR2
== 0) )
1538 throw lang::IllegalArgumentException();
1540 const ESelection
& r1
= pR1
->maSelection
;
1541 const ESelection
& r2
= pR2
->maSelection
;
1543 if( r1
.nEndPara
== r2
.nEndPara
)
1545 if( r1
.nEndPos
== r2
.nEndPos
)
1548 return r1
.nEndPos
< r2
.nEndPos
? 1 : -1;
1552 return r1
.nEndPara
< r2
.nEndPara
? 1 : -1;
1556 SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase
& rParent
, bool bPortion
/* = false */ ) throw()
1557 :SvxUnoTextRangeBase( rParent
.GetEditSource(), bPortion
? ImplGetSvxTextPortionSvxPropertySet() : rParent
.getPropertySet() ),
1558 mbPortion( bPortion
)
1560 xParentText
= (text::XText
*)&rParent
;
1563 SvxUnoTextRange::~SvxUnoTextRange() throw()
1567 uno::Any SAL_CALL
SvxUnoTextRange::queryAggregation( const uno::Type
& rType
)
1568 throw(uno::RuntimeException
, std::exception
)
1570 QUERYINT( text::XTextRange
);
1571 else if( rType
== cppu::UnoType
<beans::XMultiPropertyStates
>::get())
1572 return uno::makeAny(uno::Reference
< beans::XMultiPropertyStates
>(this));
1573 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
1574 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(this));
1575 else QUERYINT( beans::XPropertyState
);
1576 else QUERYINT( text::XTextRangeCompare
);
1577 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
1578 return uno::makeAny(uno::Reference
< beans::XMultiPropertySet
>(this));
1579 else QUERYINT( lang::XServiceInfo
);
1580 else QUERYINT( lang::XTypeProvider
);
1581 else QUERYINT( lang::XUnoTunnel
);
1583 return OWeakAggObject::queryAggregation( rType
);
1586 uno::Any SAL_CALL
SvxUnoTextRange::queryInterface( const uno::Type
& rType
)
1587 throw(uno::RuntimeException
, std::exception
)
1589 return OWeakAggObject::queryInterface(rType
);
1592 void SAL_CALL
SvxUnoTextRange::acquire()
1595 OWeakAggObject::acquire();
1598 void SAL_CALL
SvxUnoTextRange::release()
1601 OWeakAggObject::release();
1608 struct theSvxUnoTextRangeTypes
:
1609 public rtl::StaticWithInit
<uno::Sequence
<uno::Type
>, theSvxUnoTextRangeTypes
>
1611 uno::Sequence
<uno::Type
> operator () ()
1613 uno::Sequence
< uno::Type
> aTypeSequence
;
1615 aTypeSequence
.realloc( 9 ); // !DANGER! keep this updated
1616 uno::Type
* pTypes
= aTypeSequence
.getArray();
1618 *pTypes
++ = cppu::UnoType
<text::XTextRange
>::get();
1619 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
1620 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
1621 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertyStates
>::get();
1622 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
1623 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
1624 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
1625 *pTypes
++ = cppu::UnoType
<lang::XUnoTunnel
>::get();
1626 *pTypes
++ = cppu::UnoType
<text::XTextRangeCompare
>::get();
1628 return aTypeSequence
;
1633 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextRange::getTypes()
1634 throw (uno::RuntimeException
, std::exception
)
1636 return theSvxUnoTextRangeTypes::get();
1639 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextRange::getImplementationId()
1640 throw (uno::RuntimeException
, std::exception
)
1642 return css::uno::Sequence
<sal_Int8
>();
1646 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextRange::getText()
1647 throw(uno::RuntimeException
, std::exception
)
1652 // lang::XServiceInfo
1653 OUString SAL_CALL
SvxUnoTextRange::getImplementationName()
1654 throw(uno::RuntimeException
, std::exception
)
1656 return OUString("SvxUnoTextRange");
1663 SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet
* _pSet
) throw()
1664 : SvxUnoTextRangeBase( _pSet
)
1668 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> xParent
) throw()
1669 : SvxUnoTextRangeBase( pSource
, _pSet
)
1671 xParentText
= xParent
;
1672 ESelection aSelection
;
1673 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1674 SetSelection( aSelection
);
1677 SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase
& rText
) throw()
1678 : SvxUnoTextRangeBase( rText
)
1679 , text::XTextAppend()
1681 , container::XEnumerationAccess()
1682 , text::XTextRangeMover()
1683 , lang::XTypeProvider()
1685 xParentText
= rText
.xParentText
;
1688 SvxUnoTextBase::~SvxUnoTextBase() throw()
1693 uno::Any SAL_CALL
SvxUnoTextBase::queryAggregation( const uno::Type
& rType
)
1694 throw(uno::RuntimeException
, std::exception
)
1696 QUERYINT( text::XText
);
1697 QUERYINT( text::XSimpleText
);
1698 if( rType
== cppu::UnoType
<text::XTextRange
>::get())
1699 return uno::makeAny(uno::Reference
< text::XTextRange
>((text::XText
*)(this)));
1700 QUERYINT(container::XEnumerationAccess
);
1701 QUERYINT( container::XElementAccess
);
1702 QUERYINT( beans::XMultiPropertyStates
);
1703 QUERYINT( beans::XPropertySet
);
1704 QUERYINT( beans::XMultiPropertySet
);
1705 QUERYINT( beans::XPropertyState
);
1706 QUERYINT( text::XTextRangeCompare
);
1707 QUERYINT( lang::XServiceInfo
);
1708 QUERYINT( text::XTextRangeMover
);
1709 QUERYINT( text::XTextCopy
);
1710 QUERYINT( text::XTextAppend
);
1711 QUERYINT( text::XParagraphAppend
);
1712 QUERYINT( text::XTextPortionAppend
);
1713 QUERYINT( lang::XTypeProvider
);
1714 QUERYINT( lang::XUnoTunnel
);
1723 struct theSvxUnoTextBaseTypes
:
1724 public rtl::StaticWithInit
<uno::Sequence
<uno::Type
>, theSvxUnoTextBaseTypes
>
1726 uno::Sequence
<uno::Type
> operator () ()
1728 uno::Sequence
< uno::Type
> aTypeSequence
;
1730 aTypeSequence
.realloc( 15 ); // !DANGER! keep this updated
1731 uno::Type
* pTypes
= aTypeSequence
.getArray();
1733 *pTypes
++ = cppu::UnoType
<text::XText
>::get();
1734 *pTypes
++ = cppu::UnoType
<container::XEnumerationAccess
>::get();
1735 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
1736 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
1737 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertyStates
>::get();
1738 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
1739 *pTypes
++ = cppu::UnoType
<text::XTextRangeMover
>::get();
1740 *pTypes
++ = cppu::UnoType
<text::XTextAppend
>::get();
1741 *pTypes
++ = cppu::UnoType
<text::XTextCopy
>::get();
1742 *pTypes
++ = cppu::UnoType
<text::XParagraphAppend
>::get();
1743 *pTypes
++ = cppu::UnoType
<text::XTextPortionAppend
>::get();
1744 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
1745 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
1746 *pTypes
++ = cppu::UnoType
<lang::XUnoTunnel
>::get();
1747 *pTypes
++ = cppu::UnoType
<text::XTextRangeCompare
>::get();
1749 return aTypeSequence
;
1753 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextBase::getStaticTypes() throw()
1755 return theSvxUnoTextBaseTypes::get();
1758 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextBase::getTypes()
1759 throw (uno::RuntimeException
, std::exception
)
1761 return getStaticTypes();
1764 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextBase::getImplementationId()
1765 throw (uno::RuntimeException
, std::exception
)
1767 return css::uno::Sequence
<sal_Int8
>();
1770 uno::Reference
< text::XTextCursor
> SvxUnoTextBase::createTextCursorBySelection( const ESelection
& rSel
)
1772 SvxUnoTextCursor
* pCursor
= new SvxUnoTextCursor( *this );
1773 uno::Reference
< text::XTextCursor
> xCursor( pCursor
);
1774 pCursor
->SetSelection( rSel
);
1780 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursor()
1781 throw(uno::RuntimeException
, std::exception
)
1783 SolarMutexGuard aGuard
;
1784 return new SvxUnoTextCursor( *this );
1787 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursorByRange( const uno::Reference
< text::XTextRange
>& aTextPosition
)
1788 throw(uno::RuntimeException
, std::exception
)
1790 SolarMutexGuard aGuard
;
1792 uno::Reference
< text::XTextCursor
> xCursor
;
1794 if( aTextPosition
.is() )
1796 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRangeBase::getImplementation( aTextPosition
);
1798 xCursor
= createTextCursorBySelection( pRange
->GetSelection() );
1804 void SAL_CALL
SvxUnoTextBase::insertString( const uno::Reference
< text::XTextRange
>& xRange
, const OUString
& aString
, sal_Bool bAbsorb
)
1805 throw(uno::RuntimeException
, std::exception
)
1807 SolarMutexGuard aGuard
;
1812 ESelection aSelection
;
1813 if (GetEditSource())
1815 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1816 SetSelection( aSelection
);
1819 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1822 // setString on SvxUnoTextRangeBase instead of itself QuickInsertText
1823 // and UpdateData, so that the selection will be adjusted to
1824 // SvxUnoTextRangeBase. Actually all cursor objects of this Text must
1825 // to be statement to be adapted!
1827 if (!bAbsorb
) // do not replace -> append on tail
1828 pRange
->CollapseToEnd();
1830 pRange
->setString( aString
);
1832 pRange
->CollapseToEnd();
1836 void SAL_CALL
SvxUnoTextBase::insertControlCharacter( const uno::Reference
< text::XTextRange
>& xRange
, sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
1837 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1839 SolarMutexGuard aGuard
;
1841 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL
;
1845 ESelection aSelection
;
1846 ::GetSelection( aSelection
, pForwarder
);
1847 SetSelection( aSelection
);
1849 switch( nControlCharacter
)
1851 case text::ControlCharacter::PARAGRAPH_BREAK
:
1853 const OUString
aText( (sal_Unicode
)13 ); // '\r' does not work on Mac
1854 insertString( xRange
, aText
, bAbsorb
);
1858 case text::ControlCharacter::LINE_BREAK
:
1860 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1863 ESelection aRange
= pRange
->GetSelection();
1867 const OUString aEmpty
;
1868 pForwarder
->QuickInsertText( aEmpty
, aRange
);
1870 aRange
.nEndPos
= aRange
.nStartPos
;
1871 aRange
.nEndPara
= aRange
.nStartPara
;
1875 aRange
.nStartPara
= aRange
.nEndPara
;
1876 aRange
.nStartPos
= aRange
.nEndPos
;
1879 pForwarder
->QuickInsertLineBreak( aRange
);
1880 GetEditSource()->UpdateData();
1882 aRange
.nEndPos
+= 1;
1884 aRange
.nStartPos
+= 1;
1886 pRange
->SetSelection( aRange
);
1890 case text::ControlCharacter::APPEND_PARAGRAPH
:
1892 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xRange
);
1895 ESelection aRange
= pRange
->GetSelection();
1896 // ESelection aOldSelection = aRange;
1898 aRange
.nStartPos
= pForwarder
->GetTextLen( aRange
.nStartPara
);
1900 aRange
.nEndPara
= aRange
.nStartPara
;
1901 aRange
.nEndPos
= aRange
.nStartPos
;
1903 pRange
->SetSelection( aRange
);
1904 const OUString
aText( (sal_Unicode
)13 ); // '\r' geht auf'm Mac nicht
1905 pRange
->setString( aText
);
1907 aRange
.nStartPos
= 0;
1908 aRange
.nStartPara
+= 1;
1910 aRange
.nEndPara
+= 1;
1912 pRange
->SetSelection( aRange
);
1918 throw lang::IllegalArgumentException();
1924 void SAL_CALL
SvxUnoTextBase::insertTextContent( const uno::Reference
< text::XTextRange
>& xRange
, const uno::Reference
< text::XTextContent
>& xContent
, sal_Bool bAbsorb
)
1925 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
1927 SolarMutexGuard aGuard
;
1929 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL
;
1933 uno::Reference
<beans::XPropertySet
> xPropSet(xRange
, uno::UNO_QUERY
);
1935 throw lang::IllegalArgumentException();
1937 uno::Any aAny
= xPropSet
->getPropertyValue(UNO_TR_PROP_SELECTION
);
1938 text::TextRangeSelection aSel
= aAny
.get
<text::TextRangeSelection
>();
1940 aSel
.Start
= aSel
.End
;
1942 boost::scoped_ptr
<SvxFieldData
> pFieldData(SvxFieldData::Create(xContent
));
1944 throw lang::IllegalArgumentException();
1946 SvxFieldItem
aField( *pFieldData
, EE_FEATURE_FIELD
);
1947 pForwarder
->QuickInsertField(aField
, toESelection(aSel
));
1948 GetEditSource()->UpdateData();
1950 uno::Reference
<beans::XPropertySet
> xPropSetContent(xContent
, uno::UNO_QUERY
);
1952 throw lang::IllegalArgumentException();
1954 xPropSetContent
->setPropertyValue(UNO_TC_PROP_ANCHOR
, uno::makeAny(xRange
));
1956 aSel
.End
.PositionInParagraph
+= 1;
1957 aSel
.Start
.PositionInParagraph
= aSel
.End
.PositionInParagraph
;
1958 xPropSet
->setPropertyValue(UNO_TR_PROP_SELECTION
, uno::makeAny(aSel
));
1961 void SAL_CALL
SvxUnoTextBase::removeTextContent( const uno::Reference
< text::XTextContent
>& ) throw(container::NoSuchElementException
, uno::RuntimeException
, std::exception
)
1967 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextBase::getText()
1968 throw(uno::RuntimeException
, std::exception
)
1970 SolarMutexGuard aGuard
;
1972 if (GetEditSource())
1974 ESelection aSelection
;
1975 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1976 SetSelection( aSelection
);
1979 return (text::XText
*)this;
1982 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getStart()
1983 throw(uno::RuntimeException
, std::exception
)
1985 return SvxUnoTextRangeBase::getStart();
1988 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getEnd()
1989 throw(uno::RuntimeException
, std::exception
)
1991 return SvxUnoTextRangeBase::getEnd();
1994 OUString SAL_CALL
SvxUnoTextBase::getString() throw( uno::RuntimeException
, std::exception
)
1996 return SvxUnoTextRangeBase::getString();
1999 void SAL_CALL
SvxUnoTextBase::setString( const OUString
& aString
) throw(uno::RuntimeException
, std::exception
)
2001 SvxUnoTextRangeBase::setString(aString
);
2005 // XEnumerationAccess
2006 uno::Reference
< container::XEnumeration
> SAL_CALL
SvxUnoTextBase::createEnumeration()
2007 throw(uno::RuntimeException
, std::exception
)
2009 SolarMutexGuard aGuard
;
2011 ESelection aSelection
;
2012 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
2013 SetSelection( aSelection
);
2015 uno::Reference
< container::XEnumeration
> xEnum( (container::XEnumeration
*) new SvxUnoTextContentEnumeration( *this ) );
2019 // XElementAccess ( container::XEnumerationAccess )
2020 uno::Type SAL_CALL
SvxUnoTextBase::getElementType( ) throw(uno::RuntimeException
, std::exception
)
2022 return cppu::UnoType
<text::XTextRange
>::get();
2025 sal_Bool SAL_CALL
SvxUnoTextBase::hasElements( ) throw(uno::RuntimeException
, std::exception
)
2027 SolarMutexGuard aGuard
;
2031 SvxTextForwarder
* pForwarder
= GetEditSource()->GetTextForwarder();
2033 return pForwarder
->GetParagraphCount() != 0;
2039 // text::XTextRangeMover
2040 void SAL_CALL
SvxUnoTextBase::moveTextRange( const uno::Reference
< text::XTextRange
>&, sal_Int16
)
2041 throw(uno::RuntimeException
, std::exception
)
2045 void SvxPropertyValuesToItemSet(
2046 SfxItemSet
&rItemSet
,
2047 const uno::Sequence
< beans::PropertyValue
>& rPropertyVaules
,
2048 const SfxItemPropertySet
*pPropSet
,
2049 SvxTextForwarder
*pForwarder
/*needed for WID_NUMLEVEL*/,
2050 sal_Int32 nPara
/*needed for WID_NUMLEVEL*/)
2051 throw(lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
)
2053 sal_Int32 nProps
= rPropertyVaules
.getLength();
2054 const beans::PropertyValue
*pProps
= rPropertyVaules
.getConstArray();
2055 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
2057 const SfxItemPropertySimpleEntry
*pEntry
= pPropSet
->getPropertyMap().getByName( pProps
[i
].Name
);
2060 // Note: there is no need to take special care of the properties
2061 // TextField (EE_FEATURE_FIELD) and
2062 // TextPortionType (WID_PORTIONTYPE)
2063 // since they are read-only and thus are already taken care of below.
2065 if (pEntry
->nFlags
& beans::PropertyAttribute::READONLY
)
2066 // should be PropertyVetoException which is not yet defined for the new import API's functions
2067 throw uno::RuntimeException("Property is read-only: " + pProps
[i
].Name
, static_cast < cppu::OWeakObject
* > ( 0 ) );
2068 //throw PropertyVetoException ("Property is read-only: " + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2070 if (pEntry
->nWID
== WID_FONTDESC
)
2072 awt::FontDescriptor aDesc
;
2073 if (pProps
[i
].Value
>>= aDesc
)
2074 SvxUnoFontDescriptor::FillItemSet( aDesc
, rItemSet
);
2076 else if (pEntry
->nWID
== WID_NUMLEVEL
)
2080 sal_Int16 nLevel
= -1;
2081 pProps
[i
].Value
>>= nLevel
;
2083 // #101004# Call interface method instead of unsafe cast
2084 if (!pForwarder
->SetDepth( nPara
, nLevel
))
2085 throw lang::IllegalArgumentException();
2088 else if (pEntry
->nWID
== WID_NUMBERINGSTARTVALUE
)
2092 sal_Int16 nStartValue
= -1;
2093 if( !(pProps
[i
].Value
>>= nStartValue
) )
2094 throw lang::IllegalArgumentException();
2096 pForwarder
->SetNumberingStartValue( nPara
, nStartValue
);
2099 else if (pEntry
->nWID
== WID_PARAISNUMBERINGRESTART
)
2103 bool bParaIsNumberingRestart
= false;
2104 if( !(pProps
[i
].Value
>>= bParaIsNumberingRestart
) )
2105 throw lang::IllegalArgumentException();
2107 pForwarder
->SetParaIsNumberingRestart( nPara
, bParaIsNumberingRestart
);
2111 pPropSet
->setPropertyValue( pProps
[i
].Name
, pProps
[i
].Value
, rItemSet
);
2114 throw beans::UnknownPropertyException( "Unknown property: " + pProps
[i
].Name
, static_cast < cppu::OWeakObject
* > ( 0 ) );
2118 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::finishParagraphInsert(
2119 const uno::Sequence
< beans::PropertyValue
>& /*rCharAndParaProps*/,
2120 const uno::Reference
< text::XTextRange
>& /*rTextRange*/ )
2121 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
2123 uno::Reference
< text::XTextRange
> xRet
;
2127 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::finishParagraph(
2128 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2129 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
2131 SolarMutexGuard aGuard
;
2133 uno::Reference
< text::XTextRange
> xRet
;
2134 SvxEditSource
*pEditSource
= GetEditSource();
2135 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2138 sal_Int32 nParaCount
= pTextForwarder
->GetParagraphCount();
2139 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2140 pTextForwarder
->AppendParagraph();
2142 // set properties for the previously last paragraph
2143 sal_Int32 nPara
= nParaCount
- 1;
2144 ESelection
aSel( nPara
, 0, nPara
, 0 );
2145 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2146 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2147 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder
, nPara
);
2148 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2149 pEditSource
->UpdateData();
2150 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2152 pRange
->SetSelection( aSel
);
2157 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::insertTextPortion(
2158 const OUString
& /*rText*/,
2159 const uno::Sequence
< beans::PropertyValue
>& /*rCharAndParaProps*/,
2160 const uno::Reference
< text::XTextRange
>& /*rTextRange*/ )
2161 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
2163 uno::Reference
< text::XTextRange
> xRet
;
2167 // com::sun::star::text::XTextPortionAppend (new import API)
2168 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::appendTextPortion(
2169 const OUString
& rText
,
2170 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2171 throw (lang::IllegalArgumentException
, beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
2173 SolarMutexGuard aGuard
;
2175 SvxEditSource
*pEditSource
= GetEditSource();
2176 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2177 uno::Reference
< text::XTextRange
> xRet
;
2180 sal_Int32 nParaCount
= pTextForwarder
->GetParagraphCount();
2181 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2182 sal_Int32 nPara
= nParaCount
- 1;
2183 SfxItemSet
aSet( pTextForwarder
->GetParaAttribs( nPara
) );
2184 sal_Int32 nStart
= pTextForwarder
->AppendTextPortion( nPara
, rText
, aSet
);
2185 pEditSource
->UpdateData();
2186 sal_Int32 nEnd
= pTextForwarder
->GetTextLen( nPara
);
2188 // set properties for the new text portion
2189 ESelection
aSel( nPara
, nStart
, nPara
, nEnd
);
2190 pTextForwarder
->RemoveAttribs( aSel
, false, 0 );
2191 pEditSource
->UpdateData();
2193 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2194 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2195 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder
, nPara
);
2196 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2197 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2199 pRange
->SetSelection( aSel
);
2200 const beans::PropertyValue
* pProps
= rCharAndParaProps
.getConstArray();
2201 for( sal_Int32 nProp
= 0; nProp
< rCharAndParaProps
.getLength(); ++nProp
)
2202 pRange
->setPropertyValue( pProps
[nProp
].Name
, pProps
[nProp
].Value
);
2207 void SvxUnoTextBase::copyText(
2208 const uno::Reference
< text::XTextCopy
>& xSource
) throw ( uno::RuntimeException
, std::exception
)
2210 SolarMutexGuard aGuard
;
2211 uno::Reference
< lang::XUnoTunnel
> xUT( xSource
, uno::UNO_QUERY
);
2212 SvxEditSource
*pEditSource
= GetEditSource();
2213 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : 0;
2214 if( !pTextForwarder
)
2218 SvxUnoTextBase
* pSource
= reinterpret_cast<SvxUnoTextBase
*>(sal::static_int_cast
<sal_uIntPtr
>(
2219 xUT
->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2220 SvxEditSource
*pSourceEditSource
= pSource
->GetEditSource();
2221 SvxTextForwarder
*pSourceTextForwarder
= pSourceEditSource
? pSourceEditSource
->GetTextForwarder() : 0;
2222 if( pSourceTextForwarder
)
2224 pTextForwarder
->CopyText( *pSourceTextForwarder
);
2225 pEditSource
->UpdateData();
2230 uno::Reference
< text::XText
> xSourceText( xSource
, uno::UNO_QUERY
);
2231 if( xSourceText
.is() )
2233 setString( xSourceText
->getString() );
2238 // lang::XServiceInfo
2239 OUString SAL_CALL
SvxUnoTextBase::getImplementationName()
2240 throw(uno::RuntimeException
, std::exception
)
2242 return OUString("SvxUnoTextBase");
2245 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames( )
2246 throw(uno::RuntimeException
, std::exception
)
2248 return getSupportedServiceNames_Static();
2251 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames_Static( )
2253 uno::Sequence
< OUString
> aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() );
2254 comphelper::ServiceInfoHelper::addToSequence( aSeq
, 1, "com.sun.star.text.Text" );
2260 class theSvxUnoTextBaseUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextBaseUnoTunnelId
> {};
2263 const uno::Sequence
< sal_Int8
> & SvxUnoTextBase::getUnoTunnelId() throw()
2265 return theSvxUnoTextBaseUnoTunnelId::get().getSeq();
2268 SvxUnoTextBase
* SvxUnoTextBase::getImplementation( const uno::Reference
< uno::XInterface
>& xInt
)
2270 uno::Reference
< lang::XUnoTunnel
> xUT( xInt
, uno::UNO_QUERY
);
2272 return reinterpret_cast<SvxUnoTextBase
*>(sal::static_int_cast
<sal_uIntPtr
>(xUT
->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2277 sal_Int64 SAL_CALL
SvxUnoTextBase::getSomething( const uno::Sequence
< sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
) \
2279 if( rId
.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2280 rId
.getConstArray(), 16 ) )
2282 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2286 return SvxUnoTextRangeBase::getSomething( rId
);
2290 SvxUnoText::SvxUnoText( const SvxItemPropertySet
* _pSet
) throw()
2291 : SvxUnoTextBase( _pSet
)
2295 SvxUnoText::SvxUnoText( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> xParent
) throw()
2296 : SvxUnoTextBase( pSource
, _pSet
, xParent
)
2300 SvxUnoText::SvxUnoText( const SvxUnoText
& rText
) throw()
2301 : SvxUnoTextBase( rText
)
2302 , cppu::OWeakAggObject()
2306 SvxUnoText::~SvxUnoText() throw()
2311 uno::Any SAL_CALL
SvxUnoText::queryAggregation( const uno::Type
& rType
) throw( uno::RuntimeException
, std::exception
)
2313 uno::Any
aAny( SvxUnoTextBase::queryAggregation( rType
) );
2314 if( !aAny
.hasValue() )
2315 aAny
= OWeakAggObject::queryAggregation( rType
);
2320 uno::Any SAL_CALL
SvxUnoText::queryInterface( const uno::Type
& rType
) throw( uno::RuntimeException
, std::exception
)
2322 return OWeakAggObject::queryInterface( rType
);
2325 void SAL_CALL
SvxUnoText::acquire() throw( )
2327 OWeakAggObject::acquire();
2330 void SAL_CALL
SvxUnoText::release() throw( )
2332 OWeakAggObject::release();
2335 // lang::XTypeProvider
2336 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoText::getTypes( ) throw( uno::RuntimeException
, std::exception
)
2338 return SvxUnoTextBase::getTypes();
2341 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoText::getImplementationId( ) throw( uno::RuntimeException
, std::exception
)
2343 return css::uno::Sequence
<sal_Int8
>();
2348 class theSvxUnoTextUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextUnoTunnelId
> {};
2351 const uno::Sequence
< sal_Int8
> & SvxUnoText::getUnoTunnelId() throw()
2353 return theSvxUnoTextUnoTunnelId::get().getSeq();
2356 sal_Int64 SAL_CALL
SvxUnoText::getSomething( const uno::Sequence
< sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
) \
2358 if( rId
.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
2359 rId
.getConstArray(), 16 ) )
2361 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2365 return SvxUnoTextBase::getSomething( rId
);
2372 SvxDummyTextSource::~SvxDummyTextSource()
2376 SvxEditSource
* SvxDummyTextSource::Clone() const
2378 return new SvxDummyTextSource();
2381 SvxTextForwarder
* SvxDummyTextSource::GetTextForwarder()
2386 void SvxDummyTextSource::UpdateData()
2390 sal_Int32
SvxDummyTextSource::GetParagraphCount() const
2395 sal_Int32
SvxDummyTextSource::GetTextLen( sal_Int32
) const
2400 OUString
SvxDummyTextSource::GetText( const ESelection
& ) const
2405 SfxItemSet
SvxDummyTextSource::GetAttribs( const ESelection
&, EditEngineAttribs
) const
2407 // Very dangerous: The former implementation used a SfxItemPool created on the
2408 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2409 // a deleted Pool by design.
2410 return SfxItemSet(EditEngine::GetGlobalItemPool());
2413 SfxItemSet
SvxDummyTextSource::GetParaAttribs( sal_Int32
) const
2415 return GetAttribs(ESelection());
2418 void SvxDummyTextSource::SetParaAttribs( sal_Int32
, const SfxItemSet
& )
2422 void SvxDummyTextSource::RemoveAttribs( const ESelection
& , bool , sal_uInt16
)
2426 void SvxDummyTextSource::GetPortions( sal_Int32
, std::vector
<sal_Int32
>& ) const
2430 SfxItemState
SvxDummyTextSource::GetItemState( const ESelection
&, sal_uInt16
) const
2432 return SfxItemState::UNKNOWN
;
2435 SfxItemState
SvxDummyTextSource::GetItemState( sal_Int32
, sal_uInt16
) const
2437 return SfxItemState::UNKNOWN
;
2440 SfxItemPool
* SvxDummyTextSource::GetPool() const
2445 void SvxDummyTextSource::QuickInsertText( const OUString
&, const ESelection
& )
2449 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem
&, const ESelection
& )
2453 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet
&, const ESelection
& )
2457 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection
& )
2461 OUString
SvxDummyTextSource::CalcFieldValue( const SvxFieldItem
&, sal_Int32
, sal_Int32
, Color
*&, Color
*& )
2466 void SvxDummyTextSource::FieldClicked( const SvxFieldItem
&, sal_Int32
, sal_Int32
)
2470 bool SvxDummyTextSource::IsValid() const
2475 LanguageType
SvxDummyTextSource::GetLanguage( sal_Int32
, sal_Int32
) const
2477 return LANGUAGE_DONTKNOW
;
2480 sal_Int32
SvxDummyTextSource::GetFieldCount( sal_Int32
) const
2485 EFieldInfo
SvxDummyTextSource::GetFieldInfo( sal_Int32
, sal_uInt16
) const
2487 return EFieldInfo();
2490 EBulletInfo
SvxDummyTextSource::GetBulletInfo( sal_Int32
) const
2492 return EBulletInfo();
2495 Rectangle
SvxDummyTextSource::GetCharBounds( sal_Int32
, sal_Int32
) const
2500 Rectangle
SvxDummyTextSource::GetParaBounds( sal_Int32
) const
2505 MapMode
SvxDummyTextSource::GetMapMode() const
2510 OutputDevice
* SvxDummyTextSource::GetRefDevice() const
2515 bool SvxDummyTextSource::GetIndexAtPoint( const Point
&, sal_Int32
&, sal_Int32
& ) const
2520 bool SvxDummyTextSource::GetWordIndices( sal_Int32
, sal_Int32
, sal_Int32
&, sal_Int32
& ) const
2525 bool SvxDummyTextSource::GetAttributeRun( sal_Int32
&, sal_Int32
&, sal_Int32
, sal_Int32
, bool ) const
2530 sal_Int32
SvxDummyTextSource::GetLineCount( sal_Int32
) const
2535 sal_Int32
SvxDummyTextSource::GetLineLen( sal_Int32
, sal_Int32
) const
2540 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_Int32
&rStart
, /*out*/sal_Int32
&rEnd
, sal_Int32
/*nParagraph*/, sal_Int32
/*nLine*/ ) const
2545 sal_Int32
SvxDummyTextSource::GetLineNumberAtIndex( sal_Int32
/*nPara*/, sal_Int32
/*nIndex*/ ) const
2550 bool SvxDummyTextSource::QuickFormatDoc( bool )
2555 sal_Int16
SvxDummyTextSource::GetDepth( sal_Int32
) const
2560 bool SvxDummyTextSource::SetDepth( sal_Int32
, sal_Int16 nNewDepth
)
2562 return nNewDepth
== 0;
2565 bool SvxDummyTextSource::Delete( const ESelection
& )
2570 bool SvxDummyTextSource::InsertText( const OUString
&, const ESelection
& )
2575 const SfxItemSet
* SvxDummyTextSource::GetEmptyItemSetPtr()
2580 void SvxDummyTextSource::AppendParagraph()
2584 sal_Int32
SvxDummyTextSource::AppendTextPortion( sal_Int32
, const OUString
&, const SfxItemSet
& )
2589 void SvxDummyTextSource::CopyText(const SvxTextForwarder
& )
2593 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */