update emoji autocorrect entries from po-files
[LibreOffice.git] / include / svl / zforlist.hxx
blob0127662ebcfbe615cedf2f08ee5b4685d718b31a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SVL_ZFORLIST_HXX
20 #define INCLUDED_SVL_ZFORLIST_HXX
22 #include <svl/svldllapi.h>
23 #include <rtl/ustrbuf.hxx>
24 #include <rtl/ustring.hxx>
25 #include <i18nlangtag/lang.h>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/lang/Locale.hpp>
28 #include <com/sun/star/i18n/NumberFormatCode.hpp>
29 #include <com/sun/star/util/NumberFormat.hpp>
30 #include <unotools/localedatawrapper.hxx>
31 #include <unotools/numberformatcodewrapper.hxx>
32 #include <tools/link.hxx>
33 #include <svl/ondemand.hxx>
34 #include <svl/nfkeytab.hxx>
36 #include <map>
37 #include <set>
39 class Date;
40 class Color;
41 class CharClass;
42 class CalendarWrapper;
44 class ImpSvNumberformatScan;
45 class ImpSvNumberInputScan;
46 class SvNumberformat;
48 namespace com { namespace sun { namespace star {
49 namespace uno {
50 class XComponentContext;
52 }}}
54 #define SV_COUNTRY_LANGUAGE_OFFSET 10000 // Max count of formats per country/language
55 #define SV_MAX_ANZ_STANDARD_FORMATE 100 // Max count of builtin default formats per CL
57 #define NUMBERFORMAT_ENTRY_NOT_FOUND (sal_uInt32)(0xffffffff) /// MAX_ULONG
60 /** enum values for <method>SvNumberFormatter::GetFormatIndex</method>
62 <p>
63 Builtin standard formats, order should be also the arrangement in the
64 dialog list box representation.</p>
66 <p>
67 Date specials:<ul>
68 <li>SYSTEM: As set in System Regional Settings.
69 <li>SYS: short/long defined, order and separators from System Regional Settings.
70 <li>DEF: short/long and order defined, separators from System Regional Settings.
71 <li>DIN: all settings hard coded as DIN (Deutsche Industrie Norm) and EN (European Norm) require.
72 <li>all other: hard coded
73 </ul>
75 Do NOT insert any new values!
76 The values here correspond with those in offapi/com/sun/star/i18n/NumberFormatIndex.idl
78 enum NfIndexTableOffset
80 NF_NUMERIC_START = 0,
82 NF_NUMBER_START = NF_NUMERIC_START,
83 NF_NUMBER_STANDARD = NF_NUMBER_START, // Standard/General
84 NF_NUMBER_INT, // 0
85 NF_NUMBER_DEC2, // 0.00
86 NF_NUMBER_1000INT, // #,##0
87 NF_NUMBER_1000DEC2, // #,##0.00
88 NF_NUMBER_SYSTEM, // #,##0.00 or whatever is set in System Regional Settings
89 NF_NUMBER_END = NF_NUMBER_SYSTEM,
91 NF_SCIENTIFIC_START,
92 NF_SCIENTIFIC_000E000 = NF_SCIENTIFIC_START, // 0.00E+000
93 NF_SCIENTIFIC_000E00, // 0.00E+00
94 NF_SCIENTIFIC_END = NF_SCIENTIFIC_000E00,
96 NF_PERCENT_START,
97 NF_PERCENT_INT = NF_PERCENT_START, // 0%
98 NF_PERCENT_DEC2, // 0.00%
99 NF_PERCENT_END = NF_PERCENT_DEC2,
101 NF_FRACTION_START,
102 NF_FRACTION_1 = NF_FRACTION_START, // # ?/?
103 NF_FRACTION_2, // # ??/??
104 NF_FRACTION_END = NF_FRACTION_2,
106 NF_NUMERIC_END = NF_FRACTION_END,
108 NF_CURRENCY_START,
109 NF_CURRENCY_1000INT = NF_CURRENCY_START,// #,##0 DM
110 NF_CURRENCY_1000DEC2, // #,##0.00 DM
111 NF_CURRENCY_1000INT_RED, // #,##0 DM negative in red
112 NF_CURRENCY_1000DEC2_RED, // #,##0.00 DM negative in red
113 NF_CURRENCY_1000DEC2_CCC, // #,##0.00 DEM currency abbreviation
114 NF_CURRENCY_1000DEC2_DASHED, // #,##0.-- DM
115 NF_CURRENCY_END = NF_CURRENCY_1000DEC2_DASHED,
117 NF_DATE_START,
118 NF_DATE_SYSTEM_SHORT = NF_DATE_START, // 08.10.97
119 NF_DATE_SYSTEM_LONG, // Wednesday, 8. October 1997
120 NF_DATE_SYS_DDMMYY, // 08.10.97
121 NF_DATE_SYS_DDMMYYYY, // 08.10.1997
122 NF_DATE_SYS_DMMMYY, // 8. Oct 97
123 NF_DATE_SYS_DMMMYYYY, // 8. Oct 1997
124 NF_DATE_DIN_DMMMYYYY, // 8. Oct. 1997 DIN
125 NF_DATE_SYS_DMMMMYYYY, // 8. October 1997
126 NF_DATE_DIN_DMMMMYYYY, // 8. October 1997 DIN
127 NF_DATE_SYS_NNDMMMYY, // Wed, 8. Okt 97
128 NF_DATE_DEF_NNDDMMMYY, // Wed 08.Okt 97
129 NF_DATE_SYS_NNDMMMMYYYY, // Wed, 8. Oktober 1997
130 NF_DATE_SYS_NNNNDMMMMYYYY, // Wednesday, 8. Oktober 1997
131 NF_DATE_DIN_MMDD, // 10-08 DIN
132 NF_DATE_DIN_YYMMDD, // 97-10-08 DIN
133 NF_DATE_DIN_YYYYMMDD, // 1997-10-08 DIN
134 NF_DATE_SYS_MMYY, // 10.97
135 NF_DATE_SYS_DDMMM, // 08.Oct
136 NF_DATE_MMMM, // October
137 NF_DATE_QQJJ, // 4. Quarter 97
138 NF_DATE_WW, // week of year
139 NF_DATE_END = NF_DATE_WW,
141 NF_TIME_START,
142 NF_TIME_HHMM = NF_TIME_START, // HH:MM
143 NF_TIME_HHMMSS, // HH:MM:SS
144 NF_TIME_HHMMAMPM, // HH:MM AM/PM
145 NF_TIME_HHMMSSAMPM, // HH:MM:SS AM/PM
146 NF_TIME_HH_MMSS, // [HH]:MM:SS
147 NF_TIME_MMSS00, // MM:SS,00
148 NF_TIME_HH_MMSS00, // [HH]:MM:SS,00
149 NF_TIME_END = NF_TIME_HH_MMSS00,
151 NF_DATETIME_START,
152 NF_DATETIME_SYSTEM_SHORT_HHMM = NF_DATETIME_START, // 08.10.97 01:23
153 NF_DATETIME_SYS_DDMMYYYY_HHMMSS, // 08.10.1997 01:23:45
154 NF_DATETIME_END = NF_DATETIME_SYS_DDMMYYYY_HHMMSS,
156 NF_BOOLEAN, // BOOLEAN
157 NF_TEXT, // @
159 NF_INDEX_TABLE_LOCALE_DATA_DEFAULTS, // old number of predefined entries, locale data additions start after this
161 // From here on are values of new built-in formats that are not in the
162 // original NumberFormatIndex.idl
164 NF_FRACTION_3 = NF_INDEX_TABLE_LOCALE_DATA_DEFAULTS, // # ?/4
165 NF_FRACTION_4, // # ?/100
167 NF_INDEX_TABLE_ENTRIES
171 // #45717# IsNumberFormat( "98-10-24", 30, x ), YMD Format set with DMY
172 // International settings doesn't recognize the string as a date.
173 /** enum values for <method>SvNumberFormatter::SetEvalDateFormat</method>
175 <p>How <method>ImpSvNumberInputScan::GetDateRef</method> shall take the
176 DateFormat order (YMD,DMY,MDY) into account, if called from IsNumberFormat
177 with a date format to match against.
179 enum NfEvalDateFormat
181 /** DateFormat only from International, default. */
182 NF_EVALDATEFORMAT_INTL,
184 /** DateFormat only from date format passed to function (if any).
185 If no date format is passed then the DateFormat is taken from International. */
186 NF_EVALDATEFORMAT_FORMAT,
188 /** First try the DateFormat from International. If it doesn't match a
189 valid date try the DateFormat from the date format passed. */
190 NF_EVALDATEFORMAT_INTL_FORMAT,
192 /** First try the DateFormat from the date format passed. If it doesn't
193 match a valid date try the DateFormat from International. */
194 NF_EVALDATEFORMAT_FORMAT_INTL
198 typedef std::map<sal_uInt32, SvNumberformat*> SvNumberFormatTable;
199 typedef std::map<sal_uInt16, sal_uInt32> SvNumberFormatterIndexTable;
201 typedef ::std::map< sal_uInt32, sal_uInt32> SvNumberFormatterMergeMap;
203 typedef ::std::set< LanguageType > NfInstalledLocales;
206 /** Language/country dependent currency entries
208 class SVL_DLLPUBLIC NfCurrencyEntry
210 OUString aSymbol; /// currency symbol
211 OUString aBankSymbol; /// currency abbreviation
212 LanguageType eLanguage; /// language/country value
213 sal_uInt16 nPositiveFormat; /// position of symbol
214 sal_uInt16 nNegativeFormat; /// position of symbol and type and position of negative sign
215 sal_uInt16 nDigits; /// count of decimal digits
216 sal_Unicode cZeroChar; /// which character is used for zeros as last decimal digits
218 NfCurrencyEntry( const NfCurrencyEntry& ) SAL_DELETED_FUNCTION;
219 NfCurrencyEntry& operator=( const NfCurrencyEntry& ) SAL_DELETED_FUNCTION;
221 private:
223 // nDecimalFormat := 0, 1, 2
224 // #,##0 or #,##0.00 or #,##0.-- is returned
225 SVL_DLLPRIVATE OUString Impl_BuildFormatStringNumChars( const LocaleDataWrapper&, sal_uInt16 nDecimalFormat) const;
227 public:
229 NfCurrencyEntry( const LocaleDataWrapper& rLocaleData,
230 LanguageType eLang );
231 NfCurrencyEntry( const ::com::sun::star::i18n::Currency & rCurr,
232 const LocaleDataWrapper& rLocaleData,
233 LanguageType eLang );
234 inline NfCurrencyEntry(const OUString& rSymbol, const OUString& rBankSymbol,
235 LanguageType eLang, sal_uInt16 nPositiveFmt,
236 sal_uInt16 nNegativeFmt, sal_uInt16 nDig, sal_Unicode cZero);
237 ~NfCurrencyEntry() {}
239 inline NfCurrencyEntry* Clone() const;
241 /// Symbols and language identical
242 bool operator==( const NfCurrencyEntry& r ) const;
244 const OUString& GetSymbol() const { return aSymbol; }
245 const OUString& GetBankSymbol() const { return aBankSymbol; }
246 LanguageType GetLanguage() const { return eLanguage; }
247 sal_uInt16 GetPositiveFormat() const { return nPositiveFormat; }
248 sal_uInt16 GetNegativeFormat() const { return nNegativeFormat; }
249 sal_uInt16 GetDigits() const { return nDigits; }
250 sal_Unicode GetZeroChar() const { return cZeroChar; }
252 /** [$DM-407] (bBank==false) or [$DEM] (bBank==true)
253 is returned. If bBank==false and
254 bWithoutExtension==true only [$DM] */
255 OUString BuildSymbolString(bool bBank, bool bWithoutExtension = false) const;
257 /** #,##0.00 [$DM-407] is returned, separators
258 from rLoc, incl. minus sign but without [RED] */
259 OUString BuildPositiveFormatString(bool bBank, const LocaleDataWrapper&,
260 sal_uInt16 nDecimalFormat = 1) const;
261 OUString BuildNegativeFormatString(bool bBank, const LocaleDataWrapper&,
262 sal_uInt16 nDecimalFormat = 1) const;
264 /** [$DM-407] (or [$DEM] if bBank==true)
265 is appended/prepended to rStr, incl. minus sign */
266 void CompletePositiveFormatString(OUStringBuffer& rStr, bool bBank,
267 sal_uInt16 nPosiFormat) const;
268 void CompleteNegativeFormatString(OUStringBuffer& rStr, bool bBank,
269 sal_uInt16 nNegaFormat) const;
271 /// rSymStr is appended/prepended to rStr, incl. minus sign
272 static void CompletePositiveFormatString(OUStringBuffer& rStr,
273 const OUString& rSymStr, sal_uInt16 nPosiFormat);
274 static void CompleteNegativeFormatString(OUStringBuffer& rStr,
275 const OUString& rSymStr, sal_uInt16 nNegaFormat);
277 /** Representation of a currency (symbol position and
278 negative sign) in other language settings */
279 static sal_uInt16 GetEffectivePositiveFormat( sal_uInt16 nIntlFormat,
280 sal_uInt16 nCurrFormat, bool bBank );
281 static sal_uInt16 GetEffectiveNegativeFormat( sal_uInt16 nIntlFormat,
282 sal_uInt16 nCurrFormat, bool bBank );
284 /// General Unicode Euro symbol
285 static inline sal_Unicode GetEuroSymbol() { return sal_Unicode(0x20AC); }
289 * Necessary for ptr_vector on Windows. Please don't remove these, or at
290 * least check it on Windows before attempting to remove them.
292 NfCurrencyEntry::NfCurrencyEntry(const OUString& rSymbol, const OUString& rBankSymbol,
293 LanguageType eLang, sal_uInt16 nPositiveFmt,
294 sal_uInt16 nNegativeFmt, sal_uInt16 nDig, sal_Unicode cZero)
295 : aSymbol(rSymbol), aBankSymbol(rBankSymbol), eLanguage(eLang)
296 , nPositiveFormat(nPositiveFmt), nNegativeFormat(nNegativeFmt)
297 , nDigits(nDig), cZeroChar(cZero)
301 NfCurrencyEntry* NfCurrencyEntry::Clone() const
303 return new NfCurrencyEntry(
304 aSymbol, aBankSymbol, eLanguage, nPositiveFormat, nNegativeFormat, nDigits, cZeroChar);
307 inline NfCurrencyEntry* new_clone( const NfCurrencyEntry& r )
309 return r.Clone();
312 typedef std::vector< OUString > NfWSStringsDtor;
314 class SvNumberFormatterRegistry_Impl;
315 class NfCurrencyTable;
317 class SVL_DLLPUBLIC SvNumberFormatter
319 public:
321 * We can't technically have an "infinite" value, so we use an arbitrary
322 * upper precision threshold to represent the "unlimited" precision.
324 static const sal_uInt16 UNLIMITED_PRECISION;
327 * Precision suitable for numbers displayed in input bar, for instance
328 * Calc's formula input bar.
330 static const sal_uInt16 INPUTSTRING_PRECISION;
332 /// Preferred ctor with service manager and language/country enum
333 SvNumberFormatter(
334 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
335 LanguageType eLang
338 ~SvNumberFormatter();
340 /// Set CallBack to ColorTable
341 void SetColorLink( const Link<>& rColorTableCallBack );
342 /// Do the CallBack to ColorTable
343 Color* GetUserDefColor(sal_uInt16 nIndex);
345 /// Change language/country, also input and format scanner
346 void ChangeIntl( LanguageType eLnge );
347 /// Change the reference null date
348 void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear);
349 /// Change standard precision
350 void ChangeStandardPrec(short nPrec);
351 /// Set zero value suppression
352 void SetNoZero(bool bNZ);
354 /** The language with which the formatter was initialized (system setting),
355 NOT the current language after a ChangeIntl() */
356 LanguageType GetLanguage() const;
358 // Determine whether two format types are input compatible or not
359 bool IsCompatible(short eOldType, short eNewType);
361 /** Get table of formats of a specific type of a locale. A format FIndex is
362 tested whether it has the type and locale requested, if it doesn't
363 match FIndex returns the default format for the type/locale. If no
364 specific format is to be selected FIndex may be initialized to 0. */
365 SvNumberFormatTable& GetEntryTable(short eType,
366 sal_uInt32& FIndex,
367 LanguageType eLnge);
369 /** Get table of formats of a specific type of a language/country.
370 FIndex returns the default format of that type.
371 If the language/country was never touched before new entries are generated */
372 SvNumberFormatTable& ChangeCL(short eType,
373 sal_uInt32& FIndex,
374 LanguageType eLnge);
376 /** Get table of formats of the same type as FIndex; eType and rLnge are
377 set accordingly. An unknown format is set to Standard/General */
378 SvNumberFormatTable& GetFirstEntryTable(short& eType,
379 sal_uInt32& FIndex,
380 LanguageType& rLnge);
382 /// Delete an entry including the format it is referring to
383 void DeleteEntry(sal_uInt32 nKey);
385 /** Create new entry of a format code string for language/country.
386 @return
387 <TRUE/> if string new and ok and inserted.
388 <FALSE/> if string already exists or an unresolvable parse error
389 occurred, in which case nCheckPos is the error position within rString.
390 If the error occurs at position 0 or rString is empty nCheckPos
391 will be 1, so an error in the string is always indicated by
392 nCheckPos not being zero.
393 The content of the rString variable can be changed and corrected
394 by the method.
395 nType contains the type of the format.
396 nKey contains the index key of the format.
398 bool PutEntry( OUString& rString, sal_Int32& nCheckPos, short& nType, sal_uInt32& nKey,
399 LanguageType eLnge = LANGUAGE_DONTKNOW );
401 /** Same as <method>PutEntry</method> but the format code string is
402 considered to be of language/country eLnge and is converted to
403 language/country eNewLnge */
404 bool PutandConvertEntry( OUString& rString, sal_Int32& nCheckPos,
405 short& nType, sal_uInt32& nKey,
406 LanguageType eLnge, LanguageType eNewLnge );
408 /** Same as <method>PutandConvertEntry</method> but the format code string
409 is considered to be of the System language/country eLnge and is
410 converted to another System language/country eNewLnge. In this case
411 the automatic currency is converted too. */
412 bool PutandConvertEntrySystem( OUString& rString, sal_Int32& nCheckPos,
413 short& nType, sal_uInt32& nKey,
414 LanguageType eLnge, LanguageType eNewLnge );
416 /** Similar to <method>PutEntry</method> and
417 <method>PutandConvertEntry</method> or
418 <method>PutandConvertEntrySystem</method>, the format code string
419 passed is considered to be of language/country eLnge. If
420 eLnge==LANGUAGE_SYSTEM the format code has to match eSysLnge, and if
421 eSysLnge is not the current application locale the format code is
422 converted to the current locale. Additionally, if the format code
423 represents an old "automatic" currency format, it is converted to the
424 new default currency format of the eLnge locale. The rString format
425 code passed as an argument may get adapted in case eLnge was used (or
426 is LANGUAGE_SYSTEM and eSysLnge is identical); in case it wasn't the
427 method works on a copy instead, otherwise the resulting string would
428 not match eSysLnge anymore.
430 <p> This method was introduced to handle the legacy currency formats of
431 the "autotbl.fmt" file used by Calc and Writer and convert them to
432 fixed currency codes of the actual currency. Note that in the case of
433 legacy currency formats no special attribution is converted, only the
434 default currency format of the locale is chosen, and that new fixed
435 currency codes are of course not converted to other currencies. The
436 method may also be used as a general method taking, converting and
437 inserting almost arbitrary format codes. To insert or use, for example,
438 the default currency format code matching the current locale, the
439 method could be called with<br/>
441 <code>
442 GetIndexPuttingAndConverting( "0 $", LANGUAGE_SYSTEM, LANGUAGE_ENGLISH_US, ...);
443 </code>
445 @return
446 The index key of the resulting number format. If the format code
447 was empty, could not be converted or has errors, the eLnge locale's
448 standard number format is chosen instead. The index key is
449 guaranteed to represent some valid number format. If
450 rNewInserted==false and rCheckPos>0 the format code has errors
451 and/or could not be converted.
453 sal_uInt32 GetIndexPuttingAndConverting( OUString & rString, LanguageType eLnge,
454 LanguageType eSysLnge, short & rType,
455 bool & rNewInserted, sal_Int32 & rCheckPos );
457 /** Create a format code string using format nIndex as a template and
458 applying other settings (passed from the dialog) */
459 OUString GenerateFormat(sal_uInt32 nIndex,
460 LanguageType eLnge = LANGUAGE_DONTKNOW,
461 bool bThousand = false, bool IsRed = false,
462 sal_uInt16 nPrecision = 0, sal_uInt16 nAnzLeading = 1);
464 /** Analyze an input string
465 @return
466 <TRUE/> if input is a number or is matching a format F_Index
467 F_Index is set to a matching format if number, the value is
468 returned in fOutNumber
469 <FALSE/> if input is not a number
471 bool IsNumberFormat( const OUString& sString, sal_uInt32& F_Index, double& fOutNumber );
473 /// Format a number according to a format index, return string and color
474 void GetOutputString( const double& fOutNumber, sal_uInt32 nFIndex,
475 OUString& sOutString, Color** ppColor, bool bUseStarFormat = false );
477 /** Format a string according to a format index, return string and color.
478 Formats only if the format code is of type text or the 4th subcode
479 of a format code is specified, otherwise sOutString will be == "" */
480 void GetOutputString( const OUString& sString, sal_uInt32 nFIndex,
481 OUString& sOutString, Color** ppColor, bool bUseStarFormat = false );
483 /** Format a number according to the standard default format matching
484 the given format index */
485 void GetInputLineString( const double& fOutNumber,
486 sal_uInt32 nFIndex, OUString& rOutString );
488 /** Format a number according to a format code string to be scanned.
489 @return
490 <FALSE/> if format code contains an error
491 <TRUE/> else, in which case the string and color are returned.
493 bool GetPreviewString(const OUString& sFormatString,
494 double fPreviewNumber,
495 OUString& sOutString,
496 Color** ppColor,
497 LanguageType eLnge,
498 bool bUseStarFormat = false );
500 /** Same as <method>GetPreviewString</method> but the format code string
501 may be either language/country eLnge or en_US english US */
502 bool GetPreviewStringGuess( const OUString& sFormatString, double fPreviewNumber,
503 OUString& sOutString, Color** ppColor,
504 LanguageType eLnge = LANGUAGE_DONTKNOW );
506 /** Format a string according to a format code string to be scanned.
507 @return
508 <FALSE/> if format code contains an error
509 <TRUE/> else, in which case the string and color are returned.
511 bool GetPreviewString( const OUString& sFormatString, const OUString& sPreviewString,
512 OUString& sOutString, Color** ppColor,
513 LanguageType eLnge = LANGUAGE_DONTKNOW );
515 /** Test whether the format code string is already present in container
516 @return
517 NUMBERFORMAT_ENTRY_NOT_FOUND if not found, else the format index.
519 sal_uInt32 TestNewString( const OUString& sFormatString,
520 LanguageType eLnge = LANGUAGE_DONTKNOW );
522 /// Whether format index nFIndex is of type text or not
523 bool IsTextFormat(sal_uInt32 nFIndex) const;
525 /// Get additional info of a format index, e.g. for dialog box
526 void GetFormatSpecialInfo(sal_uInt32 nFormat, bool& bThousand, bool& IsRed,
527 sal_uInt16& nPrecision, sal_uInt16& nAnzLeading);
529 /// Count of decimals
530 sal_uInt16 GetFormatPrecision( sal_uInt32 nFormat ) const;
532 /// Count of integer digits
533 sal_uInt16 GetFormatIntegerDigits( sal_uInt32 nFormat ) const;
535 /** Get additional info of a format code string, e.g. for dialog box.
536 Uses a temporary parse, if possible use only if format code is not
537 present in container yet, otherwise ineffective.
538 @return
539 0 if format code string parsed without errors, otherwise error
540 position (like nCheckPos on <method>PutEntry</method>)
542 sal_uInt32 GetFormatSpecialInfo( const OUString&, bool& bThousand, bool& IsRed,
543 sal_uInt16& nPrecision, sal_uInt16& nAnzLeading,
544 LanguageType eLnge = LANGUAGE_DONTKNOW );
546 /// Check if format code string may be deleted by user
547 bool IsUserDefined( const OUString& sStr, LanguageType eLnge = LANGUAGE_DONTKNOW );
549 /** Return the format index of the format code string for language/country,
550 or NUMBERFORMAT_ENTRY_NOT_FOUND */
551 sal_uInt32 GetEntryKey( const OUString& sStr, LanguageType eLnge = LANGUAGE_DONTKNOW );
553 /// Return the format for a format index
554 const SvNumberformat* GetEntry( sal_uInt32 nKey ) const;
556 /// Return the format index of the standard default number format for language/country
557 sal_uInt32 GetStandardIndex(LanguageType eLnge = LANGUAGE_DONTKNOW);
559 /// Return the format index of the default format of a type for language/country
560 sal_uInt32 GetStandardFormat(short eType, LanguageType eLnge = LANGUAGE_DONTKNOW);
562 /** Return the format index of the default format of a type for language/country.
563 Maybe not the default format but a special builtin format, e.g. for
564 NF_TIME_HH_MMSS00, if that format is passed in nFIndex. */
565 sal_uInt32 GetStandardFormat( sal_uInt32 nFIndex, short eType, LanguageType eLnge );
567 /** Return the format index of the default format of a type for language/country.
568 Maybe not the default format but a special builtin format, e.g. for
569 NF_TIME_HH_MMSS00, or NF_TIME_HH_MMSS if fNumber >= 1.0 */
570 sal_uInt32 GetStandardFormat( double fNumber, sal_uInt32 nFIndex, short eType,
571 LanguageType eLnge );
573 /// Whether nFIndex is a special builtin format
574 bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
576 /** Return the corresponding edit format of a format. */
577 sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType,
578 LanguageType eLnge, SvNumberformat* pFormat );
580 /// Return the reference date
581 Date* GetNullDate();
582 /// Return the standard decimal precision
583 sal_uInt16 GetStandardPrec();
584 /// Return whether zero suppression is switched on
585 bool GetNoZero();
586 /** Get the type of a format (or css::util::NumberFormat::UNDEFINED if no entry),
587 but with css::util::NumberFormat::DEFINED masked out */
588 short GetType(sal_uInt32 nFIndex);
590 /// As the name says
591 void ClearMergeTable();
592 /// Merge in all new entries from rNewTable and return a table of resulting new format indices
593 SvNumberFormatterIndexTable* MergeFormatter(SvNumberFormatter& rNewTable);
595 /// Whether a merge table is present or not
596 bool HasMergeFormatTable() const;
597 /// Return the new format index for an old format index, if a merge table exists
598 sal_uInt32 GetMergeFormatIndex( sal_uInt32 nOldFmt ) const;
600 /** Convert the ugly old tools' Table type bloated with new'ed sal_uInt32
601 entries merge table to ::std::map with old index key and new index key.
602 @ATTENTION! Also clears the old table using ClearMergeTable() */
603 SvNumberFormatterMergeMap ConvertMergeTableToMap();
605 /// Return the last used position ever of a language/country combination
606 sal_uInt16 GetLastInsertKey(sal_uInt32 CLOffset);
608 /** Return the format index of a builtin format for a specific language/country.
609 If nFormat is not a builtin format nFormat is returned. */
610 sal_uInt32 GetFormatForLanguageIfBuiltIn( sal_uInt32 nFormat,
611 LanguageType eLnge = LANGUAGE_DONTKNOW );
613 /** Return the format index for a builtin format of a specific language
614 @see NfIndexTableOffset
616 sal_uInt32 GetFormatIndex( NfIndexTableOffset, LanguageType eLnge = LANGUAGE_DONTKNOW );
618 /** Return enum index of a format index of a builtin format,
619 NF_INDEX_TABLE_ENTRIES if it's not a builtin format.
620 @see NfIndexTableOffset
622 NfIndexTableOffset GetIndexTableOffset( sal_uInt32 nFormat ) const;
624 /** Set evaluation type and order of input date strings
625 @see NfEvalDateFormat
627 void SetEvalDateFormat( NfEvalDateFormat eEDF );
628 NfEvalDateFormat GetEvalDateFormat() const;
630 /** Set TwoDigitYearStart, how the input string scanner handles a two digit year.
631 Default from VCL: 1930, 30-99 19xx, 00-29 20xx
633 <p> Historically (prior to src513e) it was a two digit number determing
634 until which number the string scanner recognizes a year to be 20xx,
635 default <= 29 is used by SFX/OfaMiscCfg.
636 The name Year2000 is kept although the actual functionality is now a
637 TwoDigitYearStart which might be in any century.
639 void SetYear2000( sal_uInt16 nVal );
640 sal_uInt16 GetYear2000() const;
641 static sal_uInt16 GetYear2000Default();
643 sal_uInt16 ExpandTwoDigitYear( sal_uInt16 nYear ) const;
644 static sal_uInt16 ExpandTwoDigitYear( sal_uInt16 nYear, sal_uInt16 nTwoDigitYearStart );
646 /// DEPRECATED: Return first character of the decimal separator of the current language/country
647 sal_Unicode GetDecSep() const;
649 /// Return the decimal separator matching the locale of the given format
650 OUString GetFormatDecimalSep( sal_uInt32 nFormat ) const;
652 /// Return a NfCurrencyTable with pointers to <type>NfCurrencyEntry</type> entries
653 static const NfCurrencyTable& GetTheCurrencyTable();
655 /** Searches, according to the default locale currency, an entry of the
656 CurrencyTable which is <bold>not</bold> the first (LANGUAGE_SYSTEM) entry.
657 @return
658 <NULL/> if not found
659 else pointer to NfCurrencyEntry
661 static const NfCurrencyEntry* MatchSystemCurrency();
663 /** Return a NfCurrencyEntry matching a language/country.
664 If language/country is LANGUAGE_SYSTEM a <method>MatchSystemCurrency</method>
665 call is tried to get an entry. If that fails or the corresponding
666 language/country is not present the entry for LANGUAGE_SYSTEM is returned.
668 static const NfCurrencyEntry& GetCurrencyEntry( LanguageType );
670 /** Return a NfCurrencyEntry pointer matching a language/country
671 and currency abbreviation (AKA banking symbol).
672 This method is meant for the configuration of the default currency.
673 @return
674 <NULL/> if not found
675 else pointer to NfCurrencyEntry
677 static const NfCurrencyEntry* GetCurrencyEntry( const OUString& rAbbrev,
678 LanguageType eLang );
680 /** Return a NfCurrencyEntry pointer matching the symbol
681 combination of a LegacyOnly currency. Note that this means only that
682 the currency matching both symbols was once used in the Office, but is
683 not offered in dialogs anymore. It doesn't even mean that the currency
684 symbol combination is valid, since the reason for removing it may have
685 been just that. #i61657#
686 @return
687 A matching entry, or else <NULL/>.
689 static const NfCurrencyEntry* GetLegacyOnlyCurrencyEntry( const OUString& rSymbol, const OUString& rAbbrev );
691 /** Set the default system currency. The combination of abbreviation and
692 language must match an existent element of theCurrencyTable. If not,
693 the SYSTEM (current locale) entry becomes the default.
694 This method is meant for the configuration of the default currency.
696 static void SetDefaultSystemCurrency( const OUString& rAbbrev, LanguageType eLang );
698 /** Get all standard formats for a specific currency, formats are
699 appended to the NfWSStringsDtor list.
700 @param bBank
701 <TRUE/>: generate only format strings with currency abbreviation
702 <FALSE/>: mixed format strings
703 @return
704 position of default format
706 sal_uInt16 GetCurrencyFormatStrings( NfWSStringsDtor&, const NfCurrencyEntry&,
707 bool bBank ) const;
709 /** Whether nFormat is of type css::util::NumberFormat::CURRENCY and the format code
710 contains a new SYMBOLTYPE_CURRENCY and if so which one [$xxx-nnn].
711 If ppEntry is not NULL and exactly one entry is found, a [$xxx-nnn] is
712 returned, even if the format code only contains [$xxx] !
714 bool GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString& rSymbol,
715 const NfCurrencyEntry** ppEntry = NULL,
716 bool* pBank = NULL ) const;
718 /** Look up the corresponding NfCurrencyEntry matching
719 rSymbol (may be CurrencySymbol or CurrencyAbbreviation) and possibly
720 a rExtension (being yyy of [$xxx-yyy]) or a given language/country
721 value. Tries to match a rSymbol with rExtension first, then with
722 eFormatLanguage, then rSymbol only. This is because a currency entry
723 might have been constructed using I18N locale data where a used locale
724 of a currrency format code must not necessarily match the locale of
725 the locale data itself, e.g. [$HK$-40C] (being "zh_HK" locale) in
726 zh_CN locale data. Here the rExtension would have the value 0x40c but
727 eFormatLanguage of the number format would have the value of zh_CN
728 locale, the value with which the corresponding CurrencyEntry is
729 constructed.
731 @param bFoundBank
732 Only used for output.
733 If the return value is not <NULL/> this value is set to <TRUE/> if
734 the matching entry was found by comparing rSymbol against the
735 CurrencyAbbreviation (AKA BankSymbol).
736 If the return value is <NULL/> the value of bFoundBank is undefined.
737 @param rSymbol
738 Currency symbol, preferably obtained of a format by a call to
739 <method>SvNumberformat::GetNewCurrencySymbol()</method>
740 @param rExtension
741 Currency extension, preferably obtained of a format by a call to
742 <method>SvNumberformat::GetNewCurrencySymbol()</method>
743 @param eFormatLanguage
744 The language/country value of the format of which rSymbol and
745 rExtension are obtained (<method>SvNumberformat::GetLanguage()</method>).
746 @param bOnlyStringLanguage
747 If <TRUE/> only entries with language/country of rExtension are
748 checked, no match on eFormatLanguage. If rExtension is empty all
749 entries are checked.
750 @return
751 The matching entry if unique (in which case bFoundBank is set),
752 else <NULL/>.
754 static const NfCurrencyEntry* GetCurrencyEntry( bool & bFoundBank,
755 const OUString& rSymbol,
756 const OUString& rExtension,
757 LanguageType eFormatLanguage,
758 bool bOnlyStringLanguage = false );
760 /// Get compatibility ("automatic" old style) currency from I18N locale data
761 void GetCompatibilityCurrency( OUString& rSymbol, OUString& rAbbrev ) const;
763 /// Fill rList with the language/country codes that have been allocated
764 void GetUsedLanguages( std::vector<sal_uInt16>& rList );
766 /// Fill a NfKeywordIndex table with keywords of a language/country
767 void FillKeywordTable( NfKeywordTable& rKeywords, LanguageType eLang );
769 /** Return a keyword for a language/country and NfKeywordIndex
770 for XML import, to generate number format strings. */
771 OUString GetKeyword( LanguageType eLnge, sal_uInt16 nIndex );
773 /** Return the GENERAL keyword in proper case ("General") for a
774 language/country, used in XML import */
775 OUString GetStandardName( LanguageType eLnge );
777 /** Check if a specific locale has supported locale data. */
778 static bool IsLocaleInstalled( LanguageType eLang );
780 private:
781 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
782 LanguageTag maLanguageTag;
783 SvNumberFormatTable aFTable; // Table of format keys to format entries
784 typedef std::map<sal_uInt32, sal_uInt32> DefaultFormatKeysMap;
785 DefaultFormatKeysMap aDefaultFormatKeys; // Table of default standard to format keys
786 SvNumberFormatTable* pFormatTable; // For the UI dialog
787 SvNumberFormatterIndexTable* pMergeTable; // List of indices for merging two formatters
788 CharClass* pCharClass; // CharacterClassification
789 OnDemandLocaleDataWrapper xLocaleData; // LocaleData switched between SYSTEM, ENGLISH and other
790 OnDemandTransliterationWrapper xTransliteration; // Transliteration loaded on demand
791 OnDemandCalendarWrapper xCalendar; // Calendar loaded on demand
792 OnDemandNativeNumberWrapper xNatNum; // Native number service loaded on demand
793 ImpSvNumberInputScan* pStringScanner; // Input string scanner
794 ImpSvNumberformatScan* pFormatScanner; // Format code string scanner
795 Link<> aColorLink; // User defined color table CallBack
796 sal_uInt32 MaxCLOffset; // Max language/country offset used
797 sal_uInt32 nDefaultSystemCurrencyFormat; // NewCurrency matching SYSTEM locale
798 LanguageType IniLnge; // Initialized setting language/country
799 LanguageType ActLnge; // Current setting language/country
800 NfEvalDateFormat eEvalDateFormat; // DateFormat evaluation
801 bool bNoZero; // Zero value suppression
803 // cached locale data items needed almost any time
804 OUString aDecimalSep;
805 OUString aThousandSep;
806 OUString aDateSep;
808 SVL_DLLPRIVATE static bool bCurrencyTableInitialized;
809 SVL_DLLPRIVATE static sal_uInt16 nSystemCurrencyPosition;
810 SVL_DLLPRIVATE static SvNumberFormatterRegistry_Impl* pFormatterRegistry;
812 // get the registry, create one if none exists
813 SVL_DLLPRIVATE static SvNumberFormatterRegistry_Impl& GetFormatterRegistry();
815 // called by ctors
816 SVL_DLLPRIVATE void ImpConstruct( LanguageType eLang );
818 // Generate builtin formats provided by i18n behind CLOffset,
819 // if bNoAdditionalFormats==false also generate additional i18n formats.
820 SVL_DLLPRIVATE void ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditionalFormats );
822 // Generate additional formats provided by i18n
823 SVL_DLLPRIVATE void ImpGenerateAdditionalFormats( sal_uInt32 CLOffset,
824 NumberFormatCodeWrapper& rNumberFormatCode,
825 bool bAfterChangingSystemCL );
827 SVL_DLLPRIVATE SvNumberformat* ImpInsertFormat( const ::com::sun::star::i18n::NumberFormatCode& rCode,
828 sal_uInt32 nPos,
829 bool bAfterChangingSystemCL = false,
830 sal_Int16 nOrgIndex = 0 );
832 // Return CLOffset or (MaxCLOffset + SV_COUNTRY_LANGUAGE_OFFSET) if new language/country
833 SVL_DLLPRIVATE sal_uInt32 ImpGetCLOffset(LanguageType eLnge) const;
835 // Test whether format code already exists, then return index key,
836 // otherwise NUMBERFORMAT_ENTRY_NOT_FOUND
837 SVL_DLLPRIVATE sal_uInt32 ImpIsEntry( const OUString& rString,
838 sal_uInt32 CLOffset,
839 LanguageType eLnge );
841 // Create builtin formats for language/country if necessary, return CLOffset
842 SVL_DLLPRIVATE sal_uInt32 ImpGenerateCL( LanguageType eLnge, bool bNoAdditionalFormats = false );
844 // Build negative currency format, old compatibility style
845 SVL_DLLPRIVATE void ImpGetNegCurrFormat(OUStringBuffer& sNegStr, const OUString& rCurrSymbol);
846 // Build positive currency format, old compatibility style
847 SVL_DLLPRIVATE void ImpGetPosCurrFormat(OUStringBuffer& sPosStr, const OUString& rCurrSymbol);
849 // Create theCurrencyTable with all <type>NfCurrencyEntry</type>
850 SVL_DLLPRIVATE static void ImpInitCurrencyTable();
852 // Return the format index of the currency format of the system locale.
853 // Format is created if not already present.
854 SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultSystemCurrencyFormat();
856 // Return the format index of the currency format of the current locale.
857 // Format is created if not already present.
858 SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultCurrencyFormat();
860 // Return the default format for a given type and current locale.
861 // May ONLY be called from within GetStandardFormat().
862 SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultFormat( short nType );
864 // Return the index in a sequence of format codes matching an enum of
865 // NfIndexTableOffset. If not found 0 is returned. If the sequence doesn't
866 // contain any format code elements a default element is created and inserted.
867 SVL_DLLPRIVATE sal_Int32 ImpGetFormatCodeIndex( ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode >& rSeq,
868 const NfIndexTableOffset nTabOff );
870 // Adjust a sequence of format codes to contain only one (THE) default
871 // instead of multiple defaults for short/medium/long types.
872 // If there is no medium but a short and a long default the long is taken.
873 // Return the default index in the sequence.
874 // Non-PRODUCT version may check locale data for matching defaults in one
875 // FormatElement group.
876 SVL_DLLPRIVATE sal_Int32 ImpAdjustFormatCodeDefault( ::com::sun::star::i18n::NumberFormatCode * pFormatArr,
877 sal_Int32 nCount, bool bCheckCorrectness = true );
879 // Obtain the format entry for a given key index.
880 SVL_DLLPRIVATE SvNumberformat* GetFormatEntry( sal_uInt32 nKey );
881 SVL_DLLPRIVATE const SvNumberformat* GetFormatEntry( sal_uInt32 nKey ) const;
883 // used as a loop body inside of GetNewCurrencySymbolString() and GetCurrencyEntry()
884 static bool ImpLookupCurrencyEntryLoopBody(
885 const NfCurrencyEntry*& pFoundEntry, bool& bFoundBank, const NfCurrencyEntry* pData,
886 sal_uInt16 nPos, const OUString& rSymbol );
888 // link to be set at <method>SvtSysLocaleOptions::SetCurrencyChangeLink()</method>
889 DECL_DLLPRIVATE_STATIC_LINK( SvNumberFormatter, CurrencyChangeLink, void* );
891 // return position of a special character
892 sal_Int32 ImpPosToken ( const OUStringBuffer & sFormat, sal_Unicode token, sal_Int32 nStartPos = 0 );
894 public:
896 // own static mutex, may also be used by internal class SvNumberFormatterRegistry_Impl
897 static ::osl::Mutex& GetMutex();
899 // called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
900 void ResetDefaultSystemCurrency();
902 // Called by SvNumberFormatterRegistry_Impl::Notify if the system locale's
903 // date acceptance patterns change.
904 void InvalidateDateAcceptancePatterns();
906 // Replace the SYSTEM language/country format codes. Called upon change of
907 // the user configurable locale.
908 // Old compatibility codes are replaced, user defined are converted, and
909 // new format codes are appended.
910 void ReplaceSystemCL( LanguageType eOldLanguage );
912 css::uno::Reference<css::uno::XComponentContext> GetComponentContext() const;
914 //! The following method is not to be used from outside but must be
915 //! public for the InputScanner.
916 // return the current FormatScanner
917 const ImpSvNumberformatScan* GetFormatScanner() const;
919 //! The following methods are not to be used from outside but must be
920 //! public for the InputScanner and FormatScanner.
922 // return current (!) Locale
923 const LanguageTag& GetLanguageTag() const;
925 // return corresponding Transliteration wrapper
926 const ::utl::TransliterationWrapper* GetTransliteration() const;
928 // return the corresponding CharacterClassification wrapper
929 const CharClass* GetCharClass() const;
931 // return the corresponding LocaleData wrapper
932 const LocaleDataWrapper* GetLocaleData() const;
934 // return the corresponding Calendar wrapper
935 CalendarWrapper* GetCalendar() const;
937 // return the corresponding NativeNumberSupplier wrapper
938 const NativeNumberWrapper* GetNatNum() const;
940 // cached locale data items
942 // return the corresponding decimal separator
943 const OUString& GetNumDecimalSep() const;
945 // return the corresponding group (AKA thousand) separator
946 const OUString& GetNumThousandSep() const;
948 // return the corresponding date separator
949 const OUString& GetDateSep() const;
952 #endif // INCLUDED_SVL_ZFORLIST_HXX
954 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */