FLTK 1.3.0
Fl_Button Class Reference

Buttons generate callbacks when they are clicked by the user. More...

#include <Fl_Button.H>

Inheritance diagram for Fl_Button:
Fl_Widget Fl_Light_Button Fl_Radio_Button Fl_Repeat_Button Fl_Return_Button Fl_Toggle_Button Fl_Check_Button Fl_Radio_Light_Button Fl_Round_Button Fl_Radio_Round_Button

List of all members.

Public Member Functions

int clear ()
 Same as value(0).
Fl_Boxtype down_box () const
 Returns the current down box type, which is drawn when value() is non-zero.
void down_box (Fl_Boxtype b)
 Sets the down box type.
Fl_Color down_color () const
 (for backwards compatibility)
void down_color (unsigned c)
 (for backwards compatibility)
 Fl_Button (int X, int Y, int W, int H, const char *L=0)
 The constructor creates the button using the given position, size and label.
virtual int handle (int)
 Handles the specified event.
int set ()
 Same as value(1).
void setonly ()
 Turns on this button and turns off all other radio buttons in the group (calling value(1) or set() does not do this).
int shortcut () const
 Returns the current shortcut key for the button.
void shortcut (int s)
 Sets the shortcut key to s.
void shortcut (const char *s)
 (for backwards compatibility)
int value (int v)
 Sets the current value of the button.
char value () const
 Returns the current value of the button (0 or 1).

Protected Member Functions

virtual void draw ()
 Draws the widget.
void simulate_key_action ()

Static Protected Member Functions

static void key_release_timeout (void *)

Static Protected Attributes

static Fl_Widget_Trackerkey_release_tracker = 0

Detailed Description

Buttons generate callbacks when they are clicked by the user.

You control exactly when and how by changing the values for type() and when(). Buttons can also generate callbacks in response to FL_SHORTCUT events. The button can either have an explicit shortcut(int s) 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 FL_KEYBOARD event.

Todo:
Refactor the doxygen comments for Fl_Button type() documentation.

For an Fl_Button object, the type() call returns one of:

  • FL_NORMAL_BUTTON (0): value() remains unchanged after button press.
  • FL_TOGGLE_BUTTON: value() is inverted after button press.
  • FL_RADIO_BUTTON: value() is set to 1 after button press, and all other buttons in the current group with type() == FL_RADIO_BUTTON are set to zero.
Todo:
Refactor the doxygen comments for Fl_Button when() documentation.

For an Fl_Button object, the following when() values are useful, the default being FL_WHEN_RELEASE:

  • 0: The callback is not done, instead changed() is turned on.
  • FL_WHEN_RELEASE: The callback is done after the user successfully clicks the button, or when a shortcut is typed.
  • FL_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).

Constructor & Destructor Documentation

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

The constructor creates the button using the given position, size and label.

Parameters:
[in]X,Y,W,Hposition and size of the widget
[in]Lwidget label, default is no label

Member Function Documentation

int Fl_Button::clear ( ) [inline]

Same as value(0).

See also:
value(int v)
Fl_Boxtype Fl_Button::down_box ( ) const [inline]

Returns the current down box type, which is drawn when value() is non-zero.

Return values:
Fl_Boxtype
void Fl_Button::down_box ( Fl_Boxtype  b) [inline]

Sets the down box type.

The default value of 0 causes FLTK to figure out the correct matching down version of box().

Parameters:
[in]bdown box type
void Fl_Button::draw ( ) [protected, 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()

Implements Fl_Widget.

Reimplemented in Fl_Light_Button, and Fl_Return_Button.

int Fl_Button::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 from Fl_Widget.

Reimplemented in Fl_Light_Button, Fl_Return_Button, and Fl_Repeat_Button.

int Fl_Button::set ( ) [inline]

Same as value(1).

See also:
value(int v)
int Fl_Button::shortcut ( ) const [inline]

Returns the current shortcut key for the button.

Return values:
int
void Fl_Button::shortcut ( int  s) [inline]

Sets the shortcut key to s.

Setting this overrides the use of '&' in the label(). The value is a bitwise OR of a key and a set of shift flags, for example: FL_ALT | 'a', or FL_ALT | (FL_F + 10), or just 'a'. A value of 0 disables the shortcut.

The key can be any value returned by Fl::event_key(), but will usually be an ASCII letter. Use a lower-case letter unless you require the shift key to be held down.

The shift flags can be any set of values accepted by Fl::event_state(). If the bit is on, that shift key must be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in the shift flags (zero for the other bits indicates a "don't care" setting).

Parameters:
[in]sbitwise OR of key and shift flags
int Fl_Button::value ( int  v)

Sets the current value of the button.

A non-zero value sets the button to 1 (ON), and zero sets it to 0 (OFF).

Parameters:
[in]vbutton value.
See also:
set(), clear()

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