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

Kohei Yoshida kohei.yoshida at gmail.com
Fri Mar 15 13:44:34 PDT 2013


 sc/inc/column.hxx               |    2 +
 sc/source/core/data/column.cxx  |   20 ++++++++++++
 sc/source/core/data/column2.cxx |   63 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)

New commits:
commit d5c81662557401eb8ba7a499d3c4beb9593dd11b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Mar 15 16:46:36 2013 -0400

    Started handling the cell text script types. Still work in progress.
    
    Change-Id: I6af668894d61d33de6697fe45fce1515520d4bfa

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 2469a6c..1b01787 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -418,6 +418,8 @@ private:
      * Call this only from those methods where maItems is modified directly.
      */
     void CellStorageModified();
+
+    void CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const;
 };
 
 
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index b472e9e..c73fa94 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -863,6 +863,13 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
             unsigned short nVal2 = maTextWidths.get<unsigned short>(nRow2);
             maTextWidths.set<unsigned short>(nRow1, nVal2);
             maTextWidths.set<unsigned short>(nRow2, nVal1);
+
+            // Swap script types.
+            nVal1 = maScriptTypes.get<unsigned short>(nRow1);
+            nVal2 = maScriptTypes.get<unsigned short>(nRow2);
+            maScriptTypes.set(nRow1, nVal2);
+            maScriptTypes.set(nRow2, nVal1);
+
             CellStorageModified();
         }
         else
@@ -881,6 +888,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);
             }
 
             // Empty text width at the cell 1 position.  For now, we don't
@@ -1019,6 +1027,12 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
         maTextWidths.set<unsigned short>(nRow, nVal2);
         rCol.maTextWidths.set<unsigned short>(nRow, nVal1);
 
+        // Swap script types.
+        nVal1 = maScriptTypes.get<unsigned short>(nRow);
+        nVal2 = rCol.maScriptTypes.get<unsigned short>(nRow);
+        maScriptTypes.set(nRow, nVal2);
+        rCol.maScriptTypes.set(nRow, nVal1);
+
         CellStorageModified();
         rCol.CellStorageModified();
     }
@@ -1038,6 +1052,7 @@ void ScColumn::SwapCell( SCROW nRow, ScColumn& rCol)
         }
 
         maTextWidths.set_empty(nRow, nRow);
+        maScriptTypes.set_empty(nRow, nRow);
         CellStorageModified();
 
         // We don't transfer the text width to the destination column because
@@ -1191,6 +1206,7 @@ void ScColumn::InsertRow( SCROW nStartRow, SCSIZE nSize )
     pDocument->SetAutoCalc( bOldAutoCalc );
 
     maTextWidths.insert_empty(nStartRow, nSize);
+    maScriptTypes.insert_empty(nStartRow, nSize);
     CellStorageModified();
 }
 
@@ -1276,6 +1292,8 @@ void ScColumn::CopyStaticToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol
     if (nRow1 > nRow2)
         return;
 
+    CopyScriptTypesToDocument(nRow1, nRow2, rDestCol);
+
     // First, clear the destination column for the row range specified.
     std::vector<ColEntry>::iterator it, itEnd;
 
@@ -1353,6 +1371,8 @@ 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)
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 2715fb9..92263af 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1433,6 +1433,69 @@ void ScColumn::CellStorageModified()
 #endif
 }
 
+void ScColumn::CopyScriptTypesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol) const
+{
+    rDestCol.maScriptTypes.set_empty(nRow1, nRow2); // Empty the destination range first.
+
+    ScriptType::const_iterator itBlk = maScriptTypes.begin(), itBlkEnd = maScriptTypes.end();
+
+    // Locate the top row position.
+    size_t nOffsetInBlock = 0;
+    size_t nBlockStart = 0, nBlockEnd = 0, nRowPos = static_cast<size_t>(nRow1);
+    for (; itBlk != itBlkEnd; ++itBlk)
+    {
+        nBlockEnd = nBlockStart + itBlk->size;
+        if (nBlockStart <= nRowPos && nRowPos <= nBlockEnd)
+        {
+            // Found.
+            nOffsetInBlock = nRowPos - nBlockStart;
+            break;
+        }
+    }
+
+    if (itBlk == itBlkEnd)
+        // Specified range not found. Bail out.
+        return;
+
+    nRowPos = static_cast<size_t>(nRow2); // End row position.
+
+    // Keep copying until we hit the end row position.
+    mdds::mtv::ushort_element_block::const_iterator itData, itDataEnd;
+    for (; itBlk != itBlkEnd; ++itBlk, nBlockStart = nBlockEnd, nOffsetInBlock = 0)
+    {
+        nBlockEnd = nBlockStart + itBlk->size;
+        if (!itBlk->data)
+        {
+            // Empty block.
+            if (nBlockStart <= nRowPos && nRowPos <= nBlockEnd)
+                // This block contains the end row.
+                rDestCol.maScriptTypes.set_empty(nBlockStart + nOffsetInBlock, nRowPos);
+            else
+                rDestCol.maScriptTypes.set_empty(nBlockStart + nOffsetInBlock, nBlockEnd-1);
+
+            continue;
+        }
+
+        // Non-empty block.
+        itData = mdds::mtv::ushort_element_block::begin(*itBlk->data);
+        itDataEnd = mdds::mtv::ushort_element_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::ushort_element_block::begin(*itBlk->data);
+            std::advance(itDataEnd, nOffset);
+
+            rDestCol.maScriptTypes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+            break;
+        }
+
+        rDestCol.maScriptTypes.set(nBlockStart + nOffsetInBlock, itData, itDataEnd);
+    }
+}
+
 unsigned short ScColumn::GetTextWidth(SCROW nRow) const
 {
     return maTextWidths.get<unsigned short>(nRow);


More information about the Libreoffice-commits mailing list