FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_Input_Choice.H
1//
2// An input/chooser widget.
3// ______________ ____
4// | || __ |
5// | input area || \/ |
6// |______________||____|
7//
8// Copyright 2004 by Greg Ercolano.
9// Copyright 1998-2021 by Bill Spitzak and others.
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/*
34 A combination of the input widget and a menu button.
35
36 The user can either type into the input area, or use the
37 menu button chooser on the right to choose an item which loads
38 the input area with the selected text.
39
40 Note: doxygen docs in src/Fl_Input_Choice.cxx
41*/
42
43class FL_EXPORT Fl_Input_Choice : public Fl_Group {
44
45 // Private class to handle slightly 'special' behavior of menu button
46 class InputMenuButton : public Fl_Menu_Button {
47 void draw() FL_OVERRIDE;
48 const Fl_Menu_Item* popup();
49 public:
50 InputMenuButton(int X, int Y, int W, int H, const char *L=0);
51 int handle(int e) FL_OVERRIDE;
52 };
53
54 Fl_Input *inp_;
55 InputMenuButton *menu_;
56
57 // note: this is used by the Fl_Input_Choice ctor.
58 static void menu_cb(Fl_Widget*, void *data);
59
60 // note: this is used by the Fl_Input_Choice ctor.
61 static void inp_cb(Fl_Widget*, void *data);
62
63protected:
64 // Custom resize behavior -- input stretches, menu button doesn't
65
71 virtual int inp_x() const { return(x() + Fl::box_dx(box())); }
73 virtual int inp_y() const { return(y() + Fl::box_dy(box())); }
75 virtual int inp_w() const { return(w() - Fl::box_dw(box()) - 20); }
77 virtual int inp_h() const { return(h() - Fl::box_dh(box())); }
78
84 virtual int menu_x() const { return(x() + w() - 20 - Fl::box_dx(box())); }
86 virtual int menu_y() const { return(y() + Fl::box_dy(box())); }
88 virtual int menu_w() const { return(20); }
90 virtual int menu_h() const { return(h() - Fl::box_dh(box())); }
91
92public:
93
94 Fl_Input_Choice(int X, int Y, int W, int H, const char *L=0);
95
96 void resize(int X, int Y, int W, int H) FL_OVERRIDE;
97
112 void add(const char *s) { menu_->add(s); }
113
115 int changed() const { return inp_->changed() | Fl_Widget::changed(); }
116
117 // Clears the changed() state of both input and menu button widgets.
118 void clear_changed();
119
120 // Sets the changed() state of both input and menu button widgets.
121 void set_changed();
122
124 void clear() { menu_->clear(); }
125
127 Fl_Boxtype down_box() const { return (menu_->down_box()); }
128
130 void down_box(Fl_Boxtype b) { menu_->down_box(b); }
131
133 const Fl_Menu_Item *menu() { return (menu_->menu()); }
134
136 void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
137
139 Fl_Color textcolor() const { return (inp_->textcolor());}
140
142 void textcolor(Fl_Color c) { inp_->textcolor(c);}
143
145 Fl_Font textfont() const { return (inp_->textfont());}
146
148 void textfont(Fl_Font f) { inp_->textfont(f);}
149
151 Fl_Fontsize textsize() const { return (inp_->textsize()); }
152
154 void textsize(Fl_Fontsize s) { inp_->textsize(s); }
155
157 const char* value() const { return (inp_->value()); }
158
169 void value(const char *val) { inp_->value(val); }
170
171 /* Chooses item# \p val in the menu, and sets the Fl_Input text field
172 to that value. Any previous text is cleared. */
173 void value(int val);
174
175 int update_menubutton();
176
189 Fl_Menu_Button *menubutton() { return menu_; }
190
194 Fl_Input *input() { return inp_; }
195};
196
197#endif // !Fl_Input_Choice_H
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1044
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1101
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1073
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:626
Fl static class.
Fl_Group and Fl_End classes.
The Fl_Group class is the FLTK container widget.
Definition Fl_Group.H:56
void resize(int, int, int, int) FL_OVERRIDE
Resizes the Fl_Group widget and all of its children.
Definition Fl_Group.cxx:823
A combination of the input widget and a menu button.
Definition Fl_Input_Choice.H:43
virtual int menu_x() const
The methods menu_x(), menu_y(), menu_w() and menu_h() return the desired position and size of the int...
Definition Fl_Input_Choice.H:84
void menu(const Fl_Menu_Item *m)
Sets the Fl_Menu_Item array used for the menu.
Definition Fl_Input_Choice.H:136
virtual int menu_h() const
See menu_x() for info.
Definition Fl_Input_Choice.H:90
void textsize(Fl_Fontsize s)
Sets the Fl_Input text field's font size to s.
Definition Fl_Input_Choice.H:154
Fl_Menu_Button * menubutton()
Returns a pointer to the internal Fl_Menu_Button widget.
Definition Fl_Input_Choice.H:189
void textcolor(Fl_Color c)
Sets the Fl_Input text field's text color to c.
Definition Fl_Input_Choice.H:142
Fl_Fontsize textsize() const
Gets the Fl_Input text field's font size.
Definition Fl_Input_Choice.H:151
virtual int menu_w() const
See menu_x() for info.
Definition Fl_Input_Choice.H:88
virtual int inp_w() const
See inp_x() for info.
Definition Fl_Input_Choice.H:75
void add(const char *s)
Adds an item to the menu.
Definition Fl_Input_Choice.H:112
virtual int inp_y() const
See inp_x() for info.
Definition Fl_Input_Choice.H:73
Fl_Font textfont() const
Gets the Fl_Input text field's font style.
Definition Fl_Input_Choice.H:145
const Fl_Menu_Item * menu()
Gets the Fl_Menu_Item array used for the menu.
Definition Fl_Input_Choice.H:133
Fl_Color textcolor() const
Gets the Fl_Input text field's text color.
Definition Fl_Input_Choice.H:139
virtual int inp_h() const
See inp_x() for info.
Definition Fl_Input_Choice.H:77
virtual int menu_y() const
See menu_x() for info.
Definition Fl_Input_Choice.H:86
const char * value() const
Returns the Fl_Input text field's current contents.
Definition Fl_Input_Choice.H:157
void down_box(Fl_Boxtype b)
Sets the box type of the menu button.
Definition Fl_Input_Choice.H:130
int changed() const
Returns the combined changed() state of the input and menu button widget.
Definition Fl_Input_Choice.H:115
void value(const char *val)
Sets the Fl_Input text field's contents to val.
Definition Fl_Input_Choice.H:169
virtual int inp_x() const
The methods inp_x(), inp_y(), inp_w() and inp_h() return the desired position and size of the interna...
Definition Fl_Input_Choice.H:71
Fl_Boxtype down_box() const
Gets the box type of the menu button.
Definition Fl_Input_Choice.H:127
void textfont(Fl_Font f)
Sets the Fl_Input text field's font style to f.
Definition Fl_Input_Choice.H:148
Fl_Input * input()
Returns a pointer to the internal Fl_Input widget.
Definition Fl_Input_Choice.H:194
void clear()
Removes all items from the menu.
Definition Fl_Input_Choice.H:124
Fl_Font textfont() const
Gets the font of the text in the input field.
Definition Fl_Input_.H:427
Fl_Color textcolor() const
Gets the color of the text in the input field.
Definition Fl_Input_.H:446
int value(const char *)
Changes the widget text.
Definition Fl_Input_.cxx:1461
Fl_Fontsize textsize() const
Gets the size of the text in the input field.
Definition Fl_Input_.H:436
This is the FLTK text input widget.
Definition Fl_Input.H:220
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
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:104
int y() const
Gets the widget position in its window.
Definition Fl_Widget.H:358
int h() const
Gets the widget height.
Definition Fl_Widget.H:368
void set_changed()
Marks the value of the widget as changed.
Definition Fl_Widget.H:962
int w() const
Gets the widget width.
Definition Fl_Widget.H:363
Fl_Boxtype box() const
Gets the box type of the widget.
Definition Fl_Widget.H:432
void clear_changed()
Marks the value of the widget as unchanged.
Definition Fl_Widget.H:967
int x() const
Gets the widget position in its window.
Definition Fl_Widget.H:353
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition Fl_Widget.H:957
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition fl_boxtype.cxx:375
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition fl_boxtype.cxx:406
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition fl_boxtype.cxx:400
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition fl_boxtype.cxx:412
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:115