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 .
21 #include <libxml/xmlwriter.h>
22 #include <editeng/fhgtitem.hxx>
23 #include <editeng/lrspitem.hxx>
24 #include <editeng/ulspitem.hxx>
25 #include <osl/diagnose.h>
26 #include <sal/macros.h>
27 #include <svl/intitem.hxx>
28 #include <svl/itemiter.hxx>
32 #include <fmtcolfunc.hxx>
33 #include <hintids.hxx>
36 #include <numrule.hxx>
38 #include <swfntcch.hxx>
40 namespace TextFormatCollFunc
43 void CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle(
45 const SwNumRuleItem
* pNewNumRuleItem
)
47 SwTextFormatColl
* pTextFormatColl
= dynamic_cast<SwTextFormatColl
*>(pFormat
);
48 if ( !pTextFormatColl
)
50 OSL_FAIL( "<TextFormatCollFunc::CheckTextFormatCollFuncForDeletionOfAssignmentToOutlineStyle> - misuse of method - it's only for instances of <SwTextFormatColl>" );
55 if ( pTextFormatColl
->StayAssignedToListLevelOfOutlineStyle() ||
56 !pTextFormatColl
->IsAssignedToListLevelOfOutlineStyle() )
61 pNewNumRuleItem
= pTextFormatColl
->GetItemIfSet(RES_PARATR_NUMRULE
, false);
65 const OUString
& sNumRuleName
= pNewNumRuleItem
->GetValue();
66 if ( sNumRuleName
.isEmpty() ||
67 sNumRuleName
!= pTextFormatColl
->GetDoc()->GetOutlineNumRule()->GetName() )
69 // delete assignment of paragraph style to list level of outline style.
70 pTextFormatColl
->DeleteAssignmentToListLevelOfOutlineStyle();
75 SwNumRule
* GetNumRule( SwTextFormatColl
& rTextFormatColl
)
77 SwNumRule
* pNumRule( nullptr );
79 const SwNumRuleItem
* pNumRuleItem
= rTextFormatColl
.GetItemIfSet(RES_PARATR_NUMRULE
, false);
82 const OUString
& sNumRuleName
= pNumRuleItem
->GetValue();
83 if ( !sNumRuleName
.isEmpty() )
85 pNumRule
= rTextFormatColl
.GetDoc()->FindNumRulePtr( sNumRuleName
);
92 void AddToNumRule( SwTextFormatColl
& rTextFormatColl
)
94 SwNumRule
* pNumRule
= GetNumRule( rTextFormatColl
);
97 pNumRule
->AddParagraphStyle( rTextFormatColl
);
101 void RemoveFromNumRule( SwTextFormatColl
& rTextFormatColl
)
103 SwNumRule
* pNumRule
= GetNumRule( rTextFormatColl
);
106 pNumRule
->RemoveParagraphStyle( rTextFormatColl
);
109 } // end of namespace TextFormatCollFunc
111 SwTextFormatColl::~SwTextFormatColl()
114 pSwFontCache
->Delete( this );
116 if (GetDoc()->IsInDtor())
121 for (const auto& pCharFormat
: *GetDoc()->GetCharFormats())
123 if (pCharFormat
->GetLinkedParaFormat() == this)
125 pCharFormat
->SetLinkedParaFormat(nullptr);
130 void SwTextFormatColl::SwClientNotify(const SwModify
& rModify
, const SfxHint
& rHint
)
132 if (rHint
.GetId() == SfxHintId::SwAutoFormatUsedHint
)
134 CallSwClientNotify(rHint
);
137 else if (rHint
.GetId() == SfxHintId::SwVirtPageNumHint
)
139 CallSwClientNotify(rHint
);
142 else if (rHint
.GetId() != SfxHintId::SwLegacyModify
&& rHint
.GetId() != SfxHintId::SwFormatChange
)
144 if(GetDoc()->IsInDtor())
146 SwFormatColl::SwClientNotify(rModify
, rHint
);
149 bool bNewParent( false ); // #i66431# - adjust type of <bNewParent>
150 const SvxULSpaceItem
*pNewULSpace
= nullptr, *pOldULSpace
= nullptr;
151 const SvxFirstLineIndentItem
*pNewFirstLineIndent
= nullptr;
152 const SvxTextLeftMarginItem
*pNewTextLeftMargin
= nullptr;
153 const SvxRightMarginItem
*pNewRightMargin
= nullptr;
154 const SvxFontHeightItem
* aFontSizeArr
[3] = {nullptr,nullptr,nullptr};
156 const bool bAssignedToListLevelOfOutlineStyle(IsAssignedToListLevelOfOutlineStyle());
157 const SwNumRuleItem
* pNewNumRuleItem( nullptr );
159 if (rHint
.GetId() == SfxHintId::SwLegacyModify
)
161 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
162 const auto pNew
= pLegacy
->m_pNew
;
163 const SwAttrSetChg
*pNewChgSet
= nullptr;
165 switch( pLegacy
->GetWhich() )
167 case RES_ATTRSET_CHG
:
168 // Only recalculate if we're not the sender!
169 pNewChgSet
= &pNew
->StaticWhichCast(RES_ATTRSET_CHG
);
170 pNewFirstLineIndent
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_FIRSTLINE
, false);
171 pNewTextLeftMargin
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_TEXTLEFT
, false);
172 pNewRightMargin
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_RIGHT
, false);
173 pNewULSpace
= pNewChgSet
->GetChgSet()->GetItemIfSet( RES_UL_SPACE
, false );
174 aFontSizeArr
[0] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_FONTSIZE
, false );
175 aFontSizeArr
[1] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_CJK_FONTSIZE
, false );
176 aFontSizeArr
[2] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_CTL_FONTSIZE
, false );
177 // #i70223#, #i84745#
178 // check, if attribute set is applied to this paragraph style
179 if ( bAssignedToListLevelOfOutlineStyle
&&
180 pNewChgSet
->GetTheChgdSet() == &GetAttrSet() )
182 pNewNumRuleItem
= pNewChgSet
->GetChgSet()->GetItemIfSet( RES_PARATR_NUMRULE
, false );
187 case RES_MARGIN_FIRSTLINE
:
188 pNewFirstLineIndent
= &pNew
->StaticWhichCast(RES_MARGIN_FIRSTLINE
);
190 case RES_MARGIN_TEXTLEFT
:
191 pNewTextLeftMargin
= &pNew
->StaticWhichCast(RES_MARGIN_TEXTLEFT
);
193 case RES_MARGIN_RIGHT
:
194 pNewRightMargin
= &pNew
->StaticWhichCast(RES_MARGIN_RIGHT
);
197 pNewULSpace
= &pNew
->StaticWhichCast(RES_UL_SPACE
);
199 case RES_CHRATR_FONTSIZE
:
200 aFontSizeArr
[0] = &pNew
->StaticWhichCast(RES_CHRATR_FONTSIZE
);
202 case RES_CHRATR_CJK_FONTSIZE
:
203 aFontSizeArr
[1] = &pNew
->StaticWhichCast(RES_CHRATR_CJK_FONTSIZE
);
205 case RES_CHRATR_CTL_FONTSIZE
:
206 aFontSizeArr
[2] = &pNew
->StaticWhichCast(RES_CHRATR_CTL_FONTSIZE
);
209 case RES_PARATR_NUMRULE
:
210 if (bAssignedToListLevelOfOutlineStyle
)
212 pNewNumRuleItem
= &pNew
->StaticWhichCast(RES_PARATR_NUMRULE
);
219 else // rHint.GetId() == SfxHintId::SwFormatChange
221 if( GetAttrSet().GetParent() )
223 const SfxItemSet
* pParent
= GetAttrSet().GetParent();
224 pNewFirstLineIndent
= &pParent
->Get(RES_MARGIN_FIRSTLINE
);
225 pNewTextLeftMargin
= &pParent
->Get(RES_MARGIN_TEXTLEFT
);
226 pNewRightMargin
= &pParent
->Get(RES_MARGIN_RIGHT
);
227 pNewULSpace
= &pParent
->Get( RES_UL_SPACE
);
228 aFontSizeArr
[0] = &pParent
->Get( RES_CHRATR_FONTSIZE
);
229 aFontSizeArr
[1] = &pParent
->Get( RES_CHRATR_CJK_FONTSIZE
);
230 aFontSizeArr
[2] = &pParent
->Get( RES_CHRATR_CTL_FONTSIZE
);
231 // #i66431# - modify has to be propagated, because of new parent format.
237 if ( bAssignedToListLevelOfOutlineStyle
&& pNewNumRuleItem
)
239 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle(
240 this, pNewNumRuleItem
);
243 sal_uInt32 nNoNotify
= 0; // track handled changes: no need to notify if all are handled here
245 // Check against the own attributes
246 const SvxFirstLineIndentItem
*pOldFirstLineIndent(GetItemIfSet(RES_MARGIN_FIRSTLINE
, false));
247 if (pNewFirstLineIndent
&& pOldFirstLineIndent
)
249 if (!SfxPoolItem::areSame(pOldFirstLineIndent
, pNewFirstLineIndent
)) // Avoid recursion (SetAttr!)
252 SvxFirstLineIndentItem
aNew(*pOldFirstLineIndent
);
253 // We had a relative value -> recalculate
254 if (100 != pOldFirstLineIndent
->GetPropTextFirstLineOffset())
256 const auto stOld
= pOldFirstLineIndent
->GetTextFirstLineOffset();
257 aNew
.SetTextFirstLineOffset(pNewFirstLineIndent
->GetTextFirstLineOffset(),
258 pOldFirstLineIndent
->GetPropTextFirstLineOffset());
259 bChg
= (stOld
!= aNew
.GetTextFirstLineOffset());
263 SetFormatAttr(aNew
); // triggered separate notification about only this one property
268 const SvxTextLeftMarginItem
*pOldTextLeftMargin(GetItemIfSet(RES_MARGIN_TEXTLEFT
, false));
269 if (pNewTextLeftMargin
&& pOldTextLeftMargin
)
271 if (!SfxPoolItem::areSame(pOldTextLeftMargin
, pNewTextLeftMargin
)) // Avoid recursion (SetAttr!)
274 SvxTextLeftMarginItem
aNew(*pOldTextLeftMargin
);
275 // We had a relative value -> recalculate
276 if (100 != pOldTextLeftMargin
->GetPropLeft())
278 // note: changing from Left to TextLeft - looked wrong with Left
279 const auto stOld
= pOldTextLeftMargin
->GetTextLeft();
280 aNew
.SetTextLeft(pNewTextLeftMargin
->GetTextLeft(),
281 pOldTextLeftMargin
->GetPropLeft());
282 bChg
= (stOld
!= aNew
.GetTextLeft());
286 SetFormatAttr( aNew
);
291 const SvxRightMarginItem
*pOldRightMargin(GetItemIfSet(RES_MARGIN_RIGHT
, false));
292 if (pNewRightMargin
&& pOldRightMargin
)
294 if (!SfxPoolItem::areSame(pOldRightMargin
, pNewRightMargin
)) // Avoid recursion (SetAttr!)
297 SvxRightMarginItem
aNew(*pOldRightMargin
);
298 // We had a relative value -> recalculate
299 if (100 != pOldRightMargin
->GetPropRight())
301 const auto stOld
= pOldRightMargin
->GetRight();
302 aNew
.SetRight(pNewRightMargin
->GetRight(), pOldRightMargin
->GetPropRight());
303 bChg
= (stOld
!= aNew
.GetRight());
307 SetFormatAttr( aNew
);
313 if( pNewULSpace
&& (pOldULSpace
= GetItemIfSet(RES_UL_SPACE
, false)) &&
314 !SfxPoolItem::areSame(pOldULSpace
, pNewULSpace
) ) // Avoid recursion (SetAttr!)
316 SvxULSpaceItem
aNew( *pOldULSpace
);
318 // We had a relative value -> recalculate
319 if (100 != pOldULSpace
->GetPropUpper())
321 const sal_uInt16 nOld
= pOldULSpace
->GetUpper();
322 aNew
.SetUpper(pNewULSpace
->GetUpper(), pOldULSpace
->GetPropUpper());
323 bChg
= nOld
!= aNew
.GetUpper();
325 // We had a relative value -> recalculate
326 if (100 != pOldULSpace
->GetPropLower())
328 const sal_uInt16 nOld
= pOldULSpace
->GetLower();
329 aNew
.SetLower(pNewULSpace
->GetLower(), pOldULSpace
->GetPropLower());
330 bChg
|= nOld
!= aNew
.GetLower();
334 SetFormatAttr( aNew
);
339 for (size_t nC
= 0; nC
< SAL_N_ELEMENTS(aFontSizeArr
); ++nC
)
341 const SvxFontHeightItem
*pFSize
= aFontSizeArr
[ nC
], *pOldFSize
;
342 if( pFSize
&& (SfxItemState::SET
== GetItemState(
343 pFSize
->Which(), false, reinterpret_cast<const SfxPoolItem
**>(&pOldFSize
) )) &&
344 // Avoid recursion (SetAttr!)
345 !SfxPoolItem::areSame(pFSize
, pOldFSize
) )
347 if (100 != pOldFSize
->GetProp() || MapUnit::MapRelative
!= pOldFSize
->GetPropUnit())
349 // We had a relative value -> recalculate
350 const sal_uInt32 nOld
= pOldFSize
->GetHeight();
351 SvxFontHeightItem
aNew(240 , 100, pFSize
->Which());
352 aNew
.SetHeight( pFSize
->GetHeight(), pOldFSize
->GetProp(),
353 pOldFSize
->GetPropUnit() );
354 if (nOld
!= aNew
.GetHeight())
356 SetFormatAttr( aNew
);
363 // if the parent changed, we can't know how many properties are involved: always notify a change
364 if (rHint
.GetId() == SfxHintId::SwLegacyModify
)
366 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
367 const auto pOld
= pLegacy
->m_pOld
;
368 const SwAttrSetChg
*pOldChgSet
= nullptr;
370 if( pLegacy
->GetWhich() == RES_ATTRSET_CHG
)
371 pOldChgSet
= &pOld
->StaticWhichCast(RES_ATTRSET_CHG
);
373 if (bNewParent
|| !nNoNotify
|| (pOldChgSet
&& pOldChgSet
->GetChgSet()->Count() > nNoNotify
))
374 SwFormatColl::SwClientNotify(rModify
, rHint
);
376 else // rHint.GetId() == SfxHintId::SwFormatChange
378 if (bNewParent
|| !nNoNotify
)
379 SwFormatColl::SwClientNotify(rModify
, rHint
);
383 void SwTextFormatColl::SetLinkedCharFormat(SwCharFormat
* pLink
) { mpLinkedCharFormat
= pLink
; }
385 const SwCharFormat
* SwTextFormatColl::GetLinkedCharFormat() const { return mpLinkedCharFormat
; }
387 bool SwTextFormatColl::IsAtDocNodeSet() const
389 SwIterator
<SwContentNode
,SwFormatColl
> aIter( *this );
390 const SwNodes
& rNds
= GetDoc()->GetNodes();
391 for( SwContentNode
* pNode
= aIter
.First(); pNode
; pNode
= aIter
.Next() )
392 if( &(pNode
->GetNodes()) == &rNds
)
398 bool SwTextFormatColl::SetFormatAttr( const SfxPoolItem
& rAttr
)
400 const bool bIsNumRuleItem
= rAttr
.Which() == RES_PARATR_NUMRULE
;
401 if ( bIsNumRuleItem
)
403 TextFormatCollFunc::RemoveFromNumRule( *this );
406 const bool bRet
= SwFormatColl::SetFormatAttr( rAttr
);
408 if ( bIsNumRuleItem
)
410 TextFormatCollFunc::AddToNumRule( *this );
416 bool SwTextFormatColl::SetFormatAttr( const SfxItemSet
& rSet
)
418 const bool bIsNumRuleItemAffected
=
419 rSet
.GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
;
420 if ( bIsNumRuleItemAffected
)
422 TextFormatCollFunc::RemoveFromNumRule( *this );
425 const bool bRet
= SwFormatColl::SetFormatAttr( rSet
);
427 if ( bIsNumRuleItemAffected
)
429 TextFormatCollFunc::AddToNumRule( *this );
435 bool SwTextFormatColl::ResetFormatAttr( sal_uInt16 nWhich1
, sal_uInt16 nWhich2
)
437 const bool bIsNumRuleItemAffected
=
438 ( nWhich2
!= 0 && nWhich2
> nWhich1
)
439 ? ( nWhich1
<= RES_PARATR_NUMRULE
&&
440 RES_PARATR_NUMRULE
<= nWhich2
)
441 : nWhich1
== RES_PARATR_NUMRULE
;
442 if ( bIsNumRuleItemAffected
)
444 TextFormatCollFunc::RemoveFromNumRule( *this );
447 const bool bRet
= SwFormatColl::ResetFormatAttr( nWhich1
, nWhich2
);
453 sal_uInt16
SwTextFormatColl::ResetAllFormatAttr()
455 const bool bOldState( mbStayAssignedToListLevelOfOutlineStyle
);
456 mbStayAssignedToListLevelOfOutlineStyle
= true;
458 // Outline level is no longer a member, it is an attribute now.
459 // Thus, it needs to be restored, if the paragraph style is assigned
460 // to the outline style
461 const int nAssignedOutlineStyleLevel
= IsAssignedToListLevelOfOutlineStyle()
462 ? GetAssignedOutlineStyleLevel()
465 sal_uInt16 nRet
= SwFormatColl::ResetAllFormatAttr();
468 if ( nAssignedOutlineStyleLevel
!= -1 )
470 AssignToListLevelOfOutlineStyle( nAssignedOutlineStyleLevel
);
473 mbStayAssignedToListLevelOfOutlineStyle
= bOldState
;
478 ::sw::ListLevelIndents
SwTextFormatColl::AreListLevelIndentsApplicable() const
480 ::sw::ListLevelIndents
ret(::sw::ListLevelIndents::No
);
481 if (AreListLevelIndentsApplicableImpl(RES_MARGIN_FIRSTLINE
))
483 ret
|= ::sw::ListLevelIndents::FirstLine
;
485 if (AreListLevelIndentsApplicableImpl(RES_MARGIN_TEXTLEFT
))
487 ret
|= ::sw::ListLevelIndents::LeftMargin
;
492 bool SwTextFormatColl::AreListLevelIndentsApplicableImpl(sal_uInt16
const nWhich
) const
494 bool bAreListLevelIndentsApplicable( true );
496 if ( GetItemState( RES_PARATR_NUMRULE
) != SfxItemState::SET
)
498 // no list style applied to paragraph style
499 bAreListLevelIndentsApplicable
= false;
501 else if (GetItemState(nWhich
, false ) == SfxItemState::SET
)
503 // paragraph style has hard-set indent attributes
504 bAreListLevelIndentsApplicable
= false;
506 else if ( GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
)
508 // list style is directly applied to paragraph style and paragraph
509 // style has no hard-set indent attributes
510 bAreListLevelIndentsApplicable
= true;
514 // list style is applied through one of the parent paragraph styles and
515 // paragraph style has no hard-set indent attributes
517 // check parent paragraph styles
518 const SwTextFormatColl
* pColl
= dynamic_cast<const SwTextFormatColl
*>(DerivedFrom());
521 if (pColl
->GetAttrSet().GetItemState(nWhich
, false) == SfxItemState::SET
)
523 // indent attributes found in the paragraph style hierarchy.
524 bAreListLevelIndentsApplicable
= false;
528 if ( pColl
->GetAttrSet().GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
)
530 // paragraph style with the list style found and until now no
531 // indent attributes are found in the paragraph style hierarchy.
532 bAreListLevelIndentsApplicable
= true;
536 pColl
= dynamic_cast<const SwTextFormatColl
*>(pColl
->DerivedFrom());
538 "<SwTextFormatColl::AreListLevelIndentsApplicable()> - something wrong in paragraph style hierarchy. The applied list style is not found." );
542 return bAreListLevelIndentsApplicable
;
545 void SwTextFormatColl::dumpAsXml(xmlTextWriterPtr pWriter
) const
547 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwTextFormatColl"));
548 if (mpNextTextFormatColl
)
550 (void)xmlTextWriterWriteAttribute(
551 pWriter
, BAD_CAST("next"), BAD_CAST(mpNextTextFormatColl
->GetName().toUtf8().getStr()));
553 if (mpLinkedCharFormat
)
555 (void)xmlTextWriterWriteAttribute(
556 pWriter
, BAD_CAST("linked"), BAD_CAST(mpLinkedCharFormat
->GetName().toUtf8().getStr()));
559 SwFormat::dumpAsXml(pWriter
);
561 (void)xmlTextWriterEndElement(pWriter
);
564 void SwTextFormatColls::dumpAsXml(xmlTextWriterPtr pWriter
) const
566 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwTextFormatColls"));
567 for (size_t i
= 0; i
< size(); ++i
)
568 GetFormat(i
)->dumpAsXml(pWriter
);
569 (void)xmlTextWriterEndElement(pWriter
);
574 SwCollCondition::SwCollCondition( SwTextFormatColl
* pColl
, Master_CollCondition nMasterCond
,
575 sal_uInt32 nSubCond
)
576 : SwClient( pColl
), m_nCondition( nMasterCond
),
577 m_nSubCondition( nSubCond
)
581 SwCollCondition::SwCollCondition( const SwCollCondition
& rCopy
)
582 : SwClient( const_cast<sw::BroadcastingModify
*>(static_cast<const sw::BroadcastingModify
*>(rCopy
.GetRegisteredIn())) ),
583 m_nCondition( rCopy
.m_nCondition
),
584 m_nSubCondition( rCopy
.m_nSubCondition
)
588 SwCollCondition::~SwCollCondition()
592 void SwCollCondition::RegisterToFormat( SwFormat
& rFormat
)
597 bool SwCollCondition::operator==( const SwCollCondition
& rCmp
) const
599 return ( m_nCondition
== rCmp
.m_nCondition
)
600 && ( m_nSubCondition
== rCmp
.m_nSubCondition
);
603 void SwCollCondition::SetCondition( Master_CollCondition nCond
, sal_uInt32 nSubCond
)
605 m_nCondition
= nCond
;
606 m_nSubCondition
= nSubCond
;
609 SwConditionTextFormatColl::~SwConditionTextFormatColl()
613 const SwCollCondition
* SwConditionTextFormatColl::HasCondition(
614 const SwCollCondition
& rCond
) const
616 for (const auto &rpFnd
: m_CondColls
)
625 void SwConditionTextFormatColl::InsertCondition( const SwCollCondition
& rCond
)
627 for (SwFormatCollConditions::size_type n
= 0; n
< m_CondColls
.size(); ++n
)
629 if (*m_CondColls
[ n
] == rCond
)
631 m_CondColls
.erase( m_CondColls
.begin() + n
);
636 // Not found -> so insert it
637 m_CondColls
.push_back( std::make_unique
<SwCollCondition
> (rCond
) );
640 void SwConditionTextFormatColl::RemoveCondition( const SwCollCondition
& rCond
)
642 for (SwFormatCollConditions::size_type n
= 0; n
< m_CondColls
.size(); ++n
)
644 if (*m_CondColls
[ n
] == rCond
)
646 m_CondColls
.erase( m_CondColls
.begin() + n
);
651 void SwConditionTextFormatColl::SetConditions( const SwFormatCollConditions
& rCndClls
)
653 // Copy the Conditions, but first delete the old ones
655 SwDoc
& rDoc
= *GetDoc();
656 for (const auto &rpFnd
: rCndClls
)
658 SwTextFormatColl
*const pTmpColl
= rpFnd
->GetTextFormatColl()
659 ? rDoc
.CopyTextColl( *rpFnd
->GetTextFormatColl() )
661 std::unique_ptr
<SwCollCondition
> pNew
;
662 pNew
.reset(new SwCollCondition( pTmpColl
, rpFnd
->GetCondition(),
663 rpFnd
->GetSubCondition() ));
664 m_CondColls
.push_back( std::move(pNew
) );
668 void SwTextFormatColl::SetAttrOutlineLevel( int nLevel
)
670 OSL_ENSURE( 0 <= nLevel
&& nLevel
<= MAXLEVEL
,"SwTextFormatColl: Level Out Of Range" );
671 SetFormatAttr( SfxUInt16Item( RES_PARATR_OUTLINELEVEL
,
672 o3tl::narrowing
<sal_uInt16
>(nLevel
) ) );
675 int SwTextFormatColl::GetAttrOutlineLevel() const
677 return GetFormatAttr(RES_PARATR_OUTLINELEVEL
).GetValue();
680 int SwTextFormatColl::GetAssignedOutlineStyleLevel() const
682 OSL_ENSURE( IsAssignedToListLevelOfOutlineStyle(),
683 "<SwTextFormatColl::GetAssignedOutlineStyleLevel()> - misuse of method");
684 return GetAttrOutlineLevel() - 1;
687 void SwTextFormatColl::AssignToListLevelOfOutlineStyle(const int nAssignedListLevel
)
689 mbAssignedToOutlineStyle
= true;
690 SetAttrOutlineLevel(nAssignedListLevel
+1);
693 SwIterator
<SwTextFormatColl
,SwFormatColl
> aIter( *this );
694 SwTextFormatColl
* pDerivedTextFormatColl
= aIter
.First();
695 while ( pDerivedTextFormatColl
!= nullptr )
697 if ( !pDerivedTextFormatColl
->IsAssignedToListLevelOfOutlineStyle() )
699 if ( pDerivedTextFormatColl
->GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::DEFAULT
)
702 pDerivedTextFormatColl
->SetFormatAttr( aItem
);
704 if ( pDerivedTextFormatColl
->GetItemState( RES_PARATR_OUTLINELEVEL
, false ) == SfxItemState::DEFAULT
)
706 pDerivedTextFormatColl
->SetAttrOutlineLevel( 0 );
710 pDerivedTextFormatColl
= aIter
.Next();
714 void SwTextFormatColl::DeleteAssignmentToListLevelOfOutlineStyle()
716 mbAssignedToOutlineStyle
= false;
717 ResetFormatAttr(RES_PARATR_OUTLINELEVEL
);
720 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */