Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "oox/ppt/dgmlayout.hxx"
21 : #include "oox/drawingml/theme.hxx"
22 : #include "oox/drawingml/themefragmenthandler.hxx"
23 : #include "drawingml/diagram/diagram.hxx"
24 : #include "oox/dump/pptxdumper.hxx"
25 :
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/drawing/XShape.hpp>
28 : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
29 : #include <com/sun/star/uno/XComponentContext.hpp>
30 : #include <com/sun/star/xml/dom/XDocument.hpp>
31 : #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
32 : #include <com/sun/star/container/XChild.hpp>
33 :
34 : #include <services.hxx>
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::xml::sax;
39 : using namespace oox::core;
40 : using namespace ::oox::drawingml;
41 :
42 : namespace oox { namespace ppt {
43 :
44 90 : OUString SAL_CALL QuickDiagrammingLayout_getImplementationName()
45 : {
46 90 : return OUString( "com.sun.star.comp.Impress.oox.QuickDiagrammingLayout" );
47 : }
48 :
49 0 : uno::Sequence< OUString > SAL_CALL QuickDiagrammingLayout_getSupportedServiceNames()
50 : {
51 0 : const OUString aServiceName = "com.sun.star.comp.ooxpptx.dgm.layout";
52 0 : const Sequence< OUString > aSeq( &aServiceName, 1 );
53 0 : return aSeq;
54 : }
55 :
56 0 : uno::Reference< uno::XInterface > SAL_CALL QuickDiagrammingLayout_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
57 : {
58 0 : return static_cast<cppu::OWeakObject*>(new QuickDiagrammingLayout( rxContext ));
59 : }
60 :
61 0 : QuickDiagrammingLayout::QuickDiagrammingLayout( const Reference< XComponentContext >& rxContext )
62 : : XmlFilterBase( rxContext ),
63 0 : mpThemePtr(new drawingml::Theme())
64 0 : {}
65 :
66 0 : bool QuickDiagrammingLayout::importDocument() throw (css::uno::RuntimeException)
67 : {
68 0 : Reference<drawing::XShape> xParentShape(getParentShape(),
69 0 : UNO_QUERY_THROW);
70 : Reference<drawing::XShapes> xParentShapes(xParentShape,
71 0 : UNO_QUERY_THROW);
72 : Reference<beans::XPropertySet> xPropSet(xParentShape,
73 0 : UNO_QUERY_THROW);
74 :
75 : // can we grab the theme from the master page?
76 : Reference<container::XChild> xChild(xParentShape,
77 0 : UNO_QUERY);
78 0 : if( xChild.is() )
79 : {
80 : // TODO: cater for diagram shapes inside groups
81 0 : Reference<drawing::XMasterPageTarget> xMasterPageTarget(xChild->getParent(),
82 0 : UNO_QUERY);
83 0 : if( xMasterPageTarget.is() )
84 : {
85 : uno::Reference<drawing::XDrawPage> xMasterPage(
86 0 : xMasterPageTarget->getMasterPage());
87 :
88 : Reference<beans::XPropertySet> xPropSet2(xMasterPage,
89 0 : UNO_QUERY_THROW);
90 0 : Reference<xml::dom::XDocument> xThemeFragment;
91 0 : xPropSet2->getPropertyValue("PPTTheme") >>= xThemeFragment;
92 :
93 : importFragment(
94 : new ThemeFragmentHandler(
95 0 : *this, OUString(), *mpThemePtr ),
96 : Reference<xml::sax::XFastSAXSerializable>(
97 : xThemeFragment,
98 0 : UNO_QUERY_THROW));
99 0 : }
100 : }
101 :
102 0 : Reference<xml::dom::XDocument> xDataModelDom;
103 0 : Reference<xml::dom::XDocument> xLayoutDom;
104 0 : Reference<xml::dom::XDocument> xQStyleDom;
105 0 : Reference<xml::dom::XDocument> xColorStyleDom;
106 :
107 0 : xPropSet->getPropertyValue("DiagramData") >>= xDataModelDom;
108 0 : xPropSet->getPropertyValue("DiagramLayout") >>= xLayoutDom;
109 0 : xPropSet->getPropertyValue("DiagramQStyle") >>= xQStyleDom;
110 0 : xPropSet->getPropertyValue("DiagramColorStyle") >>= xColorStyleDom;
111 :
112 : oox::drawingml::ShapePtr pShape(
113 0 : new oox::drawingml::Shape( "com.sun.star.drawing.DiagramShape" ) );
114 : drawingml::loadDiagram(pShape,
115 : *this,
116 : xDataModelDom,
117 : xLayoutDom,
118 : xQStyleDom,
119 0 : xColorStyleDom);
120 :
121 : // don't add pShape itself, but only its children
122 0 : pShape->setXShape(getParentShape());
123 :
124 0 : const awt::Size& rSize=xParentShape->getSize();
125 0 : const awt::Point& rPoint=xParentShape->getPosition();
126 0 : const long nScaleFactor=360;
127 : const awt::Rectangle aRect(nScaleFactor*rPoint.X,
128 : nScaleFactor*rPoint.Y,
129 : nScaleFactor*rSize.Width,
130 0 : nScaleFactor*rSize.Height);
131 0 : basegfx::B2DHomMatrix aMatrix;
132 : pShape->addChildren( *this,
133 0 : mpThemePtr.get(),
134 : xParentShapes,
135 : aMatrix,
136 0 : &aRect );
137 :
138 0 : return true;
139 : }
140 :
141 0 : bool QuickDiagrammingLayout::exportDocument() throw()
142 : {
143 0 : return false;
144 : }
145 :
146 0 : const ::oox::drawingml::Theme* QuickDiagrammingLayout::getCurrentTheme() const
147 : {
148 0 : return mpThemePtr.get();
149 : }
150 :
151 0 : const oox::drawingml::table::TableStyleListPtr QuickDiagrammingLayout::getTableStyles()
152 : {
153 0 : return oox::drawingml::table::TableStyleListPtr();
154 : }
155 :
156 0 : ::oox::vml::Drawing* QuickDiagrammingLayout::getVmlDrawing()
157 : {
158 0 : return 0;
159 : }
160 :
161 0 : ::oox::drawingml::chart::ChartConverter* QuickDiagrammingLayout::getChartConverter()
162 : {
163 0 : return 0;
164 : }
165 :
166 0 : OUString QuickDiagrammingLayout::getImplementationName() throw (css::uno::RuntimeException, std::exception)
167 : {
168 0 : return QuickDiagrammingLayout_getImplementationName();
169 : }
170 :
171 0 : ::oox::ole::VbaProject* QuickDiagrammingLayout::implCreateVbaProject() const
172 : {
173 0 : return 0;
174 : }
175 :
176 246 : }}
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|