[ooo-build-commit] patches/dev300

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Oct 16 09:14:04 PDT 2009


 patches/dev300/calc-general-type-auto-decimal-sc.diff      |  104 +---
 patches/dev300/calc-general-type-auto-decimal-svtools.diff |  275 +++++++++++--
 2 files changed, 287 insertions(+), 92 deletions(-)

New commits:
commit 64cac6117b74fecb229425af6807f8a7bda65bc4
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Fri Oct 16 12:08:31 2009 -0400

    More work on automatic decimal adjustments.
    
    1) fixed the bug that caused displayed cell result to become blank.
    2) use scientific notation for larger values.
    3) when the cell text still doesn't fix even after the decimal
       adjustment, switch to scientific notation to save space.
    
    * patches/dev300/calc-general-type-auto-decimal-sc.diff:
    * patches/dev300/calc-general-type-auto-decimal-svtools.diff:

diff --git a/patches/dev300/calc-general-type-auto-decimal-sc.diff b/patches/dev300/calc-general-type-auto-decimal-sc.diff
index 63a5e47..e255cc1 100644
--- a/patches/dev300/calc-general-type-auto-decimal-sc.diff
+++ b/patches/dev300/calc-general-type-auto-decimal-sc.diff
@@ -1,5 +1,5 @@
 diff --git sc/inc/docoptio.hxx sc/inc/docoptio.hxx
-index 81b80b9..006c618 100644
+index 81b80b9..1184554 100644
 --- sc/inc/docoptio.hxx
 +++ sc/inc/docoptio.hxx
 @@ -43,7 +43,7 @@ class SC_DLLPUBLIC ScDocOptions
@@ -11,16 +11,7 @@ index 81b80b9..006c618 100644
      USHORT nDay;					// Nulldatum:
      USHORT nMonth;
      USHORT nYear;
-@@ -63,6 +63,8 @@ class SC_DLLPUBLIC ScDocOptions
-     ::rtl::OUString aFormulaSepArrayCol;
- 
- public:
-+    static const sal_uInt16 PRECISION_UNSPECIFIED;
-+
-                 ScDocOptions();
-                 ScDocOptions( const ScDocOptions& rCpy );
-                 ~ScDocOptions();
-@@ -96,8 +98,8 @@ public:
+@@ -96,8 +96,8 @@ public:
      inline int					operator==( const ScDocOptions& rOpt ) const;
      inline int					operator!=( const ScDocOptions& rOpt ) const;
  
@@ -31,19 +22,6 @@ index 81b80b9..006c618 100644
  
      BOOL	IsCalcAsShown() const		{ return bCalcAsShown; }
      void	SetCalcAsShown( BOOL bVal )	{ bCalcAsShown = bVal; }
-diff --git sc/source/core/tool/docoptio.cxx sc/source/core/tool/docoptio.cxx
-index b0188ee..e1cd909 100644
---- sc/source/core/tool/docoptio.cxx
-+++ sc/source/core/tool/docoptio.cxx
-@@ -83,6 +83,8 @@ USHORT lcl_GetDefaultTabDist()
- //      ScDocOptions - Dokument-Optionen
- //========================================================================
- 
-+const sal_uInt16 ScDocOptions::PRECISION_UNSPECIFIED = ::std::numeric_limits<USHORT>::max();
-+
- ScDocOptions::ScDocOptions()
- {
-     ResetDocOptions();
 diff --git sc/source/ui/inc/optdlg.hrc sc/source/ui/inc/optdlg.hrc
 index aaeb33d..5767bfb 100644
 --- sc/source/ui/inc/optdlg.hrc
@@ -116,7 +94,7 @@ index 7052be4..3253f59 100644
      FixedText		aFtPrec;
      NumericField	aEdPrec;
 diff --git sc/source/ui/optdlg/tpcalc.cxx sc/source/ui/optdlg/tpcalc.cxx
-index 86a4476..1a0ed0c 100644
+index 86a4476..d70bab7 100644
 --- sc/source/ui/optdlg/tpcalc.cxx
 +++ sc/source/ui/optdlg/tpcalc.cxx
 @@ -91,6 +91,7 @@ ScTpCalcOptions::ScTpCalcOptions( Window*			pParent,
@@ -143,12 +121,12 @@ index 86a4476..1a0ed0c 100644
      aEdEps     .SetValue( pLocalOptions->GetIterEps(), 6 );
  
      pLocalOptions->GetDate( d, m, y );
-@@ -171,6 +173,21 @@ void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
+@@ -171,6 +172,21 @@ void __EXPORT ScTpCalcOptions::Reset( const SfxItemSet& /* rCoreAttrs */ )
              break;
      }
  
 +    sal_uInt16 nPrec = pLocalOptions->GetStdPrecision();
-+    if (nPrec == ScDocOptions::PRECISION_UNSPECIFIED)
++    if (nPrec == SvNumberFormatter::UNLIMITED_PRECISION)
 +    {
 +        aFtPrec.Disable();
 +        aEdPrec.Disable();
@@ -165,7 +143,7 @@ index 86a4476..1a0ed0c 100644
      CheckClickHdl( &aBtnIterate );
  }
  
-@@ -181,13 +198,18 @@ BOOL __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
+@@ -181,13 +197,18 @@ BOOL __EXPORT ScTpCalcOptions::FillItemSet( SfxItemSet& rCoreAttrs )
  {
      // alle weiteren Optionen werden in den Handlern aktualisiert
      pLocalOptions->SetIterCount( (USHORT)aEdSteps.GetValue() );
@@ -180,12 +158,12 @@ index 86a4476..1a0ed0c 100644
 +        pLocalOptions->SetStdPrecision(
 +            static_cast<sal_uInt16>(aEdPrec.GetValue()) );
 +    else
-+        pLocalOptions->SetStdPrecision( ScDocOptions::PRECISION_UNSPECIFIED );
++        pLocalOptions->SetStdPrecision( SvNumberFormatter::UNLIMITED_PRECISION );
 +
      if ( *pLocalOptions != *pOldOptions )
      {
          rCoreAttrs.Put( ScTpCalcItem( nWhichCalc, *pLocalOptions ) );
-@@ -248,19 +270,35 @@ IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
+@@ -248,19 +269,35 @@ IMPL_LINK( ScTpCalcOptions, RadioClickHdl, RadioButton*, pBtn )
  
  //-----------------------------------------------------------------------
  
@@ -300,7 +278,7 @@ index f91bb81..a6a4867 100644
                  }
              }
 diff --git sc/source/ui/view/output2.cxx sc/source/ui/view/output2.cxx
-index ef7f0c9..d67ab6d 100644
+index ef7f0c9..e51cda1 100644
 --- sc/source/ui/view/output2.cxx
 +++ sc/source/ui/view/output2.cxx
 @@ -56,6 +56,7 @@
@@ -394,7 +372,7 @@ index ef7f0c9..d67ab6d 100644
          }
          //	sonst String/Groesse behalten
      }
-@@ -511,6 +500,56 @@ void ScDrawStringsVars::SetHashText()
+@@ -511,6 +500,52 @@ void ScDrawStringsVars::SetHashText()
      SetAutoText( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("###")) );
  }
  
@@ -437,10 +415,6 @@ index ef7f0c9..d67ab6d 100644
 +    if (pOutput->pFmtDevice->GetTextWidth(aString) > nWidth)
 +    {
 +        // Even after the decimal adjustment the text doesn't fit.  Give up.
-+
-+        // TODO: Excel in this case first tries to see if the value can be
-+        // displayed in scientific notation.  Failing that, it sets hash text.
-+        // We may want to do the same here in the future. --kohei
 +        SetHashText();
 +        return;
 +    }
@@ -451,7 +425,7 @@ index ef7f0c9..d67ab6d 100644
  void ScDrawStringsVars::SetAutoText( const String& rAutoText )
  {
      aString = rAutoText;
-@@ -541,6 +580,47 @@ void ScDrawStringsVars::SetAutoText( const String& rAutoText )
+@@ -541,6 +576,47 @@ void ScDrawStringsVars::SetAutoText( const String& rAutoText )
      pLastCell = NULL;		// derselbe Text kann in der naechsten Zelle wieder passen
  }
  
@@ -499,7 +473,7 @@ index ef7f0c9..d67ab6d 100644
  BOOL ScDrawStringsVars::HasEditCharacters() const
  {
      static const sal_Unicode pChars[] =
-@@ -922,29 +1002,25 @@ BOOL ScOutputData::IsAvailable( SCCOL nX, SCROW nY )
+@@ -922,29 +998,25 @@ BOOL ScOutputData::IsAvailable( SCCOL nX, SCROW nY )
  // bCellIsValue:	if set, don't extend into empty cells
  // bBreak:			if set, don't extend, and don't set clip marks (but rLeftClip/rRightClip is set)
  // bOverwrite:		if set, also extend into non-empty cells (for rotated text)
@@ -538,7 +512,7 @@ index ef7f0c9..d67ab6d 100644
          long nColWidth = ( nCompCol <= nX2 ) ?
                  pRowInfo[0].pCellInfo[nCompCol+1].nWidth :
                  (long) ( pDoc->GetColWidth( nCompCol, nTab ) * nPPTX );
-@@ -960,7 +1036,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
+@@ -960,7 +1032,7 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
          nCellPosX -= nColWidth * nLayoutSign;
      }
  
@@ -547,7 +521,7 @@ index ef7f0c9..d67ab6d 100644
      SCSIZE nCompArr = nArrY;
      SCROW nCompRow = pRowInfo[nCompArr].nRowNo;
      while ( nCellY > nCompRow )
-@@ -1005,28 +1081,30 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
+@@ -1005,28 +1077,30 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
      {
          // take first row's height from row info
          nMergeSizeY += rThisRowInfo.nHeight;
@@ -588,7 +562,7 @@ index ef7f0c9..d67ab6d 100644
      if ( nNeeded > nMergeSizeX )
      {
          SvxCellHorJustify eHorJust = (SvxCellHorJustify)nHorJustify;
-@@ -1060,14 +1138,14 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
+@@ -1060,14 +1134,14 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
          SCCOL nLeftX = nCellX;
          if ( !bMerged && !bCellIsValue && !bBreak )
          {
@@ -605,7 +579,7 @@ index ef7f0c9..d67ab6d 100644
  
                  if ( rThisRowInfo.nRowNo == nCellY && nRightX >= nX1 && nRightX <= nX2 )
                      rThisRowInfo.pCellInfo[nRightX].bHideGrid = TRUE;
-@@ -1081,33 +1159,33 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
+@@ -1081,33 +1155,33 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
                  --nLeftX;
                  long nAdd = (long) ( pDoc->GetColWidth( nLeftX, nTab ) * nPPTX );
                  nLeftMissing -= nAdd;
@@ -647,7 +621,7 @@ index ef7f0c9..d67ab6d 100644
  
          // leave space for AutoFilter on screen
          // (for automatic line break: only if not formatting for printer, as in ScColumn::GetNeededSize)
-@@ -1123,30 +1201,30 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
+@@ -1123,30 +1197,30 @@ void ScOutputData::GetOutputArea( SCCOL nX, SCSIZE nArrY, long nPosX, long nPosY
                  // content fits even in the remaining area without the filter button
                  // -> align within that remaining area
  
@@ -686,7 +660,7 @@ index ef7f0c9..d67ab6d 100644
      pDev->Pop();
      //! Test !!!
  #endif
-@@ -1187,12 +1265,9 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1187,12 +1261,9 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
          --nLoopStartX;			// start before nX1 for rest of long text to the left
  
      // variables for GetOutputArea
@@ -700,7 +674,7 @@ index ef7f0c9..d67ab6d 100644
      SvxCellHorJustify eOutHorJust = SVX_HOR_JUSTIFY_STANDARD;
      const ScPatternAttr* pPattern = NULL;
      const SfxItemSet* pCondSet = NULL;
-@@ -1363,6 +1438,7 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1363,6 +1434,7 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                      bNeedEdit = aVars.HasEditCharacters() ||
                                      (bFormulaCell && ((ScFormulaCell*)pCell)->IsMultilineResult());                
                  }
@@ -708,7 +682,7 @@ index ef7f0c9..d67ab6d 100644
                  if (bDoCell && !bNeedEdit)
                  {
                      CellType eCellType = pCell->GetCellType();
-@@ -1384,14 +1460,17 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1384,14 +1456,17 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                      BOOL bRepeat = aVars.IsRepeat() && !bBreak;
                      BOOL bShrink = aVars.IsShrink() && !bBreak && !bRepeat;
  
@@ -731,7 +705,7 @@ index ef7f0c9..d67ab6d 100644
  
                      if ( bShrink )
                      {
-@@ -1401,9 +1480,9 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1401,9 +1476,9 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                              // DrawEdit is used to vertically scale 90 deg rotated text.
                              bNeedEdit = TRUE;
                          }
@@ -743,7 +717,7 @@ index ef7f0c9..d67ab6d 100644
                              long nScaleSize = aVars.GetTextSize().Width();         // without margin
  
                              if ( nScaleSize > 0 )       // 0 if the text is empty (formulas, number formats)
-@@ -1427,16 +1506,16 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1427,16 +1502,16 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                                  // If even at half the size the font still isn't rendered smaller,
                                  // fall back to normal clipping (showing ### for numbers).
                                  if ( nNewSize <= nAvailable )
@@ -763,7 +737,7 @@ index ef7f0c9..d67ab6d 100644
                          long nRepeatSize = aVars.GetTextSize().Width();         // without margin
                          // When formatting for the printer, the text sizes don't always add up.
                          // Round down (too few repetitions) rather than exceeding the cell size then:
-@@ -1460,13 +1539,13 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1460,13 +1535,13 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                      if ( bBreak )
                      {
                          if ( aVars.GetOrient() == SVX_ORIENTATION_STANDARD )
@@ -779,7 +753,7 @@ index ef7f0c9..d67ab6d 100644
                          }
                      }
                  }
-@@ -1482,48 +1561,49 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1482,48 +1557,49 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
                  }
                  if ( bDoCell )
                  {
@@ -849,7 +823,7 @@ index ef7f0c9..d67ab6d 100644
                          bVClip = TRUE;
                      }
  
-@@ -1606,27 +1686,27 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
+@@ -1606,27 +1682,27 @@ void ScOutputData::DrawStrings( BOOL bPixelToLogic )
  
                              if (!bHClip)
                              {
@@ -884,7 +858,7 @@ index ef7f0c9..d67ab6d 100644
                          }
  
                          Point aURLStart( nJustPosX, nJustPosY );    // copy before modifying for orientation
-@@ -1830,7 +1910,7 @@ long lcl_GetEditSize( EditEngine& rEngine, BOOL bWidth, BOOL bSwap, long nAttrRo
+@@ -1830,7 +1906,7 @@ long lcl_GetEditSize( EditEngine& rEngine, BOOL bWidth, BOOL bSwap, long nAttrRo
  void ScOutputData::ShrinkEditEngine( EditEngine& rEngine, const Rectangle& rAlignRect,
              long nLeftM, long nTopM, long nRightM, long nBottomM,
              BOOL bWidth, USHORT nOrient, long nAttrRotate, BOOL bPixelToLogic,
@@ -893,7 +867,7 @@ index ef7f0c9..d67ab6d 100644
  {
      if ( !bWidth )
      {
-@@ -2152,10 +2232,7 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2152,10 +2228,7 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                  nPosY = nScrY;
                              }
  
@@ -905,7 +879,7 @@ index ef7f0c9..d67ab6d 100644
  
                              //
                              //	Initial page size - large for normal text, cell size for automatic line breaks
-@@ -2170,23 +2247,22 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2170,23 +2243,22 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
  
                                  //!	handle nArrY == 0
                                  GetOutputArea( nXForPos, nArrYForPos, nPosX, nPosY, nCellX, nCellY, 0,
@@ -934,7 +908,7 @@ index ef7f0c9..d67ab6d 100644
                                  }
                              }
                              if (bPixelToLogic)
-@@ -2375,26 +2451,26 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2375,26 +2447,26 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                              {
                                  // for break, the first GetOutputArea call is sufficient
                                  GetOutputArea( nXForPos, nArrYForPos, nPosX, nPosY, nCellX, nCellY, nNeededPixel,
@@ -968,7 +942,7 @@ index ef7f0c9..d67ab6d 100644
                                      if ( nAvailable >= 2 * nFormatted )
                                      {
                                          // "repeat" is handled with unformatted text (for performance reasons)
-@@ -2428,7 +2504,7 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2428,7 +2500,7 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                      }
                                  }
  
@@ -977,7 +951,7 @@ index ef7f0c9..d67ab6d 100644
                                  {
                                      pEngine->SetText( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("###")) );
                                      nEngineWidth = (long) pEngine->CalcTextWidth();
-@@ -2451,11 +2527,11 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2451,11 +2523,11 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                  }
                              }
  
@@ -993,7 +967,7 @@ index ef7f0c9..d67ab6d 100644
  
                              if ( bBreak || eOrient != SVX_ORIENTATION_STANDARD || bAsianVertical )
                              {
-@@ -2475,21 +2551,21 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2475,21 +2547,21 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                      nStartX += nLeftM;
                              }
  
@@ -1023,7 +997,7 @@ index ef7f0c9..d67ab6d 100644
                                  BOOL bSimClip = FALSE;
  
                                  if ( bWrapFields )
-@@ -2498,14 +2574,14 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2498,14 +2570,14 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                      bClip = TRUE;
                                  }
  
@@ -1042,7 +1016,7 @@ index ef7f0c9..d67ab6d 100644
                                      bClip = TRUE;
                                  }
  
-@@ -2557,8 +2633,8 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2557,8 +2629,8 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                          bAnyClipped = TRUE;
  
                                          long nMarkPixel = (long)( SC_CLIPMARK_SIZE * nPPTX );
@@ -1053,7 +1027,7 @@ index ef7f0c9..d67ab6d 100644
                                      }
                                  }
  
-@@ -2582,9 +2658,9 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
+@@ -2582,9 +2654,9 @@ void ScOutputData::DrawEdit(BOOL bPixelToLogic)
                                      // Clip marks are already handled in GetOutputArea
  
                                      if (bPixelToLogic)
@@ -1065,7 +1039,7 @@ index ef7f0c9..d67ab6d 100644
  
                                      if (bClip)	// bei bSimClip nur aClipRect initialisieren
                                      {
-@@ -3218,10 +3294,7 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
+@@ -3218,10 +3290,7 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
  
                                  // use GetOutputArea to hide the grid
                                  // (clip region is done manually below)
@@ -1077,7 +1051,7 @@ index ef7f0c9..d67ab6d 100644
  
                                  SCCOL nCellX = nX;
                                  SCROW nCellY = nY;
-@@ -3234,8 +3307,7 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
+@@ -3234,8 +3303,7 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
  
                                  GetOutputArea( nX, nArrY, nCellStartX, nPosY, nCellX, nCellY, nNeededWidth,
                                                  *pPattern, sal::static_int_cast<USHORT>(eOutHorJust),
@@ -1087,7 +1061,7 @@ index ef7f0c9..d67ab6d 100644
  
                                  if ( bShrink )
                                  {
-@@ -3243,19 +3315,19 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
+@@ -3243,19 +3311,19 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
                                          pRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width() : nEngineWidth;
                                      long nNeededPixel = nPixelWidth + nLeftM + nRightM;
  
@@ -1112,7 +1086,7 @@ index ef7f0c9..d67ab6d 100644
                                      }
  
                                      // nEngineWidth/nEngineHeight is updated in ShrinkEditEngine
-@@ -3309,19 +3381,19 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
+@@ -3309,19 +3377,19 @@ void ScOutputData::DrawRotated(BOOL bPixelToLogic)
                                      }
  
                                      if (bPixelToLogic)
diff --git a/patches/dev300/calc-general-type-auto-decimal-svtools.diff b/patches/dev300/calc-general-type-auto-decimal-svtools.diff
index 5ec9850..4de3095 100644
--- a/patches/dev300/calc-general-type-auto-decimal-svtools.diff
+++ b/patches/dev300/calc-general-type-auto-decimal-svtools.diff
@@ -1,5 +1,30 @@
+diff --git svtools/inc/svtools/zforlist.hxx svtools/inc/svtools/zforlist.hxx
+index bb4a589..2ae53fc 100644
+--- svtools/inc/svtools/zforlist.hxx
++++ svtools/inc/svtools/zforlist.hxx
+@@ -336,6 +336,11 @@ class SvNumberFormatterRegistry_Impl;
+ class SVT_DLLPUBLIC SvNumberFormatter
+ {
+ public:
++    /** 
++     * We can't technically have an "infinite" value, so we use an arbitrary 
++     * upper precision threshold to represent the "unlimited" precision. 
++     */ 
++    static const sal_uInt16 UNLIMITED_PRECISION;
+ 
+     /// Preferred ctor with service manager and language/country enum
+     SvNumberFormatter(
+@@ -586,7 +591,7 @@ public:
+     /// Return the reference date
+     Date* GetNullDate();
+     /// Return the standard decimal precision
+-    short GetStandardPrec();
++    sal_uInt16 GetStandardPrec();
+     /// Return whether zero suppression is switched on
+     BOOL GetNoZero() { return bNoZero; }
+     /** Get the type of a format (or NUMBERFORMAT_UNDEFINED if no entry),
 diff --git svtools/inc/svtools/zformat.hxx svtools/inc/svtools/zformat.hxx
-index 4c52b10..4037a73 100644
+index 4c52b10..8158524 100644
 --- svtools/inc/svtools/zformat.hxx
 +++ svtools/inc/svtools/zformat.hxx
 @@ -239,6 +239,12 @@ public:
@@ -19,12 +44,60 @@ index 4c52b10..4037a73 100644
  
      // standard number output
      SVT_DLLPRIVATE void ImpGetOutputStandard( double& fNumber, String& OutString );
-+    SVT_DLLPRIVATE void ImpGetOutputStdToPrecision( double& rNumber, String& rOutString, USHORT nPrecision ) const;
++    SVT_DLLPRIVATE void ImpGetOutputStdToPrecision( double& rNumber, String& rOutString, sal_uInt16 nPrecision ) const;
      // numbers in input line
      SVT_DLLPRIVATE void ImpGetOutputInputLine( double fNumber, String& OutString );
  
+diff --git svtools/source/numbers/zforlist.cxx svtools/source/numbers/zforlist.cxx
+index 4b13774..85807ce 100644
+--- svtools/source/numbers/zforlist.cxx
++++ svtools/source/numbers/zforlist.cxx
+@@ -70,6 +70,7 @@
+ #include <rtl/instance.hxx>
+ 
+ #include <math.h>
++#include <limits>
+ 
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+@@ -192,6 +193,8 @@ SV_IMPL_PTRARR( NfWSStringsDtor, String* );
+ 
+ /***********************Funktionen SvNumberFormatter**************************/
+ 
++const sal_uInt16 SvNumberFormatter::UNLIMITED_PRECISION = ::std::numeric_limits<sal_uInt16>::max();
++
+ SvNumberFormatter::SvNumberFormatter(
+             const Reference< XMultiServiceFactory >& xSMgr,
+             LanguageType eLang )
+@@ -352,7 +355,7 @@ void SvNumberFormatter::ChangeStandardPrec(short nPrec)
+     pFormatScanner->ChangeStandardPrec(nPrec);
+ }
+ 
+-short SvNumberFormatter::GetStandardPrec()
++sal_uInt16 SvNumberFormatter::GetStandardPrec()
+ {
+     return pFormatScanner->GetStandardPrec();
+ }
+@@ -1508,7 +1511,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
+         if (eType != NUMBERFORMAT_PERCENT)	// spaeter Sonderbehandlung %
+             eType = NUMBERFORMAT_NUMBER;
+         nOldPrec = pFormatScanner->GetStandardPrec();
+-        ChangeStandardPrec(300);						// Merkwert
++        ChangeStandardPrec(UNLIMITED_PRECISION);						// Merkwert
+     }
+     sal_uInt32 nKey = nFIndex;
+     switch ( eType )
+@@ -1529,7 +1532,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
+         if ( eType == NUMBERFORMAT_TIME && pFormat->GetFormatPrecision() )
+         {
+             nOldPrec = pFormatScanner->GetStandardPrec();
+-            ChangeStandardPrec(300);						// Merkwert
++            ChangeStandardPrec(UNLIMITED_PRECISION);						// Merkwert
+         }
+         pFormat->GetOutputString(fOutNumber, sOutString, &pColor);
+     }
 diff --git svtools/source/numbers/zformat.cxx svtools/source/numbers/zformat.cxx
