include/svx/dialog/ThemeDialog.hxx         |    7 +-----
 include/svx/theme/IThemeColorChanger.hxx   |    2 -
 include/svx/theme/ThemeColorChanger.hxx    |    2 -
 svx/source/dialog/ThemeDialog.cxx          |   11 +++++----
 svx/source/svdraw/svdpage.cxx              |   17 ---------------
 svx/source/theme/ThemeColorChanger.cxx     |    6 ++---
 sw/qa/core/theme/ThemeTest.cxx             |    6 ++---
 sw/source/core/inc/ThemeColorChanger.hxx   |    2 -
 sw/source/core/model/ThemeColorChanger.cxx |   32 ++++++++++++++---------------
 sw/source/uibase/shells/basesh.cxx         |   16 ++++++++++----
 sw/source/uibase/sidebar/ThemePanel.cxx    |    2 -
 11 files changed, 47 insertions(+), 56 deletions(-)

New commits:
commit 6c40e4d1796bcb6418dcb5ec17f46f576c171796
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Tue Jun 6 15:05:18 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Jun 7 08:42:12 2023 +0200

    lok: send theme palette after the change in ThemeDialog
    
    For some reason the SdrPage is constructed in Online after every
    change (cursor, selection) so can't use that to send theme change
    callback. Instead of that send it after the theme is changed with
    the ThemeDialog.
    
    in addition this requires that we transport model::ColorSet in a
    shared_ptr more, to prevent doing constant copies. This requires
    that the IThemeColorChanger interface is changed and the signature
    of apply() method.
    
    Change-Id: Iac951fce57a8e9dff467bd27b2f9c64ec65ea30c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152635
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/dialog/ThemeDialog.hxx 
b/include/svx/dialog/ThemeDialog.hxx
index d715894f027a..020240c97ca3 100644
--- a/include/svx/dialog/ThemeDialog.hxx
+++ b/include/svx/dialog/ThemeDialog.hxx
@@ -36,7 +36,7 @@ private:
     std::unique_ptr<weld::CustomWeld> mxValueSetThemeColorsWindow;
     std::unique_ptr<weld::Button> mxAdd;
 
-    std::optional<std::reference_wrapper<model::ColorSet>> moCurrentColorSet;
+    std::shared_ptr<model::ColorSet> mpCurrentColorSet;
 
     void runThemeColorEditDialog();
     void initColorSets();
@@ -49,10 +49,7 @@ public:
     DECL_LINK(SelectItem, ValueSet*, void);
     DECL_LINK(ButtonClicked, weld::Button&, void);
 
-    std::optional<std::reference_wrapper<model::ColorSet>> const& 
getCurrentColorSet()
-    {
-        return moCurrentColorSet;
-    }
+    std::shared_ptr<model::ColorSet> const& getCurrentColorSet() { return 
mpCurrentColorSet; }
 };
 
 } // end svx namespace
diff --git a/include/svx/theme/IThemeColorChanger.hxx 
b/include/svx/theme/IThemeColorChanger.hxx
index 4f10ad15120f..d9273238c712 100644
--- a/include/svx/theme/IThemeColorChanger.hxx
+++ b/include/svx/theme/IThemeColorChanger.hxx
@@ -18,7 +18,7 @@ class SVXCORE_DLLPUBLIC IThemeColorChanger
 {
 public:
     virtual ~IThemeColorChanger() = default;
-    virtual void apply(model::ColorSet const& rColorSet) = 0;
+    virtual void apply(std::shared_ptr<model::ColorSet> const& pColorSet) = 0;
 };
 
 } // end svx namespace
diff --git a/include/svx/theme/ThemeColorChanger.hxx 
b/include/svx/theme/ThemeColorChanger.hxx
index 708344fef2b3..8e942ea975ad 100644
--- a/include/svx/theme/ThemeColorChanger.hxx
+++ b/include/svx/theme/ThemeColorChanger.hxx
@@ -31,7 +31,7 @@ public:
     ThemeColorChanger(SdrPage* pPage);
     virtual ~ThemeColorChanger() override;
 
-    void apply(model::ColorSet const& rColorSet) override;
+    void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override;
 };
 
 } // end svx namespace
diff --git a/svx/source/dialog/ThemeDialog.cxx 
b/svx/source/dialog/ThemeDialog.cxx
index ce88b2ef4b79..8af6f5975df2 100644
--- a/svx/source/dialog/ThemeDialog.cxx
+++ b/svx/source/dialog/ThemeDialog.cxx
@@ -40,7 +40,7 @@ ThemeDialog::ThemeDialog(weld::Window* pParent, model::Theme* 
pTheme)
     if (!maColorSets.empty())
     {
         mxValueSetThemeColors->SelectItem(1); // ItemId 1, position 0
-        moCurrentColorSet = std::ref(maColorSets[0]);
+        mpCurrentColorSet = std::make_shared<model::ColorSet>(maColorSets[0]);
     }
 }
 
@@ -80,12 +80,12 @@ IMPL_LINK_NOARG(ThemeDialog, SelectItem, ValueSet*, void)
     if (nIndex >= maColorSets.size())
         return;
 
-    moCurrentColorSet = std::ref(maColorSets[nIndex]);
+    mpCurrentColorSet = std::make_shared<model::ColorSet>(maColorSets[nIndex]);
 }
 
 void ThemeDialog::runThemeColorEditDialog()
 {
-    auto pDialog = std::make_shared<svx::ThemeColorEditDialog>(mpWindow, 
*moCurrentColorSet);
+    auto pDialog = std::make_shared<svx::ThemeColorEditDialog>(mpWindow, 
*mpCurrentColorSet);
     weld::DialogController::runAsync(pDialog, [this, pDialog](sal_uInt32 
nResult) {
         if (nResult != RET_OK)
             return;
@@ -99,14 +99,15 @@ void ThemeDialog::runThemeColorEditDialog()
             initColorSets();
 
             mxValueSetThemeColors->SelectItem(maColorSets.size() - 1);
-            moCurrentColorSet = std::ref(maColorSets[maColorSets.size() - 1]);
+            mpCurrentColorSet
+                = 
std::make_shared<model::ColorSet>(maColorSets[maColorSets.size() - 1]);
         }
     });
 }
 
 IMPL_LINK(ThemeDialog, ButtonClicked, weld::Button&, rButton, void)
 {
-    if (moCurrentColorSet && mxAdd.get() == &rButton)
+    if (mpCurrentColorSet && mxAdd.get() == &rButton)
     {
         runThemeColorEditDialog();
     }
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 6bf81968ad17..d806cd7b9438 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -47,7 +47,6 @@
 #include <svx/fmdpage.hxx>
 #include <svx/theme/ThemeColorChanger.hxx>
 #include <svx/ColorSets.hxx>
-#include <svx/theme/ThemeColorPaletteManager.hxx>
 
 #include <sdr/contact/viewcontactofsdrpage.hxx>
 #include <svx/sdr/contact/viewobjectcontact.hxx>
@@ -57,8 +56,6 @@
 #include <rtl/strbuf.hxx>
 #include <libxml/xmlwriter.h>
 #include <docmodel/theme/Theme.hxx>
-#include <sfx2/lokhelper.hxx>
-#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 
@@ -1235,7 +1232,6 @@ SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
         {
             std::shared_ptr<model::ColorSet> pDefaultColorSet(new 
model::ColorSet(*pColorSet));
             mpTheme->setColorSet(pDefaultColorSet);
-            sendLOKitThemeChangedCallback();
         }
     }
 }
@@ -1313,8 +1309,6 @@ void 
SdrPageProperties::SetTheme(std::shared_ptr<model::Theme> const& pTheme)
 
     mpTheme = pTheme;
 
-    sendLOKitThemeChangedCallback();
-
     if (mpTheme && mpTheme->getColorSet() && mpSdrPage->IsMasterPage())
     {
         SdrModel& rModel = mpSdrPage->getSdrModelFromSdrPage();
@@ -1328,20 +1322,11 @@ void 
SdrPageProperties::SetTheme(std::shared_ptr<model::Theme> const& pTheme)
             }
 
             svx::ThemeColorChanger aChanger(pPage);
-            aChanger.apply(*mpTheme->getColorSet());
+            aChanger.apply(mpTheme->getColorSet());
         }
     }
 }
 
-void SdrPageProperties::sendLOKitThemeChangedCallback()
-{
-    if (!comphelper::LibreOfficeKit::isActive())
-        return;
-
-    svx::ThemeColorPaletteManager aManager(mpTheme->getColorSet());
-    SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, 
aManager.generateJSON());
-}
-
 std::shared_ptr<model::Theme> const& SdrPageProperties::GetTheme() const
 {
     return mpTheme;
diff --git a/svx/source/theme/ThemeColorChanger.cxx 
b/svx/source/theme/ThemeColorChanger.cxx
index 06d199cc3896..2edc00820381 100644
--- a/svx/source/theme/ThemeColorChanger.cxx
+++ b/svx/source/theme/ThemeColorChanger.cxx
@@ -135,12 +135,12 @@ ThemeColorChanger::ThemeColorChanger(SdrPage* pPage)
 
 ThemeColorChanger::~ThemeColorChanger() = default;
 
-void ThemeColorChanger::apply(model::ColorSet const& rColorSet)
+void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& 
pColorSet)
 {
     for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject)
     {
         SdrObject* pObject = mpPage->GetObj(nObject);
-        theme::updateSdrObject(rColorSet, pObject);
+        theme::updateSdrObject(*pColorSet, pObject);
 
         // update child objects
         SdrObjList* pList = pObject->GetSubList();
@@ -149,7 +149,7 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
             SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups);
             while (aIter.IsMore())
             {
-                theme::updateSdrObject(rColorSet, aIter.Next());
+                theme::updateSdrObject(*pColorSet, aIter.Next());
             }
         }
     }
diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx
index a7c937d9c923..abd368f47fa9 100644
--- a/sw/qa/core/theme/ThemeTest.cxx
+++ b/sw/qa/core/theme/ThemeTest.cxx
@@ -418,12 +418,12 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeChanging)
     // Change theme colors
     {
         auto const& rColorSets = svx::ColorSets::get();
-        model::ColorSet const& rNewColorSet = rColorSets.getColorSet(0);
+        auto pNewColorSet = 
std::make_shared<model::ColorSet>(rColorSets.getColorSet(0));
         // check that the theme colors are as expected
-        CPPUNIT_ASSERT_EQUAL(OUString(u"LibreOffice"), rNewColorSet.getName());
+        CPPUNIT_ASSERT_EQUAL(OUString(u"LibreOffice"), 
pNewColorSet->getName());
 
         sw::ThemeColorChanger aChanger(pDoc->GetDocShell());
-        aChanger.apply(rNewColorSet);
+        aChanger.apply(pNewColorSet);
     }
 
     // Check new theme colors
diff --git a/sw/source/core/inc/ThemeColorChanger.hxx 
b/sw/source/core/inc/ThemeColorChanger.hxx
index e7e2620a41d0..6c3e9f3cc7f7 100644
--- a/sw/source/core/inc/ThemeColorChanger.hxx
+++ b/sw/source/core/inc/ThemeColorChanger.hxx
@@ -25,7 +25,7 @@ public:
     ThemeColorChanger(SwDocShell* pDocSh);
     virtual ~ThemeColorChanger() override;
 
-    void apply(model::ColorSet const& rColorSet) override;
+    void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override;
 };
 
 } // end sw namespace
diff --git a/sw/source/core/model/ThemeColorChanger.cxx 
b/sw/source/core/model/ThemeColorChanger.cxx
index fb3175e929cf..171f8e67fffb 100644
--- a/sw/source/core/model/ThemeColorChanger.cxx
+++ b/sw/source/core/model/ThemeColorChanger.cxx
@@ -345,7 +345,7 @@ ThemeColorChanger::ThemeColorChanger(SwDocShell* pDocSh)
 
 ThemeColorChanger::~ThemeColorChanger() = default;
 
-void ThemeColorChanger::apply(model::ColorSet const& rColorSet)
+void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& 
pColorSet)
 {
     SwDoc* pDocument = mpDocSh->GetDoc();
     if (!pDocument)
@@ -362,8 +362,8 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
         pPage->getSdrPageProperties().SetTheme(pTheme);
     }
 
-    auto pNewColorSet = std::make_shared<model::ColorSet>(rColorSet);
-    auto pOldColorSet = pTheme->getColorSet();
+    std::shared_ptr<model::ColorSet> pNewColorSet = pColorSet;
+    std::shared_ptr<model::ColorSet> pOldColorSet = pTheme->getColorSet();
     pTheme->setColorSet(pNewColorSet);
 
     auto pUndoThemeChange
@@ -379,8 +379,8 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
         std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
 
         bool bChanged = false;
-        bChanged = bChanged || changeBackground(rAttrSet, *pNewSet, rColorSet);
-        bChanged = bChanged || changeBox(rAttrSet, *pNewSet, rColorSet);
+        bChanged = bChanged || changeBackground(rAttrSet, *pNewSet, 
*pColorSet);
+        bChanged = bChanged || changeBox(rAttrSet, *pNewSet, *pColorSet);
 
         if (bChanged)
         {
@@ -403,8 +403,8 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
             std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
 
             bool bChanged = false;
-            bChanged = changeBackground(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
-            bChanged = changeBox(rAttrSet, *pNewSet, rColorSet) || bChanged;
+            bChanged = changeBackground(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
+            bChanged = changeBox(rAttrSet, *pNewSet, *pColorSet) || bChanged;
 
             if (bChanged)
                 pDocument->ChgFormat(*pFrameFormat, *pNewSet);
@@ -423,11 +423,11 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
             std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
 
             bool bChanged = false;
-            bChanged = changeColor(rAttrSet, *pNewSet, rColorSet) || bChanged;
-            bChanged = changeOverlineColor(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
-            bChanged = changeUnderlineColor(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
-            bChanged = changeBox(rAttrSet, *pNewSet, rColorSet) || bChanged;
-            bChanged = changeBackground(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
+            bChanged = changeColor(rAttrSet, *pNewSet, *pColorSet) || bChanged;
+            bChanged = changeOverlineColor(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
+            bChanged = changeUnderlineColor(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
+            bChanged = changeBox(rAttrSet, *pNewSet, *pColorSet) || bChanged;
+            bChanged = changeBackground(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
 
             if (bChanged)
                 pDocument->ChgFormat(*pTextFormatCollection, *pNewSet);
@@ -446,9 +446,9 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
             std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone();
 
             bool bChanged = false;
-            bChanged = changeColor(rAttrSet, *pNewSet, rColorSet) || bChanged;
-            bChanged = changeOverlineColor(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
-            bChanged = changeUnderlineColor(rAttrSet, *pNewSet, rColorSet) || 
bChanged;
+            bChanged = changeColor(rAttrSet, *pNewSet, *pColorSet) || bChanged;
+            bChanged = changeOverlineColor(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
+            bChanged = changeUnderlineColor(rAttrSet, *pNewSet, *pColorSet) || 
bChanged;
             if (bChanged)
                 pDocument->ChgFormat(*pCharFormat, *pNewSet);
         }
@@ -456,7 +456,7 @@ void ThemeColorChanger::apply(model::ColorSet const& 
rColorSet)
     }
 
     // Direct format change
-    auto pHandler = std::make_shared<ThemeColorHandler>(*pDocument, rColorSet);
+    auto pHandler = std::make_shared<ThemeColorHandler>(*pDocument, 
*pColorSet);
     sw::ModelTraverser aModelTraverser(pDocument);
     aModelTraverser.addNodeHandler(pHandler);
     aModelTraverser.traverse();
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index 5055bbd33b9f..6932ed068fd7 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -91,15 +91,19 @@
 #include <SwRewriter.hxx>
 #include <GraphicSizeCheck.hxx>
 #include <svx/galleryitem.hxx>
+#include <svx/theme/ThemeColorPaletteManager.hxx>
 #include <sfx2/devtools/DevelopmentToolChildWindow.hxx>
 #include <com/sun/star/gallery/GalleryItemType.hpp>
 #include <com/sun/star/beans/PropertyValues.hpp>
 #include <memory>
 
+
 #include <svx/unobrushitemhelper.hxx>
 #include <svx/dialog/ThemeDialog.hxx>
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/lok.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <osl/diagnose.h>
 
 #include <svx/svxdlg.hxx>
@@ -3088,11 +3092,15 @@ void SwBaseShell::ExecDlg(SfxRequest &rReq)
                         if (RET_OK != nResult)
                             return;
 
-                        auto oColorSet = pDialog->getCurrentColorSet();
-                        if (oColorSet)
+                        auto pColorSet = pDialog->getCurrentColorSet();
+                        if (pColorSet)
                         {
-                            auto& rColorSet = (*oColorSet).get();
-                            pChanger->apply(rColorSet);
+                            pChanger->apply(pColorSet);
+                            if (comphelper::LibreOfficeKit::isActive())
+                            {
+                                svx::ThemeColorPaletteManager 
aManager(pColorSet);
+                                
SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, 
aManager.generateJSON());
+                            }
                         }
                     });
                 }
diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx 
b/sw/source/uibase/sidebar/ThemePanel.cxx
index 2dabadbba545..55853a544f8e 100644
--- a/sw/source/uibase/sidebar/ThemePanel.cxx
+++ b/sw/source/uibase/sidebar/ThemePanel.cxx
@@ -97,7 +97,7 @@ void ThemePanel::DoubleClickHdl()
     model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex);
 
     ThemeColorChanger aChanger(pDocSh);
-    aChanger.apply(rColorSet);
+    aChanger.apply(std::make_shared<model::ColorSet>(rColorSet));
 }
 
 void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,

Reply via email to