Resolves: tdf#146994 InitOwnBlockMode() with current mark range or cursor pos
This sets specifically the end position to the correct value. The
start position and dependent logic if meBlockMode==Own is
re-initialized in MarkCursor() via InitBlockMode(). Unfortunately
that (calling MarkCursor()) happens after the end position was
incremented in ExpandBlock(), previous with the wrong values.
This new own block mode init now also makes it possible to
expand/shrink the marked range after a paste or undo/redo, as it
would be expected for any existing selection.
Change-Id: Id26e4aa32896ec0c714e33b99dbf6702df144995
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129158
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index 0bdc143..81151f1 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -521,7 +521,7 @@ public:
void InitBlockMode( SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
bool bTestNeg = false,
bool bCols = false, bool bRows = false, bool bForceNeg = false );
void InitOwnBlockMode();
void InitOwnBlockMode( const ScRange& rMarkRange );
void DoneBlockMode( bool bContinue = false );
bool IsBlockMode() const;
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index be93e37..998330b 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1690,7 +1690,7 @@ void ScUndoUseScenario::Undo()
if (pViewShell)
{
pViewShell->DoneBlockMode();
pViewShell->InitOwnBlockMode();
pViewShell->InitOwnBlockMode( aRange );
}
ScDocument& rDoc = pDocShell->GetDocument();
@@ -1747,7 +1747,7 @@ void ScUndoUseScenario::Redo()
{
pViewShell->SetTabNo( nTab );
pViewShell->DoneBlockMode();
pViewShell->InitOwnBlockMode();
pViewShell->InitOwnBlockMode( aRange );
}
pDocShell->UseScenario( nTab, aName, false );
diff --git a/sc/source/ui/undo/undoutil.cxx b/sc/source/ui/undo/undoutil.cxx
index fc0e71b..de9a50e 100644
--- a/sc/source/ui/undo/undoutil.cxx
+++ b/sc/source/ui/undo/undoutil.cxx
@@ -43,11 +43,11 @@ void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
if ( nViewTab < nStartZ || nViewTab > nEndZ )
pViewShell->SetTabNo( nStartZ );
const ScRange aMarkRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ);
pViewShell->DoneBlockMode();
pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, false, false );
pViewShell->InitOwnBlockMode();
pViewShell->GetViewData().GetMarkData().
SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
pViewShell->InitOwnBlockMode( aMarkRange );
pViewShell->GetViewData().GetMarkData().SetMarkArea( aMarkRange );
pViewShell->MarkDataChanged();
}
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index e933830..5c6d599 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -724,7 +724,7 @@ sal_Bool SAL_CALL ScTabViewObj::select( const uno::Any& aSelection )
if ( !lcl_TabInRanges( rViewData.GetTabNo(), rRanges ) )
pViewSh->SetTabNo( rFirst.aStart.Tab() );
pViewSh->DoneBlockMode();
pViewSh->InitOwnBlockMode();
pViewSh->InitOwnBlockMode( rFirst ); /* TODO: or even the overall range? */
rViewData.GetMarkData().MarkFromRangeList( rRanges, true );
pViewSh->MarkDataChanged();
rViewData.GetDocShell()->PostPaintGridAll(); // Marks (old&new)
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 29479c7..5177342 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -587,10 +587,10 @@ void ScDBFunc::DoSubTotals( const ScSubTotalParam& rParam, bool bRecord,
pDBData->SetArea( nTab, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
rDoc.CompileDBFormula();
const ScRange aMarkRange( aNewParam.nCol1, aNewParam.nRow1, nTab, aNewParam.nCol2, aNewParam.nRow2, nTab);
DoneBlockMode();
InitOwnBlockMode();
rMark.SetMarkArea( ScRange( aNewParam.nCol1,aNewParam.nRow1,nTab,
aNewParam.nCol2,aNewParam.nRow2,nTab ) );
InitOwnBlockMode( aMarkRange );
rMark.SetMarkArea( aMarkRange );
MarkDataChanged();
pDocSh->PostPaint(ScRange(0, 0, nTab, rDoc.MaxCol(), rDoc.MaxRow(), nTab),
diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx
index ecfcd036c..aae991e 100644
--- a/sc/source/ui/view/tabview2.cxx
+++ b/sc/source/ui/view/tabview2.cxx
@@ -329,7 +329,7 @@ bool ScTabView::IsMarking( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
&& nBlockStartZ == nTab;
}
void ScTabView::InitOwnBlockMode()
void ScTabView::InitOwnBlockMode( const ScRange& rMarkRange )
{
if (IsBlockMode())
return;
@@ -340,12 +340,12 @@ void ScTabView::InitOwnBlockMode()
GetSelEngine()->CursorPosChanging( false, false );
meBlockMode = Own;
nBlockStartX = 0;
nBlockStartY = 0;
nBlockStartZ = 0;
nBlockEndX = 0;
nBlockEndY = 0;
nBlockEndZ = 0;
nBlockStartX = rMarkRange.aStart.Col();
nBlockStartY = rMarkRange.aStart.Row();
nBlockStartZ = rMarkRange.aStart.Tab();
nBlockEndX = rMarkRange.aEnd.Col();
nBlockEndY = rMarkRange.aEnd.Row();
nBlockEndZ = rMarkRange.aEnd.Tab();
SelectionChanged(); // status is checked with mark set
}
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index 7e6fec2..4471b36 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -1241,7 +1241,7 @@ void ScTabView::MoveCursorAbs( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
{
rMark.ResetMark();
DoneBlockMode();
InitOwnBlockMode();
InitOwnBlockMode( ScRange( nCurX, nCurY, aViewData.GetTabNo()));
MarkDataChanged();
}
}
@@ -1737,7 +1737,9 @@ void ScTabView::Unmark()
void ScTabView::SetMarkData( const ScMarkData& rNew )
{
DoneBlockMode();
InitOwnBlockMode();
ScRange aMarkArea( ScAddress::UNINITIALIZED );
rNew.GetMarkArea( aMarkArea );
InitOwnBlockMode( aMarkArea );
aViewData.GetMarkData() = rNew;
MarkDataChanged();
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index fd19f83..49b8fc14 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2008,7 +2008,7 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
}
DoneBlockMode(true); // don't delete mark
InitOwnBlockMode();
InitOwnBlockMode( ScRange( nCol, nRow, nStartTab, nCol, nRow, nEndTab));
// If search starts at the beginning don't ask again whether it shall start at the beginning
bool bFirst = true;
@@ -2359,7 +2359,7 @@ void ScViewFunc::UseScenario( const OUString& rName )
SCTAB nTab = GetViewData().GetTabNo();
DoneBlockMode();
InitOwnBlockMode();
InitOwnBlockMode( ScRange( GetViewData().GetCurX(), GetViewData().GetCurY(), nTab));
pDocSh->UseScenario( nTab, rName );
}
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 679557d..5d08071 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -111,7 +111,7 @@ void ScViewFunc::CutToClip()
if ( !rMark.IsMarked() && !rMark.IsMultiMarked() ) // mark the range if not marked yet
{
DoneBlockMode();
InitOwnBlockMode();
InitOwnBlockMode( aRange );
rMark.SetMarkArea( aRange );
MarkDataChanged();
}
@@ -1270,7 +1270,7 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
if (GetViewData().IsActive())
{
DoneBlockMode();
InitOwnBlockMode();
InitOwnBlockMode( aUserRange );
}
rMark.SetMarkArea( aUserRange );
MarkDataChanged();
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 8d444122..a9a2b36 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -1063,7 +1063,7 @@ void ScViewFunc::ApplyPatternLines( const ScPatternAttr& rAttr, const SvxBoxItem
aMarkRange = ScRange( GetViewData().GetCurX(),
GetViewData().GetCurY(), GetViewData().GetTabNo() );
DoneBlockMode();
InitOwnBlockMode();
InitOwnBlockMode( aMarkRange );
aFuncMark.SetMarkArea(aMarkRange);
MarkDataChanged();
}
@@ -2366,9 +2366,10 @@ void ScViewFunc::SetMarkedWidthOrHeight( bool bWidth, ScSizeMode eMode, sal_uInt
SCCOL nCol = GetViewData().GetCurX();
SCROW nRow = GetViewData().GetCurY();
SCTAB nTab = GetViewData().GetTabNo();
const ScRange aMarkRange( nCol, nRow, nTab);
DoneBlockMode();
InitOwnBlockMode();
rMark.SetMultiMarkArea( ScRange( nCol,nRow,nTab ) );
InitOwnBlockMode( aMarkRange );
rMark.SetMultiMarkArea( aMarkRange );
MarkDataChanged();
}