Fix other widgets to use Fl::focus() instead of take_focus().

Add keyboard nav to Fl_Color_Chooser.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1853 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2001-12-16 16:41:48 +00:00
parent fc008c96c3
commit 9ed48bd74a
14 changed files with 135 additions and 39 deletions

View File

@ -1,5 +1,9 @@
CHANGES IN FLTK 1.1.0b8
- The Fl_Color_Chooser widget now supports keyboard
navigation.
- Fixed button and valuator widgets to call Fl::focus()
instead of take_focus().
- Tweeked the radio button drawing code for better
circles with different boxtypes.
- The Fl_File_Chooser widget did not provide a shown()

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Color_Chooser.H,v 1.5.2.4 2001/01/22 15:13:37 easysw Exp $"
// "$Id: Fl_Color_Chooser.H,v 1.5.2.4.2.1 2001/12/16 16:41:48 easysw Exp $"
//
// Color chooser header file for the Fast Light Tool Kit (FLTK).
//
@ -40,6 +40,7 @@ class Flcc_HueBox : public Fl_Widget {
int px, py;
protected:
FL_EXPORT void draw();
FL_EXPORT int handle_key(int);
public:
FL_EXPORT int handle(int);
Flcc_HueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
@ -50,6 +51,7 @@ class Flcc_ValueBox : public Fl_Widget {
int py;
protected:
FL_EXPORT void draw();
FL_EXPORT int handle_key(int);
public:
FL_EXPORT int handle(int);
Flcc_ValueBox(int X, int Y, int W, int H) : Fl_Widget(X,Y,W,H) {
@ -96,5 +98,5 @@ FL_EXPORT int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b);
#endif
//
// End of "$Id: Fl_Color_Chooser.H,v 1.5.2.4 2001/01/22 15:13:37 easysw Exp $".
// End of "$Id: Fl_Color_Chooser.H,v 1.5.2.4.2.1 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.3 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.4 2001/12/16 16:41:48 easysw Exp $"
//
// Adjuster widget for the Fast Light Tool Kit (FLTK).
//
@ -70,7 +70,7 @@ int Fl_Adjuster::handle(int event) {
int mx = Fl::event_x();
switch (event) {
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
ix = mx;
if (w()>=h())
drag = 3*(mx-x())/w() + 1;
@ -160,5 +160,5 @@ Fl_Adjuster::Fl_Adjuster(int x, int y, int w, int h, const char* l)
}
//
// End of "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.3 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.4 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.8 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.9 2001/12/16 16:41:48 easysw Exp $"
//
// Base Browser widget class for the Fast Light Tool Kit (FLTK).
//
@ -552,7 +552,7 @@ int Fl_Browser_::handle(int event) {
switch (event) {
case FL_PUSH:
if (!Fl::event_inside(X, Y, W, H)) return 0;
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
my = py = Fl::event_y();
change = 0;
if (type() == FL_NORMAL_BROWSER || !top_)
@ -713,5 +713,5 @@ void Fl_Browser_::item_select(void*, int) {}
int Fl_Browser_::item_selected(void* l) const {return l==selection_;}
//
// End of "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.8 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.9 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Button.cxx,v 1.4.2.6.2.8 2001/12/16 12:37:02 easysw Exp $"
// "$Id: Fl_Button.cxx,v 1.4.2.6.2.9 2001/12/16 16:41:48 easysw Exp $"
//
// Button widget for the Fast Light Tool Kit (FLTK).
//
@ -66,7 +66,7 @@ int Fl_Button::handle(int event) {
// if ((value_?selection_color():color())==FL_GRAY) redraw();
return 1;
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
case FL_DRAG:
if (Fl::event_inside(this)) {
if (type() == FL_RADIO_BUTTON) newval = 1;
@ -149,5 +149,5 @@ Fl_Button::Fl_Button(int x,int y,int w,int h, const char *l)
}
//
// End of "$Id: Fl_Button.cxx,v 1.4.2.6.2.8 2001/12/16 12:37:02 easysw Exp $".
// End of "$Id: Fl_Button.cxx,v 1.4.2.6.2.9 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Choice.cxx,v 1.10.2.5.2.4 2001/11/17 18:18:53 easysw Exp $"
// "$Id: Fl_Choice.cxx,v 1.10.2.5.2.5 2001/12/16 16:41:48 easysw Exp $"
//
// Choice widget for the Fast Light Tool Kit (FLTK).
//
@ -90,7 +90,7 @@ int Fl_Choice::handle(int e) {
case FL_KEYBOARD:
if (Fl::event_key() != ' ') return 0;
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
Fl::event_is_click(0);
J1:
v = menu()->pulldown(x(), y(), w(), h(), mvalue(), this);
@ -117,5 +117,5 @@ int Fl_Choice::handle(int e) {
}
//
// End of "$Id: Fl_Choice.cxx,v 1.10.2.5.2.4 2001/11/17 18:18:53 easysw Exp $".
// End of "$Id: Fl_Choice.cxx,v 1.10.2.5.2.5 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Color_Chooser.cxx,v 1.7.2.4.2.1 2001/12/12 21:33:34 easysw Exp $"
// "$Id: Fl_Color_Chooser.cxx,v 1.7.2.4.2.2 2001/12/16 16:41:48 easysw Exp $"
//
// Color chooser for the Fast Light Tool Kit (FLTK).
//
@ -180,6 +180,10 @@ int Flcc_HueBox::handle(int e) {
Fl_Color_Chooser* c = (Fl_Color_Chooser*)parent();
switch (e) {
case FL_PUSH:
if (Fl::visible_focus()) {
Fl::focus(this);
redraw();
}
ih = c->hue();
is = c->saturation();
case FL_DRAG: {
@ -192,6 +196,15 @@ int Flcc_HueBox::handle(int e) {
if (Fl::event_state(FL_CTRL)) H = ih;
if (c->hsv(H, S, c->value())) c->do_callback();
} return 1;
case FL_FOCUS :
case FL_UNFOCUS :
if (Fl::visible_focus()) {
redraw();
return 1;
}
else return 1;
case FL_KEYBOARD :
return handle_key(Fl::event_key());
default:
return 0;
}
@ -217,6 +230,45 @@ static void generate_image(void* vv, int X, int Y, int W, uchar* buf) {
}
}
int Flcc_HueBox::handle_key(int key) {
int w1 = w()-Fl::box_dw(box())-6;
int h1 = h()-Fl::box_dh(box())-6;
Fl_Color_Chooser* c = (Fl_Color_Chooser*)parent();
#ifdef CIRCLE
int X = int(.5*(cos(c->hue()*(M_PI/3.0))*c->saturation()+1) * w1);
int Y = int(.5*(1-sin(c->hue()*(M_PI/3.0))*c->saturation()) * h1);
#else
int X = int(c->hue()/6.0*w1);
int Y = int((1-c->saturation())*h1);
#endif
switch (key) {
case FL_Up :
Y -= 3;
break;
case FL_Down :
Y += 3;
break;
case FL_Left :
X -= 3;
break;
case FL_Right :
X += 3;
break;
default :
return 0;
}
double Xf, Yf, H, S;
Xf = (double)X/(double)w1;
Yf = (double)Y/(double)h1;
tohs(Xf, Yf, H, S);
if (c->hsv(H, S, c->value())) c->do_callback();
return 1;
}
void Flcc_HueBox::draw() {
if (damage()&FL_DAMAGE_ALL) draw_box();
int x1 = x()+Fl::box_dx(box());
@ -237,7 +289,7 @@ void Flcc_HueBox::draw() {
if (X < 0) X = 0; else if (X > w1-6) X = w1-6;
if (Y < 0) Y = 0; else if (Y > h1-6) Y = h1-6;
// fl_color(c->value()>.75 ? FL_BLACK : FL_WHITE);
draw_box(FL_UP_BOX,x1+X,y1+Y,6,6,FL_GRAY);
draw_box(FL_UP_BOX,x1+X,y1+Y,6,6,Fl::focus() == this ? FL_BLACK : FL_GRAY);
px = X; py = Y;
}
@ -248,6 +300,10 @@ int Flcc_ValueBox::handle(int e) {
Fl_Color_Chooser* c = (Fl_Color_Chooser*)parent();
switch (e) {
case FL_PUSH:
if (Fl::visible_focus()) {
Fl::focus(this);
redraw();
}
iv = c->value();
case FL_DRAG: {
double Yf;
@ -255,6 +311,15 @@ int Flcc_ValueBox::handle(int e) {
if (fabs(Yf-iv)<(3*1.0/h())) Yf = iv;
if (c->hsv(c->hue(),c->saturation(),Yf)) c->do_callback();
} return 1;
case FL_FOCUS :
case FL_UNFOCUS :
if (Fl::visible_focus()) {
redraw();
return 1;
}
else return 1;
case FL_KEYBOARD :
return handle_key(Fl::event_key());
default:
return 0;
}
@ -285,10 +350,35 @@ void Flcc_ValueBox::draw() {
if (damage() == FL_DAMAGE_EXPOSE) fl_pop_clip();
int Y = int((1-c->value()) * (h1-6));
if (Y < 0) Y = 0; else if (Y > h1-6) Y = h1-6;
draw_box(FL_UP_BOX,x1,y1+Y,w1,6,FL_GRAY);
draw_box(FL_UP_BOX,x1,y1+Y,w1,6,Fl::focus() == this ? FL_BLACK : FL_GRAY);
py = Y;
}
int Flcc_ValueBox::handle_key(int key) {
int h1 = h()-Fl::box_dh(box())-6;
Fl_Color_Chooser* c = (Fl_Color_Chooser*)parent();
int Y = int((1-c->value()) * h1);
if (Y < 0) Y = 0; else if (Y > h1) Y = h1;
switch (key) {
case FL_Up :
Y -= 3;
break;
case FL_Down :
Y += 3;
break;
default :
return 0;
}
double Yf;
Yf = 1-((double)Y/(double)h1);
if (c->hsv(c->hue(),c->saturation(),Yf)) c->do_callback();
return 1;
}
////////////////////////////////////////////////////////////////
void Fl_Color_Chooser::rgb_cb(Fl_Widget* o, void*) {
@ -431,5 +521,5 @@ int fl_color_chooser(const char* name, uchar& r, uchar& g, uchar& b) {
}
//
// End of "$Id: Fl_Color_Chooser.cxx,v 1.7.2.4.2.1 2001/12/12 21:33:34 easysw Exp $".
// End of "$Id: Fl_Color_Chooser.cxx,v 1.7.2.4.2.2 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Counter.cxx,v 1.8.2.3.2.4 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Counter.cxx,v 1.8.2.3.2.5 2001/12/16 16:41:48 easysw Exp $"
//
// Counter widget for the Fast Light Tool Kit (FLTK).
//
@ -131,7 +131,7 @@ int Fl_Counter::handle(int event) {
handle_release();
return 1;
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
handle_push();
case FL_DRAG:
i = calc_mouseobj();
@ -188,5 +188,5 @@ Fl_Counter::Fl_Counter(int x, int y, int w, int h, const char* l)
}
//
// End of "$Id: Fl_Counter.cxx,v 1.8.2.3.2.4 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Counter.cxx,v 1.8.2.3.2.5 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.2 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.3 2001/12/16 16:41:48 easysw Exp $"
//
// Menu button widget for the Fast Light Tool Kit (FLTK).
//
@ -65,7 +65,7 @@ int Fl_Menu_Button::handle(int e) {
} else if (type()) {
if (!(type() & (1 << (Fl::event_button()-1)))) return 0;
}
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
popup();
return 1;
case FL_KEYBOARD:
@ -93,5 +93,5 @@ Fl_Menu_Button::Fl_Menu_Button(int X,int Y,int W,int H,const char *l)
}
//
// End of "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.2 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Menu_Button.cxx,v 1.4.2.3.2.3 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.2 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.3 2001/12/16 16:41:48 easysw Exp $"
//
// Repeat button widget for the Fast Light Tool Kit (FLTK).
//
@ -44,7 +44,7 @@ int Fl_Repeat_Button::handle(int event) {
newval = 0; goto J1;
case FL_PUSH:
case FL_DRAG:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
newval = Fl::event_inside(this);
J1:
if (value(newval)) {
@ -62,5 +62,5 @@ int Fl_Repeat_Button::handle(int event) {
}
//
// End of "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.2 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.3 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Roller.cxx,v 1.6.2.4.2.2 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Roller.cxx,v 1.6.2.4.2.3 2001/12/16 16:41:48 easysw Exp $"
//
// Roller widget for the Fast Light Tool Kit (FLTK).
//
@ -35,7 +35,7 @@ int Fl_Roller::handle(int event) {
int newpos = horizontal() ? Fl::event_x() : Fl::event_y();
switch (event) {
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
handle_push();
ipos = newpos;
return 1;
@ -168,5 +168,5 @@ Fl_Roller::Fl_Roller(int X,int Y,int W,int H,const char* L)
}
//
// End of "$Id: Fl_Roller.cxx,v 1.6.2.4.2.2 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Roller.cxx,v 1.6.2.4.2.3 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.5 2001/11/27 17:44:06 easysw Exp $"
// "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.6 2001/12/16 16:41:48 easysw Exp $"
//
// Scroll bar widget for the Fast Light Tool Kit (FLTK).
//
@ -109,7 +109,7 @@ int Fl_Scrollbar::handle(int event) {
handle_release();
return 1;
case FL_PUSH:
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
if (pushed_) return 1;
if (area != 8) pushed_ = area;
if (pushed_) {
@ -246,5 +246,5 @@ Fl_Scrollbar::Fl_Scrollbar(int X, int Y, int W, int H, const char* L)
}
//
// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.5 2001/11/27 17:44:06 easysw Exp $".
// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.6 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Slider.cxx,v 1.8.2.10.2.3 2001/11/03 19:24:22 easysw Exp $"
// "$Id: Fl_Slider.cxx,v 1.8.2.10.2.4 2001/12/16 16:41:48 easysw Exp $"
//
// Slider widget for the Fast Light Tool Kit (FLTK).
//
@ -181,7 +181,7 @@ int Fl_Slider::handle(int event, int x, int y, int w, int h) {
switch (event) {
case FL_PUSH:
if (!Fl::event_inside(x, y, w, h)) return 0;
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
handle_push();
case FL_DRAG: {
@ -291,5 +291,5 @@ int Fl_Slider::handle(int event) {
}
//
// End of "$Id: Fl_Slider.cxx,v 1.8.2.10.2.3 2001/11/03 19:24:22 easysw Exp $".
// End of "$Id: Fl_Slider.cxx,v 1.8.2.10.2.4 2001/12/16 16:41:48 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Tabs.cxx,v 1.6.2.10.2.4 2001/12/01 13:59:50 easysw Exp $"
// "$Id: Fl_Tabs.cxx,v 1.6.2.10.2.5 2001/12/16 16:41:48 easysw Exp $"
//
// Tab widget for the Fast Light Tool Kit (FLTK).
//
@ -130,7 +130,7 @@ int Fl_Tabs::handle(int event) {
} else {
if (Fl::event_y() < y()+h()+H) goto DEFAULT;
}}
if (Fl::visible_focus()) take_focus();
if (Fl::visible_focus()) Fl::focus(this);
case FL_DRAG:
case FL_RELEASE:
o = which(Fl::event_x(), Fl::event_y());
@ -291,5 +291,5 @@ Fl_Tabs::Fl_Tabs(int X,int Y,int W, int H, const char *l) :
}
//
// End of "$Id: Fl_Tabs.cxx,v 1.6.2.10.2.4 2001/12/01 13:59:50 easysw Exp $".
// End of "$Id: Fl_Tabs.cxx,v 1.6.2.10.2.5 2001/12/16 16:41:48 easysw Exp $".
//