1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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";
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
;
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;
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()
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() );
109 bColorMapped
= pClrMapPtr
->getColorMap( nToken
);
111 if ( !bColorMapped
) // try masterpage mapping
113 SlidePersistPtr pMasterPersist
= mpActualSlidePersist
->getMasterPersist();
114 if ( pMasterPersist
)
116 pClrMapPtr
= pMasterPersist
->getClrMap();
118 bColorMapped
= pClrMapPtr
->getColorMap( nToken
);
121 oox::drawingml::ClrSchemePtr
pClrSchemePtr( mpActualSlidePersist
->getClrScheme() );
123 pClrSchemePtr
->getColor( nToken
, nColor
);
126 ::oox::drawingml::ThemePtr pTheme
= mpActualSlidePersist
->getTheme();
129 pTheme
->getClrScheme().getColor( nToken
, nColor
);
133 OSL_TRACE("OOX: PowerPointImport::mpThemePtr is NULL");
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
) )
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
);
158 xExporter
->setSourceDocument( xDocument
);
159 if( xFilter
->filter( rDescriptor
) )
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();
191 class PptGraphicHelper
: public GraphicHelper
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
;
198 const PowerPointImport
& mrFilter
;
201 PptGraphicHelper::PptGraphicHelper( const PowerPointImport
& rFilter
) :
202 GraphicHelper( rFilter
.getComponentContext(), rFilter
.getTargetFrame(), rFilter
.getStorage() ),
207 sal_Int32
PptGraphicHelper::getSchemeColor( sal_Int32 nToken
) const
209 return mrFilter
.getSchemeColor( nToken
);
212 sal_Int32
PptGraphicHelper::getDefaultChartAreaFillStyle() const
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: */