docmodel/Library_docmodel.mk                               |    4 
 docmodel/source/theme/ThemeColorJSON.cxx                   |  103 +++++++++++++
 editeng/source/items/textitem.cxx                          |   33 ++++
 include/docmodel/theme/ThemeColorJSON.hxx                  |   23 ++
 include/editeng/colritem.hxx                               |    6 
 include/editeng/memberids.h                                |    1 
 include/oox/drawingml/themefragmenthandler.hxx             |   17 +-
 include/svx/svxids.hrc                                     |    8 -
 oox/inc/drawingml/ThemeOverrideFragmentHandler.hxx         |   16 +-
 oox/inc/drawingml/clrschemecontext.hxx                     |    8 -
 oox/inc/drawingml/themeelementscontext.hxx                 |    7 
 oox/source/drawingml/ThemeOverrideFragmentHandler.cxx      |   19 +-
 oox/source/drawingml/clrschemecontext.cxx                  |   45 ++++-
 oox/source/drawingml/diagram/diagramhelper.cxx             |    4 
 oox/source/drawingml/shape.cxx                             |    4 
 oox/source/drawingml/themeelementscontext.cxx              |   32 ++--
 oox/source/drawingml/themefragmenthandler.cxx              |   18 +-
 oox/source/ppt/presentationfragmenthandler.cxx             |    4 
 oox/source/shape/ShapeContextHandler.cxx                   |    3 
 sc/Library_scfilt.mk                                       |    1 
 sc/source/filter/oox/workbookfragment.cxx                  |    3 
 svx/sdi/svxitems.sdi                                       |    9 +
 svx/source/tbxctrls/PaletteManager.cxx                     |   23 ++
 sw/source/uibase/shells/textsh1.cxx                        |   18 --
 writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.cxx |    2 
 writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.hxx |    4 
 26 files changed, 319 insertions(+), 96 deletions(-)

New commits:
commit 6e8c67580974484c790f52991de26298ce8e7e1c
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Feb 23 23:38:08 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Mar 1 12:57:29 2023 +0000

    oox: import directly into docmodel's Theme and ColorSet
    
    This changes the import to directly fill values of a model::Theme
    and model::ColorSet, without filling the oox structs first. The
    goal is to get rid of the oox in the long run, but for now it is
    necessary to keep reading into both, which is a duplication.
    
    The next step is to also fill the FontScheme and FormatScheme
    structures.
    
    Change-Id: I488ec096cbc184bc70d24510ac9091a488540422
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147571
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/oox/drawingml/themefragmenthandler.hxx 
b/include/oox/drawingml/themefragmenthandler.hxx
index 918a3eb861b9..5c193544fe65 100644
--- a/include/oox/drawingml/themefragmenthandler.hxx
+++ b/include/oox/drawingml/themefragmenthandler.hxx
@@ -25,29 +25,28 @@
 #include <oox/dllapi.h>
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
+#include <docmodel/theme/Theme.hxx>
 
 namespace oox { class AttributeList; }
 namespace oox::core { class XmlFilterBase; }
 
-namespace oox::drawingml {
+namespace oox::drawingml
+{
 
 class Theme;
 
-
 class OOX_DLLPUBLIC ThemeFragmentHandler final : public 
::oox::core::FragmentHandler2
 {
 public:
-    explicit            ThemeFragmentHandler(
-                            ::oox::core::XmlFilterBase& rFilter,
-                            const OUString& rFragmentPath,
-                            Theme& rTheme );
-    virtual             ~ThemeFragmentHandler() override;
+    explicit ThemeFragmentHandler(::oox::core::XmlFilterBase& rFilter, const 
OUString& rFragmentPath, Theme& rOoxTheme, model::Theme& rTheme);
+    virtual ~ThemeFragmentHandler() override;
 
-    virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 
nElement, const AttributeList& rAttribs ) override;
+    virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, 
const AttributeList& rAttribs) override;
     void onStartElement(const AttributeList& rAttribs) override;
 
 private:
-    Theme&              mrTheme;
+    Theme& mrOoxTheme;
+    model::Theme& mrTheme;
 };
 
 
diff --git a/oox/inc/drawingml/ThemeOverrideFragmentHandler.hxx 
b/oox/inc/drawingml/ThemeOverrideFragmentHandler.hxx
index 1582ea819d95..a51c66c3eea0 100644
--- a/oox/inc/drawingml/ThemeOverrideFragmentHandler.hxx
+++ b/oox/inc/drawingml/ThemeOverrideFragmentHandler.hxx
@@ -11,24 +11,24 @@
 #define INCLUDED_OOX_DRAWINGML_THEMEOVERRICEFRAGMENTHANDLER_HXX
 
 #include <oox/core/fragmenthandler2.hxx>
+#include <oox/drawingml/theme.hxx>
 
-namespace oox::drawingml {
+namespace oox::drawingml
+{
 
 class Theme;
 
 class ThemeOverrideFragmentHandler final : public ::oox::core::FragmentHandler2
 {
 public:
-    explicit            ThemeOverrideFragmentHandler(
-                            ::oox::core::XmlFilterBase& rFilter,
-                            const OUString& rFragmentPath,
-                            Theme& rTheme );
-    virtual             ~ThemeOverrideFragmentHandler() override;
+    explicit ThemeOverrideFragmentHandler(::oox::core::XmlFilterBase& rFilter, 
const OUString& rFragmentPath, Theme& rOoxTheme, model::Theme& rTheme);
+    virtual ~ThemeOverrideFragmentHandler() override;
 
-    virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 
nElement, const AttributeList& rAttribs ) override;
+    virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, 
const AttributeList& rAttribs) override;
 
 private:
-    Theme&              mrTheme;
+    Theme& mrOoxTheme;
+    model::Theme& mrTheme;
 };
 
 } // namespace oox::drawingml
diff --git a/oox/inc/drawingml/clrschemecontext.hxx 
b/oox/inc/drawingml/clrschemecontext.hxx
index 5e7cddfb8d03..b50c8e0c93d9 100644
--- a/oox/inc/drawingml/clrschemecontext.hxx
+++ b/oox/inc/drawingml/clrschemecontext.hxx
@@ -37,22 +37,24 @@ public:
 class clrSchemeColorContext final : private Color, public ColorContext
 {
 public:
-    clrSchemeColorContext( ::oox::core::ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme, sal_Int32 nColorToken );
+    clrSchemeColorContext(::oox::core::ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme, model::ColorSet& mrColorSet, sal_Int32 nColorToken);
     virtual ~clrSchemeColorContext() override;
 
 private:
     ClrScheme&      mrClrScheme;
+    model::ColorSet& mrColorSet;
     sal_Int32       mnColorToken;
 };
 
 class clrSchemeContext final : public oox::core::ContextHandler2
 {
 public:
-    clrSchemeContext( ::oox::core::ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme );
+    clrSchemeContext(::oox::core::ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme, model::ColorSet& rColorSet);
     virtual ::oox::core::ContextHandlerRef onCreateContext( ::sal_Int32 
Element, const ::oox::AttributeList& rAttribs ) override;
 
 private:
-    ClrScheme&      mrClrScheme;
+    ClrScheme& mrClrScheme;
+    model::ColorSet& mrColorSet;
 };
 
 }
diff --git a/oox/inc/drawingml/themeelementscontext.hxx 
b/oox/inc/drawingml/themeelementscontext.hxx
index 4c113762e10c..1dba96e6c0e2 100644
--- a/oox/inc/drawingml/themeelementscontext.hxx
+++ b/oox/inc/drawingml/themeelementscontext.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_OOX_DRAWINGML_THEMEELEMENTSCONTEXT_HXX
 
 #include <oox/core/contexthandler2.hxx>
+#include <docmodel/theme/Theme.hxx>
 
 namespace oox::drawingml
 {
@@ -29,12 +30,14 @@ class Theme;
 class ThemeElementsContext final : public oox::core::ContextHandler2
 {
 public:
-    ThemeElementsContext(::oox::core::ContextHandler2Helper const& rParent, 
Theme& rTheme);
+    ThemeElementsContext(::oox::core::ContextHandler2Helper const& rParent, 
Theme& rOoxTheme,
+                         model::Theme& rTheme);
     virtual ::oox::core::ContextHandlerRef
     onCreateContext(sal_Int32 nElement, const ::oox::AttributeList& rAttribs) 
override;
 
 private:
-    Theme& mrTheme;
+    Theme& mrOoxTheme;
+    model::Theme& mrTheme;
 };
 
 } // namespace oox::drawingml
diff --git a/oox/source/drawingml/ThemeOverrideFragmentHandler.cxx 
b/oox/source/drawingml/ThemeOverrideFragmentHandler.cxx
index 1be56980cff8..72f93a7e2581 100644
--- a/oox/source/drawingml/ThemeOverrideFragmentHandler.cxx
+++ b/oox/source/drawingml/ThemeOverrideFragmentHandler.cxx
@@ -8,17 +8,18 @@
  */
 
 #include <drawingml/ThemeOverrideFragmentHandler.hxx>
-#include <oox/drawingml/theme.hxx>
 #include <oox/token/namespaces.hxx>
 #include <drawingml/themeelementscontext.hxx>
 
 using namespace ::oox::core;
 
-namespace oox::drawingml {
+namespace oox::drawingml
+{
 
-ThemeOverrideFragmentHandler::ThemeOverrideFragmentHandler( XmlFilterBase& 
rFilter, const OUString& rFragmentPath, Theme& rTheme ) :
-    FragmentHandler2( rFilter, rFragmentPath ),
-    mrTheme( rTheme )
+ThemeOverrideFragmentHandler::ThemeOverrideFragmentHandler(XmlFilterBase& 
rFilter, const OUString& rFragmentPath, Theme& rOoxTheme, model::Theme& rTheme)
+    : FragmentHandler2(rFilter, rFragmentPath)
+    , mrOoxTheme(rOoxTheme)
+    , mrTheme(rTheme)
 {
 }
 
@@ -26,16 +27,16 @@ 
ThemeOverrideFragmentHandler::~ThemeOverrideFragmentHandler()
 {
 }
 
-ContextHandlerRef ThemeOverrideFragmentHandler::onCreateContext( sal_Int32 
nElement, const AttributeList& )
+ContextHandlerRef ThemeOverrideFragmentHandler::onCreateContext(sal_Int32 
nElement, const AttributeList& /*rAttribute*/)
 {
     // CT_OfficeStyleSheet
-    switch( getCurrentElement() )
+    switch (getCurrentElement())
     {
         case XML_ROOT_CONTEXT:
-            switch( nElement )
+            switch (nElement)
             {
                 case A_TOKEN( themeOverride ): // CT_BaseStylesOverride
-                    return new ThemeElementsContext( *this, mrTheme );
+                    return new ThemeElementsContext(*this, mrOoxTheme, 
mrTheme);
             }
         break;
     }
diff --git a/oox/source/drawingml/clrschemecontext.cxx 
b/oox/source/drawingml/clrschemecontext.cxx
index e8850974c683..5e423f3a7e8a 100644
--- a/oox/source/drawingml/clrschemecontext.cxx
+++ b/oox/source/drawingml/clrschemecontext.cxx
@@ -57,21 +57,44 @@ clrMapContext::clrMapContext( ContextHandler2Helper const & 
rParent,
     setClrMap( rAttributes, rClrMap, XML_folHlink );
 }
 
-clrSchemeColorContext::clrSchemeColorContext( ContextHandler2Helper const & 
rParent, ClrScheme& rClrScheme, sal_Int32 nColorToken ) :
-    ColorContext( rParent, *this ),
-    mrClrScheme( rClrScheme ),
-    mnColorToken( nColorToken )
+clrSchemeColorContext::clrSchemeColorContext(ContextHandler2Helper const & 
rParent, ClrScheme& rClrScheme, model::ColorSet& rColorSet, sal_Int32 
nColorToken)
+    : ColorContext(rParent, *this)
+    , mrClrScheme(rClrScheme)
+    , mrColorSet(rColorSet)
+    , mnColorToken(nColorToken)
 {
 }
 
 clrSchemeColorContext::~clrSchemeColorContext()
 {
-    mrClrScheme.setColor( mnColorToken, getColor( 
getFilter().getGraphicHelper() ) );
+    ::Color aColor = getColor(getFilter().getGraphicHelper());
+    mrClrScheme.setColor(mnColorToken, aColor);
+    switch (mnColorToken)
+    {
+        case XML_tx1:
+        case XML_dk1: mrColorSet.add(model::ThemeColorType::Dark1, aColor); 
break;
+        case XML_bg1:
+        case XML_lt1: mrColorSet.add(model::ThemeColorType::Light1, aColor); 
break;
+        case XML_tx2:
+        case XML_dk2: mrColorSet.add(model::ThemeColorType::Dark2, aColor); 
break;
+        case XML_bg2:
+        case XML_lt2: mrColorSet.add(model::ThemeColorType::Light2, aColor); 
break;
+        case XML_accent1: mrColorSet.add(model::ThemeColorType::Accent1, 
aColor); break;
+        case XML_accent2: mrColorSet.add(model::ThemeColorType::Accent2, 
aColor); break;
+        case XML_accent3: mrColorSet.add(model::ThemeColorType::Accent3, 
aColor); break;
+        case XML_accent4: mrColorSet.add(model::ThemeColorType::Accent4, 
aColor); break;
+        case XML_accent5: mrColorSet.add(model::ThemeColorType::Accent5, 
aColor); break;
+        case XML_accent6: mrColorSet.add(model::ThemeColorType::Accent6, 
aColor); break;
+        case XML_hlink: mrColorSet.add(model::ThemeColorType::Hyperlink, 
aColor); break;
+        case XML_folHlink: 
mrColorSet.add(model::ThemeColorType::FollowedHyperlink, aColor); break;
+        default: break;
+    }
 }
 
-clrSchemeContext::clrSchemeContext( ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme ) :
-    ContextHandler2( rParent ),
-    mrClrScheme( rClrScheme )
+clrSchemeContext::clrSchemeContext(ContextHandler2Helper const & rParent, 
ClrScheme& rClrScheme, model::ColorSet& rColorSet)
+    : ContextHandler2(rParent)
+    , mrClrScheme(rClrScheme)
+    , mrColorSet(rColorSet)
 {
 }
 
@@ -81,9 +104,13 @@ ContextHandlerRef clrSchemeContext::onCreateContext(
     switch( nElement )
     {
         case A_TOKEN( dk1 ):
+        case A_TOKEN( tx1 ):
         case A_TOKEN( lt1 ):
+        case A_TOKEN( bg1 ):
         case A_TOKEN( dk2 ):
+        case A_TOKEN( tx2 ):
         case A_TOKEN( lt2 ):
+        case A_TOKEN( bg2 ):
         case A_TOKEN( accent1 ):
         case A_TOKEN( accent2 ):
         case A_TOKEN( accent3 ):
@@ -92,7 +119,7 @@ ContextHandlerRef clrSchemeContext::onCreateContext(
         case A_TOKEN( accent6 ):
         case A_TOKEN( hlink ):
         case A_TOKEN( folHlink ):
-            return new clrSchemeColorContext( *this, mrClrScheme, 
getBaseToken( nElement ) );
+            return new clrSchemeColorContext(*this, mrClrScheme, mrColorSet, 
getBaseToken(nElement));
     }
     return nullptr;
 }
diff --git a/oox/source/drawingml/diagram/diagramhelper.cxx 
b/oox/source/drawingml/diagram/diagramhelper.cxx
index e0e7202d3966..daf3047b6433 100644
--- a/oox/source/drawingml/diagram/diagramhelper.cxx
+++ b/oox/source/drawingml/diagram/diagramhelper.cxx
@@ -251,11 +251,11 @@ const std::shared_ptr< ::oox::drawingml::Theme >& 
AdvancedDiagramHelper::getOrCr
             // reset local Theme ModelData *always* to get rid of former data 
that would
             // else be added additionally
             const_cast<AdvancedDiagramHelper*>(this)->mpThemePtr = 
std::make_shared<oox::drawingml::Theme>();
+            model::Theme aTheme;
 
             // import Theme ModelData
             rxFilter->importFragment(
-                new ThemeFragmentHandler(
-                    *rxFilter, OUString(), *mpThemePtr ),
+                new ThemeFragmentHandler(*rxFilter, OUString(), *mpThemePtr, 
aTheme),
                 uno::Reference< css::xml::sax::XFastSAXSerializable >(
                     xThemeDocument,
                     uno::UNO_QUERY_THROW));
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index fac027376784..ccfd61410bd5 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -2170,9 +2170,9 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, const 
Reference< XShapes >&
                             
rFilter.importFragment(aThemeOverrideFragmentPath), uno::UNO_QUERY_THROW);
                     pTheme = 
pPowerPointImport->getActualSlidePersist()->getTheme();
                     auto pThemeOverride = std::make_shared<Theme>(*pTheme);
+                    model::Theme aTheme;
                     rFilter.importFragment(
-                        new ThemeOverrideFragmentHandler(rFilter, 
aThemeOverrideFragmentPath,
-                                                         *pThemeOverride),
+                        new ThemeOverrideFragmentHandler(rFilter, 
aThemeOverrideFragmentPath, *pThemeOverride, aTheme),
                         xDoc);
                     
pPowerPointImport->getActualSlidePersist()->setTheme(pThemeOverride);
                 }
diff --git a/oox/source/drawingml/themeelementscontext.cxx 
b/oox/source/drawingml/themeelementscontext.cxx
index cb62f4ef0a70..fdc691427040 100644
--- a/oox/source/drawingml/themeelementscontext.cxx
+++ b/oox/source/drawingml/themeelementscontext.cxx
@@ -213,45 +213,49 @@ void FontSchemeContext::onEndElement()
     }
 }
 
-ThemeElementsContext::ThemeElementsContext( ContextHandler2Helper const & 
rParent, Theme& rTheme ) :
-    ContextHandler2( rParent ),
-    mrTheme( rTheme )
+ThemeElementsContext::ThemeElementsContext(ContextHandler2Helper const & 
rParent, Theme& rOoxTheme, model::Theme& rTheme)
+    : ContextHandler2(rParent)
+    , mrOoxTheme(rOoxTheme)
+    , mrTheme(rTheme)
 {
 }
 
-ContextHandlerRef ThemeElementsContext::onCreateContext( sal_Int32 nElement, 
const AttributeList& rAttribs )
+ContextHandlerRef ThemeElementsContext::onCreateContext(sal_Int32 nElement, 
const AttributeList& rAttribs)
 {
     // CT_BaseStyles
-    switch( nElement )
+    switch (nElement)
     {
         case A_TOKEN( clrScheme ):  // CT_ColorScheme
         {
+            OUString aColorSchemeName = rAttribs.getStringDefaulted(XML_name);
+            
mrTheme.SetColorSet(std::make_unique<model::ColorSet>(aColorSchemeName));
             if (rAttribs.hasAttribute(XML_name))
-                
mrTheme.getClrScheme().SetName(rAttribs.getStringDefaulted(XML_name));
-            return new clrSchemeContext(*this, mrTheme.getClrScheme());
+                
mrOoxTheme.getClrScheme().SetName(rAttribs.getStringDefaulted(XML_name));
+            return new clrSchemeContext(*this, mrOoxTheme.getClrScheme(), 
*mrTheme.GetColorSet());
         }
         case A_TOKEN( fontScheme ): // CT_FontScheme
         {
             if (rAttribs.hasAttribute(XML_name))
-                
mrTheme.setFontSchemeName(rAttribs.getStringDefaulted(XML_name));
-            return new FontSchemeContext(*this, mrTheme.getFontScheme(), 
mrTheme.getSupplementalFontMap());
+                
mrOoxTheme.setFontSchemeName(rAttribs.getStringDefaulted(XML_name));
+
+            return new FontSchemeContext(*this, mrOoxTheme.getFontScheme(), 
mrOoxTheme.getSupplementalFontMap());
         }
 
         case A_TOKEN( fmtScheme ):  // CT_StyleMatrix
         {
             if (rAttribs.hasAttribute(XML_name))
-                
mrTheme.setFormatSchemeName(rAttribs.getStringDefaulted(XML_name));
+                
mrOoxTheme.setFormatSchemeName(rAttribs.getStringDefaulted(XML_name));
             return this;
         }
 
         case A_TOKEN( fillStyleLst ):   // CT_FillStyleList
-            return new FillStyleListContext( *this, mrTheme.getFillStyleList() 
);
+            return new FillStyleListContext( *this, 
mrOoxTheme.getFillStyleList() );
         case A_TOKEN( lnStyleLst ):    // CT_LineStyleList
-            return new LineStyleListContext( *this, mrTheme.getLineStyleList() 
);
+            return new LineStyleListContext( *this, 
mrOoxTheme.getLineStyleList() );
         case A_TOKEN( effectStyleLst ): // CT_EffectStyleList
-            return new EffectStyleListContext( *this, 
mrTheme.getEffectStyleList() );
+            return new EffectStyleListContext( *this, 
mrOoxTheme.getEffectStyleList() );
         case A_TOKEN( bgFillStyleLst ): // CT_BackgroundFillStyleList
-            return new FillStyleListContext( *this, 
mrTheme.getBgFillStyleList() );
+            return new FillStyleListContext( *this, 
mrOoxTheme.getBgFillStyleList() );
     }
     return nullptr;
 }
diff --git a/oox/source/drawingml/themefragmenthandler.cxx 
b/oox/source/drawingml/themefragmenthandler.cxx
index db2d6677567d..baaec066219b 100644
--- a/oox/source/drawingml/themefragmenthandler.cxx
+++ b/oox/source/drawingml/themefragmenthandler.cxx
@@ -26,11 +26,13 @@
 
 using namespace ::oox::core;
 
-namespace oox::drawingml {
+namespace oox::drawingml
+{
 
-ThemeFragmentHandler::ThemeFragmentHandler( XmlFilterBase& rFilter, const 
OUString& rFragmentPath, Theme& rTheme ) :
-    FragmentHandler2( rFilter, rFragmentPath ),
-    mrTheme( rTheme )
+ThemeFragmentHandler::ThemeFragmentHandler(XmlFilterBase& rFilter, const 
OUString& rFragmentPath, Theme& rOoxTheme, model::Theme& rTheme)
+    : FragmentHandler2(rFilter, rFragmentPath)
+    , mrOoxTheme(rOoxTheme)
+    , mrTheme(rTheme)
 {
 }
 
@@ -43,12 +45,12 @@ ContextHandlerRef ThemeFragmentHandler::onCreateContext( 
sal_Int32 nElement, con
     // CT_OfficeStyleSheet
     if (getCurrentElement() == A_TOKEN(theme))
     {
-        switch(nElement)
+        switch (nElement)
         {
             case A_TOKEN( themeElements ):              // CT_BaseStyles
-                return new ThemeElementsContext( *this, mrTheme );
+                return new ThemeElementsContext(*this, mrOoxTheme, mrTheme);
             case A_TOKEN( objectDefaults ):             // 
CT_ObjectStyleDefaults
-                return new objectDefaultContext( *this, mrTheme );
+                return new objectDefaultContext(*this, mrOoxTheme);
             case A_TOKEN( extraClrSchemeLst ):          // CT_ColorSchemeList
                 return nullptr;
             case A_TOKEN( custClrLst ):                 // CustomColorList
@@ -69,7 +71,7 @@ void ThemeFragmentHandler::onStartElement(const 
AttributeList& rAttribs)
 {
     if (getCurrentElement() == A_TOKEN(theme))
     {
-        mrTheme.setThemeName(rAttribs.getStringDefaulted(XML_name));
+        mrOoxTheme.setThemeName(rAttribs.getStringDefaulted(XML_name));
     }
 }
 
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx 
b/oox/source/ppt/presentationfragmenthandler.cxx
index c3bfc9cab9e2..b8906c735d16 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -351,9 +351,9 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 
nSlide, bool bFirstPage
                                 Reference<xml::dom::XDocument> xDoc=
                                     rFilter.importFragment(aThemeFragmentPath);
 
+                                model::Theme aTheme;
                                 rFilter.importFragment(
-                                    new ThemeFragmentHandler(
-                                        rFilter, aThemeFragmentPath, 
*pThemePtr ),
+                                    new ThemeFragmentHandler(rFilter, 
aThemeFragmentPath, *pThemePtr, aTheme),
                                     Reference<xml::sax::XFastSAXSerializable>(
                                         xDoc,
                                         UNO_QUERY_THROW));
diff --git a/oox/source/shape/ShapeContextHandler.cxx 
b/oox/source/shape/ShapeContextHandler.cxx
index a0d10e12bbc9..b6d4bcab0345 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -280,8 +280,9 @@ void SAL_CALL ShapeContextHandler::startFastElement
 
             if(!aThemeFragmentPath.isEmpty())
             {
+                model::Theme aTheme;
                 uno::Reference<xml::sax::XFastSAXSerializable> 
xDoc(mxShapeFilterBase->importFragment(aThemeFragmentPath), 
uno::UNO_QUERY_THROW);
-                mxShapeFilterBase->importFragment(new 
ThemeFragmentHandler(*mxShapeFilterBase, aThemeFragmentPath, *mpThemePtr ), 
xDoc);
+                mxShapeFilterBase->importFragment(new 
ThemeFragmentHandler(*mxShapeFilterBase, aThemeFragmentPath, *mpThemePtr, 
aTheme), xDoc);
                 mxShapeFilterBase->setCurrentTheme(mpThemePtr);
             }
         }
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index 84b6e5fd5edd..5590a4ab7605 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -44,6 +44,7 @@ $(eval $(call gb_Library_use_libraries,scfilt,\
        cppu \
        cppuhelper \
        drawinglayer \
+       docmodel \
        editeng \
        for \
        msfilter \
diff --git a/sc/source/filter/oox/workbookfragment.cxx 
b/sc/source/filter/oox/workbookfragment.cxx
index 2702335ddbbf..03abe07d6575 100644
--- a/sc/source/filter/oox/workbookfragment.cxx
+++ b/sc/source/filter/oox/workbookfragment.cxx
@@ -349,8 +349,9 @@ void WorkbookFragment::finalizeImport()
 
     // read the theme substream
     OUString aThemeFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( 
u"theme" );
+    model::Theme aTheme;
     if( !aThemeFragmentPath.isEmpty() )
-        importOoxFragment( new ThemeFragmentHandler( getFilter(), 
aThemeFragmentPath, getTheme() ) );
+        importOoxFragment(new ThemeFragmentHandler(getFilter(), 
aThemeFragmentPath, getTheme(), aTheme));
     xGlobalSegment->setPosition( 0.25 );
 
     // read the styles substream (requires finalized theme buffer)
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.cxx 
b/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.cxx
index a976453ba911..09432d1d4381 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.cxx
@@ -46,7 +46,7 @@ void OOXMLFastContextHandlerTheme::lcl_startFastElement(
             getDocument()->setTheme(pThemePtr);
         }
         mpThemeFragmentHandler = new oox::drawingml::ThemeFragmentHandler(
-            *xThemeFilterBase, aThemeFragmentPath, *pThemePtr);
+            *xThemeFilterBase, aThemeFragmentPath, *pThemePtr, maTheme);
     }
 
     if (mpThemeFragmentHandler.is())
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.hxx 
b/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.hxx
index 2de6b75590f0..c0b11bcae084 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandlerTheme.hxx
@@ -9,7 +9,7 @@
 
 #pragma once
 
-#include <set>
+#include <docmodel/theme/Theme.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
@@ -24,7 +24,9 @@ namespace writerfilter::ooxml
 {
 class OOXMLFastContextHandlerTheme : public OOXMLFastContextHandler
 {
+private:
     rtl::Reference<oox::drawingml::ThemeFragmentHandler> 
mpThemeFragmentHandler;
+    model::Theme maTheme;
 
 public:
     explicit OOXMLFastContextHandlerTheme(OOXMLFastContextHandler* pContext);
commit 855f7c08d1feab7669670bfbc4ed2b3b3225db16
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Feb 11 11:24:05 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Wed Mar 1 12:57:21 2023 +0000

    send theme info when changing color (in the picker) via UNO command
    
    Change-Id: I288f8fb3375e152b5ee746fab2c05d08150d6c99
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146817
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk
index 8db7d0fa6f93..8a07e6532dad 100644
--- a/docmodel/Library_docmodel.mk
+++ b/docmodel/Library_docmodel.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_Library_add_exception_objects,docmodel,\
     docmodel/source/uno/UnoTheme \
     docmodel/source/theme/ColorSet \
     docmodel/source/theme/Theme \
+    docmodel/source/theme/ThemeColorJSON \
 ))
 
 $(eval $(call gb_Library_set_include,docmodel,\
@@ -22,7 +23,8 @@ $(eval $(call gb_Library_set_include,docmodel,\
 ))
 
 $(eval $(call gb_Library_use_externals,docmodel,\
-       libxml2 \
+    libxml2 \
+    boost_headers \
 ))
 
 $(eval $(call gb_Library_add_defs,docmodel,\
diff --git a/docmodel/source/theme/ThemeColorJSON.cxx 
b/docmodel/source/theme/ThemeColorJSON.cxx
new file mode 100644
index 000000000000..6b2293ca1f64
--- /dev/null
+++ b/docmodel/source/theme/ThemeColorJSON.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 <docmodel/theme/ThemeColorJSON.hxx>
+#include <sstream>
+#include <utility>
+#include <sal/log.hxx>
+#include <boost/property_tree/json_parser.hpp>
+
+namespace model::theme
+{
+bool convertFromJSON(OString const& rJsonString, model::ThemeColor& 
rThemeColor)
+{
+    model::ThemeColor aThemeColor;
+    std::stringstream aStream(rJsonString.getStr());
+    boost::property_tree::ptree aRootTree;
+    try
+    {
+        boost::property_tree::read_json(aStream, aRootTree);
+    }
+    catch (const boost::property_tree::json_parser_error& /*exception*/)
+    {
+        return false;
+    }
+
+    sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1);
+    aThemeColor.setType(model::convertToThemeColorType(nThemeType));
+    boost::property_tree::ptree aTransformTree = 
aRootTree.get_child("Transformations");
+    for (const auto& rEachTransformationNode :
+         boost::make_iterator_range(aTransformTree.equal_range("")))
+    {
+        auto const& rTransformationTree = rEachTransformationNode.second;
+        std::string sType = rTransformationTree.get<std::string>("Type", "");
+        sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0);
+
+        auto eType = model::TransformationType::Undefined;
+        if (sType == "LumOff")
+            eType = model::TransformationType::LumOff;
+        else if (sType == "LumMod")
+            eType = model::TransformationType::LumMod;
+        else if (sType == "Tint")
+            eType = model::TransformationType::Tint;
+        else if (sType == "Shade")
+            eType = model::TransformationType::Shade;
+
+        if (eType != model::TransformationType::Undefined)
+            aThemeColor.addTransformation({ eType, nValue });
+    }
+    rThemeColor = aThemeColor;
+    return true;
+}
+
+OString convertToJSON(model::ThemeColor const& rThemeColor)
+{
+    boost::property_tree::ptree aTree;
+    aTree.put("ThemeIndex", sal_Int16(rThemeColor.getType()));
+
+    boost::property_tree::ptree aTransformationsList;
+    for (auto const& rTransformation : rThemeColor.getTransformations())
+    {
+        std::string aType;
+        switch (rTransformation.meType)
+        {
+            case model::TransformationType::LumMod:
+                aType = "LumMod";
+                break;
+            case model::TransformationType::LumOff:
+                aType = "LumOff";
+                break;
+            case model::TransformationType::Tint:
+                aType = "Tint";
+                break;
+            case model::TransformationType::Shade:
+                aType = "Shade";
+                break;
+            default:
+                break;
+        }
+        if (!aType.empty())
+        {
+            boost::property_tree::ptree aChild;
+            aChild.put("Type", aType);
+            aChild.put("Value", rTransformation.mnValue);
+            aTransformationsList.push_back(std::make_pair("", aChild));
+        }
+    }
+    aTree.add_child("Transformations", aTransformationsList);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+
+    return OString(aStream.str().c_str());
+}
+
+} // end model::theme
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/source/items/textitem.cxx 
b/editeng/source/items/textitem.cxx
index 5a53d6a8e14c..ece9a4a35237 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -78,6 +78,7 @@
 #include <editeng/itemtype.hxx>
 #include <editeng/eerdll.hxx>
 #include <docmodel/uno/UnoThemeColor.hxx>
+#include <docmodel/theme/ThemeColorJSON.hxx>
 #include <libxml/xmlwriter.h>
 
 using namespace ::com::sun::star;
@@ -1367,6 +1368,13 @@ SvxColorItem::SvxColorItem( const Color& rCol, const 
sal_uInt16 nId ) :
 {
 }
 
+SvxColorItem::SvxColorItem(Color const& rColor, model::ThemeColor const& 
rThemeColor, const sal_uInt16 nId)
+    : SfxPoolItem(nId)
+    , mColor(rColor)
+    , maThemeColor(rThemeColor)
+{
+}
+
 SvxColorItem::~SvxColorItem()
 {
 }
@@ -1436,12 +1444,18 @@ bool SvxColorItem::QueryValue( uno::Any& rVal, 
sal_uInt8 nMemberId ) const
             rVal <<= nValue;
             break;
         }
-       case MID_COLOR_THEME_REFERENCE:
+        case MID_COLOR_THEME_REFERENCE:
         {
             auto xThemeColor = model::theme::createXThemeColor(maThemeColor);
             rVal <<= xThemeColor;
             break;
         }
+        case MID_COLOR_THEME_REFERENCE_JSON:
+        {
+            rVal <<= 
OStringToOUString(model::theme::convertToJSON(maThemeColor), 
RTL_TEXTENCODING_UTF8);
+            break;
+        }
+        case MID_COLOR_RGB:
         default:
         {
             rVal <<= mColor;
@@ -1528,6 +1542,23 @@ bool SvxColorItem::PutValue( const uno::Any& rVal, 
sal_uInt8 nMemberId )
             }
         }
         break;
+
+        case MID_COLOR_THEME_REFERENCE_JSON:
+        {
+            OUString sThemeJson;
+            if (!(rVal >>= sThemeJson))
+                return false;
+
+            if (sThemeJson.isEmpty())
+            {
+                return false;
+            }
+            OString aJSON = OUStringToOString(sThemeJson, 
RTL_TEXTENCODING_ASCII_US);
+            model::theme::convertFromJSON(aJSON, maThemeColor);
+        }
+        break;
+
+        case MID_COLOR_RGB:
         default:
         {
             return rVal >>= mColor;
diff --git a/include/docmodel/theme/ThemeColorJSON.hxx 
b/include/docmodel/theme/ThemeColorJSON.hxx
new file mode 100644
index 000000000000..008850730e99
--- /dev/null
+++ b/include/docmodel/theme/ThemeColorJSON.hxx
@@ -0,0 +1,23 @@
+/* -*- 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 <docmodel/dllapi.h>
+#include <docmodel/theme/ThemeColor.hxx>
+
+namespace model::theme
+{
+DOCMODEL_DLLPUBLIC OString convertToJSON(model::ThemeColor const& rThemeColor);
+DOCMODEL_DLLPUBLIC bool convertFromJSON(OString const& rJsonString, 
model::ThemeColor& rThemeColor);
+
+} // end of namespace model
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/editeng/colritem.hxx b/include/editeng/colritem.hxx
index d4090eb9e7eb..fc55b6e04553 100644
--- a/include/editeng/colritem.hxx
+++ b/include/editeng/colritem.hxx
@@ -39,6 +39,7 @@ public:
 
     explicit SvxColorItem(const sal_uInt16 nId);
     SvxColorItem(const Color& aColor, const sal_uInt16 nId);
+    SvxColorItem(const Color& aColor, model::ThemeColor const& rThemeColor, 
const sal_uInt16 nId);
     virtual ~SvxColorItem() override;
 
     // "pure virtual Methods" from SfxPoolItem
@@ -63,6 +64,11 @@ public:
 
     const model::ThemeColor& GetThemeColor() const { return maThemeColor; }
 
+    void setThemeColor(model::ThemeColor const& rThemeColor)
+    {
+        maThemeColor = rThemeColor;
+    }
+
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 };
 
diff --git a/include/editeng/memberids.h b/include/editeng/memberids.h
index 0b110cb52c5d..6003ce394ba0 100644
--- a/include/editeng/memberids.h
+++ b/include/editeng/memberids.h
@@ -189,6 +189,7 @@
 #define MID_COLOR_LUM_MOD       6
 #define MID_COLOR_LUM_OFF       7
 #define MID_COLOR_THEME_REFERENCE 8
+#define MID_COLOR_THEME_REFERENCE_JSON 9
 
 
 #endif
diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc
index 0c744f007348..d3da901a09ce 100644
--- a/include/svx/svxids.hrc
+++ b/include/svx/svxids.hrc
@@ -449,9 +449,10 @@ class XFillGradientItem;
 #define SID_ATTR_TEXTCOLUMNS_NUMBER                     ( SID_SVX_START + 340 )
 #define SID_ATTR_TEXTCOLUMNS_SPACING                    ( SID_SVX_START + 341 )
 
-#define SID_ATTR_COLOR_THEME_INDEX                      
TypedWhichId<SfxInt16Item>( SID_SVX_START + 342 )
-#define SID_ATTR_COLOR_LUM_MOD                          
TypedWhichId<SfxInt16Item>( SID_SVX_START + 343 )
-#define SID_ATTR_COLOR_LUM_OFF                          
TypedWhichId<SfxInt16Item>( SID_SVX_START + 344 )
+#define SID_ATTR_COLOR_THEME_REFERENCE                  
TypedWhichId<SvxColorItem>( SID_SVX_START + 342 )
+#define SID_ATTR_COLOR_THEME_INDEX                      
TypedWhichId<SfxInt16Item>( SID_SVX_START + 343 )
+#define SID_ATTR_COLOR_LUM_MOD                          
TypedWhichId<SfxInt16Item>( SID_SVX_START + 344 )
+#define SID_ATTR_COLOR_LUM_OFF                          
TypedWhichId<SfxInt16Item>( SID_SVX_START + 345 )
 
 #define SID_SB_CONNECTIONPOOLING                        ( SID_SVX_START + 348 )
 #define SID_SB_DBREGISTEROPTIONS                        ( SID_SVX_START + 349 )
@@ -683,7 +684,6 @@ class XFillGradientItem;
 #define SID_PARAGRAPH_CHANGE_STATE                      ( SID_SVX_START + 754 )
 
 #define SID_ATTR_SHADOW_BLUR                            ( SID_SVX_START + 755 )
-
 //FREE
 //FREE
 //FREE
diff --git a/svx/sdi/svxitems.sdi b/svx/sdi/svxitems.sdi
index 66eaf39b675b..a26c02c46ebb 100644
--- a/svx/sdi/svxitems.sdi
+++ b/svx/sdi/svxitems.sdi
@@ -169,7 +169,14 @@ item INT16                  SvxParaVertAlignItem;
 item INT16                  SvxCharReliefItem;
 item BOOL                   SvxBlinkItem;
 item BOOL                   SvxAutoKernItem;
-item INT32                  SvxColorItem;
+
+struct SvxColor
+{
+    INT32  Color              MID_COLOR_RGB;
+    String ThemeReferenceJSON MID_COLOR_THEME_REFERENCE_JSON;
+};
+item SvxColor SvxColorItem;
+
 item BOOL                   SvxContourItem;
 item INT16                  SvxFormatBreakItem;  // enum
 item BOOL                   SvxFormatKeepItem;
diff --git a/svx/source/tbxctrls/PaletteManager.cxx 
b/svx/source/tbxctrls/PaletteManager.cxx
index f5cb5d221e37..314814e9dc7e 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -41,6 +41,11 @@
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/util/XURLTransformer.hpp>
 #include <com/sun/star/util/URLTransformer.hpp>
+#include <docmodel/theme/ThemeColor.hxx>
+#include <docmodel/theme/ThemeColorJSON.hxx>
+#include <editeng/colritem.hxx>
+#include <svx/svxids.hrc>
+#include <editeng/memberids.h>
 
 #include <palettes.hxx>
 
@@ -420,6 +425,7 @@ void PaletteManager::PopupColorPicker(weld::Window* 
pParent, const OUString& aCo
 
 void PaletteManager::DispatchColorCommand(const OUString& aCommand, const 
svx::NamedThemedColor& rColor)
 {
+    using namespace css;
     using namespace css::uno;
     using namespace css::frame;
     using namespace css::beans;
@@ -435,13 +441,22 @@ void PaletteManager::DispatchColorCommand(const OUString& 
aCommand, const svx::N
     INetURLObject aObj( aCommand );
 
     std::vector<PropertyValue> aArgs{
-        comphelper::makePropertyValue(aObj.GetURLPath(), 
sal_Int32(rColor.m_aColor)),
+        comphelper::makePropertyValue(aObj.GetURLPath()+ ".Color", 
sal_Int32(rColor.m_aColor)),
     };
+
     if (rColor.m_nThemeIndex != -1)
     {
-        aArgs.push_back(comphelper::makePropertyValue("ColorThemeIndex", 
rColor.m_nThemeIndex));
-        aArgs.push_back(comphelper::makePropertyValue("ColorLumMod", 
rColor.m_nLumMod));
-        aArgs.push_back(comphelper::makePropertyValue("ColorLumOff", 
rColor.m_nLumOff));
+        model::ThemeColor aThemeColor;
+        
aThemeColor.setType(model::convertToThemeColorType(rColor.m_nThemeIndex));
+        if (rColor.m_nLumMod != 10000)
+            aThemeColor.addTransformation({model::TransformationType::LumMod, 
rColor.m_nLumMod});
+        if (rColor.m_nLumMod != 0)
+            aThemeColor.addTransformation({model::TransformationType::LumOff, 
rColor.m_nLumOff});
+
+        uno::Any aAny;
+        aAny <<= OStringToOUString(model::theme::convertToJSON(aThemeColor), 
RTL_TEXTENCODING_UTF8);
+
+        aArgs.push_back(comphelper::makePropertyValue(aObj.GetURLPath() + 
".ThemeReferenceJSON", aAny));
     }
 
     URL aTargetURL;
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 4df9f6f39999..b68d5cd83baa 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1672,26 +1672,18 @@ void SwTextShell::Execute(SfxRequest &rReq)
 
         case SID_ATTR_CHAR_COLOR2:
         {
-            Color aSet;
-            bool bHasItem = false;
-
-            if(pItem)
-            {
-                aSet = static_cast<const SvxColorItem*>(pItem)->GetValue();
-                bHasItem = true;
-            }
-
-            if (bHasItem)
+            if (pItem)
             {
+                auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
                 SwEditWin& rEditWin = GetView().GetEditWin();
-                rEditWin.SetWaterCanTextColor(aSet);
+                rEditWin.SetWaterCanTextColor(pColorItem->GetValue());
                 SwApplyTemplate* pApply = rEditWin.GetApplyTemplate();
 
                 // If there is a selection, then set the color on it
                 // otherwise, it'll be the color for the next text to be typed
-                if(!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
+                if (!pApply || pApply->nColor != SID_ATTR_CHAR_COLOR_EXT)
                 {
-                    rWrtSh.SetAttrItem(SvxColorItem (aSet, RES_CHRATR_COLOR));
+                    rWrtSh.SetAttrItem(SvxColorItem(pColorItem->GetValue(), 
pColorItem->GetThemeColor(), RES_CHRATR_COLOR));
                 }
 
                 rReq.Done();

Reply via email to