fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / lotus / lotread.cxx
bloba75dc992c2aabfa38f7299efb45b680744c9c485
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 "lotfilter.hxx"
25 #include "lotimpop.hxx"
26 #include "lotattr.hxx"
27 #include "fprogressbar.hxx"
29 class ScFormulaCell;
31 FltError ImportLotus::Read()
33 enum STATE
35 S_START, // analyse first BOF
36 S_WK1, // in WK1-Stream
37 S_WK3, // in WK3-Section
38 S_WK4,
39 S_FM3,
40 S_END // Import finished
43 sal_uInt16 nOp;
44 sal_uInt16 nSubType;
45 sal_uInt16 nRecLen;
46 sal_uInt32 nNextRec = 0UL;
47 FltError eRet = eERR_OK;
48 // ScFormulaCell *pLastFormCell;
50 STATE eAkt = S_START;
52 nTab = 0;
53 nExtTab = -2;
55 pIn->Seek( nNextRec );
57 // start progressbar
58 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
59 LotusContext &rContext = aConv.getContext();
60 while( eAkt != S_END )
62 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
64 if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
65 eAkt = S_END;
67 nNextRec += nRecLen + 4;
69 switch( eAkt )
72 case S_START: // S_START
73 if( nOp )
75 eRet = SCERR_IMPORT_UNKNOWN_WK;
76 eAkt = S_END;
78 else
80 if( nRecLen > 2 )
82 Bof();
83 switch (rContext.pLotusRoot->eFirstType)
85 case Lotus_WK1: eAkt = S_WK1; break;
86 case Lotus_WK3: eAkt = S_WK3; break;
87 case Lotus_WK4: eAkt = S_WK4; break;
88 case Lotus_FM3: eAkt = S_FM3; break;
89 default:
90 eRet = SCERR_IMPORT_UNKNOWN_WK;
91 eAkt = S_END;
94 else
96 eAkt = S_END; // TODO: add here something for <= WK1!
97 eRet = 0xFFFFFFFF;
100 break;
102 case S_WK1: // S_WK1
103 break;
105 case S_WK3: // S_WK3
106 case S_WK4: // S_WK4
107 switch( nOp )
109 case 0x0001: // EOF
110 eAkt = S_FM3;
111 nTab++;
112 break;
114 case 0x0002: // PASSWORD
115 eRet = eERR_FILEPASSWD;
116 eAkt = S_END;
117 break;
119 case 0x0007: // COLUMNWIDTH
120 Columnwidth( nRecLen );
121 break;
123 case 0x0008: // HIDDENCOLUMN
124 Hiddencolumn( nRecLen );
125 break;
127 case 0x0009: // USERRANGE
128 Userrange();
129 break;
131 case 0x0013: // FORMAT
133 break;
134 case 0x0014: // ERRCELL
135 Errcell();
136 break;
138 case 0x0015: // NACELL
139 Nacell();
140 break;
142 case 0x0016: // LABELCELL
143 Labelcell();
144 break;
146 case 0x0017: // NUMBERCELL
147 Numbercell();
148 break;
150 case 0x0018: // SMALLNUMCELL
151 Smallnumcell();
152 break;
154 case 0x0019: // FORMULACELL
155 Formulacell( nRecLen );
156 break;
158 case 0x001b: // extended attributes
159 if (nRecLen > 2)
161 Read( nSubType );
162 nRecLen -= 2;
163 switch( nSubType )
165 case 2007: // ROW PRESENTATION
166 RowPresentation( nRecLen );
167 break;
169 case 14000: // NAMED SHEET
170 NamedSheet();
171 break;
174 else
176 eRet = eERR_FORMAT;
177 eAkt = S_END;
181 break;
183 case S_FM3: // S_FM3
184 break;
186 case S_END: // S_END
187 break;
190 OSL_ENSURE( nNextRec >= pIn->Tell(),
191 "*ImportLotus::Read(): Read too much..." );
193 pIn->Seek( nNextRec );
194 aPrgrsBar.Progress();
197 // TODO: eliminate stupid names
198 SCTAB nTabs = pD->GetTableCount();
199 SCTAB nCnt;
200 OUString aTabName;
201 OUString aBaseName;
202 OUString aRef( "temp" );
203 if( nTabs != 0 )
205 if( nTabs > 1 )
207 pD->GetName( 0, aBaseName );
208 aBaseName = aBaseName.copy(0, aBaseName.getLength()-1);
210 for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
212 OSL_ENSURE( pD->HasTable( nCnt ),
213 "-ImportLotus::Read(): Where is my table?!" );
214 pD->GetName( nCnt, aTabName );
215 if( aTabName.equals(aRef) )
217 aTabName = aBaseName;
218 pD->CreateValidTabName( aTabName );
219 pD->RenameTab( nCnt, aTabName );
224 pD->CalcAfterLoad();
226 return eRet;
229 FltError ImportLotus::Read(SvStream& rIn)
231 pIn = &rIn;
233 bool bRead = true;
234 sal_uInt16 nOp;
235 sal_uInt16 nRecLen;
236 sal_uInt32 nNextRec = 0UL;
237 FltError eRet = eERR_OK;
239 nTab = 0;
240 nExtTab = -1;
242 pIn->Seek( nNextRec );
244 // start progressbar
245 ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
246 LotusContext &rContext = aConv.getContext();
247 while( bRead )
249 pIn->ReadUInt16( nOp ).ReadUInt16( nRecLen );
251 if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
252 bRead = false;
253 else
255 nNextRec += nRecLen + 4;
257 switch( nOp )
259 case 0x0000: // BOF
260 if( nRecLen != 26 || !BofFm3() )
262 bRead = false;
263 eRet = eERR_FORMAT;
265 break;
267 case 0x0001: // EOF
268 bRead = false;
269 OSL_ENSURE( nTab == 0,
270 "-ImportLotus::Read( SvStream& ): EOF twice!" );
271 nTab++;
272 break;
274 case 174: // FONT_FACE
275 Font_Face();
276 break;
278 case 176: // FONT_TYPE
279 Font_Type();
280 break;
282 case 177: // FONT_YSIZE
283 Font_Ysize();
284 break;
286 case 195:
287 if( nExtTab >= 0 )
288 rContext.pLotusRoot->pAttrTable->Apply(rContext.pLotusRoot, (SCTAB)nExtTab);
289 nExtTab++;
290 break;
291 case 197:
292 _Row( nRecLen );
293 break;
296 OSL_ENSURE( nNextRec >= pIn->Tell(),
297 "*ImportLotus::Read(): Read too much..." );
298 pIn->Seek( nNextRec );
299 aPrgrsBar.Progress();
303 rContext.pLotusRoot->pAttrTable->Apply(rContext.pLotusRoot, (SCTAB)nExtTab);
305 return eRet;
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */