sd/source/core/ThemeColorChanger.cxx         |   42 ++++++++++++++-------------
 svx/source/theme/ThemeColorChangerCommon.cxx |   17 +++++-----
 2 files changed, 32 insertions(+), 27 deletions(-)

New commits:
commit e3a9b09ffdb6fd3bf9f1d14c11d87468c3fab92c
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Aug 31 08:11:18 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Sep 4 09:11:35 2023 +0200

    sd: set the theme for all master pages
    
    It can be annoying for the user to set the theme one by one for
    each master page. The reason for this is that in MSO the master
    slide (which contains the theme) has multiple layouts, which are
    converted to master pages in LO. As LO doesn't group master pages
    together the theme is defined on each master page, so it is needed
    to change each master page one by one.
    
    Change-Id: I94d75246ca012bbbb005ab376446c0941b8f57ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156361
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 70663f464b24f223c4174681b9a469d9f554bcee)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156454
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sd/source/core/ThemeColorChanger.cxx 
b/sd/source/core/ThemeColorChanger.cxx
index 573a5f085dd4..3a5c7804ae57 100644
--- a/sd/source/core/ThemeColorChanger.cxx
+++ b/sd/source/core/ThemeColorChanger.cxx
@@ -154,31 +154,35 @@ void 
ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
     {
         SdrPage* pCurrentPage = rModel.GetPage(nPage);
 
-        // Skip pages that are usign a different master page
-        if (!pCurrentPage->TRG_HasMasterPage()
-            || &pCurrentPage->TRG_GetMasterPage() != mpMasterPage)
-            continue;
-
-        for (size_t nObject = 0; nObject < pCurrentPage->GetObjCount(); 
++nObject)
+        // TODO - for now change all the objects regardless to which master 
page it belongs to.
+        // Currently we don't have a concept of master slide with a group of 
layouts as in MSO, but we always only
+        // have master pages, which aren't grouped together. In MSO the theme 
is defined per master slide, so when
+        // changing a theme, all the layouts get the new theme, as layouts are 
synonomus to master pages in LibreOffise,
+        // this is not possible to do and we would need to change the theme 
for each master page separately, which
+        // is just annoying for the user.
+
+        // if (!pCurrentPage->TRG_HasMasterPage() || 
&pCurrentPage->TRG_GetMasterPage() != mpMasterPage)
+        //     continue;
+
+        SdrObjListIter aIter(pCurrentPage, SdrIterMode::DeepWithGroups);
+        while (aIter.IsMore())
         {
-            SdrObject* pObject = pCurrentPage->GetObj(nObject);
-            svx::theme::updateSdrObject(*pColorSet, pObject, pView, 
pUndoManager);
-
-            // update child objects
-            SdrObjList* pList = pObject->GetSubList();
-            if (pList)
-            {
-                SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups);
-                while (aIter.IsMore())
-                {
-                    svx::theme::updateSdrObject(*pColorSet, aIter.Next(), 
pView, pUndoManager);
-                }
-            }
+            svx::theme::updateSdrObject(*pColorSet, aIter.Next(), pView, 
pUndoManager);
         }
     }
 
     changeThemeColors(mpDocShell, mpMasterPage, pColorSet);
 
+    // See the TODO comment a couple of line above for the explanation - need 
to change the ThemeColors for all master
+    // pages for now, but the following code will need to be changed in the 
future when we have the concept similar to
+    // master slide and layouts
+    for (sal_uInt16 nPage = 0; nPage < rModel.GetPageCount(); ++nPage)
+    {
+        SdrPage* pCurrentPage = rModel.GetPage(nPage);
+        if (pCurrentPage->IsMasterPage() && pCurrentPage != mpMasterPage)
+            changeThemeColors(mpDocShell, pCurrentPage, pColorSet);
+    }
+
     pUndoManager->LeaveListAction();
 }
 
diff --git a/svx/source/theme/ThemeColorChangerCommon.cxx 
b/svx/source/theme/ThemeColorChangerCommon.cxx
index fab4835684a1..5ff1a0de8cd6 100644
--- a/svx/source/theme/ThemeColorChangerCommon.cxx
+++ b/svx/source/theme/ThemeColorChangerCommon.cxx
@@ -105,13 +105,8 @@ bool updateEditEngTextSections(model::ColorSet const& 
rColorSet, SdrObject* pObj
 bool updateObjectAttributes(model::ColorSet const& rColorSet, SdrObject& 
rObject,
                             SfxUndoManager* pUndoManager)
 {
-    if (pUndoManager)
-    {
-        pUndoManager->AddUndoAction(
-            
rObject.getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoAttrObject(
-                rObject, true, true));
-    }
     bool bChanged = false;
+
     auto aItemSet = rObject.GetMergedItemSet();
 
     if (const XFillColorItem* pItem = aItemSet.GetItemIfSet(XATTR_FILLCOLOR, 
false))
@@ -152,6 +147,13 @@ bool updateObjectAttributes(model::ColorSet const& 
rColorSet, SdrObject& rObject
     }
     if (bChanged)
     {
+        const bool bUndo = pUndoManager && pUndoManager->IsInListAction();
+        if (bUndo)
+        {
+            pUndoManager->AddUndoAction(
+                
rObject.getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoAttrObject(
+                    rObject));
+        }
         rObject.SetMergedItemSetAndBroadcast(aItemSet);
     }
     return bChanged;
@@ -165,10 +167,9 @@ void updateSdrObject(model::ColorSet const& rColorSet, 
SdrObject* pObject, SdrVi
 {
     if (!pObject)
         return;
-
+    updateObjectAttributes(rColorSet, *pObject, pUndoManager);
     if (pView)
         updateEditEngTextSections(rColorSet, pObject, *pView);
-    updateObjectAttributes(rColorSet, *pObject, pUndoManager);
 }
 
 } // end svx::theme namespace

Reply via email to