Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / tool.h
blobc2eb72f867c172faf56745a293a7ae9077e2287b
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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_TOOL_H
21 #define INCLUDED_SC_SOURCE_FILTER_INC_TOOL_H
23 #include <i18nlangtag/lang.h>
24 #include <svl/intitem.hxx>
25 #include <types.hxx>
26 #include <osl/diagnose.h>
28 // Default values
29 const sal_uInt8 nFractionalStd = 0; // Number of digits in fractional part for standard cells
30 const sal_uInt8 nFractionalFloat = 2; // " " " " float cells
32 struct LotusContext;
34 void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Char *pString);
36 void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
38 double SnumToDouble( sal_Int16 nVal );
40 double Snum32ToDouble( sal_uInt32 nValue );
42 typedef sal_uInt16 StampTyp;
44 #define MAKE_STAMP(nF,nS) ((nS&0x0F)+((nF&0x7F)*16))
45 // Bit 0...3 = Bit 0...3 of number of digits
46 // Bit 4...10 = Bit 0...6 of Formatbyte
48 class FormIdent
50 private:
51 StampTyp nStamp; // ID key
52 std::unique_ptr<SfxUInt32Item> pAttr; // associated attribute
53 public:
54 FormIdent( void )
56 nStamp = 0;
57 pAttr = nullptr;
60 FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
62 nStamp = MAKE_STAMP( nFormat, nSt );
63 pAttr.reset(&rAttr);
66 StampTyp GetStamp( void ) const
68 return nStamp;
71 SfxUInt32Item* GetAttr( void )
73 return pAttr.get();
76 void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
78 nStamp = MAKE_STAMP( nFormat, nSt );
83 #define nSize_ 2048
86 class FormCache
88 private:
89 FormIdent aIdents[ nSize_ ]; //buffered formats
90 bool bValid[ nSize_ ];
91 FormIdent aCompareIdent; // for comparing
92 SvNumberFormatter* pFormTable; // value format table anchor
93 StampTyp nIndex;
94 LanguageType eLanguage; // System language
96 SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
97 public:
98 FormCache( const ScDocument* );
99 ~FormCache();
101 inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
105 inline const SfxUInt32Item* FormCache::GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt )
107 // PREC: nFormat = Lotus format byte
108 // nSt = Number of digit
109 // POST: return = SC-format fitting nFormat and nSt
110 SfxUInt32Item* pAttr;
111 SfxUInt32Item* pRet;
113 aCompareIdent.SetStamp( nFormat, nSt );
114 nIndex = aCompareIdent.GetStamp();
115 OSL_ENSURE( nIndex < nSize_, "FormCache::GetAttr(): Oups... not this way!" );
116 if( bValid[ nIndex ] )
117 pRet = aIdents[ nIndex ].GetAttr();
118 else
120 // create new attribute
121 pAttr = NewAttr( nFormat, nSt );
122 OSL_ENSURE( pAttr, "FormCache::GetAttr(): Nothing to save" );
124 aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
125 bValid[ nIndex ] = true;
127 pRet = pAttr;
129 return pRet;
132 #endif
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */