diff options
author | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-04-29 13:30:42 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-05-14 16:02:26 +0200 |
commit | c61b75eede5ffd6e18a44130eba25e50dccfb1d4 (patch) | |
tree | a14562ebae980bdf75cc7c67ec80a310629bd5e6 /oox/source | |
parent | afb566b6d3b15b013007a71efe0949800aa22666 (diff) |
SmartArt: regenerate diagram command
It removes diagram content and rebuilds shape tree from diagram markup.
Diagram should appear unchanged - editing will be added in future commits.
Change-Id: I6bfc21956a1a23e55d3c7a74384db71d957d690d
Reviewed-on: https://gerrit.libreoffice.org/71584
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/core/filterbase.cxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagram.cxx | 103 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramfragmenthandler.hxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/layoutnodecontext.cxx | 1 | ||||
-rw-r--r-- | oox/source/drawingml/graphicshapecontext.cxx | 2 | ||||
-rw-r--r-- | oox/source/shape/ShapeContextHandler.hxx | 2 | ||||
-rw-r--r-- | oox/source/shape/ShapeFilterBase.cxx | 29 | ||||
-rw-r--r-- | oox/source/shape/ShapeFilterBase.hxx | 76 |
8 files changed, 135 insertions, 82 deletions
diff --git a/oox/source/core/filterbase.cxx b/oox/source/core/filterbase.cxx index ea9fdcf47c0c..b79b0a569b69 100644 --- a/oox/source/core/filterbase.cxx +++ b/oox/source/core/filterbase.cxx @@ -334,6 +334,8 @@ StorageRef const & FilterBase::getStorage() const Reference< XInputStream > FilterBase::openInputStream( const OUString& rStreamName ) const { + if (!mxImpl->mxStorage) + throw RuntimeException(); return mxImpl->mxStorage->openInputStream( rStreamName ); } diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx index e8e661e64d51..c3c28a84db23 100644 --- a/oox/source/drawingml/diagram/diagram.cxx +++ b/oox/source/drawingml/diagram/diagram.cxx @@ -17,8 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <oox/drawingml/diagram/diagram.hxx> +#include "diagram.hxx" #include <com/sun/star/awt/Point.hpp> #include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp> #include <rtl/ustrbuf.hxx> @@ -27,12 +31,12 @@ #include <drawingml/textbody.hxx> #include <drawingml/textparagraph.hxx> #include <drawingml/textrun.hxx> -#include <drawingml/diagram/diagram.hxx> #include <drawingml/fillproperties.hxx> #include <drawingml/customshapeproperties.hxx> #include <oox/ppt/pptshapegroupcontext.hxx> #include <oox/ppt/pptshape.hxx> #include <oox/token/namespaces.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> #include "diagramlayoutatoms.hxx" #include "layoutatomvisitors.hxx" @@ -544,6 +548,103 @@ void loadDiagram( ShapePtr const & pShape, pDiagram->addTo(pShape); } +void loadDiagram(ShapePtr const& pShape, + const uno::Reference<xml::dom::XDocument>& dataDom, + const uno::Reference<xml::dom::XDocument>& layoutDom, + const uno::Reference<xml::dom::XDocument>& styleDom, + const uno::Reference<xml::dom::XDocument>& colorDom, + core::XmlFilterBase& rFilter) +{ + DiagramPtr pDiagram(new Diagram); + + DiagramDataPtr pData(new DiagramData()); + pDiagram->setData(pData); + + DiagramLayoutPtr pLayout(new DiagramLayout(*pDiagram)); + pDiagram->setLayout(pLayout); + + + // data + if (dataDom.is()) + { + rtl::Reference<core::FragmentHandler> xRefDataModel( + new DiagramDataFragmentHandler(rFilter, OUString(), pData)); + + importFragment(rFilter, dataDom, "OOXData", pDiagram, xRefDataModel); + } + + // layout + if (layoutDom.is()) + { + rtl::Reference<core::FragmentHandler> xRefLayout( + new DiagramLayoutFragmentHandler(rFilter, OUString(), pLayout)); + + importFragment(rFilter, layoutDom, "OOXLayout", pDiagram, xRefLayout); + } + + // style + if (styleDom.is()) + { + rtl::Reference<core::FragmentHandler> xRefQStyle( + new DiagramQStylesFragmentHandler(rFilter, OUString(), pDiagram->getStyles())); + + importFragment(rFilter, styleDom, "OOXStyle", pDiagram, xRefQStyle); + } + + // colors + if (colorDom.is()) + { + rtl::Reference<core::FragmentHandler> xRefColorStyle( + new ColorFragmentHandler(rFilter, OUString(), pDiagram->getColors())); + + importFragment(rFilter, colorDom, "OOXColor", pDiagram, xRefColorStyle); + } + + // diagram loaded. now lump together & attach to shape + pDiagram->addTo(pShape); +} + +void reloadDiagram(css::uno::Reference<css::drawing::XShape>& rXShape, + core::XmlFilterBase& rFilter) +{ + uno::Reference<beans::XPropertySet> xPropSet(rXShape, uno::UNO_QUERY_THROW); + + uno::Reference<xml::dom::XDocument> dataDom; + uno::Reference<xml::dom::XDocument> layoutDom; + uno::Reference<xml::dom::XDocument> styleDom; + uno::Reference<xml::dom::XDocument> colorDom; + + // retrieve the doms from the GrabBag + uno::Sequence<beans::PropertyValue> propList; + xPropSet->getPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG) >>= propList; + for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) + { + OUString propName = propList[nProp].Name; + if (propName == "OOXData") + propList[nProp].Value >>= dataDom; + else if (propName == "OOXLayout") + propList[nProp].Value >>= layoutDom; + else if (propName == "OOXStyle") + propList[nProp].Value >>= styleDom; + else if (propName == "OOXColor") + propList[nProp].Value >>= colorDom; + } + + ShapePtr pShape(new Shape()); + pShape->setDiagramType(); + pShape->setSize(awt::Size(rXShape->getSize().Width * EMU_PER_HMM, + rXShape->getSize().Height * EMU_PER_HMM)); + + loadDiagram(pShape, dataDom, layoutDom, styleDom, colorDom, rFilter); + + uno::Reference<drawing::XShapes> xShapes(rXShape, uno::UNO_QUERY_THROW); + basegfx::B2DHomMatrix aTransformation; + aTransformation.translate(rXShape->getPosition().X * EMU_PER_HMM, + rXShape->getPosition().Y * EMU_PER_HMM); + for (auto const& child : pShape->getChildren()) + child->addShape(rFilter, rFilter.getCurrentTheme(), xShapes, aTransformation, pShape->getFillProperties()); +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/diagram/diagramfragmenthandler.hxx b/oox/source/drawingml/diagram/diagramfragmenthandler.hxx index 80537f5f7eac..e0f0f3d9ae87 100644 --- a/oox/source/drawingml/diagram/diagramfragmenthandler.hxx +++ b/oox/source/drawingml/diagram/diagramfragmenthandler.hxx @@ -21,7 +21,7 @@ #define INCLUDED_OOX_SOURCE_DRAWINGML_DIAGRAM_DIAGRAMFRAGMENTHANDLER_HXX #include <oox/core/fragmenthandler2.hxx> -#include <drawingml/diagram/diagram.hxx> +#include <oox/drawingml/diagram/diagram.hxx> namespace oox { namespace drawingml { diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx index 10070063c8ec..e984862c44b4 100644 --- a/oox/source/drawingml/diagram/layoutnodecontext.cxx +++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx @@ -20,7 +20,6 @@ #include "layoutnodecontext.hxx" #include <oox/helper/attributelist.hxx> -#include <drawingml/diagram/diagram.hxx> #include <oox/drawingml/shapecontext.hxx> #include <drawingml/customshapeproperties.hxx> #include "diagramdefinitioncontext.hxx" diff --git a/oox/source/drawingml/graphicshapecontext.cxx b/oox/source/drawingml/graphicshapecontext.cxx index 01b14237e9c9..527c43f9be3d 100644 --- a/oox/source/drawingml/graphicshapecontext.cxx +++ b/oox/source/drawingml/graphicshapecontext.cxx @@ -27,7 +27,7 @@ #include <drawingml/misccontexts.hxx> #include <drawingml/graphicproperties.hxx> #include <drawingml/customshapeproperties.hxx> -#include <drawingml/diagram/diagram.hxx> +#include <oox/drawingml/diagram/diagram.hxx> #include <drawingml/table/tablecontext.hxx> #include <oox/core/xmlfilterbase.hxx> #include <oox/helper/attributelist.hxx> diff --git a/oox/source/shape/ShapeContextHandler.hxx b/oox/source/shape/ShapeContextHandler.hxx index 478aaa55b0c3..2de45f533637 100644 --- a/oox/source/shape/ShapeContextHandler.hxx +++ b/oox/source/shape/ShapeContextHandler.hxx @@ -28,7 +28,7 @@ #include <oox/drawingml/theme.hxx> #include <oox/core/fragmenthandler2.hxx> #include <oox/core/xmlfilterbase.hxx> -#include "ShapeFilterBase.hxx" +#include <oox/shape/ShapeFilterBase.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> diff --git a/oox/source/shape/ShapeFilterBase.cxx b/oox/source/shape/ShapeFilterBase.cxx index 6da4a5dfbe08..bde8cdca19c3 100644 --- a/oox/source/shape/ShapeFilterBase.cxx +++ b/oox/source/shape/ShapeFilterBase.cxx @@ -17,12 +17,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "ShapeFilterBase.hxx" +#include <oox/shape/ShapeFilterBase.hxx> #include <oox/drawingml/chart/chartconverter.hxx> +#include <oox/drawingml/themefragmenthandler.hxx> #include <oox/helper/graphichelper.hxx> #include <oox/ole/vbaproject.hxx> #include <oox/drawingml/theme.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp> + namespace oox { namespace shape { @@ -109,6 +113,29 @@ GraphicHelper* ShapeFilterBase::implCreateGraphicHelper() const return nColor; } +void ShapeFilterBase::importTheme() +{ + drawingml::ThemePtr pTheme(new drawingml::Theme); + uno::Reference<beans::XPropertySet> xPropSet(getModel(), uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aGrabBag; + xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag; + + for (int i = 0; i < aGrabBag.getLength(); i++) + { + if (aGrabBag[i].Name == "OOXTheme") + { + uno::Reference<xml::sax::XFastSAXSerializable> xDoc; + if (aGrabBag[i].Value >>= xDoc) + { + rtl::Reference<core::FragmentHandler> xFragmentHandler( + new drawingml::ThemeFragmentHandler(*this, OUString(), *pTheme)); + importFragment(xFragmentHandler, xDoc); + setCurrentTheme(pTheme); + } + } + } +} + } } diff --git a/oox/source/shape/ShapeFilterBase.hxx b/oox/source/shape/ShapeFilterBase.hxx deleted file mode 100644 index 86297cda7011..000000000000 --- a/oox/source/shape/ShapeFilterBase.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_OOX_SOURCE_SHAPE_SHAPEFILTERBASE_HXX -#define INCLUDED_OOX_SOURCE_SHAPE_SHAPEFILTERBASE_HXX - -#include <memory> -#include <rtl/ref.hxx> -#include <oox/vml/vmldrawing.hxx> -#include <drawingml/table/tablestylelist.hxx> -#include <oox/core/xmlfilterbase.hxx> -#include <oox/drawingml/drawingmltypes.hxx> - -namespace oox { -namespace shape { - -class ShapeFilterBase : public core::XmlFilterBase -{ -public: - typedef std::shared_ptr<ShapeFilterBase> Pointer_t; - - /// @throws css::uno::RuntimeException - explicit ShapeFilterBase( - const css::uno::Reference< css::uno::XComponentContext >& rxContext ); - - virtual ~ShapeFilterBase() override; - - /** Has to be implemented by each filter, returns the current theme. */ - virtual const ::oox::drawingml::Theme* getCurrentTheme() const override; - - void setCurrentTheme(const ::oox::drawingml::ThemePtr& pTheme); - - /** Has to be implemented by each filter to return the collection of VML shapes. */ - virtual ::oox::vml::Drawing* getVmlDrawing() override; - - /** Has to be implemented by each filter to return TableStyles. */ - virtual const ::oox::drawingml::table::TableStyleListPtr getTableStyles() override; - - virtual ::oox::drawingml::chart::ChartConverter* getChartConverter() override; - - virtual bool importDocument() override { return true; } - virtual bool exportDocument() override { return true; } - - ::Color getSchemeColor( sal_Int32 nToken ) const; - -private: - virtual ::oox::ole::VbaProject* implCreateVbaProject() const override; - virtual OUString SAL_CALL getImplementationName() override; - virtual GraphicHelper* implCreateGraphicHelper() const override; - - std::shared_ptr< ::oox::drawingml::chart::ChartConverter > mxChartConv; - ::oox::drawingml::ThemePtr mpTheme; -}; - -} // namespace shape -} // namespace oox - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |