1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <tools/solar.h>
30cdf0e10cSrcweir #include <rtl/math.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <stdio.h>
33cdf0e10cSrcweir #include <string.h>
34cdf0e10cSrcweir #include <math.h>
35cdf0e10cSrcweir #include <ctype.h>
36cdf0e10cSrcweir #include <stdlib.h>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "scitems.hxx"
39cdf0e10cSrcweir #include "patattr.hxx"
40cdf0e10cSrcweir #include "docpool.hxx"
41cdf0e10cSrcweir #include <svx/algitem.hxx>
42cdf0e10cSrcweir #include <editeng/postitem.hxx>
43cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
44cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include "cell.hxx"
47cdf0e10cSrcweir #include "rangenam.hxx"
48cdf0e10cSrcweir #include "document.hxx"
49cdf0e10cSrcweir #include "postit.hxx"
50cdf0e10cSrcweir
51cdf0e10cSrcweir #include "op.h"
52cdf0e10cSrcweir #include "optab.h"
53cdf0e10cSrcweir #include "tool.h"
54cdf0e10cSrcweir #include "decl.h"
55cdf0e10cSrcweir #include "lotform.hxx"
56cdf0e10cSrcweir #include "lotrange.hxx"
57cdf0e10cSrcweir
58cdf0e10cSrcweir #include "root.hxx"
59cdf0e10cSrcweir
60cdf0e10cSrcweir #include "ftools.hxx"
61cdf0e10cSrcweir
62cdf0e10cSrcweir #include <vector>
63cdf0e10cSrcweir #include <map>
64cdf0e10cSrcweir
65cdf0e10cSrcweir extern WKTYP eTyp; // -> filter.cxx, aktueller Dateityp
66cdf0e10cSrcweir extern sal_Bool bEOF; // -> filter.cxx, zeigt Dateiende an
67cdf0e10cSrcweir extern sal_uInt8 nDefaultFormat; // -> tool.cxx, Default-Zellenformat
68cdf0e10cSrcweir extern ScDocument* pDoc; // -> filter.cxx, Aufhaenger zum Dokumentzugriff
69cdf0e10cSrcweir extern CharSet eCharVon; // -> filter.cxx, character set specified
70cdf0e10cSrcweir
71cdf0e10cSrcweir static sal_uInt16 nDefWidth = ( sal_uInt16 ) ( TWIPS_PER_CHAR * 10 );
72cdf0e10cSrcweir
73cdf0e10cSrcweir extern std::map<sal_uInt16, ScPatternAttr> aLotusPatternPool;
74cdf0e10cSrcweir
NI(SvStream & r,sal_uInt16 n)75cdf0e10cSrcweir void NI( SvStream& r, sal_uInt16 n )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir r.SeekRel( n );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir
OP_BOF(SvStream & r,sal_uInt16)81cdf0e10cSrcweir void OP_BOF( SvStream& r, sal_uInt16 /*n*/ )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir r.SeekRel( 2 ); // Versionsnummer ueberlesen
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir
OP_EOF(SvStream &,sal_uInt16)87cdf0e10cSrcweir void OP_EOF( SvStream& /*r*/, sal_uInt16 /*n*/ )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir bEOF = sal_True;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir
OP_Integer(SvStream & r,sal_uInt16)93cdf0e10cSrcweir void OP_Integer( SvStream& r, sal_uInt16 /*n*/ )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir sal_uInt8 nFormat;
96cdf0e10cSrcweir sal_uInt16 nCol, nRow;
97cdf0e10cSrcweir SCTAB nTab = 0;
98cdf0e10cSrcweir sal_Int16 nValue;
99cdf0e10cSrcweir
100cdf0e10cSrcweir r >> nFormat >> nCol >> nRow >> nValue;
101cdf0e10cSrcweir
102*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
103*3ee7c2dbSArmin Le Grand {
104*3ee7c2dbSArmin Le Grand ScValueCell* pZelle = new ScValueCell( ( double ) nValue );
105*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
106cdf0e10cSrcweir
107*3ee7c2dbSArmin Le Grand // 0 Stellen nach'm Komma!
108*3ee7c2dbSArmin Le Grand SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, 0 );
109*3ee7c2dbSArmin Le Grand }
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
112cdf0e10cSrcweir
OP_Number(SvStream & r,sal_uInt16)113cdf0e10cSrcweir void OP_Number( SvStream& r, sal_uInt16 /*n*/ )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir sal_uInt8 nFormat;
116cdf0e10cSrcweir sal_uInt16 nCol, nRow;
117cdf0e10cSrcweir SCTAB nTab = 0;
118cdf0e10cSrcweir double fValue;
119cdf0e10cSrcweir
120cdf0e10cSrcweir r >> nFormat >> nCol >> nRow >> fValue;
121cdf0e10cSrcweir
122*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
123*3ee7c2dbSArmin Le Grand {
124*3ee7c2dbSArmin Le Grand fValue = ::rtl::math::round( fValue, 15 );
125*3ee7c2dbSArmin Le Grand ScValueCell* pZelle = new ScValueCell( fValue );
126*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
127cdf0e10cSrcweir
128*3ee7c2dbSArmin Le Grand SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
129*3ee7c2dbSArmin Le Grand }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir
OP_Label(SvStream & r,sal_uInt16 n)133cdf0e10cSrcweir void OP_Label( SvStream& r, sal_uInt16 n )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir sal_uInt8 nFormat;
136cdf0e10cSrcweir sal_uInt16 nCol, nRow;
137cdf0e10cSrcweir SCTAB nTab = 0;
138cdf0e10cSrcweir
139cdf0e10cSrcweir r >> nFormat >> nCol >> nRow;
140cdf0e10cSrcweir
141*3ee7c2dbSArmin Le Grand n -= (n > 5) ? 5 : n;
142cdf0e10cSrcweir
143*3ee7c2dbSArmin Le Grand sal_Char* pText = new sal_Char[n + 1];
144*3ee7c2dbSArmin Le Grand r.Read( pText, n );
145*3ee7c2dbSArmin Le Grand pText[n] = 0;
146cdf0e10cSrcweir
147*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
148*3ee7c2dbSArmin Le Grand {
149*3ee7c2dbSArmin Le Grand nFormat &= 0x80; // Bit 7 belassen
150*3ee7c2dbSArmin Le Grand nFormat |= 0x75; // protected egal, special-text gesetzt
151cdf0e10cSrcweir
152*3ee7c2dbSArmin Le Grand PutFormString( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pText );
153cdf0e10cSrcweir
154*3ee7c2dbSArmin Le Grand SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezStd );
155*3ee7c2dbSArmin Le Grand }
156cdf0e10cSrcweir
157*3ee7c2dbSArmin Le Grand delete [] pText;
158*3ee7c2dbSArmin Le Grand }
159cdf0e10cSrcweir
160cdf0e10cSrcweir
OP_Formula(SvStream & r,sal_uInt16)161cdf0e10cSrcweir void OP_Formula( SvStream& r, sal_uInt16 /*n*/ )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir sal_uInt8 nFormat;
164cdf0e10cSrcweir sal_uInt16 nCol, nRow, nFormulaSize;
165cdf0e10cSrcweir SCTAB nTab = 0;
166cdf0e10cSrcweir
167cdf0e10cSrcweir r >> nFormat >> nCol >> nRow;
168cdf0e10cSrcweir r.SeekRel( 8 ); // Ergebnis ueberspringen
169cdf0e10cSrcweir r >> nFormulaSize;
170cdf0e10cSrcweir
171cdf0e10cSrcweir const ScTokenArray* pErg;
172cdf0e10cSrcweir sal_Int32 nBytesLeft = nFormulaSize;
173cdf0e10cSrcweir ScAddress aAddress( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab );
174cdf0e10cSrcweir
175cdf0e10cSrcweir LotusToSc aConv( r, pLotusRoot->eCharsetQ, sal_False );
176cdf0e10cSrcweir aConv.Reset( aAddress );
177cdf0e10cSrcweir aConv.Convert( pErg, nBytesLeft );
178cdf0e10cSrcweir
179*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow))
180*3ee7c2dbSArmin Le Grand {
181*3ee7c2dbSArmin Le Grand ScFormulaCell* pZelle = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
182cdf0e10cSrcweir
183*3ee7c2dbSArmin Le Grand pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
184cdf0e10cSrcweir
185*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, pZelle, ( sal_Bool ) sal_True );
186cdf0e10cSrcweir
187*3ee7c2dbSArmin Le Grand // nFormat = Standard -> Nachkommastellen wie Float
188*3ee7c2dbSArmin Le Grand SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), nTab, nFormat, nDezFloat );
189*3ee7c2dbSArmin Le Grand }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir
OP_ColumnWidth(SvStream & r,sal_uInt16)193cdf0e10cSrcweir void OP_ColumnWidth( SvStream& r, sal_uInt16 /*n*/ )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir sal_uInt16 nCol, nBreite;
196cdf0e10cSrcweir sal_uInt8 nWidthSpaces;
197cdf0e10cSrcweir SCTAB nTab = 0;
198cdf0e10cSrcweir
199cdf0e10cSrcweir r >> nCol >> nWidthSpaces;
200cdf0e10cSrcweir
201*3ee7c2dbSArmin Le Grand if (ValidCol( static_cast<SCCOL>(nCol)))
202*3ee7c2dbSArmin Le Grand {
203*3ee7c2dbSArmin Le Grand if( nWidthSpaces )
204*3ee7c2dbSArmin Le Grand // Annahme: 10cpi-Zeichensatz
205*3ee7c2dbSArmin Le Grand nBreite = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nWidthSpaces );
206*3ee7c2dbSArmin Le Grand else
207*3ee7c2dbSArmin Le Grand {
208*3ee7c2dbSArmin Le Grand pDoc->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), 0, true);
209*3ee7c2dbSArmin Le Grand nBreite = nDefWidth;
210*3ee7c2dbSArmin Le Grand }
211cdf0e10cSrcweir
212*3ee7c2dbSArmin Le Grand pDoc->SetColWidth( static_cast<SCCOL> (nCol), nTab, nBreite );
213*3ee7c2dbSArmin Le Grand }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir
OP_NamedRange(SvStream & r,sal_uInt16)217cdf0e10cSrcweir void OP_NamedRange( SvStream& r, sal_uInt16 /*n*/ )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir // POST: waren Koordinaten ungueltig, wird nicht gespeichert
220cdf0e10cSrcweir sal_uInt16 nColSt, nRowSt, nColEnd, nRowEnd;
221cdf0e10cSrcweir
222*3ee7c2dbSArmin Le Grand sal_Char cPuffer[ 16+1 ];
223cdf0e10cSrcweir r.Read( cPuffer, 16 );
224*3ee7c2dbSArmin Le Grand cPuffer[ 16 ] = 0;
225cdf0e10cSrcweir
226cdf0e10cSrcweir r >> nColSt >> nRowSt >> nColEnd >> nRowEnd;
227cdf0e10cSrcweir
228*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
229*3ee7c2dbSArmin Le Grand {
230*3ee7c2dbSArmin Le Grand LotusRange* pRange;
231*3ee7c2dbSArmin Le Grand
232*3ee7c2dbSArmin Le Grand if( nColSt == nColEnd && nRowSt == nRowEnd )
233*3ee7c2dbSArmin Le Grand pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
234*3ee7c2dbSArmin Le Grand else
235*3ee7c2dbSArmin Le Grand pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
236*3ee7c2dbSArmin Le Grand static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
237*3ee7c2dbSArmin Le Grand
238*3ee7c2dbSArmin Le Grand sal_Char cBuf[sizeof(cPuffer)+1];
239*3ee7c2dbSArmin Le Grand if( isdigit( *cPuffer ) )
240*3ee7c2dbSArmin Le Grand { // erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
241*3ee7c2dbSArmin Le Grand cBuf[0] = 'A';
242*3ee7c2dbSArmin Le Grand strcpy( cBuf + 1, cPuffer ); // #100211# - checked
243*3ee7c2dbSArmin Le Grand }
244*3ee7c2dbSArmin Le Grand else
245*3ee7c2dbSArmin Le Grand strcpy( cBuf, cPuffer ); // #100211# - checked
246cdf0e10cSrcweir
247*3ee7c2dbSArmin Le Grand String aTmp( cBuf, pLotusRoot->eCharsetQ );
248cdf0e10cSrcweir
249*3ee7c2dbSArmin Le Grand ScfTools::ConvertToScDefinedName( aTmp );
250cdf0e10cSrcweir
251*3ee7c2dbSArmin Le Grand pLotusRoot->pRangeNames->Append( pRange, aTmp );
252*3ee7c2dbSArmin Le Grand }
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir
OP_SymphNamedRange(SvStream & r,sal_uInt16)256cdf0e10cSrcweir void OP_SymphNamedRange( SvStream& r, sal_uInt16 /*n*/ )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir // POST: waren Koordinaten ungueltig, wird nicht gespeichert
259cdf0e10cSrcweir sal_uInt16 nColSt, nRowSt, nColEnd, nRowEnd;
260cdf0e10cSrcweir sal_uInt8 nType;
261cdf0e10cSrcweir
262*3ee7c2dbSArmin Le Grand sal_Char cPuffer[ 16+1 ];
263cdf0e10cSrcweir r.Read( cPuffer, 16 );
264cdf0e10cSrcweir cPuffer[ 16 ] = 0;
265cdf0e10cSrcweir
266cdf0e10cSrcweir r >> nColSt >> nRowSt >> nColEnd >> nRowEnd >> nType;
267cdf0e10cSrcweir
268*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
269*3ee7c2dbSArmin Le Grand {
270*3ee7c2dbSArmin Le Grand LotusRange* pRange;
271*3ee7c2dbSArmin Le Grand
272*3ee7c2dbSArmin Le Grand if( nType )
273*3ee7c2dbSArmin Le Grand pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
274*3ee7c2dbSArmin Le Grand else
275*3ee7c2dbSArmin Le Grand pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
276*3ee7c2dbSArmin Le Grand static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
277*3ee7c2dbSArmin Le Grand
278*3ee7c2dbSArmin Le Grand sal_Char cBuf[sizeof(cPuffer)+1];
279*3ee7c2dbSArmin Le Grand if( isdigit( *cPuffer ) )
280*3ee7c2dbSArmin Le Grand { // erstes Zeichen im Namen eine Zahl -> 'A' vor Namen setzen
281*3ee7c2dbSArmin Le Grand cBuf[0] = 'A';
282*3ee7c2dbSArmin Le Grand strcpy( cBuf + 1, cPuffer ); // #100211# - checked
283*3ee7c2dbSArmin Le Grand }
284*3ee7c2dbSArmin Le Grand else
285*3ee7c2dbSArmin Le Grand strcpy( cBuf, cPuffer ); // #100211# - checked
286cdf0e10cSrcweir
287*3ee7c2dbSArmin Le Grand String aTmp( cBuf, pLotusRoot->eCharsetQ );
288*3ee7c2dbSArmin Le Grand ScfTools::ConvertToScDefinedName( aTmp );
289cdf0e10cSrcweir
290*3ee7c2dbSArmin Le Grand pLotusRoot->pRangeNames->Append( pRange, aTmp );
291*3ee7c2dbSArmin Le Grand }
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
294cdf0e10cSrcweir
OP_Footer(SvStream & r,sal_uInt16 n)295cdf0e10cSrcweir void OP_Footer( SvStream& r, sal_uInt16 n )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir r.SeekRel( n );
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
300cdf0e10cSrcweir
OP_Header(SvStream & r,sal_uInt16 n)301cdf0e10cSrcweir void OP_Header( SvStream& r, sal_uInt16 n )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir r.SeekRel( n );
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir
OP_Margins(SvStream & r,sal_uInt16 n)307cdf0e10cSrcweir void OP_Margins( SvStream& r, sal_uInt16 n )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir r.SeekRel( n );
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
312cdf0e10cSrcweir
OP_HiddenCols(SvStream & r,sal_uInt16)313cdf0e10cSrcweir void OP_HiddenCols( SvStream& r, sal_uInt16 /*n*/ )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir sal_uInt16 nByte, nBit;
316cdf0e10cSrcweir SCCOL nCount;
317cdf0e10cSrcweir sal_uInt8 nAkt;
318cdf0e10cSrcweir nCount = 0;
319cdf0e10cSrcweir
320cdf0e10cSrcweir for( nByte = 0 ; nByte < 32 ; nByte++ ) // 32 Bytes mit ...
321cdf0e10cSrcweir {
322cdf0e10cSrcweir r >> nAkt;
323cdf0e10cSrcweir for( nBit = 0 ; nBit < 8 ; nBit++ ) // ...jeweils 8 Bits = 256 Bits
324cdf0e10cSrcweir {
325cdf0e10cSrcweir if( nAkt & 0x01 ) // unterstes Bit gesetzt?
326cdf0e10cSrcweir // -> Hidden Col
327cdf0e10cSrcweir pDoc->SetColHidden(nCount, nCount, 0, true);
328cdf0e10cSrcweir
329cdf0e10cSrcweir nCount++;
330cdf0e10cSrcweir nAkt = nAkt / 2; // der Naechste bitte...
331cdf0e10cSrcweir }
332cdf0e10cSrcweir }
333cdf0e10cSrcweir }
334cdf0e10cSrcweir
335cdf0e10cSrcweir
OP_Window1(SvStream & r,sal_uInt16 n)336cdf0e10cSrcweir void OP_Window1( SvStream& r, sal_uInt16 n )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir r.SeekRel( 4 ); // Cursor Pos ueberspringen
339cdf0e10cSrcweir
340cdf0e10cSrcweir r >> nDefaultFormat;
341cdf0e10cSrcweir
342cdf0e10cSrcweir r.SeekRel( 1 ); // 'unused' ueberspringen
343cdf0e10cSrcweir
344cdf0e10cSrcweir r >> nDefWidth;
345cdf0e10cSrcweir
346cdf0e10cSrcweir r.SeekRel( n - 8 ); // und den Rest ueberspringen
347cdf0e10cSrcweir
348cdf0e10cSrcweir nDefWidth = ( sal_uInt16 ) ( TWIPS_PER_CHAR * nDefWidth );
349cdf0e10cSrcweir
350cdf0e10cSrcweir // statt Defaulteinstellung in SC alle Cols zu Fuss setzen
351cdf0e10cSrcweir for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ )
352cdf0e10cSrcweir pDoc->SetColWidth( nCol, 0, nDefWidth );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir
355cdf0e10cSrcweir
OP_Blank(SvStream & r,sal_uInt16)356cdf0e10cSrcweir void OP_Blank( SvStream& r, sal_uInt16 /*n*/ )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir sal_uInt16 nCol, nRow;
359cdf0e10cSrcweir sal_uInt8 nFormat;
360cdf0e10cSrcweir r >> nFormat >> nCol >> nRow;
361cdf0e10cSrcweir
362cdf0e10cSrcweir SetFormat( static_cast<SCCOL> (nCol), static_cast<SCROW> (nRow), 0, nFormat, nDezFloat );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir
OP_BOF123(SvStream & r,sal_uInt16)365cdf0e10cSrcweir void OP_BOF123( SvStream& r, sal_uInt16 /*n*/ )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir r.SeekRel( 26 );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
370cdf0e10cSrcweir
OP_EOF123(SvStream &,sal_uInt16)371cdf0e10cSrcweir void OP_EOF123( SvStream& /*r*/, sal_uInt16 /*n*/ )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir bEOF = sal_True;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
OP_Label123(SvStream & r,sal_uInt16 n)376cdf0e10cSrcweir void OP_Label123( SvStream& r, sal_uInt16 n )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir sal_uInt8 nTab, nCol;
379cdf0e10cSrcweir sal_uInt16 nRow;
380cdf0e10cSrcweir r >> nRow >> nTab >> nCol;
381*3ee7c2dbSArmin Le Grand n -= (n > 4) ? 4 : n;
382cdf0e10cSrcweir
383cdf0e10cSrcweir sal_Char* pText = new sal_Char[n + 1];
384cdf0e10cSrcweir r.Read( pText, n );
385cdf0e10cSrcweir pText[ n ] = 0;
386cdf0e10cSrcweir
387cdf0e10cSrcweir PutFormString( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pText );
388cdf0e10cSrcweir
389cdf0e10cSrcweir delete []pText;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
OP_Number123(SvStream & r,sal_uInt16)392cdf0e10cSrcweir void OP_Number123( SvStream& r, sal_uInt16 /*n*/ )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir sal_uInt8 nCol,nTab;
395cdf0e10cSrcweir sal_uInt16 nRow;
396cdf0e10cSrcweir sal_uInt32 nValue;
397cdf0e10cSrcweir
398cdf0e10cSrcweir r >> nRow >> nTab >> nCol >> nValue;
399cdf0e10cSrcweir
400*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
401*3ee7c2dbSArmin Le Grand {
402*3ee7c2dbSArmin Le Grand double fValue = Snum32ToDouble( nValue );
403*3ee7c2dbSArmin Le Grand
404*3ee7c2dbSArmin Le Grand ScValueCell *pCell = new ScValueCell( fValue );
405*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
406*3ee7c2dbSArmin Le Grand }
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
OP_Formula123(SvStream & r,sal_uInt16 n)409cdf0e10cSrcweir void OP_Formula123( SvStream& r, sal_uInt16 n )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir sal_uInt8 nCol,nTab;
412cdf0e10cSrcweir sal_uInt16 nRow;
413cdf0e10cSrcweir
414cdf0e10cSrcweir r >> nRow >> nTab >> nCol;
415cdf0e10cSrcweir r.SeekRel( 8 ); // Result- jump over
416cdf0e10cSrcweir
417cdf0e10cSrcweir const ScTokenArray* pErg;
418*3ee7c2dbSArmin Le Grand sal_Int32 nBytesLeft = (n > 12) ? n - 12 : 0;
419cdf0e10cSrcweir ScAddress aAddress( nCol, nRow, nTab );
420cdf0e10cSrcweir
421cdf0e10cSrcweir LotusToSc aConv( r, pLotusRoot->eCharsetQ, sal_True );
422cdf0e10cSrcweir aConv.Reset( aAddress );
423cdf0e10cSrcweir aConv.Convert( pErg, nBytesLeft );
424cdf0e10cSrcweir
425*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
426*3ee7c2dbSArmin Le Grand {
427*3ee7c2dbSArmin Le Grand ScFormulaCell* pCell = new ScFormulaCell( pLotusRoot->pDoc, aAddress, pErg );
428cdf0e10cSrcweir
429*3ee7c2dbSArmin Le Grand pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
430cdf0e10cSrcweir
431*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
432*3ee7c2dbSArmin Le Grand }
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
OP_IEEENumber123(SvStream & r,sal_uInt16)435cdf0e10cSrcweir void OP_IEEENumber123( SvStream& r, sal_uInt16 /*n*/ )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir sal_uInt8 nCol,nTab;
438cdf0e10cSrcweir sal_uInt16 nRow;
439cdf0e10cSrcweir double dValue;
440cdf0e10cSrcweir
441cdf0e10cSrcweir r >> nRow >> nTab >> nCol >> dValue;
442cdf0e10cSrcweir
443*3ee7c2dbSArmin Le Grand if (ValidColRow( static_cast<SCCOL>(nCol), nRow) && nTab < pDoc->GetMaxTableNumber())
444*3ee7c2dbSArmin Le Grand {
445*3ee7c2dbSArmin Le Grand ScValueCell *pCell = new ScValueCell(dValue);
446*3ee7c2dbSArmin Le Grand pDoc->PutCell( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab), pCell, (sal_Bool) sal_True );
447*3ee7c2dbSArmin Le Grand }
448cdf0e10cSrcweir }
449cdf0e10cSrcweir
OP_Note123(SvStream & r,sal_uInt16 n)450cdf0e10cSrcweir void OP_Note123( SvStream& r, sal_uInt16 n)
451cdf0e10cSrcweir {
452cdf0e10cSrcweir sal_uInt8 nTab, nCol;
453cdf0e10cSrcweir sal_uInt16 nRow;
454cdf0e10cSrcweir r >> nRow >> nTab >> nCol;
455*3ee7c2dbSArmin Le Grand n -= (n > 4) ? 4 : n;
456cdf0e10cSrcweir
457cdf0e10cSrcweir sal_Char* pText = new sal_Char[n + 1];
458cdf0e10cSrcweir r.Read( pText, n );
459cdf0e10cSrcweir pText[ n ] = 0;
460cdf0e10cSrcweir
461cdf0e10cSrcweir String aNoteText(pText,pLotusRoot->eCharsetQ);
462cdf0e10cSrcweir delete [] pText;
463cdf0e10cSrcweir
464cdf0e10cSrcweir ScAddress aPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCTAB>(nTab) );
465cdf0e10cSrcweir ScNoteUtil::CreateNoteFromString( *pDoc, aPos, aNoteText, false, false );
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
OP_HorAlign123(sal_uInt8 nAlignPattern,SfxItemSet & rPatternItemSet)468cdf0e10cSrcweir void OP_HorAlign123( sal_uInt8 nAlignPattern, SfxItemSet& rPatternItemSet )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir // pre: Pattern is stored in the last 3 bites of the 21st byte
471cdf0e10cSrcweir // post: Appropriate Horizontal Alignement is set in rPattern according to the bit pattern.
472cdf0e10cSrcweir //
473cdf0e10cSrcweir // LEFT:001, RIGHT:010, CENTER:011, JUSTIFY:110,
474cdf0e10cSrcweir // LEFT-Text/RIGHT-NUMBER:100, DEFAULT:000
475cdf0e10cSrcweir
476cdf0e10cSrcweir nAlignPattern = ( nAlignPattern & 0x07);
477cdf0e10cSrcweir
478cdf0e10cSrcweir switch (nAlignPattern)
479cdf0e10cSrcweir {
480cdf0e10cSrcweir case 1:
481cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_LEFT, ATTR_HOR_JUSTIFY ) );
482cdf0e10cSrcweir break;
483cdf0e10cSrcweir case 2:
484cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_RIGHT, ATTR_HOR_JUSTIFY ) );
485cdf0e10cSrcweir break;
486cdf0e10cSrcweir case 3:
487cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY) );
488cdf0e10cSrcweir break;
489cdf0e10cSrcweir case 4:
490cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ) );
491cdf0e10cSrcweir break;
492cdf0e10cSrcweir case 6:
493cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_BLOCK, ATTR_HOR_JUSTIFY ) );
494cdf0e10cSrcweir break;
495cdf0e10cSrcweir default:
496cdf0e10cSrcweir rPatternItemSet.Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ) );
497cdf0e10cSrcweir break;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir }
500cdf0e10cSrcweir
OP_VerAlign123(sal_uInt8 nAlignPattern,SfxItemSet & rPatternItemSet)501cdf0e10cSrcweir void OP_VerAlign123( sal_uInt8 nAlignPattern,SfxItemSet& rPatternItemSet )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir // pre: Pattern is stored in the last 3 bites of the 22nd byte
504cdf0e10cSrcweir // post: Appropriate Verticle Alignement is set in rPattern according to the bit pattern.
505cdf0e10cSrcweir //
506cdf0e10cSrcweir // TOP:001, MIDDLE:010, DOWN:100, DEFAULT:000
507cdf0e10cSrcweir
508cdf0e10cSrcweir nAlignPattern = ( nAlignPattern & 0x07);
509cdf0e10cSrcweir
510cdf0e10cSrcweir switch (nAlignPattern)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir case 0:
513cdf0e10cSrcweir rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY) );
514cdf0e10cSrcweir break;
515cdf0e10cSrcweir case 1:
516cdf0e10cSrcweir rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_TOP, ATTR_VER_JUSTIFY) );
517cdf0e10cSrcweir break;
518cdf0e10cSrcweir case 2:
519cdf0e10cSrcweir rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY) );
520cdf0e10cSrcweir break;
521cdf0e10cSrcweir case 4:
522cdf0e10cSrcweir rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_BOTTOM, ATTR_VER_JUSTIFY) );
523cdf0e10cSrcweir break;
524cdf0e10cSrcweir default:
525cdf0e10cSrcweir rPatternItemSet.Put( SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY) );
526cdf0e10cSrcweir break;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
OP_CreatePattern123(SvStream & r,sal_uInt16 n)530cdf0e10cSrcweir void OP_CreatePattern123( SvStream& r, sal_uInt16 n)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir sal_uInt16 nCode,nPatternId;
533cdf0e10cSrcweir
534cdf0e10cSrcweir ScPatternAttr aPattern(pDoc->GetPool());
535cdf0e10cSrcweir SfxItemSet& rItemSet = aPattern.GetItemSet();
536cdf0e10cSrcweir
537cdf0e10cSrcweir r >> nCode;
538*3ee7c2dbSArmin Le Grand n -= (n > 2) ? 2 : n;
539cdf0e10cSrcweir
540cdf0e10cSrcweir if ( nCode == 0x0fd2 )
541cdf0e10cSrcweir {
542cdf0e10cSrcweir r >> nPatternId;
543cdf0e10cSrcweir
544cdf0e10cSrcweir sal_uInt8 Hor_Align, Ver_Align, temp;
545cdf0e10cSrcweir sal_Bool bIsBold,bIsUnderLine,bIsItalics;
546cdf0e10cSrcweir
547cdf0e10cSrcweir r.SeekRel(12);
548cdf0e10cSrcweir
549cdf0e10cSrcweir // Read 17th Byte
550cdf0e10cSrcweir r >> temp;
551cdf0e10cSrcweir
552cdf0e10cSrcweir bIsBold = (temp & 0x01);
553cdf0e10cSrcweir bIsItalics = (temp & 0x02);
554cdf0e10cSrcweir bIsUnderLine = (temp & 0x04);
555cdf0e10cSrcweir
556cdf0e10cSrcweir if ( bIsBold )
557cdf0e10cSrcweir rItemSet.Put( SvxWeightItem(WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
558cdf0e10cSrcweir if ( bIsItalics )
559cdf0e10cSrcweir rItemSet.Put( SvxPostureItem(ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
560cdf0e10cSrcweir if ( bIsUnderLine )
561cdf0e10cSrcweir rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
562cdf0e10cSrcweir
563cdf0e10cSrcweir r.SeekRel(3);
564cdf0e10cSrcweir
565cdf0e10cSrcweir // Read 21st Byte
566cdf0e10cSrcweir r >> Hor_Align;
567cdf0e10cSrcweir OP_HorAlign123( Hor_Align, rItemSet );
568cdf0e10cSrcweir
569cdf0e10cSrcweir r >> Ver_Align;
570cdf0e10cSrcweir OP_VerAlign123( Ver_Align, rItemSet );
571cdf0e10cSrcweir
572cdf0e10cSrcweir aLotusPatternPool.insert( std::map<sal_uInt16, ScPatternAttr>::value_type( nPatternId, aPattern ) );
573*3ee7c2dbSArmin Le Grand n -= (n > 20) ? 20 : n;
574cdf0e10cSrcweir }
575cdf0e10cSrcweir r.SeekRel(n);
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
OP_SheetName123(SvStream & rStream,sal_uInt16 nLength)578cdf0e10cSrcweir void OP_SheetName123( SvStream& rStream, sal_uInt16 nLength )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir if (nLength <= 4)
581cdf0e10cSrcweir {
582cdf0e10cSrcweir rStream.SeekRel(nLength);
583cdf0e10cSrcweir return;
584cdf0e10cSrcweir }
585cdf0e10cSrcweir
586cdf0e10cSrcweir // B0 36 [sheet number (2 bytes?)] [sheet name (null terminated char array)]
587cdf0e10cSrcweir
588cdf0e10cSrcweir sal_uInt16 nDummy;
589cdf0e10cSrcweir rStream >> nDummy; // ignore the first 2 bytes (B0 36).
590cdf0e10cSrcweir rStream >> nDummy;
591cdf0e10cSrcweir SCTAB nSheetNum = static_cast<SCTAB>(nDummy);
592cdf0e10cSrcweir pDoc->MakeTable(nSheetNum);
593cdf0e10cSrcweir
594cdf0e10cSrcweir ::std::vector<sal_Char> sSheetName;
595cdf0e10cSrcweir sSheetName.reserve(nLength-4);
596cdf0e10cSrcweir for (sal_uInt16 i = 4; i < nLength; ++i)
597cdf0e10cSrcweir {
598cdf0e10cSrcweir sal_Char c;
599cdf0e10cSrcweir rStream >> c;
600cdf0e10cSrcweir sSheetName.push_back(c);
601cdf0e10cSrcweir }
602cdf0e10cSrcweir
603cdf0e10cSrcweir if (!sSheetName.empty())
604cdf0e10cSrcweir {
605cdf0e10cSrcweir String aName(&sSheetName[0], eCharVon);
606cdf0e10cSrcweir pDoc->RenameTab(nSheetNum, aName);
607cdf0e10cSrcweir }
608cdf0e10cSrcweir }
609cdf0e10cSrcweir
OP_ApplyPatternArea123(SvStream & rStream)610cdf0e10cSrcweir void OP_ApplyPatternArea123( SvStream& rStream )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir sal_uInt16 nOpcode, nLength;
613cdf0e10cSrcweir sal_uInt16 nCol = 0, nColCount = 0, nRow = 0, nRowCount = 0, nTab = 0, nData, nTabCount = 0, nLevel = 0;
614cdf0e10cSrcweir
615cdf0e10cSrcweir do
616cdf0e10cSrcweir {
617cdf0e10cSrcweir rStream >> nOpcode >> nLength;
618cdf0e10cSrcweir switch ( nOpcode )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir case ROW_FORMAT_MARKER:
621cdf0e10cSrcweir nLevel++;
622cdf0e10cSrcweir break;
623cdf0e10cSrcweir case COL_FORMAT_MARKER:
624cdf0e10cSrcweir nLevel--;
625cdf0e10cSrcweir if( nLevel == 1 )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir nTab = nTab + nTabCount;
628cdf0e10cSrcweir nCol = 0; nColCount = 0;
629cdf0e10cSrcweir nRow = 0; nRowCount = 0;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir break;
632cdf0e10cSrcweir case LOTUS_FORMAT_INDEX:
633cdf0e10cSrcweir if( nLength >= 2 )
634cdf0e10cSrcweir {
635cdf0e10cSrcweir rStream >> nData;
636cdf0e10cSrcweir rStream.SeekRel( nLength - 2 );
637cdf0e10cSrcweir if( nLevel == 1 )
638cdf0e10cSrcweir nTabCount = nData;
639cdf0e10cSrcweir else if( nLevel == 2 )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir nCol = nCol + nColCount;
642cdf0e10cSrcweir nColCount = nData;
643cdf0e10cSrcweir if ( nCol > 0xff ) // 256 is the max col size supported by 123
644cdf0e10cSrcweir nCol = 0;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir else if( nLevel == 3 )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir nRow = nRow + nRowCount;
649cdf0e10cSrcweir nRowCount = nData;
650cdf0e10cSrcweir if ( nRow > 0x1fff ) // 8192 is the max row size supported by 123
651cdf0e10cSrcweir nRow = 0;
652cdf0e10cSrcweir }
653cdf0e10cSrcweir }
654cdf0e10cSrcweir else
655cdf0e10cSrcweir rStream.SeekRel( nLength );
656cdf0e10cSrcweir break;
657cdf0e10cSrcweir case LOTUS_FORMAT_INFO:
658cdf0e10cSrcweir if( nLength >= 2 )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir rStream >> nData;
661cdf0e10cSrcweir rStream.SeekRel( nLength - 2 );
662*3ee7c2dbSArmin Le Grand std::map<sal_uInt16, ScPatternAttr>::iterator loc = aLotusPatternPool.find( nData );
663*3ee7c2dbSArmin Le Grand // #126338# apparently, files with invalid index occur in the wild -> don't crash then
664*3ee7c2dbSArmin Le Grand if ( loc != aLotusPatternPool.end() )
665*3ee7c2dbSArmin Le Grand for( int i = 0; i < nTabCount; i++)
666*3ee7c2dbSArmin Le Grand {
667cdf0e10cSrcweir pDoc->ApplyPatternAreaTab( nCol, nRow, nCol + nColCount - 1, nRow + nRowCount - 1, static_cast< SCTAB >( nTab + i ), loc->second );
668*3ee7c2dbSArmin Le Grand }
669cdf0e10cSrcweir }
670cdf0e10cSrcweir else
671cdf0e10cSrcweir rStream.SeekRel( nLength );
672cdf0e10cSrcweir break;
673cdf0e10cSrcweir default:
674cdf0e10cSrcweir rStream.SeekRel( nLength );
675cdf0e10cSrcweir break;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir }
678cdf0e10cSrcweir while( nLevel && !rStream.IsEof() );
679cdf0e10cSrcweir
680cdf0e10cSrcweir aLotusPatternPool.clear();
681cdf0e10cSrcweir }
682