include/svx/ColorSets.hxx       |   23 +++++++++++++++++
 include/svx/svdmodel.hxx        |    7 +++++
 svx/source/styles/ColorSets.cxx |   53 ++++++++++++++++++++++++++++++++++++++++
 svx/source/svdraw/svdmodel.cxx  |   11 ++++++++
 4 files changed, 94 insertions(+)

New commits:
commit 3171d185f8c17799f0b85f5931aa59101cbc6b4e
Author:     Sarper Akdemir <sarper.akde...@collabora.com>
AuthorDate: Wed Jul 28 02:03:12 2021 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Nov 17 13:26:45 2021 +0100

    make colorsets work outside of styles and with direct formatting
    
    [ Miklos: picked only the document model bits, now in SdrModel, next to
    styles. ]
    
    (cherry picked from commit 1647d34d8573f4940c0cbb7fb6cd9c6b4e5a4a15,
    from the feature/themesupport2 branch)
    
    Change-Id: I80f9e0b205b8b4a6914f851bdc63e3e0ca6706e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125313
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx
index 361fe47c622e..eee992da94b5 100644
--- a/include/svx/ColorSets.hxx
+++ b/include/svx/ColorSets.hxx
@@ -18,6 +18,8 @@
 #include <svx/svxdllapi.h>
 #include <tools/color.hxx>
 
+typedef struct _xmlTextWriter* xmlTextWriterPtr;
+
 namespace svx
 {
 
@@ -41,6 +43,8 @@ public:
     {
         return maColors[nIndex];
     }
+
+    void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
 
 class SVXCORE_DLLPUBLIC ColorSets
@@ -64,6 +68,25 @@ public:
     const ColorSet& getColorSet(std::u16string_view rName);
 };
 
+/// A named theme has a named color set.
+class SVXCORE_DLLPUBLIC Theme
+{
+    OUString maName;
+    std::unique_ptr<ColorSet> mpColorSet;
+
+public:
+    Theme(OUString const& rName);
+    ~Theme();
+
+    void SetColorSet(std::unique_ptr<ColorSet> pColorSet);
+    ColorSet* GetColorSet();
+
+    void SetName(const OUString& rName);
+    const OUString& GetName() const;
+
+    void dumpAsXml(xmlTextWriterPtr pWriter) const;
+};
+
 } // end of namespace svx
 
 #endif // INCLUDED_SVX_COLORSETS_HXX
diff --git a/include/svx/svdmodel.hxx b/include/svx/svdmodel.hxx
index 73fc9f646f43..ab9578a7bc93 100644
--- a/include/svx/svdmodel.hxx
+++ b/include/svx/svdmodel.hxx
@@ -90,6 +90,10 @@ namespace com::sun::star::beans {
     struct PropertyValue;
 }
 
+namespace svx
+{
+class Theme;
+}
 
 constexpr const sal_Unicode DEGREE_CHAR = u'\x00B0'; /* U+00B0 DEGREE SIGN */
 
@@ -536,6 +540,9 @@ public:
     SfxStyleSheetBasePool* GetStyleSheetPool() const         { return 
mxStyleSheetPool.get(); }
     void SetStyleSheetPool(SfxStyleSheetBasePool* pPool)     { 
mxStyleSheetPool=pPool; }
 
+    void SetTheme(std::unique_ptr<svx::Theme> pTheme);
+    svx::Theme* GetTheme();
+
     void    SetStarDrawPreviewMode(bool bPreview);
     bool    IsStarDrawPreviewMode() const { return m_bStarDrawPreviewMode; }
 
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 7a04eb4e6314..91a44f1782ea 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -10,6 +10,10 @@
 
 #include <svx/ColorSets.hxx>
 
+#include <sstream>
+
+#include <libxml/xmlwriter.h>
+
 namespace svx
 {
 
@@ -21,6 +25,25 @@ ColorSet::ColorSet(OUString const & aColorSetName)
 ColorSets::ColorSets()
 {}
 
+void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet"));
+    (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maColorSetName"),
+                                      
BAD_CAST(maColorSetName.toUtf8().getStr()));
+
+    for (const auto& rColor : maColors)
+    {
+        (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Color"));
+        std::stringstream ss;
+        ss << rColor;
+        (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), 
BAD_CAST(ss.str().c_str()));
+        (void)xmlTextWriterEndElement(pWriter);
+    }
+
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
 ColorSets::~ColorSets()
 {}
 
@@ -102,6 +125,36 @@ const ColorSet& ColorSets::getColorSet(std::u16string_view 
rName)
     return maColorSets[0];
 }
 
+Theme::Theme(const OUString& rName)
+    : maName(rName)
+{
+}
+
+Theme::~Theme() {}
+
+void Theme::SetColorSet(std::unique_ptr<ColorSet> pColorSet) { mpColorSet = 
std::move(pColorSet); }
+
+ColorSet* Theme::GetColorSet() { return mpColorSet.get(); }
+
+void Theme::SetName(const OUString& rName) { maName = rName; }
+
+const OUString& Theme::GetName() const { return maName; }
+
+void Theme::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Theme"));
+    (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"),
+                                      BAD_CAST(maName.toUtf8().getStr()));
+
+    if (mpColorSet)
+    {
+        mpColorSet->dumpAsXml(pWriter);
+    }
+
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
 } // end of namespace svx
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index 0212b99c7232..6dcebf3ef541 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -72,6 +72,7 @@
 #include <o3tl/enumrange.hxx>
 #include <tools/diagnose_ex.h>
 #include <tools/UnitConversion.hxx>
+#include <svx/ColorSets.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -83,6 +84,7 @@ struct SdrModelImpl
     SfxUndoManager* mpUndoManager;
     SdrUndoFactory* mpUndoFactory;
     bool mbAnchoredTextOverflowLegacy; // tdf#99729 compatibility flag
+    std::unique_ptr<svx::Theme> mpTheme;
 
     SdrModelImpl()
         : mpUndoManager(nullptr)
@@ -1571,6 +1573,10 @@ void SdrModel::SetStarDrawPreviewMode(bool bPreview)
     }
 }
 
+void SdrModel::SetTheme(std::unique_ptr<svx::Theme> pTheme) { mpImpl->mpTheme 
= std::move(pTheme); }
+
+svx::Theme* SdrModel::GetTheme() { return mpImpl->mpTheme.get(); }
+
 uno::Reference< uno::XInterface > const & SdrModel::getUnoModel()
 {
     if( !mxUnoModel.is() )
@@ -1875,6 +1881,11 @@ void SdrModel::dumpAsXml(xmlTextWriterPtr pWriter) const
             pPage->dumpAsXml(pWriter);
     }
 
+    if (mpImpl->mpTheme)
+    {
+        mpImpl->mpTheme->dumpAsXml(pWriter);
+    }
+
     (void)xmlTextWriterEndElement(pWriter);
 }
 

Reply via email to