xref: /aoo4110/main/svx/inc/svx/numfmtsh.hxx (revision b1cdbd2c)
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 #ifndef _SVX_NUMFMTSH_HXX
24 #define _SVX_NUMFMTSH_HXX
25 
26 // include ---------------------------------------------------------------
27 
28 #include <tools/string.hxx>
29 #include <i18npool/lang.h>
30 
31 #ifndef	_SVSTDARR_ULONGS
32 #define _SVSTDARR_ULONGS
33 #endif
34 #ifndef	_SVSTDARR_USHORTS
35 #define _SVSTDARR_USHORTS
36 #endif
37 #ifndef	_SVSTDARR_STRINGS
38 #define _SVSTDARR_STRINGS
39 #endif
40 #include "svx/svxdllapi.h"
41 
42 #include <svl/svstdarr.hxx>
43 
44 // forward ---------------------------------------------------------------
45 
46 class Color;
47 class SvNumberFormatter;
48 class SvNumberFormatTable;
49 class SvStrings;
50 class SvStringsDtor;
51 class NfCurrencyEntry;
52 // enum ------------------------------------------------------------------
53 
54 enum SvxNumberValueType
55 {
56 	SVX_VALUE_TYPE_UNDEFINED = 0,
57 	SVX_VALUE_TYPE_NUMBER,
58 	SVX_VALUE_TYPE_STRING
59 };
60 
61 // define ----------------------------------------------------------------
62 
63 #define CAT_ALL				0	// Reihenfolge der Kategorie-
64 #define CAT_USERDEFINED		1	// ListBox-Eintraege in der TabPage
65 #define CAT_NUMBER			2
66 #define CAT_PERCENT			3
67 #define CAT_CURRENCY		4
68 #define CAT_DATE			5
69 #define CAT_TIME			6
70 #define CAT_SCIENTIFIC		7
71 #define CAT_FRACTION		8
72 #define CAT_BOOLEAN			9
73 #define CAT_TEXT			10
74 
75 #define SELPOS_NONE			-1
76 
77 #define NUMBERFORMAT_ENTRY_NEW_CURRENCY		NUMBERFORMAT_ENTRY_NOT_FOUND-1
78 
79 typedef NfCurrencyEntry* NfShCurrencyEntryPtr;
80 SV_DECL_PTRARR( NfShCurrencyEntries, NfShCurrencyEntryPtr, 8, 1 )
81 
82 
83 class SvxDelStrgs: public SvStrings
84 {
85 
86 public:
~SvxDelStrgs()87 		~SvxDelStrgs() { DeleteAndDestroy(0,Count());}
88 
89 };
90 
91 // class SvxNumberFormatShell --------------------------------------------
92 
93 class SVX_DLLPUBLIC SvxNumberFormatShell
94 {
95 public:
96 						SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
97 											  sal_uInt32		 nFormatKey,
98 											  SvxNumberValueType eNumValType,
99 											  const String&		 rNumStr );
100 
101 						SvxNumberFormatShell( SvNumberFormatter* pNumFormatter,
102 											  sal_uInt32		 nFormatKey,
103 											  SvxNumberValueType eNumValType,
104 											  double			 nNumVal,
105 											  const String*		 pNumStr = NULL );
106 
107 						~SvxNumberFormatShell();
108 
109 
110 	static SvxNumberFormatShell*	Create( SvNumberFormatter* pNumFormatter,
111 											  sal_uInt32		 nFormatKey,
112 											  SvxNumberValueType eNumValType,
113 											  const String&		 rNumStr );
114 
115 	static SvxNumberFormatShell*	Create( SvNumberFormatter* pNumFormatter,
116 											  sal_uInt32		 nFormatKey,
117 											  SvxNumberValueType eNumValType,
118 											  double			 nNumVal,
119 											  const String*		 pNumStr = NULL );
120 
121 
122 	void				GetInitSettings( sal_uInt16&       nCatLbPos,
123 										LanguageType& rLangType,
124 										 sal_uInt16&       nFmtLbSelPos,
125 										 SvStrings&    rFmtEntries,
126 										 String&	   rPrevString,
127                                          Color*&       rpPrevColor );
128 
129 	void				CategoryChanged( sal_uInt16     nCatLbPos,
130 										short&     rFmtSelPos,
131 										 SvStrings& rFmtEntries );
132 
133 	void				LanguageChanged( LanguageType eLangType,
134 										 short&       rFmtSelPos,
135 										 SvStrings&   rFmtEntries );
136 
137 	void				FormatChanged( sal_uInt16  nFmtLbPos,
138 									   String& rPreviewStr,
139                                        Color*& rpFontColor );
140 
141 	sal_Bool				AddFormat( String&    rFormat,
142 								   xub_StrLen& rErrPos,
143 								   sal_uInt16&    rCatLbSelPos,
144 								   short&     rFmtSelPos,
145 								   SvStrings& rFmtEntries );
146 
147 	sal_Bool				RemoveFormat( const String&	rFormat,
148 									  sal_uInt16&       rCatLbSelPos,
149 									  short&        rFmtSelPos,
150 									  SvStrings&    rFmtEntries );
151 
152 	void				MakeFormat( String& rFormat,
153 									sal_Bool    bThousand,
154 									sal_Bool    bNegRed,
155 									sal_uInt16  nPrecision,
156 									sal_uInt16  nLeadingZeroes,
157 									sal_uInt16  nCurrencyEntryPos);
158 
159 	void				GetOptions( const String& rFormat,
160 									sal_Bool&         rThousand,
161 									sal_Bool&         rNegRed,
162 									sal_uInt16&       rPrecision,
163 									sal_uInt16&       rLeadingZeroes,
164 									sal_uInt16&       rCatLbPos );
165 
166 	void				MakePreviewString( const String& rFormatStr,
167 										   String&       rPreviewStr,
168                                            Color*&       rpFontColor );
169 
170 	void				MakePrevStringFromVal( const String& rFormatStr,		//@ 19.09.97
171 												String&	rPreviewStr,
172                                                 Color*& rpFontColor,
173 												double	nValue);
174 
175 	sal_Bool				IsUserDefined( const String& rFmtString );
176 	sal_Bool				IsTmpCurrencyFormat( const String& rFmtString );
177 	sal_Bool				FindEntry( const String& rFmtString, sal_uInt32* pAt = NULL );
178 
ValidateNewEntries(sal_Bool bValidate=sal_True)179 	void				ValidateNewEntries( sal_Bool bValidate = sal_True ) { bUndoAddList = !bValidate; }
180 	sal_uInt32			GetUpdateDataCount() const;
181 	void				GetUpdateData( sal_uInt32* pDelArray, const sal_uInt32 nSize );
182 
SetCurNumFmtKey(sal_uInt32 nNew)183 	void				SetCurNumFmtKey( sal_uInt32 nNew )	{ nCurFormatKey = nNew; }
SetCurLanguage(LanguageType eNew)184 	void				SetCurLanguage( LanguageType eNew ) { eCurLanguage = eNew; }
GetCurNumFmtKey() const185 	sal_uInt32			GetCurNumFmtKey() const				{ return nCurFormatKey; }
GetCurLanguage() const186 	LanguageType		GetCurLanguage() const				{ return eCurLanguage; }
187 
188                         /** Returns the name of Standard, General, ... for the
189                             current language. */
190     String              GetStandardName() const;
191 
192 	String				GetComment4Entry(short nEntry);
193 	short				GetCategory4Entry(short nEntry);
194 	sal_Bool				GetUserDefined4Entry(short nEntry);
195 	String				GetFormat4Entry(short nEntry);
196 	void				SetComment4Entry(short nEntry,String aCommentString);
197 
198 	sal_Bool				IsBankingSymbol(sal_uInt16 nPos);
199 	void				SetCurrencySymbol(sal_uInt16 nPos);
200 	sal_uInt32			GetCurrencySymbol();
201 	sal_uInt16				FindCurrencyFormat( const String& rFmtString );
202 	sal_uInt16				FindCurrencyFormat(const NfCurrencyEntry* pTmpCurrencyEntry,sal_Bool bTmpBanking);
203 	NfCurrencyEntry*	GetCurCurrencyEntry();
204 	void				SetCurCurrencyEntry(NfCurrencyEntry*);
205 	short				GetListPos4Entry(sal_uInt32 nIdx);
206 	short				GetListPos4Entry( const String& rFmtString );
207 
208 	void				GetCurrencySymbols( SvStringsDtor& rList, sal_uInt16* pPos );
209 	void				GetCurrencySymbols( SvStringsDtor& rList, sal_Bool bFlag );
210 
211 	sal_uInt16				FindCurrencyTableEntry( const String& rFmtString, sal_Bool &bTestBanking );
212 	sal_Bool				IsInTable(sal_uInt16 nPos,sal_Bool bTmpBanking,const String &rFmtString);
213 
214 	void				GetCurrencyFormats(SvStrings& rList);
215 
216 private:
217 	static const double 	DEFAULT_NUMVALUE;	// 123456789
218 
219 	SvNumberFormatter*		pFormatter;
220 	SvNumberFormatTable*	pCurFmtTable;
221 	SvxNumberValueType		eValType;
222 	String					aValStr;
223 	double					nValNum;
224 	sal_Bool					bUndoAddList;
225 	SvULongs				aAddList;
226 	SvULongs				aDelList;
227 	SvULongs				aCurEntryList;
228 	sal_uInt32				nInitFormatKey;
229 	sal_uInt32				nCurFormatKey;
230 	short					nCurCategory;
231 	LanguageType			eCurLanguage;
232 	SvUShorts				aCurCurrencyList;
233 	NfCurrencyEntry*		pCurCurrencyEntry;
234 	sal_Bool					bBankingSymbol;
235 	sal_uInt16					nCurCurrencyEntryPos;
236 	SvStrings				aCurrencyFormatList;
237 
238 #ifdef _SVX_NUMFMTSH_CXX
239 	SVX_DLLPRIVATE short					FillEntryList_Impl( SvStrings& rList );
240 	SVX_DLLPRIVATE void					FillEListWithStd_Impl( SvStrings& rList,sal_uInt16 aPrivCat, short &Pos);
241 	SVX_DLLPRIVATE short					FillEListWithFormats_Impl( SvStrings& rList,short nSelPos,
242 													   NfIndexTableOffset eOffsetStart,
243 													   NfIndexTableOffset eOffsetEnd);
244 
245 	SVX_DLLPRIVATE short					FillEListWithDateTime_Impl( SvStrings& rList,short nSelPos);
246 
247 	SVX_DLLPRIVATE short					FillEListWithCurrency_Impl( SvStrings& rList,short nSelPos);
248 	SVX_DLLPRIVATE short					FillEListWithSysCurrencys( SvStrings& rList,short nSelPos);
249 	SVX_DLLPRIVATE short					FillEListWithUserCurrencys( SvStrings& rList,short nSelPos);
250 
251 	SVX_DLLPRIVATE short					FillEListWithUsD_Impl( SvStrings& rList, sal_uInt16 nPrivCat, short Pos );
252 	SVX_DLLPRIVATE sal_Bool					IsRemoved_Impl( sal_uInt32 nKey );
253 	SVX_DLLPRIVATE sal_Bool					IsAdded_Impl( sal_uInt32 nKey );
254 	SVX_DLLPRIVATE void					GetPreviewString_Impl( String& rString,
255                                                    Color*& rpColor );
256 	SVX_DLLPRIVATE void					PosToCategory_Impl( sal_uInt16 nPos, short& rCategory );
257 	SVX_DLLPRIVATE void					CategoryToPos_Impl( short nCategory, sal_uInt16& rPos );
258 #endif
259 };
260 
261 
262 #endif
263 
264