include/svx/svdmodel.hxx                   |    5 ++++
 include/svx/svdpage.hxx                    |    4 +--
 oox/source/drawingml/theme.cxx             |    2 -
 sc/qa/unit/ucalc_DocumentThemes.cxx        |    8 +-----
 sc/qa/unit/ucalc_sparkline.cxx             |    4 ---
 sc/source/filter/excel/excdoc.cxx          |   26 ++++++++------------
 sc/source/filter/oox/workbookfragment.cxx  |    5 +---
 sc/source/ui/docshell/docsh.cxx            |   14 ++---------
 sc/source/ui/theme/ThemeColorChanger.cxx   |   16 ++++++++----
 sc/source/ui/undo/UndoThemeChange.cxx      |   36 +++++++++++++----------------
 sc/source/ui/view/tabvwsh3.cxx             |    9 +++----
 sd/qa/unit/ThemeTest.cxx                   |    2 -
 sd/source/core/ThemeColorChanger.cxx       |    4 +--
 sd/source/filter/eppt/pptx-epptooxml.cxx   |    2 -
 sd/source/ui/docshell/docshell.cxx         |    4 +--
 sd/source/ui/unoidl/unopage.cxx            |    8 +++---
 sd/source/ui/view/drviews2.cxx             |    2 -
 svx/source/form/fmmodel.cxx                |    8 +-----
 svx/source/svdraw/svdmodel.cxx             |    2 +
 svx/source/svdraw/svdpage.cxx              |   36 ++++++++++++++++-------------
 sw/qa/core/theme/ThemeTest.cxx             |   22 +++++++++--------
 sw/source/core/model/ThemeColorChanger.cxx |    6 ++--
 sw/source/core/undo/UndoThemeChange.cxx    |    8 +++---
 sw/source/core/unocore/unodraw.cxx         |    4 +--
 sw/source/filter/ww8/docxexport.cxx        |    6 +++-
 sw/source/filter/xml/xmlfmte.cxx           |    3 +-
 sw/source/uibase/app/docst.cxx             |    6 ++--
 sw/source/uibase/shells/basesh.cxx         |   10 ++++----
 28 files changed, 129 insertions(+), 133 deletions(-)

New commits:
commit d150b7a60d7be4b09a838ae4c038e78509f75126
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Sat Aug 26 15:35:40 2023 +0200
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Sun Aug 27 12:15:14 2023 +0200

    Change theme location to SdrModel and SdrPage (master page only)
    
    In Writer and Calc we only have one theme per document, so the
    theme can be stored inside the SdrModel. For Imporess/Draw the
    theme is defined per master page, so it needs to be stored on the
    master page. This changes the implementation to reflect that.
    
    In addition refactor all the usages in writer and calc to get and
    set the theme to SdrModel, when needed and rename the methods on
    the SdrPageProperties from {Get,Set}Theme to {get,set}Theme.
    
    Change-Id: I0cc3b332c029c28d15f8cda748c578c2a54a5c61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156128
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx
index 69beb4646175..a5a3a10a2763 100644
--- a/include/svx/svdmodel.hxx
+++ b/include/svx/svdmodel.hxx
@@ -96,6 +96,11 @@ namespace model
 class Theme;
 }
 
+namespace svx
+{
+class IThemeColorChanger;
+}
+
 constexpr const sal_Unicode DEGREE_CHAR = u'\x00B0'; /* U+00B0 DEGREE SIGN */
 
 
diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index 6a65712719f1..97142d661296 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -348,8 +348,8 @@ public:
     void SetStyleSheet(SfxStyleSheet* pStyleSheet);
     SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;}
 
-    void SetTheme(std::shared_ptr<model::Theme> const& pTheme);
-    std::shared_ptr<model::Theme> const& GetTheme() const;
+    void setTheme(std::shared_ptr<model::Theme> const& pTheme);
+    std::shared_ptr<model::Theme> const& getTheme() const;
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx
index e8511a32eb5d..32ae9b4349da 100644
--- a/oox/source/drawingml/theme.cxx
+++ b/oox/source/drawingml/theme.cxx
@@ -120,7 +120,7 @@ void Theme::addTheme(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPa
     if (!pPage)
         return;
 
-    pPage->getSdrPageProperties().SetTheme(getTheme());
+    pPage->getSdrPageProperties().setTheme(getTheme());
 }
 
 } // namespace oox::drawingml
diff --git a/sc/qa/unit/ucalc_DocumentThemes.cxx 
b/sc/qa/unit/ucalc_DocumentThemes.cxx
index f40116742d23..664b06a879f9 100644
--- a/sc/qa/unit/ucalc_DocumentThemes.cxx
+++ b/sc/qa/unit/ucalc_DocumentThemes.cxx
@@ -37,9 +37,7 @@ CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testGetTheme)
 
     ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
-    const SdrPage* pPage(pDrawLayer->GetPage(0));
-    CPPUNIT_ASSERT(pPage);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pDrawLayer->getTheme();
     CPPUNIT_ASSERT(pTheme);
 }
 
@@ -50,9 +48,7 @@ CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme)
 
     ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
-    const SdrPage* pPage(pDrawLayer->GetPage(0));
-    CPPUNIT_ASSERT(pPage);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pDrawLayer->getTheme();
     CPPUNIT_ASSERT(pTheme);
 
     Color aBackgroundThemeColor(0xc99c00);
diff --git a/sc/qa/unit/ucalc_sparkline.cxx b/sc/qa/unit/ucalc_sparkline.cxx
index 951ae2c9047b..d058d16f0248 100644
--- a/sc/qa/unit/ucalc_sparkline.cxx
+++ b/sc/qa/unit/ucalc_sparkline.cxx
@@ -889,9 +889,7 @@ CPPUNIT_TEST_FIXTURE(SparklineTest, 
testSparklineThemeColorChange)
 
     ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
-    const SdrPage* pPage(pDrawLayer->GetPage(0));
-    CPPUNIT_ASSERT(pPage);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pDrawLayer->getTheme();
     CPPUNIT_ASSERT(pTheme);
 
     // Sparkline range
diff --git a/sc/source/filter/excel/excdoc.cxx 
b/sc/source/filter/excel/excdoc.cxx
index 2dab16be5e87..6c97b8686edf 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -868,22 +868,18 @@ void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
         auto* pDrawLayer = GetDoc().GetDrawLayer();
         if (pDrawLayer)
         {
-            SdrPage* pPage = pDrawLayer->GetPage(0);
-            if (pPage)
+            std::shared_ptr<model::Theme> pTheme = pDrawLayer->getTheme();
+            if (pTheme)
             {
-                std::shared_ptr<model::Theme> pTheme = 
pPage->getSdrPageProperties().GetTheme();
-                if (pTheme)
-                {
-                    OUString sThemeRelationshipPath = "theme/theme1.xml";
-                    OUString sThemeDocumentPath = "xl/" + 
sThemeRelationshipPath;
-
-                    oox::ThemeExport aThemeExport(&rStrm, 
oox::drawingml::DOCUMENT_XLSX);
-                    aThemeExport.write(sThemeDocumentPath, *pTheme);
-
-                    
rStrm.addRelation(rStrm.GetCurrentStream()->getOutputStream(),
-                                      
oox::getRelationship(Relationship::THEME),
-                                      sThemeRelationshipPath);
-                }
+                OUString sThemeRelationshipPath = "theme/theme1.xml";
+                OUString sThemeDocumentPath = "xl/" + sThemeRelationshipPath;
+
+                oox::ThemeExport aThemeExport(&rStrm, 
oox::drawingml::DOCUMENT_XLSX);
+                aThemeExport.write(sThemeDocumentPath, *pTheme);
+
+                rStrm.addRelation(rStrm.GetCurrentStream()->getOutputStream(),
+                                  oox::getRelationship(Relationship::THEME),
+                                  sThemeRelationshipPath);
             }
         }
 
diff --git a/sc/source/filter/oox/workbookfragment.cxx 
b/sc/source/filter/oox/workbookfragment.cxx
index 20e595ee6e65..97cc3ca9d1f0 100644
--- a/sc/source/filter/oox/workbookfragment.cxx
+++ b/sc/source/filter/oox/workbookfragment.cxx
@@ -487,10 +487,9 @@ void WorkbookFragment::finalizeImport()
     // load all worksheets
     importSheetFragments(*this, aSheetFragments);
 
-    SdrPage* pPage = pModel->GetPage(0);
-    if (pPage && pTheme && !pTheme->GetName().isEmpty())
+    if (pTheme && !pTheme->GetName().isEmpty())
     {
-        pPage->getSdrPageProperties().SetTheme(pTheme);
+        pModel->setTheme(pTheme);
     }
 
     // assumes getTables().finalizeImport ( which creates the DatabaseRanges )
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 5902ab697789..dc61327de9d1 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -225,19 +225,11 @@ std::shared_ptr<model::ColorSet> 
ScDocShell::GetThemeColors()
     if (!pShell)
         return {};
 
-    ScTabView* pTabView = pShell->GetViewData().GetView();
-    if (!pTabView)
+    SdrModel* pSdrModel = GetDocument().GetDrawLayer();
+    if (!pSdrModel)
         return {};
 
-    ScDrawView* pView = pTabView->GetScDrawView();
-    if (!pView)
-        return {};
-
-    SdrPage* pPage = pView->GetSdrPageView()->GetPage();
-    if (!pPage)
-        return {};
-
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pSdrModel->getTheme();
     if (!pTheme)
         return {};
 
diff --git a/sc/source/ui/theme/ThemeColorChanger.cxx 
b/sc/source/ui/theme/ThemeColorChanger.cxx
index 4b1b555ec647..8af2d4885abf 100644
--- a/sc/source/ui/theme/ThemeColorChanger.cxx
+++ b/sc/source/ui/theme/ThemeColorChanger.cxx
@@ -279,23 +279,27 @@ void changeSparklines(ScDocShell& rDocShell, 
std::shared_ptr<model::ColorSet> co
     }
 }
 
-void changeTheTheme(ScDocShell& rDocShell, std::shared_ptr<model::ColorSet> 
const& pColorSet)
+std::shared_ptr<model::Theme> getTheme(ScDocShell& rDocShell)
 {
-    ScDocument& rDocument = rDocShell.GetDocument();
-    ScDrawLayer* pModel = rDocument.GetDrawLayer();
-    SdrPage* pPage = pModel->GetPage(0);
+    ScDrawLayer* pModel = rDocShell.GetDocument().GetDrawLayer();
 
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pModel->getTheme();
     if (!pTheme)
     {
         pTheme = std::make_shared<model::Theme>("Office");
-        pPage->getSdrPageProperties().SetTheme(pTheme);
+        pModel->setTheme(pTheme);
     }
+    return pTheme;
+}
 
+void changeTheTheme(ScDocShell& rDocShell, std::shared_ptr<model::ColorSet> 
const& pColorSet)
+{
+    auto pTheme = getTheme(rDocShell);
     std::shared_ptr<model::ColorSet> pNewColorSet = pColorSet;
     std::shared_ptr<model::ColorSet> pOldColorSet = pTheme->getColorSet();
     pTheme->setColorSet(pNewColorSet);
 
+    ScDocument& rDocument = rDocShell.GetDocument();
     if (rDocument.IsUndoEnabled())
     {
         auto pUndoThemeChange
diff --git a/sc/source/ui/undo/UndoThemeChange.cxx 
b/sc/source/ui/undo/UndoThemeChange.cxx
index a6a3fe83652e..a977055070c5 100644
--- a/sc/source/ui/undo/UndoThemeChange.cxx
+++ b/sc/source/ui/undo/UndoThemeChange.cxx
@@ -26,20 +26,27 @@ UndoThemeChange::UndoThemeChange(ScDocShell& rDocShell,
 
 UndoThemeChange::~UndoThemeChange() = default;
 
-void UndoThemeChange::Undo()
+namespace
 {
-    BeginUndo();
-
-    ScDocument& rDocument = pDocShell->GetDocument();
-    ScDrawLayer* pModel = rDocument.GetDrawLayer();
-    SdrPage* pPage = pModel->GetPage(0);
+std::shared_ptr<model::Theme> getTheme(ScDocShell& rDocShell)
+{
+    ScDrawLayer* pModel = rDocShell.GetDocument().GetDrawLayer();
 
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pModel->getTheme();
     if (!pTheme)
     {
         pTheme = std::make_shared<model::Theme>("Office");
-        pPage->getSdrPageProperties().SetTheme(pTheme);
+        pModel->setTheme(pTheme);
     }
+    return pTheme;
+}
+}
+
+void UndoThemeChange::Undo()
+{
+    BeginUndo();
+
+    auto pTheme = getTheme(*pDocShell);
     pTheme->setColorSet(mpOldColorSet);
 
     EndUndo();
@@ -47,18 +54,9 @@ void UndoThemeChange::Undo()
 
 void UndoThemeChange::Redo()
 {
-    BeginRedo();
-
-    ScDocument& rDocument = pDocShell->GetDocument();
-    ScDrawLayer* pModel = rDocument.GetDrawLayer();
-    SdrPage* pPage = pModel->GetPage(0);
+    BeginUndo();
 
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
-    if (!pTheme)
-    {
-        pTheme = std::make_shared<model::Theme>("Office");
-        pPage->getSdrPageProperties().SetTheme(pTheme);
-    }
+    auto pTheme = getTheme(*pDocShell);
     pTheme->setColorSet(mpNewColorSet);
 
     EndRedo();
diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index 255dbed88508..ce0453040461 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -1345,13 +1345,12 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
         case SID_THEME_DIALOG:
         {
             MakeDrawLayer();
-            ScTabView* pTabView = GetViewData().GetView();
-            ScDrawView* pView = pTabView->GetScDrawView();
-            SdrPage* pPage = pView->GetSdrPageView()->GetPage();
-            auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+            ScViewData& rViewData = GetViewData();
+            ScDocument& rDocument = rViewData.GetDocument();
+            ScDrawLayer* pModel = rDocument.GetDrawLayer();
+            auto const& pTheme = pModel->getTheme();
             if (pTheme)
             {
-                ScViewData& rViewData = GetViewData();
                 vcl::Window* pWin = rViewData.GetActiveWin();
                 auto pDialog = std::make_shared<svx::ThemeDialog>(pWin ? 
pWin->GetFrameWeld() : nullptr, pTheme.get());
                 weld::DialogController::runAsync(pDialog, [this, 
pDialog](sal_uInt32 nResult) {
diff --git a/sd/qa/unit/ThemeTest.cxx b/sd/qa/unit/ThemeTest.cxx
index 1b4f24249b9b..3a12ce69ca35 100644
--- a/sd/qa/unit/ThemeTest.cxx
+++ b/sd/qa/unit/ThemeTest.cxx
@@ -133,7 +133,7 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange)
     css::uno::Reference<css::drawing::XDrawPage> xDrawPageMaster(xMasterPage, 
uno::UNO_QUERY);
     CPPUNIT_ASSERT(xDrawPageMaster.is());
     auto* pMasterPage = GetSdrPageFromXDrawPage(xDrawPageMaster);
-    auto pTheme = pMasterPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pMasterPage->getSdrPageProperties().getTheme();
 
     sd::ThemeColorChanger aChanger(pMasterPage, pDocShell);
     aChanger.apply(pTheme->getColorSet());
diff --git a/sd/source/core/ThemeColorChanger.cxx 
b/sd/source/core/ThemeColorChanger.cxx
index a506762708f1..020bc1455f6c 100644
--- a/sd/source/core/ThemeColorChanger.cxx
+++ b/sd/source/core/ThemeColorChanger.cxx
@@ -41,11 +41,11 @@ namespace
 {
 void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> 
const& pColorSet)
 {
-    auto pTheme = pMasterPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pMasterPage->getSdrPageProperties().getTheme();
     if (!pTheme)
     {
         pTheme = std::make_shared<model::Theme>("Office");
-        pMasterPage->getSdrPageProperties().SetTheme(pTheme);
+        pMasterPage->getSdrPageProperties().setTheme(pTheme);
     }
     pTheme->setColorSet(pColorSet);
 }
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index 8c0e7f740437..9a77780614d4 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -1519,7 +1519,7 @@ void PowerPointExport::ImplWriteSlideMaster(sal_uInt32 
nPageNum, Reference< XPro
     model::Theme* pTheme = nullptr;
     if (pMasterPage)
     {
-        pTheme = pMasterPage->getSdrPageProperties().GetTheme().get();
+        pTheme = pMasterPage->getSdrPageProperties().getTheme().get();
     }
 
     // write theme per master
diff --git a/sd/source/ui/docshell/docshell.cxx 
b/sd/source/ui/docshell/docshell.cxx
index 40c2fbc97a8e..705e293974b2 100644
--- a/sd/source/ui/docshell/docshell.cxx
+++ b/sd/source/ui/docshell/docshell.cxx
@@ -491,9 +491,9 @@ std::shared_ptr<model::ColorSet> 
DrawDocShell::GetThemeColors()
         return {};
 
     SdPage* pPage = pViewShell->getCurrentPage();
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pPage->getSdrPageProperties().getTheme();
     if (!pPage->IsMasterPage())
-        pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().GetTheme();
+        pTheme = pPage->TRG_GetMasterPage().getSdrPageProperties().getTheme();
 
     if (!pTheme)
         return {};
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index ee95c853d37c..17080d0532b2 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -985,7 +985,7 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const 
OUString& aPropertyName
             if (aValue >>= xTheme)
             {
                 auto& rUnoTheme = dynamic_cast<UnoTheme&>(*xTheme);
-                pPage->getSdrPageProperties().SetTheme(rUnoTheme.getTheme());
+                pPage->getSdrPageProperties().setTheme(rUnoTheme.getTheme());
             }
             break;
         }
@@ -994,7 +994,7 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const 
OUString& aPropertyName
         {
             SdrPage* pPage = GetPage();
             std::shared_ptr<model::Theme> pTheme = 
model::Theme::FromAny(aValue);
-            pPage->getSdrPageProperties().SetTheme(pTheme);
+            pPage->getSdrPageProperties().setTheme(pTheme);
             break;
         }
 
@@ -1316,7 +1316,7 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const 
OUString& PropertyName )
     {
         SdrPage* pPage = GetPage();
         css::uno::Reference<css::util::XTheme> xTheme;
-        auto pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto pTheme = pPage->getSdrPageProperties().getTheme();
         if (pTheme)
             xTheme = model::theme::createXTheme(pTheme);
         aAny <<= xTheme;
@@ -1326,7 +1326,7 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const 
OUString& PropertyName )
     case WID_PAGE_THEME_UNO_REPRESENTATION:
     {
         SdrPage* pPage = GetPage();
-        auto pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto pTheme = pPage->getSdrPageProperties().getTheme();
         if (pTheme)
             pTheme->ToAny(aAny);
         else
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 2fea8a46f879..4dc14204b53d 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -3551,7 +3551,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
         case SID_THEME_DIALOG:
         {
             SdrPage* pMasterPage = &GetActualPage()->TRG_GetMasterPage();
-            auto pTheme = pMasterPage->getSdrPageProperties().GetTheme();
+            auto pTheme = pMasterPage->getSdrPageProperties().getTheme();
             auto pDialog = std::make_shared<svx::ThemeDialog>(GetFrameWeld(), 
pTheme.get());
             auto* pDocShell = GetDocSh();
             weld::DialogController::runAsync(pDialog, [pDialog, pMasterPage, 
pDocShell](sal_uInt32 nResult)
diff --git a/svx/source/form/fmmodel.cxx b/svx/source/form/fmmodel.cxx
index e518319aab1e..58155f874c77 100644
--- a/svx/source/form/fmmodel.cxx
+++ b/svx/source/form/fmmodel.cxx
@@ -48,12 +48,8 @@ struct FmFormModelImplData
     }
 };
 
-FmFormModel::FmFormModel(
-    SfxItemPool* pPool,
-    SfxObjectShell* pPers)
-:   SdrModel(
-        pPool,
-        pPers)
+FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers)
+    : SdrModel(pPool, pPers)
     , m_pObjShell(nullptr)
     , m_bOpenInDesignMode(false)
     , m_bAutoControlFocus(false)
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index de4f85f7c10f..a368af5a1a5e 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -50,6 +50,7 @@
 #include <svx/svdoutl.hxx>
 #include <svx/dialmgr.hxx>
 #include <svx/strings.hrc>
+#include <svx/theme/IThemeColorChanger.hxx>
 #include <svdoutlinercache.hxx>
 #include <svx/sdasitm.hxx>
 #include <officecfg/Office/Common.hxx>
@@ -89,6 +90,7 @@ struct SdrModelImpl
     bool mbConnectorUseSnapRect;       // tdf#149756 compatibility flag
     bool mbIgnoreBreakAfterMultilineField; ///< tdf#148966 compatibility flag
     std::shared_ptr<model::Theme> mpTheme;
+    std::shared_ptr<svx::IThemeColorChanger> mpThemeColorChanger;
 
     SdrModelImpl()
         : mpUndoManager(nullptr)
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index a8b5697546cd..6e17a91d5a4d 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -1192,17 +1192,6 @@ SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
     {
         maProperties.Put(XFillStyleItem(drawing::FillStyle_NONE));
     }
-
-    //if (rSdrPage.getSdrModelFromSdrPage().IsWriter() || 
rSdrPage.IsMasterPage())
-    {
-        mpTheme.reset(new model::Theme("Office Theme"));
-        auto const* pColorSet = 
svx::ColorSets::get().getColorSet(u"LibreOffice");
-        if (pColorSet)
-        {
-            std::shared_ptr<model::ColorSet> pDefaultColorSet(new 
model::ColorSet(*pColorSet));
-            mpTheme->setColorSet(pDefaultColorSet);
-        }
-    }
 }
 
 SdrPageProperties::~SdrPageProperties()
@@ -1271,16 +1260,33 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* 
pStyleSheet)
     ImpPageChange(*mpSdrPage);
 }
 
-void SdrPageProperties::SetTheme(std::shared_ptr<model::Theme> const& pTheme)
+void SdrPageProperties::setTheme(std::shared_ptr<model::Theme> const& pTheme)
 {
-    if (mpTheme == pTheme)
+    if (!mpSdrPage)
         return;
 
-    mpTheme = pTheme;
+    // Only set the theme on a master page, else set it on the model
+
+    if (mpSdrPage->IsMasterPage())
+    {
+        if (mpTheme != pTheme)
+            mpTheme = pTheme;
+    }
+    else
+    {
+        mpSdrPage->getSdrModelFromSdrPage().setTheme(pTheme);
+    }
 }
 
-std::shared_ptr<model::Theme> const& SdrPageProperties::GetTheme() const
+std::shared_ptr<model::Theme> const& SdrPageProperties::getTheme() const
 {
+    // if set - page theme has priority
+    if (mpTheme)
+        return mpTheme;
+    // else the model theme
+    else if (mpSdrPage)
+        return mpSdrPage->getSdrModelFromSdrPage().getTheme();
+    // else return empty shared_ptr
     return mpTheme;
 }
 
diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx
index de6132237a4b..fc9ed7be9abe 100644
--- a/sw/qa/core/theme/ThemeTest.cxx
+++ b/sw/qa/core/theme/ThemeTest.cxx
@@ -335,8 +335,9 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, 
testDrawPageThemeExistsDOCX)
     SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
-    SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    SdrModel* pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+    CPPUNIT_ASSERT(pModel);
+    auto const& pTheme = pModel->getTheme();
     CPPUNIT_ASSERT(pTheme);
     CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
@@ -382,8 +383,9 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, 
testDrawPageThemeExistsODT)
     SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
-    SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    SdrModel* pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+    CPPUNIT_ASSERT(pModel);
+    auto const& pTheme = pModel->getTheme();
     CPPUNIT_ASSERT(pTheme);
     CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
@@ -410,12 +412,12 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeChanging)
     CPPUNIT_ASSERT(pDoc);
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    CPPUNIT_ASSERT(pPage);
+    SdrModel* pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+    CPPUNIT_ASSERT(pModel);
 
     // Check current theme colors
     {
-        auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto const& pTheme = pModel->getTheme();
         CPPUNIT_ASSERT(pTheme);
         CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
@@ -438,7 +440,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeChanging)
 
     // Check new theme colors
     {
-        auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto const& pTheme = pModel->getTheme();
         CPPUNIT_ASSERT(pTheme);
         CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
@@ -453,7 +455,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeChanging)
 
     // Check theme colors have been reverted
     {
-        auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto const& pTheme = pModel->getTheme();
         CPPUNIT_ASSERT(pTheme);
         CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
@@ -468,7 +470,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeChanging)
 
     // Check theme colors have been applied again
     {
-        auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+        auto const& pTheme = pModel->getTheme();
         CPPUNIT_ASSERT(pTheme);
         CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName());
 
diff --git a/sw/source/core/model/ThemeColorChanger.cxx 
b/sw/source/core/model/ThemeColorChanger.cxx
index 58fb1a32bbb5..a14f8d872cf4 100644
--- a/sw/source/core/model/ThemeColorChanger.cxx
+++ b/sw/source/core/model/ThemeColorChanger.cxx
@@ -330,13 +330,13 @@ void 
ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
 
     pDocument->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
 
-    SdrPage* pPage = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+    SdrModel* pModel = pDocument->getIDocumentDrawModelAccess().GetDrawModel();
 
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto pTheme = pModel->getTheme();
     if (!pTheme)
     {
         pTheme = std::make_shared<model::Theme>("Office");
-        pPage->getSdrPageProperties().SetTheme(pTheme);
+        pModel->setTheme(pTheme);
     }
 
     std::shared_ptr<model::ColorSet> pNewColorSet = pColorSet;
diff --git a/sw/source/core/undo/UndoThemeChange.cxx 
b/sw/source/core/undo/UndoThemeChange.cxx
index 468df82274e3..8e26106873e7 100644
--- a/sw/source/core/undo/UndoThemeChange.cxx
+++ b/sw/source/core/undo/UndoThemeChange.cxx
@@ -32,15 +32,15 @@ UndoThemeChange::~UndoThemeChange() {}
 
 void UndoThemeChange::UndoImpl(UndoRedoContext& /*rUndoRedoContext*/)
 {
-    SdrPage* pPage = 
mrDocument.getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    SdrModel* pModel = mrDocument.getIDocumentDrawModelAccess().GetDrawModel();
+    auto pTheme = pModel->getTheme();
     pTheme->setColorSet(mpOldColorSet);
 }
 
 void UndoThemeChange::RedoImpl(UndoRedoContext& /*rUndoRedoContext*/)
 {
-    SdrPage* pPage = 
mrDocument.getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    auto pTheme = pPage->getSdrPageProperties().GetTheme();
+    SdrModel* pModel = mrDocument.getIDocumentDrawModelAccess().GetDrawModel();
+    auto pTheme = pModel->getTheme();
     pTheme->setColorSet(mpNewColorSet);
 }
 }
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index 422b1236c489..5ab0fea55215 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -406,7 +406,7 @@ void SwFmDrawPage::setPropertyValue(const OUString& 
rPropertyName, const uno::An
             if (aValue >>= xTheme)
             {
                 auto& rUnoTheme = dynamic_cast<UnoTheme&>(*xTheme);
-                pPage->getSdrPageProperties().SetTheme(rUnoTheme.getTheme());
+                pPage->getSdrModelFromSdrPage().setTheme(rUnoTheme.getTheme());
             }
         }
         break;
@@ -442,7 +442,7 @@ uno::Any SwFmDrawPage::getPropertyValue(const OUString& 
rPropertyName)
         {
             css::uno::Reference<css::util::XTheme> xTheme;
 
-            auto pTheme = GetSdrPage()->getSdrPageProperties().GetTheme();
+            auto pTheme = GetSdrPage()->getSdrModelFromSdrPage().getTheme();
             if (pTheme)
                 xTheme = model::theme::createXTheme(pTheme);
             aAny <<= xTheme;
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index f7258952a541..7879d44035b2 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1471,8 +1471,10 @@ void DocxExport::WriteSettings()
 
 void DocxExport::WriteTheme()
 {
-    SdrPage* pPage = 
m_rDoc.getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    SdrModel* pModel = m_rDoc.getIDocumentDrawModelAccess().GetDrawModel();
+    if (!pModel)
+        return;
+    auto const& pTheme = pModel->getTheme();
     if (!pTheme)
         return;
 
diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx
index 8769362430be..7eba318cac78 100644
--- a/sw/source/filter/xml/xmlfmte.cxx
+++ b/sw/source/filter/xml/xmlfmte.cxx
@@ -45,6 +45,7 @@
 #include <o3tl/enumrange.hxx>
 #include <svx/unoapi.hxx>
 #include <svx/svdpage.hxx>
+#include <svx/svdmodel.hxx>
 #include <docmodel/theme/ThemeColorType.hxx>
 #include <docmodel/theme/Theme.hxx>
 
@@ -205,7 +206,7 @@ void SwXMLExport::ExportThemeElement(const 
uno::Reference<drawing::XDrawPage>& x
     if (!pPage)
         return;
 
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pPage->getSdrModelFromSdrPage().getTheme();
     if (!pTheme)
         return;
 
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 8dcff2903414..02e234bdc6df 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1615,10 +1615,10 @@ std::set<Color> SwDocShell::GetDocColors()
 
 std::shared_ptr<model::ColorSet> SwDocShell::GetThemeColors()
 {
-    SdrPage* pPage = 
m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-    if (!pPage)
+    SdrModel* pModel = m_xDoc->getIDocumentDrawModelAccess().GetDrawModel();
+    if (!pModel)
         return {};
-    auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+    auto const& pTheme = pModel->getTheme();
     if (!pTheme)
         return {};
     return pTheme->getColorSet();
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index a2ea7501e1e9..57e7c8299546 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -2138,10 +2138,10 @@ void SwBaseShell::GetState( SfxItemSet &rSet )
                 auto* pDocumentShell = pDocument->GetDocShell();
                 if (pDocumentShell)
                 {
-                    SdrPage* pPage = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-                    if (pPage)
+                    SdrModel* pModel = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel();
+                    if (pModel)
                     {
-                        auto const& pTheme = 
pPage->getSdrPageProperties().GetTheme();
+                        auto const& pTheme = pModel->getTheme();
                         if (pTheme)
                             bDisable = false;
                     }
@@ -2970,8 +2970,8 @@ void SwBaseShell::ExecDlg(SfxRequest &rReq)
             auto* pDocumentShell = pDocument->GetDocShell();
             if (pDocumentShell)
             {
-                SdrPage* pPage = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-                auto const& pTheme = pPage->getSdrPageProperties().GetTheme();
+                SdrModel* pModel = 
pDocument->getIDocumentDrawModelAccess().GetDrawModel();
+                auto const& pTheme = pModel->getTheme();
                 if (pTheme)
                 {
                     std::shared_ptr<svx::IThemeColorChanger> pChanger(new 
sw::ThemeColorChanger(pDocumentShell));

Reply via email to