include/oox/shape/ShapeFilterBase.hxx          |    2 -
 include/svx/diagram/datamodel.hxx              |   11 +++++++
 oox/source/drawingml/diagram/diagram.cxx       |    6 ++++
 oox/source/drawingml/diagram/diagramhelper.cxx |   35 ++++++++++++++++++++++++-
 oox/source/drawingml/diagram/diagramhelper.hxx |    7 +++--
 oox/source/shape/ShapeFilterBase.cxx           |   23 ----------------
 6 files changed, 56 insertions(+), 28 deletions(-)

New commits:
commit 027db2df5371183136f87e84ec4829d59eef209b
Author:     Armin Le Grand (Allotropia) <[email protected]>
AuthorDate: Fri Apr 8 17:38:12 2022 +0200
Commit:     Armin Le Grand <[email protected]>
CommitDate: Mon Apr 11 09:54:33 2022 +0200

    Advanced Diagram support: Make Style/Theme info available
    
    The Style/Theme information is central for re-creating the
    Diagram shape representation. Make that data available in
    the ModelData classes in svx. With that information, a re-
    creation with all needed attributes is possible, e.g. when
    the model gets changed (remove/add data entries).
    Also some cleanups done.
    
    Change-Id: Icd925c9731891092f1ddd96c8feb165e1f846f4f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132738
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <[email protected]>

diff --git a/include/oox/shape/ShapeFilterBase.hxx 
b/include/oox/shape/ShapeFilterBase.hxx
index 200bc92ee492..477060fa6e48 100644
--- a/include/oox/shape/ShapeFilterBase.hxx
+++ b/include/oox/shape/ShapeFilterBase.hxx
@@ -70,8 +70,6 @@ public:
 
     ::Color getSchemeColor( sal_Int32 nToken ) const;
 
-    void importTheme();
-
     void setGraphicMapper(css::uno::Reference<css::graphic::XGraphicMapper> 
const & rxGraphicMapper)
     {
         mxGraphicMapper = rxGraphicMapper;
diff --git a/include/svx/diagram/datamodel.hxx 
b/include/svx/diagram/datamodel.hxx
index 3df7cc2e8afd..c42a3d26a115 100644
--- a/include/svx/diagram/datamodel.hxx
+++ b/include/svx/diagram/datamodel.hxx
@@ -30,6 +30,7 @@
 
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
 
 namespace svx::diagram {
 
@@ -183,6 +184,9 @@ public:
     OUString addNode(const OUString& rText);
     bool removeNode(const OUString& rNodeId);
 
+    const css::uno::Reference< css::xml::dom::XDocument >& getThemeDocument() 
const { return mxThemeDocument; }
+    void setThemeDocument( const css::uno::Reference< css::xml::dom::XDocument 
>& xRef ) { mxThemeDocument = xRef; }
+
 protected:
     void getChildrenString(OUStringBuffer& rBuf, const Point* pPoint, 
sal_Int32 nLevel) const;
     void addConnection(TypeConstant nType, const OUString& sSourceId, const 
OUString& sDestId);
@@ -194,8 +198,15 @@ protected:
     // See evtl. parts in oox::drawingml::DiagramData that may need t obe 
accessed
     // - logic connections/associations
     // - data point entries
+    // - Theme definition as css::xml::dom::XDocument
+    //    Note: I decided to use dom::XDocument which is already in use, 
instead of a
+    //          temp file what is also possible (implemented that for POC) but 
would
+    //          need to be created in 
PresentationFragmentHandler::importSlide. If
+    //          this needs to be written to a File, please refer to
+    //          fileDocxExport::WriteTheme(), look for "OOXTheme"
     Connections maConnections;
     Points maPoints;
+    css::uno::Reference< css::xml::dom::XDocument > mxThemeDocument;
 
     // temporary processing data, deleted when using build()
     PointNameMap      maPointNameMap;
diff --git a/oox/source/drawingml/diagram/diagram.cxx 
b/oox/source/drawingml/diagram/diagram.cxx
index d12deea33d2f..484e7af9fd13 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -416,6 +416,12 @@ void loadDiagram( ShapePtr const & pShape,
     pDiagram->addTo(pShape);
     pShape->setDiagramDoms(pDiagram->getDomsAsPropertyValues());
 
+    // Get the oox::Theme definition and - if available - move/secure the
+    // original ImportData directly to the Diagram ModelData
+    std::shared_ptr<::oox::drawingml::Theme> 
aTheme(rFilter.getCurrentThemePtr());
+    if(aTheme)
+        pData->setThemeDocument(aTheme->getFragment()); //getTempFile());
+
     // Prepare support for the advanced DiagramHelper using Diagram & Theme 
data
     pShape->prepareDiagramHelper(pDiagram, rFilter.getCurrentThemePtr());
 }
diff --git a/oox/source/drawingml/diagram/diagramhelper.cxx 
b/oox/source/drawingml/diagram/diagramhelper.cxx
index 4ed76e5bff1c..cc6efd9ba50e 100644
--- a/oox/source/drawingml/diagram/diagramhelper.cxx
+++ b/oox/source/drawingml/diagram/diagramhelper.cxx
@@ -26,6 +26,8 @@
 #include <drawingml/fillproperties.hxx>
 #include <svx/svdmodel.hxx>
 #include <comphelper/processfactory.hxx>
+#include <oox/drawingml/themefragmenthandler.hxx>
+#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
 
 using namespace ::com::sun::star;
 
@@ -101,7 +103,7 @@ void AdvancedDiagramHelper::reLayout(SdrObjGroup& rTarget)
 
     // set oox::Theme at Filter. All LineStyle/FillStyle/Colors/Attributes
     // will be taken from there
-    xFilter->setCurrentTheme(mpThemePtr);
+    xFilter->setCurrentTheme(getOrCreateThemePtr(xFilter));
 
     css::uno::Reference< css::lang::XComponent > aComponentModel( rUnoModel, 
uno::UNO_QUERY );
     xFilter->setTargetDocument(aComponentModel);
@@ -183,6 +185,37 @@ void AdvancedDiagramHelper::doAnchor(SdrObjGroup& rTarget)
     anchorToSdrObjGroup(rTarget);
 }
 
+std::shared_ptr< ::oox::drawingml::Theme > 
AdvancedDiagramHelper::getOrCreateThemePtr(
+    rtl::Reference< oox::shape::ShapeFilterBase >& rxFilter) const
+{
+    static bool bForceThemePtrReceation(false);
+
+    // (Re-)Use already existing Theme if existing/imported if possible.
+    // If not, re-import Theme if data is available and thus possible
+    if(hasDiagramData() && (bForceThemePtrReceation || !mpThemePtr))
+    {
+        // get the originally imported dom::XDocument
+        const uno::Reference< css::xml::dom::XDocument >& 
xThemeDocument(mpDiagramPtr->getData()->getThemeDocument());
+
+        if(xThemeDocument)
+        {
+            // 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>();
+
+            // import Theme ModelData
+            rxFilter->importFragment(
+                new ThemeFragmentHandler(
+                    *rxFilter, OUString(), *mpThemePtr ),
+                uno::Reference< css::xml::sax::XFastSAXSerializable >(
+                    xThemeDocument,
+                    uno::UNO_QUERY_THROW));
+        }
+    }
+
+    return mpThemePtr;
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/diagram/diagramhelper.hxx 
b/oox/source/drawingml/diagram/diagramhelper.hxx
index 33fd2da9d7a1..d8fd46ce57a1 100644
--- a/oox/source/drawingml/diagram/diagramhelper.hxx
+++ b/oox/source/drawingml/diagram/diagramhelper.hxx
@@ -22,6 +22,7 @@
 
 #include <rtl/ustring.hxx>
 #include <oox/drawingml/theme.hxx>
+#include <oox/shape/ShapeFilterBase.hxx>
 #include <svx/svdogrp.hxx>
 
 namespace oox::drawingml {
@@ -43,8 +44,8 @@ class Diagram;
 // - im/export Diagram model to other representations
 class AdvancedDiagramHelper final : public IDiagramHelper
 {
-    const std::shared_ptr< Diagram >                mpDiagramPtr;
-    const std::shared_ptr<::oox::drawingml::Theme>  mpThemePtr;
+    const std::shared_ptr< Diagram >            mpDiagramPtr;
+    std::shared_ptr<::oox::drawingml::Theme>    mpThemePtr;
 
     css::awt::Size maImportSize;
 
@@ -73,6 +74,8 @@ public:
     virtual bool removeNode(const OUString& rNodeId) override;
 
     void doAnchor(SdrObjGroup& rTarget);
+    std::shared_ptr< ::oox::drawingml::Theme > getOrCreateThemePtr(
+        rtl::Reference< oox::shape::ShapeFilterBase>& rxFilter ) const;
 };
 
 }
diff --git a/oox/source/shape/ShapeFilterBase.cxx 
b/oox/source/shape/ShapeFilterBase.cxx
index ebd47d83e9d5..ad10c4fe670d 100644
--- a/oox/source/shape/ShapeFilterBase.cxx
+++ b/oox/source/shape/ShapeFilterBase.cxx
@@ -132,29 +132,6 @@ GraphicHelper* ShapeFilterBase::implCreateGraphicHelper() 
const
     return nColor;
 }
 
-void ShapeFilterBase::importTheme()
-{
-    drawingml::ThemePtr pTheme = std::make_shared<drawingml::Theme>();
-    uno::Reference<beans::XPropertySet> xPropSet(getModel(), 
uno::UNO_QUERY_THROW);
-    uno::Sequence<beans::PropertyValue> aGrabBag;
-    xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag;
-
-    for (const auto& rProp : std::as_const(aGrabBag))
-    {
-        if (rProp.Name == "OOXTheme")
-        {
-            uno::Reference<xml::sax::XFastSAXSerializable> xDoc;
-            if (rProp.Value >>= xDoc)
-            {
-                rtl::Reference<core::FragmentHandler> xFragmentHandler(
-                    new drawingml::ThemeFragmentHandler(*this, OUString(), 
*pTheme));
-                importFragment(xFragmentHandler, xDoc);
-                setCurrentTheme(pTheme);
-            }
-        }
-    }
-}
-
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to