[Libreoffice-commits] core.git: 29 commits - sc/inc sc/Library_sc.mk sc/qa sc/source svl/inc

Kohei Yoshida kohei.yoshida at gmail.com
Thu Mar 14 12:42:41 PDT 2013


 sc/Library_sc.mk                       |    1 
 sc/inc/cell.hxx                        |    6 
 sc/inc/column.hxx                      |   27 ++
 sc/inc/columniterator.hxx              |   58 +++++
 sc/inc/document.hxx                    |   10 
 sc/inc/globalnames.hxx                 |    2 
 sc/inc/progress.hxx                    |    2 
 sc/inc/table.hxx                       |    5 
 sc/qa/unit/ucalc.cxx                   |   79 +++++++
 sc/source/core/data/cell.cxx           |   11 -
 sc/source/core/data/column.cxx         |   95 +++++++-
 sc/source/core/data/column2.cxx        |   14 +
 sc/source/core/data/column3.cxx        |   43 +++
 sc/source/core/data/columniterator.cxx |  167 +++++++++++++++
 sc/source/core/data/documen2.cxx       |    2 
 sc/source/core/data/documen3.cxx       |    6 
 sc/source/core/data/documen7.cxx       |    6 
 sc/source/core/data/documen8.cxx       |  361 +++++++++++++++++++--------------
 sc/source/core/data/document.cxx       |   16 +
 sc/source/core/data/table1.cxx         |    6 
 sc/source/core/data/table2.cxx         |    9 
 sc/source/core/data/table5.cxx         |   95 ++++----
 sc/source/core/tool/interpr2.cxx       |    6 
 sc/source/core/tool/progress.cxx       |    8 
 sc/source/filter/xml/xmlexprt.cxx      |    6 
 sc/source/ui/docshell/docsh.cxx        |   16 -
 sc/source/ui/inc/docsh.hxx             |    2 
 sc/source/ui/inc/spelldialog.hxx       |    2 
 sc/source/ui/view/output.cxx           |    6 
 sc/source/ui/view/output2.cxx          |   21 -
 sc/source/ui/view/spelldialog.cxx      |   10 
 sc/source/ui/view/viewfun4.cxx         |    6 
 svl/inc/svl/cintitem.hxx               |    2 
 33 files changed, 829 insertions(+), 277 deletions(-)

New commits:
commit 23075c27b5cf99d8415a304f9ab151a73938edcb
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 14 14:53:05 2013 -0400

    Remove a local inline function that's used from only one call site.
    
    Change-Id: I73954b8a1de436b9c4881d803f4f33cff1b79c4f

diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 6caa4e2..5f537df 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -1073,13 +1073,6 @@ static inline void lcl_CreateInterpretProgress( sal_Bool& bProgress, ScDocument*
     }
 }
 
-inline sal_uInt8 GetScriptType( ScDocument* pDoc, ScBaseCell* pCell,
-                            const ScPatternAttr* pPattern,
-                            const SfxItemSet* pCondSet )
-{
-    return pDoc->GetCellScriptType( pCell, pPattern->GetNumberFormat( pDoc->GetFormatTable(), pCondSet ) );
-}
-
 inline sal_Bool IsAmbiguousScript( sal_uInt8 nScript )
 {
     return ( nScript != SCRIPTTYPE_LATIN &&
@@ -1604,8 +1597,12 @@ void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
                         pPattern = pAltPattern;
                     }
 
-                    sal_uInt8 nScript = GetScriptType( mpDoc, pCell, pPattern, pCondSet );
-                    if (nScript == 0) nScript = ScGlobal::GetDefaultScriptType();
+                    sal_uInt8 nScript = mpDoc->GetCellScriptType(
+                        pCell, pPattern->GetNumberFormat(mpDoc->GetFormatTable(), pCondSet));
+
+                    if (nScript == 0)
+                        nScript = ScGlobal::GetDefaultScriptType();
+
                     if ( pPattern != pOldPattern || pCondSet != pOldCondSet ||
                          nScript != nOldScript || mbSyntaxMode )
                     {
commit fa5473bb69ff04f362c1f0f14b112e533cfa501a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 14 12:14:40 2013 -0400

    Unit test for the new column-based text width storage, via new iterator.
    
    Change-Id: Ibf1e254e34df98ad5c46a46252168787b07d161c

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 93ae44f..114a39b 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -97,7 +97,6 @@ class ScColumn
     ScAttrArray*       pAttrArray;
     ScDocument*                pDocument;
 
-friend class ScColumnTextWidthIterator;
 friend class ScDocument;                                       // for FillInfo
 friend class ScDocumentIterator;
 friend class ScValueIterator;
@@ -109,6 +108,7 @@ friend class ScMarkedDataIter;
 friend class ScCellIterator;
 friend class ScHorizontalCellIterator;
 friend class ScHorizontalAttrIterator;
+friend class ScColumnTextWidthIterator;
 
     ScColumn(const ScColumn&); // disabled
     ScColumn& operator= (const ScColumn&); // disabled
diff --git a/sc/inc/columniterator.hxx b/sc/inc/columniterator.hxx
index a70567c56..7bd645d 100644
--- a/sc/inc/columniterator.hxx
+++ b/sc/inc/columniterator.hxx
@@ -31,6 +31,16 @@ class ScColumnTextWidthIterator : boost::noncopyable
 public:
     ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow);
 
+    /**
+     * @param rDoc document instance.
+     * @param rStartPos position of the first cell from which to start
+     *                  iteration. Note that the caller must ensure that this
+     *                  position is valid; the constructor does not check its
+     *                  validity.
+     * @param nEndRow end row position.
+     */
+    ScColumnTextWidthIterator(ScDocument& rDoc, const ScAddress& rStartPos, SCROW nEndRow);
+
     void next();
     bool hasCell() const;
     SCROW getPos() const;
@@ -38,6 +48,7 @@ public:
     void setValue(sal_uInt16 nVal);
 
 private:
+    void init(SCROW nStartRow, SCROW nEndRow);
     void getDataIterators(size_t nOffsetInBlock);
     void checkEndRow();
 };
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 2f59ef1..541ec05 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -214,6 +214,7 @@ friend class ScDocAttrIterator;
 friend class ScAttrRectIterator;
 friend class ScDocShell;
 friend class ScDocRowHeightUpdater;
+friend class ScColumnTextWidthIterator;
 
     typedef ::std::vector<ScTable*> TableContainer;
 private:
@@ -1844,6 +1845,7 @@ public:
     void RemoveSubTotalCell(ScFormulaCell* pCell);
     void SetSubTotalCellsDirty(const ScRange& rDirtyRange);
 
+    sal_uInt16 GetTextWidth( const ScAddress& rPos ) const;
     void SetTextWidth( const ScAddress& rPos, sal_uInt16 nWidth );
 
 private: // CLOOK-Impl-methods
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 8786ccf..3e4d1eb 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -187,7 +187,7 @@ friend class ScHorizontalCellIterator;
 friend class ScHorizontalAttrIterator;
 friend class ScDocAttrIterator;
 friend class ScAttrRectIterator;
-
+friend class ScColumnTextWidthIterator;
 
 public:
                 ScTable( ScDocument* pDoc, SCTAB nNewTab, const rtl::OUString& rNewName,
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 232a501..57b00f4 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -65,6 +65,7 @@
 #include "dpfilteredcache.hxx"
 #include "calcconfig.hxx"
 #include "interpre.hxx"
+#include "columniterator.hxx"
 
 #include "formula/IFunctionDescription.hxx"
 
@@ -262,6 +263,7 @@ public:
     void testDeleteRow();
     void testDeleteCol();
     void testAnchoredRotatedShape();
+    void testCellTextWidth();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testCollator);
@@ -323,6 +325,7 @@ public:
     CPPUNIT_TEST(testDeleteRow);
     CPPUNIT_TEST(testDeleteCol);
     CPPUNIT_TEST(testAnchoredRotatedShape);
+    CPPUNIT_TEST(testCellTextWidth);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6025,6 +6028,82 @@ void Test::testAnchoredRotatedShape()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testCellTextWidth()
+{
+    m_pDoc->InsertTab(0, "Test");
+
+    ScAddress aTopCell(0, 0, 0);
+
+    // Sheet is empty.
+    boost::scoped_ptr<ScColumnTextWidthIterator> pIter(new ScColumnTextWidthIterator(*m_pDoc, aTopCell, MAXROW));
+    CPPUNIT_ASSERT_MESSAGE("Column should have no text widths stored.", !pIter->hasCell());
+
+    // Sheet only has one cell.
+    m_pDoc->SetString(0, 0, 0, "Only one cell");
+    pIter.reset(new ScColumnTextWidthIterator(*m_pDoc, aTopCell, MAXROW));
+    CPPUNIT_ASSERT_MESSAGE("Column should have a cell.", pIter->hasCell());
+    CPPUNIT_ASSERT_EQUAL(0, pIter->getPos());
+
+    // Setting a text width here should commit it to the column.
+    sal_uInt16 nTestVal = 432;
+    pIter->setValue(nTestVal);
+    CPPUNIT_ASSERT_EQUAL(nTestVal, m_pDoc->GetTextWidth(aTopCell));
+
+    // Set values to row 2 through 6.
+    for (SCROW i = 2; i <= 6; ++i)
+        m_pDoc->SetString(0, i, 0, "foo");
+
+    // Set values to row 10 through 18.
+    for (SCROW i = 10; i <= 18; ++i)
+        m_pDoc->SetString(0, i, 0, "foo");
+
+    {
+        // Full range.
+        pIter.reset(new ScColumnTextWidthIterator(*m_pDoc, aTopCell, MAXROW));
+        SCROW aRows[] = { 0, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
+        size_t n = SAL_N_ELEMENTS(aRows);
+        for (size_t i = 0; i < n; ++i, pIter->next())
+        {
+            CPPUNIT_ASSERT_MESSAGE("Cell expected, but not there.", pIter->hasCell());
+            CPPUNIT_ASSERT_EQUAL(aRows[i], pIter->getPos());
+        }
+        CPPUNIT_ASSERT_MESSAGE("Iterator should have ended.", !pIter->hasCell());
+    }
+
+    {
+        // Specify start and end rows (6 - 16)
+        ScAddress aStart = aTopCell;
+        aStart.SetRow(6);
+        pIter.reset(new ScColumnTextWidthIterator(*m_pDoc, aStart, 16));
+        SCROW aRows[] = { 6, 10, 11, 12, 13, 14, 15, 16 };
+        size_t n = SAL_N_ELEMENTS(aRows);
+        for (size_t i = 0; i < n; ++i, pIter->next())
+        {
+            CPPUNIT_ASSERT_MESSAGE("Cell expected, but not there.", pIter->hasCell());
+            CPPUNIT_ASSERT_EQUAL(aRows[i], pIter->getPos());
+        }
+        CPPUNIT_ASSERT_MESSAGE("Iterator should have ended.", !pIter->hasCell());
+    }
+
+    // Clear from row 3 to row 17. After this, we should only have cells at rows 0, 2 and 18.
+    clearRange(m_pDoc, ScRange(0, 3, 0, 0, 17, 0));
+
+    {
+        // Full range again.
+        pIter.reset(new ScColumnTextWidthIterator(*m_pDoc, aTopCell, MAXROW));
+        SCROW aRows[] = { 0, 2, 18 };
+        size_t n = SAL_N_ELEMENTS(aRows);
+        for (size_t i = 0; i < n; ++i, pIter->next())
+        {
+            CPPUNIT_ASSERT_MESSAGE("Cell expected, but not there.", pIter->hasCell());
+            CPPUNIT_ASSERT_EQUAL(aRows[i], pIter->getPos());
+        }
+        CPPUNIT_ASSERT_MESSAGE("Iterator should have ended.", !pIter->hasCell());
+    }
+
+    m_pDoc->DeleteTab(0);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }
diff --git a/sc/source/core/data/columniterator.cxx b/sc/source/core/data/columniterator.cxx
index 31298bc..24b8c05 100644
--- a/sc/source/core/data/columniterator.cxx
+++ b/sc/source/core/data/columniterator.cxx
@@ -9,6 +9,8 @@
 
 #include "columniterator.hxx"
 #include "column.hxx"
+#include "document.hxx"
+#include "table.hxx"
 
 ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow) :
     mrTextWidths(rCol.maTextWidths),
