events.h File Reference


Classes

struct  ShortcutAssignment

Enumerations

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

Functions

unsigned BUTTON (int n)
int event ()
int event_x ()
int event_y ()
int event_dx ()
int event_dy ()
int event_x_root ()
int event_y_root ()
int event_clicks ()
void event_clicks (int i)
bool event_is_click ()
void event_is_click (bool)
unsigned event_state ()
bool event_state (unsigned i)
unsigned event_key ()
unsigned event_button ()
bool event_key_state (unsigned)
const char * event_text ()
unsigned event_length ()
unsigned event_key_repeated ()
float event_pressure ()
float event_x_tilt ()
float event_y_tilt ()
int event_device ()
bool event_inside (const Rectangle &)
bool compose (int &del)
void compose_reset ()
const ShortcutAssignmentlist_shortcuts (unsigned key, unsigned &count)
const ShortcutAssignmentlist_shortcuts (const Widget *, unsigned &count)
const ShortcutAssignmentlist_shortcuts (unsigned &count)
const ShortcutAssignmentlist_matching_shortcuts (unsigned &count)
bool try_shortcut ()
const char * key_name (unsigned key)
unsigned key (const char *name)
bool get_key_state (unsigned)
void get_mouse (int &, int &)
bool handle (int, Window *)
void add_event_handler (int(*h)(int, Window *))
Widgetbelowmouse ()
void belowmouse (Widget *)
void belowmouse (Widget &w)
Widgetpushed ()
void pushed (Widget *)
void pushed (Widget &w)
Widgetfocus ()
void focus (Widget *)
void focus (Widget &w)
void copy (const char *stuff, int len, bool clipboard=false)
void paste (Widget &receiver, bool clipboard=false)
bool dnd ()
void modal (Widget *, bool grab=false)
Widgetmodal ()
bool grab ()
void exit_modal ()
bool exit_modal_flag ()
const char * event_name (int event)

Detailed Description

FLTK Events are identified by the integer argument passed to the 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 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 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 Window containing the event, and those widgets are responsible for finding and sending the events to child widgets. Some events are sent directly to 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 add_event_handler()

You can generate fake events by calling handle(int) on the correct widgets (usually a window). Currently you can change the values returned by the event_*() functions by storing the desired value into the static variables 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 event_button(). You find out the mouse position by calling event_x() and 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 pushed() widget (this is done by the enclosing group widget) and will get DRAG and the matching RELEASE events.

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

To receive RELEASE events you must return non-zero when passed a 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 belowmouse() widget and will receive MOVE and LEAVE events.
LEAVE  The mouse has moved out of the widget. To get this event you must return 1 in response to a ENTER event.
DRAG  The mouse has moved with a button held down. The current button state is in event_state(). The mouse position, relative to this widget, is in event_x() and event_y().

To receive DRAG events you must return non-zero when passed a 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 focus() widget and gets KEY, KEYUP and 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 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 focus() widget when another widget gets the focus.
KEY  A key press event. Fltk sends these directly to the focus() widget. If it returns zero then fltk will change the event into SHORTCUT and try the widgets under the mouse.

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

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

KEYUP  Sent to the focus() widget. The key that was released can be found in event_key() (event_text() is not set).
FOCUS_CHANGE  Sent to all parents of the new 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 belowmouse() widget.
SHORTCUT  If the focus() widget is zero or it returns zero for an KEY event then FLTK tries sending this event to every widget it can, until one of them returns non-zero. 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 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 visibility 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 visibility of widgets that are windows to the system.

PASTE  You should get this event some time after you call paste() or you return true for DND_RELEASE. The contents of event_text() is the text to insert and the number of characters is in event_length().
TIMEOUT  This event is generated if you called Widget::add_timeout().
MOUSEWHEEL  The wheel was moved on the mouse. event_dy() contains how many clicks the wheel moved, positive for up and negative for down. There is also a 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 interested in getting DND_DRAG and 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 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 "Apple" key
RightMetaKey  The right "Windows" or "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)
ACCELERATOR  Same as ALT on Windows/Linux, same as CTRL on OS/X
COMMAND  Same as CTRL on Windows/Linux, same as META on OS/X

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

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 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.

void belowmouse Widget o  ) 
 

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

Widget * belowmouse  )  [inline]
 

Get the widget that is below the mouse. This is the last widget to respond to an 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 PUSH or MOVE directly, for several obscure reasons, but those events typically go to this widget.

bool compose int &  del  ) 
 

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

If true is returned, then it has modified the event_text() and 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 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 compose_reset(). The next call to 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.

void copy const char *  stuff,
int  len,
bool  clipboard
 

Change the current selection. The block of text is copied to an internal buffer by FLTK (be careful if doing this in response to an PASTE as this may be the same buffer returned by event_text()).

The block of text may be retrieved (from this program or whatever program last set it) with paste().

There are actually two buffers. If clipboard is true then the text goes into the user-visible selection that is moved around with cut/copy/paste commands (on X this is the CLIPBOARD selection). If clipboard is false then the text goes into a less-visible buffer used for temporarily selecting text with the mouse and for drag & drop (on X this is the XA_PRIMARY selection).

bool dnd  ) 
 

Drag and drop the data set by the most recent copy() (with the clipboard argument false). Returns true if the data was dropped on something that accepted it.

By default only blocks of text are dragged. You can use system-specific variables to change the type of data.

int event  )  [inline]
 

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

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.

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.

int event_clicks  )  [inline]
 

Returns the number of extra times the mouse was clicked. For a normal PUSH this is zero, if the user "double-clicks" this is 1, and it is N-1 for each subsequent click.

int event_dx  )  [inline]
 

For 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.

bool event_inside const Rectangle r  ) 
 

Returns true if the current event_x() and 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.

void event_is_click bool   )  [inline]
 

You can set this to zero with 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.

bool event_is_click  )  [inline]
 

This is true for a short time after the mouse key is pressed. You test this on the RELEASE events to decide if the user "clicked" or "held" the mouse. It is very useful to do different actions depending on this.

This turns off after a timeout (implemented on X only, currently), when the mouse is moved more than 5 pixels, and when the user presses other mouse or keyboard buttons while the mouse is down.

On X this is used to decide if a click is a double-click, it is if this is still on during the next mouse press. On Windows and OS/X the system's indication is used for double-click.

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 SpaceKey.

unsigned event_key_repeated  )  [inline]
 

True if the most recent KEY event was caused by a repeating held-down key on the keyboard. The value increments for each repeat.

Note: older versions of fltk reused event_clicks() for this. This made it impossible to design a GUI where the user holds down keyboard keys while clicking the mouse, as well as being pretty hard to understand. So we had to change it for fltk 2.

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 SpaceKey.

On Win32 event_key_state(KeypadEnter) does not work.

unsigned event_length  )  [inline]
 

Returns the length of the text in 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.

const char* event_name int  event  ) 
 

return the corresponding str of an event, should not consume memory if api is not used

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 SHIFT.

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 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 incompatible 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.

const char * event_text  )  [inline]
 

Returns the ASCII text (in the future this may be UTF-8) produced by the last KEY or 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().

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_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  )  [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_y_root  )  [inline]
 

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

void exit_modal  )  [inline]
 

Turns on exit_modal_flag(). This may be used by user callbacks to cancel modal state. See also Window::make_exec_return().

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.

void focus Widget o  ) 
 

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

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

Widget * focus  )  [inline]
 

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

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 SpaceKey.

On Win32 get_key_state(KeypadEnter) does not work.

void get_mouse int &  x,
int &  y
 

Return where the mouse is on the screen by doing a round-trip query to the server. You should use event_x_root() and event_y_root() if possible, but this is necessary if you are not sure if a mouse event has been processed recently (such as to position your first window). If the display is not open, this will open it.

bool grab  )  [inline]
 

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

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 e_* variables, for instance to make event_x() return 5, you should do 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.

unsigned key const char *  name  ) 
 

Turn a string into a event_key() value or'd with event_shift() flags. The returned value can be used by by 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 ALT, SHIFT, and 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 event_key() enumeration value.

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

const char* key_name unsigned  hotkey  ) 
 

Unparse a Widget::shortcut() or 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 key().

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 event_key(), then the first letter of 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.

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_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  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!

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.

void modal Widget widget,
bool  grab
 

Restricts events to a certain widget.

First thing: much of the time 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 Window for this to work (but if it not visible, event_x() and event_y() are meaningless, use event_x_root() and 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 wait() until 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 exit_modal() is called in response to an 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!

void paste Widget receiver,
bool  clipboard
 

This is what a widget does when a "paste" command (like Ctrl+V or the middle mouse click) is done to it. Cause an PASTE event to be sent to the receiver with the contents of the current selection in the event_text(). The selection can be set by copy().

There are actually two buffers. If clipboard is true then the text is from the user-visible selection that is moved around with cut/copy/paste commands (on X this is the CLIPBOARD selection). If clipboard is false then the text is from a less-visible buffer used for temporarily selecting text with the mouse and for drag & drop (on X this is the XA_PRIMARY selection).

The reciever should be prepared to be called directly by this, or for it to happen later, or possibly not at all. This allows the window system to take as long as necessary to retrieve the paste buffer (or even to screw up completely) without complex and error-prone synchronization code most toolkits require.

void pushed Widget o  ) 
 

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

Widget * pushed  )  [inline]
 

Get the widget that is being pushed. DRAG or RELEASE (and any more 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 PUSH event.

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.


Sun Jan 7 00:55:16 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.