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 0460be8848b0ce02c07183e41dd7137ac3b94164
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Mon Jan 8 18:46:13 2024 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Jan 10 10:19:09 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>

diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx
index 5a5000bc0076..9e089b0ed495 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; }
@@ -85,6 +86,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 f40fb639878d..3050d4444a0c 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/svdpage.hxx>
@@ -23,7 +24,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 116283f48bea..9bf1598516c8 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -479,7 +479,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 06c69d31c965..4eb5a66958d2 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -1023,7 +1023,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 2480d8ab2cfa..a807b6516789 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -51,7 +51,6 @@
 #include <memory>
 #include <array>
 #include <stack>
-#include <set>
 
 PaletteManager::PaletteManager() :
     
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
@@ -464,4 +463,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();
+
+    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;
+            std::u16string_view aNamePrefix = 
Concat2View(SvxResId(RID_SVXSTR_DOC_COLOR_PREFIX) + " ");
+            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 f5f660b657a4..cb4eccd01a25 100644
--- a/svx/source/theme/ThemeColorChangerCommon.cxx
+++ b/svx/source/theme/ThemeColorChangerCommon.cxx
@@ -29,6 +29,7 @@
 
 #include <sfx2/lokhelper.hxx>
 
+#include <svx/PaletteManager.hxx>
 #include <svx/svdmodel.hxx>
 #include <svx/svdotext.hxx>
 #include <svx/svdundo.hxx>
@@ -178,12 +179,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 0e4f20899645..a89456576736 100644
--- a/svx/source/theme/ThemeColorPaletteManager.cxx
+++ b/svx/source/theme/ThemeColorPaletteManager.cxx
@@ -16,7 +16,6 @@
 #include <svx/strings.hrc>
 #include <docmodel/theme/ColorSet.hxx>
 #include <docmodel/color/ComplexColorJSON.hxx>
-#include <boost/property_tree/json_parser.hpp>
 
 #include <array>
 
@@ -127,11 +126,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)
@@ -161,11 +159,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 c5bc51ea4ce1..b527e5077f2d 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1195,7 +1195,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