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 "scitems.hxx"
21 #include <svx/algitem.hxx>
22 #include <editeng/justifyitem.hxx>
23 #include <svl/zforlist.hxx>
25 #include "rangenam.hxx"
26 #include "compiler.hxx"
31 #include "lotrange.hxx"
32 #include "namebuff.hxx"
34 #include "stringutil.hxx"
35 #include "tokenarray.hxx"
36 #include "lotfilter.hxx"
40 void PutFormString(LotusContext
& rContext
, SCCOL nCol
, SCROW nRow
, SCTAB nTab
, sal_Char
* pString
)
42 // evaluate Label-Format
43 OSL_ENSURE( pString
!= nullptr, "PutFormString(): pString == NULL" );
48 SvxHorJustifyItem
* pJustify
= nullptr;
54 case '"': // align-right
55 pJustify
= rContext
.pAttrRight
;
58 case '\'': // align-left
59 pJustify
= rContext
.pAttrLeft
;
63 pJustify
= rContext
.pAttrCenter
;
66 case '|': // printer command
69 case '\\': // repetition
70 pJustify
= rContext
.pAttrRepeat
;
73 default: // undefined case!
74 pJustify
= rContext
.pAttrStandard
;
80 nCol
= SanitizeCol(nCol
);
81 nRow
= SanitizeRow(nRow
);
82 nTab
= SanitizeTab(nTab
);
84 rContext
.pDoc
->ApplyAttr( nCol
, nRow
, nTab
, *pJustify
);
85 ScSetStringParam aParam
;
86 aParam
.setTextInput();
87 rContext
.pDoc
->SetString(ScAddress(nCol
,nRow
,nTab
), OUString(pString
, strlen(pString
), rContext
.pLotusRoot
->eCharsetQ
), &aParam
);
90 void SetFormat(LotusContext
& rContext
, SCCOL nCol
, SCROW nRow
, SCTAB nTab
, sal_uInt8 nFormat
, sal_uInt8 nSt
)
92 nCol
= SanitizeCol(nCol
);
93 nRow
= SanitizeRow(nRow
);
94 nTab
= SanitizeTab(nTab
);
96 // PREC: nSt = default number of decimal places
97 rContext
.pDoc
->ApplyAttr(nCol
, nRow
, nTab
, *(rContext
.pValueFormCache
->GetAttr(nFormat
, nSt
)));
99 ScProtectionAttr aAttr
;
101 aAttr
.SetProtection( nFormat
& 0x80 );
103 rContext
.pDoc
->ApplyAttr( nCol
, nRow
, nTab
, aAttr
);
106 double SnumToDouble( sal_Int16 nVal
)
108 const double pFacts
[ 8 ] = {
122 fVal
= pFacts
[ ( nVal
>> 1 ) & 0x0007 ];
123 fVal
*= ( sal_Int16
) ( nVal
>> 4 );
126 fVal
= ( sal_Int16
) ( nVal
>> 1 );
131 double Snum32ToDouble( sal_uInt32 nValue
)
135 fValue
= nValue
>> 6;
136 temp
= nValue
& 0x0f;
139 if (nValue
& 0x00000010)
140 fValue
/= pow((double)10, temp
);
142 fValue
*= pow((double)10, temp
);
145 if ((nValue
& 0x00000020))
150 FormCache::FormCache( ScDocument
* pDoc1
, sal_uInt8 nNewDefaultFormat
)
152 { // Default format is 'Default'
153 nDefaultFormat
= nNewDefaultFormat
;
154 pFormTable
= pDoc1
->GetFormatTable();
155 for(bool & rb
: bValid
)
157 eLanguage
= ScGlobal::eLnge
;
160 FormCache::~FormCache()
162 for(FormIdent
& rIdent
: aIdents
)
163 delete rIdent
.GetAttr();
166 SfxUInt32Item
* FormCache::NewAttr( sal_uInt8 nFormat
, sal_uInt8 nSt
)
169 sal_uInt8 nL
, nH
; // Low-/High-Nibble
170 OUString aFormString
;
171 sal_Int16 eType
= css::util::NumberFormat::ALL
;
174 NfIndexTableOffset eIndexTableOffset
= NF_NUMERIC_START
;
175 bool bDefault
= false;
177 // split into Low and High byte
179 nH
= ( nFormat
& 0xF0 ) / 16;
181 nH
&= 0x07; // extract bits 4-6
184 case 0x00: // fixed-point number
186 nIndex1
= pFormTable
->GetStandardFormat(
187 css::util::NumberFormat::NUMBER
, eLanguage
);
188 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
189 eLanguage
, false, false, nL
);
191 case 0x01: // scientific notation
193 nIndex1
= pFormTable
->GetStandardFormat(
194 css::util::NumberFormat::SCIENTIFIC
, eLanguage
);
195 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
196 eLanguage
, false, false, nL
);
198 case 0x02: // currency
200 nIndex1
= pFormTable
->GetStandardFormat(
201 css::util::NumberFormat::CURRENCY
, eLanguage
);
202 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
203 eLanguage
, false, false, nL
);
205 case 0x03: // percentage
207 nIndex1
= pFormTable
->GetStandardFormat(
208 css::util::NumberFormat::PERCENT
, eLanguage
);
209 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
210 eLanguage
, false, false, nL
);
212 case 0x04: // Decimal
214 nIndex1
= pFormTable
->GetStandardFormat(
215 css::util::NumberFormat::NUMBER
, eLanguage
);
216 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
217 eLanguage
, true, false, nL
);
219 case 0x05: // unspecified
221 nIndex1
= pFormTable
->GetStandardFormat(
222 css::util::NumberFormat::NUMBER
, eLanguage
);
223 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
224 eLanguage
, false, false, nL
);
226 case 0x06: // unspecified
228 nIndex1
= pFormTable
->GetStandardFormat(
229 css::util::NumberFormat::NUMBER
, eLanguage
);
230 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
231 eLanguage
, false, false, nL
);
233 case 0x07: // Special format
238 nIndex1
= pFormTable
->GetStandardFormat(
239 css::util::NumberFormat::NUMBER
, eLanguage
);
240 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
241 eLanguage
, false, true, nSt
);
243 case 0x01: // general Format
245 nIndex1
= pFormTable
->GetStandardFormat(
246 css::util::NumberFormat::NUMBER
, eLanguage
);
247 aFormString
= pFormTable
->GenerateFormat(nIndex1
,
248 eLanguage
, false, false, nSt
);
250 case 0x02: // Date: Day, Month, Year
251 //fDate;dfDayMonthYearLong;
252 eType
= css::util::NumberFormat::DATE
;
253 eIndexTableOffset
= NF_DATE_SYS_DDMMYYYY
;
255 case 0x03: // Date: Day, Month
256 //fDate;dfDayMonthLong;
257 eType
= css::util::NumberFormat::DATE
;
258 aFormString
= pFormTable
->GetKeyword( eLanguage
, NF_KEY_DD
);
259 aFormString
+= pFormTable
->GetDateSep(); // matches last eLanguage
260 aFormString
+= pFormTable
->GetKeyword( eLanguage
, NF_KEY_MMMM
);
262 case 0x04: // Date: Month, Year
263 //fDate;dfMonthYearLong;
264 eType
= css::util::NumberFormat::DATE
;
265 aFormString
= pFormTable
->GetKeyword( eLanguage
, NF_KEY_MM
);
266 aFormString
+= pFormTable
->GetDateSep(); // matches last eLanguage
267 aFormString
+= pFormTable
->GetKeyword( eLanguage
, NF_KEY_YYYY
);
269 case 0x05: // Text formats
271 eType
= css::util::NumberFormat::TEXT
;
272 eIndexTableOffset
= NF_TEXT
;
275 //wFlag |= paHideAll;bSetFormat = sal_False;
276 eType
= css::util::NumberFormat::NUMBER
;
277 aFormString
= "\"\"";
279 case 0x07: // Time: hour, min, sec
280 //fTime;tfHourMinSec24;
281 eType
= css::util::NumberFormat::TIME
;
282 eIndexTableOffset
= NF_TIME_HHMMSS
;
284 case 0x08: // Time: hour, min
286 eType
= css::util::NumberFormat::TIME
;
287 eIndexTableOffset
= NF_TIME_HHMM
;
289 case 0x09: // Date, intern sal_Int32 1
290 //fDate;dfDayMonthYearLong;
291 eType
= css::util::NumberFormat::DATE
;
292 eIndexTableOffset
= NF_DATE_SYS_DDMMYYYY
;
294 case 0x0A: // Date, intern sal_Int32 2
295 //fDate;dfDayMonthYearLong;
296 eType
= css::util::NumberFormat::DATE
;
297 eIndexTableOffset
= NF_DATE_SYS_DDMMYYYY
;
299 case 0x0B: // Time, intern sal_Int32 1
300 //fTime;tfHourMinSec24;
301 eType
= css::util::NumberFormat::TIME
;
302 eIndexTableOffset
= NF_TIME_HHMMSS
;
304 case 0x0C: // Time, intern sal_Int32 2
305 //fTime;tfHourMinSec24;
306 eType
= css::util::NumberFormat::TIME
;
307 eIndexTableOffset
= NF_TIME_HHMMSS
;
309 case 0x0F: // Default
321 // push Format into table
324 else if (eIndexTableOffset
!= NF_NUMERIC_START
)
325 nHandle
= pFormTable
->GetFormatIndex( eIndexTableOffset
, eLanguage
);
329 pFormTable
->PutEntry( aFormString
, nDummy
, eType
, nHandle
, eLanguage
);
332 return new SfxUInt32Item( ATTR_VALUE_FORMAT
, nHandle
);
335 void LotusRange::MakeHash()
337 // 33222222222211111111110000000000
338 // 10987654321098765432109876543210
341 // **************** nRowS
342 // **************** nRowE
343 nHash
= static_cast<sal_uInt32
>(nColStart
);
344 nHash
+= static_cast<sal_uInt32
>(nColEnd
) << 6;
345 nHash
+= static_cast<sal_uInt32
>(nRowStart
) << 12;
346 nHash
+= static_cast<sal_uInt32
>(nRowEnd
) << 16;
349 LotusRange::LotusRange( SCCOL nCol
, SCROW nRow
)
351 nColStart
= nColEnd
= nCol
;
352 nRowStart
= nRowEnd
= nRow
;
357 LotusRange::LotusRange( SCCOL nCS
, SCROW nRS
, SCCOL nCE
, SCROW nRE
)
367 LotusRange::LotusRange( const LotusRange
& rCpy
)
372 LotusRangeList::LotusRangeList(LOTUS_ROOT
* pLotRoot
)
373 : m_pLotRoot(pLotRoot
)
375 aComplRef
.InitFlags();
377 ScSingleRefData
* pSingRef
;
380 pSingRef
= &aComplRef
.Ref1
;
381 pSingRef
->SetRelTab(0);
382 pSingRef
->SetColRel( false );
383 pSingRef
->SetRowRel( false );
384 pSingRef
->SetFlag3D( false );
386 pSingRef
= &aComplRef
.Ref2
;
387 pSingRef
->SetRelTab(0);
388 pSingRef
->SetColRel( false );
389 pSingRef
->SetRowRel( false );
390 pSingRef
->SetFlag3D( false );
393 SCCOL
LotusRangeList::nEingCol
;
394 SCROW
LotusRangeList::nEingRow
;
396 LotusRangeList::~LotusRangeList ()
398 std::vector
<LotusRange
*>::iterator pIter
;
399 for (pIter
= maRanges
.begin(); pIter
!= maRanges
.end(); ++pIter
)
403 LR_ID
LotusRangeList::GetIndex( const LotusRange
&rRef
)
405 std::vector
<LotusRange
*>::iterator pIter
;
406 for (pIter
= maRanges
.begin(); pIter
!= maRanges
.end(); ++pIter
)
408 if (rRef
== *(*pIter
))
409 return (*pIter
)->nId
;
415 void LotusRangeList::Append( LotusRange
* pLR
, const OUString
& rName
)
417 OSL_ENSURE( pLR
, "*LotusRangeList::Append(): no pointer!" );
418 maRanges
.push_back(pLR
);
420 ScTokenArray aTokArray
;
422 ScSingleRefData
* pSingRef
= &aComplRef
.Ref1
;
424 pSingRef
->SetAbsCol(pLR
->nColStart
);
425 pSingRef
->SetAbsRow(pLR
->nRowStart
);
427 if( pLR
->IsSingle() )
428 aTokArray
.AddSingleReference( *pSingRef
);
431 pSingRef
= &aComplRef
.Ref2
;
432 pSingRef
->SetAbsCol(pLR
->nColEnd
);
433 pSingRef
->SetAbsRow(pLR
->nRowEnd
);
434 aTokArray
.AddDoubleReference( aComplRef
);
437 ScRangeData
* pData
= new ScRangeData(
438 m_pLotRoot
->pDoc
, rName
, aTokArray
);
440 m_pLotRoot
->pScRangeName
->insert( pData
);
442 pLR
->SetId( nIdCnt
);
447 RangeNameBufferWK3::RangeNameBufferWK3(LOTUS_ROOT
* pLotRoot
)
448 : m_pLotRoot(pLotRoot
)
450 pScTokenArray
= new ScTokenArray
;
454 RangeNameBufferWK3::~RangeNameBufferWK3()
456 delete pScTokenArray
;
459 void RangeNameBufferWK3::Add( const OUString
& rOrgName
, const ScComplexRefData
& rCRD
)
461 OUString aScName
= ScfTools::ConvertToScDefinedName(rOrgName
);
463 Entry
aInsert( rOrgName
, aScName
, rCRD
);
465 pScTokenArray
->Clear();
467 const ScSingleRefData
& rRef1
= rCRD
.Ref1
;
468 const ScSingleRefData
& rRef2
= rCRD
.Ref2
;
469 ScAddress aAbs1
= rRef1
.toAbs(ScAddress());
470 ScAddress aAbs2
= rRef2
.toAbs(ScAddress());
473 pScTokenArray
->AddSingleReference( rCRD
.Ref1
);
474 aInsert
.bSingleRef
= true;
478 pScTokenArray
->AddDoubleReference( rCRD
);
479 aInsert
.bSingleRef
= false;
482 ScRangeData
* pData
= new ScRangeData( m_pLotRoot
->pDoc
, aScName
, *pScTokenArray
);
484 aInsert
.nRelInd
= nIntCount
;
485 pData
->SetIndex( nIntCount
);
488 maEntries
.push_back( aInsert
);
489 m_pLotRoot
->pScRangeName
->insert( pData
);
492 bool RangeNameBufferWK3::FindRel( const OUString
& rRef
, sal_uInt16
& rIndex
)
494 StringHashEntry
aRef( rRef
);
496 std::vector
<Entry
>::const_iterator itr
;
497 for ( itr
= maEntries
.begin(); itr
!= maEntries
.end(); ++itr
)
499 if ( aRef
== itr
->aStrHashEntry
)
501 rIndex
= itr
->nRelInd
;
509 bool RangeNameBufferWK3::FindAbs( const OUString
& rRef
, sal_uInt16
& rIndex
)
511 OUString
aTmp( rRef
);
513 StringHashEntry
aRef( aTmp
); // search w/o '$'!
515 std::vector
<Entry
>::iterator itr
;
516 for ( itr
= maEntries
.begin(); itr
!= maEntries
.end(); ++itr
)
518 if ( aRef
== itr
->aStrHashEntry
)
520 // setup new range if needed
522 rIndex
= itr
->nAbsInd
;
525 ScSingleRefData
* pRef
= &itr
->aScComplexRefDataRel
.Ref1
;
526 pScTokenArray
->Clear();
528 pRef
->SetColRel( false );
529 pRef
->SetRowRel( false );
530 pRef
->SetTabRel( true );
532 if( itr
->bSingleRef
)
533 pScTokenArray
->AddSingleReference( *pRef
);
536 pRef
= &itr
->aScComplexRefDataRel
.Ref2
;
537 pRef
->SetColRel( false );
538 pRef
->SetRowRel( false );
539 pRef
->SetTabRel( true );
540 pScTokenArray
->AddDoubleReference( itr
->aScComplexRefDataRel
);
543 ScRangeData
* pData
= new ScRangeData( m_pLotRoot
->pDoc
, itr
->aScAbsName
, *pScTokenArray
);
545 rIndex
= itr
->nAbsInd
= nIntCount
;
546 pData
->SetIndex( rIndex
);
549 m_pLotRoot
->pScRangeName
->insert( pData
);
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */