From 61ddf34cf72bdfb738706b0836d9ecb6c0186d5d Mon Sep 17 00:00:00 2001 From: Marco Cecchetti Date: Wed, 29 Mar 2017 13:17:43 +0200 Subject: lok - sc: invalidation of cached row/col positions on several cases Cached row positions are invalidated when one of the following event occurs: - one or more rows are inserted - one or more rows are deleted - one or more hidden rows are made visible - one or more visible rows are made hidden - one row is resized - optimal row height is changed - the value of the PPTY parameter is updated - a undo/redo involving any of the above actions The same occurs for cached column positions. The solution takes care of row/column operations performed in another view and of the current tab each view is displaying Change-Id: I57895506b17986d36ab024eec9c79864ea95dad7 Reviewed-on: https://gerrit.libreoffice.org/40449 Tested-by: Jenkins Reviewed-by: Marco Cecchetti --- sc/source/ui/docshell/docfunc.cxx | 4 ++++ sc/source/ui/inc/viewdata.hxx | 3 +++ sc/source/ui/inc/viewfunc.hxx | 1 + sc/source/ui/undo/undoblk2.cxx | 3 +++ sc/source/ui/view/viewdata.cxx | 25 +++++++++++++++++++++++++ sc/source/ui/view/viewfunc.cxx | 28 ++++++++++++++++++++++++++++ 6 files changed, 64 insertions(+) (limited to 'sc') diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 7a85a367d36d..8cdfa9f12de8 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -3668,6 +3668,10 @@ bool ScDocFunc::SetWidthOrHeight( rDoc.UpdatePageBreaks( nTab ); + ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); + if (pViewSh) + pViewSh->OnLOKSetWidthOrHeight(nStart, bWidth); + rDocShell.PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PaintPartFlags::All); aModificator.SetDocumentModified(); diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx index 0b3fbb2f61b3..63b863b87bf8 100644 --- a/sc/source/ui/inc/viewdata.hxx +++ b/sc/source/ui/inc/viewdata.hxx @@ -343,6 +343,9 @@ public: ScPositionHelper& GetLOKWidthHelper() { return pThisTab->aWidthHelper; } ScPositionHelper& GetLOKHeightHelper() { return pThisTab->aHeightHelper; } + ScPositionHelper* GetLOKWidthHelper(SCTAB nTabIndex); + ScPositionHelper* GetLOKHeightHelper(SCTAB nTabIndex); + ScSplitMode GetHSplitMode() const { return pThisTab->eHSplitMode; } ScSplitMode GetVSplitMode() const { return pThisTab->eVSplitMode; } long GetHSplitPos() const { return pThisTab->nHSplitPos; } diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx index 20ed2bccb09e..c4ea49c98f01 100644 --- a/sc/source/ui/inc/viewfunc.hxx +++ b/sc/source/ui/inc/viewfunc.hxx @@ -325,6 +325,7 @@ public: void OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset); void OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset); + void OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth); // Internal helper functions protected: diff --git a/sc/source/ui/undo/undoblk2.cxx b/sc/source/ui/undo/undoblk2.cxx index cdf75b9f1882..8a1247cbca14 100644 --- a/sc/source/ui/undo/undoblk2.cxx +++ b/sc/source/ui/undo/undoblk2.cxx @@ -101,6 +101,9 @@ void ScUndoWidthOrHeight::Undo() ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end(); for (; itr != itrEnd && *itr < nTabCount; ++itr) { + if (pViewShell) + pViewShell->OnLOKSetWidthOrHeight(nStart, bWidth); + if (bWidth) // Width { pUndoDoc->CopyToDocument(static_cast(nStart), 0, *itr, diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 88d2c8e56418..10a5d01144c0 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1864,6 +1864,24 @@ void ScViewData::SetTabNo( SCTAB nNewTab ) RecalcPixPos(); //! not always needed! } +ScPositionHelper* ScViewData::GetLOKWidthHelper(SCTAB nTabIndex) +{ + if (!ValidTab(nTabIndex) || !(nTabIndex < static_cast(maTabData.size()))) + { + return nullptr; + } + return &(maTabData[nTabIndex]->aWidthHelper); +} + +ScPositionHelper* ScViewData::GetLOKHeightHelper(SCTAB nTabIndex) +{ + if (!ValidTab(nTabIndex) || !(nTabIndex < static_cast(maTabData.size()))) + { + return nullptr; + } + return &(maTabData[nTabIndex]->aHeightHelper); +} + void ScViewData::SetActivePart( ScSplitPos eNewActive ) { pThisTab->eWhichActive = eNewActive; @@ -2542,6 +2560,8 @@ void ScViewData::UpdateScreenZoom( const Fraction& rNewX, const Fraction& rNewY void ScViewData::CalcPPT() { + double nOldPPTX = nPPTX; + double nOldPPTY = nPPTY; nPPTX = ScGlobal::nScreenPPTX * (double) GetZoomX(); if (pDocShell) nPPTX = nPPTX / pDocShell->GetOutputFactor(); // Factor is printer to screen @@ -2578,6 +2598,11 @@ void ScViewData::CalcPPT() } } } + + if (nPPTX != nOldPPTX) + GetLOKWidthHelper().invalidateByPosition(0L); + if (nPPTY != nOldPPTY) + GetLOKHeightHelper().invalidateByPosition(0L); } #define SC_OLD_TABSEP '/' diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 5eae272a9a43..e2fa26b2fcd9 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -80,6 +80,7 @@ #include #include #include +#include #include @@ -1478,6 +1479,8 @@ void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset) ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); if (pTabViewShell) { + pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)->invalidateByIndex(nStartCol); + // if we remove a column the cursor position and the current selection // in other views could need to be moved on the left by one column. if (pTabViewShell != this) @@ -1526,6 +1529,8 @@ void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset) ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); if (pTabViewShell) { + pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)->invalidateByIndex(nStartRow); + // if we remove a row the cursor position and the current selection // in other views could need to be moved up by one row. if (pTabViewShell != this) @@ -1562,6 +1567,27 @@ void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset) } } +void ScViewFunc::OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth) +{ + if (!comphelper::LibreOfficeKit::isActive()) + return; + + SCTAB nCurTab = GetViewData().GetTabNo(); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); + if (pTabViewShell) + { + if (bWidth) + pTabViewShell->GetViewData().GetLOKWidthHelper(nCurTab)->invalidateByIndex(nStart); + else + pTabViewShell->GetViewData().GetLOKHeightHelper(nCurTab)->invalidateByIndex(nStart); + } + pViewShell = SfxViewShell::GetNext(*pViewShell); + } +} + // insert cells - undo OK bool ScViewFunc::InsertCells( InsCellCmd eCmd, bool bRecord, bool bPartOfPaste ) @@ -2012,6 +2038,8 @@ void ScViewFunc::SetWidthOrHeight( SCCOLROW nStart = rRanges.front().mnStart; SCCOLROW nEnd = rRanges.back().mnEnd; + OnLOKSetWidthOrHeight(nStart, bWidth); + bool bFormula = false; if ( eMode == SC_SIZE_OPTIMAL ) { -- cgit