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 "lotimpop.hxx"
30 : : #include <osl/mutex.hxx>
31 : :
32 : : #include "attrib.hxx"
33 : : #include "document.hxx"
34 : : #include "rangenam.hxx"
35 : : #include "cell.hxx"
36 : : #include "patattr.hxx"
37 : : #include "docpool.hxx"
38 : : #include "compiler.hxx"
39 : : #include "global.hxx"
40 : :
41 : : #include "root.hxx"
42 : : #include "lotfntbf.hxx"
43 : : #include "lotform.hxx"
44 : : #include "tool.h"
45 : : #include "namebuff.hxx"
46 : : #include "lotrange.hxx"
47 : : #include "lotattr.hxx"
48 : :
49 : 0 : LOTUS_ROOT::LOTUS_ROOT( ScDocument* pDocP, CharSet eQ )
50 : : :
51 : : pDoc( pDocP),
52 [ # # ]: 0 : pRangeNames( new LotusRangeList),
53 : 0 : pScRangeName( pDocP->GetRangeName()),
54 : : eCharsetQ( eQ),
55 : : eFirstType( Lotus_X),
56 : : eActType( Lotus_X),
57 [ # # ]: 0 : pRngNmBffWK3( new RangeNameBufferWK3),
58 [ # # ]: 0 : pFontBuff( new LotusFontBuffer),
59 [ # # ]: 0 : pAttrTable( new LotAttrTable)
60 : : {
61 : 0 : }
62 : :
63 : :
64 : 0 : LOTUS_ROOT::~LOTUS_ROOT()
65 : : {
66 [ # # ]: 0 : delete pRangeNames;
67 [ # # ]: 0 : delete pRngNmBffWK3;
68 [ # # ]: 0 : delete pFontBuff;
69 [ # # ]: 0 : delete pAttrTable;
70 : 0 : }
71 : :
72 : :
73 : 8 : static osl::Mutex aLotImpSemaphore;
74 : :
75 : :
76 : 0 : ImportLotus::ImportLotus( SvStream& aStream, ScDocument* pDoc, CharSet eQ ) :
77 : : ImportTyp( pDoc, eQ ),
78 : : pIn( &aStream ),
79 [ # # ]: 0 : aConv( *pIn, eQ, false )
80 : : {
81 : : // good point to start locking of import lotus
82 [ # # ]: 0 : aLotImpSemaphore.acquire();
83 : :
84 [ # # ][ # # ]: 0 : pLotusRoot = new LOTUS_ROOT( pDoc, eQ);
85 : 0 : }
86 : :
87 : :
88 [ # # ]: 0 : ImportLotus::~ImportLotus()
89 : : {
90 [ # # ][ # # ]: 0 : delete pLotusRoot;
91 : 0 : pLotusRoot = NULL;
92 : :
93 : : // no need 4 pLotusRoot anymore
94 [ # # ]: 0 : aLotImpSemaphore.release();
95 [ # # ]: 0 : }
96 : :
97 : :
98 : 0 : void ImportLotus::Bof( void )
99 : : {
100 : : sal_uInt16 nFileCode, nFileSub, nSaveCnt;
101 : : sal_uInt8 nMajorId, nMinorId, nFlags;
102 : :
103 [ # # ]: 0 : Read( nFileCode );
104 [ # # ]: 0 : Read( nFileSub );
105 [ # # ]: 0 : Read( pLotusRoot->aActRange );
106 [ # # ]: 0 : Read( nSaveCnt );
107 [ # # ]: 0 : Read( nMajorId );
108 [ # # ]: 0 : Read( nMinorId );
109 [ # # ]: 0 : Skip( 1 );
110 [ # # ]: 0 : Read( nFlags );
111 : :
112 [ # # ]: 0 : if( nFileSub == 0x0004 )
113 : : {
114 [ # # ]: 0 : if( nFileCode == 0x1000 )
115 : : {// <= WK3
116 : 0 : pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK3;
117 : : }
118 [ # # ]: 0 : else if( nFileCode == 0x1002 )
119 : : {// WK4
120 : 0 : pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK4;
121 : : }
122 : : }
123 : 0 : }
124 : :
125 : :
126 : 0 : sal_Bool ImportLotus::BofFm3( void )
127 : : {
128 : : sal_uInt16 nFileCode, nFileSub;
129 : :
130 [ # # ]: 0 : Read( nFileCode );
131 [ # # ]: 0 : Read( nFileSub );
132 : :
133 [ # # ][ # # ]: 0 : return ( nFileCode == 0x8007 && ( nFileSub == 0x0000 || nFileSub == 0x00001 ) );
[ # # ]
134 : : }
135 : :
136 : :
137 : 0 : void ImportLotus::Columnwidth( sal_uInt16 nRecLen )
138 : : {
139 : : OSL_ENSURE( nRecLen >= 4, "*ImportLotus::Columnwidth(): Record zu kurz!" );
140 : :
141 : : sal_uInt8 nLTab, nWindow2;
142 [ # # ]: 0 : sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
143 : :
144 [ # # ]: 0 : Read( nLTab );
145 [ # # ]: 0 : Read( nWindow2 );
146 : :
147 [ # # ][ # # ]: 0 : if( !pD->HasTable( static_cast<SCTAB> (nLTab) ) )
148 [ # # ]: 0 : pD->MakeTable( static_cast<SCTAB> (nLTab) );
149 : :
150 [ # # ]: 0 : if( !nWindow2 )
151 : : {
152 [ # # ]: 0 : Skip( 2 );
153 : :
154 : : sal_uInt8 nCol, nSpaces;
155 : :
156 [ # # ]: 0 : while( nCnt )
157 : : {
158 [ # # ]: 0 : Read( nCol );
159 [ # # ]: 0 : Read( nSpaces );
160 : : // ACHTUNG: Korrekturfaktor nach 'Augenmass' ermittelt!
161 [ # # ]: 0 : pD->SetColWidth( static_cast<SCCOL> (nCol), static_cast<SCTAB> (nLTab), ( sal_uInt16 ) ( TWIPS_PER_CHAR * 1.28 * nSpaces ) );
162 : :
163 : 0 : nCnt--;
164 : : }
165 : : }
166 : 0 : }
167 : :
168 : :
169 : 0 : void ImportLotus::Hiddencolumn( sal_uInt16 nRecLen )
170 : : {
171 : : OSL_ENSURE( nRecLen >= 4, "*ImportLotus::Hiddencolumn(): Record zu kurz!" );
172 : :
173 : : sal_uInt8 nLTab, nWindow2;
174 [ # # ]: 0 : sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
175 : :
176 [ # # ]: 0 : Read( nLTab );
177 [ # # ]: 0 : Read( nWindow2 );
178 : :
179 [ # # ]: 0 : if( !nWindow2 )
180 : : {
181 [ # # ]: 0 : Skip( 2 );
182 : :
183 : : sal_uInt8 nCol;
184 : :
185 [ # # ]: 0 : while( nCnt )
186 : : {
187 [ # # ]: 0 : Read( nCol );
188 : :
189 [ # # ]: 0 : pD->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), static_cast<SCTAB>(nLTab), true);
190 : 0 : nCnt--;
191 : : }
192 : : }
193 : 0 : }
194 : :
195 : :
196 : 0 : void ImportLotus::Userrange( void )
197 : : {
198 : : sal_uInt16 nRangeType;
199 : 0 : ScRange aScRange;
200 : :
201 [ # # ]: 0 : Read( nRangeType );
202 : :
203 : : sal_Char aBuffer[ 17 ];
204 [ # # ]: 0 : pIn->Read( aBuffer, 16 );
205 : 0 : aBuffer[ 16 ] = 0;
206 [ # # ]: 0 : String aName( aBuffer, eQuellChar );
207 : :
208 [ # # ]: 0 : Read( aScRange );
209 : :
210 [ # # ][ # # ]: 0 : pLotusRoot->pRngNmBffWK3->Add( aName, aScRange );
211 : 0 : }
212 : :
213 : :
214 : 0 : void ImportLotus::Errcell( void )
215 : : {
216 : 0 : ScAddress aA;
217 : :
218 [ # # ]: 0 : Read( aA );
219 : :
220 [ # # ][ # # ]: 0 : pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( CREATE_STRING( "#ERR!" ) ), true );
[ # # ][ # # ]
[ # # ][ # # ]
221 : 0 : }
222 : :
223 : :
224 : 0 : void ImportLotus::Nacell( void )
225 : : {
226 : 0 : ScAddress aA;
227 : :
228 [ # # ]: 0 : Read( aA );
229 : :
230 [ # # ][ # # ]: 0 : pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( CREATE_STRING( "#NA!" ) ), true );
[ # # ][ # # ]
[ # # ][ # # ]
231 : 0 : }
232 : :
233 : :
234 : 0 : void ImportLotus::Labelcell( void )
235 : : {
236 : 0 : ScAddress aA;
237 [ # # ]: 0 : String aLabel;
238 : : sal_Char cAlign;
239 : :
240 [ # # ]: 0 : Read( aA );
241 [ # # ]: 0 : Read( cAlign );
242 [ # # ]: 0 : Read( aLabel );
243 : :
244 : : // aLabel.Convert( pLotusRoot->eCharsetQ );
245 : :
246 [ # # ][ # # ]: 0 : pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( aLabel ), true );
[ # # ][ # # ]
[ # # ]
247 : 0 : }
248 : :
249 : :
250 : 0 : void ImportLotus::Numbercell( void )
251 : : {
252 : 0 : ScAddress aAddr;
253 : : double fVal;
254 : :
255 [ # # ]: 0 : Read( aAddr );
256 [ # # ]: 0 : Read( fVal );
257 : :
258 : 0 : pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
259 [ # # ]: 0 : new ScValueCell( fVal ), true );
[ # # # # ]
260 : 0 : }
261 : :
262 : :
263 : 0 : void ImportLotus::Smallnumcell( void )
264 : : {
265 : 0 : ScAddress aAddr;
266 : : sal_Int16 nVal;
267 : :
268 [ # # ]: 0 : Read( aAddr );
269 [ # # ]: 0 : Read( nVal );
270 : :
271 : 0 : pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
272 [ # # ][ # # ]: 0 : new ScValueCell( SnumToDouble( nVal ) ), true );
[ # # # # ]
273 : 0 : }
274 : :
275 : :
276 : 0 : ScFormulaCell *ImportLotus::Formulacell( sal_uInt16 n )
277 : : {
278 : : OSL_ENSURE( pIn, "-ImportLotus::Formulacell(): Null-Stream -> Rums!" );
279 : :
280 : 0 : ScAddress aAddr;
281 : :
282 [ # # ]: 0 : Read( aAddr );
283 [ # # ]: 0 : Skip( 10 );
284 : :
285 : 0 : n -= (n > 14) ? 14 : n;
286 : :
287 : : const ScTokenArray* pErg;
288 : 0 : sal_Int32 nRest = n;
289 : :
290 [ # # ]: 0 : aConv.Reset( aAddr );
291 : 0 : aConv.SetWK3();
292 [ # # ]: 0 : aConv.Convert( pErg, nRest );
293 : :
294 [ # # ][ # # ]: 0 : ScFormulaCell* pZelle = new ScFormulaCell( pD, aAddr, pErg );
295 : :
296 [ # # ]: 0 : pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
297 : :
298 [ # # ][ # # ]: 0 : pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(), pZelle, true );
299 : :
300 : 0 : return NULL;
301 : : }
302 : :
303 : :
304 : 0 : void ImportLotus::Read( String &r )
305 : : {
306 : 0 : ScfTools::AppendCString( *pIn, r, eQuellChar );
307 : 0 : }
308 : :
309 : :
310 : 0 : void ImportLotus::RowPresentation( sal_uInt16 nRecLen )
311 : : {
312 : : OSL_ENSURE( nRecLen > 4, "*ImportLotus::RowPresentation(): Record zu kurz!" );
313 : :
314 : : sal_uInt8 nLTab, nFlags;
315 : : sal_uInt16 nRow, nHeight;
316 [ # # ]: 0 : sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 8;
317 : :
318 [ # # ]: 0 : Read( nLTab );
319 [ # # ]: 0 : Skip( 1 );
320 : :
321 [ # # ]: 0 : while( nCnt )
322 : : {
323 [ # # ]: 0 : Read( nRow );
324 [ # # ]: 0 : Read( nHeight );
325 [ # # ]: 0 : Skip( 2 );
326 [ # # ]: 0 : Read( nFlags );
327 [ # # ]: 0 : Skip( 1 );
328 : :
329 [ # # ]: 0 : if( nFlags & 0x02 ) // Fixed / Strech to fit fonts
330 : : { // fixed
331 : : // Height in Lotus in 1/32 Points
332 : 0 : nHeight *= 20; // -> 32 * TWIPS
333 : 0 : nHeight /= 32; // -> TWIPS
334 : :
335 [ # # ][ # # ]: 0 : pD->SetRowFlags( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab), pD->GetRowFlags( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab) ) | CR_MANUALSIZE );
336 : :
337 [ # # ]: 0 : pD->SetRowHeight( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab), nHeight );
338 : : }
339 : :
340 : 0 : nCnt--;
341 : : }
342 : 0 : }
343 : :
344 : :
345 : 0 : void ImportLotus::NamedSheet( void )
346 : : {
347 : : sal_uInt16 nLTab;
348 [ # # ]: 0 : String aName;
349 : :
350 [ # # ]: 0 : Read( nLTab );
351 [ # # ]: 0 : Read( aName );
352 : :
353 [ # # ][ # # ]: 0 : if( pD->HasTable( static_cast<SCTAB> (nLTab) ) )
354 [ # # ][ # # ]: 0 : pD->RenameTab( static_cast<SCTAB> (nLTab), aName );
355 : : else
356 [ # # ][ # # ]: 0 : pD->InsertTab( static_cast<SCTAB> (nLTab), aName );
[ # # ]
357 : 0 : }
358 : :
359 : :
360 : 0 : void ImportLotus::Font_Face( void )
361 : : {
362 : : sal_uInt8 nNum;
363 [ # # ]: 0 : String aName;
364 : :
365 [ # # ]: 0 : Read( nNum );
366 : :
367 [ # # ]: 0 : if( nNum >= LotusFontBuffer::nSize )
368 : 0 : return; // nonsense
369 : :
370 [ # # ]: 0 : Read( aName );
371 : :
372 [ # # ][ # # ]: 0 : pLotusRoot->pFontBuff->SetName( nNum, aName );
[ # # ]
373 : : }
374 : :
375 : :
376 : 0 : void ImportLotus::Font_Type( void )
377 : : {
378 [ # # ]: 0 : for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
379 : : {
380 : : sal_uInt16 nType;
381 [ # # ]: 0 : Read( nType );
382 [ # # ]: 0 : pLotusRoot->pFontBuff->SetType( nCnt, nType );
383 : : }
384 : 0 : }
385 : :
386 : :
387 : 0 : void ImportLotus::Font_Ysize( void )
388 : : {
389 [ # # ]: 0 : for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
390 : : {
391 : : sal_uInt16 nSize;
392 [ # # ]: 0 : Read( nSize );
393 [ # # ]: 0 : pLotusRoot->pFontBuff->SetHeight( nCnt, nSize );
394 : : }
395 : 0 : }
396 : :
397 : :
398 : 0 : void ImportLotus::_Row( const sal_uInt16 nRecLen )
399 : : {
400 : : OSL_ENSURE( nExtTab >= 0, "*ImportLotus::_Row(): Kann hier nicht sein!" );
401 : :
402 : : sal_uInt16 nRow;
403 : : sal_uInt16 nHeight;
404 [ # # ]: 0 : sal_uInt16 nCntDwn = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 5;
405 : 0 : SCCOL nColCnt = 0;
406 : : sal_uInt8 nRepeats;
407 : : LotAttrWK3 aAttr;
408 : :
409 : 0 : sal_Bool bCenter = false;
410 : 0 : SCCOL nCenterStart = 0, nCenterEnd = 0;
411 : :
412 [ # # ]: 0 : Read( nRow );
413 [ # # ]: 0 : Read( nHeight );
414 : :
415 : 0 : nHeight &= 0x0FFF;
416 : 0 : nHeight *= 22;
417 : :
418 [ # # ]: 0 : if( nHeight )
419 [ # # ]: 0 : pD->SetRowHeight( static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab), nHeight );
420 : :
421 [ # # ]: 0 : while( nCntDwn )
422 : : {
423 [ # # ]: 0 : Read( aAttr );
424 [ # # ]: 0 : Read( nRepeats );
425 : :
426 [ # # ]: 0 : if( aAttr.HasStyles() )
427 : : pLotusRoot->pAttrTable->SetAttr(
428 [ # # ]: 0 : nColCnt, static_cast<SCCOL> ( nColCnt + nRepeats ), static_cast<SCROW> (nRow), aAttr );
429 : :
430 : : // hier und NICHT in class LotAttrTable, weil nur Attributiert wird,
431 : : // wenn die anderen Attribute gesetzt sind
432 : : // -> bei Center-Attribute wird generell zentriert gesetzt
433 [ # # ]: 0 : if( aAttr.IsCentered() )
434 : : {
435 [ # # ]: 0 : if( bCenter )
436 : : {
437 [ # # ][ # # ]: 0 : if( pD->HasData( nColCnt, static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab) ) )
438 : : {// neue Center nach vorheriger Center
439 [ # # ]: 0 : pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
440 : 0 : nCenterStart = nColCnt;
441 : : }
442 : : }
443 : : else
444 : : {// ganz neue Center
445 : 0 : bCenter = sal_True;
446 : 0 : nCenterStart = nColCnt;
447 : : }
448 : 0 : nCenterEnd = nColCnt + static_cast<SCCOL>(nRepeats);
449 : : }
450 : : else
451 : : {
452 [ # # ]: 0 : if( bCenter )
453 : : {// evtl. alte Center bemachen
454 [ # # ]: 0 : pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
455 : 0 : bCenter = false;
456 : : }
457 : : }
458 : :
459 : 0 : nColCnt = nColCnt + static_cast<SCCOL>(nRepeats);
460 : 0 : nColCnt++;
461 : :
462 : 0 : nCntDwn--;
463 : : }
464 : :
465 [ # # ]: 0 : if( bCenter )
466 : : // evtl. alte Center bemachen
467 [ # # ]: 0 : pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
468 [ + - ][ + - ]: 24 : }
469 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|