1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef SC_TOOL_H
25 #define SC_TOOL_H
26
27 #include <attrib.hxx> //!!! noch noetig?????
28 #include <document.hxx>
29
30 // Defaultwerte
31 const sal_uInt8 nDezStd = 0; // Dezimalstellen fuer Standard-Zellen
32 const sal_uInt8 nDezFloat = 2; // " " Float-Zellen
33
34 void PutFormString( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Char *pString );
35
36 void SetFormat( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt );
37
38 void InitPage( void );
39
40 String DosToSystem( sal_Char *pSource );
41
42 double SnumToDouble( sal_Int16 nVal );
43
44 double Snum32ToDouble( sal_uInt32 nValue );
45
46 typedef sal_uInt16 StampTyp;
47
48 #define MAKE_STAMP(nF,nS) ((nS&0x0F)+((nF&0x7F)*16))
49 // Bit 0...3 = Bit 0...3 von Stellenzahl
50 // Bit 4...10 = Bit 0...6 von Formatbyte
51
52 class FormIdent
53 {
54 private:
55 StampTyp nStamp; // Identifikations-Schluessel
56 SfxUInt32Item* pAttr; // zugehoeriges Attribut
57 public:
FormIdent(void)58 FormIdent( void )
59 {
60 nStamp = 0;
61 pAttr = NULL;
62 }
63
FormIdent(sal_uInt8 nFormat,sal_uInt8 nSt,SfxUInt32Item & rAttr)64 FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
65 {
66 nStamp = MAKE_STAMP( nFormat, nSt );
67 pAttr = &rAttr;
68 }
69
FormIdent(sal_uInt8 nFormat,sal_uInt8 nSt)70 FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt )
71 {
72 nStamp = MAKE_STAMP( nFormat, nSt );
73 pAttr = NULL;
74 }
75
operator ==(const FormIdent & rComp) const76 sal_Bool operator ==( const FormIdent& rComp ) const
77 {
78 return ( nStamp == rComp.nStamp );
79 }
80
operator ==(const StampTyp & rStamp) const81 sal_Bool operator ==( const StampTyp& rStamp ) const
82 {
83 return ( nStamp == rStamp );
84 }
85
GetStamp(void) const86 StampTyp GetStamp( void ) const
87 {
88 return nStamp;
89 }
90
GetAttr(void)91 SfxUInt32Item* GetAttr( void )
92 {
93 return pAttr;
94 }
95
SetStamp(sal_uInt8 nFormat,sal_uInt8 nSt)96 void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
97 {
98 nStamp = MAKE_STAMP( nFormat, nSt );
99 }
100 };
101
102
103 #define __nSize 2048
104
105
106
107
108 class FormCache
109 {
110 private:
111 FormIdent aIdents[ __nSize ]; //gepufferte Formate
112 sal_Bool bValid[ __nSize ];
113 FormIdent aCompareIdent; // zum Vergleichen
114 sal_uInt8 nDefaultFormat; // Defaultformat der Datei
115 SvNumberFormatter* pFormTable; // Value-Format-Table-Anker
116 StampTyp nIndex;
117 LanguageType eLanguage; // Systemsprache
118
119 SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
120 public:
121 FormCache( ScDocument*, sal_uInt8 nNewDefaultFormat = 0xFF );
122 ~FormCache();
123
124 inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
SetDefaultFormat(sal_uInt8 nD=0xFF)125 void SetDefaultFormat( sal_uInt8 nD = 0xFF )
126 {
127 nDefaultFormat = nD;
128 }
129 };
130
131
GetAttr(sal_uInt8 nFormat,sal_uInt8 nSt)132 inline const SfxUInt32Item* FormCache::GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt )
133 {
134 // PREC: nFormat = Lotus-Format-Byte
135 // nSt = Stellenzahl
136 // POST: return = zu nFormat und nSt passendes SC-Format
137 SfxUInt32Item* pAttr;
138 SfxUInt32Item* pRet;
139
140 aCompareIdent.SetStamp( nFormat, nSt );
141 nIndex = aCompareIdent.GetStamp();
142 DBG_ASSERT( nIndex < __nSize, "FormCache::GetAttr(): Uuuuuuups... so nicht!" );
143 if( bValid[ nIndex ] )
144 pRet = aIdents[ nIndex ].GetAttr();
145 else
146 {
147 // neues Attribut anlegen
148 pAttr = NewAttr( nFormat, nSt );
149 DBG_ASSERT( pAttr, "FormCache::GetAttr(): Nix Speicherus" );
150
151 aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
152 bValid[ nIndex ] = sal_True;
153
154 pRet = pAttr;
155 }
156 return pRet;
157 }
158
159 #endif
160
161