summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/doc/doc.cxx18
-rw-r--r--sw/source/core/text/txtfrm.cxx17
-rw-r--r--sw/source/core/txtnode/thints.cxx24
3 files changed, 40 insertions, 19 deletions
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 450fc3aed05c..4f4fb864512e 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1360,17 +1360,20 @@ bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes,
}
}
-bool SwDoc::FieldCanHidePara(SwFieldIds eFieldId) const
+// The greater the returned value, the more weight has this field type on deciding the final
+// paragraph state
+int SwDoc::FieldCanHideParaWeight(SwFieldIds eFieldId) const
{
switch (eFieldId)
{
case SwFieldIds::HiddenPara:
- return true;
+ return 20;
case SwFieldIds::Database:
- return GetDocumentSettingManager().get(
- DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA);
+ return GetDocumentSettingManager().get(DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA)
+ ? 10
+ : 0;
default:
- return false;
+ return 0;
}
}
@@ -1381,7 +1384,8 @@ bool SwDoc::FieldHidesPara(const SwField& rField) const
case SwFieldIds::HiddenPara:
return static_cast<const SwHiddenParaField&>(rField).IsHidden();
case SwFieldIds::Database:
- return FieldCanHidePara(SwFieldIds::Database) && rField.ExpandField(true).isEmpty();
+ return FieldCanHideParaWeight(SwFieldIds::Database)
+ && rField.ExpandField(true).isEmpty();
default:
return false;
}
@@ -1413,7 +1417,7 @@ bool SwDoc::RemoveInvisibleContent()
std::vector<std::unique_ptr<FieldTypeGuard>> aHidingFieldTypes;
for (SwFieldType* pType : *getIDocumentFieldsAccess().GetFieldTypes())
{
- if (FieldCanHidePara(pType->Which()))
+ if (FieldCanHideParaWeight(pType->Which()))
aHidingFieldTypes.push_back(o3tl::make_unique<FieldTypeGuard>(pType));
}
for (const auto& pTypeGuard : aHidingFieldTypes)
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 27f02f554370..62b281ae6974 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -1045,18 +1045,25 @@ bool SwTextFrame::IsHiddenNow() const
}
sw::MergedAttrIter iter(*this);
SwTextNode const* pNode(nullptr);
+ int nNewResultWeight = 0;
for (SwTextAttr const* pHint = iter.NextAttr(&pNode); pHint; pHint = iter.NextAttr(&pNode))
{
if (pHint->Which() == RES_TXTATR_FIELD)
{
+ // see also SwpHints::CalcHiddenParaField()
const SwFormatField& rField = pHint->GetFormatField();
- if (pNode->FieldCanHidePara(rField.GetField()->GetTyp()->Which()))
+ int nCurWeight = pNode->FieldCanHideParaWeight(rField.GetField()->GetTyp()->Which());
+ if (nCurWeight > nNewResultWeight)
{
+ nNewResultWeight = nCurWeight;
+ bHiddenParaField = pNode->FieldHidesPara(*rField.GetField());
+ }
+ else if (nCurWeight == nNewResultWeight && bHiddenParaField)
+ {
+ // Currently, for both supported hiding types (HiddenPara, Database), "Don't hide"
+ // takes precedence - i.e., if there's a "Don't hide" field of that weight, we only
+ // care about fields of higher weight.
bHiddenParaField = pNode->FieldHidesPara(*rField.GetField());
- if (!bHiddenParaField)
- {
- break; // not hidden, see CalcHiddenParaField()
- }
}
}
}
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index 20a732ba1755..ee8593edb708 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1155,7 +1155,7 @@ void SwTextNode::DestroyAttr( SwTextAttr* pAttr )
// certain fields must update the SwDoc's calculation flags
// Certain fields (like HiddenParaField) must trigger recalculation of visible flag
- if (FieldCanHidePara(pFieldType->Which()))
+ if (FieldCanHideParaWeight(pFieldType->Which()))
SetCalcHiddenParaField();
switch( pFieldType->Which() )
@@ -1465,7 +1465,8 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode )
case RES_TXTATR_FIELD:
{
// trigger notification for relevant fields, like HiddenParaFields
- if (FieldCanHidePara(pAttr->GetFormatField().GetField()->GetTyp()->Which()))
+ if (FieldCanHideParaWeight(
+ pAttr->GetFormatField().GetField()->GetTyp()->Which()))
{
bHiddenPara = true;
}
@@ -2590,6 +2591,7 @@ bool SwpHints::CalcHiddenParaField() const
m_bCalcHiddenParaField = false;
const bool bOldHiddenByParaField = m_bHiddenByParaField;
bool bNewHiddenByParaField = false;
+ int nNewResultWeight = 0;
const size_t nSize = Count();
const SwTextAttr* pTextHt;
@@ -2600,12 +2602,20 @@ bool SwpHints::CalcHiddenParaField() const
if (RES_TXTATR_FIELD == nWhich)
{
+ // see also SwTextFrame::IsHiddenNow()
const SwFormatField& rField = pTextHt->GetFormatField();
- if (m_rParent.FieldCanHidePara(rField.GetField()->GetTyp()->Which())
- && !(bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField())))
+ int nCurWeight = m_rParent.FieldCanHideParaWeight(rField.GetField()->GetTyp()->Which());
+ if (nCurWeight > nNewResultWeight)
{
- // If there's at least one field telling not to hide, so be it
- break;
+ nNewResultWeight = nCurWeight;
+ bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField());
+ }
+ else if (nCurWeight == nNewResultWeight && bNewHiddenByParaField)
+ {
+ // Currently, for both supported hiding types (HiddenPara, Database), "Don't hide"
+ // takes precedence - i.e., if there's a "Don't hide" field of that weight, we only
+ // care about fields of higher weight.
+ bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField());
}
}
}
@@ -3287,7 +3297,7 @@ void SwpHints::DeleteAtPos( const size_t nPos )
pTextField->ChgTextNode(nullptr);
}
else if (m_bHiddenByParaField
- && m_rParent.FieldCanHidePara(pFieldTyp->Which()))
+ && m_rParent.FieldCanHideParaWeight(pFieldTyp->Which()))
{
m_bCalcHiddenParaField = true;
}