summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMatt K <mattkse@gmail.com>2023-07-07 00:15:02 -0500
committerHeiko Tietze <heiko.tietze@documentfoundation.org>2023-07-10 16:41:26 +0200
commit7019eef453954785ad039bebd8c8a00183992584 (patch)
tree2d72844f94fc773e714f9fc97e49248e1665ea85 /sw/source
parentb26ddd42b434c84e5f8c939c2903fc7a0f79285f (diff)
tdf#146273 Do not allow non-numeric values for Navigator "Go to"
This change modifies "SwNavigationPI::EditAction" and adds a new "connect_changed" handler "PageModifiedHdl" to the spin control (needed to intercept text handling). In both functions we perform checks to ensure that only numeric values can be entered and only values within the page range of the document. This now matches the behavior of the "Go to Page" feature. To go to the first page, just enter a character input. To go to the last page, just enter a value higher than the total number of pages. Change-Id: Ia020d72f4bed5b98b668ba95888bc4bc1d65e07d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154156 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/uibase/inc/navipi.hxx1
-rw-r--r--sw/source/uibase/utlui/navipi.cxx33
2 files changed, 32 insertions, 2 deletions
diff --git a/sw/source/uibase/inc/navipi.hxx b/sw/source/uibase/inc/navipi.hxx
index 5b9862101254..f87474ab7cba 100644
--- a/sw/source/uibase/inc/navipi.hxx
+++ b/sw/source/uibase/inc/navipi.hxx
@@ -113,6 +113,7 @@ class SwNavigationPI final : public PanelLayout
DECL_LINK( EditActionHdl, weld::Entry&, bool );
DECL_LINK( SetFocusChildHdl, weld::Container&, void );
DECL_LINK( NavigateByComboBoxSelectHdl, weld::ComboBox&, void );
+ DECL_LINK( PageModifiedHdl, weld::Entry&, void );
bool EditAction();
void UsePage();
diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx
index 399e3824bf76..2506b5c83793 100644
--- a/sw/source/uibase/utlui/navipi.cxx
+++ b/sw/source/uibase/utlui/navipi.cxx
@@ -404,8 +404,17 @@ bool SwNavigationPI::EditAction()
if (pView->GetEditWin().HasFocus())
return false;
- SwWrtShell &rSh = m_pCreateView->GetWrtShell();
- sal_uInt16 nNewPage = m_xEdit->get_value();
+ if (m_xEdit->get_text().isEmpty())
+ return false;
+ sal_Int64 nNewPage = m_xEdit->get_text().toInt32();
+ SwWrtShell& rSh = m_pCreateView->GetWrtShell();
+ sal_Int64 max = rSh.GetPageCnt();
+ if (nNewPage <= 0)
+ nNewPage = 1;
+ else if (nNewPage > max)
+ nNewPage = max;
+ m_xEdit->set_value(nNewPage);
+ m_xEdit->set_position(-1);
rSh.GotoPage(nNewPage, true);
m_pCreateView->GetViewFrame().GetBindings().Invalidate(FN_STAT_PAGE);
@@ -500,6 +509,25 @@ std::unique_ptr<PanelLayout> SwNavigationPI::Create(weld::Widget* pParent,
return std::make_unique<SwNavigationPI>(pParent, rxFrame, pBindings, nullptr);
}
+IMPL_LINK_NOARG(SwNavigationPI, PageModifiedHdl, weld::Entry&, void)
+{
+ SwView* pView = GetCreateView();
+ if (!pView)
+ return;
+ if (m_xEdit->get_text().isEmpty())
+ return;
+ sal_Int64 page_value = m_xEdit->get_text().toInt32();
+ SwWrtShell& rSh = m_pCreateView->GetWrtShell();
+ sal_Int64 max = rSh.GetPageCnt();
+ if (page_value <= 0)
+ m_xEdit->set_value(1);
+ else if (page_value > max)
+ m_xEdit->set_value(max);
+ else
+ m_xEdit->set_value(page_value);
+ m_xEdit->set_position(-1);
+}
+
SwNavigationPI::SwNavigationPI(weld::Widget* pParent,
const css::uno::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* _pBindings, SfxNavigator* pNavigatorDlg)
@@ -590,6 +618,7 @@ SwNavigationPI::SwNavigationPI(weld::Widget* pParent,
m_xEdit->set_width_chars(3);
m_xEdit->connect_activate(LINK(this, SwNavigationPI, EditActionHdl));
m_xEdit->connect_value_changed(LINK(this, SwNavigationPI, PageEditModifyHdl));
+ m_xEdit->connect_changed(LINK(this, SwNavigationPI, PageModifiedHdl));
m_xEdit->set_help_id("modules/swriter/ui/navigatorpanel/numericfield");
if (!IsGlobalDoc())