Inherited by Button, ccCellBox, ccHueBox, ccValueBox, ClockOutput, Divider, Group, Input, InvisibleBox, Item, ProgressBar, and Valuator.
Public Types | |
enum | WidgetVisualType { NORMAL, RESERVED_TYPE, TOGGLE, RADIO, GROUP_TYPE, WINDOW_TYPE } |
Public Member Functions | |
Widget (int, int, int, int, const char *=0) | |
virtual | ~Widget () |
virtual void | draw () |
virtual int | handle (int) |
int | send (int event) |
virtual void | layout () |
const Style * | style () const |
void | style (const Style *s) |
void | style (const Style &s) |
bool | copy_style (const Style *s) |
Group * | parent () const |
void | parent (Group *w) |
Window * | window () const |
uchar | type () const |
void | type (uchar t) |
bool | is_group () const |
bool | is_window () const |
bool | resize (int x, int y, int w, int h) |
bool | position (int x, int y) |
bool | resize (int w, int h) |
void | get_absolute_rect (Rectangle *rect) const |
const char * | label () const |
void | label (const char *a) |
void | copy_label (const char *a) |
const Symbol * | image () const |
void | image (const Symbol *a) |
void | image (const Symbol &a) |
const char * | tooltip () const |
void | tooltip (const char *t) |
unsigned | shortcut () const |
bool | shortcut (unsigned key) |
bool | add_shortcut (unsigned key) |
bool | remove_shortcut (unsigned key) |
bool | remove_shortcuts () |
unsigned | label_shortcut () const |
bool | test_label_shortcut () const |
bool | test_shortcut () const |
bool | test_shortcut (bool) const |
Callback_p | callback () const |
void | callback (Callback *c, void *p) |
void | callback (Callback *c) |
void | callback (Callback0 *c) |
void | callback (Callback1 *c, long p=0) |
void * | user_data () const |
void | user_data (void *v) |
long | argument () const |
void | argument (long v) |
uchar | when () const |
void | when (uchar i) |
void | do_callback () |
void | do_callback (Widget *o, void *arg=0) |
void | do_callback (Widget *o, long arg) |
bool | contains (const Widget *) const |
bool | inside (const Widget *o) const |
bool | pushed () const |
bool | focused () const |
bool | belowmouse () const |
Flags | flags () const |
Flags | flags (Flags f) |
Flags | set_flag (int c) |
Flags | clear_flag (int c) |
Flags | invert_flag (int c) |
bool | state () const |
bool | state (bool) |
bool | set () |
bool | clear () |
void | setonly () |
Flags | align () const |
void | align (unsigned a) |
bool | visible () const |
bool | visible_r () const |
void | show () |
void | hide () |
void | set_visible () |
void | clear_visible () |
bool | active () const |
bool | active_r () const |
void | activate () |
void | activate (int b) |
void | deactivate () |
bool | output () const |
void | set_output () |
void | clear_output () |
bool | takesevents () const |
bool | changed () const |
void | set_changed () |
void | clear_changed () |
bool | selected () const |
void | set_selected () |
void | clear_selected () |
bool | click_to_focus () |
void | set_click_to_focus () |
void | clear_click_to_focus () |
bool | tab_to_focus () |
void | set_tab_to_focus () |
void | clear_tab_to_focus () |
bool | horizontal () const |
bool | vertical () const |
void | set_horizontal () |
void | set_vertical () |
bool | take_focus () |
void | throw_focus () |
void | redraw () |
void | redraw (uchar c) |
void | redraw_label () |
void | redraw_highlight () |
void | redraw (const Rectangle &) |
uchar | damage () const |
void | set_damage (uchar c) |
void | relayout () |
void | relayout (uchar damage) |
uchar | layout_damage () const |
void | layout_damage (uchar c) |
void | add_timeout (float) |
void | repeat_timeout (float) |
void | remove_timeout () |
void | make_current () const |
void | draw_background () const |
void | draw_frame () const |
void | draw_box () const |
void | draw_box (const Rectangle &r) const |
void | draw_label () const |
void | draw_label (const Rectangle &, Flags) const |
void | draw_glyph (int, const Rectangle &) const |
void | cursor (Cursor *) const |
void | measure_label (int &, int &) const |
Box * | box () const |
Box * | buttonbox () const |
Box * | focusbox () const |
Symbol * | glyph () const |
Font * | labelfont () const |
Font * | textfont () const |
LabelType * | labeltype () const |
Color | color () const |
Color | textcolor () const |
Color | selection_color () const |
Color | selection_textcolor () const |
Color | buttoncolor () const |
Color | labelcolor () const |
Color | highlight_color () const |
Color | highlight_textcolor () const |
float | labelsize () const |
float | textsize () const |
float | leading () const |
unsigned char | scrollbar_align () const |
unsigned char | scrollbar_width () const |
void | box (Box *) |
void | buttonbox (Box *) |
void | focusbox (Box *) |
void | glyph (Symbol *) |
void | labelfont (Font *) |
void | textfont (Font *) |
void | labeltype (LabelType *) |
void | color (Color) |
void | textcolor (Color a) |
void | selection_color (Color) |
void | selection_textcolor (Color) |
void | buttoncolor (Color) |
void | labelcolor (Color) |
void | highlight_color (Color) |
void | highlight_textcolor (Color) |
void | labelsize (float a) |
void | textsize (float a) |
void | leading (float a) |
void | scrollbar_align (unsigned char) |
void | scrollbar_width (unsigned char) |
Static Public Member Functions | |
void | default_callback (Widget *, void *) |
Static Public Attributes | |
NamedStyle * | default_style |
Symbol * | default_glyph |
|
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(). |
|
If active() is false, this turns it on. If active_r() is now true send() an ACTIVATE event. |
|
Returns true if deactivate() has not been called, or activate() has been called since then. Parents may also be deactivated, in which case this widget will not get events even if this is true. You can test for this with !active_r(). Or inside draw() events you can test flags()&INACTIVE_R. |
|
Returns whether the widget is active. This is true if active() is true for this and all parent widgets. An inactive widget does not get any events, but it does get redrawn. |
|
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. You can examine the assignments with list_shortcuts(). 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 event_state(), and either a key symbol returned by event_key(), or an ASCII character. Examples:
When FLTK gets a keystroke, it sends it to the 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 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). |
|
Sets the second argument to the callback to a number. This is done by casting the long to a void*. |
|
Returns true if this is equal to belowmouse(), meaning it has the keyboard focus and MOVE or PUSH events will be sent to this widget. Using this function avoids the need to include the <fltk/Fl.h> header file. |
|
For convenience you can also define the callback as taking a long integer argument. This is implemented by casting the function to a Callback and casting the |
|
For convenience you can also define the callback as taking only the Widget as an argument. This is implemented by casting this to a Callback and may not be portable to some machines. |
|
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. |
|
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 Group. |
|
Returns true if b is a child of this widget, or is equal to this widget. Returns false if b is NULL. |
|
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. |
|
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. |
|
Change the cursor being displayed on the screen. A widget should do this in response to
On X you can mess with the colors by setting the Color variables |
|
The 'or' of all the calls to redraw() done since the last draw(). Cleared to zero after draw() is called. |
|
If active() is true, this turns it off. If active_r() was true send() an DEACTIVATE event. |
|
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 Menu. |
|
You can also call the callback function with arbitrary arguments. |
|
You can also call the callback function with arbitrary arguments. |
|
You can cause a widget to do its callback at any time. The callback function is called with this and user_data() as 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 Choice, GlutWindow, Input, InvisibleBox, Item, PopupMenu, and 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). |
|
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 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. |
|
Calls draw_label() with the area inside the box() and with the alignment stored in flags(). The labelfont() and labelcolor() are used. For historic reasons if the OUTPUT flag is on then the textfont() and textcolor() are used. |
|
Each Widget, and most drawing functions, take a bitmask of flags that indicate the current state and exactly how to draw things. See <fltk/Flags.h> for values. |
|
Returns true if this is equal to focus(), meaning it has the keyboard focus and KEY events will be sent to this widget. Using this function avoids the need to include the <fltk/Fl.h> header file. |
|
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. The default version returns true for ENTER and MOVE events, this is done so you can put tooltips on the base widget. All other events return zero. 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 Divider, Group, Input, Item, ItemGroup, NumericInput, and Valuator. |
|
If visible() is true, turn it off. If visible_r() was true then send() a HIDE event, and redraw() the parent if necessary. |
|
Return true if this widget has a horizontal orientation and Pack will position it against the top or bottom edge. This is the default. |
|
Returns true for subclasses of Group. If so you can cast it to a group with |
|
Returns true for subclasses of Window. If so you can cast it to a window with |
|
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 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 ALT|c where c is the character after the first '&' in the label, or zero if there isn't any '&' sign or if flags() has RAW_LABEL turned 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. |
|
Directly change the value returned by layout_damage(). |
|
The 'or' of all the calls to relayout() or resize() done since the last time layout() was called. A typical layout function does not care about the widget moving, an easy way to skip it is as follows:
MyClass::layout() { if (!(layout_damage() & ~LAYOUT_XY)) return; do_expensive_layout(); redraw(); } |
|
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. |
|
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. |
|
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(). |
|
Returns a pointer to the parent widget. Usually this is a Group or Window. Returns NULL if none. |
|
Same as resize() to x, y, w(), h() Reimplemented in Input. |
|
Returns true if this is equal to pushed(), meaning it has responded to an PUSH event and the mouse is still held down. Using this function avoids the need to include the <fltk/Fl.h> header file. |
|
Indicates that a rectangular region is damaged. draw() will be called later with damage() set to DAMAGE_ALL|DAMAGE_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 not_clipped(x,y,w,h) or 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. |
|
Indicates that draw() should be called, and turns on the given bits in damage(). At least these bits, and possibly others, will still be on when draw() is called. |
|
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. |
|
Indicates that the label() should be redrawn. This does nothing if there is no label. If it is an outside label (see align()) then the parent() is told to redraw it. Otherwise redraw() is called. |
|
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. |
|
Delete a shortcut assignment. Returns true if it actually existed. |
|
Remove all shortcuts for the widget. Returns true if there were any. 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(). |
|
|
Change the size or position of the widget. Nothing is done if the passed size and position are the same as before. If there is a change then relayout() is called so that the virtual function layout() is called before the next draw(). Reimplemented in Group. |
|
Wrapper for handle(). This should be called to send events. It does a few things:
|
|
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. |
|
Directly change the value returned by damage(). Note that this replaces the value, it does not turn bits on. Use redraw() to turn bits on. |
|
Undoes set_vertical() and makes horizontal() return true. This will affect how a surrounding Pack (or similar group) will place the widget, but you must call relayout() to indicate that this must be recalculated. |
|
Makes vertical() return true. This will affect how a surrounding Pack (or similar group) will place the widget, but you must call relayout() to indicate that this must be recalculated. Some widgets classes such as MenuBar or Slider will draw differently if this is turned on, in a vertical arrangement. |
|
Calls set() on this widget and calls clear() on all other widgets in the same parent Group that have the type() set to RADIO. |
|
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). Return value is intended to indicate if the shortcut changed, but that is nyi. |
|
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 list_shortcuts(this). |
|
If visible() is false, turn it on. If visible_r() is then true, send() a SHOW event. Reimplemented in Window. |
|
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. |
|
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 FOCUS event, and if it returns non-zero, setting 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. |
|
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()[0]. 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 flags() has RAW_LABEL turned 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. |
|
Returns true if the current event matches one of the assignements made with add_shortcut(), or if test_label is true and test_label_shortcut() returns true. Normally a widget calls this in response to a SHORTCUT event to see if the shortcut key is assigned to it. This is done by doing list_matching_shortcuts() and seeing if this widget is in the returned list. If the list is empty and test_label is true, it will return test_label_shortcut(). If the current event matches a different widget "better" than this one, then false is returned. For instance if this widget has 'x' as a shortcut, this will return true if the user types 'X'. But if another widget has 'X' then this will return false. See list_matching_shortcuts() for the rules about what ones are "better". |
|
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 focus(), but the belowmouse(), modal(), and some internal pointers). Unlike older versions of fltk, no events (i.e. LEAVE or UNFOCUS) are sent to the widget. |
|
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). The PackedGroup widget uses the low bit of the type() of each child to indicate HORIZONTAL (1) or VERTICAL (0). 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 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 Group you must use Widget::GROUP_TYPE+n (n must be in the range 1 to 7) so that is_group() will work. |
|
Set the second argument to the callback. |
|
Same as !horizontal(). |
|
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:
|
|
Return a pointer to the Window this widget is in. (it will skip any and all parent widgets between this and the window). Returns NULL if none. Note: for an Window, this returns the parent window (if any), not this window. |
|
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 setflags():
Only one arrow direction at a time is currently supported. This may be improved in the future. |