fltk::Widget Class Reference

Inherits fltk::Rectangle.

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.

List of all members.


Detailed Description

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

Public Types

enum  WidgetVisualType {
  RESERVED_TYPE, TOGGLE, RADIO, GROUP_TYPE,
  WINDOW_TYPE
}

Public Member Functions

void activate (int b)
void activate ()
bool active () const
bool active_r () const
void add (const AssociationType &, void *data)
bool add_shortcut (unsigned key)
void add_timeout (float)
void align (unsigned a)
Flags align () const
bool all_of (unsigned f) const
bool any_of (unsigned f) const
void argument (long v)
long argument () const
bool belowmouse () const
void box (Box *)
Boxbox () const
void buttonbox (Box *)
Boxbuttonbox () const
void buttoncolor (Color)
Color buttoncolor () const
void callback (Callback1 *c, long p=0)
void callback (Callback0 *c)
void callback (Callback *c)
void callback (Callback *c, void *p)
Callback_p callback () const
bool changed () const
bool clear ()
void clear_changed ()
void clear_click_to_focus ()
void clear_flag (unsigned f)
void clear_output ()
void clear_selected ()
void clear_tab_to_focus ()
void clear_visible ()
bool click_to_focus ()
void color (Color)
Color color () const
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 deactivate ()
void do_callback (Widget *o, long arg)
void do_callback (Widget *o, void *arg=0)
void do_callback ()
virtual void draw ()
void draw_background () const
void draw_box (const Rectangle &r) const
void draw_box () const
void draw_frame () const
void draw_glyph (int, const Rectangle &) const
void draw_label (const Rectangle &, Flags) const
void draw_label () const
bool flag (unsigned f) const
void flags (Flags f)
Flags flags () const
bool focused () const
void * foreach (const AssociationType &, AssociationFunctor &) const
void * get (const AssociationType &) const
void get_absolute_rect (Rectangle *rect) const
void glyph (Symbol *)
Symbolglyph () const
virtual int handle (int)
void hide ()
void highlight_color (Color)
Color highlight_color () const
void highlight_textcolor (Color)
Color highlight_textcolor () const
bool horizontal () const
void image (const Symbol &a)
void image (const Symbol *a)
const Symbolimage () const
bool inside (const Widget *o) const
void invert_flag (unsigned f)
bool is_group () const
bool is_window () const
void label (const char *a)
const char * label () const
unsigned label_shortcut () const
void labelcolor (Color)
Color labelcolor () const
void labelfont (Font *)
Fontlabelfont () const
void labelsize (float a)
float labelsize () const
void labeltype (LabelType *)
LabelType * labeltype () const
virtual void layout ()
void layout_damage (uchar c)
uchar layout_damage () const
void leading (float a)
float leading () const
void make_current () const
void measure_label (int &, int &) const
bool output () const
void parent (Group *w)
Groupparent () const
bool position (int x, int y)
bool pushed () const
void redraw (const Rectangle &)
void redraw (uchar c)
void redraw ()
void redraw_highlight ()
void redraw_label ()
void relayout (uchar damage)
void relayout ()
bool remove_shortcut (unsigned key)
bool remove_shortcuts ()
void remove_timeout ()
void repeat_timeout (float)
bool resize (int w, int h)
bool resize (int x, int y, int w, int h)
void scrollbar_align (unsigned char)
unsigned char scrollbar_align () const
void scrollbar_width (unsigned char)
unsigned char scrollbar_width () const
bool selected () const
void selection_color (Color)
Color selection_color () const
void selection_textcolor (Color)
Color selection_textcolor () const
int send (int event)
void set (const AssociationType &, void *data)
bool set ()
void set_changed ()
void set_click_to_focus ()
void set_damage (uchar c)
void set_flag (unsigned f, bool b)
void set_flag (unsigned f)
void set_horizontal ()
void set_output ()
void set_selected ()
void set_tab_to_focus ()
void set_vertical ()
void set_visible ()
void setonly ()
bool shortcut (unsigned key)
unsigned shortcut () const
void show ()
bool state (bool)
bool state () const
void style (const Style &s)
void style (const Style *s)
const Stylestyle () const
bool tab_to_focus ()
bool take_focus ()
bool takesevents () const
bool test_label_shortcut () const
bool test_shortcut (bool) const
bool test_shortcut () const
void textcolor (Color a)
Color textcolor () const
void textfont (Font *)
Fonttextfont () const
void textsize (float a)
float textsize () const
void throw_focus ()
void tooltip (const char *t)
const char * tooltip () const
void type (uchar t)
uchar type () const
void user_data (void *v)
void * user_data () const
bool vertical () const
bool visible () const
bool visible_r () const
void when (uchar i)
uchar when () const
 Widget (int, int, int, int, const char *=0)
Windowwindow () const
virtual ~Widget ()

Static Public Member Functions

static void default_callback (Widget *, void *)

Static Public Attributes

static Symboldefault_glyph
static NamedStyledefault_style

Constructor & Destructor Documentation

Widget::Widget ( int  X,
int  Y,
int  W,
int  H,
const char *  L = 0 
)

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.

References fltk::Group::add(), fltk::CLICK_TO_FOCUS, fltk::Group::current(), fltk::DAMAGE_ALL, default_callback(), fltk::LAYOUT_DAMAGE, and fltk::TAB_TO_FOCUS.

Widget::~Widget (  )  [virtual]

The destructor is virtual. The base class removes itself from the parent widget (if any), and destroys any label made with copy_label().

References fltk::COPIED_LABEL, fltk::Style::dynamic(), fltk::Group::remove(), remove_shortcuts(), remove_timeout(), and throw_focus().


Member Function Documentation

void Widget::activate (  ) 

bool Widget::active (  )  const [inline]

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

References fltk::INACTIVE.

Referenced by activate(), fltk::Menu::handle_shortcut(), fltk::Group::insert(), redraw_highlight(), and send().

bool Widget::active_r (  )  const

Returns true if active() is true for this and all parent widgets. This is actually the INACTIVE_R bit in flags(), fltk keeps this up to date as widgets are deactivated and/or added to inactive parents.

References any_of(), fltk::INACTIVE, and fltk::INACTIVE_R.

Referenced by activate(), deactivate(), and fltk::Group::insert().

void Widget::add ( const AssociationType at,
void *  data 
)

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.

bool Widget::add_shortcut ( unsigned  key  ) 

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 fltk::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 fltk::event_state(), and either a key symbol returned by fltk::event_key(), or an ASCII character. Examples:

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

References fltk::ShortcutAssignment::key, and fltk::ShortcutAssignment::widget.

Referenced by shortcut().

void Widget::add_timeout ( float  time  ) 

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

References fltk::add_timeout().

Referenced by fltk::Input::handle().

bool Widget::all_of ( unsigned  f  )  const [inline]

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 [inline]

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.

Referenced by active_r(), fltk::Choice::draw(), and fltk::Window::show().

void Widget::argument ( long  v  )  [inline]

Sets the second argument to the callback to a number. This is done by casting the long to a void*.

bool Widget::belowmouse (  )  const

Returns true if this is equal to fltk::belowmouse(), meaning it has the keyboard focus and fltk::MOVE or fltk::PUSH events will be sent to this widget. Using this function avoids the need to include the <fltk/Fl.h> header file.

References fltk::belowmouse().

void Widget::callback ( fltk::Callback1 *  c,
long  p = 0 
) [inline]

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  )  [inline]

For convenience you can also define the callback as taking only the Widget as an argument. This is implemented by casting this to a fltk::Callback and may not be portable to some machines.

void Widget::callback ( fltk::Callback *  c,
void *  p 
) [inline]

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.

bool Widget::clear (  )  [inline]

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.

Referenced by setonly().

void Widget::clear_flag ( unsigned  f  )  [inline]

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.

References parent_.

Referenced by fltk::belowmouse(), fltk::Window::child_of(), fltk::flush(), fltk::focus(), fltk::handle(), fltk::TabGroup::selected_child(), send(), fltk::Browser::set_focus(), take_focus(), and throw_focus().

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.

References fltk::COPIED_LABEL, and newstring().

Referenced by fltk::StatusBarGroup::set().

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.

References fltk::Style::dynamic(), and fltk::Style::parent_.

void Widget::cursor ( Cursor *  c  )  const

Change the cursor being displayed on the screen. A widget should do this in response to fltk::ENTER and 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_fg and fl_cursor_bg to the colors you want, before calling this.

Referenced by fltk::dnd(), and fltk::WizardGroup::value().

uchar Widget::damage (  )  const [inline]

void Widget::deactivate (  ) 

void Widget::default_callback ( Widget w,
void *   
) [static]

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.

References set_changed().

Referenced by Widget().

void Widget::do_callback ( Widget o,
long  arg 
) [inline]

You can also call the callback function with arbitrary arguments.

void Widget::do_callback ( Widget o,
void *  arg = 0 
) [inline]

You can also call the callback function with arbitrary arguments.

References fltk::arg().

void Widget::do_callback (  )  [inline]

void Widget::draw ( void   )  [virtual]

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::Choice, fltk::GlutWindow, fltk::Input, fltk::InvisibleBox, fltk::Item, fltk::PopupMenu, and fltk::WizardGroup.

References fltk::ALIGN_CENTER, fltk::ALIGN_INSIDE, clear_flag(), draw_background(), draw_box(), draw_label(), fltk::HIGHLIGHT, and fltk::NO_BOX.

Referenced by fltk::InvisibleBox::draw(), fltk::Choice::draw(), fltk::Group::draw_child(), fltk::Menu::draw_in(), and fltk::Group::update_child().

void Widget::draw_background (  )  const

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.

References damage(), fltk::DAMAGE_EXPOSE, draw_background(), draw_box(), draw_label(), fltk::Rectangle::h(), parent(), fltk::pop_clip(), fltk::pop_matrix(), fltk::push_clip(), fltk::push_matrix(), fltk::translate(), fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().

Referenced by draw(), fltk::PopupMenu::draw(), fltk::Button::draw(), and draw_background().

void Widget::draw_box (  )  const

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.

References fltk::Rectangle::h(), fltk::Rectangle::Rectangle(), and fltk::Rectangle::w().

Referenced by draw(), and draw_background().

void Widget::draw_frame (  )  const

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

References fltk::Symbol::draw(), fltk::drawstyle(), fltk::Rectangle::h(), fltk::INVISIBLE, fltk::OUTPUT, fltk::Rectangle::Rectangle(), fltk::setdrawflags(), and fltk::Rectangle::w().

Referenced by fltk::Input::draw(), and fltk::Choice::draw().

void Widget::draw_glyph ( int  which,
const Rectangle rectangle 
) const

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.

References fltk::ALIGN_MASK, and fltk::Symbol::draw().

Referenced by fltk::Slider::draw(), fltk::PopupMenu::draw(), fltk::Item::draw(), fltk::Choice::draw(), and fltk::Menu::draw_in().

void Widget::draw_label ( const Rectangle ir,
Flags  flags 
) const

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.

References fltk::ALIGN_BOTTOM, fltk::ALIGN_CENTER, fltk::ALIGN_CLIP, fltk::ALIGN_INSIDE, fltk::ALIGN_LEFT, fltk::ALIGN_POSITIONMASK, fltk::ALIGN_RIGHT, fltk::ALIGN_TOP, fltk::Rectangle::b(), fltk::Symbol::draw(), fltk::Rectangle::h(), fltk::measure(), fltk::Symbol::measure(), fltk::Rectangle::move_r(), fltk::Rectangle::move_x(), fltk::Rectangle::move_y(), fltk::pop_clip(), fltk::push_clip(), fltk::Rectangle::r(), fltk::RESIZE_FILL, fltk::RESIZE_FIT, fltk::Rectangle::set_b(), fltk::Rectangle::set_r(), fltk::Rectangle::set_x(), fltk::Rectangle::set_y(), fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().

void Widget::draw_label (  )  const

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.

References fltk::ALIGN_INSIDE, fltk::drawstyle(), flags(), fltk::Rectangle::h(), fltk::Symbol::inset(), fltk::OUTPUT, fltk::Rectangle::r(), and fltk::Rectangle::w().

Referenced by draw(), fltk::PopupMenu::draw(), fltk::Item::draw(), fltk::Button::draw(), and draw_background().

bool Widget::flag ( unsigned  f  )  const [inline]

void Widget::flags ( Flags  f  )  [inline]

Replace flags(). This is for constructors, don't use it elsewhere.

Flags Widget::flags (  )  const [inline]

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. This is for copying the flag values, use flag(c) to test them.

Referenced by fltk::CreatedWindow::create(), fltk::PopupMenu::draw(), fltk::Item::draw(), fltk::Input::draw(), fltk::Choice::draw(), fltk::Button::draw(), fltk::Menu::draw_in(), draw_label(), fltk::Group::draw_outside_label(), fltk::Tooltip::layout(), fltk::Group::layout(), measure_label(), redraw_label(), resize(), and fltk::Window::show().

bool Widget::focused (  )  const

Returns true if this is equal to fltk::focus(), meaning it has the keyboard focus and fltk::KEY events will be sent to this widget. Using this function avoids the need to include the <fltk/Fl.h> header file.

References fltk::focus().

Referenced by fltk::Input::draw(), fltk::Choice::draw(), fltk::NumericInput::handle(), fltk::Input::handle(), fltk::TabGroup::selected_child(), and take_focus().

void * Widget::foreach ( const AssociationType at,
AssociationFunctor fkt 
) const

Call the functor for each piece of data of the give AssociationType. This is a wrapper for 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.

References fltk::Rectangle::h(), parent_, fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().

int Widget::handle ( int  event  )  [virtual]

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 fltk::ENTER and fltk::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 fltk::Divider, fltk::Group, fltk::Input, fltk::InvisibleBox, fltk::Item, fltk::ItemGroup, fltk::NumericInput, and fltk::Valuator.

References fltk::belowmouse(), fltk::DND_DRAG, fltk::ENTER, fltk::LEAVE, fltk::MOVE, and redraw_highlight().

Referenced by activate(), fltk::belowmouse(), deactivate(), fltk::focus(), fltk::handle(), fltk::Group::handle(), hide(), fltk::Group::insert(), fltk::paste(), send(), show(), and take_focus().

void Widget::hide (  ) 

bool Widget::horizontal (  )  const [inline]

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.

References fltk::LAYOUT_VERTICAL.

Referenced by fltk::Menu::draw_in(), fltk::Menu::find_selected(), fltk::Menu::get_location(), fltk::Menu::layout_in(), and fltk::Menu::try_popup().

void Widget::invert_flag ( unsigned  f  )  [inline]

Flip the result of flag(f) if f is a single bit. If you or together bits it will flip them all.

Referenced by fltk::Menu::handle_shortcut(), and fltk::Menu::popup().

bool Widget::is_group (  )  const [inline]

Returns true for subclasses of fltk::Group. If so you can cast it to a group with (fltk::Group*)(widget). This is done by using type(), but if your compiler supports RTTI you may want to safer dynamic_cast<fltk: