sc/inc/document.hxx | 4 sc/inc/table.hxx | 6 - sc/qa/unit/subsequent_export-test.cxx | 12 +- sc/qa/unit/ucalc_sharedformula.cxx | 2 sc/source/core/data/dociter.cxx | 4 sc/source/core/data/documen3.cxx | 2 sc/source/core/data/document.cxx | 6 - sc/source/core/data/table1.cxx | 23 ++-- sc/source/core/data/table2.cxx | 25 +++- sc/source/core/data/table5.cxx | 2 sc/source/filter/rtf/eeimpars.cxx | 2 sc/source/filter/xcl97/xcl97rec.cxx | 2 sc/source/filter/xml/xmlexprt.cxx | 2 sc/source/ui/docshell/docfunc.cxx | 181 +++++++++++++++------------------- sc/source/ui/docshell/docsh5.cxx | 2 sc/source/ui/inc/docfunc.hxx | 8 + sc/source/ui/inc/viewfunc.hxx | 2 sc/source/ui/undo/undobase.cxx | 2 sc/source/ui/undo/undoblk.cxx | 6 - sc/source/ui/undo/undoblk3.cxx | 6 - sc/source/ui/vba/vbaworksheet.cxx | 12 +- sc/source/ui/view/gridwin.cxx | 2 sc/source/ui/view/select.cxx | 2 sc/source/ui/view/tabview2.cxx | 10 - sc/source/ui/view/tabview3.cxx | 2 sc/source/ui/view/tabvwsh3.cxx | 4 sc/source/ui/view/viewfun2.cxx | 6 - sc/source/ui/view/viewfun3.cxx | 2 sc/source/ui/view/viewfun4.cxx | 2 sc/source/ui/view/viewfunc.cxx | 21 ++- 30 files changed, 182 insertions(+), 180 deletions(-)
New commits: commit 964f6eda20c4ce6415bd66fd228526b44e5b3159 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Wed Feb 10 11:58:52 2021 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:21:09 2021 +0200 Don't shrink row height when deleting cell contents interactively either Follow-up to e763e13873adfe3c6abfa4c2dfd3ac3847e2d494. Such shrinking of row height, typically by a few silly pixels, just causes unnecessary invalidation thrash in a collaborative editing context. Change-Id: I5651ce994ba4bf82c83d7d4ef1bb8ed5bab0a66d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110696 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <t...@collabora.com> diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx index c965a71196a7..a24546516df5 100644 --- a/sc/qa/unit/ucalc_sharedformula.cxx +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -2411,7 +2411,7 @@ void Test::testSharedFormulaDeleteTopCell() // Delete cell A1. ScMarkData aMark(m_pDoc->GetSheetLimits()); aMark.SelectOneTable(0); - getDocShell().GetDocFunc().DeleteCell( ScAddress(0,0,0), aMark, InsertDeleteFlags::CONTENTS, false); + getDocShell().GetDocFunc().DeleteCell( ScAddress(0,0,0), aMark, InsertDeleteFlags::CONTENTS, false, /*bApi=*/ true); // Check it's gone. CPPUNIT_ASSERT(!m_pDoc->GetFormulaCell( ScAddress(0,0,0))); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 2949e92390f1..951048e43869 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -660,7 +660,7 @@ bool ScDocFunc::DeleteContents( } bool ScDocFunc::DeleteCell( - const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord ) + const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ) { ScDocShellModificator aModificator(rDocShell); @@ -716,7 +716,7 @@ bool ScDocFunc::DeleteCell( nFlags, pDataSpans, false, bDrawUndo); } - if (!AdjustRowHeight(rPos, true, true)) + if (!AdjustRowHeight(rPos, true, bApi)) rDocShell.PostPaint( rPos.Col(), rPos.Row(), rPos.Tab(), rPos.Col(), rPos.Row(), rPos.Tab(), PaintPartFlags::Grid, nExtFlags); diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index f8319295b2f0..d52d0225b167 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -92,7 +92,7 @@ public: const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ); bool DeleteCell( - const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord ); + const ScAddress& rPos, const ScMarkData& rMark, InsertDeleteFlags nFlags, bool bRecord, bool bApi ); bool TransliterateText( const ScMarkData& rMark, TransliterationFlags nType, bool bApi ); diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index ac08fb699380..f59f5e37820c 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -1982,10 +1982,14 @@ void ScViewFunc::DeleteContents( InsertDeleteFlags nFlags ) HideAllCursors(); // for if summary is cancelled ScDocFunc& rDocFunc = pDocSh->GetDocFunc(); + + // Can we really be sure that we can pass the bApi parameter as false to DeleteCell() and + // DeleteContents() here? (Meaning that this is interactive use.) Is this never invoked from + // scripting and whatnot? if (bSimple) - rDocFunc.DeleteCell(aMarkRange.aStart, aFuncMark, nFlags, bRecord); + rDocFunc.DeleteCell(aMarkRange.aStart, aFuncMark, nFlags, bRecord, /*bApi=*/ false); else - rDocFunc.DeleteContents(aFuncMark, nFlags, bRecord, false); + rDocFunc.DeleteContents(aFuncMark, nFlags, bRecord, /*bApi=*/ false); pDocSh->UpdateOle(GetViewData()); commit 88e6fc0d1e69a6514e57f5b6e05ad41dcae0610a Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Tue Feb 2 10:39:21 2021 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:20:13 2021 +0200 Don't bother shrinking row height when changing just one row interactively This reverts dca0374fb1edbd9bdeeaadda3f1866ce66b3a778 and instead tries to achieve the same without using a flag in ScGlobal. How reliable that is I don't know. See https://gerrit.libreoffice.org/c/core/+/110245 for discussion. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110245 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Michael Meeks <michael.me...@collabora.com> Change-Id: I2a7aa5bf3d29e5fd071e2f1cab628b923b5b6754 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110285 Reviewed-by: Tor Lillqvist <t...@collabora.com> Tested-by: Tor Lillqvist <t...@collabora.com> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 98f5d441c95f..02f0aa163f3b 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1907,7 +1907,7 @@ public: const ScColWidthParam* pParam = nullptr ); SC_DLLPUBLIC bool SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW nStartRow, - SCROW nEndRow, SCTAB nTab ); + SCROW nEndRow, SCTAB nTab, bool bApi ); void UpdateAllRowHeights( sc::RowHeightContext& rCxt, const ScMarkData* pTabMark ); diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 4cb67454bc76..21d33ccc35e9 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -813,8 +813,6 @@ public: /// Calc's threaded group calculation is in progress. SC_DLLPUBLIC static bool bThreadedGroupCalcInProgress; - - SC_DLLPUBLIC static bool bKeyInputInProgress; }; // maybe move to dbdata.hxx (?): diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index e4e4e67d4430..309d49d4f140 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -780,7 +780,7 @@ public: bool bFormula, const ScMarkData* pMarkData, const ScColWidthParam* pParam ); bool SetOptimalHeight( - sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, + sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, bool bApi, ScProgress* pOuterProgress = nullptr, sal_uLong nProgressStart = 0 ); void SetOptimalHeightOnly( @@ -797,7 +797,7 @@ public: void SetColWidthOnly( SCCOL nCol, sal_uInt16 nNewWidth ); void SetRowHeight( SCROW nRow, sal_uInt16 nNewHeight ); bool SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight, - double nPPTY ); + double nPPTY, bool bApi ); /** * Set specified row height to specified ranges. Don't check for drawing diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index 50ab34540265..27301007e433 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -2732,7 +2732,7 @@ void ScDocRowHeightUpdater::update() continue; mrDoc.maTabs[nTab]->SetOptimalHeight( - aCxt, aData.mnRow1, aData.mnRow2, &aProgress, nProgressStart); + aCxt, aData.mnRow1, aData.mnRow2, true, &aProgress, nProgressStart); nProgressStart += mrDoc.maTabs[nTab]->GetWeightedCount(aData.mnRow1, aData.mnRow2); } @@ -2760,7 +2760,7 @@ void ScDocRowHeightUpdater::updateAll() if (!ValidTab(nTab) || !mrDoc.maTabs[nTab]) continue; - mrDoc.maTabs[nTab]->SetOptimalHeight(aCxt, 0, mrDoc.MaxRow(), &aProgress, nProgressStart); + mrDoc.maTabs[nTab]->SetOptimalHeight(aCxt, 0, mrDoc.MaxRow(), true, &aProgress, nProgressStart); nProgressStart += mrDoc.maTabs[nTab]->GetWeightedCount(); } } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 820676d56cc6..5911cb686cb5 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -4094,7 +4094,7 @@ void ScDocument::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, { if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) maTabs[nTab]->SetRowHeightRange - ( nStartRow, nEndRow, nNewHeight, 1.0 ); + ( nStartRow, nEndRow, nNewHeight, 1.0, true ); } void ScDocument::SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, sal_uInt16 nNewHeight ) @@ -4255,13 +4255,13 @@ tools::Long ScDocument::GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab, return 0; } -bool ScDocument::SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab ) +bool ScDocument::SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bApi ) { ScTable* pTab = FetchTable(nTab); if (!pTab) return false; - return pTab->SetOptimalHeight(rCxt, nStartRow, nEndRow); + return pTab->SetOptimalHeight(rCxt, nStartRow, nEndRow, bApi); } void ScDocument::UpdateAllRowHeights( sc::RowHeightContext& rCxt, const ScMarkData* pTabMark ) diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 11ac1f1d3e83..fa4c2065540d 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -124,7 +124,7 @@ void GetOptimalHeightsInColumn( struct OptimalHeightsFuncObjBase { virtual ~OptimalHeightsFuncObjBase() {} - virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight) = 0; + virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight, bool bApi) = 0; }; struct SetRowHeightOnlyFunc : public OptimalHeightsFuncObjBase @@ -134,7 +134,7 @@ struct SetRowHeightOnlyFunc : public OptimalHeightsFuncObjBase mpTab(pTab) {} - virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight) override + virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight, bool /* bApi */) override { mpTab->SetRowHeightOnly(nStartRow, nEndRow, nHeight); return false; @@ -151,16 +151,17 @@ struct SetRowHeightRangeFunc : public OptimalHeightsFuncObjBase mnPPTY(nPPTY) {} - virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight) override + virtual bool operator() (SCROW nStartRow, SCROW nEndRow, sal_uInt16 nHeight, bool bApi) override { - return mpTab->SetRowHeightRange(nStartRow, nEndRow, nHeight, mnPPTY); + return mpTab->SetRowHeightRange(nStartRow, nEndRow, nHeight, mnPPTY, bApi); } }; bool SetOptimalHeightsToRows( sc::RowHeightContext& rCxt, OptimalHeightsFuncObjBase& rFuncObj, - ScBitMaskCompressedArray<SCROW, CRFlags>* pRowFlags, SCROW nStartRow, SCROW nEndRow ) + ScBitMaskCompressedArray<SCROW, CRFlags>* pRowFlags, SCROW nStartRow, SCROW nEndRow, + bool bApi ) { bool bChanged = false; SCROW nRngStart = 0; @@ -201,7 +202,7 @@ bool SetOptimalHeightsToRows( } else { - bChanged |= rFuncObj(nRngStart, nRngEnd, nLast); + bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi); nLast = 0; } } @@ -216,13 +217,13 @@ bool SetOptimalHeightsToRows( else { if (nLast) - bChanged |= rFuncObj(nRngStart, nRngEnd, nLast); + bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi); nLast = 0; } i += nMoreRows; // already handled - skip } if (nLast) - bChanged |= rFuncObj(nRngStart, nRngEnd, nLast); + bChanged |= rFuncObj(nRngStart, nRngEnd, nLast, bApi); return bChanged; } @@ -448,7 +449,7 @@ tools::Long ScTable::GetNeededSize( SCCOL nCol, SCROW nRow, } bool ScTable::SetOptimalHeight( - sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, + sc::RowHeightContext& rCxt, SCROW nStartRow, SCROW nEndRow, bool bApi, ScProgress* pOuterProgress, sal_uLong nProgressStart ) { assert(nStartRow <= nEndRow); @@ -470,7 +471,7 @@ bool ScTable::SetOptimalHeight( GetOptimalHeightsInColumn(rCxt, aCol, nStartRow, nEndRow, pProgress, nProgressStart); SetRowHeightRangeFunc aFunc(this, rCxt.getPPTY()); - bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); + bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow, bApi); if ( pProgress != pOuterProgress ) delete pProgress; @@ -498,7 +499,7 @@ void ScTable::SetOptimalHeightOnly( SetRowHeightOnlyFunc aFunc(this); - SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); + SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow, true); if ( pProgress != pOuterProgress ) delete pProgress; diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 4905e111e2f6..3eabcc585850 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -2873,7 +2873,7 @@ void ScTable::StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool bRem SCROW nEndRow = aData.mnRow2; if (aData.mbValue) - SetOptimalHeight(aCxt, nRow, nEndRow); + SetOptimalHeight(aCxt, nRow, nEndRow, true); nRow = nEndRow + 1; } @@ -3011,7 +3011,7 @@ namespace { */ bool lcl_pixelSizeChanged( ScFlatUInt16RowSegments& rRowHeights, SCROW nStartRow, SCROW nEndRow, - sal_uInt16 nNewHeight, double nPPTY) + sal_uInt16 nNewHeight, double nPPTY, bool bApi) { tools::Long nNewPix = static_cast<tools::Long>(nNewHeight * nPPTY); @@ -3028,7 +3028,7 @@ bool lcl_pixelSizeChanged( // Heuristic: Don't bother when handling interactive input, if changing just one row and // the height will shrink. - bool bChanged = (nNewPix != nOldPix) && (!ScGlobal::bKeyInputInProgress || nEndRow - nStartRow > 0 || nNewPix > nOldPix); + bool bChanged = (nNewPix != nOldPix) && (bApi || nEndRow - nStartRow > 0 || nNewPix > nOldPix); if (bChanged) return true; } @@ -3042,7 +3042,7 @@ bool lcl_pixelSizeChanged( } bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNewHeight, - double nPPTY ) + double nPPTY, bool bApi ) { bool bChanged = false; if (ValidRow(nStartRow) && ValidRow(nEndRow) && mpRowHeights) @@ -3072,7 +3072,7 @@ bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNew // No idea why 20 is used here if (!bSingle || nEndRow - nStartRow < 20) { - bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY); + bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY, bApi); if (bChanged) mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight); } @@ -3080,9 +3080,9 @@ bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNew { SCROW nMid = (nStartRow + nEndRow) / 2; // No idea why nPPTY is ignored in these recursive calls and instead 1.0 is used - if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0)) + if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0, bApi)) bChanged = true; - if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0)) + if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0, bApi)) bChanged = true; } diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 220c733a4da7..be0ecc4dd829 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -448,7 +448,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu ScopedVclPtrInstance< VirtualDevice > pVirtDev; sc::RowHeightContext aCxt(mpDoc->MaxRow(), nPPTX, nPPTY, aZoom, aZoom, pVirtDev); aCxt.setExtraHeight(ScGlobal::nLastRowHeightExtra); - mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0); + mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0, true); if ( !maRowHeights.empty() ) { diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 4203bd845537..2949e92390f1 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -135,7 +135,7 @@ static void lcl_PaintAbove( ScDocShell& rDocShell, const ScRange& rRange ) } } -bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint ) +bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint, bool bApi ) { ScDocument& rDoc = rDocShell.GetDocument(); SfxViewShell* pSomeViewForThisDoc = rDocShell.GetBestViewShell(false); @@ -157,7 +157,7 @@ bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint ) Fraction aOne(1,1); sc::RowHeightContext aCxt(rDoc.MaxRow(), aProv.GetPPTX(), aProv.GetPPTY(), aOne, aOne, aProv.GetDevice()); - bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab); + bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, bApi); // tdf#76183: recalculate objects' positions if (bChanged) { @@ -649,7 +649,7 @@ bool ScDocFunc::DeleteContents( std::move(pUndoDoc), nFlags, pDataSpans, bMulti, bDrawUndo); } - if (!AdjustRowHeight( aExtendedRange )) + if (!AdjustRowHeight( aExtendedRange, true, bApi )) rDocShell.PostPaint( aExtendedRange, PaintPartFlags::Grid, nExtFlags ); else if (nExtFlags & SC_PF_LINES) lcl_PaintAbove( rDocShell, aExtendedRange ); // for lines above the range @@ -716,7 +716,7 @@ bool ScDocFunc::DeleteCell( nFlags, pDataSpans, false, bDrawUndo); } - if (!AdjustRowHeight(rPos)) + if (!AdjustRowHeight(rPos, true, true)) rDocShell.PostPaint( rPos.Col(), rPos.Row(), rPos.Tab(), rPos.Col(), rPos.Row(), rPos.Tab(), PaintPartFlags::Grid, nExtFlags); @@ -777,7 +777,7 @@ bool ScDocFunc::TransliterateText( const ScMarkData& rMark, TransliterationFlags rDoc.TransliterateText( aMultiMark, nType ); - if (!AdjustRowHeight( aMarkRange )) + if (!AdjustRowHeight( aMarkRange, true, true )) rDocShell.PostPaint( aMarkRange, PaintPartFlags::Grid ); aModificator.SetDocumentModified(); @@ -833,7 +833,7 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, con } if ( bEditDeleted || rDoc.HasAttrib( ScRange(rPos), HasAttrFlags::NeedHeight ) ) - AdjustRowHeight( ScRange(rPos) ); + AdjustRowHeight( ScRange(rPos), true, bApi ); rDocShell.PostPaintCell( rPos ); aModificator.SetDocumentModified(); @@ -877,7 +877,7 @@ bool ScDocFunc::SetValueCell( const ScAddress& rPos, double fVal, bool bInteract } if (bHeight) - AdjustRowHeight(rPos); + AdjustRowHeight(rPos, true, !bInteraction); rDocShell.PostPaintCell( rPos ); aModificator.SetDocumentModified(); @@ -948,7 +948,7 @@ bool ScDocFunc::SetStringCell( const ScAddress& rPos, const OUString& rStr, bool } if (bHeight) - AdjustRowHeight(rPos); + AdjustRowHeight(rPos, true, !bInteraction); rDocShell.PostPaintCell( rPos ); aModificator.SetDocumentModified(); @@ -983,7 +983,7 @@ bool ScDocFunc::SetEditCell( const ScAddress& rPos, const EditTextObject& rStr, } if (bHeight) - AdjustRowHeight(rPos); + AdjustRowHeight(rPos, true, !bInteraction); rDocShell.PostPaintCell( rPos ); aModificator.SetDocumentModified(); @@ -1047,7 +1047,7 @@ bool ScDocFunc::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell, boo } if (bHeight) - AdjustRowHeight(rPos); + AdjustRowHeight(rPos, true, !bInteraction); rDocShell.PostPaintCell( rPos ); aModificator.SetDocumentModified(); @@ -1473,7 +1473,7 @@ bool ScDocFunc::ApplyAttributes( const ScMarkData& rMark, const ScPatternAttr& r if ( !bImportingXML ) rDocShell.UpdatePaintExt( nExtFlags, aMultiRange ); // content after the change - if (!AdjustRowHeight( aMultiRange )) + if (!AdjustRowHeight( aMultiRange, true, bApi )) rDocShell.PostPaint( aMultiRange, PaintPartFlags::Grid, nExtFlags ); else if (nExtFlags & SC_PF_LINES) lcl_PaintAbove( rDocShell, aMultiRange ); // because of lines above the range @@ -1546,7 +1546,7 @@ bool ScDocFunc::ApplyStyle( const ScMarkData& rMark, const OUString& rStyleName, rDoc.ApplySelectionStyle( *pStyleSheet, rMark ); - if (!AdjustRowHeight( aMultiRange )) + if (!AdjustRowHeight( aMultiRange, true, bApi )) rDocShell.PostPaint( aMultiRange, PaintPartFlags::Grid ); aModificator.SetDocumentModified(); @@ -2195,8 +2195,8 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, nScenarioCount ++; bool bAdjusted = ( eCmd == INS_INSROWS_BEFORE || eCmd == INS_INSROWS_AFTER ) ? - AdjustRowHeight(ScRange(0, nStartRow, i, rDoc.MaxCol(), nEndRow, i+nScenarioCount )) : - AdjustRowHeight(ScRange(0, nPaintStartRow, i, rDoc.MaxCol(), nPaintEndRow, i+nScenarioCount )); + AdjustRowHeight(ScRange(0, nStartRow, i, rDoc.MaxCol(), nEndRow, i+nScenarioCount ), true, bApi) : + AdjustRowHeight(ScRange(0, nPaintStartRow, i, rDoc.MaxCol(), nPaintEndRow, i+nScenarioCount ), true, bApi); if (bAdjusted) { // paint only what is not done by AdjustRowHeight @@ -2807,7 +2807,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, nScenarioCount ++; // delete entire rows: do not adjust - if ( eCmd == DelCellCmd::Rows || !AdjustRowHeight(ScRange( 0, nPaintStartRow, rTab, rDoc.MaxCol(), nPaintEndRow, rTab+nScenarioCount )) ) + if ( eCmd == DelCellCmd::Rows || !AdjustRowHeight(ScRange( 0, nPaintStartRow, rTab, rDoc.MaxCol(), nPaintEndRow, rTab+nScenarioCount ), true, bApi) ) rDocShell.PostPaint( nPaintStartCol, nPaintStartRow, rTab, nPaintEndCol, nPaintEndRow, rTab+nScenarioCount, nPaintFlags, nExtFlags ); else { @@ -3033,7 +3033,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, return false; } - bSourceHeight = AdjustRowHeight( rSource, false ); + bSourceHeight = AdjustRowHeight( rSource, false, bApi ); } ScRange aPasteDest( nDestCol, nDestRow, nDestTab, nDestEndCol, nDestEndRow, nDestEndTab ); @@ -3058,7 +3058,7 @@ bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos, bool bDestHeight = AdjustRowHeight( ScRange( 0,nDestRow,nDestTab, rDoc.MaxCol(),nDestEndRow,nDestEndTab ), - false ); + false, bApi ); /* Paste drawing objects after adjusting formula references and row heights. There are no cell notes or drawing objects, if the @@ -3723,7 +3723,7 @@ bool ScDocFunc::SetWidthOrHeight( Fraction aOne(1,1); sc::RowHeightContext aCxt(rDoc.MaxRow(), aProv.GetPPTX(), aProv.GetPPTY(), aOne, aOne, aProv.GetDevice()); aCxt.setForceAutoSize(bAll); - rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab); + rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, bApi); if (bAll) rDoc.ShowRows( nStartNo, nEndNo, nTab, true ); @@ -4279,7 +4279,7 @@ bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark, break; bool bAdj = AdjustRowHeight( ScRange(nStartCol, nStartRow, rTab, - nEndCol, nEndRow, rTab), false ); + nEndCol, nEndRow, rTab), false, bApi ); if (bAdj) rDocShell.PostPaint( 0,nStartRow,rTab, rDoc.MaxCol(),rDoc.MaxRow(),rTab, PaintPartFlags::Grid | PaintPartFlags::Left ); @@ -4625,7 +4625,7 @@ bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMark, rDoc.Fill( aSourceArea.aStart.Col(), aSourceArea.aStart.Row(), aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), &aProgress, aMark, nCount, eDir, FILL_SIMPLE ); - AdjustRowHeight(aRange); + AdjustRowHeight(aRange, true, bApi); if ( bRecord ) // only now is Draw-Undo available { @@ -4756,7 +4756,7 @@ bool ScDocFunc::FillSeries( const ScRange& rRange, const ScMarkData* pTabMark, rDoc.Fill( aSourceArea.aStart.Col(), aSourceArea.aStart.Row(), aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), &aProgress, aMark, nCount, eDir, eCmd, eDateCmd, fStep, fMax ); - AdjustRowHeight(rRange); + AdjustRowHeight(rRange, true, bApi); rDocShell.PostPaintGridAll(); aModificator.SetDocumentModified(); @@ -4903,7 +4903,7 @@ bool ScDocFunc::FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillDir e aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), &aProgress, aMark, nCount, eDir, eCmd, eDateCmd, fStep, fMax ); - AdjustRowHeight(aDestArea); + AdjustRowHeight(aDestArea, true, bApi); if ( bRecord ) // only now is Draw-Undo available { @@ -5004,7 +5004,7 @@ bool ScDocFunc::MergeCells( const ScCellMergeOption& rOption, bool bContents, bo rDoc.ApplyAttr( nStartCol, nStartRow, nTab, SvxVerJustifyItem( SvxCellVerJustify::Center, ATTR_VER_JUSTIFY ) ); } - if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, rDoc.MaxCol(),nEndRow,nTab ) ) ) + if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, rDoc.MaxCol(),nEndRow,nTab ), true, bApi ) ) rDocShell.PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PaintPartFlags::Grid ); if (bNeedContents || rOption.mbCenter) @@ -5100,7 +5100,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, Sc rDoc.ExtendMerge( aRefresh, true ); - if ( !AdjustRowHeight( aExtended ) ) + if ( !AdjustRowHeight( aExtended, true, true ) ) rDocShell.PostPaint( aExtended, PaintPartFlags::Grid ); bool bDone = ScDetectiveFunc(rDoc, nTab).DeleteAll( ScDetectiveDelete::Circles ); @@ -5451,7 +5451,7 @@ bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, bool bApi ) std::move(pUndoDoc), std::move(pRedoDoc) ) ); } - if (!AdjustRowHeight(ScRange(0,nStartRow,nTab,rDoc.MaxCol(),nEndRow,nTab))) + if (!AdjustRowHeight(ScRange(0,nStartRow,nTab,rDoc.MaxCol(),nEndRow,nTab), true, true)) rDocShell.PostPaint( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab, PaintPartFlags::Grid ); aModificator.SetDocumentModified(); diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 85e620227705..b7c197fed84e 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -407,7 +407,7 @@ bool ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab ) ScSizeDeviceProvider aProv(this); Fraction aZoom(1,1); sc::RowHeightContext aCxt(m_aDocument.MaxRow(), aProv.GetPPTX(), aProv.GetPPTY(), aZoom, aZoom, aProv.GetDevice()); - bool bChange = m_aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab); + bool bChange = m_aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab, true); if (bChange) { diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 411abc10496e..f8319295b2f0 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -60,7 +60,7 @@ class ScDocFunc protected: ScDocShell& rDocShell; - bool AdjustRowHeight( const ScRange& rRange, bool bPaint = true ); + bool AdjustRowHeight( const ScRange& rRange, bool bPaint, bool bApi ); void CreateOneName( ScRangeName& rList, SCCOL nPosX, SCROW nPosY, SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx index df35741a4f3f..6cd906f85314 100644 --- a/sc/source/ui/inc/viewfunc.hxx +++ b/sc/source/ui/inc/viewfunc.hxx @@ -214,7 +214,7 @@ public: void SetMarkedWidthOrHeight( bool bWidth, ScSizeMode eMode, sal_uInt16 nSizeTwips ); bool AdjustBlockHeight( bool bPaint = true, ScMarkData* pMarkData = nullptr ); - bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow ); + bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi ); void ModifyCellSize( ScDirection eDir, bool bOptimal ); diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx index 21e91998904a..8ce8bc9e82f0 100644 --- a/sc/source/ui/undo/undobase.cxx +++ b/sc/source/ui/undo/undobase.cxx @@ -305,7 +305,7 @@ bool ScBlockUndo::AdjustHeight() sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, pVirtDev); bool bRet = rDoc.SetOptimalHeight( - aCxt, aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(), aBlockRange.aStart.Tab()); + aCxt, aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(), aBlockRange.aStart.Tab(), true); if (bRet) { diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index f6d2c1bbcbb7..f4ea10273b1e 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -1266,7 +1266,7 @@ void ScUndoDragDrop::PaintArea( ScRange aRange, sal_uInt16 nExtFlags ) const rDoc.MaxRow(), rViewData.GetPPTX(), rViewData.GetPPTY(), rViewData.GetZoomX(), rViewData.GetZoomY(), pVirtDev); - if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), aRange.aEnd.Row(), aRange.aStart.Tab())) + if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), aRange.aEnd.Row(), aRange.aStart.Tab(), true)) { // tdf#76183: recalculate objects' positions rDoc.SetDrawPageSize(aRange.aStart.Tab()); @@ -2268,7 +2268,7 @@ void ScUndoRemoveMerge::Undo() if ( pViewShell ) { pViewShell->SetTabNo(rTab); - bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow); + bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow, true); } if (!bDidPaint) ScUndoUtil::PaintMore(pDocShell, aRange); @@ -2314,7 +2314,7 @@ void ScUndoRemoveMerge::Redo() if ( pViewShell ) { pViewShell->SetTabNo(nTab); - bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow); + bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow, true); } if (!bDidPaint) ScUndoUtil::PaintMore(pDocShell, aRange); diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx index ef0a5eff9738..e2326337b173 100644 --- a/sc/source/ui/undo/undoblk3.cxx +++ b/sc/source/ui/undo/undoblk3.cxx @@ -161,7 +161,7 @@ void ScUndoDeleteContents::DoChange( const bool bUndo ) ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); if ( !( pViewShell && pViewShell->AdjustRowHeight( - aRange.aStart.Row(), aRange.aEnd.Row() ) ) ) + aRange.aStart.Row(), aRange.aEnd.Row(), true ) ) ) /*A*/ pDocShell->PostPaint( aRange, PaintPartFlags::Grid | PaintPartFlags::Extras, nExtFlags ); if (pViewShell) @@ -720,7 +720,7 @@ void ScUndoMerge::DoChange( bool bUndo ) const if ( pViewShell ) { pViewShell->SetTabNo(nTab); - bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow); + bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow, true); } if (!bDidPaint) @@ -873,7 +873,7 @@ void ScUndoAutoFormat::Redo() rDoc.SetRowFlags( nRow, nTab, nOld & ~CRFlags::ManualSize ); } - bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab); + bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab, true); for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++) if (!rDoc.ColHidden(nCol, nTab)) diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index f5934ae2dbbc..3367a34bc573 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -45,7 +45,6 @@ #include <vcl/settings.hxx> #include <sot/formats.hxx> #include <comphelper/classids.hxx> -#include <comphelper/flagguard.hxx> #include <svx/svdview.hxx> #include <editeng/outliner.hxx> @@ -3209,12 +3208,8 @@ void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, S } } -bool ScGlobal::bKeyInputInProgress = false; - void ScGridWindow::KeyInput(const KeyEvent& rKEvt) { - comphelper::FlagGuard aResetFlag(ScGlobal::bKeyInputInProgress); - // Cursor control for ref input dialog const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 9bad80bb01d0..c2914d5f615b 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -156,7 +156,7 @@ bool ScViewFunc::AdjustBlockHeight( bool bPaint, ScMarkData* pMarkData ) SCROW nEndNo = rRow.mnEnd; ScAddress aTopLeft(0, nStartNo, nTab); rDoc.UpdateScriptTypes(aTopLeft, MAXCOLCOUNT, nEndNo-nStartNo+1); - if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab)) + if (rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true)) { if (!bChanged) nPaintY = nStartNo; @@ -188,7 +188,7 @@ bool ScViewFunc::AdjustBlockHeight( bool bPaint, ScMarkData* pMarkData ) return bAnyChanged; } -bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow ) +bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, bool bApi ) { if (comphelper::LibreOfficeKit::isActive()) { @@ -214,7 +214,7 @@ bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow ) aZoomX = aZoomY = Fraction( 1, 1 ); } sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice()); - bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab); + bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab, bApi); // tdf#76183: recalculate objects' positions if (bChanged) diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index af9e50ab2373..8504cdd1fb22 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -139,7 +139,7 @@ void ScViewFunc::CutToClip() rDoc.DeleteObjectsInSelection( rMark ); rMark.MarkToSimple(); - if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row() ) ) + if ( !AdjustRowHeight( aRange.aStart.Row(), aRange.aEnd.Row(), true ) ) pDocSh->PostPaint( aRange, PaintPartFlags::Grid, nExtFlags ); if ( bRecord ) // Draw-Undo now available diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index 3371dedb8cc0..6b304ec0b351 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -171,7 +171,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, else if ( aDataHelper.GetString( SotClipboardFormatId::RICHTEXT, aStr ) ) aImpEx.ImportString( aStr, SotClipboardFormatId::RICHTEXT ); - AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row() ); + AdjustRowHeight( nStartRow, aImpEx.GetRange().aEnd.Row(), true ); pDocSh->UpdateOle(GetViewData()); ShowAllCursors(); } diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 051771e1dabe..ac08fb699380 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -705,7 +705,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, if (bSimple) { if (bCommon) - AdjustRowHeight(nRow,nRow); + AdjustRowHeight(nRow,nRow,true); EnterData(nCol,nRow,nTab,aString); } @@ -725,7 +725,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, HideAllCursors(); - AdjustRowHeight(nRow,nRow); + AdjustRowHeight(nRow,nRow,true); for (const auto& rTab : rMark) pDocSh->PostPaintCell( nCol, nRow, rTab ); @@ -1900,7 +1900,7 @@ void ScViewFunc::DeleteMulti( bool bRows ) pDocSh, bRows, bNeedRefresh, nTab, aSpans, std::move(pUndoDoc), std::move(pUndoData))); } - if (!AdjustRowHeight(0, rDoc.MaxRow())) + if (!AdjustRowHeight(0, rDoc.MaxRow(), true)) { if (bRows) { @@ -2171,7 +2171,7 @@ void ScViewFunc::SetWidthOrHeight( sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice()); aCxt.setForceAutoSize(bAll); aCxt.setExtraHeight(nSizeTwips); - rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab); + rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true); if (bAll) rDoc.ShowRows( nStartNo, nEndNo, nTab, true ); @@ -2450,7 +2450,7 @@ void ScViewFunc::ModifyCellSize( ScDirection eDir, bool bOptimal ) pPattern->GetItem( ATTR_LINEBREAK ).GetValue() || pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue() == SvxCellHorJustify::Block; if (bNeedHeight) - AdjustRowHeight( nRow, nRow ); + AdjustRowHeight( nRow, nRow, true ); } } else commit 08eaf84f4e7fafb12f9e5538f4bad8c756190ad4 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri Jan 29 16:03:29 2021 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:18:54 2021 +0200 Don't bother shrinking row height when changing just one row interactively I.e. when manually entering a new value. This used to happen at least for a sample document in .xlsx format for cells with automatic wrap turned on. After entering a value, the row height was annoyingly shrunk by a few pixels, which looked weird and pointless, and caused unnecessary invalidation thrash in the online collaborative editing context. Change-Id: I3c77f7fb4e575f02e1dd7cdc18f2919f5eb3426e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110243 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <t...@collabora.com> diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 21d33ccc35e9..4cb67454bc76 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -813,6 +813,8 @@ public: /// Calc's threaded group calculation is in progress. SC_DLLPUBLIC static bool bThreadedGroupCalcInProgress; + + SC_DLLPUBLIC static bool bKeyInputInProgress; }; // maybe move to dbdata.hxx (?): diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 33ca0d85128f..4905e111e2f6 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -3024,7 +3024,11 @@ bool lcl_pixelSizeChanged( if (nHeight != nNewHeight) { - bool bChanged = (nNewPix != static_cast<tools::Long>(nHeight * nPPTY)); + tools::Long nOldPix = static_cast<tools::Long>(nHeight * nPPTY); + + // Heuristic: Don't bother when handling interactive input, if changing just one row and + // the height will shrink. + bool bChanged = (nNewPix != nOldPix) && (!ScGlobal::bKeyInputInProgress || nEndRow - nStartRow > 0 || nNewPix > nOldPix); if (bChanged) return true; } @@ -3065,14 +3069,17 @@ bool ScTable::SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, sal_uInt16 nNew } } + // No idea why 20 is used here if (!bSingle || nEndRow - nStartRow < 20) { bChanged = lcl_pixelSizeChanged(*mpRowHeights, nStartRow, nEndRow, nNewHeight, nPPTY); - mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight); + if (bChanged) + mpRowHeights->setValue(nStartRow, nEndRow, nNewHeight); } else { SCROW nMid = (nStartRow + nEndRow) / 2; + // No idea why nPPTY is ignored in these recursive calls and instead 1.0 is used if (SetRowHeightRange(nStartRow, nMid, nNewHeight, 1.0)) bChanged = true; if (SetRowHeightRange(nMid + 1, nEndRow, nNewHeight, 1.0)) diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 3367a34bc573..f5934ae2dbbc 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -45,6 +45,7 @@ #include <vcl/settings.hxx> #include <sot/formats.hxx> #include <comphelper/classids.hxx> +#include <comphelper/flagguard.hxx> #include <svx/svdview.hxx> #include <editeng/outliner.hxx> @@ -3208,8 +3209,12 @@ void ScGridWindow::SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, S } } +bool ScGlobal::bKeyInputInProgress = false; + void ScGridWindow::KeyInput(const KeyEvent& rKEvt) { + comphelper::FlagGuard aResetFlag(ScGlobal::bKeyInputInProgress); + // Cursor control for ref input dialog const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); commit a6004aef0f1d3f95defb1495c57df065da78ec81 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Jan 6 15:02:17 2021 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:01:39 2021 +0200 ScTable::GetProtection and ScDocument::GetTabProtection can be const Change-Id: Ic30a3fe10ae6206e876a05bed5dc189a9516b452 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108851 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 832a02410eed..98f5d441c95f 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -901,7 +901,7 @@ public: SC_DLLPUBLIC bool IsDocProtected() const; bool IsDocEditable() const; SC_DLLPUBLIC bool IsTabProtected( SCTAB nTab ) const; - SC_DLLPUBLIC ScTableProtection* GetTabProtection( SCTAB nTab ) const; + SC_DLLPUBLIC const ScTableProtection* GetTabProtection(SCTAB nTab) const; SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect); void CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index ea13cf9b4071..e4e4e67d4430 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -382,7 +382,7 @@ public: bool IsProtected() const; void SetProtection(const ScTableProtection* pProtect); - ScTableProtection* GetProtection(); + const ScTableProtection* GetProtection() const; void GetUnprotectedCells( ScRangeList& rRangeList ) const; bool IsEditActionAllowed( sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd ) const; diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 4b0d5a0cb265..77068268bff8 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -795,7 +795,7 @@ void ScExportTest::testProtectionKeyODS_UTF16LErtlSHA1() ScDocument& rDoc = xShell->GetDocument(); ScDocProtection *const pDocProt(rDoc.GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we @@ -818,7 +818,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA1() ScDocument& rDoc = xShell->GetDocument(); ScDocProtection *const pDocProt(rDoc.GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we @@ -841,7 +841,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256ODF12() ScDocument& rDoc = xShell->GetDocument(); ScDocProtection *const pDocProt(rDoc.GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we @@ -864,7 +864,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256W3C() ScDocument& rDoc = xShell->GetDocument(); ScDocProtection *const pDocProt(rDoc.GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we @@ -887,7 +887,7 @@ void ScExportTest::testProtectionKeyODS_XL_SHA1() ScDocument& rDoc = xShell->GetDocument(); ScDocProtection *const pDocProt(rDoc.GetDocProtection()); CPPUNIT_ASSERT(pDocProt->verifyPassword(password)); - ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); + const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0)); CPPUNIT_ASSERT(pTabProt->verifyPassword(password)); // we can't assume that the user entered the password; check that we @@ -3475,7 +3475,7 @@ namespace { void testSheetProtection_Impl(const ScDocument& rDoc) { CPPUNIT_ASSERT(rDoc.IsTabProtected(0)); - ScTableProtection* pTabProtection = rDoc.GetTabProtection(0); + const ScTableProtection* pTabProtection = rDoc.GetTabProtection(0); CPPUNIT_ASSERT(pTabProtection); CPPUNIT_ASSERT(pTabProtection->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS)); CPPUNIT_ASSERT(!pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS)); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index c2adce1c3ae7..aa3eb825ee45 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -1896,7 +1896,7 @@ bool ScDocument::IsTabProtected( SCTAB nTab ) const return false; } -ScTableProtection* ScDocument::GetTabProtection( SCTAB nTab ) const +const ScTableProtection* ScDocument::GetTabProtection(SCTAB nTab) const { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) return maTabs[nTab]->GetProtection(); diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx index 31171f72e4ce..21d2b11d8c6e 100644 --- a/sc/source/core/data/table5.cxx +++ b/sc/source/core/data/table5.cxx @@ -1095,7 +1095,7 @@ void ScTable::SetProtection(const ScTableProtection* pProtect) SetStreamValid(false); } -ScTableProtection* ScTable::GetProtection() { return pTabProtection.get(); } +const ScTableProtection* ScTable::GetProtection() const { return pTabProtection.get(); } Size ScTable::GetPageSize() const { diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index 2eacb3edf28b..571376205724 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -1686,7 +1686,7 @@ XclExpSheetProtectOptions::XclExpSheetProtectOptions( const XclExpRoot& rRoot, S }; mnOptions = 0x0000; - ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab); + const ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab); if (!pProtect) return; diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 4fbdb0c1356a..71598827094e 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -2799,7 +2799,7 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const uno::Reference<sheet::XSpre AddAttribute(sAttrStyleName, aTableStyles[nTable]); uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY); - ScTableProtection* pProtect = nullptr; + const ScTableProtection* pProtect = nullptr; if (xProtectable.is() && xProtectable->isProtected()) { AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 2a174b88d1fb..4203bd845537 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -3949,7 +3949,7 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) if (!p) { // For protection case, use a copy of resulting ScTableProtection for undo - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); p = std::make_unique<ScTableProtection>(*pProtect); } rDocShell.GetUndoManager()->AddUndoAction( @@ -4052,7 +4052,7 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) { // sheet protection - ScTableProtection* pTabProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pTabProtect = rDoc.GetTabProtection(nTab); if (!pTabProtect || !pTabProtect->isProtected()) // already unprotected (should not happen)! return true; diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx index a2caa3fb3a77..c6f5d36f94e5 100644 --- a/sc/source/ui/vba/vbaworksheet.cxx +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -310,7 +310,7 @@ ScVbaWorksheet::getEnableSelection() uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); bool bLockedCells = false; bool bUnlockedCells = false; if( pProtect ) @@ -343,7 +343,7 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); // default is xlNoSelection bool bLockedCells = false; bool bUnlockedCells = false; @@ -358,8 +358,10 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) } if( pProtect ) { - pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells ); - pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells ); + ScTableProtection aNewProtect(*pProtect); + aNewProtect.setOption(ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells); + aNewProtect.setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells); + rDoc.SetTabProtection(nTab, &aNewProtect); } @@ -480,7 +482,7 @@ ScVbaWorksheet::getProtectDrawingObjects() { uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW ); ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument(); - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if ( pProtect ) return pProtect->isOptionEnabled( ScTableProtection::OBJECTS ); } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index dc9cc1c68946..3367a34bc573 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -2167,7 +2167,7 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt ) } // Check for cell protection attribute. - ScTableProtection* pProtect = rDoc.GetTabProtection( nTab ); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); bool bEditAllowed = true; if ( pProtect && pProtect->isProtected() ) { diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx index 9f5e2a139abe..89baed62a9f5 100644 --- a/sc/source/ui/view/select.cxx +++ b/sc/source/ui/view/select.cxx @@ -437,7 +437,7 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll if (nPosX < 0 || nPosY < 0) return false; - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if (!pProtect) return false; diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx index ee7be2a2f65c..787aa64fea71 100644 --- a/sc/source/ui/view/tabview2.cxx +++ b/sc/source/ui/view/tabview2.cxx @@ -62,7 +62,7 @@ void moveCursorByProtRule( { bool bSelectLocked = true; bool bSelectUnlocked = true; - ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab); + const ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab); if (pTabProtection && pTabProtection->isProtected()) { bSelectLocked = pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); @@ -186,7 +186,7 @@ void moveCursorByMergedCell( SCCOL nOrigX = rViewData.GetCurX(); SCROW nOrigY = rViewData.GetCurY(); - ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab); + const ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab); bool bSelectLocked = true; bool bSelectUnlocked = true; if (pTabProtection && pTabProtection->isProtected()) @@ -730,7 +730,7 @@ void ScTabView::SkipCursorHorizontal(SCCOL& rCurX, SCROW& rCurY, SCCOL nOldX, SC SCTAB nTab = aViewData.GetTabNo(); bool bSkipProtected = false, bSkipUnprotected = false; - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if (pProtect && pProtect->isProtected()) { bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); @@ -790,7 +790,7 @@ void ScTabView::SkipCursorVertical(SCCOL& rCurX, SCROW& rCurY, SCROW nOldY, SCRO SCTAB nTab = aViewData.GetTabNo(); bool bSkipProtected = false, bSkipUnprotected = false; - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if (pProtect && pProtect->isProtected()) { bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); @@ -868,7 +868,7 @@ void ScTabView::ExpandBlock(SCCOL nMovX, SCROW nMovY, ScFollowMode eMode) bool bSelectLocked = true; bool bSelectUnlocked = true; - ScTableProtection* pTabProtection = rDoc.GetTabProtection(nRefTab); + const ScTableProtection* pTabProtection = rDoc.GetTabProtection(nRefTab); if (pTabProtection && pTabProtection->isProtected()) { bSelectLocked = pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx index 214f5a02ca3d..eac7441f6162 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -1265,7 +1265,7 @@ void ScTabView::MoveCursorRel( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, SCTAB nTab = aViewData.GetTabNo(); bool bSkipProtected = false, bSkipUnprotected = false; - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if ( pProtect && pProtect->isProtected() ) { bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS); diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx index a5b7e621efa1..92fb5f4d439c 100644 --- a/sc/source/ui/view/tabvwsh3.cxx +++ b/sc/source/ui/view/tabvwsh3.cxx @@ -1232,7 +1232,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) { // Unprotect a protected sheet. - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if (pProtect && pProtect->isProtectedWithPass()) { OUString aText( ScResId(SCSTR_PASSWORDOPT) ); @@ -1264,7 +1264,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq ) ScTableProtectionDlg aDlg(GetFrameWeld()); - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); if (pProtect) aDlg.SetDialogData(*pProtect); commit baabbe09869182e2f5998906ca043cddcc01533c Author: Anshu <anshukhar...@gmail.com> AuthorDate: Thu Dec 31 23:13:07 2020 +0530 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:01:21 2021 +0200 tdf#139339 : Unify protect/unprotect cases for document protection Change-Id: I4bd3851d50a6215fef1f3ab722102adf6f44f10b Restored accidently missed lines for document protection in https: //gerrit.libreoffice.org/c/core/+/107041 Change-Id: I4bd3851d50a6215fef1f3ab722102adf6f44f10b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108541 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 3fbab69b9229..2a174b88d1fb 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -3965,38 +3965,51 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) aModificator.SetDocumentModified(); } -bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) +void ScDocFunc::ProtectDocument(const ScDocProtection& rProtect) { ScDocument& rDoc = rDocShell.GetDocument(); + + std::unique_ptr<ScDocProtection> p; + if (!rProtect.isProtected() && rDoc.IsUndoEnabled()) + { + // In case of unprotecting, use a copy of passed ScTableProtection object for undo + p = std::make_unique<ScDocProtection>(rProtect); + } + rDoc.SetDocProtection(&rProtect); + if (rDoc.IsUndoEnabled()) + { + if (!p) + { + // For protection case, use a copy of resulting ScTableProtection for undo + ScDocProtection* pProtect = rDoc.GetDocProtection(); + p = std::make_unique<ScDocProtection>(*pProtect); + } + rDocShell.GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoDocProtect>(&rDocShell, std::move(p))); + // ownership of unique_ptr now transferred to ScUndoTabProtect. + } + + rDocShell.PostPaintGridAll(); + ScDocShellModificator aModificator(rDocShell); + aModificator.SetDocumentModified(); +} + +bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) +{ if (nTab == TABLEID_DOC) { // document protection ScDocProtection aProtection; aProtection.setProtected(true); aProtection.setPassword(rPassword); - rDoc.SetDocProtection(&aProtection); - if (rDoc.IsUndoEnabled()) - { - ScDocProtection* pProtect = rDoc.GetDocProtection(); - OSL_ENSURE(pProtect, "ScDocFunc::Unprotect: ScDocProtection pointer is NULL!"); - if (pProtect) - { - ::std::unique_ptr<ScDocProtection> p(new ScDocProtection(*pProtect)); - p->setProtected(true); // just in case ... - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoDocProtect>(&rDocShell, std::move(p)) ); - // ownership of unique_ptr is transferred to ScUndoDocProtect. - } - } - rDocShell.PostPaintGridAll(); - ScDocShellModificator aModificator(rDocShell); - aModificator.SetDocumentModified(); + ProtectDocument(aProtection); + } else { // sheet protection - const ScTableProtection* pOldProtection = rDoc.GetTabProtection(nTab); + const ScTableProtection* pOldProtection = rDocShell.GetDocument().GetTabProtection(nTab); ::std::unique_ptr<ScTableProtection> pNewProtection(pOldProtection ? new ScTableProtection(*pOldProtection) : new ScTableProtection()); pNewProtection->setProtected(true); pNewProtection->setPassword(rPassword); @@ -4018,9 +4031,6 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) // already unprotected (should not happen)! return true; - // save the protection state before unprotect (for undo). - ::std::unique_ptr<ScDocProtection> pProtectCopy(new ScDocProtection(*pDocProtect)); - if (!pDocProtect->verifyPassword(rPassword)) { if (!bApi) @@ -4033,14 +4043,10 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) return false; } - rDoc.SetDocProtection(nullptr); - if (rDoc.IsUndoEnabled()) - { - pProtectCopy->setProtected(false); - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoDocProtect>(&rDocShell, std::move(pProtectCopy)) ); - // ownership of unique_ptr now transferred to ScUndoDocProtect. - } + ScDocProtection aNewProtection(*pDocProtect); + aNewProtection.setProtected(false); + ProtectDocument(aNewProtection); + } else { diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index f7b518ef7f35..411abc10496e 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -41,6 +41,7 @@ class ScFormulaCell; class ScTokenArray; struct ScTabOpParam; class ScTableProtection; +class ScDocProtection; struct ScCellMergeOption; class ScConditionalFormat; class ScConditionalFormatList; @@ -232,6 +233,9 @@ public: void SetConditionalFormatList( ScConditionalFormatList* pList, SCTAB nTab ); void ConvertFormulaToValue( const ScRange& rRange, bool bInteraction ); + +private: + void ProtectDocument(const ScDocProtection& rProtect); }; class ScDocFuncDirect : public ScDocFunc commit eac9eff48292df7a172c57e5c4e7bd9224d201a4 Author: Anshu <anshukhar...@gmail.com> AuthorDate: Wed Dec 2 08:51:15 2020 +0530 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Wed Apr 14 12:00:59 2021 +0200 tdf#133257 : Protection icon in front of sheet name Change-Id: Ifdbe0fad1f8a1d7dd6ac1dfd35c529f9e0c9fd80 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107041 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index e533d0b634fe..3fbab69b9229 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -99,6 +99,7 @@ #include <basic/basmgr.hxx> #include <set> #include <vector> +#include <sfx2/viewfrm.hxx> using namespace com::sun::star; using ::std::vector; @@ -3936,22 +3937,29 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) { ScDocument& rDoc = rDocShell.GetDocument(); + std::unique_ptr<ScTableProtection> p; + if (!rProtect.isProtected() && rDoc.IsUndoEnabled()) + { + // In case of unprotecting, use a copy of passed ScTableProtection object for undo + p = std::make_unique<ScTableProtection>(rProtect); + } rDoc.SetTabProtection(nTab, &rProtect); if (rDoc.IsUndoEnabled()) { - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); - OSL_ENSURE(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!"); - if (pProtect) + if (!p) { - ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect)); - p->setProtected(true); // just in case ... - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) ); - - // ownership of unique_ptr now transferred to ScUndoTabProtect. + // For protection case, use a copy of resulting ScTableProtection for undo + ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); + p = std::make_unique<ScTableProtection>(*pProtect); } + rDocShell.GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p))); + // ownership of unique_ptr now transferred to ScUndoTabProtect. } - + for (SfxViewFrame* fr = SfxViewFrame::GetFirst(&rDocShell); fr; + fr = SfxViewFrame::GetNext(*fr, &rDocShell)) + if (ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(fr->GetViewShell())) + pTabViewShell->SetTabProtectionSymbol(nTab, rProtect.isProtected()); rDocShell.PostPaintGridAll(); ScDocShellModificator aModificator(rDocShell); aModificator.SetDocumentModified(); @@ -3980,6 +3988,9 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) // ownership of unique_ptr is transferred to ScUndoDocProtect. } } + rDocShell.PostPaintGridAll(); + ScDocShellModificator aModificator(rDocShell); + aModificator.SetDocumentModified(); } else { @@ -3989,26 +4000,8 @@ bool ScDocFunc::Protect( SCTAB nTab, const OUString& rPassword ) ::std::unique_ptr<ScTableProtection> pNewProtection(pOldProtection ? new ScTableProtection(*pOldProtection) : new ScTableProtection()); pNewProtection->setProtected(true); pNewProtection->setPassword(rPassword); - rDoc.SetTabProtection(nTab, pNewProtection.get()); - if (rDoc.IsUndoEnabled()) - { - ScTableProtection* pProtect = rDoc.GetTabProtection(nTab); - OSL_ENSURE(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!"); - if (pProtect) - { - ::std::unique_ptr<ScTableProtection> p(new ScTableProtection(*pProtect)); - p->setProtected(true); // just in case ... - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(p)) ); - // ownership of unique_ptr now transferred to ScUndoTabProtect. - } - } + ProtectSheet(nTab, *pNewProtection); } - - rDocShell.PostPaintGridAll(); - ScDocShellModificator aModificator( rDocShell ); - aModificator.SetDocumentModified(); - return true; } @@ -4057,9 +4050,6 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) if (!pTabProtect || !pTabProtect->isProtected()) // already unprotected (should not happen)! return true; - - // save the protection state before unprotect (for undo). - ::std::unique_ptr<ScTableProtection> pProtectCopy(new ScTableProtection(*pTabProtect)); if (!pTabProtect->verifyPassword(rPassword)) { if (!bApi) @@ -4072,22 +4062,11 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi ) return false; } - ::std::unique_ptr<ScTableProtection> pNewProtection(new ScTableProtection(*pTabProtect)); - pNewProtection->setProtected(false); - rDoc.SetTabProtection(nTab, pNewProtection.get()); - if (rDoc.IsUndoEnabled()) - { - pProtectCopy->setProtected(false); - rDocShell.GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoTabProtect>(&rDocShell, nTab, std::move(pProtectCopy)) ); - // ownership of unique_ptr now transferred to ScUndoTabProtect. - } + ScTableProtection aNewProtection(*pTabProtect); + aNewProtection.setProtected(false); + ProtectSheet(nTab, aNewProtection); } - rDocShell.PostPaintGridAll(); - ScDocShellModificator aModificator( rDocShell ); - aModificator.SetDocumentModified(); - return true; } diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index d0484beb37c9..051771e1dabe 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2512,7 +2512,6 @@ void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect ) for (const auto& rTab : rMark) { rFunc.ProtectSheet(rTab, rProtect); - SetTabProtectionSymbol(rTab, true); } if (bUndo) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits