Bump version to 4.3-4
[LibreOffice.git] / sc / source / filter / lotus / lotimpop.cxx
bloba17b94d4b8fa8e639b021ec61c33a158d7d0da04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "lotimpop.hxx"
21 #include <osl/mutex.hxx>
23 #include "attrib.hxx"
24 #include "document.hxx"
25 #include "rangenam.hxx"
26 #include "formulacell.hxx"
27 #include "patattr.hxx"
28 #include "docpool.hxx"
29 #include "compiler.hxx"
30 #include "global.hxx"
32 #include "root.hxx"
33 #include "lotfntbf.hxx"
34 #include "lotform.hxx"
35 #include "tool.h"
36 #include "namebuff.hxx"
37 #include "lotrange.hxx"
38 #include "lotattr.hxx"
39 #include "stringutil.hxx"
41 LOTUS_ROOT::LOTUS_ROOT( ScDocument* pDocP, rtl_TextEncoding eQ )
43 pDoc( pDocP),
44 pRangeNames( new LotusRangeList),
45 pScRangeName( pDocP->GetRangeName()),
46 eCharsetQ( eQ),
47 eFirstType( Lotus_X),
48 eActType( Lotus_X),
49 pRngNmBffWK3( new RangeNameBufferWK3),
50 pFontBuff( new LotusFontBuffer),
51 pAttrTable( new LotAttrTable(this))
56 LOTUS_ROOT::~LOTUS_ROOT()
58 delete pRangeNames;
59 delete pRngNmBffWK3;
60 delete pFontBuff;
61 delete pAttrTable;
65 static osl::Mutex aLotImpSemaphore;
67 ImportLotus::ImportLotus( SvStream& aStream, ScDocument* pDoc, rtl_TextEncoding eQ )
68 : ImportTyp(pDoc, eQ)
69 , pIn(&aStream)
70 , aConv(*pIn, pDoc->GetSharedStringPool(), eQ, false)
71 , nTab(0)
72 , nExtTab(0)
74 // good point to start locking of import lotus
75 aLotImpSemaphore.acquire();
77 pLotusRoot = new LOTUS_ROOT(pDoc, eQ);
80 ImportLotus::~ImportLotus()
82 delete pLotusRoot;
83 pLotusRoot = NULL;
85 // no need 4 pLotusRoot anymore
86 aLotImpSemaphore.release();
90 void ImportLotus::Bof( void )
92 sal_uInt16 nFileCode, nFileSub, nSaveCnt;
93 sal_uInt8 nMajorId, nMinorId, nFlags;
95 Read( nFileCode );
96 Read( nFileSub );
97 Read( pLotusRoot->aActRange );
98 Read( nSaveCnt );
99 Read( nMajorId );
100 Read( nMinorId );
101 Skip( 1 );
102 Read( nFlags );
104 if( nFileSub == 0x0004 )
106 if( nFileCode == 0x1000 )
107 {// <= WK3
108 pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK3;
110 else if( nFileCode == 0x1002 )
111 {// WK4
112 pLotusRoot->eFirstType = pLotusRoot->eActType = Lotus_WK4;
118 bool ImportLotus::BofFm3( void )
120 sal_uInt16 nFileCode, nFileSub;
122 Read( nFileCode );
123 Read( nFileSub );
125 return ( nFileCode == 0x8007 && ( nFileSub == 0x0000 || nFileSub == 0x00001 ) );
129 void ImportLotus::Columnwidth( sal_uInt16 nRecLen )
131 OSL_ENSURE( nRecLen >= 4, "*ImportLotus::Columnwidth(): Record zu kurz!" );
133 sal_uInt8 nLTab, nWindow2;
134 sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
136 Read( nLTab );
137 Read( nWindow2 );
139 if( !pD->HasTable( static_cast<SCTAB> (nLTab) ) )
140 pD->MakeTable( static_cast<SCTAB> (nLTab) );
142 if( !nWindow2 )
144 Skip( 2 );
146 sal_uInt8 nCol, nSpaces;
148 while( nCnt )
150 Read( nCol );
151 Read( nSpaces );
152 // ACHTUNG: Korrekturfaktor nach 'Augenmass' ermittelt!
153 pD->SetColWidth( static_cast<SCCOL> (nCol), static_cast<SCTAB> (nLTab), ( sal_uInt16 ) ( TWIPS_PER_CHAR * 1.28 * nSpaces ) );
155 nCnt--;
161 void ImportLotus::Hiddencolumn( sal_uInt16 nRecLen )
163 OSL_ENSURE( nRecLen >= 4, "*ImportLotus::Hiddencolumn(): Record zu kurz!" );
165 sal_uInt8 nLTab, nWindow2;
166 sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 2;
168 Read( nLTab );
169 Read( nWindow2 );
171 if( !nWindow2 )
173 Skip( 2 );
175 sal_uInt8 nCol;
177 while( nCnt )
179 Read( nCol );
181 pD->SetColHidden(static_cast<SCCOL>(nCol), static_cast<SCCOL>(nCol), static_cast<SCTAB>(nLTab), true);
182 nCnt--;
188 void ImportLotus::Userrange( void )
190 sal_uInt16 nRangeType;
191 ScRange aScRange;
193 Read( nRangeType );
195 sal_Char aBuffer[ 17 ];
196 pIn->Read( aBuffer, 16 );
197 aBuffer[ 16 ] = 0;
198 OUString aName( aBuffer, strlen(aBuffer), eQuellChar );
200 Read( aScRange );
202 pLotusRoot->pRngNmBffWK3->Add( aName, aScRange );
206 void ImportLotus::Errcell( void )
208 ScAddress aA;
210 Read( aA );
212 ScSetStringParam aParam;
213 aParam.setTextInput();
214 pD->EnsureTable(aA.Tab());
215 pD->SetString(aA, "#ERR!", &aParam);
219 void ImportLotus::Nacell( void )
221 ScAddress aA;
223 Read( aA );
225 ScSetStringParam aParam;
226 aParam.setTextInput();
227 pD->EnsureTable(aA.Tab());
228 pD->SetString(aA, "#NA!", &aParam);
232 void ImportLotus::Labelcell( void )
234 ScAddress aA;
235 OUString aLabel;
236 sal_Char cAlign;
238 Read( aA );
239 Read( cAlign );
240 Read( aLabel );
242 ScSetStringParam aParam;
243 aParam.setTextInput();
244 pD->EnsureTable(aA.Tab());
245 pD->SetString(aA, aLabel, &aParam);
249 void ImportLotus::Numbercell( void )
251 ScAddress aAddr;
252 double fVal;
254 Read( aAddr );
255 Read( fVal );
257 pD->EnsureTable(aAddr.Tab());
258 pD->SetValue(aAddr, fVal);
262 void ImportLotus::Smallnumcell( void )
264 ScAddress aAddr;
265 sal_Int16 nVal;
267 Read( aAddr );
268 Read( nVal );
270 pD->EnsureTable(aAddr.Tab());
271 pD->SetValue(aAddr, SnumToDouble(nVal));
275 ScFormulaCell *ImportLotus::Formulacell( sal_uInt16 n )
277 OSL_ENSURE( pIn, "-ImportLotus::Formulacell(): Null-Stream -> Rums!" );
279 ScAddress aAddr;
281 Read( aAddr );
282 Skip( 10 );
284 n -= (n > 14) ? 14 : n;
286 const ScTokenArray* pErg;
287 sal_Int32 nRest = n;
289 aConv.Reset( aAddr );
290 aConv.SetWK3();
291 aConv.Convert( pErg, nRest );
293 ScFormulaCell* pCell = pErg ? new ScFormulaCell(pD, aAddr, *pErg) : new ScFormulaCell(pD, aAddr);
294 pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
295 pD->EnsureTable(aAddr.Tab());
296 pD->SetFormulaCell(aAddr, pCell);
298 return NULL;
302 void ImportLotus::Read( OUString &r )
304 ScfTools::AppendCString( *pIn, r, eQuellChar );
308 void ImportLotus::RowPresentation( sal_uInt16 nRecLen )
310 OSL_ENSURE( nRecLen > 4, "*ImportLotus::RowPresentation(): Record zu kurz!" );
312 sal_uInt8 nLTab, nFlags;
313 sal_uInt16 nRow, nHeight;
314 sal_uInt16 nCnt = (nRecLen < 4) ? 0 : ( 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 sal_uInt16 nLTab;
346 OUString 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 sal_uInt8 nNum;
361 OUString aName;
363 Read( nNum );
365 if( nNum >= LotusFontBuffer::nSize )
366 return; // nonsense
368 Read( aName );
370 pLotusRoot->pFontBuff->SetName( nNum, aName );
374 void ImportLotus::Font_Type( void )
376 for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
378 sal_uInt16 nType;
379 Read( nType );
380 pLotusRoot->pFontBuff->SetType( nCnt, nType );
385 void ImportLotus::Font_Ysize( void )
387 for( sal_uInt16 nCnt = 0 ; nCnt < LotusFontBuffer::nSize ; nCnt++ )
389 sal_uInt16 nSize;
390 Read( nSize );
391 pLotusRoot->pFontBuff->SetHeight( nCnt, nSize );
396 void ImportLotus::_Row( const sal_uInt16 nRecLen )
398 OSL_ENSURE( nExtTab >= 0, "*ImportLotus::_Row(): Kann hier nicht sein!" );
400 sal_uInt16 nRow;
401 sal_uInt16 nHeight;
402 sal_uInt16 nCntDwn = (nRecLen < 4) ? 0 : ( nRecLen - 4 ) / 5;
403 SCCOL nColCnt = 0;
404 sal_uInt8 nRepeats;
405 LotAttrWK3 aAttr;
407 bool bCenter = false;
408 SCCOL nCenterStart = 0, nCenterEnd = 0;
410 Read( nRow );
411 Read( nHeight );
413 nHeight &= 0x0FFF;
414 nHeight *= 22;
416 if( nHeight )
417 pD->SetRowHeight( static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab), nHeight );
419 while( nCntDwn )
421 Read( aAttr );
422 Read( nRepeats );
424 if( aAttr.HasStyles() )
425 pLotusRoot->pAttrTable->SetAttr(
426 nColCnt, static_cast<SCCOL> ( nColCnt + nRepeats ), static_cast<SCROW> (nRow), aAttr );
428 // hier und NICHT in class LotAttrTable, weil nur Attributiert wird,
429 // wenn die anderen Attribute gesetzt sind
430 // -> bei Center-Attribute wird generell zentriert gesetzt
431 if( aAttr.IsCentered() )
433 if( bCenter )
435 if( pD->HasData( nColCnt, static_cast<SCROW> (nRow), static_cast<SCTAB> (nExtTab) ) )
436 {// neue Center nach vorheriger Center
437 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
438 nCenterStart = nColCnt;
441 else
442 {// ganz neue Center
443 bCenter = true;
444 nCenterStart = nColCnt;
446 nCenterEnd = nColCnt + static_cast<SCCOL>(nRepeats);
448 else
450 if( bCenter )
451 {// evtl. alte Center bemachen
452 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
453 bCenter = false;
457 nColCnt = nColCnt + static_cast<SCCOL>(nRepeats);
458 nColCnt++;
460 nCntDwn--;
463 if( bCenter )
464 // evtl. alte Center bemachen
465 pD->DoMerge( static_cast<SCTAB> (nExtTab), nCenterStart, static_cast<SCROW> (nRow), nCenterEnd, static_cast<SCROW> (nRow) );
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */