summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2017-12-13 18:19:16 +0100
committerMarco Cecchetti <mrcekets@gmail.com>2017-12-16 14:14:32 +0100
commitb18e58d98f2f2c89d97140e9eea3094d5d238e6f (patch)
tree4e7f5f842e61ab8136aa8a0355d423ba02e5518f
parent7a5efaa02cbe4140c017d8777993479369c2f10a (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/46529 Reviewed-by: Marco Cecchetti <mrcekets@gmail.com> Tested-by: Marco Cecchetti <mrcekets@gmail.com>
-rw-r--r--sc/source/ui/docshell/olinefun.cxx109
1 files changed, 83 insertions, 26 deletions
diff --git a/sc/source/ui/docshell/olinefun.cxx b/sc/source/ui/docshell/olinefun.cxx
index 6e7f42cbc635..410c6e1bc58a 100644
--- a/sc/source/ui/docshell/olinefun.cxx
+++ b/sc/source/ui/docshell/olinefun.cxx
@@ -24,6 +24,7 @@
#include <docsh.hxx>
#include <olinetab.hxx>
#include <tabvwsh.hxx>
+#include <inputhdl.hxx>
#include <undodat.hxx>
#include <globstr.hrc>
#include <sc.hrc>
@@ -78,6 +79,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();
@@ -330,7 +357,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 );
@@ -358,8 +387,15 @@ 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 && lcl_IsAnyViewEditingInEntryRange(bColumns, nThisStart, nThisEnd))
+ continue;
+
if (bShow) // enable
{
pEntry->SetHidden( false );
@@ -372,12 +408,20 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
}
else // hidden below
{
- 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 );
@@ -397,16 +441,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;
}
@@ -435,7 +479,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 );
@@ -505,18 +551,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;
@@ -559,7 +605,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 );
@@ -628,7 +676,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)
@@ -689,6 +739,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 );
@@ -696,10 +750,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 ???
}
@@ -716,7 +766,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)
@@ -752,6 +808,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 );
@@ -759,9 +819,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 ???
}