Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / inc / tool.h
blob7ae32136a521b30a204ae852f94542f56e790c3e
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 <attrib.hxx>
24 #include <document.hxx>
25 #include <osl/diagnose.h>
27 // Defaultwerte
28 const sal_uInt8 nDezStd = 0; // Dezimalstellen fuer Standard-Zellen
29 const sal_uInt8 nDezFloat = 2; // " " Float-Zellen
31 struct LotusContext;
33 void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Char *pString);
35 void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
37 double SnumToDouble( sal_Int16 nVal );
39 double Snum32ToDouble( sal_uInt32 nValue );
41 typedef sal_uInt16 StampTyp;
43 #define MAKE_STAMP(nF,nS) ((nS&0x0F)+((nF&0x7F)*16))
44 // Bit 0...3 = Bit 0...3 von Stellenzahl
45 // Bit 4...10 = Bit 0...6 von Formatbyte
47 class FormIdent
49 private:
50 StampTyp nStamp; // Identifikations-Schluessel
51 SfxUInt32Item* pAttr; // zugehoeriges Attribut
52 public:
53 FormIdent( void )
55 nStamp = 0;
56 pAttr = NULL;
59 FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
61 nStamp = MAKE_STAMP( nFormat, nSt );
62 pAttr = &rAttr;
65 StampTyp GetStamp( void ) const
67 return nStamp;
70 SfxUInt32Item* GetAttr( void )
72 return pAttr;
75 void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
77 nStamp = MAKE_STAMP( nFormat, nSt );
82 #define nSize_ 2048
85 class FormCache
87 private:
88 FormIdent aIdents[ nSize_ ]; //gepufferte Formate
89 bool bValid[ nSize_ ];
90 FormIdent aCompareIdent; // zum Vergleichen
91 sal_uInt8 nDefaultFormat; // Defaultformat der Datei
92 SvNumberFormatter* pFormTable; // Value-Format-Table-Anker
93 StampTyp nIndex;
94 LanguageType eLanguage; // Systemsprache
96 SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
97 public:
98 FormCache( ScDocument*, sal_uInt8 nNewDefaultFormat = 0xFF );
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 = Stellenzahl
109 // POST: return = zu nFormat und nSt passendes SC-Format
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 // neues Attribut anlegen
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: */