merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / lotus / lotread.cxx
blob917337fa91d50957a900e392b61119b386a4658f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
33 //------------------------------------------------------------------------
35 #include "document.hxx"
37 #include "scerrors.hxx"
38 #include "root.hxx"
39 #include "lotimpop.hxx"
40 #include "lotattr.hxx"
41 #include "fprogressbar.hxx"
44 class ScFormulaCell;
47 FltError ImportLotus::Read()
49 enum STATE
51 S_START, // analyse first BOF
52 S_WK1, // in WK1-Stream
53 S_WK3, // in WK3-Section
54 S_WK4, // ...
55 S_FM3, // ...
56 S_END // Import finished
59 UINT16 nOp;
60 UINT16 nSubType;
61 UINT16 nRecLen;
62 UINT32 nNextRec = 0UL;
63 FltError eRet = eERR_OK;
64 // ScFormulaCell *pLastFormCell;
66 STATE eAkt = S_START;
68 nTab = 0;
69 nExtTab = -2;
71 pIn->Seek( nNextRec );
73 // Progressbar starten
74 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
76 while( eAkt != S_END )
78 *pIn >> nOp >> nRecLen;
80 if( pIn->IsEof() )
81 eAkt = S_END;
83 nNextRec += nRecLen + 4;
85 switch( eAkt )
87 // -----------------------------------------------------------
88 case S_START: // S_START
89 if( nOp )
91 eRet = SCERR_IMPORT_UNKNOWN_WK;
92 eAkt = S_END;
94 else
96 if( nRecLen > 2 )
98 Bof();
99 switch( pLotusRoot->eFirstType )
101 case Lotus_WK1: eAkt = S_WK1; break;
102 case Lotus_WK3: eAkt = S_WK3; break;
103 case Lotus_WK4: eAkt = S_WK4; break;
104 case Lotus_FM3: eAkt = S_FM3; break;
105 default:
106 eRet = SCERR_IMPORT_UNKNOWN_WK;
107 eAkt = S_END;
110 else
112 eAkt = S_END; // hier kommt wat fuer <= WK1 hinne!
113 eRet = 0xFFFFFFFF;
116 break;
117 // -----------------------------------------------------------
118 case S_WK1: // S_WK1
119 break;
120 // -----------------------------------------------------------
121 case S_WK3: // S_WK3
122 case S_WK4: // S_WK4
123 switch( nOp )
125 case 0x0001: // EOF
126 eAkt = S_FM3;
127 nTab++;
128 break;
130 case 0x0002: // PASSWORD
131 eRet = eERR_FILEPASSWD;
132 eAkt = S_END;
133 break;
135 case 0x0007: // COLUMNWIDTH
136 Columnwidth( nRecLen );
137 break;
139 case 0x0008: // HIDDENCOLUMN
140 Hiddencolumn( nRecLen );
141 break;
143 case 0x0009: // USERRANGE
144 Userrange();
145 break;
147 case 0x0013: // FORMAT
149 break;
150 case 0x0014: // ERRCELL
151 Errcell();
152 break;
154 case 0x0015: // NACELL
155 Nacell();
156 break;
158 case 0x0016: // LABELCELL
159 Labelcell();
160 break;
162 case 0x0017: // NUMBERCELL
163 Numbercell();
164 break;
166 case 0x0018: // SMALLNUMCELL
167 Smallnumcell();
168 break;
170 case 0x0019: // FORMULACELL
171 Formulacell( nRecLen );
172 break;
174 case 0x001b: // extended attributes
175 Read( nSubType );
176 nRecLen -= 2;
177 switch( nSubType )
179 case 2007: // ROW PRESENTATION
180 RowPresentation( nRecLen );
181 break;
183 case 14000: // NAMED SHEET
184 NamedSheet();
185 break;
189 break;
190 // -----------------------------------------------------------
191 case S_FM3: // S_FM3
192 break;
193 // -----------------------------------------------------------
194 case S_END: // S_END
195 break;
196 // -----------------------------------------------------------
197 #ifdef DBG_UTIL
198 default:
199 DBG_ERROR( "*ImportLotus::Read(): State unbekannt!" );
200 eAkt = S_END;
201 #endif
204 DBG_ASSERT( nNextRec >= pIn->Tell(),
205 "*ImportLotus::Read(): Etwas zu gierig..." );
207 pIn->Seek( nNextRec );
208 aPrgrsBar.Progress();
211 // duemmliche Namen eliminieren
212 SCTAB nTabs = pD->GetTableCount();
213 SCTAB nCnt;
214 String aTabName;
215 String aBaseName;
216 String aRef( RTL_CONSTASCII_USTRINGPARAM( "temp" ) );
217 if( nTabs != 0 )
219 if( nTabs > 1 )
221 pD->GetName( 0, aBaseName );
222 aBaseName.Erase( aBaseName.Len() - 1 );
224 for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
226 DBG_ASSERT( pD->HasTable( nCnt ),
227 "-ImportLotus::Read(): Wo ist meine Tabelle?!" );
228 pD->GetName( nCnt, aTabName );
229 if( aTabName == aRef )
231 aTabName = aBaseName;
232 pD->CreateValidTabName( aTabName );
233 pD->RenameTab( nCnt, aTabName );
238 pD->CalcAfterLoad();
240 return eRet;
244 FltError ImportLotus::Read( SvStream& rIn )
246 pIn = &rIn;
248 BOOL bRead = TRUE;
249 UINT16 nOp;
250 UINT16 nRecLen;
251 UINT32 nNextRec = 0UL;
252 FltError eRet = eERR_OK;
254 nTab = 0;
255 nExtTab = -1;
257 pIn->Seek( nNextRec );
259 // Progressbar starten
260 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
262 while( bRead )
264 *pIn >> nOp >> nRecLen;
266 if( pIn->IsEof() )
267 bRead = FALSE;
268 else
270 nNextRec += nRecLen + 4;
272 switch( nOp )
274 case 0x0000: // BOF
275 if( nRecLen != 26 || !BofFm3() )
277 bRead = FALSE;
278 eRet = eERR_FORMAT;
280 break;
282 case 0x0001: // EOF
283 bRead = FALSE;
284 DBG_ASSERT( nTab == 0,
285 "-ImportLotus::Read( SvStream& ): Zweimal EOF nicht erlaubt" );
286 nTab++;
287 break;
289 case 174: // FONT_FACE
290 Font_Face();
291 break;
293 case 176: // FONT_TYPE
294 Font_Type();
295 break;
297 case 177: // FONT_YSIZE
298 Font_Ysize();
299 break;
301 case 195:
302 if( nExtTab >= 0 )
303 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
304 nExtTab++;
305 break;
306 case 197:
307 _Row( nRecLen );
308 break;
311 DBG_ASSERT( nNextRec >= pIn->Tell(),
312 "*ImportLotus::Read(): Etwas zu gierig..." );
313 pIn->Seek( nNextRec );
314 aPrgrsBar.Progress();
318 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
320 return eRet;