sc/source/core/data/table1.cxx | 82 ++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 34 deletions(-)
New commits: commit e42ee773ffc12e38d596ce2aa016f0849c4e5ac6 Author: Pierre-André Jacquod <pjacq...@alumni.ethz.ch> Date: Tue Nov 29 09:10:26 2011 +0100 reduce scope of var and better comment of function GetDataArea diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 3c142c1..06b8203 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -743,17 +743,19 @@ bool ScTable::GetDataStart( SCCOL& rStartCol, SCROW& rStartRow ) const void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bIncludeOld, bool bOnlyDown ) const { - // bIncludeOld = true ensure that the returned area contains at least the initial area, - // independently of the case if this area has empty rows / columns at its borders - // bOnlyDown = true means extend the inputed area only down, i.e increase only rEndRow + // return the smallest area containing at least all contiguous cells having data. This area + // is a square containing also empty cells. It may shrink or extend the area given as input + // Flags as modifiers: + // + // bIncludeOld = true ensure that the returned area contains at least the initial area, + // independently of the emptniess of rows / columns (i.e. does not allow shrinking) + // bOnlyDown = true means extend / shrink the inputed area only down, i.e modifiy only rEndRow + bool bLeft = false; bool bRight = false; bool bTop = false; bool bBottom = false; - bool bChanged; - bool bFound; - SCCOL i; - SCROW nTest; + bool bChanged = false; do { @@ -784,12 +786,12 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S if (rStartRow > 0) { - nTest = rStartRow-1; - bFound = false; - for (i=rStartCol; i<=rEndCol && !bFound; i++) + SCROW nTest = rStartRow-1; + bool needExtend = false; + for ( SCCOL i = rStartCol; i<=rEndCol && !needExtend; i++) if (aCol[i].HasDataAt(nTest)) - bFound = true; - if (bFound) + needExtend = true; + if (needExtend) { --rStartRow; bChanged = true; @@ -800,12 +802,12 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S if (rEndRow < MAXROW) { - nTest = rEndRow+1; - bFound = false; - for (i=rStartCol; i<=rEndCol && !bFound; i++) + SCROW nTest = rEndRow+1; + bool needExtend = false; + for ( SCCOL i = rStartCol; i<=rEndCol && !needExtend; i++) if (aCol[i].HasDataAt(nTest)) - bFound = true; - if (bFound) + needExtend = true; + if (needExtend) { ++rEndRow; bChanged = true; @@ -830,7 +832,7 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S bool shrink = true; do { - for (i=rStartCol; i<=rEndCol && shrink; i++) + for ( SCCOL i = rStartCol; i<=rEndCol && shrink; i++) if (aCol[i].HasDataAt(rStartRow)) shrink = false; if (shrink) @@ -846,7 +848,7 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S bool shrink = true; do { - for (i=rStartCol; i<=rEndCol && shrink; i++) + for ( SCCOL i = rStartCol; i<=rEndCol && shrink; i++) if (aCol[i].HasDataAt(rEndRow)) shrink = false; if (shrink) commit 2e5023f974dd94dfeec0554ce07d0544f9ce7638 Author: Pierre-André Jacquod <pjacq...@alumni.ethz.ch> Date: Mon Nov 28 10:10:15 2011 +0100 if empty row / col leads to shrink area, suppress all empty rows/col and not just the last one, leaving the other within the selection area diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 2262eca..3c142c1 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -817,22 +817,25 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S if ( !bIncludeOld && !bOnlyDown ) { - if ( !bLeft && rStartCol < MAXCOL && rStartCol < rEndCol ) - if ( aCol[rStartCol].IsEmptyBlock(rStartRow,rEndRow) ) + if ( !bLeft ) + while ( aCol[rStartCol].IsEmptyBlock(rStartRow,rEndRow) && rStartCol < MAXCOL && rStartCol < rEndCol) ++rStartCol; - if ( !bRight && rEndCol > 0 && rStartCol < rEndCol ) - if ( aCol[rEndCol].IsEmptyBlock(rStartRow,rEndRow) ) + if ( !bRight ) + while ( aCol[rEndCol].IsEmptyBlock(rStartRow,rEndRow) && rEndCol > 0 && rStartCol < rEndCol) --rEndCol; if ( !bTop && rStartRow < MAXROW && rStartRow < rEndRow ) { - bFound = false; - for (i=rStartCol; i<=rEndCol && !bFound; i++) - if (aCol[i].HasDataAt(rStartRow)) - bFound = true; - if (!bFound) - ++rStartRow; + bool shrink = true; + do + { + for (i=rStartCol; i<=rEndCol && shrink; i++) + if (aCol[i].HasDataAt(rStartRow)) + shrink = false; + if (shrink) + ++rStartRow; + }while( shrink && rStartRow < MAXROW && rStartRow < rEndRow); } } @@ -840,12 +843,15 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S { if ( !bBottom && rEndRow > 0 && rStartRow < rEndRow ) { - bFound = false; - for (i=rStartCol; i<=rEndCol && !bFound; i++) - if (aCol[i].HasDataAt(rEndRow)) - bFound = true; - if (!bFound) - --rEndRow; + bool shrink = true; + do + { + for (i=rStartCol; i<=rEndCol && shrink; i++) + if (aCol[i].HasDataAt(rEndRow)) + shrink = false; + if (shrink) + --rEndRow; + }while( shrink && rEndRow > 0 && rStartRow < rEndRow ); } } } commit 7359ad4fc772bc355905ef8b4a4a7b44dcfc1ebe Author: Pierre-André Jacquod <pjacq...@alumni.ethz.ch> Date: Mon Nov 28 09:54:59 2011 +0100 if changes selection only down, this is also valid for shrinking and not only for expanding the selected area. Hence both part should test this condition. diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index e03c285..2262eca 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -815,14 +815,16 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S } while( bChanged ); - if ( !bIncludeOld ) + if ( !bIncludeOld && !bOnlyDown ) { if ( !bLeft && rStartCol < MAXCOL && rStartCol < rEndCol ) if ( aCol[rStartCol].IsEmptyBlock(rStartRow,rEndRow) ) ++rStartCol; + if ( !bRight && rEndCol > 0 && rStartCol < rEndCol ) if ( aCol[rEndCol].IsEmptyBlock(rStartRow,rEndRow) ) --rEndCol; + if ( !bTop && rStartRow < MAXROW && rStartRow < rEndRow ) { bFound = false; @@ -832,6 +834,10 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S if (!bFound) ++rStartRow; } + } + + if ( !bIncludeOld ) + { if ( !bBottom && rEndRow > 0 && rStartRow < rEndRow ) { bFound = false;
_______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits