Event Types and Event Handling


Classes

struct  ShortcutAssignment

Enumerations

enum  {
  fltk::NO_EVENT, fltk::PUSH, fltk::RELEASE, fltk::ENTER,
  fltk::LEAVE, fltk::DRAG, fltk::FOCUS, fltk::UNFOCUS,
  fltk::KEY, fltk::KEYUP, fltk::FOCUS_CHANGE, fltk::MOVE,
  fltk::SHORTCUT, fltk::DEACTIVATE, fltk::ACTIVATE, fltk::HIDE,
  fltk::SHOW, fltk::PASTE, fltk::TIMEOUT, fltk::MOUSEWHEEL,
  fltk::DND_ENTER, fltk::DND_DRAG, fltk::DND_LEAVE, fltk::DND_RELEASE,
  fltk::TOOLTIP
}
enum  {
  fltk::LeftButton, fltk::MiddleButton, fltk::RightButton, fltk::SpaceKey,
  fltk::BackSpaceKey, fltk::TabKey, fltk::ClearKey, fltk::ReturnKey,
  fltk::PauseKey, fltk::ScrollLockKey, fltk::EscapeKey, fltk::HomeKey,
  fltk::LeftKey, fltk::UpKey, fltk::RightKey, fltk::DownKey,
  fltk::PageUpKey, fltk::PageDownKey, fltk::EndKey, fltk::PrintKey,
  fltk::InsertKey, fltk::MenuKey, fltk::HelpKey, fltk::NumLockKey,
  fltk::Keypad, fltk::KeypadEnter, fltk::MultiplyKey, fltk::AddKey,
  fltk::SubtractKey, fltk::DecimalKey, fltk::DivideKey, fltk::Keypad0,
  fltk::Keypad1, fltk::Keypad2, fltk::Keypad3, fltk::Keypad4,
  fltk::Keypad5, fltk::Keypad6, fltk::Keypad7, fltk::Keypad8,
  fltk::Keypad9, fltk::KeypadLast, fltk::F0Key, fltk::F1Key,
  fltk::F2Key, fltk::F3Key, fltk::F4Key, fltk::F5Key,
  fltk::F6Key, fltk::F7Key, fltk::F8Key, fltk::F9Key,
  fltk::F10Key, fltk::F11Key, fltk::F12Key, fltk::LastFunctionKey,
  fltk::LeftShiftKey, fltk::RightShiftKey, fltk::LeftCtrlKey, fltk::RightCtrlKey,
  fltk::CapsLockKey, fltk::LeftMetaKey, fltk::RightMetaKey, fltk::LeftAltKey,
  fltk::RightAltKey, fltk::DeleteKey
}
enum  {
  fltk::SHIFT, fltk::CAPSLOCK, fltk::CTRL, fltk::ALT,
  fltk::NUMLOCK, fltk::META, fltk::SCROLLLOCK, fltk::BUTTON1,
  fltk::BUTTON2, fltk::BUTTON3, fltk::ANY_BUTTON
}
enum  {
  fltk::DEVICE_MOUSE, fltk::DEVICE_STYLUS, fltk::DEVICE_ERASER, fltk::DEVICE_CURSOR,
  fltk::DEVICE_AIRBRUSH, fltk::DEVICE_TOUCH
}

Functions

void fltk::add_event_handler (int(*h)(int, Window *))
bool fltk::Widget::add_shortcut (unsigned key)
void fltk::Widget::add_timeout (float)
void belowmouse (Widget &w)
void fltk::belowmouse (Widget *)
Widget * fltk::belowmouse ()
unsigned BUTTON (int n)
bool fltk::compose (int &del)
void fltk::compose_reset ()
void copy (const char *stuff, int len, bool clipboard=false)
bool dnd ()
int fltk::event ()
unsigned fltk::event_button ()
void fltk::event_clicks (int i)
int fltk::event_clicks ()
int event_device ()
int fltk::event_dx ()
int fltk::event_dy ()
bool fltk::event_inside (const Rectangle &)
void fltk::event_is_click (bool)
bool fltk::event_is_click ()
unsigned fltk::event_key ()
bool fltk::event_key_state (unsigned)
unsigned fltk::event_length ()
float event_pressure ()
bool fltk::event_state (unsigned i)
unsigned fltk::event_state ()
const char * fltk::event_text ()
int fltk::event_x ()
int fltk::event_x_root ()
float event_x_tilt ()
int fltk::event_y ()
int fltk::event_y_root ()
float event_y_tilt ()
void fltk::exit_modal ()
bool fltk::exit_modal_flag ()
void focus (Widget &w)
void fltk::focus (Widget *)
Widget * fltk::focus ()
bool fltk::get_key_state (unsigned)
void get_mouse (int &, int &)
bool fltk::grab ()
virtual int fltk::Widget::handle (int)
bool fltk::handle (int, Window *)
unsigned fltk::key (const char *name)
const char * fltk::key_name (unsigned key)
unsigned fltk::Widget::label_shortcut () const
const ShortcutAssignmentfltk::list_matching_shortcuts (unsigned &count)
const ShortcutAssignmentfltk::list_shortcuts (unsigned &count)
const ShortcutAssignmentfltk::list_shortcuts (const Widget *, unsigned &count)
const ShortcutAssignmentfltk::list_shortcuts (unsigned key, unsigned &count)
Widget * fltk::modal ()
void fltk::modal (Widget *, bool grab=false)
void paste (Widget &receiver, bool clipboard=false)
void pushed (Widget &w)
void fltk::pushed (Widget *)
Widget * fltk::pushed ()
bool fltk::Widget::remove_shortcut (unsigned key)
bool fltk::Widget::remove_shortcuts ()
void fltk::Widget::remove_timeout ()
void fltk::Widget::repeat_timeout (float)
int fltk::Widget::send (int event)
bool fltk::Widget::shortcut (unsigned key)
unsigned fltk::Widget::shortcut () const
bool fltk::Widget::test_label_shortcut () const
bool fltk::Widget::test_shortcut (bool) const
bool fltk::Widget::test_shortcut () const
bool fltk::try_shortcut ()

