Kaydet (Commit) b18e58d9 authored tarafından Marco Cecchetti's avatar Marco Cecchetti Kaydeden (comit) Marco Cecchetti

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/46529Reviewed-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
Tested-by: 's avatarMarco Cecchetti <mrcekets@gmail.com>
üst 7a5efaa0
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <docsh.hxx> #include <docsh.hxx>
#include <olinetab.hxx> #include <olinetab.hxx>
#include <tabvwsh.hxx> #include <tabvwsh.hxx>
#include <inputhdl.hxx>
#include <undodat.hxx> #include <undodat.hxx>
#include <globstr.hrc> #include <globstr.hrc>
#include <sc.hrc> #include <sc.hrc>
...@@ -78,6 +79,32 @@ static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab, ...@@ -78,6 +79,32 @@ static void lcl_PaintWidthHeight( ScDocShell& rDocShell, SCTAB nTab,
rDocShell.PostPaint( nStartCol,nStartRow,nTab, MAXCOL,MAXROW,nTab, nParts ); 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 ) void ScOutlineDocFunc::MakeOutline( const ScRange& rRange, bool bColumns, bool bRecord, bool bApi )
{ {
SCCOL nStartCol = rRange.aStart.Col(); SCCOL nStartCol = rRange.aStart.Col();
...@@ -330,7 +357,9 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -330,7 +357,9 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
SCCOLROW nStart, nEnd; SCCOLROW nStart, nEnd;
rArray.GetRange( 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 ); ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
...@@ -358,8 +387,15 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -358,8 +387,15 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
ScOutlineEntry* pEntry; ScOutlineEntry* pEntry;
while ((pEntry=aIter.GetNext()) != nullptr) while ((pEntry=aIter.GetNext()) != nullptr)
{ {
SCCOLROW nThisStart = pEntry->GetStart();
SCCOLROW nThisEnd = pEntry->GetEnd();
sal_uInt16 nThisLevel = aIter.LastLevel(); sal_uInt16 nThisLevel = aIter.LastLevel();
bool bShow = (nThisLevel < nLevel); bool bShow = (nThisLevel < nLevel);
if (!bShow && lcl_IsAnyViewEditingInEntryRange(bColumns, nThisStart, nThisEnd))
continue;
if (bShow) // enable if (bShow) // enable
{ {
pEntry->SetHidden( false ); pEntry->SetHidden( false );
...@@ -372,12 +408,20 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -372,12 +408,20 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
} }
else // hidden below 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(); for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
SCCOLROW nThisEnd = pEntry->GetEnd();
for (SCCOLROW i=nThisStart; i<=nThisEnd; i++)
{ {
if ( bColumns ) if ( bColumns )
rDoc.ShowCol( static_cast<SCCOL>(i), nTab, bShow ); rDoc.ShowCol( static_cast<SCCOL>(i), nTab, bShow );
...@@ -397,16 +441,16 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -397,16 +441,16 @@ bool ScOutlineDocFunc::SelectLevel( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
rDoc.SetDrawPageSize(nTab); rDoc.SetDrawPageSize(nTab);
rDoc.UpdatePageBreaks( nTab ); rDoc.UpdatePageBreaks( nTab );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1);
if (bPaint) if (bPaint)
lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
rDocShell.SetDocumentModified(); rDocShell.SetDocumentModified();
lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, 0);
return true; return true;
} }
...@@ -435,7 +479,9 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord ) ...@@ -435,7 +479,9 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord )
SCCOLROW nMax; SCCOLROW nMax;
SCCOLROW i; 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 ); ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
...@@ -505,18 +551,18 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord ) ...@@ -505,18 +551,18 @@ bool ScOutlineDocFunc::ShowMarkedOutlines( const ScRange& rRange, bool bRecord )
rDoc.SetDrawPageSize(nTab); rDoc.SetDrawPageSize(nTab);
rDoc.UpdatePageBreaks( 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(); ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh ) if ( pViewSh )
{ {
pViewSh->OnLOKShowHideOutline(/*columns: */ true, nMinStartCol - 1); pViewSh->OnLOKShowHideOutline(/*columns: */ true, nMinStartCol - 1);
pViewSh->OnLOKShowHideOutline(/*columns: */ false, nMinStartRow - 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; return bDone;
...@@ -559,7 +605,9 @@ bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord ) ...@@ -559,7 +605,9 @@ bool ScOutlineDocFunc::HideMarkedOutlines( const ScRange& rRange, bool bRecord )
rRowArray.FindTouchedLevel( nStartRow, nEndRow, nRowLevel ); rRowArray.FindTouchedLevel( nStartRow, nEndRow, nRowLevel );
rRowArray.ExtendBlock( nRowLevel, nEffStartRow, nEffEndRow ); 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 ); ScOutlineTable* pUndoTab = new ScOutlineTable( *pTable );
ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
...@@ -628,7 +676,9 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -628,7 +676,9 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
SCCOLROW nStart = pEntry->GetStart(); SCCOLROW nStart = pEntry->GetStart();
SCCOLROW nEnd = pEntry->GetEnd(); 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 ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
if (bColumns) if (bColumns)
...@@ -689,6 +739,10 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -689,6 +739,10 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
rDoc.InvalidatePageBreaks(nTab); rDoc.InvalidatePageBreaks(nTab);
rDoc.UpdatePageBreaks( nTab ); rDoc.UpdatePageBreaks( nTab );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1);
if (bPaint) if (bPaint)
lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
...@@ -696,10 +750,6 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -696,10 +750,6 @@ bool ScOutlineDocFunc::ShowOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1);
return true; //! always ??? return true; //! always ???
} }
...@@ -716,7 +766,13 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -716,7 +766,13 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
SCCOLROW nStart = pEntry->GetStart(); SCCOLROW nStart = pEntry->GetStart();
SCCOLROW nEnd = pEntry->GetEnd(); 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 ); ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
if (bColumns) if (bColumns)
...@@ -752,6 +808,10 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -752,6 +808,10 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
rDoc.InvalidatePageBreaks(nTab); rDoc.InvalidatePageBreaks(nTab);
rDoc.UpdatePageBreaks( nTab ); rDoc.UpdatePageBreaks( nTab );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1);
if (bPaint) if (bPaint)
lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd ); lcl_PaintWidthHeight( rDocShell, nTab, bColumns, nStart, nEnd );
...@@ -759,9 +819,6 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel ...@@ -759,9 +819,6 @@ bool ScOutlineDocFunc::HideOutline( SCTAB nTab, bool bColumns, sal_uInt16 nLevel
lcl_InvalidateOutliner( rDocShell.GetViewBindings() ); lcl_InvalidateOutliner( rDocShell.GetViewBindings() );
ScTabViewShell* pViewSh = rDocShell.GetBestViewShell();
if ( pViewSh )
pViewSh->OnLOKShowHideOutline(bColumns, nStart - 1);
return true; //! always ??? return true; //! always ???
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment