From fafc3286cd4810ba6889891deea546004e58e212 Mon Sep 17 00:00:00 2001 From: Bill Spitzak Date: Thu, 20 Jan 2000 06:14:34 +0000 Subject: [PATCH] Pageup/down by correct amount in scrollbar Handles minimum size of slider in scrollbar when deciding whether to page up/dwon. Code from Matt Morrise so that shift+click extends the selection in the browser (ctrl+click remains for toggling the current item). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@990 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Browser_.cxx | 40 +++++++++++++++---- src/Fl_Scrollbar.cxx | 94 ++++++++++++++++++++------------------------ test/browser.cxx | 5 ++- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/src/Fl_Browser_.cxx b/src/Fl_Browser_.cxx index 43932579b..ddd4716ca 100644 --- a/src/Fl_Browser_.cxx +++ b/src/Fl_Browser_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Browser_.cxx,v 1.10.2.7 1999/12/19 05:32:33 bill Exp $" +// "$Id: Fl_Browser_.cxx,v 1.10.2.8 2000/01/20 06:14:31 bill Exp $" // // Base Browser widget class for the Fast Light Tool Kit (FLTK). // @@ -547,24 +547,48 @@ int Fl_Browser_::handle(int event) { switch (event) { case FL_PUSH: if (!Fl::event_inside(X, Y, W, H)) return 0; - if (type() == FL_SELECT_BROWSER) deselect(); my = py = Fl::event_y(); change = 0; if (type() == FL_NORMAL_BROWSER || !top_) ; - else if (type() == FL_MULTI_BROWSER) { + else if (type() != FL_MULTI_BROWSER) { + change = select_only(find_item(my), when() & FL_WHEN_CHANGED); + } else { void* l = find_item(my); whichway = 1; - if (Fl::event_state(FL_SHIFT|FL_CTRL)) { // toggle selection: + if (Fl::event_state(FL_CTRL)) { // toggle selection: if (l) { whichway = !item_selected(l); change = select(l, whichway, when() & FL_WHEN_CHANGED); } - } else { + } else if (Fl::event_state(FL_SHIFT)) { // extend selection: + change = 0; + if (selection_ && l != selection_) { + void *m = l; + int down = 0; + whichway = item_selected(selection_); + for (m = selection_; m; m = item_next(m)) { + if (m == l) down = 1; + } + void *n; + if (down) { + m = selection_; + n = l; + } else { + m = l; + n = selection_; + } + while (m != n) { + select(m, whichway, when() & FL_WHEN_CHANGED); + m = item_next(m); + } + select(n, whichway, when() & FL_WHEN_CHANGED); + select(l, whichway, when() & FL_WHEN_CHANGED); + change = 1; + } + } else { // select only this item change = select_only(l, when() & FL_WHEN_CHANGED); } - } else { - change = select_only(find_item(my), when() & FL_WHEN_CHANGED); } return 1; case FL_DRAG: @@ -676,5 +700,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.7 1999/12/19 05:32:33 bill Exp $". +// End of "$Id: Fl_Browser_.cxx,v 1.10.2.8 2000/01/20 06:14:31 bill Exp $". // diff --git a/src/Fl_Scrollbar.cxx b/src/Fl_Scrollbar.cxx index 464266a17..4f05ef761 100644 --- a/src/Fl_Scrollbar.cxx +++ b/src/Fl_Scrollbar.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Scrollbar.cxx,v 1.7.2.6 2000/01/17 20:40:12 bill Exp $" +// "$Id: Fl_Scrollbar.cxx,v 1.7.2.7 2000/01/20 06:14:32 bill Exp $" // // Scroll bar widget for the Fast Light Tool Kit (FLTK). // @@ -32,17 +32,22 @@ #define REPEAT .05 void Fl_Scrollbar::increment_cb() { + int ls = maximum()>=minimum() ? linesize_ : -linesize_; int i; - int W = horizontal() ? w() : h(); - int S = int(slider_size()*W+.5); - switch (pushed_) { - case 1: i = -linesize_; break; - default:i = linesize_; break; - case 5: i = -int(S * (maximum() - minimum()) / W); break; - case 6: i = int(S * (maximum() - minimum()) / W); break; + case 1: + i = -ls; + break; + default: + i = ls; + break; + case 5: + i = -int((maximum()-minimum())*slider_size()/(1.0-slider_size())) + ls; + break; + case 6: + i = int((maximum()-minimum())*slider_size()/(1.0-slider_size())) - ls; + break; } - if (maximum() < minimum() && pushed_ < 3) i = -i; handle_drag(clamp(value() + i)); } @@ -56,7 +61,6 @@ int Fl_Scrollbar::handle(int event) { // area of scrollbar: int area; int X=x(); int Y=y(); int W=w(); int H=h(); - int SX = X; int SY = Y; int SW = W; int SH = H; // adjust slider area to be inside the arrow buttons: if (horizontal()) { @@ -66,49 +70,35 @@ int Fl_Scrollbar::handle(int event) { } // which widget part is highlighted? - int mx = Fl::event_x(); - int my = Fl::event_y(); - if (!Fl::event_inside(SX, SY, SW, SH)) area = 0; - else if (horizontal()) { - if (mx < X) area = 1; - else if (mx >= X+W) area = 2; - else { - int sliderx; - int S = int(slider_size()*W+.5); - double val; - if (minimum() == maximum()) - val = 0.5; - else - val = (value()-minimum())/(maximum()-minimum()); - if (val >= 1.0) sliderx = W-S; - else if (val <= 0.0) sliderx = 0; - else sliderx = int(val*(W-S)+.5); - - if (mx < X+sliderx) area = 5; - else if (mx >= X+sliderx+S) area = 6; - else area = 8; - } + int relx; + int ww; + if (horizontal()) { + relx = Fl::event_x()-X; + ww = W; } else { - if (mx < X || mx >= X+W) area = 0; - else if (my < Y) area = 1; - else if (my >= Y+H) area = 2; - else { - int slidery; - int S = int(slider_size()*H+.5); - double val; - if (minimum() == maximum()) - val = 0.5; - else - val = (value()-minimum())/(maximum()-minimum()); - if (val >= 1.0) slidery = H-S; - else if (val <= 0.0) slidery = 0; - else slidery = int(val*(H-S)+.5); - - if (my < Y+slidery) area = 5; - else if (my >= Y+slidery+S) area = 6; - else area = 8; - } + relx = Fl::event_y()-Y; + ww = H; } + if (relx < 0) area = 1; + else if (relx >= ww) area = 2; + else { + int S = int(slider_size()*ww+.5); + int T = (horizontal() ? H : W)/2+1; + if (S < T) S = T; + double val; + if (minimum() == maximum()) + val = 0.5; + else + val = (value()-minimum())/(maximum()-minimum()); + int sliderx; + if (val >= 1.0) sliderx = ww-S; + else if (val <= 0.0) sliderx = 0; + else sliderx = int(val*(ww-S)+.5); + if (relx < sliderx) area = 5; + else if (relx >= sliderx+S) area = 6; + else area = 8; + } + switch (event) { case FL_ENTER: case FL_LEAVE: @@ -249,5 +239,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.6 2000/01/17 20:40:12 bill Exp $". +// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.7 2000/01/20 06:14:32 bill Exp $". // diff --git a/test/browser.cxx b/test/browser.cxx index 89e13e16d..4b3a03fd2 100644 --- a/test/browser.cxx +++ b/test/browser.cxx @@ -1,5 +1,5 @@ // -// "$Id: browser.cxx,v 1.5.2.1 1999/04/26 06:45:28 bill Exp $" +// "$Id: browser.cxx,v 1.5.2.2 2000/01/20 06:14:34 bill Exp $" // // Browser test program for the Fast Light Tool Kit (FLTK). // @@ -80,6 +80,7 @@ int main(int argc, char **argv) { window.box(FL_NO_BOX); // because it is filled with browser Fl_Select_Browser browser(0,0,400,400,0); browser.type(FL_MULTI_BROWSER); + //browser.type(FL_HOLD_BROWSER); //browser.color(42); browser.callback(b_cb); // browser.scrollbar_right(); @@ -95,6 +96,6 @@ int main(int argc, char **argv) { } // -// End of "$Id: browser.cxx,v 1.5.2.1 1999/04/26 06:45:28 bill Exp $". +// End of "$Id: browser.cxx,v 1.5.2.2 2000/01/20 06:14:34 bill Exp $". //