cui/source/dialogs/SpellDialog.cxx            |   16 ++++----
 cui/source/tabpages/page.cxx                  |   15 +++----
 include/svl/grabbagitem.hxx                   |    5 +-
 sd/source/ui/func/fupage.cxx                  |    4 +-
 svl/source/items/grabbagitem.cxx              |   16 ++++++++
 sw/source/core/text/txtfld.cxx                |    2 -
 sw/source/core/txtnode/ndtxt.cxx              |    6 ++-
 sw/source/filter/ww8/wrtw8nds.cxx             |   16 +++-----
 sw/source/filter/ww8/ww8par6.cxx              |   16 ++++----
 sw/source/ui/dbui/mmaddressblockpage.cxx      |    6 +--
 sw/source/uibase/app/docst.cxx                |   14 ++-----
 sw/source/uibase/docvw/UnfloatTableButton.cxx |    8 ++--
 sw/source/uibase/shells/drwbassh.cxx          |    5 +-
 sw/source/uibase/utlui/uitool.cxx             |   49 ++++++++++----------------
 14 files changed, 90 insertions(+), 88 deletions(-)

New commits:
commit 25541338ae51435b9c23fe69cfa4219096e2dd50
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 23 12:00:51 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 23 13:44:26 2024 +0200

    tdf#158556 make SfxGrabBagItem hashable
    
    Change-Id: I0af373e9c5c93a82eb37437ac365677700d45853
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172311
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/cui/source/dialogs/SpellDialog.cxx 
b/cui/source/dialogs/SpellDialog.cxx
index 59ab182ca2b3..dd017cf3de15 100644
--- a/cui/source/dialogs/SpellDialog.cxx
+++ b/cui/source/dialogs/SpellDialog.cxx
@@ -1034,8 +1034,8 @@ bool 
SpellDialog::GetNextSentence_Impl(std::unique_ptr<UndoChangeGroupGuard>* pG
                 {
                     SpellErrorDescription aDesc( false, 
elem.xAlternatives->getWord(),
                                     elem.xAlternatives->getLocale(), 
elem.xAlternatives->getAlternatives(), nullptr);
-                    SfxGrabBagItem aSpellErrorDescription(EE_CHAR_GRABBAG);
-                    
aSpellErrorDescription.GetGrabBag()[u"SpellErrorDescription"_ustr] <<= 
aDesc.toSequence();
+                    SfxGrabBagItem aSpellErrorDescription(EE_CHAR_GRABBAG,
+                        std::map<OUString, css::uno::Any>{{ 
u"SpellErrorDescription"_ustr, uno::Any(aDesc.toSequence()) }});
                     m_xSentenceED->SetAttrib(aSpellErrorDescription, 
nStartPosition, nEndPosition);
                 }
                 else if(elem.bIsGrammarError )
@@ -1063,8 +1063,8 @@ bool 
SpellDialog::GetNextSentence_Impl(std::unique_ptr<UndoChangeGroupGuard>* pG
                         &elem.aGrammarError.aRuleIdentifier,
                         &sFullCommentURL );
 
-                    SfxGrabBagItem aSpellErrorDescriptionItem(EE_CHAR_GRABBAG);
-                    
aSpellErrorDescriptionItem.GetGrabBag()[u"SpellErrorDescription"_ustr] <<= 
aDesc.toSequence();
+                    SfxGrabBagItem aSpellErrorDescriptionItem(EE_CHAR_GRABBAG,
+                        std::map<OUString, 
css::uno::Any>{{u"SpellErrorDescription"_ustr, uno::Any(aDesc.toSequence())}});
                     m_xSentenceED->SetAttrib(aSpellErrorDescriptionItem, 
nStartPosition, nEndPosition);
                 }
 
@@ -1855,8 +1855,8 @@ int SentenceEditWindow_Impl::ChangeMarkedWord(const 
OUString& rNewWord, Language
     AddUndoAction(std::move(pAction));
     if (bSpellErrorDescription)
     {
-        SfxGrabBagItem aSpellErrorDescriptionItem(EE_CHAR_GRABBAG);
-        aSpellErrorDescriptionItem.GetGrabBag()[u"SpellErrorDescription"_ustr] 
<<= aSpellErrorDescription.toSequence();
+        SfxGrabBagItem aSpellErrorDescriptionItem(EE_CHAR_GRABBAG,
+            std::map<OUString, css::uno::Any>{{u"SpellErrorDescription"_ustr, 
uno::Any(aSpellErrorDescription.toSequence())}});
         SetAttrib(aSpellErrorDescriptionItem, m_nErrorStart, m_nErrorEnd);
     }
     SetAttrib(SvxLanguageItem(eLanguage, EE_CHAR_LANGUAGE), m_nErrorStart, 
m_nErrorEnd);
@@ -1913,8 +1913,8 @@ void SentenceEditWindow_Impl::SetAlternatives( const 
Reference< XSpellAlternativ
         aAlts   = xAlt->getAlternatives();
     }
     SpellErrorDescription aDesc( false, aWord, std::move(aLocale), aAlts, 
nullptr);
-    SfxGrabBagItem aSpellErrorDescription(EE_CHAR_GRABBAG);
-    aSpellErrorDescription.GetGrabBag()[u"SpellErrorDescription"_ustr] <<= 
aDesc.toSequence();
+    SfxGrabBagItem aSpellErrorDescription(EE_CHAR_GRABBAG,
+        std::map<OUString, css::uno::Any>{{u"SpellErrorDescription"_ustr, 
uno::Any(aDesc.toSequence())}});
     SetAttrib(aSpellErrorDescription, m_nErrorStart, m_nErrorEnd);
 }
 
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index ee0a4be0a945..809bd672817b 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -663,32 +663,31 @@ bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet )
     if (rOldSet.HasItem(SID_ATTR_CHAR_GRABBAG))
     {
         // Set gutter position.
-        SfxGrabBagItem aGrabBagItem(rOldSet.Get(SID_ATTR_CHAR_GRABBAG));
+        const SfxGrabBagItem& rOldGrabBagItem = 
rOldSet.Get(SID_ATTR_CHAR_GRABBAG);
+        std::map<OUString, css::uno::Any> aGrabBagMap = 
rOldGrabBagItem.GetGrabBag();
         if (m_xGutterPositionLB->get_value_changed_from_saved())
         {
             bool bGutterAtTop = m_xGutterPositionLB->get_active() == 1;
-            aGrabBagItem.GetGrabBag()[u"GutterAtTop"_ustr] <<= bGutterAtTop;
+            aGrabBagMap[u"GutterAtTop"_ustr] <<= bGutterAtTop;
             bModified = true;
         }
         if (m_xRtlGutterCB->get_state_changed_from_saved())
         {
             bool const bRtlGutter(m_xRtlGutterCB->get_active());
-            aGrabBagItem.GetGrabBag()[u"RtlGutter"_ustr] <<= bRtlGutter;
+            aGrabBagMap[u"RtlGutter"_ustr] <<= bRtlGutter;
             bModified = true;
         }
         if (m_xBackgroundFullSizeCB->get_state_changed_from_saved())
         {
             bool const 
isBackgroundFullSize(m_xBackgroundFullSizeCB->get_active());
-            aGrabBagItem.GetGrabBag()[u"BackgroundFullSize"_ustr] <<= 
isBackgroundFullSize;
+            aGrabBagMap[u"BackgroundFullSize"_ustr] <<= isBackgroundFullSize;
             bModified = true;
         }
 
         if (bModified)
         {
-            pOld = rOldSet.GetItem(SID_ATTR_CHAR_GRABBAG);
-
-            if (!pOld || static_cast<const SfxGrabBagItem&>(*pOld) != 
aGrabBagItem)
-                rSet->Put(aGrabBagItem);
+            if (rOldGrabBagItem.GetGrabBag() != aGrabBagMap)
+                rSet->Put(SfxGrabBagItem(SID_ATTR_CHAR_GRABBAG, 
std::move(aGrabBagMap)));
             else
                 bModified = false;
         }
diff --git a/include/svl/grabbagitem.hxx b/include/svl/grabbagitem.hxx
index 77a619aec4c1..a50a5af9dc82 100644
--- a/include/svl/grabbagitem.hxx
+++ b/include/svl/grabbagitem.hxx
@@ -24,6 +24,7 @@ private:
 public:
     SfxGrabBagItem();
     SfxGrabBagItem(sal_uInt16 nWhich);
+    SfxGrabBagItem(sal_uInt16 nWhich, std::map<OUString, css::uno::Any> aMap);
     ~SfxGrabBagItem() override;
 
     SfxGrabBagItem(SfxGrabBagItem const&) = default;
@@ -33,9 +34,9 @@ public:
 
     const std::map<OUString, css::uno::Any>& GetGrabBag() const { return 
m_aMap; }
 
-    std::map<OUString, css::uno::Any>& GetGrabBag() { return m_aMap; }
-
     bool operator==(const SfxPoolItem& rItem) const override;
+    virtual bool supportsHashCode() const override { return true; }
+    virtual size_t hashCode() const override;
     SfxGrabBagItem* Clone(SfxItemPool* pPool = nullptr) const override;
 
     bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override;
diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx
index 3ecbfd2ebe90..a90861d1a7a8 100644
--- a/sd/source/ui/func/fupage.cxx
+++ b/sd/source/ui/func/fupage.cxx
@@ -257,8 +257,8 @@ void FuPage::ExecuteAsyncDialog(weld::Window* pParent, 
const SfxRequest& rReq)
     bool bFullSize = mpPage->IsMasterPage() ?
         mpPage->IsBackgroundFullSize() : 
static_cast<SdPage&>(mpPage->TRG_GetMasterPage()).IsBackgroundFullSize();
 
-    SfxGrabBagItem grabBag(SID_ATTR_CHAR_GRABBAG);
-    grabBag.GetGrabBag()[u"BackgroundFullSize"_ustr] <<= bFullSize;
+    SfxGrabBagItem grabBag(SID_ATTR_CHAR_GRABBAG,
+        std::map<OUString, css::uno::Any>{{u"BackgroundFullSize"_ustr, 
uno::Any(bFullSize)}});
 
     aNewAttr->Put(grabBag);
 
diff --git a/svl/source/items/grabbagitem.cxx b/svl/source/items/grabbagitem.cxx
index 89c0c0336903..f5f5f2bae886 100644
--- a/svl/source/items/grabbagitem.cxx
+++ b/svl/source/items/grabbagitem.cxx
@@ -13,6 +13,7 @@
 #include <sal/log.hxx>
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/uno/Sequence.hxx>
+#include <o3tl/hash_combine.hxx>
 
 using namespace com::sun::star;
 
@@ -26,6 +27,12 @@ SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich)
 {
 }
 
+SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich, std::map<OUString, 
css::uno::Any> aMap)
+    : SfxPoolItem(nWhich, SfxItemType::SfxGrabBagItemType)
+    , m_aMap(std::move(aMap))
+{
+}
+
 SfxGrabBagItem::~SfxGrabBagItem() = default;
 
 bool SfxGrabBagItem::operator==(const SfxPoolItem& rItem) const
@@ -34,6 +41,14 @@ bool SfxGrabBagItem::operator==(const SfxPoolItem& rItem) 
const
            && m_aMap == static_cast<const SfxGrabBagItem*>(&rItem)->m_aMap;
 }
 
+size_t SfxGrabBagItem::hashCode() const
+{
+    std::size_t seed(0);
+    for (const auto& rPair : m_aMap)
+        o3tl::hash_combine(seed, rPair.first.hashCode());
+    return seed;
+}
+
 SfxGrabBagItem* SfxGrabBagItem::Clone(SfxItemPool* /*pPool*/) const
 {
     return new SfxGrabBagItem(*this);
@@ -41,6 +56,7 @@ SfxGrabBagItem* SfxGrabBagItem::Clone(SfxItemPool* /*pPool*/) 
const
 
 bool SfxGrabBagItem::PutValue(const uno::Any& rVal, sal_uInt8 /*nMemberId*/)
 {
+    ASSERT_CHANGE_REFCOUNTED_ITEM;
     uno::Sequence<beans::PropertyValue> aValue;
     if (rVal >>= aValue)
     {
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index 9f3aeec7a878..59869bb4abd9 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -384,7 +384,7 @@ static void 
checkApplyParagraphMarkFormatToNumbering(SwFont* pNumFnt, SwTextForm
             if (pCleanedSet->HasItem(RES_CHRATR_GRABBAG))
             {
                 SfxGrabBagItem aGrabBag = pCleanedSet->Get(RES_CHRATR_GRABBAG, 
/*bSrchInParent=*/false);
-                std::map<OUString, css::uno::Any>& rMap = 
aGrabBag.GetGrabBag();
+                const std::map<OUString, css::uno::Any>& rMap = 
aGrabBag.GetGrabBag();
                 auto aIterator = rMap.find(u"CharShadingMarker"_ustr);
                 if (aIterator != rMap.end())
                     aIterator->second >>= bShadingWasImported;
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 8c91d9c8b520..f5686e486e54 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4212,8 +4212,10 @@ void SwTextNode::GetAttrOutlineContentVisible(bool& 
bOutlineContentVisibleAttr)
 
 void SwTextNode::SetAttrOutlineContentVisible(bool bVisible)
 {
-    SfxGrabBagItem aGrabBagItem(RES_PARATR_GRABBAG);
-    aGrabBagItem.GetGrabBag()[u"OutlineContentVisibleAttr"_ustr] <<= bVisible;
+    SfxGrabBagItem aGrabBagItem(
+        RES_PARATR_GRABBAG,
+        std::map<OUString, css::uno::Any>{
+            { u"OutlineContentVisibleAttr"_ustr, css::uno::Any(bVisible) } });
     SetAttr(aGrabBagItem);
 }
 
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 0f4411ea32c9..110d05e97327 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -501,15 +501,13 @@ void SwWW8AttrIter::OutAttr(sal_Int32 nSwPos, bool 
bWriteCombChars)
     {
         if (const SfxGrabBagItem *pCharFmtGrabBag = 
aExportSet.GetItem<SfxGrabBagItem>(RES_CHRATR_GRABBAG, false))
         {
-            std::unique_ptr<SfxGrabBagItem> 
pNewCharFmtGrabBag(pCharFmtGrabBag->Clone());
-            assert(pNewCharFmtGrabBag);
-            auto & rNewFmtMap = pNewCharFmtGrabBag->GetGrabBag();
+            std::map<OUString, css::uno::Any> aNewGrabBagMap = 
pCharFmtGrabBag->GetGrabBag();
             for (auto const & item : pAutoFmtGrabBag->GetGrabBag())
             {
                 if (item.second.hasValue())
-                    rNewFmtMap.erase(item.first);
+                    aNewGrabBagMap.erase(item.first);
             }
-            aExportSet.Put(std::move(pNewCharFmtGrabBag));
+            
aExportSet.Put(std::make_unique<SfxGrabBagItem>(RES_CHRATR_GRABBAG, 
std::move(aNewGrabBagMap)));
         }
     }
 
@@ -3488,8 +3486,8 @@ void 
MSWordExportBase::UpdateTocSectionNodeProperties(const SwSectionNode& rSect
             {"ooxml:CT_SdtPr_docPartObj", uno::Any(aDocPropertyValues)},
         }));
 
-        SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
-        aGrabBag.GetGrabBag()[u"SdtPr"_ustr] <<= aSdtPrPropertyValues;
+        SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG,
+            std::map<OUString, css::uno::Any>{{ u"SdtPr"_ustr, 
uno::Any(aSdtPrPropertyValues) }});
 
         // create temp attr set
         SwAttrSet aSet(pNode->GetSwAttrSet());
@@ -3508,8 +3506,8 @@ void 
MSWordExportBase::UpdateTocSectionNodeProperties(const SwSectionNode& rSect
         const SwContentNode* pNodeAfterToc = rEndTocNextNode.GetContentNode();
         if (pNodeAfterToc)
         {
-            SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
-            aGrabBag.GetGrabBag()[u"ParaSdtEndBefore"_ustr] <<= true;
+            SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG,
+                std::map<OUString, css::uno::Any>{{u"ParaSdtEndBefore"_ustr, 
uno::Any(true)}});
 
             // create temp attr set
             SwAttrSet aSet(pNodeAfterToc->GetSwAttrSet());
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 595b432c6c49..d1b262858c4b 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -4188,10 +4188,10 @@ void SwWW8ImplReader::Read_CharShadow(  sal_uInt16, 
const sal_uInt8* pData, shor
         NewAttr( SvxBrushItem( aSh.m_aColor, RES_CHRATR_BACKGROUND ));
 
         // Add a marker to the grabbag indicating that character background 
was imported from MSO shading
-        SfxGrabBagItem aGrabBag = *GetFormatAttr(RES_CHRATR_GRABBAG);
-        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
-        rMap.insert(std::pair<OUString, 
css::uno::Any>("CharShadingMarker",uno::Any(true)));
-        NewAttr(aGrabBag);
+        const SfxGrabBagItem* pGrabBag = GetFormatAttr(RES_CHRATR_GRABBAG);
+        std::map<OUString, css::uno::Any> aGrabBagMap = pGrabBag->GetGrabBag();
+        aGrabBagMap["CharShadingMarker"] <<= true;
+        NewAttr(SfxGrabBagItem(RES_CHRATR_GRABBAG, std::move(aGrabBagMap)));
     }
 }
 
@@ -4210,10 +4210,10 @@ void SwWW8ImplReader::Read_TextBackColor(sal_uInt16, 
const sal_uInt8* pData, sho
         NewAttr(SvxBrushItem(aColour, RES_CHRATR_BACKGROUND));
 
         // Add a marker to the grabbag indicating that character background 
was imported from MSO shading
-        SfxGrabBagItem aGrabBag = *GetFormatAttr(RES_CHRATR_GRABBAG);
-        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
-        rMap.insert(std::pair<OUString, 
css::uno::Any>("CharShadingMarker",uno::Any(true)));
-        NewAttr(aGrabBag);
+        const SfxGrabBagItem* pGrabBag = GetFormatAttr(RES_CHRATR_GRABBAG);
+        std::map<OUString, css::uno::Any> aGrabBagMap = pGrabBag->GetGrabBag();
+        aGrabBagMap[u"CharShadingMarker"_ustr] <<= true;
+        NewAttr(SfxGrabBagItem(RES_CHRATR_GRABBAG, std::move(aGrabBagMap)));
     }
 }
 
diff --git a/sw/source/ui/dbui/mmaddressblockpage.cxx 
b/sw/source/ui/dbui/mmaddressblockpage.cxx
index fcae51d43fc7..72a407ae0b87 100644
--- a/sw/source/ui/dbui/mmaddressblockpage.cxx
+++ b/sw/source/ui/dbui/mmaddressblockpage.cxx
@@ -1130,7 +1130,6 @@ void AddressMultiLineEdit::SetText( const OUString& rStr )
     //set attributes to all address tokens
 
     sal_Int32 nSequence(0);
-    SfxGrabBagItem aProtectAttr(EE_CHAR_GRABBAG);
     const sal_uInt32 nParaCount = m_xEditEngine->GetParagraphCount();
     for(sal_uInt32 nPara = 0; nPara < nParaCount; ++nPara)
     {
@@ -1153,8 +1152,9 @@ void AddressMultiLineEdit::SetText( const OUString& rStr )
             SfxItemSet aSet(m_xEditEngine->GetEmptyItemSet());
             // make each one different, so they are not collapsed together
             // as one attribute
-            aProtectAttr.GetGrabBag()[u"Index"_ustr] <<= nSequence++;
-            aSet.Put(aProtectAttr);
+            std::map<OUString, css::uno::Any> aGrabBagMap;
+            aGrabBagMap[u"Index"_ustr] <<= nSequence++;
+            aSet.Put(SfxGrabBagItem(EE_CHAR_GRABBAG, std::move(aGrabBagMap)));
             m_xEditEngine->QuickSetAttribs(aSet, ESelection(nPara, nStart, 
nPara, nEnd + 1));
         }
 
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 60757bafdbf9..21184a6168a2 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -951,19 +951,13 @@ void SwDocShell::Edit(
         rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), 
SID_BITMAP_LIST));
         rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), 
SID_PATTERN_LIST));
 
-        std::optional<SfxGrabBagItem> oGrabBag;
+        std::map<OUString, css::uno::Any> aGrabBagMap;
         if (SfxGrabBagItem const* pItem = 
rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
-        {
-            oGrabBag.emplace(*pItem);
-        }
-        else
-        {
-            oGrabBag.emplace(SID_ATTR_CHAR_GRABBAG);
-        }
+            aGrabBagMap = pItem->GetGrabBag();
         bool bGutterAtTop
             = 
GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP);
-        oGrabBag->GetGrabBag()[u"GutterAtTop"_ustr] <<= bGutterAtTop;
-        rSet.Put(*oGrabBag);
+        aGrabBagMap[u"GutterAtTop"_ustr] <<= bGutterAtTop;
+        rSet.Put(SfxGrabBagItem(SID_ATTR_CHAR_GRABBAG, 
std::move(aGrabBagMap)));
     }
 
     SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
diff --git a/sw/source/uibase/docvw/UnfloatTableButton.cxx 
b/sw/source/uibase/docvw/UnfloatTableButton.cxx
index d5331aeec3ee..10a7cff1538e 100644
--- a/sw/source/uibase/docvw/UnfloatTableButton.cxx
+++ b/sw/source/uibase/docvw/UnfloatTableButton.cxx
@@ -136,11 +136,13 @@ IMPL_LINK_NOARG(UnfloatTableButton, ClickHdl, 
weld::Button&, void)
     assert(pTableFormat);
     if (const SfxGrabBagItem* pGrabBagItem = 
pTableFormat->GetAttrSet().GetItem(RES_FRMATR_GRABBAG))
     {
-        SfxGrabBagItem aGrabBagItem(*pGrabBagItem); // Editable copy
-        if (aGrabBagItem.GetGrabBag().erase(u"TablePosition"_ustr))
+        std::map<OUString, css::uno::Any> aGrabBagMap = 
pGrabBagItem->GetGrabBag(); // Editable copy
+        if (aGrabBagMap.erase(u"TablePosition"_ustr))
         {
+            SfxGrabBagItem aNewGrabBagItem(RES_FRMATR_GRABBAG, 
std::move(aGrabBagMap));
             css::uno::Any aVal;
-            aGrabBagItem.QueryValue(aVal);
+            aNewGrabBagItem.QueryValue(aVal);
+            pTableFormat->SetFormatAttr(aNewGrabBagItem);
             const rtl::Reference<SwXTextTable> xTable
                 = SwXTextTable::CreateXTextTable(pTableFormat);
             xTable->setPropertyValue(UNO_NAME_TABLE_INTEROP_GRAB_BAG, aVal);
diff --git a/sw/source/uibase/shells/drwbassh.cxx 
b/sw/source/uibase/shells/drwbassh.cxx
index 1a8f8640b44a..26f5c9d127e6 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -248,8 +248,9 @@ void SwDrawBaseShell::Execute(SfxRequest& rReq)
                         const IDocumentSettingAccess& rIDSA = 
pFrameFormat->getIDocumentSettingAccess();
                         if 
(rIDSA.get(DocumentSettingId::DO_NOT_MIRROR_RTL_DRAW_OBJS))
                         {
-                            SfxGrabBagItem aItem(RES_CHRATR_GRABBAG);
-                            aItem.GetGrabBag()[u"DoNotMirrorRtlDrawObjs"_ustr] 
<<= true;
+                            SfxGrabBagItem aItem(RES_CHRATR_GRABBAG,
+                                    std::map<OUString, css::uno::Any>{
+                                    { u"DoNotMirrorRtlDrawObjs"_ustr, 
uno::Any(true) } } );
                             aSet.Put(aItem);
                         }
 
diff --git a/sw/source/uibase/utlui/uitool.cxx 
b/sw/source/uibase/utlui/uitool.cxx
index c863334f220e..9f8401f368ca 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -127,8 +127,8 @@ void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara)
     // tdf#126684: We use RES_PARATR_GRABBAG, because RES_CHRATR_GRABBAG may 
be overwritten later in
     // SwDocStyleSheet::GetItemSet when applying attributes from char format
     assert(SfxItemState::SET != rSet.GetItemState(RES_PARATR_GRABBAG, false));
-    SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
-    aGrabBag.GetGrabBag()[u"DialogUseCharAttr"_ustr] <<= true;
+    std::map<OUString, css::uno::Any> aGrabBagMap;
+    aGrabBagMap[u"DialogUseCharAttr"_ustr] <<= true;
     // Store initial ranges to allow restoring later
     uno::Sequence<sal_uInt16> aOrigRanges(rSet.GetRanges().size() * 2 + 1);
     int i = 0;
@@ -138,9 +138,9 @@ void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara)
         aOrigRanges.getArray()[i++] = rPair.second;
     }
     aOrigRanges.getArray()[i++] = 0;
-    aGrabBag.GetGrabBag()[u"OrigItemSetRanges"_ustr] <<= aOrigRanges;
+    aGrabBagMap[u"OrigItemSetRanges"_ustr] <<= aOrigRanges;
     rSet.MergeRange(RES_PARATR_GRABBAG, RES_PARATR_GRABBAG);
-    rSet.Put(aGrabBag);
+    rSet.Put(SfxGrabBagItem(RES_PARATR_GRABBAG, std::move(aGrabBagMap)));
 }
 
 void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool 
bIsPara)
@@ -155,14 +155,12 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const 
SfxItemSet& rOrigSet, bool bIs
         // Remove shading marker
         if (const SfxGrabBagItem* pGrabBagItem = 
rOrigSet.GetItemIfSet(RES_CHRATR_GRABBAG, false))
         {
-            SfxGrabBagItem aGrabBag(*pGrabBagItem);
-            std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
-            auto aIterator = rMap.find(u"CharShadingMarker"_ustr);
-            if( aIterator != rMap.end() )
+            if( pGrabBagItem->GetGrabBag().count(u"CharShadingMarker"_ustr) )
             {
-                aIterator->second <<= false;
+                std::map<OUString, css::uno::Any> aGrabBagMap = 
pGrabBagItem->GetGrabBag();
+                aGrabBagMap[u"CharShadingMarker"_ustr] <<= false;
+                rSet.Put( SfxGrabBagItem(RES_CHRATR_GRABBAG, 
std::move(aGrabBagMap)) );
             }
-            rSet.Put( aGrabBag );
         }
     }
 
@@ -173,8 +171,7 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const 
SfxItemSet& rOrigSet, bool bIs
 
     if (const SfxGrabBagItem* pGrabBagItem = 
rOrigSet.GetItemIfSet(RES_PARATR_GRABBAG, false))
     {
-        SfxGrabBagItem aGrabBag(*pGrabBagItem);
-        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
+        const std::map<OUString, css::uno::Any>& rMap = 
pGrabBagItem->GetGrabBag();
         auto aIterator = rMap.find(u"OrigItemSetRanges"_ustr);
         if (aIterator != rMap.end())
         {
@@ -213,14 +210,12 @@ void ApplyCharBackground(Color const& rBackgroundColor, 
model::ComplexColor cons
     // Remove shading marker
     if (const SfxGrabBagItem* pGrabBagItem = 
aCoreSet.GetItemIfSet(RES_CHRATR_GRABBAG, false))
     {
-        SfxGrabBagItem aGrabBag(*pGrabBagItem);
-        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
-        auto aIterator = rMap.find(u"CharShadingMarker"_ustr);
-        if (aIterator != rMap.end())
+        if (pGrabBagItem->GetGrabBag().count(u"CharShadingMarker"_ustr))
         {
-            aIterator->second <<= false;
+            std::map<OUString, css::uno::Any> aGrabBagMap = 
pGrabBagItem->GetGrabBag();
+            aGrabBagMap[u"CharShadingMarker"_ustr] <<= false;
+            rShell.SetAttrItem(SfxGrabBagItem(RES_CHRATR_GRABBAG, 
std::move(aGrabBagMap)));
         }
-        rShell.SetAttrItem(aGrabBag);
     }
 
     rShell.EndUndo(SwUndoId::INSATTR);
@@ -617,31 +612,25 @@ void PageDescToItemSet( const SwPageDesc& rPageDesc, 
SfxItemSet& rSet)
     if(pCol)
         rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName()));
 
-    std::optional<SfxGrabBagItem> oGrabBag;
+    std::map<OUString, css::uno::Any> aGrabBagMap;
     if (SfxGrabBagItem const* pItem = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
-    {
-        oGrabBag.emplace(*pItem);
-    }
-    else
-    {
-        oGrabBag.emplace(SID_ATTR_CHAR_GRABBAG);
-    }
-    oGrabBag->GetGrabBag()[u"BackgroundFullSize"_ustr] <<=
+        aGrabBagMap = pItem->GetGrabBag();
+    aGrabBagMap[u"BackgroundFullSize"_ustr] <<=
         
rMaster.GetAttrSet().GetItem<SfxBoolItem>(RES_BACKGROUND_FULL_SIZE)->GetValue();
 
     if (IsOwnFormat(*rMaster.GetDoc()))
     {
-        oGrabBag->GetGrabBag()[u"RtlGutter"_ustr]
+        aGrabBagMap[u"RtlGutter"_ustr]
             <<= 
rMaster.GetAttrSet().GetItem<SfxBoolItem>(RES_RTL_GUTTER)->GetValue();
     }
 
     const IDocumentSettingAccess& rIDSA = rMaster.getIDocumentSettingAccess();
     if (rIDSA.get(DocumentSettingId::CONTINUOUS_ENDNOTES))
     {
-        oGrabBag->GetGrabBag()[u"ContinuousEndnotes"_ustr] <<= true;
+        aGrabBagMap[u"ContinuousEndnotes"_ustr] <<= true;
     }
 
-    rSet.Put(*oGrabBag);
+    rSet.Put(SfxGrabBagItem(SID_ATTR_CHAR_GRABBAG, std::move(aGrabBagMap)));
 }
 
 // Set DefaultTabs

Reply via email to