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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_TOOL_H
21 #define INCLUDED_SC_SOURCE_FILTER_INC_TOOL_H
22 
23 #include <i18nlangtag/lang.h>
24 #include <svl/intitem.hxx>
25 #include <types.hxx>
26 #include <osl/diagnose.h>
27 
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
31 
32 struct LotusContext;
33 
34 void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString);
35 
36 void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
37 
38 double SnumToDouble( sal_Int16 nVal );
39 
40 double Snum32ToDouble( sal_uInt32 nValue );
41 
42 typedef sal_uInt16 StampTyp;
43 
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
47 
48 class FormIdent
49 {
50 private:
51  StampTyp nStamp; // ID key
52  std::unique_ptr<SfxUInt32Item> pAttr; // associated attribute
53 public:
54  FormIdent( void )
55  {
56  nStamp = 0;
57  pAttr = nullptr;
58  }
59 
60  FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
61  {
62  nStamp = MAKE_STAMP( nFormat, nSt );
63  pAttr.reset(&rAttr);
64  }
65 
66  StampTyp GetStamp( void ) const
67  {
68  return nStamp;
69  }
70 
72  {
73  return pAttr.get();
74  }
75 
76  void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
77  {
78  nStamp = MAKE_STAMP( nFormat, nSt );
79  }
80 };
81 
82 
83 #define nSize_ 2048
84 
85 
86 class FormCache
87 {
88 private:
89  FormIdent aIdents[ nSize_ ]; //buffered formats
90  bool bValid[ nSize_ ];
91  FormIdent aCompareIdent; // for comparing
92  SvNumberFormatter* pFormTable; // value format table anchor
94  LanguageType eLanguage; // System language
95 
96  SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
97 public:
98  FormCache( const ScDocument* );
99  ~FormCache();
100 
101  inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
102 };
103 
104 
106 {
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;
112 
113  aCompareIdent.SetStamp( nFormat, nSt );
115  OSL_ENSURE( nIndex < nSize_, "FormCache::GetAttr(): Oups... not this way!" );
116  if( bValid[ nIndex ] )
117  pRet = aIdents[ nIndex ].GetAttr();
118  else
119  {
120  // create new attribute
121  pAttr = NewAttr( nFormat, nSt );
122  OSL_ENSURE( pAttr, "FormCache::GetAttr(): Nothing to save" );
123 
124  aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
125  bValid[ nIndex ] = true;
126 
127  pRet = pAttr;
128  }
129  return pRet;
130 }
131 
132 #endif
133 
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 StampTyp
Definition: tool.h:42
SfxUInt32Item * GetAttr(void)
Definition: tool.h:71
std::unique_ptr< SfxUInt32Item > pAttr
Definition: tool.h:52
void SetStamp(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:76
#define nSize_
Definition: tool.h:83
Definition: tool.h:48
double SnumToDouble(sal_Int16 nVal)
Definition: tool.cxx:104
const SfxUInt32Item * GetAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:105
void PutFormString(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString)
Definition: tool.cxx:38
#define MAKE_STAMP(nF, nS)
Definition: tool.h:44
FormCache(const ScDocument *)
Definition: tool.cxx:148
FormIdent aCompareIdent
Definition: tool.h:91
double Snum32ToDouble(sal_uInt32 nValue)
Definition: tool.cxx:129
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:88
FormIdent(sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item &rAttr)
Definition: tool.h:60
Definition: tool.h:86
FormIdent aIdents[nSize_]
Definition: tool.h:89
const sal_uInt8 nFractionalFloat
Definition: tool.h:30
sal_Int16 SCCOL
Definition: types.hxx:22
FormIdent(void)
Definition: tool.h:54
bool bValid[nSize_]
Definition: tool.h:90
SvNumberFormatter * pFormTable
Definition: tool.h:92
SfxUInt32Item * NewAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:161
StampTyp nIndex
Definition: tool.h:93
const sal_uInt8 nFractionalStd
Definition: tool.h:29
sal_Int32 SCROW
Definition: types.hxx:18
StampTyp nStamp
Definition: tool.h:51
unsigned char sal_uInt8
StampTyp GetStamp(void) const
Definition: tool.h:66
LanguageType eLanguage
Definition: tool.h:94
~FormCache()
Definition: tool.cxx:157
sal_Int16 SCTAB
Definition: types.hxx:23