Blame SOURCES/0001-rhbz-1326602-avoid-exp.-bg-bitmaps-from-deleted-slid.patch

f325b2
From 9a36cf42d6ea424a2ca5c92f8bf1546ab618dc5d Mon Sep 17 00:00:00 2001
f325b2
From: David Tardon <dtardon@redhat.com>
f325b2
Date: Tue, 26 Apr 2016 09:17:11 +0200
f325b2
Subject: [PATCH] rhbz#1326602 avoid exp. bg bitmaps from deleted slides
f325b2
f325b2
ODF export uses SvxUnoBitmapTable (impl. of
f325b2
com.sun.star.drawing.BitmapTable) to create fill bitmap styles. That
f325b2
returns all XATTR_FILLBITMAP items that are in the document's pool. So
f325b2
we ensure that bitmaps that are only used on deleted (either explicitly
f325b2
or by undoing their insertion) slides are not in the pool.
f325b2
f325b2
(cherry picked from commit b876bbe2cacce8af379b10d82da6c7e7d229b361)
f325b2
f325b2
Change-Id: I54c594a94989158f22b156fe660c1e716b988b3e
f325b2
---
f325b2
 include/svx/svdundo.hxx        | 13 ++++++++
f325b2
 sd/source/ui/func/undoback.cxx | 44 ++++++++++++++++++++++++--
f325b2
 sd/source/ui/inc/undoback.hxx  |  6 ++++
f325b2
 svx/source/svdraw/svdundo.cxx  | 70 ++++++++++++++++++++++++++++++++++++++++++
f325b2
 4 files changed, 131 insertions(+), 2 deletions(-)
f325b2
f325b2
diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx
f325b2
index a6c9f24..6472946 100644
f325b2
--- a/include/svx/svdundo.hxx
f325b2
+++ b/include/svx/svdundo.hxx
f325b2
@@ -20,6 +20,11 @@
f325b2
 #ifndef INCLUDED_SVX_SVDUNDO_HXX
f325b2
 #define INCLUDED_SVX_SVDUNDO_HXX
f325b2
 
f325b2
+#include <sal/config.h>
f325b2
+
f325b2
+#include <memory>
f325b2
+#include <vector>
f325b2
+
f325b2
 #include <svl/solar.hrc>
f325b2
 #include <svl/undo.hxx>
f325b2
 #include <svl/style.hxx>
f325b2
@@ -29,6 +34,7 @@
f325b2
 #include <svx/svxdllapi.h>
f325b2
 
f325b2
 class SfxItemSet;
f325b2
+class SfxPoolItem;
f325b2
 class SfxStyleSheet;
f325b2
 class SdrView;
f325b2
 class SdrPageView;
f325b2
@@ -589,6 +595,8 @@ class SVX_DLLPUBLIC SdrUndoDelPage : public SdrUndoPageList
f325b2
     // When deleting a MasterPage, we remember all relations of the
f325b2
     // Character Page with the MasterPage in this UndoGroup.
f325b2
     SdrUndoGroup*               pUndoGroup;
f325b2
+    std::unique_ptr<SfxPoolItem> mpFillBitmapItem;
f325b2
+    bool mbHasFillBitmap;
f325b2
 
f325b2
 public:
f325b2
     SdrUndoDelPage(SdrPage& rNewPg);
f325b2
@@ -602,6 +610,11 @@ public:
f325b2
 
f325b2
     virtual void SdrRepeat(SdrView& rView) SAL_OVERRIDE;
f325b2
     virtual bool CanSdrRepeat(SdrView& rView) const SAL_OVERRIDE;
f325b2
+
f325b2
+private:
f325b2
+    void queryFillBitmap(const SfxItemSet &rItemSet);
f325b2
+    void clearFillBitmap();
f325b2
+    void restoreFillBitmap();
f325b2
 };
f325b2
 
f325b2
 /**
f325b2
diff --git a/sd/source/ui/func/undoback.cxx b/sd/source/ui/func/undoback.cxx
f325b2
index bfb421b..3e3575a 100644
f325b2
--- a/sd/source/ui/func/undoback.cxx
f325b2
+++ b/sd/source/ui/func/undoback.cxx
f325b2
@@ -21,8 +21,13 @@
f325b2
 #include "sdpage.hxx"
f325b2
 #include "sdresid.hxx"
f325b2
 #include "strings.hrc"
f325b2
+
f325b2
+#include <com/sun/star/drawing/FillStyle.hpp>
f325b2
+
f325b2
 #include <svl/itemset.hxx>
f325b2
 
f325b2
+#include <svx/xfillit0.hxx>
f325b2
+
f325b2
 TYPEINIT1( SdBackgroundObjUndoAction, SdUndoAction );
f325b2
 
f325b2
 SdBackgroundObjUndoAction::SdBackgroundObjUndoAction(
f325b2
@@ -31,10 +38,12 @@ SdBackgroundObjUndoAction::SdBackgroundObjUndoAction(
f325b2
     const SfxItemSet& rItenSet)
f325b2
 :   SdUndoAction(&rDoc),
f325b2
     mrPage(rPage),
f325b2
-    mpItemSet(new SfxItemSet(rItenSet))
f325b2
+    mpItemSet(new SfxItemSet(rItenSet)),
f325b2
+    mbHasFillBitmap(false)
f325b2
 {
f325b2
     OUString aString( SdResId( STR_UNDO_CHANGE_PAGEFORMAT ) );
f325b2
     SetComment( aString );
f325b2
+    saveFillBitmap(*mpItemSet);
f325b2
 }
f325b2
 
f325b2
 SdBackgroundObjUndoAction::~SdBackgroundObjUndoAction()
f325b2
@@ -46,9 +55,14 @@ void SdBackgroundObjUndoAction::ImplRestoreBackgroundObj()
f325b2
 {
f325b2
     SfxItemSet* pNew = new SfxItemSet(mrPage.getSdrPageProperties().GetItemSet());
f325b2
     mrPage.getSdrPageProperties().ClearItem();
f325b2
+    if (bool(mpFillBitmapItem))
f325b2
+        restoreFillBitmap(*mpItemSet);
f325b2
+    mpFillBitmapItem.reset();
f325b2
+    mbHasFillBitmap = false;
f325b2
     mrPage.getSdrPageProperties().PutItemSet(*mpItemSet);
f325b2
     delete mpItemSet;
f325b2
     mpItemSet = pNew;
f325b2
+    saveFillBitmap(*mpItemSet);
f325b2
 
f325b2
     // tell the page that it's visualization has changed
f325b2
     mrPage.ActionChanged();
f325b2
@@ -66,7 +80,33 @@ void SdBackgroundObjUndoAction::Redo()
f325b2
 
f325b2
 SdUndoAction* SdBackgroundObjUndoAction::Clone() const
f325b2
 {
f325b2
-    return new SdBackgroundObjUndoAction(*mpDoc, mrPage, *mpItemSet);
f325b2
+    std::unique_ptr<SdBackgroundObjUndoAction> pCopy(new SdBackgroundObjUndoAction(*mpDoc, mrPage, *mpItemSet));
f325b2
+    if (mpFillBitmapItem)
f325b2
+        pCopy->mpFillBitmapItem.reset(mpFillBitmapItem->Clone());
f325b2
+    pCopy->mbHasFillBitmap = mbHasFillBitmap;
f325b2
+    return pCopy.release();
f325b2
+}
f325b2
+
f325b2
+void SdBackgroundObjUndoAction::saveFillBitmap(SfxItemSet &rItemSet)
f325b2
+{
f325b2
+    const SfxPoolItem *pItem = nullptr;
f325b2
+    if (rItemSet.GetItemState(XATTR_FILLBITMAP, false, &pItem) == SfxItemState::SET)
f325b2
+        mpFillBitmapItem.reset(pItem->Clone());
f325b2
+    if (bool(mpFillBitmapItem))
f325b2
+    {
f325b2
+        if (rItemSet.GetItemState(XATTR_FILLSTYLE, false, &pItem) == SfxItemState::SET)
f325b2
+            mbHasFillBitmap = static_cast<const XFillStyleItem*>(pItem)->GetValue() == css::drawing::FillStyle_BITMAP;
f325b2
+        rItemSet.ClearItem(XATTR_FILLBITMAP);
f325b2
+        if (mbHasFillBitmap)
f325b2
+            rItemSet.ClearItem(XATTR_FILLSTYLE);
f325b2
+    }
f325b2
+}
f325b2
+
f325b2
+void SdBackgroundObjUndoAction::restoreFillBitmap(SfxItemSet &rItemSet)
f325b2
+{
f325b2
+    rItemSet.Put(*mpFillBitmapItem);
f325b2
+    if (mbHasFillBitmap)
f325b2
+        rItemSet.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP));
f325b2
 }
f325b2
 
f325b2
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f325b2
diff --git a/sd/source/ui/inc/undoback.hxx b/sd/source/ui/inc/undoback.hxx
f325b2
index 360f7f5..4234424 100644
f325b2
--- a/sd/source/ui/inc/undoback.hxx
f325b2
+++ b/sd/source/ui/inc/undoback.hxx
f325b2
@@ -20,11 +20,13 @@
f325b2
 #ifndef INCLUDED_SD_SOURCE_UI_INC_UNDOBACK_HXX
f325b2
 #define INCLUDED_SD_SOURCE_UI_INC_UNDOBACK_HXX
f325b2
 
f325b2
+#include <memory>
f325b2
 #include "sdundo.hxx"
f325b2
 
f325b2
 class SdDrawDocument;
f325b2
 class SdPage;
f325b2
 class SfxItemSet;
f325b2
+class SfxPoolItem;
f325b2
 
f325b2
 // SdBackgroundObjUndoAction
f325b2
 class SdBackgroundObjUndoAction : public SdUndoAction
f325b2
@@ -33,8 +35,12 @@ private:
f325b2
 
f325b2
     SdPage&                 mrPage;
f325b2
     SfxItemSet*             mpItemSet;
f325b2
+    std::unique_ptr<SfxPoolItem> mpFillBitmapItem;
f325b2
+    bool                    mbHasFillBitmap;
f325b2
 
f325b2
     void                    ImplRestoreBackgroundObj();
f325b2
+    void                    saveFillBitmap(SfxItemSet &rItemSet);
f325b2
+    void                    restoreFillBitmap(SfxItemSet &rItemSet);
f325b2
 
f325b2
 public:
f325b2
 
f325b2
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
f325b2
index 7466532..e4dfa12 100644
f325b2
--- a/svx/source/svdraw/svdundo.cxx
f325b2
+++ b/svx/source/svdraw/svdundo.cxx
f325b2
@@ -17,6 +17,7 @@
f325b2
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
f325b2
  */
f325b2
 
f325b2
+#include <com/sun/star/drawing/FillStyle.hpp>
f325b2
 
f325b2
 #include <svl/lstner.hxx>
f325b2
 
f325b2
@@ -27,6 +28,7 @@
f325b2
 #include <svx/svdlayer.hxx>
f325b2
 #include <svx/svdmodel.hxx>
f325b2
 #include <svx/svdview.hxx>
f325b2
+#include <svx/xfillit0.hxx>
f325b2
 #include "svx/svdstr.hrc"
f325b2
 #include "svdglob.hxx"
f325b2
 #include <svx/scene3d.hxx>
f325b2
@@ -1483,9 +1485,24 @@ SdrUndoPageList::~SdrUndoPageList()
f325b2
 SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg)
f325b2
     : SdrUndoPageList(rNewPg)
f325b2
     , pUndoGroup(NULL)
f325b2
+    , mbHasFillBitmap(false)
f325b2
 {
f325b2
     bItsMine = true;
f325b2
 
f325b2
+    // keep fill bitmap separately to remove it from pool if not used elsewhere
f325b2
+    if (mrPage.IsMasterPage())
f325b2
+    {
f325b2
+        SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
f325b2
+        if (pStyleSheet)
f325b2
+            queryFillBitmap(pStyleSheet->GetItemSet());
f325b2
+    }
f325b2
+    else
f325b2
+    {
f325b2
+        queryFillBitmap(mrPage.getSdrPageProperties().GetItemSet());
f325b2
+    }
f325b2
+    if (bool(mpFillBitmapItem))
f325b2
+        clearFillBitmap();
f325b2
+
f325b2
     // now remember the master page relationships
f325b2
     if(mrPage.IsMasterPage())
f325b2
     {
f325b2
@@ -1520,6 +1537,8 @@ SdrUndoDelPage::~SdrUndoDelPage()
f325b2
 
f325b2
 void SdrUndoDelPage::Undo()
f325b2
 {
f325b2
+    if (bool(mpFillBitmapItem))
f325b2
+        restoreFillBitmap();
f325b2
     ImpInsertPage(nPageNum);
f325b2
     if (pUndoGroup!=NULL)
f325b2
     {
f325b2
@@ -1533,6 +1552,8 @@ void SdrUndoDelPage::Undo()
f325b2
 void SdrUndoDelPage::Redo()
f325b2
 {
f325b2
     ImpRemovePage(nPageNum);
f325b2
+    if (bool(mpFillBitmapItem))
f325b2
+        clearFillBitmap();
f325b2
     // master page relations are dissolved automatically
f325b2
     DBG_ASSERT(!bItsMine,"RedoDeletePage: mrPage already belongs to UndoAction.");
f325b2
     bItsMine=true;
f325b2
@@ -1561,6 +1582,55 @@ bool SdrUndoDelPage::CanSdrRepeat(SdrView& /*rView*/) const
f325b2
     return false;
f325b2
 }
f325b2
 
f325b2
+void SdrUndoDelPage::queryFillBitmap(const SfxItemSet& rItemSet)
f325b2
+{
f325b2
+    const SfxPoolItem *pItem = nullptr;
f325b2
+    if (rItemSet.GetItemState(XATTR_FILLBITMAP, false, &pItem) == SfxItemState::SET)
f325b2
+        mpFillBitmapItem.reset(pItem->Clone());
f325b2
+    if (rItemSet.GetItemState(XATTR_FILLSTYLE, false, &pItem) == SfxItemState::SET)
f325b2
+        mbHasFillBitmap = static_cast<const XFillStyleItem*>(pItem)->GetValue() == css::drawing::FillStyle_BITMAP;
f325b2
+}
f325b2
+
f325b2
+void SdrUndoDelPage::clearFillBitmap()
f325b2
+{
f325b2
+    if (mrPage.IsMasterPage())
f325b2
+    {
f325b2
+        SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
f325b2
+        assert(bool(pStyleSheet)); // who took away my stylesheet?
f325b2
+        SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
f325b2
+        rItemSet.ClearItem(XATTR_FILLBITMAP);
f325b2
+        if (mbHasFillBitmap)
f325b2
+            rItemSet.ClearItem(XATTR_FILLSTYLE);
f325b2
+    }
f325b2
+    else
f325b2
+    {
f325b2
+        SdrPageProperties &rPageProps = mrPage.getSdrPageProperties();
f325b2
+        rPageProps.ClearItem(XATTR_FILLBITMAP);
f325b2
+        if (mbHasFillBitmap)
f325b2
+            rPageProps.ClearItem(XATTR_FILLSTYLE);
f325b2
+    }
f325b2
+}
f325b2
+
f325b2
+void SdrUndoDelPage::restoreFillBitmap()
f325b2
+{
f325b2
+    if (mrPage.IsMasterPage())
f325b2
+    {
f325b2
+        SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
f325b2
+        assert(bool(pStyleSheet)); // who took away my stylesheet?
f325b2
+        SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
f325b2
+        rItemSet.Put(*mpFillBitmapItem);
f325b2
+        if (mbHasFillBitmap)
f325b2
+            rItemSet.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP));
f325b2
+    }
f325b2
+    else
f325b2
+    {
f325b2
+        SdrPageProperties &rPageProps = mrPage.getSdrPageProperties();
f325b2
+        rPageProps.PutItem(*mpFillBitmapItem);
f325b2
+        if (mbHasFillBitmap)
f325b2
+            rPageProps.PutItem(XFillStyleItem(css::drawing::FillStyle_BITMAP));
f325b2
+    }
f325b2
+}
f325b2
+
f325b2
 
f325b2
 
f325b2
 void SdrUndoNewPage::Undo()
f325b2
-- 
f325b2
2.7.4
f325b2