Bump version to 4.3-4
[LibreOffice.git] / sc / source / filter / lotus / lotread.cxx
blob525ea505b48c037e7d8d3099da3b6da75444d212
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "document.hxx"
22 #include "scerrors.hxx"
23 #include "root.hxx"
24 #include "lotimpop.hxx"
25 #include "lotattr.hxx"
26 #include "fprogressbar.hxx"
29 class ScFormulaCell;
32 FltError ImportLotus::Read()
34 enum STATE
36 S_START, // analyse first BOF
37 S_WK1, // in WK1-Stream
38 S_WK3, // in WK3-Section
39 S_WK4,
40 S_FM3,
41 S_END // Import finished
44 sal_uInt16 nOp;
45 sal_uInt16 nSubType;
46 sal_uInt16 nRecLen;
47 sal_uInt32 nNextRec = 0UL;
48 FltError eRet = eERR_OK;
49 // ScFormulaCell *pLastFormCell;
51 STATE eAkt = S_START;
53 nTab = 0;
54 nExtTab = -2;
56 pIn->Seek( nNextRec );
58 // Progressbar starten
59 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
61 while( eAkt != S_END )
63 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
65 if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
66 eAkt = S_END;
68 nNextRec += nRecLen + 4;
70 switch( eAkt )
73 case S_START: // S_START
74 if( nOp )
76 eRet = SCERR_IMPORT_UNKNOWN_WK;
77 eAkt = S_END;
79 else
81 if( nRecLen > 2 )
83 Bof();
84 switch( pLotusRoot->eFirstType )
86 case Lotus_WK1: eAkt = S_WK1; break;
87 case Lotus_WK3: eAkt = S_WK3; break;
88 case Lotus_WK4: eAkt = S_WK4; break;
89 case Lotus_FM3: eAkt = S_FM3; break;
90 default:
91 eRet = SCERR_IMPORT_UNKNOWN_WK;
92 eAkt = S_END;
95 else
97 eAkt = S_END; // hier kommt wat fuer <= WK1 hinne!
98 eRet = 0xFFFFFFFF;
101 break;
103 case S_WK1: // S_WK1
104 break;
106 case S_WK3: // S_WK3
107 case S_WK4: // S_WK4
108 switch( nOp )
110 case 0x0001: // EOF
111 eAkt = S_FM3;
112 nTab++;
113 break;
115 case 0x0002: // PASSWORD
116 eRet = eERR_FILEPASSWD;
117 eAkt = S_END;
118 break;
120 case 0x0007: // COLUMNWIDTH
121 Columnwidth( nRecLen );
122 break;
124 case 0x0008: // HIDDENCOLUMN
125 Hiddencolumn( nRecLen );
126 break;
128 case 0x0009: // USERRANGE
129 Userrange();
130 break;
132 case 0x0013: // FORMAT
134 break;
135 case 0x0014: // ERRCELL
136 Errcell();
137 break;
139 case 0x0015: // NACELL
140 Nacell();
141 break;
143 case 0x0016: // LABELCELL
144 Labelcell();
145 break;
147 case 0x0017: // NUMBERCELL
148 Numbercell();
149 break;
151 case 0x0018: // SMALLNUMCELL
152 Smallnumcell();
153 break;
155 case 0x0019: // FORMULACELL
156 Formulacell( nRecLen );
157 break;
159 case 0x001b: // extended attributes
160 if (nRecLen > 2)
162 Read( nSubType );
163 nRecLen -= 2;
164 switch( nSubType )
166 case 2007: // ROW PRESENTATION
167 RowPresentation( nRecLen );
168 break;
170 case 14000: // NAMED SHEET
171 NamedSheet();
172 break;
175 else
177 eRet = eERR_FORMAT;
178 eAkt = S_END;
182 break;
184 case S_FM3: // S_FM3
185 break;
187 case S_END: // S_END
188 break;
191 OSL_ENSURE( nNextRec >= pIn->Tell(),
192 "*ImportLotus::Read(): Etwas zu gierig..." );
194 pIn->Seek( nNextRec );
195 aPrgrsBar.Progress();
198 // duemmliche Namen eliminieren
199 SCTAB nTabs = pD->GetTableCount();
200 SCTAB nCnt;
201 OUString aTabName;
202 OUString aBaseName;
203 OUString aRef( "temp" );
204 if( nTabs != 0 )
206 if( nTabs > 1 )
208 pD->GetName( 0, aBaseName );
209 aBaseName = aBaseName.copy(0, aBaseName.getLength()-1);
211 for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
213 OSL_ENSURE( pD->HasTable( nCnt ),
214 "-ImportLotus::Read(): Wo ist meine Tabelle?!" );
215 pD->GetName( nCnt, aTabName );
216 if( aTabName.equals(aRef) )
218 aTabName = aBaseName;
219 pD->CreateValidTabName( aTabName );
220 pD->RenameTab( nCnt, aTabName );
225 pD->CalcAfterLoad();
227 return eRet;
231 FltError ImportLotus::Read( SvStream& rIn )
233 pIn = &rIn;
235 bool bRead = true;
236 sal_uInt16 nOp;
237 sal_uInt16 nRecLen;
238 sal_uInt32 nNextRec = 0UL;
239 FltError eRet = eERR_OK;
241 nTab = 0;
242 nExtTab = -1;
244 pIn->Seek( nNextRec );
246 // Progressbar starten
247 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
249 while( bRead )
251 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
253 if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
254 bRead = false;
255 else
257 nNextRec += nRecLen + 4;
259 switch( nOp )
261 case 0x0000: // BOF
262 if( nRecLen != 26 || !BofFm3() )
264 bRead = false;
265 eRet = eERR_FORMAT;
267 break;
269 case 0x0001: // EOF
270 bRead = false;
271 OSL_ENSURE( nTab == 0,
272 "-ImportLotus::Read( SvStream& ): Zweimal EOF nicht erlaubt" );
273 nTab++;
274 break;
276 case 174: // FONT_FACE
277 Font_Face();
278 break;
280 case 176: // FONT_TYPE
281 Font_Type();
282 break;
284 case 177: // FONT_YSIZE
285 Font_Ysize();
286 break;
288 case 195:
289 if( nExtTab >= 0 )
290 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
291 nExtTab++;
292 break;
293 case 197:
294 _Row( nRecLen );
295 break;
298 OSL_ENSURE( nNextRec >= pIn->Tell(),
299 "*ImportLotus::Read(): Etwas zu gierig..." );
300 pIn->Seek( nNextRec );
301 aPrgrsBar.Progress();
305 pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
307 return eRet;
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */