include/vcl/formatter.hxx       |    3 ++-
 vcl/source/control/fmtfield.cxx |    7 ++++++-
 vcl/unx/gtk3/gtkinst.cxx        |   13 ++++++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit 6e49eeeb20c035132811dcb3197b3f3cb2ac64f0
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu May 11 16:03:57 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun May 14 15:05:02 2023 +0200

    tdf#155241 keep current MetricSpinButton value if unparseable junk input
    
    Change-Id: I0f13c9ae25c1788924fd81ed77307e96400f6220
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151617
    Tested-by: Jenkins
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/include/vcl/formatter.hxx b/include/vcl/formatter.hxx
index 2049d1e12a6f..4aa81ea1be30 100644
--- a/include/vcl/formatter.hxx
+++ b/include/vcl/formatter.hxx
@@ -117,6 +117,7 @@ protected:
     bool                m_bAutoColor : 1;
     bool                m_bEnableNaN : 1;
     bool                m_bDisableRemainderFactor : 1;
+    bool                m_bDefaultValueSet : 1;
     enum valueState { valueDirty, valueString, valueDouble };
     valueState          m_ValueState;
     double              m_dCurrentValue;
@@ -181,7 +182,7 @@ public:
     void    EnableEmptyField(bool bEnable);
     // If disabled, the value will be reset to the last valid value on leave
 
-    void    SetDefaultValue(double dDefault)    { m_dDefaultValue = dDefault; 
m_ValueState = valueDirty; }
+    void    SetDefaultValue(double dDefault)    { m_dDefaultValue = dDefault; 
m_ValueState = valueDirty; m_bDefaultValueSet = true; }
     // If the current String is invalid, GetValue() returns this value
     double  GetDefaultValue() const             { return m_dDefaultValue; }
 
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index d48f4c7560b0..d8e8231e7bfa 100644
--- a/vcl/source/control/fmtfield.cxx
+++ b/vcl/source/control/fmtfield.cxx
@@ -266,6 +266,7 @@ Formatter::Formatter()
     ,m_bAutoColor(false)
     ,m_bEnableNaN(false)
     ,m_bDisableRemainderFactor(false)
+    ,m_bDefaultValueSet(false)
     ,m_ValueState(valueDirty)
     ,m_dCurrentValue(0)
     ,m_dDefaultValue(0)
@@ -791,7 +792,11 @@ bool Formatter::ImplGetValue(double& dNewVal)
     if (m_ValueState == valueDouble)
         return true;
 
-    dNewVal = m_dDefaultValue;
+    // tdf#155241 default to m_dDefaultValue only if explicitly set
+    // otherwise default to m_dCurrentValue
+    if (m_bDefaultValueSet)
+        dNewVal = m_dDefaultValue;
+
     OUString sText(GetEntryText());
     if (sText.isEmpty())
         return true;
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 172ac4ce13f7..2d4a2c7cf70f 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -17447,6 +17447,11 @@ public:
         m_aCustomFont.use_custom_font(&rFont, u"spinbutton");
     }
 
+    void set_update_policy_if_valid()
+    {
+        gtk_spin_button_set_update_policy(m_pButton, GTK_UPDATE_IF_VALID);
+    }
+
     virtual void disable_notify_events() override
     {
         g_signal_handler_block(m_pButton, m_nValueChangedSignalId);
@@ -24293,7 +24298,13 @@ public:
 
     virtual std::unique_ptr<weld::MetricSpinButton> 
weld_metric_spin_button(const OString& id, FieldUnit eUnit) override
     {
-        return std::make_unique<weld::MetricSpinButton>(weld_spin_button(id), 
eUnit);
+        std::unique_ptr<weld::SpinButton> xButton(weld_spin_button(id));
+        if (xButton)
+        {
+            GtkInstanceSpinButton& rButton = 
dynamic_cast<GtkInstanceSpinButton&>(*xButton);
+            rButton.set_update_policy_if_valid();
+        }
+        return std::make_unique<weld::MetricSpinButton>(std::move(xButton), 
eUnit);
     }
 
     virtual std::unique_ptr<weld::FormattedSpinButton> 
weld_formatted_spin_button(const OString &id) override

Reply via email to