include/vcl/weld.hxx                             |   26 +++++++++++++++--------
 sc/source/ui/inc/navipi.hxx                      |    2 -
 sc/source/ui/navipi/navipi.cxx                   |    6 +----
 sd/source/ui/dlg/diactrl.cxx                     |    4 +--
 sd/source/ui/inc/diactrl.hxx                     |    2 -
 svtools/source/dialogs/ServerDetailsControls.cxx |    4 +--
 svtools/source/dialogs/ServerDetailsControls.hxx |    2 -
 vcl/source/app/salvtables.cxx                    |   10 +++++++-
 vcl/source/window/builder.cxx                    |    9 +++----
 vcl/unx/gtk3/gtkinst.cxx                         |    6 +++--
 10 files changed, 43 insertions(+), 28 deletions(-)

New commits:
commit bd06ce16f41331acca71c5132c7847fb856e2307
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 01:19:56 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:11:22 2025 +0100

    tdf#130857 weld: Let SpinButton::signal_output return text
    
    If a custom output handler was set via
    weld::SpinButton::connect_output, return the formatted string
    it generates for the current value in SpinButton::signal_output
    instead of directly setting it as the SpinButton's text using
    SpinButton::set_text.
    
    Let the subclasses which call the method take care of setting
    the text instead.
    
    If no handler is set, return an empty std::optional.
    
    This approach is similar to how SpinButton::signal_input
    returns the new value (via an out param).
    
    But the main reason is that simply calling
    weld::SpinButton::set_text to set the new text isn't sufficient
    for the Qt implementation in QtInstanceSpinButton, but
    QDoubleSpinBox::textFromValue  can be overriden for that
    purpose - and this commit prepares for an implementation
    that will do that in an upcoming commit.
    
    Change-Id: I4962497122b79c320f3c60e5565cd64973af6df3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181685
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 7dacc9a639f1..964baac7c730 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1862,13 +1862,16 @@ class VCL_DLLPUBLIC SpinButton : virtual public Entry
 protected:
     void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
 
-    bool signal_output()
+    /** If a custom output handler (which provides a formatted string for a 
value)
+     *  is set, the formatted string is set in the returned std::optional.
+     *  Otherwise, an empty std::optional is returned.
+     */
+    std::optional<OUString> signal_output()
     {
         if (!m_aOutputHdl.IsSet())
-            return false;
+            return {};
         const OUString sText = m_aOutputHdl.Call(get_value());
-        set_text(sText);
-        return true;
+        return sText;
     }
 
     TriState signal_input(int* result)
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 2218e2d37a7f..b4d6a0ec18c3 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5941,7 +5941,15 @@ IMPL_LINK_NOARG(SalInstanceSpinButton, UpDownHdl, 
SpinField&, void) { signal_val
 
 IMPL_LINK_NOARG(SalInstanceSpinButton, LoseFocusHdl, Control&, void) { 
signal_value_changed(); }
 
-IMPL_LINK_NOARG(SalInstanceSpinButton, OutputHdl, LinkParamNone*, bool) { 
return signal_output(); }
+IMPL_LINK_NOARG(SalInstanceSpinButton, OutputHdl, LinkParamNone*, bool)
+{
+    std::optional<OUString> aText = signal_output();
+    if (!aText.has_value())
+        return false;
+
+    set_text(aText.value());
+    return true;
+}
 
 IMPL_LINK(SalInstanceSpinButton, InputHdl, sal_Int64*, pResult, TriState)
 {
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 1a492dbe0226..417da140f4f5 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -17657,9 +17657,11 @@ private:
         if (m_bBlockOutput)
             return true;
         m_bFormatting = true;
-        bool bRet = signal_output();
+        std::optional<OUString> aText = signal_output();
+        if (aText.has_value())
+            set_text(aText.value());
         m_bFormatting = false;
-        return bRet;
+        return aText.has_value();
     }
 
     static gboolean signalOutput(GtkSpinButton*, gpointer widget)
commit 9298d909e6ed081516bda9513ba1f52e44e39be9
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 14 20:38:28 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:11:15 2025 +0100

    tdf#130857 weld: Let SpinButton output hdl only format the string
    
    Adjust the logic so that the weld::SpinButton::m_aOutputHdl
    set via weld::SpinButton::connect_output is now only
    responsible for returning a string format for a given spinbox
    value, i.e. it now has a sal_Int64 input parameter and
    a OUString return value.
    
    This means that the implementations for those handlers
    generally no longer need interact with the underlying
    weld::SpinButton directly, i.e. no longer need to call
    SpinButton::get_value and SpinButton::set_text to get the
    value and manually set the formatted string as the new
    text.
    
    That logic is for now moved to
    weld::SpinButton::signal_output which gets called by the
    weld::SpinButton implementations and calls the handlers
    (i.e. one level further up in the call stack) and other
    places directly calling the handlers.
    
    The main motivation is that in order to implement
    setting the formatted text based on a value for QSpinBox/QDoubleSpinBox
    can be done by overriding QDoubleSpinBox::textFromValue
    that takes a value and returns a string. Changing
    weld::SpinButton::m_aOutputHdl to a similar logic
    is one step in preparation of implementing the logic
    for QtInstanceSpinButton.
    
    No change in behavior intended.
    
    MetricSpinButton::spin_button_output was previously
    explicitly checking whether the new and old text
    were the same, and only calling weld::SpinButton::set_text
    if they were not. If not doing that any more there should
    result in any change in behavior, it might make sense
    to reimplement that logic in the weld::SpinButton::set_value
    implementations of the concrete weld::SpinButton subclasses
    instead.
    
    Change-Id: I53df480e5b3b2e4eeb9f9fb0c24e8e735fae063b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181684
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index b1310db5b33d..7dacc9a639f1 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1856,7 +1856,7 @@ class VCL_DLLPUBLIC SpinButton : virtual public Entry
     friend class ::LOKTrigger;
 
     Link<SpinButton&, void> m_aValueChangedHdl;
-    Link<SpinButton&, void> m_aOutputHdl;
+    Link<sal_Int64, OUString> m_aOutputHdl;
     Link<int*, bool> m_aInputHdl;
 
 protected:
@@ -1866,7 +1866,8 @@ protected:
     {
         if (!m_aOutputHdl.IsSet())
             return false;
-        m_aOutputHdl.Call(*this);
+        const OUString sText = m_aOutputHdl.Call(get_value());
+        set_text(sText);
         return true;
     }
 
@@ -1913,7 +1914,7 @@ public:
 
     void connect_value_changed(const Link<SpinButton&, void>& rLink) { 
m_aValueChangedHdl = rLink; }
 
-    void connect_output(const Link<SpinButton&, void>& rLink) { m_aOutputHdl = 
rLink; }
+    void connect_output(const Link<sal_Int64, OUString>& rLink) { m_aOutputHdl 
= rLink; }
     void connect_input(const Link<int*, bool>& rLink) { m_aInputHdl = rLink; }
 
     sal_Int64 normalize(sal_Int64 nValue) const { return (nValue * 
Power10(get_digits())); }
@@ -2083,7 +2084,7 @@ class VCL_DLLPUBLIC MetricSpinButton final
     Link<MetricSpinButton&, void> m_aValueChangedHdl;
 
     DECL_LINK(spin_button_value_changed, weld::SpinButton&, void);
-    DECL_LINK(spin_button_output, weld::SpinButton&, void);
+    DECL_LINK(spin_button_output, sal_Int64, OUString);
     DECL_LINK(spin_button_input, int* result, bool);
 
     void signal_value_changed() { m_aValueChangedHdl.Call(*this); }
@@ -2102,7 +2103,7 @@ public:
         m_xSpinButton->connect_input(LINK(this, MetricSpinButton, 
spin_button_input));
         m_xSpinButton->connect_value_changed(
             LINK(this, MetricSpinButton, spin_button_value_changed));
-        spin_button_output(*m_xSpinButton);
+        
m_xSpinButton->set_text(spin_button_output(m_xSpinButton->get_value()));
     }
 
     static OUString MetricToString(FieldUnit rUnit);
@@ -2134,7 +2135,11 @@ public:
     // typically you only need to call this if set_text (e.g. with "") was
     // previously called to display some arbitrary text instead of the
     // formatted value and now you want to show it as formatted again
-    void reformat() { spin_button_output(*m_xSpinButton); }
+    void reformat()
+    {
+        const OUString sText = spin_button_output(m_xSpinButton->get_value());
+        m_xSpinButton->set_text(sText);
+    }
 
     void set_range(sal_Int64 min, sal_Int64 max, FieldUnit eValueUnit)
     {
diff --git a/sc/source/ui/inc/navipi.hxx b/sc/source/ui/inc/navipi.hxx
index e251a3b47e1d..c377ce9ead4d 100644
--- a/sc/source/ui/inc/navipi.hxx
+++ b/sc/source/ui/inc/navipi.hxx
@@ -131,7 +131,7 @@ private:
     DECL_LINK(ToolBoxSelectHdl, const OUString&, void);
     DECL_LINK(ToolBoxDropdownClickHdl, const OUString&, void);
     DECL_LINK(MenuSelectHdl, const OUString&, void);
-    DECL_LINK(FormatRowOutputHdl, weld::SpinButton&, void);
+    DECL_STATIC_LINK(ScNavigatorDlg, FormatRowOutputHdl, sal_Int64, OUString);
     DECL_LINK(ParseRowInputHdl, int*, bool);
 
     void    UpdateButtons();
diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx
index 16e6ad159a65..0863bb7413ae 100644
--- a/sc/source/ui/navipi/navipi.cxx
+++ b/sc/source/ui/navipi/navipi.cxx
@@ -160,10 +160,9 @@ IMPL_LINK_NOARG(ScNavigatorDlg, ExecuteColHdl, 
weld::Entry&, bool)
     return true;
 }
 
-IMPL_LINK_NOARG(ScNavigatorDlg, FormatRowOutputHdl, weld::SpinButton&, void)
+IMPL_STATIC_LINK(ScNavigatorDlg, FormatRowOutputHdl, sal_Int64, nValue, 
OUString)
 {
-    OUString aStr = ::ScColToAlpha(m_xEdCol->get_value() - 1);
-    m_xEdCol->set_text(aStr);
+    return ::ScColToAlpha(nValue - 1);
 }
 
 IMPL_LINK_NOARG(ScNavigatorDlg, ExecuteRowHdl, weld::Entry&, bool)
diff --git a/sd/source/ui/dlg/diactrl.cxx b/sd/source/ui/dlg/diactrl.cxx
index 5e1351657eb1..c2cdcb2ecbd9 100644
--- a/sd/source/ui/dlg/diactrl.cxx
+++ b/sd/source/ui/dlg/diactrl.cxx
@@ -109,9 +109,9 @@ void SdPagesField::UpdatePagesField( const SfxUInt16Item* 
pItem )
         m_xWidget->set_text(OUString());
 }
 
-IMPL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton&, rSpinButton, void)
+IMPL_STATIC_LINK(SdPagesField, OutputHdl, sal_Int64, nValue, OUString)
 {
-    rSpinButton.set_text(format_number(rSpinButton.get_value()));
+    return format_number(nValue);
 }
 
 IMPL_LINK(SdPagesField, spin_button_input, int*, result, bool)
diff --git a/sd/source/ui/inc/diactrl.hxx b/sd/source/ui/inc/diactrl.hxx
index 375e5401c999..caf2a0a533bb 100644
--- a/sd/source/ui/inc/diactrl.hxx
+++ b/sd/source/ui/inc/diactrl.hxx
@@ -37,7 +37,7 @@ private:
     css::uno::Reference<css::frame::XFrame> m_xFrame;
 
     DECL_LINK(ModifyHdl, weld::SpinButton&, void);
-    DECL_STATIC_LINK(SdPagesField, OutputHdl, weld::SpinButton&, void);
+    DECL_STATIC_LINK(SdPagesField, OutputHdl, sal_Int64, OUString);
     DECL_LINK(spin_button_input, int* result, bool);
     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
 
diff --git a/svtools/source/dialogs/ServerDetailsControls.cxx 
b/svtools/source/dialogs/ServerDetailsControls.cxx
index d4651945cbb0..a90d308a89e0 100644
--- a/svtools/source/dialogs/ServerDetailsControls.cxx
+++ b/svtools/source/dialogs/ServerDetailsControls.cxx
@@ -39,9 +39,9 @@ DetailsContainer::DetailsContainer(PlaceEditDialog* pDialog)
 }
 
 //format without thousand separator
-IMPL_STATIC_LINK(DetailsContainer, FormatPortHdl, weld::SpinButton&, 
rSpinButton, void)
+IMPL_STATIC_LINK(DetailsContainer, FormatPortHdl, sal_Int64, nValue, OUString)
 {
-    rSpinButton.set_text(OUString::number(rSpinButton.get_value()));
+    return OUString::number(nValue);
 }
 
 DetailsContainer::~DetailsContainer( )
diff --git a/svtools/source/dialogs/ServerDetailsControls.hxx 
b/svtools/source/dialogs/ServerDetailsControls.hxx
index ddca70807d77..bbc8ba9f7cb2 100644
--- a/svtools/source/dialogs/ServerDetailsControls.hxx
+++ b/svtools/source/dialogs/ServerDetailsControls.hxx
@@ -60,7 +60,7 @@ class DetailsContainer
     protected:
         void notifyChange( );
         DECL_LINK(ValueChangeHdl, weld::Entry&, void);
-        DECL_STATIC_LINK(DetailsContainer, FormatPortHdl, weld::SpinButton&, 
void);
+        DECL_STATIC_LINK(DetailsContainer, FormatPortHdl, sal_Int64, OUString);
 };
 
 class HostDetailsContainer : public DetailsContainer
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 0ec2fcde074c..12d5c1c4e628 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -255,11 +255,9 @@ namespace weld
         signal_value_changed();
     }
 
-    IMPL_LINK(MetricSpinButton, spin_button_output, SpinButton&, rSpinButton, 
void)
+    IMPL_LINK(MetricSpinButton, spin_button_output, sal_Int64, nValue, 
OUString)
     {
-        OUString sNewText(format_number(rSpinButton.get_value()));
-        if (sNewText != rSpinButton.get_text())
-            rSpinButton.set_text(sNewText);
+        return format_number(nValue);
     }
 
     void MetricSpinButton::update_width_chars()
@@ -362,7 +360,8 @@ namespace weld
             m_eSrcUnit = eUnit;
             set_increments(step, page, m_eSrcUnit);
             set_value(value, m_eSrcUnit);
-            spin_button_output(*m_xSpinButton);
+            const OUString sText = 
spin_button_output(m_xSpinButton->get_value());
+            m_xSpinButton->set_text(sText);
             update_width_chars();
         }
     }
commit 80b2b9b6e1324ab109742a9d45631fbe5ee64489
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 14 23:18:31 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:11:08 2025 +0100

    sc: Simplify ScNavigatorDlg::FormatRowOutputHdl
    
    Call the ScColToAlpha version that returns a OUString
    instead of using an out param.
    
    Change-Id: Iac25682b7b2bd731c9b04ca1c7ba7d0efbdd1605
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181683
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx
index d75d7088e81c..16e6ad159a65 100644
--- a/sc/source/ui/navipi/navipi.cxx
+++ b/sc/source/ui/navipi/navipi.cxx
@@ -162,8 +162,7 @@ IMPL_LINK_NOARG(ScNavigatorDlg, ExecuteColHdl, 
weld::Entry&, bool)
 
 IMPL_LINK_NOARG(ScNavigatorDlg, FormatRowOutputHdl, weld::SpinButton&, void)
 {
-    OUString aStr;
-    ::ScColToAlpha(aStr, m_xEdCol->get_value() - 1);
+    OUString aStr = ::ScColToAlpha(m_xEdCol->get_value() - 1);
     m_xEdCol->set_text(aStr);
 }
 

Reply via email to