diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-26 21:19:31 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-01-27 01:41:08 +0000 |
commit | 9cbc3a64492e0670427f17b753d0908657c8c5bd (patch) | |
tree | c07c8313c0c1ce4429ad2babacf2fe0287b26bd2 /svx/source/styles | |
parent | 6d1413da02602992b42b62bda9a26ffeb774b603 (diff) |
use ThemeColorChanger also in svx, when changing theme for SdrPage
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 <quikee@gmail.com>
Diffstat (limited to 'svx/source/styles')
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 104 |
1 files changed, 2 insertions, 102 deletions
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 <svx/ColorSets.hxx> #include <sstream> +#include <utility> #include <libxml/xmlwriter.h> - -#include <com/sun/star/util/Color.hpp> -#include <com/sun/star/text/XTextRange.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XEnumeration.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> - #include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequence.hxx> #include <sal/log.hxx> @@ -28,86 +22,10 @@ #include <editeng/unoprnms.hxx> #include <docmodel/uno/UnoThemeColor.hxx> #include <o3tl/enumrange.hxx> -#include <utility> +#include <com/sun/star/util/Color.hpp> 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<beans::XPropertySet>& xPortion, - const svx::ColorSet& rColorSet) -{ - if (!xPortion->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> 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<sal_Int32>(aColor))); -} - -void UpdateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape, const svx::ColorSet& rColorSet) -{ - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> 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<sal_Int32>(aColor))); -} - -void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) -{ - const svx::ColorSet* pColorSet = pTheme->GetColorSet(); - if (!pColorSet) - { - return; - } - - uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); - uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); - if (xShapeText.is()) - { - // E.g. group shapes have no text. - uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) - { - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) - { - uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); - UpdateTextPortionColorSet(xPortion, *pColorSet); - } - } - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); - UpdateFillColorSet(xShapeProps, *pColorSet); -} -} - namespace svx { @@ -403,24 +321,6 @@ std::unique_ptr<Theme> 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<Color> Theme::GetColors() const { if (!mpColorSet) |