From 9cbc3a64492e0670427f17b753d0908657c8c5bd Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 26 Jan 2023 21:19:31 +0900 Subject: use ThemeColorChanger also in svx, when changing theme for SdrPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This refactors the code in the Theme class to remove code that is responsible for changing the color for the SdrPage and adds an implementation of IThemeColorChanger - svx::ThemeColorChanger, that is performing the same task from now on. The svx::ThemeColorChanger is also partially used in Writer by sw::ThemeColorChanger, when it needs to change the colors in the common (Sdr) objects. Change-Id: I39cfa278d31bdd802a5bf36eeaf6d472c8013dba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146173 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- svx/source/styles/ColorSets.cxx | 104 +--------------------------------------- 1 file changed, 2 insertions(+), 102 deletions(-) (limited to 'svx/source/styles') diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 66a5e3e91016..eada260cf076 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -11,15 +11,9 @@ #include #include +#include #include - -#include -#include -#include -#include -#include - #include #include #include @@ -28,86 +22,10 @@ #include #include #include -#include +#include using namespace com::sun::star; -namespace -{ -/// Updates a text portion to match a new color set, in case it already uses theme colors. -void UpdateTextPortionColorSet(const uno::Reference& xPortion, - const svx::ColorSet& rColorSet) -{ - if (!xPortion->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE)) - return; - - uno::Reference xThemeColor; - xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = rColorSet.resolveColor(aThemeColor); - xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::Any(static_cast(aColor))); -} - -void UpdateFillColorSet(const uno::Reference& xShape, const svx::ColorSet& rColorSet) -{ - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) - return; - - uno::Reference xThemeColor; - xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = rColorSet.resolveColor(aThemeColor); - xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast(aColor))); -} - -void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) -{ - const svx::ColorSet* pColorSet = pTheme->GetColorSet(); - if (!pColorSet) - { - return; - } - - uno::Reference xShape = pObject->getUnoShape(); - uno::Reference xShapeText(xShape, uno::UNO_QUERY); - if (xShapeText.is()) - { - // E.g. group shapes have no text. - uno::Reference xText(xShapeText->getText(), uno::UNO_QUERY); - uno::Reference xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) - { - uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); - uno::Reference xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) - { - uno::Reference xPortion(xPortions->nextElement(), uno::UNO_QUERY); - UpdateTextPortionColorSet(xPortion, *pColorSet); - } - } - } - - uno::Reference xShapeProps(xShape, uno::UNO_QUERY); - UpdateFillColorSet(xShapeProps, *pColorSet); -} -} - namespace svx { @@ -403,24 +321,6 @@ std::unique_ptr Theme::FromAny(const css::uno::Any& rVal) return pTheme; } -void Theme::UpdateSdrPage(const SdrPage* pPage) -{ - for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject) - { - SdrObject* pObject = pPage->GetObj(nObject); - UpdateSdrObject(this, pObject); - SdrObjList* pList = pObject->GetSubList(); - if (pList) - { - SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); - while (aIter.IsMore()) - { - UpdateSdrObject(this, aIter.Next()); - } - } - } -} - std::vector Theme::GetColors() const { if (!mpColorSet) -- cgit