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).
void down_box (Fl_Boxtype b)
 Sets the down box type.
Fl_Boxtype down_box () const
 Returns the current down box type, which is drawn when value() is non-zero.
void down_color (unsigned c)
 (for backwards compatibility)
Fl_Color down_color () const
 (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).
void shortcut (const char *s)
 (for backwards compatibility)
void shortcut (int s)
 Sets the shortcut key to s.
int shortcut () const
 Returns the current shortcut key for the button.
char value () const
 Returns the current value of the button (0 or 1).
int value (int v)
 Sets the current value of the button.

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:

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:


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.

The default box type is box(FL_UP_BOX).

You can control how the button is drawn when ON by setting down_box(). The default is FL_NO_BOX (0) which will select an appropriate box type using the normal (OFF) box type by using fl_down(box()).

Derived classes may handle this differently.

Parameters:
[in] X,Y,W,H position and size of the widget
[in] L widget label, default is no label

Member Function Documentation

int Fl_Button::clear (  )  [inline]

Same as value(0).

See also:
value(int v)
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().

Some derived classes (e.g. Fl_Round_Button and Fl_Light_Button use down_box() for special purposes. See docs of these classes.

Parameters:
[in] b down box type
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::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] event the kind of event received
Return values:
0 if the event was not used or understood
1 if the event was used and can be deleted
See also:
Fl_Event

Reimplemented from Fl_Widget.

Reimplemented in Fl_Light_Button, Fl_Repeat_Button, and Fl_Return_Button.

int Fl_Button::set (  )  [inline]

Same as value(1).

See also:
value(int v)
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] s bitwise OR of key and shift flags
int Fl_Button::shortcut (  )  const [inline]

Returns the current shortcut key for the button.

Return values:
int 
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] v button value.
See also:
set(), clear()

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