Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / tool.h
blob786e7f669863c16151be33e383e3a78d637828f2
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 #pragma once
22 #include <document.hxx>
24 #include <i18nlangtag/lang.h>
25 #include <svl/intitem.hxx>
26 #include <types.hxx>
27 #include <osl/diagnose.h>
29 // Default values
30 const sal_uInt8 nFractionalStd = 0; // Number of digits in fractional part for standard cells
31 const sal_uInt8 nFractionalFloat = 2; // " " " " float cells
33 struct LotusContext;
35 void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString);
37 void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
39 double SnumToDouble( sal_Int16 nVal );
41 double Snum32ToDouble( sal_uInt32 nValue );
43 typedef sal_uInt16 StampTyp;
45 #define MAKE_STAMP(nF,nS) ((nS&0x0F)+((nF&0x7F)*16))
46 // Bit 0...3 = Bit 0...3 of number of digits
47 // Bit 4...10 = Bit 0...6 of Formatbyte
49 class FormIdent
51 private:
52 StampTyp nStamp; // ID key
53 std::unique_ptr<SfxUInt32Item> pAttr; // associated attribute
54 public:
55 FormIdent( void )
57 nStamp = 0;
58 pAttr = nullptr;
61 FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
63 nStamp = MAKE_STAMP( nFormat, nSt );
64 pAttr.reset(&rAttr);
67 StampTyp GetStamp( void ) const
69 return nStamp;
72 SfxUInt32Item* GetAttr( void )
74 return pAttr.get();
77 void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
79 nStamp = MAKE_STAMP( nFormat, nSt );
84 #define nSize_ 2048
87 class FormCache
89 private:
90 FormIdent aIdents[ nSize_ ]; //buffered formats
91 bool bValid[ nSize_ ];
92 FormIdent aCompareIdent; // for comparing
93 SvNumberFormatter* pFormTable; // value format table anchor
94 StampTyp nIndex;
95 LanguageType eLanguage; // System language
97 SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
98 public:
99 FormCache( const ScDocument* );
100 ~FormCache();
102 inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
106 inline const SfxUInt32Item* FormCache::GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt )
108 // PREC: nFormat = Lotus format byte
109 // nSt = Number of digit
110 // POST: return = SC-format fitting nFormat and nSt
111 SfxUInt32Item* pAttr;
112 SfxUInt32Item* pRet;
114 aCompareIdent.SetStamp( nFormat, nSt );
115 nIndex = aCompareIdent.GetStamp();
116 OSL_ENSURE( nIndex < nSize_, "FormCache::GetAttr(): Oups... not this way!" );
117 if( bValid[ nIndex ] )
118 pRet = aIdents[ nIndex ].GetAttr();
119 else
121 // create new attribute
122 pAttr = NewAttr( nFormat, nSt );
123 OSL_ENSURE( pAttr, "FormCache::GetAttr(): Nothing to save" );
125 aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
126 bValid[ nIndex ] = true;
128 pRet = pAttr;
130 return pRet;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */