From 984b0d1599ff1672cb0d28019bd652d58d6bdefa Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Thu, 28 Jul 2016 18:51:01 +0200 Subject: Resolves: tdf#60021 disallow Paste when entire sheet is selected ... which exhausts memory unless you have 100GB or more of free RAM. Change-Id: Ie6f02c48457f80acad33d2286194765f8343f2fb --- sc/source/ui/inc/viewdata.hxx | 3 +++ sc/source/ui/view/cellsh.cxx | 13 ++++++++++++- sc/source/ui/view/viewdata.cxx | 12 ++++++++++++ sc/source/ui/view/viewfun3.cxx | 3 +++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx index a7446e1c854b..7c1c09834ca4 100644 --- a/sc/source/ui/inc/viewdata.hxx +++ b/sc/source/ui/inc/viewdata.hxx @@ -354,6 +354,9 @@ public: bool IsMultiMarked(); + /// Disallow paste on Ctrl+A all selected. We'd go DOOM. + bool SelectionForbidsPaste(); + void SetFillMode( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ); void SetDragMode( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScFillMode nMode ); diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 96b82624a1c5..7379cdb94897 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -205,6 +205,14 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet ) bDisable = (!bSimpleArea); break; + case SID_PASTE: + case SID_PASTE_SPECIAL: + case SID_PASTE_ONLY_VALUE: + case SID_PASTE_ONLY_TEXT: + case SID_PASTE_ONLY_FORMULA: + bDisable = GetViewData()->SelectionForbidsPaste(); + break; + case FID_INS_ROW: case FID_INS_ROWS_BEFORE: // insert rows case FID_INS_ROWS_AFTER: @@ -490,6 +498,9 @@ bool checkDestRanges(ScViewData& rViewData) return false; } + if (rViewData.SelectionForbidsPaste()) + return false; + // Multiple destination ranges. ScDocument* pDoc = rViewData.GetDocument(); @@ -552,7 +563,7 @@ void ScCellShell::GetClipState( SfxItemSet& rSet ) if (!rDoc.IsBlockEditable( nTab, nCol,nRow, nCol,nRow )) bDisable = true; - if (!checkDestRanges(*GetViewData())) + if (!bDisable && !checkDestRanges(*GetViewData())) bDisable = true; } diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index d188643b660c..d07f711c28be 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -854,6 +854,18 @@ bool ScViewData::IsMultiMarked() return (eType & SC_MARK_SIMPLE) != SC_MARK_SIMPLE; } +bool ScViewData::SelectionForbidsPaste() +{ + SCCOL nCol1, nCol2; + SCROW nRow1, nRow2; + SCTAB nTab1, nTab2; + ScMarkType eMarkType = GetSimpleArea( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2); + /* TODO: it is still possible to select one row less than the entire sheet + * and fool around. We could narrow this down to some "sane" value, just + * what would be sane? At least this helps against the Ctrl+A cases. */ + return eMarkType != SC_MARK_MULTI && nCol1 == 0 && nCol2 == MAXCOL && nRow1 == 0 && nRow2 == MAXROW; +} + void ScViewData::SetFillMode( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) { nFillMode = ScFillMode::FILL; diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 3facbf1951a8..f798690cb8a2 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -859,6 +859,9 @@ bool ScViewFunc::PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc, return false; } + if (GetViewData().SelectionForbidsPaste()) + return false; + // undo: save all or no content InsertDeleteFlags nContFlags = InsertDeleteFlags::NONE; if (nFlags & InsertDeleteFlags::CONTENTS) -- cgit