sc: Toolbar / NotebookBar combobox for selecting sheet views

Introduced CurrentSheetView command that handles reading and
setting the sheet view for the current sheet. In addition under
the same command, the toolbar / (online) notebookbar combobox to
show and set the combobox is available, so it can be added to the
toolbar.

Change-Id: I7910ac0590ca2b2349496e91fdf61e70c297d651
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192797
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192966
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2025-10-26 05:08:31 +01:00
committed by Tomaž Vajngerl
parent 87935b4c9f
commit 8ce68da750
20 changed files with 361 additions and 7 deletions
@@ -35,6 +35,11 @@
<value xml:lang="en-US">Number Format Type</value>
</prop>
</node>
<node oor:name=".uno:CurrentSheetView" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Current Sheet View</value>
</prop>
</node>
<node oor:name=".uno:ObjectMirrorHorizontal" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">Flip Horizontally</value>
+2
View File
@@ -404,6 +404,8 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/ui/cctrl/checklistmenu \
sc/source/ui/cctrl/dpcontrol \
sc/source/ui/cctrl/tbzoomsliderctrl \
sc/source/ui/cctrl/SheetViewBox \
sc/source/ui/cctrl/SheetViewControl \
sc/source/ui/condformat/condformatdlg \
sc/source/ui/condformat/condformatdlgentry \
sc/source/ui/condformat/condformatdlgdata \
+1
View File
@@ -239,6 +239,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
sc/uiconfig/scalc/ui/sharedfooterdialog \
sc/uiconfig/scalc/ui/sharedheaderdialog \
sc/uiconfig/scalc/ui/sharedwarningdialog \
sc/uiconfig/scalc/ui/sheetviewbox \
sc/uiconfig/scalc/ui/showchangesdialog \
sc/uiconfig/scalc/ui/showdetaildialog \
sc/uiconfig/scalc/ui/showsheetdialog \
+32
View File
@@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <sfx2/tbxctrl.hxx>
namespace sc
{
/** Toolbox control for showing the SheetViewBox in the toolbar / notebookbar */
class SheetViewControl final : public SfxToolBoxControl
{
public:
SFX_DECL_TOOLBOX_CONTROL();
SheetViewControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rToolBox);
virtual ~SheetViewControl() override;
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState,
const SfxPoolItem* pState) override;
virtual VclPtr<InterimItemWindow> CreateItemWindow(vcl::Window* pParent) override;
};
} // end of namespace sc
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+2
View File
@@ -291,6 +291,8 @@ class SvxZoomSliderItem;
#define FID_SWITCH_TO_PREVIOUS_SHEET_VIEW (VIEW_MENU_START + 14)
#define FID_EXIT_SHEET_VIEW (VIEW_MENU_START + 15)
#define FID_SELECT_SHEET_VIEW (VIEW_MENU_START + 16)
#define FID_CURRENT_SHEET_VIEW TypedWhichId<SfxInt32Item>(VIEW_MENU_START + 17)
#define FID_CHG_ACCEPT (VIEW_MENU_START + 18)// DANGER DIRTY ID
#define FID_CHG_COMMENT (VIEW_MENU_START + 19)// DANGER DIRTY ID
+19 -2
View File
@@ -6049,6 +6049,23 @@ SfxBoolItem ToggleFormula FID_TOGGLEFORMULA
GroupId = SfxGroupId::View
]
SfxInt32Item CurrentSheetVIew FID_CURRENT_SHEET_VIEW
[
AutoUpdate = FALSE,
FastCall = FALSE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
AccelConfig = FALSE,
MenuConfig = FALSE,
ToolBoxConfig = TRUE,
GroupId = SfxGroupId::Format;
]
SfxBoolItem NewSheetView FID_NEW_SHEET_VIEW
[
/* flags */
@@ -6134,8 +6151,8 @@ SfxBoolItem SelectSheetView FID_SELECT_SHEET_VIEW
/* config */
AccelConfig = TRUE,
MenuConfig = FALSE,
ToolBoxConfig = FALSE,
MenuConfig = TRUE,
ToolBoxConfig = TRUE,
GroupId = SfxGroupId::View
]
+1
View File
@@ -213,6 +213,7 @@ interface TableEditView
FID_SWITCH_TO_PREVIOUS_SHEET_VIEW [ ExecMethod = Execute; StateMethod = GetState; ]
FID_EXIT_SHEET_VIEW [ ExecMethod = Execute; StateMethod = GetState; ]
FID_SELECT_SHEET_VIEW [ ExecMethod = Execute; StateMethod = GetState; ]
FID_CURRENT_SHEET_VIEW [ ExecMethod = Execute; StateMethod = GetState; ]
FID_NORMALVIEWMODE [ ExecMethod = Execute; StateMethod = GetState; ]
FID_PAGEBREAKMODE [ ExecMethod = Execute; StateMethod = GetState; ]
SID_REPAINT [ ExecMethod = Execute; StateMethod = GetState; ]
+2
View File
@@ -72,6 +72,7 @@
#include <svx/formatpaintbrushctrl.hxx>
#include <tbzoomsliderctrl.hxx>
#include <svx/zoomsliderctrl.hxx>
#include <SheetViewControl.hxx>
#include <svx/xmlsecctrl.hxx>
// Child windows
@@ -148,6 +149,7 @@ void ScDLL::Init()
SvxClipBoardControl ::RegisterControl(SID_PASTE_UNFORMATTED, pMod );
svx::FormatPaintBrushToolBoxControl::RegisterControl(SID_FORMATPAINTBRUSH, pMod );
sc::ScNumberFormatControl ::RegisterControl(SID_NUMBER_TYPE_FORMAT, pMod );
sc::SheetViewControl::RegisterControl(FID_CURRENT_SHEET_VIEW, pMod);
SvxGrafModeToolBoxControl ::RegisterControl(SID_ATTR_GRAF_MODE, pMod);
SvxGrafRedToolBoxControl ::RegisterControl(SID_ATTR_GRAF_RED, pMod);
+106
View File
@@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <SheetViewBox.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/viewsh.hxx>
#include <svl/intitem.hxx>
#include <svl/itemset.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <sc.hrc>
#include <docsh.hxx>
#include <viewdata.hxx>
#include <SheetViewManager.hxx>
#include <SheetView.hxx>
#include <SheetViewTypes.hxx>
SheetViewBox::SheetViewBox(vcl::Window* pParent)
: InterimItemWindow(pParent, u"modules/scalc/ui/sheetviewbox.ui"_ustr, u"SheetViewBox"_ustr,
true, reinterpret_cast<sal_uInt64>(SfxViewShell::Current()))
, m_xWidget(m_xBuilder->weld_combo_box(u"sheetview_combobox"_ustr))
{
m_xWidget->connect_changed(LINK(this, SheetViewBox, SelectHdl));
m_xWidget->connect_key_press(LINK(this, SheetViewBox, KeyInputHdl));
SetSizePixel(m_xWidget->get_preferred_size());
}
void SheetViewBox::dispose()
{
m_xWidget.reset();
InterimItemWindow::dispose();
}
SheetViewBox::~SheetViewBox() { disposeOnce(); }
void SheetViewBox::GetFocus()
{
if (m_xWidget)
m_xWidget->grab_focus();
InterimItemWindow::GetFocus();
}
void SheetViewBox::Update(sc::SheetViewID nSelectedID)
{
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();
if (pSheetManager)
{
sc::SheetViewID nSheetViewID = 0;
for (auto const& pSheetView : pSheetManager->getSheetViews())
{
if (pSheetView)
{
OUString sID = OUString::number(nSheetViewID);
if (nSheetViewID == nSelectedID)
sActiveID = sID;
m_xWidget->append(sID, pSheetView->GetName());
}
nSheetViewID++;
}
}
m_xWidget->thaw();
m_xWidget->set_active_id(sActiveID);
}
IMPL_STATIC_LINK(SheetViewBox, SelectHdl, weld::ComboBox&, rComboBox, void)
{
auto* pViewFrame = SfxViewFrame::Current();
if (!pViewFrame)
return;
SfxDispatcher* pDispatcher = pViewFrame->GetBindings().GetDispatcher();
if (!pDispatcher)
return;
const OUString sValue = rComboBox.get_active_id();
SfxInt32Item aItem(FID_CURRENT_SHEET_VIEW, sValue.toInt32());
pDispatcher->ExecuteList(FID_CURRENT_SHEET_VIEW, SfxCallMode::RECORD, { &aItem });
pViewFrame->GetWindow().GrabFocus();
}
IMPL_LINK(SheetViewBox, KeyInputHdl, const KeyEvent&, rKEvt, bool) { return ChildKeyInput(rKEvt); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+63
View File
@@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <SheetViewControl.hxx>
#include <SheetViewBox.hxx>
#include <svl/intitem.hxx>
#include <vcl/toolbox.hxx>
using namespace sc;
SFX_IMPL_TOOLBOX_CONTROL(SheetViewControl, SfxInt32Item);
SheetViewControl::SheetViewControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx)
: SfxToolBoxControl(nSlotId, nId, rTbx)
{
}
SheetViewControl::~SheetViewControl() {}
void SheetViewControl::StateChangedAtToolBoxControl(sal_uInt16, SfxItemState eState,
const SfxPoolItem* pState)
{
ToolBoxItemId nId = GetId();
ToolBox& rToolBox = GetToolBox();
SheetViewBox* pSheetViewBox = static_cast<SheetViewBox*>(rToolBox.GetItemWindow(nId));
if (SfxItemState::DISABLED == eState)
pSheetViewBox->Disable();
else
pSheetViewBox->Enable();
rToolBox.EnableItem(nId, SfxItemState::DISABLED != eState);
switch (eState)
{
case SfxItemState::DEFAULT:
{
const auto* pItem = static_cast<const SfxInt32Item*>(pState);
sc::SheetViewID nValue = pItem->GetValue();
pSheetViewBox->Update(nValue);
break;
}
default:
break;
}
}
VclPtr<InterimItemWindow> SheetViewControl::CreateItemWindow(vcl::Window* pParent)
{
VclPtr<SheetViewBox> pControl = VclPtr<SheetViewBox>::Create(pParent);
pControl->Show();
return pControl;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+36
View File
@@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <vcl/InterimItemWindow.hxx>
#include <SheetViewTypes.hxx>
/** Box / container for the combobox for showing / selecting the sheet view */
class SheetViewBox final : public InterimItemWindow
{
public:
explicit SheetViewBox(vcl::Window* pParent);
virtual void dispose() override;
virtual ~SheetViewBox() override;
virtual void GetFocus() override;
void Update(sc::SheetViewID nID);
weld::ComboBox* getWidget() { return m_xWidget.get(); }
private:
std::unique_ptr<weld::ComboBox> m_xWidget;
DECL_STATIC_LINK(SheetViewBox, SelectHdl, weld::ComboBox&, void);
DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+4
View File
@@ -28,6 +28,8 @@
#include <memory>
#include <o3tl/typed_flags_set.hxx>
namespace sc { class SheetViewManager; }
constexpr auto SC_SIZE_NONE = std::numeric_limits<tools::Long>::max();
enum class ScFillMode
@@ -420,6 +422,8 @@ public:
sc::SheetViewID GetSheetViewIDForSheet(SCTAB nTab) const;
std::shared_ptr<sc::SheetViewManager> GetCurrentSheetViewManager() const;
SCCOL MaxCol() const { return mrDoc.MaxCol(); }
SCROW MaxRow() const { return mrDoc.MaxRow(); }
ScSplitPos GetActivePart() const { return pThisTab->eWhichActive; }
+2
View File
@@ -2126,6 +2126,8 @@ void ScTabView::SetTabNo( SCTAB nTab, bool bNew, bool bExtendSelection, bool bSa
rBindings.Invalidate( SID_STYLE_FAMILY4 ); // Designer
rBindings.Invalidate( SID_TABLES_COUNT );
rBindings.Invalidate(FID_CURRENT_SHEET_VIEW);
if (pScMod->IsRefDialogOpen())
{
sal_uInt16 nCurRefDlgId=pScMod->GetCurRefDlgId();
+15
View File
@@ -1080,6 +1080,21 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
rReq.Done();
}
break;
case FID_CURRENT_SHEET_VIEW:
{
const SfxPoolItem* pItem = nullptr;
if (pReqArgs != nullptr && pReqArgs->HasItem(FID_CURRENT_SHEET_VIEW, &pItem))
{
const sal_Int32 nValue = static_cast<const SfxInt32Item*>(pItem)->GetValue();
sc::SheetViewID nID(nValue);
if (nID != sc::InvalidSheetViewID)
{
SelectSheetView(nID);
}
}
rReq.Done();
}
break;
case SID_ATTR_ZOOM: // status row
case FID_SCALE:
+5 -1
View File
@@ -412,7 +412,11 @@ void ScTabViewShell::GetState( SfxItemSet& rSet )
}
}
break;
case FID_CURRENT_SHEET_VIEW:
{
rSet.Put(SfxInt32Item(FID_CURRENT_SHEET_VIEW, GetViewData().GetSheetViewID()));
}
break;
case FID_NORMALVIEWMODE:
case FID_PAGEBREAKMODE:
// always handle both slots - they exclude each other
+4
View File
@@ -4465,5 +4465,9 @@ sc::SheetViewID ScViewData::GetSheetViewIDForSheet(SCTAB nTab) const
return maTabData[nTab]->mnSheetViewID;
}
std::shared_ptr<sc::SheetViewManager> ScViewData::GetCurrentSheetViewManager() const
{
return GetDocument().GetSheetViewManager(GetTabNumber());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+7 -3
View File
@@ -67,7 +67,8 @@
#include <uiitems.hxx>
#include <com/sun/star/util/XCloneable.hpp>
#include <sfx2/lokhelper.hxx>
#include <sc.hrc>
#include <sfx2/bindings.hxx>
using namespace com::sun::star;
@@ -2065,8 +2066,9 @@ void ScViewFunc::DataFormPutData( SCROW nCurrentRow ,
void ScViewFunc::SheetViewChanged()
{
ScDocShell& rDocSh = GetViewData().GetDocShell();
ScDocument& rDocument = GetViewData().GetDocument();
ScViewData& rViewData = GetViewData();
ScDocShell& rDocSh = rViewData.GetDocShell();
ScDocument& rDocument = rViewData.GetDocument();
rDocSh.PostPaint(0, 0, 0, rDocument.MaxCol(), rDocument.MaxRow(), MAXTAB, PaintPartFlags::All);
if (ScTabViewShell* pViewShell = GetViewData().GetViewShell())
@@ -2074,6 +2076,8 @@ void ScViewFunc::SheetViewChanged()
ScModelObj* pModel = comphelper::getFromUnoTunnel<ScModelObj>(pViewShell->GetCurrentDocument());
SfxLokHelper::notifyViewRenderState(pViewShell, pModel);
}
SfxBindings& rBindings = rViewData.GetBindings();
rBindings.Invalidate(FID_CURRENT_SHEET_VIEW);
}
void ScViewFunc::MakeNewSheetView()
+26 -1
View File
@@ -94,7 +94,32 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="sfxlo-NotebookbarToolBox" id="CurrentViewToolBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="toolbar_style">icons</property>
<property name="show_arrow">False</property>
<child>
<object class="GtkToolButton" id="Home-CurrentSheetView">
<property name="visible">True</property>
<property name="action_name">.uno:CurrentSheetView</property>
</object>
<packing>
<property name="expand">True</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface domain="sc">
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="SheetViewBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkComboBoxText" id="sheetview_combobox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="sheetview_combobox-atkobject">
<property name="AtkObject::accessible-name" translatable="yes" context="sheetviewbox|sheetview_combobox|accessible_name">Sheet View</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>
+1
View File
@@ -472,6 +472,7 @@ constexpr auto NavigatorList
constexpr auto NotebookbarList
= frozen::make_unordered_set<std::u16string_view>({
{ u"modules/scalc/ui/numberbox.ui" },
{ u"modules/scalc/ui/sheetviewbox.ui" },
{ u"svx/ui/fontnamebox.ui" },
{ u"svx/ui/fontsizebox.ui" },
{ u"svx/ui/stylespreview.ui" },