editeng/source/items/textitem.cxx | 70 ++++++++++++-- include/editeng/colritem.hxx | 48 +++++---- include/sfx2/ColorSets.hxx | 91 ++++++++++++++++++ include/sfx2/sfxsids.hrc | 2 include/svx/ColorSets.hxx | 71 -------------- sfx2/Library_sfx.mk | 1 sfx2/source/doc/objxtor.cxx | 4 sfx2/source/styles/ColorSets.cxx | 155 ++++++++++++++++++++++++++++++++ sfx2/source/view/viewfrm.cxx | 3 svx/Library_svxcore.mk | 1 svx/source/styles/ColorSets.cxx | 107 ---------------------- sw/source/uibase/sidebar/ThemePanel.cxx | 54 ++++++----- sw/source/uibase/sidebar/ThemePanel.hxx | 4 13 files changed, 377 insertions(+), 234 deletions(-)
New commits: commit 58b52969f02f26e6b91bfa2527e201d3883a5cae Author: Sarper Akdemir <sarper.akde...@collabora.com> AuthorDate: Wed Jul 28 02:03:12 2021 +0300 Commit: Sarper Akdemir <sarper.akde...@collabora.com> CommitDate: Wed Aug 18 01:19:54 2021 +0300 make colorsets work outside of styles and with direct formatting Change-Id: Id3cb073d4567f4dbc70a52bc08403751f4c8ddd4 diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index ac87db3a2573..ede250142444 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -78,6 +78,9 @@ #include <editeng/eerdll.hxx> #include <libxml/xmlwriter.h> +#include <sfx2/sfxsids.hrc> +#include <sfx2/objsh.hxx> + using namespace ::com::sun::star; using namespace ::com::sun::star::text; @@ -1313,17 +1316,23 @@ bool SvxContourItem::GetPresentation SvxColorItem::SvxColorItem( const sal_uInt16 nId ) : SfxPoolItem(nId), mColor( COL_BLACK ), - maThemeIndex(-1), - maTintShade(0) + mnThemeIndex(-1), + mnTintShade(0), + // maThemeColorData(std::nullopt), + mpColorSets(nullptr) { + // maThemeColorData = { 4, 0 }; } SvxColorItem::SvxColorItem( const Color& rCol, const sal_uInt16 nId ) : SfxPoolItem( nId ), mColor( rCol ), - maThemeIndex(-1), - maTintShade(0) + mnThemeIndex(-1), + mnTintShade(0), + // maThemeColorData(std::nullopt), + mpColorSets(nullptr) { + // maThemeColorData = { 4, 0 }; } SvxColorItem::~SvxColorItem() @@ -1335,9 +1344,9 @@ bool SvxColorItem::operator==( const SfxPoolItem& rAttr ) const assert(SfxPoolItem::operator==(rAttr)); const SvxColorItem& rColorItem = static_cast<const SvxColorItem&>(rAttr); - return mColor == rColorItem.mColor && - maThemeIndex == rColorItem.maThemeIndex && - maTintShade == rColorItem.maTintShade; + return mColor == rColorItem.mColor + && mnThemeIndex == rColorItem.mnThemeIndex + && mnTintShade == rColorItem.mnTintShade; } bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const @@ -1358,12 +1367,12 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const } case MID_COLOR_THEME_INDEX: { - rVal <<= maThemeIndex; + rVal <<= mnThemeIndex; break; } case MID_COLOR_TINT_OR_SHADE: { - rVal <<= maTintShade; + rVal <<= mnTintShade; break; } default: @@ -1401,7 +1410,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nIndex = -1; if (!(rVal >>= nIndex)) return false; - maThemeIndex = nIndex; + mnThemeIndex = nIndex; } break; case MID_COLOR_TINT_OR_SHADE: @@ -1409,7 +1418,7 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) sal_Int16 nTintShade = -1; if (!(rVal >>= nTintShade)) return false; - maTintShade = nTintShade; + mnTintShade = nTintShade; } break; default: @@ -1454,7 +1463,46 @@ void SvxColorItem::dumpAsXml(xmlTextWriterPtr pWriter) const (void)xmlTextWriterEndElement(pWriter); } +const Color& SvxColorItem::GetValue() const +{ + if (mnThemeIndex > -1) + { + // try to get the pointer for ColorSets if it's not there... + if (!mpColorSets) + { + if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) + { + mpColorSets = &pColorSetItem->GetSfxColorSetList(); + } + } + } + + if(mpColorSets) + { + Color aColor = mpColorSets->getThemeColorSet().getColor(mnThemeIndex); + // only calculate tint or shade applied color if necessary + if(aColor != maCacheColor) + { + maCacheColor = aColor; + aColor.ApplyTintOrShade(GetTintOrShade()); + mColor = aColor; + // TODO: add some kind of cache invalidation for + // SetTintOrShade() + } + } + else if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) + { + mpColorSets = &pColorSetItem->GetSfxColorSetList(); + } + } + } + return mColor; +} void SvxColorItem::SetValue( const Color& rNewCol ) { diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx index ce51be7f3e30..2258460e4e16 100644 --- a/include/editeng/colritem.hxx +++ b/include/editeng/colritem.hxx @@ -19,20 +19,39 @@ #ifndef INCLUDED_EDITENG_COLRITEM_HXX #define INCLUDED_EDITENG_COLRITEM_HXX +#include <sfx2/objsh.hxx> +#include <sfx2/ColorSets.hxx> #include <svl/poolitem.hxx> #include <tools/color.hxx> #include <editeng/editengdllapi.h> +#include <sal/log.hxx> + #define VERSION_USEAUTOCOLOR 1 +// struct ThemeColorData +// { +// sal_Int16 mnThemeIndex; +// sal_Int16 mnTintShade; +// }; + /** SvxColorItem item describes a color. */ class EDITENG_DLLPUBLIC SvxColorItem final : public SfxPoolItem { private: - Color mColor; - sal_Int16 maThemeIndex; - sal_Int16 maTintShade; + // TODO: obv. making almost everything mutable doesn't make sense.. + // refactor these before pushing... + + mutable Color mColor; + + /// Cache of the theme color + mutable Color maCacheColor; + // std::optional<ThemeColorData> maThemeColorData; + sal_Int16 mnThemeIndex; + sal_Int16 mnTintShade; + + mutable const ColorSets* mpColorSets; public: static SfxPoolItem* CreateDefault(); @@ -53,31 +72,20 @@ public: virtual SvxColorItem* Clone(SfxItemPool* pPool = nullptr) const override; SvxColorItem(SvxColorItem const &) = default; // SfxPoolItem copy function dichotomy - const Color& GetValue() const - { - return mColor; - } + const Color& GetValue() const; + void SetValue(const Color& rNewColor); sal_Int16 GetThemeIndex() const { - return maThemeIndex; + return mnThemeIndex; } - void SetThemeIndex(sal_Int16 nIndex) - { - maThemeIndex = nIndex; - } + void SetThemeIndex(sal_Int16 nIndex) { mnThemeIndex = nIndex; } - sal_Int16 GetTintOrShade() const - { - return maTintShade; - } + sal_Int16 GetTintOrShade() const { return mnTintShade; } - void SetTintOrShade(sal_Int16 nTintOrShade) - { - maTintShade = nTintOrShade; - } + void SetTintOrShade(sal_Int16 nTintOrShade) { mnTintShade = nTintOrShade; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; }; diff --git a/include/sfx2/ColorSets.hxx b/include/sfx2/ColorSets.hxx new file mode 100644 index 000000000000..977ab1ba6735 --- /dev/null +++ b/include/sfx2/ColorSets.hxx @@ -0,0 +1,91 @@ +/* -*- 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 <vector> + +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <sfx2/dllapi.h> +#include <svl/poolitem.hxx> +#include <tools/color.hxx> + +class ColorSet +{ + OUString maColorSetName; + std::vector<Color> maColors; + +public: + ColorSet(OUString const& aName); + + void add(sal_uInt32 nIndex, ::Color aColorData) { maColors[nIndex] = aColorData; } + + const OUString& getName() const { return maColorSetName; } + const Color& getColor(sal_uInt32 nIndex) const { return maColors[nIndex]; } + + const std::vector<Color>& getColors() const { return maColors; } +}; + +class SFX2_DLLPUBLIC ColorSets +{ + std::vector<ColorSet> maColorSets; + sal_Int32 mnThemeColorSetIndex; + +public: + ColorSets(); + ~ColorSets(); + + static ColorSets& get() + { + static ColorSets aColorSetsInstance; + return aColorSetsInstance; + } + + const ColorSet& getThemeColorSet() const { return getColorSet(mnThemeColorSetIndex); } + + void setThemeColorSet(sal_Int32 nIndex); + + void setThemeColorSet(std::u16string_view rName); + + const std::vector<ColorSet>& getColorSets() const { return maColorSets; } + + const ColorSet& getColorSet(sal_uInt32 nIndex) const { return maColorSets[nIndex]; } + + const ColorSet& getColorSet(std::u16string_view rName) const; +}; + +//typedef rtl::Reference<class ColorSets> ColorSetsRef; +//typedef ColorSets ColorSetsRef; + +class SFX2_DLLPUBLIC SfxColorSetListItem final : public SfxPoolItem +{ + std::shared_ptr<ColorSets> mpColorSets; + +public: + static SfxPoolItem* CreateDefault(); + SfxColorSetListItem(); + SfxColorSetListItem(const ColorSets& rColorSets, sal_uInt16 nWhich); + SfxColorSetListItem(const SfxColorSetListItem&); + + virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, + MapUnit ePresMetric, OUString& rText, + const IntlWrapper&) const override; + + virtual bool operator==(const SfxPoolItem&) const override; + virtual SfxColorSetListItem* Clone(SfxItemPool* pPool = nullptr) const override; + virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override; + virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override; + + const ColorSets& GetSfxColorSetList() const { return *mpColorSets; } + std::shared_ptr<ColorSets> GetSfxColorSetListPtr() const { return mpColorSets; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 35d9ab895856..c2b3a13818bc 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -28,6 +28,7 @@ class SfxUInt16Item; class SvxHyperlinkItem; class SfxDocumentInfoItem; class SvxSearchItem; +class SfxColorSetListItem; // Please be careful: // Changing just one part here doesn't add new @@ -362,6 +363,7 @@ class SvxSearchItem; #define SID_STYLE_UPD_BY_EX_NAME (SID_SFX_START + 1585) #define SID_STYLE_REFERENCE TypedWhichId<SfxStringItem>(SID_SFX_START + 1602) +#define SID_COLOR_SETS TypedWhichId<SfxColorSetListItem>(SID_SFX_START + 1605) #define SID_TEMPLATE_NAME (SID_SFX_START + 660) #define SID_TEMPLATE_REGIONNAME (SID_SFX_START + 662) #define SID_TEMPLATE_LOAD (SID_SFX_START + 663) diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx deleted file mode 100644 index 361fe47c622e..000000000000 --- a/include/svx/ColorSets.hxx +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- 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/. - * - */ - -#ifndef INCLUDED_SVX_COLORSETS_HXX -#define INCLUDED_SVX_COLORSETS_HXX - -#include <vector> - -#include <rtl/ustring.hxx> -#include <sal/types.h> -#include <svx/svxdllapi.h> -#include <tools/color.hxx> - -namespace svx -{ - -class ColorSet -{ - OUString maColorSetName; - std::vector<Color> maColors; -public: - ColorSet(OUString const & aName); - - void add(sal_uInt32 nIndex, ::Color aColorData) - { - maColors[nIndex] = aColorData; - } - - const OUString& getName() const - { - return maColorSetName; - } - const Color& getColor(sal_uInt32 nIndex) const - { - return maColors[nIndex]; - } -}; - -class SVXCORE_DLLPUBLIC ColorSets -{ - std::vector<ColorSet> maColorSets; -public: - ColorSets(); - ~ColorSets(); - - void init(); - const std::vector<ColorSet>& getColorSets() const - { - return maColorSets; - } - - const ColorSet& getColorSet(sal_uInt32 nIndex) - { - return maColorSets[nIndex]; - } - - const ColorSet& getColorSet(std::u16string_view rName); -}; - -} // end of namespace svx - -#endif // INCLUDED_SVX_COLORSETS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 0120cee75b4e..d2369bb43247 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -294,6 +294,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/sidebar/UnoDecks \ sfx2/source/sidebar/UnoSidebar \ sfx2/source/statbar/stbitem \ + sfx2/source/styles/ColorSets \ sfx2/source/styles/StyleManager \ sfx2/source/toolbox/tbxitem \ sfx2/source/toolbox/weldutils \ diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 70b2e1e2e486..4175ddf3e467 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -41,6 +41,7 @@ #include <unotools/configmgr.hxx> #include <unotools/eventcfg.hxx> +#include <sfx2/ColorSets.hxx> #include <sfx2/objsh.hxx> #include <sfx2/signaturestate.hxx> #include <sfx2/sfxmodelfactory.hxx> @@ -260,6 +261,8 @@ SfxObjectShell::SfxObjectShell( const SfxModelFlags i_nCreationFlags ) const bool bDocRecovery = ( i_nCreationFlags & SfxModelFlags::DISABLE_DOCUMENT_RECOVERY ) == SfxModelFlags::NONE; if ( !bDocRecovery ) pImpl->m_bDocRecoverySupport = false; + + PutItem(SfxColorSetListItem(ColorSets(), SID_COLOR_SETS)); } /** Constructor of the class SfxObjectShell. @@ -277,6 +280,7 @@ SfxObjectShell::SfxObjectShell(SfxObjectCreateMode eMode) , bIsInGenerateThumbnail(false) , mbAvoidRecentDocs(false) { + PutItem(SfxColorSetListItem(ColorSets(), SID_COLOR_SETS)); } SfxObjectShell::~SfxObjectShell() diff --git a/sfx2/source/styles/ColorSets.cxx b/sfx2/source/styles/ColorSets.cxx new file mode 100644 index 000000000000..ac0088311c93 --- /dev/null +++ b/sfx2/source/styles/ColorSets.cxx @@ -0,0 +1,155 @@ +/* -*- 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 <sfx2/ColorSets.hxx> + +ColorSet::ColorSet(OUString const& aColorSetName) + : maColorSetName(aColorSetName) + , maColors(12) +{ +} + +ColorSets::ColorSets() + : maColorSets() + , mnThemeColorSetIndex(0) +{ + { + ColorSet aColorSet("Breeze"); + aColorSet.add(0, 0xFCFCFC); + aColorSet.add(1, 0x232629); + aColorSet.add(2, 0xEFF0F1); + aColorSet.add(3, 0x31363B); + aColorSet.add(4, 0xDA4453); + aColorSet.add(5, 0xF47750); + aColorSet.add(6, 0xFDBC4B); + aColorSet.add(7, 0xC9CE3B); + aColorSet.add(8, 0x1CDC9A); + aColorSet.add(9, 0x2ECC71); + aColorSet.add(10, 0x1D99F3); + aColorSet.add(11, 0x3DAEE9); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Blue"); + aColorSet.add(0, 0xFFFFFF); + aColorSet.add(1, 0x212121); + aColorSet.add(2, 0xECEFF1); + aColorSet.add(3, 0x37474F); + aColorSet.add(4, 0x7986CB); + aColorSet.add(5, 0x303F9F); + aColorSet.add(6, 0x64B5F6); + aColorSet.add(7, 0x1976D2); + aColorSet.add(8, 0x4FC3F7); + aColorSet.add(9, 0x0277BD); + aColorSet.add(10, 0x4DD0E1); + aColorSet.add(11, 0x0097A7); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Red"); + aColorSet.add(0, 0xFFFFFF); + aColorSet.add(1, 0x212121); + aColorSet.add(2, 0xF5F5F5); + aColorSet.add(3, 0x424242); + aColorSet.add(4, 0xFF9800); + aColorSet.add(5, 0xFF6D00); + aColorSet.add(6, 0xFF5722); + aColorSet.add(7, 0xDD2C00); + aColorSet.add(8, 0xF44336); + aColorSet.add(9, 0xD50000); + aColorSet.add(10, 0xE91E63); + aColorSet.add(11, 0xC51162); + maColorSets.push_back(aColorSet); + } + { + ColorSet aColorSet("Material Green"); + aColorSet.add(0, 0xFFFFFF); + aColorSet.add(1, 0x212121); + aColorSet.add(2, 0xF5F5F5); + aColorSet.add(3, 0x424242); + aColorSet.add(4, 0x009688); + aColorSet.add(5, 0x00bfa5); + aColorSet.add(6, 0x4caf50); + aColorSet.add(7, 0x00c853); + aColorSet.add(8, 0x8bc34a); + aColorSet.add(9, 0x64dd17); + aColorSet.add(10, 0xcddc39); + aColorSet.add(11, 0xaeea00); + maColorSets.push_back(aColorSet); + } +} + +ColorSets::~ColorSets() {} + +const ColorSet& ColorSets::getColorSet(std::u16string_view rName) const +{ + for (const ColorSet& rColorSet : maColorSets) + { + if (rColorSet.getName() == rName) + return rColorSet; + } + return maColorSets[0]; +} + +void ColorSets::setThemeColorSet(sal_Int32 nIndex) { mnThemeColorSetIndex = nIndex; } + +void ColorSets::setThemeColorSet(std::u16string_view rName) +{ + for (sal_uInt32 nIndex = 0; nIndex < maColorSets.size(); ++nIndex) + { + if (maColorSets[nIndex].getName() == rName) + mnThemeColorSetIndex = nIndex; + } +} + +SfxColorSetListItem::SfxColorSetListItem() {} + +SfxColorSetListItem::SfxColorSetListItem(const ColorSets& rColorSets, sal_uInt16 nW) + : SfxPoolItem(nW) +{ + mpColorSets = std::make_shared<ColorSets>(rColorSets); +} + +SfxColorSetListItem::SfxColorSetListItem(const SfxColorSetListItem& rItem) + : SfxPoolItem(rItem) + , mpColorSets(rItem.mpColorSets) +{ +} + +bool SfxColorSetListItem::GetPresentation(SfxItemPresentation /*ePres*/, MapUnit /*eCoreUnit*/, + MapUnit /*ePresUnit*/, OUString& rText, + const IntlWrapper&) const +{ + rText.clear(); + return false; +} + +bool SfxColorSetListItem::operator==(const SfxPoolItem& rItem) const +{ + assert(SfxPoolItem::operator==(rItem)); + // TODO: check these out before pushing... + return false; + // return static_cast<const SfxColorSetListItem&>(rItem).mrColorSets == mrColorSets; +} + +SfxColorSetListItem* SfxColorSetListItem::Clone(SfxItemPool*) const +{ + return new SfxColorSetListItem(*this); +} + +/// TODO: check these out before pushing... +bool SfxColorSetListItem::QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId) const +{ + return false; +} + +bool SfxColorSetListItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) { return false; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index b7fa742cabe8..719e7d84bfb0 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sfx2/ColorSets.hxx> + #include <config_feature_desktop.h> #include <osl/file.hxx> #include <sfx2/docfilt.hxx> @@ -1679,6 +1681,7 @@ void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh ) Notify( *pObjSh, SfxHint(SfxHintId::TitleChanged) ); Notify( *pObjSh, SfxHint(SfxHintId::DocChanged) ); m_pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() ); + } else { diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 8e596acd4605..625fa6297109 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -359,7 +359,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/svdraw/textchaincursor \ svx/source/styles/CommonStylePreviewRenderer \ svx/source/styles/CommonStyleManager \ - svx/source/styles/ColorSets \ svx/source/table/cell \ svx/source/table/cellcursor \ svx/source/table/cellrange \ diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx deleted file mode 100644 index 7a04eb4e6314..000000000000 --- a/svx/source/styles/ColorSets.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- 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 <svx/ColorSets.hxx> - -namespace svx -{ - -ColorSet::ColorSet(OUString const & aColorSetName) - : maColorSetName(aColorSetName) - , maColors(12) -{} - -ColorSets::ColorSets() -{} - -ColorSets::~ColorSets() -{} - -void ColorSets::init() -{ - { - ColorSet aColorSet("Breeze"); - aColorSet.add(0, 0xFCFCFC); - aColorSet.add(1, 0x232629); - aColorSet.add(2, 0xEFF0F1); - aColorSet.add(3, 0x31363B); - aColorSet.add(4, 0xDA4453); - aColorSet.add(5, 0xF47750); - aColorSet.add(6, 0xFDBC4B); - aColorSet.add(7, 0xC9CE3B); - aColorSet.add(8, 0x1CDC9A); - aColorSet.add(9, 0x2ECC71); - aColorSet.add(10, 0x1D99F3); - aColorSet.add(11, 0x3DAEE9); - maColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet("Material Blue"); - aColorSet.add(0, 0xFFFFFF); - aColorSet.add(1, 0x212121); - aColorSet.add(2, 0xECEFF1); - aColorSet.add(3, 0x37474F); - aColorSet.add(4, 0x7986CB); - aColorSet.add(5, 0x303F9F); - aColorSet.add(6, 0x64B5F6); - aColorSet.add(7, 0x1976D2); - aColorSet.add(8, 0x4FC3F7); - aColorSet.add(9, 0x0277BD); - aColorSet.add(10, 0x4DD0E1); - aColorSet.add(11, 0x0097A7); - maColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet("Material Red"); - aColorSet.add(0, 0xFFFFFF); - aColorSet.add(1, 0x212121); - aColorSet.add(2, 0xF5F5F5); - aColorSet.add(3, 0x424242); - aColorSet.add(4, 0xFF9800); - aColorSet.add(5, 0xFF6D00); - aColorSet.add(6, 0xFF5722); - aColorSet.add(7, 0xDD2C00); - aColorSet.add(8, 0xF44336); - aColorSet.add(9, 0xD50000); - aColorSet.add(10, 0xE91E63); - aColorSet.add(11, 0xC51162); - maColorSets.push_back(aColorSet); - } - { - ColorSet aColorSet("Material Green"); - aColorSet.add(0, 0xFFFFFF); - aColorSet.add(1, 0x212121); - aColorSet.add(2, 0xF5F5F5); - aColorSet.add(3, 0x424242); - aColorSet.add(4, 0x009688); - aColorSet.add(5, 0x00bfa5); - aColorSet.add(6, 0x4caf50); - aColorSet.add(7, 0x00c853); - aColorSet.add(8, 0x8bc34a); - aColorSet.add(9, 0x64dd17); - aColorSet.add(10, 0xcddc39); - aColorSet.add(11, 0xaeea00); - maColorSets.push_back(aColorSet); - } -} - -const ColorSet& ColorSets::getColorSet(std::u16string_view rName) -{ - for (const ColorSet & rColorSet : maColorSets) - { - if (rColorSet.getName() == rName) - return rColorSet; - } - return maColorSets[0]; -} - -} // end of namespace svx - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index ce42983879ce..a9ddb4af0c83 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -13,6 +13,7 @@ #include "ThemePanel.hxx" #include <sfx2/objsh.hxx> +#include <sfx2/sfxsids.hrc> #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -75,7 +76,7 @@ public: maVariable = aVariable; } - Color getColor(svx::ColorSet const & rColorSet) + Color getColor(ColorSet const & rColorSet) { Color aColor; if (maVariable.mnIndex > -1) @@ -229,7 +230,7 @@ void changeFont(SwFormat* pFormat, SwDocStyleSheet const * pStyle, FontSet const } }*/ -void changeColor(SwTextFormatColl* pCollection, svx::ColorSet const& rColorSet, StyleRedefinition* /*pRedefinition*/) +void changeColor(SwTextFormatColl* pCollection, ColorSet const& rColorSet, StyleRedefinition* /*pRedefinition*/) { SvxColorItem aColorItem(pCollection->GetColor()); sal_Int16 nIndex = aColorItem.GetThemeIndex(); @@ -331,16 +332,19 @@ FontSet getFontSet(std::u16string_view rFontVariant, std::vector<FontSet>& aFont } void applyTheme(SfxStyleSheetBasePool* pPool, std::u16string_view sFontSetName, std::u16string_view sColorSetName, - StyleSet& rStyleSet, svx::ColorSets& rColorSets) + StyleSet& rStyleSet, ColorSets& rColorSets) { SwDocStyleSheet* pStyle; std::vector<FontSet> aFontSets = initFontSets(); FontSet aFontSet = getFontSet(sFontSetName, aFontSets); - svx::ColorSet aColorSet = rColorSets.getColorSet(sColorSetName); + ColorSet aColorSet = rColorSets.getColorSet(sColorSetName); pStyle = static_cast<SwDocStyleSheet*>(pPool->First(SfxStyleFamily::Para)); + + rColorSets.setThemeColorSet(sColorSetName); + while (pStyle) { SwTextFormatColl* pCollection = pStyle->GetCollection(); @@ -368,7 +372,7 @@ void applyTheme(SfxStyleSheetBasePool* pPool, std::u16string_view sFontSetName, } } -BitmapEx GenerateColorPreview(const svx::ColorSet& rColorSet) +BitmapEx GenerateColorPreview(const ColorSet& rColorSet) { ScopedVclPtrInstance<VirtualDevice> pVirtualDev(*Application::GetDefaultDevice()); float fScaleFactor = pVirtualDev->GetDPIScaleFactor(); @@ -440,7 +444,7 @@ ThemePanel::ThemePanel(weld::Widget* pParent) , mxValueSetColors(new ValueSet(nullptr)) , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, "valueset_colors", *mxValueSetColors)) , mxApplyButton(m_xBuilder->weld_button("apply")) - , maColorSets() + , maColorSets(nullptr) { mxValueSetColors->SetColCount(2); mxValueSetColors->SetLineCount(3); @@ -454,26 +458,32 @@ ThemePanel::ThemePanel(weld::Widget* pParent) for (const FontSet & rFontSet : aFontSets) mxListBoxFonts->append_text(rFontSet.maName); mxListBoxFonts->set_size_request(-1, mxListBoxFonts->get_height_rows(aFontSets.size())); + if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) + { + maColorSets = pColorSetItem->GetSfxColorSetListPtr(); + } + } - maColorSets.init(); - const std::vector<svx::ColorSet>& aColorSets = maColorSets.getColorSets(); - for (size_t i = 0; i < aColorSets.size(); ++i) - { - const svx::ColorSet& rColorSet = aColorSets[i]; + const std::vector<ColorSet>& aColorSets = maColorSets->getColorSets(); + for (size_t i = 0; i < aColorSets.size(); ++i) + { + const ColorSet& rColorSet = aColorSets[i]; - const OUString& aName = rColorSet.getName(); - BitmapEx aPreview = GenerateColorPreview(rColorSet); + const OUString& aName = rColorSet.getName(); + BitmapEx aPreview = GenerateColorPreview(rColorSet); - sal_uInt16 nId = i + 1; - mxValueSetColors->InsertItem(nId, Image(aPreview), aName); - } + sal_uInt16 nId = i + 1; + mxValueSetColors->InsertItem(nId, Image(aPreview), aName); + } - mxValueSetColors->SetOptimalSize(); + mxValueSetColors->SetOptimalSize(); - if (!aColorSets.empty()) - mxValueSetColors->SelectItem(1); // ItemId 1, position 0 -} + if (!aColorSets.empty()) + mxValueSetColors->SelectItem(1); // ItemId 1, position 0 + } ThemePanel::~ThemePanel() { @@ -510,11 +520,11 @@ void ThemePanel::DoubleClickHdl() return; OUString sEntryFonts = mxListBoxFonts->get_selected_text(); sal_uInt32 nIndex = nItemId - 1; - OUString sEntryColors = maColorSets.getColorSet(nIndex).getName(); + OUString sEntryColors = maColorSets->getColorSet(nIndex).getName(); StyleSet aStyleSet = setupThemes(); - applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, aStyleSet, maColorSets); + applyTheme(pDocSh->GetStyleSheetPool(), sEntryFonts, sEntryColors, aStyleSet, *maColorSets); } void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/, diff --git a/sw/source/uibase/sidebar/ThemePanel.hxx b/sw/source/uibase/sidebar/ThemePanel.hxx index 14af479e664a..ee0cbeaadfa1 100644 --- a/sw/source/uibase/sidebar/ThemePanel.hxx +++ b/sw/source/uibase/sidebar/ThemePanel.hxx @@ -13,7 +13,7 @@ #include <sfx2/sidebar/PanelLayout.hxx> #include <sfx2/sidebar/ControllerItem.hxx> #include <svtools/valueset.hxx> -#include <svx/ColorSets.hxx> +#include <sfx2/ColorSets.hxx> namespace sw::sidebar { @@ -40,7 +40,7 @@ private: std::unique_ptr<weld::CustomWeld> mxValueSetColorsWin; std::unique_ptr<weld::Button> mxApplyButton; - svx::ColorSets maColorSets; + std::shared_ptr<ColorSets> maColorSets; DECL_LINK(ClickHdl, weld::Button&, void); DECL_LINK(DoubleClickHdl, weld::TreeView&, bool);