[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Tue Mar 19 14:27:21 PDT 2013


 sc/inc/column.hxx                  |    2 +
 sc/inc/document.hxx                |    8 ++++++
 sc/inc/stringutil.hxx              |    2 +
 sc/inc/table.hxx                   |   16 ++++++-------
 sc/source/core/data/column2.cxx    |   10 ++++++++
 sc/source/core/data/column3.cxx    |    9 -------
 sc/source/core/data/dbdocutl.cxx   |   41 +++++++++++++++++++--------------
 sc/source/core/data/documen2.cxx   |   10 ++++++++
 sc/source/core/data/document.cxx   |   34 +++++++++++++++++++++++++++
 sc/source/core/data/table2.cxx     |   23 ++++++++++++++++++
 sc/source/core/tool/stringutil.cxx |   15 +++++++++---
 sc/source/filter/dif/difimp.cxx    |   45 +++++++++++++++++++++++--------------
 12 files changed, 161 insertions(+), 54 deletions(-)

New commits:
commit 4e8488d801f111b2c6484d040d7085ade1183515
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Mar 19 17:28:52 2013 -0400

    More on removal of direct use of cell classes outside ScDocument.
    
    Change-Id: Ie888b3494334613b5e4bcf97019b6dfbbd1a5da1

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index d8e4a38..1a1c9a4 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -428,6 +428,8 @@ public:
 
     ScFormulaVectorState GetFormulaVectorState( SCROW nRow ) const;
 
+    void SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat );
+
 private:
     const ScFormulaCell* FetchFormulaCell( SCROW nRow ) const;
 
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 91e003e..54c18ea 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -741,6 +741,8 @@ public:
     bool            TestRemoveSubTotals( SCTAB nTab, const ScSubTotalParam& rParam );
     bool            HasSubTotalCells( const ScRange& rRange );
 
+    SC_DLLPUBLIC void EnsureTable( SCTAB nTab );
+
     SC_DLLPUBLIC void           PutCell( const ScAddress&, ScBaseCell* pCell, bool bForceTab = false );
     SC_DLLPUBLIC void           PutCell( SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell* pCell,
                             bool bForceTab = false );
@@ -763,7 +765,12 @@ public:
      */
     SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, EditTextObject* pEditText );
 
+    SC_DLLPUBLIC void SetEditText( const ScAddress& rPos, const OUString& rStr );
+
+    void SetEmptyCell( const ScAddress& rPos );
+
     SC_DLLPUBLIC void           SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal );
+    SC_DLLPUBLIC void SetValue( const ScAddress& rPos, double fVal );
     void            SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError);
 
     SC_DLLPUBLIC void           InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
@@ -790,6 +797,7 @@ public:
                                      sal_uInt32& rFormat ) const;
     sal_uInt32      GetNumberFormat( const ScRange& rRange ) const;
     SC_DLLPUBLIC sal_uInt32     GetNumberFormat( const ScAddress& ) const;
+    void SetNumberFormat( const ScAddress& rPos, sal_uInt32 nNumberFormat );
                     /** If no number format attribute is set and the cell
                         pointer passed is of type formula cell, the calculated
                         number format of the formula cell is returned. pCell
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index 988dea2..a210d5b 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -109,6 +109,8 @@ public:
     static sal_Int32 SC_DLLPUBLIC GetQuotedTokenCount(const OUString &rIn, const OUString& rQuotedPairs, sal_Unicode cTok = ';' );
     static OUString  SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString& rQuotedPairs,
                                         sal_Unicode cTok,  sal_Int32& rIndex );
+
+    static bool SC_DLLPUBLIC isMultiline( const OUString& rStr );
 };
 
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 990b0fc..98ca220 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -305,6 +305,8 @@ public:
 
     void SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText );
 
+    void SetEmptyCell( SCCOL nCol, SCROW nRow );
+
     void        SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
     void        SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError);
 
@@ -509,14 +511,12 @@ public:
     const ScPatternAttr*    GetPattern( SCCOL nCol, SCROW nRow ) const;
     const ScPatternAttr*    GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
 
-    sal_uLong                   GetNumberFormat( const ScAddress& rPos ) const
-                                {
-                                    return ValidColRow(rPos.Col(),rPos.Row()) ?
-                                        aCol[rPos.Col()].GetNumberFormat( rPos.Row() ) :
-                                        0;
-                                }
-    sal_uLong                   GetNumberFormat( SCCOL nCol, SCROW nRow ) const;
-    sal_uInt32              GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
+    sal_uInt32 GetNumberFormat( const ScAddress& rPos ) const;
+    sal_uInt32 GetNumberFormat( SCCOL nCol, SCROW nRow ) const;
+    sal_uInt32 GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
+
+    void SetNumberFormat( SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat );
+
     void                    MergeSelectionPattern( ScMergePatternState& rState,
                                                 const ScMarkData& rMark, bool bDeep ) const;
     void                    MergePatternArea( ScMergePatternState& rState, SCCOL nCol1, SCROW nRow1,
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 17d951d..e2792de 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1537,6 +1537,16 @@ ScFormulaVectorState ScColumn::GetFormulaVectorState( SCROW nRow ) const
     return pCell ? pCell->GetVectorState() : FormulaVectorUnknown;
 }
 
+void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat )
+{
+    short eOldType = pDocument->GetFormatTable()->GetType(
+        (sal_uLong)((SfxUInt32Item*)GetAttr(nRow, ATTR_VALUE_FORMAT))->GetValue());
+
+    short eNewType = pDocument->GetFormatTable()->GetType(nNumberFormat);
+    if (!pDocument->GetFormatTable()->IsCompatible(eOldType, eNewType))
+        ApplyAttr(nRow, SfxUInt32Item(ATTR_VALUE_FORMAT, nNumberFormat));
+}
+
 const ScFormulaCell* ScColumn::FetchFormulaCell( SCROW nRow ) const
 {
     if (!ValidRow(nRow))
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index c4c4ec6..36689bf 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -129,14 +129,7 @@ void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
 void ScColumn::Insert( SCROW nRow, sal_uInt32 nNumberFormat, ScBaseCell* pCell )
 {
     Insert(nRow, pCell);
-    short eOldType = pDocument->GetFormatTable()->
-                        GetType( (sal_uLong)
-                            ((SfxUInt32Item*)GetAttr( nRow, ATTR_VALUE_FORMAT ))->
-                                GetValue() );
-    short eNewType = pDocument->GetFormatTable()->GetType(nNumberFormat);
-    if (!pDocument->GetFormatTable()->IsCompatible(eOldType, eNewType))
-        ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT, (sal_uInt32) nNumberFormat) );
-
+    SetNumberFormat(nRow, nNumberFormat);
     bDirtyGroups = true;
 }
 
diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx
index 1516996..167290b 100644
--- a/sc/source/core/data/dbdocutl.cxx
+++ b/sc/source/core/data/dbdocutl.cxx
@@ -24,8 +24,8 @@
 
 #include "dbdocutl.hxx"
 #include "document.hxx"
-#include "cell.hxx"
 #include "formula/errorcodes.hxx"
+#include "stringutil.hxx"
 
 using namespace ::com::sun::star;
 
@@ -153,38 +153,45 @@ void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB
         nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
                             NUMBERFORMAT_CURRENCY, ScGlobal::eLnge );
 
-    ScBaseCell* pCell;
+    ScAddress aPos(nCol, nRow, nTab);
     if (bEmptyFlag)
-    {
-        pCell = NULL;
-        pDoc->PutCell( nCol, nRow, nTab, pCell );
-    }
+        pDoc->SetEmptyCell(aPos);
     else if (bError)
     {
         pDoc->SetError( nCol, nRow, nTab, NOTAVAILABLE );
     }
     else if (bValue)
     {
-        pCell = new ScValueCell( nVal );
-        if (nFormatIndex == 0)
-            pDoc->PutCell( nCol, nRow, nTab, pCell );
-        else
-            pDoc->PutCell( nCol, nRow, nTab, pCell, nFormatIndex );
+        pDoc->SetValue(aPos, nVal);
+        if (nFormatIndex)
+            pDoc->SetNumberFormat(aPos, nFormatIndex);
     }
     else
     {
         if (aString.Len())
         {
-            pCell = ScBaseCell::CreateTextCell( aString, pDoc );
-            if (pStrData)
+            if (ScStringUtil::isMultiline(aString))
             {
-                pStrData->mbSimpleText = pCell->GetCellType() != CELLTYPE_EDIT;
-                pStrData->mnStrLength = aString.Len();
+                pDoc->SetEditText(aPos, aString);
+                if (pStrData)
+                    pStrData->mbSimpleText = false;
             }
+            else
+            {
+                ScSetStringParam aParam;
+                aParam.mbDetectNumberFormat = false;
+                aParam.mbHandleApostrophe = false;
+                aParam.meSetTextNumFormat = ScSetStringParam::Always;
+                pDoc->SetString(aPos, aString, &aParam);
+                if (pStrData)
+                    pStrData->mbSimpleText = true;
+            }
+
+            if (pStrData)
+                pStrData->mnStrLength = aString.Len();
         }
         else
-            pCell = NULL;
-        pDoc->PutCell( nCol, nRow, nTab, pCell );
+            pDoc->SetEmptyCell(aPos);
     }
 }
 
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 64eb25a..bc681ba 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -574,6 +574,16 @@ void ScDocument::ResetClip( ScDocument* pSourceDoc, SCTAB nTab )
     }
 }
 
+void ScDocument::EnsureTable( SCTAB nTab )
+{
+    bool bExtras = !bIsUndo;        // Spaltenbreiten, Zeilenhoehen, Flags
+    if (static_cast<size_t>(nTab) >= maTabs.size())
+        maTabs.resize(nTab+1, NULL);
+
+    if (!maTabs[nTab])
+        maTabs[nTab] = new ScTable(this, nTab, "temp", bExtras, bExtras);
+}
+
 void ScDocument::PutCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
                           ScBaseCell* pCell, sal_uLong nFormatIndex, bool bForceTab )
 {
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 71f4a1f..455178a 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -86,6 +86,7 @@
 #include "clipparam.hxx"
 #include "stlalgorithm.hxx"
 #include "defaultsoptions.hxx"
+#include "editutil.hxx"
 
 #include <map>
 #include <limits>
@@ -2979,6 +2980,24 @@ void ScDocument::SetEditText( const ScAddress& rPos, EditTextObject* pEditText )
     maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), pEditText);
 }
 
+void ScDocument::SetEditText( const ScAddress& rPos, const OUString& rStr )
+{
+    if (!TableExists(rPos.Tab()))
+        return;
+
+    ScFieldEditEngine& rEngine = GetEditEngine();
+    rEngine.SetText(rStr);
+    maTabs[rPos.Tab()]->SetEditText(rPos.Col(), rPos.Row(), rEngine.CreateTextObject());
+}
+
+void ScDocument::SetEmptyCell( const ScAddress& rPos )
+{
+    if (!TableExists(rPos.Tab()))
+        return;
+
+    maTabs[rPos.Tab()]->SetEmptyCell(rPos.Col(), rPos.Row());
+}
+
 void ScDocument::SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
@@ -2986,6 +3005,14 @@ void ScDocument::SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVa
             maTabs[nTab]->SetValue( nCol, nRow, rVal );
 }
 
+void ScDocument::SetValue( const ScAddress& rPos, double fVal )
+{
+    if (!TableExists(rPos.Tab()))
+        return;
+
+    maTabs[rPos.Tab()]->SetValue(rPos.Col(), rPos.Row(), fVal);
+}
+
 OUString ScDocument::GetString( SCCOL nCol, SCROW nRow, SCTAB nTab )
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
@@ -3140,6 +3167,13 @@ sal_uInt32 ScDocument::GetNumberFormat( const ScAddress& rPos ) const
     return 0;
 }
 
+void ScDocument::SetNumberFormat( const ScAddress& rPos, sal_uInt32 nNumberFormat )
+{
+    if (!TableExists(rPos.Tab()))
+        return;
+
+    maTabs[rPos.Tab()]->SetNumberFormat(rPos.Col(), rPos.Row(), nNumberFormat);
+}
 
 void ScDocument::GetNumberFormatInfo( short& nType, sal_uLong& nIndex,
             const ScAddress& rPos, const ScBaseCell* pCell ) const
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 015fa67..80cc8cb 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1334,6 +1334,14 @@ void ScTable::SetEditText( SCCOL nCol, SCROW nRow, EditTextObject* pEditText )
     aCol[nCol].SetEditText(nRow, pEditText);
 }
 
+void ScTable::SetEmptyCell( SCCOL nCol, SCROW nRow )
+{
+    if (!ValidColRow(nCol, nRow))
+        return;
+
+    aCol[nCol].Delete(nRow);
+}
+
 void ScTable::SetValue( SCCOL nCol, SCROW nRow, const double& rVal )
 {
     if (ValidColRow(nCol, nRow))
@@ -1615,8 +1623,14 @@ const SfxPoolItem* ScTable::GetAttr( SCCOL nCol, SCROW nRow, sal_uInt16 nWhich )
         return NULL;
 }
 
+sal_uInt32 ScTable::GetNumberFormat( const ScAddress& rPos ) const
+{
+    return ValidColRow(rPos.Col(),rPos.Row()) ?
+        aCol[rPos.Col()].GetNumberFormat( rPos.Row() ) :
+        0;
+}
 
-sal_uLong ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
+sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
 {
     if (ValidColRow(nCol,nRow))
         return aCol[nCol].GetNumberFormat( nRow );
@@ -1632,6 +1646,13 @@ sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow
     return aCol[nCol].GetNumberFormat(nStartRow, nEndRow);
 }
 
+void ScTable::SetNumberFormat( SCCOL nCol, SCROW nRow, sal_uInt32 nNumberFormat )
+{
+    if (!ValidColRow(nCol, nRow))
+        return;
+
+    aCol[nCol].SetNumberFormat(nRow, nNumberFormat);
+}
 
 const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
 {
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 14ea674..8924eca 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -20,9 +20,7 @@
 #include "stringutil.hxx"
 #include "rtl/ustrbuf.hxx"
 #include "rtl/math.hxx"
-
-using ::rtl::OUString;
-using ::rtl::OUStringBuffer;
+#include "global.hxx"
 
 ScSetStringParam::ScSetStringParam() :
     mpNumFormatter(NULL),
@@ -310,4 +308,15 @@ OUString ScStringUtil::GetQuotedToken(const OUString &rIn, sal_Int32 nToken, con
     }
 }
 
+bool ScStringUtil::isMultiline( const OUString& rStr )
+{
+    if (rStr.indexOf('\n') != -1)
+        return true;
+
+    if (rStr.indexOf(CHAR_CR) != -1)
+        return true;
+
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index a6864c7..63987e7 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -23,7 +23,6 @@
 #include <svl/zforlist.hxx>
 
 #include "attrib.hxx"
-#include "cell.hxx"
 #include "dif.hxx"
 #include "docpool.hxx"
 #include "document.hxx"
@@ -33,6 +32,7 @@
 #include "patattr.hxx"
 #include "scerrors.hxx"
 #include "scitems.hxx"
+#include "stringutil.hxx"
 
 const sal_Unicode pKeyTABLE[]   = { 'T', 'A', 'B', 'L', 'E', 0 };
 const sal_Unicode pKeyVECTORS[] = { 'V', 'E', 'C', 'T', 'O', 'R', 'S', 0 };
@@ -53,16 +53,16 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
 {
     DifParser   aDifParser( rIn, nDifOption, *pDoc, eVon );
 
-    const sal_Bool  bPlain = aDifParser.IsPlain();
+    const bool bPlain = aDifParser.IsPlain();
 
     SCTAB       nBaseTab = rInsPos.Tab();
 
     TOPIC       eTopic = T_UNKNOWN;
-    sal_Bool        bSyntErrWarn = false;
-    sal_Bool        bOverflowWarn = false;
+    bool        bSyntErrWarn = false;
+    bool        bOverflowWarn = false;
 
     rtl::OUString   aData = aDifParser.aData;
-    sal_Bool        bData = false;
+    bool        bData = false;
 
     rIn.Seek( 0 );
 
@@ -133,14 +133,20 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
 
         DATASET             eAkt = D_UNKNOWN;
 
+        ScSetStringParam aStrParam; // used to set string value without number detection.
+        aStrParam.mbDetectNumberFormat = false;
+        aStrParam.mbHandleApostrophe = false;
+        aStrParam.meSetTextNumFormat = ScSetStringParam::Always;
+
         while( eAkt != D_EOD )
-            {
+        {
             eAkt = aDifParser.GetNextDataset();
 
             aPrgrsBar.Progress();
+            ScAddress aPos(nColCnt, nRowCnt, nBaseTab);
 
             switch( eAkt )
-                {
+            {
                 case D_BOT:
                     if( nColCnt < SCCOL_MAX )
                         nRowCnt++;
@@ -154,17 +160,18 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
 
                     if( ValidCol(nColCnt) && ValidRow(nRowCnt) )
                     {
-                        ScBaseCell*     pCell;
+                        pDoc->EnsureTable(nBaseTab);
+
                         if( DifParser::IsV( aData.getStr() ) )
                         {
-                            pCell = new ScValueCell( aDifParser.fVal );
+                            pDoc->SetValue(aPos, aDifParser.fVal);
                             if( !bPlain )
                                 aAttrCache.SetNumFormat( nColCnt, nRowCnt,
                                     aDifParser.nNumFormat );
                         }
                         else if( aData == pKeyTRUE || aData == pKeyFALSE )
                         {
-                            pCell = new ScValueCell( aDifParser.fVal );
+                            pDoc->SetValue(aPos, aDifParser.fVal);
                             if( bPlain )
                                 aAttrCache.SetLogical( nColCnt, nRowCnt );
                             else
@@ -172,19 +179,19 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
                                     aDifParser.nNumFormat );
                         }
                         else if( aData == pKeyNA || aData == pKeyERROR  )
-                            pCell = new ScStringCell( aData );
+                        {
+                            pDoc->SetString(aPos, aData, &aStrParam);
+                        }
                         else
                         {
                             String aTmp( RTL_CONSTASCII_USTRINGPARAM( "#IND: " ));
                             aTmp += aData;
                             aTmp += sal_Unicode('?');
-                            pCell = new ScStringCell( aTmp );
+                            pDoc->SetString(aPos, aTmp, &aStrParam);
                         }
-
-                        pDoc->PutCell( nColCnt, nRowCnt, nBaseTab, pCell, true );
                     }
                     else
-                        bOverflowWarn = sal_True;
+                        bOverflowWarn = true;
 
                     nColCnt++;
                     break;
@@ -196,8 +203,12 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
                     {
                         if (!aData.isEmpty())
                         {
-                            pDoc->PutCell( nColCnt, nRowCnt, nBaseTab,
-                                ScBaseCell::CreateTextCell( aData, pDoc ), true );
+                            pDoc->EnsureTable(nBaseTab);
+
+                            if (ScStringUtil::isMultiline(aData))
+                                pDoc->SetEditText(aPos, aData);
+                            else
+                                pDoc->SetString(aPos, aData, &aStrParam);
                         }
                     }
                     else


More information about the Libreoffice-commits mailing list