include/svx/ColorSets.hxx                                   |    2 
 include/svx/theme/IThemeColorChanger.hxx                    |    2 
 include/svx/theme/ThemeColorChanger.hxx                     |   39 ++
 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |    8 
 svx/Library_svxcore.mk                                      |    1 
 svx/source/styles/ColorSets.cxx                             |  104 -------
 svx/source/svdraw/svdpage.cxx                               |    6 
 svx/source/theme/ThemeColorChanger.cxx                      |  161 ++++++++++++
 sw/source/core/inc/ThemeColorChanger.hxx                    |    8 
 sw/source/core/model/ThemeColorChanger.cxx                  |  106 -------
 sw/source/filter/xml/xmlexp.hxx                             |    3 
 sw/source/filter/xml/xmlfmte.cxx                            |   77 +++++
 12 files changed, 306 insertions(+), 211 deletions(-)

New commits:
commit 9cbc3a64492e0670427f17b753d0908657c8c5bd
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jan 26 21:19:31 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 27 01:41:08 2023 +0000

    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 <qui...@gmail.com>

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)
 {
commit 6d1413da02602992b42b62bda9a26ffeb774b603
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jan 26 18:09:06 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jan 27 01:40:59 2023 +0000

    xmloff: export Theme for ODT (Writer) documents
    
    Exports the Theme set on the one and only SdrPage for ODT (Writer)
    documents. The theme is exported as a sub-element of "style".
    This differs to ODP (Impress) documents, which export the Theme
    as part of the master-page element.
    
    Currently the code is duplicated, because the theme can't yet be
    accessed inside xmloff in a non-conflicting way (creating conflicts
    between modules), which will be fixed in the future.
    
    Change-Id: I0e440d14724b49e7d86e9deabc6615a91e8cd31a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146172
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index 4606e1cc282c..98e6015ad23f 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -3285,6 +3285,14 @@ 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
       </rng:optional>
     </rng:element>
   </rng:define>
+
+  <!-- TODO no proposal -->
+  <rng:define name="style-style" combine="interleave">
+      <rng:optional>
+        <rng:ref name="loext-theme"/>
+      </rng:optional>
+  </rng:define>
+
   <rng:define name="style-master-page" combine="choice">
     <rng:element name="style:master-page">
       <rng:ref name="style-master-page-attlist"/>
diff --git a/sw/source/filter/xml/xmlexp.hxx b/sw/source/filter/xml/xmlexp.hxx
index f8cef9c40f76..1da84af86f03 100644
--- a/sw/source/filter/xml/xmlexp.hxx
+++ b/sw/source/filter/xml/xmlexp.hxx
@@ -90,6 +90,9 @@ class SwXMLExport : public SvXMLExport
                            SwXMLTableInfo_Impl& rTableInfo,
                            sal_uInt32 nHeaderRows = 0 );
 
+    void ExportThemeElement(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPage);
+
+
     virtual void ExportMeta_() override;
     virtual void ExportFontDecls_() override;
     virtual void ExportStyles_( bool bUsed ) override;
diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx
index 7dc23bb11b54..f3c4ca04ddfd 100644
--- a/sw/source/filter/xml/xmlfmte.cxx
+++ b/sw/source/filter/xml/xmlfmte.cxx
@@ -34,9 +34,20 @@
 #include <pagedesc.hxx>
 #include <cellatr.hxx>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/Color.hpp>
 #include "xmlexp.hxx"
 #include <SwStyleNameMapper.hxx>
 #include <osl/diagnose.h>
+#include <comphelper/sequenceashashmap.hxx>
+#include <sax/tools/converter.hxx>
+
+#include <o3tl/enumrange.hxx>
+#include <svx/ColorSets.hxx>
+#include <svx/unoapi.hxx>
+#include <svx/svdpage.hxx>
+#include <docmodel/theme/ThemeColor.hxx>
+
 
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::uno;
@@ -169,6 +180,72 @@ void SwXMLExport::ExportStyles_( bool bUsed )
     GetShapeExport()->GetShapeTableExport()->exportTableStyles();
     //page defaults
     GetPageExport()->exportDefaultStyle();
+
+    // Theme
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), 
UNO_QUERY);
+    if (xDrawPageSupplier.is())
+    {
+        uno::Reference<drawing::XDrawPage> xPage = 
xDrawPageSupplier->getDrawPage();
+        if (xPage.is())
+            ExportThemeElement(xPage);
+    }
+}
+
+void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& 
xDrawPage)
+{
+    if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
+    {
+        // Do not export in standard ODF 1.3 or older.
+        return;
+    }
+
+    SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
+    SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
+
+    if (!pPage)
+        return;
+
+    auto* pTheme = pPage->getSdrPageProperties().GetTheme();
+    if (!pTheme)
+        return;
+
+    if (!pTheme->GetName().isEmpty())
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName());
+    SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, 
true);
+
+    auto* pColorSet = pTheme->GetColorSet();
+    if (!pColorSet->getName().isEmpty())
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName());
+    SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, 
XML_COLOR_TABLE, true, true);
+
+    static const XMLTokenEnum aColorTokens[] =
+    {
+        XML_DK1, // Text 1
+        XML_LT1, // Background 1
+        XML_DK2, // Text 2
+        XML_LT2, // Background 2
+        XML_ACCENT1,
+        XML_ACCENT2,
+        XML_ACCENT3,
+        XML_ACCENT4,
+        XML_ACCENT5,
+        XML_ACCENT6,
+        XML_HLINK, // Hyperlink
+        XML_FOLHLINK, // Followed hyperlink
+    };
+
+    for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
+    {
+        if (eThemeColorType == model::ThemeColorType::Unknown)
+            continue;
+
+        auto nColor = size_t(eThemeColorType);
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, 
GetXMLToken(aColorTokens[nColor]));
+        OUStringBuffer sValue;
+        sax::Converter::convertColor(sValue, 
pColorSet->getColor(eThemeColorType));
+        AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR, 
sValue.makeStringAndClear());
+        SvXMLElementExport aColor(*this, XML_NAMESPACE_LO_EXT, XML_COLOR, 
true, true);
+    }
 }
 
 void SwXMLExport::collectAutoStyles()

Reply via email to