Inherited by AnsiWidget, fltk::Button, fltk::ccCellBox, fltk::ccHueBox, fltk::ccValueBox, fltk::ClockOutput, fltk::Divider, fltk::Group, fltk::Input, fltk::InvisibleBox, fltk::Item, fltk::ProgressBar, and fltk::Valuator.
|bool||active () const|
|bool||active_r () const|
|void||add (const AssociationType &, void *data)|
|bool||add_shortcut (unsigned key)|
|void||align (unsigned a)|
|bool||all_of (unsigned f) const|
|bool||any_of (unsigned f) const|
|void||argument (long v)|
|bool||belowmouse () const|
|void||callback (Callback *c)|
|void||callback (Callback1 *c, long p=0)|
|void||callback (Callback *c, void *p)|
|void||clear_flag (unsigned f)|
|bool||contains (const Widget *) const|
|void||copy_label (const char *a)|
|bool||copy_style (const Style *s)|
|void||cursor (Cursor *) const|
|uchar||damage () const|
|void||do_callback (Widget *o, void *arg=0)|
|void||do_callback (Widget *o, long arg)|
|virtual void||draw ()|
|void||draw_background () const|
|void||draw_box () const|
|void||draw_frame () const|
|void||draw_glyph (int, const Rectangle &) const|
|void||draw_label () const|
|void||draw_label (const Rectangle &, Flags) const|
|bool||find (const AssociationType &, void *data) const|
|bool||flag (unsigned f) const|
|Flags||flags () const|
|void||flags (Flags f)|
|bool||focused () const|
|void *||foreach (const AssociationType &, AssociationFunctor &) const|
|void *||get (const AssociationType &) const|
|void||get_absolute_rect (Rectangle *rect) const|
|virtual int||handle (int)|
|bool||horizontal () const|
|void||invert_flag (unsigned f)|
|bool||is_group () const|
|bool||is_window () const|
|void||label (const char *a)|
|unsigned||label_shortcut () const|
|virtual void||layout ()|
|uchar||layout_damage () const|
|void||layout_damage (uchar c)|
|void||make_current () const|
|void||measure_label (int &, int &) const|
|bool||output () const|
|Group *||parent () const|
|bool||position (int x, int y)|
|bool||pushed () const|
|void||redraw (const Rectangle &)|
|void||redraw (uchar c)|
|bool||remove (const AssociationType &, void *data)|
|bool||remove_shortcut (unsigned key)|
|bool||resize (int x, int y, int w, int h)|
|bool||resize (int w, int h)|
|int||send (int event)|
|void||set (const AssociationType &, void *data)|
|void||set_damage (uchar c)|
|void||set_flag (unsigned f)|
|void||set_flag (unsigned f, bool b)|
|unsigned||shortcut () const|
|void||shortcut (unsigned key)|
|bool||state () const|
|bool||test_label_shortcut () const|
|bool||test_shortcut () const|
|bool||test_shortcut (bool) const|
|uchar||type () const|
|void||user_data (void *v)|
|bool||vertical () const|
|bool||visible_r () const|
|void||when (uchar i)|
|Widget (int, int, int, int, const char *=0)|
|Window *||window () const|
|static void||default_callback (Widget *, void *)|
|static Symbol *||default_glyph = &::glyph|
The base class for all widgets in FLTK. The basic Widget draws an empty box() and the label(), and ignores all events. This can be useful for making decorations or providing areas that pop up a tooltip().
|const char *||L =
Standard constructor for a widget. The default constructor takes a value for x(), y(), w(), and h(), and an optional value for label(). All subclasses must provide an identical constructor in order to work with Fluid. They may also provide alternative constructors.
If Group::begin() has been called, this widget is added as a new child of that group, and parent() is set to the group. If Group::begin() has not been called, or Group::end() has been called, or Group::current(0), then the parent() is set to null. In this case you must add the widget yourself in order to see it.
The destructor is virtual. The base class removes itself from the parent widget (if any), and destroys any label made with copy_label().
|bool Widget::active||(||)|| const
|void Widget::add||(||const AssociationType &||at,|
Add an association to a this widget. The associated data is of the given association type. The associated data must not be NULL. NULL is simply not added as association.
Add a new shortcut assignment. Returns true if successful. If key is zero or the assignment already exists this does nothing and returns false.
There can be any number of shortcut assignments, fltk stores them in internal tables shared by all widgets. A widget can have any number of shortcuts (though most have zero or one), and a given shortcut value can be assigned to more than one widget.
If you only want one shortcut use shortcut() to assign it.
The shortcut value is a bitwise OR (or sum) of a any set of shift flags returned by fltk::event_state(), and either a key symbol returned by fltk::event_key(), or an ASCII character from fltk::event_text(). Examples:
'A' will only match if the Shift key is not held down, and
fltk::SHIFT+'a' will only match if the shift key is held down. Case (and thus Caps Lock) is ignored. The case does control how the shortcut is displayed in a menu so you will want to choose based on the style of your application.
fltk::SHIFT will match whether or not Shift is held down. Since both fltk::event_key() and fltk::event_text() are matched, the '#' can be specified by any of
fltk::SHIFT+'#', or by
'#'. You can choose based on how you want the shortcut to appear in menus and how you want to map to foreign keyboards.
When FLTK gets a keystroke, it sends it to the fltk::focus() widget. If that widget's handle() returns 0, it will also send the keystroke to all parents of that widget (this is mostly for keyboard navigation to work). If all of them return 0, or the fltk::focus() is null, then it will try sending a SHORTCUT event to every single widget inside the same window as the focus until one of them returns non-zero. In most cases widgets will call Widget::test_shortcut() to see if the keystroke is registered here (many widgets will also directly test the key to see if it is something they are interested in).
Call handle(TIMEOUT) at the given time in the future. This will happen exactly once. To make it happen repeatedly, call repeat_timeout() from inside handle(TIMEOUT).
Forces the values of all the fltk::ALIGN_* flags to the passed value. This determines how the label is printed next to or inside the widget. The default value is fltk::ALIGN_CENTER, which centers the label. The value can be any of the ALIGN flags or'd together.
|bool Widget::all_of||(||unsigned||f||)|| const
Returns true if all of the bits in f are on. f should be several bits or'd together, otherwise this is the same as flag(f).
|bool Widget::any_of||(||unsigned||f||)|| const
Returns true if any of the bits in f are on. Actually this is the same function as flag(f) but using this may make the code more readable.
Sets the second argument to the callback to a number. This is done by casting the long to a void*.
|void Widget::callback||(||fltk::Callback *||c,|
void Widget::image(Image*) Sets the image. The image is drawn as part of the label, usually to the left of the text. This is designed for icons on menu items. If you want to replace the entire background of the widget with a picture you should set box() instead. Notice that you can also get images into labels by putting '@' commands into the label().
void Widget::tooltip(const char*) Set the string used as the pop-up tooltip. The pointer to the passed string is stored, it is not copied! Passing null indicates that the tooltip of the parent() should be used (or no tooltip if no parent has one). If you want to disable the tooltip but let the parent have one, set this tooltip to
Putting '@' commands in to bring up Symbol objects will allow a lot of interesting things to be put into the tooltip.
Each widget has a single callback. You can set it or examine it with these methods. The callback is called with the widget as the first argument and the void* as the second argument. It is called in response to user events, but exactly whe depends on the widget. For instance a button calls it when the button is released.
|void Widget::callback||(||fltk::Callback1 *||c,|
For convenience you can also define the callback as taking a long integer argument. This is implemented by casting the function to a fltk::Callback and casting the
long to a
void* and may not be portable to some machines.
|void Widget::callback||(||Callback *||c||)||
Same as state(false). If you know the widget will already be redrawn, or it is not displayed, it is faster to call the inline clear_flag(STATE) function.
Reimplemented in fltk::Group.
Make flag(f) return false by turning off that bit. You can turn off multiple bits by or'ing them toegher.
|bool Widget::contains||(||const Widget *||b||)||const|
Returns true if b is a child of this widget, or is equal to this widget. Returns false if b is NULL.
|void Widget::copy_label||(||const char *||s||)|
Sets the label to a copy of the string. The passed string is copied to private storage and used to set the label(). The memory will be freed when the widget is destroyed or when copy_label() is called again, or label(const char*) is called.
Passing NULL will set label() to NULL.
Reimplemented in fltk::Window.
|bool Widget::copy_style||(||const Style *||t||)|
Copy the Style from another widget. Copying a style pointer from another widget is not safe if that style is dynamic() because it may change or be deleted. This makes another dynamic() copy if necessary. For non-dynamic styles the pointer is copied.
|void Widget::cursor||(||Cursor *||c||)||const|
Change the cursor being displayed on the screen. A widget should do this in response to
fltk::MOVE events. FLTK will change it back to
fltk::CURSOR_DEFAULT if the mouse is moved outside this widget, unless another widget calls this.
On X you can mess with the colors by setting the Color variables
fl_cursor_bg to the colors you want, before calling this.
|uchar Widget::damage||(||)|| const
|void Widget::default_callback||(||Widget *||w,|
This is the initial value for callback(). It does set_changed() on the widget, thus recording the fact that the callback was done. Do not set the callback to zero, use this if you want no action.
Reimplemented in fltk::Menu.
You can cause a widget to do its callback at any time. The callback function is called with this and user_data() as arguments.
|void Widget::do_callback||(||Widget *||o,|
|void *||arg =
You can also call the callback function with arbitrary arguments.
|void Widget::do_callback||(||Widget *||o,|
You can also call the callback function with arbitrary arguments.
Fltk calls this virtual function to draw the widget, after setting up the graphics (current window, xy translation, etc) so that any drawing functions will go into this widget.
User code should not call this! You probably want to call redraw().
The default version calls draw_box() and draw_label(), thus drawing the box() to fill the widget and putting the label() and image() inside it to fill it, unless the align() flags are set to put it outside.
Information on how to write your own version is here.
Reimplemented in fltk::Adjuster, fltk::Browser, fltk::Button, fltk::CheckButton, fltk::Choice, fltk::ClockOutput, fltk::CycleButton, fltk::Dial, fltk::Divider, fltk::GlutWindow, fltk::GlWindow, fltk::Group, fltk::HelpView, fltk::Input, fltk::InvisibleBox, fltk::Item, fltk::ItemGroup, fltk::MenuBar, fltk::PopupMenu, fltk::ProgressBar, fltk::ReturnButton, fltk::Scrollbar, fltk::ScrollGroup, fltk::ShapedWindow, fltk::Slider, fltk::TabGroup, fltk::TextDisplay, fltk::ThumbWheel, fltk::Tooltip, fltk::ValueInput, fltk::ValueOutput, fltk::ValueSlider, fltk::Window, and fltk::WizardGroup.
Draw what would be in the area of the widget if the widget was not there. By calling this in draw(), a widgets can redraw as though they are partially transparent, or more complicated shapes than rectangles. Note that only parent widgets are drawn, not underlapping ones.
If DAMAGE_EXPOSE is on in damage() then the window (or at least some region of it) is being completely redrawn. Normally FLTK will have already drawn the background, so to avoid redundant drawing this will return immediatly without drawing anything. However FLTK may be compiled with USE_CLIPOUT (an option to reduce blinking in single-buffered windows) and in that case the widget must draw any visible background. In this case this function always draws the background.
Draw the widget's box() such that it fills the entire area of the widget. If the box is not rectangluar, this also draws the area of the parent widget that is exposed.
This also does drawstyle(style(),flags()&~OUTPUT) and thus the colors and font are set up for drawing text in the widget.
Same as draw_box() but draws only the boundary of the box() by calling it's draw routine with the INVISIBLE flag set. This only works for rectangular boxes. This is useful for avoiding blinking during update for widgets that erase their contents as part of redrawing them anyway (ie anything displaying text).
|const Rectangle &||rectangle|
Changes the lower 5 bits (the "align" bits) of drawflags() to be the value of which, then draws the glyph(), then put drawflags() back. This is a convienence function for widgets that actually need to draw several different glyphs. They have to define a glyph whicy draws a different image depending on the align flags. This allows the style to be changed by replacing the glyph function, though the replacement should draw the same things for the align flags, perhaps by being an fltk::MultiImage.
Draws labels inside the widget using the current font and color settings. XYWH is the bounding box to fit the label into, flags is used to align in that box.
If the flags contain any ALIGN flags and don't have ALIGN_INSIDE then the label() is not drawn. Instead the image() is drawn to fill the box (most image() types will center the picture).
Otherwise it tries to put both the label() and the image() into the box in a nice way. The image() is put against the side that any ALIGN flags say, and then the label() is put next to that.
|bool Widget::find||(||const AssociationType &||at,|
tries to find an association of this type with the given data if found the function returns true, else false
|bool Widget::flag||(||unsigned||f||)|| const
Returns true if the bit for f is on.
|Flags Widget::flags||(||)|| const
Replace flags(). This is for constructors, don't use it elsewhere.
Call the functor for each piece of data of the give AssociationType. This is a wrapper for fltk::foreach(&at, this, fkt).
|void * Widget::get||(||const AssociationType &||at||)||const|
Returns the first association of the given type that is connected with this widget. Returns NULL if none.
|void Widget::get_absolute_rect||(||Rectangle *||rect||)||const|
Fills the Rectangle pointed to by rect with the widget's rectangle expressed in absolute (i.e. screen) coordinates.
Handle an event. Returns non-zero if the widget understood and used the event.
The event numbers are listed in <fltk/events.h> . All other information about the current event (like mouse position) is accessed by various functions listed in the same header file.
If you want to send an event to a widget you probably want to call send(), not handle(). Send will do extra work with each event before calling this, such as turning HIGHLIGHT and FOCUSED flags on/off.
Reimplemented in fltk::Adjuster, fltk::Browser, fltk::Button, fltk::Choice, fltk::Clock, fltk::CycleButton, fltk::Dial, fltk::Divider, fltk::GlutWindow, fltk::GlWindow, fltk::Group, fltk::HelpView, fltk::Input, fltk::InvisibleBox, fltk::Item, fltk::ItemGroup, fltk::MenuBar, fltk::NumericInput, fltk::Output, fltk::PopupMenu, fltk::RepeatButton, fltk::Scrollbar, fltk::ScrollGroup, fltk::Slider, fltk::TabGroup, fltk::TextDisplay, fltk::TextEditor, fltk::ThumbWheel, fltk::Valuator, fltk::ValueInput, fltk::ValueOutput, fltk::ValueSlider, and fltk::Window.
|bool Widget::horizontal||(||)|| const
Return true if this widget has a horizontal orientation and fltk::Pack will position it against the top or bottom edge. This is the default.
Reimplemented in fltk::Slider.
Flip the result of flag(f) if f is a single bit. If you or together bits it will flip them all.
|bool Widget::is_group||(||)|| const
|bool Widget::is_window||(||)|| const
|void Widget::label||(||const char *||s||)|
bool Widget::inside(const Widget* a) const Returns true if this is a child of a, or is equal to a. Returns false if a is NULL.
Sets the label directly to a string. The label is printed somewhere on the widget or next to it. The string passed to label() is not copied, instead the pointer to the string is stored. If copy_label() was called earlier the old string's memory is freed.
Reimplemented in fltk::Window.
Returns a value that can be passed to add_shortcut() so that this widget has a real shortcut assignment to match any &x in it's label(). The returned value is ACCELERATOR|c where c is the character after the first '&' in the label (except '&&' is ignored), or zero if there isn't any '&' sign or if flag(RAW_LABEL) is on.
Virtual function to respond to layout_damage(), it should calculate the correct size of this widget and all it's children. This function is called by fltk or by the layout() method in other widgets. User programs should not call it.
A widget is allowed to alter it's own size in a layout() method, to indicate a size that the data will fit in. A parent widget is then expected to rearrange itself to accomodate the new size. This may mean it will move the widget and thus layout() will be called again.
You can look at layout_damage() to find out why this is being called.
The base class redraws the widget.
Reimplemented in fltk::Browser, fltk::Divider, fltk::GlWindow, fltk::Group, fltk::HelpView, fltk::Item, fltk::ItemGroup, fltk::Menu, fltk::PackedGroup, fltk::ScrollGroup, fltk::StatusBarGroup, fltk::TextDisplay, fltk::Tooltip, fltk::ValueInput, fltk::ValueSlider, and fltk::Window.
|uchar Widget::layout_damage||(||)|| const
A typical layout function does not care about the widget moving, an easy way to skip it is as follows:
Directly change the value returned by layout_damage().
Make the fltk drawing functions draw into this widget. The transformation is set so 0,0 is at the upper-left corner of the widget and 1 unit equals one pixel. The transformation stack is empied, and all other graphics state is left in unknown settings.
The equivalent of this is already done before a Widget::draw() function is called. The only reason to call this is for incremental updating of widgets without using redraw(). This will crash if the widget is not in a currently shown() window. Also this may not work correctly for double-buffered windows.
|void Widget::measure_label||(||int &||w,|
Replace w and h with the size of the area the label will take up. This is the size of the draw_outside_label() and thus does not include any image() and always uses the labelfont even if the OUTPUT flag is set.
If the ALIGN_WRAP flag is set this chooses the rather arbitrary width of 300 to wrap the label at. Ideally this should have been passed in w but is not for back-compatability reasons.
|bool Widget::output||(||)|| const
This flag is similar to !active() except it does not change how the widget is drawn. The widget will not recieve any events. This is useful for making scrollbars or buttons that work as displays rather than input devices.
Set or clear this flag with set_output() and clear_output().
|Group * Widget::parent||(||)|| const
By default fltk only turns this on on certain widgets such as fltk::Input. Turning this on on all widgets will make the user interface match Windows more closely.
Turning this off with clear_tab_to_focus() will also turn off the click_to_focus() flag. This is for compatability in case we change the default to a more Windows-like style where all widgets get the focus on clicks.
For historical reasons this flag is true on many more widgets than it should be, and FLTK relies on handle() returing 0 for FOCUS. This may change in the future so that more widgets have this flag off.
bool Widget::changed() const
The default callback() turns this flag on. This can be used to find what widgets have had their value changed by the user, for instance in response to an "OK" button.
Most widgets turn this flag off when they do the callback, and when the program sets the stored value.
bool Widget::value() const A true/false flag used by fltk::Button to indicate the current state and by "parent" items in a hierarchial fltk::Browser to indicate if they are open. Many widgets will draw pushed-in or otherwise indicate that this flag is on.
Returns true if this is equal to fltk::pushed(), meaning it has responded to an fltk::PUSH event and the mouse is still held down. Using this function avoids the need to include the <fltk/Fl.h> header file.
|void Widget::redraw||(||const Rectangle &||r1||)|
Indicates that a rectangular region is damaged. draw() will be called later with damage() set to fltk::DAMAGE_ALL|fltkDAMAGE_EXPOSE and with FLTK's clipping set to at least the given rectangle. Normally this is called more than once and the clip region will be the union of all these calls. In addition damage from the operating system (ie from overlapping windows) will increase the clipping region.
This can be used to get speed up and improve complex displays of many overlapping and changing objects. Even if you do nothing else about it, it is usually faster to do a drawing operation that is clipped than one that appears, so display will be faster. You can also check to see if anything by testing fltk::not_clipped(x,y,w,h) or fltk::clip_box(...) and skipping unnecessary drawing calls completely. Also if your normal drawing causes blinking (due to overlapping objects) this can make the display look much better by limiting the blinking to the small area that is actually changing.
Same as redraw(DAMAGE_ALL). This bit is used by most widgets to indicate that they should not attempt any incremental update, and should instead completely draw themselves.
Causes a redraw if highlighting changes.
Calls redraw(DAMAGE_HIGHLIGHT) if this widget has a non-zero highlight_color(). This is designed to be called in response to ENTER and EXIT events and not redraw the widget if the no highlight color is being used.
Same as relayout(LAYOUT_DAMAGE), indicates that data inside the widget may have changed, but the size did not change. This flag is also on when the widget is initially created.
|bool Widget::remove||(||const AssociationType &||at,|
tries to remove one association from a widget, if it exists it is removed and the function returns true, if such an association doesn't exist false is returned and nothing is changed
Delete a shortcut assignment. Returns true if it actually existed.
Remove all shortcuts for the widget. This is automatically done by the Widget destructor.
Cancel any and all pending handle(TIMEOUT) callbacks.
Call handle(TIMEOUT) at the given time interval since the last timeout. This will produce much more accurate time intervals than add_timeout().
Wrapper for handle(). This should be called to send events. It does a few things:
|void Widget::set||(||const AssociationType &||at,|
Removes all associations of the given assiciation type from this widget and, if data is not NULL, add the given data pointer as a new association.
The removed data is freed by calling the destroy method of the association type.
Same as state(true). If you know the widget will already be redrawn, or it is not displayed, it is faster to call the inline set_flag(STATE) function.
Make flag(f) return true by turning on that bit. You can set more than one by or'ing them together.
Make flag(f) return b. Same as b ? set_flag(f) : clear_flag(f).
Same as remove_shortcuts(), add_shortcut(key) except it may be implemented in a more efficient way. The result is exactly one shortcut (or none if key is zero).
Returns one of the add_shortcut() assignments for this widget, or returns zero if there are none. If you want to look at more than onle you must use fltk::list_shortcuts(this).
Change the state(). Also calls clear_changed(). If the state is different, redraw(DAMAGE_VALUE) is called and true is returned. If the state is the same then false is returned and the widget is not redrawn.
|bool Widget::state||(||)|| const
Widgets have space in them to store a single true/false value (put into the STATE bit of flags()). This is used by buttons and checkmarks and radio menu items.
Tries to make this widget be the keyboard focus widget, by first sending it an fltk::FOCUS event, and if it returns non-zero, setting fltk::focus() to this widget. You should use this method to assign the focus to a widget. Returns true if the widget accepted the focus.
On current systems fltk does not force the window system to set the focus. If the window does not have focus it will usually switch back to the previous window when the user types a key.
Test to see if the current KEY or SHORTCUT event matches a shortcut specified with &x in the label.
This will match if the character in the label() after a '&' matches event_text(). Case is ignored. The caller may want to check if ACCELERATOR or some other shift key is held down before calling this so that plain keys do not do anything, and should certainly make sure no other widgets want the shortcut.
This is ignored if flag(RAW_LABEL) is on (which stops the &x from printing as an underscore. The sequence "&&" is ignored as well because that is used to print a plain '&' in the label.
Same as test_shortcut(true)
This function is called by ~Widget() and by deactivate() and by hide(). It indicates that the widget does not want to receive any more events, and also removes all global variables that point at the widget (not just the fltk::focus(), but the fltk::belowmouse(), fltk::modal(), and some internal pointers). Unlike older versions of fltk, no events (i.e. fltk::LEAVE or fltk::UNFOCUS) are sent to the widget.
|uchar Widget::type||(||)|| const
8-bit identifier that controls how widget works. This value had to be provided for Forms compatibility, but you can use it for any purpose you want (mostly for "bad object oriented programming" where you insert some subclass functionality into the base class). Widget subclasses may store values in the range 0-99 here (larger values are reserved for use by FLTK).
For portability FLTK does not use RTTI (Run Time Typing Infomation) internally (you are free to use it, though). If you don't have RTTI you can use the clumsy FLTK mechanisim, by having type() use a unique value. These unique values must be greater than the symbol Widget::RESERVED_TYPE (which is 100). Look through the header files for Widget::RESERVED_TYPE to find an unused number. If you make a subclass of fltk::Window you must use Widget::WINDOW_TYPE+n (n must be in the range 1 to 7) so that is_window() will work, if you make a subclass of fltk::Group you must use Widget::GROUP_TYPE+n (n must be in the range 1 to 7) so that is_group() will work.
|void Widget::user_data||(||void *||v||)||
Set the second argument to the callback.
|bool Widget::vertical||(||)|| const
Same as !horizontal().
bool Widget::visible() const Returns true if the widget is visible (flag(INVISIBLE) is false)
Returns true if the widget and all of its parents are visible. Only if this is true can the user see the widget.
Flags indicating when to do the callback(). This field is in the base class so that you can scan a panel and do_callback() on all the ones that don't do their own callbacks in response to an "OK" button.
The following constants can be used, their exact meaning depends on the widget's implementation:
|Window * Widget::window||(||)||const|
This is the value of glyph() in the Widget::default_style. It is an internal symbol called "@widget;". It draws a number of small buttons with arrows on them. The direction of the arrows are determined by the align values in fltk::setflags():
Only one arrow direction at a time is currently supported. This may be improved in the future.