Keyboard Focus

FUNCTIONS

  void  set_focus(Control *c);
  int   has_focus(Control *c);

  void  pass_event(Control *c);

NOTES

A control can have the keyboard focus, which means that in its parent window, if a user types a key on the keyboard, that key click will be sent to the control which has focus rather than to the window itself.

To set focus to a particular control, use set_focus. This will remove focus from whatever control previously had the focus, if any, and it will redraw all affected controls (since some controls appear differently if they have the focus).

Use has_focus to determine if the given control has the keyboard focus.

Focus has no effect on mouse events.

The pass_event function can be called within a call-back function to pass a keyboard event up the object hierarchy (to the enclosing parent control or window). This might be used if a control handles some events, but not others. For instance, a text field handles ordinary key strokes, but might not want to accept 'Enter' or 'Tab' key events; instead it might want to pass these events to the window's call-back functions.