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>
31 #include <fmtcolfunc.hxx>
32 #include <hintids.hxx>
35 #include <numrule.hxx>
37 #include <swfntcch.hxx>
39 namespace TextFormatCollFunc
42 void CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle(
44 const SwNumRuleItem
* pNewNumRuleItem
)
46 SwTextFormatColl
* pTextFormatColl
= dynamic_cast<SwTextFormatColl
*>(pFormat
);
47 if ( !pTextFormatColl
)
49 OSL_FAIL( "<TextFormatCollFunc::CheckTextFormatCollFuncForDeletionOfAssignmentToOutlineStyle> - misuse of method - it's only for instances of <SwTextFormatColl>" );
54 if ( pTextFormatColl
->StayAssignedToListLevelOfOutlineStyle() ||
55 !pTextFormatColl
->IsAssignedToListLevelOfOutlineStyle() )
60 pNewNumRuleItem
= pTextFormatColl
->GetItemIfSet(RES_PARATR_NUMRULE
, false);
64 const OUString
& sNumRuleName
= pNewNumRuleItem
->GetValue();
65 if ( sNumRuleName
.isEmpty() ||
66 sNumRuleName
!= pTextFormatColl
->GetDoc()->GetOutlineNumRule()->GetName() )
68 // delete assignment of paragraph style to list level of outline style.
69 pTextFormatColl
->DeleteAssignmentToListLevelOfOutlineStyle();
74 SwNumRule
* GetNumRule( SwTextFormatColl
& rTextFormatColl
)
76 SwNumRule
* pNumRule( nullptr );
78 const SwNumRuleItem
* pNumRuleItem
= rTextFormatColl
.GetItemIfSet(RES_PARATR_NUMRULE
, false);
81 const OUString
& sNumRuleName
= pNumRuleItem
->GetValue();
82 if ( !sNumRuleName
.isEmpty() )
84 pNumRule
= rTextFormatColl
.GetDoc()->FindNumRulePtr( sNumRuleName
);
91 void AddToNumRule( SwTextFormatColl
& rTextFormatColl
)
93 SwNumRule
* pNumRule
= GetNumRule( rTextFormatColl
);
96 pNumRule
->AddParagraphStyle( rTextFormatColl
);
100 void RemoveFromNumRule( SwTextFormatColl
& rTextFormatColl
)
102 SwNumRule
* pNumRule
= GetNumRule( rTextFormatColl
);
105 pNumRule
->RemoveParagraphStyle( rTextFormatColl
);
108 } // end of namespace TextFormatCollFunc
110 SwTextFormatColl::~SwTextFormatColl()
113 pSwFontCache
->Delete( this );
115 if (GetDoc()->IsInDtor())
120 for (const auto& pCharFormat
: *GetDoc()->GetCharFormats())
122 if (pCharFormat
->GetLinkedParaFormat() == this)
124 pCharFormat
->SetLinkedParaFormat(nullptr);
128 void SwTextFormatColl::SwClientNotify(const SwModify
& rModify
, const SfxHint
& rHint
)
130 if (rHint
.GetId() != SfxHintId::SwLegacyModify
)
132 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
133 if(GetDoc()->IsInDtor())
135 SwFormatColl::SwClientNotify(rModify
, rHint
);
138 bool bNewParent( false ); // #i66431# - adjust type of <bNewParent>
139 const SvxULSpaceItem
*pNewULSpace
= nullptr, *pOldULSpace
= nullptr;
140 const SvxFirstLineIndentItem
*pNewFirstLineIndent
= nullptr;
141 const SvxTextLeftMarginItem
*pNewTextLeftMargin
= nullptr;
142 const SvxRightMarginItem
*pNewRightMargin
= nullptr;
143 const SvxFontHeightItem
* aFontSizeArr
[3] = {nullptr,nullptr,nullptr};
145 const bool bAssignedToListLevelOfOutlineStyle(IsAssignedToListLevelOfOutlineStyle());
146 const SwNumRuleItem
* pNewNumRuleItem( nullptr );
148 const SwAttrSetChg
*pNewChgSet
= nullptr, *pOldChgSet
= nullptr;
149 const auto pOld
= pLegacy
->m_pOld
;
150 const auto pNew
= pLegacy
->m_pNew
;
151 switch( pLegacy
->GetWhich() )
153 case RES_ATTRSET_CHG
:
154 // Only recalculate if we're not the sender!
155 pNewChgSet
= &pNew
->StaticWhichCast(RES_ATTRSET_CHG
);
156 pOldChgSet
= &pOld
->StaticWhichCast(RES_ATTRSET_CHG
);
157 pNewFirstLineIndent
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_FIRSTLINE
, false);
158 pNewTextLeftMargin
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_TEXTLEFT
, false);
159 pNewRightMargin
= pNewChgSet
->GetChgSet()->GetItemIfSet(RES_MARGIN_RIGHT
, false);
160 pNewULSpace
= pNewChgSet
->GetChgSet()->GetItemIfSet( RES_UL_SPACE
, false );
161 aFontSizeArr
[0] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_FONTSIZE
, false );
162 aFontSizeArr
[1] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_CJK_FONTSIZE
, false );
163 aFontSizeArr
[2] = pNewChgSet
->GetChgSet()->GetItemIfSet( RES_CHRATR_CTL_FONTSIZE
, false );
164 // #i70223#, #i84745#
165 // check, if attribute set is applied to this paragraph style
166 if ( bAssignedToListLevelOfOutlineStyle
&&
167 pNewChgSet
->GetTheChgdSet() == &GetAttrSet() )
169 pNewNumRuleItem
= pNewChgSet
->GetChgSet()->GetItemIfSet( RES_PARATR_NUMRULE
, false );
175 if( GetAttrSet().GetParent() )
177 const SfxItemSet
* pParent
= GetAttrSet().GetParent();
178 pNewFirstLineIndent
= &pParent
->Get(RES_MARGIN_FIRSTLINE
);
179 pNewTextLeftMargin
= &pParent
->Get(RES_MARGIN_TEXTLEFT
);
180 pNewRightMargin
= &pParent
->Get(RES_MARGIN_RIGHT
);
181 pNewULSpace
= &pParent
->Get( RES_UL_SPACE
);
182 aFontSizeArr
[0] = &pParent
->Get( RES_CHRATR_FONTSIZE
);
183 aFontSizeArr
[1] = &pParent
->Get( RES_CHRATR_CJK_FONTSIZE
);
184 aFontSizeArr
[2] = &pParent
->Get( RES_CHRATR_CTL_FONTSIZE
);
185 // #i66431# - modify has to be propagated, because of new parent format.
190 case RES_MARGIN_FIRSTLINE
:
191 pNewFirstLineIndent
= &pNew
->StaticWhichCast(RES_MARGIN_FIRSTLINE
);
193 case RES_MARGIN_TEXTLEFT
:
194 pNewTextLeftMargin
= &pNew
->StaticWhichCast(RES_MARGIN_TEXTLEFT
);
196 case RES_MARGIN_RIGHT
:
197 pNewRightMargin
= &pNew
->StaticWhichCast(RES_MARGIN_RIGHT
);
200 pNewULSpace
= &pNew
->StaticWhichCast(RES_UL_SPACE
);
202 case RES_CHRATR_FONTSIZE
:
203 aFontSizeArr
[0] = &pNew
->StaticWhichCast(RES_CHRATR_CJK_FONTSIZE
);
205 case RES_CHRATR_CJK_FONTSIZE
:
206 aFontSizeArr
[1] = &pNew
->StaticWhichCast(RES_CHRATR_CJK_FONTSIZE
);
208 case RES_CHRATR_CTL_FONTSIZE
:
209 aFontSizeArr
[2] = &pNew
->StaticWhichCast(RES_CHRATR_CTL_FONTSIZE
);
212 case RES_PARATR_NUMRULE
:
213 if (bAssignedToListLevelOfOutlineStyle
)
215 pNewNumRuleItem
= &pNew
->StaticWhichCast(RES_PARATR_NUMRULE
);
223 if ( bAssignedToListLevelOfOutlineStyle
&& pNewNumRuleItem
)
225 TextFormatCollFunc::CheckTextFormatCollForDeletionOfAssignmentToOutlineStyle(
226 this, pNewNumRuleItem
);
229 bool bContinue
= true;
231 // Check against the own attributes
232 const SvxFirstLineIndentItem
*pOldFirstLineIndent(GetItemIfSet(RES_MARGIN_FIRSTLINE
, false));
233 if (pNewFirstLineIndent
&& pOldFirstLineIndent
)
235 if (pOldFirstLineIndent
!= pNewFirstLineIndent
) // Avoid recursion (SetAttr!)
238 SvxFirstLineIndentItem
aNew(*pOldFirstLineIndent
);
239 // We had a relative value -> recalculate
240 if( 100 != aNew
.GetPropTextFirstLineOffset() )
242 short nTmp
= aNew
.GetTextFirstLineOffset(); // keep so that we can compare
243 aNew
.SetTextFirstLineOffset(pNewFirstLineIndent
->GetTextFirstLineOffset(),
244 aNew
.GetPropTextFirstLineOffset() );
245 bChg
|= nTmp
!= aNew
.GetTextFirstLineOffset();
249 SetFormatAttr( aNew
);
250 bContinue
= nullptr != pOldChgSet
|| bNewParent
;
252 // We set it to absolute -> do not propagate it further, unless
254 else if( pNewChgSet
)
255 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
258 const SvxTextLeftMarginItem
*pOldTextLeftMargin(GetItemIfSet(RES_MARGIN_TEXTLEFT
, false));
259 if (pNewTextLeftMargin
&& pOldTextLeftMargin
)
261 if (pOldTextLeftMargin
!= pNewTextLeftMargin
) // Avoid recursion (SetAttr!)
264 SvxTextLeftMarginItem
aNew(*pOldTextLeftMargin
);
265 // We had a relative value -> recalculate
266 if( 100 != aNew
.GetPropLeft() )
268 // note: changing from Left to TextLeft - looked wrong with Left
269 tools::Long nTmp
= aNew
.GetTextLeft(); // keep so that we can compare
270 aNew
.SetTextLeft(pNewTextLeftMargin
->GetTextLeft(), aNew
.GetPropLeft());
271 bChg
|= nTmp
!= aNew
.GetTextLeft();
275 SetFormatAttr( aNew
);
276 bContinue
= nullptr != pOldChgSet
|| bNewParent
;
278 // We set it to absolute -> do not propagate it further, unless
280 else if( pNewChgSet
)
281 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
284 const SvxRightMarginItem
*pOldRightMargin(GetItemIfSet(RES_MARGIN_RIGHT
, false));
285 if (pNewRightMargin
&& pOldRightMargin
)
287 if (pOldRightMargin
!= pNewRightMargin
) // Avoid recursion (SetAttr!)
290 SvxRightMarginItem
aNew(*pOldRightMargin
);
291 // We had a relative value -> recalculate
292 if( 100 != aNew
.GetPropRight() )
294 tools::Long nTmp
= aNew
.GetRight(); // keep so that we can compare
295 aNew
.SetRight(pNewRightMargin
->GetRight(), aNew
.GetPropRight());
296 bChg
|= nTmp
!= aNew
.GetRight();
300 SetFormatAttr( aNew
);
301 bContinue
= nullptr != pOldChgSet
|| bNewParent
;
303 // We set it to absolute -> do not propagate it further, unless
305 else if( pNewChgSet
)
306 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
310 if( pNewULSpace
&& (pOldULSpace
= GetItemIfSet(RES_UL_SPACE
, false)) &&
311 pOldULSpace
!= pNewULSpace
) // Avoid recursion (SetAttr!)
313 SvxULSpaceItem
aNew( *pOldULSpace
);
315 // We had a relative value -> recalculate
316 if( 100 != aNew
.GetPropUpper() )
318 sal_uInt16 nTmp
= aNew
.GetUpper(); // keep so that we can compare
319 aNew
.SetUpper( pNewULSpace
->GetUpper(), aNew
.GetPropUpper() );
320 bChg
|= nTmp
!= aNew
.GetUpper();
322 // We had a relative value -> recalculate
323 if( 100 != aNew
.GetPropLower() )
325 sal_uInt16 nTmp
= aNew
.GetLower(); // keep so that we can compare
326 aNew
.SetLower( pNewULSpace
->GetLower(), aNew
.GetPropLower() );
327 bChg
|= nTmp
!= aNew
.GetLower();
331 SetFormatAttr( aNew
);
332 bContinue
= nullptr != pOldChgSet
|| bNewParent
;
334 // We set it to absolute -> do not propagate it further, unless
336 else if( pNewChgSet
)
337 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
340 for( int nC
= 0; nC
< int(SAL_N_ELEMENTS(aFontSizeArr
)); ++nC
)
342 const SvxFontHeightItem
*pFSize
= aFontSizeArr
[ nC
], *pOldFSize
;
343 if( pFSize
&& (SfxItemState::SET
== GetItemState(
344 pFSize
->Which(), false, reinterpret_cast<const SfxPoolItem
**>(&pOldFSize
) )) &&
345 // Avoid recursion (SetAttr!)
346 pFSize
!= pOldFSize
)
348 if( 100 == pOldFSize
->GetProp() &&
349 MapUnit::MapRelative
== pOldFSize
->GetPropUnit() )
351 // We set it to absolute -> do not propagate it further, unless
354 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
358 // We had a relative value -> recalculate
359 sal_uInt32 nTmp
= pOldFSize
->GetHeight(); // keep so that we can compare
360 SvxFontHeightItem
aNew(240 , 100, pFSize
->Which());
361 aNew
.SetHeight( pFSize
->GetHeight(), pOldFSize
->GetProp(),
362 pOldFSize
->GetPropUnit() );
363 if( nTmp
!= aNew
.GetHeight() )
365 SetFormatAttr( aNew
);
366 bContinue
= nullptr != pOldChgSet
|| bNewParent
;
368 // We set it to absolute -> do not propagate it further, unless
370 else if( pNewChgSet
)
371 bContinue
= pNewChgSet
->GetTheChgdSet() == &GetAttrSet();
377 SwFormatColl::SwClientNotify(rModify
, rHint
);
380 void SwTextFormatColl::SetLinkedCharFormat(SwCharFormat
* pLink
) { mpLinkedCharFormat
= pLink
; }
382 const SwCharFormat
* SwTextFormatColl::GetLinkedCharFormat() const { return mpLinkedCharFormat
; }
384 bool SwTextFormatColl::IsAtDocNodeSet() const
386 SwIterator
<SwContentNode
,SwFormatColl
> aIter( *this );
387 const SwNodes
& rNds
= GetDoc()->GetNodes();
388 for( SwContentNode
* pNode
= aIter
.First(); pNode
; pNode
= aIter
.Next() )
389 if( &(pNode
->GetNodes()) == &rNds
)
395 bool SwTextFormatColl::SetFormatAttr( const SfxPoolItem
& rAttr
)
397 const bool bIsNumRuleItem
= rAttr
.Which() == RES_PARATR_NUMRULE
;
398 if ( bIsNumRuleItem
)
400 TextFormatCollFunc::RemoveFromNumRule( *this );
403 const bool bRet
= SwFormatColl::SetFormatAttr( rAttr
);
405 if ( bIsNumRuleItem
)
407 TextFormatCollFunc::AddToNumRule( *this );
413 bool SwTextFormatColl::SetFormatAttr( const SfxItemSet
& rSet
)
415 const bool bIsNumRuleItemAffected
=
416 rSet
.GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
;
417 if ( bIsNumRuleItemAffected
)
419 TextFormatCollFunc::RemoveFromNumRule( *this );
422 const bool bRet
= SwFormatColl::SetFormatAttr( rSet
);
424 if ( bIsNumRuleItemAffected
)
426 TextFormatCollFunc::AddToNumRule( *this );
432 bool SwTextFormatColl::ResetFormatAttr( sal_uInt16 nWhich1
, sal_uInt16 nWhich2
)
434 const bool bIsNumRuleItemAffected
=
435 ( nWhich2
!= 0 && nWhich2
> nWhich1
)
436 ? ( nWhich1
<= RES_PARATR_NUMRULE
&&
437 RES_PARATR_NUMRULE
<= nWhich2
)
438 : nWhich1
== RES_PARATR_NUMRULE
;
439 if ( bIsNumRuleItemAffected
)
441 TextFormatCollFunc::RemoveFromNumRule( *this );
444 const bool bRet
= SwFormatColl::ResetFormatAttr( nWhich1
, nWhich2
);
450 sal_uInt16
SwTextFormatColl::ResetAllFormatAttr()
452 const bool bOldState( mbStayAssignedToListLevelOfOutlineStyle
);
453 mbStayAssignedToListLevelOfOutlineStyle
= true;
455 // Outline level is no longer a member, it is an attribute now.
456 // Thus, it needs to be restored, if the paragraph style is assigned
457 // to the outline style
458 const int nAssignedOutlineStyleLevel
= IsAssignedToListLevelOfOutlineStyle()
459 ? GetAssignedOutlineStyleLevel()
462 sal_uInt16 nRet
= SwFormatColl::ResetAllFormatAttr();
465 if ( nAssignedOutlineStyleLevel
!= -1 )
467 AssignToListLevelOfOutlineStyle( nAssignedOutlineStyleLevel
);
470 mbStayAssignedToListLevelOfOutlineStyle
= bOldState
;
475 ::sw::ListLevelIndents
SwTextFormatColl::AreListLevelIndentsApplicable() const
477 ::sw::ListLevelIndents
ret(::sw::ListLevelIndents::No
);
478 if (AreListLevelIndentsApplicableImpl(RES_MARGIN_FIRSTLINE
))
480 ret
|= ::sw::ListLevelIndents::FirstLine
;
482 if (AreListLevelIndentsApplicableImpl(RES_MARGIN_TEXTLEFT
))
484 ret
|= ::sw::ListLevelIndents::LeftMargin
;
489 bool SwTextFormatColl::AreListLevelIndentsApplicableImpl(sal_uInt16
const nWhich
) const
491 bool bAreListLevelIndentsApplicable( true );
493 if ( GetItemState( RES_PARATR_NUMRULE
) != SfxItemState::SET
)
495 // no list style applied to paragraph style
496 bAreListLevelIndentsApplicable
= false;
498 else if (GetItemState(nWhich
, false ) == SfxItemState::SET
)
500 // paragraph style has hard-set indent attributes
501 bAreListLevelIndentsApplicable
= false;
503 else if ( GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
)
505 // list style is directly applied to paragraph style and paragraph
506 // style has no hard-set indent attributes
507 bAreListLevelIndentsApplicable
= true;
511 // list style is applied through one of the parent paragraph styles and
512 // paragraph style has no hard-set indent attributes
514 // check parent paragraph styles
515 const SwTextFormatColl
* pColl
= dynamic_cast<const SwTextFormatColl
*>(DerivedFrom());
518 if (pColl
->GetAttrSet().GetItemState(nWhich
, false) == SfxItemState::SET
)
520 // indent attributes found in the paragraph style hierarchy.
521 bAreListLevelIndentsApplicable
= false;
525 if ( pColl
->GetAttrSet().GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::SET
)
527 // paragraph style with the list style found and until now no
528 // indent attributes are found in the paragraph style hierarchy.
529 bAreListLevelIndentsApplicable
= true;
533 pColl
= dynamic_cast<const SwTextFormatColl
*>(pColl
->DerivedFrom());
535 "<SwTextFormatColl::AreListLevelIndentsApplicable()> - something wrong in paragraph style hierarchy. The applied list style is not found." );
539 return bAreListLevelIndentsApplicable
;
542 void SwTextFormatColl::dumpAsXml(xmlTextWriterPtr pWriter
) const
544 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwTextFormatColl"));
545 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
546 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
547 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("name"), BAD_CAST(GetName().toUtf8().getStr()));
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()));
558 GetAttrSet().dumpAsXml(pWriter
);
559 (void)xmlTextWriterEndElement(pWriter
);
562 void SwTextFormatColls::dumpAsXml(xmlTextWriterPtr pWriter
) const
564 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwTextFormatColls"));
565 for (size_t i
= 0; i
< size(); ++i
)
566 GetFormat(i
)->dumpAsXml(pWriter
);
567 (void)xmlTextWriterEndElement(pWriter
);
572 SwCollCondition::SwCollCondition( SwTextFormatColl
* pColl
, Master_CollCondition nMasterCond
,
573 sal_uInt32 nSubCond
)
574 : SwClient( pColl
), m_nCondition( nMasterCond
),
575 m_nSubCondition( nSubCond
)
579 SwCollCondition::SwCollCondition( const SwCollCondition
& rCopy
)
580 : SwClient( const_cast<sw::BroadcastingModify
*>(static_cast<const sw::BroadcastingModify
*>(rCopy
.GetRegisteredIn())) ),
581 m_nCondition( rCopy
.m_nCondition
),
582 m_nSubCondition( rCopy
.m_nSubCondition
)
586 SwCollCondition::~SwCollCondition()
590 void SwCollCondition::RegisterToFormat( SwFormat
& rFormat
)
595 bool SwCollCondition::operator==( const SwCollCondition
& rCmp
) const
597 return ( m_nCondition
== rCmp
.m_nCondition
)
598 && ( m_nSubCondition
== rCmp
.m_nSubCondition
);
601 void SwCollCondition::SetCondition( Master_CollCondition nCond
, sal_uInt32 nSubCond
)
603 m_nCondition
= nCond
;
604 m_nSubCondition
= nSubCond
;
607 SwConditionTextFormatColl::~SwConditionTextFormatColl()
611 const SwCollCondition
* SwConditionTextFormatColl::HasCondition(
612 const SwCollCondition
& rCond
) const
614 for (const auto &rpFnd
: m_CondColls
)
623 void SwConditionTextFormatColl::InsertCondition( const SwCollCondition
& rCond
)
625 for (SwFormatCollConditions::size_type n
= 0; n
< m_CondColls
.size(); ++n
)
627 if (*m_CondColls
[ n
] == rCond
)
629 m_CondColls
.erase( m_CondColls
.begin() + n
);
634 // Not found -> so insert it
635 m_CondColls
.push_back( std::make_unique
<SwCollCondition
> (rCond
) );
638 void SwConditionTextFormatColl::RemoveCondition( const SwCollCondition
& rCond
)
640 for (SwFormatCollConditions::size_type n
= 0; n
< m_CondColls
.size(); ++n
)
642 if (*m_CondColls
[ n
] == rCond
)
644 m_CondColls
.erase( m_CondColls
.begin() + n
);
649 void SwConditionTextFormatColl::SetConditions( const SwFormatCollConditions
& rCndClls
)
651 // Copy the Conditions, but first delete the old ones
653 SwDoc
& rDoc
= *GetDoc();
654 for (const auto &rpFnd
: rCndClls
)
656 SwTextFormatColl
*const pTmpColl
= rpFnd
->GetTextFormatColl()
657 ? rDoc
.CopyTextColl( *rpFnd
->GetTextFormatColl() )
659 std::unique_ptr
<SwCollCondition
> pNew
;
660 pNew
.reset(new SwCollCondition( pTmpColl
, rpFnd
->GetCondition(),
661 rpFnd
->GetSubCondition() ));
662 m_CondColls
.push_back( std::move(pNew
) );
666 void SwTextFormatColl::SetAttrOutlineLevel( int nLevel
)
668 OSL_ENSURE( 0 <= nLevel
&& nLevel
<= MAXLEVEL
,"SwTextFormatColl: Level Out Of Range" );
669 SetFormatAttr( SfxUInt16Item( RES_PARATR_OUTLINELEVEL
,
670 o3tl::narrowing
<sal_uInt16
>(nLevel
) ) );
673 int SwTextFormatColl::GetAttrOutlineLevel() const
675 return GetFormatAttr(RES_PARATR_OUTLINELEVEL
).GetValue();
678 int SwTextFormatColl::GetAssignedOutlineStyleLevel() const
680 OSL_ENSURE( IsAssignedToListLevelOfOutlineStyle(),
681 "<SwTextFormatColl::GetAssignedOutlineStyleLevel()> - misuse of method");
682 return GetAttrOutlineLevel() - 1;
685 void SwTextFormatColl::AssignToListLevelOfOutlineStyle(const int nAssignedListLevel
)
687 mbAssignedToOutlineStyle
= true;
688 SetAttrOutlineLevel(nAssignedListLevel
+1);
691 SwIterator
<SwTextFormatColl
,SwFormatColl
> aIter( *this );
692 SwTextFormatColl
* pDerivedTextFormatColl
= aIter
.First();
693 while ( pDerivedTextFormatColl
!= nullptr )
695 if ( !pDerivedTextFormatColl
->IsAssignedToListLevelOfOutlineStyle() )
697 if ( pDerivedTextFormatColl
->GetItemState( RES_PARATR_NUMRULE
, false ) == SfxItemState::DEFAULT
)
700 pDerivedTextFormatColl
->SetFormatAttr( aItem
);
702 if ( pDerivedTextFormatColl
->GetItemState( RES_PARATR_OUTLINELEVEL
, false ) == SfxItemState::DEFAULT
)
704 pDerivedTextFormatColl
->SetAttrOutlineLevel( 0 );
708 pDerivedTextFormatColl
= aIter
.Next();
712 void SwTextFormatColl::DeleteAssignmentToListLevelOfOutlineStyle()
714 mbAssignedToOutlineStyle
= false;
715 ResetFormatAttr(RES_PARATR_OUTLINELEVEL
);
718 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */