GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ppt / pptimport.cxx
blob285ac2a064bcd4e00b8ed1886ffec87789e71891
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 "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"
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;
32 using ::com::sun::star::beans::PropertyValue;
33 using ::com::sun::star::lang::XComponent;
35 namespace oox { namespace ppt {
37 OUString SAL_CALL PowerPointImport_getImplementationName() throw()
39 return OUString( "com.sun.star.comp.oox.ppt.PowerPointImport" );
42 uno::Sequence< OUString > SAL_CALL PowerPointImport_getSupportedServiceNames() throw()
44 Sequence< OUString > aSeq( 2 );
45 aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
46 aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
47 return aSeq;
50 uno::Reference< uno::XInterface > SAL_CALL PowerPointImport_createInstance( const Reference< XComponentContext >& rxContext ) throw( Exception )
52 return static_cast< ::cppu::OWeakObject* >( new PowerPointImport( rxContext ) );
55 #if OSL_DEBUG_LEVEL > 0
56 XmlFilterBase* PowerPointImport::mpDebugFilterBase = NULL;
57 #endif
59 PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
60 XmlFilterBase( rxContext ),
61 mxChartConv( new ::oox::drawingml::chart::ChartConverter )
64 #if OSL_DEBUG_LEVEL > 0
65 mpDebugFilterBase = this;
66 #endif
69 PowerPointImport::~PowerPointImport()
73 bool PowerPointImport::importDocument() throw()
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 );
80 OUString aFragmentPath = getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "officeDocument" ) );
81 FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
82 maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstType( CREATE_OFFICEDOC_RELATION_TYPE( "tableStyles" ) );
83 return importFragment( xPresentationFragmentHandler );
88 bool PowerPointImport::exportDocument() throw()
90 return false;
93 sal_Int32 PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
95 sal_Int32 nColor = 0;
96 if ( mpActualSlidePersist )
98 sal_Bool bColorMapped = sal_False;
99 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
100 if ( pClrMapPtr )
101 bColorMapped = pClrMapPtr->getColorMap( nToken );
103 if ( !bColorMapped ) // try masterpage mapping
105 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
106 if ( pMasterPersist )
108 pClrMapPtr = pMasterPersist->getClrMap();
109 if ( pClrMapPtr )
110 bColorMapped = pClrMapPtr->getColorMap( nToken );
113 oox::drawingml::ClrSchemePtr pClrSchemePtr( mpActualSlidePersist->getClrScheme() );
114 if ( pClrSchemePtr )
115 pClrSchemePtr->getColor( nToken, nColor );
116 else
118 ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
119 if( pTheme )
121 pTheme->getClrScheme().getColor( nToken, nColor );
123 else
125 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
129 return nColor;
132 const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
134 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : 0;
137 sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor ) throw( RuntimeException )
139 if( XmlFilterBase::filter( rDescriptor ) )
140 return true;
142 if( isExportFilter() ) {
143 Reference< XExporter > xExporter( Reference<css::lang::XMultiServiceFactory>(getComponentContext()->getServiceManager(), UNO_QUERY_THROW)->createInstance( "com.sun.star.comp.Impress.oox.PowerPointExport" ), UNO_QUERY );;
145 if( xExporter.is() ) {
146 Reference< XComponent > xDocument( getModel(), UNO_QUERY );
147 Reference< XFilter > xFilter( xExporter, UNO_QUERY );
149 if( xFilter.is() ) {
150 xExporter->setSourceDocument( xDocument );
151 if( xFilter->filter( rDescriptor ) )
152 return true;
157 return false;
160 ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
162 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : 0;
165 const oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
167 if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
169 mpTableStyleList = oox::drawingml::table::TableStyleListPtr( new oox::drawingml::table::TableStyleList() );
170 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
171 *this, maTableStyleListPath, *mpTableStyleList ) );
173 return mpTableStyleList;
176 ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
178 return mxChartConv.get();
181 namespace {
183 class PptGraphicHelper : public GraphicHelper
185 public:
186 explicit PptGraphicHelper( const PowerPointImport& rFilter );
187 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
188 private:
189 const PowerPointImport& mrFilter;
192 PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
193 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
194 mrFilter( rFilter )
198 sal_Int32 PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
200 return mrFilter.getSchemeColor( nToken );
203 } // namespace
205 GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
207 return new PptGraphicHelper( *this );
210 ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
212 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), "Impress" );
215 OUString PowerPointImport::implGetImplementationName() const
217 return PowerPointImport_getImplementationName();
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */