xref: /aoo4110/main/sc/source/filter/lotus/lotread.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_sc.hxx"
26 
27 
28 
29 //------------------------------------------------------------------------
30 
31 #include "document.hxx"
32 
33 #include "scerrors.hxx"
34 #include "root.hxx"
35 #include "lotimpop.hxx"
36 #include "lotattr.hxx"
37 #include "fprogressbar.hxx"
38 
39 
40 class ScFormulaCell;
41 
42 
Read()43 FltError ImportLotus::Read()
44 {
45 	enum STATE
46 	{
47 		S_START,		// analyse first BOF
48 		S_WK1,			// in WK1-Stream
49 		S_WK3,			// in WK3-Section
50 		S_WK4,			// ...
51 		S_FM3,			// ...
52 		S_END			// Import finished
53 	};
54 
55 	sal_uInt16			nOp;
56 	sal_uInt16			nSubType;
57 	sal_uInt16			nRecLen;
58 	sal_uInt32			nNextRec = 0UL;
59 	FltError		eRet = eERR_OK;
60 //	ScFormulaCell	*pLastFormCell;
61 
62 	STATE			eAkt = S_START;
63 
64 	nTab = 0;
65 	nExtTab = -2;
66 
67 	pIn->Seek( nNextRec );
68 
69 	// Progressbar starten
70     ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
71 
72 	while( eAkt != S_END )
73 	{
74 		*pIn >> nOp >> nRecLen;
75 
76 		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
77 			eAkt = S_END;
78 
79 		nNextRec += nRecLen + 4;
80 
81 		switch( eAkt )
82 		{
83 			// -----------------------------------------------------------
84 			case S_START:											// S_START
85 			if( nOp )
86 			{
87 				eRet = SCERR_IMPORT_UNKNOWN_WK;
88 				eAkt = S_END;
89 			}
90 			else
91 			{
92 				if( nRecLen > 2 )
93 				{
94 					Bof();
95 					switch( pLotusRoot->eFirstType )
96 					{
97 						case Lotus_WK1:	eAkt = S_WK1; break;
98 						case Lotus_WK3:	eAkt = S_WK3; break;
99 						case Lotus_WK4:	eAkt = S_WK4; break;
100 						case Lotus_FM3: eAkt = S_FM3; break;
101 						default:
102 						eRet = SCERR_IMPORT_UNKNOWN_WK;
103 						eAkt = S_END;
104 					}
105 				}
106 				else
107 				{
108 					eAkt = S_END;	// hier kommt wat fuer <= WK1 hinne!
109 					eRet = 0xFFFFFFFF;
110 				}
111 			}
112 			break;
113 			// -----------------------------------------------------------
114 			case S_WK1:												// S_WK1
115 			break;
116 			// -----------------------------------------------------------
117 			case S_WK3:												// S_WK3
118 			case S_WK4:												// S_WK4
119 			switch( nOp )
120 			{
121 				case 0x0001:							// EOF
122 				eAkt = S_FM3;
123 				nTab++;
124 				break;
125 
126 				case 0x0002:							// PASSWORD
127 				eRet = eERR_FILEPASSWD;
128 				eAkt = S_END;
129 				break;
130 
131 				case 0x0007:							// COLUMNWIDTH
132 				Columnwidth( nRecLen );
133 				break;
134 
135 				case 0x0008:							// HIDDENCOLUMN
136 				Hiddencolumn( nRecLen );
137 				break;
138 
139 				case 0x0009:							// USERRANGE
140 				Userrange();
141 				break;
142 
143 				case 0x0013:							// FORMAT
144 
145 				break;
146 				case 0x0014:							// ERRCELL
147 				Errcell();
148 				break;
149 
150 				case 0x0015:							// NACELL
151 				Nacell();
152 				break;
153 
154 				case 0x0016:							// LABELCELL
155 				Labelcell();
156 				break;
157 
158 				case 0x0017:							// NUMBERCELL
159 				Numbercell();
160 				break;
161 
162 				case 0x0018:							// SMALLNUMCELL
163 				Smallnumcell();
164 				break;
165 
166 				case 0x0019:							// FORMULACELL
167 				Formulacell( nRecLen );
168 				break;
169 
170 				case 0x001b:							// extended attributes
171                 if (nRecLen > 2)
172                 {
173                     Read( nSubType );
174                     nRecLen -= 2;
175                     switch( nSubType )
176                     {
177                         case 2007:                      // ROW PRESENTATION
178                             RowPresentation( nRecLen );
179                             break;
180 
181                         case 14000:                     // NAMED SHEET
182                             NamedSheet();
183                             break;
184                     }
185                 }
186                 else
187                 {
188                     eRet = eERR_FORMAT;
189                     eAkt = S_END;
190                 }
191 			}
192 
193 			break;
194 			// -----------------------------------------------------------
195 			case S_FM3:												// S_FM3
196 			break;
197 			// -----------------------------------------------------------
198 			case S_END:												// S_END
199 			break;
200 		}
201 
202 		DBG_ASSERT( nNextRec >= pIn->Tell(),
203 			"*ImportLotus::Read(): Etwas zu gierig..." );
204 
205 		pIn->Seek( nNextRec );
206 		aPrgrsBar.Progress();
207 	}
208 
209 	// duemmliche Namen eliminieren
210 	SCTAB		nTabs = pD->GetTableCount();
211 	SCTAB		nCnt;
212 	String		aTabName;
213 	String		aBaseName;
214 	String		aRef( RTL_CONSTASCII_USTRINGPARAM( "temp" ) );
215 	if( nTabs != 0 )
216 	{
217 		if( nTabs > 1 )
218 		{
219 			pD->GetName( 0, aBaseName );
220 			aBaseName.Erase( aBaseName.Len() - 1 );
221 		}
222 		for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
223 		{
224 			DBG_ASSERT( pD->HasTable( nCnt ),
225 				"-ImportLotus::Read(): Wo ist meine Tabelle?!" );
226 			pD->GetName( nCnt, aTabName );
227 			if( aTabName == aRef )
228 			{
229 				aTabName = aBaseName;
230 				pD->CreateValidTabName( aTabName );
231 				pD->RenameTab( nCnt, aTabName );
232 			}
233 		}
234 	}
235 
236 	pD->CalcAfterLoad();
237 
238 	return eRet;
239 }
240 
241 
Read(SvStream & rIn)242 FltError ImportLotus::Read( SvStream& rIn )
243 {
244 	pIn = &rIn;
245 
246 	sal_Bool			bRead = sal_True;
247 	sal_uInt16			nOp;
248 	sal_uInt16			nRecLen;
249 	sal_uInt32			nNextRec = 0UL;
250 	FltError		eRet = eERR_OK;
251 
252 	nTab = 0;
253 	nExtTab = -1;
254 
255 	pIn->Seek( nNextRec );
256 
257 	// Progressbar starten
258     ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
259 
260 	while( bRead )
261 	{
262 		*pIn >> nOp >> nRecLen;
263 
264 		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
265 			bRead = sal_False;
266 		else
267 		{
268 			nNextRec += nRecLen + 4;
269 
270 			switch( nOp )
271 			{
272 				case 0x0000:							// BOF
273 				if( nRecLen != 26 || !BofFm3() )
274 				{
275 					bRead = sal_False;
276 					eRet = eERR_FORMAT;
277 				}
278 				break;
279 
280 				case 0x0001:							// EOF
281 					bRead = sal_False;
282 					DBG_ASSERT( nTab == 0,
283 						"-ImportLotus::Read( SvStream& ): Zweimal EOF nicht erlaubt" );
284 					nTab++;
285 				break;
286 
287 				case 174:								// FONT_FACE
288 					Font_Face();
289 				break;
290 
291 				case 176:								// FONT_TYPE
292 					Font_Type();
293 				break;
294 
295 				case 177:								// FONT_YSIZE
296 					Font_Ysize();
297 				break;
298 
299 				case 195:
300 					if( nExtTab >= 0 )
301 						pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
302 					nExtTab++;
303 					break;
304 				case 197:
305 					_Row( nRecLen );
306 				break;
307 			}
308 
309 			DBG_ASSERT( nNextRec >= pIn->Tell(),
310 				"*ImportLotus::Read(): Etwas zu gierig..." );
311 			pIn->Seek( nNextRec );
312 			aPrgrsBar.Progress();
313 		}
314 	}
315 
316 	pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
317 
318 	return eRet;
319 }
320 
321 
322 
323