include/svl/zformat.hxx | 3 + svl/source/numbers/zforlist.cxx | 85 +++++++++++++++++++++++++--------------- svl/source/numbers/zformat.cxx | 20 +++++++++ 3 files changed, 77 insertions(+), 31 deletions(-)
New commits: commit 8ba7657a9653f8ae5d1b865356d11138df7b2093 Author: Laurent Balland <laurent.ball...@mailo.fr> AuthorDate: Mon Jan 2 18:39:35 2023 +0100 Commit: Eike Rathke <er...@redhat.com> CommitDate: Mon Jan 30 15:19:19 2023 +0000 tdf#152722 Number Format: keep NatNum modifiers When modifying number format with UI (decimal places, negative in red...) NatNum modifiers must be preserved Implement an helper to get NatNum string As NatNum12 already inserts currency unit, do not treat it Change-Id: I38be1da08a44d75ef663eaf50fccb3820ff9ed5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144963 Tested-by: Jenkins Reviewed-by: Eike Rathke <er...@redhat.com> diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx index 43f6ad9775f4..ea08234e93a2 100644 --- a/include/svl/zformat.hxx +++ b/include/svl/zformat.hxx @@ -459,6 +459,9 @@ public: void GetNatNumXml( css::i18n::NativeNumberXmlAttributes2& rAttr, sal_uInt16 nNumFor ) const; + /** Return empty string if no NatNum modifier or unvalid nNumFor + otherwhise return "[NatNum1]" or "[NatNum12 ...]" */ + OUString GetNatNumModifierString( sal_uInt16 nNumFor = 0 ) const; /** Switches to the first non-"gregorian" calendar, but only if the current calendar is "gregorian"; original calendar name and date/time returned, diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index cee75fc9265e..ca8b6524b9e2 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -3231,6 +3231,15 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, sString.append(GetNumDecimalSep()); padToLength(sString, sString.getLength() + nPrecision, '0'); } + + // Native Number + const OUString sPosNatNumModifier = pFormat ? pFormat->GetNatNumModifierString( 0 ) : ""; + const OUString sNegNatNumModifier = pFormat ? + // if a negative format already exists, use its NatNum modifier + // else use NatNum modifier of positive format + ( pFormat->GetNumForString( 1, 0 ) ? pFormat->GetNatNumModifierString( 1 ) : sPosNatNumModifier ) + : ""; + if (eType == SvNumFormatType::PERCENT) { sString.append( pFormat->GetPercentString() ); @@ -3254,50 +3263,62 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, OUString aCurr; const NfCurrencyEntry* pEntry; bool bBank; - if ( GetNewCurrencySymbolString( nIndex, aCurr, &pEntry, &bBank ) ) + bool isPosNatNum12 = sPosNatNumModifier.startsWith( "[NatNum12" ); + bool isNegNatNum12 = sNegNatNumModifier.startsWith( "[NatNum12" ); + if ( !isPosNatNum12 || !isNegNatNum12 ) { - if ( pEntry ) + if ( GetNewCurrencySymbolString( nIndex, aCurr, &pEntry, &bBank ) ) { - sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), - pEntry->GetPositiveFormat(), bBank ); - sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), - pEntry->GetNegativeFormat(), bBank ); - pEntry->CompletePositiveFormatString( sString, bBank, nPosiForm ); - pEntry->CompleteNegativeFormatString( sNegStr, bBank, nNegaForm ); + if ( pEntry ) + { + sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( + xLocaleData->getCurrPositiveFormat(), + pEntry->GetPositiveFormat(), bBank ); + sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( + xLocaleData->getCurrNegativeFormat(), + pEntry->GetNegativeFormat(), bBank ); + if ( !isPosNatNum12 ) + pEntry->CompletePositiveFormatString( sString, bBank, nPosiForm ); + if ( !isNegNatNum12 ) + pEntry->CompleteNegativeFormatString( sNegStr, bBank, nNegaForm ); + } + else + { // assume currency abbreviation (AKA banking symbol), not symbol + sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( + xLocaleData->getCurrPositiveFormat(), + xLocaleData->getCurrPositiveFormat(), true ); + sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( + xLocaleData->getCurrNegativeFormat(), + xLocaleData->getCurrNegativeFormat(), true ); + if ( !isPosNatNum12 ) + NfCurrencyEntry::CompletePositiveFormatString( sString, aCurr, nPosiForm ); + if ( !isNegNatNum12 ) + NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, aCurr, nNegaForm ); + } } else - { // assume currency abbreviation (AKA banking symbol), not symbol - sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), - xLocaleData->getCurrPositiveFormat(), true ); - sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), - xLocaleData->getCurrNegativeFormat(), true ); - NfCurrencyEntry::CompletePositiveFormatString( sString, aCurr, nPosiForm ); - NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, aCurr, nNegaForm ); + { // "automatic" old style + OUString aSymbol, aAbbrev; + GetCompatibilityCurrency( aSymbol, aAbbrev ); + if ( !isPosNatNum12 ) + NfCurrencyEntry::CompletePositiveFormatString( sString, + aSymbol, xLocaleData->getCurrPositiveFormat() ); + if ( !isNegNatNum12 ) + NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, + aSymbol, xLocaleData->getCurrNegativeFormat() ); } } - else - { // "automatic" old style - OUString aSymbol, aAbbrev; - GetCompatibilityCurrency( aSymbol, aAbbrev ); - NfCurrencyEntry::CompletePositiveFormatString( sString, - aSymbol, xLocaleData->getCurrPositiveFormat() ); - NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, - aSymbol, xLocaleData->getCurrNegativeFormat() ); - } + sString.append( ';' ); if (IsRed) { - sString.append(';'); sString.append('['); sString.append(pFormatScanner->GetRedString()); sString.append(']'); } - else + sString.append( sNegNatNumModifier ); + if ( isNegNatNum12 ) { - sString.append(';'); + sString.append( '-' ); } sString.append(sNegStr); } @@ -3343,6 +3364,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, sTmpStr.append(pFormatScanner->GetRedString()); sTmpStr.append(']'); } + sTmpStr.append( sNegNatNumModifier ); if (insertBrackets) { @@ -3358,6 +3380,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, sString = sTmpStr; } } + sString.insert( 0, sPosNatNumModifier ); return sString.makeStringAndClear(); } diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index b675ed7cca99..eb790ee425b0 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -5765,6 +5765,26 @@ void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes2& rAttr, } } +OUString SvNumberformat::GetNatNumModifierString( sal_uInt16 nNumFor ) const +{ + if ( nNumFor > 3 ) + return ""; + const SvNumberNatNum& rNum = NumFor[nNumFor].GetNatNum(); + if ( !rNum.IsSet() ) + return ""; + OUStringBuffer sNatNumModifier = "[NatNum"; + const sal_Int32 nNum = rNum.GetNatNum(); + sNatNumModifier.append( nNum ); + if ( NatNumTakesParameters( nNum ) ) + { + sNatNumModifier.append( " " ); + sNatNumModifier.append( rNum.GetParams() ); + } + sNatNumModifier.append( "]" ); + + return sNatNumModifier.makeStringAndClear(); +} + // static bool SvNumberformat::HasStringNegativeSign( const OUString& rStr ) {