fltk::Button Class Reference

Inherits fltk::Widget.

Inherited by BButton, fltk::CheckButton, fltk::HighlightButton, fltk::RepeatButton, fltk::ReturnButton, and fltk::ToggleButton.

List of all members.

Public Types

enum  { HIDDEN }

Public Member Functions

 Button (int, int, int, int, const char *=0)
void draw (int glyph_width) const
virtual void draw ()
int handle (int event, const Rectangle &)
int handle (int)
bool value () const
bool value (bool v)

Static Public Attributes

static NamedStyledefault_style

Detailed Description

Buttons generate callbacks when they are clicked by the user. You control exactly when and how by changing the values for when():

  • fltk::WHEN_NEVER: The callback is not done, instead changed() is turned on.
  • fltk::WHEN_RELEASE: This is the default, the callback is done after the user successfully clicks the button (i.e. they let it go with the mouse still pointing at it), or when a shortcut is typed.
  • fltk::WHEN_CHANGED : The callback is done each time the value() changes (when the user pushes and releases the button, and as the mouse is dragged around in and out of the button).

Buttons can also generate callbacks in response to fltk::SHORTCUT events. The button can either have an explicit shortcut() value or a letter shortcut can be indicated in the label() with an '&' character before it. For the label shortcut it does not matter if Alt is held down, but if you have an input field in the same window, the user will have to hold down the Alt key so that the input field does not eat the event first as an fltk::KEY event.

buttons.gif

Member Function Documentation

bool Button::value ( ) const [inline]

The current value. True means it is pushed down, false means it is not pushed down. The ToggleButton subclass provides the ability for the user to change this value permanently, otherwise it is just temporary while the user is holding the button down.

This is the same as Widget::state().

bool Button::value ( bool  v) [inline]

Change the value(). Redraws the button and returns true if the new value is different. This is the same function as Widget::state(). See also Widget::set(), Widget::clear(), and Widget::setonly().

If you turn it on, a normal button will draw pushed-in, until the user clicks it and releases it.

void Button::draw ( int  glyph_width) const

This function provides a mess of back-compatabilty and Windows emulation to subclasses of Button to draw with. It will draw the button according to the current state of being pushed and it's state(). If non-zero is passed for glyph_width then the glyph() is drawn in that space on the left (or on the right if negative), and it assummes the glyph indicates the state(), so the box is only used to indicate the pushed state.

References fltk::Style::buttonbox(), fltk::contrast(), fltk::Widget::damage(), fltk::DAMAGE_EXPOSE, fltk::DAMAGE_HIGHLIGHT, fltk::Symbol::draw(), fltk::Widget::draw_background(), fltk::Widget::draw_label(), fltk::drawstyle(), fltk::fillrect(), fltk::Widget::flags(), fltk::Rectangle::h(), fltk::HIGHLIGHT, fltk::Style::highlight_color(), fltk::NO_BOX, fltk::OUTPUT, fltk::Rectangle::r(), fltk::Style::selection_textcolor(), fltk::Rectangle::set_x(), fltk::setbgcolor(), fltk::setcolor(), fltk::Widget::state(), fltk::STATE, fltk::Rectangle::w(), and fltk::Rectangle::x().