Pressing and holding using mouse on wxSpin Control with set range stops at wrong values (Issue #22537)

79 views
Skip to first unread message

guzmanpaco

unread,
Jun 15, 2022, 8:10:24 PM6/15/22
to wx-...@googlegroups.com, Subscribed

Describe the bug
If user presses and holds (using a mouse) on a spin control button with set range, it stops before the limit. For example range is (0,100). Pressing up button (using mouse) continuously from 0 will have it stop at 61 instead of at 100. Pressing up is ignored by later clicks. Starting from 100 and pressing down, results in similar behavior where it stops at 39 and pressing down again is ignored. It seems that wxEVT_SPIN* events are no longer generating when this case occurs.

This was replicated on wxSpin with style "wxSP_VERTICAL | wxSP_ARROW_KEYS". Issue is not encountered if wxSP_WRAP is set as style. This was replicated in Win 10 and Win 11 using wxWidgets 3.1.7 release zip. This issue does not occur on wxWidgets 3.1.0.

Expected vs observed behaviour
If I set range of wxSpin to (0, 100), pressing and holding at the buttons should stop at 0 and 100. Actual is 39(minimum) and 61 (maximum). Issue does not occur with normal single clicks.

Patch or snippet allowing to reproduce the problem
I attached modified minimal.cpp (Modified Minimal sample application) that can replicate the issue.
minimal.txt

To Reproduce
Steps to reproduce the behaviour, please make them

as detailed as possible, e.g.

  1. Build modified minimal sample project
  2. Perform long press and hold of up spin button until value stops incrementing
  3. Perform long press and hold of down spin button until value stops decrementing

Platform and version information

  • wxWidgets version you use: 3.1.7
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 10.19044


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537@github.com>

PB

unread,
Jun 19, 2022, 1:29:11 PM6/19/22
to wx-...@googlegroups.com, Subscribed

I could not reproduce with the master using the widgets sample on Windows 10 21H2 build 19044.1766.
spinctrl-hold

Works as expected going down as well.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537/1159780797@github.com>

PB

unread,
Jun 19, 2022, 1:40:18 PM6/19/22
to wx-...@googlegroups.com, Subscribed

Ooops, I only now realized that the issue is about wxSpinButton and not wxSpinCtrl, as the OP used the ambiguous "wxSpin".

Still, in the sample, the button seems to work as well, although there is a couple of odd messages logged when hitting 10:
spinbutton-hold


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537/1159782325@github.com>

VZ

unread,
Jun 19, 2022, 3:44:45 PM6/19/22
to wx-...@googlegroups.com, Subscribed

Thanks for testing! I guess this is due to doing something in the attached minimal.cpp, as it seems to do quite a few strange things.

@guzmanpaco Can you explain what are you doing there and why? Also, attaching diffs to the sample (minimal one in this case) is strongly preferred to attaching the whole files.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537/1159799265@github.com>

PB

unread,
Jun 20, 2022, 10:30:44 AM6/20/22
to wx-...@googlegroups.com, Subscribed

I also tried with a patch to the minimal sample

diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 470e765423..1a91974a95 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -26,6 +26,8 @@
     #include "wx/wx.h"
 #endif
 
+#include "wx/spinbutt.h"
+
 // ----------------------------------------------------------------------------
 // resources
 // ----------------------------------------------------------------------------
@@ -175,6 +177,20 @@ MyFrame::MyFrame(const wxString& title)
     CreateStatusBar(2);
     SetStatusText("Welcome to wxWidgets!");
 #endif // wxUSE_STATUSBAR
+
+    wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
+
+    wxSpinButton* spinBtn = new wxSpinButton(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_VERTICAL | wxSP_ARROW_KEYS);
+    spinBtn->SetValue(0);
+    spinBtn->SetRange(0, 100);
+    spinBtn->Bind(wxEVT_SPIN, [this](wxSpinEvent& e) { wxLogMessage("wxEVT_SPIN: position = %d", e.GetPosition()); });
+
+    wxTextCtrl* logCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
+    wxLog::SetActiveTarget(new wxLogTextCtrl(logCtrl));
+
+    mainSizer->Add(spinBtn, wxSizerFlags().Border());
+    mainSizer->Add(logCtrl, wxSizerFlags(1).Expand().Border());
+    SetSizer(mainSizer);
 }

and it still worked.
spinbutton-hold-minimal

I have also skimmed the not-actually-a-minimal example provided by @guzmanpaco. The code there for some reason changes the spin button value in its spin event handler. Does not seem correct to me. I would also generally advise against changing focus from inside event handlers like these (e.g., where mouse is very involved).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537/1160519251@github.com>

VZ

unread,
Jun 20, 2022, 1:47:32 PM6/20/22
to wx-...@googlegroups.com, Subscribed

Thanks a lot for taking time to test this. I agree that this is probably due to changing the values in the control and/or focus in OP's code, which is not recommended at all and not supported.

Please try to provide a really minimal patch if you can isolate the problem further, but I think you will just find that you're doing something wrong in your code (which, again, is not really obvious to understand).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/22537/1160705377@github.com>

VZ

unread,
Jun 20, 2022, 1:47:32 PM6/20/22
to wx-...@googlegroups.com, Subscribed

Closed #22537 as not planned.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/22537/issue_event/6841241026@github.com>

Reply all
Reply to author
Forward
0 new messages