1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <tools/color.hxx>
22 #include <tools/debug.hxx>
23 #include <i18nlangtag/mslangid.hxx>
24 #include <o3tl/safeint.hxx>
25 #include <svl/numformat.hxx>
26 #include <svl/zforlist.hxx>
27 #include <svl/zformat.hxx>
28 #include <svl/currencytable.hxx>
30 #include <svx/numfmtsh.hxx>
31 #include <svx/flagsdef.hxx>
32 #include <svx/tbcontrl.hxx>
38 double GetDefaultValNum(const SvNumFormatType nType
)
42 case SvNumFormatType::NUMBER
:
43 return fSvxNumValConst
[SvxNumValCategory::Standard
];
44 case SvNumFormatType::CURRENCY
:
45 return fSvxNumValConst
[SvxNumValCategory::Currency
];
46 case SvNumFormatType::PERCENT
:
47 return fSvxNumValConst
[SvxNumValCategory::Percent
];
48 case SvNumFormatType::DATE
:
49 case SvNumFormatType::DATETIME
:
50 return fSvxNumValConst
[SvxNumValCategory::Date
];
51 case SvNumFormatType::TIME
:
52 return fSvxNumValConst
[SvxNumValCategory::Time
];
53 case SvNumFormatType::SCIENTIFIC
:
54 return fSvxNumValConst
[SvxNumValCategory::Scientific
];
55 case SvNumFormatType::FRACTION
:
56 return fSvxNumValConst
[SvxNumValCategory::Fraction
];
57 case SvNumFormatType::LOGICAL
:
58 return fSvxNumValConst
[SvxNumValCategory::Boolean
];
62 return fSvxNumValConst
[SvxNumValCategory::NoValue
];
66 SvxNumberFormatShell
* SvxNumberFormatShell::Create(SvNumberFormatter
* pNumFormatter
,
67 sal_uInt32 nFormatKey
,
68 SvxNumberValueType eNumValType
,
69 const OUString
& rNumStr
)
71 return new SvxNumberFormatShell(pNumFormatter
, nFormatKey
, eNumValType
, rNumStr
);
74 SvxNumberFormatShell
* SvxNumberFormatShell::Create(SvNumberFormatter
* pNumFormatter
,
75 sal_uInt32 nFormatKey
,
76 SvxNumberValueType eNumValType
, double nNumVal
,
77 const OUString
* pNumStr
)
79 return new SvxNumberFormatShell(pNumFormatter
, nFormatKey
, eNumValType
, nNumVal
, pNumStr
);
82 SvxNumberFormatShell::SvxNumberFormatShell(SvNumberFormatter
* pNumFormatter
, sal_uInt32 nFormatKey
,
83 SvxNumberValueType eNumValType
, const OUString
& rNumStr
)
84 : pFormatter(pNumFormatter
)
85 , pCurFmtTable(nullptr)
86 , eValType(eNumValType
)
88 , nCurFormatKey(nFormatKey
)
89 , nCurCategory(SvNumFormatType::ALL
)
90 , eCurLanguage(LANGUAGE_NONE
)
91 , pCurCurrencyEntry(nullptr)
92 , bBankingSymbol(false)
93 , nCurCurrencyEntryPos(sal_uInt16(SELPOS_NONE
))
94 , bUseStarFormat(false)
95 , bIsDefaultValNum(true)
101 case SvxNumberValueType::String
:
104 case SvxNumberValueType::Number
:
107 nValNum
= GetDefaultValNum(pFormatter
->GetType(nCurFormatKey
));
110 case SvxNumberValueType::Undefined
:
116 SvxNumberFormatShell::SvxNumberFormatShell(SvNumberFormatter
* pNumFormatter
, sal_uInt32 nFormatKey
,
117 SvxNumberValueType eNumValType
, double nNumVal
,
118 const OUString
* pNumStr
)
119 : pFormatter(pNumFormatter
)
120 , pCurFmtTable(nullptr)
121 , eValType(eNumValType
)
123 , nCurFormatKey(nFormatKey
)
124 , nCurCategory(SvNumFormatType::ALL
)
125 , eCurLanguage(LANGUAGE_NONE
)
126 , pCurCurrencyEntry(nullptr)
127 , bBankingSymbol(false)
128 , nCurCurrencyEntryPos(sal_uInt16(SELPOS_NONE
))
129 , bUseStarFormat(false)
130 , bIsDefaultValNum(false)
132 // #50441# When used in Writer, the SvxNumberInfoItem contains the
133 // original string in addition to the value
140 case SvxNumberValueType::Number
:
143 case SvxNumberValueType::String
:
144 case SvxNumberValueType::Undefined
:
147 bIsDefaultValNum
= true;
151 SvxNumberFormatShell::~SvxNumberFormatShell()
154 * At this point, depending on whether the added user-defined were
155 * validated (ValidateNewEntries()), the add list is removed from
156 * the number formatter again.
158 * Deleting formats from the formatter happens for Undo reasons
159 * only in the calling instance.
164 // Added formats are invalid => remove them
166 for (const auto& rItem
: aAddList
)
167 pFormatter
->DeleteEntry(rItem
);
171 std::vector
<sal_uInt32
> const& SvxNumberFormatShell::GetUpdateData() const { return aDelList
; }
173 void SvxNumberFormatShell::CategoryChanged(sal_uInt16 nCatLbPos
, short& rFmtSelPos
,
174 std::vector
<OUString
>& rFmtEntries
)
176 SvNumFormatType nOldCategory
= nCurCategory
;
177 PosToCategory_Impl(nCatLbPos
, nCurCategory
);
178 pCurFmtTable
= &(pFormatter
->GetEntryTable(nCurCategory
, nCurFormatKey
, eCurLanguage
));
179 // reinitialize currency if category newly entered
180 if (nCurCategory
== SvNumFormatType::CURRENCY
&& nOldCategory
!= nCurCategory
)
181 pCurCurrencyEntry
= nullptr;
182 rFmtSelPos
= FillEntryList_Impl(rFmtEntries
);
185 void SvxNumberFormatShell::LanguageChanged(LanguageType eLangType
, short& rFmtSelPos
,
186 std::vector
<OUString
>& rFmtEntries
)
188 eCurLanguage
= eLangType
;
189 pCurFmtTable
= &(pFormatter
->ChangeCL(nCurCategory
, nCurFormatKey
, eCurLanguage
));
190 rFmtSelPos
= FillEntryList_Impl(rFmtEntries
);
193 void SvxNumberFormatShell::FormatChanged(sal_uInt16 nFmtLbPos
, OUString
& rPreviewStr
,
194 const Color
*& rpFontColor
)
196 if (static_cast<size_t>(nFmtLbPos
) >= aCurEntryList
.size())
199 nCurFormatKey
= aCurEntryList
[nFmtLbPos
];
201 if (nCurFormatKey
!= NUMBERFORMAT_ENTRY_NOT_FOUND
)
203 GetPreviewString_Impl(rPreviewStr
, rpFontColor
);
205 else if (nCurCategory
== SvNumFormatType::CURRENCY
)
207 if (static_cast<size_t>(nFmtLbPos
) < aCurrencyFormatList
.size())
209 MakePrevStringFromVal(aCurrencyFormatList
[nFmtLbPos
], rPreviewStr
, rpFontColor
,
215 bool SvxNumberFormatShell::AddFormat(OUString
& rFormat
, sal_Int32
& rErrPos
,
216 sal_uInt16
& rCatLbSelPos
, short& rFmtSelPos
,
217 std::vector
<OUString
>& rFmtEntries
)
219 bool bInserted
= false;
220 sal_uInt32 nAddKey
= pFormatter
->GetEntryKey(rFormat
, eCurLanguage
);
222 if (nAddKey
!= NUMBERFORMAT_ENTRY_NOT_FOUND
) // exists already?
224 ::std::vector
<sal_uInt32
>::iterator nAt
= GetRemoved_Impl(nAddKey
);
225 if (nAt
!= aDelList
.end())
232 OSL_FAIL("duplicate format!");
238 bInserted
= pFormatter
->PutEntry(rFormat
, nPos
, nCurCategory
, nAddKey
, eCurLanguage
);
239 rErrPos
= (nPos
>= 0) ? nPos
: -1;
243 // May be sorted under a different locale if LCID was parsed.
244 const SvNumberformat
* pEntry
= pFormatter
->GetEntry(nAddKey
);
247 LanguageType nLang
= pEntry
->GetLanguage();
248 if (eCurLanguage
!= nLang
)
250 // Current language's list would not show entry, adapt.
251 eCurLanguage
= nLang
;
259 nCurFormatKey
= nAddKey
;
260 DBG_ASSERT(GetAdded_Impl(nCurFormatKey
) == aAddList
.end(), "duplicate format!");
261 aAddList
.push_back(nCurFormatKey
);
264 pCurFmtTable
= &(pFormatter
->GetEntryTable(nCurCategory
, nCurFormatKey
, eCurLanguage
));
265 nCurCategory
= pFormatter
->GetType(nAddKey
);
266 CategoryToPos_Impl(nCurCategory
, rCatLbSelPos
);
267 rFmtSelPos
= FillEntryList_Impl(rFmtEntries
);
269 else if (rErrPos
!= 0) // syntax error
273 else // insert twice not possible
275 OSL_FAIL("duplicate format!");
281 void SvxNumberFormatShell::RemoveFormat(std::u16string_view rFormat
, sal_uInt16
& rCatLbSelPos
,
282 short& rFmtSelPos
, std::vector
<OUString
>& rFmtEntries
)
284 sal_uInt32 nDelKey
= pFormatter
->GetEntryKey(rFormat
, eCurLanguage
);
286 DBG_ASSERT(nDelKey
!= NUMBERFORMAT_ENTRY_NOT_FOUND
, "entry not found!");
287 DBG_ASSERT(!IsRemoved_Impl(nDelKey
), "entry already removed!");
289 if ((nDelKey
== NUMBERFORMAT_ENTRY_NOT_FOUND
) || IsRemoved_Impl(nDelKey
))
292 aDelList
.push_back(nDelKey
);
294 ::std::vector
<sal_uInt32
>::iterator nAt
= GetAdded_Impl(nDelKey
);
295 if (nAt
!= aAddList
.end())
300 nCurCategory
= pFormatter
->GetType(nDelKey
);
301 pCurFmtTable
= &(pFormatter
->GetEntryTable(nCurCategory
, nCurFormatKey
, eCurLanguage
));
303 nCurFormatKey
= pFormatter
->GetStandardFormat(nCurCategory
, eCurLanguage
);
305 CategoryToPos_Impl(nCurCategory
, rCatLbSelPos
);
306 rFmtSelPos
= FillEntryList_Impl(rFmtEntries
);
309 void SvxNumberFormatShell::MakeFormat(OUString
& rFormat
, bool bThousand
, bool bNegRed
,
310 sal_uInt16 nPrecision
, sal_uInt16 nLeadingZeroes
,
311 sal_uInt16 nCurrencyPos
)
313 if (aCurrencyFormatList
.size() > static_cast<size_t>(nCurrencyPos
))
315 sal_Int32 rErrPos
= 0;
316 std::vector
<OUString
> aFmtEList
;
319 = pFormatter
->TestNewString(aCurrencyFormatList
[nCurrencyPos
], eCurLanguage
);
321 if (nFound
== NUMBERFORMAT_ENTRY_NOT_FOUND
)
323 sal_uInt16 rCatLbSelPos
= 0;
324 short rFmtSelPos
= 0;
325 AddFormat(aCurrencyFormatList
[nCurrencyPos
], rErrPos
, rCatLbSelPos
, rFmtSelPos
,
331 rFormat
= pFormatter
->GenerateFormat(nCurFormatKey
, eCurLanguage
, bThousand
, bNegRed
,
332 nPrecision
, nLeadingZeroes
);
337 rFormat
= pFormatter
->GenerateFormat(nCurFormatKey
, eCurLanguage
, bThousand
, bNegRed
,
338 nPrecision
, nLeadingZeroes
);
342 sal_uInt16
SvxNumberFormatShell::GetFormatIntegerDigits(std::u16string_view rFormat
) const
344 sal_uInt32 nFmtKey
= pFormatter
->GetEntryKey(rFormat
, eCurLanguage
);
346 return pFormatter
->GetFormatIntegerDigits(nFmtKey
);
349 void SvxNumberFormatShell::GetOptions(const OUString
& rFormat
, bool& rThousand
, bool& rNegRed
,
350 sal_uInt16
& rPrecision
, sal_uInt16
& rLeadingZeroes
,
351 sal_uInt16
& rCatLbPos
)
353 sal_uInt32 nFmtKey
= pFormatter
->GetEntryKey(rFormat
, eCurLanguage
);
355 if (nFmtKey
!= NUMBERFORMAT_ENTRY_NOT_FOUND
)
357 pFormatter
->GetFormatSpecialInfo(nFmtKey
, rThousand
, rNegRed
, rPrecision
, rLeadingZeroes
);
359 CategoryToPos_Impl(pFormatter
->GetType(nFmtKey
), rCatLbPos
);
363 bool bTestBanking
= false;
364 sal_uInt16 nPos
= FindCurrencyTableEntry(rFormat
, bTestBanking
);
366 if (IsInTable(nPos
, bTestBanking
, rFormat
)
367 && pFormatter
->GetFormatSpecialInfo(rFormat
, rThousand
, rNegRed
, rPrecision
,
368 rLeadingZeroes
, eCurLanguage
)
371 rCatLbPos
= CAT_CURRENCY
;
374 rCatLbPos
= CAT_USERDEFINED
;
378 void SvxNumberFormatShell::MakePreviewString(const OUString
& rFormatStr
, OUString
& rPreviewStr
,
379 const Color
*& rpFontColor
)
381 rpFontColor
= nullptr;
383 sal_uInt32 nExistingFormat
= pFormatter
->GetEntryKey(rFormatStr
, eCurLanguage
);
384 if (nExistingFormat
== NUMBERFORMAT_ENTRY_NOT_FOUND
)
386 // real preview - not implemented in NumberFormatter for text formats
387 pFormatter
->GetPreviewString(rFormatStr
, nValNum
, rPreviewStr
, &rpFontColor
, eCurLanguage
,
394 // #50441# if a string was set in addition to the value, use it for text formats
395 bool bUseText
= (eValType
== SvxNumberValueType::String
396 || (!aValStr
.isEmpty()
397 && (pFormatter
->GetType(nExistingFormat
) & SvNumFormatType::TEXT
)));
401 pFormatter
->GetOutputString(aValStr
, nExistingFormat
, rPreviewStr
, &rpFontColor
);
405 if (bIsDefaultValNum
)
406 nValNum
= GetDefaultValNum(pFormatter
->GetType(nExistingFormat
));
407 pFormatter
->GetOutputString(nValNum
, nExistingFormat
, rPreviewStr
, &rpFontColor
,
413 bool SvxNumberFormatShell::IsUserDefined(const OUString
& rFmtString
)
415 sal_uInt32 nFound
= pFormatter
->GetEntryKey(rFmtString
, eCurLanguage
);
418 if (nFound
!= NUMBERFORMAT_ENTRY_NOT_FOUND
)
420 bFlag
= pFormatter
->IsUserDefined(rFmtString
, eCurLanguage
);
424 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nFound
);
426 if (pNumEntry
!= nullptr && pNumEntry
->HasNewCurrency())
429 sal_uInt16 nPos
= FindCurrencyTableEntry(rFmtString
, bTestBanking
);
430 bFlag
= !IsInTable(nPos
, bTestBanking
, rFmtString
);
437 bool SvxNumberFormatShell::FindEntry(const OUString
& rFmtString
, sal_uInt32
* pAt
/* = NULL */)
441 sal_uInt32 nFound
= NUMBERFORMAT_ENTRY_NOT_FOUND
;
442 // There may be multiple builtin entries with the same format code, first
443 // try if the current key matches.
444 const SvNumberformat
* pEntry
= pFormatter
->GetEntry(nCurFormatKey
);
445 if (pEntry
&& pEntry
->GetLanguage() == eCurLanguage
&& pEntry
->GetFormatstring() == rFmtString
)
446 nFound
= nCurFormatKey
;
448 if (nFound
== NUMBERFORMAT_ENTRY_NOT_FOUND
)
449 // Find the first matching format code.
450 nFound
= pFormatter
->TestNewString(rFmtString
, eCurLanguage
);
452 if (nFound
== NUMBERFORMAT_ENTRY_NOT_FOUND
)
454 bool bTestBanking
= false;
455 sal_uInt16 nPos
= FindCurrencyTableEntry(rFmtString
, bTestBanking
);
457 if (IsInTable(nPos
, bTestBanking
, rFmtString
))
459 nFound
= NUMBERFORMAT_ENTRY_NEW_CURRENCY
;
465 bRes
= !IsRemoved_Impl(nFound
);
474 void SvxNumberFormatShell::GetInitSettings(sal_uInt16
& nCatLbPos
, LanguageType
& rLangType
,
475 sal_uInt16
& nFmtLbSelPos
,
476 std::vector
<OUString
>& rFmtEntries
,
477 OUString
& rPrevString
, const Color
*& rpPrevColor
)
479 // precondition: number formater found
480 DBG_ASSERT(pFormatter
!= nullptr, "Number formatter not found!");
482 short nSelPos
= SELPOS_NONE
;
484 // special treatment for undefined number format:
485 if ((eValType
== SvxNumberValueType::Undefined
) && (nCurFormatKey
== 0))
486 PosToCategory_Impl(CAT_ALL
, nCurCategory
); // category = all
488 nCurCategory
= SvNumFormatType::UNDEFINED
; // category = undefined
490 pCurFmtTable
= &(pFormatter
->GetFirstEntryTable(nCurCategory
, nCurFormatKey
, eCurLanguage
));
492 CategoryToPos_Impl(nCurCategory
, nCatLbPos
);
493 rLangType
= eCurLanguage
;
495 nSelPos
= FillEntryList_Impl(rFmtEntries
);
497 DBG_ASSERT(nSelPos
!= SELPOS_NONE
, "Leere Formatliste!");
499 nFmtLbSelPos
= (nSelPos
!= SELPOS_NONE
) ? static_cast<sal_uInt16
>(nSelPos
) : 0;
500 GetPreviewString_Impl(rPrevString
, rpPrevColor
);
503 short SvxNumberFormatShell::FillEntryList_Impl(std::vector
<OUString
>& rList
)
505 /* Create a current list of format entries. The return value is
506 * the list position of the current format. If the list is empty
507 * or if there is no current format, SELPOS_NONE is delivered.
509 short nSelPos
= SELPOS_NONE
;
511 aCurEntryList
.clear();
513 if (nCurCategory
== SvNumFormatType::ALL
)
515 FillEListWithStd_Impl(rList
, SvNumFormatType::NUMBER
, nSelPos
);
516 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::NUMBER
, nSelPos
);
518 FillEListWithStd_Impl(rList
, SvNumFormatType::PERCENT
, nSelPos
);
519 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::PERCENT
, nSelPos
);
521 FillEListWithStd_Impl(rList
, SvNumFormatType::CURRENCY
, nSelPos
);
522 // No FillEListWithUsD_Impl() here, user defined currency formats
523 // were already added.
525 FillEListWithStd_Impl(rList
, SvNumFormatType::DATE
, nSelPos
);
526 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::DATE
, nSelPos
);
528 FillEListWithStd_Impl(rList
, SvNumFormatType::TIME
, nSelPos
);
529 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::TIME
, nSelPos
);
531 nSelPos
= FillEListWithDateTime_Impl(rList
, nSelPos
, false);
532 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::DATETIME
, nSelPos
);
534 FillEListWithStd_Impl(rList
, SvNumFormatType::SCIENTIFIC
, nSelPos
);
535 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::SCIENTIFIC
, nSelPos
);
537 FillEListWithStd_Impl(rList
, SvNumFormatType::FRACTION
, nSelPos
);
538 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::FRACTION
, nSelPos
);
540 FillEListWithStd_Impl(rList
, SvNumFormatType::LOGICAL
, nSelPos
);
541 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::LOGICAL
, nSelPos
);
543 FillEListWithStd_Impl(rList
, SvNumFormatType::TEXT
, nSelPos
);
544 nSelPos
= FillEListWithUsD_Impl(rList
, SvNumFormatType::TEXT
, nSelPos
);
548 FillEListWithStd_Impl(rList
, nCurCategory
, nSelPos
, true);
549 nSelPos
= FillEListWithUsD_Impl(rList
, nCurCategory
, nSelPos
);
550 if (nCurCategory
== SvNumFormatType::DATE
|| nCurCategory
== SvNumFormatType::TIME
)
551 nSelPos
= FillEListWithDateTime_Impl(rList
, nSelPos
, true);
557 void SvxNumberFormatShell::FillEListWithStd_Impl(std::vector
<OUString
>& rList
,
558 SvNumFormatType eCategory
, short& nSelPos
,
559 bool bSuppressDuplicates
)
561 /* Create a current list of format entries. The return value is
562 * the list position of the current format. If the list is empty
563 * or if there is no current format, SELPOS_NONE is delivered.
566 assert(pCurFmtTable
!= nullptr);
568 aCurrencyFormatList
.clear();
570 NfIndexTableOffset eOffsetStart
;
571 NfIndexTableOffset eOffsetEnd
;
575 case SvNumFormatType::NUMBER
:
576 eOffsetStart
= NF_NUMBER_START
;
577 eOffsetEnd
= NF_NUMBER_END
;
579 case SvNumFormatType::PERCENT
:
580 eOffsetStart
= NF_PERCENT_START
;
581 eOffsetEnd
= NF_PERCENT_END
;
583 case SvNumFormatType::CURRENCY
:
584 // Currency entries are generated and assembled, ignore
585 // bSuppressDuplicates.
586 nSelPos
= FillEListWithCurrency_Impl(rList
, nSelPos
);
588 case SvNumFormatType::DATE
:
589 eOffsetStart
= NF_DATE_START
;
590 eOffsetEnd
= NF_DATE_END
;
592 case SvNumFormatType::TIME
:
593 eOffsetStart
= NF_TIME_START
;
594 eOffsetEnd
= NF_TIME_END
;
596 case SvNumFormatType::SCIENTIFIC
:
597 eOffsetStart
= NF_SCIENTIFIC_START
;
598 eOffsetEnd
= NF_SCIENTIFIC_END
;
600 case SvNumFormatType::FRACTION
:
601 eOffsetStart
= NF_FRACTION_START
;
602 eOffsetEnd
= NF_FRACTION_END
;
603 // Fraction formats are internally generated by the number
604 // formatter and are not supposed to contain duplicates anyway.
605 nSelPos
= FillEListWithFormats_Impl(rList
, nSelPos
, eOffsetStart
, eOffsetEnd
, false);
607 = FillEListWithFormats_Impl(rList
, nSelPos
, NF_FRACTION_3D
, NF_FRACTION_100
, false);
609 case SvNumFormatType::LOGICAL
:
610 eOffsetStart
= NF_BOOLEAN
;
611 eOffsetEnd
= NF_BOOLEAN
;
613 case SvNumFormatType::TEXT
:
614 eOffsetStart
= NF_TEXT
;
615 eOffsetEnd
= NF_TEXT
;
622 = FillEListWithFormats_Impl(rList
, nSelPos
, eOffsetStart
, eOffsetEnd
, bSuppressDuplicates
);
625 short SvxNumberFormatShell::FillEListWithFormats_Impl(std::vector
<OUString
>& rList
, short nSelPos
,
626 NfIndexTableOffset eOffsetStart
,
627 NfIndexTableOffset eOffsetEnd
,
628 bool bSuppressDuplicates
)
630 /* Create a current list of format entries. The return value is
631 * the list position of the current format. If the list is empty
632 * or if there is no current format, SELPOS_NONE is delivered.
634 for (tools::Long nIndex
= eOffsetStart
; nIndex
<= eOffsetEnd
; ++nIndex
)
636 FillEListWithOneFormat_Impl(rList
, nSelPos
, bSuppressDuplicates
,
637 static_cast<NfIndexTableOffset
>(nIndex
), false);
643 short SvxNumberFormatShell::FillEListWithDateTime_Impl(std::vector
<OUString
>& rList
, short nSelPos
,
644 bool bSuppressDuplicates
)
646 // Append a list of date+time formats.
648 // Add first, so a NF_DATETIME_SYSTEM_SHORT_HHMM may be suppressed in
649 // locales that do not use 2-digit years there and this here is the
651 FillEListWithOneFormat_Impl(rList
, nSelPos
, bSuppressDuplicates
, NF_DATETIME_SYS_DDMMYYYY_HHMM
,
654 for (tools::Long nIndex
= NF_DATETIME_START
; nIndex
<= NF_DATETIME_END
; ++nIndex
)
656 FillEListWithOneFormat_Impl(rList
, nSelPos
, bSuppressDuplicates
,
657 static_cast<NfIndexTableOffset
>(nIndex
), true);
660 // Always add the internally generated ISO formats.
661 nSelPos
= FillEListWithFormats_Impl(rList
, nSelPos
, NF_DATETIME_ISO_YYYYMMDD_HHMMSS
,
662 NF_DATETIME_ISO_YYYYMMDDTHHMMSS000
, false);
667 void SvxNumberFormatShell::FillEListWithOneFormat_Impl(std::vector
<OUString
>& rList
, short& nSelPos
,
668 bool bSuppressDuplicates
,
669 NfIndexTableOffset nOffset
,
670 bool bSuppressIsoDateTime
)
672 sal_uInt32 nNFEntry
= pFormatter
->GetFormatIndex(nOffset
, eCurLanguage
);
674 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nNFEntry
);
675 if (pNumEntry
== nullptr)
678 SvNumFormatType nMyCat
= pNumEntry
->GetMaskedType();
680 CategoryToPos_Impl(nMyCat
, nMyType
);
681 OUString aNewFormNInfo
= pNumEntry
->GetFormatstring();
683 if (nNFEntry
== nCurFormatKey
)
685 nSelPos
= (!IsRemoved_Impl(nNFEntry
)) ? aCurEntryList
.size() : SELPOS_NONE
;
688 // Ugly hack to suppress an ISO date+time format that is the default
689 // date+time format of the locale and identical to the internally generated
690 // one always to be added after/below.
692 = bSuppressIsoDateTime
&& bSuppressDuplicates
693 && (aNewFormNInfo
== "YYYY-MM-DD HH:MM:SS" || aNewFormNInfo
== "YYYY-MM-DD\"T\"HH:MM:SS");
696 && (!bSuppressDuplicates
|| IsEssentialFormat_Impl(nMyCat
, nNFEntry
)
697 || std::find(rList
.begin(), rList
.end(), aNewFormNInfo
) == rList
.end()))
699 rList
.push_back(aNewFormNInfo
);
700 aCurEntryList
.push_back(nNFEntry
);
704 bool SvxNumberFormatShell::IsEssentialFormat_Impl(SvNumFormatType eType
, sal_uInt32 nKey
)
706 if (nKey
== nCurFormatKey
)
709 const NfIndexTableOffset nIndex
= pFormatter
->GetIndexTableOffset(nKey
);
712 // These are preferred or edit formats.
713 case NF_DATE_SYS_DDMMYYYY
:
714 case NF_DATE_ISO_YYYYMMDD
:
715 case NF_TIME_HH_MMSS
:
717 case NF_TIME_HH_MMSS00
:
718 case NF_DATETIME_SYS_DDMMYYYY_HHMM
:
719 case NF_DATETIME_SYS_DDMMYYYY_HHMMSS
:
720 case NF_DATETIME_ISO_YYYYMMDD_HHMMSS
:
721 case NF_DATETIME_ISO_YYYYMMDD_HHMMSS000
:
722 case NF_DATETIME_ISO_YYYYMMDDTHHMMSS
:
723 case NF_DATETIME_ISO_YYYYMMDDTHHMMSS000
:
729 return nKey
== pFormatter
->GetStandardFormat(eType
, eCurLanguage
);
732 short SvxNumberFormatShell::FillEListWithCurrency_Impl(std::vector
<OUString
>& rList
, short nSelPos
)
734 /* Create a current list of format entries. The return value is
735 * the list position of the current format. If the list is empty
736 * or if there is no current format, SELPOS_NONE is delivered.
738 DBG_ASSERT(pCurFmtTable
!= nullptr, "unknown NumberFormat");
740 const NfCurrencyEntry
* pTmpCurrencyEntry
;
744 bool bFlag
= pFormatter
->GetNewCurrencySymbolString(nCurFormatKey
, rSymbol
, &pTmpCurrencyEntry
,
747 if ((!bFlag
&& pCurCurrencyEntry
== nullptr)
748 || (bFlag
&& pTmpCurrencyEntry
== nullptr && rSymbol
.isEmpty())
749 || (nCurCategory
== SvNumFormatType::ALL
))
751 if (nCurCategory
== SvNumFormatType::ALL
)
752 FillEListWithUserCurrencys(rList
, nSelPos
);
753 nSelPos
= FillEListWithSysCurrencys(rList
, nSelPos
);
757 nSelPos
= FillEListWithUserCurrencys(rList
, nSelPos
);
763 short SvxNumberFormatShell::FillEListWithSysCurrencys(std::vector
<OUString
>& rList
, short nSelPos
)
765 /* Create a current list of format entries. The return value is
766 * the list position of the current format. If the list is empty
767 * or if there is no current format, SELPOS_NONE is delivered.
771 DBG_ASSERT(pCurFmtTable
!= nullptr, "unknown NumberFormat");
774 OUString aNewFormNInfo
;
776 nCurCurrencyEntryPos
= 0;
778 for (tools::Long nIndex
= NF_CURRENCY_START
; nIndex
<= NF_CURRENCY_END
; nIndex
++)
781 = pFormatter
->GetFormatIndex(static_cast<NfIndexTableOffset
>(nIndex
), eCurLanguage
);
783 if (nCurCategory
== SvNumFormatType::ALL
&& nNFEntry
!= nCurFormatKey
)
784 // Deprecated old currency entries, for ALL add only if used as
785 // current format key.
788 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nNFEntry
);
790 if (pNumEntry
== nullptr)
793 SvNumFormatType nMyCat
= pNumEntry
->GetMaskedType();
794 CategoryToPos_Impl(nMyCat
, nMyType
);
795 aNewFormNInfo
= pNumEntry
->GetFormatstring();
797 if (nNFEntry
== nCurFormatKey
)
799 nSelPos
= (!IsRemoved_Impl(nNFEntry
)) ? aCurEntryList
.size() : SELPOS_NONE
;
802 rList
.push_back(aNewFormNInfo
);
803 aCurEntryList
.push_back(nNFEntry
);
806 if (nCurCategory
!= SvNumFormatType::ALL
)
808 for (const auto& rEntry
: *pCurFmtTable
)
810 sal_uInt32 nKey
= rEntry
.first
;
811 const SvNumberformat
* pNumEntry
= rEntry
.second
;
813 if (!IsRemoved_Impl(nKey
))
815 bool bUserNewCurrency
= false;
816 if (pNumEntry
->HasNewCurrency())
818 const NfCurrencyEntry
* pTmpCurrencyEntry
;
822 pFormatter
->GetNewCurrencySymbolString(nKey
, rSymbol
, &pTmpCurrencyEntry
,
825 bUserNewCurrency
= (pTmpCurrencyEntry
!= nullptr);
828 if (!bUserNewCurrency
&& (pNumEntry
->GetType() & SvNumFormatType::DEFINED
))
830 SvNumFormatType nMyCat
= pNumEntry
->GetMaskedType();
831 CategoryToPos_Impl(nMyCat
, nMyType
);
832 aNewFormNInfo
= pNumEntry
->GetFormatstring();
834 if (nKey
== nCurFormatKey
)
835 nSelPos
= aCurEntryList
.size();
836 rList
.push_back(aNewFormNInfo
);
837 aCurEntryList
.push_back(nKey
);
845 short SvxNumberFormatShell::FillEListWithUserCurrencys(std::vector
<OUString
>& rList
, short nSelPos
)
847 /* Create a current list of format entries. The return value is
848 * the list position of the current format. If the list is empty
849 * or if there is no current format, SELPOS_NONE is delivered.
853 DBG_ASSERT(pCurFmtTable
!= nullptr, "unknown NumberFormat");
855 OUString aNewFormNInfo
;
857 const NfCurrencyEntry
* pTmpCurrencyEntry
;
858 bool bTmpBanking
, bAdaptSelPos
;
860 OUString rBankSymbol
;
862 std::vector
<OUString
> aList
;
863 std::vector
<sal_uInt32
> aKeyList
;
865 pFormatter
->GetNewCurrencySymbolString(nCurFormatKey
, rSymbol
, &pTmpCurrencyEntry
,
868 OUString rShortSymbol
;
870 if (pCurCurrencyEntry
== nullptr)
872 // #110398# If no currency format was previously selected (we're not
873 // about to add another currency), try to select the initial currency
874 // format (nCurFormatKey) that was set in FormatChanged() after
875 // matching the format string entered in the dialog.
877 pCurCurrencyEntry
= const_cast<NfCurrencyEntry
*>(pTmpCurrencyEntry
);
878 bBankingSymbol
= bTmpBanking
;
879 nCurCurrencyEntryPos
= FindCurrencyFormat(pTmpCurrencyEntry
, bTmpBanking
);
883 if (pTmpCurrencyEntry
== pCurCurrencyEntry
)
887 bAdaptSelPos
= false;
888 pTmpCurrencyEntry
= pCurCurrencyEntry
;
890 bTmpBanking
= bBankingSymbol
;
893 if (pTmpCurrencyEntry
!= nullptr)
895 rSymbol
= pTmpCurrencyEntry
->BuildSymbolString(false);
896 rBankSymbol
= pTmpCurrencyEntry
->BuildSymbolString(true);
897 rShortSymbol
= pTmpCurrencyEntry
->BuildSymbolString(bTmpBanking
, true);
900 for (const auto& rEntry
: *pCurFmtTable
)
902 sal_uInt32 nKey
= rEntry
.first
;
903 const SvNumberformat
* pNumEntry
= rEntry
.second
;
905 if (!IsRemoved_Impl(nKey
))
907 if (pNumEntry
->GetType() & SvNumFormatType::DEFINED
|| pNumEntry
->IsAdditionalBuiltin())
909 SvNumFormatType nMyCat
= pNumEntry
->GetMaskedType();
910 CategoryToPos_Impl(nMyCat
, nMyType
);
911 aNewFormNInfo
= pNumEntry
->GetFormatstring();
913 bool bInsFlag
= false;
914 if (pNumEntry
->HasNewCurrency())
916 bInsFlag
= true; // merge locale formats into currency selection
918 else if ((!bTmpBanking
&& aNewFormNInfo
.indexOf(rSymbol
) >= 0)
919 || (bTmpBanking
&& aNewFormNInfo
.indexOf(rBankSymbol
) >= 0))
923 else if (aNewFormNInfo
.indexOf(rShortSymbol
) >= 0)
926 const NfCurrencyEntry
* pTstCurrencyEntry
;
929 pFormatter
->GetNewCurrencySymbolString(nKey
, rTstSymbol
, &pTstCurrencyEntry
,
932 if (pTmpCurrencyEntry
== pTstCurrencyEntry
&& bTstBanking
== bTmpBanking
)
940 aList
.push_back(aNewFormNInfo
);
941 aKeyList
.push_back(nKey
);
947 NfWSStringsDtor aWSStringsDtor
;
949 if (pTmpCurrencyEntry
&& nCurCategory
!= SvNumFormatType::ALL
)
952 = pFormatter
->GetCurrencyFormatStrings(aWSStringsDtor
, *pTmpCurrencyEntry
, bTmpBanking
);
954 pFormatter
->GetCurrencyFormatStrings(aWSStringsDtor
, *pTmpCurrencyEntry
, true);
958 if (!bTmpBanking
&& nCurCategory
!= SvNumFormatType::ALL
)
960 // append formats for all currencies defined in the current I18N locale
961 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
962 sal_uInt16 nCurrCount
= rCurrencyTable
.size();
963 LanguageType eLang
= MsLangId::getRealLanguage(eCurLanguage
);
964 for (sal_uInt16 i
= 0; i
< nCurrCount
; ++i
)
966 const NfCurrencyEntry
* pCurr
= &rCurrencyTable
[i
];
967 if (pCurr
->GetLanguage() == eLang
&& pTmpCurrencyEntry
!= pCurr
)
969 pFormatter
->GetCurrencyFormatStrings(aWSStringsDtor
, *pCurr
, false);
970 pFormatter
->GetCurrencyFormatStrings(aWSStringsDtor
, *pCurr
, true);
975 size_t nOldListCount
= rList
.size();
976 for (size_t i
= 0, nPos
= nOldListCount
; i
< aWSStringsDtor
.size(); ++i
)
979 OUString
aInsStr(aWSStringsDtor
[i
]);
981 for (j
= 0; j
< aList
.size(); ++j
)
983 if (aList
[j
] == aInsStr
)
991 rList
.push_back(aInsStr
);
992 aCurEntryList
.insert(aCurEntryList
.begin() + (nPos
++), NUMBERFORMAT_ENTRY_NOT_FOUND
);
996 rList
.push_back(aList
[j
]);
997 aList
.erase(aList
.begin() + j
);
998 aCurEntryList
.insert(aCurEntryList
.begin() + (nPos
++), aKeyList
[j
]);
999 aKeyList
.erase(aKeyList
.begin() + j
);
1003 for (size_t i
= 0; i
< aKeyList
.size(); ++i
)
1005 if (aKeyList
[i
] != NUMBERFORMAT_ENTRY_NOT_FOUND
)
1007 rList
.push_back(aList
[i
]);
1008 aCurEntryList
.push_back(aKeyList
[i
]);
1012 for (size_t i
= nOldListCount
; i
< rList
.size(); ++i
)
1014 aCurrencyFormatList
.push_back(rList
[i
]);
1016 if (nSelPos
== SELPOS_NONE
&& bAdaptSelPos
&& aCurEntryList
[i
] == nCurFormatKey
)
1020 if (nSelPos
== SELPOS_NONE
&& nCurCategory
!= SvNumFormatType::ALL
)
1026 short SvxNumberFormatShell::FillEListWithUsD_Impl(std::vector
<OUString
>& rList
,
1027 SvNumFormatType eCategory
, short nSelPos
)
1029 /* Create a current list of format entries. The return value is
1030 * the list position of the current format. If the list is empty
1031 * or if there is no current format, SELPOS_NONE is delivered.
1034 assert(pCurFmtTable
!= nullptr);
1036 OUString aNewFormNInfo
;
1038 const bool bCatDefined
= (eCategory
== SvNumFormatType::DEFINED
);
1039 const bool bCategoryMatch
= (eCategory
!= SvNumFormatType::ALL
&& !bCatDefined
);
1040 const bool bNatNumCurrency
= (eCategory
== SvNumFormatType::CURRENCY
);
1042 for (const auto& rEntry
: *pCurFmtTable
)
1044 const SvNumberformat
* pNumEntry
= rEntry
.second
;
1046 if (bCategoryMatch
&& (pNumEntry
->GetMaskedType() & eCategory
) != eCategory
)
1047 continue; // for; type does not match category if not ALL
1049 const bool bUserDefined
= bool(pNumEntry
->GetType() & SvNumFormatType::DEFINED
);
1050 if (!bUserDefined
&& bCatDefined
)
1051 continue; // for; not user defined in DEFINED category
1053 if (!(bUserDefined
|| (!bCatDefined
&& pNumEntry
->IsAdditionalBuiltin())))
1054 continue; // for; does not match criteria at all
1056 const sal_uInt32 nKey
= rEntry
.first
;
1057 if (!IsRemoved_Impl(nKey
))
1059 aNewFormNInfo
= pNumEntry
->GetFormatstring();
1061 if (bNatNumCurrency
&& (aNewFormNInfo
.indexOf("NatNum12") < 0 || bUserDefined
))
1062 continue; // for; extra CURRENCY must be not user-defined NatNum12 type
1065 if (pNumEntry
->HasNewCurrency())
1068 sal_uInt16 nPos
= FindCurrencyTableEntry(aNewFormNInfo
, bTestBanking
);
1069 bAdd
= !IsInTable(nPos
, bTestBanking
, aNewFormNInfo
);
1073 if (nKey
== nCurFormatKey
)
1074 nSelPos
= aCurEntryList
.size();
1075 rList
.push_back(aNewFormNInfo
);
1076 aCurEntryList
.push_back(nKey
);
1083 void SvxNumberFormatShell::GetPreviewString_Impl(OUString
& rString
, const Color
*& rpColor
)
1087 // #50441# if a string was set in addition to the value, use it for text formats
1089 = (eValType
== SvxNumberValueType::String
1090 || (!aValStr
.isEmpty() && (pFormatter
->GetType(nCurFormatKey
) & SvNumFormatType::TEXT
)));
1094 pFormatter
->GetOutputString(aValStr
, nCurFormatKey
, rString
, &rpColor
);
1098 pFormatter
->GetOutputString(nValNum
, nCurFormatKey
, rString
, &rpColor
, bUseStarFormat
);
1102 ::std::vector
<sal_uInt32
>::iterator
SvxNumberFormatShell::GetRemoved_Impl(size_t nKey
)
1104 return ::std::find(aDelList
.begin(), aDelList
.end(), nKey
);
1107 bool SvxNumberFormatShell::IsRemoved_Impl(size_t nKey
)
1109 return GetRemoved_Impl(nKey
) != aDelList
.end();
1112 ::std::vector
<sal_uInt32
>::iterator
SvxNumberFormatShell::GetAdded_Impl(size_t nKey
)
1114 return ::std::find(aAddList
.begin(), aAddList
.end(), nKey
);
1117 // Conversion routines:
1118 void SvxNumberFormatShell::PosToCategory_Impl(sal_uInt16 nPos
, SvNumFormatType
& rCategory
)
1120 // map category css::form positions (->resource)
1123 case CAT_USERDEFINED
:
1124 rCategory
= SvNumFormatType::DEFINED
;
1127 rCategory
= SvNumFormatType::NUMBER
;
1130 rCategory
= SvNumFormatType::PERCENT
;
1133 rCategory
= SvNumFormatType::CURRENCY
;
1136 rCategory
= SvNumFormatType::DATE
;
1139 rCategory
= SvNumFormatType::TIME
;
1141 case CAT_SCIENTIFIC
:
1142 rCategory
= SvNumFormatType::SCIENTIFIC
;
1145 rCategory
= SvNumFormatType::FRACTION
;
1148 rCategory
= SvNumFormatType::LOGICAL
;
1151 rCategory
= SvNumFormatType::TEXT
;
1155 rCategory
= SvNumFormatType::ALL
;
1160 void SvxNumberFormatShell::CategoryToPos_Impl(SvNumFormatType nCategory
, sal_uInt16
& rPos
)
1162 // map category to css::form positions (->resource)
1165 case SvNumFormatType::DEFINED
:
1166 rPos
= CAT_USERDEFINED
;
1168 case SvNumFormatType::NUMBER
:
1171 case SvNumFormatType::PERCENT
:
1174 case SvNumFormatType::CURRENCY
:
1175 rPos
= CAT_CURRENCY
;
1177 case SvNumFormatType::DATETIME
:
1178 case SvNumFormatType::DATE
:
1181 case SvNumFormatType::TIME
:
1184 case SvNumFormatType::SCIENTIFIC
:
1185 rPos
= CAT_SCIENTIFIC
;
1187 case SvNumFormatType::FRACTION
:
1188 rPos
= CAT_FRACTION
;
1190 case SvNumFormatType::LOGICAL
:
1193 case SvNumFormatType::TEXT
:
1196 case SvNumFormatType::ALL
:
1203 * Function: Formats the number nValue dependent on rFormatStr
1204 * and stores the result in rPreviewStr.
1205 * Input: FormatString, color, number to format
1206 * Output: Output string rPreviewStr
1208 void SvxNumberFormatShell::MakePrevStringFromVal(const OUString
& rFormatStr
, OUString
& rPreviewStr
,
1209 const Color
*& rpFontColor
, double nValue
)
1211 rpFontColor
= nullptr;
1212 pFormatter
->GetPreviewString(rFormatStr
, nValue
, rPreviewStr
, &rpFontColor
, eCurLanguage
);
1216 * Function: Returns the comment for a given entry.
1217 * Input: Number of the entry
1218 * Output: Comment string
1220 void SvxNumberFormatShell::SetComment4Entry(short nEntry
, const OUString
& aEntStr
)
1222 SvNumberformat
* pNumEntry
;
1225 sal_uInt32 nMyNfEntry
= aCurEntryList
[nEntry
];
1226 pNumEntry
= const_cast<SvNumberformat
*>(pFormatter
->GetEntry(nMyNfEntry
));
1227 if (pNumEntry
!= nullptr)
1228 pNumEntry
->SetComment(aEntStr
);
1232 * Function: Returns the comment for a given entry.
1233 * Input: Number of the entry
1234 * Output: Comment string
1236 OUString
SvxNumberFormatShell::GetComment4Entry(short nEntry
)
1241 if (o3tl::make_unsigned(nEntry
) < aCurEntryList
.size())
1243 sal_uInt32 nMyNfEntry
= aCurEntryList
[nEntry
];
1244 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1245 if (pNumEntry
!= nullptr)
1246 return pNumEntry
->GetComment();
1253 * Function: Returns the category number for a given entry.
1254 * Input: Number of the entry
1255 * Output: Category number
1257 short SvxNumberFormatShell::GetCategory4Entry(short nEntry
) const
1261 if (o3tl::make_unsigned(nEntry
) < aCurEntryList
.size())
1263 sal_uInt32 nMyNfEntry
= aCurEntryList
[nEntry
];
1265 if (nMyNfEntry
!= NUMBERFORMAT_ENTRY_NOT_FOUND
)
1267 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1268 if (pNumEntry
!= nullptr)
1270 SvNumFormatType nMyCat
= pNumEntry
->GetMaskedType();
1272 CategoryToPos_Impl(nMyCat
, nMyType
);
1274 return static_cast<short>(nMyType
);
1278 else if (!aCurrencyFormatList
.empty())
1280 return CAT_CURRENCY
;
1287 * Function: Returns the information about whether an entry is user-specific.
1288 * Input: Number of the entry
1289 * Output: User-specific?
1291 bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry
)
1295 if (o3tl::make_unsigned(nEntry
) < aCurEntryList
.size())
1297 sal_uInt32 nMyNfEntry
= aCurEntryList
[nEntry
];
1298 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1300 if (pNumEntry
!= nullptr)
1302 if (pNumEntry
->GetType() & SvNumFormatType::DEFINED
)
1312 * Function: Returns the format string for a given entry.
1313 * Input: Number of the entry
1314 * Output: Format string
1316 OUString
SvxNumberFormatShell::GetFormat4Entry(short nEntry
)
1321 if (!aCurrencyFormatList
.empty()
1322 && (!pFormatter
->GetEntry(aCurEntryList
[nEntry
])
1323 || pFormatter
->GetEntry(aCurEntryList
[nEntry
])->GetFormatstring().indexOf("NatNum12")
1326 if (aCurrencyFormatList
.size() > o3tl::make_unsigned(nEntry
))
1327 return aCurrencyFormatList
[nEntry
];
1331 sal_uInt32 nMyNfEntry
= aCurEntryList
[nEntry
];
1332 const SvNumberformat
* pNumEntry
= pFormatter
->GetEntry(nMyNfEntry
);
1334 if (pNumEntry
!= nullptr)
1335 return pNumEntry
->GetFormatstring();
1341 * Function: Returns the list number for a given format index.
1342 * Input: Number of the entry
1343 * Output: Category number
1345 short SvxNumberFormatShell::GetListPos4Entry(sal_uInt32 nIdx
, std::u16string_view rFmtString
)
1347 short nSelP
= SELPOS_NONE
;
1348 if (nIdx
!= NUMBERFORMAT_ENTRY_NEW_CURRENCY
)
1350 // Check list size against return type limit.
1351 if (aCurEntryList
.size() <= o3tl::make_unsigned(::std::numeric_limits
<short>::max()))
1353 for (size_t i
= 0; i
< aCurEntryList
.size(); ++i
)
1355 if (aCurEntryList
[i
] == nIdx
)
1364 OSL_FAIL("svx::SvxNumberFormatShell::GetListPos4Entry(), list got too large!");
1369 // A second list holds the generated currency formats.
1370 for (size_t i
= 0; i
< aCurrencyFormatList
.size(); ++i
)
1372 if (rFmtString
== aCurrencyFormatList
[i
])
1374 nSelP
= static_cast<short>(i
);
1382 OUString
SvxNumberFormatShell::GetStandardName() const
1384 return pFormatter
->GetStandardName(eCurLanguage
);
1387 void SvxNumberFormatShell::GetCurrencySymbols(std::vector
<OUString
>& rList
, sal_uInt16
* pPos
)
1389 const NfCurrencyEntry
* pTmpCurrencyEntry
= SvNumberFormatter::MatchSystemCurrency();
1391 bool bFlag
= (pTmpCurrencyEntry
== nullptr);
1393 SvxCurrencyToolBoxControl::GetCurrencySymbols(rList
, bFlag
, aCurCurrencyList
);
1395 if (pPos
== nullptr)
1398 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1399 sal_uInt16 nTableCount
= rCurrencyTable
.size();
1402 size_t nCount
= aCurCurrencyList
.size();
1407 nCurCurrencyEntryPos
= 1;
1411 for (size_t i
= 1; i
< nCount
; i
++)
1413 const sal_uInt16 j
= aCurCurrencyList
[i
];
1414 if (j
!= sal_uInt16(-1) && j
< nTableCount
&& pTmpCurrencyEntry
== &rCurrencyTable
[j
])
1416 *pPos
= static_cast<sal_uInt16
>(i
);
1417 nCurCurrencyEntryPos
= static_cast<sal_uInt16
>(i
);
1424 void SvxNumberFormatShell::SetCurrencySymbol(sal_uInt32 nPos
)
1426 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1427 sal_uInt16 nCount
= rCurrencyTable
.size();
1429 bBankingSymbol
= (nPos
>= nCount
);
1431 if (nPos
>= aCurCurrencyList
.size())
1434 sal_uInt16 nCurrencyPos
= aCurCurrencyList
[nPos
];
1435 if (nCurrencyPos
!= sal_uInt16(-1))
1437 pCurCurrencyEntry
= const_cast<NfCurrencyEntry
*>(&rCurrencyTable
[nCurrencyPos
]);
1438 nCurCurrencyEntryPos
= nPos
;
1442 pCurCurrencyEntry
= nullptr;
1443 nCurCurrencyEntryPos
= 0;
1444 nCurFormatKey
= pFormatter
->GetFormatIndex(NF_CURRENCY_1000DEC2_RED
, eCurLanguage
);
1448 void SvxNumberFormatShell::SetCurCurrencyEntry(NfCurrencyEntry
* pCEntry
)
1450 pCurCurrencyEntry
= pCEntry
;
1453 bool SvxNumberFormatShell::IsTmpCurrencyFormat(const OUString
& rFmtString
)
1456 FindEntry(rFmtString
, &nFound
);
1457 return nFound
== NUMBERFORMAT_ENTRY_NEW_CURRENCY
;
1460 sal_uInt16
SvxNumberFormatShell::FindCurrencyFormat(const OUString
& rFmtString
)
1462 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1463 sal_uInt16 nCount
= rCurrencyTable
.size();
1465 bool bTestBanking
= false;
1467 sal_uInt16 nPos
= FindCurrencyTableEntry(rFmtString
, bTestBanking
);
1469 if (nPos
!= sal_uInt16(-1))
1471 sal_uInt16 nStart
= 0;
1472 if (bTestBanking
&& aCurCurrencyList
.size() > nPos
)
1476 for (size_t j
= nStart
; j
< aCurCurrencyList
.size(); j
++)
1478 if (aCurCurrencyList
[j
] == nPos
)
1482 return sal_uInt16(-1);
1485 sal_uInt16
SvxNumberFormatShell::FindCurrencyTableEntry(const OUString
& rFmtString
,
1488 sal_uInt16 nPos
= sal_uInt16(-1);
1490 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1491 sal_uInt16 nCount
= rCurrencyTable
.size();
1493 const SvNumberformat
* pFormat
;
1494 OUString aSymbol
, aExtension
;
1495 sal_uInt32 nFound
= pFormatter
->TestNewString(rFmtString
, eCurLanguage
);
1496 if (nFound
!= NUMBERFORMAT_ENTRY_NOT_FOUND
1497 && ((pFormat
= pFormatter
->GetEntry(nFound
)) != nullptr)
1498 && pFormat
->GetNewCurrencySymbol(aSymbol
, aExtension
))
1500 // eventually match with format locale
1501 const NfCurrencyEntry
* pTmpCurrencyEntry
= SvNumberFormatter::GetCurrencyEntry(
1502 bTestBanking
, aSymbol
, aExtension
, pFormat
->GetLanguage());
1503 if (pTmpCurrencyEntry
)
1505 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
1507 if (pTmpCurrencyEntry
== &rCurrencyTable
[i
])
1517 // search symbol string only
1518 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
1520 const NfCurrencyEntry
* pTmpCurrencyEntry
= &rCurrencyTable
[i
];
1521 OUString _aSymbol
= pTmpCurrencyEntry
->BuildSymbolString(false);
1522 OUString aBankSymbol
= pTmpCurrencyEntry
->BuildSymbolString(true);
1524 if (rFmtString
.indexOf(_aSymbol
) != -1)
1526 bTestBanking
= false;
1530 else if (rFmtString
.indexOf(aBankSymbol
) != -1)
1532 bTestBanking
= true;
1542 sal_uInt16
SvxNumberFormatShell::FindCurrencyFormat(const NfCurrencyEntry
* pTmpCurrencyEntry
,
1545 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1546 sal_uInt16 nCount
= rCurrencyTable
.size();
1548 sal_uInt16 nPos
= 0;
1549 for (sal_uInt16 i
= 0; i
< nCount
; i
++)
1551 if (pTmpCurrencyEntry
== &rCurrencyTable
[i
])
1558 sal_uInt16 nStart
= 0;
1559 if (bTmpBanking
&& aCurCurrencyList
.size() > nPos
)
1563 for (size_t j
= nStart
; j
< aCurCurrencyList
.size(); j
++)
1565 if (aCurCurrencyList
[j
] == nPos
)
1568 return sal_uInt16(-1);
1571 bool SvxNumberFormatShell::IsInTable(sal_uInt16
const nPos
, bool const bTmpBanking
,
1572 std::u16string_view rFmtString
) const
1576 if (nPos
!= sal_uInt16(-1))
1578 const NfCurrencyTable
& rCurrencyTable
= SvNumberFormatter::GetTheCurrencyTable();
1580 if (nPos
< rCurrencyTable
.size())
1582 NfWSStringsDtor aWSStringsDtor
;
1583 pFormatter
->GetCurrencyFormatStrings(aWSStringsDtor
, rCurrencyTable
[nPos
], bTmpBanking
);
1585 for (const OUString
& s
: aWSStringsDtor
)
1587 if (s
== rFmtString
)
1599 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */