send theme info when changing color (in the picker) via UNO command
Change-Id: I288f8fb3375e152b5ee746fab2c05d08150d6c99 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146817 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
committed by
Tomaž Vajngerl
parent
79434c3215
commit
855f7c08d1
@@ -14,6 +14,7 @@ $(eval $(call gb_Library_add_exception_objects,docmodel,\
|
|||||||
docmodel/source/uno/UnoTheme \
|
docmodel/source/uno/UnoTheme \
|
||||||
docmodel/source/theme/ColorSet \
|
docmodel/source/theme/ColorSet \
|
||||||
docmodel/source/theme/Theme \
|
docmodel/source/theme/Theme \
|
||||||
|
docmodel/source/theme/ThemeColorJSON \
|
||||||
))
|
))
|
||||||
|
|
||||||
$(eval $(call gb_Library_set_include,docmodel,\
|
$(eval $(call gb_Library_set_include,docmodel,\
|
||||||
@@ -22,7 +23,8 @@ $(eval $(call gb_Library_set_include,docmodel,\
|
|||||||
))
|
))
|
||||||
|
|
||||||
$(eval $(call gb_Library_use_externals,docmodel,\
|
$(eval $(call gb_Library_use_externals,docmodel,\
|
||||||
libxml2 \
|
libxml2 \
|
||||||
|
boost_headers \
|
||||||
))
|
))
|
||||||
|
|
||||||
$(eval $(call gb_Library_add_defs,docmodel,\
|
$(eval $(call gb_Library_add_defs,docmodel,\
|
||||||
|
103
docmodel/source/theme/ThemeColorJSON.cxx
Normal file
103
docmodel/source/theme/ThemeColorJSON.cxx
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <docmodel/theme/ThemeColorJSON.hxx>
|
||||||
|
#include <sstream>
|
||||||
|
#include <utility>
|
||||||
|
#include <sal/log.hxx>
|
||||||
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
|
|
||||||
|
namespace model::theme
|
||||||
|
{
|
||||||
|
bool convertFromJSON(OString const& rJsonString, model::ThemeColor& rThemeColor)
|
||||||
|
{
|
||||||
|
model::ThemeColor aThemeColor;
|
||||||
|
std::stringstream aStream(rJsonString.getStr());
|
||||||
|
boost::property_tree::ptree aRootTree;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boost::property_tree::read_json(aStream, aRootTree);
|
||||||
|
}
|
||||||
|
catch (const boost::property_tree::json_parser_error& /*exception*/)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1);
|
||||||
|
aThemeColor.setType(model::convertToThemeColorType(nThemeType));
|
||||||
|
boost::property_tree::ptree aTransformTree = aRootTree.get_child("Transformations");
|
||||||
|
for (const auto& rEachTransformationNode :
|
||||||
|
boost::make_iterator_range(aTransformTree.equal_range("")))
|
||||||
|
{
|
||||||
|
auto const& rTransformationTree = rEachTransformationNode.second;
|
||||||
|
std::string sType = rTransformationTree.get<std::string>("Type", "");
|
||||||
|
sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0);
|
||||||
|
|
||||||
|
auto eType = model::TransformationType::Undefined;
|
||||||
|
if (sType == "LumOff")
|
||||||
|
eType = model::TransformationType::LumOff;
|
||||||
|
else if (sType == "LumMod")
|
||||||
|
eType = model::TransformationType::LumMod;
|
||||||
|
else if (sType == "Tint")
|
||||||
|
eType = model::TransformationType::Tint;
|
||||||
|
else if (sType == "Shade")
|
||||||
|
eType = model::TransformationType::Shade;
|
||||||
|
|
||||||
|
if (eType != model::TransformationType::Undefined)
|
||||||
|
aThemeColor.addTransformation({ eType, nValue });
|
||||||
|
}
|
||||||
|
rThemeColor = aThemeColor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
OString convertToJSON(model::ThemeColor const& rThemeColor)
|
||||||
|
{
|
||||||
|
boost::property_tree::ptree aTree;
|
||||||
|
aTree.put("ThemeIndex", sal_Int16(rThemeColor.getType()));
|
||||||
|
|
||||||
|
boost::property_tree::ptree aTransformationsList;
|
||||||
|
for (auto const& rTransformation : rThemeColor.getTransformations())
|
||||||
|
{
|
||||||
|
std::string aType;
|
||||||
|
switch (rTransformation.meType)
|
||||||
|
{
|
||||||
|
case model::TransformationType::LumMod:
|
||||||
|
aType = "LumMod";
|
||||||
|
break;
|
||||||
|
case model::TransformationType::LumOff:
|
||||||
|
aType = "LumOff";
|
||||||
|
break;
|
||||||
|
case model::TransformationType::Tint:
|
||||||
|
aType = "Tint";
|
||||||
|
break;
|
||||||
|
case model::TransformationType::Shade:
|
||||||
|
aType = "Shade";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!aType.empty())
|
||||||
|
{
|
||||||
|
boost::property_tree::ptree aChild;
|
||||||
|
aChild.put("Type", aType);
|
||||||
|
aChild.put("Value", rTransformation.mnValue);
|
||||||
|
aTransformationsList.push_back(std::make_pair("", aChild));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aTree.add_child("Transformations", aTransformationsList);
|
||||||
|
std::stringstream aStream;
|
||||||
|
boost::property_tree::write_json(aStream, aTree);
|
||||||
|
|
||||||
|
return OString(aStream.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end model::theme
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -78,6 +78,7 @@
|
|||||||
#include <editeng/itemtype.hxx>
|
#include <editeng/itemtype.hxx>
|
||||||
#include <editeng/eerdll.hxx>
|
#include <editeng/eerdll.hxx>
|
||||||
#include <docmodel/uno/UnoThemeColor.hxx>
|
#include <docmodel/uno/UnoThemeColor.hxx>
|
||||||
|
#include <docmodel/theme/ThemeColorJSON.hxx>
|
||||||
#include <libxml/xmlwriter.h>
|
#include <libxml/xmlwriter.h>
|
||||||
|
|
||||||
using namespace ::com::sun::star;
|
using namespace ::com::sun::star;
|
||||||
@@ -1367,6 +1368,13 @@ SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SvxColorItem::SvxColorItem(Color const& rColor, model::ThemeColor const& rThemeColor, const sal_uInt16 nId)
|
||||||
|
: SfxPoolItem(nId)
|
||||||
|
, mColor(rColor)
|
||||||
|
, maThemeColor(rThemeColor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SvxColorItem::~SvxColorItem()
|
SvxColorItem::~SvxColorItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1436,12 +1444,18 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
|
|||||||
rVal <<= nValue;
|
rVal <<= nValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MID_COLOR_THEME_REFERENCE:
|
case MID_COLOR_THEME_REFERENCE:
|
||||||
{
|
{
|
||||||
auto xThemeColor = model::theme::createXThemeColor(maThemeColor);
|
auto xThemeColor = model::theme::createXThemeColor(maThemeColor);
|
||||||
rVal <<= xThemeColor;
|
rVal <<= xThemeColor;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MID_COLOR_THEME_REFERENCE_JSON:
|
||||||
|
{
|
||||||
|
rVal <<= OStringToOUString(model::theme::convertToJSON(maThemeColor), RTL_TEXTENCODING_UTF8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MID_COLOR_RGB:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
rVal <<= mColor;
|
rVal <<= mColor;
|
||||||
@@ -1528,6 +1542,23 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MID_COLOR_THEME_REFERENCE_JSON:
|
||||||
|
{
|
||||||
|
OUString sThemeJson;
|
||||||
|
if (!(rVal >>= sThemeJson))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (sThemeJson.isEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
OString aJSON = OUStringToOString(sThemeJson, RTL_TEXTENCODING_ASCII_US);
|
||||||
|
model::theme::convertFromJSON(aJSON, maThemeColor);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MID_COLOR_RGB:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return rVal >>= mColor;
|
return rVal >>= mColor;
|
||||||
|
23
include/docmodel/theme/ThemeColorJSON.hxx
Normal file
23
include/docmodel/theme/ThemeColorJSON.hxx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <docmodel/dllapi.h>
|
||||||
|
#include <docmodel/theme/ThemeColor.hxx>
|
||||||
|
|
||||||
|
namespace model::theme
|
||||||
|
{
|
||||||
|
DOCMODEL_DLLPUBLIC OString convertToJSON(model::ThemeColor const& rThemeColor);
|
||||||
|
DOCMODEL_DLLPUBLIC bool convertFromJSON(OString const& rJsonString, model::ThemeColor& rThemeColor);
|
||||||
|
|
||||||
|
} // end of namespace model
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
explicit SvxColorItem(const sal_uInt16 nId);
|
explicit SvxColorItem(const sal_uInt16 nId);
|
||||||
SvxColorItem(const Color& aColor, const sal_uInt16 nId);
|
SvxColorItem(const Color& aColor, const sal_uInt16 nId);
|
||||||
|
SvxColorItem(const Color& aColor, model::ThemeColor const& rThemeColor, const sal_uInt16 nId);
|
||||||
virtual ~SvxColorItem() override;
|
virtual ~SvxColorItem() override;
|
||||||
|
|
||||||
// "pure virtual Methods" from SfxPoolItem
|
// "pure virtual Methods" from SfxPoolItem
|
||||||
@@ -63,6 +64,11 @@ public:
|
|||||||
|
|
||||||
const model::ThemeColor& GetThemeColor() const { return maThemeColor; }
|
const model::ThemeColor& GetThemeColor() const { return maThemeColor; }
|
||||||
|
|
||||||
|
void setThemeColor(model::ThemeColor const& rThemeColor)
|
||||||
|
{
|
||||||
|
maThemeColor = rThemeColor;
|
||||||
|
}
|
||||||
|
|
||||||
void dumpAsXml(xmlTextWriterPtr pWriter) const override;
|
void dumpAsXml(xmlTextWriterPtr pWriter) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -189,6 +189,7 @@
|
|||||||
#define MID_COLOR_LUM_MOD 6
|
#define MID_COLOR_LUM_MOD 6
|
||||||
#define MID_COLOR_LUM_OFF 7
|
#define MID_COLOR_LUM_OFF 7
|
||||||
#define MID_COLOR_THEME_REFERENCE 8
|
#define MID_COLOR_THEME_REFERENCE 8
|
||||||
|
#define MID_COLOR_THEME_REFERENCE_JSON 9
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -449,9 +449,10 @@ class XFillGradientItem;
|
|||||||
#define SID_ATTR_TEXTCOLUMNS_NUMBER ( SID_SVX_START + 340 )
|
#define SID_ATTR_TEXTCOLUMNS_NUMBER ( SID_SVX_START + 340 )
|
||||||
#define SID_ATTR_TEXTCOLUMNS_SPACING ( SID_SVX_START + 341 )
|
#define SID_ATTR_TEXTCOLUMNS_SPACING ( SID_SVX_START + 341 )
|
||||||
|
|
||||||
#define SID_ATTR_COLOR_THEME_INDEX TypedWhichId<SfxInt16Item>( SID_SVX_START + 342 )
|
#define SID_ATTR_COLOR_THEME_REFERENCE TypedWhichId<SvxColorItem>( SID_SVX_START + 342 )
|
||||||
#define SID_ATTR_COLOR_LUM_MOD TypedWhichId<SfxInt16Item>( SID_SVX_START + 343 )
|
#define SID_ATTR_COLOR_THEME_INDEX TypedWhichId<SfxInt16Item>( SID_SVX_START + 343 )
|
||||||
#define SID_ATTR_COLOR_LUM_OFF TypedWhichId<SfxInt16Item>( SID_SVX_START + 344 )
|
#define SID_ATTR_COLOR_LUM_MOD TypedWhichId<SfxInt16Item>( SID_SVX_START + 344 )
|
||||||
|
#define SID_ATTR_COLOR_LUM_OFF TypedWhichId<SfxInt16Item>( SID_SVX_START + 345 )
|
||||||
|
|
||||||
#define SID_SB_CONNECTIONPOOLING ( SID_SVX_START + 348 )
|
#define SID_SB_CONNECTIONPOOLING ( SID_SVX_START + 348 )
|
||||||
#define SID_SB_DBREGISTEROPTIONS ( SID_SVX_START + 349 )
|
#define SID_SB_DBREGISTEROPTIONS ( SID_SVX_START + 349 )
|
||||||
@@ -683,7 +684,6 @@ class XFillGradientItem;
|
|||||||
#define SID_PARAGRAPH_CHANGE_STATE ( SID_SVX_START + 754 )
|
#define SID_PARAGRAPH_CHANGE_STATE ( SID_SVX_START + 754 )
|
||||||
|
|
||||||
#define SID_ATTR_SHADOW_BLUR ( SID_SVX_START + 755 )
|
#define SID_ATTR_SHADOW_BLUR ( SID_SVX_START + 755 )
|
||||||
|
|
||||||
//FREE
|
//FREE
|
||||||
//FREE
|
//FREE
|
||||||
//FREE
|
//FREE
|
||||||
|
@@ -169,7 +169,14 @@ item INT16 SvxParaVertAlignItem;
|
|||||||
item INT16 SvxCharReliefItem;
|
item INT16 SvxCharReliefItem;
|
||||||
item BOOL SvxBlinkItem;
|
item BOOL SvxBlinkItem;
|
||||||
item BOOL SvxAutoKernItem;
|
item BOOL SvxAutoKernItem;
|
||||||
item INT32 SvxColorItem;
|
|
||||||
|
struct SvxColor
|
||||||
|
{
|
||||||
|
INT32 Color MID_COLOR_RGB;
|
||||||
|
String ThemeReferenceJSON MID_COLOR_THEME_REFERENCE_JSON;
|
||||||
|
};
|
||||||
|
item SvxColor SvxColorItem;
|
||||||
|
|
||||||
item BOOL SvxContourItem;
|
item BOOL SvxContourItem;
|
||||||
item INT16 SvxFormatBreakItem; // enum
|
item INT16 SvxFormatBreakItem; // enum
|
||||||
item BOOL SvxFormatKeepItem;
|
item BOOL SvxFormatKeepItem;
|
||||||
|
@@ -41,6 +41,11 @@
|
|||||||
#include <com/sun/star/frame/Desktop.hpp>
|
#include <com/sun/star/frame/Desktop.hpp>
|
||||||
#include <com/sun/star/util/XURLTransformer.hpp>
|
#include <com/sun/star/util/XURLTransformer.hpp>
|
||||||
#include <com/sun/star/util/URLTransformer.hpp>
|
#include <com/sun/star/util/URLTransformer.hpp>
|
||||||
|
#include <docmodel/theme/ThemeColor.hxx>
|
||||||
|
#include <docmodel/theme/ThemeColorJSON.hxx>
|
||||||
|
#include <editeng/colritem.hxx>
|
||||||
|
#include <svx/svxids.hrc>
|
||||||
|
#include <editeng/memberids.h>
|
||||||
|
|
||||||
#include <palettes.hxx>
|
#include <palettes.hxx>
|
||||||
|
|
||||||
@@ -420,6 +425,7 @@ void PaletteManager::PopupColorPicker(weld::Window* pParent, const OUString& aCo
|
|||||||
|
|
||||||
void PaletteManager::DispatchColorCommand(const OUString& aCommand, const svx::NamedThemedColor& rColor)
|
void PaletteManager::DispatchColorCommand(const OUString& aCommand, const svx::NamedThemedColor& rColor)
|
||||||
{
|
{
|
||||||
|
using namespace css;
|
||||||
using namespace css::uno;
|
using namespace css::uno;
|
||||||
using namespace css::frame;
|
using namespace css::frame;
|
||||||
using namespace css::beans;
|
using namespace css::beans;
|
||||||
@@ -435,13 +441,22 @@ void PaletteManager::DispatchColorCommand(const OUString& aCommand, const svx::N
|
|||||||
INetURLObject aObj( aCommand );
|
INetURLObject aObj( aCommand );
|
||||||
|
|
||||||
std::vector<PropertyValue> aArgs{
|
std::vector<PropertyValue> aArgs{
|
||||||
comphelper::makePropertyValue(aObj.GetURLPath(), sal_Int32(rColor.m_aColor)),
|
comphelper::makePropertyValue(aObj.GetURLPath()+ ".Color", sal_Int32(rColor.m_aColor)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (rColor.m_nThemeIndex != -1)
|
if (rColor.m_nThemeIndex != -1)
|
||||||
{
|
{
|
||||||
aArgs.push_back(comphelper::makePropertyValue("ColorThemeIndex", rColor.m_nThemeIndex));
|
model::ThemeColor aThemeColor;
|
||||||
aArgs.push_back(comphelper::makePropertyValue("ColorLumMod", rColor.m_nLumMod));
|
aThemeColor.setType(model::convertToThemeColorType(rColor.m_nThemeIndex));
|
||||||
aArgs.push_back(comphelper::makePropertyValue("ColorLumOff", rColor.m_nLumOff));
|
if (rColor.m_nLumMod != 10000)
|
||||||
|
aThemeColor.addTransformation({model::TransformationType::LumMod, rColor.m_nLumMod});
|
||||||
|
if (rColor.m_nLumMod != 0)
|
||||||
|
aThemeColor.addTransformation({model::TransformationType::LumOff, rColor.m_nLumOff});
|
||||||
|
|
||||||
|
uno::Any aAny;
|
||||||
|
aAny <<= OStringToOUString(model::theme::convertToJSON(aThemeColor), RTL_TEXTENCODING_UTF8);
|
||||||
|
|
||||||
|
aArgs.push_back(comphelper::makePropertyValue(aObj.GetURLPath() + ".ThemeReferenceJSON", aAny));
|
||||||
}
|
}
|
||||||
|
|
||||||
URL aTargetURL;
|
URL aTargetURL;
|
||||||
|
@@ -1672,26 +1672,18 @@ void SwTextShell::Execute(SfxRequest &rReq)
|
|||||||
|
|
||||||
case SID_ATTR_CHAR_COLOR2:
|
case SID_ATTR_CHAR_COLOR2:
|
||||||
{
|
{
|
||||||
Color aSet;
|
if (pItem)
|
||||||
bool bHasItem = false;
|
|
||||||
|
|
||||||
if(pItem)
|
|
||||||
{
|
|
||||||
aSet = static_cast<const SvxColorItem*>(pItem)->GetValue();
|
|
||||||
bHasItem = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bHasItem)
|
|
||||||
{
|
{
|
||||||
|
auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||||
SwEditWin& rEditWin = GetView().GetEditWin();
|
SwEditWin& rEditWin = GetView().GetEditWin();
|
||||||
rEditWin.SetWaterCanTextColor(aSet);
|
rEditWin.SetWaterCanTextColor(pColorItem->GetValue());
|
||||||
SwApplyTemplate* pApply = rEditWin.GetApplyTemplate();
|
SwApplyTemplate* pApply = rEditWin.GetApplyTemplate();
|
||||||
|
|
||||||
// If there is a selection, then set the color on it
|
// If there is a selection, then set the color on it
|
||||||
// otherwise, it'll be the color for the next text to be typed
|
// otherwise, it'll be the color for the next text to be typed
|
||||||
if(!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
|
if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
|
||||||
{
|
{
|
||||||
rWrtSh.SetAttrItem(SvxColorItem (aSet, RES_CHRATR_COLOR));
|
rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), pColorItem->GetThemeColor(), RES_CHRATR_COLOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
rReq.Done();
|
rReq.Done();
|
||||||
|
Reference in New Issue
Block a user