FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Input_Choice.H
1 //
2 // "$Id: Fl_Input_Choice.H 9740 2012-12-09 17:45:24Z manolo $"
3 //
4 // An input/chooser widget.
5 // ______________ ____
6 // | || __ |
7 // | input area || \/ |
8 // |______________||____|
9 //
10 // Copyright 1998-2010 by Bill Spitzak and others.
11 // Copyright 2004 by Greg Ercolano.
12 //
13 // This library is free software. Distribution and use rights are outlined in
14 // the file "COPYING" which should have been included with this file. If this
15 // file is missing or damaged, see the license at:
16 //
17 // http://www.fltk.org/COPYING.php
18 //
19 // Please report all bugs and problems on the following page:
20 //
21 // http://www.fltk.org/str.php
22 //
23
24 /* \file
25 Fl_Input_Choice widget . */
26
27 #ifndef Fl_Input_Choice_H
28 #define Fl_Input_Choice_H
29
30 #include <FL/Fl.H>
31 #include <FL/Fl_Group.H>
32 #include <FL/Fl_Input.H>
33 #include <FL/Fl_Menu_Button.H>
34 #include <FL/fl_draw.H>
35 #include <string.h>
36
51 class FL_EXPORT Fl_Input_Choice : public Fl_Group {
52 // Private class to handle slightly 'special' behavior of menu button
53 class InputMenuButton : public Fl_Menu_Button {
54 void draw() {
55 draw_box(FL_UP_BOX, color());
56 fl_color(active_r() ? labelcolor() : fl_inactive(labelcolor()));
57 int xc = x()+w()/2, yc=y()+h()/2;
58 fl_polygon(xc-5,yc-3,xc+5,yc-3,xc,yc+3);
59 if (Fl::focus() == this) draw_focus();
60 }
61 public:
62 InputMenuButton(int X,int Y,int W,int H,const char*L=0) :
63 Fl_Menu_Button(X, Y, W, H, L) { box(FL_UP_BOX); }
64 };
65
66 Fl_Input *inp_;
67 InputMenuButton *menu_;
68
69 static void menu_cb(Fl_Widget*, void *data) {
70 Fl_Input_Choice *o=(Fl_Input_Choice *)data;
71 Fl_Widget_Tracker wp(o);
72 const Fl_Menu_Item *item = o->menubutton()->mvalue();
73 if (item && item->flags & (FL_SUBMENU|FL_SUBMENU_POINTER)) return; // ignore submenus
74 if (!strcmp(o->inp_->value(), o->menu_->text()))
75 {
76 o->Fl_Widget::clear_changed();
77 if (o->when() & FL_WHEN_NOT_CHANGED)
78 o->do_callback();
79 }
80 else
81 {
82 o->inp_->value(o->menu_->text());
83 o->inp_->set_changed();
84 o->Fl_Widget::set_changed();
85 if (o->when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE))
86 o->do_callback();
87 }
88
89 if (wp.deleted()) return;
90
91 if (o->callback() != default_callback)
92 {
93 o->Fl_Widget::clear_changed();
94 o->inp_->clear_changed();
95 }
96 }
97
98 static void inp_cb(Fl_Widget*, void *data) {
99 Fl_Input_Choice *o=(Fl_Input_Choice *)data;
100 Fl_Widget_Tracker wp(o);
101 if (o->inp_->changed()) {
102 o->Fl_Widget::set_changed();
103 if (o->when() & (FL_WHEN_CHANGED|FL_WHEN_RELEASE))
104 o->do_callback();
105 } else {
106 o->Fl_Widget::clear_changed();
107 if (o->when() & FL_WHEN_NOT_CHANGED)
108 o->do_callback();
109 }
110
111 if (wp.deleted()) return;
112
113 if (o->callback() != default_callback)
114 o->Fl_Widget::clear_changed();
115 }
116
117 // Custom resize behavior -- input stretches, menu button doesn't
118 inline int inp_x() { return(x() + Fl::box_dx(box())); }
119 inline int inp_y() { return(y() + Fl::box_dy(box())); }
120 inline int inp_w() { return(w() - Fl::box_dw(box()) - 20); }
121 inline int inp_h() { return(h() - Fl::box_dh(box())); }
122
123 inline int menu_x() { return(x() + w() - 20 - Fl::box_dx(box())); }
124 inline int menu_y() { return(y() + Fl::box_dy(box())); }
125 inline int menu_w() { return(20); }
126 inline int menu_h() { return(h() - Fl::box_dh(box())); }
127
128 public:
134 Fl_Input_Choice(int X,int Y,int W,int H,const char*L=0);
135
147 void add(const char *s) { menu_->add(s); }
149 int changed() const { return inp_->changed() | Fl_Widget::changed(); }
151 void clear_changed() {
152 inp_->clear_changed();
153 Fl_Widget::clear_changed();
154 }
157 void set_changed() {
158 inp_->set_changed();
159 // no need to call Fl_Widget::set_changed()
160 }
162 void clear() { menu_->clear(); }
164 Fl_Boxtype down_box() const { return (menu_->down_box()); }
166 void down_box(Fl_Boxtype b) { menu_->down_box(b); }
168 const Fl_Menu_Item *menu() { return (menu_->menu()); }
170 void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
171 void resize(int X, int Y, int W, int H) {
172 Fl_Group::resize(X,Y,W,H);
173 inp_->resize(inp_x(), inp_y(), inp_w(), inp_h());
174 menu_->resize(menu_x(), menu_y(), menu_w(), menu_h());
175 }
177 Fl_Color textcolor() const { return (inp_->textcolor());}
179 void textcolor(Fl_Color c) { inp_->textcolor(c);}
181 Fl_Font textfont() const { return (inp_->textfont());}
183 void textfont(Fl_Font f) { inp_->textfont(f);}
185 Fl_Fontsize textsize() const { return (inp_->textsize()); }
187 void textsize(Fl_Fontsize s) { inp_->textsize(s); }
189 const char* value() const { return (inp_->value()); }
192 void value(const char *val) { inp_->value(val); }
195 void value(int val) {
196 menu_->value(val);
197 inp_->value(menu_->text(val));
198 }
211 Fl_Menu_Button *menubutton() { return menu_; }
215 Fl_Input *input() { return inp_; }
216 };
217
218 #endif // !Fl_Input_Choice_H
219
220 //
221 // End of "$Id: Fl_Input_Choice.H 9740 2012-12-09 17:45:24Z manolo $".
222 //
Fl_Widget
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:100
FL_WHEN_RELEASE
Do the callback when the button or key is released and the value changes.
Definition: Enumerations.H:313
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:170
Fl_Widget_Tracker::deleted
int deleted()
Returns 1, if the watched widget has been deleted.
Definition: Fl.H:1184
Fl::focus
static Fl_Widget * focus()
Gets the current Fl::focus() widget.
Definition: Fl.H:711
Fl_Widget::x
int x() const
Gets the widget position in its window.
Definition: Fl_Widget.H:273
Fl_Input_Choice::textfont
Fl_Font textfont() const
Gets the Fl_Input text field&#39;s font style.
Definition: Fl_Input_Choice.H:181
Fl.H
Fl static class.
Fl_Widget::changed
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition: Fl_Widget.H:768
Fl_Input_Choice::clear_changed
void clear_changed()
Clears the changed() state of both input and menu button widgets.
Definition: Fl_Input_Choice.H:151
Fl::box_dw
static int box_dw(Fl_Boxtype)
Returns the width offset for the given boxtype.
Definition: fl_boxtype.cxx:341
Fl_Input_Choice::set_changed
void set_changed()
Sets the changed() state of both input and menu button widgets to the specfied value.
Definition: Fl_Input_Choice.H:157
Fl_Widget::h
int h() const
Gets the widget height.
Definition: Fl_Widget.H:288
Fl_Input_Choice::changed
int changed() const
Returns the combined changed() state of the input and menu button widget.
Definition: Fl_Input_Choice.H:149
FL_WHEN_NOT_CHANGED
Do the callback whenever the user interacts with the widget.
Definition: Enumerations.H:312
fl_color
void fl_color(Fl_Color c)
Sets the color for all subsequent drawing operations.
Definition: fl_draw.H:52
Fl_Widget::set_changed
void set_changed()
Marks the value of the widget as changed.
Definition: Fl_Widget.H:773
Fl_Widget::default_callback
static void default_callback(Fl_Widget *cb, void *d)
Sets the default callback for all widgets.
Definition: Fl_Widget.cxx:39
Fl::box_dy
static int box_dy(Fl_Boxtype)
Returns the Y offset for the given boxtype.
Definition: fl_boxtype.cxx:335
Fl_Input_Choice::textsize
Fl_Fontsize textsize() const
Gets the Fl_Input text field&#39;s font size.
Definition: Fl_Input_Choice.H:185
Fl_Widget::w
int w() const
Gets the widget width.
Definition: Fl_Widget.H:283
Fl_Input_Choice::textfont
void textfont(Fl_Font f)
Sets the Fl_Input text field&#39;s font style to f.
Definition: Fl_Input_Choice.H:183
Fl_Input_Choice::down_box
Fl_Boxtype down_box() const
Gets the box type of the menu button.
Definition: Fl_Input_Choice.H:164
Fl_Input_::value
int value(const char *)
Changes the widget text.
Definition: Fl_Input_.cxx:1244
FL_WHEN_CHANGED
Do the callback only when the widget value changes.
Definition: Enumerations.H:311
Fl_Input_Choice::menu
const Fl_Menu_Item * menu()
Gets the Fl_Menu_Item array used for the menu.
Definition: Fl_Input_Choice.H:168
Fl_Boxtype
Fl_Boxtype
Definition: Enumerations.H:469
Fl_Input
This is the FLTK text input widget.
Definition: Fl_Input.H:221
FL_UP_BOX
see figure 1
Definition: Enumerations.H:473
Fl_Widget::y
int y() const
Gets the widget position in its window.
Definition: Fl_Widget.H:278
Fl_Group
The Fl_Group class is the FLTK container widget.
Definition: Fl_Group.H:36
Fl::box_dx
static int box_dx(Fl_Boxtype)
Returns the X offset for the given boxtype.
Definition: fl_boxtype.cxx:310
Fl_Input_Choice
A combination of the input widget and a menu button.
Definition: Fl_Input_Choice.H:51
Fl_Input_Choice::down_box
void down_box(Fl_Boxtype b)
Sets the box type of the menu button.
Definition: Fl_Input_Choice.H:166
Fl_Input_Choice::menubutton
Fl_Menu_Button * menubutton()
Returns a pointer to the internal Fl_Menu_Button widget.
Definition: Fl_Input_Choice.H:211
Fl_Widget::box
Fl_Boxtype box() const
Gets the box type of the widget.
Definition: Fl_Widget.H:352
fl_inactive
FL_EXPORT Fl_Color fl_inactive(Fl_Color c)
Returns the inactive, dimmed version of the given color.
Definition: fl_color.cxx:423
Fl_Input_Choice::resize
void resize(int X, int Y, int W, int H)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Input_Choice.H:171
Fl_Widget::clear_changed
void clear_changed()
Marks the value of the widget as unchanged.
Definition: Fl_Widget.H:778
Fl_Fontsize
int Fl_Fontsize
Size of a font in pixels.
Definition: Enumerations.H:746
Fl::box_dh
static int box_dh(Fl_Boxtype)
Returns the height offset for the given boxtype.
Definition: fl_boxtype.cxx:347
Fl_Widget_Tracker
This class should be used to control safe widget deletion.
Definition: Fl.H:1159
Fl_Group::resize
void resize(int, int, int, int)
Resizes the Fl_Group widget and all of its children.
Definition: Fl_Group.cxx:632
Fl_Input_Choice::textsize
void textsize(Fl_Fontsize s)
Sets the Fl_Input text field&#39;s font size to s.
Definition: Fl_Input_Choice.H:187
fl_draw.H
utility header to pull drawing functions together
Fl_Color
unsigned int Fl_Color
an FLTK color value
Definition: Enumerations.H:774
Fl_Widget::do_callback
void do_callback()
Calls the widget callback.
Definition: Fl_Widget.H:857
Fl_Font
int Fl_Font
A font number is an index into the internal font table.
Definition: Enumerations.H:717
Fl_Input_Choice::value
const char * value() const
Returns the Fl_Input text field&#39;s current contents.
Definition: Fl_Input_Choice.H:189
fl_polygon
void fl_polygon(int x, int y, int x1, int y1, int x2, int y2)
Fills a 3-sided polygon.
Definition: fl_draw.H:244
Fl_Input_Choice::input
Fl_Input * input()
Returns a pointer to the internal Fl_Input widget.
Definition: Fl_Input_Choice.H:215
Fl_Input_Choice::textcolor
void textcolor(Fl_Color c)
Sets the Fl_Input text field&#39;s text color to c.
Definition: Fl_Input_Choice.H:179
Fl_Input_Choice::value
void value(int val)
Chooses item# val in the menu, and sets the Fl_Input text field to that value.
Definition: Fl_Input_Choice.H:195
Fl_Widget::when
Fl_When when() const
Returns the conditions under which the callback is called.
Definition: Fl_Widget.H:608
Fl_Widget::callback
Fl_Callback_p callback() const
Gets the current callback function for the widget.
Definition: Fl_Widget.H:550
Fl_Input_Choice::add
void add(const char *s)
Adds an item to the menu.
Definition: Fl_Input_Choice.H:147
Fl_Input_Choice::value
void value(const char *val)
Sets the Fl_Input text field&#39;s contents to val.
Definition: Fl_Input_Choice.H:192
Fl_Input_Choice::clear
void clear()
Removes all items from the menu.
Definition: Fl_Input_Choice.H:162
Fl_Input_Choice::textcolor
Fl_Color textcolor() const
Gets the Fl_Input text field&#39;s text color.
Definition: Fl_Input_Choice.H:177
- © 1998-2012 by Bill Spitzak and others.