editeng/source/items/textitem.cxx | 80 +++++++++++++++++---- include/editeng/colritem.hxx | 11 ++ include/editeng/memberids.h | 1 include/editeng/unoprnms.hxx | 1 include/editeng/unotext.hxx | 1 include/oox/drawingml/clrscheme.hxx | 4 - include/oox/ppt/slidepersist.hxx | 5 + include/sfx2/ColorSets.hxx | 66 ++++++++++++++--- include/sfx2/sfxbasemodel.hxx | 3 offapi/com/sun/star/document/XColorSetsManager.idl | 4 - oox/source/drawingml/clrscheme.cxx | 4 - oox/source/drawingml/shape.cxx | 2 oox/source/drawingml/textcharacterproperties.cxx | 12 +++ oox/source/ppt/presentationfragmenthandler.cxx | 8 +- oox/source/ppt/slidepersist.cxx | 32 ++++++++ oox/source/token/properties.txt | 1 sfx2/source/doc/sfxbasemodel.cxx | 15 +++ sfx2/source/styles/ColorSets.cxx | 29 +++++-- svx/source/unodraw/unoprov.cxx | 1 sw/source/uibase/sidebar/ThemePanel.cxx | 5 - 20 files changed, 236 insertions(+), 49 deletions(-)
New commits: commit c089e07b5b74bd02f37889706892bc12b1a8be99 Author: Sarper Akdemir <sarper.akde...@collabora.com> AuthorDate: Mon Oct 11 10:27:59 2021 +0300 Commit: Sarper Akdemir <sarper.akde...@collabora.com> CommitDate: Mon Oct 11 10:27:59 2021 +0300 introduce virtual theme color sets Change-Id: I6831bd5673605cdb630d0e4d47436b1890cb016c diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index 11407bb79a31..088e2b7d0dbd 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -1321,36 +1321,43 @@ bool ThemeColorData::operator==(const ThemeColorData &rOther) const return true; else return mnThemeColorIndex == rOther.mnThemeColorIndex + && mnVirtualThemeColorSetIndex == rOther.mnVirtualThemeColorSetIndex && mnTintShade == rOther.mnTintShade; } std::optional<Color> ThemeColorData::getThemeColorIfNeedsUpdate() const { - if (mnThemeColorIndex > -1) + // HACK: after getting rid of SfxObjectShell::Current() should be + // able to get rid of mnContainerIndex + if (mnThemeColorIndex != -1 && mnVirtualThemeColorSetIndex != -1) { - // try to get the pointer for ColorSets if it's not there... - if (!mpColorSets) + // HACK: try to get the pointer to the container.. if it's not there + // We won't need this after figuring out a better way of interacting with SfxObjectShell + if(mpVirtualThemeColorSet.expired()) { if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) { if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) { - mpColorSets = &pColorSetItem->GetSfxColorSetList(); + ColorSets& rColorSets = pColorSetItem->GetSfxColorSetList(); + mpVirtualThemeColorSet = rColorSets.getVirtualColorSet(mnVirtualThemeColorSetIndex); } } } - if (mpColorSets) + if (auto pVirtualThemeColorSet = mpVirtualThemeColorSet.lock()) { - Color aColor = mpColorSets->getThemeColorSet().getColor(mnThemeColorIndex); - - // only calculate transformations applied color when necessary - if(aColor != maCachedBaseColor || mbRecalculateColor) + if ( auto pColorSet = pVirtualThemeColorSet->getColorSetPtr().lock() ) { - maCachedBaseColor = aColor; - mbRecalculateColor = false; - aColor.ApplyTintOrShade(mnTintShade); - return aColor; + Color aColor = pColorSet->getColor(mnThemeColorIndex); + // only calculate transformations applied color when necessary + if(aColor != maCachedBaseColor || mbRecalculateColor) + { + maCachedBaseColor = aColor; + mbRecalculateColor = false; + aColor.ApplyTintOrShade(mnTintShade); + return aColor; + } } } } @@ -1398,6 +1405,40 @@ void ThemeColorData::RecalculateOnNextGet() // maCachedBaseColor = 0xDEADBEEF; } +void ThemeColorData::setVirtualThemeColorSet(sal_Int32 nVirtualThemeColorSetIndex) +{ + // HACK: + mnVirtualThemeColorSetIndex = nVirtualThemeColorSetIndex; + return; + + // After swapping out SfxObjectShell::Current() with something reasonable + // this should work: + if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) + { + ColorSets& rColorSets = pColorSetItem->GetSfxColorSetList(); + mpVirtualThemeColorSet = rColorSets.getVirtualColorSet(nVirtualThemeColorSetIndex); + } + } +} + +sal_Int32 ThemeColorData::getVirtualThemeColorSetIndex() const +{ + // HACK: + return mnVirtualThemeColorSetIndex; + + // After swapping out SfxObjectShell::Current() with something reasonable + // this should work: + if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + if (const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) + { + return pColorSetItem->GetSfxColorSetList().getVirtualColorSetIndex(mpVirtualThemeColorSet); + } + } +} + // class SvxColorItem ---------------------------------------------------- SvxColorItem::SvxColorItem( const sal_uInt16 nId ) : SfxPoolItem(nId), @@ -1472,6 +1513,11 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const rVal <<= maThemeColorData.getTintOrShade(); break; } + case MID_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX: + { + rVal <<= maThemeColorData.getVirtualThemeColorSetIndex(); + break; + } default: { rVal <<= mColor; @@ -1518,6 +1564,14 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) maThemeColorData.setTintOrShade(nTintShade); } break; + case MID_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX: + { + sal_Int32 nContainerIndex = -1; + if (!(rVal >>= nContainerIndex)) + return false; + maThemeColorData.setVirtualThemeColorSet(nContainerIndex); + } + break; default: { return rVal >>= mColor; diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx index 13444a57541c..fe300045598f 100644 --- a/include/editeng/colritem.hxx +++ b/include/editeng/colritem.hxx @@ -47,6 +47,8 @@ public: sal_Int16 getTintOrShade() const; void setThemeColorIndex(sal_Int16 nThemeColorIndex); sal_Int16 getThemeColorIndex() const; + void setVirtualThemeColorSet(sal_Int32 nVirtualThemeColorSetIndex); + sal_Int32 getVirtualThemeColorSetIndex() const; private: void RecalculateOnNextGet(); @@ -74,6 +76,15 @@ private: mutable const ColorSets* mpColorSets = nullptr; // mutable since marked as false after recalculation in getThemeColorIfNeedsUpdate mutable bool mbRecalculateColor = true; + + // HACK: VirtualColorSet index + // should be able to remove this after removing SfxObjectShell::Current() + // from the themecolordata code + sal_Int32 mnVirtualThemeColorSetIndex = -1; + + + // HACK: mutable here until I fix the SfxObjectShell interactions.. + mutable std::weak_ptr<VirtualThemeColorSet> mpVirtualThemeColorSet = std::weak_ptr<VirtualThemeColorSet>(); }; /** SvxColorItem item describes a color. diff --git a/include/editeng/memberids.h b/include/editeng/memberids.h index c6d781da568a..82f735da80ed 100644 --- a/include/editeng/memberids.h +++ b/include/editeng/memberids.h @@ -183,6 +183,7 @@ //#define MID_GRAPHIC_TRANSPARENT 3 // used, but already defined above #define MID_COLOR_THEME_INDEX 4 #define MID_COLOR_TINT_OR_SHADE 5 +#define MID_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX 6 #endif diff --git a/include/editeng/unoprnms.hxx b/include/editeng/unoprnms.hxx index 8418dbf2e91c..2061e12963c6 100644 --- a/include/editeng/unoprnms.hxx +++ b/include/editeng/unoprnms.hxx @@ -327,6 +327,7 @@ #define UNO_NAME_EDIT_CHAR_COLOR "CharColor" #define UNO_NAME_EDIT_CHAR_COLOR_THEME_COLOR_INDEX "CharColorThemeColorIndex" #define UNO_NAME_EDIT_CHAR_COLOR_TINT_OR_SHADE "CharColorTintOrShade" +#define UNO_NAME_EDIT_CHAR_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX "CharColorVirtualThemeColorSetIndex" #define UNO_NAME_EDIT_CHAR_TRANSPARENCE "CharTransparence" #define UNO_NAME_EDIT_CHAR_CROSSEDOUT "CharCrossedOut" #define UNO_NAME_EDIT_CHAR_STRIKEOUT "CharStrikeout" diff --git a/include/editeng/unotext.hxx b/include/editeng/unotext.hxx index 59c7fd32b12a..0e80dd0a2667 100644 --- a/include/editeng/unotext.hxx +++ b/include/editeng/unotext.hxx @@ -89,6 +89,7 @@ struct SfxItemPropertyMapEntry; { u"" UNO_NAME_EDIT_CHAR_TRANSPARENCE,EE_CHAR_COLOR, ::cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_ALPHA }, \ { u"" UNO_NAME_EDIT_CHAR_COLOR_THEME_COLOR_INDEX, EE_CHAR_COLOR, ::cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_THEME_INDEX }, \ { u"" UNO_NAME_EDIT_CHAR_COLOR_TINT_OR_SHADE, EE_CHAR_COLOR, ::cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_TINT_OR_SHADE }, \ + { u"" UNO_NAME_EDIT_CHAR_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX, EE_CHAR_COLOR, ::cppu::UnoType<sal_Int32>::get(), 0, MID_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX }, \ { u"CharBackColor", EE_CHAR_BKGCOLOR, ::cppu::UnoType<sal_Int32>::get(), 0, 0 }, \ { u"CharBackTransparent", EE_CHAR_BKGCOLOR, ::cppu::UnoType<bool>::get(), 0, MID_GRAPHIC_TRANSPARENT }, \ { u"" UNO_NAME_EDIT_CHAR_ESCAPEMENT, EE_CHAR_ESCAPEMENT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_ESC }, \ diff --git a/include/oox/drawingml/clrscheme.hxx b/include/oox/drawingml/clrscheme.hxx index cd8755e77088..6ba9322a7c64 100644 --- a/include/oox/drawingml/clrscheme.hxx +++ b/include/oox/drawingml/clrscheme.hxx @@ -86,8 +86,8 @@ public: bool getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const; void setColor( sal_Int32 nSchemeClrToken, ::Color nColor ); - std::vector<::Color> getColorVector(); - std::vector<sal_Int32> getColorVectorAsInts(); + std::vector<::Color> getColorVector() const; + std::vector<sal_Int32> getColorVectorAsInts() const; bool getColorByIndex(size_t nIndex, ::Color& rColor) const; diff --git a/include/oox/ppt/slidepersist.hxx b/include/oox/ppt/slidepersist.hxx index c09e5f0b0da0..495ef1b9bde0 100644 --- a/include/oox/ppt/slidepersist.hxx +++ b/include/oox/ppt/slidepersist.hxx @@ -83,8 +83,10 @@ public: void setLayoutPath( const OUString& rLayoutPath ) { maLayoutPath = rLayoutPath; } const OUString& getLayoutPath() const { return maLayoutPath; } - void setTheme( const oox::drawingml::ThemePtr& rThemePtr ){ mpThemePtr = rThemePtr; } + void setTheme(const oox::drawingml::ThemePtr& rThemePtr, + const oox::core::XmlFilterBase& rFilterBase); const oox::drawingml::ThemePtr& getTheme() const { return mpThemePtr; } + const std::optional<sal_Int32>& getVirtualThemeColorSetIndex() { return moVirtualColorSetIndex; } void setClrMap( const oox::drawingml::ClrMapPtr pClrMapPtr ){ mpClrMapPtr = pClrMapPtr; } const oox::drawingml::ClrMapPtr& getClrMap() const { return mpClrMapPtr; } @@ -132,6 +134,7 @@ private: css::uno::Reference< css::drawing::XDrawPage > mxPage; oox::drawingml::ThemePtr mpThemePtr; // the theme that is used oox::drawingml::ClrMapPtr mpClrMapPtr; // color mapping (if any) + std::optional<sal_Int32> moVirtualColorSetIndex; SlidePersistPtr mpMasterPagePtr; oox::drawingml::ShapePtr maShapesPtr; diff --git a/include/sfx2/ColorSets.hxx b/include/sfx2/ColorSets.hxx index 9ca322ab458d..1f0cb6312c75 100644 --- a/include/sfx2/ColorSets.hxx +++ b/include/sfx2/ColorSets.hxx @@ -10,6 +10,7 @@ #pragma once +#include <memory> #include <vector> #include <rtl/ustring.hxx> @@ -34,38 +35,79 @@ public: const std::vector<Color>& getColors() const { return maColors; } }; +class VirtualThemeColorSet +{ +public: + VirtualThemeColorSet() = default; + VirtualThemeColorSet(const std::shared_ptr<ColorSet>& pColorSet) + : mpThemeColorSet(pColorSet) + { + } + const std::weak_ptr<ColorSet>& getColorSetPtr() { return mpThemeColorSet; } + +private: + std::weak_ptr<ColorSet> mpThemeColorSet = std::weak_ptr<ColorSet>(); +}; + class SFX2_DLLPUBLIC ColorSets { - std::vector<ColorSet> maColorSets; + std::vector<std::shared_ptr<ColorSet>> maColorSets; + std::vector<std::shared_ptr<VirtualThemeColorSet>> maVirtualThemeColorSets; + // TEMP: should remove sal_Int32 mnThemeColorSetIndex; public: ColorSets(); ~ColorSets(); - static ColorSets& get() - { - static ColorSets aColorSetsInstance; - return aColorSetsInstance; - } - + // TEMP: should remove const ColorSet& getThemeColorSet() const { return getColorSet(mnThemeColorSetIndex); } + // TEMP: should remove 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 std::vector<std::shared_ptr<ColorSet>>& getColorSets() const { return maColorSets; } + const ColorSet& getColorSet(sal_Int32 nIndex) const { return *maColorSets[nIndex]; } + const std::shared_ptr<ColorSet>& getColorSetPtr(sal_Int32 nIndex) const + { + return maColorSets[nIndex]; + } const ColorSet& getColorSet(std::u16string_view rName) const; + const std::shared_ptr<ColorSet>& getColorSetPtr(std::u16string_view rName) const; int addColorSet(const ColorSet& rColorSet) { - maColorSets.push_back(rColorSet); + maColorSets.emplace_back(std::make_shared<ColorSet>(rColorSet)); return maColorSets.size() - 1; } + + std::shared_ptr<VirtualThemeColorSet>& getVirtualColorSet(int nVirtualColorSetIndex) + { + return maVirtualThemeColorSets[nVirtualColorSetIndex]; + } + + sal_Int32 getVirtualColorSetIndex(const std::weak_ptr<VirtualThemeColorSet>& pVirtualColorSet) + { + if (auto aIt = std::find_if( + maVirtualThemeColorSets.begin(), maVirtualThemeColorSets.end(), + [pVirtualColorSet](std::shared_ptr<VirtualThemeColorSet>& pVirtualColorSet_) { + return pVirtualColorSet_.get() == pVirtualColorSet.lock().get(); + }); + aIt != maVirtualThemeColorSets.end()) + { + return aIt - maVirtualThemeColorSets.begin(); + } + return -1; + } + + int addVirtualThemeColorSet(int nIndexColorSetToReference) + { + maVirtualThemeColorSets.emplace_back( + std::make_shared<VirtualThemeColorSet>(getColorSetPtr(nIndexColorSetToReference))); + return maVirtualThemeColorSets.size() - 1; + } }; class SFX2_DLLPUBLIC SfxColorSetListItem final : public SfxPoolItem diff --git a/include/sfx2/sfxbasemodel.hxx b/include/sfx2/sfxbasemodel.hxx index b96e8e25c786..6e22c98fb60e 100644 --- a/include/sfx2/sfxbasemodel.hxx +++ b/include/sfx2/sfxbasemodel.hxx @@ -669,7 +669,8 @@ public: virtual sal_Bool SAL_CALL canCheckIn( ) override; // XColorSetsManager - virtual void SAL_CALL addNewColorSet(const OUString& rColorSetName, const css::uno::Sequence<css::util::Color>& rColorSetColors) override; + virtual sal_Int32 SAL_CALL addNewColorSet(const OUString& rColorSetName, const css::uno::Sequence<css::util::Color>& rColorSetColors) override; + virtual sal_Int32 SAL_CALL createVirtualThemeColorSet( sal_Int32 nIndexColorSetToReference ) override; /// @throws css::uno::RuntimeException bool getBoolPropertyValue( const OUString& rName ); diff --git a/offapi/com/sun/star/document/XColorSetsManager.idl b/offapi/com/sun/star/document/XColorSetsManager.idl index 5e16df71e06b..7e6e7690d5a9 100644 --- a/offapi/com/sun/star/document/XColorSetsManager.idl +++ b/offapi/com/sun/star/document/XColorSetsManager.idl @@ -15,8 +15,8 @@ module com { module sun { module star { module document { interface XColorSetsManager: com::sun::star::uno::XInterface { - /* definitions of colorset functions here*/ - void addNewColorSet( [in] string ColorSetName, [in] sequence < com::sun::star::util::Color > ColorSetColors ); + long addNewColorSet( [in] string ColorSetName, [in] sequence < com::sun::star::util::Color > ColorSetColors ); + long createVirtualThemeColorSet( [in] long IndexColorSetToReference ); }; }; }; }; }; diff --git a/oox/source/drawingml/clrscheme.cxx b/oox/source/drawingml/clrscheme.cxx index cb3e9104855d..311bbdc8e4a8 100644 --- a/oox/source/drawingml/clrscheme.cxx +++ b/oox/source/drawingml/clrscheme.cxx @@ -103,7 +103,7 @@ bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const return true; } -std::vector<::Color> ClrScheme::getColorVector() +std::vector<::Color> ClrScheme::getColorVector() const { // most likely should reorder using tokens here... // this is a experimental hack: @@ -117,7 +117,7 @@ std::vector<::Color> ClrScheme::getColorVector() return aColors; } -std::vector<sal_Int32> ClrScheme::getColorVectorAsInts() +std::vector<sal_Int32> ClrScheme::getColorVectorAsInts() const { // most likely should reorder using tokens here... // this is a experimental hack: diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 78a482abd446..c4a411ee2aaa 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1921,7 +1921,7 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& ThemePtr pTheme = pPowerPointImport->getActualSlidePersist()->getTheme(); rFilter.importFragment(new ThemeOverrideFragmentHandler( rFilter, aThemeOverrideFragmentPath, *pTheme), xDoc); - pPowerPointImport->getActualSlidePersist()->setTheme(pTheme); + pPowerPointImport->getActualSlidePersist()->setTheme(pTheme, rFilter); } // convert imported chart model to chart document diff --git a/oox/source/drawingml/textcharacterproperties.cxx b/oox/source/drawingml/textcharacterproperties.cxx index e6faa9cd64bb..06df4379d47b 100644 --- a/oox/source/drawingml/textcharacterproperties.cxx +++ b/oox/source/drawingml/textcharacterproperties.cxx @@ -30,8 +30,10 @@ #include <oox/helper/propertyset.hxx> #include <oox/core/xmlfilterbase.hxx> #include <oox/drawingml/drawingmltypes.hxx> +#include <oox/ppt/pptimport.hxx> #include <oox/token/properties.hxx> #include <oox/token/tokens.hxx> +#include <optional> using ::oox::core::XmlFilterBase; using namespace ::com::sun::star; @@ -114,6 +116,16 @@ void TextCharacterProperties::pushToPropMap( PropertyMap& rPropMap, const XmlFil // set color theme index rPropMap.setProperty(PROP_CharColorThemeColorIndex, aColor.getSchemeColorIndex()); rPropMap.setProperty(PROP_CharColorTintOrShade, aColor.getTintOrShade()); + if (const ::oox::ppt::PowerPointImport* pPowerPointImport + = dynamic_cast<const ::oox::ppt::PowerPointImport*>(&rFilter)) + { + if (std::optional<sal_Int32> oVirtualColorSetIndex + = pPowerPointImport->getActualSlidePersist()->getVirtualThemeColorSetIndex()) + { + rPropMap.setProperty(PROP_CharColorVirtualThemeColorSetIndex, + oVirtualColorSetIndex.value()); + } + } if (aColor.hasTransparency()) { diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index 9aabd45d18af..66c94fe6b06d 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -45,6 +45,7 @@ #include <oox/drawingml/themefragmenthandler.hxx> #include <drawingml/textliststylecontext.hxx> #include <oox/helper/attributelist.hxx> +#include <oox/helper/propertyset.hxx> #include <oox/ole/olestorage.hxx> #include <oox/ole/vbaproject.hxx> #include <oox/ppt/pptshape.hxx> @@ -53,6 +54,7 @@ #include <oox/ppt/layoutfragmenthandler.hxx> #include <oox/ppt/pptimport.hxx> #include <oox/token/namespaces.hxx> +#include <oox/token/properties.hxx> #include <oox/token/tokens.hxx> #include <com/sun/star/office/XAnnotation.hpp> @@ -355,7 +357,6 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage if( aIter2 == rThemes.end() ) { oox::drawingml::ThemePtr pThemePtr = std::make_shared<oox::drawingml::Theme>(); - pMasterPersistPtr->setTheme( pThemePtr ); Reference<xml::dom::XDocument> xDoc= rFilter.importFragment(aThemeFragmentPath); @@ -367,11 +368,12 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage UNO_QUERY_THROW)); rThemes[ aThemeFragmentPath ] = pThemePtr; pThemePtr->setFragment(xDoc); + pMasterPersistPtr->setTheme(pThemePtr, rFilter); saveThemeToGrabBag(pThemePtr, nIndex + 1); } else { - pMasterPersistPtr->setTheme( (*aIter2).second ); + pMasterPersistPtr->setTheme( (*aIter2).second, rFilter ); } } importSlide( xMasterFragmentHandler, pMasterPersistPtr ); @@ -385,7 +387,7 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage // importing slide page if (pMasterPersistPtr) { pSlidePersistPtr->setMasterPersist( pMasterPersistPtr ); - pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() ); + pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme(), rFilter ); Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY ); if( xMasterPageTarget.is() ) xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() ); diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx index ae9f0f567a7c..d270b2ade9fe 100644 --- a/oox/source/ppt/slidepersist.cxx +++ b/oox/source/ppt/slidepersist.cxx @@ -21,10 +21,12 @@ #include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/frame/XModel.hpp> +#include <comphelper/sequence.hxx> #include <oox/ppt/timenode.hxx> #include <oox/ppt/pptshape.hxx> #include <oox/ppt/slidepersist.hxx> #include <drawingml/fillproperties.hxx> +#include <oox/drawingml/theme.hxx> #include <oox/drawingml/shapepropertymap.hxx> #include <oox/helper/propertymap.hxx> #include <oox/helper/propertyset.hxx> @@ -35,8 +37,11 @@ #include <drawingml/textliststyle.hxx> #include <drawingml/textparagraphproperties.hxx> +#include <sfx2/ColorSets.hxx> + #include <osl/diagnose.h> +#include <com/sun/star/document/XColorSetsManager.hpp> #include <com/sun/star/style/XStyle.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/container/XNamed.hpp> @@ -330,6 +335,33 @@ Reference<XAnimationNode> SlidePersist::getAnimationNode(const OUString& sId) co return aResult; } +void SlidePersist::setTheme(const oox::drawingml::ThemePtr& rThemePtr, + const oox::core::XmlFilterBase& rFilterBase) +{ + const auto& xModel = rFilterBase.getModel(); + mpThemePtr = rThemePtr; + + if (isMasterPage()) + { + css::uno::Reference<css::document::XColorSetsManager> xColorSetsManager( + xModel, css::uno::UNO_QUERY_THROW); + + const OUString& rThemeName = mpThemePtr->getStyleName(); + const drawingml::ClrScheme& rColorScheme = mpThemePtr->getClrScheme(); + + auto nColorSetIndex = xColorSetsManager->addNewColorSet( + rThemeName, comphelper::containerToSequence(rColorScheme.getColorVectorAsInts())); + + moVirtualColorSetIndex + = xColorSetsManager->createVirtualThemeColorSet(nColorSetIndex); + } + else + { + // share master's virtual color set + moVirtualColorSetIndex = getMasterPersist()->getVirtualThemeColorSetIndex(); + } +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index cc9068c23a07..43b8ad6b3bc7 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -56,6 +56,7 @@ CharColor CharContoured CharColorThemeColorIndex CharColorTintOrShade +CharColorVirtualThemeColorSetIndex CharEscapement CharEscapementHeight CharFontCharSet diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 3178aa601718..6407a4235bcd 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -2736,7 +2736,7 @@ void SfxBaseModel::loadCmisProperties( ) } } -void SAL_CALL SfxBaseModel::addNewColorSet(const OUString& rColorSetName, +sal_Int32 SAL_CALL SfxBaseModel::addNewColorSet(const OUString& rColorSetName, const css::uno::Sequence<css::util::Color>& rColorSetColors) { if(SfxObjectShell* pObjShell = GetObjectShell()) @@ -2752,12 +2752,21 @@ void SAL_CALL SfxBaseModel::addNewColorSet(const OUString& rColorSetName, ColorSets& rColorSets = pColorSetItem->GetSfxColorSetList(); - // let's force it as the selected color set for the moment. - rColorSets.setThemeColorSet( rColorSets.addColorSet(aColorSet) ); + // let's force it as the selected "theme" color set for the moment. + int nColorSetIndex = rColorSets.addColorSet(aColorSet); + rColorSets.setThemeColorSet( nColorSetIndex ); + return nColorSetIndex; } } } +sal_Int32 SAL_CALL SfxBaseModel::createVirtualThemeColorSet( sal_Int32 nIndexColorSetToReference ) +{ + SfxObjectShell* pObjShell = GetObjectShell(); + const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS); + return pColorSetItem->GetSfxColorSetList().addVirtualThemeColorSet(nIndexColorSetToReference); +} + SfxMedium* SfxBaseModel::handleLoadError( ErrCode nError, SfxMedium* pMedium ) { if (!nError) diff --git a/sfx2/source/styles/ColorSets.cxx b/sfx2/source/styles/ColorSets.cxx index ac0088311c93..96b9370978f7 100644 --- a/sfx2/source/styles/ColorSets.cxx +++ b/sfx2/source/styles/ColorSets.cxx @@ -8,6 +8,7 @@ * */ +#include <memory> #include <sfx2/ColorSets.hxx> ColorSet::ColorSet(OUString const& aColorSetName) @@ -18,6 +19,7 @@ ColorSet::ColorSet(OUString const& aColorSetName) ColorSets::ColorSets() : maColorSets() + , maVirtualThemeColorSets() , mnThemeColorSetIndex(0) { { @@ -34,7 +36,7 @@ ColorSets::ColorSets() aColorSet.add(9, 0x2ECC71); aColorSet.add(10, 0x1D99F3); aColorSet.add(11, 0x3DAEE9); - maColorSets.push_back(aColorSet); + addColorSet(aColorSet); } { ColorSet aColorSet("Material Blue"); @@ -50,7 +52,7 @@ ColorSets::ColorSets() aColorSet.add(9, 0x0277BD); aColorSet.add(10, 0x4DD0E1); aColorSet.add(11, 0x0097A7); - maColorSets.push_back(aColorSet); + addColorSet(aColorSet); } { ColorSet aColorSet("Material Red"); @@ -66,7 +68,7 @@ ColorSets::ColorSets() aColorSet.add(9, 0xD50000); aColorSet.add(10, 0xE91E63); aColorSet.add(11, 0xC51162); - maColorSets.push_back(aColorSet); + addColorSet(aColorSet); } { ColorSet aColorSet("Material Green"); @@ -82,7 +84,7 @@ ColorSets::ColorSets() aColorSet.add(9, 0x64dd17); aColorSet.add(10, 0xcddc39); aColorSet.add(11, 0xaeea00); - maColorSets.push_back(aColorSet); + addColorSet(aColorSet); } } @@ -90,9 +92,19 @@ ColorSets::~ColorSets() {} const ColorSet& ColorSets::getColorSet(std::u16string_view rName) const { - for (const ColorSet& rColorSet : maColorSets) + for (const std::shared_ptr<ColorSet>& rColorSet : maColorSets) { - if (rColorSet.getName() == rName) + if (rColorSet->getName() == rName) + return *rColorSet; + } + return *maColorSets[0]; +} + +const std::shared_ptr<ColorSet>& ColorSets::getColorSetPtr(std::u16string_view rName) const +{ + for (const std::shared_ptr<ColorSet>& rColorSet : maColorSets) + { + if (rColorSet->getName() == rName) return rColorSet; } return maColorSets[0]; @@ -104,8 +116,11 @@ void ColorSets::setThemeColorSet(std::u16string_view rName) { for (sal_uInt32 nIndex = 0; nIndex < maColorSets.size(); ++nIndex) { - if (maColorSets[nIndex].getName() == rName) + if (maColorSets[nIndex]->getName() == rName) + { mnThemeColorSetIndex = nIndex; + break; + } } } diff --git a/svx/source/unodraw/unoprov.cxx b/svx/source/unodraw/unoprov.cxx index 8c4787a19c14..5b2725895f25 100644 --- a/svx/source/unodraw/unoprov.cxx +++ b/svx/source/unodraw/unoprov.cxx @@ -581,6 +581,7 @@ static SfxItemPropertyMapEntry const * ImplGetSvxControlShapePropertyMap() { u"" UNO_NAME_EDIT_CHAR_COLOR, 0, cppu::UnoType<sal_Int32>::get(), 0, MID_COLOR_RGB }, { u"" UNO_NAME_EDIT_CHAR_COLOR_THEME_COLOR_INDEX, 0, cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_THEME_INDEX }, { u"" UNO_NAME_EDIT_CHAR_COLOR_TINT_OR_SHADE, 0, cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_TINT_OR_SHADE }, + { u"" UNO_NAME_EDIT_CHAR_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX, 0, cppu::UnoType<sal_Int32>::get(), 0, MID_COLOR_VIRTUAL_THEME_COLOR_SET_INDEX }, { u"CharBackColor", 0, cppu::UnoType<sal_Int32>::get(), 0, 0 }, { u"CharBackTransparent", 0, cppu::UnoType<bool>::get(), 0, 0 }, { u"CharRelief", 0, cppu::UnoType<sal_Int16>::get(), 0, 0 }, diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index a9ddb4af0c83..528f6280ea52 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -8,6 +8,7 @@ * */ +#include <memory> #include <sal/config.h> #include "ThemePanel.hxx" @@ -467,10 +468,10 @@ ThemePanel::ThemePanel(weld::Widget* pParent) } - const std::vector<ColorSet>& aColorSets = maColorSets->getColorSets(); + const std::vector<std::shared_ptr<ColorSet>>& aColorSets = maColorSets->getColorSets(); for (size_t i = 0; i < aColorSets.size(); ++i) { - const ColorSet& rColorSet = aColorSets[i]; + const ColorSet& rColorSet = *aColorSets[i]; const OUString& aName = rColorSet.getName(); BitmapEx aPreview = GenerateColorPreview(rColorSet);