[ooo-build-commit] patches/dev300

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Jul 29 11:34:48 PDT 2009


 patches/dev300/apply                                     |    4 
 patches/dev300/calc-html-csv-import-force-text-cell.diff |  381 +++++++++++++++
 2 files changed, 385 insertions(+)

New commits:
commit c1a22accf14d422e9e8f1a5a00591cc94482bd6b
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Jul 29 14:08:57 2009 -0400

    Set cell format to Text for string value during text file import.
    
    * patches/dev300/apply: apply the new patch.
    
    * patches/dev300/calc-html-csv-import-force-text-cell.diff: set cell
      format to Text when a string value is requested & the value itself
      would be interpreted as a number otherwise.  With this change, those
      string number values don't need to display ' in front of them which
      some users found confusing. (n#523414)

diff --git a/patches/dev300/apply b/patches/dev300/apply
index 42b9197..f44dbdf 100644
--- a/patches/dev300/apply
+++ b/patches/dev300/apply
@@ -3382,6 +3382,10 @@ calc-xls-import-shared-formula-refwrap.diff, n#522833, i#103861, kohei
 # line even if matching quotes are on separate lines.
 stream-read-csv-always-single-line.diff, n#523517, kohei
 
+# set cell format to Text when a string format is requested, and don't 
+# prepend ' in front of the value.
+calc-html-csv-import-force-text-cell.diff, n#523414, kohei
+
 # draw an animated dashed border around copied ranges.
 calc-copy-range-animated-border-sc.diff, kohei
 calc-copy-range-animated-border-svx.diff, kohei
diff --git a/patches/dev300/calc-html-csv-import-force-text-cell.diff b/patches/dev300/calc-html-csv-import-force-text-cell.diff
new file mode 100644
index 0000000..6ddcfc2
--- /dev/null
+++ b/patches/dev300/calc-html-csv-import-force-text-cell.diff
@@ -0,0 +1,381 @@
+diff --git sc/inc/column.hxx sc/inc/column.hxx
+index 606602c..a39a958 100644
+--- sc/inc/column.hxx
++++ sc/inc/column.hxx
+@@ -72,6 +72,7 @@ struct ScFunctionData;
+ struct ScLineFlags;
+ struct ScMergePatternState;
+ class ScFlatBoolRowSegments;
++struct ScSetStringParam;
+ 
+ #define COLUMN_DELTA	4
+ 
+@@ -244,8 +245,7 @@ public:
+                 //	TRUE = Zahlformat gesetzt
+     BOOL		SetString( SCROW nRow, SCTAB nTab, const String& rString,
+ 						   formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO,
+-                           SvNumberFormatter* pFormatter = NULL,
+-                           bool bDetectNumberFormat = true );
++                           ScSetStringParam* pParam = NULL );
+     void		SetValue( SCROW nRow, const double& rVal);
+     void		SetError( SCROW nRow, const USHORT nError);
+ 
+diff --git sc/inc/document.hxx sc/inc/document.hxx
+index 862682c..8d28d82 100644
+--- sc/inc/document.hxx
++++ sc/inc/document.hxx
+@@ -142,6 +142,7 @@ class ScLookupCache;
+ struct ScLookupCacheMapImpl;
+ struct ScClipParam;
+ struct ScClipRangeNameData;
++struct ScSetStringParam;
+ 
+ namespace com { namespace sun { namespace star {
+     namespace lang {
+@@ -736,8 +737,7 @@ public:
+                             ULONG nFormatIndex, BOOL bForceTab = FALSE);
+                     //	return TRUE = Zahlformat gesetzt
+     SC_DLLPUBLIC BOOL           SetString(
+-        SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, 
+-        SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true );
++        SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, ScSetStringParam* pParam = NULL );
+     SC_DLLPUBLIC void           SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal );
+     void 			SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const USHORT nError);
+ 
+diff --git sc/inc/stringutil.hxx sc/inc/stringutil.hxx
+index 4ca8629..fd2d7c3 100644
+--- sc/inc/stringutil.hxx
++++ sc/inc/stringutil.hxx
+@@ -32,6 +32,41 @@
+ #define SC_STRINGUTIL_HXX
+ 
+ #include "rtl/ustring.hxx"
++#include "scdllapi.h"
++
++class SvNumberFormatter;
++
++/** 
++ * Store parameters used in the ScDocument::SetString() method.  Various 
++ * options for string-setting operation are specified herein. 
++ */
++struct SC_DLLPUBLIC ScSetStringParam
++{
++    /** 
++     * Stores the pointer to the number formatter instance to be used during 
++     * number format detection.  The caller must manage the life cycle of the 
++     * instance. 
++     */
++    SvNumberFormatter* mpNumFormatter;
++
++    /** 
++     * When true, we try to detect special number format (dates etc) from the 
++     * input string, when false, we only try to detect a basic decimal number 
++     * format. 
++     */
++    bool mbDetectNumberFormat;
++
++    /** 
++     * When true, set the format of the cell to Text when a string cell is 
++     * requested for a number input.  We may want to do this during text file 
++     * import (csv, html etc). 
++     */
++    bool mbSetTextCellFormat; 
++
++    ScSetStringParam();
++};
++
++// ============================================================================
+ 
+ class ScStringUtil
+ {
+diff --git sc/inc/table.hxx sc/inc/table.hxx
+index 43163c4..7f8d968 100644
+--- sc/inc/table.hxx
++++ sc/inc/table.hxx
+@@ -85,7 +85,7 @@ struct ScLineFlags;
+ class CollatorWrapper;
+ class ScFlatBoolRowSegments;
+ class ScFlatBoolColSegments;
+-
++struct ScSetStringParam;
+ 
+ class ScTable
+ {
+@@ -274,7 +274,7 @@ public:
+     void		PutCell(SCCOL nCol, SCROW nRow, ULONG nFormatIndex, ScBaseCell* pCell);
+                 //	TRUE = Zahlformat gesetzt
+ 	BOOL		SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, 
+-                           SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true );
++                           ScSetStringParam* pParam = NULL );
+     void		SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
+     void 		SetError( SCCOL nCol, SCROW nRow, USHORT nError);
+ 
+diff --git sc/source/core/data/column3.cxx sc/source/core/data/column3.cxx
+index 56e7c1a..a37a53e 100644
+--- sc/source/core/data/column3.cxx
++++ sc/source/core/data/column3.cxx
+@@ -55,6 +55,7 @@
+ #include "detfunc.hxx"			// fuer Notizen bei DeleteRange
+ #include "postit.hxx"
+ #include "stringutil.hxx"
++#include "docpool.hxx"
+ 
+ #include <com/sun/star/i18n/LocaleDataItem.hpp>
+ 
+@@ -1263,7 +1264,7 @@ void ScColumn::StartListeningInArea( SCROW nRow1, SCROW nRow2 )
+ //	TRUE = Zahlformat gesetzt
+ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                           formula::FormulaGrammar::AddressConvention eConv,
+-                          SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
++                          ScSetStringParam* pParam )
+ {
+     BOOL bNumFmtSet = FALSE;
+     if (VALIDROW(nRow))
+@@ -1272,11 +1273,15 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+         BOOL bIsLoading = FALSE;
+         if (rString.Len() > 0)
+         {
++            ScSetStringParam aParam;
++            if (pParam)
++                aParam = *pParam;
++
+             double nVal;
+             sal_uInt32 nIndex, nOldIndex = 0;
+             sal_Unicode cFirstChar;
+-            if (!pFormatter)
+-                pFormatter = pDocument->GetFormatTable();
++            if (!aParam.mpNumFormatter)
++                aParam.mpNumFormatter = pDocument->GetFormatTable();
+             SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
+             if ( pDocSh )
+                 bIsLoading = pDocSh->IsLoading();
+@@ -1285,7 +1290,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+             {
+                 nIndex = nOldIndex = GetNumberFormat( nRow );
+                 if ( rString.Len() > 1
+-                        && pFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
++                        && aParam.mpNumFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
+                     cFirstChar = rString.GetChar(0);
+                 else
+                     cFirstChar = 0;								// Text
+@@ -1341,7 +1346,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                     }
+                     // nIndex fuer IsNumberFormat vorbelegen
+                     if ( !bIsText )
+-                        nIndex = nOldIndex = pFormatter->GetStandardIndex();
++                        nIndex = nOldIndex = aParam.mpNumFormatter->GetStandardIndex();
+                 }
+ 
+                 do
+@@ -1349,9 +1354,9 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                     if (bIsText)
+                         break;
+ 
+-                    if (bDetectNumberFormat)
++                    if (aParam.mbDetectNumberFormat)
+                     {
+-                        if (!pFormatter->IsNumberFormat(rString, nIndex, nVal))
++                        if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
+                             break;
+ 
+                         pNewCell = new ScValueCell( nVal );
+@@ -1362,21 +1367,21 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                             // Exception: If the new format is boolean, always apply it.
+ 
+                             BOOL bOverwrite = FALSE;
+-                            const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex );
++                            const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
+                             if ( pOldFormat )
+                             {
+                                 short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED;
+                                 if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE ||
+                                      nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL )
+                                 {
+-                                    if ( nOldIndex == pFormatter->GetStandardFormat(
++                                    if ( nOldIndex == aParam.mpNumFormatter->GetStandardFormat(
+                                                         nOldType, pOldFormat->GetLanguage() ) )
+                                     {
+                                         bOverwrite = TRUE;      // default of these types can be overwritten
+                                     }
+                                 }
+                             }
+-                            if ( !bOverwrite && pFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
++                            if ( !bOverwrite && aParam.mpNumFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
+                             {
+                                 bOverwrite = TRUE;              // overwrite anything if boolean was detected
+                             }
+@@ -1392,7 +1397,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                     else
+                     {
+                         // Only check if the string is a regular number.
+-                        const LocaleDataWrapper* pLocale = pFormatter->GetLocaleData();
++                        const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData();
+                         if (!pLocale)
+                             break;
+                         
+@@ -1414,7 +1419,19 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
+                 while (false);
+ 
+                 if (!pNewCell)
++                {
++                    if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
++                    {
++                        // Set the cell format type to Text.
++                        sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
++                        ScPatternAttr aNewAttrs(pDocument->GetPool());
++                        SfxItemSet& rSet = aNewAttrs.GetItemSet();
++                        rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
++                        ApplyPattern(nRow, aNewAttrs);
++                    }
++                        
+                     pNewCell = new ScStringCell(rString);
++                }
+             }
+         }
+ 
+diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
+index 3c50c24..56f2158 100644
+--- sc/source/core/data/document.cxx
++++ sc/source/core/data/document.cxx
+@@ -2512,10 +2512,10 @@ void ScDocument::PutCell( const ScAddress& rPos, ScBaseCell* pCell, BOOL bForceT
+ 
+ 
+ BOOL ScDocument::SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, 
+-                            SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
++                            ScSetStringParam* pParam )
+ {
+     if ( ValidTab(nTab) && pTab[nTab] )
+-		return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pFormatter, bDetectNumberFormat );
++		return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pParam );
+     else
+         return FALSE;
+ }
+diff --git sc/source/core/data/table2.cxx sc/source/core/data/table2.cxx
+index 9505877..6a373e9 100644
+--- sc/source/core/data/table2.cxx
++++ sc/source/core/data/table2.cxx
+@@ -904,11 +904,11 @@ void ScTable::PutCell( const ScAddress& rPos, ULONG nFormatIndex, ScBaseCell* pC
+ 
+ 
+ BOOL ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const String& rString, 
+-                         SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
++                         ScSetStringParam* pParam )
+ {
+     if (ValidColRow(nCol,nRow))
+         return aCol[nCol].SetString( 
+-            nRow, nTabP, rString, pDocument->GetAddressConvention(), pFormatter, bDetectNumberFormat );
++            nRow, nTabP, rString, pDocument->GetAddressConvention(), pParam );
+     else
+         return FALSE;
+ }
+diff --git sc/source/core/tool/stringutil.cxx sc/source/core/tool/stringutil.cxx
+index ae6247f..d5e09a6 100644
+--- sc/source/core/tool/stringutil.cxx
++++ sc/source/core/tool/stringutil.cxx
+@@ -40,6 +40,15 @@
+ using ::rtl::OUString;
+ using ::rtl::OUStringBuffer;
+ 
++ScSetStringParam::ScSetStringParam() :
++    mpNumFormatter(NULL),
++    mbDetectNumberFormat(true),
++    mbSetTextCellFormat(false)
++{
++}
++
++// ============================================================================-
++
+ bool ScStringUtil::parseSimpleNumber(
+     const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal)
+ {
+diff --git sc/source/filter/rtf/eeimpars.cxx sc/source/filter/rtf/eeimpars.cxx
+index e78e371..b25ad37 100644
+--- sc/source/filter/rtf/eeimpars.cxx
++++ sc/source/filter/rtf/eeimpars.cxx
+@@ -69,6 +69,7 @@
+ #include "drwlayer.hxx"
+ #include "rangenam.hxx"
+ #include "progress.hxx"
++#include "stringutil.hxx"
+ 
+ #include "globstr.hrc"
+ 
+@@ -331,12 +332,17 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu
+             // Daten eintragen
+             if (bSimple)
+             {
++                ScSetStringParam aParam;
++                aParam.mpNumFormatter = pFormatter;
++                aParam.mbDetectNumberFormat = true;
++                aParam.mbSetTextCellFormat = true;
++
+                 if ( aValStr.Len() )
+                     mpDoc->SetValue( nCol, nRow, nTab, fVal );
+                 else if ( !pE->aSel.HasRange() )
+                 {
+                     // maybe ALT text of IMG or similar
+-                    mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, pFormatter );
++                    mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
+                     // wenn SelRange komplett leer kann nachfolgender Text im gleichen Absatz liegen!
+                 }
+                 else
+@@ -381,7 +387,10 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu
+                     if (bNumbersEnglishUS && !bEnUsRecognized)
+                         mpDoc->PutCell( nCol, nRow, nTab, new ScStringCell( aStr));
+                     else
+-                        mpDoc->SetString( nCol, nRow, nTab, aStr, pFormatter, bConvertDate );
++                    {
++                        aParam.mbDetectNumberFormat = bConvertDate;    
++                        mpDoc->SetString( nCol, nRow, nTab, aStr, &aParam );
++                    }
+                 }
+             }
+             else
+diff --git sc/source/ui/docshell/impex.cxx sc/source/ui/docshell/impex.cxx
+index d388887..573443d 100644
+--- sc/source/ui/docshell/impex.cxx
++++ sc/source/ui/docshell/impex.cxx
+@@ -85,6 +85,9 @@ class StarBASIC;
+ 
+ // ause
+ #include "editutil.hxx"
++#include "patattr.hxx"
++#include "docpool.hxx"
++#include "stringutil.hxx"
+ 
+ #include "globstr.hrc"
+ #include <vcl/msgbox.hxx>
+@@ -804,6 +807,18 @@ static bool lcl_PutString(
+ 
+     if ( nColFormat == SC_COL_TEXT )
+     {
++        double fDummy;
++        sal_uInt32 nIndex;
++        if (pFormatter->IsNumberFormat(rStr, nIndex, fDummy))
++        {
++            // Set the format of this cell to Text.
++            sal_uInt32 nFormat = pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
++            ScPatternAttr aNewAttrs(pDoc->GetPool());
++            SfxItemSet& rSet = aNewAttrs.GetItemSet();
++            rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
++            pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs);
++
++        }
+         pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( rStr, pDoc ) );
+         return bMultiLine;
+     }
+@@ -1016,7 +1031,13 @@ static bool lcl_PutString(
+ 
+     // Standard or date not determined -> SetString / EditCell
+     if( rStr.Search( _LF ) == STRING_NOTFOUND )
+-        pDoc->SetString( nCol, nRow, nTab, rStr, pFormatter, bDetectNumFormat );
++    {
++        ScSetStringParam aParam;
++        aParam.mpNumFormatter = pFormatter;
++        aParam.mbDetectNumberFormat = bDetectNumFormat;
++        aParam.mbSetTextCellFormat = true;    
++        pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
++    }
+     else 
+     {
+         bMultiLine = true;


More information about the ooo-build-commit mailing list