merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / lotus / filter.cxx
blob3d864c2960c4589722acf880b5a19f5704546ad9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filter.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 // Das geht: Versionserkennung WKS, WK1 und WK3
34 // ...Rest steht in op.cpp
36 //------------------------------------------------------------------------
38 #include <tools/solar.h>
39 #include <string.h>
40 #include <map>
42 #include "filter.hxx"
43 #include "document.hxx"
44 #include "compiler.hxx"
45 #include "scerrors.hxx"
47 #include "root.hxx"
48 #include "lotrange.hxx"
49 #include "optab.h"
50 #include "scmem.h"
51 #include "decl.h"
52 #include "tool.h"
54 #include "fprogressbar.hxx"
56 #include "op.h"
58 // Konstanten ------------------------------------------------------------
59 const UINT16 nBOF = 0x0000;
63 // externe Variablen -----------------------------------------------------
64 extern WKTYP eTyp; // Typ der gerade in bearbeitung befindlichen Datei
65 WKTYP eTyp;
67 extern BOOL bEOF; // zeigt Ende der Datei
68 BOOL bEOF;
70 extern CharSet eCharNach; // Zeichenkonvertierung von->nach
71 CharSet eCharNach;
73 extern CharSet eCharVon;
74 CharSet eCharVon;
76 extern ScDocument* pDoc; // Aufhaenger zum Dokumentzugriff
77 ScDocument* pDoc;
80 extern sal_Char* pPuffer; // -> memory.cxx
81 extern sal_Char* pDummy1; // -> memory.cxx
83 extern OPCODE_FKT pOpFkt[ FKT_LIMIT ];
84 // -> optab.cxx, Tabelle moeglicher Opcodes
85 extern OPCODE_FKT pOpFkt123[ FKT_LIMIT123 ];
86 // -> optab.cxx, Table of possible Opcodes
88 extern long nDateiLaenge; // -> datei.cpp, ...der gerade offenen Datei
90 LOTUS_ROOT* pLotusRoot = NULL;
93 std::map<UINT16, ScPatternAttr> aLotusPatternPool;
95 static FltError
96 generate_Opcodes( SvStream& aStream, ScDocument& rDoc,
97 ScfStreamProgressBar& aPrgrsBar, WKTYP eType )
99 OPCODE_FKT *pOps;
100 int nOps;
102 switch(eType)
104 case eWK_1:
105 case eWK_2:
106 pOps = pOpFkt;
107 nOps = FKT_LIMIT;
108 break;
109 case eWK123:
110 pOps = pOpFkt123;
111 nOps = FKT_LIMIT123;
112 break;
113 case eWK3: return eERR_NI;
114 case eWK_Error: return eERR_FORMAT;
115 default: return eERR_UNKN_WK;
118 // #i76299# seems that SvStream::IsEof() does not work correctly
119 aStream.Seek( STREAM_SEEK_TO_END );
120 sal_Size nStrmSize = aStream.Tell();
121 aStream.Seek( STREAM_SEEK_TO_BEGIN );
122 while( !bEOF && !aStream.IsEof() && (aStream.Tell() < nStrmSize) )
124 UINT16 nOpcode, nLength;
126 aStream >> nOpcode >> nLength;
127 aPrgrsBar.Progress();
128 if( nOpcode == LOTUS_EOF )
129 bEOF = TRUE;
131 else if( nOpcode == LOTUS_FILEPASSWD )
132 return eERR_FILEPASSWD;
134 else if( nOpcode < nOps )
135 pOps[ nOpcode ] ( aStream, nLength );
137 else if( eType == eWK123 &&
138 nOpcode == LOTUS_PATTERN )
140 // This is really ugly - needs re-factoring ...
141 aStream.SeekRel(nLength);
142 aStream >> nOpcode >> nLength;
143 if ( nOpcode == 0x29a)
145 aStream.SeekRel(nLength);
146 aStream >> nOpcode >> nLength;
147 if ( nOpcode == 0x804 )
149 aStream.SeekRel(nLength);
150 OP_ApplyPatternArea123(aStream);
152 else
153 aStream.SeekRel(nLength);
155 else
156 aStream.SeekRel(nLength);
158 else
159 aStream.SeekRel( nLength );
162 MemDelete();
164 rDoc.CalcAfterLoad();
166 return eERR_OK;
169 WKTYP ScanVersion( SvStream& aStream )
171 // PREC: pWKDatei: Zeiger auf offene Datei
172 // POST: return: Typ der Datei
173 UINT16 nOpcode, nVersNr, nRecLen;
175 // erstes Byte muss wegen BOF zwingend 0 sein!
176 aStream >> nOpcode;
177 if( nOpcode != nBOF )
178 return eWK_UNKNOWN;
180 aStream >> nRecLen >> nVersNr;
182 if( aStream.IsEof() )
183 return eWK_Error;
185 switch( nVersNr )
187 case 0x0404:
188 if( nRecLen == 2 )
189 return eWK_1;
190 else
191 return eWK_UNKNOWN;
193 case 0x0406:
194 if( nRecLen == 2 )
195 return eWK_2;
196 else
197 return eWK_UNKNOWN;
199 case 0x1000:
200 aStream >> nVersNr;
201 if( aStream.IsEof() ) return eWK_Error;
202 if( nVersNr == 0x0004 && nRecLen == 26 )
203 { // 4 Bytes von 26 gelesen->22 ueberlesen
204 aStream.Read( pDummy1, 22 );
205 return eWK3;
207 break;
208 case 0x1003:
209 if( nRecLen == 0x1a )
210 return eWK123;
211 else
212 return eWK_UNKNOWN;
213 case 0x1005:
214 if( nRecLen == 0x1a )
215 return eWK123;
216 else
217 return eWK_UNKNOWN;
220 return eWK_UNKNOWN;
223 FltError ScImportLotus123old( SvStream& aStream, ScDocument* pDocument, CharSet eSrc )
225 aStream.Seek( 0UL );
227 // Zeiger auf Dokument global machen
228 pDoc = pDocument;
230 bEOF = FALSE;
232 eCharVon = eSrc;
234 // Speicher besorgen
235 if( !MemNew() )
236 return eERR_NOMEM;
238 InitPage(); // Seitenformat initialisieren (nur Tab 0!)
240 // Progressbar starten
241 ScfStreamProgressBar aPrgrsBar( aStream, pDocument->GetDocumentShell() );
243 // Datei-Typ ermitteln
244 eTyp = ScanVersion( aStream );
246 aLotusPatternPool.clear();
248 return generate_Opcodes( aStream, *pDoc, aPrgrsBar, eTyp );