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 <sfx2/docfile.hxx>
21 #include <sfx2/docfilt.hxx>
22 #include <sfx2/objsh.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 "DrawDocShell.hxx"
33 #include <tools/urlobj.hxx>
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::task
;
40 using namespace ::com::sun::star::frame
;
42 typedef sal_Bool ( SAL_CALL
*ExportPPTPointer
)( const std::vector
< com::sun::star::beans::PropertyValue
>&, tools::SvRef
<SotStorage
>&,
43 Reference
< XModel
> &,
44 Reference
< XStatusIndicator
> &,
45 SvMemoryStream
*, sal_uInt32 nCnvrtFlags
);
47 typedef sal_Bool ( SAL_CALL
*ImportPPTPointer
)( SdDrawDocument
*, SvStream
&, SotStorage
&, SfxMedium
& );
49 typedef sal_Bool ( SAL_CALL
*SaveVBAPointer
)( SfxObjectShell
&, SvMemoryStream
*& );
51 #ifdef DISABLE_DYNLOADING
53 extern "C" sal_Bool
ExportPPT( const std::vector
< com::sun::star::beans::PropertyValue
>&, tools::SvRef
<SotStorage
>&,
54 Reference
< XModel
> &,
55 Reference
< XStatusIndicator
> &,
56 SvMemoryStream
*, sal_uInt32 nCnvrtFlags
);
58 extern "C" sal_Bool
ImportPPT( SdDrawDocument
*, SvStream
&, SotStorage
&, SfxMedium
& );
60 extern "C" sal_Bool
SaveVBA( SfxObjectShell
&, SvMemoryStream
*& );
66 SdPPTFilter::SdPPTFilter( SfxMedium
& rMedium
, ::sd::DrawDocShell
& rDocShell
, bool bShowProgress
) :
67 SdFilter( rMedium
, rDocShell
, bShowProgress
),
72 SdPPTFilter::~SdPPTFilter()
74 delete pBas
; // deleting the compressed basic storage
77 bool SdPPTFilter::Import()
80 tools::SvRef
<SotStorage
> pStorage
= new SotStorage( mrMedium
.GetInStream(), false );
81 if( !pStorage
->GetError() )
83 /* check if there is a dualstorage, then the
84 document is probably a PPT95 containing PPT97 */
85 tools::SvRef
<SotStorage
> xDualStorage
;
86 OUString
sDualStorage( "PP97_DUALSTORAGE" );
87 if ( pStorage
->IsContained( sDualStorage
) )
89 xDualStorage
= pStorage
->OpenSotStorage( sDualStorage
, STREAM_STD_READ
);
90 pStorage
= xDualStorage
;
92 SvStream
* pDocStream
= pStorage
->OpenSotStream( OUString("PowerPoint Document") , STREAM_STD_READ
);
95 pDocStream
->SetVersion( pStorage
->GetVersion() );
96 pDocStream
->SetCryptMaskKey(pStorage
->GetKey());
98 if ( pStorage
->IsStream( OUString("EncryptedSummary" ) ) )
99 mrMedium
.SetError( ERRCODE_SVX_READ_FILTER_PPOINT
, OSL_LOG_PREFIX
);
102 #ifndef DISABLE_DYNLOADING
103 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
106 ImportPPTPointer PPTImport
= reinterpret_cast< ImportPPTPointer
>( pLibrary
->getFunctionSymbol( "ImportPPT" ) );
108 bRet
= PPTImport( &mrDocument
, *pDocStream
, *pStorage
, mrMedium
);
111 mrMedium
.SetError( SVSTREAM_WRONGVERSION
, OSL_LOG_PREFIX
);
114 bRet
= ImportPPT( &mrDocument
, *pDocStream
, *pStorage
, mrMedium
);
116 mrMedium
.SetError( SVSTREAM_WRONGVERSION
, OSL_LOG_PREFIX
);
127 bool SdPPTFilter::Export()
129 #ifndef DISABLE_DYNLOADING
130 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
134 #ifndef DISABLE_DYNLOADING
140 tools::SvRef
<SotStorage
> xStorRef
= new SotStorage( mrMedium
.GetOutStream(), false );
141 #ifndef DISABLE_DYNLOADING
142 ExportPPTPointer PPTExport
= reinterpret_cast<ExportPPTPointer
>(pLibrary
->getFunctionSymbol( "ExportPPT" ));
144 ExportPPTPointer PPTExport
= ExportPPT
;
147 if( PPTExport
&& xStorRef
.Is() )
149 sal_uInt32 nCnvrtFlags
= 0;
150 const SvtFilterOptions
& rFilterOptions
= SvtFilterOptions::Get();
151 if ( rFilterOptions
.IsMath2MathType() )
152 nCnvrtFlags
|= OLE_STARMATH_2_MATHTYPE
;
153 if ( rFilterOptions
.IsWriter2WinWord() )
154 nCnvrtFlags
|= OLE_STARWRITER_2_WINWORD
;
155 if ( rFilterOptions
.IsCalc2Excel() )
156 nCnvrtFlags
|= OLE_STARCALC_2_EXCEL
;
157 if ( rFilterOptions
.IsImpress2PowerPoint() )
158 nCnvrtFlags
|= OLE_STARIMPRESS_2_POWERPOINT
;
159 if ( rFilterOptions
.IsEnablePPTPreview() )
160 nCnvrtFlags
|= 0x8000;
162 mrDocument
.SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP
);
165 CreateStatusIndicator();
167 //OUString sBaseURI( "BaseURI");
168 std::vector
< PropertyValue
> aProperties
;
169 PropertyValue aProperty
;
170 aProperty
.Name
= "BaseURI";
171 aProperty
.Value
= makeAny( mrMedium
.GetBaseURL( true ) );
172 aProperties
.push_back( aProperty
);
174 bRet
= PPTExport( aProperties
, xStorRef
, mxModel
, mxStatusIndicator
, pBas
, nCnvrtFlags
);
178 #ifndef DISABLE_DYNLOADING
185 void SdPPTFilter::PreSaveBasic()
187 const SvtFilterOptions
& rFilterOptions
= SvtFilterOptions::Get();
188 if( rFilterOptions
.IsLoadPPointBasicStorage() )
190 #ifndef DISABLE_DYNLOADING
191 ::osl::Module
* pLibrary
= OpenLibrary( mrMedium
.GetFilter()->GetUserData() );
194 SaveVBAPointer pSaveVBA
= reinterpret_cast<SaveVBAPointer
>(pLibrary
->getFunctionSymbol( "SaveVBA" ));
197 pSaveVBA( static_cast<SfxObjectShell
&>(mrDocShell
), pBas
);
202 SaveVBA( (SfxObjectShell
&) mrDocShell
, pBas
);
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */