cui/source/tabpages/chardlg.cxx | 6 +-- editeng/source/items/textitem.cxx | 65 +++++++++++++++++++++++--------------- editeng/source/uno/unotext.cxx | 6 +-- include/editeng/colritem.hxx | 58 +++++++++++++++++++++------------ include/svx/xcolit.hxx | 8 ++++ sd/source/ui/view/drtxtob1.cxx | 6 +-- svx/source/xoutdev/xattr.cxx | 16 +++++++-- 7 files changed, 107 insertions(+), 58 deletions(-)
New commits: commit 8cc70d18c4507a746607fe5922b7c5e94b7f7579 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Feb 16 20:02:01 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Feb 17 08:23:15 2022 +0100 sd theme: add doc model for shape fill color In preparation of adding UNO API for this. Change-Id: Iecb2e44c43bca9e892fcb6242870ec12faa48be5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130050 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx index c3f5984e6ea4..1d2fed77c86e 100644 --- a/cui/source/tabpages/chardlg.cxx +++ b/cui/source/tabpages/chardlg.cxx @@ -1600,9 +1600,9 @@ bool SvxCharEffectsPage::FillItemSetColor_Impl( SfxItemSet& rSet ) if (aSelectedColor.m_nThemeIndex != -1) { // The color was picked from the theme palette, remember its index. - aItem.SetThemeIndex(aSelectedColor.m_nThemeIndex); - aItem.SetLumMod(aSelectedColor.m_nLumMod); - aItem.SetLumOff(aSelectedColor.m_nLumOff); + aItem.GetThemeColor().SetThemeIndex(aSelectedColor.m_nThemeIndex); + aItem.GetThemeColor().SetLumMod(aSelectedColor.m_nLumMod); + aItem.GetThemeColor().SetLumOff(aSelectedColor.m_nLumOff); } rSet.Put(aItem); diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index 2c787d34b171..72b982b73ff9 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -1352,24 +1352,46 @@ bool SvxContourItem::GetPresentation return true; } +SvxThemeColor::SvxThemeColor() + : maThemeIndex(-1), + mnLumMod(10000), + mnLumOff(0) +{ +} + +bool SvxThemeColor::operator==(const SvxThemeColor& rThemeColor) const +{ + return maThemeIndex == rThemeColor.maThemeIndex && + mnLumMod == rThemeColor.mnLumMod && + mnLumOff == rThemeColor.mnLumOff; +} + +void SvxThemeColor::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxThemeColor")); + + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("theme-index"), + BAD_CAST(OString::number(maThemeIndex).getStr())); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("lum-mod"), + BAD_CAST(OString::number(mnLumMod).getStr())); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("lum-off"), + BAD_CAST(OString::number(mnLumOff).getStr())); + + (void)xmlTextWriterEndElement(pWriter); +} + // class SvxColorItem ---------------------------------------------------- SvxColorItem::SvxColorItem( const sal_uInt16 nId ) : SfxPoolItem(nId), mColor( COL_BLACK ), - maThemeIndex(-1), - maTintShade(0), - mnLumMod(10000), - mnLumOff(0) + maTintShade(0) { } SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) : SfxPoolItem( nId ), mColor( rCol ), - maThemeIndex(-1), - maTintShade(0), - mnLumMod(10000), - mnLumOff(0) + maTintShade(0) { } @@ -1383,10 +1405,8 @@ bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const const SvxColorItem& rColorItem = static_cast<const SvxColorItem&>(rAttr); return mColor == rColorItem.mColor && - maThemeIndex == rColorItem.maThemeIndex && - maTintShade == rColorItem.maTintShade && - mnLumMod == rColorItem.mnLumMod && - mnLumOff == rColorItem.mnLumOff; + maThemeColor == rColorItem.maThemeColor && + maTintShade == rColorItem.maTintShade; } bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const @@ -1407,7 +1427,7 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const } case MID_COLOR_THEME_INDEX: { - rVal <<= maThemeIndex; + rVal <<= maThemeColor.GetThemeIndex(); break; } case MID_COLOR_TINT_OR_SHADE: @@ -1417,12 +1437,12 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const } case MID_COLOR_LUM_MOD: { - rVal <<= mnLumMod; + rVal <<= maThemeColor.GetLumMod(); break; } case MID_COLOR_LUM_OFF: { - rVal <<= mnLumOff; + rVal <<= maThemeColor.GetLumOff(); break; } default: @@ -1460,7 +1480,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nIndex = -1; if (!(rVal >>= nIndex)) return false; - maThemeIndex = nIndex; + maThemeColor.SetThemeIndex(nIndex); } break; case MID_COLOR_TINT_OR_SHADE: @@ -1476,7 +1496,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nLumMod = -1; if (!(rVal >>= nLumMod)) return false; - mnLumMod = nLumMod; + maThemeColor.SetLumMod(nLumMod); } break; case MID_COLOR_LUM_OFF: @@ -1484,7 +1504,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nLumOff = -1; if (!(rVal >>= nLumOff)) return false; - mnLumOff = nLumOff; + maThemeColor.SetLumOff(nLumOff); } break; default: @@ -1521,17 +1541,14 @@ void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const std::stringstream ss; ss << mColor; (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str())); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("theme-index"), - BAD_CAST(OString::number(maThemeIndex).getStr())); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("lum-mod"), - BAD_CAST(OString::number(mnLumMod).getStr())); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("lum-off"), - BAD_CAST(OString::number(mnLumOff).getStr())); OUString aStr; IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag()); GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, aStr, aIntlWrapper); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8).getStr())); + + maThemeColor.dumpAsXml(pWriter); + (void)xmlTextWriterEndElement(pWriter); } diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index b8ad3d09e9ed..81549327bf24 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -1141,19 +1141,19 @@ bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const Sf switch (pMap->nMemberId) { case MID_COLOR_THEME_INDEX: - if (pColor->GetThemeIndex() == -1) + if (pColor->GetThemeColor().GetThemeIndex() == -1) { eItemState = SfxItemState::DEFAULT; } break; case MID_COLOR_LUM_MOD: - if (pColor->GetLumMod() == 10000) + if (pColor->GetThemeColor().GetLumMod() == 10000) { eItemState = SfxItemState::DEFAULT; } break; case MID_COLOR_LUM_OFF: - if (pColor->GetLumOff() == 0) + if (pColor->GetThemeColor().GetLumOff() == 0) { eItemState = SfxItemState::DEFAULT; } diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx index 21e389115b11..cbd52844b059 100644 --- a/include/editeng/colritem.hxx +++ b/include/editeng/colritem.hxx @@ -25,18 +25,48 @@ #define VERSION_USEAUTOCOLOR 1 +/// Represents theme metadata for a (tools) Color. +class EDITENG_DLLPUBLIC SvxThemeColor +{ + sal_Int16 maThemeIndex; + /// Luminance Modulation: 100th percentage, defaults to 100%. + sal_Int16 mnLumMod; + /// Luminance Offset: 100th percentage, defaults to 0%. + sal_Int16 mnLumOff; + +public: + explicit SvxThemeColor(); + bool operator==(const SvxThemeColor& rThemeColor) const; + + sal_Int16 GetThemeIndex() const + { + return maThemeIndex; + } + + void SetThemeIndex(sal_Int16 nIndex) + { + maThemeIndex = nIndex; + } + + void SetLumMod(sal_Int16 nLumMod) { mnLumMod = nLumMod; } + + sal_Int16 GetLumMod() const { return mnLumMod; } + + void SetLumOff(sal_Int16 nLumOff) { mnLumOff = nLumOff; } + + sal_Int16 GetLumOff() const { return mnLumOff; } + + void dumpAsXml(xmlTextWriterPtr pWriter) const; +}; + /** SvxColorItem item describes a color. */ class EDITENG_DLLPUBLIC SvxColorItem final : public SfxPoolItem { private: Color mColor; - sal_Int16 maThemeIndex; + SvxThemeColor maThemeColor; sal_Int16 maTintShade; - /// Luminance Modulation: 100th percentage, defaults to 100%. - sal_Int16 mnLumMod; - /// Luminance Offset: 100th percentage, defaults to 0%. - sal_Int16 mnLumOff; public: static SfxPoolItem* CreateDefault(); @@ -63,16 +93,6 @@ public: } void SetValue(const Color& rNewColor); - sal_Int16 GetThemeIndex() const - { - return maThemeIndex; - } - - void SetThemeIndex(sal_Int16 nIndex) - { - maThemeIndex = nIndex; - } - sal_Int16 GetTintOrShade() const { return maTintShade; @@ -83,13 +103,9 @@ public: maTintShade = nTintOrShade; } - void SetLumMod(sal_Int16 nLumMod) { mnLumMod = nLumMod; } - - sal_Int16 GetLumMod() const { return mnLumMod; } + SvxThemeColor& GetThemeColor() { return maThemeColor; } - void SetLumOff(sal_Int16 nLumOff) { mnLumOff = nLumOff; } - - sal_Int16 GetLumOff() const { return mnLumOff; } + const SvxThemeColor& GetThemeColor() const { return maThemeColor; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; diff --git a/include/svx/xcolit.hxx b/include/svx/xcolit.hxx index 8760ba88208e..5b882f9a97a9 100644 --- a/include/svx/xcolit.hxx +++ b/include/svx/xcolit.hxx @@ -21,8 +21,9 @@ #define INCLUDED_SVX_XCOLIT_HXX #include <tools/color.hxx> -#include <svx/svxdllapi.h> +#include <editeng/colritem.hxx> +#include <svx/svxdllapi.h> #include <svx/xit.hxx> class XColorList; @@ -32,6 +33,7 @@ class XColorList; class SVXCORE_DLLPUBLIC XColorItem : public NameOrIndex { Color aColor; + SvxThemeColor maThemeColor; public: static SfxPoolItem* CreateDefault(); @@ -48,6 +50,10 @@ public: const Color& GetColorValue() const; void SetColorValue(const Color& rNew) { aColor = rNew; Detach(); } + + SvxThemeColor& GetThemeColor() { return maThemeColor; } + const SvxThemeColor& GetThemeColor() const { return maThemeColor; } + virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; diff --git a/sd/source/ui/view/drtxtob1.cxx b/sd/source/ui/view/drtxtob1.cxx index fa1f160df964..6aa73bce3301 100644 --- a/sd/source/ui/view/drtxtob1.cxx +++ b/sd/source/ui/view/drtxtob1.cxx @@ -827,17 +827,17 @@ void TextObjectBar::Execute( SfxRequest &rReq ) if (pArgs->GetItemState(SID_ATTR_COLOR_THEME_INDEX, false, &pItem) == SfxItemState::SET) { auto pIntItem = static_cast<const SfxInt16Item*>(pItem); - pColorItem->SetThemeIndex(pIntItem->GetValue()); + pColorItem->GetThemeColor().SetThemeIndex(pIntItem->GetValue()); } if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_MOD, false, &pItem) == SfxItemState::SET) { auto pIntItem = static_cast<const SfxInt16Item*>(pItem); - pColorItem->SetLumMod(pIntItem->GetValue()); + pColorItem->GetThemeColor().SetLumMod(pIntItem->GetValue()); } if (pArgs->GetItemState(SID_ATTR_COLOR_LUM_OFF, false, &pItem) == SfxItemState::SET) { auto pIntItem = static_cast<const SfxInt16Item*>(pItem); - pColorItem->SetLumOff(pIntItem->GetValue()); + pColorItem->GetThemeColor().SetLumOff(pIntItem->GetValue()); } if (pColorItem) { diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx index 0539e19664e7..81d10a97061c 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -279,7 +279,8 @@ XColorItem::XColorItem(TypedWhichId<XColorItem> _nWhich, const Color& rTheColor) XColorItem::XColorItem(const XColorItem& rItem) : NameOrIndex(rItem), - aColor(rItem.aColor) + aColor(rItem.aColor), + maThemeColor(rItem.maThemeColor) { } @@ -291,7 +292,8 @@ XColorItem* XColorItem::Clone(SfxItemPool* /*pPool*/) const bool XColorItem::operator==(const SfxPoolItem& rItem) const { return ( NameOrIndex::operator==(rItem) && - static_cast<const XColorItem&>(rItem).aColor == aColor ); + static_cast<const XColorItem&>(rItem).aColor == aColor ) && + static_cast<const XColorItem&>(rItem).maThemeColor == maThemeColor; } const Color& XColorItem::GetColorValue() const @@ -323,11 +325,17 @@ void XColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST("SDRATTR_SHADOWCOLOR")); } + else if (Which() == XATTR_FILLCOLOR) + { + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST("XATTR_FILLCOLOR")); + } (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("aColor"), BAD_CAST(aColor.AsRGBHexString().toUtf8().getStr())); NameOrIndex::dumpAsXml(pWriter); + maThemeColor.dumpAsXml(pWriter); + (void)xmlTextWriterEndElement(pWriter); } @@ -1913,7 +1921,9 @@ void XFillColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("XFillColorItem")); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetColorValue().AsRGBHexString().toUtf8().getStr())); + + XColorItem::dumpAsXml(pWriter); + (void)xmlTextWriterEndElement(pWriter); }