diff --git a/configh.in b/configh.in index 0c6531b18..f97f8008a 100644 --- a/configh.in +++ b/configh.in @@ -1,5 +1,5 @@ /* - * "$Id: configh.in,v 1.11.2.4 2000/06/07 12:11:52 mike Exp $" + * "$Id: configh.in,v 1.11.2.5 2000/06/18 00:38:37 bill Exp $" * * Configuration file for the Fast Light Tool Kit (FLTK). * @configure_input@ @@ -145,13 +145,13 @@ #define HAVE_SYS_SELECT_H 0 /* - * HAVE_POLL: + * USE_POLL: * - * Use poll() if we don't have select(). + * Use the poll() call provided on Linux and Irix instead of select() */ -#define HAVE_POLL 0 +#define USE_POLL 0 /* - * End of "$Id: configh.in,v 1.11.2.4 2000/06/07 12:11:52 mike Exp $". + * End of "$Id: configh.in,v 1.11.2.5 2000/06/18 00:38:37 bill Exp $". */ diff --git a/documentation/functions.html b/documentation/functions.html index 3a156c687..162b89400 100644 --- a/documentation/functions.html +++ b/documentation/functions.html @@ -1,841 +1,1041 @@ - -

B - Function Reference

- This appendix describes all of the fl_ functions and Fl:: - methods. For a description of the FLTK widgets, see -Appendix A. -

Functions

+ -

int fl_color_chooser(const char *title, double -&r, double &g, double &b) -
int fl_color_chooser(const char *title, uchar &r, uchar &g, uchar &b)
-

+

B - Function Reference

-The double version takes RGB values in the range 0.0 to 1.0. The -uchar version takes RGB values in the range 0 to 255. The title +This appendix describes all of the fl_ functions and Fl:: +methods. For a description of the FLTK widgets, see Appendix A. + +

Functions

+ +

int fl_color_chooser(const char +*title, double &r, double &g, double &b) +
int fl_color_chooser(const char *title, uchar &r, uchar &g, uchar &b)

+ +The double version takes RGB values in the range 0.0 to 1.0. The +uchar version takes RGB values in the range 0 to 255. The title argument specifies the label (title) for the window. -

+

-

fl_color_chooser() pops up a window to let the user pick an -arbitrary RGB color. They can pick the hue and saturation in the "hue -box" on the left (hold down CTRL to just change the saturation), and -the brighness using the vertical slider. Or they can type the 8-bit -numbers into the RGB -Fl_Value_Input fields, or drag the mouse across them to adjust -them. The pull-down menu lets the user set the input fields to show -RGB, HSV, or 8-bit RGB (0 to 255).

-

This returns non-zero if the user picks ok, and updates the RGB -values. If the user picks cancel or closes the window this returns -zero and leaves RGB unchanged.

-

If you use the color chooser on an 8-bit screen, it will allocate -all the available colors, leaving you no space to exactly represent the -color the user picks! You can however use -fl_rectf() to fill a region with a simulated color using -dithering.

-

int fl_show_colormap(int oldcol)

-fl_show_colormap() pops up a panel of the 256 colors you can -access with fl_color() and lets the user -pick one of them. It returns the new color index, or the old one if -the user types ESC or clicks outside the window. -

-

void fl_message(const char *, ...)

- Displays a printf-style message in a pop-up box with an "OK" button, -waits for the user to hit the button. The message will wrap to fit the -window, or may be many lines by putting \n characters into it. - The enter key is a shortcut for the OK button. -

-

void fl_alert(const char *, ...)

- Same as fl_message() except for the "!" symbol. -

-

int fl_ask(const char *, ...)

- Displays a printf-style message in a pop-up box with an "Yes" and "No" -button and waits for the user to hit a button. The return value is 1 -if the user hits Yes, 0 if they pick No. The enter key is a shortcut -for Yes and ESC is a shortcut for No. -

-

int fl_choice(const char *q, const char *b0, -const char *b1, const char *b2, ...)

+

fl_color_chooser() pops up a window to let the user pick an +arbitrary RGB color. They can pick the hue and saturation in the "hue +box" on the left (hold down CTRL to just change the saturation), and +the brighness using the vertical slider. Or they can type the 8-bit +numbers into the RGB +Fl_Value_Input fields, or drag the mouse across them to adjust +them. The pull-down menu lets the user set the input fields to show +RGB, HSV, or 8-bit RGB (0 to 255). - Shows the message with three buttons below it marked with the strings - b0, b1, and b2. Returns 0, 1, or 2 +

This returns non-zero if the user picks ok, and updates the RGB +values. If the user picks cancel or closes the window this returns +zero and leaves RGB unchanged. + +

If you use the color chooser on an 8-bit screen, it will allocate +all the available colors, leaving you no space to exactly represent the +color the user picks! You can however use +fl_rectf() to fill a region with a simulated color using +dithering. + +

int fl_show_colormap(int oldcol)

+ +fl_show_colormap() pops up a panel of the 256 colors you can +access with fl_color() and lets the user +pick one of them. It returns the new color index, or the old one if +the user types ESC or clicks outside the window. +

+ +

void fl_message(const char *, ...)

+ +Displays a printf-style message in a pop-up box with an "OK" button, +waits for the user to hit the button. The message will wrap to fit the +window, or may be many lines by putting \n characters into it. +The enter key is a shortcut for the OK button. +

+ +

void fl_alert(const char *, ...)

+ +Same as fl_message() except for the "!" symbol. +

+ +

int fl_ask(const char *, ...)

+ +Displays a printf-style message in a pop-up box with an +"Yes" and "No" button and waits for the user to +hit a button. The return value is 1 if the user hits Yes, 0 if they +pick No. The enter key is a shortcut for Yes and ESC is a shortcut +for No. + +

+ +

int fl_choice(const char *q, const char *b0, +const char *b1, const char *b2, ...)

+ +Shows the message with three buttons below it marked with the strings + b0, b1, and b2. Returns 0, 1, or 2 depending on which button is hit. ESC is a shortcut for button 0 and the enter key is a shortcut for button 1. Notice the buttons are positioned "backwards" You can hide buttons by passing -NULL as their labels. +NULL as their labels. -

-

const char *fl_input(const char *label, const char -*deflt = 0, ...)

- Pops up a window displaying a string, lets the user edit it, and -return the new value. The cancel button returns NULL. The -returned pointer is only valid until the next time fl_input() - is called. Due to back-compatability, the arguments to any printf -commands in the label are after the default value. -

-

const char *fl_password(const char *label, -const char *deflt = 0, ...)

- Same as fl_input() except an -Fl_Secret_Input field is used. -

-

void fl_message_font(Fl_Font fontid, uchar -size)

- Change the font and font size used for the messages in all the popups. -

Fl_Widget *fl_message_icon()

- Returns a pointer to the box at the left edge of all the popups. You -can alter the font, color, or label (including making it a Pixmap), -before calling the functions. -

char *fl_file_chooser(const char * message, -const char *pattern, const char *fname)

- FLTK provides a "tab completion" file chooser that makes it easy to -choose files from large directories. This file chooser has several -unique features, the major one being that the Tab key completes -filenames like it does in Emacs or tcsh, and the list always shows all -possible completions. -

-fl_file_chooser() pops up the file chooser, waits for the user -to pick a file or Cancel, and then returns a pointer to that filename -or NULL if Cancel is chosen. -

message is a string used to title the window.

-

pattern is used to limit the files listed in a directory to +

+ +

const char *fl_input(const char *label, const char +*deflt = 0, ...)

+ +Pops up a window displaying a string, lets the user edit it, and +return the new value. The cancel button returns NULL. The +returned pointer is only valid until the next time fl_input() +is called. Due to back-compatability, the arguments to any printf +commands in the label are after the default value. + +

+ +

const char *fl_password(const char *label, +const char *deflt = 0, ...)

+ +Same as fl_input() except an Fl_Secret_Input field is used. + +

+ +

void fl_message_font(Fl_Font fontid, uchar +size)

+ +Change the font and font size used for the messages in all the popups. + +

Fl_Widget *fl_message_icon()

+ +Returns a pointer to the box at the left edge of all the popups. You +can alter the font, color, or label (including making it a Pixmap), +before calling the functions. + +

char *fl_file_chooser(const char * message, +const char *pattern, const char *fname)

+ +FLTK provides a "tab completion" file chooser that makes it easy to +choose files from large directories. This file chooser has several +unique features, the major one being that the Tab key completes +filenames like it does in Emacs or tcsh, and the list always shows all +possible completions. + +

+ +fl_file_chooser() pops up the file chooser, waits for the user +to pick a file or Cancel, and then returns a pointer to that filename +or NULL if Cancel is chosen. + +

message is a string used to title the window. + +

pattern is used to limit the files listed in a directory to those matching the pattern. This matching is done by -filename_match(). Use NULL to show all files.

-

fname is a default filename to fill in the chooser with. - If this is NULL then the last filename that was choosen is -used (unless that had a different pattern, in which case just the last -directory with no name is used). The first time the file chooser is -called this defaults to a blank string.

-

The returned value points at a static buffer that is only good until -the next time fl_file_chooser() is called.

-

void fl_file_chooser_callback(void -(*cb)(const char *))

- Set a function that is called every time the user clicks a file in the -currently popped-up file chooser. This could be used to preview the -contents of the file. It has to be reasonably fast, and cannot create -FLTK windows. -

int filename_list(const char *d, dirent -***list)

- This is a portable and const-correct wrapper for the fl_scandir - function. d is the name of a directory (it does not matter if -it has a trailing slash or not). For each file in that directory a -"dirent" structure is created. The only portable thing about a dirent -is that dirent.d_name is the nul-terminated file name. An array of -pointers to these dirents is created and a pointer to the array is -returned in *list. The number of entries is given as a return -value. If there is an error reading the directory a number less than -zero is returned, and errno has the reason (errno - does not work under WIN32). The files are sorted in "alphanumeric" -order, where an attempt is made to put unpadded numbers in consecutive -order. -

You can free the returned list of files with the following code:

- -

int filename_isdir(const char *f)

- Returns non-zero if the file exists and is a directory. -

const char *filename_name(const char *f)

- Returns a pointer to the character after the last slash, or to the -start of the filename if there is none. -

const char *filename_ext(const char *f)

- Returns a pointer to the last period in filename_name(f), or -a pointer to the trailing nul if none. -

char *filename_setext(char *f, const char -*ext)

- Does strcpy(filename_ext(f), ext ? ext : ""). Returns a -pointer to f. -

int filename_expand(char *out, const char -*in)

- Splits in at each slash character. Replaces any occurrance -of $X with getenv("X") (leaving it as $X if -the environment variable does not exist). Replaces any occurances of -~X with user X's home directory (leaving it as ~X - if the user does not exist). Any resulting double slashes cause -everything before the second slash to be deleted. Copies the result to -out (in and out may be the same buffer). - Returns non-zero if any changes were made. In true retro -programming style, it is up to you to provide a buffer big enough for -the result. 1024 characters should be enough. -

int filename_absolute(char *out, const -char *in)

- If in does not start with a slash, this prepends the current -working directory to in and then deletes any occurances of -. and x/.. from the result, which it copies to out (in - and out may be the same buffer). Returns non-zero if any -changes were made. In true retro programming style, it is up to you -to provide a buffer big enough for the result. 1024 characters should +filename_match(). Use NULL to show all files. + +

fname is a default filename to fill in the chooser with. +If this is NULL then the last filename that was choosen is +used (unless that had a different pattern, in which case just the last +directory with no name is used). The first time the file chooser is +called this defaults to a blank string. + +

The returned value points at a static buffer that is only good until +the next time fl_file_chooser() is called. + +

void fl_file_chooser_callback(void +(*cb)(const char *))

+ +Set a function that is called every time the user clicks a file in the +currently popped-up file chooser. This could be used to preview the +contents of the file. It has to be reasonably fast, and cannot create +FLTK windows. + +

int filename_list(const char *d, dirent +***list)

+ +This is a portable and const-correct wrapper for the +fl_scandir function. d is the name of a directory +(it does not matter if it has a trailing slash or not). For each file +in that directory a "dirent" structure is created. The only +portable thing about a dirent is that dirent.d_name is the +nul-terminated file name. An array of pointers to these dirents is +created and a pointer to the array is returned in *list. The +number of entries is given as a return value. If there is an error +reading the directory a number less than zero is returned, and +errno has the reason (errno does not work under +WIN32). The files are sorted in "alphanumeric" order, where +an attempt is made to put unpadded numbers in consecutive order. + +

You can free the returned list of files with the following code: + +

+ +

int filename_isdir(const char *f)

+ +Returns non-zero if the file exists and is a directory. + +

const char *filename_name(const char *f)

+ +Returns a pointer to the character after the last slash, or to the +start of the filename if there is none. + +

const char *filename_ext(const char *f)

+ +Returns a pointer to the last period in filename_name(f), or +a pointer to the trailing nul if none. + +

char *filename_setext(char *f, const char +*ext)

+ +Does strcpy(filename_ext(f), ext ? ext : ""). Returns a +pointer to f. + +

int filename_expand(char *out, const char +*in)

+ +Splits in at each slash character. Replaces any occurrance +of $X with getenv("X") (leaving it as +$X if the environment variable does not exist). Replaces any +occurances of ~X with user X's home directory +(leaving it as ~X if the user does not exist). Any resulting +double slashes cause everything before the second slash to be deleted. +Copies the result to out (in and out may +be the same buffer). Returns non-zero if any changes were made. In +true retro programming style, it is up to you to provide a buffer big +enough for the result. 1024 characters should be enough. + +

int filename_absolute(char *out, const +char *in)

+ +If in does not start with a slash, this prepends the current +working directory to in and then deletes any occurances of +. and x/.. from the result, which it copies to out (in +and out may be the same buffer). Returns non-zero if any +changes were made. In true retro programming style, it is up to you +to provide a buffer big enough for the result. 1024 characters should be enough. -

int filename_match(const char *f, const char -*pattern)

- Returns true if f matches pattern. The following -syntax is used by pattern: + +

int filename_match(const char *f, const char +*pattern)

+ +Returns true if f matches pattern. The following +syntax is used by pattern: + -

Fl:: Methods

-

static void Fl::add_fd(int fd, void (*cb)(int, void -*), void * = 0) -
static void Fl::add_fd(int fd, int when, void (*cb)(int, void *), -void * = 0)
-
static void Fl::remove_fd(int)

-Add file descriptor fd to listen to. When the fd -becomes ready for reading the callback is done. The callback is -passed the fd and the arbitrary void * argument. -Fl::wait() will return immediately after calling the callback. -

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.

-

static void Fl::add_handler(int (*f)(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:: Methods

+ +

static void Fl::add_fd(int fd, void (*cb)(int, void +*), void* = 0) +
static void Fl::add_fd(int fd, int when, void (*cb)(int, void*), +void* = 0)
+
static void Fl::remove_fd(int)

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

static void Fl::add_handler(int (*f)(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: + -

static Fl::add_idle(void (*cb)(void *), void *)

-Adds a callback function that is called by Fl::wait() when -there is nothing to do. This can be used for background processing. -

Warning: this can absorb all your machine's time!

+ +

static Fl::add_idle(void (*cb)(void*), void*)

+ +Adds a callback function that is called every time by +Fl::wait() and also makes it act as though the timeout is +zero (so it just checks for events and returns immediately). This 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. However if you call -something that calls Fl::wait() or Fl::check() (such -as a message pop-up) you should first remove the idle callback so that -it does not recurse.

+href=#remove_idle>Fl::remove_idle(). -

static void Fl::add_timeout(float t, void -(*cb)(void *),void *v=0)

+

Fl::wait() and Fl::check() call idle callbacks, +but Fl::ready() does not. -Add a one-shot timeout callback. The timeout will happen as soon as -possible after t seconds after the last time wait() -was called. The optional void * argument is passed to the -callback. -

This code will print "TICK" each second on stdout, no matter what -else the user or program does:

- + +

static int Fl::arg(int argc, char **argv, int &i)

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

static int Fl::args(int argc, char **argv, int &i, int (*callback)(int, char**,int &)=0) -
void Fl::args(int argc, char **argv)

- 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. +
void Fl::args(int argc, char **argv) + +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 +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 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 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:

+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: +

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

static void Fl::background(uchar, uchar, uchar) -

- Changes fl_color(FL_GRAY) 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. -

static void Fl::background2(uchar, uchar, uchar) -

- Changes fl_color(FL_WHITE) and the same colors as -Fl::foreground(). This color is used as a background by -Fl_Input and other text widgets. -

static Fl_Widget *Fl::belowmouse() const -
static void Fl::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()).

-

static int Fl::box_dh(Fl_Boxtype)

- Returns the height offset for the given boxtype. -

static int Fl::box_dw(Fl_Boxtype)

- Returns the width offset for the given boxtype. -

static int Fl::box_dx(Fl_Boxtype)

- Returns the X offset for the given boxtype. -

static int Fl::box_dy(Fl_Boxtype)

- Returns the Y offset for the given boxtype. -

static int Fl::check()

- This does the same thing as Fl::wait(0), except because it -does not have to return the elapsed time value it can be implemented -faster on certain systems. Use this to interrupt a big calculation: - - This returns non-zero if any windows are displayed, and 0 if no -windows are displayed. -

static int Fl::damage()

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

static void Fl::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. -

static void Fl::enable_symbols()

- Enables the symbol drawing code. -

static int Fl::event_button()

- Returns which mouse button was pressed. This returns garbage if the -most recent event was not a FL_PUSH or FL_RELEASE - event. -

int Fl::event_clicks() -
void Fl::event_clicks(int)

- 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 Fl::event_inside(const Fl_Widget *) const -
int Fl::event_inside(int x, int y, int w, int h)

- 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 Fl::event_is_click() -
void Fl::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 Fl::event_key() -
int Fl::event_key(int)
-
int Fl::get_key(int)

-Fl::event_key() returns which key on the keyboard was last -pushed. -

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

static void Fl::background(uchar, uchar, uchar) +

+ +Changes fl_color(FL_GRAY) 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. + +

static void Fl::background2(uchar, uchar, uchar) +

+ +Changes fl_color(FL_WHITE) and the same colors as +Fl::foreground(). This color is used as a background by +Fl_Input and other text widgets. + +

static Fl_Widget *Fl::belowmouse() const +
static void Fl::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()). + +

static int Fl::box_dh(Fl_Boxtype)

+ +Returns the height offset for the given boxtype. + +

static int Fl::box_dw(Fl_Boxtype)

+ +Returns the width offset for the given boxtype. + +

static int Fl::box_dx(Fl_Boxtype)

+ +Returns the X offset for the given boxtype. + +

static int Fl::box_dy(Fl_Boxtype)

+ +Returns the Y offset for the given boxtype. + +

static int Fl::check()

+ +Same as Fl::wait(0). Calling this during a big calculation +will keep the screen up to date and the interface responsive: + + + +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). + +

static int Fl::damage()

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

static void Fl::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. + +

static void Fl::enable_symbols()

+ +Enables the symbol drawing code. + +

static int Fl::event_button()

+ +Returns which mouse button was pressed. This returns garbage if the +most recent event was not a FL_PUSH or FL_RELEASE +event. + +

int Fl::event_clicks() +
void Fl::event_clicks(int)

+ +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 Fl::event_inside(const Fl_Widget *) const +
int Fl::event_inside(int x, int y, int w, int h)

+ +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 Fl::event_is_click() +
void Fl::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 Fl::event_key() +
int Fl::event_key(int)
+
int Fl::get_key(int)

+ +Fl::event_key() returns which key on the keyboard was last +pushed. + +

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:

+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: +

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

-

char *Fl::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. -

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

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

char *Fl::event_text()

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

-

static int Fl::event_x() -
static int Fl::event_y()

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

static int Fl::event_x_root() -
static int Fl::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(). -

static Fl_Window *Fl::first_window()

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

char *Fl::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. + +

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

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

char *Fl::event_text()

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

static int Fl::event_x() +
static int Fl::event_y()

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

static int Fl::event_x_root() +
static int Fl::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(). + +

static Fl_Window *Fl::first_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. -

static Fl_Window *Fl::next_window(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(). +

static Fl_Window *Fl::next_window(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(). + +

static void Fl::first_window(Fl_Window*)

-

static void Fl::first_window(Fl_Window*)

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

static void Fl::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. -

static Fl_Widget *Fl::focus() const -
static void Fl::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()).

-

static void Fl::foreground(uchar, uchar, uchar) -

- Changes fl_color(FL_BLACK). Also changes -FL_INACTIVE_COLOR and FL_SELECTION_COLOR to be a ramp -between this and FL_WHITE. -

static void Fl::free_color(Fl_Color, 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. -

static unsigned Fl::get_color(Fl_Color) -
static void Fl::get_color(Fl_Color, uchar &r, uchar &g, uchar &b)
-

- Returns the color index or RGB value for the given FLTK color index. -

static const char *Fl::get_font(int face)

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

static void Fl::flush()

-

static const char *Fl::get_font_name(int -face, 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(int face, 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. -

static void Fl::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. -

static void Fl::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. -

Currently this only does something on WIN32. In future versions for -X it may read the window manager (KDE, Gnome, etc.) setup as well.

-

static int Fl::gl_visual(int)

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

-

static void Fl::grab(Fl_Window*) -
static Fl_Window* Fl::grab()

+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. - This is used when pop-up menu systems are active. Send all events to +

static Fl_Widget *Fl::focus() const +
static void Fl::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()). + +

static void Fl::foreground(uchar, uchar, uchar)

+ +Changes fl_color(FL_BLACK). Also changes +FL_INACTIVE_COLOR and FL_SELECTION_COLOR to be a ramp +between this and FL_WHITE. + +

static void Fl::free_color(Fl_Color, 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. + +

static unsigned Fl::get_color(Fl_Color) +
static void Fl::get_color(Fl_Color, uchar &r, uchar &g, uchar &b)

+ +Returns the color index or RGB value for the given FLTK color index. + +

static const char *Fl::get_font(int face)

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

static const char *Fl::get_font_name(int +face, 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(int face, 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. + +

static void Fl::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. + +

static void Fl::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. + +

static int Fl::gl_visual(int)

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

static void Fl::grab(Fl_Window*) +
static Fl_Window* Fl::grab()

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

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!

-

static int Fl::h()

- Returns the height of the screen in pixels. -

static int Fl::handle(int, Fl_Window *)

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

static const char *Fl::help

- This is the usage string that is displayed if Fl::args() - detects an invalid argument on the command-line. -

static Fl_Window *Fl::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). -

static void Fl::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.

-

static void Fl::paste(Fl_Widget *receiver)

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

static Fl_Widget *Fl::pushed() const -
static void Fl::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()).

-

static Fl_Widget *Fl::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. -

static int Fl::ready()

- Returns non-zero if there are pending timeouts or events or file -descriptors. This does not call Fl::flush() or any -callbacks, which is useful if your program is in a state where such -callbacks are illegal: - -

static void Fl::redraw()

- Redraws all widgets. -

static int Fl::has_idle(void (*cb)(void *), -void *= 0)

+

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

static int Fl::h()

+ +Returns the height of the screen in pixels. + +

static int Fl::handle(int, Fl_Window *)

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

static const char *Fl::help

+ +This is the usage string that is displayed if Fl::args() +detects an invalid argument on the command-line. + +

static Fl_Window *Fl::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). + +

static void Fl::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. + +

static void Fl::paste(Fl_Widget *receiver)

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

static Fl_Widget *Fl::pushed() const +
static void Fl::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()). + +

static Fl_Widget *Fl::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. + +

static int Fl::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()). + + + +

static void Fl::redraw()

+ +Redraws all widgets. + +

static int Fl::has_idle(void (*cb)(void*), void* = 0)

Returns true if the specified idle callback is currently installed. -

static void Fl::remove_idle(void (*cb)(void *), -void *= 0)

+

static void Fl::remove_idle(void (*cb)(void*), void* = 0)

Removes the specified idle callback, if it is installed. -

static int Fl::has_timeout(void -(*cb)(void *), void *= 0)

+

static int Fl::has_timeout(void (*cb)(void*), void* = 0)

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

static void Fl::remove_timeout(void -(*cb)(void *), void *= 0)

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

static Fl::run()

- Runs FLTK until there are no windows displayed, and then returns a -zero. Fl::run() is exactly equivalent to: - -

static void Fl::selection(Fl_Widget *owner, const +

static void Fl::remove_timeout(void (*cb)(void*), void* = 0)

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

static Fl::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();. + +

static void Fl::selection(Fl_Widget *owner, const char *stuff, int len) -
static const char* Fl::selection() -
static int Fl::selection_length()

- The first form 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 (possibly sending -FL_SELECTIONCLEAR to the previous owner). The second form looks -at the buffer containing the current selection. The contents of this -buffer are undefined if this program does not own the current -selection. -

static Fl_Widget *Fl::selection_owner() -const -
static void Fl::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.

-

static void Fl::set_boxtype(Fl_Boxtype, +
static const char* Fl::selection() +
static int Fl::selection_length()

+ +The first form 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 (possibly sending +FL_SELECTIONCLEAR to the previous owner). The second form looks +at the buffer containing the current selection. The contents of this +buffer are undefined if this program does not own the current +selection. + +

static Fl_Widget *Fl::selection_owner() const +
static void Fl::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. + +

static void Fl::set_boxtype(Fl_Boxtype, Fl_Box_Draw_F *, uchar, uchar, uchar, uchar) -
static void Fl::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.

-

static void Fl::set_color(Fl_Color, uchar r, -uchar g, uchar b)

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

static int Fl::set_font(int face, const char *) -
static int Fl::set_font(int face, int from)

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

-

int Fl::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.

-

static void Fl::set_labeltype(Fl_Labeltype, +
static void Fl::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. + +

static void Fl::set_color(Fl_Color, uchar r, +uchar g, uchar b)

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

static int Fl::set_font(int face, const char *) +
static int Fl::set_font(int face, int from)

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

int Fl::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. + +

static void Fl::set_labeltype(Fl_Labeltype, Fl_Label_Draw_F *, Fl_Label_Measure_F *) -
static void Fl: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 Fl::test_shortcut(ulong) const

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

static int Fl::visual(int)

- Selects a visual so that your graphics are drawn correctly. 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:

+
static void Fl: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 Fl::test_shortcut(ulong) const

+ +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(). + +

static int Fl::visual(int)

+ +Selects a visual so that your graphics are drawn correctly. You must +do this before calling 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: +

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

static int Fl::w()

- Returns the width of the screen in pixels. -

static int wait() -
static double wait(double time)

- Calls the idle function if any, then calls any pending timeout -functions, then calls Fl::flush(). If -there are any windows displayed it then waits some time for events -(zero if there is an idle(), the shortest timeout if there are any -timeouts, or forever) and calls the handle() function on those events, -and then returns non-zero. -

Your program can check its global state and update things after each -call to Fl::wait(), which can be very useful in complex -programs.

-

If there are no windows (this is checked after the idle and timeouts -are called) then Fl::wait() returns zero without waiting for -any events. Your program can either exit at this point, or call -show() on some window so the GUI can continue to operate. The -second form of Fl::wait() waits only a certain amount of time -for anything to happen. This does the same as wait() except -if the given time (in seconds) passes it returns. The return value is -how much time remains. If the return value is zero or negative then -the entire time period elapsed.

-

If you do several wait(time) calls in a row, the subsequent -ones are measured from when the first one is called, even if you do -time-consuming calculations after they return. This allows you to -accurately make something happen at regular intervals. This code will -accurately call A() once per second (as long as it takes less -than a second to execute):

- -

static void (*Fl::warning)(const char *, ...) -
static void (*Fl::error)(const char *, ...) -
static void (*Fl::fatal)(const char *, ...)

- FLTK will call these to print messages when unexpected conditions -occur. By default they fprintf to stderr, and -Fl::error and Fl::fatal call exit(1). You can -override the behavior by setting the function pointers to your own -routines. -

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). Fl::error means there is a -recoverable error, but the display is so messed up it is unlikely the -user can continue (very little calls this now). 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.

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

static int Fl::w()

+ +Returns the width of the screen in pixels. + +

static int Fl::wait()

+ +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 is non-zero if there are any visible windows (this +may change in future versions of fltk). + +

static double Fl::wait(double time)

+ +Same as Fl::wait() except it 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). + +

static void (*Fl::warning)(const char *, ...) +
static void (*Fl::error)(const char *, ...) +
static void (*Fl::fatal)(const char *, ...)

+ +FLTK will call these to print messages when unexpected conditions +occur. By default they fprintf to stderr, and +Fl::error and Fl::fatal call exit(1). You can +override the behavior by setting the function pointers to your own +routines. + +

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). Fl::error means there is a +recoverable error, but the display is so messed up it is unlikely the +user can continue (very little calls this now). 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. + + diff --git a/src/Fl.cxx b/src/Fl.cxx index 4792db339..d67235e9f 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl.cxx,v 1.24.2.26 2000/06/16 07:28:02 bill Exp $" +// "$Id: Fl.cxx,v 1.24.2.27 2000/06/18 00:38:39 bill Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -50,8 +50,6 @@ int Fl::damage_, char *Fl::e_text = ""; int Fl::e_length; -static double fl_elapsed(); - // // 'Fl:event_inside()' - Return whether or not the mouse event is inside // the given rectangle. @@ -67,6 +65,11 @@ int Fl::event_inside(const Fl_Widget *o) /*const*/ { return event_inside(o->x(),o->y(),o->w(),o->h()); } +//////////////////////////////////////////////////////////////// +// Timeouts and Fl::wait() + +void (*Fl::idle)(); + // Timeouts are insert-sorted into order. This works good if there // are only a small number: @@ -78,9 +81,131 @@ static struct Timeout { static int numtimeouts; static int timeout_array_size; +extern int fl_wait(double time); // warning: assummes time >= 0.0 +extern int fl_ready(); + +#ifndef WIN32 +#include +#endif + +// I avoid the overhead of getting the current time when we have no +// timeouts by setting this flag instead of getting the time. +// In this case calling elapse_timeouts() does nothing, but records +// the current time, and the next call will actualy elapse time. +static char reset_clock = 1; + +static void elapse_timeouts() { + +#ifdef WIN32 + + unsigned long newclock = GetTickCount(); + static unsigned long prevclock; + if (reset_clock) { + prevclock = newclock; + reset_clock = 0; + return; + } + if (newclock <= prevclock) return; + double elapsed = (newclock-prevclock)/1000.0; + prevclock = newclock; + +#else + + static struct timeval prevclock; + struct timeval newclock; + gettimeofday(&newclock, NULL); + if (reset_clock) { + prevclock.tv_sec = newclock.tv_sec; + prevclock.tv_usec = newclock.tv_usec; + reset_clock = 0; + return; + } + double elapsed = newclock.tv_sec - prevclock.tv_sec + + (newclock.tv_usec - prevclock.tv_usec)/1000000.0; + prevclock.tv_sec = newclock.tv_sec; + prevclock.tv_usec = newclock.tv_usec; + if (elapsed <= 0) return; + +#endif + + for (int i=0; i 0) break; + // The first timeout in the array has expired. + // We must remove timeout from array before doing the callback: + void (*cb)(void*) = timeout[0].cb; + void *arg = timeout[0].arg; + numtimeouts--; + if (numtimeouts) + memmove(timeout, timeout+1, numtimeouts*sizeof(Timeout)); + // Now it is safe for the callback to do add_timeout: + in_timeout = 1; + cb(arg); + in_timeout = 0; + } + } else { + reset_clock = 1; // we are not going to check the clock + } + if (idle) { + if (!in_idle) {in_idle = 1; idle(); in_idle = 0;} + // the idle function may turn off idle, we can then wait: + if (idle) time_to_wait = 0.0; + } + if (time_to_wait <= 0.0) { + // do flush second so that the results of events are visible: + int ret = fl_wait(0.0); + flush(); + return ret; + } else { + // do flush first so that user sees the display: + flush(); + return fl_wait(time_to_wait); + } +} + +#define FOREVER 1e20 + +int Fl::run() { + while (Fl_X::first) wait(FOREVER); + return 0; +} + +int Fl::wait() { + wait(FOREVER); + return Fl_X::first != 0; // return true if there is a window +} + +int Fl::check() { + wait(0.0); + return Fl_X::first != 0; // return true if there is a window +} + +int Fl::ready() { + if (numtimeouts) { + elapse_timeouts(); + if (timeout[0].time <= 0) return 1; + } else { + reset_clock = 1; + } + return fl_ready(); +} + void Fl::add_timeout(double t, Fl_Timeout_Handler cb, void *v) { - fl_elapsed(); + // This little test gets rid of about half the calls to get the time + // and has the added advantage of making timeouts that think they + // are happening at regular intervals actually happen at regular + // intervals: + if (!in_timeout) elapse_timeouts(); if (numtimeouts >= timeout_array_size) { timeout_array_size = 2*timeout_array_size+1; @@ -117,145 +242,6 @@ void Fl::remove_timeout(Fl_Timeout_Handler cb, void *v) { numtimeouts = j; } -static int call_timeouts() { - int expired = 0; - while (numtimeouts) { - if (timeout[0].time > 0) break; - // we must remove timeout from array before doing the callback: - void (*cb)(void*) = timeout[0].cb; - void *arg = timeout[0].arg; - numtimeouts--; expired++; - if (numtimeouts) memmove(timeout, timeout+1, numtimeouts*sizeof(Timeout)); - // now it is safe for the callback to do add_timeout: - cb(arg); - } - return expired; -} - -void Fl::flush() { - if (damage()) { - damage_ = 0; - for (Fl_X* x = Fl_X::first; x; x = x->next) { - if (x->w->damage() && x->w->visible_r()) { - if (x->wait_for_expose) { - // leave Fl::damage() set so programs can tell damage still exists - damage_ = 1; - } else { - x->flush(); - x->w->clear_damage(); - } - } - } - } -#ifndef WIN32 - if (fl_display) XFlush(fl_display); -#endif -} - -extern double fl_wait(int timeout_flag, double timeout); -extern int fl_ready(); - -static int initclock; // if false we didn't call fl_elapsed() last time - -#ifndef WIN32 -#include -#endif - -// fl_elapsed must return the amount of time since the last time it was -// called. To reduce the number of system calls to get the -// current time, the "initclock" symbol is turned on by an indefinite -// wait. This should then reset the measured-from time and return zero -static double fl_elapsed() { - -#ifdef WIN32 - - unsigned long newclock = GetTickCount(); - const int TICKS_PER_SECOND = 1000; // divisor of the value to get seconds - static unsigned long prevclock; - if (!initclock) {prevclock = newclock; initclock = 1; return 0.0;} - else if (newclock < prevclock) return 0.0; - - double t = double(newclock-prevclock)/TICKS_PER_SECOND; - prevclock = newclock; - -#else - - static struct timeval prevclock; - struct timeval newclock; - gettimeofday(&newclock, NULL); - if (!initclock) { - prevclock.tv_sec = newclock.tv_sec; - prevclock.tv_usec = newclock.tv_usec; - initclock = 1; - return 0.0; - } - double t = newclock.tv_sec - prevclock.tv_sec + - (newclock.tv_usec - prevclock.tv_usec)/1000000.0; - prevclock.tv_sec = newclock.tv_sec; - prevclock.tv_usec = newclock.tv_usec; - -#endif - - // expire any timeouts: - if (t > 0.0) for (int i=0; inext) x->w->redraw(); } +void Fl::flush() { + if (damage()) { + damage_ = 0; + for (Fl_X* x = Fl_X::first; x; x = x->next) { + if (x->w->damage() && x->w->visible_r()) { + if (x->wait_for_expose) { + // leave Fl::damage() set so programs can tell damage still exists + damage_ = 1; + } else { + x->flush(); + x->w->clear_damage(); + } + } + } + } +#ifndef WIN32 + if (fl_display) XFlush(fl_display); +#endif +} + //////////////////////////////////////////////////////////////// // Event handlers: @@ -727,5 +733,5 @@ void Fl_Window::flush() { } // -// End of "$Id: Fl.cxx,v 1.24.2.26 2000/06/16 07:28:02 bill Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.27 2000/06/18 00:38:39 bill Exp $". // diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 4e4d5afb2..982044ab3 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.33.2.26 2000/06/05 21:21:02 mike Exp $" +// "$Id: Fl_win32.cxx,v 1.33.2.27 2000/06/18 00:38:40 bill Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -151,24 +151,14 @@ void Fl::remove_fd(int n) { MSG fl_msg; -int fl_ready() { - if (PeekMessage(&fl_msg, NULL, 0, 0, PM_NOREMOVE)) return 1; +#define FOREVER 1e20 -#ifdef USE_ASYNC_SELECT - return (0); -#else - timeval t; - t.tv_sec = 0; - t.tv_usec = 0; - fd_set fdt[3]; - fdt[0] = fdsets[0]; - fdt[1] = fdsets[1]; - fdt[2] = fdsets[2]; - return ::select(0,&fdt[0],&fdt[1],&fdt[2],&t); -#endif // USE_ASYNC_SELECT -} - -double fl_wait(int timeout_flag, double time) { +// This is never called with time_to_wait < 0.0. +// It *should* return negative on error, 0 if nothing happens before +// timeout, and >0 if any callbacks were done. This version only +// returns zero if nothing happens during a 0.0 timeout, otherwise +// it returns 1. +int fl_wait(double time_to_wait) { int have_message = 0; int timerid; @@ -195,46 +185,29 @@ double fl_wait(int timeout_flag, double time) { if (FD_ISSET(f,&fdt[2])) revents |= POLLERR; if (fd[i].events & revents) fd[i].cb(f, fd[i].arg); } + time_to_wait = 0.0; // just peek for any messages + } else { + // we need to check them periodically, so set a short timeout: + if (time_to_wait > .001) time_to_wait = .001; } } #endif // USE_ASYNC_SELECT - // get the first message by waiting the correct amount of time: - if (!timeout_flag) { -#ifdef USE_ASYNC_SELECT - // Wait for a message... - have_message = GetMessage(&fl_msg, NULL, 0, 0); -#else - // If we are monitoring sockets we need to check them periodically, - // so set a timer in this case... - if (nfds) { - // First see if there is a message waiting... - have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE); - if (!have_message) { - // If not then set a 1ms timer... - timerid = SetTimer(NULL, 0, 1, NULL); - GetMessage(&fl_msg, NULL, 0, 0); - KillTimer(NULL, timerid); - } - } else { - // Wait for a message... - GetMessage(&fl_msg, NULL, 0, 0); - } - have_message = 1; -#endif // USE_ASYNC_SELECT - } else { + if (time_to_wait < 2147483.648) { // Perform the requested timeout... have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE); - if (!have_message && time > 0.0) { - int t = (int)(time * 1000.0); - if (t <= 0) t = 1; + if (!have_message) { + int t = (int)(time_to_wait * 1000.0 + .5); + if (t <= 0) return 0; // too short to measure timerid = SetTimer(NULL, 0, t, NULL); have_message = GetMessage(&fl_msg, NULL, 0, 0); KillTimer(NULL, timerid); } + } else { + have_message = GetMessage(&fl_msg, NULL, 0, 0); } - // execute it, them execute any other messages that become ready during it: + // Execute the message we got, and all other pending messages: while (have_message) { #ifdef USE_ASYNC_SELECT if (fl_msg.message == WM_FLSELECT) { @@ -244,20 +217,33 @@ double fl_wait(int timeout_flag, double time) { (fd[i].cb)(fd[i].fd, fd[i].arg); break; } - } else { - // Some other message... - TranslateMessage(&fl_msg); - DispatchMessage(&fl_msg); + // looks like it is best to do the dispatch-message anyway: } -#else +#endif TranslateMessage(&fl_msg); DispatchMessage(&fl_msg); -#endif // USE_ASYNC_SELECT - have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE); } - return time; + // This should return 0 if only timer events were handled: + return 1; +} + +// fl_ready() is just like fl_wait(0.0) except no callbacks are done: +int fl_ready() { + if (PeekMessage(&fl_msg, NULL, 0, 0, PM_NOREMOVE)) return 1; +#ifdef USE_ASYNC_SELECT + return (0); +#else + timeval t; + t.tv_sec = 0; + t.tv_usec = 0; + fd_set fdt[3]; + fdt[0] = fdsets[0]; + fdt[1] = fdsets[1]; + fdt[2] = fdsets[2]; + return ::select(0,&fdt[0],&fdt[1],&fdt[2],&t); +#endif // USE_ASYNC_SELECT } //////////////////////////////////////////////////////////////// @@ -967,5 +953,5 @@ void Fl_Window::make_current() { } // -// End of "$Id: Fl_win32.cxx,v 1.33.2.26 2000/06/05 21:21:02 mike Exp $". +// End of "$Id: Fl_win32.cxx,v 1.33.2.27 2000/06/18 00:38:40 bill Exp $". // diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 1819254d0..3828cde8f 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_x.cxx,v 1.24.2.17 2000/06/05 21:21:03 mike Exp $" +// "$Id: Fl_x.cxx,v 1.24.2.18 2000/06/18 00:38:41 bill Exp $" // // X specific code for the Fast Light Tool Kit (FLTK). // @@ -45,7 +45,7 @@ //////////////////////////////////////////////////////////////// // interface to poll/select call: -#if HAVE_POLL +#if USE_POLL #include static pollfd *pollfds = 0; @@ -65,13 +65,15 @@ static int maxfd; #define POLLOUT 4 #define POLLERR 8 -#endif /* HAVE_POLL */ +#endif /* USE_POLL */ static int nfds = 0; static int fd_array_size = 0; static struct FD { +#if !USE_POLL int fd; short events; +#endif void (*cb)(int, void*); void* arg; } *fd = 0; @@ -82,18 +84,18 @@ void Fl::add_fd(int n, int events, void (*cb)(int, void*), void *v) { if (i >= fd_array_size) { fd_array_size = 2*fd_array_size+1; fd = (FD*)realloc(fd, fd_array_size*sizeof(FD)); -#if HAVE_POLL +#if USE_POLL pollfds = (pollfd*)realloc(pollfds, fd_array_size*sizeof(pollfd)); #endif } - fd[i].fd = n; - fd[i].events = events; fd[i].cb = cb; fd[i].arg = v; -#if HAVE_POLL - fds[i].fd = n; - fds[i].events = events; +#if USE_POLL + pollfds[i].fd = n; + pollfds[i].events = events; #else + fd[i].fd = n; + fd[i].events = events; if (events & POLLIN) FD_SET(n, &fdsets[0]); if (events & POLLOUT) FD_SET(n, &fdsets[1]); if (events & POLLERR) FD_SET(n, &fdsets[2]); @@ -108,25 +110,30 @@ void Fl::add_fd(int fd, void (*cb)(int, void*), void* v) { void Fl::remove_fd(int n, int events) { int i,j; for (i=j=0; i0 if any callbacks were done. +int fl_wait(double time_to_wait) { // OpenGL and other broken libraries call XEventsQueued // unnecessarily and thus cause the file descriptor to not be ready, // so we must check for already-read events: - if (XQLength(fl_display)) {do_queued_events(); return time;} + if (fl_display && XQLength(fl_display)) {do_queued_events(); return 1;} -#if !HAVE_POLL +#if !USE_POLL fd_set fdt[3]; fdt[0] = fdsets[0]; fdt[1] = fdsets[1]; @@ -187,31 +181,26 @@ double fl_wait(int timeout_flag, double time) { #endif int n; - if (!timeout_flag) { -#if HAVE_POLL - n = ::poll(fds, nfds, -1); -#else - n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],0); -#endif - } else { -#if HAVE_POLL - int n = ::poll(fds, nfds, time > 0.0 ? int(time*1000) : 0); + if (time_to_wait < 2147483.648) { +#if USE_POLL + n = ::poll(pollfds, nfds, int(time_to_wait*1000 + .5)); #else timeval t; - if (time <= 0.0) { - t.tv_sec = 0; - t.tv_usec = 0; - } else { - t.tv_sec = int(time); - t.tv_usec = int(1000000 * (time-t.tv_sec)); - } + t.tv_sec = int(time_to_wait); + t.tv_usec = int(1000000 * (time_to_wait-t.tv_sec)); n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); +#endif + } else { +#if USE_POLL + n = ::poll(pollfds, nfds, -1); +#else + n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],0); #endif } if (n > 0) { for (int i=0; i