diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2015-01-31 16:47:28 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-02-03 09:46:31 +0000 |
commit | 343a23058e080c28088a97bf22e444160aa2030e (patch) | |
tree | dea698997a0f2a501c9ac978d9510406080899ec /sc | |
parent | 07cf8750cd094269513c5cec7bee518bbc0e5d81 (diff) |
tdf#88960 Scientific format: add/remove digits with buttons
Use buttons "Add Decimal Place" or "Delete Decimal Place" to change the
number of significant digits with scientific format (also works for
"General" format)
Improve format management for "red for negative"
to be compatible with tdf#88999
Change-Id: Id681afc4fc73674c9823172c6cd71925e63b867f
Reviewed-on: https://gerrit.libreoffice.org/14264
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index ba1d4322dd60..d213846bb96a 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2504,15 +2504,15 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) short nOldType = pOldEntry->GetType(); if ( 0 == ( nOldType & ( - NUMBERFORMAT_NUMBER | NUMBERFORMAT_CURRENCY | NUMBERFORMAT_PERCENT ) ) ) + NUMBERFORMAT_NUMBER | NUMBERFORMAT_CURRENCY | NUMBERFORMAT_PERCENT | NUMBERFORMAT_SCIENTIFIC ) ) ) { // date, time, fraction, logical, text can not be changed - //! in case of scientific the Numberformatter also can't bError = true; } //! SvNumberformat has a Member bStandard, but doesn't disclose it bool bWasStandard = ( nOldFormat == pFormatter->GetStandardIndex( eLanguage ) ); + OUString sExponentialStandardFormat = ""; if (bWasStandard) { // with "Standard" the decimal places depend on cell content @@ -2526,16 +2526,22 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) nPrecision = 0; // 'E' for exponential is fixed in Numberformatter - if ( aOut.indexOf((sal_Unicode)'E') >= 0 ) - bError = true; // exponential not changed - else + sal_Int32 nIndexE = aOut.indexOf((sal_Unicode)'E'); + if ( nIndexE >= 0 ) { - OUString aDecSep( pFormatter->GetFormatDecimalSep( nOldFormat ) ); - sal_Int32 nPos = aOut.indexOf( aDecSep ); - if ( nPos >= 0 ) - nPrecision = aOut.getLength() - nPos - aDecSep.getLength(); - // else keep 0 + sExponentialStandardFormat = aOut.copy( nIndexE ).replace( '-', '+' ); + for ( sal_Int32 i=1 ; i<sExponentialStandardFormat.getLength() ; i++ ) + { + if ( sExponentialStandardFormat[i] >= '1' && sExponentialStandardFormat[i] <= '9' ) + sExponentialStandardFormat = sExponentialStandardFormat.replaceAt( i, 1, OUString( "0" ) ); + } + aOut = aOut.copy( 0, nIndexE ); // remove exponential part } + OUString aDecSep( pFormatter->GetFormatDecimalSep( nOldFormat ) ); + sal_Int32 nPos = aOut.indexOf( aDecSep ); + if ( nPos >= 0 ) + nPrecision = aOut.getLength() - nPos - aDecSep.getLength(); + // else keep 0 } if (!bError) @@ -2560,7 +2566,8 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) { OUString aNewPicture = pFormatter->GenerateFormat(nOldFormat, eLanguage, bThousand, bNegRed, - nPrecision, nLeading); + nPrecision, nLeading) + + sExponentialStandardFormat; nNewFormat = pFormatter->GetEntryKey( aNewPicture, eLanguage ); if ( nNewFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) |