sc/source/ui/app/inputwin.cxx | 19 ++- 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/undodat.cxx | 129 ++++++++++++++++--------- sc/source/ui/undo/undotab.cxx | 26 ++++- sc/source/ui/view/tabvwsh4.cxx | 2 9 files changed, 183 insertions(+), 109 deletions(-)
New commits: commit 982cf82f52935057ac94334a608f6dde99e6c1da Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Tue May 21 17:22:53 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Jun 4 12:19:48 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> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167923 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> (cherry picked from commit 768823934200096c4bd736526aa9765b1bceb0bb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167935 Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org> diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index 7f0cf742b05d..2b2dcb7ebd77 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; + } } } @@ -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 ade0cede7cef..171c9ecd135b 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -440,43 +440,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/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 4237aab46358..0eacb70d1c9c 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -105,6 +105,9 @@ void ScUndoInsertTab::SetChangeTrack() void ScUndoInsertTab::Undo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + pViewShell->SetTabNo(nTab); pDocShell->SetInUndo( true ); //! BeginUndo @@ -126,6 +129,8 @@ void ScUndoInsertTab::Undo() void ScUndoInsertTab::Redo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; RedoSdrUndoAction( pDrawUndo.get() ); // Draw Redo first @@ -202,6 +207,9 @@ void ScUndoInsertTables::SetChangeTrack() void ScUndoInsertTables::Undo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; + pViewShell->SetTabNo(nTab); pDocShell->SetInUndo( true ); //! BeginUndo @@ -225,6 +233,8 @@ void ScUndoInsertTables::Undo() void ScUndoInsertTables::Redo() { ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); + if (!pViewShell) + return; RedoSdrUndoAction( pDrawUndo.get() ); // Draw Redo first @@ -493,9 +503,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(); @@ -645,8 +657,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) @@ -883,6 +898,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) @@ -1105,9 +1123,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 345a33534d1c..2daa55be00ce 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -1075,7 +1075,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 )