Fl_Input_Choice Class Reference

A combination of the input widget and a menu button. More...

#include <Fl_Input_Choice.H>

Inheritance diagram for Fl_Input_Choice:
Fl_Group Fl_Widget

List of all members.

Classes

class  InputMenuButton

Public Member Functions

void add (const char *s)
 Adds an item to the menu.
int changed () const
 Returns the combined changed() state of the input and menu button widget.
void clear ()
 Removes all items from the menu.
void clear_changed ()
 Clears the changed() state of both input and menu button widgets.
void down_box (Fl_Boxtype b)
 Sets the box type of the menu button.
Fl_Boxtype down_box () const
 Gets the box type of the menu button.
 Fl_Input_Choice (int X, int Y, int W, int H, const char *L=0)
 Creates a new Fl_Input_Choice widget using the given position, size, and label string.
Fl_Inputinput ()
 Returns a pointer to the internal Fl_Input widget.
void menu (const Fl_Menu_Item *m)
 Sets the Fl_Menu_Item array used for the menu.
const Fl_Menu_Itemmenu ()
 Gets the Fl_Menu_Item array used for the menu.
Fl_Menu_Buttonmenubutton ()
 Returns a pointer to the internal Fl_Menu_Button widget.
void resize (int X, int Y, int W, int H)
 Resizes the Fl_Group widget and all of its children.
void set_changed ()
 Sets the changed() state of both input and menu button widgets to the specfied value.
void textcolor (Fl_Color c)
 Sets the Fl_Input text field's text color to c.
Fl_Color textcolor () const
 Gets the Fl_Input text field's text color.
void textfont (Fl_Font f)
 Sets the Fl_Input text field's font style to f.
Fl_Font textfont () const
 Gets the Fl_Input text field's font style.
void textsize (Fl_Fontsize s)
 Sets the Fl_Input text field's font size to s.
Fl_Fontsize textsize () const
 Gets the Fl_Input text field's font size.
void value (int val)
 Chooses item# val in the menu, and sets the Fl_Input text field to that value.
void value (const char *val)
 Sets the Fl_Input text field's contents to val.
const char * value () const
 Returns the Fl_Input text field's current contents.

Detailed Description

A combination of the input widget and a menu button.

input_choice.jpg

The user can either type into the input area, or use the menu button chooser on the right to choose an item which loads the input area with the selected text.

The application can directly access both the internal Fl_Input and Fl_Menu_Button widgets respectively using the input() and menubutton() accessor methods.

The default behavior is to invoke the Fl_Input_Choice::callback() if the user changes the input field's contents, either by typing, pasting, or clicking a different item in the choice menu.

The callback can determine if an item was picked vs. typing into the input field by checking the value of menubutton()->changed(), which will be:

Example use:

  #include <stdio.h>
  #include <FL/Fl.H>
  #include <FL/Fl_Double_Window.H>
  #include <FL/Fl_Input_Choice.H>
  void choice_cb(Fl_Widget *w, void *userdata) {
    // Show info about the picked item
    Fl_Input_Choice *choice = (Fl_Input_Choice*)w;
    const Fl_Menu_Item *item = choice->menubutton()->mvalue();
    printf("*** Choice Callback:\n");
    printf("    item label()='%s'\n", item ? item->label() : "(No item)");
    printf("    item value()=%d\n", choice->menubutton()->value());
    printf("    input value()='%s'\n", choice->input()->value());
    printf("    The user %s\n", choice->menubutton()->changed()
                                    ? "picked a menu item"
                                    : "typed text");
  }
  int main() {
    Fl_Double_Window win(200,100,"Input Choice");
    win.begin();
      Fl_Input_Choice choice(10,10,100,30);
      choice.callback(choice_cb, 0);
      choice.add("Red");
      choice.add("Orange");
      choice.add("Yellow");
      //choice.value("Red");    // uncomment to make "Red" default
    win.end();
    win.show();
    return Fl::run();
  }

Constructor & Destructor Documentation

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

Creates a new Fl_Input_Choice widget using the given position, size, and label string.

Inherited destructor destroys the widget and any values associated with it.


Member Function Documentation

void Fl_Input_Choice::add ( const char *  s  )  [inline]

Adds an item to the menu.

You can access the more complex Fl_Menu_Button::add() methods (setting callbacks, userdata, etc), via menubutton(). Example:

   Fl_Input_Choice *choice = new Fl_Input_Choice(100,10,120,25,"Fonts");
   Fl_Menu_Button *mb = choice->menubutton();             // use Fl_Input_Choice's Fl_Menu_Button
   mb->add("Helvetica", 0, MyFont_CB,     (void*)mydata); // use Fl_Menu_Button's add() methods
   mb->add("Courier",   0, MyFont_CB,     (void*)mydata);
   mb->add("More..",    0, FontDialog_CB, (void*)mydata);
int Fl_Input_Choice::changed (  )  const [inline]

Returns the combined changed() state of the input and menu button widget.

Reimplemented from Fl_Widget.

void Fl_Input_Choice::clear (  )  [inline]

Removes all items from the menu.

Reimplemented from Fl_Group.

void Fl_Input_Choice::clear_changed (  )  [inline]

Clears the changed() state of both input and menu button widgets.

Reimplemented from Fl_Widget.

Fl_Input* Fl_Input_Choice::input (  )  [inline]

Returns a pointer to the internal Fl_Input widget.

This can be used to directly access all of the Fl_Input widget's methods.

void Fl_Input_Choice::menu ( const Fl_Menu_Item m  )  [inline]

Sets the Fl_Menu_Item array used for the menu.

const Fl_Menu_Item* Fl_Input_Choice::menu (  )  [inline]

Gets the Fl_Menu_Item array used for the menu.

Fl_Menu_Button* Fl_Input_Choice::menubutton (  )  [inline]

Returns a pointer to the internal Fl_Menu_Button widget.

This can be used to access any of the methods of the menu button, e.g.

   Fl_Input_Choice *choice = new Fl_Input_Choice(100,10,120,25,"Choice:");
   [..]
   // Print all the items in the choice menu
   for ( int t=0; t<choice->menubutton()->size(); t++ ) {
       const Fl_Menu_Item &item = choice->menubutton()->menu()[t];
       printf("item %d -- label=%s\n", t, item.label() ? item.label() : "(Null)");
   }
void Fl_Input_Choice::resize ( int  X,
int  Y,
int  W,
int  H 
) [inline, virtual]

Resizes the Fl_Group widget and all of its children.

The Fl_Group widget first resizes itself, and then it moves and resizes all its children according to the rules documented for Fl_Group::resizable(Fl_Widget*)

See also:
Fl_Group::resizable(Fl_Widget*)
Fl_Group::resizable()
Fl_Widget::resize(int,int,int,int)

Reimplemented from Fl_Group.

void Fl_Input_Choice::set_changed (  )  [inline]

Sets the changed() state of both input and menu button widgets to the specfied value.

Reimplemented from Fl_Widget.

void Fl_Input_Choice::value ( int  val  )  [inline]

Chooses item# val in the menu, and sets the Fl_Input text field to that value.

Any previous text is cleared.

void Fl_Input_Choice::value ( const char *  val  )  [inline]

Sets the Fl_Input text field's contents to val.

Does not affect the menu selection.


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