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