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