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
30 const sal_uInt8 nFractionalStd = 0; // Number of digits in fractional part for standard cells
31 const sal_uInt8 nFractionalFloat = 2; // " " " " float cells
32 
33 struct LotusContext;
34 
35 void PutFormString(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString);
36 
37 void SetFormat(LotusContext& rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt);
38 
39 double SnumToDouble( sal_Int16 nVal );
40 
41 double Snum32ToDouble( sal_uInt32 nValue );
42 
43 typedef 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 
49 class FormIdent
50 {
51 private:
52  StampTyp nStamp; // ID key
53  std::unique_ptr<SfxUInt32Item> pAttr; // associated attribute
54 public:
55  FormIdent( void )
56  {
57  nStamp = 0;
58  pAttr = nullptr;
59  }
60 
61  FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
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 
87 class FormCache
88 {
89 private:
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 
97  SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
98 public:
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: */
sal_uInt16 StampTyp
Definition: tool.h:43
SfxUInt32Item * GetAttr(void)
Definition: tool.h:72
std::unique_ptr< SfxUInt32Item > pAttr
Definition: tool.h:53
void SetStamp(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:77
#define nSize_
Definition: tool.h:84
Definition: tool.h:49
double SnumToDouble(sal_Int16 nVal)
Definition: tool.cxx:103
const SfxUInt32Item * GetAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.h:106
void PutFormString(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, char *pString)
Definition: tool.cxx:37
#define MAKE_STAMP(nF, nS)
Definition: tool.h:45
FormCache(const ScDocument *)
Definition: tool.cxx:147
FormIdent aCompareIdent
Definition: tool.h:92
double Snum32ToDouble(sal_uInt32 nValue)
Definition: tool.cxx:128
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:87
FormIdent(sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item &rAttr)
Definition: tool.h:61
Definition: tool.h:87
FormIdent aIdents[nSize_]
Definition: tool.h:90
const sal_uInt8 nFractionalFloat
Definition: tool.h:31
sal_Int16 SCCOL
Definition: types.hxx:21
FormIdent(void)
Definition: tool.h:55
bool bValid[nSize_]
Definition: tool.h:91
SvNumberFormatter * pFormTable
Definition: tool.h:93
SfxUInt32Item * NewAttr(sal_uInt8 nFormat, sal_uInt8 nSt)
Definition: tool.cxx:160
StampTyp nIndex
Definition: tool.h:94
const sal_uInt8 nFractionalStd
Definition: tool.h:30
sal_Int32 SCROW
Definition: types.hxx:17
StampTyp nStamp
Definition: tool.h:52
unsigned char sal_uInt8
StampTyp GetStamp(void) const
Definition: tool.h:67
LanguageType eLanguage
Definition: tool.h:95
~FormCache()
Definition: tool.cxx:156
sal_Int16 SCTAB
Definition: types.hxx:22