summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2022-06-17 17:12:51 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2022-06-17 17:16:59 +0200
commit232743c3a5d903be813f6c4445f3f96bab25cae0 (patch)
tree82feaa0a0fdcff87219dc84cd4a2e820b65696aa
parentf3bf231cc06ab82576b798a1f615981924a2903c (diff)
Fix Fl_Counter event handling (#450, part 2)
This fixes some issues of the repeat timeout of Fl_Counter. It could happen that the widget missed the FL_RELEASE event, for instance if a modal window like fl_message() was opened in the callback but there could be other reasons as well. See issue #450 for more info.
-rw-r--r--src/Fl_Counter.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Fl_Counter.cxx b/src/Fl_Counter.cxx
index 992f0c2e9..ed856c208 100644
--- a/src/Fl_Counter.cxx
+++ b/src/Fl_Counter.cxx
@@ -1,7 +1,7 @@
//
// Counter widget for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -93,7 +93,9 @@ void Fl_Counter::increment_cb() {
void Fl_Counter::repeat_callback(void* v) {
Fl_Counter* b = (Fl_Counter*)v;
- if (b->mouseobj) {
+ int buttons = Fl::event_state() & FL_BUTTONS; // any mouse button pressed
+ int focus = (Fl::focus() == b); // the widget has focus
+ if (b->mouseobj && buttons && focus) {
Fl::add_timeout(REPEAT, repeat_callback, b);
b->increment_cb();
}
@@ -136,7 +138,8 @@ int Fl_Counter::handle(int event) {
if (i != mouseobj) {
Fl::remove_timeout(repeat_callback, this);
mouseobj = (uchar)i;
- if (i) Fl::add_timeout(INITIALREPEAT, repeat_callback, this);
+ if (i > 0)
+ Fl::add_timeout(INITIALREPEAT, repeat_callback, this);
Fl_Widget_Tracker wp(this);
increment_cb();
if (wp.deleted()) return 1;
@@ -155,8 +158,10 @@ int Fl_Counter::handle(int event) {
return 0;
}
// break not required because of switch...
- case FL_FOCUS : /* FALLTHROUGH */
case FL_UNFOCUS :
+ mouseobj = 0;
+ /* FALLTHROUGH */
+ case FL_FOCUS :
if (Fl::visible_focus()) {
redraw();
return 1;