1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
21 #include <docoptio.hxx>
25 #include <scerrors.hxx>
26 #include "lotfilter.hxx"
27 #include <lotimpop.hxx>
28 #include <lotattr.hxx>
29 #include <fprogressbar.hxx>
31 #include <sal/log.hxx>
33 ErrCode
ImportLotus::parse()
37 S_START
, // analyse first BOF
38 S_WK3
, // in WK3-Section
41 S_END
// Import finished
46 sal_uInt32 nNextRec
= 0;
47 ErrCode eRet
= ERRCODE_NONE
;
48 // ScFormulaCell *pLastFormCell;
50 STATE eCurrent
= S_START
;
55 pIn
->Seek( nNextRec
);
58 ScfStreamProgressBar
aPrgrsBar( *pIn
, rD
.GetDocumentShell() );
59 LotusContext
&rContext
= aConv
.getContext();
60 while( eCurrent
!= S_END
)
62 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
64 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
66 eRet
= SCERR_IMPORT_FORMAT
;
72 nNextRec
+= nRecLen
+ 4;
77 case S_START
: // S_START
80 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
88 switch (rContext
.eFirstType
)
90 case Lotus123Typ::WK3
: eCurrent
= S_WK3
; break;
91 case Lotus123Typ::WK4
: eCurrent
= S_WK4
; break;
93 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
99 eCurrent
= S_END
; // TODO: add here something for <= WK1!
100 eRet
= ErrCode(0xFFFFFFFF);
114 case 0x0002: // PASSWORD
115 eRet
= SCERR_IMPORT_FILEPASSWD
;
119 case 0x0007: // COLUMNWIDTH
120 Columnwidth( nRecLen
);
123 case 0x0008: // HIDDENCOLUMN
124 Hiddencolumn( nRecLen
);
127 case 0x0009: // USERRANGE
131 case 0x0013: // FORMAT
134 case 0x0014: // ERRCELL
138 case 0x0015: // NACELL
142 case 0x0016: // LABELCELL
146 case 0x0017: // NUMBERCELL
150 case 0x0018: // SMALLNUMCELL
154 case 0x0019: // FORMULACELL
155 Formulacell( nRecLen
);
158 case 0x001b: // extended attributes
161 sal_uInt16
nSubType(0);
166 case 2007: // ROW PRESENTATION
167 RowPresentation( nRecLen
);
170 case 14000: // NAMED SHEET
177 eRet
= SCERR_IMPORT_FORMAT
;
191 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
192 "*ImportLotus::Read(): Read too much..." );
194 pIn
->Seek( nNextRec
);
195 aPrgrsBar
.Progress();
198 // TODO: eliminate stupid names
199 SCTAB nTabs
= rD
.GetTableCount();
207 rD
.GetName( 0, aBaseName
);
208 aBaseName
= aBaseName
.copy(0, aBaseName
.getLength()-1);
210 for( nCnt
= 1 ; nCnt
< nTabs
; nCnt
++ )
212 SAL_WARN_IF( !rD
.HasTable( nCnt
), "sc.filter",
213 "-ImportLotus::Read(): Where is my table?!" );
214 rD
.GetName( nCnt
, aTabName
);
215 if( aTabName
== "temp" )
217 aTabName
= aBaseName
;
218 rD
.CreateValidTabName( aTabName
);
219 rD
.RenameTab( nCnt
, aTabName
);
227 ErrCode
ImportLotus::Read()
229 ErrCode eRet
= parse();
234 ErrCode
ImportLotus::Read(SvStream
& rIn
)
241 sal_uInt32 nNextRec
= 0;
242 ErrCode eRet
= ERRCODE_NONE
;
247 pIn
->Seek( nNextRec
);
250 ScfStreamProgressBar
aPrgrsBar( *pIn
, rD
.GetDocumentShell() );
251 LotusContext
&rContext
= aConv
.getContext();
254 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
256 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
260 nNextRec
+= nRecLen
+ 4;
265 if( nRecLen
!= 26 || !BofFm3() )
268 eRet
= SCERR_IMPORT_FORMAT
;
274 SAL_WARN_IF( nTab
!= 0, "sc.filter",
275 "-ImportLotus::Read( SvStream& ): EOF twice!" );
279 case 174: // FONT_FACE
283 case 176: // FONT_TYPE
287 case 177: // FONT_YSIZE
293 rContext
.maAttrTable
.Apply(rContext
, static_cast<SCTAB
>(nExtTab
));
301 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
302 "*ImportLotus::Read(): Read too much..." );
303 pIn
->Seek( nNextRec
);
304 aPrgrsBar
.Progress();
308 rContext
.maAttrTable
.Apply(rContext
, static_cast<SCTAB
>(nExtTab
));
313 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportWKS(SvStream
& rStream
)
316 ScDocument aDocument
;
317 ScDocOptions aDocOpt
= aDocument
.GetDocOptions();
318 aDocOpt
.SetLookUpColRowNames(false);
319 aDocument
.SetDocOptions(aDocOpt
);
320 aDocument
.MakeTable(0);
321 aDocument
.EnableExecuteLink(false);
322 aDocument
.SetInsertingFromOtherDoc(true);
324 LotusContext
aContext(aDocument
, RTL_TEXTENCODING_ASCII_US
);
325 ImportLotus
aLotusImport(aContext
, rStream
, RTL_TEXTENCODING_ASCII_US
);
327 ErrCode eRet
= aLotusImport
.parse();
328 if (eRet
== ErrCode(0xFFFFFFFF))
331 eRet
= ScImportLotus123old(aContext
, rStream
, RTL_TEXTENCODING_ASCII_US
);
334 return eRet
== ERRCODE_NONE
;
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */