1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include "document.hxx"
25 #include "rangenam.hxx"
26 #include "formulacell.hxx"
27 #include "patattr.hxx"
28 #include "docpool.hxx"
29 #include "compiler.hxx"
33 #include "lotfntbf.hxx"
34 #include "lotform.hxx"
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
)
44 pRangeNames( new LotusRangeList
),
45 pScRangeName( pDocP
->GetRangeName()),
49 pRngNmBffWK3( new RangeNameBufferWK3
),
50 pFontBuff( new LotusFontBuffer
),
51 pAttrTable( new LotAttrTable(this))
56 LOTUS_ROOT::~LOTUS_ROOT()
65 static osl::Mutex aLotImpSemaphore
;
67 ImportLotus::ImportLotus( SvStream
& aStream
, ScDocument
* pDoc
, rtl_TextEncoding eQ
)
70 , aConv(*pIn
, pDoc
->GetSharedStringPool(), eQ
, false)
74 // good point to start locking of import lotus
75 aLotImpSemaphore
.acquire();
77 pLotusRoot
= new LOTUS_ROOT(pDoc
, eQ
);
80 ImportLotus::~ImportLotus()
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
;
97 Read( pLotusRoot
->aActRange
);
104 if( nFileSub
== 0x0004 )
106 if( nFileCode
== 0x1000 )
108 pLotusRoot
->eFirstType
= pLotusRoot
->eActType
= Lotus_WK3
;
110 else if( nFileCode
== 0x1002 )
112 pLotusRoot
->eFirstType
= pLotusRoot
->eActType
= Lotus_WK4
;
118 bool ImportLotus::BofFm3( void )
120 sal_uInt16 nFileCode
, 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;
139 if( !pD
->HasTable( static_cast<SCTAB
> (nLTab
) ) )
140 pD
->MakeTable( static_cast<SCTAB
> (nLTab
) );
146 sal_uInt8 nCol
, 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
) );
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;
181 pD
->SetColHidden(static_cast<SCCOL
>(nCol
), static_cast<SCCOL
>(nCol
), static_cast<SCTAB
>(nLTab
), true);
188 void ImportLotus::Userrange( void )
190 sal_uInt16 nRangeType
;
195 sal_Char aBuffer
[ 17 ];
196 pIn
->Read( aBuffer
, 16 );
198 OUString
aName( aBuffer
, strlen(aBuffer
), eQuellChar
);
202 pLotusRoot
->pRngNmBffWK3
->Add( aName
, aScRange
);
206 void ImportLotus::Errcell( void )
212 ScSetStringParam aParam
;
213 aParam
.setTextInput();
214 pD
->EnsureTable(aA
.Tab());
215 pD
->SetString(aA
, "#ERR!", &aParam
);
219 void ImportLotus::Nacell( void )
225 ScSetStringParam aParam
;
226 aParam
.setTextInput();
227 pD
->EnsureTable(aA
.Tab());
228 pD
->SetString(aA
, "#NA!", &aParam
);
232 void ImportLotus::Labelcell( void )
242 ScSetStringParam aParam
;
243 aParam
.setTextInput();
244 pD
->EnsureTable(aA
.Tab());
245 pD
->SetString(aA
, aLabel
, &aParam
);
249 void ImportLotus::Numbercell( void )
257 pD
->EnsureTable(aAddr
.Tab());
258 pD
->SetValue(aAddr
, fVal
);
262 void ImportLotus::Smallnumcell( void )
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!" );
284 n
-= (n
> 14) ? 14 : n
;
286 const ScTokenArray
* pErg
;
289 aConv
.Reset( aAddr
);
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
);
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;
327 if( nFlags
& 0x02 ) // Fixed / Strech to fit fonts
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
);
343 void ImportLotus::NamedSheet( void )
351 if( pD
->HasTable( static_cast<SCTAB
> (nLTab
) ) )
352 pD
->RenameTab( static_cast<SCTAB
> (nLTab
), aName
);
354 pD
->InsertTab( static_cast<SCTAB
> (nLTab
), aName
);
358 void ImportLotus::Font_Face( void )
365 if( nNum
>= LotusFontBuffer::nSize
)
370 pLotusRoot
->pFontBuff
->SetName( nNum
, aName
);
374 void ImportLotus::Font_Type( void )
376 for( sal_uInt16 nCnt
= 0 ; nCnt
< LotusFontBuffer::nSize
; nCnt
++ )
380 pLotusRoot
->pFontBuff
->SetType( nCnt
, nType
);
385 void ImportLotus::Font_Ysize( void )
387 for( sal_uInt16 nCnt
= 0 ; nCnt
< LotusFontBuffer::nSize
; nCnt
++ )
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!" );
402 sal_uInt16 nCntDwn
= (nRecLen
< 4) ? 0 : ( nRecLen
- 4 ) / 5;
407 bool bCenter
= false;
408 SCCOL nCenterStart
= 0, nCenterEnd
= 0;
417 pD
->SetRowHeight( static_cast<SCROW
> (nRow
), static_cast<SCTAB
> (nExtTab
), nHeight
);
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() )
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
;
444 nCenterStart
= nColCnt
;
446 nCenterEnd
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
451 {// evtl. alte Center bemachen
452 pD
->DoMerge( static_cast<SCTAB
> (nExtTab
), nCenterStart
, static_cast<SCROW
> (nRow
), nCenterEnd
, static_cast<SCROW
> (nRow
) );
457 nColCnt
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
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: */