Update ooo320-m1
[ooovba.git] / sd / source / filter / sdpptwrp.cxx
blob116df059a6be408dcebb30cdc23daacdbf4df37c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpptwrp.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/docfilt.hxx>
36 #include <osl/module.hxx>
37 #include <svx/msoleexp.hxx>
38 #include <svx/svxmsbas.hxx>
39 #include <svx/svxerr.hxx>
40 #include <svtools/fltrcfg.hxx>
42 #include "sdpptwrp.hxx"
43 #include "ppt/pptin.hxx"
44 #include "drawdoc.hxx"
45 #include <tools/urlobj.hxx>
46 #include <svx/msfiltertracer.hxx>
48 // --------------
49 // - Namespaces -
50 // --------------
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::task;
55 using namespace ::com::sun::star::frame;
58 typedef BOOL ( __LOADONCALLAPI *ExportPPT )( SvStorageRef&,
59 Reference< XModel > &,
60 Reference< XStatusIndicator > &,
61 SvMemoryStream*, sal_uInt32 nCnvrtFlags );
63 typedef sal_Bool ( SAL_CALL *ImportPPT )( const ::rtl::OUString&, Sequence< PropertyValue >*,
64 SdDrawDocument*, SvStream&, SvStorage&, SfxMedium& );
66 // ---------------
67 // - SdPPTFilter -
68 // ---------------
70 SdPPTFilter::SdPPTFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress ) :
71 SdFilter( rMedium, rDocShell, bShowProgress ),
72 pBas ( NULL )
76 // -----------------------------------------------------------------------------
78 SdPPTFilter::~SdPPTFilter()
80 delete pBas; // deleting the compressed basic storage
83 // -----------------------------------------------------------------------------
85 sal_Bool SdPPTFilter::Import()
87 sal_Bool bRet = sal_False;
88 SotStorageRef pStorage = new SotStorage( mrMedium.GetInStream(), FALSE );
89 if( !pStorage->GetError() )
91 /* check if there is a dualstorage, then the
92 document is propably a PPT95 containing PPT97 */
93 SvStorageRef xDualStorage;
94 String sDualStorage( RTL_CONSTASCII_USTRINGPARAM( "PP97_DUALSTORAGE" ) );
95 if ( pStorage->IsContained( sDualStorage ) )
97 xDualStorage = pStorage->OpenSotStorage( sDualStorage, STREAM_STD_READ );
98 pStorage = xDualStorage;
100 SvStream* pDocStream = pStorage->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM("PowerPoint Document") ), STREAM_STD_READ );
101 if( pDocStream )
103 pDocStream->SetVersion( pStorage->GetVersion() );
104 pDocStream->SetKey( pStorage->GetKey() );
106 String aTraceConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Tracing/Import/PowerPoint" ) );
107 Sequence< PropertyValue > aConfigData( 1 );
108 PropertyValue aPropValue;
109 aPropValue.Value <<= rtl::OUString( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
110 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentURL" ) );
111 aConfigData[ 0 ] = aPropValue;
113 if ( pStorage->IsStream( String( RTL_CONSTASCII_USTRINGPARAM("EncryptedSummary") ) ) )
114 mrMedium.SetError( ERRCODE_SVX_READ_FILTER_PPOINT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
115 else
117 ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
118 if ( pLibrary )
120 ImportPPT PPTImport = reinterpret_cast< ImportPPT >( pLibrary->getFunctionSymbol( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImportPPT" ) ) ) );
121 if ( PPTImport )
122 bRet = PPTImport( aTraceConfigPath, &aConfigData, &mrDocument, *pDocStream, *pStorage, mrMedium );
124 if ( !bRet )
125 mrMedium.SetError( SVSTREAM_WRONGVERSION, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
129 delete pDocStream;
133 return bRet;
136 // -----------------------------------------------------------------------------
138 sal_Bool SdPPTFilter::Export()
140 ::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
141 sal_Bool bRet = sal_False;
143 if( pLibrary )
145 if( mxModel.is() )
147 SotStorageRef xStorRef = new SotStorage( mrMedium.GetOutStream(), FALSE );
148 ExportPPT PPTExport = reinterpret_cast<ExportPPT>(pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii("ExportPPT") ));
150 /* !!!
151 if ( pViewShell && pViewShell->GetView() )
152 pViewShell->GetView()->SdrEndTextEdit();
154 if( PPTExport && xStorRef.Is() )
156 sal_uInt32 nCnvrtFlags = 0;
157 SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
158 if ( pFilterOptions )
160 if ( pFilterOptions->IsMath2MathType() )
161 nCnvrtFlags |= OLE_STARMATH_2_MATHTYPE;
162 if ( pFilterOptions->IsWriter2WinWord() )
163 nCnvrtFlags |= OLE_STARWRITER_2_WINWORD;
164 if ( pFilterOptions->IsCalc2Excel() )
165 nCnvrtFlags |= OLE_STARCALC_2_EXCEL;
166 if ( pFilterOptions->IsImpress2PowerPoint() )
167 nCnvrtFlags |= OLE_STARIMPRESS_2_POWERPOINT;
168 if ( pFilterOptions->IsEnablePPTPreview() )
169 nCnvrtFlags |= 0x8000;
172 mrDocument.SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
174 if( mbShowProgress )
175 CreateStatusIndicator();
177 bRet = PPTExport( xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
178 xStorRef->Commit();
181 delete pLibrary;
183 return bRet;
186 void SdPPTFilter::PreSaveBasic()
188 SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
189 if( pFilterOptions && pFilterOptions->IsLoadPPointBasicStorage() )
191 SvStorageRef xDest( new SvStorage( new SvMemoryStream(), TRUE ) );
192 SvxImportMSVBasic aMSVBas( (SfxObjectShell&) mrDocShell, *xDest, FALSE, FALSE );
193 aMSVBas.SaveOrDelMSVBAStorage( TRUE, String( RTL_CONSTASCII_USTRINGPARAM("_MS_VBA_Overhead") ) );
195 SvStorageRef xOverhead = xDest->OpenSotStorage( String( RTL_CONSTASCII_USTRINGPARAM("_MS_VBA_Overhead") ) );
196 if ( xOverhead.Is() && ( xOverhead->GetError() == SVSTREAM_OK ) )
198 SvStorageRef xOverhead2 = xOverhead->OpenSotStorage( String( RTL_CONSTASCII_USTRINGPARAM("_MS_VBA_Overhead") ) );
199 if ( xOverhead2.Is() && ( xOverhead2->GetError() == SVSTREAM_OK ) )
201 SvStorageStreamRef xTemp = xOverhead2->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM("_MS_VBA_Overhead2") ) );
202 if ( xTemp.Is() && ( xTemp->GetError() == SVSTREAM_OK ) )
204 UINT32 nLen = xTemp->GetSize();
205 if ( nLen )
207 char* pTemp = new char[ nLen ];
208 if ( pTemp )
210 xTemp->Seek( STREAM_SEEK_TO_BEGIN );
211 xTemp->Read( pTemp, nLen );
212 pBas = new SvMemoryStream( pTemp, nLen, STREAM_READ );
213 pBas->ObjectOwnsMemory( TRUE );