diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2024-01-08 18:46:13 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-01-10 10:19:09 +0100 |
commit | 0460be8848b0ce02c07183e41dd7137ac3b94164 (patch) | |
tree | 5b0dec82cc9c9ff22dfe163464a6acb23394a461 /svx | |
parent | 606537da38eca6077a0c6ec7d82ca31c92b7e3a6 (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>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 36 | ||||
-rw-r--r-- | svx/source/theme/ThemeColorChangerCommon.cxx | 16 | ||||
-rw-r--r-- | svx/source/theme/ThemeColorPaletteManager.cxx | 9 |
3 files changed, 50 insertions, 11 deletions
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 |