@@ -17,58 +19,17 @@ ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStar
     miBlockCur(mrTextWidths.begin()),
     miBlockEnd(mrTextWidths.end())
 {
-    if (!ValidRow(nStartRow) || !ValidRow(nEndRow))
-        miBlockCur = miBlockEnd;
-
-    size_t nStart = static_cast<size_t>(nStartRow);
-
-    // Locate the start row position.
-    size_t nBlockStart = 0, nBlockEnd = 0;
-    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
-    {
-        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
-        if (nBlockStart <= nStart && nStart < nBlockEnd)
-        {
-            // Initial block is found!
-            break;
-        }
-    }
-
-    if (miBlockCur == miBlockEnd)
-        // Initial block not found for whatever reason... Bail out.
-        return;
-
-    // Locate the initial row position within this block.
-    if (miBlockCur->type == mdds::mtv::element_type_ushort)
-    {
-        // This block stores text widths for non-empty cells.
-        size_t nOffsetInBlock = nStart - nBlockStart;
-        mnCurPos = nStart;
-        getDataIterators(nOffsetInBlock);
-        checkEndRow();
-        return;
-    }
-
-    // Current block is not of ushort type.  Skip to the next block.
-    nBlockStart = nBlockEnd;
-    ++miBlockCur;
-
-    // Look for the first ushort block.
-    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
-    {
-        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
-        if (miBlockCur->type != mdds::mtv::element_type_ushort)
-            continue;
-
-        // Found!
-        mnCurPos = nBlockStart;
-        getDataIterators(0);
-        checkEndRow();
-        return;
-    }
+    init(nStartRow, nEndRow);
+}
 
-    // Not found.
-    OSL_ASSERT(miBlockCur == miBlockEnd);
+ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScDocument& rDoc, const ScAddress& rStartPos, SCROW nEndRow) :
+    mrTextWidths(rDoc.maTabs[rStartPos.Tab()]->aCol[rStartPos.Col()].maTextWidths),
+    mnEnd(static_cast<size_t>(nEndRow)),
+    mnCurPos(0),
+    miBlockCur(mrTextWidths.begin()),
+    miBlockEnd(mrTextWidths.end())
+{
+    init(rStartPos.Row(), nEndRow);
 }
 
 void ScColumnTextWidthIterator::next()
@@ -125,6 +86,62 @@ void ScColumnTextWidthIterator::setValue(sal_uInt16 nVal)
     *miDataCur = nVal;
 }
 
+void ScColumnTextWidthIterator::init(SCROW nStartRow, SCROW nEndRow)
+{
+    if (!ValidRow(nStartRow) || !ValidRow(nEndRow))
+        miBlockCur = miBlockEnd;
+
+    size_t nStart = static_cast<size_t>(nStartRow);
+
+    // Locate the start row position.
+    size_t nBlockStart = 0, nBlockEnd = 0;
+    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
+    {
+        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
+        if (nBlockStart <= nStart && nStart < nBlockEnd)
+        {
+            // Initial block is found!
+            break;
+        }
+    }
+
+    if (miBlockCur == miBlockEnd)
+        // Initial block not found for whatever reason... Bail out.
+        return;
+
+    // Locate the initial row position within this block.
+    if (miBlockCur->type == mdds::mtv::element_type_ushort)
+    {
+        // This block stores text widths for non-empty cells.
+        size_t nOffsetInBlock = nStart - nBlockStart;
+        mnCurPos = nStart;
+        getDataIterators(nOffsetInBlock);
+        checkEndRow();
+        return;
+    }
+
+    // Current block is not of ushort type.  Skip to the next block.
+    nBlockStart = nBlockEnd;
+    ++miBlockCur;
+
+    // Look for the first ushort block.
+    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
+    {
+        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
+        if (miBlockCur->type != mdds::mtv::element_type_ushort)
+            continue;
+
+        // Found!
+        mnCurPos = nBlockStart;
+        getDataIterators(0);
+        checkEndRow();
+        return;
+    }
+
+    // Not found.
+    OSL_ASSERT(miBlockCur == miBlockEnd);
+}
+
 void ScColumnTextWidthIterator::getDataIterators(size_t nOffsetInBlock)
 {
     OSL_ENSURE(miBlockCur != miBlockEnd, "block is at end position");
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index acce598..a73cd60 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -5695,6 +5695,15 @@ void ScDocument::SetSubTotalCellsDirty(const ScRange& rDirtyRange)
     maSubTotalCells.swap(aNewSet); // update the list.
 }
 
+sal_uInt16 ScDocument::GetTextWidth( const ScAddress& rPos ) const
+{
+    SCTAB nTab = rPos.Tab();
+    if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
+        return maTabs[nTab]->GetTextWidth(rPos.Col(), rPos.Row());
+
+    return 0;
+}
+
 void ScDocument::SetTextWidth( const ScAddress& rPos, sal_uInt16 nWidth )
 {
     SCTAB nTab = rPos.Tab();
commit e9a52f1591912ce8527da863f741625de5a2b4ff
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 23:55:48 2013 -0400

    Move TEXTWIDTH_DIRTH to globalnames.hxx.
    
    Change-Id: I648da6f2c43a10137c0834659022296883368dc9

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 5fbfb0b..214fa2d 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -38,7 +38,6 @@
 #include "scdllapi.h"
 
 #define USE_MEMPOOL
-#define TEXTWIDTH_DIRTY     0xffff
 
 // in addition to SCRIPTTYPE_... flags from scripttypeitem.hxx:
 // set (in nScriptType) if type has not been determined yet
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 0a699d3..93ae44f 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -84,6 +84,9 @@ class ScColumn
 {
     typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
 
+    // 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;
 
     SCCOL           nCol;
diff --git a/sc/inc/globalnames.hxx b/sc/inc/globalnames.hxx
index 33ac520..4fee471 100644
--- a/sc/inc/globalnames.hxx
+++ b/sc/inc/globalnames.hxx
@@ -34,6 +34,8 @@
 
 #define STR_GLOBAL_RANGE_NAME "__Global_Range_Name__"
 
+#define TEXTWIDTH_DIRTY 0xffff
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx
index bc6367c..0b990a8 100644
--- a/sc/source/core/data/cell.cxx
+++ b/sc/source/core/data/cell.cxx
@@ -40,6 +40,7 @@
 #include "externalrefmgr.hxx"
 #include "macromgr.hxx"
 #include "dbdata.hxx"
+#include "globalnames.hxx"
 
 #include <editeng/editobj.hxx>
 #include <svl/intitem.hxx>
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 6082ed6..682afc6 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -29,6 +29,7 @@
 #include "markdata.hxx"
 #include "detfunc.hxx"          // for Notes in Sort/Swap
 #include "postit.hxx"
+#include "globalnames.hxx"
 
 #include <svl/poolcach.hxx>
 #include <svl/zforlist.hxx>
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 5054a81..57b5370 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -44,6 +44,7 @@
 #include "postit.hxx"
 #include "stringutil.hxx"
 #include "docpool.hxx"
+#include "globalnames.hxx"
 
 #include <com/sun/star/i18n/LocaleDataItem.hpp>
 
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 9b9fecc..7c782f3 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -86,6 +86,7 @@
 #include "docuno.hxx"
 #include "scresid.hxx"
 #include "columniterator.hxx"
+#include "globalnames.hxx"
 
 #include <memory>
 #include <boost/scoped_ptr.hpp>
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index be34e51..b50380a 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -44,6 +44,7 @@
 #include "dbdata.hxx"
 #include "colorscale.hxx"
 #include "conditio.hxx"
+#include "globalnames.hxx"
 
 #include <vector>
 
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 355d2f1..1525371 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -37,6 +37,7 @@
 #include "globstr.hrc"
 #include "segmenttree.hxx"
 #include "columniterator.hxx"
+#include "globalnames.hxx"
 
 #include <com/sun/star/sheet/TablePageBreakData.hpp>
 
commit cf82be72950eeea9a3de89154c3412adbed5bd56
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 23:30:32 2013 -0400

    We should exit the idle calc when the sheet changes.
    
    Otherwise the code would end up in an undefined state.
    
    Change-Id: I47f58698ac1eb94bf92ab7278bb7521d892ba340

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 6684d32..9b9fecc 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -664,7 +664,10 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                     pColIter.reset(new ScColumnTextWidthIterator(*pCol, aScope.Row(), MAXROW));
                 }
                 else
+                {
                     aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
+                    return false;
+                }
             }
         }
 
commit 7a13e3dc20908bad26b65606ce6efbfeb97fca55
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 23:26:27 2013 -0400

    ScBaseCell::nTextWidth is no more.
    
    Change-Id: I32368d39a21d44bef8ab7fe265077cd147a50024

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index c84e985..5fbfb0b 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -101,10 +101,6 @@ public:
         Returns false for formula cells returning nothing, use HasEmptyData() for that. */
     bool            IsBlank() const;
 
-// for idle-calculations
-    inline sal_uInt16   GetTextWidth() const { return nTextWidth; }
-    inline void     SetTextWidth( sal_uInt16 nNew ) { nTextWidth = nNew; }
-
     inline sal_uInt8     GetScriptType() const { return nScriptType; }
     inline void     SetScriptType( sal_uInt8 nNew ) { nScriptType = nNew; }
 
@@ -148,7 +144,6 @@ private:
     SvtBroadcaster* mpBroadcaster;  /// Broadcaster for changed values. Cell takes ownership!
 
 protected:
-    sal_uInt16          nTextWidth;
     sal_uInt8            eCellType;      // enum CellType - sal_uInt8 spart Speicher
     sal_uInt8            nScriptType;
 };
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8c3fac2..2f59ef1 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1844,6 +1844,8 @@ public:
     void RemoveSubTotalCell(ScFormulaCell* pCell);
     void SetSubTotalCellsDirty(const ScRange& rDirtyRange);
 
+    void SetTextWidth( const ScAddress& rPos, sal_uInt16 nWidth );
+
 private: // CLOOK-Impl-methods
 
     /**
diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx
index 5ffd85e..bc6367c 100644
--- a/sc/source/core/data/cell.cxx
+++ b/sc/source/core/data/cell.cxx
@@ -69,7 +69,6 @@ IMPL_FIXEDMEMPOOL_NEWDEL( ScNoteCell )
 
 ScBaseCell::ScBaseCell( CellType eNewType ) :
     mpBroadcaster( 0 ),
-    nTextWidth( TEXTWIDTH_DIRTY ),
     eCellType( sal::static_int_cast<sal_uInt8>(eNewType) ),
     nScriptType( SC_SCRIPTTYPE_UNKNOWN )
 {
@@ -77,7 +76,6 @@ ScBaseCell::ScBaseCell( CellType eNewType ) :
 
 ScBaseCell::ScBaseCell( const ScBaseCell& rCell ) :
     mpBroadcaster( 0 ),
-    nTextWidth( rCell.nTextWidth ),
     eCellType( rCell.eCellType ),
     nScriptType( SC_SCRIPTTYPE_UNKNOWN )
 {
@@ -1002,7 +1000,7 @@ void ScFormulaCell::Compile( const rtl::OUString& rFormula, bool bNoListening,
     else
     {
         bChanged = true;
-        SetTextWidth( TEXTWIDTH_DIRTY );
+        pDocument->SetTextWidth(aPos, TEXTWIDTH_DIRTY);
         SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
     }
     if ( bWasInFormulaTree )
@@ -1096,7 +1094,7 @@ void ScFormulaCell::CompileXML( ScProgress& rProgress )
     else
     {
         bChanged = true;
-        SetTextWidth( TEXTWIDTH_DIRTY );
+        pDocument->SetTextWidth(aPos, TEXTWIDTH_DIRTY);
         SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
     }
 
@@ -1367,7 +1365,7 @@ void ScFormulaCell::Interpret()
                             pIterCell->bTableOpDirty = false;
                             pIterCell->aResult.SetResultError( errNoConvergence);
                             pIterCell->bChanged = true;
-                            pIterCell->SetTextWidth( TEXTWIDTH_DIRTY);
+                            pDocument->SetTextWidth(pIterCell->aPos, TEXTWIDTH_DIRTY);
                             pIterCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN);
                         }
                     }
@@ -1662,7 +1660,7 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
         }
         if( bChanged )
         {
-            SetTextWidth( TEXTWIDTH_DIRTY );
+            pDocument->SetTextWidth(aPos, TEXTWIDTH_DIRTY);
             SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
         }
         if (bContentChanged && pDocument->IsStreamValid(aPos.Tab()))
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 8cfc787..acce598 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -5695,6 +5695,13 @@ void ScDocument::SetSubTotalCellsDirty(const ScRange& rDirtyRange)
     maSubTotalCells.swap(aNewSet); // update the list.
 }
 
+void ScDocument::SetTextWidth( const ScAddress& rPos, sal_uInt16 nWidth )
+{
+    SCTAB nTab = rPos.Tab();
+    if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
+        maTabs[nTab]->SetTextWidth(rPos.Col(), rPos.Row(), nWidth);
+}
+
 void ScDocument::EnableUndo( bool bVal )
 {
     // The undo manager increases lock count every time undo is disabled.
commit bcc703f2b6bdfd1321f2599faa51e387c9ad3174
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 23:04:20 2013 -0400

    MaybeAddExtraColumn() too.  This one is trivial.
    
    Change-Id: I0cd33c90bdb3c6b7cf48677140e3c66fa78caaba

diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index caf858f..be34e51 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1751,7 +1751,7 @@ void ScTable::MaybeAddExtraColumn(SCCOL& rCol, SCROW nRow, OutputDevice* pDev, d
         return;
 
     bool bFormula = false;  //! ueberge
-    long nPixel = pCell->GetTextWidth();
+    long nPixel = aCol[rCol].GetTextWidth(nRow);
 
     // Breite bereits im Idle-Handler berechnet?
     if ( TEXTWIDTH_DIRTY == nPixel )
@@ -1764,7 +1764,8 @@ void ScTable::MaybeAddExtraColumn(SCCOL& rCol, SCROW nRow, OutputDevice* pDev, d
         Fraction aZoom(1,1);
         nPixel = aCol[rCol].GetNeededSize(
             nRow, pDev, nPPTX, nPPTY, aZoom, aZoom, true, aOptions );
-        pCell->SetTextWidth( (sal_uInt16)nPixel );
+
+        aCol[rCol].SetTextWidth(nRow, static_cast<sal_uInt16>(nPixel));
     }
 
     long nTwips = (long) (nPixel / nPPTX);
commit 63ee16274ba64c803e38a3bfba6e5fc9e9d772b6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 22:59:38 2013 -0400

    InvalidateTextWidth() now uses the new iterator.
    
    No more SetTextWidth() directly to the cells.
    
    Change-Id: I0a2aba63685ea1461b763e8d628052ecd4c71c25

diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 74af647..355d2f1 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -36,6 +36,8 @@
 #include "tabprotection.hxx"
 #include "globstr.hrc"
 #include "segmenttree.hxx"
+#include "columniterator.hxx"
+
 #include <com/sun/star/sheet/TablePageBreakData.hpp>
 
 #include <algorithm>
@@ -1145,20 +1147,64 @@ void ScTable::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* p
 {
     if ( pAdrFrom && !pAdrTo )
     {
-        ScBaseCell* pCell = aCol[pAdrFrom->Col()].GetCell( pAdrFrom->Row() );
-        if ( pCell )
+        // Special case: only process the "from" cell.
+        SCCOL nCol = pAdrFrom->Col();
+        SCROW nRow = pAdrFrom->Row();
+        ScColumn& rCol = aCol[nCol];
+        ScBaseCell* pCell = rCol.GetCell(nRow);
+        if (!pCell)
+            return;
+
+        rCol.SetTextWidth(nRow, TEXTWIDTH_DIRTY);
+
+        if ( bNumFormatChanged )
+            pCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
+
+        if ( bBroadcast )
+        {   // nur bei CalcAsShown
+            switch ( pCell->GetCellType() )
+            {
+                case CELLTYPE_VALUE :
+                    pDocument->Broadcast(SC_HINT_DATACHANGED, ScAddress(nCol, nRow, nTab), pCell);
+                    break;
+                case CELLTYPE_FORMULA :
+                    ((ScFormulaCell*)pCell)->SetDirty();
+                    break;
+                default:
+                {
+                    // added to avoid warnings
+                }
+            }
+        }
+
+        return;
+    }
+
+    const SCCOL nCol1 = pAdrFrom ? pAdrFrom->Col() : 0;
+    const SCROW nRow1 = pAdrFrom ? pAdrFrom->Row() : 0;
+    const SCCOL nCol2 = pAdrTo   ? pAdrTo->Col()   : MAXCOL;
+    const SCROW nRow2 = pAdrTo   ? pAdrTo->Row()   : MAXROW;
+
+    for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+    {
+        ScColumnTextWidthIterator aIter(aCol[nCol], nRow1, nRow2);
+
+        for (; aIter.hasCell(); aIter.next())
         {
-            pCell->SetTextWidth( TEXTWIDTH_DIRTY );
+            SCROW nRow = aIter.getPos();
+            aIter.setValue(TEXTWIDTH_DIRTY);
+            ScBaseCell* pCell = aCol[nCol].GetCell(nRow);
+
             if ( bNumFormatChanged )
                 pCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
+
             if ( bBroadcast )
             {   // nur bei CalcAsShown
                 switch ( pCell->GetCellType() )
                 {
                     case CELLTYPE_VALUE :
                         pDocument->Broadcast( SC_HINT_DATACHANGED,
-                            ScAddress( pAdrFrom->Col(), pAdrFrom->Row(), nTab ),
-                            pCell );
+                            ScAddress( nCol, nRow, nTab ), pCell );
                         break;
                     case CELLTYPE_FORMULA :
                         ((ScFormulaCell*)pCell)->SetDirty();
@@ -1171,44 +1217,6 @@ void ScTable::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* p
             }
         }
     }
-    else
-    {
-        const SCCOL nColStart = pAdrFrom ? pAdrFrom->Col() : 0;
-        const SCROW nRowStart = pAdrFrom ? pAdrFrom->Row() : 0;
-        const SCCOL nColEnd   = pAdrTo   ? pAdrTo->Col()   : MAXCOL;
-        const SCROW nRowEnd   = pAdrTo   ? pAdrTo->Row()   : MAXROW;
-
-        for ( SCCOL nCol=nColStart; nCol<=nColEnd; nCol++ )
-        {
-            ScColumnIterator aIter( &aCol[nCol], nRowStart, nRowEnd );
-            ScBaseCell*      pCell = NULL;
-            SCROW            nRow  = nRowStart;
-
-            while ( aIter.Next( nRow, pCell ) )
-            {
-                pCell->SetTextWidth( TEXTWIDTH_DIRTY );
-                if ( bNumFormatChanged )
-                    pCell->SetScriptType( SC_SCRIPTTYPE_UNKNOWN );
-                if ( bBroadcast )
-                {   // nur bei CalcAsShown
-                    switch ( pCell->GetCellType() )
-                    {
-                        case CELLTYPE_VALUE :
-                            pDocument->Broadcast( SC_HINT_DATACHANGED,
-                                ScAddress( nCol, nRow, nTab ), pCell );
-                            break;
-                        case CELLTYPE_FORMULA :
-                            ((ScFormulaCell*)pCell)->SetDirty();
-                            break;
-                        default:
-                        {
-                            // added to avoid warnings
-                        }
-                    }
-                }
-            }
-        }
-    }
 }
 
 
commit d4d282e342a014f0416b7d4b725d918558dab18d
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 22:54:14 2013 -0400

    Forgot to increment the iterator.
    
    Change-Id: Ica8c9be8a383879a509d90c6da6309d2eee4fe8c

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index e9bf545..6684d32 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -604,6 +604,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                 pColIter->setValue(nNewWidth);
                 aScope.setNeedMore(true);
             }
+            pColIter->next();
         }
         else
         {
commit f4c54749cfeca8703c8335a7310dbed24e8a9cf5
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 22:34:23 2013 -0400

    IdleCalcTextWidth() now sets cell text widths to the new container.
    
    No more direct access to ScBaseCell's nTextWidth.
    
    Change-Id: I5a0a5fd24555d9fa8e1de895f0f9d8b710cc8094

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index f1996f1..0a699d3 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -244,6 +244,8 @@ public:
     bool    HasValueData( SCROW nRow ) const;
     bool    HasStringCells( SCROW nStartRow, SCROW nEndRow ) const;
 
+    bool IsFormulaDirty( SCROW nRow ) const;
+
     void        SetDirty();
     void        SetDirty( const ScRange& );
     void        SetDirtyVar();
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index e81456d..6082ed6 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2008,6 +2008,23 @@ void ScColumn::SetDirtyVar()
     }
 }
 
+bool ScColumn::IsFormulaDirty( SCROW nRow ) const
+{
+    if (!ValidRow(nRow))
+        return false;
+
+    SCSIZE nIndex;
+    if (!Search(nRow, nIndex))
+        // No cell at this row position.
+        return false;
+
+    const ScBaseCell* pCell = maItems[nIndex].pCell;
+    if (pCell->GetCellType() != CELLTYPE_FORMULA)
+        // Not even a formula cell.
+        return false;
+
+    return static_cast<const ScFormulaCell*>(pCell)->GetDirty();
+}
 
 void ScColumn::SetDirty()
 {
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 263dc74..e9bf545 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -495,6 +495,8 @@ public:
     SCCOL Col() const { return mrCalcPos.Col(); }
     SCROW Row() const { return mrCalcPos.Row(); }
 
+    const ScAddress& Pos() const { return mrCalcPos; }
+
     void setTab(SCTAB nTab) { mrCalcPos.SetTab(nTab); }
     void setCol(SCCOL nCol) { mrCalcPos.SetCol(nCol); }
     void setRow(SCROW nRow) { mrCalcPos.SetRow(nRow); }
@@ -563,21 +565,20 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
     // Start at specified cell position (nCol, nRow, nTab).
     ScColumn* pCol  = &pTab->aCol[aScope.Col()];
-    boost::scoped_ptr<ScColumnIterator> pColIter(new ScColumnIterator(pCol, aScope.Row(), MAXROW));
+    boost::scoped_ptr<ScColumnTextWidthIterator> pColIter(new ScColumnTextWidthIterator(*pCol, aScope.Row(), MAXROW));
 
     OutputDevice* pDev = NULL;
     sal_uInt16 nRestart = 0;
     sal_uInt16 nCount = 0;
     while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
     {
-        SCROW nRow;
-        ScBaseCell* pCell = NULL;
-        if ( pColIter->Next(nRow, pCell) )
+        if (pColIter->hasCell())
         {
             // More cell in this column.
+            SCROW nRow = pColIter->getPos();
             aScope.setRow(nRow);
 
-            if ( TEXTWIDTH_DIRTY == pCell->GetTextWidth() )
+            if (pColIter->getValue() == TEXTWIDTH_DIRTY)
             {
                 // Calculate text width for this cell.
                 double nPPTX = 0.0;
@@ -593,17 +594,14 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                     nPPTY = aPix1000.Y() / 1000.0;
                 }
 
-                if (!aScope.hasProgressBar() && pCell->GetCellType() == CELLTYPE_FORMULA
-                    && ((ScFormulaCell*)pCell)->GetDirty())
-                {
+                if (!aScope.hasProgressBar() && pCol->IsFormulaDirty(nRow))
                     aScope.createProgressBar();
-                }
 
                 sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize(
                     aScope.Col(), aScope.Row(), aScope.Tab(),
                     pDev, nPPTX, nPPTY, aZoomFract,aZoomFract, true, true);   // bTotalSize
 
-                pCell->SetTextWidth( nNewWidth );
+                pColIter->setValue(nNewWidth);
                 aScope.setNeedMore(true);
             }
         }
@@ -662,14 +660,14 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                 if ( nZoom > 0 )
                 {
                     pCol  = &pTab->aCol[aScope.Col()];
-                    pColIter.reset(new ScColumnIterator(pCol, aScope.Row(), MAXROW));
+                    pColIter.reset(new ScColumnTextWidthIterator(*pCol, aScope.Row(), MAXROW));
                 }
                 else
                     aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
             }
         }
 
-        nCount++;
+        ++nCount;
 
         // Quit if either 1) its duration exceeds 50 ms, or 2) there is any
         // pending event after processing 32 cells.
commit 8945bddcc9294dc839e046d2d8b6c6dabd8caeb9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 21:13:14 2013 -0400

    First cut on column text width iterator implementation. Untested.
    
    Change-Id: Ic615e5645f1a89a4b1a60dc519eb79ff921203a9

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index acaede3..f1996f1 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -61,7 +61,7 @@ struct ScMergePatternState;
 class ScFlatBoolRowSegments;
 struct ScSetStringParam;
 struct ScColWidthParam;
-struct ScColumnImpl;
+class ScColumnTextWidthIterator;
 
 struct ScNeededSizeOptions
 {
diff --git a/sc/inc/columniterator.hxx b/sc/inc/columniterator.hxx
index b8f8f59..a70567c56 100644
--- a/sc/inc/columniterator.hxx
+++ b/sc/inc/columniterator.hxx
@@ -10,13 +10,36 @@
 #ifndef __SC_COLUMNITERATOR_HXX__
 #define __SC_COLUMNITERATOR_HXX__
 
+#include <boost/noncopyable.hpp>
+
+#include "column.hxx"
+
 class ScColumn;
 
-class ScColumnTextWidthIterator
+class ScColumnTextWidthIterator : boost::noncopyable
 {
-    ScColumn& mrCol;
+    typedef ScColumn::TextWidthType TextWidthType;
+
+    TextWidthType& mrTextWidths;
+    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;
+
 public:
-    ScColumnTextWidthIterator(ScColumn& rCol);
+    ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow);
+
+    void next();
+    bool hasCell() const;
+    SCROW getPos() const;
+    sal_uInt16 getValue() const;
+    void setValue(sal_uInt16 nVal);
+
+private:
+    void getDataIterators(size_t nOffsetInBlock);
+    void checkEndRow();
 };
 
 #endif
diff --git a/sc/source/core/data/columniterator.cxx b/sc/source/core/data/columniterator.cxx
index 289c194..31298bc 100644
--- a/sc/source/core/data/columniterator.cxx
+++ b/sc/source/core/data/columniterator.cxx
@@ -10,7 +10,141 @@
 #include "columniterator.hxx"
 #include "column.hxx"
 
-ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol) :
-    mrCol(rCol) {}
+ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol, SCROW nStartRow, SCROW nEndRow) :
+    mrTextWidths(rCol.maTextWidths),
+    mnEnd(static_cast<size_t>(nEndRow)),
+    mnCurPos(0),
+    miBlockCur(mrTextWidths.begin()),
+    miBlockEnd(mrTextWidths.end())
+{
+    if (!ValidRow(nStartRow) || !ValidRow(nEndRow))
+        miBlockCur = miBlockEnd;
+
+    size_t nStart = static_cast<size_t>(nStartRow);
+
+    // Locate the start row position.
+    size_t nBlockStart = 0, nBlockEnd = 0;
+    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
+    {
+        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
+        if (nBlockStart <= nStart && nStart < nBlockEnd)
+        {
+            // Initial block is found!
+            break;
+        }
+    }
+
+    if (miBlockCur == miBlockEnd)
+        // Initial block not found for whatever reason... Bail out.
+        return;
+
+    // Locate the initial row position within this block.
+    if (miBlockCur->type == mdds::mtv::element_type_ushort)
+    {
+        // This block stores text widths for non-empty cells.
+        size_t nOffsetInBlock = nStart - nBlockStart;
+        mnCurPos = nStart;
+        getDataIterators(nOffsetInBlock);
+        checkEndRow();
+        return;
+    }
+
+    // Current block is not of ushort type.  Skip to the next block.
+    nBlockStart = nBlockEnd;
+    ++miBlockCur;
+
+    // Look for the first ushort block.
+    for (; miBlockCur != miBlockEnd; ++miBlockCur, nBlockStart = nBlockEnd)
+    {
+        nBlockEnd = nBlockStart + miBlockCur->size; // non-inclusive end point.
+        if (miBlockCur->type != mdds::mtv::element_type_ushort)
+            continue;
+
+        // Found!
+        mnCurPos = nBlockStart;
+        getDataIterators(0);
+        checkEndRow();
+        return;
+    }
+
+    // Not found.
+    OSL_ASSERT(miBlockCur == miBlockEnd);
+}
+
+void ScColumnTextWidthIterator::next()
+{
+    ++miDataCur;
+    ++mnCurPos;
+
+    if (miDataCur != miDataEnd)
+    {
+        // Stil in the same block. We're good.
+        checkEndRow();
+        return;
+    }
+
+    // Move to the next block.
+    for (++miBlockCur; miBlockCur != miBlockEnd; ++miBlockCur)
+    {
+        if (miBlockCur->type != mdds::mtv::element_type_ushort)
+        {
+            // We don't iterator over this block.
+            mnCurPos += miBlockCur->size;
+            continue;
+        }
+
+        getDataIterators(0);
+        checkEndRow();
+        return;
+    }
+
+    // Reached the end.
+    OSL_ASSERT(miBlockCur == miBlockEnd);
+}
+
+bool ScColumnTextWidthIterator::hasCell() const
+{
+    return miBlockCur != miBlockEnd;
+}
+
+SCROW ScColumnTextWidthIterator::getPos() const
+{
+    OSL_ASSERT(miBlockCur != miBlockEnd && miDataCur != miDataEnd);
+    return static_cast<SCROW>(mnCurPos);
+}
+
+sal_uInt16 ScColumnTextWidthIterator::getValue() const
+{
+    OSL_ASSERT(miBlockCur != miBlockEnd && miDataCur != miDataEnd);
+    return *miDataCur;
+}
+
+void ScColumnTextWidthIterator::setValue(sal_uInt16 nVal)
+{
+    OSL_ASSERT(miBlockCur != miBlockEnd && miDataCur != miDataEnd);
+    *miDataCur = nVal;
+}
+
+void ScColumnTextWidthIterator::getDataIterators(size_t nOffsetInBlock)
+{
+    OSL_ENSURE(miBlockCur != miBlockEnd, "block is at end position");
+    OSL_ENSURE(miBlockCur->type == mdds::mtv::element_type_ushort,
+               "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);
+
+    std::advance(miDataCur, nOffsetInBlock);
+}
+
+void ScColumnTextWidthIterator::checkEndRow()
+{
+    if (mnCurPos <= mnEnd)
+        // We're still good.
+        return;
+
+    // We're below the end position. End the iteration.
+    miBlockCur = miBlockEnd;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index bceb8c8..263dc74 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -85,6 +85,7 @@
 #include "dpobject.hxx"
 #include "docuno.hxx"
 #include "scresid.hxx"
+#include "columniterator.hxx"
 
 #include <memory>
 #include <boost/scoped_ptr.hpp>
commit b086f0fa026a5bc794832e8457833379036e5440
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 16:43:48 2013 -0400

    Add skeleton files for the new iterator for column cells' text widths.
    
    To be implemented soon.
    
    Change-Id: Ifa72245f89635ac604c233197891fb67c8d99915

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index b72deec..0295e74 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -104,6 +104,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/data/column \
 	sc/source/core/data/column2 \
 	sc/source/core/data/column3 \
+	sc/source/core/data/columniterator \
 	sc/source/core/data/compressedarray \
 	sc/source/core/data/colorscale \
 	sc/source/core/data/conditio \
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 0fbd743..acaede3 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -94,6 +94,7 @@ class ScColumn
     ScAttrArray*       pAttrArray;
     ScDocument*                pDocument;
 
+friend class ScColumnTextWidthIterator;
 friend class ScDocument;                                       // for FillInfo
 friend class ScDocumentIterator;
 friend class ScValueIterator;
diff --git a/sc/inc/columniterator.hxx b/sc/inc/columniterator.hxx
new file mode 100644
index 0000000..b8f8f59
--- /dev/null
+++ b/sc/inc/columniterator.hxx
@@ -0,0 +1,24 @@
+/* -*- 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/.
+ */
+
+#ifndef __SC_COLUMNITERATOR_HXX__
+#define __SC_COLUMNITERATOR_HXX__
+
+class ScColumn;
+
+class ScColumnTextWidthIterator
+{
+    ScColumn& mrCol;
+public:
+    ScColumnTextWidthIterator(ScColumn& rCol);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/columniterator.cxx b/sc/source/core/data/columniterator.cxx
new file mode 100644
index 0000000..289c194
--- /dev/null
+++ b/sc/source/core/data/columniterator.cxx
@@ -0,0 +1,16 @@
+/* -*- 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 "columniterator.hxx"
+#include "column.hxx"
+
+ScColumnTextWidthIterator::ScColumnTextWidthIterator(ScColumn& rCol) :
+    mrCol(rCol) {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1748c6896cfa96f5cfbe090df9f9bbf347848dd6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 16:37:20 2013 -0400

    Some renaming of local variables...
    
    Change-Id: I27b5512d90eba0c0235d11d1b4f1c9cafc4bcce6

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 6b50d12..bceb8c8 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -545,8 +545,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()])
         aScope.setTab(0);
 
-    ScTable* pTable = maTabs[aScope.Tab()];
-    ScStyleSheet* pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
+    ScTable* pTab = maTabs[aScope.Tab()];
+    ScStyleSheet* pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTab->aPageStyle, SFX_STYLE_FAMILY_PAGE);
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
     if (!pStyle || getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
@@ -561,9 +561,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     Fraction aZoomFract(nZoom, 100);
 
     // Start at specified cell position (nCol, nRow, nTab).
-    ScColumn* pColumn  = &pTable->aCol[aScope.Col()];
-    boost::scoped_ptr<ScColumnIterator> pColIter(
-        new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
+    ScColumn* pCol  = &pTab->aCol[aScope.Col()];
+    boost::scoped_ptr<ScColumnIterator> pColIter(new ScColumnIterator(pCol, aScope.Row(), MAXROW));
 
     OutputDevice* pDev = NULL;
     sal_uInt16 nRestart = 0;
@@ -582,7 +581,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                 // Calculate text width for this cell.
                 double nPPTX = 0.0;
                 double nPPTY = 0.0;
-                if ( !pDev )
+                if (!pDev)
                 {
                     pDev = GetPrinter();
                     aScope.setOldMapMode(pDev->GetMapMode());
@@ -636,9 +635,9 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
             {
                 if ( bNewTab )
                 {
-                    pTable = maTabs[aScope.Tab()];
+                    pTab = maTabs[aScope.Tab()];
                     pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(
-                        pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
+                        pTab->aPageStyle, SFX_STYLE_FAMILY_PAGE);
 
                     if ( pStyle )
                     {
@@ -661,8 +660,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
                 if ( nZoom > 0 )
                 {
-                    pColumn  = &pTable->aCol[aScope.Col()];
-                    pColIter.reset(new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
+                    pCol  = &pTab->aCol[aScope.Col()];
+                    pColIter.reset(new ScColumnIterator(pCol, aScope.Row(), MAXROW));
                 }
                 else
                     aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
commit 351536e40a6c822d95a87d851f5d3cce829e69a7
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 15:48:08 2013 -0400

    Reduce scope level.
    
    Change-Id: I28db9130864ac3408398834bfbbdeb904ca4948e

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 9ac10a7..6b50d12 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -549,131 +549,133 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     ScStyleSheet* pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
-    if (pStyle && 0 == getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES))
+    if (!pStyle || getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
     {
-        sal_uInt16 nRestart = 0;
-        sal_uInt16 nCount = 0;
-        ScBaseCell* pCell = NULL;
+        // Move to the next sheet as the current one has scale-to-pages set,
+        // and bail out.
+        aScope.incTab();
+        return false;
+    }
 
-        sal_uInt16 nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
-        Fraction aZoomFract( nZoom, 100 );
+    sal_uInt16 nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
+    Fraction aZoomFract(nZoom, 100);
 
-        // Start at specified cell position (nCol, nRow, nTab).
-        ScColumn* pColumn  = &pTable->aCol[aScope.Col()];
-        boost::scoped_ptr<ScColumnIterator> pColIter(
-            new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
+    // Start at specified cell position (nCol, nRow, nTab).
+    ScColumn* pColumn  = &pTable->aCol[aScope.Col()];
+    boost::scoped_ptr<ScColumnIterator> pColIter(
+        new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
 
-        OutputDevice* pDev = NULL;
-        while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
+    OutputDevice* pDev = NULL;
+    sal_uInt16 nRestart = 0;
+    sal_uInt16 nCount = 0;
+    while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
+    {
+        SCROW nRow;
+        ScBaseCell* pCell = NULL;
+        if ( pColIter->Next(nRow, pCell) )
         {
-            SCROW nRow;
-            if ( pColIter->Next(nRow, pCell) )
-            {
-                // More cell in this column.
-                aScope.setRow(nRow);
+            // More cell in this column.
+            aScope.setRow(nRow);
 
-                if ( TEXTWIDTH_DIRTY == pCell->GetTextWidth() )
+            if ( TEXTWIDTH_DIRTY == pCell->GetTextWidth() )
+            {
+                // Calculate text width for this cell.
+                double nPPTX = 0.0;
+                double nPPTY = 0.0;
+                if ( !pDev )
                 {
-                    // Calculate text width for this cell.
-                    double nPPTX = 0.0;
-                    double nPPTY = 0.0;
-                    if ( !pDev )
-                    {
-                        pDev = GetPrinter();
-                        aScope.setOldMapMode(pDev->GetMapMode());
-                        pDev->SetMapMode( MAP_PIXEL );  // wichtig fuer GetNeededSize
+                    pDev = GetPrinter();
+                    aScope.setOldMapMode(pDev->GetMapMode());
+                    pDev->SetMapMode( MAP_PIXEL );  // wichtig fuer GetNeededSize
 
-                        Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
-                        nPPTX = aPix1000.X() / 1000.0;
-                        nPPTY = aPix1000.Y() / 1000.0;
-                    }
+                    Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
+                    nPPTX = aPix1000.X() / 1000.0;
+                    nPPTY = aPix1000.Y() / 1000.0;
+                }
 
-                    if (!aScope.hasProgressBar() && pCell->GetCellType() == CELLTYPE_FORMULA
-                        && ((ScFormulaCell*)pCell)->GetDirty())
-                    {
-                        aScope.createProgressBar();
-                    }
+                if (!aScope.hasProgressBar() && pCell->GetCellType() == CELLTYPE_FORMULA
+                    && ((ScFormulaCell*)pCell)->GetDirty())
+                {
+                    aScope.createProgressBar();
+                }
 
-                    sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize(
-                        aScope.Col(), aScope.Row(), aScope.Tab(),
-                        pDev, nPPTX, nPPTY, aZoomFract,aZoomFract, true, true);   // bTotalSize
+                sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize(
+                    aScope.Col(), aScope.Row(), aScope.Tab(),
+                    pDev, nPPTX, nPPTY, aZoomFract,aZoomFract, true, true);   // bTotalSize
 
-                    pCell->SetTextWidth( nNewWidth );
-                    aScope.setNeedMore(true);
-                }
+                pCell->SetTextWidth( nNewWidth );
+                aScope.setNeedMore(true);
             }
-            else
-            {
-                // No more cell in this column.  Move to the left column and start at row 0.
+        }
+        else
+        {
+            // No more cell in this column.  Move to the left column and start at row 0.
 
-                bool bNewTab = false;
+            bool bNewTab = false;
 
-                aScope.setRow(0);
-                aScope.incCol(-1);
+            aScope.setRow(0);
+            aScope.incCol(-1);
 
-                if (aScope.Col() < 0)
-                {
-                    // No more column to the left.  Move to the right-most column of the next sheet.
-                    aScope.setCol(MAXCOL);
-                    aScope.incTab();
-                    bNewTab = true;
-                }
+            if (aScope.Col() < 0)
+            {
+                // No more column to the left.  Move to the right-most column of the next sheet.
+                aScope.setCol(MAXCOL);
+                aScope.incTab();
+                bNewTab = true;
+            }
 
-                if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()] )
-                {
-                    // Sheet doesn't exist at specified sheet position.  Restart at sheet 0.
-                    aScope.setTab(0);
-                    nRestart++;
-                    bNewTab = true;
-                }
+            if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()] )
+            {
+                // Sheet doesn't exist at specified sheet position.  Restart at sheet 0.
+                aScope.setTab(0);
+                nRestart++;
+                bNewTab = true;
+            }
 
-                if ( nRestart < 2 )
+            if ( nRestart < 2 )
+            {
+                if ( bNewTab )
                 {
-                    if ( bNewTab )
-                    {
-                        pTable = maTabs[aScope.Tab()];
-                        pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(
-                            pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
+                    pTable = maTabs[aScope.Tab()];
+                    pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(
+                        pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
 
-                        if ( pStyle )
+                    if ( pStyle )
+                    {
+                        // Check if the scale-to-pages setting is set. If
+                        // set, we exit the loop.  If not, get the page
+                        // scale factor of the new sheet.
+                        if (getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
                         {
-                            // Check if the scale-to-pages setting is set. If
-                            // set, we exit the loop.  If not, get the page
-                            // scale factor of the new sheet.
-                            if (getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
-                            {
-                                nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
-                                aZoomFract = Fraction(nZoom, 100);
-                            }
-                            else
-                                nZoom = 0;
+                            nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
+                            aZoomFract = Fraction(nZoom, 100);
                         }
                         else
-                        {
-                            OSL_FAIL( "Missing StyleSheet :-/" );
-                        }
+                            nZoom = 0;
                     }
-
-                    if ( nZoom > 0 )
+                    else
                     {
-                        pColumn  = &pTable->aCol[aScope.Col()];
-                        pColIter.reset(new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
+                        OSL_FAIL( "Missing StyleSheet :-/" );
                     }
-                    else
-                        aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
                 }
+
+                if ( nZoom > 0 )
+                {
+                    pColumn  = &pTable->aCol[aScope.Col()];
+                    pColIter.reset(new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
+                }
+                else
+                    aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
             }
+        }
 
-            nCount++;
+        nCount++;
 
-            // Quit if either 1) its duration exceeds 50 ms, or 2) there is
-            // any pending event after processing 32 cells.
-            if ((50L < Time::GetSystemTicks() - aScope.getStartTime()) || (nCount > 31 && Application::AnyInput(ABORT_EVENTS)))
-                nCount = CALCMAX;
-        }
+        // Quit if either 1) its duration exceeds 50 ms, or 2) there is any
+        // pending event after processing 32 cells.
+        if ((50L < Time::GetSystemTicks() - aScope.getStartTime()) || (nCount > 31 && Application::AnyInput(ABORT_EVENTS)))
+            nCount = CALCMAX;
     }
-    else
-        aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
 
     return aScope.getNeedMore();
 }
commit df52ec007bb8e03be22caf5095ac214896ba2a73
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 15:33:41 2013 -0400

    A bit more re-organization.
    
    Change-Id: Ie722a910303ff8852c164ccc9ae256d52f4695f0

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 541e709..9ac10a7 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -87,6 +87,7 @@
 #include "scresid.hxx"
 
 #include <memory>
+#include <boost/scoped_ptr.hpp>
 
 //  states for online spelling in the visible range (0 is set initially)
 #define VSPL_START  0
@@ -529,11 +530,6 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
     IdleCalcTextWidthScope aScope(*this, aCurTextWidthCalcPos);
 
-    OutputDevice*       pDev     = NULL;
-    ScStyleSheet*       pStyle   = NULL;
-    ScColumnIterator*   pColIter = NULL;
-    ScTable*            pTable   = NULL;
-
     if (!ValidRow(aScope.Row()))
     {
         aScope.setRow(0);
@@ -549,9 +545,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()])
         aScope.setTab(0);
 
-    pTable = maTabs[aScope.Tab()];
-    pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
-
+    ScTable* pTable = maTabs[aScope.Tab()];
+    ScStyleSheet* pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
     if (pStyle && 0 == getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES))
@@ -565,8 +560,10 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
         // Start at specified cell position (nCol, nRow, nTab).
         ScColumn* pColumn  = &pTable->aCol[aScope.Col()];
-        pColIter = new ScColumnIterator(pColumn, aScope.Row(), MAXROW);
+        boost::scoped_ptr<ScColumnIterator> pColIter(
+            new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
 
+        OutputDevice* pDev = NULL;
         while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
         {
             SCROW nRow;
@@ -659,10 +656,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
                     if ( nZoom > 0 )
                     {
-                        delete pColIter;
-
                         pColumn  = &pTable->aCol[aScope.Col()];
-                        pColIter = new ScColumnIterator( pColumn, aScope.Row(), MAXROW );
+                        pColIter.reset(new ScColumnIterator(pColumn, aScope.Row(), MAXROW));
                     }
                     else
                         aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
@@ -680,8 +675,6 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     else
         aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
 
-    delete pColIter;
-
     return aScope.getNeedMore();
 }
 
commit 09b4e76d028686aad1a36830c71398b758121c74
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 15:22:50 2013 -0400

    Move the style sheet pool handling too.
    
    Change-Id: Ia24e2effa8d6200eb0e9ad5e30fb5c9a4d8dd670

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index e6d1e38..541e709 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -449,10 +449,11 @@ class IdleCalcTextWidthScope
 {
     ScDocument& mrDoc;
     ScAddress& mrCalcPos;
-    sal_uInt16 mnOldSearchMask;
-    SfxStyleFamily meOldFamily;
     MapMode maOldMapMode;
     sal_uLong mnStartTime;
+    ScStyleSheetPool* mpStylePool;
+    sal_uInt16 mnOldSearchMask;
+    SfxStyleFamily meOldFamily;
     bool mbNeedMore;
     bool mbProgress;
 
@@ -461,17 +462,18 @@ public:
         mrDoc(rDoc),
         mrCalcPos(rCalcPos),
         mnStartTime(Time::GetSystemTicks()),
+        mpStylePool(rDoc.GetStyleSheetPool()),
+        mnOldSearchMask(mpStylePool->GetSearchMask()),
+        meOldFamily(mpStylePool->GetSearchFamily()),
         mbNeedMore(false),
         mbProgress(false)
     {
-        mrDoc.EnableIdle(false);
-
         // The old search mask / family flags must be restored so that e.g.
         // the styles dialog shows correct listing when it's opened in-between
         // the calls.
-        ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
-        mnOldSearchMask = pStylePool->GetSearchMask();
-        meOldFamily = pStylePool->GetSearchFamily();
+
+        mrDoc.EnableIdle(false);
+        mpStylePool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
     }
 
     ~IdleCalcTextWidthScope()
@@ -483,8 +485,7 @@ public:
         if (mbProgress)
             ScProgress::DeleteInterpretProgress();
 
-        ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
-        pStylePool->SetSearchMask(meOldFamily, mnOldSearchMask);
+        mpStylePool->SetSearchMask(meOldFamily, mnOldSearchMask);
         mrDoc.EnableIdle(true);
     }
 
@@ -514,6 +515,8 @@ public:
     }
 
     bool hasProgressBar() const { return mbProgress; }
+
+    ScStyleSheetPool* getStylePool() { return mpStylePool; }
 };
 
 }
@@ -546,12 +549,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()])
         aScope.setTab(0);
 
-    ScStyleSheetPool* pStylePool = xPoolHelper->GetStylePool();
-
     pTable = maTabs[aScope.Tab()];
-    pStylePool->SetSearchMask( SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL );
-    pStyle = (ScStyleSheet*)pStylePool->Find( pTable->aPageStyle,
-                                              SFX_STYLE_FAMILY_PAGE );
+    pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
 
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
@@ -636,8 +635,8 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                     if ( bNewTab )
                     {
                         pTable = maTabs[aScope.Tab()];
-                        pStyle = (ScStyleSheet*)pStylePool->Find( pTable->aPageStyle,
-                                                                  SFX_STYLE_FAMILY_PAGE );
+                        pStyle = (ScStyleSheet*)aScope.getStylePool()->Find(
+                            pTable->aPageStyle, SFX_STYLE_FAMILY_PAGE);
 
                         if ( pStyle )
                         {
commit fd5f562ebc014ccf366bdf2e447e49b033e5e4d6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 15:05:26 2013 -0400

    Move progress bar handling to the scope object too.
    
    Change-Id: Iff93958c5025e000f7e39eb71e3f91ff41db911a

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 5c4c6f6..e6d1e38 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -454,13 +454,15 @@ class IdleCalcTextWidthScope
     MapMode maOldMapMode;
     sal_uLong mnStartTime;
     bool mbNeedMore;
+    bool mbProgress;
 
 public:
     IdleCalcTextWidthScope(ScDocument& rDoc, ScAddress& rCalcPos) :
         mrDoc(rDoc),
         mrCalcPos(rCalcPos),
         mnStartTime(Time::GetSystemTicks()),
-        mbNeedMore(false)
+        mbNeedMore(false),
+        mbProgress(false)
     {
         mrDoc.EnableIdle(false);
 
@@ -478,6 +480,9 @@ public:
         if (pDev)
             pDev->SetMapMode(maOldMapMode);
 
+        if (mbProgress)
+            ScProgress::DeleteInterpretProgress();
+
         ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
         pStylePool->SetSearchMask(meOldFamily, mnOldSearchMask);
         mrDoc.EnableIdle(true);
@@ -501,6 +506,14 @@ public:
     bool getNeedMore() const { return mbNeedMore; }
 
     sal_uLong getStartTime() const { return mnStartTime; }
+
+    void createProgressBar()
+    {
+        ScProgress::CreateInterpretProgress(&mrDoc, false);
+        mbProgress = true;
+    }
+
+    bool hasProgressBar() const { return mbProgress; }
 };
 
 }
@@ -542,8 +555,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
-    bool bProgress = false;
-    if ( pStyle && 0 == getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES))
+    if (pStyle && 0 == getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES))
     {
         sal_uInt16 nRestart = 0;
         sal_uInt16 nCount = 0;
@@ -579,11 +591,11 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                         nPPTX = aPix1000.X() / 1000.0;
                         nPPTY = aPix1000.Y() / 1000.0;
                     }
-                    if ( !bProgress && pCell->GetCellType() == CELLTYPE_FORMULA
-                      && ((ScFormulaCell*)pCell)->GetDirty() )
+
+                    if (!aScope.hasProgressBar() && pCell->GetCellType() == CELLTYPE_FORMULA
+                        && ((ScFormulaCell*)pCell)->GetDirty())
                     {
-                        ScProgress::CreateInterpretProgress( this, false );
-                        bProgress = true;
+                        aScope.createProgressBar();
                     }
 
                     sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize(
@@ -669,9 +681,6 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     else
         aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
 
-    if ( bProgress )
-        ScProgress::DeleteInterpretProgress();
-
     delete pColIter;
 
     return aScope.getNeedMore();
commit 9a1524d6d62d6ef264e78977aab6bc8a385980c5
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 14:59:50 2013 -0400

    Use a scope object to avoid manual unwinding at the end of the call.
    
    Change-Id: Id2565dfa250b93ba4f70e596d6b66f3e5e55fb5f

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 4592d13..5c4c6f6 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -443,41 +443,99 @@ void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress
 #define CALCMAX                 1000    // Berechnungen
 #define ABORT_EVENTS            (VCL_INPUT_ANY & ~VCL_INPUT_TIMER & ~VCL_INPUT_OTHER)
 
+namespace {
+
+class IdleCalcTextWidthScope
+{
+    ScDocument& mrDoc;
+    ScAddress& mrCalcPos;
+    sal_uInt16 mnOldSearchMask;
+    SfxStyleFamily meOldFamily;
+    MapMode maOldMapMode;
+    sal_uLong mnStartTime;
+    bool mbNeedMore;
+
+public:
+    IdleCalcTextWidthScope(ScDocument& rDoc, ScAddress& rCalcPos) :
+        mrDoc(rDoc),
+        mrCalcPos(rCalcPos),
+        mnStartTime(Time::GetSystemTicks()),
+        mbNeedMore(false)
+    {
+        mrDoc.EnableIdle(false);
+
+        // The old search mask / family flags must be restored so that e.g.
+        // the styles dialog shows correct listing when it's opened in-between
+        // the calls.
+        ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
+        mnOldSearchMask = pStylePool->GetSearchMask();
+        meOldFamily = pStylePool->GetSearchFamily();
+    }
+
+    ~IdleCalcTextWidthScope()
+    {
+        SfxPrinter* pDev = mrDoc.GetPrinter();
+        if (pDev)
+            pDev->SetMapMode(maOldMapMode);
+
+        ScStyleSheetPool* pStylePool = mrDoc.GetStyleSheetPool();
+        pStylePool->SetSearchMask(meOldFamily, mnOldSearchMask);
+        mrDoc.EnableIdle(true);
+    }
+
+    SCTAB Tab() const { return mrCalcPos.Tab(); }
+    SCCOL Col() const { return mrCalcPos.Col(); }
+    SCROW Row() const { return mrCalcPos.Row(); }
+
+    void setTab(SCTAB nTab) { mrCalcPos.SetTab(nTab); }
+    void setCol(SCCOL nCol) { mrCalcPos.SetCol(nCol); }
+    void setRow(SCROW nRow) { mrCalcPos.SetRow(nRow); }
+
+    void incTab(SCTAB nInc=1) { mrCalcPos.IncTab(nInc); }
+    void incCol(SCCOL nInc=1) { mrCalcPos.IncCol(nInc); }
+    void incRow(SCROW nInc=1) { mrCalcPos.IncRow(nInc); }
+
+    void setOldMapMode(const MapMode& rOldMapMode) { maOldMapMode = rOldMapMode; }
+
+    void setNeedMore(bool b) { mbNeedMore = b; }
+    bool getNeedMore() const { return mbNeedMore; }
+
+    sal_uLong getStartTime() const { return mnStartTime; }
+};
+
+}
+
 bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder versuchen
 {
     // #i75610# if a printer hasn't been set or created yet, don't create one for this
     if (!mbIdleEnabled || IsInLinkUpdate() || GetPrinter(false) == NULL)
         return false;
 
-    mbIdleEnabled = false;
+    IdleCalcTextWidthScope aScope(*this, aCurTextWidthCalcPos);
 
-    const sal_uLong         nStart   = Time::GetSystemTicks();
     OutputDevice*       pDev     = NULL;
-    MapMode             aOldMap;
     ScStyleSheet*       pStyle   = NULL;
     ScColumnIterator*   pColIter = NULL;
     ScTable*            pTable   = NULL;
-    SCTAB               nTab     = aCurTextWidthCalcPos.Tab();
-    SCROW               nRow     = aCurTextWidthCalcPos.Row();
-    SCsCOL              nCol     = aCurTextWidthCalcPos.Col();
-    bool                bNeedMore= false;
-
-    if ( !ValidRow(nRow) )
-        nRow = 0, nCol--;
-    if ( nCol < 0 )
-        nCol = MAXCOL, nTab++;
-    if ( !ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] )
-        nTab = 0;
-
-    //  SearchMask/Family muss gemerkt werden,
-    //  damit z.B. der Organizer nicht durcheinanderkommt, wenn zwischendurch eine
-    //  Query-Box aufgemacht wird !!!
+
+    if (!ValidRow(aScope.Row()))
+    {
+        aScope.setRow(0);
+        aScope.incCol(-1);
+    }
+
+    if (aScope.Col() < 0)
+    {
+        aScope.setCol(MAXCOL);
+        aScope.incTab();
+    }
+
+    if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()])
+        aScope.setTab(0);
 
     ScStyleSheetPool* pStylePool = xPoolHelper->GetStylePool();
-    sal_uInt16 nOldMask = pStylePool->GetSearchMask();
-    SfxStyleFamily eOldFam = pStylePool->GetSearchFamily();
 
-    pTable = maTabs[nTab];
+    pTable = maTabs[aScope.Tab()];
     pStylePool->SetSearchMask( SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL );
     pStyle = (ScStyleSheet*)pStylePool->Find( pTable->aPageStyle,
                                               SFX_STYLE_FAMILY_PAGE );
@@ -495,14 +553,16 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
         Fraction aZoomFract( nZoom, 100 );
 
         // Start at specified cell position (nCol, nRow, nTab).
-        ScColumn* pColumn  = &pTable->aCol[nCol];
-        pColIter = new ScColumnIterator( pColumn, nRow, MAXROW );
+        ScColumn* pColumn  = &pTable->aCol[aScope.Col()];
+        pColIter = new ScColumnIterator(pColumn, aScope.Row(), MAXROW);
 
         while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
         {
-            if ( pColIter->Next( nRow, pCell ) )
+            SCROW nRow;
+            if ( pColIter->Next(nRow, pCell) )
             {
                 // More cell in this column.
+                aScope.setRow(nRow);
 
                 if ( TEXTWIDTH_DIRTY == pCell->GetTextWidth() )
                 {
@@ -512,7 +572,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                     if ( !pDev )
                     {
                         pDev = GetPrinter();
-                        aOldMap = pDev->GetMapMode();
+                        aScope.setOldMapMode(pDev->GetMapMode());
                         pDev->SetMapMode( MAP_PIXEL );  // wichtig fuer GetNeededSize
 
                         Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
@@ -526,14 +586,12 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                         bProgress = true;
                     }
 
-                    sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize( nCol, nRow, nTab,
-                                                              pDev, nPPTX, nPPTY,
-                                                              aZoomFract,aZoomFract, true,
-                                                              true );   // bTotalSize
+                    sal_uInt16 nNewWidth = (sal_uInt16)GetNeededSize(
+                        aScope.Col(), aScope.Row(), aScope.Tab(),
+                        pDev, nPPTX, nPPTY, aZoomFract,aZoomFract, true, true);   // bTotalSize
 
                     pCell->SetTextWidth( nNewWidth );
-
-                    bNeedMore = true;
+                    aScope.setNeedMore(true);
                 }
             }
             else
@@ -542,21 +600,21 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
                 bool bNewTab = false;
 
-                nRow = 0;
-                nCol--;
+                aScope.setRow(0);
+                aScope.incCol(-1);
 
-                if ( nCol < 0 )
+                if (aScope.Col() < 0)
                 {
                     // No more column to the left.  Move to the right-most column of the next sheet.
-                    nCol = MAXCOL;
-                    nTab++;
+                    aScope.setCol(MAXCOL);
+                    aScope.incTab();
                     bNewTab = true;
                 }
 
-                if ( !ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] )
+                if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()] )
                 {
                     // Sheet doesn't exist at specified sheet position.  Restart at sheet 0.
-                    nTab = 0;
+                    aScope.setTab(0);
                     nRestart++;
                     bNewTab = true;
                 }
@@ -565,7 +623,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                 {
                     if ( bNewTab )
                     {
-                        pTable = maTabs[nTab];
+                        pTable = maTabs[aScope.Tab()];
                         pStyle = (ScStyleSheet*)pStylePool->Find( pTable->aPageStyle,
                                                                   SFX_STYLE_FAMILY_PAGE );
 
@@ -592,11 +650,11 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                     {
                         delete pColIter;
 
-                        pColumn  = &pTable->aCol[nCol];
-                        pColIter = new ScColumnIterator( pColumn, nRow, MAXROW );
+                        pColumn  = &pTable->aCol[aScope.Col()];
+                        pColIter = new ScColumnIterator( pColumn, aScope.Row(), MAXROW );
                     }
                     else
-                        ++nTab; // Move to the next sheet as the current one has scale-to-pages set.
+                        aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
                 }
             }
 
@@ -604,29 +662,19 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
 
             // Quit if either 1) its duration exceeds 50 ms, or 2) there is
             // any pending event after processing 32 cells.
-            if ((50L < Time::GetSystemTicks() - nStart) || (nCount > 31 && Application::AnyInput(ABORT_EVENTS)))
+            if ((50L < Time::GetSystemTicks() - aScope.getStartTime()) || (nCount > 31 && Application::AnyInput(ABORT_EVENTS)))
                 nCount = CALCMAX;
         }
     }
     else
-        ++nTab; // Move to the next sheet as the current one has scale-to-pages set.
+        aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
 
     if ( bProgress )
         ScProgress::DeleteInterpretProgress();
 
     delete pColIter;
 
-    if (pDev)
-        pDev->SetMapMode(aOldMap);
-
-    aCurTextWidthCalcPos.SetTab( nTab );
-    aCurTextWidthCalcPos.SetRow( nRow );
-    aCurTextWidthCalcPos.SetCol( (SCCOL)nCol );
-
-    pStylePool->SetSearchMask( eOldFam, nOldMask );
-    mbIdleEnabled = true;
-
-    return bNeedMore;
+    return aScope.getNeedMore();
 }
 
 //------------------------------------------------------------------------
commit d6c7fd2fcc5c9287e1d22d23c6291004f2dec297
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 13:55:13 2013 -0400

    Reverse the logic of enable / disable idle flag...
    
    so that true -> enabled and false -> disabled.  This is much easier
    for human brain to process.
    
    Change-Id: I51059ee9090610ad8455a072b165860527cd9d50

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 67be28a..8c3fac2 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -356,7 +356,7 @@ private:
     bool                bCalcingAfterLoad;              // in CalcAfterLoad TRUE
     // don't construct/destruct listeners temporarily
     bool                bNoListening;
-    bool                bIdleDisabled;
+    bool                mbIdleEnabled;
     bool                bInLinkUpdate;                  // TableLink or AreaLink
     bool                bChartListenerCollectionNeedsUpdate;
     // are/were there RC_FORCED formula cells in the document (if set once to TRUE then set forever)
@@ -1538,8 +1538,8 @@ public:
     void            RepaintRange( const ScRange& rRange );
     void            RepaintRange( const ScRangeList& rRange );
 
-    bool        IsIdleDisabled() const      { return bIdleDisabled; }
-    void            DisableIdle(bool bDo)   { bIdleDisabled = bDo; }
+    bool IsIdleEnabled() const { return mbIdleEnabled; }
+    void EnableIdle(bool bDo) { mbIdleEnabled = bDo; }
 
     bool            IsDetectiveDirty() const     { return bDetectiveDirty; }
     void            SetDetectiveDirty(bool bSet) { bDetectiveDirty = bSet; }
diff --git a/sc/inc/progress.hxx b/sc/inc/progress.hxx
index 0607c05..52c1fe2 100644
--- a/sc/inc/progress.hxx
+++ b/sc/inc/progress.hxx
@@ -48,7 +48,7 @@ private:
     static  sal_uLong           nInterpretProgress;
     static  sal_Bool            bAllowInterpretProgress;
     static  ScDocument*     pInterpretDoc;
-    static  sal_Bool            bIdleWasDisabled;
+    static  bool            bIdleWasEnabled;
 
             SfxProgress*    pProgress;
 
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 10428e8..1d159db 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -181,7 +181,7 @@ ScDocument::ScDocument( ScDocumentMode  eMode,
         bXMLFromWrapper( false ),
         bCalcingAfterLoad( false ),
         bNoListening( false ),
-        bIdleDisabled( false ),
+        mbIdleEnabled(true),
         bInLinkUpdate( false ),
         bChartListenerCollectionNeedsUpdate( false ),
         bHasForcedFormulas( false ),
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 5fa9f7a..55e01eb 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1340,10 +1340,10 @@ void ScDocument::Sort(SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
     {
-        bool bOldDisableIdle = IsIdleDisabled();
-        DisableIdle( true );
+        bool bOldEnableIdle = IsIdleEnabled();
+        EnableIdle(false);
         maTabs[nTab]->Sort(rSortParam, bKeepQuery, pProgress);
-        DisableIdle( bOldDisableIdle );
+        EnableIdle(bOldEnableIdle);
     }
 }
 
diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx
index 5a8bed3..56eb5651 100644
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@ -280,8 +280,8 @@ void ScDocument::CalcFormulaTree( bool bOnlyForced, bool bProgressBar, bool bSet
     bCalculatingFormulaTree = true;
 
     SetForcedFormulaPending( false );
-    bool bOldIdleDisabled = IsIdleDisabled();
-    DisableIdle( true );
+    bool bOldIdleEnabled = IsIdleEnabled();
+    EnableIdle(false);
     bool bOldAutoCalc = GetAutoCalc();
     //! _nicht_ SetAutoCalc( true ) weil das evtl. CalcFormulaTree( true )
     //! aufruft, wenn vorher disabled war und bHasForcedFormulas gesetzt ist
@@ -373,7 +373,7 @@ void ScDocument::CalcFormulaTree( bool bOnlyForced, bool bProgressBar, bool bSet
             ScProgress::DeleteInterpretProgress();
     }
     bAutoCalc = bOldAutoCalc;
-    DisableIdle( bOldIdleDisabled );
+    EnableIdle(bOldIdleEnabled);
     bCalculatingFormulaTree = false;
 }
 
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 896848c..4592d13 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -446,9 +446,10 @@ void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress
 bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder versuchen
 {
     // #i75610# if a printer hasn't been set or created yet, don't create one for this
-    if ( bIdleDisabled || IsInLinkUpdate() || GetPrinter(false) == NULL )
+    if (!mbIdleEnabled || IsInLinkUpdate() || GetPrinter(false) == NULL)
         return false;
-    bIdleDisabled = true;
+
+    mbIdleEnabled = false;
 
     const sal_uLong         nStart   = Time::GetSystemTicks();
     OutputDevice*       pDev     = NULL;
@@ -623,7 +624,7 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     aCurTextWidthCalcPos.SetCol( (SCCOL)nCol );
 
     pStylePool->SetSearchMask( eOldFam, nOldMask );
-    bIdleDisabled = false;
+    mbIdleEnabled = true;
 
     return bNeedMore;
 }
@@ -819,7 +820,7 @@ bool ScDocument::OnlineSpellInRange( const ScRange& rSpellRange, ScAddress& rSpe
 
 bool ScDocument::ContinueOnlineSpelling()
 {
-    if ( bIdleDisabled || !pDocOptions->IsAutoSpell() || (pShell && pShell->IsReadOnly()) )
+    if (!mbIdleEnabled || !pDocOptions->IsAutoSpell() || (pShell && pShell->IsReadOnly()))
         return false;
 
     // #i48433# set bInsertingFromOtherDoc flag so there are no broadcasts when PutCell is called
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 85d599c..39e780f 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -2277,8 +2277,8 @@ void ScInterpreter::ScDde()
             //  solange der Link nicht ausgewertet ist, Idle abklemmen
             //  (um zirkulaere Referenzen zu vermeiden)
 
-        bool bOldDis = pDok->IsIdleDisabled();
-        pDok->DisableIdle( true );
+        bool bOldEnabled = pDok->IsIdleEnabled();
+        pDok->EnableIdle(false);
 
             //  Link-Objekt holen / anlegen
 
@@ -2337,7 +2337,7 @@ void ScInterpreter::ScDde()
         else
             PushNA();
 
-        pDok->DisableIdle( bOldDis );
+        pDok->EnableIdle(bOldEnabled);
         pLinkMgr->CloseCachedComps();
     }
 }
diff --git a/sc/source/core/tool/progress.cxx b/sc/source/core/tool/progress.cxx
index 0c43616..8085727 100644
--- a/sc/source/core/tool/progress.cxx
+++ b/sc/source/core/tool/progress.cxx
@@ -44,7 +44,7 @@ ScProgress*     ScProgress::pOldInterpretProgress = NULL;
 sal_uLong           ScProgress::nInterpretProgress = 0;
 sal_Bool            ScProgress::bAllowInterpretProgress = sal_True;
 ScDocument*     ScProgress::pInterpretDoc;
-sal_Bool            ScProgress::bIdleWasDisabled = false;
+bool            ScProgress::bIdleWasEnabled = false;
 
 
 static sal_Bool lcl_IsHiddenDocument( SfxObjectShell* pObjSh )
@@ -145,8 +145,8 @@ void ScProgress::CreateInterpretProgress( ScDocument* pDoc, sal_Bool bWait )
         else if ( pDoc->GetAutoCalc() )
         {
             nInterpretProgress = 1;
-            bIdleWasDisabled = pDoc->IsIdleDisabled();
-            pDoc->DisableIdle( sal_True );
+            bIdleWasEnabled = pDoc->IsIdleEnabled();
+            pDoc->EnableIdle(false);
             // Interpreter may be called in many circumstances, also if another
             // progress bar is active, for example while adapting row heights.
             // Keep the dummy interpret progress.
@@ -180,7 +180,7 @@ void ScProgress::DeleteInterpretProgress()
                 delete pTmpProgress;
             }
             if ( pInterpretDoc )
-                pInterpretDoc->DisableIdle( bIdleWasDisabled );
+                pInterpretDoc->EnableIdle(bIdleWasEnabled);
         }
         --nInterpretProgress;
     }
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 7d7be79..175a6c6 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -4694,10 +4694,10 @@ sal_Bool SAL_CALL ScXMLExport::filter( const ::com::sun::star::uno::Sequence< ::
 {
     SolarMutexGuard aGuard;
     if (pDoc)
-        pDoc->DisableIdle(true);
+        pDoc->EnableIdle(false);
     bool bReturn(SvXMLExport::filter(aDescriptor));
     if (pDoc)
-        pDoc->DisableIdle(false);
+        pDoc->EnableIdle(true);
     return bReturn;
 }
 
@@ -4706,7 +4706,7 @@ void SAL_CALL ScXMLExport::cancel()
 {
     SolarMutexGuard aGuard;
     if (pDoc)
-        pDoc->DisableIdle(false);
+        pDoc->EnableIdle(true);
     SvXMLExport::cancel();
 }
 
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index a9707de..c56d010 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -250,7 +250,7 @@ sal_uInt16 ScDocShell::GetHiddenInformationState( sal_uInt16 nStates )
 
 void ScDocShell::BeforeXMLLoading()
 {
-    aDocument.DisableIdle( sal_True );
+    aDocument.EnableIdle(false);
 
     // prevent unnecessary broadcasts and updates
     OSL_ENSURE(pModificator == NULL, "The Modificator should not exist");
@@ -367,7 +367,7 @@ void ScDocShell::AfterXMLLoading(sal_Bool bRet)
         OSL_FAIL("The Modificator should exist");
     }
 
-    aDocument.DisableIdle( false );
+    aDocument.EnableIdle(true);
 }
 
 namespace {
@@ -479,7 +479,7 @@ sal_Bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const ::com::sun::star::un
 {
     RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScDocShell::SaveXML" );
 
-    aDocument.DisableIdle( sal_True );
+    aDocument.EnableIdle(false);
 
     ScXMLImportWrapper aImport( aDocument, pSaveMedium, xStor );
     sal_Bool bRet(false);
@@ -488,7 +488,7 @@ sal_Bool ScDocShell::SaveXML( SfxMedium* pSaveMedium, const ::com::sun::star::un
     else
         bRet = aImport.Export(sal_True);
 
-    aDocument.DisableIdle( false );
+    aDocument.EnableIdle(true);
 
     return bRet;
 }
@@ -2443,7 +2443,7 @@ sal_uInt16 ScDocShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
 
     sal_uInt16 nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing );
     if (nRet == sal_True)                       // sal_True = schliessen
-        aDocument.DisableIdle(sal_True);        // nicht mehr drin rumpfuschen !!!
+        aDocument.EnableIdle(false);        // nicht mehr drin rumpfuschen !!!
 
     return nRet;
 }
@@ -2976,9 +2976,9 @@ ScDocShellModificator::ScDocShellModificator( ScDocShell& rDS )
 {
     ScDocument* pDoc = rDocShell.GetDocument();
     bAutoCalcShellDisabled = pDoc->IsAutoCalcShellDisabled();
-    bIdleDisabled = pDoc->IsIdleDisabled();
+    bIdleEnabled = pDoc->IsIdleEnabled();
     pDoc->SetAutoCalcShellDisabled( sal_True );
-    pDoc->DisableIdle( sal_True );
+    pDoc->EnableIdle(false);
 }
 
 
@@ -2988,7 +2988,7 @@ ScDocShellModificator::~ScDocShellModificator()
     pDoc->SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
     if ( !bAutoCalcShellDisabled && rDocShell.IsDocumentModifiedPending() )
         rDocShell.SetDocumentModified();    // last one shuts off the lights
-    pDoc->DisableIdle( bIdleDisabled );
+    pDoc->EnableIdle(bIdleEnabled);
 }
 
 
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index ade8dfb..010ea82 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -454,7 +454,7 @@ class SC_DLLPUBLIC ScDocShellModificator
             ScDocShell&     rDocShell;
     ScRefreshTimerProtector aProtector;
             sal_Bool            bAutoCalcShellDisabled;
-            sal_Bool            bIdleDisabled;
+            bool            bIdleEnabled;
 
                             // not implemented
                             ScDocShellModificator( const ScDocShellModificator& );
diff --git a/sc/source/ui/inc/spelldialog.hxx b/sc/source/ui/inc/spelldialog.hxx
index b0bf42f..4eaf656 100644
--- a/sc/source/ui/inc/spelldialog.hxx
+++ b/sc/source/ui/inc/spelldialog.hxx
@@ -89,7 +89,7 @@ private:
     ScDocShell*         mpDocShell;
     ScDocument*         mpDoc;
     bool                mbNeedNextObj;
-    bool                mbOldIdleDisabled;
+    bool                mbOldIdleEnabled;
 };
 
 // ============================================================================
diff --git a/sc/source/ui/view/output.cxx b/sc/source/ui/view/output.cxx
index c8018cf..18325cd 100644
--- a/sc/source/ui/view/output.cxx
+++ b/sc/source/ui/view/output.cxx
@@ -1949,8 +1949,8 @@ void ScOutputData::FindChanged()
     SCCOL   nX;
     SCSIZE  nArrY;
 
-    bool bWasIdleDisabled = mpDoc->IsIdleDisabled();
-    mpDoc->DisableIdle(true);
+    bool bWasIdleEnabled = mpDoc->IsIdleEnabled();
+    mpDoc->EnableIdle(false);
     for (nArrY=0; nArrY<nArrCount; nArrY++)
         pRowInfo[nArrY].bChanged = false;
 
@@ -1997,7 +1997,7 @@ void ScOutputData::FindChanged()
     }
     if ( bProgress )
         ScProgress::DeleteInterpretProgress();
-    mpDoc->DisableIdle( bWasIdleDisabled );
+    mpDoc->EnableIdle(bWasIdleEnabled);
 }
 
 void ScOutputData::DrawRefMark( SCCOL nRefStartX, SCROW nRefStartY,
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 0158f17..6caa4e2 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -1413,8 +1413,8 @@ void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
 
     vcl::PDFExtOutDevData* pPDFData = PTR_CAST( vcl::PDFExtOutDevData, mpDev->GetExtOutDevData() );
 
-    sal_Bool bWasIdleDisabled = mpDoc->IsIdleDisabled();
-    mpDoc->DisableIdle( true );
+    bool bWasIdleEnabled = mpDoc->IsIdleEnabled();
+    mpDoc->EnableIdle(false);
 
     ScDrawStringsVars aVars( this, bPixelToLogic );
 
@@ -2015,7 +2015,7 @@ void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
     }
     if ( bProgress )
         ScProgress::DeleteInterpretProgress();
-    mpDoc->DisableIdle( bWasIdleDisabled );
+    mpDoc->EnableIdle(bWasIdleEnabled);
 }
 
 //  -------------------------------------------------------------------------------
diff --git a/sc/source/ui/view/spelldialog.cxx b/sc/source/ui/view/spelldialog.cxx
index 8b24d51..1839f26 100644
--- a/sc/source/ui/view/spelldialog.cxx
+++ b/sc/source/ui/view/spelldialog.cxx
@@ -47,7 +47,7 @@ ScSpellDialogChildWindow::ScSpellDialogChildWindow( Window* pParentP, sal_uInt16
     mpDocShell( 0 ),
     mpDoc( 0 ),
     mbNeedNextObj( false ),
-    mbOldIdleDisabled( false )
+    mbOldIdleEnabled(true)
 {
     Init();
 }
@@ -141,7 +141,7 @@ void ScSpellDialogChildWindow::Reset()
         mpViewShell->KillEditView( sal_True );
         mpDocShell->PostPaintGridAll();
         mpViewShell->UpdateInputHandler();
-        mpDoc->DisableIdle( mbOldIdleDisabled );
+        mpDoc->EnableIdle(mbOldIdleEnabled);
     }
     mxEngine.reset();
     mxUndoDoc.reset();
@@ -153,7 +153,7 @@ void ScSpellDialogChildWindow::Reset()
     mpDocShell = 0;
     mpDoc = 0;
     mbNeedNextObj = false;
-    mbOldIdleDisabled = false;
+    mbOldIdleEnabled = true;
 }
 
 void ScSpellDialogChildWindow::Init()
@@ -214,8 +214,8 @@ void ScSpellDialogChildWindow::Init()
             OSL_FAIL( "ScSpellDialogChildWindow::Init - unknown selection type" );
     }
 
-    mbOldIdleDisabled = mpDoc->IsIdleDisabled();
-    mpDoc->DisableIdle( true );   // stop online spelling
+    mbOldIdleEnabled = mpDoc->IsIdleEnabled();
+    mpDoc->EnableIdle(false);   // stop online spelling
 
     // *** create Undo/Redo documents *** -------------------------------------
 
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 0b3158c..cd48942 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -511,8 +511,8 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, sal_Boo
 
     //  ab hier kein return mehr
 
-    sal_Bool bOldDis = pDoc->IsIdleDisabled();
-    pDoc->DisableIdle( true );   // stop online spelling
+    bool bOldEnabled = pDoc->IsIdleEnabled();
+    pDoc->EnableIdle(false);   // stop online spelling
 
     // *** create and init the edit engine *** --------------------------------
 
@@ -579,7 +579,7 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, sal_Boo
     delete pEngine;
     pDocSh->PostPaintGridAll();
     rViewData.GetViewShell()->UpdateInputHandler();
-    pDoc->DisableIdle(bOldDis);
+    pDoc->EnableIdle(bOldEnabled);
 }
 
 // Pasten von FORMAT_FILE-Items
commit 51c449bc8765756c23054e9a1a8172603987024b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 12:20:16 2013 -0400

    Use inline function over preprocessor macro.
    
    Change-Id: I08d83f274af1ce891235c2f24d5e4b697de19309

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index a4e88a4..896848c 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -88,8 +88,6 @@
 
 #include <memory>
 
-#define GET_SCALEVALUE(set,id)  ((const SfxUInt16Item&)(set.Get( id ))).GetValue()
-
 //  states for online spelling in the visible range (0 is set initially)
 #define VSPL_START  0
 #define VSPL_DONE   1
@@ -97,7 +95,14 @@
 
 // STATIC DATA -----------------------------------------------------------
 
-//------------------------------------------------------------------------
+namespace {
+
+inline sal_uInt16 getScaleValue(SfxStyleSheetBase& rStyle, sal_uInt16 nWhich)
+{
+    return static_cast<const SfxUInt16Item&>(rStyle.GetItemSet().Get(nWhich)).GetValue();
+}
+
+}
 
 void ScDocument::ImplCreateOptions()
 {
@@ -229,11 +234,11 @@ void ScDocument::ModifyStyleSheet( SfxStyleSheetBase& rStyleSheet,
     {
         case SFX_STYLE_FAMILY_PAGE:
             {
-                const sal_uInt16 nOldScale        = GET_SCALEVALUE(rSet,ATTR_PAGE_SCALE);
-                const sal_uInt16 nOldScaleToPages = GET_SCALEVALUE(rSet,ATTR_PAGE_SCALETOPAGES);
+                const sal_uInt16 nOldScale = getScaleValue(rStyleSheet, ATTR_PAGE_SCALE);
+                const sal_uInt16 nOldScaleToPages = getScaleValue(rStyleSheet, ATTR_PAGE_SCALETOPAGES);
                 rSet.Put( rChanges );
-                const sal_uInt16 nNewScale        = GET_SCALEVALUE(rSet,ATTR_PAGE_SCALE);
-                const sal_uInt16 nNewScaleToPages = GET_SCALEVALUE(rSet,ATTR_PAGE_SCALETOPAGES);
+                const sal_uInt16 nNewScale        = getScaleValue(rStyleSheet, ATTR_PAGE_SCALE);
+                const sal_uInt16 nNewScaleToPages = getScaleValue(rStyleSheet, ATTR_PAGE_SCALETOPAGES);
 
                 if ( (nOldScale != nNewScale) || (nOldScaleToPages != nNewScaleToPages) )
                     InvalidateTextWidth( rStyleSheet.GetName() );
@@ -479,13 +484,13 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
     OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
 
     bool bProgress = false;
-    if ( pStyle && 0 == GET_SCALEVALUE(pStyle->GetItemSet(),ATTR_PAGE_SCALETOPAGES) )
+    if ( pStyle && 0 == getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES))
     {
         sal_uInt16 nRestart = 0;
         sal_uInt16 nCount = 0;
         ScBaseCell* pCell = NULL;
 
-        sal_uInt16 nZoom = GET_SCALEVALUE(pStyle->GetItemSet(),ATTR_PAGE_SCALE);
+        sal_uInt16 nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
         Fraction aZoomFract( nZoom, 100 );
 
         // Start at specified cell position (nCol, nRow, nTab).
@@ -568,10 +573,9 @@ bool ScDocument::IdleCalcTextWidth()            // true = demnaechst wieder vers
                             // Check if the scale-to-pages setting is set. If
                             // set, we exit the loop.  If not, get the page
                             // scale factor of the new sheet.
-                            SfxItemSet& rSet = pStyle->GetItemSet();
-                            if ( GET_SCALEVALUE( rSet, ATTR_PAGE_SCALETOPAGES ) == 0 )
+                            if (getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
                             {
-                                nZoom = GET_SCALEVALUE(rSet, ATTR_PAGE_SCALE );
+                                nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
                                 aZoomFract = Fraction(nZoom, 100);
                             }
                             else
commit 2245288574ef77b09416872326b4543c82790815
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 11:55:02 2013 -0400

    I'm pretty sure this was meant to be unsigned.
    
    Change-Id: Id074e31542383f6a31181749d7d4a5219522d9e0

diff --git a/svl/inc/svl/cintitem.hxx b/svl/inc/svl/cintitem.hxx
index 6914dd5..e781ada 100644
--- a/svl/inc/svl/cintitem.hxx
+++ b/svl/inc/svl/cintitem.hxx
@@ -134,7 +134,7 @@ public:
 
     virtual SfxFieldUnit GetUnit() const;
 
-    sal_Int16 GetValue() const { return m_nValue; }
+    sal_uInt16 GetValue() const { return m_nValue; }
 
     inline void SetValue(sal_uInt16 nTheValue);
 };
commit e92ed1560e13c7458e24ed6c7edf7fb1438c0823
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 13 10:05:47 2013 -0400

    Annotate this algorithm & a few cleanup and one possible bug fix.
    
    Change-Id: Ifd101364119db7c30ba28e66b4a8b1320a54fe66

diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 46d160d..a4e88a4 100644
--- a/sc/source/core/data/documen8.cxx

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list