xref: /trunk/main/sd/source/filter/sdpptwrp.cxx (revision ac9b9032)
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 probably 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 				delete pLibrary;
122 			}
123 
124 			delete pDocStream;
125 		}
126 	}
127 
128 	return bRet;
129 }
130 
131 // -----------------------------------------------------------------------------
132 
Export()133 sal_Bool SdPPTFilter::Export()
134 {
135 	::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
136 	sal_Bool		bRet = sal_False;
137 
138 	if( pLibrary )
139 	{
140 		if( mxModel.is() )
141 		{
142 			SotStorageRef	xStorRef = new SotStorage( mrMedium.GetOutStream(), sal_False );
143 			ExportPPT		PPTExport = reinterpret_cast<ExportPPT>(pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii("ExportPPT") ));
144 
145 			/* !!!
146 			if ( pViewShell && pViewShell->GetView() )
147 				pViewShell->GetView()->SdrEndTextEdit();
148 			*/
149 			if( PPTExport && xStorRef.Is() )
150 			{
151 				sal_uInt32			nCnvrtFlags = 0;
152 				SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
153 				if ( pFilterOptions )
154 				{
155 					if ( pFilterOptions->IsMath2MathType() )
156 						nCnvrtFlags |= OLE_STARMATH_2_MATHTYPE;
157 					if ( pFilterOptions->IsWriter2WinWord() )
158 						nCnvrtFlags |= OLE_STARWRITER_2_WINWORD;
159 					if ( pFilterOptions->IsCalc2Excel() )
160 						nCnvrtFlags |= OLE_STARCALC_2_EXCEL;
161 					if ( pFilterOptions->IsImpress2PowerPoint() )
162 						nCnvrtFlags |= OLE_STARIMPRESS_2_POWERPOINT;
163 					if ( pFilterOptions->IsEnablePPTPreview() )
164 						nCnvrtFlags |= 0x8000;
165 				}
166 
167 				mrDocument.SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
168 
169 				if( mbShowProgress )
170 					CreateStatusIndicator();
171 
172 				rtl::OUString sBaseURI( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
173 				std::vector< PropertyValue > aProperties;
174 				PropertyValue aProperty;
175 				aProperty.Name = sBaseURI;
176 				aProperty.Value = makeAny( mrMedium.GetBaseURL( true ) );
177 				aProperties.push_back( aProperty );
178 
179 				bRet = PPTExport( aProperties, xStorRef, mxModel, mxStatusIndicator, pBas, nCnvrtFlags );
180 				xStorRef->Commit();
181 			}
182 		}
183 		delete pLibrary;
184 	}
185 	return bRet;
186 }
187 
PreSaveBasic()188 void SdPPTFilter::PreSaveBasic()
189 {
190 	SvtFilterOptions* pFilterOptions = SvtFilterOptions::Get();
191 	if( pFilterOptions && pFilterOptions->IsLoadPPointBasicStorage() )
192 	{
193 		::osl::Module* pLibrary = OpenLibrary( mrMedium.GetFilter()->GetUserData() );
194 		if( pLibrary )
195 		{
196 			SaveVBA pSaveVBA= reinterpret_cast<SaveVBA>(pLibrary->getFunctionSymbol( ::rtl::OUString::createFromAscii("SaveVBA") ));
197 			if( pSaveVBA )
198 			{
199 				pSaveVBA( (SfxObjectShell&) mrDocShell, pBas );
200 			}
201 			delete pLibrary;
202 		}
203 	}
204 }
205 
206 /* vim: set noet sw=4 ts=4: */
207