summaryrefslogtreecommitdiff
path: root/svx
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 /svx
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>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/tbxctrls/PaletteManager.cxx36
-rw-r--r--svx/source/theme/ThemeColorChangerCommon.cxx16
-rw-r--r--svx/source/theme/ThemeColorPaletteManager.cxx9
3 files changed, 50 insertions, 11 deletions
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