Detailed Description

FLTK Events are identified by the integer argument passed to the fltk::Widget::handle() virtual method. Often a widget will modify this number before passing it to it's children.

Fltk only thinks about one event at a time. Therefore all of the other data about the event is stored in static memory, rather than a typical "event structure". It is accessed with fast inline functions of the form fltk::event_*.

FLTK has very simple rules for sending events to widgets. The major unusual aspect of FLTK is that widgets indicate if they "handled" an event by returning non-zero from their fltk::Widget::handle() method. If they return zero, FLTK can then try the event elsewhere. This eliminates the need for "interests" (event masks or tables), and this is the main reason FLTK is much smaller than other toolkits.

Most events are sent to the outermost fltk::Window containing the event, and those widgets are responsible for finding and sending the events to child widgets. Some events are sent directly to fltk::Widgets, this is controlled by the following methods, which the container widgets are required to call:

If all the widgets that FLTK tries to send an event to return zero, then you can add global functions that FLTK will call with these events. This is done with fltk::add_event_handler()

You can generate fake events by calling handle(int) on the correct widgets (usally a window). Currently you can change the values returned by the fltk::event_*() functions by storing the desired value into the static variables fltk::e_*, but this may change in future versions.


Enumeration Type Documentation

anonymous enum
 

Numbers passed to Widget::handle() and returned by event().

Enumeration values:
NO_EVENT  Has the value zero. All fltk widgets return false if this is passed to their handle() method.

Fltk will produce this for unrecognized X events, if it can figure out what window to send them to. You can then subclass Window and add a handler for these events. Unfortunately this is not done on Windows due to the enormous number of garbage messages a program gets, you should instead use Windows pre-filtering functions to look for unknown messages.

PUSH  A mouse button has gone down with the mouse pointing at this widget. You can find out what button by calling fltk::event_button(). You find out the mouse position by calling fltk::event_x() and fltk::event_y(). These positions are relative to the corner of the widget whose handle() method is being called.

A widget indicates that it "wants" the mouse click by returning non-zero from its handle() method. It will then become the fltk::pushed() widget (this is done by the enclosing group widget) and will get fltk::DRAG and the matching fltk::RELEASE events.

RELEASE  A mouse button has been released. You can find out what button by calling fltk::event_button().

To receive fltk::RELEASE events you must return non-zero when passed a fltk::PUSH event.

ENTER  The mouse has been moved to point at this widget. This can be used for highlighting feedback. If a widget wants to highlight or otherwise track the mouse, it indicates this by returning non-zero from its handle() method. It then becomes the fltk::belowmouse() widget and will receive fltk::MOVE and fltk::LEAVE events.
LEAVE  The mouse has moved out of the widget. To get this event you must return 1 in response to a fltk::ENTER event.
DRAG  The mouse has moved with a button held down. The current button state is in fltk::event_state(). The mouse position, relative to this widget, is in fltk::event_x() and fltk::event_y().

To receive fltk::DRAG events you must return non-zero when passed a fltk::PUSH event.

FOCUS  This indicates an attempt to give a widget the keyboard focus.

If a widget wants the focus, it should change itself to display the fact that it has the focus, and return non-zero from its handle() method. It then becomes the fltk::focus() widget and gets fltk::KEY, fltk::KEYUP and fltk::UNFOCUS events.

The focus will change either because the window manager changed which window gets the focus, or because the user tried to navigate using tab, arrows, or other keys. You can check fltk::event_key() to figure out why it moved, for navigation it will be the key pressed and for switching windows it will be zero.

UNFOCUS  Sent to the previous fltk::focus() widget when another widget gets the focus.
KEY  A key press event. Fltk sends these directly to the fltk::focus() widget. If it returns zero then fltk will change the event into fltk::SHORTCUT and try the widgets under the mouse.

The key pressed can be found in fltk::event_key(). The text that the key should insert can be found with fltk::event_text() and its length is in fltk::event_length().

If you are actually doing text editing, you should use fltk::compose() to process the individual keystrokes into I18N characters.

KEYUP  Sent to the fltk::focus() widget. The key that was released can be found in fltk::event_key() (fltk::event_text() is not set).
FOCUS_CHANGE  Sent to all parents of the new fltk::focus() widget when the focus changes. This can be used to record which child has focus so it can be restored later, or to scroll a view to show the focus.
MOVE  The mouse has moved without any mouse buttons held down. This event is sent to the fltk::belowmouse() widget.
SHORTCUT  If the fltk::focus() widget is zero or it returns zero for an fltk::KEY event then FLTK tries sending this event to every widget it can, until one of them returns non-zero. fltk::SHORTCUT is first sent to the belowmouse() widget, then its parents and siblings, and eventually to every widget in the window, trying to find an object that returns non-zero. FLTK tries really hard to not to ignore any keystrokes!

You can also make "global" shortcuts by using fltk::add_handler(). A global shortcut will work no matter what windows are displayed or which one has the focus.

DEACTIVATE  The method Widget::deactivate() has been called on this widget or one of its parents. The function Widget::active_r() will now return false.
ACTIVATE  The method Widget::activate() has been called on this widget or one of its parents. The function Widget::active_r() will now return true.
HIDE  This widget is no longer visible, due to Widget::hide() being called on it or one of its parents, or due to a parent window being minimized. The function Widget::visible_r() will now return false.

If you implement a widget class it is important to call your base class with this same event. Fltk relies on this to communicate the visiblilty of widgets that are windows to the system.

SHOW  This widget is visible, due to Widget::show() being called on it or one of its parents, or due to a parent window being restored from minimized state. The function Widget::visible_r() will now return true.

If you implement a widget class it is important to call your base class with this same event. Fltk relies on this to communicate the visiblilty of widgets that are windows to the system.

PASTE  You should get this event some time after you call fltk::paste() or you return true for fltk::DND_RELEASE. The contents of fltk::event_text() is the text to insert and the number of characters is in fltk::event_length().
TIMEOUT  This event is generated if you called Widget::add_timeout().
MOUSEWHEEL  The wheel was moved on the mouse. fltk::event_dy() contains how many clicks the wheel moved, positive for up and negative for down. There is also a fltk::event_dx() for any kind of horizontal scrolling device but nothing produces that yet.
DND_ENTER  The user is dragging something over your widget. Return 1 if you are intersted in getting fltk::DND_DRAG and fltk::DND_RELEASE events.

It is impossible to examine the text of the drag until you release it. There are system-specific variables that can be examined to determine the type of drag being done, but unless you are making a file-management application that wants to delete or rename the source files, you should not need this information.

DND_DRAG  The user moved the mouse some more while dragging something. You might use this to move around a cursor indicating where the insertion will go.
DND_LEAVE  The user moved out of the widget without releasing the dragged object.
DND_RELEASE  The user let go of the mouse and dropped something on your widget. Return 1 if you are interested in getting this data. In this case you will get an fltk::PASTE event with the text of object. This is usually a URL string, such as a filename with "file:" on the start. All fltk widgets just insert the data as text into text editors.
TOOLTIP  NYI. Sent when the mouse hovers over the widget long enough for it to pop up a tooltip. The base class handle() actually pops up the tooltip.

anonymous enum
 

Values returned by event_key(), passed to event_key_state() and get_key_state(), and used for the low 16 bits of add_shortcut().

The actual values returned are based on X11 keysym values, though fltk always returns "unshifted" values much like Windows does. A given key always returns the same value no matter what shift keys are held down. Use event_text() to see the results of any shift keys.

The lowercase letters 'a' through 'z' and the ascii symbols '`', '-', '=', '[', ']', '\', ',', '.', '/', ';', '\'' and space are used to identify the keys in the main keyboard.

On X systems unrecognized keys are returned unchanged as their X keysym value. If they have no keysym it uses the scan code or'd with 0x8000, this is what all those blue buttons on a Microsoft keyboard will do. I don't know how to get those buttons on Windows.

Enumeration values:
LeftButton  PUSH/RELEASE set event_key to this
MiddleButton  PUSH/RELEASE set event_key to this
RightButton  PUSH/RELEASE set event_key to this
SpaceKey  Same as ' ' or 32
BackSpaceKey  Backspace
TabKey  Tab
ClearKey  On some systems with NumLock off '5' produces this
ReturnKey  Main Enter key, Windows and X documentation calls this "Return"
PauseKey  Pause + Break button
ScrollLockKey  Scroll Lock button
EscapeKey  Esc
HomeKey  Home
LeftKey  Left
UpKey  Up arrow
RightKey  Right arrow
DownKey  Down arrow
PageUpKey  Page Up
PageDownKey  Page Down
EndKey  End
PrintKey  Print Scrn key + SysRq key
InsertKey  Insert
MenuKey  Key in lower-right with picture of popup menu
HelpKey  Help key on Macintosh keyboards
NumLockKey  NumLock key
Keypad  Add ASCII to get keypad keys
KeypadEnter  Keypad+'\r'
MultiplyKey  Keypad+'*'
AddKey  Keypad+'+'
SubtractKey  Keypad+'-'
DecimalKey  Keypad+'.'
DivideKey  Keypad+'/'
Keypad0  Keypad+'0'
Keypad1  Keypad+'1'
Keypad2  Keypad+'2'
Keypad3  Keypad+'3'
Keypad4  Keypad+'4'
Keypad5  Keypad+'5'
Keypad6  Keypad+'6'
Keypad7  Keypad+'7'
Keypad8  Keypad+'8'
Keypad9  Keypad+'9'
KeypadLast  Keypad+'=', largest legal keypad key
F0Key  Add a number to get function key
F1Key  F0Key+1
F2Key  F0Key+2
F3Key  F0Key+3
F4Key  F0Key+4
F5Key  F0Key+5
F6Key  F0Key+6
F7Key  F0Key+7
F8Key  F0Key+8
F9Key  F0Key+9
F10Key  F0Key+10
F11Key  F0Key+11
F12Key  F0Key+12
LastFunctionKey  F0Key+35, largest legal function key
LeftShiftKey  Left-hand Shift
RightShiftKey  Right-hand Shift
LeftCtrlKey  Left-hand Ctrl
RightCtrlKey  Right-hand Ctrl
CapsLockKey  Caps Lock
LeftMetaKey  The left "Windows" or the "Apple" key
RightMetaKey  The right "Windows" or the "Apple" key
LeftAltKey  Left-hand Alt (option on Mac)
RightAltKey  Right-hand Alt (option on Mac)
DeleteKey  Delete

anonymous enum
 

Flags returned by event_state(), and used as the high 16 bits of Widget::add_shortcut() values (the low 16 bits are all zero, so these may be or'd with key values).

The inline function BUTTON(n) will turn n (1-8) into the flag for a mouse button.

Enumeration values:
SHIFT  Either shift key held down
CAPSLOCK  Caps lock is toggled on
CTRL  Either ctrl key held down
ALT  Either alt key held down
NUMLOCK  Num Lock turned on
META  "Windows" or the "Apple" keys held down
SCROLLLOCK  Scroll Lock turned on
BUTTON1  Left mouse button held down
BUTTON2  Middle mouse button held down
BUTTON3  Right mouse button held down
ANY_BUTTON  Any mouse button (up to 8)

anonymous enum
 

Device identifier returned by event_device(). This enumeration is useful to get the device type that caused a PUSH, RELEASE, DRAG or MOVE event

Enumeration values:
DEVICE_MOUSE  Event triggered by the system mouse
DEVICE_STYLUS  Event triggered by a pen on a tablet, givin pressure and tilt information
DEVICE_ERASER  Event triggered by an eraser on a tablet, givin pressure and tilt information
DEVICE_CURSOR  Event triggered by a puck style device on a tablet
DEVICE_AIRBRUSH  Event triggered by an airbrush on a tablet, giving pressure and tilt information
DEVICE_TOUCH  Event triggered by touch a touch screen device


Function Documentation

int event  )  [inline]
 

Returns the most recent event handled, such as fltk::PUSH or fltk::KEY. This is useful so callbacks can find out why they were called.

int event_x  )  [inline]
 

Returns the distance the mouse is to the right of the left edge of the widget. Widget::send() modifies this as needed before calling the Widget::handle() method.

int event_y  )  [inline]
 

Returns the distance the mouse is below the top edge of the widget. Widget::send() modifies this as needed before calling the Widget::handle() method.

int event_dx  )  [inline]
 

For fltk::MOUSEWHEEL events this is how many clicks the user moved in the x and y directions (currently dx is always zero).

int event_dy  )  [inline]
 

Reserved for future use if horizontal mouse wheels (or some kind of joystick on the mouse) becomes popular.

int event_x_root  )  [inline]
 

Return the absolute horizontal position of the mouse. Usually this is relative to the left edge of the screen, but multiple Monitor setup may change that.

