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 <vcl/msgbox.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svtools/sfxecode.hxx>
28 #include <svtools/ehdl.hxx>
29 #include <svtools/svtools.hrc>
30 #include <tools/urlobj.hxx>
31 #include <svx/dialogs.hrc>
32 #include "oox/ppt/pptimport.hxx"
33 #include "oox/drawingml/chart/chartconverter.hxx"
34 #include "oox/dump/pptxdumper.hxx"
35 #include "drawingml/table/tablestylelistfragmenthandler.hxx"
36 #include "oox/helper/graphichelper.hxx"
37 #include "oox/ole/vbaproject.hxx"
38 #include <oox/ppt/presentationfragmenthandler.hxx>
39 #include <oox/token/tokens.hxx>
41 #include <services.hxx>
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::xml::sax
;
46 using namespace oox::core
;
48 using ::com::sun::star::beans::PropertyValue
;
49 using ::com::sun::star::lang::XComponent
;
51 namespace oox
{ namespace ppt
{
53 OUString SAL_CALL
PowerPointImport_getImplementationName()
55 return OUString( "com.sun.star.comp.oox.ppt.PowerPointImport" );
58 uno::Sequence
< OUString
> SAL_CALL
PowerPointImport_getSupportedServiceNames()
60 Sequence
< OUString
> aSeq( 2 );
61 aSeq
[ 0 ] = "com.sun.star.document.ImportFilter";
62 aSeq
[ 1 ] = "com.sun.star.document.ExportFilter";
66 uno::Reference
< uno::XInterface
> SAL_CALL
PowerPointImport_createInstance( const Reference
< XComponentContext
>& rxContext
)
68 return static_cast< ::cppu::OWeakObject
* >( new PowerPointImport( rxContext
) );
71 #if OSL_DEBUG_LEVEL > 0
72 XmlFilterBase
* PowerPointImport::mpDebugFilterBase
= nullptr;
75 PowerPointImport::PowerPointImport( const Reference
< XComponentContext
>& rxContext
) :
76 XmlFilterBase( rxContext
),
77 mxChartConv( new ::oox::drawingml::chart::ChartConverter
)
80 #if OSL_DEBUG_LEVEL > 0
81 mpDebugFilterBase
= this;
85 PowerPointImport::~PowerPointImport()
89 bool PowerPointImport::importDocument()
91 /* to activate the PPTX dumper, define the environment variable
92 OOO_PPTXDUMPER and insert the full path to the file
93 file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
94 OOX_DUMP_FILE( ::oox::dump::pptx::Dumper
);
96 importDocumentProperties();
98 OUString aFragmentPath
= getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
99 FragmentHandlerRef
xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath
) );
100 maTableStyleListPath
= xPresentationFragmentHandler
->getFragmentPathFromFirstTypeFromOfficeDoc( "tableStyles" );
101 bool bRet
= importFragment(xPresentationFragmentHandler
);
103 if (mbMissingExtDrawing
)
105 // Construct a warning message.
106 INetURLObject
aURL(getFileUrl());
107 SfxErrorContext
aContext(ERRCTX_SFX_OPENDOC
, aURL
.getName(INetURLObject::LAST_SEGMENT
, true, INetURLObject::DecodeMechanism::WithCharset
), nullptr, RID_ERRCTX
);
109 aContext
.GetString(ERRCODE_WARNING_MASK
, aWarning
);
111 static ResMgr
* pResMgr
= ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag());
112 aWarning
+= ResId(RID_SVXSTR_WARN_MISSING_SMARTART
, *pResMgr
).toString();
115 WinBits eBits
= WB_OK
| WB_DEF_OK
;
116 ScopedVclPtrInstance
<WarningBox
> pBox(nullptr, eBits
, aWarning
);
124 bool PowerPointImport::exportDocument() throw()
129 sal_Int32
PowerPointImport::getSchemeColor( sal_Int32 nToken
) const
131 sal_Int32 nColor
= 0;
132 if ( mpActualSlidePersist
)
134 bool bColorMapped
= false;
135 oox::drawingml::ClrMapPtr
pClrMapPtr( mpActualSlidePersist
->getClrMap() );
137 bColorMapped
= pClrMapPtr
->getColorMap( nToken
);
139 if ( !bColorMapped
) // try masterpage mapping
141 SlidePersistPtr pMasterPersist
= mpActualSlidePersist
->getMasterPersist();
142 if ( pMasterPersist
)
144 pClrMapPtr
= pMasterPersist
->getClrMap();
146 pClrMapPtr
->getColorMap( nToken
);
149 oox::drawingml::ClrSchemePtr
pClrSchemePtr( mpActualSlidePersist
->getClrScheme() );
151 pClrSchemePtr
->getColor( nToken
, nColor
);
154 ::oox::drawingml::ThemePtr pTheme
= mpActualSlidePersist
->getTheme();
157 pTheme
->getClrScheme().getColor( nToken
, nColor
);
161 SAL_WARN("oox", "OOX: PowerPointImport::mpThemePtr is NULL");
168 const ::oox::drawingml::Theme
* PowerPointImport::getCurrentTheme() const
170 return mpActualSlidePersist
? mpActualSlidePersist
->getTheme().get() : nullptr;
173 sal_Bool SAL_CALL
PowerPointImport::filter( const Sequence
< PropertyValue
>& rDescriptor
)
175 if( XmlFilterBase::filter( rDescriptor
) )
178 if( isExportFilter() ) {
179 Reference
< XExporter
> xExporter( Reference
<css::lang::XMultiServiceFactory
>(getComponentContext()->getServiceManager(), UNO_QUERY_THROW
)->createInstance( "com.sun.star.comp.Impress.oox.PowerPointExport" ), UNO_QUERY
);
181 if( xExporter
.is() ) {
182 Reference
< XComponent
> xDocument( getModel(), UNO_QUERY
);
183 Reference
< XFilter
> xFilter( xExporter
, UNO_QUERY
);
186 xExporter
->setSourceDocument( xDocument
);
187 if( xFilter
->filter( rDescriptor
) )
196 ::oox::vml::Drawing
* PowerPointImport::getVmlDrawing()
198 return mpActualSlidePersist
? mpActualSlidePersist
->getDrawing() : nullptr;
201 const oox::drawingml::table::TableStyleListPtr
PowerPointImport::getTableStyles()
203 if ( !mpTableStyleList
&& !maTableStyleListPath
.isEmpty() )
205 mpTableStyleList
= std::make_shared
<oox::drawingml::table::TableStyleList
>( );
206 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
207 *this, maTableStyleListPath
, *mpTableStyleList
) );
209 return mpTableStyleList
;
212 ::oox::drawingml::chart::ChartConverter
* PowerPointImport::getChartConverter()
214 return mxChartConv
.get();
219 class PptGraphicHelper
: public GraphicHelper
222 explicit PptGraphicHelper( const PowerPointImport
& rFilter
);
223 virtual sal_Int32
getSchemeColor( sal_Int32 nToken
) const override
;
224 virtual sal_Int32
getDefaultChartAreaFillStyle() const override
;
226 const PowerPointImport
& mrFilter
;
229 PptGraphicHelper::PptGraphicHelper( const PowerPointImport
& rFilter
) :
230 GraphicHelper( rFilter
.getComponentContext(), rFilter
.getTargetFrame(), rFilter
.getStorage() ),
235 sal_Int32
PptGraphicHelper::getSchemeColor( sal_Int32 nToken
) const
237 return mrFilter
.getSchemeColor( nToken
);
240 sal_Int32
PptGraphicHelper::getDefaultChartAreaFillStyle() const
247 GraphicHelper
* PowerPointImport::implCreateGraphicHelper() const
249 return new PptGraphicHelper( *this );
252 ::oox::ole::VbaProject
* PowerPointImport::implCreateVbaProject() const
254 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), "Impress" );
257 OUString
PowerPointImport::getImplementationName()
259 return PowerPointImport_getImplementationName();
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */