Bump version to 24.04.3.4
[LibreOffice.git] / oox / source / ppt / pptimport.cxx
blob55e094db652f111c6f48792d2cab7a288bd2ab1a
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 <config_wasm_strip.h>
22 #include <sal/config.h>
23 #include <sal/log.hxx>
25 #include <com/sun/star/frame/XModel.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/document/XUndoManager.hpp>
29 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
30 #include <comphelper/propertysequence.hxx>
31 #include <comphelper/scopeguard.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/weld.hxx>
34 #include <svtools/sfxecode.hxx>
35 #include <svtools/ehdl.hxx>
36 #include <tools/urlobj.hxx>
37 #include <svx/dialmgr.hxx>
38 #include <svx/strings.hrc>
39 #include <oox/ppt/pptimport.hxx>
40 #include <oox/drawingml/chart/chartconverter.hxx>
41 #include <oox/dump/pptxdumper.hxx>
42 #include <drawingml/table/tablestylelistfragmenthandler.hxx>
43 #include <oox/helper/graphichelper.hxx>
44 #include <oox/ole/vbaproject.hxx>
45 #include <oox/ppt/presentationfragmenthandler.hxx>
46 #include <oox/ppt/presPropsfragmenthandler.hxx>
47 #include <oox/token/tokens.hxx>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::xml::sax;
52 using namespace oox::core;
54 using ::com::sun::star::beans::PropertyValue;
55 using ::com::sun::star::lang::XComponent;
57 namespace oox::ppt {
59 #if OSL_DEBUG_LEVEL > 0
60 XmlFilterBase* PowerPointImport::mpDebugFilterBase = nullptr;
61 #endif
63 PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) :
64 XmlFilterBase( rxContext ),
65 #if ENABLE_WASM_STRIP_CHART
66 // WASM_CHART change
67 mxChartConv( )
68 #else
69 mxChartConv( std::make_shared<::oox::drawingml::chart::ChartConverter>() )
70 #endif
72 #if OSL_DEBUG_LEVEL > 0
73 mpDebugFilterBase = this;
74 #endif
77 PowerPointImport::~PowerPointImport()
81 bool PowerPointImport::importDocument()
83 /* to activate the PPTX dumper, define the environment variable
84 OOO_PPTXDUMPER and insert the full path to the file
85 file:///<path-to-oox-module>/source/dump/pptxdumper.ini. */
86 OOX_DUMP_FILE( ::oox::dump::pptx::Dumper );
88 uno::Reference< document::XUndoManagerSupplier > xUndoManagerSupplier (getModel(), UNO_QUERY );
89 uno::Reference< util::XLockable > xUndoManager;
90 bool bWasUnLocked = true;
91 if(xUndoManagerSupplier.is())
93 xUndoManager = xUndoManagerSupplier->getUndoManager();
94 if(xUndoManager.is())
96 bWasUnLocked = !xUndoManager->isLocked();
97 xUndoManager->lock();
101 importDocumentProperties();
103 OUString aFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( u"officeDocument" );
104 FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
105 maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( u"tableStyles" );
106 const OUString sPresPropsPath
107 = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(u"presProps");
109 bool bRet = importFragment(xPresentationFragmentHandler);
110 if (bRet && !sPresPropsPath.isEmpty())
112 FragmentHandlerRef xPresPropsFragmentHandler(
113 new PresPropsFragmentHandler(*this, sPresPropsPath));
114 importFragment(xPresPropsFragmentHandler);
117 static bool bNoSmartartWarning = getenv("OOX_NO_SMARTART_WARNING");
118 if (!bNoSmartartWarning && mbMissingExtDrawing)
120 // Construct a warning message.
121 INetURLObject aURL(getFileUrl());
122 SfxErrorContext aContext(ERRCTX_SFX_OPENDOC, aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset), nullptr, RID_ERRCTX);
123 OUString aWarning;
124 aContext.GetString(ERRCODE_NONE.MakeWarning(), aWarning);
125 aWarning += ":\n" + SvxResId(RID_SVXSTR_WARN_MISSING_SMARTART);
127 // Show it.
128 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(nullptr,
129 VclMessageType::Warning, VclButtonsType::Ok,
130 aWarning));
131 xWarn->run();
134 if(xUndoManager.is() && bWasUnLocked)
135 xUndoManager->unlock();
137 return bRet;
141 bool PowerPointImport::exportDocument() noexcept
143 return false;
146 ::Color PowerPointImport::getSchemeColor( sal_Int32 nToken ) const
148 ::Color nColor;
149 if ( mpActualSlidePersist )
151 bool bColorMapped = false;
152 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
153 if ( pClrMapPtr )
154 bColorMapped = pClrMapPtr->getColorMap( nToken );
156 if ( !bColorMapped ) // try masterpage mapping
158 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
159 if ( pMasterPersist )
161 pClrMapPtr = pMasterPersist->getClrMap();
162 if ( pClrMapPtr )
163 pClrMapPtr->getColorMap( nToken );
167 ::oox::drawingml::ThemePtr pTheme = mpActualSlidePersist->getTheme();
168 if( pTheme )
170 pTheme->getClrScheme().getColor( nToken, nColor );
172 else
174 SAL_WARN("oox", "OOX: PowerPointImport::mpThemePtr is NULL");
177 return nColor;
180 const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
182 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : nullptr;
185 std::shared_ptr<::oox::drawingml::Theme> PowerPointImport::getCurrentThemePtr() const
187 return mpActualSlidePersist ? mpActualSlidePersist->getTheme() : std::shared_ptr<::oox::drawingml::Theme>();
190 sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor )
192 if( XmlFilterBase::filter( rDescriptor ) )
193 return true;
195 if (isExportFilter())
197 uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
199 {"IsPPTM", uno::Any(exportVBA())},
200 {"IsTemplate", uno::Any(isExportTemplate())},
201 }));
203 Reference<css::lang::XMultiServiceFactory> aFactory(getComponentContext()->getServiceManager(), UNO_QUERY_THROW);
204 Reference< XExporter > xExporter(aFactory->createInstanceWithArguments("com.sun.star.comp.Impress.oox.PowerPointExport", aArguments), UNO_QUERY);
206 if (Reference<XFilter> xFilter{ xExporter, UNO_QUERY })
208 Reference<util::XLockable> xUndoManager;
209 bool bWasUnLocked = true;
210 if (Reference<document::XUndoManagerSupplier> xUMS{ getModel(), UNO_QUERY })
212 xUndoManager = xUMS->getUndoManager();
213 if (xUndoManager.is())
215 bWasUnLocked = !xUndoManager->isLocked();
216 xUndoManager->lock();
219 comphelper::ScopeGuard aGuard([xUndoManager, bWasUnLocked] {
220 if (xUndoManager && bWasUnLocked)
221 xUndoManager->unlock();
224 Reference< XComponent > xDocument = getModel();
225 xExporter->setSourceDocument(xDocument);
226 if (xFilter->filter(rDescriptor))
227 return true;
231 return false;
234 ::oox::vml::Drawing* PowerPointImport::getVmlDrawing()
236 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : nullptr;
239 oox::drawingml::table::TableStyleListPtr PowerPointImport::getTableStyles()
241 if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
243 mpTableStyleList = std::make_shared<oox::drawingml::table::TableStyleList>( );
244 importFragment( new oox::drawingml::table::TableStyleListFragmentHandler(
245 *this, maTableStyleListPath, *mpTableStyleList ) );
247 return mpTableStyleList;
250 ::oox::drawingml::chart::ChartConverter* PowerPointImport::getChartConverter()
252 return mxChartConv.get();
255 namespace {
257 class PptGraphicHelper : public GraphicHelper
259 public:
260 explicit PptGraphicHelper( const PowerPointImport& rFilter );
261 virtual ::Color getSchemeColor( sal_Int32 nToken ) const override;
262 virtual sal_Int32 getDefaultChartAreaFillStyle() const override;
263 private:
264 const PowerPointImport& mrFilter;
267 PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
268 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
269 mrFilter( rFilter )
273 ::Color PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
275 return mrFilter.getSchemeColor( nToken );
278 sal_Int32 PptGraphicHelper::getDefaultChartAreaFillStyle() const
280 return XML_noFill;
283 } // namespace
285 GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
287 return new PptGraphicHelper( *this );
290 ::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
292 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), u"Impress" );
295 OUString PowerPointImport::getImplementationName()
297 return "com.sun.star.comp.oox.ppt.PowerPointImport";
302 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
303 com_sun_star_comp_oox_ppt_PowerPointImport_get_implementation(
304 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
306 return cppu::acquire(new oox::ppt::PowerPointImport(pCtx));
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */