sc/source/ui/cctrl/SheetViewBox.cxx | 10 +++------- sc/source/ui/cctrl/SheetViewControl.cxx | 18 ++++++++++++++---- sc/source/ui/inc/SheetViewBox.hxx | 4 +++- sc/source/ui/view/tabvwsha.cxx | 7 ++++++- sc/source/ui/view/viewfun3.cxx | 26 +++++++++++++++++++++----- 5 files changed, 47 insertions(+), 18 deletions(-)
New commits: commit 01461d957c79768feee8c3cf3aded58a4a9893dc Author: Tomaž Vajngerl <[email protected]> AuthorDate: Fri Feb 20 19:49:03 2026 +0900 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Feb 20 14:56:34 2026 +0100 sc: Fix sheet view ComboBox updating in toolbar and online This properly udpates and selects the correct sheet view in the sheet view combo-box in the toolbar and online in the notebookbar. Without this invalidations would not be received on all views, but this is needed as the combo box is different for different views. It also contains a temporary hack to always set a unique value into the item set for .uno:CurrentSheetView so it forces the toolbar control to recieve an update. Change-Id: I39baa49088ee58d87ddddc012e75398aa3c9017e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199825 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/source/ui/cctrl/SheetViewBox.cxx b/sc/source/ui/cctrl/SheetViewBox.cxx index 5134f1029ae7..0323c05d5706 100644 --- a/sc/source/ui/cctrl/SheetViewBox.cxx +++ b/sc/source/ui/cctrl/SheetViewBox.cxx @@ -50,26 +50,22 @@ void SheetViewBox::GetFocus() InterimItemWindow::GetFocus(); } -void SheetViewBox::Update(sc::SheetViewID nSelectedID) +void SheetViewBox::Update(ScViewData& rViewData) { - ScViewData* pViewData = ScDocShell::GetViewData(); - if (!pViewData) - return; - m_xWidget->clear(); m_xWidget->freeze(); OUString sActiveID = OUString::number(sc::DefaultSheetViewID); m_xWidget->append(sActiveID, sc::SheetViewManager::defaultViewName()); - auto pSheetManager = pViewData->GetCurrentSheetViewManager(); + auto pSheetManager = rViewData.GetCurrentSheetViewManager(); if (pSheetManager) { for (auto const& rSheetView : pSheetManager->iterateValidSheetViews()) { OUString sID = OUString::number(rSheetView.getID()); - if (rSheetView.getID() == nSelectedID) + if (rSheetView.getID() == rViewData.GetSheetViewID()) sActiveID = sID; m_xWidget->append(sID, rSheetView.GetName()); } diff --git a/sc/source/ui/cctrl/SheetViewControl.cxx b/sc/source/ui/cctrl/SheetViewControl.cxx index cd0a8e5e92a8..934fcd266c50 100644 --- a/sc/source/ui/cctrl/SheetViewControl.cxx +++ b/sc/source/ui/cctrl/SheetViewControl.cxx @@ -9,8 +9,10 @@ #include <SheetViewControl.hxx> #include <SheetViewBox.hxx> +#include <tabvwsh.hxx> #include <svl/intitem.hxx> #include <vcl/toolbox.hxx> +#include <sfx2/viewsh.hxx> using namespace sc; @@ -23,13 +25,21 @@ SheetViewControl::SheetViewControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBo SheetViewControl::~SheetViewControl() {} -void SheetViewControl::StateChangedAtToolBoxControl(sal_uInt16, SfxItemState eState, +void SheetViewControl::StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState) { ToolBoxItemId nId = GetId(); ToolBox& rToolBox = GetToolBox(); SheetViewBox* pSheetViewBox = static_cast<SheetViewBox*>(rToolBox.GetItemWindow(nId)); + css::uno::Reference<css::frame::XFrame> xFrame = getFrameInterface(); + SfxViewShell* pShell = SfxViewShell::Get(xFrame->getController()); + ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pShell); + if (!pTabViewShell) + return; + + ScViewData& rViewData = pTabViewShell->GetViewData(); + if (SfxItemState::DISABLED == eState) pSheetViewBox->Disable(); else @@ -41,15 +51,15 @@ void SheetViewControl::StateChangedAtToolBoxControl(sal_uInt16, SfxItemState eSt { case SfxItemState::DEFAULT: { - const auto* pItem = static_cast<const SfxInt32Item*>(pState); - sc::SheetViewID nValue = pItem->GetValue(); - pSheetViewBox->Update(nValue); + pSheetViewBox->Update(rViewData); break; } default: break; } + + SfxToolBoxControl::StateChangedAtToolBoxControl(nSID, eState, pState); } VclPtr<InterimItemWindow> SheetViewControl::CreateItemWindow(vcl::Window* pParent) diff --git a/sc/source/ui/inc/SheetViewBox.hxx b/sc/source/ui/inc/SheetViewBox.hxx index 95a39c7571dc..2f4a62dd9e09 100644 --- a/sc/source/ui/inc/SheetViewBox.hxx +++ b/sc/source/ui/inc/SheetViewBox.hxx @@ -12,6 +12,8 @@ #include <vcl/InterimItemWindow.hxx> #include <SheetViewTypes.hxx> +class ScViewData; + /** Box / container for the combobox for showing / selecting the sheet view */ class SheetViewBox final : public InterimItemWindow { @@ -22,7 +24,7 @@ public: virtual void GetFocus() override; - void Update(sc::SheetViewID nID); + void Update(ScViewData& rViewData); weld::ComboBox* getWidget() { return m_xWidget.get(); } diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index 4797ee18dcc5..b0ba187d2d2c 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -415,7 +415,12 @@ void ScTabViewShell::GetState( SfxItemSet& rSet ) break; case FID_CURRENT_SHEET_VIEW: { - rSet.Put(SfxInt32Item(FID_CURRENT_SHEET_VIEW, GetViewData().GetSheetViewID())); + // TODO: This is a HACK - Set unique values so we force an update to the ToolBar every time + // an invalidation occurs. This probably needs to be changed to a custom item or something, + // or do it in another way. + static sal_Int32 n = 0; + rSet.ClearItem(FID_CURRENT_SHEET_VIEW); + rSet.Put(SfxInt32Item(FID_CURRENT_SHEET_VIEW, n++)); } break; case FID_NORMALVIEWMODE: diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx index 70ea7dcad657..685fc5512dfe 100644 --- a/sc/source/ui/view/viewfun3.cxx +++ b/sc/source/ui/view/viewfun3.cxx @@ -20,6 +20,7 @@ #include <scitems.hxx> #include <svx/svdpage.hxx> #include <sfx2/docfile.hxx> +#include <sfx2/viewfrm.hxx> #include <comphelper/classids.hxx> #include <comphelper/lok.hxx> #include <sot/formats.hxx> @@ -2072,7 +2073,8 @@ void ScViewFunc::SheetViewChanged() ScViewData& rViewData = GetViewData(); ScDocShell& rDocSh = *rViewData.GetDocShell(); ScDocument& rDocument = rViewData.GetDocument(); - rDocSh.PostPaint(0, 0, 0, rDocument.MaxCol(), rDocument.MaxRow(), MAXTAB, PaintPartFlags::All); + SCTAB nTab = rViewData.GetTabNumber(); + rDocSh.PostPaint(0, 0, nTab, rDocument.MaxCol(), rDocument.MaxRow(), nTab, PaintPartFlags::All); if (ScTabViewShell* pViewShell = GetViewData().GetViewShell()) { @@ -2081,8 +2083,23 @@ void ScViewFunc::SheetViewChanged() pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, "all"_ostr); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY, "all"_ostr); } - SfxBindings& rBindings = rViewData.GetBindings(); - rBindings.Invalidate(FID_CURRENT_SHEET_VIEW); + // Invalidate for all views (connected to the current document) + ScTabViewShell* pThisViewShell = rViewData.GetViewShell(); + if (pThisViewShell) + { + ViewShellDocId nDocID = pThisViewShell->GetDocId(); + SfxViewShell* pViewShell = SfxViewShell::GetFirst(); + while (pViewShell) + { + ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell); + if (pTabViewShell && pTabViewShell->GetDocId() == nDocID) + { + SfxBindings& rBindings = pTabViewShell->GetViewFrame().GetBindings(); + rBindings.Invalidate(FID_CURRENT_SHEET_VIEW); + } + pViewShell = SfxViewShell::GetNext(*pViewShell); + } + } } void ScViewFunc::MakeNewSheetView() @@ -2162,8 +2179,7 @@ void ScViewFunc::SelectSheetView(sc::SheetViewID nSelectSheetViewID) if (GetViewData().GetDocument().IsSheetViewHolder(nTab)) return; - sc::SheetViewID nSheetViewID = GetViewData().GetSheetViewID(); - if (nSheetViewID == nSelectSheetViewID) + if (nSelectSheetViewID == GetViewData().GetSheetViewID()) return; GetViewData().SetSheetViewID(nSelectSheetViewID);