To find the absolute position of the current widget, subtract event_x_root()-event_x().

int event_y_root  )  [inline]
 

Return the absolute vertical position of the mouse. Zero is at the top.

int event_clicks  )  [inline]
 

Returns the number of times the last mouse button was pushed while fltk::event_is_click() was true. For a normal fltk::PUSH this is zero, if the user "double-clicks" this is 1, and it is N-1 for each subsequent click.

This is also used to indicate if fltk::KEY events are caused by the key repeating. Zero means the user pushed the key down, non-zero means it is being held down and is repeating.

void event_clicks int  i  )  [inline]
 

Setting this value can be used to make callbacks think things were (or were not) double-clicked, and thus act differently.

bool event_is_click  )  [inline]
 

This is true if the time and mouse movement since the last fltk::PUSH or fltk::KEY is short enough that the user is intending to "click". After enough time or after enough mouse movement this turns off.

The main use of this is to decide whether to increment fltk::event_clicks() when the user clicks the mouse. But you can also test this on a fltk::RELEASE or fltk::KEYUP event to decide if the user clicked quickly, versus holding the mouse or key down.

void event_is_click bool   )  [inline]
 

You can set this to zero with fltk::event_is_click(0), this can be used to prevent the next mouse click from being considered a double click. Only false works, attempts to set this true are ignored.

unsigned event_state  )  [inline]
 

This is a bitfield of what shift states were on and what mouse buttons were held down during the most recent event. The flags to pass are described under fltk::SHIFT.

Because Emacs screws up if any key returns the predefined META flag, lots of X servers have really botched up the key assignments trying to make Emacs work. Fltk tries to work around this but you may find that Alt or Meta don't work, since I have seen at least 3 mutually incompatable arrangements. Non-XFree86 machines may also have selected different values so that NUMLOCK, META, and SCROLLLOCK are mixed up. In addition X reports the state before the last key was pressed so the state looks backwards for any shift keys, currently fltk only fixes this bug for the mouse buttons.

bool event_state unsigned  mask  )  [inline]
 

Same as event_state()&mask, returns true if any of the passed bits were turned on during the last event. So doing event_state(SHIFT) will return true if the shift keys are held down. This is provided to make the calling code easier to read. The flags to pass are described under fltk::SHIFT.

unsigned event_key  )  [inline]
 

Returns which key on the keyboard was last pushed. Most non-keyboard events set this to values that do not correspond to any keys, so you can test this in callbacks without having to test first if the event really was a keystroke. The values returned are described under fltk::SpaceKey.

unsigned event_button  )  [inline]
 

Returns which mouse button was pressed or released by a PUSH or RELEASE event. Returns garbage for other events, so be careful (this actually is the same as event_key(), the buttons have been assigned the key values 1,2,3, etc.

bool event_key_state unsigned  key  ) 
 

Returns true if the given key was held down (or pressed) during the last event. This is constant until the next event is read from the server. The possible values for the key are listed under fltk::SpaceKey.

On Win32 event_key_state(KeypadEnter) does not work.

const char * event_text  )  [inline]
 

Returns the ASCII text (in the future this may be UTF-8) produced by the last fltk::KEY or fltk::PASTE or possibly other event. A zero-length string is returned for any keyboard function keys that do not produce text. This pointer points at a static buffer and is only valid until the next event is processed.

Under X this is the result of calling XLookupString().

unsigned event_length  )  [inline]
 

Returns the length of the text in fltk::event_text(). There will always be a nul at this position in the text. However there may be a nul before that if the keystroke translates to a nul character or you paste a nul character.

bool event_inside const Rectangle r  ) 
 

Returns true if the current fltk::event_x() and fltk::event_y() put it inside the Rectangle. You should always call this rather than doing your own comparison so you are consistent about edge effects.

bool compose int &  del  ) 
 

Use of this function is very simple. Any text editing widget should call this for each fltk::KEY event.

If true is returned, then it has modified the fltk::event_text() and fltk::event_length() to a set of bytes to insert (it may be of zero length!). It will also set the del parameter to the number of bytes to the left of the cursor to delete, this is used to delete the results of the previous call to fltk::compose(). Compose may consume the key, which is indicated by returning true, but both the length and del are set to zero.

Compose returns false if it thinks the key is a function key that the widget should handle itself, and not an attempt by the user to insert text.

Though the current implementation returns immediately, future versions may take quite awhile, as they may pop up a window or do other user-interface things to allow international characters to be selected.

void compose_reset  )  [inline]
 

If the user moves the cursor, be sure to call fltk::compose_reset(). The next call to fltk::compose() will start out in an initial state. In particular it will not set "del" to non-zero. This call is very fast so it is ok to call it many times and in many places.

const ShortcutAssignment * list_shortcuts unsigned  key,
unsigned &  count
 

Returns an array of shortcut assignments that match the given value for key. The number of matching ones is put in count. If there are no matches count is set to zero. Do not assumme any particular order for the returned array. Also there may be entries with widget==0, ignore them.

The returned array is temporary storage and can be overwritten by the next call to alter or query shortcuts!

const ShortcutAssignment * list_shortcuts const Widget widget,
unsigned &  count
 

Returns an array of shortcut assignments for this widget. The number of matching ones is put in count. Do not assumme any particular order for the returned array. Also there may be entries with key==0, ignore them.

The returned array is temporary storage and can be overwritten by the next call to alter or query shortcuts!

const ShortcutAssignment * list_shortcuts unsigned &  count  ) 
 

Returns an array of every shortcut assignment. They are sorted by the key, and then by shift flags.

The returned array is temporary storage and will be overwritten by the next call to alter or query shortcuts! Also there may be entries with widget==0, ignore them.

const ShortcutAssignment * list_matching_shortcuts unsigned &  count  ) 
 

Returns an array of shortcut assignments that match the current event, which should be a KEY, SHORTCUT, or KEYUP event. The number of matching ones is put in count. If there are no matches null is returned and count is set to zero.

The returned array is temporary storage and can be overwritten by the next call to alter or query shortcuts! Also there may be entries with widget==0, ignore them.

This is very similar to list_shortcuts(event_key()|event_state()) except if no exact match is found, it will try to locate a "close" matching key assignment and return that:

  • Shift flags other than META, ALT, SHIFT, and CTRL do not have to be "off". For instance a shortcut with SCROLL_LOCK requires the SCROLL_LOCK to be on, but one without it does not require it to be off. If there are several matches the numerically-highest one is chosen.
  • If no shortcut matches fltk::event_key(), then the first letter of fltk::event_text() is converted to upper-case and tried instead, and SHIFT can be held down even if the shortcut does not indicate it. This means that a shortcut that is a capital 'A' will match the 'a' key, and '3' will match both the main and keypad 3, and a shortcut of '#' or SHIFT+'#' will work.

bool try_shortcut  ) 
 

Try sending the current KEY event as a SHORTCUT event.

Normally the focus() gets all keystrokes, and shortcuts are only tested if that widget indicates it is uninterested by returning zero from Widget::handle(). However in some cases the focus wants to use the keystroke only if it is not a shortcut. The most common example is Emacs-style editing keystrokes in text editing widgets, which conflict with Microsoft-compatable menu key bindings, but we want the editing keys to work if there is no conflict.

This will send a SHORTCUT event just like the focus returned zero, to every widget in the focus window, and to the add_handler() calls, if any. It will return true if any widgets were found that were interested in it. A handle() method can call this in a KEY event. If it returns true, return 1 immediatly, as the shortcut will have executed and may very well have destroyed your widget. If this returns false, then do what you want the key to do.

const char * key_name unsigned  hotkey  ) 
 

Unparse a fltk::Widget::shortcut() or fltk::event_key() value into human-readable text. Returns a pointer to a human-readable string like "Alt+N". If hotkey is zero an empty string is returned. The return value points at a static buffer that is overwritten with each call.

The opposite function is fltk::key().

unsigned key const char *  name  ) 
 

Turn a string into a fltk::event_key() value or'd with fltk::event_shift() flags. The returned value can be used by by fltk::Widget::add_shortcut(). Any error, or a null or zero-length string, returns 0.

Currently this understands prefixes of "Alt+", "Shift+", and "Ctrl+" to turn on fltk::ALT, fltk::SHIFT, and fltk::CTRL. Case is ignored and the '+' can be a '-' instead and the prefixes can be in any order. You can also use '#' instead of "Alt+", '+' instead of "Shift+", and '^' instead of Ctrl+.

After the shift prefixes there can either be a single ASCII letter, "Fn" where n is a number to indicate a function key, or "0xnnnn" to get an arbitrary fltk::event_key() enumeration value.

The inverse function to turn a number into a string is fltk::key_name(). Currently this function does not parse some strings fltk::key_name() can return, such as the names of arrow keys!

bool get_key_state unsigned  key  ) 
 

Returns true if the given key is held down now. This is different than event_key_state() as that returns how the key was during the last event. This can also be slower as it requires a round-trip query to the window server. The values to pass are described under fltk::SpaceKey.

On Win32 fltk::get_key_state(fltk::KeypadEnter) does not work.

bool handle int  event,
Window window
 

This is the function called from the system-specific code for all events that can be passed to Widget::handle().

You can call it directly to fake events happening to your widgets. Currently data other than the event number can only be faked by writing to the undocumented fltk::e_* variables, for instance to make event_x() return 5, you should do fltk::e_x = 5. This may change in future versions.

