Skip to content

Commit

Permalink
convert RES_OBJECTDYING to SfxHint
Browse files Browse the repository at this point in the history
and remove SwPtrMsgPoolItem, which is now unused

Change-Id: I4f5246aa03e300d78b81801c54255b3ab68ce312
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179781
Reviewed-by: Noel Grandin <[email protected]>
Tested-by: Jenkins
  • Loading branch information
grandinj committed Jan 6, 2025
1 parent f5cb16b commit cc56bf5
Show file tree
Hide file tree
Showing 44 changed files with 270 additions and 230 deletions.
1 change: 1 addition & 0 deletions include/svl/hint.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ enum class SfxHintId {
SwHiddenParaPrint,
SwFormatChange,
SwAttrSetChange,
SwObjectDying,

ThisIsAnSdrHint,
ThisIsAnSfxEventHint
Expand Down
1 change: 0 additions & 1 deletion sw/IwyuFilter_sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ excludelist:
- class SwFormatChg
- class SwFormatMeta
- class SwMsgPoolItem
- class SwPtrMsgPoolItem
- class SwUpdateAttr
- class SfxBoolItem
- class SvxCharSetColorItem
Expand Down
3 changes: 2 additions & 1 deletion sw/inc/calbck.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace sw
{
class ClientIteratorBase;
class ListenerEntry;
class ObjectDyingHint;
enum class IteratorMode { Exact, UnwrapMulti };
}

Expand Down Expand Up @@ -170,7 +171,7 @@ namespace sw

// in case an SwModify object is destroyed that itself is registered in another SwModify,
// its SwClient objects can decide to get registered to the latter instead by calling this method
std::optional<sw::ModifyChangedHint> CheckRegistration( const SfxPoolItem* pOldValue );
std::optional<sw::ModifyChangedHint> CheckRegistration( const sw::ObjectDyingHint& rHint );
// SwFormat wants to die different than the rest: It wants to reparent every client to its parent
// and then send a SwFormatChg hint.
void CheckRegistrationFormat(SwFormat& rOld);
Expand Down
5 changes: 1 addition & 4 deletions sw/inc/deletelistener.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ private:

virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override
{
if (rHint.GetId() != SfxHintId::SwLegacyModify)
return;
auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
if (pLegacy->GetWhich() == RES_OBJECTDYING)
if (rHint.GetId() == SfxHintId::SwObjectDying)
{
m_pModify->Remove(*this);
m_pModify = nullptr;
Expand Down
8 changes: 0 additions & 8 deletions sw/inc/fmtcol.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ public:
{
m_bInSwFntCache = false;
}
else
{
switch(nWhich)
{
case RES_OBJECTDYING:
m_bInSwFntCache = false;
}
}
};
virtual void InvalidateInSwFntCache() override
{
Expand Down
6 changes: 3 additions & 3 deletions sw/inc/hintids.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class SwFormatMeta;
class SwFormatContentControl;
class SvXMLAttrContainerItem;
class SwMsgPoolItem;
class SwPtrMsgPoolItem;
class SfxBoolItem;
class SvxColorItem;
class SvxLeftMarginItem;
Expand Down Expand Up @@ -426,10 +425,11 @@ inline constexpr sal_uInt16 RES_FMT_END(167);

// ID's for Messages in the Formats
inline constexpr sal_uInt16 RES_FORMAT_MSG_BEGIN(RES_FMT_END);
inline constexpr TypedWhichId<SwPtrMsgPoolItem> RES_OBJECTDYING(RES_FORMAT_MSG_BEGIN); // 167
inline constexpr sal_uInt16 RES_UPDATEATTR_FMT_CHG(
168); // used by SwUpdateAttr just as an ID to communicate what has changed
167); // used by SwUpdateAttr just as an ID to communicate what has changed
inline constexpr sal_uInt16 RES_UPDATEATTR_ATTRSET_CHG(
168); // used by SwUpdateAttr just as an ID to communicate what has changed
inline constexpr sal_uInt16 RES_UPDATEATTR_OBJECTDYING(
169); // used by SwUpdateAttr just as an ID to communicate what has changed
inline constexpr TypedWhichId<SwUpdateAttr> RES_UPDATE_ATTR(170);
// empty
Expand Down
18 changes: 6 additions & 12 deletions sw/inc/hints.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ public:
virtual SwMsgPoolItem* Clone( SfxItemPool* pPool = nullptr ) const override;
};

// SwPtrMsgPoolItem (old SwObjectDying!)

class SwPtrMsgPoolItem final : public SwMsgPoolItem
{
public:
void * pObject;

SwPtrMsgPoolItem( sal_uInt16 nId, void * pObj )
: SwMsgPoolItem( nId ), pObject( pObj )
{}
};

/**
* SwFormatChg is sent when a format has changed to another format.
*/
Expand Down Expand Up @@ -327,6 +315,12 @@ public:
const SwAttrSetChg* m_pNew;
AttrSetChangeHint(const SwAttrSetChg* pOld, const SwAttrSetChg* pNew) : SfxHint(SfxHintId::SwAttrSetChange), m_pOld(pOld), m_pNew(pNew) {}
};
class ObjectDyingHint final : public SfxHint
{
public:
SwModify* m_pDying;
ObjectDyingHint(SwModify* pDead) : SfxHint(SfxHintId::SwObjectDying), m_pDying(pDead) {}
};
} // namespace sw

class SwUpdateAttr final : public SwMsgPoolItem
Expand Down
1 change: 1 addition & 0 deletions sw/inc/ndtxt.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public:
void TriggerNodeUpdate(const sw::LegacyModifyHint&);
void TriggerNodeUpdate(const sw::AttrSetChangeHint&);
void TriggerNodeUpdate(const sw::RemoveUnoObjectHint&);
void TriggerNodeUpdate(const sw::ObjectDyingHint&);
void TriggerNodeUpdate(const SwFormatChangeHint&);

const OUString& GetText() const { return m_Text; }
Expand Down
4 changes: 3 additions & 1 deletion sw/inc/swevent.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ struct SwCallMouseEvent final
if (!GetRegisteredIn() || pChgHint->m_pOldFormat == PTR.pFormat)
Clear();
}
else if (rHint.GetId() == SfxHintId::SwLegacyModify || SfxHintId::SwAttrSetChange == rHint.GetId())
else if (rHint.GetId() == SfxHintId::SwLegacyModify
|| SfxHintId::SwAttrSetChange == rHint.GetId()
|| SfxHintId::SwObjectDying == rHint.GetId())
{
assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType);
SwClient::SwClientNotify(rMod, rHint);
Expand Down
1 change: 1 addition & 0 deletions sw/inc/txtatr.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public:
void TriggerNodeUpdate(const sw::LegacyModifyHint&);
void TriggerNodeUpdate(const SwFormatChangeHint&);
void TriggerNodeUpdate(const sw::AttrSetChangeHint&);
void TriggerNodeUpdate(const sw::ObjectDyingHint&);

// get and set TextNode pointer
void ChgTextNode( SwTextNode* pNew ) { m_pTextNode = pNew; }
Expand Down
1 change: 0 additions & 1 deletion sw/source/core/attr/BorderCacheOwner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void BorderCacheOwner::InvalidateInSwCache(const sal_uInt16 nWhich)
{
switch (nWhich)
{
case RES_OBJECTDYING:
case RES_UL_SPACE:
case RES_MARGIN_FIRSTLINE:
case RES_MARGIN_TEXTLEFT:
Expand Down
39 changes: 15 additions & 24 deletions sw/source/core/attr/calbck.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ namespace sw
{ return m_pToTell == nullptr || m_pToTell->GetInfo( rInfo ); }
void ListenerEntry::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
{
if (rHint.GetId() == SfxHintId::SwLegacyModify)
if (rHint.GetId() == SfxHintId::SwObjectDying)
{
auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
if (pLegacyHint->m_pNew && pLegacyHint->m_pNew->Which() == RES_OBJECTDYING)
{
auto pModifyChanged = CheckRegistration(pLegacyHint->m_pOld);
if (pModifyChanged)
m_pToTell->SwClientNotify(rModify, *pModifyChanged);
}
else if (m_pToTell)
m_pToTell->SwClientNotify(rModify, rHint);
auto pDyingHint = static_cast<const sw::ObjectDyingHint*>(&rHint);
auto pModifyChanged = CheckRegistration(*pDyingHint);
if (pModifyChanged)
m_pToTell->SwClientNotify(rModify, *pModifyChanged);
}
else if (m_pToTell)
m_pToTell->SwClientNotify(rModify, rHint);
Expand Down Expand Up @@ -78,16 +73,11 @@ sw::ClientBase<T>::~ClientBase()
}

template<typename T>
std::optional<sw::ModifyChangedHint> sw::ClientBase<T>::CheckRegistration( const SfxPoolItem* pOld )
std::optional<sw::ModifyChangedHint> sw::ClientBase<T>::CheckRegistration( const sw::ObjectDyingHint& rHint )
{
DBG_TESTSOLARMUTEX();
// this method only handles notification about dying SwModify objects
if( !pOld || pOld->Which() != RES_OBJECTDYING )
return {};

assert(dynamic_cast<const SwPtrMsgPoolItem*>(pOld));
const SwPtrMsgPoolItem* pDead = static_cast<const SwPtrMsgPoolItem*>(pOld);
if(pDead->pObject != m_pRegisteredIn)
if(rHint.m_pDying != m_pRegisteredIn)
{
// we should only care received death notes from objects we are following
return {};
Expand Down Expand Up @@ -123,10 +113,10 @@ void sw::ClientBase<T>::CheckRegistrationFormat(SwFormat& rOld)
template<typename T>
void sw::ClientBase<T>::SwClientNotify(const SwModify&, const SfxHint& rHint)
{
if (rHint.GetId() != SfxHintId::SwLegacyModify)
if (rHint.GetId() != SfxHintId::SwObjectDying)
return;
auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
CheckRegistration(pLegacyHint->m_pOld);
auto pDyingHint = static_cast<const sw::ObjectDyingHint*>(&rHint);
CheckRegistration(*pDyingHint);
};

template<typename T>
Expand All @@ -151,15 +141,15 @@ SwModify::~SwModify()
OSL_ENSURE( !IsModifyLocked(), "Modify destroyed but locked." );

// notify all clients that they shall remove themselves
SwPtrMsgPoolItem aDyObject( RES_OBJECTDYING, this );
SwModify::SwClientNotify(*this, sw::LegacyModifyHint(&aDyObject, &aDyObject));
sw::ObjectDyingHint aDyObject( this );
SwModify::SwClientNotify(*this, aDyObject);

const bool hasListenersOnDeath = m_pWriterListeners;
(void)hasListenersOnDeath;
while(m_pWriterListeners)
{
SAL_WARN("sw.core", "lost a client of type: " << typeid(*m_pWriterListeners).name() << " at " << m_pWriterListeners << " still registered on type: " << typeid(*this).name() << " at " << this << ".");
static_cast<SwClient*>(m_pWriterListeners)->CheckRegistration(&aDyObject);
static_cast<SwClient*>(m_pWriterListeners)->CheckRegistration(aDyObject);
}
assert(!hasListenersOnDeath);
}
Expand Down Expand Up @@ -220,7 +210,8 @@ void SwModify::SwClientNotify(const SwModify&, const SfxHint& rHint)
{
if (rHint.GetId() != SfxHintId::SwLegacyModify
&& rHint.GetId() != SfxHintId::SwRemoveUnoObject
&& rHint.GetId() != SfxHintId::SwAttrSetChange)
&& rHint.GetId() != SfxHintId::SwAttrSetChange
&& rHint.GetId() != SfxHintId::SwObjectDying)
return;

DBG_TESTSOLARMUTEX();
Expand Down
71 changes: 34 additions & 37 deletions sw/source/core/attr/format.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -264,53 +264,50 @@ void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint)
}
return;
}
if (rHint.GetId() == SfxHintId::SwObjectDying)
{
auto pDyingHint = static_cast<const sw::ObjectDyingHint*>(&rHint);
InvalidateInSwCache();
// If the dying object is the parent format of this format so
// attach this to the parent of the parent
SwFormat* pFormat = static_cast<SwFormat*>(pDyingHint->m_pDying);

// do not move if this is the topmost format
if(GetRegisteredIn() && GetRegisteredIn() == pFormat)
{
if(pFormat->GetRegisteredIn())
{
// if parent so register in new parent
pFormat->DerivedFrom()->Add(*this);
m_aSet.SetParent(&DerivedFrom()->m_aSet);
}
else
{
// otherwise de-register at least from dying one
EndListeningAll();
m_aSet.SetParent(nullptr);
}
}
InvalidateInSwFntCache();
SwModify::SwClientNotify(*this, rHint);
return;
}
if (rHint.GetId() != SfxHintId::SwLegacyModify)
return;
auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);

std::optional<SwAttrSetChg> oOldClientChg, oNewClientChg;
std::optional<sw::LegacyModifyHint> oDependsHint(std::in_place, pLegacy->m_pOld, pLegacy->m_pNew);
const sal_uInt16 nWhich = pLegacy->GetWhich();
InvalidateInSwCache(nWhich);
switch(nWhich)
if(nWhich != 0)
{
case 0:
break;
case RES_OBJECTDYING:
// attribute is defined in this format
if(SfxItemState::SET == m_aSet.GetItemState(nWhich, false))
{
// NB: this still notifies depends even if pLegacy->m_pNew is nullptr, which seems non-obvious
if(!pLegacy->m_pNew)
break;
// If the dying object is the parent format of this format so
// attach this to the parent of the parent
SwFormat* pFormat = static_cast<SwFormat*>(pLegacy->m_pNew->StaticWhichCast(RES_OBJECTDYING).pObject);

// do not move if this is the topmost format
if(GetRegisteredIn() && GetRegisteredIn() == pFormat)
{
if(pFormat->GetRegisteredIn())
{
// if parent so register in new parent
pFormat->DerivedFrom()->Add(*this);
m_aSet.SetParent(&DerivedFrom()->m_aSet);
}
else
{
// otherwise de-register at least from dying one
EndListeningAll();
m_aSet.SetParent(nullptr);
}
}
break;
// DropCaps might come into this block
SAL_WARN_IF(RES_PARATR_DROP != nWhich, "sw.core", "Hint was sent without sender");
oDependsHint.reset();
}
default:
// attribute is defined in this format
if(SfxItemState::SET == m_aSet.GetItemState(nWhich, false))
{
// DropCaps might come into this block
SAL_WARN_IF(RES_PARATR_DROP != nWhich, "sw.core", "Hint was sent without sender");
oDependsHint.reset();
}
}
if(oDependsHint)
{
Expand Down
12 changes: 7 additions & 5 deletions sw/source/core/crsr/crsrsh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2917,21 +2917,23 @@ void SwCursorShell::SwClientNotify(const SwModify&, const SfxHint& rHint)
CallChgLnk();
return;
}
if (rHint.GetId() == SfxHintId::SwObjectDying)
{
EndListeningAll();
return;
}
if (rHint.GetId() != SfxHintId::SwLegacyModify)
return;
auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
auto nWhich = pLegacy->GetWhich();
if(!nWhich)
nWhich = RES_OBJECTDYING;
if( m_bCallChgLnk &&
( !isFormatMessage(nWhich)
|| nWhich == RES_UPDATE_ATTR ))
( nWhich == 0 || !isFormatMessage(nWhich) || nWhich == RES_UPDATE_ATTR ))
// messages are not forwarded
// #i6681#: RES_UPDATE_ATTR is implicitly unset in
// SwTextNode::Insert(SwTextHint*, sal_uInt16); we react here and thus do
// not need to send the expensive RES_FMT_CHG in Insert.
CallChgLnk();
if( nWhich == RES_OBJECTDYING )
if( nWhich == 0 )
{
EndListeningAll();
}
Expand Down
15 changes: 3 additions & 12 deletions sw/source/core/doc/acmplwrd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,9 @@ void SwAutoCompleteClient::Notify(const SfxHint& rHint)
case SfxHintId::SwRemoveUnoObject:
DocumentDying();
return;
case SfxHintId::SwLegacyModify:
{
auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
switch(pLegacy->GetWhich())
{
case RES_OBJECTDYING:
DocumentDying();
return;
default:
return;
}
}
case SfxHintId::SwObjectDying:
DocumentDying();
return;
default:
return;
}
Expand Down
6 changes: 3 additions & 3 deletions sw/source/core/doc/docftn.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ void SwEndNoteInfo::UpdateFormatOrAttr()

void SwEndNoteInfo::SwClientNotify( const SwModify& rModify, const SfxHint& rHint)
{
if (rHint.GetId() == SfxHintId::SwLegacyModify)
if (rHint.GetId() == SfxHintId::SwObjectDying)
{
auto pLegacyHint = static_cast<const sw::LegacyModifyHint*>(&rHint);
CheckRegistration( pLegacyHint->m_pOld );
auto pDyingHint = static_cast<const sw::ObjectDyingHint*>(&rHint);
CheckRegistration( *pDyingHint );
}
else if (rHint.GetId() == SfxHintId::SwFormatChange || rHint.GetId() == SfxHintId::SwAttrSetChange)
{
Expand Down
Loading

0 comments on commit cc56bf5

Please sign in to comment.