## class Fl

### Class Hierarchy

    Fl

### Include Files

    #include <FL/Fl.H>

### Description

The `Fl` class is the FLTK global (static) class containing state information and global methods for the current application.

### Methods

- add_check
- add_fd
- add_handler
- add_idle
- add_timeout
- arg
- args
- atclose
- awake
- background
- background2
- belowmouse
- box_dh
- box_dw
- box_dx
- box_dy
- check
- compose
- compose_reset
- copy
- damage
- default_atclose
- delete_widget
- display
- dnd
- dnd_text_ops
- error
- event
- event_alt
- event_button1
- event_button2
- event_button3
- event_button
- event_buttons
- event_clicks
- event_ctrl
- event_dx
- event_dy
- event_inside
- event_is_click
- event_key
- event_length
- event_original_key
- event_shift
- event_state
- event_text
- event_x
- event_x_root
- event_y
- event_y_root
- fatal
- first_window
- flush
- focus
- foreground
- free_color
- get_boxtype
- get_color
- get_font
- get_font_name
- get_font_sizes
- get_key
- get_mouse
- get_system_colors
- gl_visual
- grab
- h
- handle
- has_check
- has_idle
- has_timeout
- lock
- modal
- next_window
- own_colormap
- paste
- pushed
- readqueue
- ready
- redraw
- release
- remove_check
- remove_fd
- remove_handler
- remove_idle
- remove_timeout
- repeat_timeout
- run
- scheme
- screen_count
- screen_xywh
- scrollbar_size
- selection
- selection_owner
- set_abort
- set_atclose
- set_boxtype
- set_color
- set_font
- set_fonts
- set_idle
- set_labeltype
- test_shortcut
- thread_message
- unlock
- version
- visible_focus
- visual
- wait
- warning
- w
- x
- y

#### void add_check(Fl_Timeout_Handler, void* = 0);

FLTK will call this callback just before it flushes the display and waits for events. This is different than an idle callback because it is only called once, then FLTK calls the system and tells it not to return until an event happens.

This can be used by code that wants to monitor the application's state, such as to keep a display up to date. The advantage of using a check callback is that it is called only when no events are pending. If events are coming in quickly, whole blocks of them will be processed before this is called once. This can save significant time and avoid the application falling behind the events.

Sample code:

    bool state_changed; // anything that changes the display turns this on

    void callback(void*) {
      if (!state_changed) return;
      state_changed = false;
      do_expensive_calculation();
      widget->redraw();
    }

    main() {
      Fl::add_check(callback);
      return Fl::run();
    }

#### void add_fd(int fd, void (*cb)(int,void*),void* =0);
void add_fd(int fd, int when, void (*cb)(int, void*), void* = 0);

Add file descriptor `fd` to listen to. When the `fd` becomes ready for reading `Fl::wait()` will call the callback and then return. The callback is passed the `fd` and the arbitrary `void*` argument.

The second version takes a `when` bitfield, with the bits `FL_READ`, `FL_WRITE`, and `FL_EXCEPT` defined, to indicate when the callback should be done.

There can only be one callback of each type for a file descriptor. `Fl::remove_fd()` gets rid of all the callbacks for a given file descriptor.

Under UNIX any file descriptor can be monitored (files, devices, pipes, sockets, etc.) Due to limitations in Microsoft Windows, WIN32 applications can only monitor sockets.

#### void add_handler(int (*h)(int));

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. Events that cause this to be called are:

- `FL_SHORTCUT` events that are not recognized by any widget. This lets you provide global shortcut keys.
- System events that FLTK does not recognize. See `fl_xevent`.
- Some other events when the widget FLTK selected returns zero from its `handle()` method. Exactly which ones may change in future versions, however.

#### void add_idle(void (*cb)(void*), void* = 0);

Adds a callback function that is called every time by `Fl::wait()` and also makes it act as though the timeout is zero (this makes `Fl::wait()` return immediately, so if it is in a loop it is called repeatedly, and thus the idle fucntion is called repeatedly). The idle function can be used to get background processing done.

You can have multiple idle callbacks. To remove an idle callback use `Fl::remove_idle()`.

`Fl::wait()` and `Fl::check()` call idle callbacks, but `Fl::ready()` does not.

The idle callback can call any FLTK functions, including `Fl::wait()`, `Fl::check()`, and `Fl::ready()`. FLTK will not recursively call the idle callback.

#### void add_timeout(double t, Fl_Timeout_Handler,void* = 0);

Add a one-shot timeout callback. The function will be called by `Fl::wait()` at t seconds after this function is called. The optional `void*` argument is passed to the callback.

You can have multiple timeout callbacks. To remove an timeout callback use `Fl::remove_timeout()`.

If you need more accurate, repeated timeouts, use `Fl::repeat_timeout()` to reschedule the subsequent timeouts.

The following code will print "TICK" each second on `stdout` with a fair degree of accuracy:

        void callback(void*) {
          puts("TICK");
          Fl::repeat_timeout(1.0, callback);
        }

        int main() {
          Fl::add_timeout(1.0, callback);
          return Fl::run();
        }

#### int arg(int, char**, int&);

Consume a single switch from `argv`, starting at word i. Returns the number of words eaten (1 or 2, or 0 if it is not recognized) and adds the same value to `i`. You can use this function if you prefer to control the incrementing through the arguments yourself.

#### int args(int, char**, int&, int (*)(int,char**,int&) = 0);

FLTK provides an entirely optional command-line switch parser. You don't have to call it if you don't like them! Everything it can do can be done with other calls to FLTK.

To use the switch parser, call `Fl::args(...)` near the start of your program. This does not open the display, instead switches that need the display open are stashed into static variables. Then you must display your first window by calling window->show(argc,argv), which will do anything stored in the static variables.

`callback` lets you define your own switches. It is called with the same `argc` and `argv`, and with `i` the index of each word. The callback should return zero if the switch is unrecognized, and not change `i`. It should return non-zero if the switch is recognized, and add at least 1 to `i` (it can add more to consume words after the switch). This function is called before any other tests, so you can override any FLTK switch (this is why FLTK can use very short switches instead of the long ones all other toolkits force you to use).

On return `i` is set to the index of the first non-switch. This is either:

- The first word that does not start with '-'.
- The word '-' (used by many programs to name stdin as a file)
- The first unrecognized switch (return value is 0).
- `argc`

The return value is `i` unless an unrecognized switch is found, in which case it is zero. If your program takes no arguments other than switches you should produce an error if the return value is less than `argc`.

All switches except -bg2 may be abbreviated one letter and case is ignored:

- `-bg color` or `-background color`

  Sets the background color using `Fl::background()`.

- `-bg2 color` or `-background2 color`

  Sets the secondary background color using `Fl::background2()`.

- `-display host:n.n`

  Sets the X display to use; this option is silently ignored under WIN32 and MacOS.

- `-dnd` and `-nodnd`

  Enables or disables drag and drop text operations using `Fl::dnd_text_ops()`.

- `-fg color` or `-foreground color`

  Sets the foreground color using `Fl::foreground()`.

- `-geometry WxH+X+Y`

  Sets the initial window position and size according the the standard X geometry string.

- `-iconic`

  Iconifies the window using `Fl_Window::iconize()`.

- `-kbd` and `-nokbd`

  Enables or disables visible keyboard focus for non-text widgets using `Fl::visible_focus()`.

- `-name string`

  Sets the window class using `Fl_Window::xclass()`.

- `-scheme string`

  Sets the widget scheme using `Fl::scheme()`.

- `-title string`

  Sets the window title using `Fl_Window::label()`.

- `-tooltips` and `-notooltips`

  Enables or disables tooltips using `Fl_Tooltip::enable()`.

The second form of `Fl::args()` is useful if your program does not have command line switches of its own. It parses all the switches, and if any are not recognized it calls `Fl::abort(Fl::help)`.

A usage string is displayed if `Fl::args()` detects an invalid argument on the command-line. You can change the message by setting the `Fl::help` pointer.

#### void (*atclose)(Fl_Window*,void*);

#### void awake(void *p);

#### int awake(void (*callback)(void*), void *userdata);

The `awake()` method sends a message pointer to the main thread, causing any pending `Fl::wait()` call to terminate so that the main thread can retrieve the message and any pending redraws can be processed.

Multiple calls to `Fl::awake()` will queue multiple pointers for the main thread to process, up to a system-defined (typically several thousand) depth. The default message handler saves the last message which can be accessed using the `Fl::thread_message()` function.

The second form of `awake()` registers a function that will be called by the main thread during the next message handling cycle. `awake()` will return 0 if the callback function was registered, and -1 if registration failed. Over a thousand awake callbacks can be registered simultaneously.

See also: multithreading.

#### void background2(uchar, uchar, uchar);

Changes the alternative background color. This color is used as a background by `Fl_Input` and other text widgets.

This call may change `fl_color(FL_FOREGROUND_COLOR)` if it does not provide sufficient contrast to FL_BACKGROUND2_COLOR.

#### void background(uchar, uchar, uchar);

Changes `fl_color(FL_BACKGROUND_COLOR)` to the given color, and changes the gray ramp from 32 to 56 to black to white. These are the colors used as backgrounds by almost all widgets and used to draw the edges of all the boxtypes.

#### Fl_Widget* belowmouse();
void belowmouse(Fl_Widget*);

Get or set the widget that is below the mouse. This is for highlighting buttons. It is not used to send `FL_PUSH` or `FL_MOVE` directly, for several obscure reasons, but those events typically go to this widget. This is also the first widget tried for `FL_SHORTCUT` events.

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

#### int box_dh(Fl_Boxtype);

Returns the height offset for the given boxtype. See `box_dy`.

#### int box_dw(Fl_Boxtype);

Returns the width offset for the given boxtype. See `box_dy`.

#### int box_dx(Fl_Boxtype);

Returns the X offset for the given boxtype. See `box_dy`.

#### int box_dy(Fl_Boxtype);

Returns the Y offset for the given boxtype.

These functions return the offset values necessary for a given boxtype, useful for computing the area inside a box's borders, to prevent overdrawing the borders.

For instance, in the case of a boxtype like `FL_DOWN_BOX` where the border width might be 2 pixels all around, the above functions would return 2, 2, 4, and 4 for `box_dx`, `box_dy`, `box_dw`, and `box_dh` respectively.

An example to compute the area inside a widget's box():

          int X = yourwidget->x() + Fl::box_dx(yourwidget->box());
          int Y = yourwidget->y() + Fl::box_dy(yourwidget->box());
          int W = yourwidget->w() - Fl::box_dw(yourwidget->box());
          int H = yourwidget->h() - Fl::box_dh(yourwidget->box());

These functions are mainly useful in the `draw()` code for deriving custom widgets, where one wants to avoid drawing over the widget's own border `box()`.

#### int check();

Same as `Fl::wait(0)`. Calling this during a big calculation will keep the screen up to date and the interface responsive:

    while (!calculation_done()) {
     calculate();
     Fl::check();
     if (user_hit_abort_button()) break;
    }

The returns non-zero if any windows are displayed, and 0 if no windows are displayed (this is likely to change in future versions of FLTK).

#### int compose(int &del);

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

If true is returned, then it has modified the Fl::event_text() and Fl::event_length() to a set of bytes to insert (it may be of zero length!). In 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 Fl::compose().

If false is returned, the keys should be treated as function keys, and del is set to zero. You could insert the text anyways, if you don't know what else to do.

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 characters to be selected.

#### void compose_reset();

If the user moves the cursor, be sure to call Fl::compose_reset(). The next call to Fl::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, int clipboard);

Copies the data pointed to by `stuff` to the selection (0) or primary (1) clipboard. The selection clipboard is used for middle-mouse pastes and for drag-and-drop selections. The primary clipboard is used for traditional copy/cut/paste operations.

#### int damage();
void damage(int x);

If true then `flush()` will do something.

#### void default_atclose(Fl_Window*,void*);

This is the default callback for window widgets. It hides the window and then calls the default widget callback.

#### void delete_widget(Fl_Widget*);

Schedules a widget for deletion at the next call to the event loop. Use this method to delete a widget inside a callback function. To avoid early deletion of widgets, this function should be called toward the end of a callback and only after any call to the event loop (`Fl:wait()`, `Fl::flush()`, `fl_ask()`, etc).

When deleting groups or windows, you must only delete the group or window widget and not the individual child widgets.

#### void display(const char*);

Sets the X display to use for all windows. Actually this just sets the environment variable $DISPLAY to the passed string, so this only works before you show() the first window or otherwise open the display, and does nothing useful under WIN32.

#### int dnd();

Initiate a Drag And Drop operation. The clipboard should be filled with relevant data before calling this method. FLTK will then initiate the system wide drag and drop handling. Dropped data will be marked as text.

#### void dnd_text_ops(int d);
int dnd_text_ops();

Gets or sets whether drag and drop text operations are supported. This specifically affects whether selected text can be dragged from text fields or dragged within a text field as a cut/paste shortcut.

#### void (*error)(const char*, ...);

FLTK calls this to print a normal error message. You can override the behavior by setting the function pointer to your own routine.

`Fl::error` means there is a recoverable error such as the inability to read an image file. The default implementation prints the error message to `stderr` and returns.

#### int event_alt();

Returns non-zero if the Alt key is pressed.

#### int event_button1();

Returns non-zero if button 1 is currently held down. For more details, see `Fl::event_buttons()`.

#### int event_button2();

Returns non-zero if button 2 is currently held down. For more details, see `Fl::event_buttons()`.

#### int event_button3();

Returns non-zero if button 3 is currently held down. For more details, see `Fl::event_buttons()`.

#### int event_button();

Returns which mouse button caused te current event. This returns garbage if the most recent event was not a `FL_PUSH` or `FL_RELEASE` event.

#### int event_buttons();

Returns the button state bits; if non-zero, then at least one button is pressed. This function returns the button state at the time of the event. During an `FL_RELEASE` event, the state of the released button will be `0`. To find out, which button caused an `FL_RELEASE` event, you can use `Fl::event_button()` instead.

#### int event_clicks();
void event_clicks(int i);

The first form returns non-zero if the most recent `FL_PUSH` or `FL_KEYBOARD` was a "double click". Returns N-1 for N clicks. A double click is counted if the same button is pressed again while `event_is_click()` is true.

The second form directly sets the number returned by `Fl::event_clicks()`. This can be used to set it to zero so that later code does not think an item was double-clicked.

#### int event_ctrl();

Returns non-zero if the Control key is pressed.

#### int event();

Returns the last event that was processed. This can be used to determine if a callback is being done in response to a keypress, mouse click, etc.

#### int event_inside(int,int,int,int);
int event_inside(const Fl_Widget*);

Returns non-zero if the current `event_x` and `event_y` put it inside the widget or inside an arbitrary bounding box. You should always call this rather than doing your own comparison so you are consistent about edge effects.

#### int event_is_click();
void event_is_click(0);

The first form returns non-zero if the mouse has not moved far enough and not enough time has passed since the last `FL_PUSH` or `FL_KEYBOARD` event for it to be considered a "drag" rather than a "click". You can test this on `FL_DRAG`, `FL_RELEASE`, and `FL_MOVE` events. The second form clears the value returned by `Fl::event_is_click()`. Useful to prevent the next click from being counted as a double-click or to make a popup menu pick an item with a single click. Don't pass non-zero to this.

#### int event_key();
int event_key(int s);

`Fl::event_key()` returns which key on the keyboard was last pushed. It returns zero if the last event was not a key press or release.

`Fl::event_key(int)` 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.

`Fl::get_key(int)` returns true if the given key is held down now. Under X this requires a round-trip to the server and is much slower than `Fl::event_key(int)`.

Keys are identified by the unshifted values. FLTK defines a set of symbols that should work on most modern machines for every key on the keyboard:

- All keys on the main keyboard producing a printable ASCII character use the value of that ASCII character (as though shift, ctrl, and caps lock were not on). The space bar is 32.
- All keys on the numeric keypad producing a printable ASCII character use the value of that ASCII character plus `FL_KP`. The highest possible value is `FL_KP_Last` so you can range-check to see if something is on the keypad.
- All numbered function keys use the number on the function key plus `FL_F`. The highest possible number is `FL_F_Last`, so you can range-check a value.
- Buttons on the mouse are considered keys, and use the button number (where the left button is 1) plus `FL_Button`.
- All other keys on the keypad have a symbol: `FL_Escape, FL_BackSpace, FL_Tab, FL_Enter, FL_Print, FL_Scroll_Lock, FL_Pause, FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down, FL_Left, FL_Up, FL_Right, FL_Down, FL_Shift_L, FL_Shift_R, FL_Control_L, FL_Control_R, FL_Caps_Lock, FL_Alt_L, FL_Alt_R, FL_Meta_L, FL_Meta_R, FL_Menu, FL_Num_Lock, FL_KP_Enter`. Be careful not to confuse these with the very similar, but all-caps, symbols used by `Fl::event_state()` .

On X `Fl::get_key(FL_Button+n)` does not work.

On WIN32 `Fl::get_key(FL_KP_Enter)` and `Fl::event_key(FL_KP_Enter)` do not work.

#### int event_length();

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

#### int event_original_key();

If NumLock is deactivated, FLTK translates events from the numeric keypad into the corresponding arrow key events. `event_key()` returns the translated key code, whereas `event_original_key()` returns the keycode before NumLock translation.

#### int event_shift();

Returns non-zero if the Shift key is pressed.

#### int event_state();
int event_state(int i);

This is a bitfield of what shift states were on and what mouse buttons were held down during the most recent event. The second version returns non-zero if any of the passed bits are turned on. The legal bits are:

- `FL_SHIFT`
- `FL_CAPS_LOCK`
- `FL_CTRL`
- `FL_ALT`
- `FL_NUM_LOCK`
- `FL_META`
- `FL_SCROLL_LOCK`
- `FL_BUTTON1`
- `FL_BUTTON2`
- `FL_BUTTON3`

X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and FL_SCROLL_LOCK may not work. The values were selected to match the XFree86 server on Linux. In addition there is a bug in the way X works so that the shift state is not correctly reported until the first event after the shift key is pressed or released.

#### int event_x();

Returns the mouse position of the event relative to the `Fl_Window` it was passed to.

#### int event_x_root();

Returns the mouse position on the screen of the event. To find the absolute position of an `Fl_Window` on the screen, use the difference between `event_x_root(),event_y_root()` and `event_x(),event_y()`.

#### int event_y();

Returns the mouse position of the event relative to the `Fl_Window` it was passed to.

#### int event_y_root();

Returns the mouse position on the screen of the event. To find the absolute position of an `Fl_Window` on the screen, use the difference between `event_x_root(),event_y_root()` and `event_x(),event_y()`.

#### void (*fatal)(const char*, ...);

FLTK calls this to print a fatal error message. You can override the behavior by setting the function pointer to your own routine.

`Fl::fatal` must not return, as FLTK is in an unusable state, however your version may be able to use `longjmp` or an exception to continue, as long as it does not call FLTK again. The default implementation prints the error message to `stderr` and exits with status 1.

#### Fl_Window* first_window();
void first_window(Fl_Window*);

Returns the first top-level window in the list of shown() windows. If a modal() window is shown this is the top-most modal window, otherwise it is the most recent window to get an event.

The second form sets the window that is returned by first_window. The window is removed from wherever it is in the list and inserted at the top. This is not done if Fl::modal() is on or if the window is not shown(). Because the first window is used to set the "parent" of modal windows, this is often useful.

#### void flush();

Causes all the windows that need it to be redrawn and graphics forced out through the pipes. This is what `wait()` does before looking for events.

#### Fl_Widget* focus();
void focus(Fl_Widget*);

Get or set the widget that will receive `FL_KEYBOARD` events.

If you change `Fl::focus()`, the previous widget and all parents (that don't contain the new widget) are sent `FL_UNFOCUS` events. Changing the focus does not send `FL_FOCUS` to this or any widget, because sending `FL_FOCUS` is supposed to test if the widget wants the focus (by it returning non-zero from `handle()`).

#### void foreground(uchar, uchar, uchar);

Changes `fl_color(FL_FOREGROUND_COLOR)`.

#### void free_color(Fl_Color c, int overlay = 0);

Frees the specified color from the colormap, if applicable. If `overlay` is non-zero then the color is freed from the overlay colormap.

#### Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);

Gets the current box drawing function for the specified box type.

#### unsigned get_color(Fl_Color c);
void get_color(Fl_Color c, uchar&r, uchar&g, uchar&b);

Returns the RGB value(s) for the given FLTK color index. The first form returns the RGB values packed in a 32-bit unsigned integer with the red value in the upper 8 bits, the green value in the next 8 bits, and the blue value in bits 8-15. The lower 8 bits will always be 0.

The second form returns the red, green, and blue values separately in referenced variables.

#### const char* get_font(Fl_Font);

Get the string for this face. This string is different for each face. Under X this value is passed to XListFonts to get all the sizes of this face.

#### const char* get_font_name(Fl_Font, int* attributes = 0);

Get a human-readable string describing the family of this face. This is useful if you are presenting a choice to the user. There is no guarantee that each face has a different name. The return value points to a static buffer that is overwritten each call.

The integer pointed to by `attributes` (if the pointer is not zero) is set to zero, `FL_BOLD` or `FL_ITALIC` or `FL_BOLD | FL_ITALIC`. To locate a "family" of fonts, search forward and back for a set with non-zero attributes, these faces along with the face with a zero attribute before them constitute a family.

#### int get_font_sizes(Fl_Font, int*& sizep);

Return an array of sizes in `sizep`. The return value is the length of this array. The sizes are sorted from smallest to largest and indicate what sizes can be given to `fl_font()` that will be matched exactly (`fl_font()` will pick the closest size for other sizes). A zero in the first location of the array indicates a scalable font, where any size works, although the array may list sizes that work "better" than others. Warning: the returned array points at a static buffer that is overwritten each call. Under X this will open the display.

#### int get_key(int);

#### 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 `Fl::event_x_root()` and `Fl::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.

#### void get_system_colors();

Read the user preference colors from the system and use them to call `Fl::foreground()`, `Fl::background()`, and `Fl::background2()`. This is done by `Fl_Window::show(argc,argv)` before applying the -fg and -bg switches.

On X this reads some common values from the Xdefaults database. KDE users can set these values by running the "krdb" program, and newer versions of KDE set this automatically if you check the "apply style to other X programs" switch in their control panel.

#### int gl_visual(int, int *alist=0);

This does the same thing as `Fl::visual(int)` but also requires OpenGL drawing to work. This must be done if you want to draw in normal windows with OpenGL with `gl_start()` and `gl_end()`. It may be useful to call this so your X windows use the same visual as an `Fl_Gl_Window`, which on some servers will reduce colormap flashing.

See `Fl_Gl_Window` for a list of additional values for the argument.

#### Fl_Window* grab();
void grab(Fl_Window&w) {grab(&w);}

This is used when pop-up menu systems are active. Send all events to the passed window no matter where the pointer or focus is (including in other programs). The window does not have to be `shown()` , this lets the `handle()` method of a "dummy" window override all event handling and allows you to map and unmap a complex set of windows (under both X and WIN32 some window must be mapped because the system interface needs a window id).

If `grab()` is on it will also affect show() of windows by doing system-specific operations (on X it turns on override-redirect). These are designed to make menus popup reliably and faster on the system.

To turn off grabbing do `Fl::grab(0)`.

Be careful that your program does not enter an infinite loop while `grab()` is on. On X this will lock up your screen! To avoid this potential lockup, all newer operating systems seem to limit mouse pointer grabbing to the time during which a mouse button is held down. Some OS's may not support grabbing at all.

#### int h();

Returns the height of the screen in pixels.

#### int handle(int, Fl_Window*);

Sends the event to a window for processing. Returns non-zero if any widget uses the event.

#### int has_check(Fl_Timeout_Handler, void* = 0);

Returns true if the check exists and has not been called yet.

#### int has_idle(void (*cb)(void*), void* = 0);

Returns true if the specified idle callback is currently installed.

#### int has_timeout(Fl_Timeout_Handler, void* = 0);

Returns true if the timeout exists and has not been called yet.

#### void lock();

The `lock()` method blocks the current thread until it can safely access FLTK widgets and data. Child threads should call this method prior to updating any widgets or accessing data. The main thread must call `lock()` to initialize the threading support in FLTK.

Child threads must call `unlock()` when they are done accessing FLTK.

When the `wait()` method is waiting for input or timeouts, child threads are given access to FLTK. Similarly, when the main thread needs to do processing, it will wait until all child threads have called `unlock()` before processing additional data.

See also: multithreading

#### Fl_Window* modal();

Returns the top-most `modal()` window currently shown. This is the most recently `shown()` window with `modal()` true, or `NULL` if there are no `modal()` windows `shown()`. The `modal()` window has its `handle()` method called for all events, and no other windows will have `handle()` called (`grab()` overrides this).

#### Fl_Window* next_window(const Fl_Window*);

Returns the next top-level window in the list of shown() windows. You can use this call to iterate through all the windows that are shown().

#### void own_colormap();

Makes FLTK use its own colormap. This may make FLTK display better and will reduce conflicts with other programs that want lots of colors. However the colors may flash as you move the cursor between windows.

This does nothing if the current visual is not colormapped.

#### void paste(Fl_Widget &receiver, int clipboard=0);

Set things up so the receiver widget will be called with an `FL_PASTE` event some time in the future for the specified clipboard. 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 in FLTK.

#### Fl_Widget* pushed();
void pushed(Fl_Widget*);

Get or set the widget that is being pushed. `FL_DRAG` or `FL_RELEASE` (and any more `FL_PUSH`) events will be sent to this widget.

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

#### Fl_Widget* readqueue();

All `Fl_Widgets` that don't have a callback defined use a default callback that puts a pointer to the widget in this queue, and this method reads the oldest widget out of this queue.

#### int ready();

This is similar to `Fl::check()` except this does not call `Fl::flush()` or any callbacks, which is useful if your program is in a state where such callbacks are illegal. This returns true if `Fl::check()` would do anything (it will continue to return true until you call `Fl::check()` or `Fl::wait()`).

    while (!calculation_done()) {
     calculate();
     if (Fl::ready()) {
       do_expensive_cleanup();
       Fl::check();
       if (user_hit_abort_button()) break;
     }
    }

#### void redraw();

Redraws all widgets.

#### void release();

#### void remove_check(Fl_Timeout_Handler, void* = 0);

Removes a check callback. It is harmless to remove a check callback that no longer exists.

#### void remove_fd(int, int when);
void remove_fd(int);

Removes a file descriptor handler.

#### void remove_handler(int (*h)(int));

Removes a previously added event handler.

#### void remove_idle(void (*cb)(void*), void* = 0);

Removes the specified idle callback, if it is installed.

#### void remove_timeout(Fl_Timeout_Handler, void* = 0);

Removes a timeout callback. It is harmless to remove a timeout callback that no longer exists.

#### void repeat_timeout(double t, Fl_Timeout_Handler,void* = 0);

This method repeats a timeout callback from the expiration of the previous timeout, allowing for more accurate timing. You may only call this method inside a timeout callback.

The following code will print "TICK" each second on `stdout` with a fair degree of accuracy:

        void callback(void*) {
          puts("TICK");
          Fl::repeat_timeout(1.0, callback);
        }

        int main() {
          Fl::add_timeout(1.0, callback);
          return Fl::run();
        }

#### int run();

As long as any windows are displayed this calls `Fl::wait()` repeatedly. When all the windows are closed it returns zero (supposedly it would return non-zero on any errors, but FLTK calls exit directly for these). A normal program will end `main()` with `return Fl::run();`.

#### void scheme(const char *name);
const char *scheme();

Gets or sets the current widget scheme. `NULL` will use the scheme defined in the `FLTK_SCHEME` environment variable or the `scheme` resource under X11. Otherwise, any of the following schemes can be used:

- "none" - This is the default look-n-feel which resembles old Windows (95/98/Me/NT/2000) and old GTK/KDE
- "plastic" - This scheme is inspired by the Aqua user interface on Mac OS X
- "gtk+" - This scheme is inspired by the Red Hat Bluecurve theme

#### int screen_count();

Gets the number of available screens.

#### void screen_xywh(int &x, int &y, int &w, int &h);
void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my);
void screen_xywh(int &x, int &y, int &w, int &h, int n);

Gets the bounding box of a screen. The first form gets the bounding box for the screen the mouse pointer is in. The second form gets the bounding box for the screen that contains the specified coordinates. The last form gets the bounding box for the numbered screen, where `n` is a number from 0 to the number of screens less 1.

#### void scrollbar_size(int W);
int scrollbar_size();

Sets or gets the default scrollbar size that is used by the `Fl_Browser_`, `Fl_Help_View`, `Fl_Scroll`, and `Fl_Text_Display` widgets.

#### void selection(Fl_Widget &owner, const char* stuff, int len);

Changes the current selection. The block of text is copied to an internal buffer by FLTK (be careful if doing this in response to an `FL_PASTE` as this may be the same buffer returned by `event_text()`). The `selection_owner()` widget is set to the passed owner.

#### Fl_Widget* selection_owner();
void selection_owner(Fl_Widget*);

The single-argument `selection_owner(x)` call can be used to move the selection to another widget or to set the owner to `NULL`, without changing the actual text of the selection. `FL_SELECTIONCLEAR` is sent to the previous selection owner, if any.

Copying the buffer every time the selection is changed is obviously wasteful, especially for large selections. An interface will probably be added in a future version to allow the selection to be made by a callback function. The current interface will be emulated on top of this.

#### void set_abort(void (*f)(const char*,...));

#### void set_atclose(void (*f)(Fl_Window*,void*));

#### void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
void set_boxtype(Fl_Boxtype, Fl_Boxtype from);

The first form sets the function to call to draw a specific boxtype.

The second form copies the `from` boxtype.

#### void set_color(Fl_Color, uchar, uchar, uchar);
void set_color(Fl_Color, unsigned);

Sets an entry in the `fl_color` index table. You can set it to any 8-bit RGB color. The color is not allocated until `fl_color(i)` is used.

#### void set_font(Fl_Font, const char*);
void set_font(Fl_Font, Fl_Font);

The first form changes a face. The string pointer is simply stored, the string is not copied, so the string must be in static memory.

The second form copies one face to another.

#### Fl_Font set_fonts(const char* = 0);

FLTK will open the display, and add every font on the server to the face table. It will attempt to put "families" of faces together, so that the normal one is first, followed by bold, italic, and bold italic.

The optional argument is a string to describe the set of fonts to add. Passing `NULL` will select only fonts that have the ISO8859-1 character set (and are thus usable by normal text). Passing "-*" will select all fonts with any encoding as long as they have normal X font names with dashes in them. Passing "*" will list every font that exists (on X this may produce some strange output). Other values may be useful but are system dependent. With WIN32 `NULL` selects fonts with ISO8859-1 encoding and non-`NULL` selects all fonts.

The return value is how many faces are in the table after this is done.

#### void set_idle(void (*cb)());

Sets an idle callback.

This method is obsolete - use the `add_idle()` method instead.

#### void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
void set_labeltype(Fl_Labeltype, Fl_Labeltype from);

The first form sets the functions to call to draw and measure a specific labeltype.

The second form copies the `from` labeltype.

#### int test_shortcut(int);

Test the current event, which must be an `FL_KEYBOARD` or `FL_SHORTCUT`, against a shortcut value (described in `Fl_Button`). Returns non-zero if there is a match. Not to be confused with `Fl_Widget::test_shortcut()`.

#### void *thread_message();

The `thread_message()` method returns the last message that was sent from a child by the `awake()` method.

See also: multithreading

#### void unlock();

The `unlock()` method releases the lock that was set using the `lock()` method. Child threads should call this method as soon as they are finished accessing FLTK.

See also: multithreading

#### double version();

Returns the compiled-in value of the FL_VERSION constant. This is useful for checking the version of a shared library.

#### void visible_focus(int v);
int visible_focus();

Gets or sets the visible keyboard focus on buttons and other non-text widgets. The default mode is to enable keyboard focus for all widgets.

#### int visual(int);

Selects a visual so that your graphics are drawn correctly. This is only allowed before you call show() on any windows. This does nothing if the default visual satisfies the capabilities, or if no visual satisfies the capabilities, or on systems that don't have such brain-dead notions.

Only the following combinations do anything useful:

- `Fl::visual(FL_RGB)`
  Full/true color (if there are several depths FLTK chooses the largest). Do this if you use `fl_draw_image` for much better (non-dithered) output.
- `Fl::visual(FL_RGB8)`
  Full color with at least 24 bits of color. `FL_RGB` will always pick this if available, but if not it will happily return a less-than-24 bit deep visual. This call fails if 24 bits are not available.
- `Fl::visual(FL_DOUBLE|FL_INDEX)`
  Hardware double buffering. Call this if you are going to use `Fl_Double_Window`.
- `Fl::visual(FL_DOUBLE|FL_RGB)`
- `Fl::visual(FL_DOUBLE|FL_RGB8)`
  Hardware double buffering and full color.

This returns true if the system has the capabilities by default or FLTK suceeded in turing them on. Your program will still work even if this returns false (it just won't look as good).

#### int w();

Returns the width of the screen in pixels.

#### int wait();
double wait(double time);

Waits until "something happens" and then returns. Call this repeatedly to "run" your program. You can also check what happened each time after this returns, which is quite useful for managing program state.

What this really does is call all idle callbacks, all elapsed timeouts, call `Fl::flush()` to get the screen to update, and then wait some time (zero if there are idle callbacks, the shortest of all pending timeouts, or infinity), for any events from the user or any `Fl::add_fd()` callbacks. It then handles the events and calls the callbacks and then returns.

The return value of the first form is non-zero if there are any visible windows - this may change in future versions of FLTK.

The second form waits a maximum of time seconds. It can return much sooner if something happens.

The return value is positive if an event or fd happens before the time elapsed. It is zero if nothing happens (on Win32 this will only return zero if time is zero). It is negative if an error occurs (this will happen on UNIX if a signal happens).

#### void (*warning)(const char*, ...);

FLTK calls this to print a warning message. You can override the behavior by setting the function pointer to your own routine.

`Fl::warning` means that there was a recoverable problem, the display may be messed up but the user can probably keep working - all X protocol errors call this, for example.

#### int x();

Returns the origin of the current screen, where 0 indicates the left side of the screen.

#### int y();

Returns the origin of the current screen, where 0 indicates the top edge of the screen.

#### int event_dx();

Returns the current horizontal mouse scrolling associated with the `FL_MOUSEWHEEL` event. Right is positive.

#### int event_dy();

Returns the current vertical mouse scrolling assoaciated with the `FL_MOUSEWHEEL` event. Down is positive.

#### const char* event_text();

Returns the text associated with the current `FL_PASTE` or `FL_DND_RELEASE` event.