diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2017-12-13 18:19:16 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-12-15 13:59:32 +0100 |
commit | 1d7fc3d615f611c1a3729c92dbef363a1357f0cd (patch) | |
tree | 85d9fdbc896e77fa6749658c9ef785c873a8bcc4 | |
parent | 5651eb34534db14851d4107435ca75e8f414124a (diff) |
lok: sc: handling conflicts btw group collapsing and cell editing
Now when a cell is edited, a group including the cell in its range
can't be collapsed.
When whole levels are collapsed all together any group entry including
an edited cell is skipped from collapsing.
Undo/redo of collapsing/expanding has been (temporarily) disabled in
the LOK case, since it could mess things up when a cell is edited and
a group is collapsed because of an undo/redo.
Change-Id: I401fa69b7a0275e3e14428b16ab48c409408a861
Reviewed-on: https://gerrit.libreoffice.org/46544
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | sc/source/ui/docshell/olinefun.cxx | 111 |
1 files changed, 84 insertions, 27 deletions
diff --git a/sc/source/ui/docshell/olinefun.cxx b/sc/source/ui/docshell/olinefun.cxx index c2e56231cc74..2e07e6d2d2c0 100644 --- a/sc/source/ui/docshell/olinefun.cxx +++ b/sc/source/ui/docshell/olinefun.cxx @@ -28,6 +28,7 @@ #include "sc.hrc" #include <tabvwsh.hxx> +#include <inputhdl.hxx> #include <sfx2/lokhelper.hxx> #include <comphelper/lok.hxx> @@ -77,6 +78,32 @@ static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab, rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts ); } +static bool lcl_IsAnyViewEditingInEntryRange(bool bColumns, SCCOLROW nStart, SCCOLROW nEnd) +{ + if (comphelper::LibreOfficeKit::isActive()) + { + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell); + if (pTabViewShell) + { + ScInputHandler* pInputHandler = pTabViewShell->GetInputHandler(); + if (pInputHandler && pInputHandler->GetActiveView()) + { + const ScViewData& rViewData = pTabViewShell->GetViewData(); + SCCOLROW nPos = bColumns ? rViewData.GetCurX() : rViewData.GetCurY(); + if (nStart <= nPos && nPos <= nEnd) + return true; + } + } + pViewShell = SfxViewShell::GetNext(*pViewShell); + } + } + return false; +} + + void ScOutlineDocFunc::MakeOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi ) { SCCOL nStartCol = rRange.aStart.Col(); @@ -333,7 +360,9 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel SCCOLROW nStart, nEnd; rArray.GetRange( nStart, nEnd ); - if ( bRecord ) + // TODO undo can mess things up when another view is editing a cell in the range of group entry + // this is a temporarily workaround + if (!comphelper::LibreOfficeKit::isActive() && bRecord ) { ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); @@ -361,9 +390,16 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ScOutlineEntry* pEntry; while ((pEntry=aIter.GetNext()) != nullptr) { + SCCOLROW nThisStart = pEntry->GetStart(); + SCCOLROW nThisEnd = pEntry->GetEnd(); + sal_uInt16 nThisLevel = aIter.LastLevel(); bool bShow = (nThisLevel < nLevel); - if (bShow) // einblenden + + if (!bShow && lcl_IsAnyViewEditingInEntryRange(bColumns, nThisStart, nThisEnd)) + continue; + + if (bShow) // enable { pEntry->SetHidden( false ); pEntry->SetVisible( true ); @@ -375,12 +411,20 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel } else // verdeckt { - pEntry->SetVisible( false ); + if (comphelper::LibreOfficeKit::isActive() && nThisLevel > 0) + { + pEntry->SetHidden( true ); + const ScOutlineEntry* pParentEntry = rArray.GetEntryByPos(nThisLevel - 1, nThisStart); + if (pParentEntry && pParentEntry->IsHidden()) + pEntry->SetVisible( false ); + } + else + { + pEntry->SetVisible( false ); + } } - SCCOLROW nThisStart = pEntry->GetStart(); - SCCOLROW nThisEnd = pEntry->GetEnd(); - for (SCCOLROW i=nThisStart; i<=nThisEnd; i++) + for (SCCOLROW i=nThisStart; i<=nThisEnd; i++) { if ( bColumns ) rDoc.ShowCol( static_cast<SCCOL>(i), nTab, bShow ); @@ -400,16 +444,16 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel rDoc.SetDrawPageSize(nTab); rDoc.UpdatePageBreaks( nTab ); + ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); + if ( pViewSh ) + pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1); + if (bPaint) lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); rDocShell.SetDocumentModified(); lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); - ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); - if ( pViewSh ) - pViewSh->OnLOKShowHideOutline(bColumns, 0); - return true; } @@ -438,7 +482,9 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord ) SCCOLROW nMax; SCCOLROW i; - if ( bRecord ) + // TODO undo can mess things up when another view is editing a cell in the range of group entry + // this is a temporarily workaround + if ( !comphelper::LibreOfficeKit::isActive() && bRecord ) { ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); @@ -508,18 +554,18 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord ) rDoc.SetDrawPageSize(nTab); rDoc.UpdatePageBreaks( nTab ); - rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top ); - rDocShell.SetDocumentModified(); - bDone = true; - - lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); - ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); if ( pViewSh ) { pViewSh->OnLOKShowHideOutline(/*columns: */ true, nMinStartCol - 1); pViewSh->OnLOKShowHideOutline(/*columns: */ false, nMinStartRow - 1); } + + rDocShell.PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top ); + rDocShell.SetDocumentModified(); + bDone = true; + + lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); } return bDone; @@ -562,7 +608,9 @@ bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord ) rRowArray.FindTouchedLevel( nStartRow, nEndRow, nRowLevel ); rRowArray.ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow ); - if ( bRecord ) + // TODO undo can mess things up when another view is editing a cell in the range of group entry + // this is a temporarily workaround + if ( !comphelper::LibreOfficeKit::isActive() && bRecord ) { ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); @@ -631,7 +679,9 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel SCCOLROW nStart = pEntry->GetStart(); SCCOLROW nEnd = pEntry->GetEnd(); - if ( bRecord ) + // TODO undo can mess things up when another view is editing a cell in the range of group entry + // this is a temporarily workaround + if ( !comphelper::LibreOfficeKit::isActive() && bRecord ) { ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); if (bColumns) @@ -692,6 +742,10 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel rDoc.InvalidatePageBreaks(nTab); rDoc.UpdatePageBreaks( nTab ); + ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); + if ( pViewSh ) + pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1); + if (bPaint) lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); @@ -699,10 +753,6 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); - ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); - if ( pViewSh ) - pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1); - return true; //! always ??? } @@ -719,7 +769,13 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel SCCOLROW nStart = pEntry->GetStart(); SCCOLROW nEnd = pEntry->GetEnd(); - if ( bRecord ) + + if (lcl_IsAnyViewEditingInEntryRange(bColumns, nStart, nEnd)) + return false; + + // TODO undo can mess things up when another view is editing a cell in the range of group entry + // this is a temporarily workaround + if ( !comphelper::LibreOfficeKit::isActive() && bRecord ) { ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); if (bColumns) @@ -755,6 +811,10 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel rDoc.InvalidatePageBreaks(nTab); rDoc.UpdatePageBreaks( nTab ); + ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); + if ( pViewSh ) + pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1); + if (bPaint) lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); @@ -762,9 +822,6 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); - ScTabViewShell* pViewSh = rDocShell.GetBestViewShell(); - if ( pViewSh ) - pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1); return true; //! always ??? } |