diff options
author | tagezi <lera.goncharuk@gmail.com> | 2018-02-01 13:52:49 +0300 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-03-21 01:08:03 +0100 |
commit | 3b3e203461441da733096be323641a8dc07ff24f (patch) | |
tree | c900fba2839cdf0bee457e68a0b79a0f78d31fce | |
parent | dd4f1b1bd31daf080dc0420524712dc244e539b5 (diff) |
tdf#68290 cursor moves with Enter in protected sheet
Change-Id: I2ac848f1799d94f521628480664cdb579417772a
Reviewed-on: https://gerrit.libreoffice.org/49085
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | sc/inc/table.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 73 |
2 files changed, 57 insertions, 18 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index b4634806069b..08ddea363fbf 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -593,6 +593,8 @@ public: void GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY, bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const; + bool SkipRow( const SCCOL rCol, SCROW& rRow, const SCROW nMovY, const ScMarkData& rMark, + const bool bUp, const SCROW nUsedY, const bool bSheetProtected ) const; void LimitChartArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow ) const; bool HasData( SCCOL nCol, SCROW nRow ) const; diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index ddc440d55fa0..5a0d97d83b60 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -1318,10 +1318,47 @@ bool ScTable::ValidNextPos( SCCOL nCol, SCROW nRow, const ScMarkData& rMark, return true; } +// Skips the current cell if it is Hidden, Overlapped or Protected and Sheet is Protected +bool ScTable::SkipRow( const SCCOL nCol, SCROW& rRow, const SCROW nMovY, + const ScMarkData& rMark, const bool bUp, const SCROW nUsedY, const bool bSheetProtected ) const +{ + if ( !ValidRow( rRow )) + return false; + + if (bSheetProtected && pDocument->HasAttrib( nCol, rRow, nTab, nCol, rRow, nTab, HasAttrFlags::Protected)) + { + if ( rRow > nUsedY ) + rRow = (bUp ? nUsedY : MAXROW + nMovY); + else + rRow += nMovY; + + rRow = rMark.GetNextMarked( nCol, rRow, bUp ); + + return true; + } + else + { + bool bRowHidden = RowHidden( rRow ); + bool bOverlapped = pDocument->HasAttrib( nCol, rRow, nTab, nCol, rRow, nTab, HasAttrFlags::Overlapped ); + + if ( bRowHidden || bOverlapped ) + { + rRow += nMovY; + rRow = rMark.GetNextMarked( nCol, rRow, bUp ); + + return true; + } + } + + return false; +} + void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY, bool bMarked, bool bUnprotected, const ScMarkData& rMark ) const { - if (bUnprotected && !IsProtected()) // Is sheet really protected? + bool bSheetProtected = IsProtected(); + + if ( bUnprotected && !bSheetProtected ) // Is sheet really protected? bUnprotected = false; sal_uInt16 nWrap = 0; @@ -1336,30 +1373,33 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY, if ( nMovY && bMarked ) { - bool bUp = ( nMovY < 0 ); + bool bUp = ( nMovY < 0 ); + SCROW nUsedY = nRow; + SCCOL nUsedX = nCol; + nRow = rMark.GetNextMarked( nCol, nRow, bUp ); - while ( ValidRow(nRow) && - (RowHidden(nRow) || pDocument->HasAttrib(nCol, nRow, nTab, nCol, nRow, nTab, HasAttrFlags::Overlapped)) ) - { - // skip hidden rows (see above) - nRow += nMovY; - nRow = rMark.GetNextMarked( nCol, nRow, bUp ); - } + pDocument->GetPrintArea( nTab, nUsedX, nUsedY ); + + while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nUsedY, bSheetProtected )) + ; while ( nRow < 0 || nRow > MAXROW ) { nCol = sal::static_int_cast<SCCOL>( nCol + static_cast<SCCOL>(nMovY) ); + while ( ValidCol(nCol) && ColHidden(nCol) ) nCol = sal::static_int_cast<SCCOL>( nCol + static_cast<SCCOL>(nMovY) ); // skip hidden rows (see above) if (nCol < 0) { - nCol = MAXCOL; + nCol = (bSheetProtected ? nUsedX : MAXCOL); + if (++nWrap >= 2) return; } - else if (nCol > MAXCOL) + else if (nCol > MAXCOL || ( nCol > nUsedX && bSheetProtected )) { nCol = 0; + if (++nWrap >= 2) return; } @@ -1367,14 +1407,11 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY, nRow = MAXROW; else if (nRow > MAXROW) nRow = 0; + nRow = rMark.GetNextMarked( nCol, nRow, bUp ); - while ( ValidRow(nRow) && - (RowHidden(nRow) || pDocument->HasAttrib(nCol, nRow, nTab, nCol, nRow, nTab, HasAttrFlags::Overlapped)) ) - { - // skip hidden rows (see above) - nRow += nMovY; - nRow = rMark.GetNextMarked( nCol, nRow, bUp ); - } + + while ( SkipRow( nCol, nRow, nMovY, rMark, bUp, nUsedY, bSheetProtected )) + ; } } |