From ab0998c77cc5b1f15c4d584185e7c401ef6fe62b Mon Sep 17 00:00:00 2001 From: Andres Gomez Date: Tue, 3 Sep 2013 11:13:22 +0300 Subject: 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 Tested-by: Miklos Vajna --- 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 +++ 4 files changed, 123 insertions(+), 39 deletions(-) (limited to 'oox/source') diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx index a7bc286acfca..93f5850c961a 100644 --- a/oox/source/drawingml/diagram/diagram.cxx +++ b/oox/source/drawingml/diagram/diagram.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #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 Diagram::getDomsAsPropertyValues() const +{ + sal_Int32 length = maMainDomMap.size(); + + uno::Sequence 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 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 loadFragment( + core::XmlFilterBase& rFilter, + const rtl::Reference< core::FragmentHandler >& rxHandler ) +{ + return loadFragment( rFilter, rxHandler->getFragmentPath() ); } void importFragment( core::XmlFilterBase& rFilter, const uno::Reference& 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 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::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 93e810472c7e..3df38a8bc3cf 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 > 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 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 ee9d9de369fb..d8d127a48ea4 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -37,6 +37,7 @@ #include "oox/helper/propertyset.hxx" #include // for the F_PI180 define +#include #include #include #include @@ -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 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 3f601b328309..461a1fe175aa 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 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(); } -- cgit