This will redirect events to the modal(), pushed(), belowmouse(), or focus() widget depending on those settings and the event type. It will turn MOVE into DRAG if any buttons are down. If the resulting widget returns 0 (or the window or widget is null) then the functions pointed to by add_event_handler() are called.

void add_event_handler int(*)(int, Window *)  h  ) 
 

Install a function to parse unrecognized events. If FLTK cannot figure out what to do with an event, it calls each of these functions (most recent first) until one of them returns non-zero. If none of them returns non zero then the event is ignored.

Currently this is called for these reasons:

  • If there is a keystroke that no widgets are interested in, this is called with fltk::SHORTCUT. You can use this to implement global hotkeys.
  • Unrecognized X events cause this to be called with NO_EVENT. The Window parameter is set if fltk can figure out the target window and it is an fltk one. You can then use system specific code to access the event data and figure out what to do. This is not done on Windows due to the enormous number of garbage messages a program gets, you should instead use Windows pre-filtering functions to look at these.
  • Events it gets with a window id it does not recognize cause this to be called, with the Window parameter set to null. This can only happen on X, on Windows any unknown windows should have their own message handling function that does not call fltk.
  • This may be called with other event types when the widget fltk wants to send it to returns zero. However the exact rules when this happens may change in future versions.

Widget * belowmouse  )  [inline]
 

Get the widget that is below the mouse. This is the last widget to respond to an fltk::ENTER event as long as the mouse is still pointing at it. This is for highlighting buttons and bringing up tooltips. It is not used to send fltk::PUSH or fltk::MOVE directly, for several obscure reasons, but those events typically go to this widget.

void belowmouse Widget o  ) 
 

Change the fltk::belowmouse() widget, the previous one and all parents (that don't contain the new widget) are sent fltk::LEAVE events. Changing this does not send fltk::ENTER to this or any widget, because sending fltk::ENTER is supposed to test if the widget wants the mouse (by it returning non-zero from handle()).

Widget * pushed  )  [inline]
 

Get the widget that is being pushed. fltk::DRAG or fltk::RELEASE (and any more fltk::PUSH) events will be sent to this widget. This is null if no mouse button is being held down, or if no widget responded to the fltk::PUSH event.

void pushed Widget o  ) 
 

Change the fltk::pushed() widget. This sends no events.

Widget * focus  )  [inline]
 

Returns the widgets that will receive fltk::KEY events. This is NULL if the application does not have focus now, or if no widgets accepted focus.

void focus Widget o  ) 
 

Change fltk::focus() to the given widget, the previous widget and all parents (that don't contain the new widget) are sent fltk::UNFOCUS events, the new widget is sent an fltk::FOCUS event, and all parents of it get fltk::FOCUS_CHANGE events.

fltk::focus() is set whether or not the applicaton has the focus or if the widgets accept the focus. You may want to use fltk::Widget::take_focus() instead, it will test first.

void modal Widget widget,
bool  grab = false
 

Restricts events to a certain widget.

First thing: much of the time fltk::Window::exec() will do what you want, so try using that.

This function sets the passed widget as the "modal widget". All user events are directed to it or a child of it, preventing the user from messing with other widgets. The modal widget does not have to be visible or even a child of an fltk::Window for this to work (but if it not visible, fltk::event_x() and fltk::event_y() are meaningless, use fltk::event_x_root() and fltk::event_y_root()).

The calling code is responsible for saving the current value of modal() and grab() and restoring them by calling this after it is done. The code calling this should then loop calling fltk::wait() until fltk::exit_modal_flag() is set or you otherwise decide to get out of the modal state. It is the calling code's responsibility to monitor this flag and restore the modal widget to it's previous value when it turns on.

grab indicates that the modal widget should get events from anywhere on the screen. This is done by messing with the window system. If fltk::exit_modal() is called in response to an fltk::PUSH event (rather than waiting for the drag or release event) fltk will "repost" the event so that it is handled after modal state is exited. This may also be done for keystrokes in the future. On both X and WIN32 grab will not work unless you have some visible window because the system interface needs a visible window id. On X be careful that your program does not enter an infinite loop while grab() is on, it will lock up your screen!

Widget * modal  )  [inline]
 

Returns the current modal widget, or null if there isn't one. It is useful to test these in timeouts and file descriptor callbacks in order to block actions that should not happen while the modal window is up. You also need these in order to save and restore the modal state.

bool grab  )  [inline]
 

returns the current value of grab (this is always false if modal() is null).

void exit_modal  )  [inline]
 

Turns on exit_modal_flag(). This may be used by user callbacks to cancel modal state.

bool exit_modal_flag  )  [inline]
 

True if exit_modal() has been called. The flag is also set by the destruction or hiding of the modal widget, and on Windows by other applications taking the focus when grab is on.

bool add_shortcut unsigned  key  )  [inherited]
 

Add a new shortcut assignment. Returns true if successful. If key is zero or the assignment already exists this does nothing and returns false.

There can be any number of shortcut assignments, fltk stores them in internal tables shared by all widgets. A widget can have any number of shortcuts (though most have zero or one), and a given shortcut value can be assigned to more than one widget. You can examine the assignments with fltk::list_shortcuts().

If you only want one shortcut use shortcut() to assign it.

The shortcut value is a bitwise OR (or sum) of a any set of shift flags returned by fltk::event_state(), and either a key symbol returned by fltk::event_key(), or an ASCII character. Examples:

When FLTK gets a keystroke, it sends it to the fltk::focus() widget. If that widget's handle() returns 0, it will also send the keystroke to all parents of that widget (this is mostly for keyboard navigation to work). If all of them return 0, or the fltk::focus() is null, then it will try sending a SHORTCUT event to every single widget inside the same window as the focus until one of them returns non-zero. In most cases widgets will call Widget::test_shortcut() to see if the keystroke is registered here (many widgets will also directly test the key to see if it is something they are interested in).

bool remove_shortcut unsigned  key  )  [inherited]
 

Delete a shortcut assignment. Returns true if it actually existed.

bool remove_shortcuts  )  [inherited]
 

Remove all shortcuts for the widget. Returns true if there were any. This is automatically done by the Widget destructor.

unsigned shortcut  )  const [inherited]
 

Returns one of the add_shortcut() assignments for this widget, or returns zero if there are none. If you want to look at more than onle you must use fltk::list_shortcuts(this).

bool shortcut unsigned  key  )  [inherited]
 

Same as remove_shortcuts(), add_shortcut(key) except it may be implemented in a more efficient way. The result is exactly one shortcut (or none if key is zero). Return value is intended to indicate if the shortcut changed, but that is nyi.

unsigned label_shortcut  )  const [inherited]
 

Returns a value that can be passed to add_shortcut() so that this widget has a real shortcut assignment to match any &x in it's label(). The returned value is ALT|c where c is the character after the first '&' in the label, or zero if there isn't any '&' sign or if flags() has RAW_LABEL turned on.

bool test_label_shortcut  )  const [inherited]
 

Test to see if the current KEY or SHORTCUT event matches a shortcut specified with &x in the label.

This will match if the character after the first '&' matches the event_text()[0]. Case is ignored. The caller may want to check if ALT or some other shift key is held down before calling this so that plain keys do not do anything, and should certainly make sure no other widgets want the shortcut.

This is ignored if flags() has RAW_LABEL turned on (which stops the &x from printing as an underscore. The sequence "&&" is ignored as well because that is used to print a plain '&' in the label.

bool test_shortcut  )  const [inherited]
 

Same as test_shortcut(true)

bool test_shortcut bool  test_label  )  const [inherited]
 

Returns true if the current event matches one of the assignements made with add_shortcut(), or if test_label is true and test_label_shortcut() returns true. Normally a widget calls this in response to a SHORTCUT event to see if the shortcut key is assigned to it.

This is done by doing list_matching_shortcuts() and seeing if this widget is in the returned list. If the list is empty and test_label is true, it will return test_label_shortcut().

If the current event matches a different widget "better" than this one, then false is returned. For instance if this widget has 'x' as a shortcut, this will return true if the user types 'X'. But if another widget has 'X' then this will return false. See fltk::list_matching_shortcuts() for the rules about what ones are "better".

int handle int  event  )  [virtual, inherited]
 

Handle an Event Types and Event Handling(event). Returns non-zero if the widget understood and used the event.

The default version returns true for fltk::ENTER and fltk::MOVE events, this is done so you can put tooltips on the base widget. All other events return zero.

Information on how to write your own version of handle() is can be found under Event Types and Event Handling.

If you want to send an event to a widget you probably want to call send(), not handle(). Send will do extra work with each event before calling this, such as turning HIGHLIGHT and FOCUSED flags on/off.

Reimplemented in Divider, Group, Input, Item, ItemGroup, NumericInput, and Valuator.

int send int  event  )  [inherited]
 

Wrapper for handle(). This should be called to send events. It does a few things:

void add_timeout float  time  )  [inherited]
 

Call handle(TIMEOUT) at the given time in the future. This will happen exactly once. To make it happen repeatedly, call repeat_timeout() from inside handle(TIMEOUT).

void repeat_timeout float  time  )  [inherited]
 

Call handle(TIMEOUT) at the given time interval since the last timeout. This will produce much more accurate time intervals than add_timeout().

void remove_timeout  )  [inherited]
 

Cancel any and all pending handle(TIMEOUT) callbacks.


Sun May 8 21:48:57 2005. FLTK ©2004 Bill Spitzak and others. See Main Page for details.