include/xmloff/xmlexp.hxx                 |    4 +
 sc/inc/unonames.hxx                       |    1 
 sc/qa/extras/scspreadsheetsettingsobj.cxx |   19 +-----
 sc/qa/unit/ThemeImportExportTest.cxx      |   85 +++++++++++++++++++++++++++++-
 sc/source/filter/xml/xmlexprt.cxx         |   21 +++++++
 sc/source/filter/xml/xmlexprt.hxx         |    2 
 sc/source/ui/unoobj/docuno.cxx            |   23 ++++++++
 sw/source/filter/xml/xmlexp.hxx           |    3 -
 sw/source/filter/xml/xmlfmte.cxx          |   61 +++------------------
 xmloff/inc/XMLThemeContext.hxx            |    6 +-
 xmloff/source/core/xmlexp.cxx             |   48 ++++++++++++++++
 xmloff/source/draw/sdxmlexp.cxx           |   44 +--------------
 xmloff/source/draw/sdxmlexp_impl.hxx      |    2 
 xmloff/source/style/XMLThemeContext.cxx   |    6 +-
 xmloff/source/style/xmlstyle.cxx          |   22 ++++---
 15 files changed, 222 insertions(+), 125 deletions(-)

New commits:
commit b36f7769dd07a6b6f55cdf4ce76e2f39ed186e89
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Aug 31 22:29:46 2023 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Sep 1 10:12:11 2023 +0200

    sc: add ODF import/export of the Theme + tests
    
    One missing thing is the support in calc to save the Theme into
    the ODS document and read that back. The theme element is added as
    a child element to the office:styles - the same as it already is
    added in Writer.
    
    Also adds "Theme" property as a top level document property
    so it is possible to get and set the theme in xmloff.
    
    Also tests have been added to cover this usecases.
    
    Change-Id: Ic214ff5e945b77d50e6c881def9d49509560a0e0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156363
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx
index 522582a36fb5..f88d89fdd2f0 100644
--- a/sc/inc/unonames.hxx
+++ b/sc/inc/unonames.hxx
@@ -47,6 +47,7 @@ inline constexpr OUStringLiteral SC_UNO_ROWLABELRNG          
= u"RowLabelRanges"
 inline constexpr OUStringLiteral SC_UNO_SHEETLINKS           = u"SheetLinks";
 inline constexpr OUStringLiteral SC_UNO_FORBIDDEN            = 
u"ForbiddenCharacters";
 inline constexpr OUStringLiteral SC_UNO_HASDRAWPAGES         = u"HasDrawPages";
+inline constexpr OUStringLiteral SC_UNO_THEME                = u"Theme";
 
 //  CharacterProperties
 inline constexpr OUStringLiteral SC_UNONAME_CCOLOR           = u"CharColor";
diff --git a/sc/qa/extras/scspreadsheetsettingsobj.cxx 
b/sc/qa/extras/scspreadsheetsettingsobj.cxx
index 117fc4d4a097..9173a80ba178 100644
--- a/sc/qa/extras/scspreadsheetsettingsobj.cxx
+++ b/sc/qa/extras/scspreadsheetsettingsobj.cxx
@@ -48,21 +48,10 @@ public:
 
 ScSpreadsheetSettingsObj::ScSpreadsheetSettingsObj()
     : UnoApiTest("/sc/qa/extras/testdocuments")
-    , XPropertySet({
-          "AreaLinks",
-          "CharLocale",
-          "CharLocaleAsian",
-          "CharLocaleComplex",
-          "ColumnLabelRanges",
-          "DDELinks",
-          "DatabaseRanges",
-          "ExternalDocLinks",
-          "InteropGrabBag",
-          "NamedRanges",
-          "NullDate",
-          "RowLabelRanges",
-          "SheetLinks",
-      })
+    , XPropertySet({ "AreaLinks", "CharLocale", "CharLocaleAsian", 
"CharLocaleComplex",
+                     "ColumnLabelRanges", "DDELinks", "DatabaseRanges", 
"ExternalDocLinks",
+                     "InteropGrabBag", "NamedRanges", "NullDate", 
"RowLabelRanges", "SheetLinks",
+                     "Theme" })
 {
 }
 
diff --git a/sc/qa/unit/ThemeImportExportTest.cxx 
b/sc/qa/unit/ThemeImportExportTest.cxx
index 9eac3762d6af..e8e1a31dbbff 100644
--- a/sc/qa/unit/ThemeImportExportTest.cxx
+++ b/sc/qa/unit/ThemeImportExportTest.cxx
@@ -15,6 +15,11 @@
 #include <editeng/colritem.hxx>
 #include <editeng/borderline.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/util/XTheme.hpp>
+#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
+
 using namespace css;
 
 namespace
@@ -28,7 +33,85 @@ public:
     }
 };
 
-CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testThemeExport)
+CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testThemeExportAndImport)
+{
+    mxComponent = loadFromDesktop("private:factory/scalc");
+    {
+        uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, 
uno::UNO_QUERY_THROW);
+
+        auto pTheme = std::make_shared<model::Theme>("MyTheme");
+        auto pColorSet = std::make_shared<model::ColorSet>("MyColorSet");
+        pColorSet->add(model::ThemeColorType::Dark1, 0x111111);
+        pColorSet->add(model::ThemeColorType::Light1, 0x222222);
+        pColorSet->add(model::ThemeColorType::Dark2, 0x333333);
+        pColorSet->add(model::ThemeColorType::Light2, 0x444444);
+        pColorSet->add(model::ThemeColorType::Accent1, 0x555555);
+        pColorSet->add(model::ThemeColorType::Accent2, 0x666666);
+        pColorSet->add(model::ThemeColorType::Accent3, 0x777777);
+        pColorSet->add(model::ThemeColorType::Accent4, 0x888888);
+        pColorSet->add(model::ThemeColorType::Accent5, 0x999999);
+        pColorSet->add(model::ThemeColorType::Accent6, 0xaaaaaa);
+        pColorSet->add(model::ThemeColorType::Hyperlink, 0xbbbbbb);
+        pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xcccccc);
+        pTheme->setColorSet(pColorSet);
+
+        xPropertySet->setPropertyValue("Theme", 
uno::Any(model::theme::createXTheme(pTheme)));
+    }
+
+    // Check the "Theme" property
+    {
+        uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, 
uno::UNO_QUERY_THROW);
+        uno::Reference<util::XTheme> 
xTheme(xPropertySet->getPropertyValue("Theme"),
+                                            uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT(xTheme.is());
+        auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get());
+        CPPUNIT_ASSERT(pUnoTheme);
+        auto pTheme = pUnoTheme->getTheme();
+
+        CPPUNIT_ASSERT_EQUAL(OUString("MyTheme"), pTheme->GetName());
+        CPPUNIT_ASSERT_EQUAL(OUString("MyColorSet"), 
pTheme->getColorSet()->getName());
+        CPPUNIT_ASSERT_EQUAL(OUString("Office"), 
pTheme->getFontScheme().getName());
+        CPPUNIT_ASSERT_EQUAL(OUString(""), 
pTheme->getFormatScheme().getName());
+    }
+
+    saveAndReload("calc8");
+
+    {
+        xmlDocUniquePtr pXmlDoc = parseExport("styles.xml");
+        static constexpr OStringLiteral sThemePath = 
"//office:styles/loext:theme";
+        assertXPath(pXmlDoc, sThemePath, 1);
+        assertXPath(pXmlDoc, sThemePath + "[@loext:name='MyTheme']");
+        const OString sThemeColorsPath = sThemePath + "/loext:theme-colors";
+        assertXPath(pXmlDoc, sThemeColorsPath, 1);
+        assertXPath(pXmlDoc, sThemeColorsPath + "[@loext:name='MyColorSet']");
+        const OString sThemeColorPath = sThemeColorsPath + "/loext:color";
+        assertXPath(pXmlDoc, sThemeColorPath, 12);
+        assertXPath(pXmlDoc, sThemeColorPath + "[3]", "name", "dark2");
+        assertXPath(pXmlDoc, sThemeColorPath + "[3]", "color", "#333333");
+        assertXPath(pXmlDoc, sThemeColorPath + "[9]", "name", "accent5");
+        assertXPath(pXmlDoc, sThemeColorPath + "[9]", "color", "#999999");
+        assertXPath(pXmlDoc, sThemeColorPath + "[12]", "name", 
"followed-hyperlink");
+        assertXPath(pXmlDoc, sThemeColorPath + "[12]", "color", "#cccccc");
+    }
+
+    // Check the theme after import/export cycle
+    {
+        uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, 
uno::UNO_QUERY_THROW);
+        uno::Reference<util::XTheme> 
xTheme(xPropertySet->getPropertyValue("Theme"),
+                                            uno::UNO_QUERY_THROW);
+        CPPUNIT_ASSERT(xTheme.is());
+        auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get());
+        CPPUNIT_ASSERT(pUnoTheme);
+        auto pTheme = pUnoTheme->getTheme();
+
+        CPPUNIT_ASSERT_EQUAL(OUString("MyTheme"), pTheme->GetName());
+        CPPUNIT_ASSERT_EQUAL(OUString("MyColorSet"), 
pTheme->getColorSet()->getName());
+        CPPUNIT_ASSERT_EQUAL(OUString("Office"), 
pTheme->getFontScheme().getName());
+        CPPUNIT_ASSERT_EQUAL(OUString(""), 
pTheme->getFormatScheme().getName());
+    }
+}
+
+CPPUNIT_TEST_FIXTURE(ThemeImportExportTest, testThemeExportOOXML)
 {
     loadFromURL(u"xlsx/CalcThemeTest.xlsx");
 
diff --git a/sc/source/filter/xml/xmlexprt.cxx 
b/sc/source/filter/xml/xmlexprt.cxx
index e38ed5dcacda..65a94257cbc9 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -121,7 +121,9 @@
 #include <svx/svdobj.hxx>
 #include <svx/svdocapt.hxx>
 #include <svx/svdomeas.hxx>
+#include <svx/svdmodel.hxx>
 #include <vcl/svapp.hxx>
+#include <docmodel/theme/Theme.hxx>
 
 #include <comphelper/processfactory.hxx>
 #include <com/sun/star/beans/XPropertySet.hpp>
@@ -1991,6 +1993,25 @@ void ScXMLExport::ExportStyles_( bool bUsed )
         XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME, 
xCellStylesExportPropertySetMapper, false, XmlStyleFamily::TABLE_CELL);
 
     SvXMLExport::ExportStyles_(bUsed);
+
+    exportTheme();
+}
+
+void ScXMLExport::exportTheme()
+{
+    if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
+        return;
+
+    SdrModel* pModel = GetDocument()->GetDrawLayer();
+
+    if (!pModel)
+        return;
+
+    auto const& pTheme = pModel->getTheme();
+    if (!pTheme)
+        return;
+
+    ExportThemeElement(pTheme);
 }
 
 void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& 
xProperties,
diff --git a/sc/source/filter/xml/xmlexprt.hxx 
b/sc/source/filter/xml/xmlexprt.hxx
index 2fcdd0244f16..aaf490736a45 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -222,6 +222,8 @@ class ScXMLExport : public SvXMLExport
 
     const ScXMLEditAttributeMap& GetEditAttributeMap() const;
 
+    void exportTheme();
+
 protected:
     virtual SvXMLAutoStylePoolP* CreateAutoStylePool() override;
     virtual XMLPageExport* CreatePageExport() override;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index d98731951d17..86333bbd4b43 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -57,6 +57,7 @@
 
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/util/Date.hpp>
+#include <com/sun/star/util/XTheme.hpp>
 #include <com/sun/star/sheet/XNamedRanges.hpp>
 #include <com/sun/star/sheet/XLabelRanges.hpp>
 #include <com/sun/star/sheet/XSelectedSheetsSupplier.hpp>
@@ -82,6 +83,8 @@
 #include <sfx2/lokhelper.hxx>
 #include <sfx2/lokcomponenthelpers.hxx>
 #include <sfx2/LokControlHandler.hxx>
+#include <docmodel/uno/UnoTheme.hxx>
+#include <docmodel/theme/Theme.hxx>
 
 #include <cellsuno.hxx>
 #include <columnspanset.hxx>
@@ -165,6 +168,7 @@ static o3tl::span<const SfxItemPropertyMapEntry> 
lcl_GetDocOptPropertyMap()
         { SC_UNO_LOOKUPLABELS,            PROP_UNO_LOOKUPLABELS, 
cppu::UnoType<bool>::get(),                         0, 0},
         { SC_UNO_MATCHWHOLE,              PROP_UNO_MATCHWHOLE, 
cppu::UnoType<bool>::get(),                           0, 0},
         { SC_UNO_NAMEDRANGES,             0, 
cppu::UnoType<sheet::XNamedRanges>::get(),             0, 0},
+        { SC_UNO_THEME,                   0, 
cppu::UnoType<util::XTheme>::get(), 0,  0},
         { SC_UNO_DATABASERNG,             0, 
cppu::UnoType<sheet::XDatabaseRanges>::get(),          0, 0},
         { SC_UNO_NULLDATE,                PROP_UNO_NULLDATE, 
cppu::UnoType<util::Date>::get(),                      0, 0},
         { SC_UNO_ROWLABELRNG,             0, 
cppu::UnoType<sheet::XLabelRanges>::get(),             0, 0},
@@ -2837,6 +2841,16 @@ void SAL_CALL ScModelObj::setPropertyValue(
     {
         setGrabBagItem(aValue);
     }
+    else if (aPropertyName == SC_UNO_THEME)
+    {
+        SdrModel& rSdrModel = getSdrModelFromUnoModel();
+        uno::Reference<util::XTheme> xTheme;
+        if (aValue >>= xTheme)
+        {
+            auto& rUnoTheme = dynamic_cast<UnoTheme&>(*xTheme);
+            rSdrModel.setTheme(rUnoTheme.getTheme());
+        }
+    }
 
     if ( aNewOpt != rOldOpt )
     {
@@ -3023,6 +3037,15 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const 
OUString& aPropertyName )
         {
             getGrabBagItem(aRet);
         }
+        else if (aPropertyName == SC_UNO_THEME)
+        {
+            SdrModel& rSdrModel = getSdrModelFromUnoModel();
+            css::uno::Reference<css::util::XTheme> xTheme;
+            auto pTheme = rSdrModel.getTheme();
+            if (pTheme)
+                xTheme = model::theme::createXTheme(pTheme);
+            aRet <<= xTheme;
+        }
     }
 
     return aRet;
diff --git a/xmloff/inc/XMLThemeContext.hxx b/xmloff/inc/XMLThemeContext.hxx
index ce6f5ec9bbb6..f8ee08d5d4e8 100644
--- a/xmloff/inc/XMLThemeContext.hxx
+++ b/xmloff/inc/XMLThemeContext.hxx
@@ -10,7 +10,7 @@
 #include <utility>
 #include <xmloff/xmlprcon.hxx>
 
-#include <com/sun/star/drawing/XDrawPage.hpp>
+#include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/util/Color.hpp>
 #include <com/sun/star/container/XNameContainer.hpp>
 
@@ -24,13 +24,13 @@ class Theme;
 /// Imports the theme
 class XMLThemeContext : public SvXMLImportContext
 {
-    css::uno::Reference<css::drawing::XDrawPage> m_xPage;
+    css::uno::Reference<css::uno::XInterface> m_xObject;
     std::shared_ptr<model::Theme> mpTheme;
 
 public:
     XMLThemeContext(SvXMLImport& rImport,
                     css::uno::Reference<css::xml::sax::XFastAttributeList> 
const& xAttrList,
-                    css::uno::Reference<css::drawing::XDrawPage> const& xPage);
+                    css::uno::Reference<css::uno::XInterface> const& xObject);
     ~XMLThemeContext();
 
     css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL 
createFastChildContext(
diff --git a/xmloff/source/style/XMLThemeContext.cxx 
b/xmloff/source/style/XMLThemeContext.cxx
index 1579af468003..5c210c7a48dc 100644
--- a/xmloff/source/style/XMLThemeContext.cxx
+++ b/xmloff/source/style/XMLThemeContext.cxx
@@ -33,9 +33,9 @@ using namespace xmloff::token;
 
 XMLThemeContext::XMLThemeContext(SvXMLImport& rImport,
                                  const 
uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
-                                 css::uno::Reference<css::drawing::XDrawPage> 
const& xPage)
+                                 css::uno::Reference<css::uno::XInterface> 
const& xObject)
     : SvXMLImportContext(rImport)
-    , m_xPage(xPage)
+    , m_xObject(xObject)
     , mpTheme(new model::Theme)
 {
     for (const auto& rAttribute : 
sax_fastparser::castToFastAttributeList(xAttrList))
@@ -56,7 +56,7 @@ XMLThemeContext::~XMLThemeContext()
 {
     if (mpTheme && mpTheme->getColorSet())
     {
-        uno::Reference<beans::XPropertySet> xPropertySet(m_xPage, 
uno::UNO_QUERY);
+        uno::Reference<beans::XPropertySet> xPropertySet(m_xObject, 
uno::UNO_QUERY);
         auto xTheme = model::theme::createXTheme(mpTheme);
         xPropertySet->setPropertyValue("Theme", uno::Any(xTheme));
     }
diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx
index d0dc368870a2..5158b43592cd 100644
--- a/xmloff/source/style/xmlstyle.cxx
+++ b/xmloff/source/style/xmlstyle.cxx
@@ -683,22 +683,26 @@ SvXMLStylesContext::~SvXMLStylesContext()
 css::uno::Reference< css::xml::sax::XFastContextHandler > 
SvXMLStylesContext::createFastChildContext(
         sal_Int32 nElement, const css::uno::Reference< 
css::xml::sax::XFastAttributeList >& xAttrList )
 {
-    SvXMLStyleContext* pStyle = CreateStyleChildContext( nElement, xAttrList );
-    if (pStyle)
-    {
-        if (!pStyle->IsTransient())
-            mpImpl->AddStyle(pStyle);
-        return pStyle;
-    }
-    else if (nElement ==  XML_ELEMENT(LO_EXT, XML_THEME))
+    if (nElement ==  XML_ELEMENT(LO_EXT, XML_THEME))
     {
+        uno::Reference<uno::XInterface> xObject(GetImport().GetModel(), 
uno::UNO_QUERY);
         uno::Reference<drawing::XDrawPageSupplier> const 
xDrawPageSupplier(GetImport().GetModel(), uno::UNO_QUERY);
         if (xDrawPageSupplier.is())
         {
             uno::Reference<drawing::XDrawPage> xPage = 
xDrawPageSupplier->getDrawPage();
             if (xPage.is())
-                return new XMLThemeContext(GetImport(), xAttrList, xPage);
+                xObject = xPage;
         }
+
+        return new XMLThemeContext(GetImport(), xAttrList, xObject);
+    }
+
+    SvXMLStyleContext* pStyle = CreateStyleChildContext( nElement, xAttrList );
+    if (pStyle)
+    {
+        if (!pStyle->IsTransient())
+            mpImpl->AddStyle(pStyle);
+        return pStyle;
     }
 
     return nullptr;
commit b53a03d1d55de7fd04efc47c4a57baa11d72dd85
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Aug 31 13:47:27 2023 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Sep 1 10:12:04 2023 +0200

    move theme element export to xmloff to remove code duplication
    
    Both Impress/Draw and Writer export the model::Theme in a similar
    way, but the code is duplicated. Remove duplication and move the
    code to a common place (on the SwXMLExport class) so it can be
    reused at both places.
    
    Change-Id: Id93acfafb0dd4ab0168b3228079f6ce6f64e6b55
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156362
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/xmloff/xmlexp.hxx b/include/xmloff/xmlexp.hxx
index 8fd763438e81..2db5a90949ef 100644
--- a/include/xmloff/xmlexp.hxx
+++ b/include/xmloff/xmlexp.hxx
@@ -87,6 +87,8 @@ namespace com::sun::star {
 }
 namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; }
 
+namespace model { class Theme; }
+
 enum class SvXMLExportFlags {
     NONE                     = 0,
     META                     = 0x0001,
@@ -260,6 +262,8 @@ protected:
 
     void SetDocHandler( const css::uno::Reference< 
css::xml::sax::XDocumentHandler > &rHandler );
 
+    void ExportThemeElement(std::shared_ptr<model::Theme> const& pTheme);
+
     bool mbAutoStylesCollected;
 public:
 
diff --git a/sw/source/filter/xml/xmlexp.hxx b/sw/source/filter/xml/xmlexp.hxx
index 1da84af86f03..6e095396db61 100644
--- a/sw/source/filter/xml/xmlexp.hxx
+++ b/sw/source/filter/xml/xmlexp.hxx
@@ -90,8 +90,7 @@ class SwXMLExport : public SvXMLExport
                            SwXMLTableInfo_Impl& rTableInfo,
                            sal_uInt32 nHeaderRows = 0 );
 
-    void ExportThemeElement(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPage);
-
+    void exportTheme();
 
     virtual void ExportMeta_() override;
     virtual void ExportFontDecls_() override;
diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx
index 7eba318cac78..8e20f46e4299 100644
--- a/sw/source/filter/xml/xmlfmte.cxx
+++ b/sw/source/filter/xml/xmlfmte.cxx
@@ -40,9 +40,7 @@
 #include <SwStyleNameMapper.hxx>
 #include <osl/diagnose.h>
 #include <comphelper/sequenceashashmap.hxx>
-#include <sax/tools/converter.hxx>
 
-#include <o3tl/enumrange.hxx>
 #include <svx/unoapi.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/svdmodel.hxx>
@@ -183,22 +181,21 @@ void SwXMLExport::ExportStyles_( bool bUsed )
     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);
-    }
+    exportTheme();
 }
 
-void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& 
xDrawPage)
+void SwXMLExport::exportTheme()
 {
     if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
-    {
-        // Do not export in standard ODF 1.3 or older.
         return;
-    }
+
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), 
UNO_QUERY);
+    if (!xDrawPageSupplier.is())
+        return;
+
+    uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+    if (!xDrawPage.is())
+        return;
 
     SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
     SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
@@ -210,43 +207,7 @@ void SwXMLExport::ExportThemeElement(const 
uno::Reference<drawing::XDrawPage>& x
     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_THEME_COLORS, true, true);
-
-    static const XMLTokenEnum aColorTokens[] =
-    {
-        XML_DARK1, // Text 1
-        XML_LIGHT1, // Background 1
-        XML_DARK2, // Text 2
-        XML_LIGHT2, // Background 2
-        XML_ACCENT1,
-        XML_ACCENT2,
-        XML_ACCENT3,
-        XML_ACCENT4,
-        XML_ACCENT5,
-        XML_ACCENT6,
-        XML_HYPERLINK, // Hyperlink
-        XML_FOLLOWED_HYPERLINK, // 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);
-    }
+    ExportThemeElement(pTheme);
 }
 
 void SwXMLExport::collectAutoStyles()
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index 1202d797972e..eb173fc4d98c 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -87,6 +87,9 @@
 #include <comphelper/extract.hxx>
 #include <comphelper/SetFlagContextHelper.hxx>
 #include <PropertySetMerger.hxx>
+#include <docmodel/theme/Theme.hxx>
+#include <o3tl/enumrange.hxx>
+#include <sax/tools/converter.hxx>
 
 #include <unotools/docinfohelper.hxx>
 #include <com/sun/star/document/XDocumentProperties.hpp>
@@ -1067,6 +1070,7 @@ void SvXMLExport::ImplExportSettings()
 
 void SvXMLExport::ImplExportStyles()
 {
+    printf ("SvXMLExport::ImplExportStyles\n");
     CheckAttrList();
 
     {
@@ -1663,6 +1667,50 @@ void SvXMLExport::ExportStyles_( bool )
     }
 }
 
+void SvXMLExport::ExportThemeElement(std::shared_ptr<model::Theme> const& 
pTheme)
+{
+    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_THEME_COLORS, true, true);
+
+    static const XMLTokenEnum aColorTokens[] =
+    {
+        XML_DARK1, // Text 1
+        XML_LIGHT1, // Background 1
+        XML_DARK2, // Text 2
+        XML_LIGHT2, // Background 2
+        XML_ACCENT1,
+        XML_ACCENT2,
+        XML_ACCENT3,
+        XML_ACCENT4,
+        XML_ACCENT5,
+        XML_ACCENT6,
+        XML_HYPERLINK, // Hyperlink
+        XML_FOLLOWED_HYPERLINK, // 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);
+    }
+}
+
 XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
 {
     return new XMLTextParagraphExport( *this, *GetAutoStylePool() );
diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index f0d7fc6c220f..b23570d9dd25 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -2301,7 +2301,7 @@ void SdXMLExport::ExportMasterStyles_()
             exportFormsElement( xMasterPage );
 
             // write optional loext:theme
-            ExportThemeElement(xMasterPage);
+            exportTheme(xMasterPage);
 
             // write graphic objects on this master page (if any)
             if(xMasterPage.is() && xMasterPage->getCount())
@@ -2358,7 +2358,7 @@ void SdXMLExport::exportFormsElement( const Reference< 
XDrawPage >& xDrawPage )
     }
 }
 
-void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& 
xDrawPage)
+void SdXMLExport::exportTheme(const uno::Reference<drawing::XDrawPage>& 
xDrawPage)
 {
     if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
     {
@@ -2382,46 +2382,8 @@ void SdXMLExport::ExportThemeElement(const 
uno::Reference<drawing::XDrawPage>& x
     auto pTheme = pUnoTheme->getTheme();
     if (!pTheme)
         return;
-    auto pColorSet = pTheme->getColorSet();
-    if (!pColorSet)
-        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);
-
-    if (!pColorSet->getName().isEmpty())
-        AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName());
-    SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, 
XML_THEME_COLORS, true, true);
-
-    static const XMLTokenEnum aColorTokens[] =
-    {
-        XML_DARK1, // Text 1
-        XML_LIGHT1, // Background 1
-        XML_DARK2, // Text 2
-        XML_LIGHT2, // Background 2
-        XML_ACCENT1,
-        XML_ACCENT2,
-        XML_ACCENT3,
-        XML_ACCENT4,
-        XML_ACCENT5,
-        XML_ACCENT6,
-        XML_HYPERLINK, // Hyperlink
-        XML_FOLLOWED_HYPERLINK, // 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);
-    }
+    ExportThemeElement(pTheme);
 }
 
 void SdXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps)
diff --git a/xmloff/source/draw/sdxmlexp_impl.hxx 
b/xmloff/source/draw/sdxmlexp_impl.hxx
index 9808c738120e..8207d64e3b9e 100644
--- a/xmloff/source/draw/sdxmlexp_impl.hxx
+++ b/xmloff/source/draw/sdxmlexp_impl.hxx
@@ -135,7 +135,7 @@ class SdXMLExport : public SvXMLExport
     void ImplExportHeaderFooterDeclAttributes( const 
HeaderFooterPageSettingsImpl& aSettings );
 
     void exportFormsElement( const css::uno::Reference< 
css::drawing::XDrawPage >& xDrawPage );
-    void ExportThemeElement(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPage);
+    void exportTheme(const css::uno::Reference<css::drawing::XDrawPage>& 
xDrawPage);
     void exportPresentationSettings();
 
     // #82003# helper function for recursive object count

Reply via email to