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_Choice Class Reference

A button that is used to pop up a menu. More...

#include <Fl_Choice.H>

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

Public Member Functions

int handle (int)
 
 Fl_Choice (int X, int Y, int W, int H, const char *L=0)
 
int value () const
 
int value (int v)
 
int value (const Fl_Menu_Item *v)
 
- Public Member Functions inherited from Fl_Menu_
 Fl_Menu_ (int, int, int, int, const char *=0)
 
 ~Fl_Menu_ ()
 
int item_pathname (char *name, int namelen, const Fl_Menu_Item *finditem=0) const
 
const Fl_Menu_Itempicked (const Fl_Menu_Item *)
 
const Fl_Menu_Itemfind_item (const char *name)
 
const Fl_Menu_Itemfind_item (Fl_Callback *)
 
int find_index (const char *name) const
 
int find_index (const Fl_Menu_Item *item) const
 
int find_index (Fl_Callback *cb) const
 
const Fl_Menu_Itemtest_shortcut ()
 
void global ()
 
const Fl_Menu_Itemmenu () const
 
void menu (const Fl_Menu_Item *m)
 
void copy (const Fl_Menu_Item *m, void *user_data=0)
 
int insert (int index, const char *, int shortcut, Fl_Callback *, void *=0, int=0)
 
int add (const char *, int shortcut, Fl_Callback *, void *=0, int=0)
 
int add (const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
 
int insert (int index, const char *a, const char *b, Fl_Callback *c, void *d=0, int e=0)
 
int add (const char *)
 
int size () const
 
void size (int W, int H)
 
void clear ()
 
int clear_submenu (int index)
 
void replace (int, const char *)
 
void remove (int)
 
void shortcut (int i, int s)
 
void mode (int i, int fl)
 
int mode (int i) const
 
const Fl_Menu_Itemmvalue () const
 
int value () const
 
int value (const Fl_Menu_Item *)
 
int value (int i)
 
const char * text () const
 
const char * text (int i) const
 
Fl_Font textfont () const
 
void textfont (Fl_Font c)
 
Fl_Fontsize textsize () const
 
void textsize (Fl_Fontsize c)
 
Fl_Color textcolor () const
 
void textcolor (Fl_Color c)
 
Fl_Boxtype down_box () const
 
void down_box (Fl_Boxtype b)
 
Fl_Color down_color () const
 
void down_color (unsigned c)
 
void setonly (Fl_Menu_Item *item)
 
- 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 draw ()
 
- Protected Member Functions inherited from Fl_Menu_
int item_pathname_ (char *name, int namelen, const Fl_Menu_Item *finditem, const Fl_Menu_Item *menu=0) const
 
- 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
 

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
}
 
- Protected Attributes inherited from Fl_Menu_
uchar alloc
 
uchar down_box_
 
Fl_Font textfont_
 
Fl_Fontsize textsize_
 
Fl_Color textcolor_
 

Detailed Description

A button that is used to pop up a menu.

This is a button that, when pushed, pops up a menu (or hierarchy of menus) defined by an array of Fl_Menu_Item objects. Motif calls this an OptionButton.

The only difference between this and a Fl_Menu_Button is that the name of the most recent chosen menu item is displayed inside the box, while the label is displayed outside the box. However, since the use of this is most often to control a single variable rather than do individual callbacks, some of the Fl_Menu_Button methods are redescribed here in those terms.

When the user clicks a menu item, value() is set to that item and then:

- The item's callback is done if one has been set; the
  Fl_Choice is passed as the Fl_Widget* argument, 
  along with any userdata configured for the callback.

- If the item does not have a callback, the Fl_Choice widget's
  callback is done instead, along with any userdata configured
  for it.  The callback can determine which item was picked using
  value(), mvalue(), item_pathname(), etc.

All three mouse buttons pop up the menu. The Forms behavior of the first two buttons to increment/decrement the choice is not implemented. This could be added with a subclass, however.

The menu will also pop up in response to shortcuts indicated by putting a '&' character in the label(). See Fl_Button::shortcut(int s) for a description of this.

Typing the shortcut() of any of the items will do exactly the same as when you pick the item with the mouse. The '&' character in item names are only looked at when the menu is popped up, however.

Todo:
Refactor the doxygen comments for Fl_Choice changed() documentation.

Definition at line 83 of file Fl_Choice.H.

Constructor & Destructor Documentation

◆ Fl_Choice()

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

Create a new Fl_Choice widget using the given position, size and label string. The default boxtype is FL_UP_BOX.

The constructor sets menu() to NULL. See Fl_Menu_ for the methods to set or change the menu.

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

Definition at line 138 of file Fl_Choice.cxx.

References Fl_Widget::align(), Fl_Widget::box(), Fl_Menu_::down_box(), FL_ALIGN_LEFT, FL_BORDER_BOX, FL_FLAT_BOX, FL_HELVETICA, FL_WHEN_RELEASE, Fl_Menu_::textfont(), and Fl_Widget::when().

Member Function Documentation

◆ draw()

void Fl_Choice::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.

Definition at line 28 of file Fl_Choice.cxx.

References Fl_Menu_Item::activate(), Fl_Menu_Item::active(), Fl_Widget::active_r(), Fl_Widget::box(), Fl::box_dx(), Fl::box_dy(), Fl_Label::color, Fl_Widget::color(), Fl_Menu_Item::deactivate(), Fl_Label::deimage, Fl_Label::draw(), Fl_Menu_Item::draw(), Fl_Widget::draw_box(), Fl_Widget::draw_focus(), Fl_Widget::draw_label(), dx, dy, FL_ALIGN_LEFT, FL_BACKGROUND2_COLOR, fl_color(), fl_contrast(), fl_darker(), FL_DOWN_BOX, fl_draw_shortcut, fl_inactive(), fl_lighter(), fl_polygon(), fl_pop_clip(), fl_push_clip(), FL_UP_BOX, fl_yxline(), Fl::focus(), Fl_Label::font, H, Fl_Widget::h(), Fl_Label::image, Fl::is_scheme(), Fl_Widget::labelcolor(), Fl_Menu_Item::labelcolor_, Fl_Menu_Item::labelfont_, Fl_Menu_Item::labelsize_, Fl_Menu_Item::labeltype_, Fl_Menu_::mvalue(), Fl::scheme(), Fl_Label::size, Fl_Menu_Item::text, Fl_Menu_::textcolor(), Fl_Menu_::textfont(), Fl_Menu_::textsize(), Fl_Label::type, Fl_Label::value, Fl_Widget::w(), Fl_Widget::x(), Y, and Fl_Widget::y().

◆ handle()

int Fl_Choice::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.

Definition at line 173 of file Fl_Choice.cxx.

References Fl_Widget::color(), Fl_Widget_Tracker::deleted(), Fl::event_key(), Fl::event_state(), FL_ALT, FL_BACKGROUND2_COLOR, fl_contrast(), FL_CTRL, FL_ENTER, FL_FOCUS, FL_KEYBOARD, FL_LEAVE, FL_META, FL_PUSH, FL_SHIFT, FL_SHORTCUT, FL_UNFOCUS, Fl::focus(), Fl_Widget::h(), Fl_Menu_::menu(), Fl_Menu_::mvalue(), Fl_Menu_::picked(), Fl_Menu_Item::pulldown(), Fl_Widget::redraw(), Fl::scheme(), Fl_Menu_Item::submenu(), Fl_Menu_Item::test_shortcut(), Fl_Widget::test_shortcut(), Fl_Menu_::text(), Fl_Menu_::textcolor(), Fl::visible_focus(), Fl_Widget::w(), Fl_Widget::x(), and Fl_Widget::y().

◆ value() [1/3]

◆ value() [2/3]

int Fl_Choice::value ( const Fl_Menu_Item v)

Sets the currently selected value using a pointer to menu item. Changing the selected value causes a redraw().

Parameters
[in]vpointer to menu item in the menu item array.
Returns
non-zero if the new value is different to the old one.

Definition at line 153 of file Fl_Choice.cxx.

References Fl_Widget::redraw(), and Fl_Menu_::value().

◆ value() [3/3]

int Fl_Choice::value ( int  v)

Sets the currently selected value using the index into the menu item array. Changing the selected value causes a redraw().

Parameters
[in]vindex of value in the menu item array.
Returns
non-zero if the new value is different to the old one.

Definition at line 165 of file Fl_Choice.cxx.

References Fl_Widget::redraw(), Fl_Menu_::size(), value(), and Fl_Menu_::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