aea8c0e
From 402f64fc8464366015259d44e238a77cb7d9d776 Mon Sep 17 00:00:00 2001
aea8c0e
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
aea8c0e
Date: Wed, 30 Sep 2015 13:30:36 +0100
aea8c0e
Subject: [PATCH] implement save slide background for impress
aea8c0e
aea8c0e
to go along with the existing "set background",
aea8c0e
same sort of thing as the competitor's effort
aea8c0e
aea8c0e
(cherry picked from commit ed25a000ab67324075e68d9a7f3ca657b4e6a573)
aea8c0e
aea8c0e
Change-Id: I2a1106771ead2cd926f3d631850447499340697c
aea8c0e
---
aea8c0e
 sd/inc/app.hrc                     |  3 +-
aea8c0e
 sd/inc/sdcommands.h                |  1 +
aea8c0e
 sd/sdi/_drvwsh.sdi                 |  5 +++
aea8c0e
 sd/sdi/sdraw.sdi                   | 24 +++++++++++
aea8c0e
 sd/source/ui/app/menuids_tmpl.src  | 11 ++++-
aea8c0e
 sd/source/ui/func/fupage.cxx       | 85 +++++++++++++++++++++++---------------
aea8c0e
 sd/source/ui/inc/DrawViewShell.hxx |  4 ++
aea8c0e
 sd/source/ui/view/drviews2.cxx     |  1 +
aea8c0e
 sd/source/ui/view/drviews7.cxx     | 25 ++++++++++-
aea8c0e
 9 files changed, 122 insertions(+), 37 deletions(-)
aea8c0e
aea8c0e
diff --git a/sd/inc/app.hrc b/sd/inc/app.hrc
aea8c0e
index 4f3d82e..956c7d4 100644
aea8c0e
--- a/sd/inc/app.hrc
aea8c0e
+++ b/sd/inc/app.hrc
aea8c0e
@@ -421,7 +421,8 @@
aea8c0e
 #define SID_SLIDE_SORTER_MULTI_PANE_GUI     (SID_SD_START+421)
aea8c0e
 
aea8c0e
 #define SID_SELECT_BACKGROUND               (SID_SD_START+422)
aea8c0e
-
aea8c0e
+#define SID_SAVE_BACKGROUND                 (SID_SD_START+423)
aea8c0e
+        // FREE
aea8c0e
 // Slots for the tool pane popup
aea8c0e
 #define SID_TP_APPLY_TO_ALL_SLIDES          (SID_SD_START+425)
aea8c0e
 #define SID_TP_APPLY_TO_SELECTED_SLIDES     (SID_SD_START+426)
aea8c0e
diff --git a/sd/inc/sdcommands.h b/sd/inc/sdcommands.h
aea8c0e
index 2f4bf56..1d3502f 100644
aea8c0e
--- a/sd/inc/sdcommands.h
aea8c0e
+++ b/sd/inc/sdcommands.h
aea8c0e
@@ -90,6 +90,7 @@
aea8c0e
 #define CMD_SID_DELETE_MASTER_PAGE                  ".uno:DeleteMasterPage"
aea8c0e
 #define CMD_SID_RENAME_MASTER_PAGE                  ".uno:RenameMasterPage"
aea8c0e
 #define CMD_SID_SELECT_BACKGROUND                   ".uno:SelectBackground"
aea8c0e
+#define CMD_SID_SAVE_BACKGROUND                     ".uno:SaveBackground"
aea8c0e
 #define CMD_SID_DISPLAY_MASTER_BACKGROUND           ".uno:DisplayMasterBackground"
aea8c0e
 #define CMD_SID_DISPLAY_MASTER_OBJECTS              ".uno:DisplayMasterObjects"
aea8c0e
 #define CMD_SID_TABLE_DISTRIBUTE_COLUMNS            ".uno:DistributeColumns"
aea8c0e
diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi
aea8c0e
index 263a8ed..28ee22c 100644
aea8c0e
--- a/sd/sdi/_drvwsh.sdi
aea8c0e
+++ b/sd/sdi/_drvwsh.sdi
aea8c0e
@@ -2662,6 +2662,11 @@ interface DrawView
aea8c0e
         ExecMethod = FuTemporary ;
aea8c0e
         StateMethod = GetMenuState ;
aea8c0e
     ]
aea8c0e
+    SID_SAVE_BACKGROUND
aea8c0e
+    [
aea8c0e
+        ExecMethod = FuTemporary ;
aea8c0e
+        StateMethod = GetMenuState ;
aea8c0e
+    ]
aea8c0e
     SID_DISPLAY_MASTER_BACKGROUND
aea8c0e
     [
aea8c0e
         ExecMethod = FuTemporary ;
aea8c0e
diff --git a/sd/sdi/sdraw.sdi b/sd/sdi/sdraw.sdi
aea8c0e
index 7297c1f..d2d5d28 100644
aea8c0e
--- a/sd/sdi/sdraw.sdi
aea8c0e
+++ b/sd/sdi/sdraw.sdi
aea8c0e
@@ -6439,6 +6439,30 @@ SfxVoidItem SelectBackground SID_SELECT_BACKGROUND
aea8c0e
     GroupId = GID_OPTIONS;
aea8c0e
 ]
aea8c0e
 
aea8c0e
+SfxVoidItem SaveBackground SID_SAVE_BACKGROUND
aea8c0e
+()
aea8c0e
+[
aea8c0e
+    /* flags: */
aea8c0e
+    AutoUpdate = FALSE,
aea8c0e
+    Cachable = Cachable,
aea8c0e
+    FastCall = FALSE,
aea8c0e
+    HasCoreId = FALSE,
aea8c0e
+    HasDialog = TRUE,
aea8c0e
+    ReadOnlyDoc = TRUE,
aea8c0e
+    Toggle = FALSE,
aea8c0e
+    Container = FALSE,
aea8c0e
+    RecordAbsolute = FALSE,
aea8c0e
+    RecordPerSet;
aea8c0e
+    Synchron;
aea8c0e
+
aea8c0e
+    /* config: */
aea8c0e
+    AccelConfig = FALSE,
aea8c0e
+    MenuConfig = FALSE,
aea8c0e
+    StatusBarConfig = FALSE,
aea8c0e
+    ToolBoxConfig = FALSE,
aea8c0e
+    GroupId = GID_OPTIONS;
aea8c0e
+]
aea8c0e
+
aea8c0e
 SfxBoolItem DisplayMasterBackground SID_DISPLAY_MASTER_BACKGROUND
aea8c0e
 [
aea8c0e
     /* flags: */
aea8c0e
diff --git a/sd/source/ui/app/menuids_tmpl.src b/sd/source/ui/app/menuids_tmpl.src
aea8c0e
index bf30830..6917de2 100644
aea8c0e
--- a/sd/source/ui/app/menuids_tmpl.src
aea8c0e
+++ b/sd/source/ui/app/menuids_tmpl.src
aea8c0e
@@ -138,6 +138,13 @@
aea8c0e
         HelpId = CMD_SID_SELECT_BACKGROUND ; \
aea8c0e
         Text [ en-US ] = "Set Background Image..." ; \
aea8c0e
     };
aea8c0e
+#define MN_SAVE_BACKGROUND \
aea8c0e
+    MenuItem\
aea8c0e
+    {\
aea8c0e
+        Identifier = SID_SAVE_BACKGROUND ; \
aea8c0e
+        HelpId = CMD_SID_SAVE_BACKGROUND ; \
aea8c0e
+        Text [ en-US ] = "Save Background Image..." ; \
aea8c0e
+    };
aea8c0e
 #define MN_DISPLAY_MASTER_BACKGROUND \
aea8c0e
     MenuItem\
aea8c0e
     {\
aea8c0e
@@ -169,6 +176,7 @@
aea8c0e
                 MN_SELECT_BACKGROUND\
aea8c0e
                 MN_PAGE_DESIGN\
aea8c0e
                 MN_RENAME_PAGE\
aea8c0e
+                MN_SAVE_BACKGROUND\
aea8c0e
             };\
aea8c0e
         };\
aea8c0e
         Text [ en-US ] = "Pag~e" ; \
aea8c0e
@@ -200,7 +208,8 @@
aea8c0e
                 MN_DISPLAY_MASTER_OBJECTS\
aea8c0e
             };\
aea8c0e
         };\
aea8c0e
-    };
aea8c0e
+    }; \
aea8c0e
+    MN_SAVE_BACKGROUND
aea8c0e
 
aea8c0e
  // Layer
aea8c0e
 #define MN_RENAME_LAYER \
aea8c0e
diff --git a/sd/source/ui/func/fupage.cxx b/sd/source/ui/func/fupage.cxx
aea8c0e
index 83146e4..d3a053f 100644
aea8c0e
--- a/sd/source/ui/func/fupage.cxx
aea8c0e
+++ b/sd/source/ui/func/fupage.cxx
aea8c0e
@@ -36,6 +36,7 @@
aea8c0e
 #include <svx/svdundo.hxx>
aea8c0e
 #include <editeng/eeitem.hxx>
aea8c0e
 #include <editeng/frmdiritem.hxx>
aea8c0e
+#include <svx/graphichelper.hxx>
aea8c0e
 #include <svx/xbtmpit.hxx>
aea8c0e
 #include <svx/xsetit.hxx>
aea8c0e
 #include <editeng/ulspitem.hxx>
aea8c0e
@@ -164,6 +165,41 @@ void FuPage::Deactivate()
aea8c0e
 {
aea8c0e
 }
aea8c0e
 
aea8c0e
+void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr)
aea8c0e
+{
aea8c0e
+    if (bMasterPage)
aea8c0e
+    {
aea8c0e
+        if (pStyleSheet)
aea8c0e
+            mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
aea8c0e
+    }
aea8c0e
+    else
aea8c0e
+    {
aea8c0e
+        // Only this page, get attributes for background fill
aea8c0e
+        const SfxItemSet& rBackgroundAttributes = pPage->getSdrPageProperties().GetItemSet();
aea8c0e
+
aea8c0e
+        if(drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(rBackgroundAttributes.Get(XATTR_FILLSTYLE)).GetValue())
aea8c0e
+        {
aea8c0e
+            // page attributes are used, take them
aea8c0e
+            rMergedAttr.Put(rBackgroundAttributes);
aea8c0e
+        }
aea8c0e
+        else
aea8c0e
+        {
aea8c0e
+            if(pStyleSheet
aea8c0e
+                && drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
aea8c0e
+            {
aea8c0e
+                // if the page has no fill style, use the settings from the
aea8c0e
+                // background stylesheet (if used)
aea8c0e
+                mergeItemSetsImpl(rMergedAttr, pStyleSheet->GetItemSet());
aea8c0e
+            }
aea8c0e
+            else
aea8c0e
+            {
aea8c0e
+                // no fill style from page, start with no fill style
aea8c0e
+                rMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
aea8c0e
+            }
aea8c0e
+        }
aea8c0e
+    }
aea8c0e
+}
aea8c0e
+
aea8c0e
 const SfxItemSet* FuPage::ExecuteDialog( vcl::Window* pParent )
aea8c0e
 {
aea8c0e
     if (!mpDrawViewShell)
aea8c0e
@@ -247,44 +283,27 @@ const SfxItemSet* FuPage::ExecuteDialog( vcl::Window* pParent )
aea8c0e
     // merge page background filling to the dialogs input set
aea8c0e
     if( mbDisplayBackgroundTabPage )
aea8c0e
     {
aea8c0e
-        if( mbMasterPage )
aea8c0e
-        {
aea8c0e
-            if(pStyleSheet)
aea8c0e
-                mergeItemSetsImpl( aMergedAttr, pStyleSheet->GetItemSet() );
aea8c0e
-        }
aea8c0e
-        else
aea8c0e
-        {
aea8c0e
-            // Only this page, get attributes for background fill
aea8c0e
-            const SfxItemSet& rBackgroundAttributes = mpPage->getSdrPageProperties().GetItemSet();
aea8c0e
-
aea8c0e
-            if(drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(rBackgroundAttributes.Get(XATTR_FILLSTYLE)).GetValue())
aea8c0e
-            {
aea8c0e
-                // page attributes are used, take them
aea8c0e
-                aMergedAttr.Put(rBackgroundAttributes);
aea8c0e
-            }
aea8c0e
-            else
aea8c0e
-            {
aea8c0e
-                if(pStyleSheet
aea8c0e
-                    && drawing::FillStyle_NONE != static_cast<const XFillStyleItem&>(pStyleSheet->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
aea8c0e
-                {
aea8c0e
-                    // if the page has no fill style, use the settings from the
aea8c0e
-                    // background stylesheet (if used)
aea8c0e
-                    mergeItemSetsImpl(aMergedAttr, pStyleSheet->GetItemSet());
aea8c0e
-                }
aea8c0e
-                else
aea8c0e
-                {
aea8c0e
-                    // no fill style from page, start with no fill style
aea8c0e
-                    aMergedAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
aea8c0e
-                }
aea8c0e
-            }
aea8c0e
-        }
aea8c0e
+        MergePageBackgroundFilling(mpPage, pStyleSheet, mbMasterPage, aMergedAttr);
aea8c0e
     }
aea8c0e
 
aea8c0e
     boost::scoped_ptr< SfxItemSet > pTempSet;
aea8c0e
 
aea8c0e
-    if( GetSlotID() == SID_SELECT_BACKGROUND )
aea8c0e
+    const sal_uInt16 nId = GetSlotID();
aea8c0e
+    if (nId == SID_SAVE_BACKGROUND)
aea8c0e
+    {
aea8c0e
+        const XFillStyleItem& rStyleItem =
aea8c0e
+            static_cast<const XFillStyleItem&>(aMergedAttr.Get(XATTR_FILLSTYLE));
aea8c0e
+        if (drawing::FillStyle_BITMAP == (drawing::FillStyle)rStyleItem.GetValue())
aea8c0e
+        {
aea8c0e
+            const XFillBitmapItem& rBitmap =
aea8c0e
+                static_cast<const XFillBitmapItem&>(aMergedAttr.Get(XATTR_FILLBITMAP));
aea8c0e
+            const GraphicObject& rGraphicObj = rBitmap.GetGraphicObject();
aea8c0e
+            GraphicHelper::ExportGraphic(rGraphicObj.GetGraphic(), "");
aea8c0e
+        }
aea8c0e
+    }
aea8c0e
+    else if (nId == SID_SELECT_BACKGROUND)
aea8c0e
     {
aea8c0e
-        SvxOpenGraphicDialog    aDlg(SdResId(STR_SET_BACKGROUND_PICTURE));
aea8c0e
+        SvxOpenGraphicDialog aDlg(SdResId(STR_SET_BACKGROUND_PICTURE));
aea8c0e
 
aea8c0e
         if( aDlg.Execute() == GRFILTER_OK )
aea8c0e
         {
aea8c0e
diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx
aea8c0e
index 405e7af..5ec628c 100644
aea8c0e
--- a/sd/source/ui/inc/DrawViewShell.hxx
aea8c0e
+++ b/sd/source/ui/inc/DrawViewShell.hxx
aea8c0e
@@ -33,6 +33,7 @@
aea8c0e
 
aea8c0e
 class Outliner;
aea8c0e
 class SdPage;
aea8c0e
+class SdStyleSheet;
aea8c0e
 class SdrExternalToolEdit;
aea8c0e
 class DrawDocShell;
aea8c0e
 class TabBar;
aea8c0e
@@ -509,6 +510,9 @@ private:
aea8c0e
     std::vector<std::unique_ptr<SdrExternalToolEdit>> m_ExternalEdits;
aea8c0e
 };
aea8c0e
 
aea8c0e
+    /// Merge the background properties together and deposit the result in rMergeAttr
aea8c0e
+    void MergePageBackgroundFilling(SdPage *pPage, SdStyleSheet *pStyleSheet, bool bMasterPage, SfxItemSet& rMergedAttr);
aea8c0e
+
aea8c0e
 } // end of namespace sd
aea8c0e
 
aea8c0e
 #endif
aea8c0e
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
aea8c0e
index e9c5f00..5c26c55 100644
aea8c0e
--- a/sd/source/ui/view/drviews2.cxx
aea8c0e
+++ b/sd/source/ui/view/drviews2.cxx
aea8c0e
@@ -1190,6 +1190,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
aea8c0e
         break;
aea8c0e
 
aea8c0e
         case SID_SELECT_BACKGROUND:
aea8c0e
+        case SID_SAVE_BACKGROUND:
aea8c0e
         case SID_PAGESETUP:  // BASIC ??
aea8c0e
         {
aea8c0e
             SetCurrentFunction( FuPage::Create( this, GetActiveWindow(), mpDrawView, GetDoc(), rReq ) );
aea8c0e
diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx
aea8c0e
index 8b6d968..fba8bc1 100644
aea8c0e
--- a/sd/source/ui/view/drviews7.cxx
aea8c0e
+++ b/sd/source/ui/view/drviews7.cxx
aea8c0e
@@ -83,6 +83,7 @@
aea8c0e
 #include "fuediglu.hxx"
aea8c0e
 #include "fubullet.hxx"
aea8c0e
 #include "fuformatpaintbrush.hxx"
aea8c0e
+#include "stlsheet.hxx"
aea8c0e
 
aea8c0e
 #include <config_features.h>
aea8c0e
 
aea8c0e
@@ -714,6 +715,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
aea8c0e
     {
aea8c0e
         rSet.DisableItem(SID_PRESENTATION_LAYOUT);
aea8c0e
         rSet.DisableItem(SID_SELECT_BACKGROUND);
aea8c0e
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
aea8c0e
     }
aea8c0e
 
aea8c0e
     if (mePageKind == PK_NOTES)
aea8c0e
@@ -730,6 +732,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
aea8c0e
             rSet.DisableItem(SID_MODIFYPAGE);
aea8c0e
 
aea8c0e
         rSet.DisableItem(SID_SELECT_BACKGROUND);
aea8c0e
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
aea8c0e
         rSet.DisableItem(SID_INSERTLAYER);
aea8c0e
         rSet.DisableItem(SID_LAYERMODE);
aea8c0e
         rSet.DisableItem(SID_INSERTFILE);
aea8c0e
@@ -750,6 +753,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
aea8c0e
         rSet.DisableItem(SID_INSERTFILE);
aea8c0e
         rSet.DisableItem(SID_PAGEMODE);
aea8c0e
         rSet.DisableItem(SID_SELECT_BACKGROUND);
aea8c0e
+        rSet.DisableItem(SID_SAVE_BACKGROUND);
aea8c0e
     }
aea8c0e
     else
aea8c0e
     {
aea8c0e
@@ -1646,8 +1650,7 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
aea8c0e
         || rSet.GetItemState(SID_DISPLAY_MASTER_OBJECTS) == SfxItemState::DEFAULT)
aea8c0e
     {
aea8c0e
         SdPage* pPage = GetActualPage();
aea8c0e
-        if (pPage != NULL
aea8c0e
-            && GetDoc() != NULL)
aea8c0e
+        if (pPage != NULL && GetDoc() != NULL)
aea8c0e
         {
aea8c0e
             SetOfByte aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
aea8c0e
             SdrLayerAdmin& rLayerAdmin = GetDoc()->GetLayerAdmin();
aea8c0e
@@ -1668,6 +1671,24 @@ void DrawViewShell::GetMenuState( SfxItemSet &rSet )
aea8c0e
     }
aea8c0e
 #endif
aea8c0e
 
aea8c0e
+    if (rSet.GetItemState(SID_SAVE_BACKGROUND) == SfxItemState::DEFAULT)
aea8c0e
+    {
aea8c0e
+        bool bDisableSaveBackground = true;
aea8c0e
+        SdPage* pPage = GetActualPage();
aea8c0e
+        if (pPage != NULL && GetDoc() != NULL)
aea8c0e
+        {
aea8c0e
+            SfxItemSet aMergedAttr(GetDoc()->GetPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST, 0);
aea8c0e
+            SdStyleSheet* pStyleSheet = pPage->getPresentationStyle(HID_PSEUDOSHEET_BACKGROUND);
aea8c0e
+            MergePageBackgroundFilling(pPage, pStyleSheet, meEditMode == EM_MASTERPAGE, aMergedAttr);
aea8c0e
+            if (drawing::FillStyle_BITMAP == static_cast<const XFillStyleItem&>(aMergedAttr.Get(XATTR_FILLSTYLE)).GetValue())
aea8c0e
+            {
aea8c0e
+                bDisableSaveBackground = false;
aea8c0e
+            }
aea8c0e
+        }
aea8c0e
+        if (bDisableSaveBackground)
aea8c0e
+            rSet.DisableItem(SID_SAVE_BACKGROUND);
aea8c0e
+    }
aea8c0e
+
aea8c0e
     GetModeSwitchingMenuState (rSet);
aea8c0e
 }
aea8c0e
 
aea8c0e
-- 
aea8c0e
2.4.3
aea8c0e