LibreOffice Module oox (master) 1
pptimport.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_wasm_strip.h>
21
22#include <sal/config.h>
23#include <sal/log.hxx>
24
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>
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>
47#include <oox/token/tokens.hxx>
48
49using namespace ::com::sun::star;
50using namespace ::com::sun::star::uno;
51using namespace ::com::sun::star::xml::sax;
52using namespace oox::core;
53
54using ::com::sun::star::beans::PropertyValue;
55using ::com::sun::star::lang::XComponent;
56
57namespace oox::ppt {
58
59#if OSL_DEBUG_LEVEL > 0
61#endif
62
63PowerPointImport::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
71{
72#if OSL_DEBUG_LEVEL > 0
73 mpDebugFilterBase = this;
74#endif
75}
76
78{
79}
80
82{
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. */
87
88 uno::Reference< document::XUndoManagerSupplier > xUndoManagerSupplier (getModel(), UNO_QUERY );
89 uno::Reference< util::XLockable > xUndoManager;
90 bool bWasUnLocked = true;
91 if(xUndoManagerSupplier.is())
92 {
93 xUndoManager = xUndoManagerSupplier->getUndoManager();
94 if(xUndoManager.is())
95 {
96 bWasUnLocked = !xUndoManager->isLocked();
97 xUndoManager->lock();
98 }
99 }
100
102
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");
108
109 bool bRet = importFragment(xPresentationFragmentHandler);
110 if (bRet && !sPresPropsPath.isEmpty())
111 {
112 FragmentHandlerRef xPresPropsFragmentHandler(
113 new PresPropsFragmentHandler(*this, sPresPropsPath));
114 importFragment(xPresPropsFragmentHandler);
115 }
116
117 static bool bNoSmartartWarning = getenv("OOX_NO_SMARTART_WARNING");
118 if (!bNoSmartartWarning && mbMissingExtDrawing)
119 {
120 // Construct a warning message.
123 OUString aWarning;
124 aContext.GetString(ERRCODE_NONE.MakeWarning(), aWarning);
125 aWarning += ":\n" + SvxResId(RID_SVXSTR_WARN_MISSING_SMARTART);
126
127 // Show it.
128 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(nullptr,
129 VclMessageType::Warning, VclButtonsType::Ok,
130 aWarning));
131 xWarn->run();
132 }
133
134 if(xUndoManager.is() && bWasUnLocked)
135 xUndoManager->unlock();
136
137 return bRet;
138
139}
140
142{
143 return false;
144}
145
147{
148 ::Color nColor;
150 {
151 bool bColorMapped = false;
152 oox::drawingml::ClrMapPtr pClrMapPtr( mpActualSlidePersist->getClrMap() );
153 if ( pClrMapPtr )
154 bColorMapped = pClrMapPtr->getColorMap( nToken );
155
156 if ( !bColorMapped ) // try masterpage mapping
157 {
158 SlidePersistPtr pMasterPersist = mpActualSlidePersist->getMasterPersist();
159 if ( pMasterPersist )
160 {
161 pClrMapPtr = pMasterPersist->getClrMap();
162 if ( pClrMapPtr )
163 pClrMapPtr->getColorMap( nToken );
164 }
165 }
166
168 if( pTheme )
169 {
170 pTheme->getClrScheme().getColor( nToken, nColor );
171 }
172 else
173 {
174 SAL_WARN("oox", "OOX: PowerPointImport::mpThemePtr is NULL");
175 }
176 }
177 return nColor;
178}
179
180const ::oox::drawingml::Theme* PowerPointImport::getCurrentTheme() const
181{
182 return mpActualSlidePersist ? mpActualSlidePersist->getTheme().get() : nullptr;
183}
184
185std::shared_ptr<::oox::drawingml::Theme> PowerPointImport::getCurrentThemePtr() const
186{
187 return mpActualSlidePersist ? mpActualSlidePersist->getTheme() : std::shared_ptr<::oox::drawingml::Theme>();
188}
189
190sal_Bool SAL_CALL PowerPointImport::filter( const Sequence< PropertyValue >& rDescriptor )
191{
192 if( XmlFilterBase::filter( rDescriptor ) )
193 return true;
194
195 if (isExportFilter())
196 {
197 uno::Sequence<uno::Any> aArguments(comphelper::InitAnyPropertySequence(
198 {
199 {"IsPPTM", uno::Any(exportVBA())},
200 {"IsTemplate", uno::Any(isExportTemplate())},
201 }));
202
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);
205
206 if (Reference<XFilter> xFilter{ xExporter, UNO_QUERY })
207 {
208 Reference<util::XLockable> xUndoManager;
209 bool bWasUnLocked = true;
210 if (Reference<document::XUndoManagerSupplier> xUMS{ getModel(), UNO_QUERY })
211 {
212 xUndoManager = xUMS->getUndoManager();
213 if (xUndoManager.is())
214 {
215 bWasUnLocked = !xUndoManager->isLocked();
216 xUndoManager->lock();
217 }
218 }
219 comphelper::ScopeGuard aGuard([xUndoManager, bWasUnLocked] {
220 if (xUndoManager && bWasUnLocked)
221 xUndoManager->unlock();
222 });
223
224 Reference< XComponent > xDocument = getModel();
225 xExporter->setSourceDocument(xDocument);
226 if (xFilter->filter(rDescriptor))
227 return true;
228 }
229 }
230
231 return false;
232}
233
235{
236 return mpActualSlidePersist ? mpActualSlidePersist->getDrawing() : nullptr;
237}
238
240{
241 if ( !mpTableStyleList && !maTableStyleListPath.isEmpty() )
242 {
243 mpTableStyleList = std::make_shared<oox::drawingml::table::TableStyleList>( );
246 }
247 return mpTableStyleList;
248}
249
251{
252 return mxChartConv.get();
253}
254
255namespace {
256
257class PptGraphicHelper : public GraphicHelper
258{
259public:
260 explicit PptGraphicHelper( const PowerPointImport& rFilter );
261 virtual ::Color getSchemeColor( sal_Int32 nToken ) const override;
262 virtual sal_Int32 getDefaultChartAreaFillStyle() const override;
263private:
264 const PowerPointImport& mrFilter;
265};
266
267PptGraphicHelper::PptGraphicHelper( const PowerPointImport& rFilter ) :
268 GraphicHelper( rFilter.getComponentContext(), rFilter.getTargetFrame(), rFilter.getStorage() ),
269 mrFilter( rFilter )
270{
271}
272
273::Color PptGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
274{
275 return mrFilter.getSchemeColor( nToken );
276}
277
278sal_Int32 PptGraphicHelper::getDefaultChartAreaFillStyle() const
279{
280 return XML_noFill;
281}
282
283} // namespace
284
285GraphicHelper* PowerPointImport::implCreateGraphicHelper() const
286{
287 return new PptGraphicHelper( *this );
288}
289
290::oox::ole::VbaProject* PowerPointImport::implCreateVbaProject() const
291{
292 return new ::oox::ole::VbaProject( getComponentContext(), getModel(), u"Impress" );
293}
294
295OUString PowerPointImport::getImplementationName()
296{
297 return "com.sun.star.comp.oox.ppt.PowerPointImport";
298}
299
300}
301
302extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
304 uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
305{
306 return cppu::acquire(new oox::ppt::PowerPointImport(pCtx));
307}
308
309/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
bool GetString(ErrCode nErrId, OUString &rStr) override
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
const OUString & getFileUrl() const
Returns the URL of the imported or exported file.
Definition: filterbase.cxx:250
bool isExportFilter() const
Returns true, if filter is an export filter.
Definition: filterbase.cxx:205
bool exportVBA() const
Definition: filterbase.cxx:584
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
Definition: filterbase.cxx:220
bool isExportTemplate() const
Definition: filterbase.cxx:589
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Returns the component context passed in the filter constructor (always existing).
Definition: filterbase.cxx:215
void importDocumentProperties()
Read the document properties and also the customXml entries (xlsx and pptx only).
OUString getFragmentPathFromFirstTypeFromOfficeDoc(std::u16string_view rPart)
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
::Color getSchemeColor(sal_Int32 nToken) const
Definition: pptimport.cxx:146
std::shared_ptr< ::oox::drawingml::chart::ChartConverter > mxChartConv
Definition: pptimport.hxx:100
virtual ::oox::vml::Drawing * getVmlDrawing() override
Has to be implemented by each filter to return the collection of VML shapes.
Definition: pptimport.cxx:234
virtual oox::drawingml::table::TableStyleListPtr getTableStyles() override
Has to be implemented by each filter to return the table style list.
Definition: pptimport.cxx:239
oox::drawingml::table::TableStyleListPtr mpTableStyleList
Definition: pptimport.hxx:91
static XmlFilterBase * mpDebugFilterBase
Definition: pptimport.hxx:81
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &rDescriptor) override
Definition: pptimport.cxx:190
virtual bool importDocument() override
Derived classes implement import of the entire document.
Definition: pptimport.cxx:81
virtual std::shared_ptr<::oox::drawingml::Theme > getCurrentThemePtr() const override
May be implemented by filters which handle Diagrams, default returns empty ptr.
Definition: pptimport.cxx:185
virtual ::oox::drawingml::chart::ChartConverter * getChartConverter() override
Has to be implemented by each filter, returns a filter-specific chart converter object,...
Definition: pptimport.cxx:250
SlidePersistPtr mpActualSlidePersist
Definition: pptimport.hxx:93
PowerPointImport(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
Definition: pptimport.cxx:63
virtual bool exportDocument() noexcept override
Derived classes implement export of the entire document.
Definition: pptimport.cxx:141
virtual const ::oox::drawingml::Theme * getCurrentTheme() const override
Has to be implemented by each filter, returns the current theme.
Definition: pptimport.cxx:180
virtual ~PowerPointImport() override
Definition: pptimport.cxx:77
Represents the collection of VML shapes for a complete draw page.
Definition: vmldrawing.hxx:94
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
URL aURL
#define OOX_DUMP_FILE(DumperClassName)
float u
SVT_DLLPUBLIC const ErrMsgCode RID_ERRCTX[]
#define ERRCODE_NONE
Sequence< PropertyValue > aArguments
#define SAL_WARN(area, stream)
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
std::shared_ptr< T > make_shared(Args &&... args)
std::shared_ptr< TableStyleList > TableStyleListPtr
std::shared_ptr< Theme > ThemePtr
std::shared_ptr< ClrMap > ClrMapPtr
Definition: clrscheme.hxx:64
std::shared_ptr< SlidePersist > SlidePersistPtr
const PowerPointImport & mrFilter
Definition: pptimport.cxx:264
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_oox_ppt_PowerPointImport_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
Definition: pptimport.cxx:303
DefTokenId nToken
#define ERRCTX_SFX_OPENDOC
unsigned char sal_Bool