refactor DocPosUpdate, part 2

- separate the message send from the field manager to the fields
  containing no start index from those send from the field to the
  frames containing an index
- use member functions where possible: SwFieldType, SwFormatField,
  SwTextNode

Change-Id: I488e4003b75bf7b0ae700f39e2364d6e34a8bbfc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147490
Tested-by: Jenkins
Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org>
This commit is contained in:
Bjoern Michaelsen 2023-02-20 02:38:11 +01:00
parent a885d48398
commit 0f959ba9e8
16 changed files with 74 additions and 61 deletions

View file

@ -149,6 +149,8 @@ enum class SfxHintId {
SwSectionHidden,
SwTitleChanged,
SwDescriptionChanged,
SwDocPosUpdate,
SwDocPosUpdateAtIndex,
ThisIsAnSdrHint
};

View file

@ -435,7 +435,6 @@
// class SwPtrMsgPoolItem : public SwMsgPoolItem
// class SwFormatChg: public SwMsgPoolItem
// class SwUpdateAttr : public SwMsgPoolItem
// class SwDocPosUpdate : public SwMsgPoolItem
// class SwTableFormulaUpdate : public SwMsgPoolItem
// class SwAutoFormatGetDocNode: public SwMsgPoolItem
// class SwAttrSetChg: public SwMsgPoolItem

View file

@ -219,7 +219,6 @@ excludelist:
- class SfxStringItem
- class SvXMLAttrContainerItem
- class SwAttrSetChg
- class SwDocPosUpdate
- class SwFormatChg
- class SwFormatMeta
- class SwMsgPoolItem

View file

@ -21,6 +21,7 @@
#include <i18nlangtag/lang.h>
#include "swdllapi.h"
#include "swtypes.hxx"
#include "calbck.hxx"
#include "nodeoffset.hxx"
@ -283,6 +284,7 @@ public:
void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
void GatherDdeTables(std::vector<SwDDETable*>& rvTables) const;
void UpdateDocPos(const SwTwips nDocPos);
virtual void UpdateFields();
};

View file

@ -27,6 +27,7 @@
#include <unotools/weakref.hxx>
#include "swdllapi.h"
#include "swtypes.hxx"
#include "calbck.hxx"
#include "reffld.hxx"
#include "nodeoffset.hxx"
@ -168,6 +169,7 @@ public:
void ForceUpdateTextNode();
void UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* pNew);
void UpdateDocPos(const SwTwips nDocPos);
};
enum class SwFormatFieldHintWhich

View file

@ -31,7 +31,6 @@ class SfxStringItem;
class SwFormatChg;
class SwUpdateAttr;
class SwAttrSetChg;
class SwDocPosUpdate;
class SwFormatMeta;
class SwFormatContentControl;
class SvXMLAttrContainerItem;
@ -434,7 +433,6 @@ constexpr TypedWhichId<SwFormatChg> RES_FMT_CHG(168);
constexpr TypedWhichId<SwAttrSetChg> RES_ATTRSET_CHG(169);
constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(170);
constexpr TypedWhichId<SwPtrMsgPoolItem> RES_REFMARKFLD_UPDATE(171);
constexpr TypedWhichId<SwDocPosUpdate> RES_DOCPOS_UPDATE(172);
constexpr TypedWhichId<SwTableFormulaUpdate> RES_TABLEFML_UPDATE(173);
constexpr TypedWhichId<SwMsgPoolItem> RES_UPDATEDDETBL(174);
constexpr TypedWhichId<SwMsgPoolItem> RES_TBLHEADLINECHG(175);

View file

@ -140,6 +140,30 @@ public:
RedlineUnDelText(sal_Int32 nS, sal_Int32 nL);
};
/** DocPosUpdate is sent to signal that only the frames from or to a specified document-global position
have to be updated. At the moment this is only needed when updating pagenumber fields. */
class DocPosUpdate final : public SfxHint
{
public:
const SwTwips m_nDocPos;
DocPosUpdate(const SwTwips nDocPos)
: SfxHint(SfxHintId::SwDocPosUpdate)
, m_nDocPos(nDocPos)
{};
};
class DocPosUpdateAtIndex final : public SfxHint
{
public:
const SwTwips m_nDocPos;
const SwTextNode& m_rNode;
const sal_uInt32 m_nIndex;
DocPosUpdateAtIndex(const SwTwips nDocPos, const SwTextNode& rNode, sal_uInt32 nIndex)
: SfxHint(SfxHintId::SwDocPosUpdateAtIndex)
, m_nDocPos(nDocPos)
, m_rNode(rNode)
, m_nIndex(nIndex)
{};
};
class CondCollCondChg final : public SfxHint
{
public:
@ -267,15 +291,6 @@ public:
}
};
/** SwDocPosUpdate is sent to signal that only the frames from or to a specified document-global position
have to be updated. At the moment this is only needed when updating pagenumber fields. */
class SwDocPosUpdate final : public SwMsgPoolItem
{
public:
const SwTwips nDocPos;
SwDocPosUpdate( const SwTwips nDocPos );
};
/// SwTableFormulaUpdate is sent when the table has to be newly calculated or when a table itself is merged or split
enum TableFormulaUpdateFlags { TBL_CALC = 0,
TBL_BOXNAME,

View file

@ -237,6 +237,7 @@ public:
public:
using SwContentNode::GetAttr;
void UpdateDocPos(const SwTwips nDocPos, const sal_uInt32 nIndex);
/// for hanging TextFormatCollections somewhere else (Outline-Numbering!)
void TriggerNodeUpdate(const sw::LegacyModifyHint&);

View file

@ -81,11 +81,6 @@ SwUpdateAttr::SwUpdateAttr( sal_Int32 nS, sal_Int32 nE, sal_uInt16 nW, std::vect
{
}
SwDocPosUpdate::SwDocPosUpdate( const SwTwips nDcPos )
: SwMsgPoolItem( RES_DOCPOS_UPDATE ), nDocPos(nDcPos)
{
}
SwTableFormulaUpdate::SwTableFormulaUpdate( const SwTable* pNewTable )
: SwMsgPoolItem( RES_TABLEFML_UPDATE ),
m_pTable( pNewTable ), m_pHistory( nullptr ), m_nSplitLine( USHRT_MAX ),

View file

@ -1337,8 +1337,6 @@ sal_Int32 DocumentFieldsManager::GetRecordsPerDocument() const
void DocumentFieldsManager::UpdatePageFields(const SwTwips nDocPos)
{
SwDocPosUpdate aDosPosUpdate(nDocPos);
sw::LegacyModifyHint aHint(nullptr, &aDosPosUpdate);
for(SwFieldTypes::size_type i = 0; i < INIT_FLDTYPES; ++i)
{
SwFieldType* pFieldType = (*mpFieldTypes)[i].get();
@ -1348,7 +1346,7 @@ void DocumentFieldsManager::UpdatePageFields(const SwTwips nDocPos)
case SwFieldIds::Chapter:
case SwFieldIds::GetExp:
case SwFieldIds::RefPageGet:
pFieldType->CallSwClientNotify(aHint);
pFieldType->UpdateDocPos(nDocPos);
break;
case SwFieldIds::DocStat:
pFieldType->CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));

View file

@ -320,7 +320,7 @@ void SwDDEFieldType::UpdateDDE(const bool bNotifyShells)
for(auto pFormatField: vFields)
{
if(pFormatField->GetTextField())
pFormatField->UpdateTextNode( nullptr, &aUpdateDDE );
pFormatField->UpdateTextNode(nullptr, &aUpdateDDE);
}
// a DDE tables in the text
for(auto pTable: vTables)

View file

@ -269,15 +269,9 @@ std::unique_ptr<SwFieldType> SwGetExpFieldType::Copy() const
return std::make_unique<SwGetExpFieldType>(GetDoc());
}
void SwGetExpFieldType::SwClientNotify(const SwModify&, const SfxHint& rHint)
void SwGetExpFieldType::SwClientNotify(const SwModify&, const SfxHint&)
{
if (rHint.GetId() != SfxHintId::SwLegacyModify)
return;
auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
// do not expand anything else
if(pLegacy->GetWhich() != RES_DOCPOS_UPDATE)
return;
CallSwClientNotify(rHint);
// do not expand anything (else)
}
SwGetExpField::SwGetExpField(SwGetExpFieldType* pTyp, const OUString& rFormel,

View file

@ -210,6 +210,10 @@ void SwFieldType::GatherDdeTables(std::vector<SwDDETable*>& rvTables) const
CallSwClientNotify(sw::GatherDdeTablesHint(rvTables));
}
void SwFieldType::UpdateDocPos(const SwTwips nDocPos)
{
CallSwClientNotify(sw::DocPosUpdate(nDocPos));
}
void SwFieldType::UpdateFields()
{
CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));

View file

@ -2024,6 +2024,20 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint)
{
pDeleteChar = static_cast<const sw::DeleteChar*>(&rHint);
}
else if (rHint.GetId() == SfxHintId::SwDocPosUpdateAtIndex)
{
auto pDocPosAt = static_cast<const sw::DocPosUpdateAtIndex*>(&rHint);
Broadcast(SfxHint()); // notify SwAccessibleParagraph
if(IsLocked())
return;
if(pDocPosAt->m_nDocPos > getFrameArea().Top())
return;
TextFrameIndex const nIndex(MapModelToView(
&pDocPosAt->m_rNode,
pDocPosAt->m_nIndex));
InvalidateRange(SwCharRange(nIndex, TextFrameIndex(1)));
return;
}
else if (auto const pHt = dynamic_cast<sw::MoveText const*>(&rHint))
{
pMoveText = pHt;
@ -2613,23 +2627,6 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint)
#endif
}
break;
// Process SwDocPosUpdate
case RES_DOCPOS_UPDATE:
{
if( pOld && pNew )
{
const SwDocPosUpdate *pDocPos = static_cast<const SwDocPosUpdate*>(pOld);
if( pDocPos->nDocPos <= getFrameArea().Top() )
{
const SwFormatField *pField = static_cast<const SwFormatField *>(pNew);
TextFrameIndex const nIndex(MapModelToView(&rNode,
pField->GetTextField()->GetStart()));
InvalidateRange(SwCharRange(nIndex, TextFrameIndex(1)));
}
}
break;
}
case RES_PARATR_SPLIT:
if ( GetPrev() )
CheckKeep();

View file

@ -302,6 +302,10 @@ void SwFormatField::SwClientNotify( const SwModify& rModify, const SfxHint& rHin
}
pGatherFieldsHint->m_rvFields.push_back(this);
}
else if (rHint.GetId() == SfxHintId::SwDocPosUpdate)
{
UpdateDocPos(static_cast<const sw::DocPosUpdate*>(&rHint)->m_nDocPos);
}
}
namespace
@ -383,6 +387,14 @@ void SwFormatField::ForceUpdateTextNode()
bool bNeedForced = lcl_NeedsForcedUpdate(*mpTextField->GetFormatField().GetField());
mpTextField->ExpandTextField(bNeedForced);
}
void SwFormatField::UpdateDocPos(const SwTwips nDocPos)
{
if (!IsFieldInDoc())
return;
auto pTextNd = &mpTextField->GetTextNode();
pTextNd->UpdateDocPos(nDocPos, mpTextField->GetStart());
}
void SwFormatField::UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* pNew)
{
if (pOld == nullptr && pNew == nullptr)
@ -408,25 +420,14 @@ void SwFormatField::UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* p
SwTextNode* pTextNd = &mpTextField->GetTextNode();
OSL_ENSURE(pTextNd, "Where is my Node?");
bool bTriggerNode = false;
bool bTriggerNode = pNew != nullptr;
bool bExpand = false;
const SfxPoolItem* pNodeOld = nullptr;
const SfxPoolItem* pNodeNew = nullptr;
if(pNew)
{
switch(pNew->Which())
{
case RES_DOCPOS_UPDATE:
// handled in SwTextFrame::Modify()
bTriggerNode = true;
pNodeOld = pNew;
pNodeNew = this;
break;
case RES_ATTRSET_CHG:
case RES_FMT_CHG:
bTriggerNode = true;
pNodeOld = pOld;
pNodeNew = pNew;
break;
case RES_REFMARKFLD_UPDATE:
// update GetRef fields
@ -441,13 +442,13 @@ void SwFormatField::UpdateTextNode(const SfxPoolItem* pOld, const SfxPoolItem* p
auto pType = mpField->GetTyp();
lcl_EnsureUserFieldValid(*pType);
bTriggerNode = lcl_TriggerNode(pType->Which());
pNodeNew = pNew;
bExpand = lcl_ExpandField(pType->Which(), pOld && pOld->Which() == RES_HIDDENPARA_PRINT);
pOld = nullptr;
}
}
}
if(bTriggerNode)
pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pNodeOld, pNodeNew));
pTextNd->TriggerNodeUpdate(sw::LegacyModifyHint(pOld, pNew));
if(bExpand)
mpTextField->ExpandTextField(false);
}

View file

@ -5465,6 +5465,12 @@ void SwTextNode::HandleNonLegacyHint(const SfxHint& rHint)
}
}
void SwTextNode::UpdateDocPos(const SwTwips nDocPos, const sal_uInt32 nIndex)
{
const sw::DocPosUpdateAtIndex aHint(nDocPos, *this, nIndex);
CallSwClientNotify(aHint);
}
void SwTextNode::TriggerNodeUpdate(const sw::LegacyModifyHint& rHint)
{
const auto pOldValue = rHint.m_pOld;