FLTK 1.3.3
Fl_Widget Class Referenceabstract

Fl_Widget is the base class for all widgets in FLTK. More...

#include <Fl_Widget.H>

Inheritance diagram for Fl_Widget:
Fl_Box Fl_Button Fl_Chart Fl_Clock_Output Fl_FormsBitmap Fl_FormsPixmap Fl_FormsText Fl_Free Fl_Group Fl_Input_ Fl_Menu_ Fl_Positioner Fl_Progress Fl_Timer Fl_Valuator

Public Member Functions

void _clear_fullscreen ()
 
void _set_fullscreen ()
 
void activate ()
 Activates the widget. More...
 
unsigned int active () const
 Returns whether the widget is active. More...
 
int active_r () const
 Returns whether the widget and all of its parents are active. More...
 
Fl_Align align () const
 Gets the label alignment. More...
 
void align (Fl_Align alignment)
 Sets the label alignment. More...
 
long argument () const
 Gets the current user data (long) argument that is passed to the callback function.
 
void argument (long v)
 Sets the current user data (long) argument that is passed to the callback function. More...
 
virtual class Fl_Gl_Windowas_gl_window ()
 Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window. More...
 
virtual Fl_Groupas_group ()
 Returns an Fl_Group pointer if this widget is an Fl_Group. More...
 
virtual Fl_Windowas_window ()
 Returns an Fl_Window pointer if this widget is an Fl_Window. More...
 
Fl_Boxtype box () const
 Gets the box type of the widget. More...
 
void box (Fl_Boxtype new_box)
 Sets the box type for the widget. More...
 
Fl_Callback_p callback () const
 Gets the current callback function for the widget. More...
 
void callback (Fl_Callback *cb, void *p)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback *cb)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback0 *cb)
 Sets the current callback function for the widget. More...
 
void callback (Fl_Callback1 *cb, long p=0)
 Sets the current callback function for the widget. More...
 
unsigned int changed () const
 Checks if the widget value changed since the last callback. More...
 
void clear_active ()
 Marks the widget as inactive without sending events or changing focus. More...
 
void clear_changed ()
 Marks the value of the widget as unchanged. More...
 
void clear_damage (uchar c=0)
 Clears or sets the damage flags. More...
 
void clear_output ()
 Sets a widget to accept input. More...
 
void clear_visible ()
 Hides the widget. More...
 
void clear_visible_focus ()
 Disables keyboard focus navigation with this widget. More...
 
Fl_Color color () const
 Gets the background color of the widget. More...
 
void color (Fl_Color bg)
 Sets the background color of the widget. More...
 
void color (Fl_Color bg, Fl_Color sel)
 Sets the background and selection color of the widget. More...
 
Fl_Color color2 () const
 For back compatibility only. More...
 
void color2 (unsigned a)
 For back compatibility only. More...
 
int contains (const Fl_Widget *w) const
 Checks if w is a child of this widget. More...
 
void copy_label (const char *new_label)
 Sets the current label. More...
 
void copy_tooltip (const char *text)
 Sets the current tooltip text. More...
 
uchar damage () const
 Returns non-zero if draw() needs to be called. More...
 
void damage (uchar c)
 Sets the damage bits for the widget. More...
 
void damage (uchar c, int x, int y, int w, int h)
 Sets the damage bits for an area inside the widget. More...
 
int damage_resize (int, int, int, int)
 Internal use only. More...
 
void deactivate ()
 Deactivates the widget. More...
 
Fl_Imagedeimage ()
 Gets the image that is used as part of the widget label. More...
 
const Fl_Imagedeimage () const
 
void deimage (Fl_Image *img)
 Sets the image to use as part of the widget label. More...
 
void deimage (Fl_Image &img)
 Sets the image to use as part of the widget label. More...
 
void do_callback ()
 Calls the widget callback. More...
 
void do_callback (Fl_Widget *o, long arg)
 Calls the widget callback. More...
 
void do_callback (Fl_Widget *o, void *arg=0)
 Calls the widget callback. More...
 
virtual void draw ()=0
 Draws the widget. More...
 
void draw_label (int, int, int, int, Fl_Align) const
 Draws the label in an arbitrary bounding box with an arbitrary alignment. More...
 
int h () const
 Gets the widget height. More...
 
virtual int handle (int event)
 Handles the specified event. More...
 
virtual void hide ()
 Makes a widget invisible. More...
 
Fl_Imageimage ()
 Gets the image that is used as part of the widget label. More...
 
const Fl_Imageimage () const
 
void image (Fl_Image *img)
 Sets the image to use as part of the widget label. More...
 
void image (Fl_Image &img)
 Sets the image to use as part of the widget label. More...
 
int inside (const Fl_Widget *wgt) const
 Checks if this widget is a child of wgt. More...
 
const char * label () const
 Gets the current label text. More...
 
void label (const char *text)
 Sets the current label pointer. More...
 
void label (Fl_Labeltype a, const char *b)
 Shortcut to set the label text and type in one call. More...
 
Fl_Color labelcolor () const
 Gets the label color. More...
 
void labelcolor (Fl_Color c)
 Sets the label color. More...
 
Fl_Font labelfont () const
 Gets the font to use. More...
 
void labelfont (Fl_Font f)
 Sets the font to use. More...
 
Fl_Fontsize labelsize () const
 Gets the font size in pixels. More...
 
void labelsize (Fl_Fontsize pix)
 Sets the font size in pixels. More...
 
Fl_Labeltype labeltype () const
 Gets the label type. More...
 
void labeltype (Fl_Labeltype a)
 Sets the label type. More...
 
void measure_label (int &ww, int &hh) const
 Sets width ww and height hh accordingly with the label size. More...
 
unsigned int output () const
 Returns if a widget is used for output only. More...
 
Fl_Groupparent () const
 Returns a pointer to the parent widget. More...
 
void parent (Fl_Group *p)
 Internal use only - "for hacks only". More...
 
void position (int X, int Y)
 Repositions the window or widget. More...
 
void redraw ()
 Schedules the drawing of the widget. More...
 
void redraw_label ()
 Schedules the drawing of the label. More...
 
virtual void resize (int x, int y, int w, int h)
 Changes the size or position of the widget. More...
 
Fl_Color selection_color () const
 Gets the selection color. More...
 
void selection_color (Fl_Color a)
 Sets the selection color. More...
 
void set_active ()
 Marks the widget as active without sending events or changing focus. More...
 
void set_changed ()
 Marks the value of the widget as changed. More...
 
void set_output ()
 Sets a widget to output only. More...
 
void set_visible ()
 Makes the widget visible. More...
 
void set_visible_focus ()
 Enables keyboard focus navigation with this widget. More...
 
virtual void show ()
 Makes a widget visible. More...
 
void size (int W, int H)
 Changes the size of the widget. More...
 
int take_focus ()
 Gives the widget the keyboard focus. More...
 
unsigned int takesevents () const
 Returns if the widget is able to take events. More...
 
int test_shortcut ()
 Returns true if the widget's label contains the entered '&x' shortcut. More...
 
const char * tooltip () const
 Gets the current tooltip text. More...
 
void tooltip (const char *text)
 Sets the current tooltip text. More...
 
Fl_Windowtop_window () const
 Returns a pointer to the top-level window for the widget. More...
 
Fl_Windowtop_window_offset (int &xoff, int &yoff) const
 Finds the x/y offset of the current widget relative to the top-level window. More...
 
uchar type () const
 Gets the widget type. More...
 
void type (uchar t)
 Sets the widget type. More...
 
int use_accents_menu ()
 Returns non zero if MAC_USE_ACCENTS_MENU flag is set, 0 otherwise.
 
void * user_data () const
 Gets the user data for this widget. More...
 
void user_data (void *v)
 Sets the user data for this widget. More...
 
unsigned int visible () const
 Returns whether a widget is visible. More...
 
void visible_focus (int v)
 Modifies keyboard focus navigation. More...
 
unsigned int visible_focus ()
 Checks whether this widget has a visible focus. More...
 
int visible_r () const
 Returns whether a widget and all its parents are visible. More...
 
int w () const
 Gets the widget width. More...
 
Fl_When when () const
 Returns the conditions under which the callback is called. More...
 
void when (uchar i)
 Sets the flags used to decide when a callback is called. More...
 
Fl_Windowwindow () const
 Returns a pointer to the nearest parent window up the widget hierarchy. More...
 
int x () const
 Gets the widget position in its window. More...
 
int y () const
 Gets the widget position in its window. More...
 
virtual ~Fl_Widget ()
 Destroys the widget. More...
 

Static Public Member Functions

static void default_callback (Fl_Widget *cb, void *d)
 Sets the default callback for all widgets. More...
 
static unsigned int label_shortcut (const char *t)
 Returns the Unicode value of the '&x' shortcut in a given text. More...
 
static int test_shortcut (const char *, const bool require_alt=false)
 Returns true if the given text t contains the entered '&x' shortcut. More...
 

Protected Types

enum  {
  INACTIVE = 1<<0, INVISIBLE = 1<<1, OUTPUT = 1<<2, NOBORDER = 1<<3,
  FORCE_POSITION = 1<<4, NON_MODAL = 1<<5, SHORTCUT_LABEL = 1<<6, CHANGED = 1<<7,
  OVERRIDE = 1<<8, VISIBLE_FOCUS = 1<<9, COPIED_LABEL = 1<<10, CLIP_CHILDREN = 1<<11,
  MENU_WINDOW = 1<<12, TOOLTIP_WINDOW = 1<<13, MODAL = 1<<14, NO_OVERLAY = 1<<15,
  GROUP_RELATIVE = 1<<16, COPIED_TOOLTIP = 1<<17, FULLSCREEN = 1<<18, MAC_USE_ACCENTS_MENU = 1<<19,
  USERFLAG3 = 1<<29, USERFLAG2 = 1<<30, USERFLAG1 = 1<<31
}
 flags possible values enumeration. More...
 

Protected Member Functions

void clear_flag (unsigned int c)
 Clears a flag in the flags mask.
 
void draw_backdrop () const
 If FL_ALIGN_IMAGE_BACKDROP is set, the image or deimage will be drawn.
 
void draw_box () const
 Draws the widget box according its box style.
 
void draw_box (Fl_Boxtype t, Fl_Color c) const
 Draws a box of type t, of color c at the widget's position and size. More...
 
void draw_box (Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) const
 Draws a box of type t, of color c at the position X,Y and size W,H. More...
 
void draw_focus ()
 draws a focus rectangle around the widget
 
void draw_focus (Fl_Boxtype t, int x, int y, int w, int h) const
 Draws a focus box for the widget at the given position and size.
 
void draw_label () const
 Draws the widget's label at the defined label position. More...
 
void draw_label (int, int, int, int) const
 Draws the label in an arbitrary bounding box. More...
 
 Fl_Widget (int x, int y, int w, int h, const char *label=0L)
 Creates a widget at the given position and size. More...
 
unsigned int flags () const
 Gets the widget flags mask.
 
void h (int v)
 Internal use only. More...
 
void set_flag (unsigned int c)
 Sets a flag in the flags mask.
 
void w (int v)
 Internal use only. More...
 
void x (int v)
 Internal use only. More...
 
void y (int v)
 Internal use only. More...
 

Friends

class Fl_Group
 

Detailed Description

Fl_Widget is the base class for all widgets in FLTK.

You can't create one of these because the constructor is not public. However you can subclass it.

All "property" accessing methods, such as color(), parent(), or argument() are implemented as trivial inline functions and thus are as fast and small as accessing fields in a structure. Unless otherwise noted, the property setting methods such as color(n) or label(s) are also trivial inline functions, even if they change the widget's appearance. It is up to the user code to call redraw() after these.

Member Enumeration Documentation

anonymous enum
protected

flags possible values enumeration.

See activate(), output(), visible(), changed(), set_visible_focus()

Enumerator
INACTIVE 

the widget can't receive focus, and is disabled but potentially visible

INVISIBLE 

the widget is not drawn, but can receive a few special events

OUTPUT 

for output only

NOBORDER 

don't draw a decoration (Fl_Window)

FORCE_POSITION 

don't let the window manager position the window (Fl_Window)

NON_MODAL 

this is a hovering toolbar window (Fl_Window)

SHORTCUT_LABEL 

the label contains a shortcut we need to draw

CHANGED 

the widget value changed

OVERRIDE 

position window on top (Fl_Window)

VISIBLE_FOCUS 

accepts keyboard focus navigation if the widget can have the focus

COPIED_LABEL 

the widget label is internally copied, its destruction is handled by the widget

CLIP_CHILDREN 

all drawing within this widget will be clipped (Fl_Group)

MENU_WINDOW 

a temporary popup window, dismissed by clicking outside (Fl_Window)

TOOLTIP_WINDOW 

a temporary popup, transparent to events, and dismissed easily (Fl_Window)

MODAL 

a window blocking input to all other winows (Fl_Window)

NO_OVERLAY 

window not using a hardware overlay plane (Fl_Menu_Window)

GROUP_RELATIVE 

position this widget relative to the parent group, not to the window

COPIED_TOOLTIP 

the widget tooltip is internally copied, its destruction is handled by the widget

FULLSCREEN 

a fullscreen window (Fl_Window)

MAC_USE_ACCENTS_MENU 

On the Mac OS platform, pressing and holding a key on the keyboard opens an accented-character menu window (Fl_Input_, Fl_Text_Editor)

USERFLAG3 

reserved for 3rd party extensions

USERFLAG2 

reserved for 3rd party extensions

USERFLAG1 

reserved for 3rd party extensions

Constructor & Destructor Documentation

Fl_Widget::Fl_Widget ( int  x,
int  y,
int  w,
int  h,
const char *  label = 0L 
)
protected

Creates a widget at the given position and size.

The Fl_Widget is a protected constructor, but all derived widgets have a matching public constructor. It takes a value for x(), y(), w(), h(), and an optional value for label().

Parameters
[in]x,ythe position of the widget relative to the enclosing window
[in]w,hsize of the widget in pixels
[in]labeloptional text for the widget label
Fl_Widget::~Fl_Widget ( )
virtual

Destroys the widget.

Destroys the widget, taking care of throwing focus before if any.

Destroying single widgets is not very common. You almost always want to destroy the parent group instead, which will destroy all of the child widgets and groups in that group.

Since
FLTK 1.3, the widget's destructor removes the widget from its parent group, if it is member of a group.

Destruction removes the widget from any parent group! And groups when destroyed destroy all their children. This is convenient and fast.

Member Function Documentation

void Fl_Widget::activate ( )

Activates the widget.

Changing this value will send FL_ACTIVATE to the widget if active_r() is true.

See Also
active(), active_r(), deactivate()
unsigned int Fl_Widget::active ( ) const
inline

Returns whether the widget is active.

Return values
0if the widget is inactive
See Also
active_r(), activate(), deactivate()
int Fl_Widget::active_r ( ) const

Returns whether the widget and all of its parents are active.

Return values
0if this or any of the parent widgets are inactive
See Also
active(), activate(), deactivate()
Fl_Align Fl_Widget::align ( ) const
inline

Gets the label alignment.

Returns
label alignment
See Also
label(), align(Fl_Align), Fl_Align
void Fl_Widget::align ( Fl_Align  alignment)
inline

Sets the label alignment.

This controls how the label is displayed next to or inside the widget. The default value is FL_ALIGN_CENTER, which centers the label inside the widget.

Parameters
[in]alignmentnew label alignment
See Also
align(), Fl_Align
void Fl_Widget::argument ( long  v)
inline

Sets the current user data (long) argument that is passed to the callback function.

Todo:
The user data value must be implemented using intptr_t or similar to avoid 64-bit machine incompatibilities.
virtual class Fl_Gl_Window* Fl_Widget::as_gl_window ( )
inlinevirtual

Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.

Use this method if you have a widget (pointer) and need to know whether this widget is derived from Fl_Gl_Window. If it returns non-NULL, then the widget in question is derived from Fl_Gl_Window.

Return values
NULLif this widget is not derived from Fl_Gl_Window.
Note
This method is provided to avoid dynamic_cast.
See Also
Fl_Widget::as_group(), Fl_Widget::as_window()

Reimplemented in Fl_Gl_Window.

virtual Fl_Group* Fl_Widget::as_group ( )
inlinevirtual

Returns an Fl_Group pointer if this widget is an Fl_Group.

Use this method if you have a widget (pointer) and need to know whether this widget is derived from Fl_Group. If it returns non-NULL, then the widget in question is derived from Fl_Group, and you can use the returned pointer to access its children or other Fl_Group-specific methods.

Example:

void my_callback (Fl_Widget *w, void *) {
Fl_Group *g = w->as_group();
if (g)
printf ("This group has %d children\n",g->children());
else
printf ("This widget is not a group!\n");
}
Return values
NULLif this widget is not derived from Fl_Group.
Note
This method is provided to avoid dynamic_cast.
See Also
Fl_Widget::as_window(), Fl_Widget::as_gl_window()

Reimplemented in Fl_Group.

virtual Fl_Window* Fl_Widget::as_window ( )
inlinevirtual

Returns an Fl_Window pointer if this widget is an Fl_Window.

Use this method if you have a widget (pointer) and need to know whether this widget is derived from Fl_Window. If it returns non-NULL, then the widget in question is derived from Fl_Window, and you can use the returned pointer to access its children or other Fl_Window-specific methods.

Return values
NULLif this widget is not derived from Fl_Window.
Note
This method is provided to avoid dynamic_cast.
See Also
Fl_Widget::as_group(), Fl_Widget::as_gl_window()

Reimplemented in Fl_Window.

Fl_Boxtype Fl_Widget::box ( ) const
inline

Gets the box type of the widget.

Returns
the current box type
See Also
box(Fl_Boxtype), Fl_Boxtype
void Fl_Widget::box ( Fl_Boxtype  new_box)
inline

Sets the box type for the widget.

This identifies a routine that draws the background of the widget. See Fl_Boxtype for the available types. The default depends on the widget, but is usually FL_NO_BOX or FL_UP_BOX.

Parameters
[in]new_boxthe new box type
See Also
box(), Fl_Boxtype
Fl_Callback_p Fl_Widget::callback ( ) const
inline

Gets the current callback function for the widget.

Each widget has a single callback.

Returns
current callback
void Fl_Widget::callback ( Fl_Callback cb,
void *  p 
)
inline

Sets the current callback function for the widget.

Each widget has a single callback.

Parameters
[in]cbnew callback
[in]puser data
void Fl_Widget::callback ( Fl_Callback cb)
inline

Sets the current callback function for the widget.

Each widget has a single callback.

Parameters
[in]cbnew callback
void Fl_Widget::callback ( Fl_Callback0 cb)
inline

Sets the current callback function for the widget.

Each widget has a single callback.

Parameters
[in]cbnew callback
void Fl_Widget::callback ( Fl_Callback1 cb,
long  p = 0 
)
inline

Sets the current callback function for the widget.

Each widget has a single callback.

Parameters
[in]cbnew callback
[in]puser data
unsigned int Fl_Widget::changed ( ) const
inline

Checks if the widget value changed since the last callback.

"Changed" is a flag that is turned on when the user changes the value stored in the widget. This is only used by subclasses of Fl_Widget that store values, but is in the base class so it is easier to scan all the widgets in a panel and do_callback() on the changed ones 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.

Return values
0if the value did not change
See Also
set_changed(), clear_changed()
void Fl_Widget::clear_active ( )
inline

Marks the widget as inactive without sending events or changing focus.

This is mainly for specialized use, for normal cases you want deactivate().

See Also
deactivate()
void Fl_Widget::clear_changed ( )
inline

Marks the value of the widget as unchanged.

See Also
changed(), set_changed()
void Fl_Widget::clear_damage ( uchar  c = 0)
inline

Clears or sets the damage flags.

Damage flags are cleared when parts of the widget drawing is repaired.

The optional argument c specifies the bits that are set after the call (default: 0) and not the bits that are cleared!

Note
Therefore it is possible to set damage bits with this method, but this should be avoided. Use damage(uchar) instead.
Parameters
[in]cnew bitmask of damage flags (default: 0)
See Also
damage(uchar), damage()
void Fl_Widget::clear_output ( )
inline

Sets a widget to accept input.

See Also
set_output(), output()
void Fl_Widget::clear_visible ( )
inline

Hides the widget.

You must still redraw the parent to see a change in the window. Normally you want to use the hide() method instead.

void Fl_Widget::clear_visible_focus ( )
inline

Disables keyboard focus navigation with this widget.

Normally, all widgets participate in keyboard focus navigation.

See Also
set_visible_focus(), visible_focus(), visible_focus(int)
Fl_Color Fl_Widget::color ( ) const
inline

Gets the background color of the widget.

Returns
current background color
See Also
color(Fl_Color), color(Fl_Color, Fl_Color)
void Fl_Widget::color ( Fl_Color  bg)
inline

Sets the background color of the widget.

The color is passed to the box routine. The color is either an index into an internal table of RGB colors or an RGB color value generated using fl_rgb_color().

The default for most widgets is FL_BACKGROUND_COLOR. Use Fl::set_color() to redefine colors in the color map.

Parameters
[in]bgbackground color
See Also
color(), color(Fl_Color, Fl_Color), selection_color(Fl_Color)
void Fl_Widget::color ( Fl_Color  bg,
Fl_Color  sel 
)
inline

Sets the background and selection color of the widget.

The two color form sets both the background and selection colors.

Parameters
[in]bgbackground color
[in]selselection color
See Also
color(unsigned), selection_color(unsigned)
Fl_Color Fl_Widget::color2 ( ) const
inline

For back compatibility only.

Deprecated:
Use selection_color() instead.
void Fl_Widget::color2 ( unsigned  a)
inline

For back compatibility only.

Deprecated:
Use selection_color(unsigned) instead.
int Fl_Widget::contains ( const Fl_Widget w) const

Checks if w is a child of this widget.

Parameters
[in]wpotential child widget
Returns
Returns 1 if w is a child of this widget, or is equal to this widget. Returns 0 if w is NULL.
void Fl_Widget::copy_label ( const char *  new_label)

Sets the current label.

Unlike label(), this method allocates a copy of the label string instead of using the original string pointer.

The internal copy will automatically be freed whenever you assign a new label or when the widget is destroyed.

Parameters
[in]new_labelthe new label text
See Also
label()
void Fl_Widget::copy_tooltip ( const char *  text)

Sets the current tooltip text.

Unlike tooltip(), this method allocates a copy of the tooltip string instead of using the original string pointer.

The internal copy will automatically be freed whenever you assign a new tooltip or when the widget is destroyed.

If no tooltip is set, the tooltip of the parent is inherited. Setting a tooltip for a group and setting no tooltip for a child will show the group's tooltip instead. To avoid this behavior, you can set the child's tooltip to an empty string ("").

Parameters
[in]textNew tooltip text (an internal copy is made and managed)
See Also
tooltip(const char*), tooltip()
uchar Fl_Widget::damage ( ) const
inline

Returns non-zero if draw() needs to be called.

The damage value is actually a bit field that the widget subclass can use to figure out what parts to draw.

Returns
a bitmap of flags describing the kind of damage to the widget
See Also
damage(uchar), clear_damage(uchar)
void Fl_Widget::damage ( uchar  c)

Sets the damage bits for the widget.

Setting damage bits will schedule the widget for the next redraw.

Parameters
[in]cbitmask of flags to set
See Also
damage(), clear_damage(uchar)
void Fl_Widget::damage ( uchar  c,
int  x,
int  y,
int  w,
int  h 
)

Sets the damage bits for an area inside the widget.

Setting damage bits will schedule the widget for the next redraw.

Parameters
[in]cbitmask of flags to set
[in]x,y,w,hsize of damaged area
See Also
damage(), clear_damage(uchar)
int Fl_Widget::damage_resize ( int  X,
int  Y,
int  W,
int  H 
)

Internal use only.

void Fl_Widget::deactivate ( )

Deactivates the widget.

Inactive widgets will be drawn "grayed out", e.g. with less contrast than the active widget. Inactive widgets will not receive any keyboard or mouse button events. Other events (including FL_ENTER, FL_MOVE, FL_LEAVE, FL_SHORTCUT, and others) will still be sent. A widget is only active if active() is true on it and all of its parents.

Changing this value will send FL_DEACTIVATE to the widget if active_r() is true.

Currently you cannot deactivate Fl_Window widgets.

See Also
activate(), active(), active_r()
void Fl_Widget::default_callback ( Fl_Widget cb,
void *  d 
)
static

Sets the default callback for all widgets.

Sets the default callback, which puts a pointer to the widget on the queue returned by Fl::readqueue(). You may want to call this from your own callback.

Parameters
[in]cbthe new callback
[in]duser data associated with that callback
See Also
callback(), do_callback(), Fl::readqueue()
Fl_Image* Fl_Widget::deimage ( )
inline

Gets the image that is used as part of the widget label.

This image is used when drawing the widget in the inactive state.

Returns
the current image for the deactivated widget
void Fl_Widget::deimage ( Fl_Image img)
inline

Sets the image to use as part of the widget label.

This image is used when drawing the widget in the inactive state.

Parameters
[in]imgthe new image for the deactivated widget
void Fl_Widget::deimage ( Fl_Image img)
inline

Sets the image to use as part of the widget label.

This image is used when drawing the widget in the inactive state.

Parameters
[in]imgthe new image for the deactivated widget
void Fl_Widget::do_callback ( )
inline

Calls the widget callback.

Causes a widget to invoke its callback function with default arguments.

See Also
callback()
void Fl_Widget::do_callback ( Fl_Widget o,
long  arg 
)
inline

Calls the widget callback.

Causes a widget to invoke its callback function with arbitrary arguments.

Parameters
[in]ocall the callback with o as the widget argument
[in]argcall the callback with arg as the user data argument
See Also
callback()
void Fl_Widget::do_callback ( Fl_Widget o,
void *  arg = 0 
)

Calls the widget callback.

Causes a widget to invoke its callback function with arbitrary arguments.

Parameters
[in]ocall the callback with o as the widget argument
[in]arguse arg as the user data argument
See Also
callback()
virtual void Fl_Widget::draw ( )
pure virtual

Draws the widget.

Never call this function directly. FLTK will schedule redrawing whenever needed. If your widget must be redrawn as soon as possible, call redraw() instead.

Override this function to draw your own widgets.

If you ever need to call another widget's draw method from within your own draw() method, e.g. for an embedded scrollbar, you can do it (because draw() is virtual) like this:

Fl_Widget *s = &scroll; // scroll is an embedded Fl_Scrollbar
s->draw(); // calls Fl_Scrollbar::draw()

Implemented in Fl_Table, Fl_FormsText, Fl_Tree, Fl_Text_Display, Fl_Input, Fl_Gl_Window, Fl_Tabs, Fl_Browser_, Fl_Window, Fl_Scroll, Fl_Button, Fl_Chart, Fl_Choice, Fl_Slider, Fl_Value_Input, Fl_File_Input, Fl_Counter, Fl_Free, Fl_Clock_Output, Fl_Group, Fl_Dial, Fl_Cairo_Window, Fl_Menu_Bar, Fl_Pack, Fl_Menu_Button, Fl_Scrollbar, Fl_Positioner, Fl_Adjuster, Fl_Timer, Fl_Value_Output, Fl_Glut_Window, Fl_Progress, Fl_Sys_Menu_Bar, Fl_Light_Button, Fl_Value_Slider, Fl_Roller, Fl_Box, Fl_Return_Button, Fl_FormsPixmap, and Fl_FormsBitmap.

void Fl_Widget::draw_box ( Fl_Boxtype  t,
Fl_Color  c 
) const
protected

Draws a box of type t, of color c at the widget's position and size.

void Fl_Widget::draw_box ( Fl_Boxtype  t,
int  X,
int  Y,
int  W,
int  H,
Fl_Color  c 
) const
protected

Draws a box of type t, of color c at the position X,Y and size W,H.

void Fl_Widget::draw_label ( ) const
protected

Draws the widget's label at the defined label position.

This is the normal call for a widget's draw() method.

void Fl_Widget::draw_label ( int  X,
int  Y,
int  W,
int  H 
) const
protected

Draws the label in an arbitrary bounding box.

draw() can use this instead of draw_label(void) to change the bounding box

void Fl_Widget::draw_label ( int  X,
int  Y,
int  W,
int  H,
Fl_Align  a 
) const

Draws the label in an arbitrary bounding box with an arbitrary alignment.

Anybody can call this to force the label to draw anywhere.

void Fl_Widget::h ( int  v)
inlineprotected

Internal use only.

Use position(int,int), size(int,int) or resize(int,int,int,int) instead.

int Fl_Widget::h ( ) const
inline

Gets the widget height.

Returns
the height of the widget in pixels.
int Fl_Widget::handle ( int  event)
virtual

Handles the specified event.

You normally don't call this method directly, but instead let FLTK do it when the user interacts with the widget.

When implemented in a widget, this function must return 0 if the widget does not use the event or 1 otherwise.

Most of the time, you want to call the inherited handle() method in your overridden method so that you don't short-circuit events that you don't handle. In this last case you should return the callee retval.

Parameters
[in]eventthe kind of event received
Return values
0if the event was not used or understood
1if the event was used and can be deleted
See Also
Fl_Event

