LibreOffice Module sc (master) 1
tool.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <document.hxx>
23
24#include <i18nlangtag/lang.h>
25#include <svl/intitem.hxx>
26#include <types.hxx>
27#include <osl/diagnose.h>
28
29// Default values
30const sal_uInt8 nFractionalStd = 0; // Number of digits in fractional part for standard cells
31const sal_uInt8 nFractionalFloat = 2; // " " " " float cells
32
33struct LotusContext;
34
35void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString);
36
37void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
38
39double SnumToDouble( sal_Int16 nVal );
40
41double Snum32ToDouble( sal_uInt32 nValue );
42
43typedef sal_uInt16 StampTyp;
44
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
48
50{
51private:
52 StampTyp nStamp; // ID key
53 std::unique_ptr<SfxUInt32Item> pAttr; // associated attribute
54public:
55 FormIdent( void )
56 {
57 nStamp = 0;
58 pAttr = nullptr;
59 }
60
62 {
63 nStamp = MAKE_STAMP( nFormat, nSt );
64 pAttr.reset(&rAttr);
65 }
66
67 StampTyp GetStamp( void ) const
68 {
69 return nStamp;
70 }
71
73 {
74 return pAttr.get();
75 }
76
77 void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
78 {
79 nStamp = MAKE_STAMP( nFormat, nSt );
80 }
81};
82
83
84#define nSize_ 2048
85
86
88{
89private:
90 FormIdent aIdents[ nSize_ ]; //buffered formats
91 bool bValid[ nSize_ ];
92 FormIdent aCompareIdent; // for comparing
93 SvNumberFormatter* pFormTable; // value format table anchor
95 LanguageType eLanguage; // System language
96
98public:
99 FormCache( const ScDocument* );
100 ~FormCache();
101
102 inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
103};
104
105
107{
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;
113
114 aCompareIdent.SetStamp( nFormat, nSt );
116 OSL_ENSURE( nIndex < nSize_, "FormCache::GetAttr(): Oups... not this way!" );
117 if( bValid[ nIndex ] )
118 pRet = aIdents[ nIndex ].GetAttr();
119 else
120 {
121 // create new attribute
122 pAttr = NewAttr( nFormat, nSt );
123 OSL_ENSURE( pAttr, "FormCache::GetAttr(): Nothing to save" );
124
125 aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
126 bValid[ nIndex ] = true;
127
128 pRet = pAttr;
129 }
130 return pRet;
131}
132
133/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: tool.h:88
const SfxUInt32Item * GetAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:106
LanguageType eLanguage
Definition: tool.h:95
StampTyp nIndex
Definition: tool.h:94
~FormCache()
Definition: tool.cxx:157
FormIdent aIdents[nSize_]
Definition: tool.h:90
bool bValid[nSize_]
Definition: tool.h:91
SfxUInt32Item * NewAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:161
FormCache(const ScDocument *)
Definition: tool.cxx:148
FormIdent aCompareIdent
Definition: tool.h:92
SvNumberFormatter * pFormTable
Definition: tool.h:93
Definition: tool.h:50
std::unique_ptr< SfxUInt32Item > pAttr
Definition: tool.h:53
SfxUInt32Item * GetAttr(void)
Definition: tool.h:72
FormIdent(void)
Definition: tool.h:55
FormIdent(sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item &rAttr)
Definition: tool.h:61
StampTyp nStamp
Definition: tool.h:52
void SetStamp(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:77
StampTyp GetStamp(void) const
Definition: tool.h:67
sal_uInt16 StampTyp
Definition: tool.h:43
#define nSize_
Definition: tool.h:84
double SnumToDouble(sal_Int16 nVal)
Definition: tool.cxx:104
void PutFormString(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString)
Definition: tool.cxx:38
const sal_uInt8 nFractionalFloat
Definition: tool.h:31
const sal_uInt8 nFractionalStd
Definition: tool.h:30
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:88
double Snum32ToDouble(sal_uInt32 nValue)
Definition: tool.cxx:129
#define MAKE_STAMP(nF, nS)
Definition: tool.h:45
unsigned char sal_uInt8
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17