FLTK 1.4.5: Fl_Input_Choice.H Source File

FLTK 1.4.5

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
43 class 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
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:1063
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:1092
Fl_Boxtype
Fl_Boxtype
FLTK standard box types.
Definition Enumerations.H:644
Fl.H
Fl static class.
Fl_Group.H
Fl_Group and Fl_End classes.
Fl_Group::handle
int handle(int) FL_OVERRIDE
Handles the specified event.
Definition Fl_Group.cxx:145
Fl_Input_Choice
A combination of the input widget and a menu button.
Definition Fl_Input_Choice.H:43
Fl_Input_Choice::menu_x
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
Fl_Input_Choice::menu
void menu(const Fl_Menu_Item *m)
Sets the Fl_Menu_Item array used for the menu.
Definition Fl_Input_Choice.H:138
Fl_Input_Choice::menu_h
virtual int menu_h() const
See menu_x() for info.
Definition Fl_Input_Choice.H:90
Fl_Input_Choice::textsize
void textsize(Fl_Fontsize s)
Sets the Fl_Input text field's font size to s.
Definition Fl_Input_Choice.H:156
Fl_Input_Choice::menubutton
Fl_Menu_Button * menubutton()
Returns a pointer to the internal Fl_Menu_Button widget.
Definition Fl_Input_Choice.H:191
Fl_Input_Choice::textcolor
void textcolor(Fl_Color c)
Sets the Fl_Input text field's text color to c.
Definition Fl_Input_Choice.H:144
Fl_Input_Choice::textsize
Fl_Fontsize textsize() const
Gets the Fl_Input text field's font size.
Definition Fl_Input_Choice.H:153
Fl_Input_Choice::menu_w
virtual int menu_w() const
See menu_x() for info.
Definition Fl_Input_Choice.H:88
Fl_Input_Choice::inp_w
virtual int inp_w() const
See inp_x() for info.
Definition Fl_Input_Choice.H:75
Fl_Input_Choice::add
void add(const char *s)
Adds an item to the menu.
Definition Fl_Input_Choice.H:114
Fl_Input_Choice::inp_y
virtual int inp_y() const
See inp_x() for info.
Definition Fl_Input_Choice.H:73
Fl_Input_Choice::textfont
Fl_Font textfont() const
Gets the Fl_Input text field's font style.
Definition Fl_Input_Choice.H:147
Fl_Input_Choice::menu
const Fl_Menu_Item * menu()
Gets the Fl_Menu_Item array used for the menu.
Definition Fl_Input_Choice.H:135
Fl_Input_Choice::textcolor
Fl_Color textcolor() const
Gets the Fl_Input text field's text color.
Definition Fl_Input_Choice.H:141
Fl_Input_Choice::inp_h
virtual int inp_h() const
See inp_x() for info.
Definition Fl_Input_Choice.H:77
Fl_Input_Choice::menu_y
virtual int menu_y() const
See menu_x() for info.
Definition Fl_Input_Choice.H:86
Fl_Input_Choice::value
const char * value() const
Returns the Fl_Input text field's current contents.
Definition Fl_Input_Choice.H:159
Fl_Input_Choice::draw
void draw() FL_OVERRIDE
Draws the widget.
Definition Fl_Input_Choice.cxx:348
Fl_Input_Choice::down_box
void down_box(Fl_Boxtype b)
Sets the box type of the menu button.
Definition Fl_Input_Choice.H:132
Fl_Input_Choice::changed
int changed() const
Returns the combined changed() state of the input and menu button widget.
Definition Fl_Input_Choice.H:117
Fl_Input_Choice::value
void value(const char *val)
Sets the Fl_Input text field's contents to val.
Definition Fl_Input_Choice.H:171
Fl_Input_Choice::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.
Definition Fl_Input_Choice.cxx:261
Fl_Input_Choice::inp_x
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_Input_Choice::down_box
Fl_Boxtype down_box() const
Gets the box type of the menu button.
Definition Fl_Input_Choice.H:129
Fl_Input_Choice::textfont
void textfont(Fl_Font f)
Sets the Fl_Input text field's font style to f.
Definition Fl_Input_Choice.H:150
Fl_Input_Choice::input
Fl_Input * input()
Returns a pointer to the internal Fl_Input widget.
Definition Fl_Input_Choice.H:196
Fl_Input_Choice::clear
void clear()
Removes all items from the menu.
Definition Fl_Input_Choice.H:126
Fl_Input
This is the FLTK text input widget.
Definition Fl_Input.H:220
Fl_Widget::box
Fl_Boxtype box() const
Gets the box type of the widget.
Definition Fl_Widget.H:440
Fl_Widget::x
void x(int v)
Internal use only.
Definition Fl_Widget.H:150
Fl_Widget::w
void w(int v)
Internal use only.
Definition Fl_Widget.H:154
Fl_Widget::y
void y(int v)
Internal use only.
Definition Fl_Widget.H:152
Fl_Widget::h
void h(int v)
Internal use only.
Definition Fl_Widget.H:156
Fl_Widget::changed
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition Fl_Widget.H:996
Fl::box_dx
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition fl_boxtype.cxx:379
Fl::box_dw
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition fl_boxtype.cxx:410
Fl::box_dy
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition fl_boxtype.cxx:404
Fl::box_dh
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition fl_boxtype.cxx:416
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46