Line data Source code
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 <sfx2/docfile.hxx>
21 : #include <sfx2/docfilt.hxx>
22 : #include <osl/module.hxx>
23 : #include <filter/msfilter/msoleexp.hxx>
24 : #include <filter/msfilter/svxmsbas.hxx>
25 : #include <svx/svxerr.hxx>
26 : #include <unotools/fltrcfg.hxx>
27 :
28 : #include "sdpptwrp.hxx"
29 : #include "ppt/pptin.hxx"
30 : #include "drawdoc.hxx"
31 : #include <tools/urlobj.hxx>
32 :
33 : // - Namespaces -
34 :
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::task;
38 : using namespace ::com::sun::star::frame;
39 :
40 : typedef sal_Bool ( SAL_CALL *ExportPPTPointer )( const std::vector< com::sun::star::beans::PropertyValue >&, SvStorageRef&,
41 : Reference< XModel > &,
42 : Reference< XStatusIndicator > &,
43 : SvMemoryStream*, sal_uInt32 nCnvrtFlags );
44 :
45 : typedef sal_Bool ( SAL_CALL *ImportPPTPointer )( SdDrawDocument*, SvStream&, SvStorage&, SfxMedium& );
46 :
47 : typedef sal_Bool ( SAL_CALL *SaveVBAPointer )( SfxObjectShell&, SvMemoryStream*& );
48 :
49 : #ifdef DISABLE_DYNLOADING
50 :
51 : extern "C" sal_Bool ExportPPT( const std::vector< com::sun::star::beans::PropertyValue >&, SvStorageRef&,
52 : Reference< XModel > &,
53 : Reference< XStatusIndicator > &,
54 : SvMemoryStream*, sal_uInt32 nCnvrtFlags );
55 :
56 : extern "C" sal_Bool ImportPPT( SdDrawDocument*, SvStream&, SvStorage&, SfxMedium& );
57 :
58 : extern "C" sal_Bool SaveVBA( SfxObjectShell&, SvMemoryStream*& );
59 :
60 : #endif
61 :
62 : // - SdPPTFilter -
63 :
64 20 : SdPPTFilter::SdPPTFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, bool bShowProgress ) :
65 : SdFilter( rMedium, rDocShell, bShowProgress ),
66 20 : pBas ( NULL )
67 : {
68 20 : }
69 :
70 40 : SdPPTFilter::~SdPPTFilter()
71 : {
72 20 : delete pBas; // deleting the compressed basic storage
73 20 : }
74 :
75 20 : bool SdPPTFilter::Import()
76 : {
77 20 : bool bRet = false;
78 20 : SotStorageRef pStorage = new SotStorage( mrMedium.GetInStream(), false );
79 20 : if( !pStorage->GetError() )
80 : {
81 : /* check if there is a dualstorage, then the
82 : document is probably a PPT95 containing PPT97 */
83 20 : SvStorageRef xDualStorage;
84 40 : OUString sDualStorage( "PP97_DUALSTORAGE" );
85 20 : if ( pStorage->IsContained( sDualStorage ) )
86 : {
87 0 : xDualStorage = pStorage->OpenSotStorage( sDualStorage, STREAM_STD_READ );
88 0 : pStorage = xDualStorage;
89 : }
90 20 : SvStream* pDocStream = pStorage->OpenSotStream( OUString("PowerPoint Document") , STREAM_STD_READ );
91 20 : if( pDocStream )
92 : {
93 20 : pDocStream->SetVersion( pStorage->GetVersion() );
94 20 : pDocStream->SetCryptMaskKey(pStorage->GetKey());
95 :
96 20 : if ( pStorage->IsStream( OUString("EncryptedSummary" ) ) )
97 0 : mrMedium.SetError( ERRCODE_SVX_READ_FILTER_PPOINT, OSL_LOG_PREFIX );
98 : else
99 : {
100 : #ifndef DISABLE_DYNLOADING
101 20 : ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
102 20 : if ( pLibrary )
103 : {
104 20 : ImportPPTPointer PPTImport = reinterpret_cast< ImportPPTPointer >( pLibrary->getFunctionSymbol( "ImportPPT" ) );
105 20 : if ( PPTImport )
106 20 : bRet = PPTImport( &mrDocument, *pDocStream, *pStorage, mrMedium );
107 :
108 20 : if ( !bRet )
109 2 : mrMedium.SetError( SVSTREAM_WRONGVERSION, OSL_LOG_PREFIX );
110 : }
111 : #else
112 : bRet = ImportPPT( &mrDocument, *pDocStream, *pStorage, mrMedium );
113 : if ( !bRet )
114 : mrMedium.SetError( SVSTREAM_WRONGVERSION, OSL_LOG_PREFIX );
115 : #endif
116 : }
117 :
118 20 : delete pDocStream;
119 20 : }
120 : }
121 :
122 20 : return bRet;
123 : }
124 :
125 0 : bool SdPPTFilter::Export()
126 : {
127 : #ifndef DISABLE_DYNLOADING
128 0 : ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
129 : #endif
130 0 : bool bRet = false;
131 :
132 : #ifndef DISABLE_DYNLOADING
133 0 : if( pLibrary )
134 : #endif
135 : {
136 0 : if( mxModel.is() )
137 : {
138 0 : SotStorageRef xStorRef = new SotStorage( mrMedium.GetOutStream(), false );
139 : #ifndef DISABLE_DYNLOADING
140 0 : ExportPPTPointer PPTExport = reinterpret_cast<ExportPPTPointer>(pLibrary->getFunctionSymbol( "ExportPPT" ));
141 : #else
142 : ExportPPTPointer PPTExport = ExportPPT;
143 : #endif
144 :
145 0 : if( PPTExport && xStorRef.Is() )
146 : {
147 0 : sal_uInt32 nCnvrtFlags = 0;
148 0 : const SvtFilterOptions& rFilterOptions = SvtFilterOptions::Get();
149 0 : if ( rFilterOptions.IsMath2MathType() )
150 0 : nCnvrtFlags |= OLE_STARMATH_2_MATHTYPE;
151 0 : if ( rFilterOptions.IsWriter2WinWord() )
152 0 : nCnvrtFlags |= OLE_STARWRITER_2_WINWORD;
153 0 : if ( rFilterOptions.IsCalc2Excel() )
154 0 : nCnvrtFlags |= OLE_STARCALC_2_EXCEL;
155 0 : if ( rFilterOptions.IsImpress2PowerPoint() )
156 0 : nCnvrtFlags |= OLE_STARIMPRESS_2_POWERPOINT;
157 0 : if ( rFilterOptions.IsEnablePPTPreview() )
158 0 : nCnvrtFlags |= 0x8000;
159 :
160 0 : mrDocument.SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
161 :
162 0 : if( mbShowProgress )
163 0 : CreateStatusIndicator();
164 :
165 : //OUString sBaseURI( "BaseURI");
166 0 : std::vector< PropertyValue > aProperties;
167 0 : PropertyValue aProperty;
168 0 : aProperty.Name = "BaseURI";
169 0 : aProperty.Value = makeAny( mrMedium.GetBaseURL( true ) );
170 0 : aProperties.push_back( aProperty );
171 :
172 0 : bRet = PPTExport( aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
173 0 : xStorRef->Commit();
174 0 : }
175 : }
176 : #ifndef DISABLE_DYNLOADING
177 0 : delete pLibrary;
178 : #endif
179 : }
180 0 : return bRet;
181 : }
182 :
183 0 : void SdPPTFilter::PreSaveBasic()
184 : {
185 0 : const SvtFilterOptions& rFilterOptions = SvtFilterOptions::Get();
186 0 : if( rFilterOptions.IsLoadPPointBasicStorage() )
187 : {
188 : #ifndef DISABLE_DYNLOADING
189 0 : ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
190 0 : if( pLibrary )
191 : {
192 0 : SaveVBAPointer pSaveVBA= reinterpret_cast<SaveVBAPointer>(pLibrary->getFunctionSymbol( "SaveVBA" ));
193 0 : if( pSaveVBA )
194 : {
195 0 : pSaveVBA( (SfxObjectShell&) mrDocShell, pBas );
196 : }
197 0 : delete pLibrary;
198 : }
199 : #else
200 : SaveVBA( (SfxObjectShell&) mrDocShell, pBas );
201 : #endif
202 : }
203 114 : }
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|