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/pptimport.hxx"
21 : #include "oox/drawingml/chart/chartconverter.hxx"
22 : #include "oox/dump/pptxdumper.hxx"
23 : #include "oox/drawingml/table/tablestylelistfragmenthandler.hxx"
24 : #include "oox/helper/graphichelper.hxx"
25 : #include "oox/ole/vbaproject.hxx"
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::xml::sax;
30 : using namespace oox::core;
31 :
32 : using ::com::sun::star::beans::PropertyValue;
33 : using ::com::sun::star::lang::XComponent;
34 :
35 : namespace oox { namespace ppt {
36 :
37 25 : OUString SAL_CALL PowerPointImport_getImplementationName() throw()
38 : {
39 25 : return OUString( "com.sun.star.comp.oox.ppt.PowerPointImport" );
40 : }
41 :
42 1 : uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw()
43 : {
44 1 : Sequence< OUString > aSeq( 2 );
45 1 : aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
46 1 : aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
47 1 : return aSeq;
48 : }
49 :
50 7 : uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
51 : {
52 7 : return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
53 : }
54 :
55 : #if OSL_DEBUG_LEVEL > 0
56 : XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
57 : #endif
58 :
59 7 : PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
60 : XmlFilterBase( rxContext ),
61 7 : mxChartConv( new ::oox::drawingml::chart::ChartConverter )
62 :
63 : {
64 : #if OSL_DEBUG_LEVEL > 0
65 : mpDebugFilterBase = this;
66 : #endif
67 7 : }
68 :
69 14 : PowerPointImport::~PowerPointImport()
70 : {
71 14 : }
72 :
73 7 : bool PowerPointImport::importDocument() throw()
74 : {
75 : /* to activate the PPTX dumper, define the environment variable
76 : OOO_PPTXDUMPER and insert the full path to the file
77 : file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
78 : OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
79 :
80 7 : OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
81 14 : FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
82 7 : maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) );
83 14 : return importFragment( xPresentationFragmentHandler );
84 :
85 :
86 : }
87 :
88 0 : bool PowerPointImport::exportDocument() throw()
89 : {
90 0 : return false;
91 : }
92 :
93 331 : sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
94 : {
95 331 : sal_Int32 nColor = 0;
96 331 : if ( mpActualSlidePersist )
97 : {
98 331 : sal_Bool bColorMapped = sal_False;
99 331 : oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
100 331 : if ( pClrMapPtr )
101 81 : bColorMapped = pClrMapPtr->getColorMap( nToken );
102 :
103 331 : if ( !bColorMapped ) // try masterpage mapping
104 : {
105 250 : SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
106 250 : if ( pMasterPersist )
107 : {
108 250 : pClrMapPtr = pMasterPersist->getClrMap();
109 250 : if ( pClrMapPtr )
110 250 : bColorMapped = pClrMapPtr->getColorMap( nToken );
111 250 : }
112 : }
113 662 : oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
114 331 : if ( pClrSchemePtr )
115 0 : pClrSchemePtr->getColor( nToken, nColor );
116 : else
117 : {
118 331 : ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
119 331 : if( pTheme )
120 : {
121 330 : pTheme->getClrScheme().getColor( nToken, nColor );
122 : }
123 : else
124 : {
125 : OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
126 331 : }
127 331 : }
128 : }
129 331 : return nColor;
130 : }
131 :
132 1067 : const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
133 : {
134 1067 : return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
135 : }
136 :
137 7 : sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException )
138 : {
139 7 : if( XmlFilterBase::filter( rDescriptor ) )
140 7 : return true;
141 :
142 0 : if( isExportFilter() ) {
143 0 : Reference< XExporter > xExporter( Reference<css::lang::XMultiServiceFactory>(getComponentContext()->getServiceManager(), UNO_QUERY_THROW)->createInstance( "com.sun.star.comp.Impress.oox.PowerPointExport" ), UNO_QUERY );;
144 :
145 0 : if( xExporter.is() ) {
146 0 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
147 0 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
148 :
149 0 : if( xFilter.is() ) {
150 0 : xExporter->setSourceDocument( xDocument );
151 0 : if( xFilter->filter( rDescriptor ) )
152 0 : return true;
153 0 : }
154 0 : }
155 : }
156 :
157 0 : return false;
158 : }
159 :
160 0 : ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
161 : {
162 0 : return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
163 : }
164 :
165 0 : const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
166 : {
167 0 : if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
168 : {
169 0 : mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
170 : importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
171 0 : *this, maTableStyleListPath, *mpTableStyleList ) );
172 : }
173 0 : return mpTableStyleList;
174 : }
175 :
176 0 : ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
177 : {
178 0 : return mxChartConv.get();
179 : }
180 :
181 : namespace {
182 :
183 14 : class PptGraphicHelper : public GraphicHelper
184 : {
185 : public:
186 : explicit PptGraphicHelper( const PowerPointImport& rFilter );
187 : virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
188 : private:
189 : const PowerPointImport& mrFilter;
190 : };
191 :
192 7 : PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
193 7 : GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
194 14 : mrFilter( rFilter )
195 : {
196 7 : }
197 :
198 331 : sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
199 : {
200 331 : return mrFilter.getSchemeColor( nToken );
201 : }
202 :
203 : } // namespace
204 :
205 7 : GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
206 : {
207 7 : return new PptGraphicHelper( *this );
208 : }
209 :
210 0 : ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
211 : {
212 0 : return new ::oox::ole::VbaProject( getComponentContext(), getModel(), "Impress" );
213 : }
214 :
215 0 : OUString PowerPointImport::implGetImplementationName() const
216 : {
217 0 : return PowerPointImport_getImplementationName();
218 : }
219 :
220 141 : }}
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|