update dev300-m58
[ooovba.git] / sc / source / filter / lotus / lotread.cxx
blob3321663dd621663e7738d828f48b6834b4ba6e22
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: lotread.cxx,v $
10 * $Revision: 1.8 $
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_sc.hxx"
36 //------------------------------------------------------------------------
38 #include "document.hxx"
40 #include "scerrors.hxx"
41 #include "root.hxx"
42 #include "lotimpop.hxx"
43 #include "lotattr.hxx"
44 #include "fprogressbar.hxx"
47 class ScFormulaCell;
50 FltError ImportLotus::Read()
52 enum STATE
54 S_START, // analyse first BOF
55 S_WK1, // in WK1-Stream
56 S_WK3, // in WK3-Section
57 S_WK4, // ...
58 S_FM3, // ...
59 S_END // Import finished
62 UINT16 nOp;
63 UINT16 nSubType;
64 UINT16 nRecLen;
65 UINT32 nNextRec = 0UL;
66 FltError eRet = eERR_OK;
67 // ScFormulaCell *pLastFormCell;
69 STATE eAkt = S_START;
71 nTab = 0;
72 nExtTab = -2;
74 pIn->Seek( nNextRec );
76 // Progressbar starten
77 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
79 while( eAkt != S_END )
81 *pIn >> nOp >> nRecLen;
83 if( pIn->IsEof() )
84 eAkt = S_END;
86 nNextRec += nRecLen + 4;
88 switch( eAkt )
90 // -----------------------------------------------------------
91 case S_START: // S_START
92 if( nOp )
94 eRet = SCERR_IMPORT_UNKNOWN_WK;
95 eAkt = S_END;
97 else
99 if( nRecLen > 2 )
101 Bof();
102 switch( pLotusRoot->eFirstType )
104 case Lotus_WK1: eAkt = S_WK1; break;
105 case Lotus_WK3: eAkt = S_WK3; break;
106 case Lotus_WK4: eAkt = S_WK4; break;
107 case Lotus_FM3: eAkt = S_FM3; break;
108 default:
109 eRet = SCERR_IMPORT_UNKNOWN_WK;
110 eAkt = S_END;
113 else
115 eAkt = S_END; // hier kommt wat fuer <= WK1 hinne!
116 eRet = 0xFFFFFFFF;
119 break;
120 // -----------------------------------------------------------
121 case S_WK1: // S_WK1
122 break;
123 // -----------------------------------------------------------
124 case S_WK3: // S_WK3
125 case S_WK4: // S_WK4
126 switch( nOp )
128 case 0x0001: // EOF
129 eAkt = S_FM3;
130 nTab++;
131 break;
133 case 0x0002: // PASSWORD
134 eRet = eERR_FILEPASSWD;
135 eAkt = S_END;
136 break;
138 case 0x0007: // COLUMNWIDTH
139 Columnwidth( nRecLen );
140 break;
142 case 0x0008: // HIDDENCOLUMN
143 Hiddencolumn( nRecLen );
144 break;
146 case 0x0009: // USERRANGE
147 Userrange();
148 break;
150 case 0x0013: // FORMAT
152 break;
153 case 0x0014: // ERRCELL
154 Errcell();
155 break;
157 case 0x0015: // NACELL
158 Nacell();
159 break;
161 case 0x0016: // LABELCELL
162 Labelcell();
163 break;
165 case 0x0017: // NUMBERCELL
166 Numbercell();
167 break;
169 case 0x0018: // SMALLNUMCELL
170 Smallnumcell();
171 break;
173 case 0x0019: // FORMULACELL
174 Formulacell( nRecLen );
175 break;
177 case 0x001b: // extended attributes
178 Read( nSubType );
179 nRecLen -= 2;
180 switch( nSubType )
182 case 2007: // ROW PRESENTATION
183 RowPresentation( nRecLen );
184 break;
186 case 14000: // NAMED SHEET
187 NamedSheet();
188 break;
192 break;
193 // -----------------------------------------------------------
194 case S_FM3: // S_FM3
195 break;
196 // -----------------------------------------------------------
197 case S_END: // S_END
198 break;
199 // -----------------------------------------------------------
200 #ifdef DBG_UTIL
201 default:
202 DBG_ERROR( "*ImportLotus::Read(): State unbekannt!" );
203 eAkt = S_END;
204 #endif
207 DBG_ASSERT( nNextRec >= pIn->Tell(),
208 "*ImportLotus::Read(): Etwas zu gierig..." );
210 pIn->Seek( nNextRec );
211 aPrgrsBar.Progress();
214 // duemmliche Namen eliminieren
215 SCTAB nTabs = pD->GetTableCount();
216 SCTAB nCnt;
217 String aTabName;
218 String aBaseName;
219 String aRef( RTL_CONSTASCII_USTRINGPARAM( "temp" ) );
220 if( nTabs != 0 )
222 if( nTabs > 1 )
224 pD->GetName( 0, aBaseName );
225 aBaseName.Erase( aBaseName.Len() - 1 );
227 for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
229 DBG_ASSERT( pD->HasTable( nCnt ),
230 "-ImportLotus::Read(): Wo ist meine Tabelle?!" );
231 pD->GetName( nCnt, aTabName );
232 if( aTabName == aRef )
234 aTabName = aBaseName;
235 pD->CreateValidTabName( aTabName );
236 pD->RenameTab( nCnt, aTabName );
241 pD->CalcAfterLoad();
243 return eRet;
247 FltError ImportLotus::Read( SvStream& rIn )
249 pIn = &rIn;
251 BOOL bRead = TRUE;
252 UINT16 nOp;
253 UINT16 nRecLen;
254 UINT32 nNextRec = 0UL;
255 FltError eRet = eERR_OK;
257 nTab = 0;
258 nExtTab = -1;
260 pIn->Seek( nNextRec );
262 // Progressbar starten
263 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
265 while( bRead )
267 *pIn >> nOp >> nRecLen;
269 if( pIn->IsEof() )
270 bRead = FALSE;
271 else
273 nNextRec += nRecLen + 4;
275 switch( nOp )
277 case 0x0000: // BOF
278 if( nRecLen != 26 || !BofFm3() )
280 bRead = FALSE;
281 eRet = eERR_FORMAT;
283 break;
285 case 0x0001: // EOF
286 bRead = FALSE;
287 DBG_ASSERT( nTab == 0,
288 "-ImportLotus::Read( SvStream& ): Zweimal EOF nicht erlaubt" );
289 nTab++;
290 break;
292 case 174: // FONT_FACE
293 Font_Face();
294 break;
296 case 176: // FONT_TYPE
297 Font_Type();
298 break;
300 case 177: // FONT_YSIZE
301 Font_Ysize();
302 break;
304 case 195:
305 if( nExtTab >= 0 )
306 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
307 nExtTab++;
308 break;
309 case 197:
310 _Row( nRecLen );
311 break;
314 DBG_ASSERT( nNextRec >= pIn->Tell(),
315 "*ImportLotus::Read(): Etwas zu gierig..." );
316 pIn->Seek( nNextRec );
317 aPrgrsBar.Progress();
321 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
323 return eRet;