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 "lotfilter.hxx"
21 #include "lotimpop.hxx"
22 #include <osl/mutex.hxx>
25 #include "document.hxx"
26 #include "rangenam.hxx"
27 #include "formulacell.hxx"
28 #include "patattr.hxx"
29 #include "docpool.hxx"
30 #include "compiler.hxx"
34 #include "lotfntbf.hxx"
35 #include "lotform.hxx"
37 #include "namebuff.hxx"
38 #include "lotrange.hxx"
39 #include "lotattr.hxx"
40 #include "stringutil.hxx"
42 LOTUS_ROOT::LOTUS_ROOT( ScDocument
* pDocP
, rtl_TextEncoding eQ
)
45 pRangeNames( new LotusRangeList(this)),
46 pScRangeName( pDocP
->GetRangeName()),
50 pRngNmBffWK3( new RangeNameBufferWK3(this)),
51 pFontBuff( new LotusFontBuffer
),
52 pAttrTable( new LotAttrTable(this))
56 LOTUS_ROOT::~LOTUS_ROOT()
64 static osl::Mutex aLotImpSemaphore
;
66 ImportLotus::ImportLotus(LotusContext
&rContext
, SvStream
& aStream
, ScDocument
* pDoc
, rtl_TextEncoding eQ
)
69 , aConv(rContext
, *pIn
, pDoc
->GetSharedStringPool(), eQ
, false)
73 // good point to start locking of import lotus
74 aLotImpSemaphore
.acquire();
76 rContext
.pLotusRoot
= new LOTUS_ROOT(pDoc
, eQ
);
79 ImportLotus::~ImportLotus()
81 LotusContext
&rContext
= aConv
.getContext();
82 delete rContext
.pLotusRoot
;
83 rContext
.pLotusRoot
= NULL
;
85 // no need 4 pLotusRoot anymore
86 aLotImpSemaphore
.release();
89 void ImportLotus::Bof()
91 sal_uInt16 nFileCode
, nFileSub
, nSaveCnt
;
92 sal_uInt8 nMajorId
, nMinorId
, nFlags
;
96 LotusContext
&rContext
= aConv
.getContext();
97 Read( rContext
.pLotusRoot
->aActRange
);
104 if( nFileSub
== 0x0004 )
106 if( nFileCode
== 0x1000 )
108 rContext
.pLotusRoot
->eFirstType
= rContext
.pLotusRoot
->eActType
= Lotus_WK3
;
110 else if( nFileCode
== 0x1002 )
112 rContext
.pLotusRoot
->eFirstType
= rContext
.pLotusRoot
->eActType
= Lotus_WK4
;
117 bool ImportLotus::BofFm3()
119 sal_uInt16 nFileCode
, nFileSub
;
124 return ( nFileCode
== 0x8007 && ( nFileSub
== 0x0000 || nFileSub
== 0x00001 ) );
127 void ImportLotus::Columnwidth( sal_uInt16 nRecLen
)
129 OSL_ENSURE( nRecLen
>= 4, "*ImportLotus::Columnwidth(): Record zu kurz!" );
131 sal_uInt8 nLTab
, nWindow2
;
132 sal_uInt16 nCnt
= (nRecLen
< 4) ? 0 : ( nRecLen
- 4 ) / 2;
137 if( !pD
->HasTable( static_cast<SCTAB
> (nLTab
) ) )
138 pD
->MakeTable( static_cast<SCTAB
> (nLTab
) );
144 sal_uInt8 nCol
, nSpaces
;
150 // Attention: ambiguous Correction factor!
151 pD
->SetColWidth( static_cast<SCCOL
> (nCol
), static_cast<SCTAB
> (nLTab
), ( sal_uInt16
) ( TWIPS_PER_CHAR
* 1.28 * nSpaces
) );
158 void ImportLotus::Hiddencolumn( sal_uInt16 nRecLen
)
160 OSL_ENSURE( nRecLen
>= 4, "*ImportLotus::Hiddencolumn(): Record too short!" );
162 sal_uInt8 nLTab
, nWindow2
;
163 sal_uInt16 nCnt
= (nRecLen
< 4) ? 0 : ( nRecLen
- 4 ) / 2;
178 pD
->SetColHidden(static_cast<SCCOL
>(nCol
), static_cast<SCCOL
>(nCol
), static_cast<SCTAB
>(nLTab
), true);
184 void ImportLotus::Userrange()
186 sal_uInt16 nRangeType
;
191 sal_Char aBuffer
[ 17 ];
192 pIn
->Read( aBuffer
, 16 );
194 OUString
aName( aBuffer
, strlen(aBuffer
), eQuellChar
);
198 LotusContext
&rContext
= aConv
.getContext();
199 rContext
.pLotusRoot
->pRngNmBffWK3
->Add( aName
, aScRange
);
202 void ImportLotus::Errcell()
208 ScSetStringParam aParam
;
209 aParam
.setTextInput();
210 pD
->EnsureTable(aA
.Tab());
211 pD
->SetString(aA
, "#ERR!", &aParam
);
214 void ImportLotus::Nacell()
220 ScSetStringParam aParam
;
221 aParam
.setTextInput();
222 pD
->EnsureTable(aA
.Tab());
223 pD
->SetString(aA
, "#NA!", &aParam
);
226 void ImportLotus::Labelcell()
236 ScSetStringParam aParam
;
237 aParam
.setTextInput();
238 pD
->EnsureTable(aA
.Tab());
239 pD
->SetString(aA
, aLabel
, &aParam
);
242 void ImportLotus::Numbercell()
250 pD
->EnsureTable(aAddr
.Tab());
251 pD
->SetValue(aAddr
, fVal
);
254 void ImportLotus::Smallnumcell()
262 pD
->EnsureTable(aAddr
.Tab());
263 pD
->SetValue(aAddr
, SnumToDouble(nVal
));
266 ScFormulaCell
*ImportLotus::Formulacell( sal_uInt16 n
)
268 OSL_ENSURE( pIn
, "-ImportLotus::Formulacell(): Null-Stream!" );
275 n
-= (n
> 14) ? 14 : n
;
277 const ScTokenArray
* pErg
;
280 aConv
.Reset( aAddr
);
282 aConv
.Convert( pErg
, nRest
);
284 ScFormulaCell
* pCell
= pErg
? new ScFormulaCell(pD
, aAddr
, *pErg
) : new ScFormulaCell(pD
, aAddr
);
285 pCell
->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE
);
286 pD
->EnsureTable(aAddr
.Tab());
287 pD
->SetFormulaCell(aAddr
, pCell
);
292 void ImportLotus::Read( OUString
&r
)
294 ScfTools::AppendCString( *pIn
, r
, eQuellChar
);
297 void ImportLotus::RowPresentation( sal_uInt16 nRecLen
)
299 OSL_ENSURE( nRecLen
> 4, "*ImportLotus::RowPresentation(): Record too short!" );
301 sal_uInt8 nLTab
, nFlags
;
302 sal_uInt16 nRow
, nHeight
;
303 sal_uInt16 nCnt
= (nRecLen
< 4) ? 0 : ( nRecLen
- 4 ) / 8;
316 if( nFlags
& 0x02 ) // Fixed / Stretch to fit fonts
318 // Height in Lotus in 1/32 Points
319 nHeight
*= 20; // -> 32 * TWIPS
320 nHeight
/= 32; // -> TWIPS
322 pD
->SetRowFlags( static_cast<SCROW
> (nRow
), static_cast<SCTAB
> (nLTab
), pD
->GetRowFlags( static_cast<SCROW
> (nRow
), static_cast<SCTAB
> (nLTab
) ) | CR_MANUALSIZE
);
324 pD
->SetRowHeight( static_cast<SCROW
> (nRow
), static_cast<SCTAB
> (nLTab
), nHeight
);
331 void ImportLotus::NamedSheet()
333 sal_uInt16
nTmpTab(0);
338 SCTAB
nLTab(SanitizeTab(static_cast<SCTAB
>(nTmpTab
)));
340 if (pD
->HasTable(nLTab
))
341 pD
->RenameTab(nLTab
, aName
);
343 pD
->InsertTab(nLTab
, aName
);
346 void ImportLotus::Font_Face()
353 if( nNum
>= LotusFontBuffer::nSize
)
358 LotusContext
&rContext
= aConv
.getContext();
359 rContext
.pLotusRoot
->pFontBuff
->SetName( nNum
, aName
);
362 void ImportLotus::Font_Type()
364 LotusContext
&rContext
= aConv
.getContext();
365 for( sal_uInt16 nCnt
= 0 ; nCnt
< LotusFontBuffer::nSize
; nCnt
++ )
369 rContext
.pLotusRoot
->pFontBuff
->SetType( nCnt
, nType
);
373 void ImportLotus::Font_Ysize()
375 LotusContext
&rContext
= aConv
.getContext();
376 for( sal_uInt16 nCnt
= 0 ; nCnt
< LotusFontBuffer::nSize
; nCnt
++ )
380 rContext
.pLotusRoot
->pFontBuff
->SetHeight( nCnt
, nSize
);
384 void ImportLotus::_Row( const sal_uInt16 nRecLen
)
386 OSL_ENSURE( nExtTab
>= 0, "*ImportLotus::_Row(): not possible!" );
388 sal_uInt16 nCntDwn
= (nRecLen
< 4) ? 0 : ( nRecLen
- 4 ) / 5;
393 bool bCenter
= false;
394 SCCOL nCenterStart
= 0, nCenterEnd
= 0;
396 sal_uInt16
nTmpRow(0);
398 SCROW
nRow(SanitizeRow(static_cast<SCROW
>(nTmpRow
)));
399 sal_uInt16
nHeight(0);
405 SCTAB
nDestTab(static_cast<SCTAB
>(nExtTab
));
408 pD
->SetRowHeight(nRow
, nDestTab
, nHeight
);
410 LotusContext
&rContext
= aConv
.getContext();
416 if( aAttr
.HasStyles() )
417 rContext
.pLotusRoot
->pAttrTable
->SetAttr(
418 nColCnt
, static_cast<SCCOL
> ( nColCnt
+ nRepeats
), nRow
, aAttr
);
420 // Do this here and NOT in class LotAttrTable, as we only add attributes if the other
421 // attributes are set
422 // -> for Center-Attribute default is centered
423 if( aAttr
.IsCentered() )
427 if (pD
->HasData(nColCnt
, nRow
, nDestTab
))
429 // new Center after previous Center
430 pD
->DoMerge(nDestTab
, nCenterStart
, nRow
, nCenterEnd
, nRow
);
431 nCenterStart
= nColCnt
;
438 nCenterStart
= nColCnt
;
440 nCenterEnd
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
446 // possibly reset old Center
447 pD
->DoMerge(nDestTab
, nCenterStart
, nRow
, nCenterEnd
, nRow
);
452 nColCnt
= nColCnt
+ static_cast<SCCOL
>(nRepeats
);
459 // possibly reset old Center
460 pD
->DoMerge(nDestTab
, nCenterStart
, nRow
, nCenterEnd
, nRow
);
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */