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

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 13 12:23:38 PDT 2013


 sc/source/core/data/documen8.cxx |  200 ++++++++++++++++++++++++---------------
 1 file changed, 128 insertions(+), 72 deletions(-)

New commits:
commit 8b1143fafd20ba5f2d2090f582874a2ffb543d68
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 452daf08e383c886e918a94c1e901cabb572b648
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 6be6bc72f1aeafb66f60170f89faefb41743b320
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();
 }
 
 //------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list