[Libreoffice-commits] core.git: include/oox oox/source sw/qa

Andres Gomez agomez at igalia.com
Wed Sep 11 00:36:19 PDT 2013


 include/oox/drawingml/shape.hxx          |    5 +
 oox/source/drawingml/diagram/diagram.cxx |  106 +++++++++++++++++++++----------
 oox/source/drawingml/diagram/diagram.hxx |   20 ++++-
 oox/source/drawingml/shape.cxx           |   27 +++++++
 oox/source/shape/ShapeContextHandler.cxx |    9 ++
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx |   47 +++++++++++++
 6 files changed, 175 insertions(+), 39 deletions(-)

New commits:
commit ab0998c77cc5b1f15c4d584185e7c401ef6fe62b
Author: Andres Gomez <agomez at igalia.com>
Date:   Tue Sep 3 11:13:22 2013 +0300

    oox: Smart-Art DOMs stored in the InteropGrabBag
    
    The XDocuments representing the DOM documents of a
    DrawingML diagram (Smart-Art) are now stored as
    the PropertyValues "OOXData", "OOXLayout",
    "OOXStyle",  "OOXColor" and "OOXDrawing" into the
    "InteropGraBag" property of the parent
    SvxGroupShape created from such diagram.
    
    Modified the oox::drawingml::dgm::Diagram class to
    be able to hold the map storing the XDocuments and
    its names. Added the getDomMap() method to obtain
    the map directly and the getDomsAsPropertyValues
    method to get the map as a sequence of Property
    Values.
    
    Modified the methods for importing and loading the
    Smart-Art into the Diagram so they add
    automatically the DOM documents to it.
    
    Modified the oox::drawingml::Shape class to be
    able to hold the sequence of PropertyValues
    storing the XDocuments and its names coming from
    the oox::drawingml::dgm::Diagram class. Added the
    getDiagramDoms() and setDiagramDoms() methods.
    
    Enhanced the
    oox::shape::ShapeContextHandler::getShape() method
    to add the extended drawing document to the
    oox::drawingml::Shape class.
    
    Modified the
    oox::drawingml::Shape::createAndInsert() method to
    store the sequence of XDocuments in the
    "InteropGrabBag" property of the GroupShape
    service SvxGroupShape implementation representing
    a Smart-Art.
    
    Change-Id: I7d0b9dfbfc9d5299ddd25fab394e5e9a422d1dd1
    Reviewed-on: https://gerrit.libreoffice.org/5849
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx
index 94c8342..8573968 100644
--- a/include/oox/drawingml/shape.hxx
+++ b/include/oox/drawingml/shape.hxx
@@ -174,6 +174,9 @@ public:
     void                addExtDrawingRelId( const OUString &rRelId ) { maExtDrawings.push_back( rRelId ); }
     void                setLockedCanvas(bool bLockedCanvas);
     bool                getLockedCanvas();
+    const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> &
+                        getDiagramDoms() { return maDiagramDoms; }
+    void                setDiagramDoms(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rDiagramDoms) { maDiagramDoms = rDiagramDoms; }
 
 protected:
 
@@ -265,6 +268,8 @@ private:
                                                          // we need separate flag because we don't want
                                                          // to propagate it when applying reference shape
     bool mbLockedCanvas; ///< Is this shape part of a locked canvas?
+
+    com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> maDiagramDoms;
 };
 
 // ============================================================================
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index a7bc286..93f5850 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
 #include <rtl/ustrbuf.hxx>
+#include <editeng/unoprnms.hxx>
 #include "oox/drawingml/textbody.hxx"
 #include "oox/drawingml/textparagraph.hxx"
 #include "oox/drawingml/textrun.hxx"
@@ -329,23 +330,53 @@ void Diagram::addTo( const ShapePtr & pParentShape )
     ShapeCreationVisitor aCreationVisitor(pParentShape, *this);
     if( mpLayout->getNode() )
         mpLayout->getNode()->accept( aCreationVisitor );
+
+    pParentShape->setDiagramDoms( getDomsAsPropertyValues() );
+}
+
+uno::Sequence<beans::PropertyValue> Diagram::getDomsAsPropertyValues() const
+{
+    sal_Int32 length = maMainDomMap.size();
+
+    uno::Sequence<beans::PropertyValue> aValue(length);
+    beans::PropertyValue* pValue = aValue.getArray();
+    for (DiagramDomMap::const_iterator i = maMainDomMap.begin();
+         i != maMainDomMap.end();
+         ++i)
+    {
+        pValue[0].Name = i->first;
+        pValue[0].Value = uno::makeAny(i->second);
+        ++pValue;
+    }
+
+    return aValue;
 }
 
 uno::Reference<xml::dom::XDocument> loadFragment(
     core::XmlFilterBase& rFilter,
-    const rtl::Reference< core::FragmentHandler >& rxHandler )
+    const OUString& rFragmentPath )
 {
     // load diagramming fragments into DOM representation, that later
     // gets serialized back to SAX events and parsed
-    return rFilter.importFragment( rxHandler->getFragmentPath() );
+    return rFilter.importFragment( rFragmentPath );
+}
+
+uno::Reference<xml::dom::XDocument> loadFragment(
+    core::XmlFilterBase& rFilter,
+    const rtl::Reference< core::FragmentHandler >& rxHandler )
+{
+    return loadFragment( rFilter, rxHandler->getFragmentPath() );
 }
 
 void importFragment( core::XmlFilterBase& rFilter,
                      const uno::Reference<xml::dom::XDocument>& rXDom,
-                     const char* /*pPropName*/,
-                     const ShapePtr& /*pShape*/,
+                     const char* pDocName,
+                     const DiagramPtr& pDiagram,
                      const rtl::Reference< core::FragmentHandler >& rxHandler )
 {
+    DiagramDomMap& rMainDomMap = pDiagram->getDomMap();
+    rMainDomMap[OUString::createFromAscii(pDocName)] = rXDom;
+
     uno::Reference<xml::sax::XFastSAXSerializable> xSerializer(
         rXDom, uno::UNO_QUERY_THROW);
 
@@ -371,14 +402,14 @@ void loadDiagram( ShapePtr& pShape,
     // data
     if( !rDataModelPath.isEmpty() )
     {
-        rtl::Reference< core::FragmentHandler > xRef(
-            new DiagramDataFragmentHandler( rFilter, rDataModelPath, pData ));
+        rtl::Reference< core::FragmentHandler > xRefDataModel(
+                new DiagramDataFragmentHandler( rFilter, rDataModelPath, pData ));
 
         importFragment(rFilter,
-                       loadFragment(rFilter,xRef),
-                       "DiagramData",
-                       pShape,
-                       xRef);
+                       loadFragment(rFilter,xRefDataModel),
+                       "OOXData",
+                       pDiagram,
+                       xRefDataModel);
         // Pass the info to pShape
         for( ::std::vector<OUString>::const_iterator aIt = pData->getExtDrawings().begin(), aEnd = pData->getExtDrawings().end();
                 aIt != aEnd; ++aIt )
@@ -391,38 +422,47 @@ void loadDiagram( ShapePtr& pShape,
         // layout
         if( !rLayoutPath.isEmpty() )
         {
-            rtl::Reference< core::FragmentHandler > xRef(
+            rtl::Reference< core::FragmentHandler > xRefLayout(
                     new DiagramLayoutFragmentHandler( rFilter, rLayoutPath, pLayout ));
+
             importFragment(rFilter,
-                    loadFragment(rFilter,xRef),
-                    "DiagramLayout",
-                    pShape,
-                    xRef);
+                    loadFragment(rFilter,xRefLayout),
+                    "OOXLayout",
+                    pDiagram,
+                    xRefLayout);
         }
 
         // style
         if( !rQStylePath.isEmpty() )
         {
-            rtl::Reference< core::FragmentHandler > xRef(
+            rtl::Reference< core::FragmentHandler > xRefQStyle(
                     new DiagramQStylesFragmentHandler( rFilter, rQStylePath, pDiagram->getStyles() ));
+
             importFragment(rFilter,
-                    loadFragment(rFilter,xRef),
-                    "DiagramQStyle",
-                    pShape,
-                    xRef);
+                    loadFragment(rFilter,xRefQStyle),
+                    "OOXStyle",
+                    pDiagram,
+                    xRefQStyle);
         }
 
         // colors
         if( !rColorStylePath.isEmpty() )
         {
-            rtl::Reference< core::FragmentHandler > xRef(
+            rtl::Reference< core::FragmentHandler > xRefColorStyle(
                     new ColorFragmentHandler( rFilter, rColorStylePath, pDiagram->getColors() ));
+
             importFragment(rFilter,
-                    loadFragment(rFilter,xRef),
-                    "DiagramColorStyle",
-                    pShape,
-                    xRef);
+                    loadFragment(rFilter,xRefColorStyle),
+                    "OOXColor",
+                    pDiagram,
+                    xRefColorStyle);
         }
+    } else {
+        // We still want to add the XDocuments to the DiagramDomMap
+        DiagramDomMap& rMainDomMap = pDiagram->getDomMap();
+        rMainDomMap[OUString::createFromAscii("OOXLayout")] = loadFragment(rFilter,rLayoutPath);
+        rMainDomMap[OUString::createFromAscii("OOXStyle")] = loadFragment(rFilter,rQStylePath);
+        rMainDomMap[OUString::createFromAscii("OOXColor")] = loadFragment(rFilter,rColorStylePath);
     }
 
     // diagram loaded. now lump together & attach to shape
@@ -450,32 +490,32 @@ void loadDiagram( const ShapePtr& pShape,
     if( rXDataModelDom.is() )
         importFragment(rFilter,
                        rXDataModelDom,
-                       "DiagramData",
-                       pShape,
+                       "OOXData",
+                       pDiagram,
                        new DiagramDataFragmentHandler( rFilter, aEmpty, pData ));
 
     // layout
     if( rXLayoutDom.is() )
         importFragment(rFilter,
                        rXLayoutDom,
-                       "DiagramLayout",
-                       pShape,
+                       "OOXLayout",
+                       pDiagram,
                        new DiagramLayoutFragmentHandler( rFilter, aEmpty, pLayout ));
 
     // style
     if( rXQStyleDom.is() )
         importFragment(rFilter,
                        rXQStyleDom,
-                       "DiagramQStyle",
-                       pShape,
+                       "OOXStyle",
+                       pDiagram,
                        new DiagramQStylesFragmentHandler( rFilter, aEmpty, pDiagram->getStyles() ));
 
     // colors
     if( rXColorStyleDom.is() )
         importFragment(rFilter,
                        rXColorStyleDom,
-                       "DiagramColorStyle",
-                       pShape,
+                       "OOXColor",
+                       pDiagram,
                        new ColorFragmentHandler( rFilter, aEmpty, pDiagram->getColors() ));
 
     // diagram loaded. now lump together & attach to shape
diff --git a/oox/source/drawingml/diagram/diagram.hxx b/oox/source/drawingml/diagram/diagram.hxx
index 93e8104..3df38a8 100644
--- a/oox/source/drawingml/diagram/diagram.hxx
+++ b/oox/source/drawingml/diagram/diagram.hxx
@@ -35,6 +35,8 @@ namespace com { namespace sun { namespace star {
     namespace xml { namespace dom { class XDocument; } }
 } } }
 
+using namespace ::com::sun::star;
+
 namespace oox { namespace drawingml {
 
 namespace dgm {
@@ -154,6 +156,10 @@ typedef boost::shared_ptr< LayoutNode > LayoutNodePtr;
 
 ////////////////////
 
+typedef std::map< OUString, uno::Reference<xml::dom::XDocument> > DiagramDomMap;
+
+////////////////////
+
 class DiagramData
 {
 public:
@@ -289,15 +295,19 @@ public:
     const DiagramQStyleMap& getStyles() const { return maStyles; }
     DiagramColorMap& getColors() { return maColors; }
     const DiagramColorMap& getColors() const { return maColors; }
+    DiagramDomMap & getDomMap() { return maMainDomMap; }
 
     void addTo( const ShapePtr & pShape );
+
+    uno::Sequence<beans::PropertyValue> getDomsAsPropertyValues() const;
 private:
     void build( );
-    DiagramDataPtr                             mpData;
-    DiagramLayoutPtr                           mpLayout;
-    DiagramQStyleMap                           maStyles;
-    DiagramColorMap                            maColors;
-    std::map< OUString, ShapePtr >             maShapeMap;
+    DiagramDataPtr                 mpData;
+    DiagramLayoutPtr               mpLayout;
+    DiagramQStyleMap               maStyles;
+    DiagramColorMap                maColors;
+    std::map< OUString, ShapePtr > maShapeMap;
+    DiagramDomMap                  maMainDomMap;
 };
 
 
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index ee9d9de..d8d127a 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -37,6 +37,7 @@
 #include "oox/helper/propertyset.hxx"
 
 #include <tools/solar.h>        // for the F_PI180 define
+#include <editeng/unoprnms.hxx>
 #include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/container/XNamed.hpp>
 #include <com/sun/star/container/XNameContainer.hpp>
@@ -83,6 +84,7 @@ Shape::Shape( const sal_Char* pServiceName )
 , mbHidden( false )
 , mbHiddenMasterShape( false )
 , mbLockedCanvas( false )
+, maDiagramDoms( 0 )
 {
     if ( pServiceName )
         msServiceName = OUString::createFromAscii( pServiceName );
@@ -118,6 +120,7 @@ Shape::Shape( const ShapePtr& pSourceShape )
 , mbHidden( pSourceShape->mbHidden )
 , mbHiddenMasterShape( pSourceShape->mbHiddenMasterShape )
 , mbLockedCanvas( pSourceShape->mbLockedCanvas )
+, maDiagramDoms( pSourceShape->maDiagramDoms )
 {}
 
 
@@ -571,7 +574,8 @@ Reference< XShape > Shape::createAndInsert(
             if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
                 xSet->setPropertyValue( rPropName, Any( false ) );
 
-        // do not set properties at a group shape (this causes assertions from svx)
+        // do not set properties at a group shape (this causes
+        // assertions from svx) ...
         if( aServiceName != "com.sun.star.drawing.GroupShape" )
         {
             PropertySet( xSet ).setProperties( aShapeProps );
@@ -583,6 +587,27 @@ Reference< XShape > Shape::createAndInsert(
             }
         }
 
+        // ... but for the InteropGrabBag property
+        const OUString& aGrabBagPropName = OUString::createFromAscii(UNO_NAME_MISC_OBJ_INTEROPGRABBAG);
+        if( maDiagramDoms.hasElements() && xSetInfo.is() && xSetInfo->hasPropertyByName( aGrabBagPropName ) )
+        {
+            Sequence<PropertyValue> aGrabBag;
+            xSet->getPropertyValue( aGrabBagPropName ) >>= aGrabBag;
+
+            // we keep the previous items, if present
+            if (aGrabBag.hasElements())
+            {
+                sal_Int32 length = aGrabBag.getLength();
+                aGrabBag.realloc(length+maDiagramDoms.getLength());
+
+                for(sal_Int32 i = 0; i < maDiagramDoms.getLength(); ++i)
+                    aGrabBag[length+i] = maDiagramDoms[i];
+
+                xSet->setPropertyValue( aGrabBagPropName, Any( aGrabBag ) );
+            } else
+                xSet->setPropertyValue( aGrabBagPropName, Any( maDiagramDoms ) );
+        }
+
         if( bIsCustomShape )
         {
             if ( mbFlipH )
diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index 3f601b3..461a1fe 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -326,6 +326,15 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
                     OUString aFragmentPath(pDiagramGraphicDataContext->getFragmentPathFromRelId(*aIt));
                     oox::drawingml::ShapePtr pShapePtr( new Shape( "com.sun.star.drawing.GroupShape" ) );
                     mxFilterBase->importFragment(new ShapeDrawingFragmentHandler(*mxFilterBase, aFragmentPath, pShapePtr));
+
+                    uno::Sequence<beans::PropertyValue> aValue(mpShape->getDiagramDoms());
+                    sal_Int32 length = aValue.getLength();
+                    aValue.realloc(length+1);
+                    beans::PropertyValue* pValue = aValue.getArray();
+                    pValue[length].Name = OUString::createFromAscii("OOXDrawing");
+                    pValue[length].Value = uno::makeAny( mxFilterBase->importFragment( aFragmentPath ) );
+                    pShapePtr->setDiagramDoms( aValue );
+
                     pShapePtr->addShape( *mxFilterBase, mpThemePtr.get(), xShapes, aMatrix, pShapePtr->getFillProperties() );
                     xResult = pShapePtr->getXShape();
                 }
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index b933e85..06a3ae2 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -36,6 +36,7 @@
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <com/sun/star/table/TableBorder2.hpp>
 #include <com/sun/star/text/SizeType.hpp>
+#include <com/sun/star/xml/dom/XDocument.hpp>
 
 #include <vcl/svapp.hxx>
 
@@ -542,6 +543,52 @@ void Test::testSmartart()
     uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xGroup->getCount()); // 3 rectangles and an arrow in the group
 
+    uno::Reference<beans::XPropertySet> xGroupPropertySet(getShape(1), uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aGrabBag(0);
+    xGroupPropertySet->getPropertyValue(OUString::createFromAscii("InteropGrabBag")) >>= aGrabBag;
+    CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
+
+    sal_Bool bData, bLayout, bQStyle, bColor, bDrawing = sal_False;
+    for(int i = 0; i < aGrabBag.getLength(); ++i)
+    {
+      if (aGrabBag[i].Name == OUString::createFromAscii("OOXData"))
+      {
+        bData = sal_True;
+        uno::Reference<xml::dom::XDocument> aDataDom;
+        CPPUNIT_ASSERT(aGrabBag[i].Value >>= aDataDom); // PropertyValue of proper type
+        CPPUNIT_ASSERT(aDataDom.get()); // Reference not empty
+      }
+      else if (aGrabBag[i].Name == OUString::createFromAscii("OOXLayout"))
+      {
+        bLayout = sal_True;
+        uno::Reference<xml::dom::XDocument> aLayoutDom;
+        CPPUNIT_ASSERT(aGrabBag[i].Value >>= aLayoutDom); // PropertyValue of proper type
+        CPPUNIT_ASSERT(aLayoutDom.get()); // Reference not empty
+      }
+      else if (aGrabBag[i].Name == OUString::createFromAscii("OOXStyle"))
+      {
+        bQStyle = sal_True;
+        uno::Reference<xml::dom::XDocument> aStyleDom;
+        CPPUNIT_ASSERT(aGrabBag[i].Value >>= aStyleDom); // PropertyValue of proper type
+        CPPUNIT_ASSERT(aStyleDom.get()); // Reference not empty
+      }
+      else if (aGrabBag[i].Name == OUString::createFromAscii("OOXColor"))
+      {
+        bColor = sal_True;
+        uno::Reference<xml::dom::XDocument> aColorDom;
+        CPPUNIT_ASSERT(aGrabBag[i].Value >>= aColorDom); // PropertyValue of proper type
+        CPPUNIT_ASSERT(aColorDom.get()); // Reference not empty
+      }
+      else if (aGrabBag[i].Name == OUString::createFromAscii("OOXDrawing"))
+      {
+        bDrawing = sal_True;
+        uno::Reference<xml::dom::XDocument> aDrawingDom;
+        CPPUNIT_ASSERT(aGrabBag[i].Value >>= aDrawingDom); // PropertyValue of proper type
+        CPPUNIT_ASSERT(aDrawingDom.get()); // Reference not empty
+      }
+    }
+    CPPUNIT_ASSERT(bData && bLayout && bQStyle && bColor && bDrawing); // Grab Bag has all the expected elements
+
     uno::Reference<beans::XPropertySet> xPropertySet(xGroup->getByIndex(1), uno::UNO_QUERY);
     sal_Int32 nValue(0);
     xPropertySet->getPropertyValue("FillColor") >>= nValue;


More information about the Libreoffice-commits mailing list