[Libreoffice-commits] core.git: sw/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 17 09:27:35 UTC 2019


 sw/source/uibase/utlui/uitool.cxx |   52 ++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 10 deletions(-)

New commits:
commit 202c9a7d826c95fc05db912a8d19c598a240f1cd
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Aug 17 10:52:14 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Aug 17 11:26:47 2019 +0200

    tdf#126787: extend/restore item set ranges to hold RES_PARATR_GRABBAG
    
    The original item set did not include that in its ranges list, so it
    ignored attempts to set its value.
    
    Change-Id: I5f928206f0614f0cfd54652e77d7dc6b9833fb26
    Reviewed-on: https://gerrit.libreoffice.org/77617
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx
index c3581e6df888..0ed3fe8b24a5 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -148,10 +148,21 @@ void ConvertAttrCharToGen(SfxItemSet& rSet)
     std::unique_ptr<SfxGrabBagItem> pGrabBag;
     const SfxPoolItem *pTmpItem;
     if (SfxItemState::SET == rSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem))
+    {
+        SAL_WARN("sw.ui", "Unexpected: non-empty paragraph grab bag in character item set!");
         pGrabBag.reset(static_cast<SfxGrabBagItem*>(pTmpItem->Clone()));
+    }
     else
         pGrabBag.reset(new SfxGrabBagItem(RES_PARATR_GRABBAG));
     pGrabBag->GetGrabBag()["DialogUseCharAttr"] <<= true;
+    // Store initial ranges to allow restoring later
+    const sal_uInt16* pRanges = rSet.GetRanges();
+    const sal_uInt16* pEnd = pRanges;
+    while (*pEnd)
+        ++pEnd;
+    const uno::Sequence<sal_uInt16> aOrigRanges(pRanges, pEnd - pRanges + 1);
+    pGrabBag->GetGrabBag()["OrigItemSetRanges"] <<= aOrigRanges;
+    rSet.MergeRange(RES_PARATR_GRABBAG, RES_PARATR_GRABBAG);
     rSet.Put(std::move(pGrabBag));
 }
 
@@ -177,19 +188,40 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet)
             }
             rSet.Put( aGrabBag );
         }
-        if (SfxItemState::SET == rOrigSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem))
+    }
+    rSet.ClearItem( RES_BACKGROUND );
+
+    if (SfxItemState::SET == rOrigSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem))
+    {
+        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
+        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
+        auto aIterator = rMap.find("OrigItemSetRanges");
+        if (aIterator != rMap.end())
         {
-            SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
-            std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
-            // Remove temporary GrabBag entry
-            rMap.erase("DialogUseCharAttr");
-            if (rMap.empty())
-                rSet.ClearItem(RES_PARATR_GRABBAG);
-            else
-                rSet.Put(aGrabBag);
+            if (uno::Sequence<sal_uInt16> aOrigRanges; (aIterator->second >>= aOrigRanges)
+                                                       && aOrigRanges.getLength() % 2 == 1
+                                                       && *(std::cend(aOrigRanges) - 1) == 0)
+                rSet.SetRanges(aOrigRanges.getConstArray());
+        }
+    }
+    if (SfxItemState::SET == rSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem))
+    {
+        // In fact, we should not reach here: it shouldn't have been there; and even if it was, it
+        // should have been erased on the previous step when restoring original ranges
+        SAL_WARN("sw.ui", "Unexpected: paragraph grab bag in character item set!");
+        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
+        std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
+        // Remove temporary GrabBag entries
+        rMap.erase("DialogUseCharAttr");
+        rMap.erase("OrigItemSetRanges");
+        if (rMap.empty())
+            rSet.ClearItem(RES_PARATR_GRABBAG);
+        else
+        {
+            SAL_WARN("sw.ui", "Unexpected: non-empty paragraph grab bag in character item set!");
+            rSet.Put(aGrabBag);
         }
     }
-    rSet.ClearItem( RES_BACKGROUND );
 }
 
 void ApplyCharBackground(const Color& rBackgroundColor, SwWrtShell& rShell)


More information about the Libreoffice-commits mailing list