fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Button Class Reference

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

#include <Fl_Button.H>

Inheritance diagram for Fl_Button:
[legend]
Collaboration diagram for Fl_Button:
[legend]

Public Member Functions

virtual int handle (int)
 
 Fl_Button (int X, int Y, int W, int H, const char *L=0)
 
int value (int v)
 
char value () const
 
int set ()
 
int clear ()
 
void setonly ()
 
int shortcut () const
 
void shortcut (int s)
 
Fl_Boxtype down_box () const
 
void down_box (Fl_Boxtype b)
 
void shortcut (const char *s)
 (for backwards compatibility) More...
 
Fl_Color down_color () const
 (for backwards compatibility) More...
 
void down_color (unsigned c)
 (for backwards compatibility) More...
 
- Public Member Functions inherited from Fl_Widget
virtual ~Fl_Widget ()
 
int is_label_copied () const
 
Fl_Groupparent () const
 
void parent (Fl_Group *p)
 
uchar type () const
 
void type (uchar t)
 
int x () const
 
int y () const
 
int w () const
 
int h () const
 
virtual void resize (int x, int y, int w, int h)
 
int damage_resize (int, int, int, int)
 
void position (int X, int Y)
 
void size (int W, int H)
 
Fl_Align align () const
 
void align (Fl_Align alignment)
 
Fl_Boxtype box () const
 
void box (Fl_Boxtype new_box)
 
Fl_Color color () const
 
void color (Fl_Color bg)
 
Fl_Color selection_color () const
 
void selection_color (Fl_Color a)
 
void color (Fl_Color bg, Fl_Color sel)
 
const char * label () const
 
void label (const char *text)
 
void copy_label (const char *new_label)
 
void label (Fl_Labeltype a, const char *b)
 
Fl_Labeltype labeltype () const
 
void labeltype (Fl_Labeltype a)
 
Fl_Color labelcolor () const
 
void labelcolor (Fl_Color c)
 
Fl_Font labelfont () const
 
void labelfont (Fl_Font f)
 
Fl_Fontsize labelsize () const
 
void labelsize (Fl_Fontsize pix)
 
Fl_Imageimage ()
 
const Fl_Imageimage () const
 
void image (Fl_Image *img)
 
void image (Fl_Image &img)
 
Fl_Imagedeimage ()
 
const Fl_Imagedeimage () const
 
void deimage (Fl_Image *img)
 
void deimage (Fl_Image &img)
 
const char * tooltip () const
 
void tooltip (const char *text)
 
void copy_tooltip (const char *text)
 
Fl_Callback_p callback () const
 
void callback (Fl_Callback *cb, void *p)
 
void callback (Fl_Callback *cb)
 
void callback (Fl_Callback0 *cb)
 
void callback (Fl_Callback1 *cb, long p=0)
 
void * user_data () const
 
void user_data (void *v)
 
long argument () const
 
void argument (long v)
 
Fl_When when () const
 
void when (uchar i)
 
unsigned int visible () const
 
int visible_r () const
 
virtual void show ()
 
virtual void hide ()
 
void set_visible ()
 
void clear_visible ()
 
unsigned int active () const
 
int active_r () const
 
void activate ()
 
void deactivate ()
 
unsigned int output () const
 
void set_output ()
 
void clear_output ()
 
unsigned int takesevents () const
 
unsigned int changed () const
 
void set_changed ()
 
void clear_changed ()
 
void clear_active ()
 
void set_active ()
 
int take_focus ()
 
void set_visible_focus ()
 
void clear_visible_focus ()
 
void visible_focus (int v)
 
unsigned int visible_focus ()
 
void do_callback ()
 
void do_callback (Fl_Widget *o, long arg)
 
void do_callback (Fl_Widget *o, void *arg=0)
 
int test_shortcut ()
 
void _set_fullscreen ()
 
void _clear_fullscreen ()
 
int contains (const Fl_Widget *w) const
 
int inside (const Fl_Widget *wgt) const
 
void redraw ()
 
void redraw_label ()
 
uchar damage () const
 
void clear_damage (uchar c=0)
 
void damage (uchar c)
 
void damage (uchar c, int x, int y, int w, int h)
 
void draw_label (int, int, int, int, Fl_Align) const
 
void measure_label (int &ww, int &hh) const
 
Fl_Windowwindow () const
 
Fl_Windowtop_window () const
 
Fl_Windowtop_window_offset (int &xoff, int &yoff) const
 
virtual Fl_Groupas_group ()
 
virtual Fl_Windowas_window ()
 
virtual class Fl_Gl_Windowas_gl_window ()
 
int use_accents_menu ()
 
Fl_Color color2 () const
 
void color2 (unsigned a)
 

Protected Member Functions

void simulate_key_action ()
 
virtual void draw ()
 
- Protected Member Functions inherited from Fl_Widget
 Fl_Widget (int x, int y, int w, int h, const char *label=0L)
 
void x (int v)
 
void y (int v)
 
void w (int v)
 
void h (int v)
 
unsigned int flags () const
 
void set_flag (unsigned int c)
 
void clear_flag (unsigned int c)
 
void draw_box () const
 
void draw_box (Fl_Boxtype t, Fl_Color c) const
 
void draw_box (Fl_Boxtype t, int x, int y, int w, int h, Fl_Color c) const
 
void draw_backdrop () const
 
void draw_focus ()
 
void draw_focus (Fl_Boxtype t, int x, int y, int w, int h) const
 
void draw_label () const
 
void draw_label (int, int, int, int) const
 

Static Protected Member Functions

static void key_release_timeout (void *)
 

Static Protected Attributes

static Fl_Widget_Trackerkey_release_tracker = 0
 

Private Attributes

int shortcut_
 
char value_
 
char oldval
 
uchar down_box_
 

Additional Inherited Members

- Static Public Member Functions inherited from Fl_Widget
static void default_callback (Fl_Widget *cb, void *d)
 
static unsigned int label_shortcut (const char *t)
 
static int test_shortcut (const char *, const bool require_alt=false)
 
- Protected Types inherited from Fl_Widget
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
}
 

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

Definition at line 79 of file Fl_Button.H.

Constructor & Destructor Documentation

◆ Fl_Button()

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,Hposition and size of the widget
[in]Lwidget label, default is no label

Definition at line 213 of file Fl_Button.cxx.

References Fl_Widget::box(), down_box(), FL_NO_BOX, FL_UP_BOX, oldval, Fl_Widget::set_flag(), shortcut_, Fl_Widget::SHORTCUT_LABEL, and value_.

Member Function Documentation

◆ clear()

int Fl_Button::clear ( )
inline

Same as value(0).

See also
value(int v)

Definition at line 117 of file Fl_Button.H.

Referenced by align_cb().

◆ down_box() [1/2]

◆ down_box() [2/2]

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]bdown box type

Definition at line 163 of file Fl_Button.H.

References fl_old_shortcut().

◆ down_color() [1/2]

Fl_Color Fl_Button::down_color ( ) const
inline

(for backwards compatibility)

Definition at line 169 of file Fl_Button.H.

References Fl_Widget::selection_color().

◆ down_color() [2/2]

void Fl_Button::down_color ( unsigned  c)
inline

(for backwards compatibility)

Definition at line 172 of file Fl_Button.H.

◆ draw()

void Fl_Button::draw ( )
protectedvirtual

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, Fl_Return_Button, and Shortcut_Button.

Definition at line 69 of file Fl_Button.cxx.

References Fl_Widget::box(), Fl_Widget::color(), down_box(), Fl_Widget::draw_backdrop(), Fl_Widget::draw_box(), Fl_Widget::draw_focus(), Fl_Widget::draw_label(), fl_contrast(), fl_down(), FL_HIDDEN_BUTTON, FL_NORMAL_LABEL, Fl::focus(), Fl_Widget::labelcolor(), Fl_Widget::labeltype(), Fl_Widget::selection_color(), Fl_Widget::type(), and value().

◆ handle()

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

< is set to 1 at button press, and all other buttons in the same group with type() == FL_RADIO_BUTTON are set to zero.

< is set to 1 at button press, and all other buttons in the same group with type() == FL_RADIO_BUTTON are set to zero.

< is set to 1 at button press, and all other buttons in the same group with type() == FL_RADIO_BUTTON are set to zero.

Reimplemented from Fl_Widget.

Reimplemented in Fl_Light_Button, Fl_Return_Button, Fl_Repeat_Button, and Shortcut_Button.

Definition at line 83 of file Fl_Button.cxx.

References Fl_Widget::box(), Fl_Widget::clear_changed(), Fl_Widget::damage(), Fl_Widget_Tracker::deleted(), Fl_Widget::do_callback(), Fl::event_inside(), Fl::event_key(), Fl::event_state(), FL_ALT, FL_CTRL, FL_DAMAGE_ALL, FL_DRAG, FL_ENTER, FL_FOCUS, FL_KEYBOARD, FL_LEAVE, FL_META, FL_NO_BOX, FL_PUSH, FL_RADIO_BUTTON, FL_RELEASE, FL_SHIFT, FL_SHORTCUT, FL_TOGGLE_BUTTON, FL_UNFOCUS, FL_WHEN_CHANGED, FL_WHEN_NOT_CHANGED, FL_WHEN_RELEASE, Fl::focus(), Fl_Widget::h(), oldval, Fl_Widget::redraw(), Fl_Widget::set_changed(), setonly(), shortcut(), simulate_key_action(), Fl::test_shortcut(), Fl_Widget::test_shortcut(), Fl_Widget::type(), value(), value_, Fl::visible_focus(), Fl_Widget::w(), Fl_Widget::when(), Fl_Widget::window(), Fl_Widget::x(), Y, and Fl_Widget::y().

Referenced by Shortcut_Button::handle(), Fl_Repeat_Button::handle(), Fl_Return_Button::handle(), and Fl_Light_Button::handle().

◆ key_release_timeout()

void Fl_Button::key_release_timeout ( void *  d)
staticprotected

◆ set()

int Fl_Button::set ( )
inline

Same as value(1).

See also
value(int v)

Definition at line 111 of file Fl_Button.H.

◆ setonly()

void Fl_Button::setonly ( )

Turns on this button and turns off all other radio buttons in the group (calling value(1) or set() does not do this).

< is set to 1 at button press, and all other buttons in the same group with type() == FL_RADIO_BUTTON are set to zero.

Definition at line 59 of file Fl_Button.cxx.

References Fl_Group::array(), Fl_Group::children(), FL_RADIO_BUTTON, Fl_Widget::parent(), Fl_Widget::type(), and value().

Referenced by handle(), print_update_status(), show_grid_cb(), and Fl_PostScript_Printer::start_job().

◆ shortcut() [1/3]

int Fl_Button::shortcut ( ) const
inline

◆ shortcut() [2/3]

void Fl_Button::shortcut ( const char *  s)
inline

(for backwards compatibility)

Definition at line 166 of file Fl_Button.H.

References Fl_Widget::selection_color().

◆ shortcut() [3/3]

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

Definition at line 146 of file Fl_Button.H.

◆ simulate_key_action()

void Fl_Button::simulate_key_action ( )
protected

◆ value() [1/2]

char Fl_Button::value ( ) const
inline

◆ value() [2/2]

Member Data Documentation

◆ down_box_

uchar Fl_Button::down_box_
private

Definition at line 84 of file Fl_Button.H.

◆ key_release_tracker

Fl_Widget_Tracker * Fl_Button::key_release_tracker = 0
staticprotected

Definition at line 88 of file Fl_Button.H.

Referenced by key_release_timeout(), and simulate_key_action().

◆ oldval

char Fl_Button::oldval
private

Definition at line 83 of file Fl_Button.H.

Referenced by Fl_Button(), handle(), and value().

◆ shortcut_

int Fl_Button::shortcut_
private

Definition at line 81 of file Fl_Button.H.

Referenced by Fl_Button().

◆ value_

char Fl_Button::value_
private

Definition at line 82 of file Fl_Button.H.

Referenced by Fl_Button(), handle(), and value().


The documentation for this class was generated from the following files:
Fl_Widget
Definition: Fl_Widget.H:101
Fl_Widget::draw
virtual void draw()=0