bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / filter / sdpptwrp.cxx
blobedc21c482d45a9b0a5f1f429a97eaee2b389438f
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 <sfx2/docfile.hxx>
21 #include <sfx2/docfilt.hxx>
22 #include <filter/msfilter/msoleexp.hxx>
23 #include <svx/svxerr.hxx>
24 #include <unotools/fltrcfg.hxx>
25 #include <sot/storage.hxx>
27 #include <sdpptwrp.hxx>
28 #include <DrawDocShell.hxx>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::task;
34 using namespace ::com::sun::star::frame;
36 typedef sal_Bool ( *ExportPPTPointer )( const std::vector< css::beans::PropertyValue >&, tools::SvRef<SotStorage> const&,
37 Reference< XModel > const &,
38 Reference< XStatusIndicator > const &,
39 SvMemoryStream*, sal_uInt32 nCnvrtFlags );
41 typedef sal_Bool ( *ImportPPTPointer )( SdDrawDocument*, SvStream&, SotStorage&, SfxMedium& );
43 typedef sal_Bool ( *SaveVBAPointer )( SfxObjectShell&, SvMemoryStream*& );
45 #ifdef DISABLE_DYNLOADING
47 extern "C" sal_Bool ExportPPT( const std::vector< css::beans::PropertyValue >&, tools::SvRef<SotStorage> const&,
48 Reference< XModel > const &,
49 Reference< XStatusIndicator > const &,
50 SvMemoryStream*, sal_uInt32 nCnvrtFlags );
52 extern "C" sal_Bool ImportPPT( SdDrawDocument*, SvStream&, SotStorage&, SfxMedium& );
54 extern "C" sal_Bool SaveVBA( SfxObjectShell&, SvMemoryStream*& );
56 #endif
59 SdPPTFilter::SdPPTFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell ) :
60 SdFilter( rMedium, rDocShell ),
61 pBas ( nullptr )
65 SdPPTFilter::~SdPPTFilter()
67 delete pBas; // deleting the compressed basic storage
70 bool SdPPTFilter::Import()
72 bool bRet = false;
73 tools::SvRef<SotStorage> pStorage = new SotStorage( mrMedium.GetInStream(), false );
74 if( !pStorage->GetError() )
76 /* check if there is a dualstorage, then the
77 document is probably a PPT95 containing PPT97 */
78 tools::SvRef<SotStorage> xDualStorage;
79 OUString sDualStorage( "PP97_DUALSTORAGE" );
80 if ( pStorage->IsContained( sDualStorage ) )
82 xDualStorage = pStorage->OpenSotStorage( sDualStorage, StreamMode::STD_READ );
83 pStorage = xDualStorage;
85 std::unique_ptr<SvStream> pDocStream(pStorage->OpenSotStream( "PowerPoint Document" , StreamMode::STD_READ ));
86 if( pDocStream )
88 pDocStream->SetVersion( pStorage->GetVersion() );
89 pDocStream->SetCryptMaskKey(pStorage->GetKey());
91 if ( pStorage->IsStream( "EncryptedSummary" ) )
92 mrMedium.SetError(ERRCODE_SVX_READ_FILTER_PPOINT);
93 else
95 #ifdef DISABLE_DYNLOADING
96 ImportPPTPointer pPPTImport = ImportPPT;
97 #else
98 ImportPPTPointer pPPTImport = reinterpret_cast< ImportPPTPointer >(
99 SdFilter::GetLibrarySymbol(mrMedium.GetFilter()->GetUserData(), "ImportPPT"));
100 #endif
102 if ( pPPTImport )
103 bRet = pPPTImport( &mrDocument, *pDocStream, *pStorage, mrMedium );
105 if ( !bRet )
106 mrMedium.SetError(SVSTREAM_WRONGVERSION);
111 return bRet;
114 bool SdPPTFilter::Export()
116 bool bRet = false;
118 if( mxModel.is() )
120 tools::SvRef<SotStorage> xStorRef = new SotStorage( mrMedium.GetOutStream(), false );
122 #ifdef DISABLE_DYNLOADING
123 ExportPPTPointer PPTExport = ExportPPT;
124 #else
125 ExportPPTPointer PPTExport = reinterpret_cast< ExportPPTPointer >(
126 SdFilter::GetLibrarySymbol(mrMedium.GetFilter()->GetUserData(), "ExportPPT"));
127 #endif
129 if( PPTExport && xStorRef.is() )
131 sal_uInt32 nCnvrtFlags = 0;
132 const SvtFilterOptions& rFilterOptions = SvtFilterOptions::Get();
133 if ( rFilterOptions.IsMath2MathType() )
134 nCnvrtFlags |= OLE_STARMATH_2_MATHTYPE;
135 if ( rFilterOptions.IsWriter2WinWord() )
136 nCnvrtFlags |= OLE_STARWRITER_2_WINWORD;
137 if ( rFilterOptions.IsCalc2Excel() )
138 nCnvrtFlags |= OLE_STARCALC_2_EXCEL;
139 if ( rFilterOptions.IsImpress2PowerPoint() )
140 nCnvrtFlags |= OLE_STARIMPRESS_2_POWERPOINT;
141 if ( rFilterOptions.IsEnablePPTPreview() )
142 nCnvrtFlags |= 0x8000;
144 CreateStatusIndicator();
146 //OUString sBaseURI( "BaseURI");
147 std::vector< PropertyValue > aProperties;
148 PropertyValue aProperty;
149 aProperty.Name = "BaseURI";
150 aProperty.Value <<= mrMedium.GetBaseURL( true );
151 aProperties.push_back( aProperty );
153 bRet = PPTExport( aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
154 xStorRef->Commit();
158 return bRet;
161 void SdPPTFilter::PreSaveBasic()
163 const SvtFilterOptions& rFilterOptions = SvtFilterOptions::Get();
164 if( rFilterOptions.IsLoadPPointBasicStorage() )
166 #ifdef DISABLE_DYNLOADING
167 SaveVBAPointer pSaveVBA= SaveVBA;
168 #else
169 SaveVBAPointer pSaveVBA = reinterpret_cast< SaveVBAPointer >(
170 SdFilter::GetLibrarySymbol(mrMedium.GetFilter()->GetUserData(), "SaveVBA"));
171 #endif
172 if( pSaveVBA )
173 pSaveVBA( static_cast<SfxObjectShell&>(mrDocShell), pBas );
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */