fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / oox / source / ppt / pptimport.cxx
blob27d831762aa8b0432642cc993632854ed8d19317
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <osl/diagnose.h>
25 #include "oox/ppt/pptimport.hxx"
26 #include "oox/drawingml/chart/chartconverter.hxx"
27 #include "oox/dump/pptxdumper.hxx"
28 #include "drawingml/table/tablestylelistfragmenthandler.hxx"
29 #include "oox/helper/graphichelper.hxx"
30 #include "oox/ole/vbaproject.hxx"
32 #include <services.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace oox::core;
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::lang::XComponent;
42 namespace oox { namespace ppt {
44 OUString SAL_CALL PowerPointImport_getImplementationName()
46 return OUString( "com.sun.star.comp.oox.ppt.PowerPointImport" );
49 uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames()
51 Sequence< OUString > aSeq( 2 );
52 aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
53 aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
54 return aSeq;
57 uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
59 return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
62 #if OSL_DEBUG_LEVEL > 0
63 XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
64 #endif
66 PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
67 XmlFilterBase( rxContext ),
68 mxChartConv( new ::oox::drawingml::chart::ChartConverter )
71 #if OSL_DEBUG_LEVEL > 0
72 mpDebugFilterBase = this;
73 #endif
76 PowerPointImport::~PowerPointImport()
80 bool PowerPointImport::importDocument()
82 /* to activate the PPTX dumper, define the environment variable
83 OOO_PPTXDUMPER and insert the full path to the file
84 file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
85 OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
87 importDocumentProperties();
89 OUString aFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
90 FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
91 maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( "tableStyles" );
92 return importFragment( xPresentationFragmentHandler );
96 bool PowerPointImport::exportDocument() throw()
98 return false;
101 sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
103 sal_Int32 nColor = 0;
104 if ( mpActualSlidePersist )
106 bool bColorMapped = false;
107 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
108 if ( pClrMapPtr )
109 bColorMapped = pClrMapPtr->getColorMap( nToken );
111 if ( !bColorMapped ) // try masterpage mapping
113 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
114 if ( pMasterPersist )
116 pClrMapPtr = pMasterPersist->getClrMap();
117 if ( pClrMapPtr )
118 bColorMapped = pClrMapPtr->getColorMap( nToken );
121 oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
122 if ( pClrSchemePtr )
123 pClrSchemePtr->getColor( nToken, nColor );
124 else
126 ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
127 if( pTheme )
129 pTheme->getClrScheme().getColor( nToken, nColor );
131 else
133 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
137 return nColor;
140 const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
142 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
145 sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException, std::exception )
147 if( XmlFilterBase::filter( rDescriptor ) )
148 return true;
150 if( isExportFilter() ) {
151 Reference< XExporter > xExporter( Reference<css::lang::XMultiServiceFactory>(getComponentContext()->getServiceManager(), UNO_QUERY_THROW)->createInstance( "com.sun.star.comp.Impress.oox.PowerPointExport" ), UNO_QUERY );;
153 if( xExporter.is() ) {
154 Reference< XComponent > xDocument( getModel(), UNO_QUERY );
155 Reference< XFilter > xFilter( xExporter, UNO_QUERY );
157 if( xFilter.is() ) {
158 xExporter->setSourceDocument( xDocument );
159 if( xFilter->filter( rDescriptor ) )
160 return true;
165 return false;
168 ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
170 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
173 const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
175 if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
177 mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
178 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
179 *this, maTableStyleListPath, *mpTableStyleList ) );
181 return mpTableStyleList;
184 ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
186 return mxChartConv.get();
189 namespace {
191 class PptGraphicHelper : public GraphicHelper
193 public:
194 explicit PptGraphicHelper( const PowerPointImport& rFilter );
195 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const SAL_OVERRIDE;
196 virtual sal_Int32 getDefaultChartAreaFillStyle() const SAL_OVERRIDE;
197 private:
198 const PowerPointImport& mrFilter;
201 PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
202 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
203 mrFilter( rFilter )
207 sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
209 return mrFilter.getSchemeColor( nToken );
212 sal_Int32 PptGraphicHelper::getDefaultChartAreaFillStyle() const
214 return XML_noFill;
217 } // namespace
219 GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
221 return new PptGraphicHelper( *this );
224 ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
226 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), "Impress" );
229 OUString PowerPointImport::getImplementationName() throw (css::uno::RuntimeException, std::exception)
231 return PowerPointImport_getImplementationName();
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */