cui/source/dialogs/hyphen.cxx     |    2 +-
 cui/source/inc/hyphen.hxx         |    2 +-
 formula/source/ui/dlg/formula.cxx |    4 ++--
 include/vcl/weld/Entry.hxx        |    7 -------
 include/vcl/weld/TextView.hxx     |   12 ------------
 include/vcl/weld/TextWidget.hxx   |    9 +++++++++
 include/vcl/weld/weldutils.hxx    |    2 +-
 vcl/inc/salvtables.hxx            |    4 ++--
 vcl/source/app/salvtables.cxx     |    4 ++--
 vcl/source/control/field2.cxx     |    2 +-
 vcl/source/weld/Entry.cxx         |    7 -------
 vcl/source/weld/TextWidget.cxx    |    7 +++++++
 12 files changed, 26 insertions(+), 36 deletions(-)

New commits:
commit 18112de4f47624458008f6be7f2bff61046795ba
Author:     Michael Weghorn <[email protected]>
AuthorDate: Sat Jan 17 09:07:25 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Jan 17 13:34:19 2026 +0100

    weld: Move cursor position change signalling to TextWidget base
    
    Both, weld::Entry and weld::TextView implement the same
    logic to notify about changes to the cursor position.
    
    Deduplicate that by moving it to the common
    weld::TextWidget base class.
    
    Change-Id: I93cc335f5c3707ce627d5e10f0b09d1223ceeb35
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197488
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/cui/source/dialogs/hyphen.cxx b/cui/source/dialogs/hyphen.cxx
index afaf415468e8..5dbac2bb97cc 100644
--- a/cui/source/dialogs/hyphen.cxx
+++ b/cui/source/dialogs/hyphen.cxx
@@ -35,7 +35,7 @@
 
 using namespace css;
 
-IMPL_LINK_NOARG(SvxHyphenWordDialog, CursorChangeHdl_Impl, weld::Entry&, void)
+IMPL_LINK_NOARG(SvxHyphenWordDialog, CursorChangeHdl_Impl, weld::TextWidget&, 
void)
 {
     int nStart, nEnd;
     m_xWordEdit->get_selection_bounds(nStart, nEnd);
diff --git a/cui/source/inc/hyphen.hxx b/cui/source/inc/hyphen.hxx
index 386ed0b221c8..c8c20c3088ec 100644
--- a/cui/source/inc/hyphen.hxx
+++ b/cui/source/inc/hyphen.hxx
@@ -69,7 +69,7 @@ class SvxHyphenWordDialog : public SfxDialogController
     DECL_LINK(HyphenateAllHdl_Impl, weld::Button&, void);
     DECL_LINK(CancelHdl_Impl, weld::Button&, void);
     DECL_LINK(GetFocusHdl_Impl, weld::Widget&, void);
-    DECL_LINK(CursorChangeHdl_Impl, weld::Entry&, void);
+    DECL_LINK(CursorChangeHdl_Impl, weld::TextWidget&, void);
 
 public:
     SvxHyphenWordDialog(OUString aWord, LanguageType nLang,
diff --git a/formula/source/ui/dlg/formula.cxx 
b/formula/source/ui/dlg/formula.cxx
index d937656d2e0d..3c54a0c96381 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -118,7 +118,7 @@ public:
 
     DECL_LINK( MatrixHdl, weld::Toggleable&, void );
     DECL_LINK( FormulaHdl, weld::TextView&, void);
-    DECL_LINK( FormulaCursorHdl, weld::TextView&, void );
+    DECL_LINK( FormulaCursorHdl, weld::TextWidget&, void);
     DECL_LINK( BtnHdl, weld::Button&, void );
     DECL_LINK( FavToggleHdl, weld::Button&, void );
     DECL_LINK( DblClkHdl, FuncPage&, void );
@@ -1467,7 +1467,7 @@ void FormulaDlg_Impl::UpdateOldSel()
         std::swap(m_nSelectionStart, m_nSelectionEnd);
 }
 
-IMPL_LINK_NOARG( FormulaDlg_Impl, FormulaCursorHdl, weld::TextView&, void)
+IMPL_LINK_NOARG(FormulaDlg_Impl, FormulaCursorHdl, weld::TextWidget&, void)
 {
     int nStartPos, nEndPos;
     m_xMEdit->get_selection_bounds(nStartPos, nEndPos);
diff --git a/include/vcl/weld/Entry.hxx b/include/vcl/weld/Entry.hxx
index b11d3d612701..8fe36b7673b6 100644
--- a/include/vcl/weld/Entry.hxx
+++ b/include/vcl/weld/Entry.hxx
@@ -19,7 +19,6 @@ class VCL_DLLPUBLIC Entry : virtual public TextWidget
 protected:
     Link<Entry&, void> m_aChangeHdl;
     Link<OUString&, bool> m_aInsertTextHdl;
-    Link<Entry&, void> m_aCursorPositionHdl;
     Link<Entry&, bool> m_aActivateHdl;
 
     friend class ::LOKTrigger;
@@ -28,8 +27,6 @@ protected:
 
     void signal_activated();
 
-    void signal_cursor_position();
-
     virtual void do_set_position(int nCursorPos) = 0;
 
 public:
@@ -53,10 +50,6 @@ public:
     void connect_insert_text(const Link<OUString&, bool>& rLink) { 
m_aInsertTextHdl = rLink; }
     // callback returns true to indicated no further processing of activate 
wanted
     void connect_activate(const Link<Entry&, bool>& rLink) { m_aActivateHdl = 
rLink; }
-    virtual void connect_cursor_position(const Link<Entry&, void>& rLink)
-    {
-        m_aCursorPositionHdl = rLink;
-    }
 
     virtual void set_alignment(TxtAlign eXAlign) = 0;
 };
diff --git a/include/vcl/weld/TextView.hxx b/include/vcl/weld/TextView.hxx
index 319b929dfeff..5a952b8ea797 100644
--- a/include/vcl/weld/TextView.hxx
+++ b/include/vcl/weld/TextView.hxx
@@ -21,17 +21,9 @@ class VCL_DLLPUBLIC TextView : virtual public TextWidget
 protected:
     Link<TextView&, void> m_aChangeHdl;
     Link<TextView&, void> m_aVValueChangeHdl;
-    Link<TextView&, void> m_aCursorPositionHdl;
 
     void signal_changed() { m_aChangeHdl.Call(*this); }
 
-    void signal_cursor_position()
-    {
-        if (notify_events_disabled())
-            return;
-        m_aCursorPositionHdl.Call(*this);
-    }
-
     void signal_vadjustment_value_changed() { m_aVValueChangeHdl.Call(*this); }
 
 public:
@@ -41,10 +33,6 @@ public:
     int get_height_rows(int nRows) const;
 
     void connect_changed(const Link<TextView&, void>& rLink) { m_aChangeHdl = 
rLink; }
-    virtual void connect_cursor_position(const Link<TextView&, void>& rLink)
-    {
-        m_aCursorPositionHdl = rLink;
-    }
 
     // returns true if pressing up would move the cursor
     // doesn't matter if that move is to a previous line or to the start of the
diff --git a/include/vcl/weld/TextWidget.hxx b/include/vcl/weld/TextWidget.hxx
index b51d33b41172..3449e5850db1 100644
--- a/include/vcl/weld/TextWidget.hxx
+++ b/include/vcl/weld/TextWidget.hxx
@@ -21,6 +21,10 @@ private:
     OUString m_sSavedValue;
 
 protected:
+    Link<TextWidget&, void> m_aCursorPositionHdl;
+
+    void signal_cursor_position();
+
     virtual void do_set_text(const OUString& rText) = 0;
     virtual void do_select_region(int nStartPos, int nEndPos) = 0;
     virtual void do_replace_selection(const OUString& rText) = 0;
@@ -60,6 +64,11 @@ public:
     void save_value() { m_sSavedValue = get_text(); }
     OUString const& get_saved_value() const { return m_sSavedValue; }
     bool get_value_changed_from_saved() const { return m_sSavedValue != 
get_text(); }
+
+    virtual void connect_cursor_position(const Link<TextWidget&, void>& rLink)
+    {
+        m_aCursorPositionHdl = rLink;
+    }
 };
 }
 
diff --git a/include/vcl/weld/weldutils.hxx b/include/vcl/weld/weldutils.hxx
index f682e0f399da..6a3acf73e734 100644
--- a/include/vcl/weld/weldutils.hxx
+++ b/include/vcl/weld/weldutils.hxx
@@ -318,7 +318,7 @@ public:
 private:
     DECL_DLLPRIVATE_LINK(FormatOutputHdl, double, std::optional<OUString>);
     DECL_DLLPRIVATE_LINK(ParseInputHdl, const OUString&, 
Formatter::ParseResult);
-    DECL_DLLPRIVATE_LINK(CursorChangedHdl, weld::Entry&, void);
+    DECL_DLLPRIVATE_LINK(CursorChangedHdl, weld::TextWidget&, void);
 
     SAL_DLLPRIVATE void Init();
 
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index be5c78a3f31a..d90c9416b057 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -655,7 +655,7 @@ public:
 
     virtual void set_font_color(const Color& rColor) override;
 
-    virtual void connect_cursor_position(const Link<Entry&, void>& rLink) 
override;
+    virtual void connect_cursor_position(const Link<TextWidget&, void>& rLink) 
override;
 
     virtual void set_placeholder_text(const OUString& rText) override;
 
@@ -1447,7 +1447,7 @@ public:
 
     virtual void set_font_color(const Color& rColor) override;
 
-    virtual void connect_cursor_position(const Link<TextView&, void>& rLink) 
override;
+    virtual void connect_cursor_position(const Link<TextWidget&, void>& rLink) 
override;
 
     virtual bool can_move_cursor_with_up() const override;
 
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index d9f997d5f858..841425ef52ed 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -3393,7 +3393,7 @@ void SalInstanceEntry::set_font_color(const Color& rColor)
         m_xEntry->SetControlForeground(rColor);
 }
 
-void SalInstanceEntry::connect_cursor_position(const Link<Entry&, void>& rLink)
+void SalInstanceEntry::connect_cursor_position(const Link<TextWidget&, void>& 
rLink)
 {
     assert(!m_aCursorPositionHdl.IsSet());
     m_xEntry->AddEventListener(LINK(this, SalInstanceEntry, CursorListener));
@@ -5667,7 +5667,7 @@ void SalInstanceTextView::set_font(const vcl::Font& rFont)
     m_xTextView->Invalidate();
 }
 
-void SalInstanceTextView::connect_cursor_position(const Link<TextView&, void>& 
rLink)
+void SalInstanceTextView::connect_cursor_position(const Link<TextWidget&, 
void>& rLink)
 {
     assert(!m_aCursorPositionHdl.IsSet());
     m_xTextView->AddEventListener(LINK(this, SalInstanceTextView, 
CursorListener));
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index 73c607e31ac1..7d8feedd4826 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -3163,7 +3163,7 @@ namespace weld
         return Formatter::ParseResult(bRet ? TRISTATE_TRUE : TRISTATE_FALSE, 
fValue);
     }
 
-    IMPL_LINK(TimeFormatter, CursorChangedHdl, weld::Entry&, rEntry, void)
+    IMPL_LINK(TimeFormatter, CursorChangedHdl, weld::TextWidget&, rEntry, void)
     {
         int nStartPos, nEndPos;
         rEntry.get_selection_bounds(nStartPos, nEndPos);
diff --git a/vcl/source/weld/Entry.cxx b/vcl/source/weld/Entry.cxx
index 7fdfbdf1ac5c..3af623586223 100644
--- a/vcl/source/weld/Entry.cxx
+++ b/vcl/source/weld/Entry.cxx
@@ -25,13 +25,6 @@ void Entry::signal_activated()
     m_aActivateHdl.Call(*this);
 }
 
-void Entry::signal_cursor_position()
-{
-    if (notify_events_disabled())
-        return;
-    m_aCursorPositionHdl.Call(*this);
-}
-
 void Entry::set_position(int nCursorPos)
 {
     disable_notify_events();
diff --git a/vcl/source/weld/TextWidget.cxx b/vcl/source/weld/TextWidget.cxx
index 0546fd66cd3d..7c61bd4726f3 100644
--- a/vcl/source/weld/TextWidget.cxx
+++ b/vcl/source/weld/TextWidget.cxx
@@ -14,6 +14,13 @@
 
 namespace weld
 {
+void TextWidget::signal_cursor_position()
+{
+    if (notify_events_disabled())
+        return;
+    m_aCursorPositionHdl.Call(*this);
+}
+
 void TextWidget::set_text(const OUString& rText)
 {
     disable_notify_events();

Reply via email to