[Libreoffice-commits] core.git: sc/source svl/source

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Tue Feb 3 01:46:52 PST 2015


 sc/source/ui/view/viewfunc.cxx  |   29 ++++++++++++++++++-----------
 svl/source/numbers/zforlist.cxx |   13 +++++++++++++
 2 files changed, 31 insertions(+), 11 deletions(-)

New commits:
commit 343a23058e080c28088a97bf22e444160aa2030e
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Sat Jan 31 16:47:28 2015 +0100

    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 at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index ba1d432..d213846 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 )
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 2a3ed22..8a9b17a 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -2652,6 +2652,19 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex,
     {
         sString.append('%');
     }
+    else if (eType == NUMBERFORMAT_SCIENTIFIC)
+    {
+      OUStringBuffer sOldFormatString = pFormat->GetFormatstring();
+      sal_Int32 nIndexE = sOldFormatString.indexOf('E');
+      if (nIndexE > -1)
+      {
+        sal_Int32 nIndexSep = sOldFormatString.indexOf(';');
+        if (nIndexSep > -1)
+            sString.append( sOldFormatString.copy(nIndexE, nIndexSep - nIndexE) );
+        else
+            sString.append( sOldFormatString.copy(nIndexE) );
+      }
+    }
     else if (eType == NUMBERFORMAT_CURRENCY)
     {
         OUStringBuffer sNegStr(sString);


More information about the Libreoffice-commits mailing list