Events in Fltk

Events are identified the small integer argument passed to the Fl_Widget::handle() virtual method. Other information about the most recent event is stored in static locations and aquired by calling Fl::event_*(). This static information remains valid until the next event is read from the X server (that is, it is ok to look at it outside the handle() method).

FL_PUSH (1)

FL_DRAG (5)

FL_RELEASE (2)

FL_ENTER (3)

FL_MOVE (10)

FL_LEAVE (4)

FL_FOCUS (6)

FL_UNFOCUS (7)

FL_KEYBOARD (8)

FL_SHORTCUT (11)

FL_DEACTIVATE (13)

FL_ACTIVATE (14)

FL_HIDE (15)

FL_SHOW (16)

FL_PASTE (17)

FL_SELECTIONCLEAR (18)

Fl::event_*() methods

Fltk keeps the information about the most recent event in static storage. This information is good until the next event is processed. Thus it is valid inside handle() and callback() methods.

These are all trivial inline functions and thus very fast and small. The data is stored in static locations and remains valid until the next X event is handled.

int Fl::event_button();

int Fl::event_x()
int Fl::event_y()

int Fl::event_x_root()
int Fl::event_y_root()

void Fl::get_mouse(int &,int &)

ulong Fl::event_state();
unsigned int Fl::event_state(int);

int Fl::event_key();
int Fl::event_key(int);
int Fl::get_key(int);

char * Fl::event_text()

char * Fl::event_length()

int Fl::event_is_click()

void Fl::event_is_click(0)

int Fl::event_clicks()

void Fl::event_clicks(int)

int Fl::event_inside(const Fl_Widget *) const ;
int Fl::event_inside(int,int,int,int);

int Fl::test_shortcut(ulong) const ;

Event Propagation

Fltk follows very simple and unchangeable rules for sending events. The major innovation is that widgets can indicate (by returning 0 from the handle() method) that they are not interested in an event, and fltk can then send that event elsewhere. This eliminates the need for "interests" (event masks or tables), and this is probably the main reason fltk is much smaller than other X toolkits.

Most events are sent directly to the handle() method of the Fl_Window that X says they belong to. The window (actually the Fl_Group that Fl_Window is a subclass of) is responsible for sending the events on to any child widgets. To make the Fl_Group code somewhat easier, fltk sends some events (FL_DRAG, FL_RELEASE, FL_KEYBOARD, FL_SHORTCUT, FL_UNFOCUS, FL_LEAVE) directly to leaf widgets. These procedures control those leaf widgets:

Fl_Widget *Fl::focus() const;
void Fl::focus(Fl_Widget *);

int Fl_Widget::take_focus();

Fl_Widget *Fl::belowmouse() const;
void Fl::belowmouse(Fl_Widget *);

Fl_Widget *Fl::pushed() const;
void Fl::pushed(Fl_Widget *);

void Fl::add_handler(int (*f)(int));

Fl_Window* Fl::modal();

void Fl::grab(Fl_Window&);
Fl_Window* Fl::grab();

void Fl::release()

(back to contents)