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 .
21 #include <sfx2/docfile.hxx>
22 #include <sfx2/docfilt.hxx>
23 #include <osl/module.hxx>
24 #include <filter/msfilter/msoleexp.hxx>
25 #include <filter/msfilter/svxmsbas.hxx>
26 #include <svx/svxerr.hxx>
27 #include <unotools/fltrcfg.hxx>
29 #include "sdpptwrp.hxx"
30 #include "ppt/pptin.hxx"
31 #include "drawdoc.hxx"
32 #include <tools/urlobj.hxx>
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::beans
;
40 using namespace ::com::sun::star::task
;
41 using namespace ::com::sun::star::frame
;
43 typedef sal_Bool ( SAL_CALL
*ExportPPTPointer
)( const std::vector
< com::sun::star::beans::PropertyValue
>&, SvStorageRef
&,
44 Reference
< XModel
> &,
45 Reference
< XStatusIndicator
> &,
46 SvMemoryStream
*, sal_uInt32 nCnvrtFlags
);
48 typedef sal_Bool ( SAL_CALL
*ImportPPTPointer
)( SdDrawDocument
*, SvStream
&, SvStorage
&, SfxMedium
& );
50 typedef sal_Bool ( SAL_CALL
*SaveVBAPointer
)( SfxObjectShell
&, SvMemoryStream
*& );
52 #ifdef DISABLE_DYNLOADING
54 extern "C" sal_Bool
ExportPPT( const std::vector
< com::sun::star::beans::PropertyValue
>&, SvStorageRef
&,
55 Reference
< XModel
> &,
56 Reference
< XStatusIndicator
> &,
57 SvMemoryStream
*, sal_uInt32 nCnvrtFlags
);
59 extern "C" sal_Bool
ImportPPT( SdDrawDocument
*, SvStream
&, SvStorage
&, SfxMedium
& );
61 extern "C" sal_Bool
SaveVBA( SfxObjectShell
&, SvMemoryStream
*& );
69 SdPPTFilter::SdPPTFilter( SfxMedium
& rMedium
, ::sd::DrawDocShell
& rDocShell
, sal_Bool bShowProgress
) :
70 SdFilter( rMedium
, rDocShell
, bShowProgress
),
75 // -----------------------------------------------------------------------------
77 SdPPTFilter::~SdPPTFilter()
79 delete pBas
; // deleting the compressed basic storage
82 // -----------------------------------------------------------------------------
84 sal_Bool
SdPPTFilter::Import()
86 sal_Bool bRet
= sal_False
;
87 SotStorageRef pStorage
= new SotStorage( mrMedium
.GetInStream(), sal_False
);
88 if( !pStorage
->GetError() )
90 /* check if there is a dualstorage, then the
91 document is propably a PPT95 containing PPT97 */
92 SvStorageRef xDualStorage
;
93 String
sDualStorage( "PP97_DUALSTORAGE" );
94 if ( pStorage
->IsContained( sDualStorage
) )
96 xDualStorage
= pStorage
->OpenSotStorage( sDualStorage
, STREAM_STD_READ
);
97 pStorage
= xDualStorage
;
99 SvStream
* pDocStream
= pStorage
->OpenSotStream( OUString("PowerPoint Document") , STREAM_STD_READ
);
102 pDocStream
->SetVersion( pStorage
->GetVersion() );
103 pDocStream
->SetCryptMaskKey(pStorage
->GetKey());
105 if ( pStorage
->IsStream( OUString("EncryptedSummary" ) ) )
106 mrMedium
.SetError( ERRCODE_SVX_READ_FILTER_PPOINT
, OSL_LOG_PREFIX
);
109 #ifndef DISABLE_DYNLOADING
110 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
113 ImportPPTPointer PPTImport
= reinterpret_cast< ImportPPTPointer
>( pLibrary
->getFunctionSymbol( "ImportPPT" ) );
115 bRet
= PPTImport( &mrDocument
, *pDocStream
, *pStorage
, mrMedium
);
118 mrMedium
.SetError( SVSTREAM_WRONGVERSION
, OSL_LOG_PREFIX
);
121 bRet
= ImportPPT( &mrDocument
, *pDocStream
, *pStorage
, mrMedium
);
123 mrMedium
.SetError( SVSTREAM_WRONGVERSION
, OSL_LOG_PREFIX
);
134 // -----------------------------------------------------------------------------
136 sal_Bool
SdPPTFilter::Export()
138 #ifndef DISABLE_DYNLOADING
139 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
141 sal_Bool bRet
= sal_False
;
143 #ifndef DISABLE_DYNLOADING
149 SotStorageRef xStorRef
= new SotStorage( mrMedium
.GetOutStream(), sal_False
);
150 #ifndef DISABLE_DYNLOADING
151 ExportPPTPointer PPTExport
= reinterpret_cast<ExportPPTPointer
>(pLibrary
->getFunctionSymbol( "ExportPPT" ));
153 ExportPPTPointer PPTExport
= ExportPPT
;
156 if( PPTExport
&& xStorRef
.Is() )
158 sal_uInt32 nCnvrtFlags
= 0;
159 const SvtFilterOptions
& rFilterOptions
= SvtFilterOptions::Get();
160 if ( rFilterOptions
.IsMath2MathType() )
161 nCnvrtFlags
|= OLE_STARMATH_2_MATHTYPE
;
162 if ( rFilterOptions
.IsWriter2WinWord() )
163 nCnvrtFlags
|= OLE_STARWRITER_2_WINWORD
;
164 if ( rFilterOptions
.IsCalc2Excel() )
165 nCnvrtFlags
|= OLE_STARCALC_2_EXCEL
;
166 if ( rFilterOptions
.IsImpress2PowerPoint() )
167 nCnvrtFlags
|= OLE_STARIMPRESS_2_POWERPOINT
;
168 if ( rFilterOptions
.IsEnablePPTPreview() )
169 nCnvrtFlags
|= 0x8000;
171 mrDocument
.SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP
);
174 CreateStatusIndicator();
176 //OUString sBaseURI( "BaseURI");
177 std::vector
< PropertyValue
> aProperties
;
178 PropertyValue aProperty
;
179 aProperty
.Name
= "BaseURI";
180 aProperty
.Value
= makeAny( mrMedium
.GetBaseURL( true ) );
181 aProperties
.push_back( aProperty
);
183 bRet
= PPTExport( aProperties
, xStorRef
, mxModel
, mxStatusIndicator
, pBas
, nCnvrtFlags
);
187 #ifndef DISABLE_DYNLOADING
194 void SdPPTFilter::PreSaveBasic()
196 const SvtFilterOptions
& rFilterOptions
= SvtFilterOptions::Get();
197 if( rFilterOptions
.IsLoadPPointBasicStorage() )
199 #ifndef DISABLE_DYNLOADING
200 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
203 SaveVBAPointer pSaveVBA
= reinterpret_cast<SaveVBAPointer
>(pLibrary
->getFunctionSymbol( "SaveVBA" ));
206 pSaveVBA( (SfxObjectShell
&) mrDocShell
, pBas
);
210 SaveVBA( (SfxObjectShell
&) mrDocShell
, pBas
);
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */