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>
24 #include <scerrors.hxx>
25 #include "lotfilter.hxx"
26 #include <lotimpop.hxx>
27 #include <lotattr.hxx>
28 #include <fprogressbar.hxx>
30 #include <sal/log.hxx>
32 ErrCode
ImportLotus::parse()
36 S_START
, // analyse first BOF
37 S_WK3
, // in WK3-Section
40 S_END
// Import finished
45 sal_uInt32 nNextRec
= 0;
46 ErrCode eRet
= ERRCODE_NONE
;
47 // ScFormulaCell *pLastFormCell;
49 STATE eCurrent
= S_START
;
54 pIn
->Seek( nNextRec
);
57 ScfStreamProgressBar
aPrgrsBar( *pIn
, rD
.GetDocumentShell() );
58 LotusContext
&rContext
= aConv
.getContext();
59 while( eCurrent
!= S_END
)
61 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
63 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
65 eRet
= SCERR_IMPORT_FORMAT
;
71 nNextRec
+= nRecLen
+ 4;
76 case S_START
: // S_START
79 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
87 switch (rContext
.eFirstType
)
89 case Lotus123Typ::WK3
: eCurrent
= S_WK3
; break;
90 case Lotus123Typ::WK4
: eCurrent
= S_WK4
; break;
92 eRet
= SCERR_IMPORT_UNKNOWN_WK
;
98 eCurrent
= S_END
; // TODO: add here something for <= WK1!
99 eRet
= ErrCode(0xFFFFFFFF);
113 case 0x0002: // PASSWORD
114 eRet
= SCERR_IMPORT_FILEPASSWD
;
118 case 0x0007: // COLUMNWIDTH
119 Columnwidth( nRecLen
);
122 case 0x0008: // HIDDENCOLUMN
123 Hiddencolumn( nRecLen
);
126 case 0x0009: // USERRANGE
130 case 0x0013: // FORMAT
133 case 0x0014: // ERRCELL
137 case 0x0015: // NACELL
141 case 0x0016: // LABELCELL
145 case 0x0017: // NUMBERCELL
149 case 0x0018: // SMALLNUMCELL
153 case 0x0019: // FORMULACELL
154 Formulacell( nRecLen
);
157 case 0x001b: // extended attributes
160 sal_uInt16
nSubType(0);
165 case 2007: // ROW PRESENTATION
166 RowPresentation( nRecLen
);
169 case 14000: // NAMED SHEET
176 eRet
= SCERR_IMPORT_FORMAT
;
190 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
191 "*ImportLotus::Read(): Read too much..." );
193 pIn
->Seek( nNextRec
);
194 aPrgrsBar
.Progress();
197 // TODO: eliminate stupid names
198 SCTAB nTabs
= rD
.GetTableCount();
206 rD
.GetName( 0, aBaseName
);
207 aBaseName
= aBaseName
.copy(0, aBaseName
.getLength()-1);
209 for( nCnt
= 1 ; nCnt
< nTabs
; nCnt
++ )
211 SAL_WARN_IF( !rD
.HasTable( nCnt
), "sc.filter",
212 "-ImportLotus::Read(): Where is my table?!" );
213 rD
.GetName( nCnt
, aTabName
);
214 if( aTabName
== "temp" )
216 aTabName
= aBaseName
;
217 rD
.CreateValidTabName( aTabName
);
218 rD
.RenameTab( nCnt
, aTabName
);
226 ErrCode
ImportLotus::Read()
228 ErrCode eRet
= parse();
233 ErrCode
ImportLotus::Read(SvStream
& rIn
)
240 sal_uInt32 nNextRec
= 0;
241 ErrCode eRet
= ERRCODE_NONE
;
246 pIn
->Seek( nNextRec
);
249 ScfStreamProgressBar
aPrgrsBar( *pIn
, rD
.GetDocumentShell() );
250 LotusContext
&rContext
= aConv
.getContext();
253 pIn
->ReadUInt16( nOp
).ReadUInt16( nRecLen
);
255 if (!pIn
->good() || nNextRec
> SAL_MAX_UINT32
- nRecLen
- 4)
259 nNextRec
+= nRecLen
+ 4;
264 if( nRecLen
!= 26 || !BofFm3() )
267 eRet
= SCERR_IMPORT_FORMAT
;
273 SAL_WARN_IF( nTab
!= 0, "sc.filter",
274 "-ImportLotus::Read( SvStream& ): EOF twice!" );
278 case 174: // FONT_FACE
282 case 176: // FONT_TYPE
286 case 177: // FONT_YSIZE
292 rContext
.maAttrTable
.Apply(rContext
, static_cast<SCTAB
>(nExtTab
));
300 SAL_WARN_IF( nNextRec
< pIn
->Tell(), "sc.filter",
301 "*ImportLotus::Read(): Read too much..." );
302 pIn
->Seek( nNextRec
);
303 aPrgrsBar
.Progress();
307 rContext
.maAttrTable
.Apply(rContext
, static_cast<SCTAB
>(nExtTab
));
312 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportWKS(SvStream
& rStream
)
315 ScDocument aDocument
;
316 ScDocOptions aDocOpt
= aDocument
.GetDocOptions();
317 aDocOpt
.SetLookUpColRowNames(false);
318 aDocument
.SetDocOptions(aDocOpt
);
319 aDocument
.MakeTable(0);
320 aDocument
.EnableExecuteLink(false);
321 aDocument
.SetInsertingFromOtherDoc(true);
323 LotusContext
aContext(aDocument
, RTL_TEXTENCODING_ASCII_US
);
324 ImportLotus
aLotusImport(aContext
, rStream
, RTL_TEXTENCODING_ASCII_US
);
326 ErrCode eRet
= aLotusImport
.parse();
327 if (eRet
== ErrCode(0xFFFFFFFF))
330 eRet
= ScImportLotus123old(aContext
, rStream
, RTL_TEXTENCODING_ASCII_US
);
333 return eRet
== ERRCODE_NONE
;
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */