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