Opened 12 months ago

Last modified 12 months ago

#18735 portneeded defect (port to stable)

wxSpinCtrlDouble::SetIncrement() may not take effect immediately.

Reported by: AliKet Owned by:
Priority: normal Milestone:
Component: wxGTK Version: dev-latest
Keywords: GTK+2.0 Cc:
Blocked By: Blocking:
Patch: yes

Description

How to reproduce the issue:

  1. Apply this patch to the widgets sample:
diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp
index 2d371e8103..e72b966ed1 100644
--- a/samples/widgets/spinbtn.cpp
+++ b/samples/widgets/spinbtn.cpp
@@ -414,6 +414,8 @@ void SpinBtnWidgetsPage::CreateSpin()
                                          flags | textFlags,
                                          m_min, m_max, val, 0.1);
 
+    m_spinctrldbl->SetIncrement(0.5);
+
     // Add spacers, labels and spin controls to the sizer.
     m_sizerSpin->Add(0, 0, 1);
     m_sizerSpin->Add(new wxStaticText(this, wxID_ANY, "wxSpinButton"),
  1. Run the sample and activate the Spin page.
  1. Set the focus to the wxSpinCtrlDouble by clicking inside the entry.
  1. In the keyboard, press the UP key to change the control's value from 0.0 to the next step.

Bug: the control will use the old step (i.e. '0.1') instead of the new one ('0.5') thus, the control will contain '0.1' and not '0.5'.

  1. Repeat step 4. now the control will use the new step ('0.5') and the value will be ('0.6')

_

Not sure if this is correct or not, but this seems to solve the problem and the test herehttps://github.com/wxWidgets/wxWidgets/blob/master/tests/controls/spinctrldbltest.cpp#L195 will succeed:

diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp
index 150a6284ec..99ebe8c983 100644
--- a/src/gtk/spinctrl.cpp
+++ b/src/gtk/spinctrl.cpp
@@ -284,11 +284,21 @@ void wxSpinCtrlGTKBase::DoSetIncrement(double inc)
 
     wxSpinCtrlEventDisabler disable(this);
 
+#ifdef __WXGTK20__
+    GtkAdjustment* adj =
+        gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(m_widget));
+
+    wxASSERT_MSG(adj != NULL, "spin button with a missing adjustment"); // Unlikely
+
+    gtk_adjustment_set_step_increment(adj, inc);
+    gtk_spin_button_update(GTK_SPIN_BUTTON(m_widget));
+#else
     // Preserve the old page value when changing just the increment.
     double page = 10*inc;
     gtk_spin_button_get_increments( GTK_SPIN_BUTTON(m_widget), NULL, &page);
 
     gtk_spin_button_set_increments( GTK_SPIN_BUTTON(m_widget), inc, page);
+#endif
 }
 
 void wxSpinCtrlGTKBase::GtkDisableEvents()

Change History (3)

comment:1 Changed 12 months ago by vadz

  • Milestone set to 3.1.4
  • Patch set
  • Status changed from new to confirmed

Yes, I see why this happens in GTK source... They use timer_step as increment, but it's initialized when the adjustment created by gtk_spin_button_new_with_range() is set and not updated until either a button is pressed or a key is released (but not when it's pressed).

I wonder if there is some way to synthesize an artificial key-release event for the spin button, as this should be enough to update it. If not, I guess the workaround above is the least bad way to do it (we could also recreate adjustment ourselves, but this wouldn't be any better, would it?).

Paul, do you have any thoughts about this (other than that we shouldn't be using GTK 2 any longer)?

comment:2 Changed 12 months ago by Paul Cornett <paulcor@…>

In 9f9bb66d1/git-wxWidgets:

Fix for GTK2 wxSpinCtrl SetIncrement() not immediately updating increment

See #18735

comment:3 Changed 12 months ago by vadz

  • Milestone 3.1.4 deleted
  • Resolution set to port to stable
  • Status changed from confirmed to portneeded

Thanks for fixing this, but was there any reason for leaving it open?

I guess we could apply it to 3.0 too, but otherwise there doesn't seem to be anything remaining to do here.

Note: See TracTickets for help on using tickets.