summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorLaurent Balland <laurent.balland@mailo.fr>2023-01-02 18:39:35 +0100
committerAndras Timar <andras.timar@collabora.com>2023-02-03 23:33:12 +0100
commitae928386ece4708236038f0d14f0870c4ef01bf6 (patch)
tree8b7810caa23d3597d4099cd232b8cd170745608e /svl
parentd06435292cc881e3784f6633a7538068cdc3d6f6 (diff)
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 <erack@redhat.com> (cherry picked from commit 8ba7657a9653f8ae5d1b865356d11138df7b2093) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146406
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zforlist.cxx85
-rw-r--r--svl/source/numbers/zformat.cxx20
2 files changed, 74 insertions, 31 deletions
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 )
{