sc/source/ui/app/inputwin.cxx | 21 ++-- sc/source/ui/condformat/condformatdlgentry.cxx | 68 ++++++------- sc/source/ui/dialogs/searchresults.cxx | 20 ++- sc/source/ui/miscdlgs/mvtabdlg.cxx | 16 +-- sc/source/ui/namedlg/namedefdlg.cxx | 8 - sc/source/ui/namedlg/namedlg.cxx | 4 sc/source/ui/undo/undoblk.cxx | 55 +++++----- sc/source/ui/undo/undodat.cxx | 129 ++++++++++++++++--------- sc/source/ui/undo/undotab.cxx | 33 +++++- sc/source/ui/view/tabvwsh4.cxx | 2 10 files changed, 219 insertions(+), 137 deletions(-)
New commits: commit 860d11230d67900238f97a06fd2ebd0262c16ae4 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Tue May 21 17:22:53 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue May 21 21:35:50 2024 +0200 sc: check GetActiveViewShell() See the recently introduced https://crashreport.libreoffice.org/stats/crash_details/3da2dcd1-ca3e-409a-a665-dcb09d2a3ba0 Change-Id: If6ddc71bc2946232d57d5fd8fd6029b45b19495f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167903 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index 3aa9a36c5af0..f39139b7b6e7 100644 --- a/sc/source/ui/app/inputwin.cxx +++ b/sc/source/ui/app/inputwin.cxx @@ -799,9 +799,11 @@ void ScInputWindow::MouseButtonDown( const MouseEvent& rMEvt ) // I'd prefer to leave at least a single column header and a // row but I don't know how to get that value in pixels. // Use TOOLBOX_WINDOW_HEIGHT for the moment - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - mnMaxY = GetOutputSizePixel().Height() + (pViewSh->GetGridHeight(SC_SPLIT_TOP) - + pViewSh->GetGridHeight(SC_SPLIT_BOTTOM)) - TOOLBOX_WINDOW_HEIGHT; + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + { + mnMaxY = GetOutputSizePixel().Height() + (pViewSh->GetGridHeight(SC_SPLIT_TOP) + + pViewSh->GetGridHeight(SC_SPLIT_BOTTOM)) - TOOLBOX_WINDOW_HEIGHT; + } } } @@ -1720,7 +1722,6 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt ) if (m_xEditView) { ScModule* pScMod = SC_MOD(); - ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell(); // don't modify the font defaults here - the right defaults are // already set in StartEditEngine when the EditEngine is created @@ -1738,6 +1739,7 @@ bool ScTextWnd::Command( const CommandEvent& rCEvt ) { // Is dragged onto another View? ScTabViewShell* pEndViewSh = ScTabViewShell::GetActiveViewShell(); + ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell(); if ( pEndViewSh != pStartViewSh && pStartViewSh != nullptr ) { ScViewData& rViewData = pStartViewSh->GetViewData(); @@ -2663,11 +2665,12 @@ void ScPosWnd::DoEnter() if (bOpenManageNamesDialog) { const sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId(); - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - assert(pViewSh); - SfxViewFrame& rViewFrm = pViewSh->GetViewFrame(); - SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId ); - SC_MOD()->SetRefDialog( nId, pWnd == nullptr ); + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + { + SfxViewFrame& rViewFrm = pViewSh->GetViewFrame(); + SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId ); + SC_MOD()->SetRefDialog( nId, pWnd == nullptr ); + } } } diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx index 88de0f73a606..01d13c821981 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -446,43 +446,45 @@ void StyleSelect(weld::Window* pDialogParent, weld::ComboBox& rLbStyle, const Sc // unlock the dispatcher so SID_STYLE_NEW can be executed // (SetDispatcherLock would affect all Calc documents) - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); - SfxDispatcher* pDisp = pViewShell->GetDispatcher(); - bool bLocked = pDisp->IsLocked(); - if (bLocked) - pDisp->Lock(false); - - // Execute the "new style" slot, complete with undo and all necessary updates. - // The return value (SfxUInt16Item) is ignored, look for new styles instead. - pDisp->ExecuteList(SID_STYLE_NEW, - SfxCallMode::SYNCHRON | SfxCallMode::RECORD, - { &aFamilyItem, &aRefItem }, { &aDialogParent }); - - if (bLocked) - pDisp->Lock(true); - - // Find the new style and add it into the style list boxes - SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para ); - bool bFound = false; - for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() ) + if (ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell()) { - const OUString& aName = pStyle->GetName(); - if (rLbStyle.find_text(aName) == -1) // all lists contain the same entries + SfxDispatcher* pDisp = pViewShell->GetDispatcher(); + bool bLocked = pDisp->IsLocked(); + if (bLocked) + pDisp->Lock(false); + + // Execute the "new style" slot, complete with undo and all necessary updates. + // The return value (SfxUInt16Item) is ignored, look for new styles instead. + pDisp->ExecuteList(SID_STYLE_NEW, + SfxCallMode::SYNCHRON | SfxCallMode::RECORD, + { &aFamilyItem, &aRefItem }, { &aDialogParent }); + + if (bLocked) + pDisp->Lock(true); + + // Find the new style and add it into the style list boxes + SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para ); + bool bFound = false; + for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() ) { - for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && !bFound; ++i) + const OUString& aName = pStyle->GetName(); + if (rLbStyle.find_text(aName) == -1) // all lists contain the same entries { - OUString aStyleName = ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i)); - if( i == n ) + for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && !bFound; ++i) { - rLbStyle.append_text(aName); - rLbStyle.set_active_text(aName); - bFound = true; - } - else if( aStyleName > ScGlobal::getCharClass().uppercase(aName) ) - { - rLbStyle.insert_text(i, aName); - rLbStyle.set_active_text(aName); - bFound = true; + OUString aStyleName = ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i)); + if( i == n ) + { + rLbStyle.append_text(aName); + rLbStyle.set_active_text(aName); + bFound = true; + } + else if( aStyleName > ScGlobal::getCharClass().uppercase(aName) ) + { + rLbStyle.insert_text(i, aName); + rLbStyle.set_active_text(aName); + bFound = true; + } } } } diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx index 4ea08c1d49cb..31444dbb3f39 100644 --- a/sc/source/ui/dialogs/searchresults.cxx +++ b/sc/source/ui/dialogs/searchresults.cxx @@ -249,18 +249,22 @@ IMPL_LINK_NOARG( SearchResultsDlg, ListSelectHdl, weld::TreeView&, void ) return; // Jump to the cell. - ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell(); - pScViewShell->SetTabNo(nTab); - pScViewShell->SetCursor(aPos.Col(), aPos.Row()); - pScViewShell->AlignToCursor(aPos.Col(), aPos.Row(), SC_FOLLOW_JUMP); + if (ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell()) + { + pScViewShell->SetTabNo(nTab); + pScViewShell->SetCursor(aPos.Col(), aPos.Row()); + pScViewShell->AlignToCursor(aPos.Col(), aPos.Row(), SC_FOLLOW_JUMP); + } } IMPL_STATIC_LINK( SearchResultsDlg, OnShowToggled, weld::Toggleable&, rButton, void ) { - ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell(); - ScViewOptions aViewOpt( pScViewShell->GetViewData().GetOptions() ); - aViewOpt.SetOption( VOPT_SUMMARY, rButton.get_active() ); - pScViewShell->GetViewData().SetOptions( aViewOpt ); + if (ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell()) + { + ScViewOptions aViewOpt( pScViewShell->GetViewData().GetOptions() ); + aViewOpt.SetOption( VOPT_SUMMARY, rButton.get_active() ); + pScViewShell->GetViewData().SetOptions( aViewOpt ); + } } SearchResultsDlgWrapper::SearchResultsDlgWrapper( diff --git a/sc/source/ui/miscdlgs/mvtabdlg.cxx b/sc/source/ui/miscdlgs/mvtabdlg.cxx index afacdc48b46e..fe2b9d211104 100644 --- a/sc/source/ui/miscdlgs/mvtabdlg.cxx +++ b/sc/source/ui/miscdlgs/mvtabdlg.cxx @@ -191,9 +191,9 @@ void ScMoveTableDlg::Init() m_xEdTabName->connect_changed(LINK(this, ScMoveTableDlg, CheckNameHdl)); // tdf#96854 - remember last used option for copy/move sheet - const bool bIsCopyActive - = ScTabViewShell::GetActiveViewShell()->GetViewData().GetOptions().GetOption( - VOPT_COPY_SHEET); + bool bIsCopyActive = false; + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + bIsCopyActive = pViewSh->GetViewData().GetOptions().GetOption(VOPT_COPY_SHEET); m_xBtnMove->set_active(!bIsCopyActive); m_xBtnCopy->set_active(bIsCopyActive); m_xEdTabName->set_sensitive(false); @@ -251,10 +251,12 @@ void ScMoveTableDlg::SetOkBtnLabel() // tdf#139464 Write "Copy" or "Move" on OK button m_xBtnOk->set_label(bIsCopyActive ? m_xBtnCopy->get_label() : m_xBtnMove->get_label()); // tdf#96854 - remember last used option for copy/move sheet - ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell(); - ScViewOptions aViewOpt(pScViewShell->GetViewData().GetOptions()); - aViewOpt.SetOption(VOPT_COPY_SHEET, bIsCopyActive); - pScViewShell->GetViewData().SetOptions(aViewOpt); + if (ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell()) + { + ScViewOptions aViewOpt(pScViewShell->GetViewData().GetOptions()); + aViewOpt.SetOption(VOPT_COPY_SHEET, bIsCopyActive); + pScViewShell->GetViewData().SetOptions(aViewOpt); + } } // Handler: diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx index 3304f4d39b08..81139b77660a 100644 --- a/sc/source/ui/namedlg/namedefdlg.cxx +++ b/sc/source/ui/namedlg/namedefdlg.cxx @@ -94,8 +94,8 @@ void ScNameDefDlg::CancelPushed() response(RET_CANCEL); else { - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - pViewSh->SwitchBetweenRefDialogs(this); + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + pViewSh->SwitchBetweenRefDialogs(this); } } @@ -254,8 +254,8 @@ void ScNameDefDlg::AddPushed() { maName = aName; maScope = aScope; - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - pViewSh->SwitchBetweenRefDialogs(this); + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + pViewSh->SwitchBetweenRefDialogs(this); } } else diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx index a6a182cd82d9..25016723781c 100644 --- a/sc/source/ui/namedlg/namedlg.cxx +++ b/sc/source/ui/namedlg/namedlg.cxx @@ -306,8 +306,8 @@ void ScNameDlg::ShowOptions(const ScRangeNameLine& rLine) void ScNameDlg::AddPushed() { mbCloseWithoutUndo = true; - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - pViewSh->SwitchBetweenRefDialogs(this); + if (ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell()) + pViewSh->SwitchBetweenRefDialogs(this); } void ScNameDlg::SetEntry(const OUString& rName, const OUString& rScope) diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index 534415b6a7b3..46c10bfe6f5d 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -1352,18 +1352,21 @@ void ScUndoDragDrop::DoUndo( ScRange aRange ) pDocShell->UpdatePaintExt(mnPaintExtFlags, aPaintRange); maPaintRanges.Join(aPaintRange); - if (comphelper::LibreOfficeKit::isActive()) + if (ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell()) { - ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell(); - pTabViewShell->OnLOKSetWidthOrHeight(aPaintRange.aStart.Col(), true); - pTabViewShell->OnLOKSetWidthOrHeight(aPaintRange.aStart.Row(), false); + if (comphelper::LibreOfficeKit::isActive()) + { + pTabViewShell->OnLOKSetWidthOrHeight(aPaintRange.aStart.Col(), true); + pTabViewShell->OnLOKSetWidthOrHeight(aPaintRange.aStart.Row(), false); + } + + ScTabViewShell::notifyAllViewsSheetGeomInvalidation( + pTabViewShell, + true /* bColumns */, true /* bRows */, + true /* bSizes */, true /* bHidden */, true /* bFiltered */, + true /* bGroups */, aPaintRange.aStart.Tab()); } - ScTabViewShell::notifyAllViewsSheetGeomInvalidation( - ScTabViewShell::GetActiveViewShell(), - true /* bColumns */, true /* bRows */, - true /* bSizes */, true /* bHidden */, true /* bFiltered */, - true /* bGroups */, aPaintRange.aStart.Tab()); } void ScUndoDragDrop::Undo() @@ -1522,23 +1525,25 @@ void ScUndoDragDrop::Redo() nStartRow = std::min(nStartRow, aSrcRange.aStart.Row()); } - ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell(); - pTabViewShell->OnLOKSetWidthOrHeight(nStartCol, true); - pTabViewShell->OnLOKSetWidthOrHeight(nStartRow, false); - - SCTAB nStartTab = aDestRange.aStart.Tab(); - SCTAB nEndTab = aDestRange.aEnd.Tab(); - if (bCut) + if (ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell()) { - nStartTab = std::min(nStartTab, aSrcRange.aStart.Tab()); - nEndTab = std::max(nEndTab, aSrcRange.aEnd.Tab()); - } - for (nTab = nStartTab; nTab <= nEndTab; ++nTab) - { - ScTabViewShell::notifyAllViewsSheetGeomInvalidation( - ScTabViewShell::GetActiveViewShell(), true /* bColumns */, true /* bRows */, - true /* bSizes */, true /* bHidden */, true /* bFiltered */, true /* bGroups */, - nTab); + pTabViewShell->OnLOKSetWidthOrHeight(nStartCol, true); + pTabViewShell->OnLOKSetWidthOrHeight(nStartRow, false); + + SCTAB nStartTab = aDestRange.aStart.Tab(); + SCTAB nEndTab = aDestRange.aEnd.Tab(); + if (bCut) + { + nStartTab = std::min(nStartTab, aSrcRange.aStart.Tab()); + nEndTab = std::max(nEndTab, aSrcRange.aEnd.Tab()); + } + for (nTab = nStartTab; nTab <= nEndTab; ++nTab) + { + ScTabViewShell::notifyAllViewsSheetGeomInvalidation( + pTabViewShell, true /* bColumns */, true /* bRows */, + true /* bSizes */, true /* bHidden */, true /* bFiltered */, true /* bGroups */, + nTab); + } } } } diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx index 498060839ab1..f34ebba87d32 100644 --- a/sc/source/ui/undo/undodat.cxx +++ b/sc/source/ui/undo/undodat.cxx @@ -77,10 +77,13 @@ OUString ScUndoDoOutline::GetComment() const void ScUndoDoOutline::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); // sheet has to be switched over (#46952#)! @@ -114,9 +117,11 @@ void ScUndoDoOutline::Undo() void ScUndoDoOutline::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); // sheet has to be switched over (#46952#)! @@ -168,10 +173,13 @@ OUString ScUndoMakeOutline::GetComment() const void ScUndoMakeOutline::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd ); @@ -196,10 +204,13 @@ void ScUndoMakeOutline::Undo() void ScUndoMakeOutline::Redo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginRedo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd ); @@ -253,10 +264,13 @@ OUString ScUndoOutlineLevel::GetComment() const void ScUndoOutlineLevel::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); // Original Outline table @@ -288,9 +302,11 @@ void ScUndoOutlineLevel::Undo() void ScUndoOutlineLevel::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); // sheet has to be switched on or off before this (#46952#) !!! @@ -337,10 +353,13 @@ OUString ScUndoOutlineBlock::GetComment() const void ScUndoOutlineBlock::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); // Original Outline table @@ -387,9 +406,11 @@ void ScUndoOutlineBlock::Undo() void ScUndoOutlineBlock::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd ); if (bShow) @@ -437,10 +458,13 @@ OUString ScUndoRemoveAllOutlines::GetComment() const void ScUndoRemoveAllOutlines::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); // Original Outline table @@ -477,9 +501,11 @@ void ScUndoRemoveAllOutlines::Undo() void ScUndoRemoveAllOutlines::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); // sheet has to be switched over (#46952#)! @@ -523,10 +549,13 @@ OUString ScUndoAutoOutline::GetComment() const void ScUndoAutoOutline::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); // Original outline table @@ -561,19 +590,18 @@ void ScUndoAutoOutline::Undo() void ScUndoAutoOutline::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); SCTAB nTab = aBlockStart.Tab(); - if (pViewShell) - { - // sheet has to be switched on or off before this (#46952#) !!! + // sheet has to be switched on or off before this (#46952#) !!! - SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); - if ( nVisTab != nTab ) - pViewShell->SetTabNo( nTab ); - } + SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); + if ( nVisTab != nTab ) + pViewShell->SetTabNo( nTab ); ScRange aRange( aBlockStart.Col(), aBlockStart.Row(), nTab, aBlockEnd.Col(), aBlockEnd.Row(), nTab ); @@ -584,8 +612,7 @@ void ScUndoAutoOutline::Redo() // If it was called with a multi selection, // then this is now the enclosing range... - if (pViewShell) - pViewShell->MarkRange( aRange ); + pViewShell->MarkRange( aRange ); EndRedo(); } @@ -624,10 +651,13 @@ OUString ScUndoSubTotals::GetComment() const void ScUndoSubTotals::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); if (nNewEndRow > aParam.nRow2) { @@ -691,9 +721,11 @@ void ScUndoSubTotals::Undo() void ScUndoSubTotals::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); if ( nVisTab != nTab ) @@ -755,6 +787,9 @@ OUString ScUndoQuery::GetComment() const void ScUndoQuery::Undo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + if (ScTabViewShell::isAnyEditViewInRange(pViewShell, /*bColumns*/ false, aQueryParam.nRow1, aQueryParam.nRow2)) return; @@ -870,9 +905,11 @@ void ScUndoQuery::Undo() void ScUndoQuery::Redo() { - BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + BeginRedo(); SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); if ( nVisTab != nTab ) @@ -1065,10 +1102,13 @@ OUString ScUndoImportData::GetComment() const void ScUndoImportData::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab, nEndCol,nEndRow,nTab ); @@ -1150,10 +1190,13 @@ void ScUndoImportData::Undo() void ScUndoImportData::Redo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginRedo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab, nEndCol,nEndRow,nTab ); @@ -1274,10 +1317,13 @@ OUString ScUndoRepeatDB::GetComment() const void ScUndoRepeatDB::Undo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginUndo(); ScDocument& rDoc = pDocShell->GetDocument(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); if (bQuerySize) @@ -1375,9 +1421,12 @@ void ScUndoRepeatDB::Undo() void ScUndoRepeatDB::Redo() { + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + BeginRedo(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); SCTAB nTab = aBlockStart.Tab(); SCTAB nVisTab = pViewShell->GetViewData().GetTabNo(); @@ -1493,12 +1542,6 @@ void ScUndoDataPilot::Undo() pDocShell->PostPaint(aOldRange, PaintPartFlags::Grid, SC_PF_LINES); pDocShell->PostDataChanged(); - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); - if (pViewShell) - { - //! set current sheet - } - if (xNewDPObject) { // notify API objects @@ -1887,7 +1930,7 @@ void ScUndoDataForm::DoChange( const bool bUndo ) aDrawRange.aEnd.SetCol(rDoc.MaxCol()); aDrawRange.aEnd.SetRow(rDoc.MaxRow()); nPaint |= PaintPartFlags::Top | PaintPartFlags::Left; -/*A*/ if (pViewShell) + if (pViewShell) pViewShell->AdjustBlockHeight(false); } else @@ -1902,7 +1945,7 @@ void ScUndoDataForm::DoChange( const bool bUndo ) nPaint |= PaintPartFlags::Left; aDrawRange.aEnd.SetRow(rDoc.MaxRow()); } -/*A*/ if (pViewShell && pViewShell->AdjustBlockHeight(false)) + if (pViewShell && pViewShell->AdjustBlockHeight(false)) { aDrawRange.aStart.SetCol(0); aDrawRange.aStart.SetRow(0); diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx index 20e40a416e7d..c12c54bad8ee 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -163,6 +163,9 @@ void ScUndoInsertTab::SetChangeTrack() void ScUndoInsertTab::Undo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + pViewShell->SetTabNo(nTab); pDocShell->SetInUndo( true ); //! BeginUndo @@ -193,6 +196,8 @@ void ScUndoInsertTab::Undo() void ScUndoInsertTab::Redo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; RedoSdrUndoAction( pDrawUndo.get() ); // Draw Redo first @@ -277,6 +282,9 @@ void ScUndoInsertTables::SetChangeTrack() void ScUndoInsertTables::Undo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + pViewShell->SetTabNo(nTab); pDocShell->SetInUndo( true ); //! BeginUndo @@ -300,6 +308,8 @@ void ScUndoInsertTables::Undo() void ScUndoInsertTables::Redo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; RedoSdrUndoAction( pDrawUndo.get() ); // Draw Redo first @@ -438,8 +448,11 @@ void ScUndoDeleteTab::Undo() ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); if (comphelper::LibreOfficeKit::isActive() && !theTabs.empty()) { - lcl_OnTabsChanged(pViewShell, rDoc, theTabs[0]); - lcl_UndoCommandResult(pViewShell, ".uno:Undo", "ScUndoDeleteTab", &theTabs); + if (pViewShell) + { + lcl_OnTabsChanged(pViewShell, rDoc, theTabs[0]); + lcl_UndoCommandResult(pViewShell, ".uno:Undo", "ScUndoDeleteTab", &theTabs); + } } for(SCTAB nTab: theTabs) @@ -581,9 +594,11 @@ OUString ScUndoMoveTab::GetComment() const void ScUndoMoveTab::DoChange( bool bUndo ) const { - ScDocument& rDoc = pDocShell->GetDocument(); ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + ScDocument& rDoc = pDocShell->GetDocument(); if (bUndo) // UnDo { size_t i = mpNewTabs->size(); @@ -742,8 +757,11 @@ void ScUndoCopyTab::Undo() void ScUndoCopyTab::Redo() { - ScDocument& rDoc = pDocShell->GetDocument(); ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + + ScDocument& rDoc = pDocShell->GetDocument(); SCTAB nDestTab = 0; for (size_t i = 0, n = mpNewTabs->size(); i < n; ++i) @@ -980,6 +998,9 @@ OUString ScUndoImportTab::GetComment() const void ScUndoImportTab::DoChange() const { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + ScDocument& rDoc = pDocShell->GetDocument(); SCTAB nTabCount = rDoc.GetTableCount(); if (pViewShell) @@ -1202,9 +1223,11 @@ ScUndoShowHideTab::~ScUndoShowHideTab() void ScUndoShowHideTab::DoChange( bool bShowP ) const { - ScDocument& rDoc = pDocShell->GetDocument(); ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + ScDocument& rDoc = pDocShell->GetDocument(); for(const SCTAB& nTab : undoTabs) { rDoc.SetVisible( nTab, bShowP ); diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index aafc46a2fa32..5c62962e2c06 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -1079,7 +1079,7 @@ void ScTabViewShell::SetDrawTextUndo( SfxUndoManager* pNewUndoMgr ) ScTabViewShell* ScTabViewShell::GetActiveViewShell() { - return dynamic_cast< ScTabViewShell *>( Current() ); + return dynamic_cast< ScTabViewShell *>( SfxViewShell::Current() ); } SfxPrinter* ScTabViewShell::GetPrinter( bool bCreate )