-index 368fb16..831e999 100644
+index 368fb16..2be8168 100644
 --- svtools/source/numbers/zformat.cxx
 +++ svtools/source/numbers/zformat.cxx
 @@ -57,6 +57,9 @@
@@ -37,50 +110,135 @@ index 368fb16..831e999 100644
  using namespace svt;
  
  namespace {
-@@ -1778,9 +1781,14 @@ void SvNumberformat::Build50Formatstring( String& rStr ) const
+@@ -66,6 +69,9 @@ struct Gregorian
+         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("gregorian"));
+     }
+ };
++
++const sal_uInt16 UPPER_PRECISION = 300; // entirely arbitrary...
++
+ }
+ 
+ const double _D_MAX_U_LONG_ = (double) 0xffffffff;      // 4294967295.0
+@@ -1777,47 +1783,62 @@ void SvNumberformat::Build50Formatstring( String& rStr ) const
+ 
  void SvNumberformat::ImpGetOutputStandard(double& fNumber, String& OutString)
  {
-     USHORT nStandardPrec = rScan.GetStandardPrec();
--    if ( fabs(fNumber) > 1.0E15 )       // #58531# war E16
--        OutString = ::rtl::math::doubleToUString( fNumber,
--                rtl_math_StringFormat_E, nStandardPrec /*2*/,
-+    ImpGetOutputStdToPrecision(fNumber, OutString, nStandardPrec);
-+}
+-    USHORT nStandardPrec = rScan.GetStandardPrec();
++    sal_uInt16 nStandardPrec = rScan.GetStandardPrec();
 +
-+void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, String& rOutString, USHORT nPrecision) const
-+{
-+    if ( fabs(rNumber) > 1.0E15 )       // #58531# war E16
-+        rOutString = ::rtl::math::doubleToUString( rNumber,
-+                rtl_math_StringFormat_E, nPrecision /*2*/,
+     if ( fabs(fNumber) > 1.0E15 )       // #58531# war E16
++    {
++        nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals
+         OutString = ::rtl::math::doubleToUString( fNumber,
+                 rtl_math_StringFormat_E, nStandardPrec /*2*/,
                  GetFormatter().GetNumDecimalSep().GetChar(0));
++    }
      else
-     {
-@@ -1809,15 +1817,14 @@ void SvNumberformat::ImpGetOutputStandard(double& fNumber, String& OutString)
+-    {
++        ImpGetOutputStdToPrecision(fNumber, OutString, nStandardPrec);
++}
++
++void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, String& rOutString, sal_uInt16 nPrecision) const
++{
++    // Make sure the precision doesn't go over the maximum allowable precision.
++    nPrecision = ::std::min(UPPER_PRECISION, nPrecision);
++
+ #if 0
+ {
+-        // debugger test case for ANSI standard correctness
+-        ::rtl::OUString aTest;
+-        // expect 0.00123   OK
+-        aTest = ::rtl::math::doubleToUString( 0.001234567,
+-                rtl_math_StringFormat_G, 3, '.', sal_True );
+-        // expect 123       OK
+-        aTest = ::rtl::math::doubleToUString( 123.4567,
+-                rtl_math_StringFormat_G, 3, '.', sal_True );
+-        // expect 123.5     OK
+-        aTest = ::rtl::math::doubleToUString( 123.4567,
+-                rtl_math_StringFormat_G, 4, '.', sal_True );
+-        // expect 1e+03 (as 999.6 rounded to 3 significant digits results in
+-        // 1000 with an exponent equal to significant digits)
+-        // Currently (24-Jan-2003) we do fail in this case and output 1000
+-        // instead, negligible.
+-        aTest = ::rtl::math::doubleToUString( 999.6,
+-                rtl_math_StringFormat_G, 3, '.', sal_True );
+-        // expect what? result is 1.2e+004
+-        aTest = ::rtl::math::doubleToUString( 12345.6789,
+-                rtl_math_StringFormat_G, -3, '.', sal_True );
++    // debugger test case for ANSI standard correctness
++    ::rtl::OUString aTest;
++    // expect 0.00123   OK
++    aTest = ::rtl::math::doubleToUString( 0.001234567,
++            rtl_math_StringFormat_G, 3, '.', sal_True );
++    // expect 123       OK
++    aTest = ::rtl::math::doubleToUString( 123.4567,
++            rtl_math_StringFormat_G, 3, '.', sal_True );
++    // expect 123.5     OK
++    aTest = ::rtl::math::doubleToUString( 123.4567,
++            rtl_math_StringFormat_G, 4, '.', sal_True );
++    // expect 1e+03 (as 999.6 rounded to 3 significant digits results in
++    // 1000 with an exponent equal to significant digits)
++    // Currently (24-Jan-2003) we do fail in this case and output 1000
++    // instead, negligible.
++    aTest = ::rtl::math::doubleToUString( 999.6,
++            rtl_math_StringFormat_G, 3, '.', sal_True );
++    // expect what? result is 1.2e+004
++    aTest = ::rtl::math::doubleToUString( 12345.6789,
++            rtl_math_StringFormat_G, -3, '.', sal_True );
  }
  #endif
  
 -        OutString = ::rtl::math::doubleToUString( fNumber,
 -                rtl_math_StringFormat_F, nStandardPrec /*2*/,
-+        rOutString = ::rtl::math::doubleToUString( rNumber,
-+                rtl_math_StringFormat_F, nPrecision /*2*/,
-                 GetFormatter().GetNumDecimalSep().GetChar(0), sal_True );
+-                GetFormatter().GetNumDecimalSep().GetChar(0), sal_True );
 -        if (OutString.GetChar(0) == '-' &&
 -            OutString.GetTokenCount('0') == OutString.Len())
 -            OutString.EraseLeadingChars('-');            // nicht -0
-+        if (rOutString.GetChar(0) == '-' &&
-+            rOutString.GetTokenCount('0') == rOutString.Len())
-+            rOutString.EraseLeadingChars('-');            // nicht -0
-     }
+-    }
 -    ImpTransliterate( OutString, NumFor[0].GetNatNum() );
 -    return;
++    // If truncating the value to desired precision alters the original value,
++    // we should show the trailing zeros, otherwise strip them.
++    double fRounded = ::rtl::math::round(rNumber, nPrecision);
++    bool bRemoveZeros = ::rtl::math::approxEqual(fRounded, rNumber);
++
++    rOutString = ::rtl::math::doubleToUString( rNumber,
++            rtl_math_StringFormat_F, nPrecision /*2*/,
++            GetFormatter().GetNumDecimalSep().GetChar(0), bRemoveZeros );
++    if (rOutString.GetChar(0) == '-' &&
++        rOutString.GetTokenCount('0') == rOutString.Len())
++        rOutString.EraseLeadingChars('-');            // nicht -0
++
 +    ImpTransliterate( rOutString, NumFor[0].GetNatNum() );
  }
  
  void SvNumberformat::ImpGetOutputInputLine(double fNumber, String& OutString)
-@@ -1958,6 +1965,31 @@ ULONG SvNumberformat::ImpGGTRound(ULONG x, ULONG y)
+@@ -1958,6 +1979,62 @@ ULONG SvNumberformat::ImpGGTRound(ULONG x, ULONG y)
      }
  }
  
++namespace {
++
++void lcl_GetOutputStringScientific(
++    double fNumber, sal_uInt16 nCharCount, const SvNumberFormatter& rFormatter, String& rOutString)
++{
++    bool bSign = ::rtl::math::isSignBitSet(fNumber);
++
++    // 1.000E+015 (one digit and the decimal point, and the five chars for the exponential part, totalling 7).
++    sal_uInt16 nPrec = nCharCount > 7 ? nCharCount - 7 : 0;
++    if (nPrec && bSign)
++        // Make room for the negative sign.
++        --nPrec;
++
++    nPrec = ::std::min(nPrec, static_cast<sal_uInt16>(14)); // limit to 14 decimals.
++
++    rOutString = ::rtl::math::doubleToUString(
++        fNumber, rtl_math_StringFormat_E, nPrec, rFormatter.GetNumDecimalSep().GetChar(0));
++}
++
++}
++
 +bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, String& rOutString) const
 +{
 +    using namespace std;
@@ -89,11 +247,17 @@ index 368fb16..831e999 100644
 +        return false;
 +
 +    double fTestNum = fNumber;
-+    bool bSign = fTestNum < 0;
++    bool bSign = ::rtl::math::isSignBitSet(fTestNum);
 +    if (bSign)
 +        fTestNum = -fTestNum;
 +
-+    double nDigitPre = ceil(log10(fTestNum));
++    sal_uInt16 nDigitPre = static_cast<sal_uInt16>(ceil(log10(fTestNum)));
++    if (nDigitPre > 15)
++    {
++        lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString);
++        return true;
++    }
++
 +    sal_uInt16 nPrec = nCharCount >= nDigitPre ? nCharCount - nDigitPre : 0;
 +    if (nPrec && bSign)
 +        // Subtract the negative sign.
@@ -103,9 +267,66 @@ index 368fb16..831e999 100644
 +        --nPrec;
 +
 +    ImpGetOutputStdToPrecision(fNumber, rOutString, nPrec);
++    if (rOutString.Len() > nCharCount)
++        // String still wider than desired.  Switch to scientific notation.
++        lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString);
++
 +    return true;
 +}
 +
  BOOL SvNumberformat::GetOutputString(double fNumber,
                                       String& OutString,
                                       Color** ppColor)
+@@ -1981,7 +2058,7 @@ BOOL SvNumberformat::GetOutputString(double fNumber,
+     BOOL bHadStandard = FALSE;
+     if (bStandard)                              // einzelne Standardformate
+     {
+-        if (rScan.GetStandardPrec() == 300)     // alle Zahlformate InputLine
++        if (rScan.GetStandardPrec() == SvNumberFormatter::UNLIMITED_PRECISION)     // alle Zahlformate InputLine
+         {
+             ImpGetOutputInputLine(fNumber, OutString);
+             return FALSE;
+diff --git svtools/source/numbers/zforscan.cxx svtools/source/numbers/zforscan.cxx
+index ab780cd..7bd764e 100644
+--- svtools/source/numbers/zforscan.cxx
++++ svtools/source/numbers/zforscan.cxx
+@@ -468,7 +468,7 @@ void ImpSvNumberformatScan::ChangeNullDate(USHORT nDay, USHORT nMonth, USHORT nY
+         pNullDate = new Date(nDay, nMonth, nYear);
+ }
+ 
+-void ImpSvNumberformatScan::ChangeStandardPrec(short nPrec)
++void ImpSvNumberformatScan::ChangeStandardPrec(sal_uInt16 nPrec)
+ {
+     nStandardPrec = nPrec;
+ }
+diff --git svtools/source/numbers/zforscan.hxx svtools/source/numbers/zforscan.hxx
+index df243f1..6a69675 100644
+--- svtools/source/numbers/zforscan.hxx
++++ svtools/source/numbers/zforscan.hxx
+@@ -57,7 +57,7 @@ public:
+ 
+     void ChangeNullDate(USHORT nDay, USHORT nMonth, USHORT nYear);
+                                                 // tauscht Referenzdatum aus
+-    void ChangeStandardPrec(short nPrec);		// tauscht Standardprecision aus
++    void ChangeStandardPrec(sal_uInt16 nPrec);  // tauscht Standardprecision aus
+ 
+     xub_StrLen ScanFormat( String& rString, String& rComment );	// Aufruf der Scan-Analyse
+ 
+@@ -96,7 +96,7 @@ public:
+                 InitKeywords();
+             return sNameStandardFormat;
+         }
+-    short GetStandardPrec() const				{ return nStandardPrec; }
++    sal_uInt16 GetStandardPrec() const          { return nStandardPrec; }
+     const Color& GetRedColor() const			{ return StandardColor[4]; }
+     Color* GetColor(String& sStr);			// Setzt Hauptfarben oder
+                                                 // definierte Farben
+@@ -161,7 +161,7 @@ private:							// ---- privater Teil
+                                                 // Array der Standardfarben
+     Date* pNullDate;							// 30Dec1899
+     String sNameStandardFormat;				// "Standard"
+-    short nStandardPrec;						// default Precision fuer Standardformat (2)
++    sal_uInt16 nStandardPrec;                   // default Precision for Standardformat
+     SvNumberFormatter* pFormatter;				// Pointer auf die Formatliste
+ 
+     String sStrArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Symbole


More information about the ooo-build-commit mailing list