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

Kohei Yoshida kohei.yoshida at gmail.com
Tue Mar 12 13:00:56 PDT 2013


 sc/inc/column.hxx               |   15 ++++++++-
 sc/source/core/data/column.cxx  |   63 ++++++++++++++++++++++++++++++++++++----
 sc/source/core/data/column2.cxx |    4 ++
 sc/source/core/data/column3.cxx |   16 ++++++++++
 4 files changed, 91 insertions(+), 7 deletions(-)

New commits:
commit 0713b97ea4031233984f24ad6a56b91fd09d4fe6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 22:08:42 2012 -0500

    Add accessor methods for text widths using mdds::multi_type_vector.
    
    We only use unsigned short and empty types in this container.  Empty type
    represents empty cells whereas unsigned short type represents non-empty
    cells.
    
    Change-Id: Id9b6e0941fdfabc48fc8bb2aa6479f466270381c

diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ce5823e..1226f9b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -36,6 +36,8 @@
 
 #include <cstring>
 #include <map>
+#include <mdds/multi_type_vector.hpp>
+#include <mdds/multi_type_vector_trait.hpp>
 
 using ::editeng::SvxBorderLine;
 using namespace formula;
@@ -55,6 +57,11 @@ inline bool IsAmbiguousScriptNonZero( sal_uInt8 nScript )
 
 struct ScColumnImpl
 {
+    typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
+
+    TextWidthType maTextWidths;
+
+    ScColumnImpl() : maTextWidths(MAXROWCOUNT) {}
 };
 
 ScNeededSizeOptions::ScNeededSizeOptions() :
@@ -2287,5 +2294,22 @@ bool ScColumn::SearchStyleRange(
         return pAttrArray->SearchStyleRange( rRow, rEndRow, pSearchStyle, bUp, NULL );
 }
 
+sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
+{
+    switch (mpImpl->maTextWidths.get_type(nRow))
+    {
+        case mdds::mtv::element_type_ushort:
+            return mpImpl->maTextWidths.get<unsigned short>(nRow);
+        default:
+            ;
+    }
+    return TEXTWIDTH_DIRTY;
+}
+
+void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
+{
+    // We only use unsigned short type in this container.
+    mpImpl->maTextWidths.set(nRow, static_cast<unsigned short>(nWidth));
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 71881b4..c43320a 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1952,13 +1952,4 @@ xub_StrLen ScColumn::GetMaxNumberStringLen(
     return nStringLen;
 }
 
-sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
-{
-    return 0;
-}
-
-void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
-{
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 289d3beef83f3c651e29633557d5ec7eccd6bb42
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 19:17:19 2012 -0500

    Re-order the header includes. Make sure column.hxx comes first.
    
    Change-Id: I9f93724c4e0b565a9148d0893feda9e82109bff7

diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 5ae9b8a..ce5823e 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -30,6 +30,13 @@
 #include "detfunc.hxx"          // for Notes in Sort/Swap
 #include "postit.hxx"
 
+#include <svl/poolcach.hxx>
+#include <svl/zforlist.hxx>
+#include <editeng/scripttypeitem.hxx>
+
+#include <cstring>
+#include <map>
+
 using ::editeng::SvxBorderLine;
 using namespace formula;
 
commit 7c15b4fad26210e3d7fddaeef8f7096f17a2f74b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 19:15:11 2012 -0500

    Let's start using impl class for ScColumn.
    
    No need to migrate the existing data members to it for now, but let's
    define new members in the impl class from now on.
    
    Change-Id: Idee66dae87beb4bb6efc9c7d7ffd658148ed887c

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 8653bfd..39f9753 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -58,6 +58,7 @@ struct ScMergePatternState;
 class ScFlatBoolRowSegments;
 struct ScSetStringParam;
 struct ScColWidthParam;
+struct ScColumnImpl;
 
 struct ScNeededSizeOptions
 {
@@ -79,6 +80,8 @@ struct ColEntry
 class ScColumn
 {
 private:
+    ScColumnImpl* mpImpl;
+
     SCCOL           nCol;
     SCTAB           nTab;
 
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index d5d73c4..5ae9b8a 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -30,16 +30,11 @@
 #include "detfunc.hxx"          // for Notes in Sort/Swap
 #include "postit.hxx"
 
-#include <svl/poolcach.hxx>
-#include <svl/zforlist.hxx>
-#include <editeng/scripttypeitem.hxx>
-
-#include <cstring>
-#include <map>
-
 using ::editeng::SvxBorderLine;
 using namespace formula;
 
+namespace {
+
 inline bool IsAmbiguousScriptNonZero( sal_uInt8 nScript )
 {
     //! move to a header file
@@ -49,12 +44,19 @@ inline bool IsAmbiguousScriptNonZero( sal_uInt8 nScript )
              nScript != 0 );
 }
 
+}
+
+struct ScColumnImpl
+{
+};
+
 ScNeededSizeOptions::ScNeededSizeOptions() :
     pPattern(NULL), bFormula(false), bSkipMerged(true), bGetFont(true), bTotalSize(false)
 {
 }
 
 ScColumn::ScColumn() :
+    mpImpl(new ScColumnImpl),
     nCol( 0 ),
     pAttrArray( NULL ),
     pDocument( NULL )
commit 2f232849c33eb681339c67858c083e71db914ea4
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 17:14:54 2012 -0500

    Add empty GetTextWidth() to ScColumn. Will be implemented later.
    
    Change-Id: I4df0719fee426ab5d54bfc2ac8fa4c37325906e2

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 257cb0e..8653bfd 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -371,6 +371,7 @@ public:
     xub_StrLen  GetMaxNumberStringLen( sal_uInt16& nPrecision,
                                        SCROW nRowStart, SCROW nRowEnd ) const;
 
+    sal_uInt16 GetTextWidth(SCROW nRow) const;
     void SetTextWidth(SCROW nRow, sal_uInt16 nWidth);
 
 private:
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 42472e0..71881b4 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1952,6 +1952,11 @@ xub_StrLen ScColumn::GetMaxNumberStringLen(
     return nStringLen;
 }
 
+sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
+{
+    return 0;
+}
+
 void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
 {
 }
commit 62765aca30de652aa3792fe8342eea2d3b466026
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 16:13:37 2012 -0500

    Identify all places that modify the cell array & call CellStorageModified().
    
    CellStorageModified() is empty at the moment.
    
    Change-Id: I9498b4d7819bba1778cbab644e7b46ce25d66ae4

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 6c8e0e0..257cb0e 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -371,6 +371,8 @@ public:
     xub_StrLen  GetMaxNumberStringLen( sal_uInt16& nPrecision,
                                        SCROW nRowStart, SCROW nRowEnd ) const;
 
+    void SetTextWidth(SCROW nRow, sal_uInt16 nWidth);
+
 private:
     ScBaseCell* CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos) const;
 
@@ -378,8 +380,10 @@ private:
     SCROW FindNextVisibleRow(SCROW nRow, bool bForward) const;
 
     /**
-     * Called whenever the state of cell array gets modified i.e. a new cell
-     * is inserted, a cell is moved or removed, cells are swapped, and so on.
+     * Called whenever the state of cell array gets modified i.e. new cell
+     * insertion, cell removal or relocation, cell value update and so on.
+     *
+     * Call this only from those methods where maItems is modified directly.
      */
     void CellStorageModified();
 };
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ac5f1d5..d5d73c4 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -793,14 +793,14 @@ void lclTakeBroadcaster( ScBaseCell*& rpCell, SvtBroadcaster* pBC )
 //  SwapRow for sorting
 void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
 {
+    if (nRow1 == nRow2)
+        // Nothing to swap.
+        return;
+
     /*  Simple swap of cell pointers does not work if broadcasters exist (crash
         if cell broadcasts directly or indirectly to itself). While swapping
         the cells, broadcasters have to remain at old positions! */
 
-    /*  While cloning cells, do not clone notes, but move note pointers to new
-        cells. This prevents creation of new caption drawing objects for every
-        swap operation while sorting. */
-
     ScBaseCell* pCell1 = 0;
     SCSIZE nIndex1;
     if ( Search( nRow1, nIndex1 ) )
@@ -850,6 +850,8 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
             SvtBroadcaster* pBC2 = pCell2->ReleaseBroadcaster();
             pCell1->TakeBroadcaster( pBC2 );
             pCell2->TakeBroadcaster( pBC1 );
+
+            CellStorageModified();
         }
         else
         {
@@ -858,11 +860,13 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
             {
                 // insert dummy note cell (without note) containing old broadcaster
                 maItems[nIndex1].pCell = pDummyCell;
+                CellStorageModified();
             }
             else
             {
                 // remove ColEntry at old position
                 maItems.erase( maItems.begin() + nIndex1 );
+                CellStorageModified();
             }
 
             // insert ColEntry at new position
@@ -910,8 +914,7 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
     }
 
     /*  Create clone of pCell1 at position of pCell2 (pCell1 exists always, see
-        variable swapping above). Do not clone the note, but move pointer of
-        old note to new cell. */
+        variable swapping above).*/
     ScBaseCell* pNew2 = pCell1->Clone( *pDocument, aPos2, SC_CLONECELL_ADJUST3DREL );
 
     /*  Create clone of pCell2 at position of pCell1. Do not clone the note,
@@ -971,7 +974,10 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
     {
         // swap
         maItems[nIndex1].pCell = pCell2;
+        CellStorageModified();
         rCol.maItems[nIndex2].pCell = pCell1;
+        rCol.CellStorageModified();
+
         // update references
         SCsCOL dx = rCol.nCol - nCol;
         if ( pFmlaCell1 )
@@ -993,6 +999,8 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
     {
         // remove
         maItems.erase(maItems.begin() + nIndex1);
+        CellStorageModified();
+
         // update references
         SCsCOL dx = rCol.nCol - nCol;
         if ( pFmlaCell1 )
@@ -1148,6 +1156,8 @@ void ScColumn::InsertRow( SCROW nStartRow, SCSIZE nSize )
     }
 
     pDocument->SetAutoCalc( bOldAutoCalc );
+
+    CellStorageModified();
 }
 
 
@@ -1545,6 +1555,8 @@ void ScColumn::MarkScenarioIn( ScMarkData& rDestMark ) const
 void ScColumn::SwapCol(ScColumn& rCol)
 {
     maItems.swap(rCol.maItems);
+    CellStorageModified();
+    rCol.CellStorageModified();
 
     ScAttrArray* pTempAttr = rCol.pAttrArray;
     rCol.pAttrArray = pAttrArray;
@@ -1637,9 +1649,11 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
             }
             // Erase the slots containing pointers to the dummy cell instance.
             maItems.erase(maItems.begin() + nStartPos, maItems.begin() + nStopPos);
+            CellStorageModified();
         }
         pNoteCell->Delete(); // Delete the dummy cell instance.
     }
+
 }
 
 bool ScColumn::UpdateReference( UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
@@ -1780,6 +1794,7 @@ void ScColumn::UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets)
             {
                 ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
                 p->UpdateFields(nTab);
+                SetTextWidth(maItems[i].nRow, TEXTWIDTH_DIRTY);
             }
             break;
             default:
@@ -1810,6 +1825,7 @@ void ScColumn::UpdateInsertTabAbs(SCTAB nNewPos)
             {
                 ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
                 p->UpdateFields(nTab);
+                SetTextWidth(maItems[i].nRow, TEXTWIDTH_DIRTY);
             }
             break;
             default:
@@ -1859,6 +1875,7 @@ void ScColumn::UpdateDeleteTab(SCTAB nDelPos, bool bIsMove, ScColumn* pRefUndo,
             {
                 ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
                 p->UpdateFields(nTab);
+                SetTextWidth(maItems[i].nRow, TEXTWIDTH_DIRTY);
             }
             break;
             default:
@@ -1891,6 +1908,7 @@ void ScColumn::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo )
             {
                 ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
                 p->UpdateFields(nTab);
+                SetTextWidth(maItems[i].nRow, TEXTWIDTH_DIRTY);
             }
             break;
             default:
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 6fb54e6..42472e0 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -87,12 +87,14 @@ void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
             }
             pOldCell->Delete();
             maItems[nIndex].pCell = pNewCell;
+            CellStorageModified();
         }
         else
         {
             maItems.insert(maItems.begin() + nIndex, ColEntry());
             maItems[nIndex].pCell = pNewCell;
             maItems[nIndex].nRow  = nRow;
+            CellStorageModified();
         }
     }
     // When we insert from the Clipboard we still have wrong (old) References!
@@ -136,6 +138,8 @@ void ScColumn::Append( SCROW nRow, ScBaseCell* pCell )
     maItems.push_back(ColEntry());
     maItems.back().pCell = pCell;
     maItems.back().nRow  = nRow;
+
+    CellStorageModified();
 }
 
 
@@ -162,6 +166,8 @@ void ScColumn::Delete( SCROW nRow )
         }
         pCell->EndListeningTo( pDocument );
         pCell->Delete();
+
+        CellStorageModified();
     }
 }
 
@@ -177,6 +183,8 @@ void ScColumn::DeleteAtIndex( SCSIZE nIndex )
     maItems.erase(maItems.begin() + nIndex);
     pCell->EndListeningTo( pDocument );
     pCell->Delete();
+
+    CellStorageModified();
 }
 
 
@@ -185,6 +193,8 @@ void ScColumn::FreeAll()
     for (SCSIZE i = 0; i < maItems.size(); i++)
         maItems[i].pCell->Delete();
     maItems.clear();
+
+    CellStorageModified();
 }
 
 
@@ -480,6 +490,7 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
         if (bRemoved)
             nShift += maItems.size() - nStartSegment;
         maItems.erase(maItems.end() - nShift, maItems.end());
+        CellStorageModified();
     }
 
     // *** delete all formula cells ***
@@ -1403,8 +1414,11 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
                     if ( i >= maItems.size() || maItems[i].nRow != nRow )
                         Search(nRow, i);
                 }
+
                 pOldCell->Delete();
                 maItems[i].pCell = pNewCell; // Replace
+                CellStorageModified();
+
                 if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
                 {
                     pNewCell->StartListeningTo( pDocument );
@@ -1626,6 +1640,8 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
                         maItems[nIndex].pCell = new ScStringCell( aString );
                     }
                     delete pFormula;
+
+                    CellStorageModified();
                 }
                 ++nIndex;
             }
@@ -1936,4 +1952,8 @@ xub_StrLen ScColumn::GetMaxNumberStringLen(
     return nStringLen;
 }
 
+void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
+{
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 6662fb5216479af3209bed2a49c1d28d9b02ffe2
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Nov 6 13:53:57 2012 -0500

    Redundant use of 'public' modifier.
    
    Plus added a new method that will get called whenever cell array
    state changes.  It's not used yet.
    
    Change-Id: I96719db0460bfb72d8dbe98a80a3880d8f279c33

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 35316cd..6c8e0e0 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -342,7 +342,6 @@ public:
         SCROW nStartRow, SCROW nEndRow, sal_uInt16* pHeight, OutputDevice* pDev,
         double nPPTX, double nPPTY, const Fraction& rZoomX, const Fraction& rZoomY,
         bool bShrink, sal_uInt16 nMinHeight, SCROW nMinStart) const;
-public:
 
                 /// Including current, may return -1
     SCsROW      GetNextUnprotected( SCROW nRow, bool bUp ) const;
@@ -377,6 +376,12 @@ private:
 
     SCROW FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const;
     SCROW FindNextVisibleRow(SCROW nRow, bool bForward) const;
+
+    /**
+     * Called whenever the state of cell array gets modified i.e. a new cell
+     * is inserted, a cell is moved or removed, cells are swapped, and so on.
+     */
+    void CellStorageModified();
 };
 
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 791ca24..91ddbb1 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1382,6 +1382,10 @@ SCROW ScColumn::FindNextVisibleRowWithContent(SCROW nRow, bool bForward) const
     }
 }
 
+void ScColumn::CellStorageModified()
+{
+}
+
 void ScColumn::FindDataAreaPos(SCROW& rRow, bool bDown) const
 {
     // check if we are in a data area


More information about the Libreoffice-commits mailing list