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/text/ControlCharacter.hpp>
22 #include <com/sun/star/text/XTextField.hpp>
23 #include <com/sun/star/text/TextRangeSelection.hpp>
24 #include <com/sun/star/lang/Locale.hpp>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <svl/itemset.hxx>
29 #include <svl/itempool.hxx>
30 #include <svl/eitem.hxx>
31 #include <rtl/instance.hxx>
32 #include <tools/debug.hxx>
34 #include <editeng/unoprnms.hxx>
35 #include <editeng/unotext.hxx>
36 #include <editeng/unoedsrc.hxx>
37 #include <editeng/unonrule.hxx>
38 #include <editeng/unofdesc.hxx>
39 #include <editeng/unofield.hxx>
40 #include <editeng/flditem.hxx>
41 #include <editeng/numitem.hxx>
42 #include <editeng/editeng.hxx>
43 #include <editeng/outliner.hxx>
44 #include <editeng/unoipset.hxx>
45 #include <comphelper/sequence.hxx>
46 #include <comphelper/servicehelper.hxx>
47 #include <cppuhelper/supportsservice.hxx>
49 #include <editeng/unonames.hxx>
51 #include <initializer_list>
53 #include <string_view>
55 using namespace ::cppu
;
56 using namespace ::com::sun::star
;
60 ESelection
toESelection(const text::TextRangeSelection
& rSel
)
63 aESel
.nStartPara
= rSel
.Start
.Paragraph
;
64 aESel
.nStartPos
= rSel
.Start
.PositionInParagraph
;
65 aESel
.nEndPara
= rSel
.End
.Paragraph
;
66 aESel
.nEndPos
= rSel
.End
.PositionInParagraph
;
72 #define QUERYINT( xint ) \
73 if( rType == cppu::UnoType<xint>::get() ) \
74 return uno::makeAny(uno::Reference< xint >(this))
76 const SvxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet()
78 static SvxItemPropertySet
aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() );
79 return &aTextCursorSvxPropertySet
;
82 const SfxItemPropertyMapEntry
* ImplGetSvxTextPortionPropertyMap()
84 // Propertymap for an Outliner Text
85 static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap
[] =
87 SVX_UNOEDIT_CHAR_PROPERTIES
,
88 SVX_UNOEDIT_FONT_PROPERTIES
,
89 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
90 SVX_UNOEDIT_PARA_PROPERTIES
,
91 { u
"TextField", EE_FEATURE_FIELD
, cppu::UnoType
<text::XTextField
>::get(), beans::PropertyAttribute::READONLY
, 0 },
92 { u
"TextPortionType", WID_PORTIONTYPE
, ::cppu::UnoType
<OUString
>::get(), beans::PropertyAttribute::READONLY
, 0 },
93 { u
"TextUserDefinedAttributes", EE_CHAR_XMLATTRIBS
, cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
94 { u
"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS
, cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
95 { u
"", 0, css::uno::Type(), 0, 0 }
97 return aSvxTextPortionPropertyMap
;
99 const SvxItemPropertySet
* ImplGetSvxTextPortionSvxPropertySet()
101 static SvxItemPropertySet
aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() );
102 return &aSvxTextPortionPropertySet
;
105 static const SfxItemPropertySet
* ImplGetSvxTextPortionSfxPropertySet()
107 static SfxItemPropertySet
aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() );
108 return &aSvxTextPortionSfxPropertySet
;
111 const SfxItemPropertyMapEntry
* ImplGetSvxUnoOutlinerTextCursorPropertyMap()
113 // Propertymap for an Outliner Text
114 static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap
[] =
116 SVX_UNOEDIT_CHAR_PROPERTIES
,
117 SVX_UNOEDIT_FONT_PROPERTIES
,
118 SVX_UNOEDIT_OUTLINER_PROPERTIES
,
119 SVX_UNOEDIT_PARA_PROPERTIES
,
120 { u
"TextUserDefinedAttributes", EE_CHAR_XMLATTRIBS
, cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
121 { u
"ParaUserDefinedAttributes", EE_PARA_XMLATTRIBS
, cppu::UnoType
<css::container::XNameContainer
>::get(), 0, 0},
122 { u
"", 0, css::uno::Type(), 0, 0 }
125 return aSvxUnoOutlinerTextCursorPropertyMap
;
127 static const SfxItemPropertySet
* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
129 static SfxItemPropertySet
aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
130 return &aTextCursorSfxPropertySet
;
134 // helper for Item/Property conversion
137 void GetSelection( struct ESelection
& rSel
, SvxTextForwarder
const * pForwarder
) throw()
139 DBG_ASSERT( pForwarder
, "I need a valid SvxTextForwarder!" );
142 sal_Int32 nParaCount
= pForwarder
->GetParagraphCount();
146 rSel
= ESelection( 0,0, nParaCount
, pForwarder
->GetTextLen( nParaCount
));
150 void CheckSelection( struct ESelection
& rSel
, SvxTextForwarder
const * pForwarder
) throw()
152 DBG_ASSERT( pForwarder
, "I need a valid SvxTextForwarder!" );
156 if( rSel
.nStartPara
== EE_PARA_MAX_COUNT
)
158 ::GetSelection( rSel
, pForwarder
);
162 ESelection aMaxSelection
;
163 GetSelection( aMaxSelection
, pForwarder
);
165 // check start position
166 if( rSel
.nStartPara
< aMaxSelection
.nStartPara
)
168 rSel
.nStartPara
= aMaxSelection
.nStartPara
;
169 rSel
.nStartPos
= aMaxSelection
.nStartPos
;
171 else if( rSel
.nStartPara
> aMaxSelection
.nEndPara
)
173 rSel
.nStartPara
= aMaxSelection
.nEndPara
;
174 rSel
.nStartPos
= aMaxSelection
.nEndPos
;
176 else if( rSel
.nStartPos
> pForwarder
->GetTextLen( rSel
.nStartPara
) )
178 rSel
.nStartPos
= pForwarder
->GetTextLen( rSel
.nStartPara
);
181 // check end position
182 if( rSel
.nEndPara
< aMaxSelection
.nStartPara
)
184 rSel
.nEndPara
= aMaxSelection
.nStartPara
;
185 rSel
.nEndPos
= aMaxSelection
.nStartPos
;
187 else if( rSel
.nEndPara
> aMaxSelection
.nEndPara
)
189 rSel
.nEndPara
= aMaxSelection
.nEndPara
;
190 rSel
.nEndPos
= aMaxSelection
.nEndPos
;
192 else if( rSel
.nEndPos
> pForwarder
->GetTextLen( rSel
.nEndPara
) )
194 rSel
.nEndPos
= pForwarder
->GetTextLen( rSel
.nEndPara
);
199 static void CheckSelection( struct ESelection
& rSel
, SvxEditSource
*pEdit
) throw()
203 CheckSelection( rSel
, pEdit
->GetTextForwarder() );
209 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase
);
211 SvxUnoTextRangeBase::SvxUnoTextRangeBase(const SvxItemPropertySet
* _pSet
)
216 SvxUnoTextRangeBase::SvxUnoTextRangeBase(const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
)
219 SolarMutexGuard aGuard
;
221 DBG_ASSERT(pSource
,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
223 mpEditSource
= pSource
->Clone();
224 if (mpEditSource
!= nullptr)
226 ESelection aSelection
;
227 ::GetSelection( aSelection
, mpEditSource
->GetTextForwarder() );
228 SetSelection( aSelection
);
230 mpEditSource
->addRange( this );
234 SvxUnoTextRangeBase::SvxUnoTextRangeBase(const SvxUnoTextRangeBase
& rRange
)
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 if (rRange
.mpEditSource
)
249 mpEditSource
= rRange
.mpEditSource
->Clone();
251 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
254 maSelection
= rRange
.maSelection
;
255 CheckSelection( maSelection
, pForwarder
);
259 mpEditSource
->addRange( this );
262 SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw()
265 mpEditSource
->removeRange( this );
268 void SvxUnoTextRangeBase::SetEditSource( SvxEditSource
* pSource
) throw()
270 DBG_ASSERT(pSource
,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
271 DBG_ASSERT(mpEditSource
==nullptr,"SvxUnoTextRangeBase::SetEditSource called while SvxEditSource already set" );
273 mpEditSource
.reset( pSource
);
275 maSelection
.nStartPara
= EE_PARA_MAX_COUNT
;
278 mpEditSource
->addRange( this );
281 /** puts a field item with a copy of the given FieldData into the itemset
282 corresponding with this range */
283 void SvxUnoTextRangeBase::attachField( std::unique_ptr
<SvxFieldData
> pData
) throw()
285 SolarMutexGuard aGuard
;
287 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
290 SvxFieldItem
aField( std::move(pData
), EE_FEATURE_FIELD
);
291 pForwarder
->QuickInsertField( std::move(aField
), maSelection
);
295 void SvxUnoTextRangeBase::SetSelection( const ESelection
& rSelection
) throw()
297 SolarMutexGuard aGuard
;
299 maSelection
= rSelection
;
300 CheckSelection( maSelection
, mpEditSource
.get() );
303 // Interface XTextRange ( XText )
305 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getStart()
307 SolarMutexGuard aGuard
;
309 uno::Reference
< text::XTextRange
> xRange
;
311 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
314 CheckSelection( maSelection
, pForwarder
);
316 SvxUnoTextBase
* pText
= comphelper::getUnoTunnelImplementation
<SvxUnoTextBase
>( getText() );
319 throw uno::RuntimeException();
321 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *pText
);
324 ESelection aNewSel
= maSelection
;
325 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
326 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
327 pRange
->SetSelection( aNewSel
);
333 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextRangeBase::getEnd()
335 SolarMutexGuard aGuard
;
337 uno::Reference
< text::XTextRange
> xRet
;
339 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
342 CheckSelection( maSelection
, pForwarder
);
344 SvxUnoTextBase
* pText
= comphelper::getUnoTunnelImplementation
<SvxUnoTextBase
>( getText() );
347 throw uno::RuntimeException();
349 SvxUnoTextRange
* pNew
= new SvxUnoTextRange( *pText
);
352 ESelection aNewSel
= maSelection
;
353 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
354 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
355 pNew
->SetSelection( aNewSel
);
360 OUString SAL_CALL
SvxUnoTextRangeBase::getString()
362 SolarMutexGuard aGuard
;
364 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
367 CheckSelection( maSelection
, pForwarder
);
369 return pForwarder
->GetText( maSelection
);
377 void SAL_CALL
SvxUnoTextRangeBase::setString(const OUString
& aString
)
379 SolarMutexGuard aGuard
;
381 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
385 CheckSelection( maSelection
, pForwarder
);
387 OUString
aConverted(convertLineEnd(aString
, LINEEND_LF
)); // Simply count the number of line endings
389 pForwarder
->QuickInsertText( aConverted
, maSelection
);
390 mpEditSource
->UpdateData();
393 //! It would be easier if the EditEngine would return the selection
394 //! on QuickInsertText...
397 sal_Int32 nLen
= aConverted
.getLength();
399 GoRight( nLen
, true );
402 // Interface beans::XPropertySet
403 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SvxUnoTextRangeBase::getPropertySetInfo()
405 return mpPropSet
->getPropertySetInfo();
408 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValue(const OUString
& PropertyName
, const uno::Any
& aValue
)
410 if (PropertyName
== UNO_TR_PROP_SELECTION
)
412 text::TextRangeSelection aSel
= aValue
.get
<text::TextRangeSelection
>();
413 SetSelection(toESelection(aSel
));
418 _setPropertyValue( PropertyName
, aValue
);
421 void SvxUnoTextRangeBase::_setPropertyValue( const OUString
& PropertyName
, const uno::Any
& aValue
, sal_Int32 nPara
)
423 SolarMutexGuard aGuard
;
425 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
428 CheckSelection( maSelection
, pForwarder
);
430 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
433 ESelection
aSel( GetSelection() );
434 bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
436 if( nPara
== -1 && !bParaAttrib
)
438 SfxItemSet
aOldSet( pForwarder
->GetAttribs( aSel
) );
439 // we have a selection and no para attribute
440 SfxItemSet
aNewSet( *aOldSet
.GetPool(), aOldSet
.GetRanges() );
442 setPropertyValue( pMap
, aValue
, maSelection
, aOldSet
, aNewSet
);
445 pForwarder
->QuickSetAttribs( aNewSet
, GetSelection() );
453 nPara
= aSel
.nStartPara
;
454 nEndPara
= aSel
.nEndPara
;
458 // only one paragraph
462 while( nPara
<= nEndPara
)
464 // we have a paragraph
465 SfxItemSet
aSet( pForwarder
->GetParaAttribs( nPara
) );
466 setPropertyValue( pMap
, aValue
, maSelection
, aSet
, aSet
);
467 pForwarder
->SetParaAttribs( nPara
, aSet
);
472 GetEditSource()->UpdateData();
477 throw beans::UnknownPropertyException(PropertyName
);
480 void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& rValue
, const ESelection
& rSelection
, const SfxItemSet
& rOldSet
, SfxItemSet
& rNewSet
)
482 if(!SetPropertyValueHelper( pMap
, rValue
, rNewSet
, &rSelection
, GetEditSource() ))
484 // For parts of composite items with multiple properties (eg background)
485 // must be taken from the document before the old item.
486 rNewSet
.Put(rOldSet
.Get(pMap
->nWID
)); // Old Item in new Set
487 SvxItemPropertySet::setPropertyValue(pMap
, rValue
, rNewSet
, false );
491 bool SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemPropertySimpleEntry
* pMap
, const uno::Any
& aValue
, SfxItemSet
& rNewSet
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL*/ )
497 awt::FontDescriptor aDesc
;
500 SvxUnoFontDescriptor::FillItemSet( aDesc
, rNewSet
);
506 case EE_PARA_NUMBULLET
:
508 uno::Reference
< container::XIndexReplace
> xRule
;
509 return !aValue
.hasValue() || ((aValue
>>= xRule
) && !xRule
.is());
514 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
515 if(pForwarder
&& pSelection
)
517 sal_Int16 nLevel
= sal_Int16();
518 if( aValue
>>= nLevel
)
520 // #101004# Call interface method instead of unsafe cast
521 if(! pForwarder
->SetDepth( pSelection
->nStartPara
, nLevel
) )
522 throw lang::IllegalArgumentException();
529 case WID_NUMBERINGSTARTVALUE
:
531 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
532 if(pForwarder
&& pSelection
)
534 sal_Int16 nStartValue
= -1;
535 if( aValue
>>= nStartValue
)
537 pForwarder
->SetNumberingStartValue( pSelection
->nStartPara
, nStartValue
);
543 case WID_PARAISNUMBERINGRESTART
:
545 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
546 if(pForwarder
&& pSelection
)
548 bool bParaIsNumberingRestart
= false;
549 if( aValue
>>= bParaIsNumberingRestart
)
551 pForwarder
->SetParaIsNumberingRestart( pSelection
->nStartPara
, bParaIsNumberingRestart
);
557 case EE_PARA_BULLETSTATE
:
560 if( aValue
>>= bBullet
)
562 SfxBoolItem
aItem( EE_PARA_BULLETSTATE
, bBullet
);
573 throw lang::IllegalArgumentException();
576 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyValue(const OUString
& PropertyName
)
578 if (PropertyName
== UNO_TR_PROP_SELECTION
)
580 const ESelection
& rSel
= GetSelection();
581 text::TextRangeSelection aSel
;
582 aSel
.Start
.Paragraph
= rSel
.nStartPara
;
583 aSel
.Start
.PositionInParagraph
= rSel
.nStartPos
;
584 aSel
.End
.Paragraph
= rSel
.nEndPara
;
585 aSel
.End
.PositionInParagraph
= rSel
.nEndPos
;
586 return uno::makeAny(aSel
);
589 return _getPropertyValue( PropertyName
);
592 uno::Any
SvxUnoTextRangeBase::_getPropertyValue(const OUString
& PropertyName
, sal_Int32 nPara
)
594 SolarMutexGuard aGuard
;
598 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
601 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry(PropertyName
);
604 std::unique_ptr
<SfxItemSet
> pAttribs
;
606 pAttribs
= pForwarder
->GetParaAttribs( nPara
).Clone();
608 pAttribs
= pForwarder
->GetAttribs( GetSelection() ).Clone();
610 // Replace Dontcare with Default, so that one always has a mirror
611 pAttribs
->ClearInvalidItems();
613 getPropertyValue( pMap
, aAny
, *pAttribs
);
619 throw beans::UnknownPropertyException(PropertyName
);
622 void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& rAny
, const SfxItemSet
& rSet
)
626 case EE_FEATURE_FIELD
:
627 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, false ) == SfxItemState::SET
)
629 const SvxFieldItem
* pItem
= rSet
.GetItem
<SvxFieldItem
>( EE_FEATURE_FIELD
);
630 const SvxFieldData
* pData
= pItem
->GetField();
631 uno::Reference
< text::XTextRange
> xAnchor( this );
633 // get presentation string for field
634 std::optional
<Color
> pTColor
;
635 std::optional
<Color
> pFColor
;
637 SvxTextForwarder
* pForwarder
= mpEditSource
->GetTextForwarder();
638 OUString
aPresentation( pForwarder
->CalcFieldValue( SvxFieldItem(*pData
, EE_FEATURE_FIELD
), maSelection
.nStartPara
, maSelection
.nStartPos
, pTColor
, pFColor
) );
640 uno::Reference
< text::XTextField
> xField( new SvxUnoTextField( xAnchor
, aPresentation
, pData
) );
645 case WID_PORTIONTYPE
:
646 if ( rSet
.GetItemState( EE_FEATURE_FIELD
, false ) == SfxItemState::SET
)
648 rAny
<<= OUString("TextField");
652 rAny
<<= OUString("Text");
657 if(!GetPropertyValueHelper( *const_cast<SfxItemSet
*>(&rSet
), pMap
, rAny
, &maSelection
, GetEditSource() ))
658 rAny
= SvxItemPropertySet::getPropertyValue(pMap
, rSet
, true, false );
662 bool SvxUnoTextRangeBase::GetPropertyValueHelper( SfxItemSet
const & rSet
, const SfxItemPropertySimpleEntry
* pMap
, uno::Any
& aAny
, const ESelection
* pSelection
/* = NULL */, SvxEditSource
* pEditSource
/* = NULL */ )
668 awt::FontDescriptor aDesc
;
669 SvxUnoFontDescriptor::FillFromItemSet( rSet
, aDesc
);
674 case EE_PARA_NUMBULLET
:
676 SfxItemState eState
= rSet
.GetItemState( EE_PARA_NUMBULLET
);
677 if( eState
!= SfxItemState::SET
&& eState
!= SfxItemState::DEFAULT
)
678 throw uno::RuntimeException();
680 const SvxNumBulletItem
* pBulletItem
= rSet
.GetItem( EE_PARA_NUMBULLET
);
682 if( pBulletItem
== nullptr )
683 throw uno::RuntimeException();
685 aAny
<<= SvxCreateNumRule( pBulletItem
->GetNumRule() );
691 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
692 if(pForwarder
&& pSelection
)
694 sal_Int16 nLevel
= pForwarder
->GetDepth( pSelection
->nStartPara
);
700 case WID_NUMBERINGSTARTVALUE
:
702 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
703 if(pForwarder
&& pSelection
)
704 aAny
<<= pForwarder
->GetNumberingStartValue( pSelection
->nStartPara
);
707 case WID_PARAISNUMBERINGRESTART
:
709 SvxTextForwarder
* pForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
710 if(pForwarder
&& pSelection
)
711 aAny
<<= pForwarder
->IsParaIsNumberingRestart( pSelection
->nStartPara
);
715 case EE_PARA_BULLETSTATE
:
718 SfxItemState eState
= rSet
.GetItemState( EE_PARA_BULLETSTATE
);
719 if( eState
== SfxItemState::SET
|| eState
== SfxItemState::DEFAULT
)
721 const SfxBoolItem
* pItem
= rSet
.GetItem
<SfxBoolItem
>( EE_PARA_BULLETSTATE
);
722 bState
= pItem
->GetValue();
736 // is not (yet) supported
737 void SAL_CALL
SvxUnoTextRangeBase::addPropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) {}
738 void SAL_CALL
SvxUnoTextRangeBase::removePropertyChangeListener( const OUString
& , const uno::Reference
< beans::XPropertyChangeListener
>& ) {}
739 void SAL_CALL
SvxUnoTextRangeBase::addVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) {}
740 void SAL_CALL
SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString
& , const uno::Reference
< beans::XVetoableChangeListener
>& ) {}
743 void SAL_CALL
SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
)
745 _setPropertyValues( aPropertyNames
, aValues
);
748 void SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, const uno::Sequence
< uno::Any
>& aValues
, sal_Int32 nPara
)
750 SolarMutexGuard aGuard
;
752 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
756 CheckSelection( maSelection
, pForwarder
);
758 ESelection
aSel( GetSelection() );
760 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
761 const uno::Any
* pValues
= aValues
.getConstArray();
762 sal_Int32 nCount
= aPropertyNames
.getLength();
764 sal_Int32 nEndPara
= nPara
;
765 sal_Int32 nTempPara
= nPara
;
767 if( nTempPara
== -1 )
769 nTempPara
= aSel
.nStartPara
;
770 nEndPara
= aSel
.nEndPara
;
773 std::unique_ptr
<SfxItemSet
> pOldAttrSet
;
774 std::unique_ptr
<SfxItemSet
> pNewAttrSet
;
776 std::unique_ptr
<SfxItemSet
> pOldParaSet
;
777 std::unique_ptr
<SfxItemSet
> pNewParaSet
;
779 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
781 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
785 bool bParaAttrib
= (pMap
->nWID
>= EE_PARA_START
) && ( pMap
->nWID
<= EE_PARA_END
);
787 if( (nPara
== -1) && !bParaAttrib
)
789 if( nullptr == pNewAttrSet
)
791 const SfxItemSet
aSet( pForwarder
->GetAttribs( aSel
) );
792 pOldAttrSet
.reset(new SfxItemSet( aSet
));
793 pNewAttrSet
.reset(new SfxItemSet( *pOldAttrSet
->GetPool(), pOldAttrSet
->GetRanges() ));
796 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldAttrSet
, *pNewAttrSet
);
798 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
800 const SfxPoolItem
* pItem
;
801 if( pNewAttrSet
->GetItemState( pMap
->nWID
, true, &pItem
) == SfxItemState::SET
)
803 pOldAttrSet
->Put( *pItem
);
809 if( nullptr == pNewParaSet
)
811 const SfxItemSet
& rSet
= pForwarder
->GetParaAttribs( nTempPara
);
812 pOldParaSet
.reset(new SfxItemSet( rSet
));
813 pNewParaSet
.reset(new SfxItemSet( *pOldParaSet
->GetPool(), pOldParaSet
->GetRanges() ));
816 setPropertyValue( pMap
, *pValues
, GetSelection(), *pOldParaSet
, *pNewParaSet
);
818 if( pMap
->nWID
>= EE_ITEMS_START
&& pMap
->nWID
<= EE_ITEMS_END
)
820 const SfxPoolItem
* pItem
;
821 if( pNewParaSet
->GetItemState( pMap
->nWID
, true, &pItem
) == SfxItemState::SET
)
823 pOldParaSet
->Put( *pItem
);
831 bool bNeedsUpdate
= false;
835 if( pNewParaSet
->Count() )
837 while( nTempPara
<= nEndPara
)
839 SfxItemSet
aSet( pForwarder
->GetParaAttribs( nTempPara
) );
840 aSet
.Put( *pNewParaSet
);
841 pForwarder
->SetParaAttribs( nTempPara
, aSet
);
853 if( pNewAttrSet
->Count() )
855 pForwarder
->QuickSetAttribs( *pNewAttrSet
, GetSelection() );
863 GetEditSource()->UpdateData();
866 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
)
868 return _getPropertyValues( aPropertyNames
);
871 uno::Sequence
< uno::Any
> SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence
< OUString
>& aPropertyNames
, sal_Int32 nPara
)
873 SolarMutexGuard aGuard
;
875 sal_Int32 nCount
= aPropertyNames
.getLength();
878 uno::Sequence
< uno::Any
> aValues( nCount
);
880 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
883 std::unique_ptr
<SfxItemSet
> pAttribs
;
885 pAttribs
= pForwarder
->GetParaAttribs( nPara
).Clone();
887 pAttribs
= pForwarder
->GetAttribs( GetSelection() ).Clone();
889 pAttribs
->ClearInvalidItems();
891 const OUString
* pPropertyNames
= aPropertyNames
.getConstArray();
892 uno::Any
* pValues
= aValues
.getArray();
894 for( ; nCount
; nCount
--, pPropertyNames
++, pValues
++ )
896 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( *pPropertyNames
);
899 getPropertyValue( pMap
, *pValues
, *pAttribs
);
907 void SAL_CALL
SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence
< OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& )
911 void SAL_CALL
SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& )
915 void SAL_CALL
SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence
< OUString
>& , const uno::Reference
< beans::XPropertiesChangeListener
>& )
919 // beans::XPropertyState
920 beans::PropertyState SAL_CALL
SvxUnoTextRangeBase::getPropertyState( const OUString
& PropertyName
)
922 return _getPropertyState( PropertyName
);
925 const sal_uInt16 aSvxUnoFontDescriptorWhichMap
[] = { EE_CHAR_FONTINFO
, EE_CHAR_FONTHEIGHT
, EE_CHAR_ITALIC
,
926 EE_CHAR_UNDERLINE
, EE_CHAR_WEIGHT
, EE_CHAR_STRIKEOUT
, EE_CHAR_CASEMAP
,
929 beans::PropertyState
SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
933 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
936 SfxItemState eItemState
= SfxItemState::UNKNOWN
;
943 const sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
944 SfxItemState eTempItemState
= SfxItemState::UNKNOWN
;
948 eTempItemState
= pForwarder
->GetItemState( nPara
, *pWhichId
);
950 eTempItemState
= pForwarder
->GetItemState( GetSelection(), *pWhichId
);
952 switch( eTempItemState
)
954 case SfxItemState::DISABLED
:
955 case SfxItemState::DONTCARE
:
956 eItemState
= SfxItemState::DONTCARE
;
959 case SfxItemState::DEFAULT
:
960 if( eItemState
!= SfxItemState::DEFAULT
)
962 if( eItemState
== SfxItemState::UNKNOWN
)
963 eItemState
= SfxItemState::DEFAULT
;
967 case SfxItemState::READONLY
:
968 case SfxItemState::SET
:
969 if( eItemState
!= SfxItemState::SET
)
971 if( eItemState
== SfxItemState::UNKNOWN
)
972 eItemState
= SfxItemState::SET
;
976 throw beans::UnknownPropertyException();
985 case WID_NUMBERINGSTARTVALUE
:
986 case WID_PARAISNUMBERINGRESTART
:
987 eItemState
= SfxItemState::SET
;
997 eItemState
= pForwarder
->GetItemState( nPara
, nWID
);
999 eItemState
= pForwarder
->GetItemState( GetSelection(), nWID
);
1002 switch( eItemState
)
1004 case SfxItemState::DONTCARE
:
1005 case SfxItemState::DISABLED
:
1006 return beans::PropertyState_AMBIGUOUS_VALUE
;
1007 case SfxItemState::READONLY
:
1008 case SfxItemState::SET
:
1009 return beans::PropertyState_DIRECT_VALUE
;
1010 case SfxItemState::DEFAULT
:
1011 return beans::PropertyState_DEFAULT_VALUE
;
1013 // case SfxItemState::UNKNOWN:
1017 throw beans::UnknownPropertyException();
1020 beans::PropertyState
SvxUnoTextRangeBase::_getPropertyState(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1022 SolarMutexGuard aGuard
;
1024 return _getPropertyState( mpPropSet
->getPropertyMapEntry( PropertyName
), nPara
);
1027 uno::Sequence
< beans::PropertyState
> SAL_CALL
SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence
< OUString
>& aPropertyName
)
1029 return _getPropertyStates( aPropertyName
);
1032 uno::Sequence
< beans::PropertyState
> SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence
< OUString
>& PropertyName
, sal_Int32 nPara
/* = -1 */)
1034 uno::Sequence
< beans::PropertyState
> aRet( PropertyName
.getLength() );
1036 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1039 std::unique_ptr
<SfxItemSet
> pSet
;
1042 pSet
.reset(new SfxItemSet( pForwarder
->GetParaAttribs( nPara
) ));
1046 ESelection
aSel( GetSelection() );
1047 CheckSelection( aSel
, pForwarder
);
1048 pSet
.reset(new SfxItemSet( pForwarder
->GetAttribs( aSel
, EditEngineAttribs::OnlyHard
) ));
1051 beans::PropertyState
* pState
= aRet
.getArray();
1052 for( const OUString
& rName
: PropertyName
)
1054 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( rName
);
1055 if( !_getOnePropertyStates(pSet
.get(), pMap
, *pState
++) )
1057 throw beans::UnknownPropertyException(rName
);
1065 bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet
* pSet
, const SfxItemPropertySimpleEntry
* pMap
, beans::PropertyState
& rState
)
1067 bool bUnknownPropertyFound
= false;
1070 SfxItemState eItemState
= SfxItemState::UNKNOWN
;
1071 sal_uInt16 nWID
= 0;
1073 switch( pMap
->nWID
)
1077 const sal_uInt16
* pWhichId
= aSvxUnoFontDescriptorWhichMap
;
1078 SfxItemState eTempItemState
= SfxItemState::UNKNOWN
;
1081 eTempItemState
= pSet
->GetItemState( *pWhichId
);
1083 switch( eTempItemState
)
1085 case SfxItemState::DISABLED
:
1086 case SfxItemState::DONTCARE
:
1087 eItemState
= SfxItemState::DONTCARE
;
1090 case SfxItemState::DEFAULT
:
1091 if( eItemState
!= SfxItemState::DEFAULT
)
1093 if( eItemState
== SfxItemState::UNKNOWN
)
1094 eItemState
= SfxItemState::DEFAULT
;
1098 case SfxItemState::READONLY
:
1099 case SfxItemState::SET
:
1100 if( eItemState
!= SfxItemState::SET
)
1102 if( eItemState
== SfxItemState::UNKNOWN
)
1103 eItemState
= SfxItemState::SET
;
1107 bUnknownPropertyFound
= true;
1117 case WID_NUMBERINGSTARTVALUE
:
1118 case WID_PARAISNUMBERINGRESTART
:
1119 eItemState
= SfxItemState::SET
;
1126 if( bUnknownPropertyFound
)
1130 eItemState
= pSet
->GetItemState( nWID
, false );
1132 switch( eItemState
)
1134 case SfxItemState::READONLY
:
1135 case SfxItemState::SET
:
1136 rState
= beans::PropertyState_DIRECT_VALUE
;
1138 case SfxItemState::DEFAULT
:
1139 rState
= beans::PropertyState_DEFAULT_VALUE
;
1141 // case SfxItemState::UNKNOWN:
1142 // case SfxItemState::DONTCARE:
1143 // case SfxItemState::DISABLED:
1145 rState
= beans::PropertyState_AMBIGUOUS_VALUE
;
1151 void SAL_CALL
SvxUnoTextRangeBase::setPropertyToDefault( const OUString
& PropertyName
)
1153 _setPropertyToDefault( PropertyName
);
1156 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString
& PropertyName
, sal_Int32 nPara
/* = -1 */)
1158 SolarMutexGuard aGuard
;
1160 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1164 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( PropertyName
);
1167 CheckSelection( maSelection
, mpEditSource
->GetTextForwarder() );
1168 _setPropertyToDefault( pForwarder
, pMap
, nPara
);
1173 throw beans::UnknownPropertyException(PropertyName
);
1176 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder
* pForwarder
, const SfxItemPropertySimpleEntry
* pMap
, sal_Int32 nPara
)
1180 SfxItemSet
aSet(*pForwarder
->GetPool());
1182 if( pMap
->nWID
== WID_FONTDESC
)
1184 SvxUnoFontDescriptor::setPropertyToDefault( aSet
);
1186 else if( pMap
->nWID
== WID_NUMLEVEL
)
1188 // #101004# Call interface method instead of unsafe cast
1189 pForwarder
->SetDepth( maSelection
.nStartPara
, -1 );
1192 else if( pMap
->nWID
== WID_NUMBERINGSTARTVALUE
)
1194 pForwarder
->SetNumberingStartValue( maSelection
.nStartPara
, -1 );
1196 else if( pMap
->nWID
== WID_PARAISNUMBERINGRESTART
)
1198 pForwarder
->SetParaIsNumberingRestart( maSelection
.nStartPara
, false );
1202 aSet
.InvalidateItem( pMap
->nWID
);
1206 pForwarder
->SetParaAttribs( nPara
, aSet
);
1208 pForwarder
->QuickSetAttribs( aSet
, GetSelection() );
1210 GetEditSource()->UpdateData();
1217 uno::Any SAL_CALL
SvxUnoTextRangeBase::getPropertyDefault( const OUString
& aPropertyName
)
1219 SolarMutexGuard aGuard
;
1221 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1224 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMapEntry( aPropertyName
);
1227 SfxItemPool
* pPool
= pForwarder
->GetPool();
1229 switch( pMap
->nWID
)
1232 return SvxUnoFontDescriptor::getPropertyDefault( pPool
);
1240 case WID_NUMBERINGSTARTVALUE
:
1241 return uno::Any( sal_Int16(-1) );
1243 case WID_PARAISNUMBERINGRESTART
:
1244 return uno::Any( false );
1248 // Get Default from ItemPool
1249 if(SfxItemPool::IsWhich(pMap
->nWID
))
1251 SfxItemSet
aSet( *pPool
, {{pMap
->nWID
, pMap
->nWID
}});
1252 aSet
.Put(pPool
->GetDefaultItem(pMap
->nWID
));
1253 return SvxItemPropertySet::getPropertyValue(pMap
, aSet
, true, false );
1259 throw beans::UnknownPropertyException(aPropertyName
);
1262 // beans::XMultiPropertyStates
1263 void SAL_CALL
SvxUnoTextRangeBase::setAllPropertiesToDefault()
1265 SolarMutexGuard aGuard
;
1267 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1271 for (auto & entry
: mpPropSet
->getPropertyMap().getPropertyEntries())
1273 _setPropertyToDefault( pForwarder
, &entry
, -1 );
1278 void SAL_CALL
SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence
< OUString
>& aPropertyNames
)
1280 for( const OUString
& rName
: aPropertyNames
)
1282 setPropertyToDefault( rName
);
1286 uno::Sequence
< uno::Any
> SAL_CALL
SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence
< OUString
>& aPropertyNames
)
1288 uno::Sequence
< uno::Any
> ret( aPropertyNames
.getLength() );
1289 uno::Any
* pDefaults
= ret
.getArray();
1291 for( const OUString
& rName
: aPropertyNames
)
1293 *pDefaults
++ = getPropertyDefault( rName
);
1300 void SvxUnoTextRangeBase::CollapseToStart() throw()
1302 CheckSelection( maSelection
, mpEditSource
.get() );
1304 maSelection
.nEndPara
= maSelection
.nStartPara
;
1305 maSelection
.nEndPos
= maSelection
.nStartPos
;
1308 void SvxUnoTextRangeBase::CollapseToEnd() throw()
1310 CheckSelection( maSelection
, mpEditSource
.get() );
1312 maSelection
.nStartPara
= maSelection
.nEndPara
;
1313 maSelection
.nStartPos
= maSelection
.nEndPos
;
1316 bool SvxUnoTextRangeBase::IsCollapsed() throw()
1318 CheckSelection( maSelection
, mpEditSource
.get() );
1320 return ( maSelection
.nStartPara
== maSelection
.nEndPara
&&
1321 maSelection
.nStartPos
== maSelection
.nEndPos
);
1324 bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount
, bool Expand
) throw()
1326 CheckSelection( maSelection
, mpEditSource
.get() );
1328 // #75098# use end position, as in Writer (start is anchor, end is cursor)
1329 sal_uInt16 nNewPos
= maSelection
.nEndPos
;
1330 sal_Int32 nNewPar
= maSelection
.nEndPara
;
1333 SvxTextForwarder
* pForwarder
= nullptr;
1334 while ( nCount
> nNewPos
&& bOk
)
1341 pForwarder
= mpEditSource
->GetTextForwarder(); // first here, it is necessary...
1344 nCount
-= nNewPos
+ 1;
1345 nNewPos
= pForwarder
->GetTextLen( nNewPar
);
1351 nNewPos
= nNewPos
- nCount
;
1352 maSelection
.nStartPara
= nNewPar
;
1353 maSelection
.nStartPos
= nNewPos
;
1362 bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount
, bool Expand
) throw()
1364 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1367 CheckSelection( maSelection
, pForwarder
);
1369 sal_Int32 nNewPos
= maSelection
.nEndPos
+ nCount
; //! Overflow???
1370 sal_Int32 nNewPar
= maSelection
.nEndPara
;
1373 sal_Int32 nParCount
= pForwarder
->GetParagraphCount();
1374 sal_Int32 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1375 while ( nNewPos
> nThisLen
&& bOk
)
1377 if ( nNewPar
+ 1 >= nParCount
)
1381 nNewPos
-= nThisLen
+1;
1383 nThisLen
= pForwarder
->GetTextLen( nNewPar
);
1389 maSelection
.nEndPara
= nNewPar
;
1390 maSelection
.nEndPos
= nNewPos
;
1401 void SvxUnoTextRangeBase::GotoStart(bool Expand
) throw()
1403 maSelection
.nStartPara
= 0;
1404 maSelection
.nStartPos
= 0;
1410 void SvxUnoTextRangeBase::GotoEnd(bool Expand
) throw()
1412 CheckSelection( maSelection
, mpEditSource
.get() );
1414 SvxTextForwarder
* pForwarder
= mpEditSource
? mpEditSource
->GetTextForwarder() : nullptr;
1418 sal_Int32 nPar
= pForwarder
->GetParagraphCount();
1422 maSelection
.nEndPara
= nPar
;
1423 maSelection
.nEndPos
= pForwarder
->GetTextLen( nPar
);
1429 // lang::XServiceInfo
1430 sal_Bool SAL_CALL
SvxUnoTextRangeBase::supportsService( const OUString
& ServiceName
)
1432 return cppu::supportsService( this, ServiceName
);
1435 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextRangeBase::getSupportedServiceNames()
1437 return getSupportedServiceNames_Static();
1440 uno::Sequence
< OUString
> SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1442 return { "com.sun.star.style.CharacterProperties",
1443 "com.sun.star.style.CharacterPropertiesComplex",
1444 "com.sun.star.style.CharacterPropertiesAsian" };
1447 // XTextRangeCompare
1448 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
)
1450 SvxUnoTextRangeBase
* pR1
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRangeBase
>( xR1
);
1451 SvxUnoTextRangeBase
* pR2
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRangeBase
>( xR2
);
1453 if( (pR1
== nullptr) || (pR2
== nullptr) )
1454 throw lang::IllegalArgumentException();
1456 const ESelection
& r1
= pR1
->maSelection
;
1457 const ESelection
& r2
= pR2
->maSelection
;
1459 if( r1
.nStartPara
== r2
.nStartPara
)
1461 if( r1
.nStartPos
== r2
.nStartPos
)
1464 return r1
.nStartPos
< r2
.nStartPos
? 1 : -1;
1468 return r1
.nStartPara
< r2
.nStartPara
? 1 : -1;
1472 sal_Int16 SAL_CALL
SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference
< text::XTextRange
>& xR1
, const uno::Reference
< text::XTextRange
>& xR2
)
1474 SvxUnoTextRangeBase
* pR1
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRangeBase
>( xR1
);
1475 SvxUnoTextRangeBase
* pR2
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRangeBase
>( xR2
);
1477 if( (pR1
== nullptr) || (pR2
== nullptr) )
1478 throw lang::IllegalArgumentException();
1480 const ESelection
& r1
= pR1
->maSelection
;
1481 const ESelection
& r2
= pR2
->maSelection
;
1483 if( r1
.nEndPara
== r2
.nEndPara
)
1485 if( r1
.nEndPos
== r2
.nEndPos
)
1488 return r1
.nEndPos
< r2
.nEndPos
? 1 : -1;
1492 return r1
.nEndPara
< r2
.nEndPara
? 1 : -1;
1496 SvxUnoTextRange::SvxUnoTextRange(const SvxUnoTextBase
& rParent
, bool bPortion
/* = false */)
1497 :SvxUnoTextRangeBase( rParent
.GetEditSource(), bPortion
? ImplGetSvxTextPortionSvxPropertySet() : rParent
.getPropertySet() ),
1498 mbPortion( bPortion
)
1500 xParentText
= static_cast<text::XText
*>(const_cast<SvxUnoTextBase
*>(&rParent
));
1503 SvxUnoTextRange::~SvxUnoTextRange() throw()
1507 uno::Any SAL_CALL
SvxUnoTextRange::queryAggregation( const uno::Type
& rType
)
1509 QUERYINT( text::XTextRange
);
1510 else if( rType
== cppu::UnoType
<beans::XMultiPropertyStates
>::get())
1511 return uno::makeAny(uno::Reference
< beans::XMultiPropertyStates
>(this));
1512 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
1513 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(this));
1514 else QUERYINT( beans::XPropertyState
);
1515 else QUERYINT( text::XTextRangeCompare
);
1516 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
1517 return uno::makeAny(uno::Reference
< beans::XMultiPropertySet
>(this));
1518 else QUERYINT( lang::XServiceInfo
);
1519 else QUERYINT( lang::XTypeProvider
);
1520 else QUERYINT( lang::XUnoTunnel
);
1522 return OWeakAggObject::queryAggregation( rType
);
1525 uno::Any SAL_CALL
SvxUnoTextRange::queryInterface( const uno::Type
& rType
)
1527 return OWeakAggObject::queryInterface(rType
);
1530 void SAL_CALL
SvxUnoTextRange::acquire()
1533 OWeakAggObject::acquire();
1536 void SAL_CALL
SvxUnoTextRange::release()
1539 OWeakAggObject::release();
1546 struct theSvxUnoTextRangeTypes
:
1547 public rtl::StaticWithInit
<uno::Sequence
<uno::Type
>, theSvxUnoTextRangeTypes
>
1549 uno::Sequence
<uno::Type
> operator () ()
1551 uno::Sequence
< uno::Type
> aTypeSequence
;
1553 aTypeSequence
.realloc( 9 ); // !DANGER! keep this updated
1554 uno::Type
* pTypes
= aTypeSequence
.getArray();
1556 *pTypes
++ = cppu::UnoType
<text::XTextRange
>::get();
1557 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
1558 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
1559 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertyStates
>::get();
1560 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
1561 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
1562 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
1563 *pTypes
++ = cppu::UnoType
<lang::XUnoTunnel
>::get();
1564 *pTypes
++ = cppu::UnoType
<text::XTextRangeCompare
>::get();
1566 return aTypeSequence
;
1571 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextRange::getTypes()
1573 return theSvxUnoTextRangeTypes::get();
1576 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextRange::getImplementationId()
1578 return css::uno::Sequence
<sal_Int8
>();
1582 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextRange::getText()
1587 // lang::XServiceInfo
1588 OUString SAL_CALL
SvxUnoTextRange::getImplementationName()
1590 return "SvxUnoTextRange";
1596 SvxUnoTextBase::SvxUnoTextBase(const SvxItemPropertySet
* _pSet
)
1597 : SvxUnoTextRangeBase(_pSet
)
1601 SvxUnoTextBase::SvxUnoTextBase(const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> const & xParent
)
1602 : SvxUnoTextRangeBase(pSource
, _pSet
)
1604 xParentText
= xParent
;
1605 ESelection aSelection
;
1606 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1607 SetSelection( aSelection
);
1610 SvxUnoTextBase::SvxUnoTextBase(const SvxUnoTextBase
& rText
)
1611 : SvxUnoTextRangeBase( rText
)
1612 , text::XTextAppend()
1614 , container::XEnumerationAccess()
1615 , text::XTextRangeMover()
1616 , lang::XTypeProvider()
1618 xParentText
= rText
.xParentText
;
1621 SvxUnoTextBase::~SvxUnoTextBase() throw()
1626 uno::Any SAL_CALL
SvxUnoTextBase::queryAggregation( const uno::Type
& rType
)
1628 QUERYINT( text::XText
);
1629 QUERYINT( text::XSimpleText
);
1630 if( rType
== cppu::UnoType
<text::XTextRange
>::get())
1631 return uno::makeAny(uno::Reference
< text::XTextRange
>(static_cast<text::XText
*>(this)));
1632 QUERYINT(container::XEnumerationAccess
);
1633 QUERYINT( container::XElementAccess
);
1634 QUERYINT( beans::XMultiPropertyStates
);
1635 QUERYINT( beans::XPropertySet
);
1636 QUERYINT( beans::XMultiPropertySet
);
1637 QUERYINT( beans::XPropertyState
);
1638 QUERYINT( text::XTextRangeCompare
);
1639 QUERYINT( lang::XServiceInfo
);
1640 QUERYINT( text::XTextRangeMover
);
1641 QUERYINT( text::XTextCopy
);
1642 QUERYINT( text::XTextAppend
);
1643 QUERYINT( text::XParagraphAppend
);
1644 QUERYINT( text::XTextPortionAppend
);
1645 QUERYINT( lang::XTypeProvider
);
1646 QUERYINT( lang::XUnoTunnel
);
1655 struct theSvxUnoTextBaseTypes
:
1656 public rtl::StaticWithInit
<uno::Sequence
<uno::Type
>, theSvxUnoTextBaseTypes
>
1658 uno::Sequence
<uno::Type
> operator () ()
1660 uno::Sequence
< uno::Type
> aTypeSequence
;
1662 aTypeSequence
.realloc( 15 ); // !DANGER! keep this updated
1663 uno::Type
* pTypes
= aTypeSequence
.getArray();
1665 *pTypes
++ = cppu::UnoType
<text::XText
>::get();
1666 *pTypes
++ = cppu::UnoType
<container::XEnumerationAccess
>::get();
1667 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
1668 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
1669 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertyStates
>::get();
1670 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
1671 *pTypes
++ = cppu::UnoType
<text::XTextRangeMover
>::get();
1672 *pTypes
++ = cppu::UnoType
<text::XTextAppend
>::get();
1673 *pTypes
++ = cppu::UnoType
<text::XTextCopy
>::get();
1674 *pTypes
++ = cppu::UnoType
<text::XParagraphAppend
>::get();
1675 *pTypes
++ = cppu::UnoType
<text::XTextPortionAppend
>::get();
1676 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
1677 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
1678 *pTypes
++ = cppu::UnoType
<lang::XUnoTunnel
>::get();
1679 *pTypes
++ = cppu::UnoType
<text::XTextRangeCompare
>::get();
1681 return aTypeSequence
;
1686 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextBase::getTypes()
1688 return theSvxUnoTextBaseTypes::get();
1691 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextBase::getImplementationId()
1693 return css::uno::Sequence
<sal_Int8
>();
1696 uno::Reference
< text::XTextCursor
> SvxUnoTextBase::createTextCursorBySelection( const ESelection
& rSel
)
1698 SvxUnoTextCursor
* pCursor
= new SvxUnoTextCursor( *this );
1699 uno::Reference
< text::XTextCursor
> xCursor( pCursor
);
1700 pCursor
->SetSelection( rSel
);
1706 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursor()
1708 SolarMutexGuard aGuard
;
1709 return new SvxUnoTextCursor( *this );
1712 uno::Reference
< text::XTextCursor
> SAL_CALL
SvxUnoTextBase::createTextCursorByRange( const uno::Reference
< text::XTextRange
>& aTextPosition
)
1714 SolarMutexGuard aGuard
;
1716 uno::Reference
< text::XTextCursor
> xCursor
;
1718 if( aTextPosition
.is() )
1720 SvxUnoTextRangeBase
* pRange
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRangeBase
>( aTextPosition
);
1722 xCursor
= createTextCursorBySelection( pRange
->GetSelection() );
1728 void SAL_CALL
SvxUnoTextBase::insertString( const uno::Reference
< text::XTextRange
>& xRange
, const OUString
& aString
, sal_Bool bAbsorb
)
1730 SolarMutexGuard aGuard
;
1735 SvxUnoTextRangeBase
* pRange
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRange
>( xRange
);
1739 // setString on SvxUnoTextRangeBase instead of itself QuickInsertText
1740 // and UpdateData, so that the selection will be adjusted to
1741 // SvxUnoTextRangeBase. Actually all cursor objects of this Text must
1742 // to be statement to be adapted!
1744 if (!bAbsorb
) // do not replace -> append on tail
1745 pRange
->CollapseToEnd();
1747 pRange
->setString( aString
);
1749 pRange
->CollapseToEnd();
1751 if (GetEditSource())
1753 ESelection aSelection
;
1754 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1755 SetSelection( aSelection
);
1759 void SAL_CALL
SvxUnoTextBase::insertControlCharacter( const uno::Reference
< text::XTextRange
>& xRange
, sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
1761 SolarMutexGuard aGuard
;
1763 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : nullptr;
1768 ESelection aSelection
;
1769 ::GetSelection( aSelection
, pForwarder
);
1770 SetSelection( aSelection
);
1772 switch( nControlCharacter
)
1774 case text::ControlCharacter::PARAGRAPH_BREAK
:
1776 insertString( xRange
, "\x0D", bAbsorb
);
1780 case text::ControlCharacter::LINE_BREAK
:
1782 SvxUnoTextRangeBase
* pRange
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRange
>( xRange
);
1785 ESelection aRange
= pRange
->GetSelection();
1789 pForwarder
->QuickInsertText( "", aRange
);
1791 aRange
.nEndPos
= aRange
.nStartPos
;
1792 aRange
.nEndPara
= aRange
.nStartPara
;
1796 aRange
.nStartPara
= aRange
.nEndPara
;
1797 aRange
.nStartPos
= aRange
.nEndPos
;
1800 pForwarder
->QuickInsertLineBreak( aRange
);
1801 GetEditSource()->UpdateData();
1803 aRange
.nEndPos
+= 1;
1805 aRange
.nStartPos
+= 1;
1807 pRange
->SetSelection( aRange
);
1811 case text::ControlCharacter::APPEND_PARAGRAPH
:
1813 SvxUnoTextRangeBase
* pRange
= comphelper::getUnoTunnelImplementation
<SvxUnoTextRange
>( xRange
);
1816 ESelection aRange
= pRange
->GetSelection();
1817 // ESelection aOldSelection = aRange;
1819 aRange
.nStartPos
= pForwarder
->GetTextLen( aRange
.nStartPara
);
1821 aRange
.nEndPara
= aRange
.nStartPara
;
1822 aRange
.nEndPos
= aRange
.nStartPos
;
1824 pRange
->SetSelection( aRange
);
1825 pRange
->setString( "\x0D" );
1827 aRange
.nStartPos
= 0;
1828 aRange
.nStartPara
+= 1;
1830 aRange
.nEndPara
+= 1;
1832 pRange
->SetSelection( aRange
);
1839 throw lang::IllegalArgumentException();
1844 void SAL_CALL
SvxUnoTextBase::insertTextContent( const uno::Reference
< text::XTextRange
>& xRange
, const uno::Reference
< text::XTextContent
>& xContent
, sal_Bool bAbsorb
)
1846 SolarMutexGuard aGuard
;
1848 SvxTextForwarder
* pForwarder
= GetEditSource() ? GetEditSource()->GetTextForwarder() : nullptr;
1852 uno::Reference
<beans::XPropertySet
> xPropSet(xRange
, uno::UNO_QUERY
);
1854 throw lang::IllegalArgumentException();
1856 uno::Any aAny
= xPropSet
->getPropertyValue(UNO_TR_PROP_SELECTION
);
1857 text::TextRangeSelection aSel
= aAny
.get
<text::TextRangeSelection
>();
1859 aSel
.Start
= aSel
.End
;
1861 std::unique_ptr
<SvxFieldData
> pFieldData(SvxFieldData::Create(xContent
));
1863 throw lang::IllegalArgumentException();
1865 SvxFieldItem
aField( *pFieldData
, EE_FEATURE_FIELD
);
1866 pForwarder
->QuickInsertField(aField
, toESelection(aSel
));
1867 GetEditSource()->UpdateData();
1869 uno::Reference
<beans::XPropertySet
> xPropSetContent(xContent
, uno::UNO_QUERY
);
1871 throw lang::IllegalArgumentException();
1873 xPropSetContent
->setPropertyValue(UNO_TC_PROP_ANCHOR
, uno::makeAny(xRange
));
1875 aSel
.End
.PositionInParagraph
+= 1;
1876 aSel
.Start
.PositionInParagraph
= aSel
.End
.PositionInParagraph
;
1877 xPropSet
->setPropertyValue(UNO_TR_PROP_SELECTION
, uno::makeAny(aSel
));
1880 void SAL_CALL
SvxUnoTextBase::removeTextContent( const uno::Reference
< text::XTextContent
>& )
1886 uno::Reference
< text::XText
> SAL_CALL
SvxUnoTextBase::getText()
1888 SolarMutexGuard aGuard
;
1890 if (GetEditSource())
1892 ESelection aSelection
;
1893 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1894 SetSelection( aSelection
);
1897 return static_cast<text::XText
*>(this);
1900 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getStart()
1902 return SvxUnoTextRangeBase::getStart();
1905 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::getEnd()
1907 return SvxUnoTextRangeBase::getEnd();
1910 OUString SAL_CALL
SvxUnoTextBase::getString()
1912 return SvxUnoTextRangeBase::getString();
1915 void SAL_CALL
SvxUnoTextBase::setString( const OUString
& aString
)
1917 SvxUnoTextRangeBase::setString(aString
);
1921 // XEnumerationAccess
1922 uno::Reference
< container::XEnumeration
> SAL_CALL
SvxUnoTextBase::createEnumeration()
1924 SolarMutexGuard aGuard
;
1925 if( maSelection
== ESelection(0,0,0,0) || maSelection
== ESelection(EE_PARA_MAX_COUNT
,0,0,0) )
1927 ESelection aSelection
;
1928 ::GetSelection( aSelection
, GetEditSource()->GetTextForwarder() );
1929 return new SvxUnoTextContentEnumeration(*this, aSelection
);
1933 return new SvxUnoTextContentEnumeration(*this, maSelection
);
1937 // XElementAccess ( container::XEnumerationAccess )
1938 uno::Type SAL_CALL
SvxUnoTextBase::getElementType( )
1940 return cppu::UnoType
<text::XTextRange
>::get();
1943 sal_Bool SAL_CALL
SvxUnoTextBase::hasElements( )
1945 SolarMutexGuard aGuard
;
1949 SvxTextForwarder
* pForwarder
= GetEditSource()->GetTextForwarder();
1951 return pForwarder
->GetParagraphCount() != 0;
1957 // text::XTextRangeMover
1958 void SAL_CALL
SvxUnoTextBase::moveTextRange( const uno::Reference
< text::XTextRange
>&, sal_Int16
)
1962 /// @throws lang::IllegalArgumentException
1963 /// @throws beans::UnknownPropertyException
1964 /// @throws uno::RuntimeException
1965 static void SvxPropertyValuesToItemSet(
1966 SfxItemSet
&rItemSet
,
1967 const uno::Sequence
< beans::PropertyValue
>& rPropertyValues
,
1968 const SfxItemPropertySet
*pPropSet
,
1969 SvxTextForwarder
*pForwarder
/*needed for WID_NUMLEVEL*/,
1970 sal_Int32 nPara
/*needed for WID_NUMLEVEL*/)
1972 for (const beans::PropertyValue
& rProp
: rPropertyValues
)
1974 const SfxItemPropertySimpleEntry
*pEntry
= pPropSet
->getPropertyMap().getByName( rProp
.Name
);
1976 throw beans::UnknownPropertyException( "Unknown property: " + rProp
.Name
, static_cast < cppu::OWeakObject
* > ( nullptr ) );
1977 // Note: there is no need to take special care of the properties
1978 // TextField (EE_FEATURE_FIELD) and
1979 // TextPortionType (WID_PORTIONTYPE)
1980 // since they are read-only and thus are already taken care of below.
1982 if (pEntry
->nFlags
& beans::PropertyAttribute::READONLY
)
1983 // should be PropertyVetoException which is not yet defined for the new import API's functions
1984 throw uno::RuntimeException("Property is read-only: " + rProp
.Name
, static_cast < cppu::OWeakObject
* > ( nullptr ) );
1985 //throw PropertyVetoException ("Property is read-only: " + rProp.Name, static_cast < cppu::OWeakObject * > ( 0 ) );
1987 if (pEntry
->nWID
== WID_FONTDESC
)
1989 awt::FontDescriptor aDesc
;
1990 if (rProp
.Value
>>= aDesc
)
1991 SvxUnoFontDescriptor::FillItemSet( aDesc
, rItemSet
);
1993 else if (pEntry
->nWID
== WID_NUMLEVEL
)
1997 sal_Int16 nLevel
= -1;
1998 rProp
.Value
>>= nLevel
;
2000 // #101004# Call interface method instead of unsafe cast
2001 if (!pForwarder
->SetDepth( nPara
, nLevel
))
2002 throw lang::IllegalArgumentException();
2005 else if (pEntry
->nWID
== WID_NUMBERINGSTARTVALUE
)
2009 sal_Int16 nStartValue
= -1;
2010 if( !(rProp
.Value
>>= nStartValue
) )
2011 throw lang::IllegalArgumentException();
2013 pForwarder
->SetNumberingStartValue( nPara
, nStartValue
);
2016 else if (pEntry
->nWID
== WID_PARAISNUMBERINGRESTART
)
2020 bool bParaIsNumberingRestart
= false;
2021 if( !(rProp
.Value
>>= bParaIsNumberingRestart
) )
2022 throw lang::IllegalArgumentException();
2024 pForwarder
->SetParaIsNumberingRestart( nPara
, bParaIsNumberingRestart
);
2028 pPropSet
->setPropertyValue( rProp
.Name
, rProp
.Value
, rItemSet
);
2032 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::finishParagraphInsert(
2033 const uno::Sequence
< beans::PropertyValue
>& /*rCharAndParaProps*/,
2034 const uno::Reference
< text::XTextRange
>& /*rTextRange*/ )
2036 uno::Reference
< text::XTextRange
> xRet
;
2040 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::finishParagraph(
2041 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2043 SolarMutexGuard aGuard
;
2045 uno::Reference
< text::XTextRange
> xRet
;
2046 SvxEditSource
*pEditSource
= GetEditSource();
2047 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
2050 sal_Int32 nParaCount
= pTextForwarder
->GetParagraphCount();
2051 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2052 pTextForwarder
->AppendParagraph();
2054 // set properties for the previously last paragraph
2055 sal_Int32 nPara
= nParaCount
- 1;
2056 ESelection
aSel( nPara
, 0, nPara
, 0 );
2057 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2058 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2059 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder
, nPara
);
2060 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2061 pEditSource
->UpdateData();
2062 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2064 pRange
->SetSelection( aSel
);
2069 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::insertTextPortion(
2070 const OUString
& /*rText*/,
2071 const uno::Sequence
< beans::PropertyValue
>& /*rCharAndParaProps*/,
2072 const uno::Reference
< text::XTextRange
>& /*rTextRange*/ )
2074 uno::Reference
< text::XTextRange
> xRet
;
2078 // css::text::XTextPortionAppend (new import API)
2079 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextBase::appendTextPortion(
2080 const OUString
& rText
,
2081 const uno::Sequence
< beans::PropertyValue
>& rCharAndParaProps
)
2083 SolarMutexGuard aGuard
;
2085 SvxEditSource
*pEditSource
= GetEditSource();
2086 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
2087 uno::Reference
< text::XTextRange
> xRet
;
2090 sal_Int32 nParaCount
= pTextForwarder
->GetParagraphCount();
2091 DBG_ASSERT( nParaCount
> 0, "paragraph count is 0 or negative" );
2092 sal_Int32 nPara
= nParaCount
- 1;
2093 SfxItemSet
aSet( pTextForwarder
->GetParaAttribs( nPara
) );
2094 sal_Int32 nStart
= pTextForwarder
->AppendTextPortion( nPara
, rText
, aSet
);
2095 pEditSource
->UpdateData();
2096 sal_Int32 nEnd
= pTextForwarder
->GetTextLen( nPara
);
2098 // set properties for the new text portion
2099 ESelection
aSel( nPara
, nStart
, nPara
, nEnd
);
2100 pTextForwarder
->RemoveAttribs( aSel
);
2101 pEditSource
->UpdateData();
2103 SfxItemSet
aItemSet( *pTextForwarder
->GetEmptyItemSetPtr() );
2104 SvxPropertyValuesToItemSet( aItemSet
, rCharAndParaProps
,
2105 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder
, nPara
);
2106 pTextForwarder
->QuickSetAttribs( aItemSet
, aSel
);
2107 SvxUnoTextRange
* pRange
= new SvxUnoTextRange( *this );
2109 pRange
->SetSelection( aSel
);
2110 for( const beans::PropertyValue
& rProp
: rCharAndParaProps
)
2111 pRange
->setPropertyValue( rProp
.Name
, rProp
.Value
);
2116 void SvxUnoTextBase::copyText(
2117 const uno::Reference
< text::XTextCopy
>& xSource
)
2119 SolarMutexGuard aGuard
;
2120 uno::Reference
< lang::XUnoTunnel
> xUT( xSource
, uno::UNO_QUERY
);
2121 SvxEditSource
*pEditSource
= GetEditSource();
2122 SvxTextForwarder
*pTextForwarder
= pEditSource
? pEditSource
->GetTextForwarder() : nullptr;
2123 if( !pTextForwarder
)
2127 SvxUnoTextBase
* pSource
= reinterpret_cast<SvxUnoTextBase
*>(sal::static_int_cast
<sal_uIntPtr
>(
2128 xUT
->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2129 SvxEditSource
*pSourceEditSource
= pSource
->GetEditSource();
2130 SvxTextForwarder
*pSourceTextForwarder
= pSourceEditSource
? pSourceEditSource
->GetTextForwarder() : nullptr;
2131 if( pSourceTextForwarder
)
2133 pTextForwarder
->CopyText( *pSourceTextForwarder
);
2134 pEditSource
->UpdateData();
2139 uno::Reference
< text::XText
> xSourceText( xSource
, uno::UNO_QUERY
);
2140 if( xSourceText
.is() )
2142 setString( xSourceText
->getString() );
2147 // lang::XServiceInfo
2148 OUString SAL_CALL
SvxUnoTextBase::getImplementationName()
2150 return "SvxUnoTextBase";
2153 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames( )
2155 return getSupportedServiceNames_Static();
2158 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextBase::getSupportedServiceNames_Static( )
2160 return comphelper::concatSequences(
2161 SvxUnoTextRangeBase::getSupportedServiceNames_Static(),
2162 std::initializer_list
<std::u16string_view
>{ u
"com.sun.star.text.Text" });
2167 class theSvxUnoTextBaseUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextBaseUnoTunnelId
> {};
2170 const uno::Sequence
< sal_Int8
> & SvxUnoTextBase::getUnoTunnelId() throw()
2172 return theSvxUnoTextBaseUnoTunnelId::get().getSeq();
2175 sal_Int64 SAL_CALL
SvxUnoTextBase::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
2177 if( isUnoTunnelId
<SvxUnoTextBase
>(rId
) )
2179 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2183 return SvxUnoTextRangeBase::getSomething( rId
);
2187 SvxUnoText::SvxUnoText( const SvxItemPropertySet
* _pSet
) throw()
2188 : SvxUnoTextBase( _pSet
)
2192 SvxUnoText::SvxUnoText( const SvxEditSource
* pSource
, const SvxItemPropertySet
* _pSet
, uno::Reference
< text::XText
> const & xParent
) throw()
2193 : SvxUnoTextBase( pSource
, _pSet
, xParent
)
2197 SvxUnoText::SvxUnoText( const SvxUnoText
& rText
) throw()
2198 : SvxUnoTextBase( rText
)
2199 , cppu::OWeakAggObject()
2203 SvxUnoText::~SvxUnoText() throw()
2208 uno::Any SAL_CALL
SvxUnoText::queryAggregation( const uno::Type
& rType
)
2210 uno::Any
aAny( SvxUnoTextBase::queryAggregation( rType
) );
2211 if( !aAny
.hasValue() )
2212 aAny
= OWeakAggObject::queryAggregation( rType
);
2217 uno::Any SAL_CALL
SvxUnoText::queryInterface( const uno::Type
& rType
)
2219 return OWeakAggObject::queryInterface( rType
);
2222 void SAL_CALL
SvxUnoText::acquire() throw( )
2224 OWeakAggObject::acquire();
2227 void SAL_CALL
SvxUnoText::release() throw( )
2229 OWeakAggObject::release();
2232 // lang::XTypeProvider
2233 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoText::getTypes( )
2235 return SvxUnoTextBase::getTypes();
2238 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoText::getImplementationId( )
2240 return css::uno::Sequence
<sal_Int8
>();
2245 class theSvxUnoTextUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextUnoTunnelId
> {};
2248 const uno::Sequence
< sal_Int8
> & SvxUnoText::getUnoTunnelId() throw()
2250 return theSvxUnoTextUnoTunnelId::get().getSeq();
2253 sal_Int64 SAL_CALL
SvxUnoText::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
2255 if( isUnoTunnelId
<SvxUnoText
>(rId
) )
2257 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
2261 return SvxUnoTextBase::getSomething( rId
);
2266 SvxDummyTextSource::~SvxDummyTextSource()
2270 std::unique_ptr
<SvxEditSource
> SvxDummyTextSource::Clone() const
2272 return std::unique_ptr
<SvxEditSource
>(new SvxDummyTextSource
);
2275 SvxTextForwarder
* SvxDummyTextSource::GetTextForwarder()
2280 void SvxDummyTextSource::UpdateData()
2284 sal_Int32
SvxDummyTextSource::GetParagraphCount() const
2289 sal_Int32
SvxDummyTextSource::GetTextLen( sal_Int32
) const
2294 OUString
SvxDummyTextSource::GetText( const ESelection
& ) const
2299 SfxItemSet
SvxDummyTextSource::GetAttribs( const ESelection
&, EditEngineAttribs
) const
2301 // Very dangerous: The former implementation used a SfxItemPool created on the
2302 // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2303 // a deleted Pool by design.
2304 return SfxItemSet(EditEngine::GetGlobalItemPool());
2307 SfxItemSet
SvxDummyTextSource::GetParaAttribs( sal_Int32
) const
2309 return GetAttribs(ESelection());
2312 void SvxDummyTextSource::SetParaAttribs( sal_Int32
, const SfxItemSet
& )
2316 void SvxDummyTextSource::RemoveAttribs( const ESelection
& )
2320 void SvxDummyTextSource::GetPortions( sal_Int32
, std::vector
<sal_Int32
>& ) const
2324 SfxItemState
SvxDummyTextSource::GetItemState( const ESelection
&, sal_uInt16
) const
2326 return SfxItemState::UNKNOWN
;
2329 SfxItemState
SvxDummyTextSource::GetItemState( sal_Int32
, sal_uInt16
) const
2331 return SfxItemState::UNKNOWN
;
2334 SfxItemPool
* SvxDummyTextSource::GetPool() const
2339 void SvxDummyTextSource::QuickInsertText( const OUString
&, const ESelection
& )
2343 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem
&, const ESelection
& )
2347 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet
&, const ESelection
& )
2351 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection
& )
2355 OUString
SvxDummyTextSource::CalcFieldValue( const SvxFieldItem
&, sal_Int32
, sal_Int32
, std::optional
<Color
>&, std::optional
<Color
>& )
2360 void SvxDummyTextSource::FieldClicked( const SvxFieldItem
& )
2364 bool SvxDummyTextSource::IsValid() const
2369 LanguageType
SvxDummyTextSource::GetLanguage( sal_Int32
, sal_Int32
) const
2371 return LANGUAGE_DONTKNOW
;
2374 sal_Int32
SvxDummyTextSource::GetFieldCount( sal_Int32
) const
2379 EFieldInfo
SvxDummyTextSource::GetFieldInfo( sal_Int32
, sal_uInt16
) const
2381 return EFieldInfo();
2384 EBulletInfo
SvxDummyTextSource::GetBulletInfo( sal_Int32
) const
2386 return EBulletInfo();
2389 tools::Rectangle
SvxDummyTextSource::GetCharBounds( sal_Int32
, sal_Int32
) const
2391 return tools::Rectangle();
2394 tools::Rectangle
SvxDummyTextSource::GetParaBounds( sal_Int32
) const
2396 return tools::Rectangle();
2399 MapMode
SvxDummyTextSource::GetMapMode() const
2404 OutputDevice
* SvxDummyTextSource::GetRefDevice() const
2409 bool SvxDummyTextSource::GetIndexAtPoint( const Point
&, sal_Int32
&, sal_Int32
& ) const
2414 bool SvxDummyTextSource::GetWordIndices( sal_Int32
, sal_Int32
, sal_Int32
&, sal_Int32
& ) const
2419 bool SvxDummyTextSource::GetAttributeRun( sal_Int32
&, sal_Int32
&, sal_Int32
, sal_Int32
, bool ) const
2424 sal_Int32
SvxDummyTextSource::GetLineCount( sal_Int32
) const
2429 sal_Int32
SvxDummyTextSource::GetLineLen( sal_Int32
, sal_Int32
) const
2434 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_Int32
&rStart
, /*out*/sal_Int32
&rEnd
, sal_Int32
/*nParagraph*/, sal_Int32
/*nLine*/ ) const
2439 sal_Int32
SvxDummyTextSource::GetLineNumberAtIndex( sal_Int32
/*nPara*/, sal_Int32
/*nIndex*/ ) const
2444 bool SvxDummyTextSource::QuickFormatDoc( bool )
2449 sal_Int16
SvxDummyTextSource::GetDepth( sal_Int32
) const
2454 bool SvxDummyTextSource::SetDepth( sal_Int32
, sal_Int16 nNewDepth
)
2456 return nNewDepth
== 0;
2459 bool SvxDummyTextSource::Delete( const ESelection
& )
2464 bool SvxDummyTextSource::InsertText( const OUString
&, const ESelection
& )
2469 const SfxItemSet
* SvxDummyTextSource::GetEmptyItemSetPtr()
2474 void SvxDummyTextSource::AppendParagraph()
2478 sal_Int32
SvxDummyTextSource::AppendTextPortion( sal_Int32
, const OUString
&, const SfxItemSet
& )
2483 void SvxDummyTextSource::CopyText(const SvxTextForwarder
& )
2487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */