FLTK 1.5.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-2024 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()) - menu_w()); }
77 virtual int inp_h() const { return(h() - Fl::box_dh(box())); }
78
84 virtual int menu_x() const { return x() + w() - menu_w() - 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
92 void draw() FL_OVERRIDE;
93
94public:
95
96 Fl_Input_Choice(int X, int Y, int W, int H, const char *L=0);
97
98 void resize(int X, int Y, int W, int H) FL_OVERRIDE;
99
114 void add(const char *s) { menu_->add(s); }
115
117 int changed() const { return inp_->changed() | Fl_Widget::changed(); }
118
119 // Clears the changed() state of both input and menu button widgets.
120 void clear_changed();
121
122 // Sets the changed() state of both input and menu button widgets.
123 void set_changed();
124
126 void clear() { menu_->clear(); }
127
129 Fl_Boxtype down_box() const { return (menu_->down_box()); }
130
132 void down_box(Fl_Boxtype b) { menu_->down_box(b); }
133
135 const Fl_Menu_Item *menu() { return (menu_->menu()); }
136
138 void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
139
141 Fl_Color textcolor() const { return (inp_->textcolor());}
142
144 void textcolor(Fl_Color c) { inp_->textcolor(c);}
145
147 Fl_Font textfont() const { return (inp_->textfont());}
148
150 void textfont(Fl_Font f) { inp_->textfont(f);}
151
153 Fl_Fontsize textsize() const { return (inp_->textsize()); }
154
156 void textsize(Fl_Fontsize s) { inp_->textsize(s); }
157
159 const char* value() const { return (inp_->value()); }
160
171 void value(const char *val) { inp_->value(val); }
172
173 /* Chooses item# \p val in the menu, and sets the Fl_Input text field
174 to that value. Any previous text is cleared. */
175 void value(int val);
176
177 int update_menubutton();
178
191 Fl_Menu_Button *menubutton() { return menu_; }
192
196 Fl_Input *input() { return inp_; }
197};
198
199#endif // !Fl_Input_Choice_H
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1057
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1114
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1086
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:638
Fl static class.
Fl_Group and Fl_End classes.
The Fl_Group class is the main FLTK container widget.
Definition Fl_Group.H:59
void draw() FL_OVERRIDE
Draws the widget.
Definition Fl_Group.cxx:928
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:138
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:156
Fl_Menu_Button * menubutton()
Returns a pointer to the internal Fl_Menu_Button widget.
Definition Fl_Input_Choice.H:191
void textcolor(Fl_Color c)
Sets the Fl_Input text field's text color to c.
Definition Fl_Input_Choice.H:144
Fl_Fontsize textsize() const
Gets the Fl_Input text field's font size.
Definition Fl_Input_Choice.H:153
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
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:147
const Fl_Menu_Item * menu()
Gets the Fl_Menu_Item array used for the menu.
Definition Fl_Input_Choice.H:135
Fl_Color textcolor() const
Gets the Fl_Input text field's text color.
Definition Fl_Input_Choice.H:141
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:159
void down_box(Fl_Boxtype b)
Sets the box type of the menu button.
Definition Fl_Input_Choice.H:132
int changed() const
Returns the combined changed() state of the input and menu button widget.
Definition Fl_Input_Choice.H:117
void value(const char *val)
Sets the Fl_Input text field's contents to val.
Definition Fl_Input_Choice.H:171
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:129
void textfont(Fl_Font f)
Sets the Fl_Input text field's font style to f.
Definition Fl_Input_Choice.H:150
Fl_Input * input()
Returns a pointer to the internal Fl_Input widget.
Definition Fl_Input_Choice.H:196
void clear()
Removes all items from the menu.
Definition Fl_Input_Choice.H:126
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
void clear()
Same as menu(NULL), set the array pointer to null, indicating a zero-length menu.
Definition Fl_Menu_.cxx:562
const Fl_Menu_Item * menu() const
Returns a pointer to the array of Fl_Menu_Items.
Definition Fl_Menu_.H:133
int add(const char *, int shortcut, Fl_Callback *, void *=0, int=0)
Adds a new menu item.
Definition Fl_Menu_add.cxx:348
Fl_Boxtype down_box() const
This box type is used to surround the currently-selected items in the menus.
Definition Fl_Menu_.H:233
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:112
int y() const
Gets the widget position in its window.
Definition Fl_Widget.H:366
int h() const
Gets the widget height.
Definition Fl_Widget.H:376
void set_changed()
Marks the value of the widget as changed.
Definition Fl_Widget.H:1001
int w() const
Gets the widget width.
Definition Fl_Widget.H:371
Fl_Boxtype box() const
Gets the box type of the widget.
Definition Fl_Widget.H:440
void clear_changed()
Marks the value of the widget as unchanged.
Definition Fl_Widget.H:1006
int x() const
Gets the widget position in its window.
Definition Fl_Widget.H:361
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition Fl_Widget.H:996
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition fl_boxtype.cxx:379
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition fl_boxtype.cxx:410
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition fl_boxtype.cxx:404
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition fl_boxtype.cxx:416
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:38
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:124