1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filter.cxx,v $
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>
43 #include "document.hxx"
44 #include "compiler.hxx"
45 #include "scerrors.hxx"
48 #include "lotrange.hxx"
54 #include "fprogressbar.hxx"
58 // Konstanten ------------------------------------------------------------
59 const UINT16 nBOF
= 0x0000;
63 // externe Variablen -----------------------------------------------------
64 extern WKTYP eTyp
; // Typ der gerade in bearbeitung befindlichen Datei
67 extern BOOL bEOF
; // zeigt Ende der Datei
70 extern CharSet eCharNach
; // Zeichenkonvertierung von->nach
73 extern CharSet eCharVon
;
76 extern ScDocument
* pDoc
; // Aufhaenger zum Dokumentzugriff
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
;
96 generate_Opcodes( SvStream
& aStream
, ScDocument
& rDoc
,
97 ScfStreamProgressBar
& aPrgrsBar
, WKTYP eType
)
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
)
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
);
153 aStream
.SeekRel(nLength
);
156 aStream
.SeekRel(nLength
);
159 aStream
.SeekRel( nLength
);
164 rDoc
.CalcAfterLoad();
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!
177 if( nOpcode
!= nBOF
)
180 aStream
>> nRecLen
>> nVersNr
;
182 if( aStream
.IsEof() )
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 );
209 if( nRecLen
== 0x1a )
214 if( nRecLen
== 0x1a )
223 FltError
ScImportLotus123old( SvStream
& aStream
, ScDocument
* pDocument
, CharSet eSrc
)
227 // Zeiger auf Dokument global machen
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
);