sc/inc/SheetViewTypes.hxx | 3 +++ sc/inc/document.hxx | 2 +- sc/source/core/data/document10.cxx | 22 +++++++++++++--------- sc/source/ui/view/viewfun3.cxx | 31 ++++++++++++++++--------------- 4 files changed, 33 insertions(+), 25 deletions(-)
New commits: commit d305dee4e20095a0782d1a4db5ba41bc3705fff9 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Aug 19 13:43:23 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Sep 18 10:31:35 2025 +0200 sc: move part of sheet view creation into ScDocument Instead of setting up in ScViewFunc, just create everything needed for adding a sheet view inside ScDocument::CreateNewSheetView. This will limit the functions we need to expose to the outside of ScDocument. Change-Id: Ie8c432b175e7bbb55fc5ae3c6fe3a2b822e6d619 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189914 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 9e062392a77c26ba7e39b90a689acf0d6a2cf7eb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191085 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/inc/SheetViewTypes.hxx b/sc/inc/SheetViewTypes.hxx index 51e676423d5f..b41e8b3cfac0 100644 --- a/sc/inc/SheetViewTypes.hxx +++ b/sc/inc/SheetViewTypes.hxx @@ -16,6 +16,9 @@ typedef sal_Int32 SheetViewID; /** Defines the value to identify the default view of the sheet */ constexpr SheetViewID DefaultSheetViewID = -1; + +/** Invalid sheet view ID */ +constexpr SheetViewID InvalidSheetViewID = SAL_MIN_INT32; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 6502df8e8e3e..fd6d1eeeea61 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2399,7 +2399,7 @@ public: /* Sheet View */ /** Creates a new sheet view for the table, using the sheet view table */ - sal_Int32 CreateNewSheetView(SCTAB nMainTable, SCTAB nSheetViewTable); + std::pair<sc::SheetViewID, SCTAB> CreateNewSheetView(SCTAB nTab); /** Return the sheet view table for the ID */ SCTAB GetSheetViewNumber(SCTAB nTab, sc::SheetViewID nID); diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index 8cf23b7d97c7..b288967fccf4 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -1132,20 +1132,24 @@ void ScDocument::SetSheetView(SCTAB nTab, bool bSheetView) } } -sc::SheetViewID ScDocument::CreateNewSheetView(SCTAB nMainTable, SCTAB nSheetViewTable) + +std::pair<sc::SheetViewID, SCTAB> ScDocument::CreateNewSheetView(SCTAB nTab) { - if (ScTable* pTable = FetchTable(nMainTable)) + if (ScTable* pTable = FetchTable(nTab)) { - if (pTable->IsSheetView()) - return -1; - - if (ScTable* pSheetViewTable = FetchTable(nSheetViewTable)) + SCTAB nSheetViewTab = nTab + 1; + if (CopyTab(nTab, nSheetViewTab)) { - auto nSheetViewID = pTable->GetSheetViewManager()->create(pSheetViewTable); - return nSheetViewID; + if (ScTable* pSheetViewTable = FetchTable(nSheetViewTab)) + { + auto nSheetViewID = pTable->GetSheetViewManager()->create(pSheetViewTable); + pSheetViewTable->SetVisible(false); + pSheetViewTable->SetSheetView(true); + return { nSheetViewID, nSheetViewTab }; + } } } - return -1; + return { sc::InvalidSheetViewID, -1 }; } bool ScDocument::HasSheetViews(SCTAB nTab) const diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index b1d284114636..3f5d0125953a 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -2068,25 +2068,26 @@ void ScViewFunc::MakeNewSheetView() SCTAB nTab = GetViewData().GetTabNumber(); ScDocument& rDocument = GetViewData().GetDocument(); - SCTAB nSheetViewTab = nTab + 1; - if (rDocument.CopyTab(nTab, nSheetViewTab)) + auto[nSheetViewID, nSheetViewTab] = rDocument.CreateNewSheetView(nTab); + + if (nSheetViewID == sc::InvalidSheetViewID) { - GetViewData().GetDocShell()->Broadcast(ScTablesHint(SC_TAB_INSERTED, nSheetViewTab)); - SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScTablesChanged)); + SAL_WARN("sc", "Sheet view couldn't be created"); + return; + } - // Add and register the created sheet view - rDocument.SetSheetView(nSheetViewTab, true); - sc::SheetViewID nSheetViewID = rDocument.CreateNewSheetView(nTab, nSheetViewTab); - GetViewData().SetSheetViewID(nSheetViewID); + GetViewData().SetSheetViewID(nSheetViewID); + + // Update + GetViewData().SetTabNo(nSheetViewTab); // force add the sheet view tab + GetViewData().SetTabNo(nTab); // then change back to the current tab - // Update - GetViewData().SetTabNo(nSheetViewTab); // force add the sheet view tab - GetViewData().SetTabNo(nTab); // then change back to the current tab + ScDocShell& rDocSh = *GetViewData().GetDocShell(); + rDocSh.PostPaintGridAll(); + PaintExtras(); // update Tab Control - ScDocShell& rDocSh = *GetViewData().GetDocShell(); - rDocSh.PostPaintGridAll(); - PaintExtras(); // update Tab Control - } + rDocSh.Broadcast(ScTablesHint(SC_TAB_INSERTED, nSheetViewTab)); + SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScTablesChanged)); } void ScViewFunc::RemoveCurrentSheetView()