summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2024-01-08 18:46:13 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2024-01-15 21:07:28 +0100
commit88281b55c1d781f73a663188229c639a290c53bc (patch)
tree7eef013c082d295bc950c98d2b147a9307f4f1df
parent035cd913e0361cce9d799eb3b331b6d7bcf7910e (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@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.klos@collabora.com>
-rw-r--r--include/svx/PaletteManager.hxx4
-rw-r--r--include/svx/theme/IThemeColorChanger.hxx2
-rw-r--r--include/svx/theme/ThemeColorChangerCommon.hxx5
-rw-r--r--include/svx/theme/ThemeColorPaletteManager.hxx3
-rw-r--r--sc/source/ui/view/tabvwshc.cxx4
-rw-r--r--sd/source/ui/view/ViewShellBase.cxx4
-rw-r--r--svx/source/tbxctrls/PaletteManager.cxx36
-rw-r--r--svx/source/theme/ThemeColorChangerCommon.cxx16
-rw-r--r--svx/source/theme/ThemeColorPaletteManager.cxx9
-rw-r--r--sw/source/uibase/uiview/view.cxx4
10 files changed, 70 insertions, 17 deletions
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 3cde75058033..13d852f58630 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 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 a98149ff30bb..c9330eec408f 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -50,7 +50,6 @@
#include <memory>
#include <array>
#include <stack>
-#include <set>
PaletteManager::PaletteManager() :
mnMaxRecentColors(Application::GetSettings().GetStyleSettings().GetColorValueSetColumnCount()),
@@ -469,4 +468,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 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 0474824e69eb..8583fc004a5a 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);
}
}