FLTK
Fl_Input_Choice.H
1 //
2 // An input/chooser widget.
3 // ______________ ____
4 // | || __ |
5 // | input area || \/ |
6 // |______________||____|
7 //
8 // Copyright 1998-2017 by Bill Spitzak and others.
9 // Copyright 2004 by Greg Ercolano.
10 //
11 // This library is free software. Distribution and use rights are outlined in
12 // the file "COPYING" which should have been included with this file. If this
13 // file is missing or damaged, see the license at:
14 //
15 // https://www.fltk.org/COPYING.php
16 //
17 // Please see the following page on how to report bugs and issues:
18 //
19 // https://www.fltk.org/bugs.php
20 //
21 
22 /* \file
23  Fl_Input_Choice widget . */
24 
25 #ifndef Fl_Input_Choice_H
26 #define Fl_Input_Choice_H
27 
28 #include <FL/Fl.H>
29 #include <FL/Fl_Group.H>
30 #include <FL/Fl_Input.H>
31 #include <FL/Fl_Menu_Button.H>
32 
33 // Leaving these two headers so builds don't break if user includes this
34 // header and uses items from fl_draw or string (but doesn't include in src).
35 // Note: this would ensure compatibility with FLTK 1.3.x.
36 // Shall we? Currently not!
37 // #include <FL/fl_draw.H>
38 // #include <string.h>
39 
40 /*
41  A combination of the input widget and a menu button.
42 
43  The user can either type into the input area, or use the
44  menu button chooser on the right to choose an item which loads
45  the input area with the selected text.
46 
47  Note: doxygen docs in src/Fl_Input_Choice.cxx
48 */
49 
50 class FL_EXPORT Fl_Input_Choice : public Fl_Group {
51 
52  // Private class to handle slightly 'special' behavior of menu button
53  class InputMenuButton : public Fl_Menu_Button {
54  void draw();
55  public:
56  InputMenuButton(int X, int Y, int W, int H, const char *L=0);
57  };
58 
59  Fl_Input *inp_;
60  InputMenuButton *menu_;
61 
62  // note: this is used by the Fl_Input_Choice ctor.
63  static void menu_cb(Fl_Widget*, void *data);
64 
65  // note: this is used by the Fl_Input_Choice ctor.
66  static void inp_cb(Fl_Widget*, void *data);
67 
68  // Custom resize behavior -- input stretches, menu button doesn't
69  inline int inp_x() { return(x() + Fl::box_dx(box())); }
70  inline int inp_y() { return(y() + Fl::box_dy(box())); }
71  inline int inp_w() { return(w() - Fl::box_dw(box()) - 20); }
72  inline int inp_h() { return(h() - Fl::box_dh(box())); }
73 
74  inline int menu_x() { return(x() + w() - 20 - Fl::box_dx(box())); }
75  inline int menu_y() { return(y() + Fl::box_dy(box())); }
76  inline int menu_w() { return(20); }
77  inline int menu_h() { return(h() - Fl::box_dh(box())); }
78 
79 public:
80 
81  Fl_Input_Choice(int X, int Y, int W, int H, const char *L=0);
82 
83  void resize(int X, int Y, int W, int H);
84 
99  void add(const char *s) { menu_->add(s); }
100 
102  int changed() const { return inp_->changed() | Fl_Widget::changed(); }
103 
104  // Clears the changed() state of both input and menu button widgets.
105  void clear_changed();
106 
107  // Sets the changed() state of both input and menu button widgets.
108  void set_changed();
109 
111  void clear() { menu_->clear(); }
112 
114  Fl_Boxtype down_box() const { return (menu_->down_box()); }
115 
117  void down_box(Fl_Boxtype b) { menu_->down_box(b); }
118 
120  const Fl_Menu_Item *menu() { return (menu_->menu()); }
121 
123  void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
124 
126  Fl_Color textcolor() const { return (inp_->textcolor());}
127 
129  void textcolor(Fl_Color c) { inp_->textcolor(c);}
130 
132  Fl_Font textfont() const { return (inp_->textfont());}
133 
135  void textfont(Fl_Font f) { inp_->textfont(f);}
136 
138  Fl_Fontsize textsize() const { return (inp_->textsize()); }
139 
141  void textsize(Fl_Fontsize s) { inp_->textsize(s); }
142 
144  const char* value() const { return (inp_->value()); }
145 
156  void value(const char *val) { inp_->value(val); }
157 
158  /* Chooses item# \p val in the menu, and sets the Fl_Input text field
159  to that value. Any previous text is cleared. */
160  void value(int val);
161 
162  int update_menubutton();
163 
176  Fl_Menu_Button *menubutton() { return menu_; }
177 
181  Fl_Input *input() { return inp_; }
182 };
183 
184 #endif // !Fl_Input_Choice_H
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
Fl_Boxtype down_box() const
Gets the box type of the menu button.
Definition: Fl_Input_Choice.H:114
void menu(const Fl_Menu_Item *m)
Sets the Fl_Menu_Item array used for the menu.
Definition: Fl_Input_Choice.H:123
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition: Fl_Input_.H:397
Fl static class.
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition: fl_boxtype.cxx:392
This is a button that when pushed pops up a menu (or hierarchy of menus) defined by an array of Fl_Me...
Definition: Fl_Menu_Button.H:56
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition: fl_boxtype.cxx:386
void textfont(Fl_Font f)
Sets the Fl_Input text field&#39;s font style to f.
Definition: Fl_Input_Choice.H:135
int value(const char *)
Changes the widget text.
Definition: Fl_Input_.cxx:1296
const Fl_Menu_Item * menu()
Gets the Fl_Menu_Item array used for the menu.
Definition: Fl_Input_Choice.H:120
Fl_Boxtype
FLTK standard box types.
Definition: Enumerations.H:598
This is the FLTK text input widget.
Definition: Fl_Input.H:220
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:42
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition: fl_boxtype.cxx:361
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition: Fl_Input_.H:388
A combination of the input widget and a menu button.
Definition: Fl_Input_Choice.H:50
void down_box(Fl_Boxtype b)
Sets the box type of the menu button.
Definition: Fl_Input_Choice.H:117
Fl_Menu_Button * menubutton()
Returns a pointer to the internal Fl_Menu_Button widget.
Definition: Fl_Input_Choice.H:176
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:1014
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition: fl_boxtype.cxx:398
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition: Fl_Widget.H:791
void textsize(Fl_Fontsize s)
Sets the Fl_Input text field&#39;s font size to s.
Definition: Fl_Input_Choice.H:141
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class...
Definition: Fl_Menu_Item.H:107
Fl_Fontsize textsize() const
Gets the Fl_Input text field&#39;s font size.
Definition: Fl_Input_Choice.H:138
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:985
Fl_Input * input()
Returns a pointer to the internal Fl_Input widget.
Definition: Fl_Input_Choice.H:181
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition: Fl_Input_.H:407
void textcolor(Fl_Color c)
Sets the Fl_Input text field&#39;s text color to c.
Definition: Fl_Input_Choice.H:129
Fl_Font textfont() const
Gets the Fl_Input text field&#39;s font style.
Definition: Fl_Input_Choice.H:132
Fl_Color textcolor() const
Gets the Fl_Input text field&#39;s text color.
Definition: Fl_Input_Choice.H:126
int changed() const
Returns the combined changed() state of the input and menu button widget.
Definition: Fl_Input_Choice.H:102
void add(const char *s)
Adds an item to the menu.
Definition: Fl_Input_Choice.H:99
void value(const char *val)
Sets the Fl_Input text field&#39;s contents to val.
Definition: Fl_Input_Choice.H:156
const char * value() const
Returns the Fl_Input text field&#39;s current contents.
Definition: Fl_Input_Choice.H:144
void clear()
Removes all items from the menu.
Definition: Fl_Input_Choice.H:111