Reimplemented in Fl_Tree, Fl_Table, Fl_Input, Fl_Window, Fl_Browser_, Fl_Tabs, Fl_Text_Display, Fl_Scroll, Fl_Spinner, Fl_Table_Row, Fl_Clock, Fl_Check_Browser, Fl_Button, Fl_Gl_Window, Fl_Choice, Fl_Slider, Fl_Menu_Button, Fl_Group, Fl_Value_Input, Fl_Counter, Fl_File_Input, Fl_Free, Fl_Dial, Fl_Menu_Bar, Fl_Scrollbar, Fl_Text_Editor, Fl_Positioner, Fl_Box, Fl_Value_Output, Fl_Timer, Fl_Glut_Window, Fl_Adjuster, Fl_Secret_Input, Fl_Light_Button, Fl_Value_Slider, Fl_Roller, Fl_Return_Button, Fl_Repeat_Button, and Fl_Tile.

void Fl_Widget::hide ( )
virtual

Makes a widget invisible.

See Also
show(), visible(), visible_r()

Reimplemented in Fl_Window, Fl_Browser, Fl_Gl_Window, Fl_Overlay_Window, Fl_Double_Window, and Fl_Menu_Window.

Fl_Image* Fl_Widget::image ( )
inline

Gets the image that is used as part of the widget label.

This image is used when drawing the widget in the active state.

Returns
the current image
void Fl_Widget::image ( Fl_Image img)
inline

Sets the image to use as part of the widget label.

This image is used when drawing the widget in the active state.

Parameters
[in]imgthe new image for the label
void Fl_Widget::image ( Fl_Image img)
inline

Sets the image to use as part of the widget label.

This image is used when drawing the widget in the active state.

Parameters
[in]imgthe new image for the label
int Fl_Widget::inside ( const Fl_Widget wgt) const
inline

Checks if this widget is a child of wgt.

Returns 1 if this widget is a child of wgt, or is equal to wgt. Returns 0 if wgt is NULL.

Parameters
[in]wgtthe possible parent widget.
See Also
contains()
const char* Fl_Widget::label ( ) const
inline

Gets the current label text.

Returns
a pointer to the current label text
See Also
label(const char *), copy_label(const char *)
void Fl_Widget::label ( const char *  text)

Sets the current label pointer.

The label is shown somewhere on or next to the widget. The passed pointer is stored unchanged in the widget (the string is not copied), so if you need to set the label to a formatted value, make sure the buffer is static, global, or allocated. The copy_label() method can be used to make a copy of the label string automatically.

Parameters
[in]textpointer to new label text
See Also
copy_label()
void Fl_Widget::label ( Fl_Labeltype  a,
const char *  b 
)
inline

Shortcut to set the label text and type in one call.

See Also
label(const char *), labeltype(Fl_Labeltype)
unsigned int Fl_Widget::label_shortcut ( const char *  t)
static

Returns the Unicode value of the '&x' shortcut in a given text.

