editeng/source/items/paraitem.cxx | 13 +++++++++++++ include/editeng/lspcitem.hxx | 9 +++++++-- sw/inc/paratr.hxx | 10 ++++++---- sw/source/core/para/paratr.cxx | 15 +++++++++++++++ sw/source/filter/html/htmlcss1.cxx | 8 ++++---- sw/source/filter/html/htmlctxt.cxx | 2 +- sw/source/filter/ww8/ww8par.cxx | 8 ++++---- sw/source/ui/chrdlg/drpcps.cxx | 14 +++++++------- 8 files changed, 57 insertions(+), 22 deletions(-)
New commits: commit 978f0071425e89d21225bdd2976abe15e964b6c1 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Aug 22 20:22:02 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 23 17:45:22 2024 +0200 tdf#158556 make SvxLineSpacingItem hashable Change-Id: I19d88a35332ab3aa07e88085742d92cb48d5ff79 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172293 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/editeng/source/items/paraitem.cxx b/editeng/source/items/paraitem.cxx index 27331148d486..3978db4bc6d5 100644 --- a/editeng/source/items/paraitem.cxx +++ b/editeng/source/items/paraitem.cxx @@ -110,6 +110,17 @@ bool SvxLineSpacingItem::operator==( const SfxPoolItem& rAttr ) const && (nInterLineSpace == rLineSpace.nInterLineSpace))); } +size_t SvxLineSpacingItem::hashCode() const +{ + std::size_t seed(0); + o3tl::hash_combine(seed, eLineSpaceRule); + o3tl::hash_combine(seed, nLineHeight); + o3tl::hash_combine(seed, eInterLineSpaceRule); + o3tl::hash_combine(seed, nPropLineSpace); + o3tl::hash_combine(seed, nInterLineSpace); + return seed; +} + /* Who does still know why the LineSpacingItem is so complicated? We can not use it for UNO since there are only two values: - a sal_uInt16 for the mode @@ -162,6 +173,7 @@ bool SvxLineSpacingItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const bool SvxLineSpacingItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); nMemberId &= ~CONVERT_TWIPS; @@ -329,6 +341,7 @@ sal_uInt16 SvxLineSpacingItem::GetEnumValue() const void SvxLineSpacingItem::SetEnumValue( sal_uInt16 nVal ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; switch ( static_cast<SvxSpecialLineSpace>(nVal) ) { case SvxSpecialLineSpace::OneLine: nPropLineSpace = 100; break; diff --git a/include/editeng/lspcitem.hxx b/include/editeng/lspcitem.hxx index e4c97cfcd460..1bc4e769cff1 100644 --- a/include/editeng/lspcitem.hxx +++ b/include/editeng/lspcitem.hxx @@ -51,6 +51,8 @@ public: // "pure virtual Methods" from SfxPoolItem virtual bool operator==( const SfxPoolItem& ) const override; + virtual bool supportsHashCode() const override { return true; } + virtual size_t hashCode() const override; virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override; virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; @@ -65,6 +67,7 @@ public: short GetInterLineSpace() const { return nInterLineSpace; } void SetInterLineSpace( const short nSpace ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; nInterLineSpace = nSpace; eInterLineSpaceRule = SvxInterLineSpaceRule::Fix; } @@ -73,6 +76,7 @@ public: sal_uInt16 GetLineHeight() const { return nLineHeight; } void SetLineHeight( const sal_uInt16 nHeight ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; nLineHeight = nHeight; eLineSpaceRule = SvxLineSpaceRule::Min; } @@ -81,14 +85,15 @@ public: sal_uInt16 GetPropLineSpace() const { return nPropLineSpace; } void SetPropLineSpace( const sal_uInt16 nProp ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; nPropLineSpace = nProp; eInterLineSpaceRule = SvxInterLineSpaceRule::Prop; } - void SetLineSpaceRule(SvxLineSpaceRule e) { eLineSpaceRule = e; } + void SetLineSpaceRule(SvxLineSpaceRule e) { ASSERT_CHANGE_REFCOUNTED_ITEM; eLineSpaceRule = e; } SvxLineSpaceRule GetLineSpaceRule() const { return eLineSpaceRule; } - void SetInterLineSpaceRule(SvxInterLineSpaceRule e) { eInterLineSpaceRule = e; } + void SetInterLineSpaceRule(SvxInterLineSpaceRule e) { ASSERT_CHANGE_REFCOUNTED_ITEM; eInterLineSpaceRule = e; } SvxInterLineSpaceRule GetInterLineSpaceRule() const { return eInterLineSpaceRule; } virtual sal_uInt16 GetValueCount() const override; commit 7a648f23ecb67fbdbd29ac7a1d81db19f769ebb3 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Aug 23 14:01:29 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Aug 23 17:45:07 2024 +0200 tdf#158556 make SwFormatDrop hashable Change-Id: I87508693abce928c9dfd22fd888e2aa441631f1d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172314 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/paratr.hxx b/sw/inc/paratr.hxx index 5c8d93b49b76..ca67197e02be 100644 --- a/sw/inc/paratr.hxx +++ b/sw/inc/paratr.hxx @@ -98,6 +98,8 @@ public: /// "pure virtual methods" of SfxPoolItem virtual bool operator==( const SfxPoolItem& ) const override; + virtual bool supportsHashCode() const override { return true; } + virtual size_t hashCode() const override; virtual SwFormatDrop* Clone( SfxItemPool* pPool = nullptr ) const override; virtual bool GetPresentation( SfxItemPresentation ePres, MapUnit eCoreMetric, @@ -108,16 +110,16 @@ public: virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override; sal_uInt8 GetLines() const { return m_nLines; } - sal_uInt8 &GetLines() { return m_nLines; } + void SetLines(sal_uInt8 n) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nLines = n; } sal_uInt8 GetChars() const { return m_nChars; } - sal_uInt8 &GetChars() { return m_nChars; } + void SetChars(sal_uInt8 n) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nChars = n; } bool GetWholeWord() const { return m_bWholeWord; } - bool &GetWholeWord() { return m_bWholeWord; } + void SetWholeWord(bool b) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_bWholeWord = b; } sal_uInt16 GetDistance() const { return m_nDistance; } - sal_uInt16 &GetDistance() { return m_nDistance; } + void SetDistance(sal_uInt16 n) { ASSERT_CHANGE_REFCOUNTED_ITEM; m_nDistance = n; } const SwCharFormat *GetCharFormat() const { return static_cast<const SwCharFormat*>(GetRegisteredIn()); } SwCharFormat *GetCharFormat() { return static_cast<SwCharFormat*>(GetRegisteredIn()); } diff --git a/sw/source/core/para/paratr.cxx b/sw/source/core/para/paratr.cxx index 0cffb932c57e..5f67f56f2ef5 100644 --- a/sw/source/core/para/paratr.cxx +++ b/sw/source/core/para/paratr.cxx @@ -27,6 +27,7 @@ #include <libxml/xmlwriter.h> #include <osl/diagnose.h> #include <tools/UnitConversion.hxx> +#include <o3tl/hash_combine.hxx> using namespace ::com::sun::star; @@ -65,6 +66,7 @@ SwFormatDrop::~SwFormatDrop() void SwFormatDrop::SetCharFormat( SwCharFormat *pNew ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; assert(!pNew || !pNew->IsDefault()); // expose cases that lead to use-after-free // Rewire EndListeningAll(); @@ -88,6 +90,18 @@ bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const m_pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).m_pDefinedIn ); } +size_t SwFormatDrop::hashCode() const +{ + std::size_t seed(0); + o3tl::hash_combine(seed, m_nLines); + o3tl::hash_combine(seed, m_nChars); + o3tl::hash_combine(seed, m_nDistance); + o3tl::hash_combine(seed, m_bWholeWord); + o3tl::hash_combine(seed, GetCharFormat()); + // note that we cannot use m_pDefinedIn, that is updated on items already in a pool + return seed; +} + SwFormatDrop* SwFormatDrop::Clone( SfxItemPool* ) const { return new SwFormatDrop( *this ); @@ -127,6 +141,7 @@ bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) { + ASSERT_CHANGE_REFCOUNTED_ITEM; switch(nMemberId&~CONVERT_TWIPS) { case MID_DROPCAP_LINES : diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index 752e75e273fd..15ada592cc0d 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1006,7 +1006,7 @@ void SwCSS1Parser::StyleParsed( const CSS1Selector *pSelector, { // create a DropCap attribute SwFormatDrop aDrop( pColl->GetDrop() ); - aDrop.GetChars() = 1; + aDrop.SetChars( 1 ); // set the attributes of the DropCap attribute if( Css1ScriptFlags::AllMask == nScript ) @@ -1484,12 +1484,12 @@ void SwCSS1Parser::FillDropCap( SwFormatDrop& rDrop, if( nLines<=1 ) return; - rDrop.GetLines() = nLines; + rDrop.SetLines(nLines); // a right border becomes the spacing to text! if (const SvxRightMarginItem *const pRightMargin = rItemSet.GetItemIfSet(RES_MARGIN_RIGHT, false)) { - rDrop.GetDistance() = static_cast<sal_uInt16>(pRightMargin->GetRight()); + rDrop.SetDistance(static_cast<sal_uInt16>(pRightMargin->GetRight())); rItemSet.ClearItem(RES_MARGIN_RIGHT); } rItemSet.ClearItem(RES_MARGIN_FIRSTLINE); @@ -2238,7 +2238,7 @@ void SwHTMLParser::EndContextAttrs( HTMLAttrContext *pContext ) pAttr->Invalidate(); else if( nChars > MAX_DROPCAP_CHARS ) nChars = MAX_DROPCAP_CHARS; - static_cast<SwFormatDrop&>(pAttr->GetItem()).GetChars() = static_cast<sal_uInt8>(nChars); + static_cast<SwFormatDrop&>(pAttr->GetItem()).SetChars(static_cast<sal_uInt8>(nChars)); } EndAttr( pAttr ); diff --git a/sw/source/filter/html/htmlctxt.cxx b/sw/source/filter/html/htmlctxt.cxx index 0e87b83644f8..2358b3152cb2 100644 --- a/sw/source/filter/html/htmlctxt.cxx +++ b/sw/source/filter/html/htmlctxt.cxx @@ -540,7 +540,7 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, SvxAdjust::Left == rPropInfo.m_eFloat ) { SwFormatDrop aDrop; - aDrop.GetChars() = 1; + aDrop.SetChars(1); m_pCSS1Parser->FillDropCap( aDrop, rItemSet ); diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index ef09c6e08006..ab2dbdc242a6 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -4131,11 +4131,11 @@ bool SwWW8ImplReader::ReadText(WW8_CP nStartCp, WW8_CP nTextLen, ManTypes nType) const SwFormatDrop* defaultDrop = GetFormatAttr(RES_PARATR_DROP); SwFormatDrop aDrop(*defaultDrop); - aDrop.GetLines() = nDropLines; - aDrop.GetDistance() = nDistance; - aDrop.GetChars() = writer_cast<sal_uInt8>(nDropCapLen); + aDrop.SetLines(nDropLines); + aDrop.SetDistance(nDistance); + aDrop.SetChars(writer_cast<sal_uInt8>(nDropCapLen)); // Word has no concept of a "whole word dropcap" - aDrop.GetWholeWord() = false; + aDrop.SetWholeWord(false); if (pFormat) aDrop.SetCharFormat(const_cast<SwCharFormat*>(pFormat)); diff --git a/sw/source/ui/chrdlg/drpcps.cxx b/sw/source/ui/chrdlg/drpcps.cxx index f669c5c51640..323c3d833128 100644 --- a/sw/source/ui/chrdlg/drpcps.cxx +++ b/sw/source/ui/chrdlg/drpcps.cxx @@ -718,10 +718,10 @@ void SwDropCapsPage::FillSet( SfxItemSet &rSet ) if (bOn) { // quantity, lines, gap - aFormat.GetChars() = static_cast<sal_uInt8>(m_xDropCapsField->get_value()); - aFormat.GetLines() = static_cast<sal_uInt8>(m_xLinesField->get_value()); - aFormat.GetDistance() = o3tl::narrowing<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))); - aFormat.GetWholeWord() = m_xWholeWordCB->get_active(); + aFormat.SetChars( static_cast<sal_uInt8>(m_xDropCapsField->get_value()) ); + aFormat.SetLines( static_cast<sal_uInt8>(m_xLinesField->get_value()) ); + aFormat.SetDistance( o3tl::narrowing<sal_uInt16>(m_xDistanceField->denormalize(m_xDistanceField->get_value(FieldUnit::TWIP))) ); + aFormat.SetWholeWord( m_xWholeWordCB->get_active() ); // template if (SwView* pView = GetActiveView()) @@ -730,9 +730,9 @@ void SwDropCapsPage::FillSet( SfxItemSet &rSet ) } else { - aFormat.GetChars() = 1; - aFormat.GetLines() = 1; - aFormat.GetDistance() = 0; + aFormat.SetChars(1); + aFormat.SetLines(1); + aFormat.SetDistance(0); } // set attributes