2 // "$Id: Fl_Value_Input.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Value input widget for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // FLTK widget for drag-adjusting a floating point value.
29 // Warning: this works by making a child Fl_Input object, even
30 // though this object is *not* an Fl_Group. May be a kludge?
33 #include <FL/Fl_Value_Input.H>
34 #include <FL/Fl_Group.H>
39 void Fl_Value_Input::input_cb(Fl_Widget
*, void* v
) {
40 Fl_Value_Input
& t
= *(Fl_Value_Input
*)v
;
42 if ((t
.step() - floor(t
.step()))>0.0 || t
.step() == 0.0) nv
= strtod(t
.input
.value(), 0);
43 else nv
= strtol(t
.input
.value(), 0, 0);
44 if (nv
!= t
.value() || t
.when() & FL_WHEN_NOT_CHANGED
) {
47 if (t
.when()) t
.do_callback();
51 void Fl_Value_Input::draw() {
52 if (damage()&~FL_DAMAGE_CHILD
) input
.clear_damage(FL_DAMAGE_ALL
);
54 input
.color(color(), selection_color());
55 Fl_Widget
*i
= &input
; i
->draw(); // calls protected input.draw()
59 void Fl_Value_Input::resize(int X
, int Y
, int W
, int H
) {
60 Fl_Valuator::resize(X
, Y
, W
, H
);
61 input
.resize(X
, Y
, W
, H
);
64 void Fl_Value_Input::value_damage() {
68 input
.mark(input
.position()); // turn off selection highlight
71 int Fl_Value_Input::handle(int event
) {
74 int mx
= Fl::event_x_root();
79 if (!step()) goto DEFAULT
;
81 drag
= Fl::event_button();
85 if (!step()) goto DEFAULT
;
87 if (delta
> 5) delta
-= 5;
88 else if (delta
< -5) delta
+= 5;
91 case 3: v
= increment(previous_value(), delta
*100); break;
92 case 2: v
= increment(previous_value(), delta
*10); break;
93 default:v
= increment(previous_value(), delta
); break;
96 handle_drag(soft()?softclamp(v
):clamp(v
));;
99 if (!step()) goto DEFAULT
;
100 if (value() != previous_value() || !Fl::event_is_click())
103 Fl_Widget_Tracker
wp(&input
);
104 input
.handle(FL_PUSH
);
106 input
.handle(FL_RELEASE
);
110 return input
.take_focus();
112 return input
.handle(event
);
115 input
.type(((step() - floor(step()))>0.0 || step() == 0.0) ? FL_FLOAT_INPUT
: FL_INT_INPUT
);
116 return input
.handle(event
);
121 Creates a new Fl_Value_Input widget using the given
122 position, size, and label string. The default boxtype is
125 Fl_Value_Input::Fl_Value_Input(int X
, int Y
, int W
, int H
, const char* l
)
126 : Fl_Valuator(X
, Y
, W
, H
, l
), input(X
, Y
, W
, H
, 0) {
128 if (input
.parent()) // defeat automatic-add
129 input
.parent()->remove(input
);
130 input
.parent((Fl_Group
*)this); // kludge!
131 input
.callback(input_cb
, this);
132 input
.when(FL_WHEN_CHANGED
);
134 color(input
.color());
135 selection_color(input
.selection_color());
136 align(FL_ALIGN_LEFT
);
138 set_flag(SHORTCUT_LABEL
);
141 Fl_Value_Input::~Fl_Value_Input() {
143 if (input
.parent() == (Fl_Group
*)this)
144 input
.parent(0); // *revert* ctor kludge!
148 // End of "$Id: Fl_Value_Input.cxx 7903 2010-11-28 21:06:39Z matt $".