sc: filter: rtf: add method "AddFont"
[LibreOffice.git] / include / svl / zforlist.hxx
blobf332d840547009b1dce88a6295358ef94485c4d4
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 <config_options.h>
23 #include <svl/svldllapi.h>
24 #include <rtl/ustrbuf.hxx>
25 #include <rtl/ustring.hxx>
26 #include <o3tl/typed_flags_set.hxx>
27 #include <i18nlangtag/lang.h>
28 #include <com/sun/star/util/NumberFormat.hpp>
29 #include <unotools/localedatawrapper.hxx>
30 #include <tools/link.hxx>
31 #include <svl/ondemand.hxx>
32 #include <svl/nfkeytab.hxx>
34 #include <unordered_map>
35 #include <memory>
37 namespace com::sun::star::i18n { class XNumberFormatCode; }
38 namespace com::sun::star::i18n { struct Currency; }
39 namespace com::sun::star::i18n { struct NumberFormatCode; }
41 class Date;
42 class Color;
43 class CharClass;
44 class CalendarWrapper;
46 class ImpSvNumberformatScan;
47 class ImpSvNumberInputScan;
48 class SvNumberformat;
49 namespace com::sun::star::uno { class XComponentContext; }
51 #define SV_COUNTRY_LANGUAGE_OFFSET 10000 // Max count of formats per country/language
52 #define SV_MAX_COUNT_STANDARD_FORMATS 100 // Max count of builtin default formats per CL
54 constexpr size_t NF_MAX_FORMAT_SYMBOLS = 100;
56 /// The built-in @ Text format, offset within a locale, key in the locale the
57 /// number formatter was constructed with.
58 constexpr sal_uInt32 NF_STANDARD_FORMAT_TEXT = SV_MAX_COUNT_STANDARD_FORMATS;
60 constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND = 0xffffffff; /// MAX_ULONG
62 enum class SvNumFormatType : sal_Int16
64 /** selects all number formats.
66 ALL = css::util::NumberFormat::ALL, // 0
67 /** selects only user-defined number formats.
69 DEFINED = css::util::NumberFormat::DEFINED, // 1
70 /** selects date formats.
72 DATE = css::util::NumberFormat::DATE, // 2
73 /** selects time formats.
75 TIME = css::util::NumberFormat::TIME, // 4
76 /** selects currency formats.
78 CURRENCY = css::util::NumberFormat::CURRENCY, // 8
79 /** selects decimal number formats.
81 NUMBER = css::util::NumberFormat::NUMBER, // 16
82 /** selects scientific number formats.
84 SCIENTIFIC = css::util::NumberFormat::SCIENTIFIC, // 32
85 /** selects number formats for fractions.
87 FRACTION = css::util::NumberFormat::FRACTION, // 64
88 /** selects percentage number formats.
90 PERCENT = css::util::NumberFormat::PERCENT, // 128
91 /** selects text number formats.
93 TEXT = css::util::NumberFormat::TEXT, // 256
94 /** selects number formats which contain date and time.
96 DATETIME = DATE | TIME, // 6
97 /** selects boolean number formats.
99 LOGICAL = css::util::NumberFormat::LOGICAL, // 1024
100 /** is used as a return value if no format exists.
102 UNDEFINED = css::util::NumberFormat::UNDEFINED, // 2048
103 /** @internal is used to flag an empty sub format.
104 @since LibreOffice 5.1
106 EMPTY = css::util::NumberFormat::EMPTY, // 4096
107 /** @internal selects a time duration format.
108 8192 + TIME (4)
109 @since LibreOffice 6.2
111 DURATION = css::util::NumberFormat::DURATION, // 8196
113 namespace o3tl {
114 template<> struct typed_flags<SvNumFormatType> : is_typed_flags<SvNumFormatType, 0x3dff> {};
117 /** enum values for <method>SvNumberFormatter::GetFormatIndex</method>
120 Builtin standard formats, order should be also the arrangement in the
121 dialog list box representation.</p>
124 Date specials:<ul>
125 <li>SYSTEM: As set in System Regional Settings.
126 <li>SYS: short/long defined, order and separators from System Regional Settings.
127 <li>DEF: short/long and order defined, separators from System Regional Settings.
128 <li>DIN: all settings hard coded as DIN (Deutsche Industrie Norm) and EN (European Norm) require.
129 <li>all other: hard coded
130 </ul>
132 Do NOT insert any new values!
133 The values here correspond with those in offapi/com/sun/star/i18n/NumberFormatIndex.idl
134 You may append values though after NF_INDEX_TABLE_LOCALE_DATA_DEFAULTS.
136 enum NfIndexTableOffset
138 NF_NUMERIC_START = 0,
140 NF_NUMBER_START = NF_NUMERIC_START,
141 NF_NUMBER_STANDARD = NF_NUMBER_START, // Standard/General
142 NF_NUMBER_INT, // 0
143 NF_NUMBER_DEC2, // 0.00
144 NF_NUMBER_1000INT, // #,##0
145 NF_NUMBER_1000DEC2, // #,##0.00
146 NF_NUMBER_SYSTEM, // #,##0.00 or whatever is set in System Regional Settings
147 NF_NUMBER_END = NF_NUMBER_SYSTEM,
149 NF_SCIENTIFIC_START,
150 NF_SCIENTIFIC_000E000 = NF_SCIENTIFIC_START, // 0.00E+000
151 NF_SCIENTIFIC_000E00, // 0.00E+00
152 NF_SCIENTIFIC_END = NF_SCIENTIFIC_000E00,
154 NF_PERCENT_START,
155 NF_PERCENT_INT = NF_PERCENT_START, // 0%
156 NF_PERCENT_DEC2, // 0.00%
157 NF_PERCENT_END = NF_PERCENT_DEC2,
159 NF_FRACTION_START,
160 NF_FRACTION_1D = NF_FRACTION_START, // # ?/?
161 NF_FRACTION_2D, // # ??/??
162 NF_FRACTION_END = NF_FRACTION_2D,
164 NF_NUMERIC_END = NF_FRACTION_END,
166 NF_CURRENCY_START,
167 NF_CURRENCY_1000INT = NF_CURRENCY_START,// #,##0 DM
168 NF_CURRENCY_1000DEC2, // #,##0.00 DM
169 NF_CURRENCY_1000INT_RED, // #,##0 DM negative in red
170 NF_CURRENCY_1000DEC2_RED, // #,##0.00 DM negative in red
171 NF_CURRENCY_1000DEC2_CCC, // #,##0.00 DEM currency abbreviation
172 NF_CURRENCY_1000DEC2_DASHED, // #,##0.-- DM
173 NF_CURRENCY_END = NF_CURRENCY_1000DEC2_DASHED,
175 NF_DATE_START,
176 NF_DATE_SYSTEM_SHORT = NF_DATE_START, // 08.10.97
177 NF_DATE_SYSTEM_LONG, // Wednesday, 8. October 1997
178 NF_DATE_SYS_DDMMYY, // 08.10.97
179 NF_DATE_SYS_DDMMYYYY, // 08.10.1997 THE edit format, formatindex="21"
180 NF_DATE_SYS_DMMMYY, // 8. Oct 97
181 NF_DATE_SYS_DMMMYYYY, // 8. Oct 1997
182 NF_DATE_DIN_DMMMYYYY, // 8. Oct. 1997 DIN
183 NF_DATE_SYS_DMMMMYYYY, // 8. October 1997
184 NF_DATE_DIN_DMMMMYYYY, // 8. October 1997 DIN
185 NF_DATE_SYS_NNDMMMYY, // Wed, 8. Okt 97
186 NF_DATE_DEF_NNDDMMMYY, // Wed 08.Okt 97
187 NF_DATE_SYS_NNDMMMMYYYY, // Wed, 8. Oktober 1997
188 NF_DATE_SYS_NNNNDMMMMYYYY, // Wednesday, 8. Oktober 1997
189 NF_DATE_DIN_MMDD, // 10-08 DIN
190 NF_DATE_DIN_YYMMDD, // 97-10-08 DIN
191 NF_DATE_DIN_YYYYMMDD, // 1997-10-08 DIN
192 NF_DATE_ISO_YYYYMMDD = NF_DATE_DIN_YYYYMMDD, // 1997-10-08 ISO clarify with name, formatindex="33"
193 NF_DATE_SYS_MMYY, // 10.97
194 NF_DATE_SYS_DDMMM, // 08.Oct
195 NF_DATE_MMMM, // October
196 NF_DATE_QQJJ, // 4. Quarter 97
197 NF_DATE_WW, // week of year
198 NF_DATE_END = NF_DATE_WW,
200 NF_TIME_START,
201 NF_TIME_HHMM = NF_TIME_START, // HH:MM
202 NF_TIME_HHMMSS, // HH:MM:SS
203 NF_TIME_HHMMAMPM, // HH:MM AM/PM
204 NF_TIME_HHMMSSAMPM, // HH:MM:SS AM/PM
205 NF_TIME_HH_MMSS, // [HH]:MM:SS formatindex="43"
206 NF_TIME_MMSS00, // MM:SS,00 formatindex="44"
207 NF_TIME_HH_MMSS00, // [HH]:MM:SS,00 formatindex="45"
208 NF_TIME_END = NF_TIME_HH_MMSS00,
210 NF_DATETIME_START,
211 NF_DATETIME_SYSTEM_SHORT_HHMM = NF_DATETIME_START, // 08.10.97 01:23
212 NF_DATETIME_SYS_DDMMYYYY_HHMMSS, // 08.10.1997 01:23:45 THE edit format, formatindex="47"
213 NF_DATETIME_END = NF_DATETIME_SYS_DDMMYYYY_HHMMSS,
215 NF_BOOLEAN, // BOOLEAN
216 NF_TEXT, // @
218 NF_INDEX_TABLE_LOCALE_DATA_DEFAULTS, // == 50, old number of predefined entries, i18npool locale data additions start after this
220 // From here on are values of new predefined and built-in formats that are
221 // not in the original NumberFormatIndex.idl
223 // XXX Values appended here must also get a corresponding entry in
224 // svl/source/numbers/zforlist.cxx indexTable[] in the same order.
226 // XXX The dialog's number format shell assumes start/end spans
227 // (NF_..._START and NF_..._END above) to fill its categories with builtin
228 // formats, make new formats known to svx/source/items/numfmtsh.cxx
229 // SvxNumberFormatShell::FillEListWithStd_Impl(), otherwise they will not
230 // be listed at all. Yes that is ugly.
231 // DATETIME formats need to be added to
232 // SvxNumberFormatShell::FillEListWithDateTime_Impl().
234 // New predefined format added to i18npool locale data.
235 NF_DATETIME_SYS_DDMMYYYY_HHMM = NF_INDEX_TABLE_LOCALE_DATA_DEFAULTS, // 08.10.1997 01:23 formatindex="50"
237 // No i18npool defined locale data between here and NF_INDEX_TABLE_ENTRIES.
238 NF_INDEX_TABLE_RESERVED_START,
240 NF_FRACTION_3D = NF_INDEX_TABLE_RESERVED_START, // # ???/???
241 NF_FRACTION_2, // # ?/2
242 NF_FRACTION_4, // # ?/4
243 NF_FRACTION_8, // # ?/8
244 NF_FRACTION_16, // # ??/16
245 NF_FRACTION_10, // # ??/10
246 NF_FRACTION_100, // # ??/100
248 NF_DATETIME_ISO_YYYYMMDD_HHMMSS, // 1997-10-08 01:23:45 ISO (with blank instead of T)
249 NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, // 1997-10-08 01:23:45.678 not quite ISO with locale's separator
250 NF_DATETIME_ISO_YYYYMMDDTHHMMSS, // 1997-10-08T01:23:45 ISO
251 NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, // 1997-10-08T01:23:45,678 ISO with milliseconds and ',' or '.'
253 // XXX When adding values here, follow the comment above about
254 // svx/source/items/numfmtsh.cxx
256 NF_INDEX_TABLE_ENTRIES // == 62, reserved to not be used in i18npool locale data.
258 // XXX Adding values above may increment the reserved area that can't be
259 // used by i18npool's locale data FormatCode definitions, see the
260 // description at i18npool/source/localedata/data/locale.dtd for ELEMENT
261 // FormatCode what the current convention's value is. In that case, the
262 // used formatIndex values in i18npool/source/localedata/data/*.xml will
263 // have to be adjusted.
264 // Overlapping the area will bail out with a check in
265 // SvNumberFormatter::ImpInsertFormat() in debug builds.
269 // #45717# IsNumberFormat( "98-10-24", 30, x ), YMD Format set with DMY
270 // International settings doesn't recognize the string as a date.
271 /** enum values for <method>SvNumberFormatter::SetEvalDateFormat</method>
273 <p>How <method>ImpSvNumberInputScan::GetDateRef</method> shall take the
274 DateFormat order (YMD,DMY,MDY) into account, if called from IsNumberFormat
275 with a date format to match against.
277 enum NfEvalDateFormat
279 /** DateFormat only from International, default. */
280 NF_EVALDATEFORMAT_INTL,
282 /** DateFormat only from date format passed to function (if any).
283 If no date format is passed then the DateFormat is taken from International. */
284 NF_EVALDATEFORMAT_FORMAT,
286 /** First try the DateFormat from International. If it doesn't match a
287 valid date try the DateFormat from the date format passed. */
288 NF_EVALDATEFORMAT_INTL_FORMAT,
290 /** First try the DateFormat from the date format passed. If it doesn't
291 match a valid date try the DateFormat from International. */
292 NF_EVALDATEFORMAT_FORMAT_INTL
296 typedef std::unordered_map<sal_uInt32, SvNumberformat*> SvNumberFormatTable;
297 typedef std::unordered_map<sal_uInt16, sal_uInt32> SvNumberFormatterIndexTable;
298 typedef std::unordered_map< sal_uInt32, sal_uInt32> SvNumberFormatterMergeMap;
301 /** Language/country dependent currency entries
303 class UNLESS_MERGELIBS(SVL_DLLPUBLIC) NfCurrencyEntry final
305 OUString aSymbol; /// currency symbol
306 OUString aBankSymbol; /// currency abbreviation
307 LanguageType eLanguage; /// language/country value
308 sal_uInt16 nPositiveFormat; /// position of symbol
309 sal_uInt16 nNegativeFormat; /// position of symbol and type and position of negative sign
310 sal_uInt16 nDigits; /// count of decimal digits
311 sal_Unicode cZeroChar; /// which character is used for zeros as last decimal digits
313 private:
315 // nDecimalFormat := 0, 1, 2
316 // #,##0 or #,##0.00 or #,##0.-- is returned
317 SVL_DLLPRIVATE OUString Impl_BuildFormatStringNumChars( const LocaleDataWrapper&, sal_uInt16 nDecimalFormat) const;
319 public:
321 NfCurrencyEntry( const LocaleDataWrapper& rLocaleData,
322 LanguageType eLang );
323 NfCurrencyEntry( const css::i18n::Currency & rCurr,
324 const LocaleDataWrapper& rLocaleData,
325 LanguageType eLang );
327 /// Symbols and language identical
328 bool operator==( const NfCurrencyEntry& r ) const;
330 const OUString& GetSymbol() const { return aSymbol; }
331 const OUString& GetBankSymbol() const { return aBankSymbol; }
332 LanguageType GetLanguage() const { return eLanguage; }
333 sal_uInt16 GetPositiveFormat() const { return nPositiveFormat; }
334 sal_uInt16 GetNegativeFormat() const { return nNegativeFormat; }
335 sal_uInt16 GetDigits() const { return nDigits; }
337 /** Only to resolve system locale for currency list. */
338 void SetLanguage( LanguageType nLang ) { eLanguage = nLang; }
340 /** [$DM-407] (bBank==false) or [$DEM] (bBank==true)
341 is returned. If bBank==false and
342 bWithoutExtension==true only [$DM] */
343 OUString BuildSymbolString(bool bBank, bool bWithoutExtension = false) const;
345 /** #,##0.00 [$DM-407] is returned, separators
346 from rLoc, incl. minus sign but without [RED] */
347 OUString BuildPositiveFormatString(bool bBank, const LocaleDataWrapper&,
348 sal_uInt16 nDecimalFormat = 1) const;
349 OUString BuildNegativeFormatString(bool bBank, const LocaleDataWrapper&,
350 sal_uInt16 nDecimalFormat = 1) const;
352 /** [$DM-407] (or [$DEM] if bBank==true)
353 is appended/prepended to rStr, incl. minus sign */
354 void CompletePositiveFormatString(OUStringBuffer& rStr, bool bBank,
355 sal_uInt16 nPosiFormat) const;
356 void CompleteNegativeFormatString(OUStringBuffer& rStr, bool bBank,
357 sal_uInt16 nNegaFormat) const;
359 /// rSymStr is appended/prepended to rStr, incl. minus sign
360 static void CompletePositiveFormatString(OUStringBuffer& rStr,
361 std::u16string_view rSymStr, sal_uInt16 nPosiFormat);
362 static void CompleteNegativeFormatString(OUStringBuffer& rStr,
363 std::u16string_view rSymStr, sal_uInt16 nNegaFormat);
365 /** Representation of a currency (symbol position and
366 negative sign) in other language settings */
367 static sal_uInt16 GetEffectivePositiveFormat( sal_uInt16 nIntlFormat,
368 sal_uInt16 nCurrFormat, bool bBank );
369 static sal_uInt16 GetEffectiveNegativeFormat( sal_uInt16 nIntlFormat,
370 sal_uInt16 nCurrFormat, bool bBank );
372 /// General Unicode Euro symbol
373 static sal_Unicode GetEuroSymbol() { return u'\x20AC'; }
376 typedef std::vector< OUString > NfWSStringsDtor;
378 /** Input options to be used with IsNumberFormat() */
379 enum class SvNumInputOptions : sal_uInt16
381 NONE = 0,
382 LAX_TIME = 1 ///< allow input of minutes or seconds >59
384 namespace o3tl {
385 template<> struct typed_flags<SvNumInputOptions> : is_typed_flags<SvNumInputOptions, 0x0001> {};
389 #endif // INCLUDED_SVL_ZFORLIST_HXX
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */