summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svx/ColorSets.hxx2
-rw-r--r--include/svx/theme/IThemeColorChanger.hxx2
-rw-r--r--include/svx/theme/ThemeColorChanger.hxx39
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/source/styles/ColorSets.cxx104
-rw-r--r--svx/source/svdraw/svdpage.cxx6
-rw-r--r--svx/source/theme/ThemeColorChanger.cxx161
-rw-r--r--sw/source/core/inc/ThemeColorChanger.hxx8
-rw-r--r--sw/source/core/model/ThemeColorChanger.cxx106
9 files changed, 218 insertions, 211 deletions
diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index 4c6666833a14..68da92152431 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -244,8 +244,6 @@ public:
static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal);
- void UpdateSdrPage(const SdrPage* pPage);
-
std::vector<Color> GetColors() const;
Color GetColor(model::ThemeColorType eType) const;
diff --git a/include/svx/theme/IThemeColorChanger.hxx b/include/svx/theme/IThemeColorChanger.hxx
index 5f90f273ee37..93cba5870b96 100644
--- a/include/svx/theme/IThemeColorChanger.hxx
+++ b/include/svx/theme/IThemeColorChanger.hxx
@@ -14,7 +14,7 @@
namespace svx
{
-class SVX_DLLPUBLIC IThemeColorChanger
+class SVXCORE_DLLPUBLIC IThemeColorChanger
{
public:
virtual ~IThemeColorChanger() = default;
diff --git a/include/svx/theme/ThemeColorChanger.hxx b/include/svx/theme/ThemeColorChanger.hxx
new file mode 100644
index 000000000000..cf4071824d9c
--- /dev/null
+++ b/include/svx/theme/ThemeColorChanger.hxx
@@ -0,0 +1,39 @@
+/* -*- 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 <svx/svxdllapi.h>
+#include <svx/theme/IThemeColorChanger.hxx>
+#include <svx/ColorSets.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdobj.hxx>
+
+namespace svx
+{
+namespace theme
+{
+SVXCORE_DLLPUBLIC void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject);
+}
+
+class SVXCORE_DLLPUBLIC ThemeColorChanger : public IThemeColorChanger
+{
+private:
+ SdrPage* mpPage;
+
+public:
+ ThemeColorChanger(SdrPage* pPage);
+ virtual ~ThemeColorChanger() override;
+
+ void apply(svx::ColorSet const& rColorSet) override;
+};
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 439ae516427c..9ecc9ec58fc4 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -428,6 +428,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/table/tablerows \
svx/source/table/tableundo \
svx/source/table/viewcontactoftableobj \
+ svx/source/theme/ThemeColorChanger \
svx/source/tbxctrls/extrusioncontrols \
svx/source/tbxctrls/fontworkgallery \
svx/source/tbxctrls/linectrl \
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)
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index a4c804f53e12..7ec883e397c5 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -44,6 +44,7 @@
#include <svx/svdundo.hxx>
#include <svx/xfillit0.hxx>
#include <svx/fmdpage.hxx>
+#include <svx/theme/ThemeColorChanger.hxx>
#include <sdr/contact/viewcontactofsdrpage.hxx>
#include <svx/sdr/contact/viewobjectcontact.hxx>
@@ -1291,7 +1292,7 @@ void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme)
{
mpTheme = std::move(pTheme);
- if (mpTheme && mpSdrPage->IsMasterPage())
+ if (mpTheme && mpTheme->GetColorSet() && mpSdrPage->IsMasterPage())
{
SdrModel& rModel = mpSdrPage->getSdrModelFromSdrPage();
sal_uInt16 nPageCount = rModel.GetPageCount();
@@ -1303,7 +1304,8 @@ void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme)
continue;
}
- mpTheme->UpdateSdrPage(pPage);
+ svx::ThemeColorChanger aChanger(pPage);
+ aChanger.apply(*mpTheme->GetColorSet());
}
}
}
diff --git a/svx/source/theme/ThemeColorChanger.cxx b/svx/source/theme/ThemeColorChanger.cxx
new file mode 100644
index 000000000000..677a0446451a
--- /dev/null
+++ b/svx/source/theme/ThemeColorChanger.cxx
@@ -0,0 +1,161 @@
+/* -*- 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/theme/ThemeColorChanger.hxx>
+
+#include <sal/config.h>
+#include <svx/svdpage.hxx>
+#include <svx/svditer.hxx>
+#include <editeng/unoprnms.hxx>
+#include <docmodel/uno/UnoThemeColor.hxx>
+
+#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 <com/sun/star/util/XThemeColor.hpp>
+
+using namespace css;
+
+namespace svx
+{
+namespace theme
+{
+namespace
+{
+/// Updates text portion property colors
+void updateTextPortionColorSet(svx::ColorSet const& rColorSet,
+ const uno::Reference<beans::XPropertySet>& xPortion)
+{
+ 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)));
+}
+
+/// Updates the fill property colors
+void updateFillColorSet(svx::ColorSet const& rColorSet,
+ const uno::Reference<beans::XPropertySet>& xShape)
+{
+ 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)));
+}
+
+/// Updates the line property colors
+void updateLineColorSet(svx::ColorSet const& rColorSet,
+ const uno::Reference<beans::XPropertySet>& xShape)
+{
+ if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE))
+ return;
+
+ uno::Reference<util::XThemeColor> xThemeColor;
+ xShape->getPropertyValue(UNO_NAME_LINECOLOR_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_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor)));
+}
+
+} // end anonymous namespace
+
+/// Updates properties of the SdrObject
+void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject)
+{
+ 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(rColorSet, xPortion);
+ }
+ }
+ }
+
+ uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+ updateFillColorSet(rColorSet, xShapeProps);
+ updateLineColorSet(rColorSet, xShapeProps);
+}
+
+} // end theme
+
+ThemeColorChanger::ThemeColorChanger(SdrPage* pPage)
+ : mpPage(pPage)
+{
+}
+
+ThemeColorChanger::~ThemeColorChanger() = default;
+
+void ThemeColorChanger::apply(svx::ColorSet const& rColorSet)
+{
+ for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject)
+ {
+ SdrObject* pObject = mpPage->GetObj(nObject);
+ theme::updateSdrObject(rColorSet, pObject);
+
+ // update child objects
+ SdrObjList* pList = pObject->GetSubList();
+ if (pList)
+ {
+ SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups);
+ while (aIter.IsMore())
+ {
+ theme::updateSdrObject(rColorSet, aIter.Next());
+ }
+ }
+ }
+}
+
+} // end svx namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/ThemeColorChanger.hxx b/sw/source/core/inc/ThemeColorChanger.hxx
index d4ba7a9fcad5..a246f17453a1 100644
--- a/sw/source/core/inc/ThemeColorChanger.hxx
+++ b/sw/source/core/inc/ThemeColorChanger.hxx
@@ -11,7 +11,7 @@
#include <docsh.hxx>
#include <svx/ColorSets.hxx>
-#include <svx/theme/IThemeColorChanger.hxx>
+#include <svx/theme/ThemeColorChanger.hxx>
namespace sw
{
@@ -21,11 +21,7 @@ private:
SwDocShell* mpDocSh;
public:
- ThemeColorChanger(SwDocShell* pDocSh)
- : mpDocSh(pDocSh)
- {
- }
-
+ ThemeColorChanger(SwDocShell* pDocSh);
virtual ~ThemeColorChanger() override;
void apply(svx::ColorSet const& rColorSet) override;
diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx
index 87f1901083c4..dc9a7fe1c86c 100644
--- a/sw/source/core/model/ThemeColorChanger.cxx
+++ b/sw/source/core/model/ThemeColorChanger.cxx
@@ -97,105 +97,10 @@ public:
updateHints(pNode->GetTextNode());
}
- /// Updates text portion property colors
- void updateTextPortionColorSet(const uno::Reference<beans::XPropertySet>& xPortion)
- {
- 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 = mrColorSet.resolveColor(aThemeColor);
- xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR,
- uno::Any(static_cast<sal_Int32>(aColor)));
- }
-
- /// Updates the fill property colors
- void updateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape)
- {
- 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 = mrColorSet.resolveColor(aThemeColor);
- xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor)));
- }
-
- /// Updates the line property colors
- void updateLineColorSet(const uno::Reference<beans::XPropertySet>& xShape)
- {
- if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE))
- return;
-
- uno::Reference<util::XThemeColor> xThemeColor;
- xShape->getPropertyValue(UNO_NAME_LINECOLOR_THEME_REFERENCE) >>= xThemeColor;
- if (!xThemeColor.is())
- return;
-
- model::ThemeColor aThemeColor;
- model::theme::setFromXThemeColor(aThemeColor, xThemeColor);
-
- if (aThemeColor.getType() == model::ThemeColorType::Unknown)
- return;
-
- Color aColor = mrColorSet.resolveColor(aThemeColor);
- xShape->setPropertyValue(UNO_NAME_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor)));
- }
-
- /// Updates properties of the SdrObject
- void updateSdrObject(SdrObject* pObject)
- {
- 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);
- }
- }
- }
-
- uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
- updateFillColorSet(xShapeProps);
- updateLineColorSet(xShapeProps);
- }
-
void handleSdrObject(SdrObject* pObject) override
{
// update current object
- updateSdrObject(pObject);
+ svx::theme::updateSdrObject(mrColorSet, pObject);
// update child objects
SdrObjList* pList = pObject->GetSubList();
@@ -204,7 +109,7 @@ public:
SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups);
while (aIter.IsMore())
{
- updateSdrObject(aIter.Next());
+ svx::theme::updateSdrObject(mrColorSet, aIter.Next());
}
}
}
@@ -230,7 +135,12 @@ void changeColor(SwFormat* pFormat, svx::ColorSet const& rColorSet, SwDoc* pDocu
} // end anonymous namespace
-ThemeColorChanger::~ThemeColorChanger() {}
+ThemeColorChanger::ThemeColorChanger(SwDocShell* pDocSh)
+ : mpDocSh(pDocSh)
+{
+}
+
+ThemeColorChanger::~ThemeColorChanger() = default;
void ThemeColorChanger::apply(svx::ColorSet const& rColorSet)
{