Update ooo320-m1
[ooovba.git] / sc / source / filter / lotus / lotimpop.cxx
blob8d887b0ed885925d9b4ef32b4c0a7735d8e4f817
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: lotimpop.cxx,v $
10 * $Revision: 1.13 $
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 #include "lotimpop.hxx"
34 #include <vos/mutex.hxx>
36 #include "attrib.hxx"
37 #include "document.hxx"
38 #include "rangenam.hxx"
39 #include "cell.hxx"
40 #include "patattr.hxx"
41 #include "docpool.hxx"
42 #include "compiler.hxx"
43 #include "global.hxx"
45 #include "root.hxx"
46 #include "lotfntbf.hxx"
47 #include "lotform.hxx"
48 #include "tool.h"
49 #include "namebuff.hxx"
50 #include "lotrange.hxx"
51 #include "lotattr.hxx"
54 static NAMESPACE_VOS( OMutex ) aLotImpSemaphore;
57 ImportLotus::ImportLotus( SvStream& aStream, ScDocument* pDoc, CharSet eQ ) :
58 ImportTyp( pDoc, eQ ),
59 pIn( &aStream ),
60 aConv( *pIn, eQ, FALSE )
62 // good point to start locking of import lotus
63 aLotImpSemaphore.acquire();
65 pLotusRoot = new LOTUS_ROOT;
66 pLotusRoot->pDoc = pDoc;
67 pLotusRoot->pRangeNames = new LotusRangeList;
68 pLotusRoot->pScRangeName = pDoc->GetRangeName();
69 pLotusRoot->eCharsetQ = eQ;
70 pLotusRoot->eFirstType = Lotus_X;
71 pLotusRoot->eActType = Lotus_X;
72 pLotusRoot->pRngNmBffWK3 = new RangeNameBufferWK3;
73 pFontBuff = pLotusRoot->pFontBuff = new LotusFontBuffer;
74 pLotusRoot->pAttrTable = new LotAttrTable;
78 ImportLotus::~ImportLotus()
80 delete pLotusRoot->pRangeNames;
81 delete pLotusRoot->pRngNmBffWK3;
82 delete pFontBuff;
83 delete pLotusRoot->pAttrTable;
84 delete pLotusRoot;
86 #ifdef DBG_UTIL
87 pLotusRoot = NULL;
88 #endif
90 // no need 4 pLotusRoot anymore
91 aLotImpSemaphore.release();
95 void ImportLotus::Bof( void )
97 UINT16 nFileCode, nFileSub, nSaveCnt;
98 BYTE nMajorId, nMinorId, nFlags;
100 Read( nFileCode );
101 Read( nFileSub );
102 Read( pLotusRoot->aActRange );
103 Read( nSaveCnt );
104 Read( nMajorId );
105 Read( nMinorId );
106 Skip( 1 );
107 Read( nFlags );
109 if( nFileSub == 0x0004 )
111 if( nFileCode == 0x1000 )
112 {// <= WK3
113 pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK3;
115 else if( nFileCode == 0x1002 )
116 {// WK4
117 pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK4;
123 BOOL ImportLotus::BofFm3( void )
125 UINT16 nFileCode, nFileSub;
127 Read( nFileCode );
128 Read( nFileSub );
130 return ( nFileCode == 0x8007 && ( nFileSub == 0x0000 || nFileSub == 0x00001 ) );
134 void ImportLotus::Columnwidth( UINT16 nRecLen )
136 DBG_ASSERT( nRecLen >= 4, "*ImportLotus::Columnwidth(): Record zu kurz!" );
138 BYTE nLTab, nWindow2;
139 UINT16 nCnt = ( nRecLen - 4 ) / 2;
141 Read( nLTab );
142 Read( nWindow2 );
144 if( !pD->HasTable( static_cast<SCTAB> (nLTab) ) )
145 pD->MakeTable( static_cast<SCTAB> (nLTab) );
147 if( !nWindow2 )
149 Skip( 2 );
151 BYTE nCol, nSpaces;
153 while( nCnt )
155 Read( nCol );
156 Read( nSpaces );
157 // ACHTUNG: Korrekturfaktor nach 'Augenmass' ermittelt!
158 pD->SetColWidth( static_cast<SCCOL> (nCol), static_cast<SCTAB> (nLTab), ( UINT16 ) ( TWIPS_PER_CHAR * 1.28 * nSpaces ) );
160 nCnt--;
166 void ImportLotus::Hiddencolumn( UINT16 nRecLen )
168 DBG_ASSERT( nRecLen >= 4, "*ImportLotus::Hiddencolumn(): Record zu kurz!" );
170 BYTE nLTab, nWindow2;
171 UINT16 nCnt = ( nRecLen - 4 ) / 2;
173 Read( nLTab );
174 Read( nWindow2 );
176 if( !nWindow2 )
178 Skip( 2 );
180 BYTE nCol;
182 while( nCnt )
184 Read( nCol );
186 pD->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), static_cast<SCTAB>(nLTab), true);
187 nCnt--;
193 void ImportLotus::Userrange( void )
195 UINT16 nRangeType;
196 ScRange aScRange;
197 sal_Char* pBuffer = new sal_Char[ 32 ];
199 Read( nRangeType );
201 pIn->Read( pBuffer, 16 );
202 pBuffer[ 16 ] = ( sal_Char ) 0x00; // zur Sicherheit...
203 String aName( pBuffer, eQuellChar );
205 Read( aScRange );
207 pLotusRoot->pRngNmBffWK3->Add( aName, aScRange );
208 delete[] pBuffer;
212 void ImportLotus::Errcell( void )
214 ScAddress aA;
216 Read( aA );
218 pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( CREATE_STRING( "#ERR!" ) ), (BOOL)TRUE );
222 void ImportLotus::Nacell( void )
224 ScAddress aA;
226 Read( aA );
228 pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( CREATE_STRING( "#NA!" ) ), (BOOL)TRUE );
232 void ImportLotus::Labelcell( void )
234 ScAddress aA;
235 String aLabel;
236 sal_Char cAlign;
238 Read( aA );
239 Read( cAlign );
240 Read( aLabel );
242 // aLabel.Convert( pLotusRoot->eCharsetQ );
244 pD->PutCell( aA.Col(), aA.Row(), aA.Tab(), new ScStringCell( aLabel ), (BOOL)TRUE );
248 void ImportLotus::Numbercell( void )
250 ScAddress aAddr;
251 double fVal;
253 Read( aAddr );
254 Read( fVal );
256 pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
257 new ScValueCell( fVal ), (BOOL)TRUE );
261 void ImportLotus::Smallnumcell( void )
263 ScAddress aAddr;
264 INT16 nVal;
266 Read( aAddr );
267 Read( nVal );
269 pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(),
270 new ScValueCell( SnumToDouble( nVal ) ), ( BOOL ) TRUE );
274 ScFormulaCell *ImportLotus::Formulacell( UINT16 n )
276 DBG_ASSERT( pIn, "-ImportLotus::Formulacell(): Null-Stream -> Rums!" );
278 ScAddress aAddr;
280 Read( aAddr );
281 Skip( 10 );
283 n -= 14;
285 const ScTokenArray* pErg;
286 INT32 nRest = n;
288 aConv.Reset( aAddr );
289 aConv.SetWK3();
290 aConv.Convert( pErg, nRest );
292 ScFormulaCell* pZelle = new ScFormulaCell( pD, aAddr, pErg );
294 pZelle->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
296 pD->PutCell( aAddr.Col(), aAddr.Row(), aAddr.Tab(), pZelle, (BOOL)TRUE );
298 return NULL;
302 void ImportLotus::Read( String &r )
304 ScfTools::AppendCString( *pIn, r, eQuellChar );
308 void ImportLotus::RowPresentation( UINT16 nRecLen )
310 DBG_ASSERT( nRecLen > 4, "*ImportLotus::RowPresentation(): Record zu kurz!" );
312 BYTE nLTab, nFlags;
313 UINT16 nRow, nHeight;
314 UINT16 nCnt = ( nRecLen - 4 ) / 8;
316 Read( nLTab );
317 Skip( 1 );
319 while( nCnt )
321 Read( nRow );
322 Read( nHeight );
323 Skip( 2 );
324 Read( nFlags );
325 Skip( 1 );
327 if( nFlags & 0x02 ) // Fixed / Strech to fit fonts
328 { // fixed
329 // Height in Lotus in 1/32 Points
330 nHeight *= 20; // -> 32 * TWIPS
331 nHeight /= 32; // -> TWIPS
333 pD->SetRowFlags( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab), pD->GetRowFlags( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab) ) | CR_MANUALSIZE );
335 pD->SetRowHeight( static_cast<SCROW> (nRow), static_cast<SCTAB> (nLTab), nHeight );
338 nCnt--;
343 void ImportLotus::NamedSheet( void )
345 UINT16 nLTab;
346 String aName;
348 Read( nLTab );
349 Read( aName );
351 if( pD->HasTable( static_cast<SCTAB> (nLTab) ) )
352 pD->RenameTab( static_cast<SCTAB> (nLTab), aName );
353 else
354 pD->InsertTab( static_cast<SCTAB> (nLTab), aName );
358 void ImportLotus::Font_Face( void )
360 BYTE nNum;
361 String aName;
363 Read( nNum );
365 // ACHTUNG: QUICK-HACK gegen unerklaerliche Loops
366 if( nNum > 7 )
367 return;
368 // ACHTUNG
370 Read( aName );
372 pFontBuff->SetName( nNum, aName );
376 void ImportLotus::Font_Type( void )
378 static const UINT16 nAnz = 8;
379 UINT16 nCnt;
380 UINT16 nType;
382 for( nCnt = 0 ; nCnt < nAnz ; nCnt++ )
384 Read( nType );
385 pFontBuff->SetType( nCnt, nType );
390 void ImportLotus::Font_Ysize( void )
392 static const UINT16 nAnz = 8;
393 UINT16 nCnt;
394 UINT16 nSize;
396 for( nCnt = 0 ; nCnt < nAnz ; nCnt++ )
398 Read( nSize );
399 pFontBuff->SetHeight( nCnt, nSize );
404 void ImportLotus::_Row( const UINT16 nRecLen )
406 DBG_ASSERT( nExtTab >= 0, "*ImportLotus::_Row(): Kann hier nicht sein!" );
408 UINT16 nRow;
409 UINT16 nHeight;
410 UINT16 nCntDwn = ( nRecLen - 4 ) / 5;
411 SCCOL nColCnt = 0;
412 UINT8 nRepeats;
413 LotAttrWK3 aAttr;
415 BOOL bCenter = FALSE;
416 SCCOL nCenterStart = 0, nCenterEnd = 0;
418 Read( nRow );
419 Read( nHeight );
421 nHeight &= 0x0FFF;
422 nHeight *= 22;
424 if( nHeight )
425 pD->SetRowHeight( static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab), nHeight );
427 while( nCntDwn )
429 Read( aAttr );
430 Read( nRepeats );
432 if( aAttr.HasStyles() )
433 pLotusRoot->pAttrTable->SetAttr(
434 nColCnt, static_cast<SCCOL> ( nColCnt + nRepeats ), static_cast<SCROW> (nRow), aAttr );
436 // hier und NICHT in class LotAttrTable, weil nur Attributiert wird,
437 // wenn die anderen Attribute gesetzt sind
438 // -> bei Center-Attribute wird generell zentriert gesetzt
439 if( aAttr.IsCentered() )
441 if( bCenter )
443 if( pD->HasData( nColCnt, static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab) ) )
444 {// neue Center nach vorheriger Center
445 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
446 nCenterStart = nColCnt;
449 else
450 {// ganz neue Center
451 bCenter = TRUE;
452 nCenterStart = nColCnt;
454 nCenterEnd = nColCnt + static_cast<SCCOL>(nRepeats);
456 else
458 if( bCenter )
459 {// evtl. alte Center bemachen
460 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
461 bCenter = FALSE;
465 nColCnt = nColCnt + static_cast<SCCOL>(nRepeats);
466 nColCnt++;
468 nCntDwn--;
471 if( bCenter )
472 // evtl. alte Center bemachen
473 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );