diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-02-11 19:31:30 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-02-11 20:42:42 -0500 |
commit | 5f61d6da668ba7d14f8cdf390aad4f12fc6900bd (patch) | |
tree | 8f5ae128734d13162a20b1b4a0a9566746678d53 /sc/source/ui/view/tabview2.cxx | |
parent | ef0fcadc9b1a719b78e624199ea71bd5c3417dae (diff) |
Fixed incorrect cursor navigation. (fdo#33756)
Block selection with keyboard was incorrect when the selected range
included hidden cells. This also fixes one crasher on block
selection during formula reference mode i.e. type '=SUM(' and select
range via keyboard afterward.
Diffstat (limited to 'sc/source/ui/view/tabview2.cxx')
-rw-r--r-- | sc/source/ui/view/tabview2.cxx | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx index cd82a7697d96..9baa04ed8f87 100644 --- a/sc/source/ui/view/tabview2.cxx +++ b/sc/source/ui/view/tabview2.cxx @@ -401,8 +401,9 @@ void ScTabView::GetAreaMoveEndPosition(SCsCOL nMovX, SCsROW nMovY, ScFollowMode { SCCOL nNewX = -1; SCROW nNewY = -1; - SCCOL nCurX = -1; - SCROW nCurY = -1; + // current cursor position. + SCCOL nCurX = aViewData.GetCurX(); + SCROW nCurY = aViewData.GetCurY(); if (aViewData.IsRefMode()) { @@ -414,14 +415,11 @@ void ScTabView::GetAreaMoveEndPosition(SCsCOL nMovX, SCsROW nMovY, ScFollowMode // block end position. nNewX = nBlockEndX; nNewY = nBlockEndY; - // cursor position - diagonally opposite of the block end position. - nCurX = aViewData.GetCurX(); - nCurY = aViewData.GetCurY(); } else { - nNewX = nCurX = aViewData.GetCurX(); - nNewY = nCurY = aViewData.GetCurY(); + nNewX = nCurX; + nNewY = nCurY; } ScDocument* pDoc = aViewData.GetDocument(); @@ -591,7 +589,7 @@ void ScTabView::SkipCursorVertical(SCsCOL& rCurX, SCsROW& rCurY, SCsROW nOldY, S namespace { -bool lcl_isCellQualified(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, bool bSelectLocked, bool bSelectUnlocked) +bool isCellQualified(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, bool bSelectLocked, bool bSelectUnlocked) { bool bCellProtected = pDoc->HasAttrib( nCol, nRow, nTab, nCol, nRow, nTab, HASATTR_PROTECTED); @@ -605,33 +603,7 @@ bool lcl_isCellQualified(ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, b return true; } -void skipHiddenRows(ScDocument* pDoc, SCTAB nTab, SCROW& rRow, bool bForward) -{ - SCROW nFirst, nLast; - if (!pDoc->RowHidden(rRow, nTab, &nFirst, &nLast)) - // This row is visible. Nothing to do. - return; - - if (bForward) - rRow = nLast < MAXROW ? nLast + 1 : MAXROW; - else - rRow = nFirst > 0 ? nFirst - 1 : 0; -} - -void skipHiddenCols(ScDocument* pDoc, SCTAB nTab, SCCOL& rCol, bool bForward) -{ - SCCOL nFirst, nLast; - if (!pDoc->ColHidden(rCol, nTab, &nFirst, &nLast)) - // This row is visible. Nothing to do. - return; - - if (bForward) - rCol = nLast < MAXCOL ? nLast + 1 : MAXCOL; - else - rCol = nFirst > 0 ? nFirst - 1 : 0; -} - -void lcl_moveCursorByProtRule( +void moveCursorByProtRule( SCCOL& rCol, SCROW& rRow, SCsCOL nMovX, SCsROW nMovY, SCTAB nTab, ScDocument* pDoc) { bool bSelectLocked = true; @@ -649,10 +621,9 @@ void lcl_moveCursorByProtRule( { for (SCCOL i = 0; i < nMovX; ++i) { - if (!lcl_isCellQualified(pDoc, rCol+1, rRow, nTab, bSelectLocked, bSelectUnlocked)) + if (!isCellQualified(pDoc, rCol+1, rRow, nTab, bSelectLocked, bSelectUnlocked)) break; ++rCol; - skipHiddenCols(pDoc, nTab, rCol, true); } } } @@ -663,10 +634,9 @@ void lcl_moveCursorByProtRule( nMovX = -nMovX; for (SCCOL i = 0; i < nMovX; ++i) { - if (!lcl_isCellQualified(pDoc, rCol-1, rRow, nTab, bSelectLocked, bSelectUnlocked)) + if (!isCellQualified(pDoc, rCol-1, rRow, nTab, bSelectLocked, bSelectUnlocked)) break; --rCol; - skipHiddenCols(pDoc, nTab, rCol, false); } } } @@ -677,10 +647,9 @@ void lcl_moveCursorByProtRule( { for (SCROW i = 0; i < nMovY; ++i) { - if (!lcl_isCellQualified(pDoc, rCol, rRow+1, nTab, bSelectLocked, bSelectUnlocked)) + if (!isCellQualified(pDoc, rCol, rRow+1, nTab, bSelectLocked, bSelectUnlocked)) break; ++rRow; - skipHiddenRows(pDoc, nTab, rRow, true); } } } @@ -691,10 +660,9 @@ void lcl_moveCursorByProtRule( nMovY = -nMovY; for (SCROW i = 0; i < nMovY; ++i) { - if (!lcl_isCellQualified(pDoc, rCol, rRow-1, nTab, bSelectLocked, bSelectUnlocked)) + if (!isCellQualified(pDoc, rCol, rRow-1, nTab, bSelectLocked, bSelectUnlocked)) break; --rRow; - skipHiddenRows(pDoc, nTab, rRow, false); } } } @@ -733,7 +701,7 @@ void ScTabView::ExpandBlock(SCsCOL nMovX, SCsROW nMovY, ScFollowMode eMode) bSelectUnlocked = pTabProtection->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS); } - lcl_moveCursorByProtRule(nNewX, nNewY, nMovX, nMovY, nRefTab, pDoc); + moveCursorByProtRule(nNewX, nNewY, nMovX, nMovY, nRefTab, pDoc); if (nMovX) { @@ -745,7 +713,7 @@ void ScTabView::ExpandBlock(SCsCOL nMovX, SCsROW nMovY, ScFollowMode eMode) else --nTempX; } - if (lcl_isCellQualified(pDoc, nTempX, nNewY, nRefTab, bSelectLocked, bSelectUnlocked)) + if (isCellQualified(pDoc, nTempX, nNewY, nRefTab, bSelectLocked, bSelectUnlocked)) nNewX = nTempX; } @@ -759,7 +727,7 @@ void ScTabView::ExpandBlock(SCsCOL nMovX, SCsROW nMovY, ScFollowMode eMode) else --nTempY; } - if (lcl_isCellQualified(pDoc, nNewX, nTempY, nRefTab, bSelectLocked, bSelectUnlocked)) + if (isCellQualified(pDoc, nNewX, nTempY, nRefTab, bSelectLocked, bSelectUnlocked)) nNewY = nTempY; } @@ -776,7 +744,7 @@ void ScTabView::ExpandBlock(SCsCOL nMovX, SCsROW nMovY, ScFollowMode eMode) if (!IsBlockMode()) InitBlockMode(aViewData.GetCurX(), aViewData.GetCurY(), nTab, true); - lcl_moveCursorByProtRule(nBlockEndX, nBlockEndY, nMovX, nMovY, nTab, pDoc); + moveCursorByProtRule(nBlockEndX, nBlockEndY, nMovX, nMovY, nTab, pDoc); if (nBlockEndX < 0) nBlockEndX = 0; |