[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter' - 4 commits - sc/inc sc/Library_sc.mk sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Fri May 10 09:52:26 PDT 2013


 sc/Library_sc.mk                       |    1 
 sc/inc/cell.hxx                        |    4 -
 sc/inc/column.hxx                      |   27 +++++------
 sc/inc/columniterator.hxx              |   12 ++---
 sc/inc/globalnames.hxx                 |    4 +
 sc/inc/mtvblockfunc.hxx                |   35 --------------
 sc/inc/mtvelements.hxx                 |   50 ++++++++++++++++++++
 sc/source/core/data/column.cxx         |   79 +++++++--------------------------
 sc/source/core/data/column2.cxx        |   60 +++++++++++++++----------
 sc/source/core/data/column3.cxx        |   74 ++++++++++++++++++------------
 sc/source/core/data/columniterator.cxx |   28 +++++------
 sc/source/core/data/documen6.cxx       |    1 
 sc/source/core/data/documentimport.cxx |    8 ---
 sc/source/core/data/mtvelements.cxx    |   29 ++++++++++++
 14 files changed, 218 insertions(+), 194 deletions(-)

New commits:
commit e036aa88437e8c2ddc2da874fe6a6fdab22672de
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri May 10 12:47:19 2013 -0400

    Broadcast only on deleted cells that were previously non-empty.
    
    Change-Id: I87e9cffcb50f879b699fe8df141281fdc6d2dbae

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index a76fd86..1fe28909 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -474,7 +474,8 @@ public:
     const SvtBroadcaster* GetBroadcaster( SCROW nRow ) const;
 
 private:
-    void DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag );
+    void DeleteRange(
+        SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag, std::vector<SCROW>& rDeletedRows );
 
     const ScFormulaCell* FetchFormulaCell( SCROW nRow ) const;
 
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 0b1571c..dc26882 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -61,6 +61,22 @@ extern const ScFormulaCell* pLastFormulaTreeTop; // in cellform.cxx
 using namespace formula;
 // STATIC DATA -----------------------------------------------------------
 
+namespace {
+
+void broadcastCells(ScDocument& rDoc, SCCOL nCol, SCROW nTab, const std::vector<SCROW>& rRows)
+{
+    // Broadcast the changes.
+    ScHint aHint(SC_HINT_DATACHANGED, ScAddress(nCol, 0, nTab));
+    std::vector<SCROW>::const_iterator itRow = rRows.begin(), itRowEnd = rRows.end();
+    for (; itRow != itRowEnd; ++itRow)
+    {
+        aHint.GetAddress().SetRow(*itRow);
+        rDoc.Broadcast(aHint);
+    }
+}
+
+}
+
 void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
 {
     SetCell(nRow, pNewCell);
@@ -195,7 +211,10 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize )
 
     if (bFound)
     {
-        DeleteRange( nStartIndex, nEndIndex, IDF_CONTENTS );
+        std::vector<SCROW> aDeletedRows;
+        DeleteRange(nStartIndex, nEndIndex, IDF_CONTENTS, aDeletedRows);
+        broadcastCells(*pDocument, nCol, nTab, aDeletedRows);
+
         Search( nStartRow, i );
         if ( i >= maItems.size() )
         {
@@ -303,7 +322,8 @@ bool checkDeleteCellByFlag(
 
 }
 
-void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag )
+void ScColumn::DeleteRange(
+    SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag, std::vector<SCROW>& rDeletedRows )
 {
     /*  If caller specifies to not remove the note caption objects, all cells
         have to forget the pointers to them. This is used e.g. while undoing a
@@ -326,6 +346,8 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
             // all content is to be deleted.
 
             ScBaseCell* pOldCell = maItems[ nIdx ].pCell;
+            rDeletedRows.push_back(maItems[nIdx].nRow);
+
             if (pOldCell->GetCellType() == CELLTYPE_FORMULA)
             {
                 // cache formula cell, will be deleted below
@@ -361,6 +383,8 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
             }
             else
                 pOldCell->Delete();
+
+            rDeletedRows.push_back(maItems[nIdx].nRow);
         }
 
         if (!bDelete)
@@ -428,7 +452,6 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
     }
 }
 
-
 void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag)
 {
     //  FreeAll must not be called here due to Broadcasters
@@ -440,10 +463,14 @@ void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag)
         nContMask |= IDF_NOCAPTIONS;
     sal_uInt16 nContFlag = nDelFlag & nContMask;
 
+    std::vector<SCROW> aDeletedRows;
+
     if ( !maItems.empty() && nContFlag)
     {
         if (nStartRow==0 && nEndRow==MAXROW)
-            DeleteRange( 0, maItems.size()-1, nContFlag );
+        {
+            DeleteRange(0, maItems.size()-1, nContFlag, aDeletedRows);
+        }
         else
         {
             sal_Bool bFound=false;
@@ -460,7 +487,7 @@ void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag)
                     nEndIndex = i;
                 }
             if (bFound)
-                DeleteRange( nStartIndex, nEndIndex, nContFlag );
+                DeleteRange(nStartIndex, nEndIndex, nContFlag, aDeletedRows);
         }
     }
 
@@ -476,13 +503,9 @@ void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag)
     else if ((nDelFlag & IDF_ATTRIB) != 0)
         pAttrArray->DeleteHardAttr( nStartRow, nEndRow );
 
-    // Broadcast the changes.
-    ScHint aHint(SC_HINT_DATACHANGED, ScAddress(nCol, 0, nTab));
-    for (SCROW i = nStartRow; i <= nEndRow; ++i)
-    {
-        aHint.GetAddress().SetRow(i);
-        pDocument->Broadcast(aHint);
-    }
+    // Broadcast on only cells that were deleted; no point broadcasting on
+    // cells that were already empty before the deletion.
+    broadcastCells(*pDocument, nCol, nTab, aDeletedRows);
 }
 
 
commit d9583b8bfd9385c857c797bc067b21763a65fef1
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu May 9 20:36:49 2013 -0400

    Consolidate the text width and script type arrays into one.
    
    Since they are always in sync...
    
    Change-Id: Ic07f57e1804d76ae801c7947d18df5fd0d729632

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 8e49004..a76fd86 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -122,16 +122,16 @@ class ScColumn
     typedef mdds::mtv::custom_block_func1<sc::element_type_broadcaster, sc::custom_broadcaster_block> BCBlkFunc;
     typedef mdds::multi_type_vector<BCBlkFunc> BCStoreType;
 
-    typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
-    typedef mdds::multi_type_vector<mdds::mtv::element_block_func> ScriptType;
+    // Cell text attribute container.
+    typedef mdds::mtv::custom_block_func1<sc::element_type_celltextattr, sc::custom_celltextattr_block> CTAttrFunc;
+    typedef mdds::multi_type_vector<CTAttrFunc> CTAttrStoreType;
 
-    // Only stores empty or unsigned short values.  Empty values correspond
-    // with empty cells. All non-empty cell positions must have unsigned short
-    // values; either the reall text widths or TEXTWIDTH_DIRTY.
-    TextWidthType maTextWidths;
-
-    // Script types are stored as unsigned char.
-    ScriptType maScriptTypes;
+    // Empty values correspond with empty cells. All non-empty cell positions
+    // must have non-empty elements. For text width, the value should be
+    // either the real text width, or TEXTWIDTH_DIRTY in case it hasn't been
+    // calculated yet. For script type, it should be either the real script
+    // type value or SC_SCRIPTTYPE_UNKNOWN.
+    CTAttrStoreType maCellTextAttrs;
 
     BCStoreType maBroadcasters;
 
@@ -165,8 +165,6 @@ friend class ScDocumentImport;
     ScColumn(const ScColumn&); // disabled
     ScColumn& operator= (const ScColumn&); // disabled
 
-    static void SwapScriptTypes( ScriptType& rSrc, SCROW nSrcRow, ScriptType& rDest, SCROW nDestRow );
-
     std::vector<ColEntry>::iterator Search( SCROW nRow );
     std::vector<ColEntry>::const_iterator Search( SCROW nRow ) const;
 
@@ -493,7 +491,7 @@ private:
      */
     void CellStorageModified();
 
-    void CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const;
+    void CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const;
 
     void SetCell(SCROW nRow, ScBaseCell* pNewCell);
 };
diff --git a/sc/inc/columniterator.hxx b/sc/inc/columniterator.hxx
index 7bd645d..676f675 100644
--- a/sc/inc/columniterator.hxx
+++ b/sc/inc/columniterator.hxx
@@ -18,15 +18,15 @@ class ScColumn;
 
 class ScColumnTextWidthIterator : boost::noncopyable
 {
-    typedef ScColumn::TextWidthType TextWidthType;
+    typedef ScColumn::CTAttrStoreType CTAttrStoreType;
 
-    TextWidthType& mrTextWidths;
+    CTAttrStoreType& mrCellTextAttrs;
     const size_t mnEnd;
     size_t mnCurPos;
-    TextWidthType::iterator miBlockCur;
-    TextWidthType::iterator miBlockEnd;
-    mdds::mtv::ushort_element_block::iterator miDataCur;
-    mdds::mtv::ushort_element_block::iterator miDataEnd;
+    CTAttrStoreType::iterator miBlockCur;
+    CTAttrStoreType::iterator miBlockEnd;
+    sc::custom_celltextattr_block::iterator miDataCur;
+    sc::custom_celltextattr_block::iterator miDataEnd;
 
 public:
     ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow);
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index a4371f2..0e42ff1 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -73,27 +73,6 @@ ScNeededSizeOptions::ScNeededSizeOptions() :
 {
 }
 
-void ScColumn::SwapScriptTypes( ScriptType& rSrc, SCROW nSrcRow, ScriptType& rDest, SCROW nDestRow )
-{
-    unsigned char nSrcVal = 0;
-    unsigned char nDestVal = 0;
-
-    if (!rSrc.is_empty(nSrcRow))
-        nSrcVal = rSrc.get<unsigned char>(nSrcRow);
-    if (!rDest.is_empty(nDestRow))
-        nDestVal = rDest.get<unsigned char>(nDestRow);
-
-    if (nDestVal)
-        rSrc.set(nSrcRow, nDestVal);
-    else
-        rSrc.set_empty(nSrcRow, nSrcRow);
-
-    if (nSrcVal)
-        rDest.set(nDestRow, nSrcVal);
-    else
-        rDest.set_empty(nDestRow, nDestRow);
-}
-
 std::vector<ColEntry>::iterator ScColumn::Search( SCROW nRow )
 {
     // Find first cell whose position is equal or greater than nRow.
@@ -111,8 +90,7 @@ std::vector<ColEntry>::const_iterator ScColumn::Search( SCROW nRow ) const
 }
 
 ScColumn::ScColumn() :
-    maTextWidths(MAXROWCOUNT),
-    maScriptTypes(MAXROWCOUNT),
+    maCellTextAttrs(MAXROWCOUNT),
     maBroadcasters(MAXROWCOUNT),
     nCol( 0 ),
     pAttrArray( NULL ),
@@ -897,14 +875,11 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
             maItems[nIndex1].pCell = pCell2;
             maItems[nIndex2].pCell = pCell1;
 
-            // Swap text width values.
-            unsigned short nVal1 = maTextWidths.get<unsigned short>(nRow1);
-            unsigned short nVal2 = maTextWidths.get<unsigned short>(nRow2);
-            maTextWidths.set<unsigned short>(nRow1, nVal2);
-            maTextWidths.set<unsigned short>(nRow2, nVal1);
-
-            // Swap script types.
-            SwapScriptTypes(maScriptTypes, nRow1, maScriptTypes, nRow2);
+            // Swap text width values and script types.
+            sc::CellTextAttr aVal1 = maCellTextAttrs.get<sc::CellTextAttr>(nRow1);
+            sc::CellTextAttr aVal2 = maCellTextAttrs.get<sc::CellTextAttr>(nRow2);
+            maCellTextAttrs.set(nRow1, aVal2);
+            maCellTextAttrs.set(nRow2, aVal1);
 
             CellStorageModified();
         }
@@ -915,8 +890,7 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
 
             // remove ColEntry at old position
             maItems.erase( maItems.begin() + nIndex1 );
-            maTextWidths.set_empty(nRow1, nRow1);
-            maScriptTypes.set_empty(nRow1, nRow1);
+            maCellTextAttrs.set_empty(nRow1, nRow1);
 
             // Empty text width at the cell 1 position.  For now, we don't
             // transfer the old value to the cell 2 position since Insert() is
@@ -1042,14 +1016,11 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
             pFmlaCell2->UpdateReference(URM_MOVE, aRange, -dx, 0, 0);
         }
 
-        // Swap the text widths.
-        unsigned short nVal1 = maTextWidths.get<unsigned short>(nRow);
-        unsigned short nVal2 = rCol.maTextWidths.get<unsigned short>(nRow);
-        maTextWidths.set<unsigned short>(nRow, nVal2);
-        rCol.maTextWidths.set<unsigned short>(nRow, nVal1);
-
-        // Swap script types.
-        SwapScriptTypes(maScriptTypes, nRow, rCol.maScriptTypes, nRow);
+        // Swap text width values and script types.
+        sc::CellTextAttr aVal1 = maCellTextAttrs.get<sc::CellTextAttr>(nRow);
+        sc::CellTextAttr aVal2 = rCol.maCellTextAttrs.get<sc::CellTextAttr>(nRow);
+        maCellTextAttrs.set(nRow, aVal2);
+        rCol.maCellTextAttrs.set(nRow, aVal1);
 
         CellStorageModified();
         rCol.CellStorageModified();
@@ -1069,8 +1040,7 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
             pFmlaCell1->UpdateReference(URM_MOVE, aRange, dx, 0, 0);
         }
 
-        maTextWidths.set_empty(nRow, nRow);
-        maScriptTypes.set_empty(nRow, nRow);
+        maCellTextAttrs.set_empty(nRow, nRow);
         CellStorageModified();
 
         // We don't transfer the text width to the destination column because
@@ -1206,11 +1176,8 @@ void ScColumn::InsertRow( SCROW nStartRow, SCSIZE nSize )
 
     pDocument->SetAutoCalc( bOldAutoCalc );
 
-    maTextWidths.insert_empty(nStartRow, nSize);
-    maTextWidths.resize(MAXROWCOUNT);
-    maScriptTypes.insert_empty(nStartRow, nSize);
-    maScriptTypes.resize(MAXROWCOUNT);
-
+    maCellTextAttrs.insert_empty(nStartRow, nSize);
+    maCellTextAttrs.resize(MAXROWCOUNT);
     CellStorageModified();
 }
 
@@ -1296,7 +1263,7 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol
     if (nRow1 > nRow2)
         return;
 
-    CopyScriptTypesToDocument(nRow1, nRow2, rDestCol);
+    CopyCellTextAttrsToDocument(nRow1, nRow2, rDestCol);
 
     // First, clear the destination column for the row range specified.
     std::vector<ColEntry>::iterator it, itEnd;
@@ -1307,7 +1274,6 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol
         itEnd = std::find_if(it, rDestCol.maItems.end(), FindAboveRow(nRow2));
         std::for_each(it, itEnd, DeleteCell());
         rDestCol.maItems.erase(it, itEnd);
-        rDestCol.maTextWidths.set_empty(nRow1, nRow2);
     }
 
     // Determine the range of cells in the original column that need to be copied.
@@ -1375,12 +1341,6 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol
     // destination column shouldn't have any cells within the specified range.
     it = std::find_if(rDestCol.maItems.begin(), rDestCol.maItems.end(), FindAboveRow(nRow2));
     rDestCol.maItems.insert(it, aCopied.begin(), aCopied.end());
-
-    // Set text width values dirty for all non-empty cell positions.
-    it = aCopied.begin();
-    itEnd = aCopied.end();
-    for (; it != itEnd; ++it)
-        rDestCol.maTextWidths.set<unsigned short>(it->nRow, TEXTWIDTH_DIRTY);
 }
 
 void ScColumn::CopyCellToDocument( SCROW nSrcRow, SCROW nDestRow, ScColumn& rDestCol )
@@ -1635,8 +1595,7 @@ void ScColumn::MarkScenarioIn( ScMarkData& rDestMark ) const
 void ScColumn::SwapCol(ScColumn& rCol)
 {
     maItems.swap(rCol.maItems);
-    maTextWidths.swap(rCol.maTextWidths);
-    maScriptTypes.swap(rCol.maScriptTypes);
+    maCellTextAttrs.swap(rCol.maCellTextAttrs);
 
     CellStorageModified();
     rCol.CellStorageModified();
@@ -1693,9 +1652,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
     if (nStartPos < nStopPos)
     {
         // At least one cell gets copied to the destination column.
-        maTextWidths.set_empty(nStartRow, nEndRow);
-        maScriptTypes.set_empty(nStartRow, nEndRow);
-
+        maCellTextAttrs.set_empty(nStartRow, nEndRow);
         CellStorageModified();
 
         // Create list of ranges of cell entry positions.
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 9fcf5aa..cc590e0 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1371,16 +1371,16 @@ void ScColumn::CellStorageModified()
 #if DEBUG_COLUMN_STORAGE
     if (maItems.empty())
     {
-        if (maTextWidths.empty())
+        if (maCellTextAttrs.empty())
         {
             cout << "ScColumn::CellStorageModified: Text width array is empty, but shouldn't." << endl;
             cout.flush();
             abort();
         }
 
-        if (maTextWidths.block_size() != 1 || maTextWidths.begin()->type != mdds::mtv::element_type_empty)
+        if (maCellTextAttrs.block_size() != 1 || maCellTextAttrs.begin()->type != mdds::mtv::element_type_empty)
         {
-            cout << "ScColumn::CellStorageModified: When the cell array is empty, the text with array should consist of one empty block." << endl;
+            cout << "ScColumn::CellStorageModified: When the cell array is empty, the cell text attribute array should consist of one empty block." << endl;
             cout.flush();
             abort();
         }
@@ -1410,11 +1410,11 @@ void ScColumn::CellStorageModified()
 #endif
 }
 
-void ScColumn::CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const
+void ScColumn::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const
 {
-    rDestCol.maScriptTypes.set_empty(nRow1, nRow2); // Empty the destination range first.
+    rDestCol.maCellTextAttrs.set_empty(nRow1, nRow2); // Empty the destination range first.
 
-    ScriptType::const_iterator itBlk = maScriptTypes.begin(), itBlkEnd = maScriptTypes.end();
+    CTAttrStoreType::const_iterator itBlk = maCellTextAttrs.begin(), itBlkEnd = maCellTextAttrs.end();
 
     // Locate the top row position.
     size_t nOffsetInBlock = 0;
@@ -1437,7 +1437,7 @@ void ScColumn::CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDe
     nRowPos = static_cast<size_t>(nRow2); // End row position.
 
     // Keep copying until we hit the end row position.
-    mdds::mtv::uchar_element_block::const_iterator itData, itDataEnd;
+    sc::custom_celltextattr_block::const_iterator itData, itDataEnd;
     for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
     {
         nBlockEnd = nBlockStart + itBlk->size;
@@ -1446,30 +1446,30 @@ void ScColumn::CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDe
             // Empty block.
             if (nBlockStart <= nRowPos && nRowPos <= nBlockEnd)
                 // This block contains the end row.
-                rDestCol.maScriptTypes.set_empty(nBlockStart + nOffsetInBlock, nRowPos);
+                rDestCol.maCellTextAttrs.set_empty(nBlockStart + nOffsetInBlock, nRowPos);
             else
-                rDestCol.maScriptTypes.set_empty(nBlockStart + nOffsetInBlock, nBlockEnd-1);
+                rDestCol.maCellTextAttrs.set_empty(nBlockStart + nOffsetInBlock, nBlockEnd-1);
 
             continue;
         }
 
         // Non-empty block.
-        itData = mdds::mtv::uchar_element_block::begin(*itBlk->data);
-        itDataEnd = mdds::mtv::uchar_element_block::end(*itBlk->data);
+        itData = sc::custom_celltextattr_block::begin(*itBlk->data);
+        itDataEnd = sc::custom_celltextattr_block::end(*itBlk->data);
         std::advance(itData, nOffsetInBlock);
 
         if (nBlockStart <= nRowPos && nRowPos <= nBlockEnd)
         {
             // This block contains the end row. Only copy partially.
             size_t nOffset = nRowPos - nBlockStart + 1;
-            itDataEnd = mdds::mtv::uchar_element_block::begin(*itBlk->data);
+            itDataEnd = sc::custom_celltextattr_block::begin(*itBlk->data);
             std::advance(itDataEnd, nOffset);
 
-            rDestCol.maScriptTypes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+            rDestCol.maCellTextAttrs.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
             break;
         }
 
-        rDestCol.maScriptTypes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+        rDestCol.maCellTextAttrs.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
     }
 }
 
@@ -1502,8 +1502,7 @@ void ScColumn::SetCell(SCROW nRow, ScBaseCell* pNewCell)
             maItems[nIndex].nRow  = nRow;
         }
 
-        maTextWidths.set<unsigned short>(nRow, TEXTWIDTH_DIRTY);
-        maScriptTypes.set<unsigned char>(nRow, SC_SCRIPTTYPE_UNKNOWN);
+        maCellTextAttrs.set(nRow, sc::CellTextAttr());
         CellStorageModified();
     }
 }
@@ -1518,22 +1517,24 @@ const SvtBroadcaster* ScColumn::GetBroadcaster(SCROW nRow) const
     return maBroadcasters.get<SvtBroadcaster*>(nRow);
 }
 
-unsigned short ScColumn::GetTextWidth(SCROW nRow) const
+sal_uInt16 ScColumn::GetTextWidth(SCROW nRow) const
 {
-    return maTextWidths.get<unsigned short>(nRow);
+    return maCellTextAttrs.get<sc::CellTextAttr>(nRow).mnTextWidth;
 }
 
-void ScColumn::SetTextWidth(SCROW nRow, unsigned short nWidth)
+void ScColumn::SetTextWidth(SCROW nRow, sal_uInt16 nWidth)
 {
-    maTextWidths.set(nRow, nWidth);
+    sc::CellTextAttr aVal = maCellTextAttrs.get<sc::CellTextAttr>(nRow);
+    aVal.mnTextWidth = nWidth;
+    maCellTextAttrs.set(nRow, aVal);
 }
 
 sal_uInt8 ScColumn::GetScriptType( SCROW nRow ) const
 {
-    if (!ValidRow(nRow) || maScriptTypes.is_empty(nRow))
+    if (!ValidRow(nRow) || maCellTextAttrs.is_empty(nRow))
         return 0;
 
-    return maScriptTypes.get<unsigned char>(nRow);
+    return maCellTextAttrs.get<sc::CellTextAttr>(nRow).mnScriptType;
 }
 
 void ScColumn::SetScriptType( SCROW nRow, sal_uInt8 nType )
@@ -1542,9 +1543,20 @@ void ScColumn::SetScriptType( SCROW nRow, sal_uInt8 nType )
         return;
 
     if (!nType)
-        maScriptTypes.set_empty(nRow, nRow);
+    {
+        if (maCellTextAttrs.is_empty(nRow))
+            return;
+
+        sc::CellTextAttr aVal = maCellTextAttrs.get<sc::CellTextAttr>(nRow);
+        aVal.mnScriptType = nType;
+        maCellTextAttrs.set(nRow, aVal);
+    }
     else
-        maScriptTypes.set<unsigned char>(nRow, nType);
+    {
+        sc::CellTextAttr aVal = maCellTextAttrs.get<sc::CellTextAttr>(nRow);
+        aVal.mnScriptType = nType;
+        maCellTextAttrs.set(nRow, aVal);
+    }
 }
 
 size_t ScColumn::GetFormulaHash( SCROW nRow ) const
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 8e8ad31..0b1571c 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -101,8 +101,7 @@ void ScColumn::Append( SCROW nRow, ScBaseCell* pCell )
     maItems.back().pCell = pCell;
     maItems.back().nRow  = nRow;
 
-    maTextWidths.set<unsigned short>(nRow, TEXTWIDTH_DIRTY);
-    maScriptTypes.set<unsigned char>(nRow, SC_SCRIPTTYPE_UNKNOWN);
+    maCellTextAttrs.set<sc::CellTextAttr>(nRow, sc::CellTextAttr());
     CellStorageModified();
 }
 
@@ -115,8 +114,7 @@ void ScColumn::Delete( SCROW nRow )
 
     ScBaseCell* pCell = maItems[nIndex].pCell;
     maItems.erase(maItems.begin() + nIndex);
-    maTextWidths.set_empty(nRow, nRow);
-    maScriptTypes.set_empty(nRow, nRow);
+    maCellTextAttrs.set_empty(nRow, nRow);
     // Should we free memory here (delta)? It'll be slower!
     if (pCell->GetCellType() == CELLTYPE_FORMULA)
         static_cast<ScFormulaCell*>(pCell)->EndListeningTo(pDocument);
@@ -141,8 +139,7 @@ void ScColumn::DeleteAtIndex( SCSIZE nIndex )
     pDocument->Broadcast(
         ScHint(SC_HINT_DATACHANGED, ScAddress(nCol, nRow, nTab)));
 
-    maTextWidths.set_empty(nRow, nRow);
-    maScriptTypes.set_empty(nRow, nRow);
+    maCellTextAttrs.set_empty(nRow, nRow);
     CellStorageModified();
 }
 
@@ -154,10 +151,8 @@ void ScColumn::FreeAll()
     maItems.clear();
 
     // Text width should keep a logical empty range of 0-MAXROW when the cell array is empty.
-    maTextWidths.clear();
-    maTextWidths.resize(MAXROWCOUNT);
-    maScriptTypes.clear();
-    maScriptTypes.resize(MAXROWCOUNT);
+    maCellTextAttrs.clear();
+    maCellTextAttrs.resize(MAXROWCOUNT);
     CellStorageModified();
 }
 
@@ -214,10 +209,8 @@ void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize )
     // There are cells below the deletion point.  Shift their row positions.
 
     // Shift the text width array too (before the broadcast).
-    maTextWidths.erase(nStartRow, nEndRow);
-    maTextWidths.resize(MAXROWCOUNT);
-    maScriptTypes.erase(nStartRow, nEndRow);
-    maScriptTypes.resize(MAXROWCOUNT);
+    maCellTextAttrs.erase(nStartRow, nEndRow);
+    maCellTextAttrs.resize(MAXROWCOUNT);
 
     ScAddress aAdr( nCol, 0, nTab );
     ScHint aHint(SC_HINT_DATACHANGED, aAdr); // only areas (ScBaseCell* == NULL)
@@ -414,8 +407,7 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe
             std::advance(itEraseEnd, nEndSegment);
             maItems.erase(itErase, itEraseEnd);
 
-            maTextWidths.set_empty(nStartRow, nEndRow);
-            maScriptTypes.set_empty(nStartRow, nEndRow);
+            maCellTextAttrs.set_empty(nStartRow, nEndRow);
 
             nEndSegment = nStartSegment;
         }
@@ -1313,8 +1305,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
 
                 pOldCell->Delete();
                 maItems[i].pCell = pNewCell; // Replace
-                maTextWidths.set<unsigned short>(nRow, TEXTWIDTH_DIRTY);
-                maScriptTypes.set<unsigned char>(nRow, SC_SCRIPTTYPE_UNKNOWN);
+                maCellTextAttrs.set<sc::CellTextAttr>(nRow, sc::CellTextAttr());
                 CellStorageModified();
 
                 if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
diff --git a/sc/source/core/data/columniterator.cxx b/sc/source/core/data/columniterator.cxx
index 24b8c05..3380c0a 100644
--- a/sc/source/core/data/columniterator.cxx
+++ b/sc/source/core/data/columniterator.cxx
@@ -13,21 +13,21 @@
 #include "table.hxx"
 
 ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow) :
-    mrTextWidths(rCol.maTextWidths),
+    mrCellTextAttrs(rCol.maCellTextAttrs),
     mnEnd(static_cast<size_t>(nEndRow)),
     mnCurPos(0),
-    miBlockCur(mrTextWidths.begin()),
-    miBlockEnd(mrTextWidths.end())
+    miBlockCur(mrCellTextAttrs.begin()),
+    miBlockEnd(mrCellTextAttrs.end())
 {
     init(nStartRow, nEndRow);
 }
 
 ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScDocument& rDoc, const ScAddress& rStartPos, SCROW nEndRow) :
-    mrTextWidths(rDoc.maTabs[rStartPos.Tab()]->aCol[rStartPos.Col()].maTextWidths),
+    mrCellTextAttrs(rDoc.maTabs[rStartPos.Tab()]->aCol[rStartPos.Col()].maCellTextAttrs),
     mnEnd(static_cast<size_t>(nEndRow)),
     mnCurPos(0),
-    miBlockCur(mrTextWidths.begin()),
-    miBlockEnd(mrTextWidths.end())
+    miBlockCur(mrCellTextAttrs.begin()),
+    miBlockEnd(mrCellTextAttrs.end())
 {
     init(rStartPos.Row(), nEndRow);
 }
@@ -47,7 +47,7 @@ void ScColumnTextWidthIterator::next()
     // Move to the next block.
     for (++miBlockCur; miBlockCur != miBlockEnd; ++miBlockCur)
     {
-        if (miBlockCur->type != mdds::mtv::element_type_ushort)
+        if (miBlockCur->type != sc::element_type_celltextattr)
         {
             // We don't iterator over this block.
             mnCurPos += miBlockCur->size;
@@ -77,13 +77,13 @@ SCROW ScColumnTextWidthIterator::getPos() const
 sal_uInt16 ScColumnTextWidthIterator::getValue() const
 {
     OSL_ASSERT(miBlockCur != miBlockEnd && miDataCur != miDataEnd);
-    return *miDataCur;
+    return miDataCur->mnTextWidth;
 }
 
 void ScColumnTextWidthIterator::setValue(sal_uInt16 nVal)
 {
     OSL_ASSERT(miBlockCur != miBlockEnd && miDataCur != miDataEnd);
-    *miDataCur = nVal;
+    miDataCur->mnTextWidth = nVal;
 }
 
 void ScColumnTextWidthIterator::init(SCROW nStartRow, SCROW nEndRow)
@@ -110,7 +110,7 @@ void ScColumnTextWidthIterator::init(SCROW nStartRow, SCROW nEndRow)
         return;
 
     // Locate the initial row position within this block.
-    if (miBlockCur->type == mdds::mtv::element_type_ushort)
+    if (miBlockCur->type == sc::element_type_celltextattr)
     {
         // This block stores text widths for non-empty cells.
         size_t nOffsetInBlock = nStart - nBlockStart;
@@ -128,7 +128,7 @@ void ScColumnTextWidthIterator::init(SCROW nStartRow, SCROW nEndRow)
     for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
     {
         nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
-        if (miBlockCur->type != mdds::mtv::element_type_ushort)
+        if (miBlockCur->type != sc::element_type_celltextattr)
             continue;
 
         // Found!
@@ -145,11 +145,11 @@ void ScColumnTextWidthIterator::init(SCROW nStartRow, SCROW nEndRow)
 void ScColumnTextWidthIterator::getDataIterators(size_t nOffsetInBlock)
 {
     OSL_ENSURE(miBlockCur != miBlockEnd, "block is at end position");
-    OSL_ENSURE(miBlockCur->type == mdds::mtv::element_type_ushort,
+    OSL_ENSURE(miBlockCur->type == sc::custom_celltextattr_block,
                "wrong block type - unsigned short block expected.");
 
-    miDataCur = mdds::mtv::ushort_element_block::begin(*miBlockCur->data);
-    miDataEnd = mdds::mtv::ushort_element_block::end(*miBlockCur->data);
+    miDataCur = sc::custom_celltextattr_block::begin(*miBlockCur->data);
+    miDataEnd = sc::custom_celltextattr_block::end(*miBlockCur->data);
 
     std::advance(miDataCur, nOffsetInBlock);
 }
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index bb638af..0b68fed 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -109,14 +109,10 @@ void ScDocumentImport::finalize()
                 // Column has no cells. Skip it.
                 continue;
 
-            ScColumn::TextWidthType::iterator itWidthPos = rCol.maTextWidths.begin();
-            ScColumn::ScriptType::iterator itScriptPos = rCol.maScriptTypes.begin();
+            ScColumn::CTAttrStoreType::iterator itCTAPos = rCol.maCellTextAttrs.begin();
             std::vector<ColEntry>::iterator itCell = rCol.maItems.begin(), itCellEnd = rCol.maItems.end();
             for (; itCell != itCellEnd; ++itCell)
-            {
-                itWidthPos = rCol.maTextWidths.set<unsigned short>(itWidthPos, itCell->nRow, TEXTWIDTH_DIRTY);
-                itScriptPos = rCol.maScriptTypes.set<unsigned char>(itScriptPos, itCell->nRow, SC_SCRIPTTYPE_UNKNOWN);
-            }
+                itCTAPos = rCol.maCellTextAttrs.set<sc::CellTextAttr>(itCTAPos, itCell->nRow, sc::CellTextAttr());
         }
     }
 }
commit ea4c604b6f5071dfc9fc076a8e34c00bb98077d7
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu May 9 17:49:24 2013 -0400

    Block definition for CellTextAttr.
    
    This block will be used to merge the text width and script type vectors
    that are currently separate.  Text widths and script types should really
    be stored together.
    
    Change-Id: I6783769cc03180b513319e0a98a0773bd20ba941

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 2903aa6..ccd8ebe 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -141,6 +141,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/data/globalx \
 	sc/source/core/data/markarr \
 	sc/source/core/data/markdata \
+	sc/source/core/data/mtvelements \
 	sc/source/core/data/olinetab \
 	sc/source/core/data/pagepar \
 	sc/source/core/data/patattr \
diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 909c89d..597feb8 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -29,10 +29,6 @@
 
 #define USE_MEMPOOL
 
-// in addition to SCRIPTTYPE_... flags from scripttypeitem.hxx:
-// set (in nScriptType) if type has not been determined yet
-#define SC_SCRIPTTYPE_UNKNOWN   0x08
-
 class ScDocument;
 class EditTextObject;
 class ScMatrix;
diff --git a/sc/inc/globalnames.hxx b/sc/inc/globalnames.hxx
index 384ab3f..a7f0053 100644
--- a/sc/inc/globalnames.hxx
+++ b/sc/inc/globalnames.hxx
@@ -19,6 +19,10 @@
 
 #define DATE_TIME_FACTOR 86400.0
 
+// in addition to SCRIPTTYPE_... flags from scripttypeitem.hxx:
+// set (in nScriptType) if type has not been determined yet
+#define SC_SCRIPTTYPE_UNKNOWN 0x08
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/mtvelements.hxx b/sc/inc/mtvelements.hxx
index 41c5175..9fc5947 100644
--- a/sc/inc/mtvelements.hxx
+++ b/sc/inc/mtvelements.hxx
@@ -7,8 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef SC_MTVBLOCKFUNC_HXX
-#define SC_MTVBLOCKFUNC_HXX
+#ifndef SC_MTVELEMENTS_HXX
+#define SC_MTVELEMENTS_HXX
 
 #include "svl/broadcast.hxx"
 
@@ -17,13 +17,28 @@
 
 namespace sc {
 
+struct CellTextAttr
+{
+    sal_uInt16 mnTextWidth;
+    sal_uInt8 mnScriptType;
+
+    CellTextAttr();
+    CellTextAttr(const CellTextAttr& r);
+    CellTextAttr(sal_uInt16 nTextWidth, sal_uInt8 nScriptType);
+};
+
 // Custom element type IDs for multi_type_vector.
 
 const mdds::mtv::element_t element_type_broadcaster = mdds::mtv::element_type_user_start;
+const mdds::mtv::element_t element_type_celltextattr = mdds::mtv::element_type_user_start + 1;
 
 // Custom element blocks.
 
 typedef mdds::mtv::noncopyable_managed_element_block<element_type_broadcaster, SvtBroadcaster> custom_broadcaster_block;
+typedef mdds::mtv::default_element_block<element_type_celltextattr, CellTextAttr> custom_celltextattr_block;
+
+// This needs to be in the same namespace as CellTextAttr.
+MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr, element_type_celltextattr, CellTextAttr(), custom_celltextattr_block)
 
 }
 
diff --git a/sc/source/core/data/documen6.cxx b/sc/source/core/data/documen6.cxx
index fbd00bc..bd55fc4 100644
--- a/sc/source/core/data/documen6.cxx
+++ b/sc/source/core/data/documen6.cxx
@@ -32,6 +32,7 @@
 #include "scrdata.hxx"
 #include "poolhelp.hxx"
 #include "attrib.hxx"
+#include "globalnames.hxx"
 
 using namespace com::sun::star;
 
diff --git a/sc/source/core/data/mtvelements.cxx b/sc/source/core/data/mtvelements.cxx
new file mode 100644
index 0000000..45c06dd
--- /dev/null
+++ b/sc/source/core/data/mtvelements.cxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "mtvelements.hxx"
+#include "globalnames.hxx"
+
+namespace sc {
+
+CellTextAttr::CellTextAttr() :
+    mnTextWidth(TEXTWIDTH_DIRTY),
+    mnScriptType(SC_SCRIPTTYPE_UNKNOWN) {}
+
+CellTextAttr::CellTextAttr(const CellTextAttr& r) :
+    mnTextWidth(r.mnTextWidth),
+    mnScriptType(r.mnScriptType) {}
+
+CellTextAttr::CellTextAttr(sal_uInt16 nTextWidth, sal_uInt8 nScriptType) :
+    mnTextWidth(nTextWidth),
+    mnScriptType(nScriptType) {}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 87fce6c8ecb31ed0df80b30d82367f308e4b1bfb
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu May 9 17:28:09 2013 -0400

    Rename header: mtvelement -> multi_type_vector (mtv) elements.
    
    This header hosts custom element types and blocks used in
    multi_type_vector.
    
    Change-Id: I32481a2354d8c66eb877b4005a260a79183cd714

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index e594ba2..8e49004 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -25,7 +25,7 @@
 #include "address.hxx"
 #include "rangenam.hxx"
 #include "types.hxx"
-#include "mtvblockfunc.hxx"
+#include "mtvelements.hxx"
 #include "formula/types.hxx"
 
 #include <set>
diff --git a/sc/inc/mtvblockfunc.hxx b/sc/inc/mtvelements.hxx
similarity index 100%
rename from sc/inc/mtvblockfunc.hxx
rename to sc/inc/mtvelements.hxx


More information about the Libreoffice-commits mailing list