From 5544404f7a89a3d7e781f5e57d1271076485c91c Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 10 Mar 2017 21:47:08 +0000 Subject: Enable Up/Down keys in Fl_Spinner if input has focus (STR #2989). Previously Up/Down keys worked only if one of the buttons was pressed before so that it had the focus. test/valuators.fl: The second Fl_Spinner widget (FL_FLOAT_INPUT) now has wrap mode disabled whereas the first one (FL_INT_INPUT) uses wrap mode (default, compatible with FLTK 1.3.x and older). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12191 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Spinner.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/Fl_Spinner.cxx b/src/Fl_Spinner.cxx index 220ac1698..3ef102a55 100644 --- a/src/Fl_Spinner.cxx +++ b/src/Fl_Spinner.cxx @@ -196,6 +196,24 @@ void Fl_Spinner::type(uchar v) { } +/** + Handles events of Fl_Spinner's embedded input widget. + + Works like Fl_Input::handle() but ignores FL_Up and FL_Down keys + so they can be handled by the parent widget (Fl_Spinner). +*/ +int Fl_Spinner::Fl_Spinner_Input::handle(int event) { + if (event == FL_KEYBOARD) { + const int key = Fl::event_key(); + if (key == FL_Up || key == FL_Down) { + Fl_Input::handle(FL_UNFOCUS); // sets and potentially clips the input value + return 0; + } + } + return Fl_Input::handle(event); +} + + // // End of "$Id$". // -- cgit v1.2.3