xref: /aoo41x/main/sd/source/filter/sdpptwrp.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sfx2/docfile.hxx>
28cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
29cdf0e10cSrcweir #include <osl/module.hxx>
30cdf0e10cSrcweir #include <filter/msfilter/msoleexp.hxx>
31cdf0e10cSrcweir #include <filter/msfilter/svxmsbas.hxx>
32cdf0e10cSrcweir #include <svx/svxerr.hxx>
33cdf0e10cSrcweir #include <unotools/fltrcfg.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "sdpptwrp.hxx"
36cdf0e10cSrcweir #include "ppt/pptin.hxx"
37cdf0e10cSrcweir #include "drawdoc.hxx"
38cdf0e10cSrcweir #include <tools/urlobj.hxx>
39cdf0e10cSrcweir #include <filter/msfilter/msfiltertracer.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // --------------
42cdf0e10cSrcweir // - Namespaces -
43cdf0e10cSrcweir // --------------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace ::com::sun::star::beans;
47cdf0e10cSrcweir using namespace ::com::sun::star::task;
48cdf0e10cSrcweir using namespace ::com::sun::star::frame;
49cdf0e10cSrcweir 
503681f89cSEike Rathke typedef sal_Bool ( __LOADONCALLAPI *ExportPPT )( const std::vector< com::sun::star::beans::PropertyValue >&, SvStorageRef&,
51cdf0e10cSrcweir 											 Reference< XModel > &,
52cdf0e10cSrcweir 											 Reference< XStatusIndicator > &,
53cdf0e10cSrcweir 											 SvMemoryStream*, sal_uInt32 nCnvrtFlags );
54cdf0e10cSrcweir 
55cdf0e10cSrcweir typedef sal_Bool ( SAL_CALL *ImportPPT )( const ::rtl::OUString&, Sequence< PropertyValue >*,
56cdf0e10cSrcweir                                           SdDrawDocument*, SvStream&, SvStorage&, SfxMedium& );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir typedef sal_Bool ( __LOADONCALLAPI *SaveVBA )( SfxObjectShell&, SvMemoryStream*& );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // ---------------
61cdf0e10cSrcweir // - SdPPTFilter -
62cdf0e10cSrcweir // ---------------
63cdf0e10cSrcweir 
SdPPTFilter(SfxMedium & rMedium,::sd::DrawDocShell & rDocShell,sal_Bool bShowProgress)64cdf0e10cSrcweir SdPPTFilter::SdPPTFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress ) :
65cdf0e10cSrcweir 	SdFilter( rMedium, rDocShell, bShowProgress ),
66cdf0e10cSrcweir 	pBas	( NULL )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // -----------------------------------------------------------------------------
71cdf0e10cSrcweir 
~SdPPTFilter()72cdf0e10cSrcweir SdPPTFilter::~SdPPTFilter()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	delete pBas;	// deleting the compressed basic storage
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // -----------------------------------------------------------------------------
78cdf0e10cSrcweir 
Import()79cdf0e10cSrcweir sal_Bool SdPPTFilter::Import()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	sal_Bool	bRet = sal_False;
82cdf0e10cSrcweir 	SotStorageRef pStorage = new SotStorage( mrMedium.GetInStream(), sal_False );
83cdf0e10cSrcweir 	if( !pStorage->GetError() )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		/* check if there is a dualstorage, then the
86cdf0e10cSrcweir 		document is propably a PPT95 containing PPT97 */
87cdf0e10cSrcweir 		SvStorageRef xDualStorage;
88cdf0e10cSrcweir 		String sDualStorage( RTL_CONSTASCII_USTRINGPARAM( "PP97_DUALSTORAGE" ) );
89cdf0e10cSrcweir 		if ( pStorage->IsContained( sDualStorage ) )
90cdf0e10cSrcweir 		{
91cdf0e10cSrcweir             xDualStorage = pStorage->OpenSotStorage( sDualStorage, STREAM_STD_READ );
92cdf0e10cSrcweir 			pStorage = xDualStorage;
93cdf0e10cSrcweir 		}
94cdf0e10cSrcweir         SvStream* pDocStream = pStorage->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM("PowerPoint Document") ), STREAM_STD_READ );
95cdf0e10cSrcweir 		if( pDocStream )
96cdf0e10cSrcweir 		{
97cdf0e10cSrcweir 			pDocStream->SetVersion( pStorage->GetVersion() );
98cdf0e10cSrcweir 			pDocStream->SetKey( pStorage->GetKey() );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 			String aTraceConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Tracing/Import/PowerPoint" ) );
101cdf0e10cSrcweir 			Sequence< PropertyValue > aConfigData( 1 );
102cdf0e10cSrcweir 			PropertyValue aPropValue;
103cdf0e10cSrcweir 			aPropValue.Value <<= rtl::OUString( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
104cdf0e10cSrcweir 			aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentURL" ) );
105cdf0e10cSrcweir 			aConfigData[ 0 ] = aPropValue;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 			if ( pStorage->IsStream( String( RTL_CONSTASCII_USTRINGPARAM("EncryptedSummary") ) ) )
108cdf0e10cSrcweir 				mrMedium.SetError( ERRCODE_SVX_READ_FILTER_PPOINT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
109cdf0e10cSrcweir 			else
110cdf0e10cSrcweir 			{
111cdf0e10cSrcweir 				::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
112cdf0e10cSrcweir 				if ( pLibrary )
113cdf0e10cSrcweir 				{
114cdf0e10cSrcweir 					ImportPPT PPTImport = reinterpret_cast< ImportPPT >( pLibrary->getFunctionSymbol( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImportPPT" ) ) ) );
115cdf0e10cSrcweir 					if ( PPTImport )
116cdf0e10cSrcweir 						bRet = PPTImport( aTraceConfigPath, &aConfigData, &mrDocument, *pDocStream, *pStorage, mrMedium );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 					if ( !bRet )
119cdf0e10cSrcweir 						mrMedium.SetError( SVSTREAM_WRONGVERSION, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
120cdf0e10cSrcweir 				}
121cdf0e10cSrcweir 			}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 			delete pDocStream;
124cdf0e10cSrcweir 		}
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	return bRet;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir // -----------------------------------------------------------------------------
131cdf0e10cSrcweir 
Export()132cdf0e10cSrcweir sal_Bool SdPPTFilter::Export()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
135cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	if( pLibrary )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		if( mxModel.is() )
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir             SotStorageRef    xStorRef = new SotStorage( mrMedium.GetOutStream(), sal_False );
142cdf0e10cSrcweir 			ExportPPT		PPTExport = reinterpret_cast<ExportPPT>(pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii("ExportPPT") ));
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 			/* !!!
145cdf0e10cSrcweir 			if ( pViewShell && pViewShell->GetView() )
146cdf0e10cSrcweir 				pViewShell->GetView()->SdrEndTextEdit();
147cdf0e10cSrcweir 			*/
148cdf0e10cSrcweir             if( PPTExport && xStorRef.Is() )
149cdf0e10cSrcweir 			{
150cdf0e10cSrcweir 				sal_uInt32			nCnvrtFlags = 0;
151cdf0e10cSrcweir 				SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
152cdf0e10cSrcweir 				if ( pFilterOptions )
153cdf0e10cSrcweir 				{
154cdf0e10cSrcweir 					if ( pFilterOptions->IsMath2MathType() )
155cdf0e10cSrcweir 						nCnvrtFlags |= OLE_STARMATH_2_MATHTYPE;
156cdf0e10cSrcweir 					if ( pFilterOptions->IsWriter2WinWord() )
157cdf0e10cSrcweir 						nCnvrtFlags |= OLE_STARWRITER_2_WINWORD;
158cdf0e10cSrcweir 					if ( pFilterOptions->IsCalc2Excel() )
159cdf0e10cSrcweir 						nCnvrtFlags |= OLE_STARCALC_2_EXCEL;
160cdf0e10cSrcweir 					if ( pFilterOptions->IsImpress2PowerPoint() )
161cdf0e10cSrcweir 						nCnvrtFlags |= OLE_STARIMPRESS_2_POWERPOINT;
162cdf0e10cSrcweir 					if ( pFilterOptions->IsEnablePPTPreview() )
163cdf0e10cSrcweir 						nCnvrtFlags |= 0x8000;
164cdf0e10cSrcweir 				}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 				mrDocument.SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 				if( mbShowProgress )
169cdf0e10cSrcweir 					CreateStatusIndicator();
170cdf0e10cSrcweir 
1713681f89cSEike Rathke 				rtl::OUString sBaseURI( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
1723681f89cSEike Rathke 				std::vector< PropertyValue > aProperties;
1733681f89cSEike Rathke 				PropertyValue aProperty;
1743681f89cSEike Rathke 				aProperty.Name = sBaseURI;
1753681f89cSEike Rathke 				aProperty.Value = makeAny( mrMedium.GetBaseURL( true ) );
1763681f89cSEike Rathke 				aProperties.push_back( aProperty );
1773681f89cSEike Rathke 
1783681f89cSEike Rathke 				bRet = PPTExport( aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
179cdf0e10cSrcweir                 xStorRef->Commit();
180cdf0e10cSrcweir 			}
181cdf0e10cSrcweir 		}
182cdf0e10cSrcweir 		delete pLibrary;
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 	return bRet;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
PreSaveBasic()187cdf0e10cSrcweir void SdPPTFilter::PreSaveBasic()
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
190cdf0e10cSrcweir 	if( pFilterOptions && pFilterOptions->IsLoadPPointBasicStorage() )
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
193cdf0e10cSrcweir 		if( pLibrary )
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			SaveVBA pSaveVBA= reinterpret_cast<SaveVBA>(pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii("SaveVBA") ));
196cdf0e10cSrcweir             if( pSaveVBA )
197cdf0e10cSrcweir 			{
198cdf0e10cSrcweir 				pSaveVBA( (SfxObjectShell&) mrDocShell, pBas );
199cdf0e10cSrcweir 			}
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir }
203