Greg Ercolano wrote:
> But if you want to get mouse click events in an Fl_Browser, you can
> flesh out the above:
This will work too; using return(1) in place of "ret = 1; break;"
makes the handle() code a bit shorter:
int handle(int e) {
int ret = Fl_Browser::handle(e);
switch (e) {
case FL_FOCUS:
case FL_UNFOCUS:
return(1); // express interest in keyboard
events
case FL_KEYBOARD:
cout << "keyboard" << endl;
return(1);
case FL_PUSH: // mouse click push
cout << "push" << endl;
return(1);
case FL_RELEASE: // mouse click release
cout << "release" << endl;
return(1);
}
return(ret);
}
The return value is very important, as it tells FLTK's event dispatcher
whether you're interested in related events or not, and if you 'handled'
the event.
For instance, in the above, we're saying we're interested in handling
"all" keyboard events.
This might be bad if we have an event handler in the parent window looking
for e.g. ^C/^V events. With the above, if our browser widget has focus,
ALL keyboard events will be 'eaten' by it, because we're always returning
1 for all keyboard events. So FLTK won't bother trying to deliver the
keyboard event to other widgets.
But if we only returned 1 for the events we wanted (say the shift key),
and for all others, we returned 'ret' (important: NOT 0), then the parent
window (or other widgets) could still get the other keyboard events.
It's important to do this right. Note there's attention to returning 'ret'
for events we don't handle, so that the 0|1 values Fl_Browser returns
still pass through our event handler correctly. (Fl_Browser will want to
handle certain keyboard events for itself, like up/down arrows, enter, space,
etc)
When writing a handle() function, always be wary of passing the values to the
base class you're deriving from, and the preserving its return value, and
carefully returning '1' for values your own code handles, if you don't want
those events getting to other widgets too when your widget is in focus.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk