diff --git a/CHANGES b/CHANGES index dd217eeac..1c782d9a0 100644 --- a/CHANGES +++ b/CHANGES @@ -9,7 +9,7 @@ TODO - Added new alignment bit FL_ALIGN_TEXT_OVER_IMAGE. - Added tooltip support using Jacques Tremblay's tooltip patch. -PARTIAL - Added keyboard navigation to all widgets. + - Added keyboard navigation to all widgets. - Added support for mouse wheels using the new FL_MOUSEWHEEL event type. Get the mouse wheel diff --git a/src/Fl_Adjuster.cxx b/src/Fl_Adjuster.cxx index dc8a39b50..b591ed0c3 100644 --- a/src/Fl_Adjuster.cxx +++ b/src/Fl_Adjuster.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Adjuster.cxx,v 1.5.2.3 2001/01/22 15:13:39 easysw Exp $" +// "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.1 2001/08/05 14:00:15 easysw Exp $" // // Adjuster widget for the Fast Light Tool Kit (FLTK). // @@ -61,6 +61,7 @@ void Fl_Adjuster::draw() { y()+dy+(H-mediumarrow_height)/2, W, H); slowarrow.draw(x()+2*dx+(W-slowarrow_width)/2, y()+(H-slowarrow_width)/2, W, H); + if (Fl::focus() == this) draw_focus(); } int Fl_Adjuster::handle(int event) { @@ -68,54 +69,81 @@ int Fl_Adjuster::handle(int event) { int delta; int mx = Fl::event_x(); switch (event) { - case FL_PUSH: - ix = mx; - if (w()>=h()) - drag = 3*(mx-x())/w() + 1; - else - drag = 3-3*(Fl::event_y()-y()-1)/h(); - handle_push(); - redraw(); - return 1; - case FL_DRAG: - if (w() >= h()) { - delta = x()+(drag-1)*w()/3; // left edge of button - if (mx < delta) - delta = mx-delta; - else if (mx > (delta+w()/3)) // right edge of button - delta = mx-delta-w()/3; + case FL_PUSH: + take_focus(); + ix = mx; + if (w()>=h()) + drag = 3*(mx-x())/w() + 1; else - delta = 0; - } else { - if (mx < x()) - delta = mx-x(); - else if (mx > (x()+w())) - delta = mx-x()-w(); - else - delta = 0; - } - switch (drag) { - case 3: v = increment(previous_value(), delta); break; - case 2: v = increment(previous_value(), delta*10); break; - default:v = increment(previous_value(), delta*100); break; - } - handle_drag(soft() ? softclamp(v) : clamp(v)); - return 1; - case FL_RELEASE: - if (Fl::event_is_click()) { // detect click but no drag - if (Fl::event_state()&0xF0000) delta = -10; - else delta = 10; + drag = 3-3*(Fl::event_y()-y()-1)/h(); + handle_push(); + redraw(); + return 1; + case FL_DRAG: + if (w() >= h()) { + delta = x()+(drag-1)*w()/3; // left edge of button + if (mx < delta) + delta = mx-delta; + else if (mx > (delta+w()/3)) // right edge of button + delta = mx-delta-w()/3; + else + delta = 0; + } else { + if (mx < x()) + delta = mx-x(); + else if (mx > (x()+w())) + delta = mx-x()-w(); + else + delta = 0; + } switch (drag) { case 3: v = increment(previous_value(), delta); break; case 2: v = increment(previous_value(), delta*10); break; default:v = increment(previous_value(), delta*100); break; } handle_drag(soft() ? softclamp(v) : clamp(v)); - } - drag = 0; - redraw(); - handle_release(); - return 1; + return 1; + case FL_RELEASE: + if (Fl::event_is_click()) { // detect click but no drag + if (Fl::event_state()&0xF0000) delta = -10; + else delta = 10; + switch (drag) { + case 3: v = increment(previous_value(), delta); break; + case 2: v = increment(previous_value(), delta*10); break; + default:v = increment(previous_value(), delta*100); break; + } + handle_drag(soft() ? softclamp(v) : clamp(v)); + } + drag = 0; + redraw(); + handle_release(); + return 1; + case FL_KEYBOARD : + switch (Fl::event_key()) { + case FL_Up: + if (w() > h()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Down: + if (w() > h()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + case FL_Left: + if (w() < h()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Right: + if (w() < h()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + default: + return 0; + } + break; + case FL_FOCUS: + case FL_UNFOCUS: + redraw(); + return 1; } return 0; } @@ -130,5 +158,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 2001/01/22 15:13:39 easysw Exp $". +// End of "$Id: Fl_Adjuster.cxx,v 1.5.2.3.2.1 2001/08/05 14:00:15 easysw Exp $". // diff --git a/src/Fl_Counter.cxx b/src/Fl_Counter.cxx index 06f26ff30..93f8c0e3f 100644 --- a/src/Fl_Counter.cxx +++ b/src/Fl_Counter.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Counter.cxx,v 1.8.2.3 2001/01/22 15:13:39 easysw Exp $" +// "$Id: Fl_Counter.cxx,v 1.8.2.3.2.1 2001/08/05 14:00:15 easysw Exp $" // // Counter widget for the Fast Light Tool Kit (FLTK). // @@ -59,6 +59,7 @@ void Fl_Counter::draw() { fl_color(active_r() ? textcolor() : inactive(textcolor())); char str[128]; format(str); fl_draw(str, xx[0], y(), ww[0], h(), FL_ALIGN_CENTER); + if (Fl::focus() == this) draw_focus(boxtype[0], xx[0], y(), ww[0], h()); if (!(damage()&FL_DAMAGE_ALL)) return; // only need to redraw text if (active_r()) @@ -130,6 +131,7 @@ int Fl_Counter::handle(int event) { handle_release(); return 1; case FL_PUSH: + take_focus(); handle_push(); case FL_DRAG: i = calc_mouseobj(); @@ -141,6 +143,22 @@ int Fl_Counter::handle(int event) { redraw(); } return 1; + case FL_KEYBOARD : + switch (Fl::event_key()) { + case FL_Left: + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Right: + handle_drag(clamp(increment(value(),1))); + return 1; + default: + return 0; + } + break; + case FL_FOCUS : + case FL_UNFOCUS : + damage(FL_DAMAGE_ALL); + return 1; default: return 0; } @@ -165,5 +183,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 2001/01/22 15:13:39 easysw Exp $". +// End of "$Id: Fl_Counter.cxx,v 1.8.2.3.2.1 2001/08/05 14:00:15 easysw Exp $". // diff --git a/src/Fl_Roller.cxx b/src/Fl_Roller.cxx index 4f598eb58..2ec920337 100644 --- a/src/Fl_Roller.cxx +++ b/src/Fl_Roller.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Roller.cxx,v 1.6.2.4 2001/01/22 15:13:40 easysw Exp $" +// "$Id: Fl_Roller.cxx,v 1.6.2.4.2.1 2001/08/05 14:00:15 easysw Exp $" // // Roller widget for the Fast Light Tool Kit (FLTK). // @@ -35,6 +35,7 @@ int Fl_Roller::handle(int event) { int newpos = horizontal() ? Fl::event_x() : Fl::event_y(); switch (event) { case FL_PUSH: + take_focus(); handle_push(); ipos = newpos; return 1; @@ -44,6 +45,32 @@ int Fl_Roller::handle(int event) { case FL_RELEASE: handle_release(); return 1; + case FL_KEYBOARD : + switch (Fl::event_key()) { + case FL_Up: + if (horizontal()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Down: + if (horizontal()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + case FL_Left: + if (!horizontal()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Right: + if (!horizontal()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + default: + return 0; + } + break; + case FL_FOCUS : + case FL_UNFOCUS : + damage(FL_DAMAGE_ALL); + return 1; default: return 0; } @@ -128,14 +155,16 @@ void Fl_Roller::draw() { fl_yxline(X+W,Y+h1,Y); } } + + if (Fl::focus() == this) draw_focus(FL_THIN_UP_FRAME, x(), y(), w(), h()); } Fl_Roller::Fl_Roller(int X,int Y,int W,int H,const char* L) : Fl_Valuator(X,Y,W,H,L) { - box(FL_UP_FRAME); + box(FL_UP_BOX); step(1,1000); } // -// End of "$Id: Fl_Roller.cxx,v 1.6.2.4 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: Fl_Roller.cxx,v 1.6.2.4.2.1 2001/08/05 14:00:15 easysw Exp $". // diff --git a/src/Fl_Scrollbar.cxx b/src/Fl_Scrollbar.cxx index feeb34fea..c252dc2b7 100644 --- a/src/Fl_Scrollbar.cxx +++ b/src/Fl_Scrollbar.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.1 2001/08/04 12:21:33 easysw Exp $" +// "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.2 2001/08/05 14:00:15 easysw Exp $" // // Scroll bar widget for the Fast Light Tool Kit (FLTK). // @@ -109,6 +109,7 @@ int Fl_Scrollbar::handle(int event) { handle_release(); return 1; case FL_PUSH: + take_focus(); if (pushed_) return 1; if (area != 8) pushed_ = area; if (pushed_) { @@ -126,7 +127,12 @@ int Fl_Scrollbar::handle(int event) { if (horizontal()) return 0; handle_drag(clamp(value() + 3 * linesize_ * Fl::e_dy)); return 1; - case FL_SHORTCUT: { + case FL_FOCUS : + case FL_UNFOCUS : + damage(FL_DAMAGE_ALL); + return 1; + case FL_SHORTCUT: + case FL_KEYBOARD: { int v = value(); int ls = maximum()>=minimum() ? linesize_ : -linesize_; if (horizontal()) { @@ -238,5 +244,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.1 2001/08/04 12:21:33 easysw Exp $". +// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.14.2.2 2001/08/05 14:00:15 easysw Exp $". // diff --git a/src/Fl_Slider.cxx b/src/Fl_Slider.cxx index 9bae98a65..9a2c44952 100644 --- a/src/Fl_Slider.cxx +++ b/src/Fl_Slider.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Slider.cxx,v 1.8.2.10 2001/01/22 15:13:40 easysw Exp $" +// "$Id: Fl_Slider.cxx,v 1.8.2.10.2.1 2001/08/05 14:00:15 easysw Exp $" // // Slider widget for the Fast Light Tool Kit (FLTK). // @@ -163,6 +163,10 @@ void Fl_Slider::draw(int x, int y, int w, int h) { } draw_label(xsl, ysl, wsl, hsl); + if (Fl::focus() == this) { + if (type() == FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) draw_focus(); + else draw_focus(box1, xsl, ysl, wsl, hsl); + } } void Fl_Slider::draw() { @@ -177,6 +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; + take_focus(); handle_push(); case FL_DRAG: { @@ -241,6 +246,32 @@ int Fl_Slider::handle(int event, int x, int y, int w, int h) { case FL_RELEASE: handle_release(); return 1; + case FL_KEYBOARD : + switch (Fl::event_key()) { + case FL_Up: + if (horizontal()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Down: + if (horizontal()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + case FL_Left: + if (!horizontal()) return 0; + handle_drag(clamp(increment(value(),-1))); + return 1; + case FL_Right: + if (!horizontal()) return 0; + handle_drag(clamp(increment(value(),1))); + return 1; + default: + return 0; + } + break; + case FL_FOCUS : + case FL_UNFOCUS : + damage(FL_DAMAGE_ALL); + return 1; default: return 0; } @@ -255,5 +286,5 @@ int Fl_Slider::handle(int event) { } // -// End of "$Id: Fl_Slider.cxx,v 1.8.2.10 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: Fl_Slider.cxx,v 1.8.2.10.2.1 2001/08/05 14:00:15 easysw Exp $". // diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index cedf0d0e4..5737eaf25 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.3 2001/08/04 20:17:10 easysw Exp $" +// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.4 2001/08/05 14:00:15 easysw Exp $" // // Base widget class for the Fast Light Tool Kit (FLTK). // @@ -136,8 +136,19 @@ Fl_Widget::~Fl_Widget() { // draw a focus box for the widget... void Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const { + switch (B) { + case FL_DOWN_BOX: + case FL_DOWN_FRAME: + case FL_THIN_DOWN_BOX: + case FL_THIN_DOWN_FRAME: + X ++; + Y ++; + default: + break; + } + fl_color(FL_BLACK); - fl_line_style(FL_DASH); + fl_line_style(FL_DOT); fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B), W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1); fl_line_style(FL_SOLID); @@ -218,5 +229,5 @@ int Fl_Widget::contains(const Fl_Widget *o) const { } // -// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.3 2001/08/04 20:17:10 easysw Exp $". +// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.4 2001/08/05 14:00:15 easysw Exp $". //