1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lotimpop.cxx,v $
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>
37 #include "document.hxx"
38 #include "rangenam.hxx"
40 #include "patattr.hxx"
41 #include "docpool.hxx"
42 #include "compiler.hxx"
46 #include "lotfntbf.hxx"
47 #include "lotform.hxx"
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
),
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
;
83 delete pLotusRoot
->pAttrTable
;
90 // no need 4 pLotusRoot anymore
91 aLotImpSemaphore
.release();
95 void ImportLotus::Bof( void )
97 UINT16 nFileCode
, nFileSub
, nSaveCnt
;
98 BYTE nMajorId
, nMinorId
, nFlags
;
102 Read( pLotusRoot
->aActRange
);
109 if( nFileSub
== 0x0004 )
111 if( nFileCode
== 0x1000 )
113 pLotusRoot
->eFirstType
= pLotusRoot
->eActType
= Lotus_WK3
;
115 else if( nFileCode
== 0x1002 )
117 pLotusRoot
->eFirstType
= pLotusRoot
->eActType
= Lotus_WK4
;
123 BOOL
ImportLotus::BofFm3( void )
125 UINT16 nFileCode
, 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;
144 if( !pD
->HasTable( static_cast<SCTAB
> (nLTab
) ) )
145 pD
->MakeTable( static_cast<SCTAB
> (nLTab
) );
157 // ACHTUNG: Korrekturfaktor nach 'Augenmass' ermittelt!
158 pD
->SetColWidth( static_cast<SCCOL
> (nCol
), static_cast<SCTAB
> (nLTab
), ( UINT16
) ( TWIPS_PER_CHAR
* 1.28 * nSpaces
) );
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;
186 pD
->SetColHidden(static_cast<SCCOL
>(nCol
), static_cast<SCCOL
>(nCol
), static_cast<SCTAB
>(nLTab
), true);
193 void ImportLotus::Userrange( void )
197 sal_Char
* pBuffer
= new sal_Char
[ 32 ];
201 pIn
->Read( pBuffer
, 16 );
202 pBuffer
[ 16 ] = ( sal_Char
) 0x00; // zur Sicherheit...
203 String
aName( pBuffer
, eQuellChar
);
207 pLotusRoot
->pRngNmBffWK3
->Add( aName
, aScRange
);
212 void ImportLotus::Errcell( void )
218 pD
->PutCell( aA
.Col(), aA
.Row(), aA
.Tab(), new ScStringCell( CREATE_STRING( "#ERR!" ) ), (BOOL
)TRUE
);
222 void ImportLotus::Nacell( void )
228 pD
->PutCell( aA
.Col(), aA
.Row(), aA
.Tab(), new ScStringCell( CREATE_STRING( "#NA!" ) ), (BOOL
)TRUE
);
232 void ImportLotus::Labelcell( void )
242 // aLabel.Convert( pLotusRoot->eCharsetQ );
244 pD
->PutCell( aA
.Col(), aA
.Row(), aA
.Tab(), new ScStringCell( aLabel
), (BOOL
)TRUE
);
248 void ImportLotus::Numbercell( void )
256 pD
->PutCell( aAddr
.Col(), aAddr
.Row(), aAddr
.Tab(),
257 new ScValueCell( fVal
), (BOOL
)TRUE
);
261 void ImportLotus::Smallnumcell( void )
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!" );
285 const ScTokenArray
* pErg
;
288 aConv
.Reset( aAddr
);
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
);
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!" );
313 UINT16 nRow
, nHeight
;
314 UINT16 nCnt
= ( 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 // ACHTUNG: QUICK-HACK gegen unerklaerliche Loops
372 pFontBuff
->SetName( nNum
, aName
);
376 void ImportLotus::Font_Type( void )
378 static const UINT16 nAnz
= 8;
382 for( nCnt
= 0 ; nCnt
< nAnz
; nCnt
++ )
385 pFontBuff
->SetType( nCnt
, nType
);
390 void ImportLotus::Font_Ysize( void )
392 static const UINT16 nAnz
= 8;
396 for( nCnt
= 0 ; nCnt
< nAnz
; nCnt
++ )
399 pFontBuff
->SetHeight( nCnt
, nSize
);
404 void ImportLotus::_Row( const UINT16 nRecLen
)
406 DBG_ASSERT( nExtTab
>= 0, "*ImportLotus::_Row(): Kann hier nicht sein!" );
410 UINT16 nCntDwn
= ( nRecLen
- 4 ) / 5;
415 BOOL bCenter
= FALSE
;
416 SCCOL nCenterStart
= 0, nCenterEnd
= 0;
425 pD
->SetRowHeight( static_cast<SCROW
> (nRow
), static_cast<SCTAB
> (nExtTab
), nHeight
);
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() )
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
;
452 nCenterStart
= nColCnt
;
454 nCenterEnd
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
459 {// evtl. alte Center bemachen
460 pD
->DoMerge( static_cast<SCTAB
> (nExtTab
), nCenterStart
, static_cast<SCROW
> (nRow
), nCenterEnd
, static_cast<SCROW
> (nRow
) );
465 nColCnt
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
472 // evtl. alte Center bemachen
473 pD
->DoMerge( static_cast<SCTAB
> (nExtTab
), nCenterStart
, static_cast<SCROW
> (nRow
), nCenterEnd
, static_cast<SCROW
> (nRow
) );