On 21.10.2011 17:45, David wrote:
Anyway - if you want to change a widget's features, you are free
to subclass the widget and use the handle() method to make it do
what you want. The core widgets are not intended to do *everything*
that all users expect, but to provide an extendible framework with
features for "standard" applications ready to go.
I can do that, can someone provide a simple example. I want to override a
Fl_Button to say Fl_Button_X, in the handler I want to say this:
if this widget has the keyboard focus and FL_Enter was pressed then do the
callback (because this button is considered clicked) (eat the Fl_Enter).
See the attached file enter_button.cxx for a complete
example program. The middle button can be clicked by using
its shortcut (E) or by pressing Space, Enter, or Keypad-Enter.
As a bonus, this also calls simulate_key_action() to give a
visual feedback (with FLTK 1.3 or later).
I'd also, if not too big a pain, like to override the raido button, and say, if
this widget has keyboard focus, select it (this way users don't have to know to
press space bar - they can just arrow to select it), then tab is pressed, I
want it to go to outside the group the radio button belongs to (instead of tab
moving to the next radio button and cause it to be selected).
If you want to do this (make Tab work as described: leave the
radio button group and go to the next widget), then the only
thing (I think) you need to do is to derive your own group widget
(e.g. MyRadioGroup) that *ignores* the Tab key. Then put all
radio buttons into this group.
Usually the enclosing group widget uses the Tab key to switch
focus to the next widget in the group. If MyRadioGroup ignores
the Tab key, then it will be propagated to the next higher group
widget, and this will switch focus to the next widget or group
(outside the radio button group). Ignoring a key press is easy:
check the key value as in the attachment, and return 0 if you
don't want to use it. I'll leave the rest as an exercise... ;-)
HTH
Albrecht
//
// Button/callback test program for the Fast Light Tool Kit (FLTK).
//
// This is a modified version of test/button.cxx .
//
// Copyright 1998-2011 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
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/fl_ask.H>
#include <FL/Enumerations.H>
#include <stdlib.h>
// derive a button class that uses the Enter key to trigger
// the button's callback
class MyEnterButton : public Fl_Button {
public:
MyEnterButton(int x, int y, int w, int h, const char *L=0)
: Fl_Button(x,y,w,h,L) {};
protected:
int handle(int e) {
switch(e) {
case FL_KEYBOARD:
if (Fl::event_key()==FL_Enter || Fl::event_key()==FL_KP_Enter) {
#if FL_MAJOR_VERSION >= 3 || (FL_MAJOR_VERSION == 1 && FL_MINOR_VERSION >= 3)
simulate_key_action(); // only in FLTK 1.3 and later
#endif
do_callback();
return 1;
}
break;
default:
break;
}
return Fl_Button::handle(e);
}
};
void beep_cb(Fl_Widget *, void *) {
fl_beep();
}
void exit_cb(Fl_Widget *, void *) {
exit(0);
}
int main(int argc, char ** argv) {
Fl_Window *window = new Fl_Window(320,65);
Fl_Button *b1 = new Fl_Button(20, 20, 80, 25, "&Beep");
b1->tooltip("Use Space to 'click' this button");
b1->callback(beep_cb);
MyEnterButton *b2 = new MyEnterButton(120,20, 80, 25, "&Enter");
b2->tooltip("Use Space OR Enter to 'click' this button");
b2->color(fl_lighter(FL_GREEN));
b2->callback(beep_cb);
Fl_Button *b3 = new Fl_Button(220,20, 80, 25, "E&xit");
b3->tooltip("Use Space to 'click' this button");
b3->callback(exit_cb,0);
window->end();
window->show(argc,argv);
return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk