7a4f76d
From 1ca19a345a948e37f2457326b6d5f7e92d5812a6 Mon Sep 17 00:00:00 2001
7a4f76d
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
7a4f76d
Date: Wed, 30 Sep 2015 13:30:36 +0100
7a4f76d
Subject: [PATCH] implement save slide background for impress
7a4f76d
7a4f76d
to go along with the existing "set background",
7a4f76d
same sort of thing as the competitor's effort
7a4f76d
7a4f76d
(cherry picked from commit ed25a000ab67324075e68d9a7f3ca657b4e6a573)
7a4f76d
7a4f76d
Change-Id: I2a1106771ead2cd926f3d631850447499340697c
7a4f76d
---
7a4f76d
 sd/inc/app.hrc                     |  2 +-
7a4f76d
 sd/inc/sdcommands.h                |  1 +
7a4f76d
 sd/sdi/_drvwsh.sdi                 |  5 +++
7a4f76d
 sd/sdi/sdraw.sdi                   | 24 +++++++++++
7a4f76d
 sd/source/ui/app/menuids_tmpl.src  | 11 ++++-
7a4f76d
 sd/source/ui/func/fupage.cxx       | 85 +++++++++++++++++++++++---------------
7a4f76d
 sd/source/ui/inc/DrawViewShell.hxx |  4 ++
7a4f76d
 sd/source/ui/view/drviews2.cxx     |  1 +
7a4f76d
 sd/source/ui/view/drviews7.cxx     | 25 ++++++++++-
7a4f76d
 9 files changed, 121 insertions(+), 37 deletions(-)
7a4f76d
7a4f76d
diff --git a/sd/inc/app.hrc b/sd/inc/app.hrc
7a4f76d
index 2130577..8effdac 100644
7a4f76d
--- a/sd/inc/app.hrc
7a4f76d
+++ b/sd/inc/app.hrc
7a4f76d
@@ -423,7 +423,7 @@
7a4f76d
 
7a4f76d
 #define SID_SELECT_BACKGROUND               (SID_SD_START+422)
7a4f76d
 #define SID_OBJECT_CROP                     (SID_SD_START+423)
7a4f76d
-
7a4f76d
+#define SID_SAVE_BACKGROUND                 (SID_SD_START+424)
7a4f76d
 // Slots for the tool pane popup
7a4f76d
 #define SID_TP_APPLY_TO_ALL_SLIDES          (SID_SD_START+425)
7a4f76d
 #define SID_TP_APPLY_TO_SELECTED_SLIDES     (SID_SD_START+426)
7a4f76d
diff --git a/sd/inc/sdcommands.h b/sd/inc/sdcommands.h
7a4f76d
index 276bf6d..d49fed8 100644
7a4f76d
--- a/sd/inc/sdcommands.h
7a4f76d
+++ b/sd/inc/sdcommands.h
7a4f76d
@@ -107,6 +107,7 @@
7a4f76d
 #define CMD_SID_DELETE_MASTER_PAGE                  ".uno:DeleteMasterPage"
7a4f76d
 #define CMD_SID_RENAME_MASTER_PAGE                  ".uno:RenameMasterPage"
7a4f76d
 #define CMD_SID_SELECT_BACKGROUND                   ".uno:SelectBackground"
7a4f76d
+#define CMD_SID_SAVE_BACKGROUND                     ".uno:SaveBackground"
7a4f76d
 #define CMD_SID_DISPLAY_MASTER_BACKGROUND           ".uno:DisplayMasterBackground"
7a4f76d
 #define CMD_SID_DISPLAY_MASTER_OBJECTS              ".uno:DisplayMasterObjects"
7a4f76d
 #define CMD_SID_TABLE_DISTRIBUTE_COLUMNS            ".uno:DistributeColumns"
7a4f76d
diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi
7a4f76d
index 38953ca..f7e07f2 100644
7a4f76d
--- a/sd/sdi/_drvwsh.sdi
7a4f76d
+++ b/sd/sdi/_drvwsh.sdi
7a4f76d
@@ -2662,6 +2662,11 @@ interface DrawView
7a4f76d
         ExecMethod = FuTemporary ;
7a4f76d
         StateMethod = GetMenuState ;
7a4f76d
     ]
7a4f76d
+    SID_SAVE_BACKGROUND
7a4f76d
+    [
7a4f76d
+        ExecMethod = FuTemporary ;
7a4f76d
+        StateMethod = GetMenuState ;
7a4f76d
+    ]
7a4f76d
     SID_DISPLAY_MASTER_BACKGROUND
7a4f76d
     [
7a4f76d
         ExecMethod = FuTemporary ;
7a4f76d
diff --git a/sd/sdi/sdraw.sdi b/sd/sdi/sdraw.sdi
7a4f76d
index a397d02..ad6174e 100644
7a4f76d
--- a/sd/sdi/sdraw.sdi
7a4f76d
+++ b/sd/sdi/sdraw.sdi
7a4f76d
@@ -6518,6 +6518,30 @@ SfxVoidItem SelectBackground SID_SELECT_BACKGROUND
7a4f76d
     GroupId = GID_OPTIONS;
7a4f76d
 ]
7a4f76d
 
7a4f76d
+SfxVoidItem SaveBackground SID_SAVE_BACKGROUND
7a4f76d
+()
7a4f76d
+[
7a4f76d
+    /* flags: */
7a4f76d
+    AutoUpdate = FALSE,
7a4f76d
+    Cachable = Cachable,
7a4f76d
+    FastCall = FALSE,
7a4f76d
+    HasCoreId = FALSE,
7a4f76d
+    HasDialog = TRUE,
7a4f76d
+    ReadOnlyDoc = TRUE,
7a4f76d
+    Toggle = FALSE,
7a4f76d
+    Container = FALSE,
7a4f76d
+    RecordAbsolute = FALSE,
7a4f76d
+    RecordPerSet;
7a4f76d
+    Synchron;
7a4f76d
+
7a4f76d
+    /* config: */
7a4f76d
+    AccelConfig = FALSE,
7a4f76d
+    MenuConfig = FALSE,
7a4f76d
+    StatusBarConfig = FALSE,
7a4f76d
+    ToolBoxConfig = FALSE,
7a4f76d
+    GroupId = GID_OPTIONS;
7a4f76d
+]
7a4f76d
+
7a4f76d
 SfxBoolItem DisplayMasterBackground SID_DISPLAY_MASTER_BACKGROUND
7a4f76d
 [
7a4f76d
     /* flags: */
7a4f76d
diff --git a/sd/source/ui/app/menuids_tmpl.src b/sd/source/ui/app/menuids_tmpl.src
7a4f76d
index 7944b1c..a61a1d0 100644
7a4f76d
--- a/sd/source/ui/app/menuids_tmpl.src
7a4f76d
+++ b/sd/source/ui/app/menuids_tmpl.src
7a4f76d
@@ -114,6 +114,13 @@
7a4f76d
         HelpId = CMD_SID_SELECT_BACKGROUND ; \
7a4f76d
         Text [ en-US ] = "Set Background Image for Slide ..." ; \
7a4f76d
     };
7a4f76d
+#define MN_SAVE_BACKGROUND \
7a4f76d
+    MenuItem\
7a4f76d
+    {\
7a4f76d
+        Identifier = SID_SAVE_BACKGROUND ; \
7a4f76d
+        HelpId = CMD_SID_SAVE_BACKGROUND ; \
7a4f76d
+        Text [ en-US ] = "Save Background Image..." ; \
7a4f76d
+    };
7a4f76d
 #define MN_DISPLAY_MASTER_BACKGROUND \
7a4f76d
     MenuItem\
7a4f76d
     {\
7a4f76d
@@ -144,6 +151,7 @@
7a4f76d
                 MN_FORMAT_PAGE\
7a4f76d
                 MN_PRESENTATION_LAYOUT\
7a4f76d
                 MN_RENAME_PAGE\
7a4f76d
+                MN_SAVE_BACKGROUND\
7a4f76d
             };\
7a4f76d
         };\
7a4f76d
         Text [ en-US ] = "Pag~e" ; \
7a4f76d
@@ -172,7 +180,8 @@
7a4f76d
                 MN_DISPLAY_MASTER_OBJECTS\
7a4f76d
             };\
7a4f76d
         };\
7a4f76d
-    };
7a4f76d
+    }; \
7a4f76d
+    MN_SAVE_BACKGROUND
7a4f76d
 
7a4f76d
  // Layer
7a4f76d
 #define MN_RENAME_LAYER \
7a4f76d
diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx
7a4f76d
index 8253ee5..2277c19 100644
7a4f76d
--- a/sd/source/ui/func/fupage.cxx
7a4f76d
+++ b/sd/source/ui/func/fupage.cxx
7a4f76d
@@ -36,6 +36,7 @@
7a4f76d
 #include <svx/svdundo.hxx>
7a4f76d
 #include <editeng/eeitem.hxx>
7a4f76d
 #include <editeng/frmdiritem.hxx>
7a4f76d
+#include <svx/graphichelper.hxx>
7a4f76d
 #include <svx/xbtmpit.hxx>
7a4f76d
 #include <svx/xsetit.hxx>
7a4f76d
 #include <editeng/ulspitem.hxx>
7a4f76d
@@ -164,6 +165,41 @@ void FuPage::Deactivate()
7a4f76d
 {
7a4f76d
 }
7a4f76d
 
7a4f76d
+void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr)
7a4f76d
+{
7a4f76d
+    if (bMasterPage)
7a4f76d
+    {
7a4f76d
+        if (pStyleSheet)
7a4f76d
+            mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
7a4f76d
+    }
7a4f76d
+    else
7a4f76d
+    {
7a4f76d
+        // Only this page, get attributes for background fill
7a4f76d
+        const SfxItemSet& rBackgroundAttributes = pPage->getSdrPageProperties().GetItemSet();
7a4f76d
+
7a4f76d
+        if(drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(rBackgroundAttributes.Get(XATTR_FILLSTYLE)).GetValue())
7a4f76d
+        {
7a4f76d
+            // page attributes are used, take them
7a4f76d
+            rMergedAttr.Put(rBackgroundAttributes);
7a4f76d
+        }
7a4f76d
+        else
7a4f76d
+        {
7a4f76d
+            if(pStyleSheet
7a4f76d
+                && drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
7a4f76d
+            {
7a4f76d
+                // if the page has no fill style, use the settings from the
7a4f76d
+                // background stylesheet (if used)
7a4f76d
+                mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
7a4f76d
+            }
7a4f76d
+            else
7a4f76d
+            {
7a4f76d
+                // no fill style from page, start with no fill style
7a4f76d
+                rMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
7a4f76d
+            }
7a4f76d
+        }
7a4f76d
+    }
7a4f76d
+}
7a4f76d
+
7a4f76d
 const SfxItemSet* FuPage::ExecuteDialog( ::vcl::Window* pParent )
7a4f76d
 {
7a4f76d
     if (!mpDrawViewShell)
7a4f76d
@@ -247,44 +283,27 @@ const SfxItemSet* FuPage::ExecuteDialog( ::vcl::Window* pParent )
7a4f76d
     // merge page background filling to the dialogs input set
7a4f76d
     if( mbDisplayBackgroundTabPage )
7a4f76d
     {
7a4f76d
-        if( mbMasterPage )
7a4f76d
-        {
7a4f76d
-            if(pStyleSheet)
7a4f76d
-                mergeItemSetsImpl( aMergedAttr, pStyleSheet->GetItemSet() );
7a4f76d
-        }
7a4f76d
-        else
7a4f76d
-        {
7a4f76d
-            // Only this page, get attributes for background fill
7a4f76d
-            const SfxItemSet& rBackgroundAttributes = mpPage->getSdrPageProperties().GetItemSet();
7a4f76d
-
7a4f76d
-            if(drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(rBackgroundAttributes.Get(XATTR_FILLSTYLE)).GetValue())
7a4f76d
-            {
7a4f76d
-                // page attributes are used, take them
7a4f76d
-                aMergedAttr.Put(rBackgroundAttributes);
7a4f76d
-            }
7a4f76d
-            else
7a4f76d
-            {
7a4f76d
-                if(pStyleSheet
7a4f76d
-                    && drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
7a4f76d
-                {
7a4f76d
-                    // if the page has no fill style, use the settings from the
7a4f76d
-                    // background stylesheet (if used)
7a4f76d
-                    mergeItemSetsImpl(aMergedAttr, pStyleSheet->GetItemSet());
7a4f76d
-                }
7a4f76d
-                else
7a4f76d
-                {
7a4f76d
-                    // no fill style from page, start with no fill style
7a4f76d
-                    aMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
7a4f76d
-                }
7a4f76d
-            }
7a4f76d
-        }
7a4f76d
+        MergePageBackgroundFilling(mpPage, pStyleSheet, mbMasterPage, aMergedAttr);
7a4f76d
     }
7a4f76d
 
7a4f76d
     boost::scoped_ptr< SfxItemSet > pTempSet;
7a4f76d
 
7a4f76d
-    if( GetSlotID() == SID_SELECT_BACKGROUND )
7a4f76d
+    const sal_uInt16 nId = GetSlotID();
7a4f76d
+    if (nId == SID_SAVE_BACKGROUND)
7a4f76d
+    {
7a4f76d
+        const XFillStyleItem& rStyleItem =
7a4f76d
+            static_cast<const XFillStyleItem&>(aMergedAttr.Get(XATTR_FILLSTYLE));
7a4f76d
+        if (drawing::FillStyle_BITMAP == (drawing::FillStyle)rStyleItem.GetValue())
7a4f76d
+        {
7a4f76d
+            const XFillBitmapItem& rBitmap =
7a4f76d
+                static_cast<const XFillBitmapItem&>(aMergedAttr.Get(XATTR_FILLBITMAP));
7a4f76d
+            const GraphicObject& rGraphicObj = rBitmap.GetGraphicObject();
7a4f76d
+            GraphicHelper::ExportGraphic(rGraphicObj.GetGraphic(), "");
7a4f76d
+        }
7a4f76d
+    }
7a4f76d
+    else if (nId == SID_SELECT_BACKGROUND)
7a4f76d
     {
7a4f76d
-        SvxOpenGraphicDialog    aDlg(SdResId(STR_SET_BACKGROUND_PICTURE));
7a4f76d
+        SvxOpenGraphicDialog aDlg(SdResId(STR_SET_BACKGROUND_PICTURE));
7a4f76d
 
7a4f76d
         if( aDlg.Execute() == GRFILTER_OK )
7a4f76d
         {
7a4f76d
diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx
7a4f76d
index 8a92f42..6a56a4f 100644
7a4f76d
--- a/sd/source/ui/inc/DrawViewShell.hxx
7a4f76d
+++ b/sd/source/ui/inc/DrawViewShell.hxx
7a4f76d
@@ -33,6 +33,7 @@
7a4f76d
 
7a4f76d
 class Outliner;
7a4f76d
 class SdPage;
7a4f76d
+class SdStyleSheet;
7a4f76d
 class SdrExternalToolEdit;
7a4f76d
 class DrawDocShell;
7a4f76d
 class TabBar;
7a4f76d
@@ -512,6 +513,9 @@ private:
7a4f76d
     std::vector<std::unique_ptr<SdrExternalToolEdit>> m_ExternalEdits;
7a4f76d
 };
7a4f76d
 
7a4f76d
+    /// Merge the background properties together and deposit the result in rMergeAttr
7a4f76d
+    void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr);
7a4f76d
+
7a4f76d
 } // end of namespace sd
7a4f76d
 
7a4f76d
 #endif
7a4f76d
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
7a4f76d
index 59a42d8..4b8cea1 100644
7a4f76d
--- a/sd/source/ui/view/drviews2.cxx
7a4f76d
+++ b/sd/source/ui/view/drviews2.cxx
7a4f76d
@@ -1191,6 +1191,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
7a4f76d
         break;
7a4f76d
 
7a4f76d
         case SID_SELECT_BACKGROUND:
7a4f76d
+        case SID_SAVE_BACKGROUND:
7a4f76d
         case SID_PAGESETUP:  // BASIC ??
7a4f76d
         {
7a4f76d
             SetCurrentFunction( FuPage::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
7a4f76d
diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
7a4f76d
index 37e8a31..48e6607 100644
7a4f76d
--- a/sd/source/ui/view/drviews7.cxx
7a4f76d
+++ b/sd/source/ui/view/drviews7.cxx
7a4f76d
@@ -83,6 +83,7 @@
7a4f76d
 #include "fuediglu.hxx"
7a4f76d
 #include "fubullet.hxx"
7a4f76d
 #include "fuformatpaintbrush.hxx"
7a4f76d
+#include "stlsheet.hxx"
7a4f76d
 
7a4f76d
 #include <config_features.h>
7a4f76d
 
7a4f76d
@@ -713,6 +714,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
7a4f76d
     {
7a4f76d
         rSet.DisableItem(SID_PRESENTATION_LAYOUT);
7a4f76d
         rSet.DisableItem(SID_SELECT_BACKGROUND);
7a4f76d
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
7a4f76d
     }
7a4f76d
 
7a4f76d
     if (mePageKind == PK_NOTES)
7a4f76d
@@ -729,6 +731,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
7a4f76d
             rSet.DisableItem(SID_MODIFYPAGE);
7a4f76d
 
7a4f76d
         rSet.DisableItem(SID_SELECT_BACKGROUND);
7a4f76d
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
7a4f76d
         rSet.DisableItem(SID_INSERTLAYER);
7a4f76d
         rSet.DisableItem(SID_LAYERMODE);
7a4f76d
         rSet.DisableItem(SID_INSERTFILE);
7a4f76d
@@ -749,6 +752,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
7a4f76d
         rSet.DisableItem(SID_INSERTFILE);
7a4f76d
         rSet.DisableItem(SID_PAGEMODE);
7a4f76d
         rSet.DisableItem(SID_SELECT_BACKGROUND);
7a4f76d
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
7a4f76d
     }
7a4f76d
     else
7a4f76d
     {
7a4f76d
@@ -1645,8 +1649,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
7a4f76d
         || rSet.GetItemState(SID_DISPLAY_MASTER_OBJECTS) == SfxItemState::DEFAULT)
7a4f76d
     {
7a4f76d
         SdPage* pPage = GetActualPage();
7a4f76d
-        if (pPage != NULL
7a4f76d
-            && GetDoc() != NULL)
7a4f76d
+        if (pPage != NULL && GetDoc() != NULL)
7a4f76d
         {
7a4f76d
             SetOfByte aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
7a4f76d
             SdrLayerAdmin& rLayerAdmin = GetDoc()->GetLayerAdmin();
7a4f76d
@@ -1667,6 +1670,24 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
7a4f76d
     }
7a4f76d
 #endif
7a4f76d
 
7a4f76d
+    if (rSet.GetItemState(SID_SAVE_BACKGROUND) == SfxItemState::DEFAULT)
7a4f76d
+    {
7a4f76d
+        bool bDisableSaveBackground = true;
7a4f76d
+        SdPage* pPage = GetActualPage();
7a4f76d
+        if (pPage != NULL && GetDoc() != NULL)
7a4f76d
+        {
7a4f76d
+            SfxItemSet aMergedAttr(GetDoc()->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST, 0);
7a4f76d
+            SdStyleSheet* pStyleSheet = pPage->getPresentationStyle(HID_PSEUDOSHEET_BACKGROUND);
7a4f76d
+            MergePageBackgroundFilling(pPage, pStyleSheet, meEditMode == EM_MASTERPAGE, aMergedAttr);
7a4f76d
+            if (drawing::FillStyle_BITMAP == static_cast<const XFillStyleItem&>(aMergedAttr.Get(XATTR_FILLSTYLE)).GetValue())
7a4f76d
+            {
7a4f76d
+                bDisableSaveBackground = false;
7a4f76d
+            }
7a4f76d
+        }
7a4f76d
+        if (bDisableSaveBackground)
7a4f76d
+            rSet.DisableItem(SID_SAVE_BACKGROUND);
7a4f76d
+    }
7a4f76d
+
7a4f76d
     GetModeSwitchingMenuState (rSet);
7a4f76d
 }
7a4f76d
 
7a4f76d
-- 
7a4f76d
2.4.3
7a4f76d