An old STR #2199 brought up an issue where regular letter keys
can trigger buttons with label shortcuts, ie. a button declared as:
Fl_Button but(x,y,w,h, "&Button");
..could be triggered by someone just typing 'b' or Shift-'b'.
It's been discussed that this behavior can be seen in native windows
widgets, but not e.g. in Firefox, which seemed to enforce the need for
a modifier like 'Alt'.
Just curious: allowing regular letters to trigger a label shortcut
seems like a dangerous thing; consider a simple industrial interface
that has a 'Start' and 'Stop' button and an input field for a password
to use the machine.
It might be implemented as:
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
void MyCallback(Fl_Widget*w,void *userdata) { fprintf(stderr, "You pressed
'%s'\n", w->label()); }
int main() {
Fl_Window win(400,400);
Fl_Button start(140,10,180,25,"&Start"); start.callback(MyCallback);
Fl_Button allstop(140,40,180,25,"&All Stop"); allstop.callback(MyCallback);
Fl_Input password(140,70,180,25,"Password:");
win.end();
win.show();
return(Fl::run());
}
With this, if the user forgets to click in the password field,
and just types 'sally', the 's' triggers the machine to start,
and the 'a' triggers the machine to stop.
I'd posit this is unexpected and probably bad behavior.
I'd think a modifier like Alt (for win/linux)
or Cloverleaf- (for Mac) would at least be needed, similar
to how menubars work.
If the programmer really wanted unadorned letter shortcuts
to work, they could use shortcut() to define the exact sequence,
or derive a widget that handle()ed multiple keypresses if desired.
Or maybe we should have a compatibility flag that enables the
current behavior, but have it disabled by default.
Just fishing for some thoughts on this.
Currently the docs for Fl_Button (under 'Description') says this:
Buttons can also generate callbacks in response to FL_SHORTCUT events.
The button can either have an explicit shortcut() value
*or a letter shortcut can be indicated in the label() with an '&' character*
before it. For the label shortcut *it does not matter if Alt is held down,*
but *if you have an input field in the same window*, the user will have to
*hold down the Alt key* so that the input field does not eat the event first
as an FL_KEYBOARD event.
I don't think we currently hold to that last sentence, as it seems
if there's an input field in the same interface, still regular
letter buttons will trigger the shortcuts.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev