Fltk Utility functions

Fltk has several "utility" functions. All these functions are optional: if you don't call them fltk has been written so that their code is not linked into your program. So if you don't like them, there is no loss if you don't use them.

#include <FL/fl_ask.H>

void fl_message(const char *);


Displays a 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. Return 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 message in a pop-up box with an "Yes" and "No" button, waits for the user to hit the button. The message may be many lines by putting \n characters into it. The return value is 1 if the user hits Yes, 0 if they pick No. Return is a shortcut for Yes, Escape 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. Escape is a shortcut for button 0, and Return is a shortcut for button 1. Notice the "misordered" position of the buttons. You can hide buttons by passing 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.

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.

#include <FL/fl_file_chooser.H>

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.

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


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.

#include <FL/filename.H>

This header defines several filename utility functions used by the file chooser. You can call them yourself if it is useful.

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

int filename_isdir(const char *f);

const char *filename_name(const char *f);

const char *filename_ext(const char *f);

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

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

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

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

(back to contents)