The given text t (usually a widget's label or a menu text) is searched for a '&x' shortcut label, and if found, the Unicode value (code point) of the '&x' shortcut is returned.

Parameters
ttext or label to search for '&x' shortcut.
Returns
Unicode (UCS-4) value of shortcut in t or 0.
Note
Internal use only.
Fl_Color Fl_Widget::labelcolor ( ) const
inline

Gets the label color.

The default color is FL_FOREGROUND_COLOR.

Returns
the current label color
void Fl_Widget::labelcolor ( Fl_Color  c)
inline

Sets the label color.

The default color is FL_FOREGROUND_COLOR.

Parameters
[in]cthe new label color
Fl_Font Fl_Widget::labelfont ( ) const
inline

Gets the font to use.

Fonts are identified by indexes into a table. The default value uses a Helvetica typeface (Arial for Microsoft® Windows®). The function Fl::set_font() can define new typefaces.

Returns
current font used by the label
See Also
Fl_Font
void Fl_Widget::labelfont ( Fl_Font  f)
inline

Sets the font to use.

Fonts are identified by indexes into a table. The default value uses a Helvetica typeface (Arial for Microsoft® Windows®). The function Fl::set_font() can define new typefaces.

Parameters
[in]fthe new font for the label
See Also
Fl_Font
Fl_Fontsize Fl_Widget::labelsize ( ) const
inline

Gets the font size in pixels.

The default size is 14 pixels.

Returns
the current font size
void Fl_Widget::labelsize ( Fl_Fontsize  pix)
inline

Sets the font size in pixels.

Parameters
[in]pixthe new font size
See Also
Fl_Fontsize labelsize()
Fl_Labeltype Fl_Widget::labeltype ( ) const
inline

Gets the label type.

Returns
the current label type.
See Also
Fl_Labeltype
void Fl_Widget::labeltype ( Fl_Labeltype  a)
inline

Sets the label type.

The label type identifies the function that draws the label of the widget. This is generally used for special effects such as embossing or for using the label() pointer as another form of data such as an icon. The value FL_NORMAL_LABEL prints the label as plain text.

Parameters
[in]anew label type
See Also
Fl_Labeltype
void Fl_Widget::measure_label ( int &  ww,
int &  hh 
) const
inline

Sets width ww and height hh accordingly with the label size.

Labels with images will return w() and h() of the image.

This calls fl_measure() internally. For more information about the arguments ww and hh and word wrapping

See Also
fl_measure(const char*, int&, int&, int)
unsigned int Fl_Widget::output ( ) const
inline

Returns if a widget is used for output only.

output() means the same as !active() except it does not change how the widget is drawn. The widget will not receive any events. This is useful for making scrollbars or buttons that work as displays rather than input devices.

Return values
0if the widget is used for input and output
See Also
set_output(), clear_output()
Fl_Group* Fl_Widget::parent ( ) const
inline

Returns a pointer to the parent widget.

Usually this is a Fl_Group or Fl_Window.

Return values
NULLif the widget has no parent
See Also
Fl_Group::add(Fl_Widget*)
void Fl_Widget::parent ( Fl_Group p)
inline

Internal use only - "for hacks only".

It is STRONGLY recommended not to use this method, because it short-circuits Fl_Group's normal widget adding and removing methods, if the widget is already a child widget of another Fl_Group.

Use Fl_Group::add(Fl_Widget*) and/or Fl_Group::remove(Fl_Widget*) instead.

void Fl_Widget::position ( int  X,
int  Y 
)
inline

Repositions the window or widget.

position(X, Y) is a shortcut for resize(X, Y, w(), h()).

Parameters
[in]X,Ynew position relative to the parent window
See Also
resize(int,int,int,int), size(int,int)
void Fl_Widget::redraw ( )

Schedules the drawing of the widget.

Marks the widget as needing its draw() routine called.

void Fl_Widget::redraw_label ( )

Schedules the drawing of the label.

Marks the widget or the parent as needing a redraw for the label area of a widget.

void Fl_Widget::resize ( int  x,
int  y,
int  w,
int  h 
)
virtual

Changes the size or position of the widget.

This is a virtual function so that the widget may implement its own handling of resizing. The default version does not call the redraw() method, but instead relies on the parent widget to do so because the parent may know a faster way to update the display, such as scrolling from the old position.

Some window managers under X11 call resize() a lot more often than needed. Please verify that the position or size of a widget did actually change before doing any extensive calculations.

position(X, Y) is a shortcut for resize(X, Y, w(), h()), and size(W, H) is a shortcut for resize(x(), y(), W, H).

Parameters
[in]x,ynew position relative to the parent window
[in]w,hnew size
See Also
position(int,int), size(int,int)

Reimplemented in Fl_Table, Fl_Tree, Fl_Help_View, Fl_Text_Display, Fl_Window, Fl_Browser_, Fl_Input_, Fl_Input_Choice, Fl_Spinner, Fl_Scroll, Fl_Group, Fl_Gl_Window, Fl_Value_Input, Fl_Overlay_Window, Fl_Double_Window, and Fl_Tile.

Fl_Color Fl_Widget::selection_color ( ) const
inline

Gets the selection color.

Returns
the current selection color
See Also
selection_color(Fl_Color), color(Fl_Color, Fl_Color)
void Fl_Widget::selection_color ( Fl_Color  a)
inline

Sets the selection color.

The selection color is defined for Forms compatibility and is usually used to color the widget when it is selected, although some widgets use this color for other purposes. You can set both colors at once with color(Fl_Color bg, Fl_Color sel).

Parameters
[in]athe new selection color
See Also
selection_color(), color(Fl_Color, Fl_Color)
void Fl_Widget::set_active ( )
inline

Marks the widget as active without sending events or changing focus.

This is mainly for specialized use, for normal cases you want activate().

See Also
activate()
void Fl_Widget::set_changed ( )
inline

Marks the value of the widget as changed.

See Also
changed(), clear_changed()
void Fl_Widget::set_output ( )
inline

Sets a widget to output only.

See Also
output(), clear_output()
void Fl_Widget::set_visible ( )
inline

Makes the widget visible.

You must still redraw the parent widget to see a change in the window. Normally you want to use the show() method instead.

void Fl_Widget::set_visible_focus ( )
inline

Enables keyboard focus navigation with this widget.

Note, however, that this will not necessarily mean that the widget will accept focus, but for widgets that can accept focus, this method enables it if it has been disabled.

See Also
visible_focus(), clear_visible_focus(), visible_focus(int)
void Fl_Widget::show ( )
virtual

Makes a widget visible.

An invisible widget never gets redrawn and does not get keyboard or mouse events, but can receive a few other events like FL_SHOW.

The visible() method returns true if the widget is set to be visible. The visible_r() method returns true if the widget and all of its parents are visible. A widget is only visible if visible() is true on it and all of its parents.

Changing it will send FL_SHOW or FL_HIDE events to the widget. Do not change it if the parent is not visible, as this will send false FL_SHOW or FL_HIDE events to the widget. redraw() is called if necessary on this or the parent.

See Also
hide(), visible(), visible_r()

Reimplemented in Fl_Window, Fl_Browser, Fl_Gl_Window, Fl_Overlay_Window, Fl_Double_Window, Fl_Single_Window, and Fl_Menu_Window.

void Fl_Widget::size ( int  W,
int  H 
)
inline

Changes the size of the widget.

size(W, H) is a shortcut for resize(x(), y(), W, H).

Parameters
[in]W,Hnew size
See Also
position(int,int), resize(int,int,int,int)
int Fl_Widget::take_focus ( )

Gives the widget the keyboard focus.

Tries to make this widget be the Fl::focus() widget, by first sending it an FL_FOCUS event, and if it returns non-zero, setting Fl::focus() to this widget. You should use this method to assign the focus to a widget.

Returns
true if the widget accepted the focus.
unsigned int Fl_Widget::takesevents ( ) const
inline

Returns if the widget is able to take events.

This is the same as (active() && !output() && visible()) but is faster.

Return values
0if the widget takes no events
int Fl_Widget::test_shortcut ( )

Returns true if the widget's label contains the entered '&x' shortcut.

This method must only be called in handle() methods or callbacks after a keypress event (usually FL_KEYDOWN or FL_SHORTCUT). The widget's label is searched for a '&x' shortcut, and if found, this is compared with the entered key value.

Fl::event_text() is used to get the entered key value.

Returns
true, if the entered text matches the widget's'&x' shortcut, false (0) otherwise.
Note
Internal use only.
int Fl_Widget::test_shortcut ( const char *  t,
const bool  require_alt = false 
)
static

Returns true if the given text t contains the entered '&x' shortcut.

This method must only be called in handle() methods or callbacks after a keypress event (usually FL_KEYDOWN or FL_SHORTCUT). The given text t (usually a widget's label or menu text) is searched for a '&x' shortcut, and if found, this is compared with the entered key value.

Fl::event_text() is used to get the entered key value. Fl::event_state() is used to get the Alt modifier, if require_alt is true.

Parameters
ttext or label to search for '&x' shortcut.
require_altif true: match only if Alt key is pressed.
Returns
true, if the entered text matches the '&x' shortcut in t false (0) otherwise.
Note
Internal use only.
const char* Fl_Widget::tooltip ( ) const
inline

Gets the current tooltip text.

Returns
a pointer to the tooltip text or NULL
See Also
tooltip(const char*), copy_tooltip(const char*)
void Fl_Widget::tooltip ( const char *  text)

Sets the current tooltip text.

Sets a string of text to display in a popup tooltip window when the user hovers the mouse over the widget. The string is not copied, so make sure any formatted string is stored in a static, global, or allocated buffer. If you want a copy made and managed for you, use the copy_tooltip() method, which will manage the tooltip string automatically.

If no tooltip is set, the tooltip of the parent is inherited. Setting a tooltip for a group and setting no tooltip for a child will show the group's tooltip instead. To avoid this behavior, you can set the child's tooltip to an empty string ("").

Parameters
[in]textNew tooltip text (no copy is made)
See Also
copy_tooltip(const char*), tooltip()
Fl_Window * Fl_Widget::top_window ( ) const

Returns a pointer to the top-level window for the widget.

In other words, the 'window manager window' that contains this widget. This method differs from window() in that it won't return sub-windows (if there are any).

Returns
the top-level window, or NULL if no top-level window is associated with this widget.
See Also
window()
Fl_Window * Fl_Widget::top_window_offset ( int &  xoff,
int &  yoff 
) const

Finds the x/y offset of the current widget relative to the top-level window.

Parameters
[out]xoff,yoffReturns the x/y offset
Returns
the top-level window (or NULL for a widget that's not in any window)
uchar Fl_Widget::type ( ) const
inline

Gets the widget type.

Returns the widget type value, which is used for Forms compatibility and to simulate RTTI.

Todo:
Explain "simulate RTTI" (currently only used to decide if a widget is a window, i.e. type()>=FL_WINDOW ?). Is type() really used in a way that ensures "Forms compatibility" ?
void Fl_Widget::type ( uchar  t)
inline

Sets the widget type.

This is used for Forms compatibility.

void* Fl_Widget::user_data ( ) const
inline

Gets the user data for this widget.

Gets the current user data (void *) argument that is passed to the callback function.

Returns
user data as a pointer
void Fl_Widget::user_data ( void *  v)
inline

Sets the user data for this widget.

Sets the new user data (void *) argument that is passed to the callback function.

Parameters
[in]vnew user data
unsigned int Fl_Widget::visible ( ) const
inline

Returns whether a widget is visible.

Return values
0if the widget is not drawn and hence invisible.
See Also
show(), hide(), visible_r()
void Fl_Widget::visible_focus ( int  v)
inline

Modifies keyboard focus navigation.

Parameters
[in]vset or clear visible focus
See Also
set_visible_focus(), clear_visible_focus(), visible_focus()
unsigned int Fl_Widget::visible_focus ( )
inline

Checks whether this widget has a visible focus.

Return values
0if this widget has no visible focus.
See Also
visible_focus(int), set_visible_focus(), clear_visible_focus()
int Fl_Widget::visible_r ( ) const

Returns whether a widget and all its parents are visible.

Return values
0if the widget or any of its parents are invisible.
See Also
show(), hide(), visible()
void Fl_Widget::w ( int  v)
inlineprotected

Internal use only.

Use position(int,int), size(int,int) or resize(int,int,int,int) instead.

int Fl_Widget::w ( ) const
inline

Gets the widget width.

Returns
the width of the widget in pixels.
Fl_When Fl_Widget::when ( ) const
inline

Returns the conditions under which the callback is called.

You can set the flags with when(uchar), the default value is FL_WHEN_RELEASE.

Returns
set of flags
See Also
when(uchar)
void Fl_Widget::when ( uchar  i)
inline

Sets the flags used to decide when a callback is called.

This controls when callbacks are done. The following values are useful, the default value is FL_WHEN_RELEASE:

  • 0: The callback is not done, but changed() is turned on.
  • FL_WHEN_CHANGED: The callback is done each time the text is changed by the user.
  • FL_WHEN_RELEASE: The callback will be done when this widget loses the focus, including when the window is unmapped. This is a useful value for text fields in a panel where doing the callback on every change is wasteful. However the callback will also happen if the mouse is moved out of the window, which means it should not do anything visible (like pop up an error message). You might do better setting this to zero, and scanning all the items for changed() when the OK button on a panel is pressed.
  • FL_WHEN_ENTER_KEY: If the user types the Enter key, the entire text is selected, and the callback is done if the text has changed. Normally the Enter key will navigate to the next field (or insert a newline for a Fl_Multiline_Input) - this changes the behavior.
  • FL_WHEN_ENTER_KEY|FL_WHEN_NOT_CHANGED: The Enter key will do the callback even if the text has not changed. Useful for command fields. Fl_Widget::when() is a set of bitflags used by subclasses of Fl_Widget to decide when to do the callback.

If the value is zero then the callback is never done. Other values are described in the individual widgets. 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.

Parameters
[in]iset of flags
Fl_Window * Fl_Widget::window ( ) const

Returns a pointer to the nearest parent window up the widget hierarchy.

This will return sub-windows if there are any, or the parent window if there's no sub-windows. If this widget IS the top-level window, NULL is returned.

Return values
NULLif no window is associated with this widget.
Note
for an Fl_Window widget, this returns its parent window (if any), not this window.
See Also
top_window()
void Fl_Widget::x ( int  v)
inlineprotected

Internal use only.

Use position(int,int), size(int,int) or resize(int,int,int,int) instead.

int Fl_Widget::x ( ) const
inline

Gets the widget position in its window.

Returns
the x position relative to the window
void Fl_Widget::y ( int  v)
inlineprotected

Internal use only.

Use position(int,int), size(int,int) or resize(int,int,int,int) instead.

int Fl_Widget::y ( ) const
inline

Gets the widget position in its window.

Returns
the y position relative to the window

The documentation for this class was generated from the following files: