Line data Source code
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 SC_TOOL_H
21 : #define SC_TOOL_H
22 :
23 : #include <attrib.hxx>
24 : #include <document.hxx>
25 :
26 : // Defaultwerte
27 : const sal_uInt8 nDezStd = 0; // Dezimalstellen fuer Standard-Zellen
28 : const sal_uInt8 nDezFloat = 2; // " " Float-Zellen
29 :
30 : void PutFormString( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_Char *pString );
31 :
32 : void SetFormat( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt );
33 :
34 : void InitPage( void );
35 :
36 : OUString DosToSystem( sal_Char *pSource );
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 von Stellenzahl
46 : // Bit 4...10 = Bit 0...6 von Formatbyte
47 :
48 : class FormIdent
49 : {
50 : private:
51 : StampTyp nStamp; // Identifikations-Schluessel
52 : SfxUInt32Item* pAttr; // zugehoeriges Attribut
53 : public:
54 2049 : FormIdent( void )
55 : {
56 2049 : nStamp = 0;
57 2049 : pAttr = NULL;
58 2049 : }
59 :
60 0 : FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt, SfxUInt32Item& rAttr )
61 : {
62 0 : nStamp = MAKE_STAMP( nFormat, nSt );
63 0 : pAttr = &rAttr;
64 0 : }
65 :
66 : FormIdent( sal_uInt8 nFormat, sal_uInt8 nSt )
67 : {
68 : nStamp = MAKE_STAMP( nFormat, nSt );
69 : pAttr = NULL;
70 : }
71 :
72 : sal_Bool operator ==( const FormIdent& rComp ) const
73 : {
74 : return ( nStamp == rComp.nStamp );
75 : }
76 :
77 : sal_Bool operator ==( const StampTyp& rStamp ) const
78 : {
79 : return ( nStamp == rStamp );
80 : }
81 :
82 0 : StampTyp GetStamp( void ) const
83 : {
84 0 : return nStamp;
85 : }
86 :
87 2048 : SfxUInt32Item* GetAttr( void )
88 : {
89 2048 : return pAttr;
90 : }
91 :
92 0 : void SetStamp( sal_uInt8 nFormat, sal_uInt8 nSt )
93 : {
94 0 : nStamp = MAKE_STAMP( nFormat, nSt );
95 0 : }
96 : };
97 :
98 :
99 : #define __nSize 2048
100 :
101 :
102 : class FormCache
103 : {
104 : private:
105 : FormIdent aIdents[ __nSize ]; //gepufferte Formate
106 : sal_Bool bValid[ __nSize ];
107 : FormIdent aCompareIdent; // zum Vergleichen
108 : sal_uInt8 nDefaultFormat; // Defaultformat der Datei
109 : SvNumberFormatter* pFormTable; // Value-Format-Table-Anker
110 : StampTyp nIndex;
111 : LanguageType eLanguage; // Systemsprache
112 :
113 : SfxUInt32Item* NewAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
114 : public:
115 : FormCache( ScDocument*, sal_uInt8 nNewDefaultFormat = 0xFF );
116 : ~FormCache();
117 :
118 : inline const SfxUInt32Item* GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt );
119 : void SetDefaultFormat( sal_uInt8 nD = 0xFF )
120 : {
121 : nDefaultFormat = nD;
122 : }
123 : };
124 :
125 :
126 0 : inline const SfxUInt32Item* FormCache::GetAttr( sal_uInt8 nFormat, sal_uInt8 nSt )
127 : {
128 : // PREC: nFormat = Lotus-Format-Byte
129 : // nSt = Stellenzahl
130 : // POST: return = zu nFormat und nSt passendes SC-Format
131 : SfxUInt32Item* pAttr;
132 : SfxUInt32Item* pRet;
133 :
134 0 : aCompareIdent.SetStamp( nFormat, nSt );
135 0 : nIndex = aCompareIdent.GetStamp();
136 : OSL_ENSURE( nIndex < __nSize, "FormCache::GetAttr(): Oups... not this way!" );
137 0 : if( bValid[ nIndex ] )
138 0 : pRet = aIdents[ nIndex ].GetAttr();
139 : else
140 : {
141 : // neues Attribut anlegen
142 0 : pAttr = NewAttr( nFormat, nSt );
143 : OSL_ENSURE( pAttr, "FormCache::GetAttr(): Nothing to save" );
144 :
145 0 : aIdents[ nIndex ] = FormIdent( nFormat, nSt, *pAttr );
146 0 : bValid[ nIndex ] = sal_True;
147 :
148 0 : pRet = pAttr;
149 : }
150 0 : return pRet;
151 : }
152 :
153 : #endif
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|