include/svx/PaletteManager.hxx                 |    4 ++
 include/svx/theme/IThemeColorChanger.hxx       |    2 -
 include/svx/theme/ThemeColorChangerCommon.hxx  |    5 ++-
 include/svx/theme/ThemeColorPaletteManager.hxx |    3 +-
 sc/source/ui/view/tabvwshc.cxx                 |    4 ++
 sd/source/ui/view/ViewShellBase.cxx            |    4 ++
 svx/source/tbxctrls/PaletteManager.cxx         |   36 ++++++++++++++++++++++++-
 svx/source/theme/ThemeColorChangerCommon.cxx   |   16 +++++++++--
 svx/source/theme/ThemeColorPaletteManager.cxx  |    9 ------
 sw/source/uibase/uiview/view.cxx               |    4 ++
 10 files changed, 70 insertions(+), 17 deletions(-)

New commits:
commit 39b5a39bdc6d7fc86db5be6058b9f9251f070739
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Mon Jan 8 18:46:13 2024 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Fri Jan 12 13:58:22 2024 +0100

    Send document colors with lok callback
    
    First step for publishing any palette for LOK.
    Let's start with Document colors (colors used in the
    document) which can be extracted similar to theme
    colors from SfxViewShell.
    
    Modify generateJSON function so it appends palette into
    existing ptree/JSON.
    
    In the next step we can make it more generic so it will
    be able to send any palette managed by PaletteManager.
    
    Change-Id: Ibb56690af6dfd59ee232e88b28e7a3d312d0e16c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161798
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit 0460be8848b0ce02c07183e41dd7137ac3b94164)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161941
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx
index 81f30ea7de76..90fa00de59fe 100644
--- a/include/svx/PaletteManager.hxx
+++ b/include/svx/PaletteManager.hxx
@@ -27,6 +27,7 @@
 #include <deque>
 #include <vector>
 #include <memory>
+#include <set>
 
 namespace com::sun::star::uno { class XComponentContext; }
 namespace svx { class ToolboxButtonColorUpdaterBase; }
@@ -86,6 +87,9 @@ public:
     bool GetLumModOff(sal_uInt16 nThemeIndex, sal_uInt16 nEffect, sal_Int16& 
rLumMod, sal_Int16& rLumOff);
 
     static void DispatchColorCommand(const OUString& aCommand, const 
NamedColor& rColor);
+
+    /// Appends node for Document Colors into the ptree
+    static void generateJSON(boost::property_tree::ptree& aTree, const 
std::set<Color>& rColors);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/theme/IThemeColorChanger.hxx 
b/include/svx/theme/IThemeColorChanger.hxx
index 0b3b88d60afa..035494f12324 100644
--- a/include/svx/theme/IThemeColorChanger.hxx
+++ b/include/svx/theme/IThemeColorChanger.hxx
@@ -22,7 +22,7 @@ public:
     void apply(std::shared_ptr<model::ColorSet> const& pColorSet)
     {
         doApply(pColorSet);
-        svx::theme::notifyLOK(pColorSet);
+        svx::theme::notifyLOK(pColorSet, std::set<Color>());
     }
 
 private:
diff --git a/include/svx/theme/ThemeColorChangerCommon.hxx 
b/include/svx/theme/ThemeColorChangerCommon.hxx
index 3a585236fbf8..9fa3f4376ddc 100644
--- a/include/svx/theme/ThemeColorChangerCommon.hxx
+++ b/include/svx/theme/ThemeColorChangerCommon.hxx
@@ -9,6 +9,7 @@
 
 #pragma once
 
+#include <set>
 #include <svx/svxdllapi.h>
 #include <docmodel/theme/ColorSet.hxx>
 #include <svx/svdobj.hxx>
@@ -22,7 +23,9 @@ namespace theme
 SVXCORE_DLLPUBLIC void updateSdrObject(model::ColorSet const& rColorSet, 
SdrObject* pObject,
                                        SdrView* pView, SfxUndoManager* 
pUndoManager = nullptr);
 
-SVXCORE_DLLPUBLIC void notifyLOK(std::shared_ptr<model::ColorSet> const& 
pColorSet);
+/// Sends to the LOK updated palettes
+SVXCORE_DLLPUBLIC void notifyLOK(std::shared_ptr<model::ColorSet> const& 
pColorSet,
+                                 const std::set<Color>& rDocumentColors);
 }
 
 } // end svx namespace
diff --git a/include/svx/theme/ThemeColorPaletteManager.hxx 
b/include/svx/theme/ThemeColorPaletteManager.hxx
index 7bb8526a2409..8531021bbc84 100644
--- a/include/svx/theme/ThemeColorPaletteManager.hxx
+++ b/include/svx/theme/ThemeColorPaletteManager.hxx
@@ -14,6 +14,7 @@
 #include <memory>
 #include <tools/color.hxx>
 #include <docmodel/theme/ThemeColorType.hxx>
+#include <boost/property_tree/json_parser.hpp>
 
 namespace model
 {
@@ -60,7 +61,7 @@ class SVXCORE_DLLPUBLIC ThemeColorPaletteManager final
 public:
     ThemeColorPaletteManager(std::shared_ptr<model::ColorSet> const& 
pColorSet);
     ThemePaletteCollection generate();
-    OString generateJSON();
+    void generateJSON(boost::property_tree::ptree& aTree);
 };
 
 } // end svx namespace
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 1012f1ceb249..b0c3aa54343c 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -483,7 +483,9 @@ void ScTabViewShell::afterCallbackRegistered()
     SfxObjectShell* pDocShell = GetObjectShell();
     if (pDocShell)
     {
-        svx::theme::notifyLOK(pDocShell->GetThemeColors());
+        std::shared_ptr<model::ColorSet> pThemeColors = 
pDocShell->GetThemeColors();
+        std::set<Color> aDocumentColors = pDocShell->GetDocColors();
+        svx::theme::notifyLOK(pThemeColors, aDocumentColors);
     }
 }
 
diff --git a/sd/source/ui/view/ViewShellBase.cxx 
b/sd/source/ui/view/ViewShellBase.cxx
index 6ba412acf7d9..70691ce1133e 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -1019,7 +1019,9 @@ void ViewShellBase::afterCallbackRegistered()
     SfxObjectShell* pDocShell = GetObjectShell();
     if (pDocShell)
     {
-        svx::theme::notifyLOK(pDocShell->GetThemeColors());
+        std::shared_ptr<model::ColorSet> pThemeColors = 
pDocShell->GetThemeColors();
+        std::set<Color> aDocumentColors = pDocShell->GetDocColors();
+        svx::theme::notifyLOK(pThemeColors, aDocumentColors);
     }
 }
 
diff --git a/svx/source/tbxctrls/PaletteManager.cxx 
b/svx/source/tbxctrls/PaletteManager.cxx
index 257a935002c5..e4fd8b2d1fa2 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -47,7 +47,6 @@
 #include <memory>
 #include <array>
 #include <stack>
-#include <set>
 
 PaletteManager::PaletteManager() :
     
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
@@ -467,4 +466,39 @@ void PaletteManager::DispatchColorCommand(const OUString& 
aCommand, const NamedC
     }
 }
 
+// TODO: make it generic, send any palette
+void PaletteManager::generateJSON(boost::property_tree::ptree& aTree, const 
std::set<Color>& rColors)
+{
+    boost::property_tree::ptree aColorListTree;
+    sal_uInt32 nStartIndex = 1;
+
+    const StyleSettings& rStyleSettings = 
Application::GetSettings().GetStyleSettings();
+    sal_uInt32 nColumnCount = rStyleSettings.GetColorValueSetColumnCount();
+    const OUString 
aNamePrefix(Concat2View(SvxResId(RID_SVXSTR_DOC_COLOR_PREFIX) + " "));
+
+    auto aColorIt = rColors.begin();
+    while (aColorIt != rColors.end())
+    {
+        boost::property_tree::ptree aColorRowTree;
+
+        for (sal_uInt32 nColumn = 0; nColumn < nColumnCount; nColumn++)
+        {
+            boost::property_tree::ptree aColorTree;
+            OUString sName = aNamePrefix + OUString::number(nStartIndex++);
+            aColorTree.put("Value", aColorIt->AsRGBHexString().toUtf8());
+            aColorTree.put("Name", sName);
+
+            aColorRowTree.push_back(std::make_pair("", aColorTree));
+
+            aColorIt++;
+            if (aColorIt == rColors.end())
+                break;
+        }
+
+        aColorListTree.push_back(std::make_pair("", aColorRowTree));
+    }
+
+    aTree.add_child("DocumentColors", aColorListTree);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/theme/ThemeColorChangerCommon.cxx 
b/svx/source/theme/ThemeColorChangerCommon.cxx
index 0e3548ed83cc..bca8ea1a1bb7 100644
--- a/svx/source/theme/ThemeColorChangerCommon.cxx
+++ b/svx/source/theme/ThemeColorChangerCommon.cxx
@@ -22,6 +22,7 @@
 
 #include <sfx2/lokhelper.hxx>
 
+#include <svx/PaletteManager.hxx>
 #include <svx/svdmodel.hxx>
 #include <svx/svdotext.hxx>
 #include <svx/svdundo.hxx>
@@ -171,12 +172,23 @@ void updateSdrObject(model::ColorSet const& rColorSet, 
SdrObject* pObject, SdrVi
         updateEditEngTextSections(rColorSet, pObject, *pView);
 }
 
-void notifyLOK(std::shared_ptr<model::ColorSet> const& pColorSet)
+void notifyLOK(std::shared_ptr<model::ColorSet> const& pColorSet,
+               const std::set<Color>& rDocumentColors)
 {
     if (comphelper::LibreOfficeKit::isActive())
     {
         svx::ThemeColorPaletteManager aManager(pColorSet);
-        SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, 
aManager.generateJSON());
+        std::stringstream aStream;
+        boost::property_tree::ptree aTree;
+
+        if (pColorSet)
+            aManager.generateJSON(aTree);
+        if (rDocumentColors.size())
+            PaletteManager::generateJSON(aTree, rDocumentColors);
+
+        boost::property_tree::write_json(aStream, aTree);
+
+        SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, 
OString(aStream.str()));
     }
 }
 
diff --git a/svx/source/theme/ThemeColorPaletteManager.cxx 
b/svx/source/theme/ThemeColorPaletteManager.cxx
index eeef402a9661..4ba2ddfe8312 100644
--- a/svx/source/theme/ThemeColorPaletteManager.cxx
+++ b/svx/source/theme/ThemeColorPaletteManager.cxx
@@ -15,7 +15,6 @@
 #include <svx/strings.hrc>
 #include <docmodel/theme/ColorSet.hxx>
 #include <docmodel/color/ComplexColorJSON.hxx>
-#include <boost/property_tree/json_parser.hpp>
 
 #include <array>
 
@@ -126,11 +125,10 @@ svx::ThemePaletteCollection 
ThemeColorPaletteManager::generate()
     return aThemePaletteCollection;
 }
 
-OString ThemeColorPaletteManager::generateJSON()
+void ThemeColorPaletteManager::generateJSON(boost::property_tree::ptree& aTree)
 {
     svx::ThemePaletteCollection aThemePaletteCollection = generate();
 
-    boost::property_tree::ptree aTree;
     boost::property_tree::ptree aColorListTree;
 
     for (size_t nEffect = 0; nEffect < 6; ++nEffect)
@@ -160,11 +158,6 @@ OString ThemeColorPaletteManager::generateJSON()
     }
 
     aTree.add_child("ThemeColors", aColorListTree);
-
-    std::stringstream aStream;
-    boost::property_tree::write_json(aStream, aTree);
-
-    return OString(aStream.str());
 }
 
 } // end svx namespace
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index d21738670d8b..8edd299342d3 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1218,7 +1218,9 @@ void SwView::afterCallbackRegistered()
     auto* pDocShell = GetDocShell();
     if (pDocShell)
     {
-        svx::theme::notifyLOK(pDocShell->GetThemeColors());
+        std::shared_ptr<model::ColorSet> pThemeColors = 
pDocShell->GetThemeColors();
+        std::set<Color> aDocumentColors = pDocShell->GetDocColors();
+        svx::theme::notifyLOK(pThemeColors, aDocumentColors);
     }
 }
 

Reply via email to