int Fl_Roller::handle(int event) { static int ipos; int newpos = type()==HORIZONTAL ? Fl::event_x() : -Fl::event_y(); switch (event) { case FL_PUSH: handle_push(); ipos = newpos; return 1; case FL_DRAG: handle_drag(previous_value()+(newpos-ipos)*(step()?step():.01)); return 1; case FL_RELEASE: handle_release(); return 1; case FL_KEY: // Only arrows in the correct direction are used. This allows the // opposite arrows to be used to navigate between a set of parellel // rollers. switch (Fl::event_key()) { case FL_Up: case FL_Down: case FL_Home: case FL_End: if (type()==HORIZONTAL) return 0; break; case FL_Left: case FL_Right: if (type() != HORIZONTAL) return 0; } // else fall through... default: return Fl_Valuator::handle(event); } }
int Fl_Value_Slider_Input::handle(int event) { int mx = Fl::event_x(); int my = Fl::event_y(); static int indrag = 0; static int sldrag = 0; int sxx = x(), syy = y(), sww = w(), shh = h(); int border_size=Fl::box_dx(box()); if (horizontal()) { sxx += textboxsize(); sww -= textboxsize(); } else { fl_font(input.textfont(), input.textsize()); syy += fl_height()+(border_size+1)*2; shh -= fl_height()+(border_size+1)*2; } if( !indrag && ( !sldrag || !((mx>=sxx && mx<=(sxx+sww)) && (my>=syy && my<=(syy+shh))))) { indrag=0; switch(event) { case FL_PUSH: case FL_DRAG: sldrag=1; break; case FL_FOCUS: input.take_focus(); break; case FL_UNFOCUS: redraw(); break; case FL_KEYBOARD: switch (Fl::event_key()) { case FL_Up: if (!horizontal()) indrag=1 ; break; case FL_Down: if (!horizontal()) indrag=1 ; break; case FL_Left: if (horizontal()) indrag=1 ; break; case FL_Right: if (horizontal()) indrag=1 ; break; } break; default: sldrag=0; } if(!indrag) { input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); return input.handle(event); } } switch (event) { case FL_PUSH: ix = mx; drag = Fl::event_button(); indrag=1; return Fl_Slider::handle(event,sxx,syy,sww,shh); case FL_DRAG: indrag=1; return Fl_Slider::handle(event,sxx,syy,sww,shh); case FL_RELEASE: // if (!step()) goto DEFAULT; if (value() != previous_value() || !Fl::event_is_click()) { handle_release(); } else { input.handle(FL_PUSH); input.handle(FL_RELEASE); } indrag=0; return 1; case FL_FOCUS: indrag=0; input.take_focus(); return Fl_Slider::handle(event,sxx,syy,sww,shh); default: indrag=0; input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); input.handle(event); return Fl_Slider::handle(event,sxx,syy,sww,shh); } }
int Fl_Slider::handle(int event, int x, int y, int w, int h) { switch (event) { case FL_FOCUS: case FL_UNFOCUS: redraw(FL_DAMAGE_ALL); return 1; case FL_PUSH: redraw(FL_DAMAGE_HIGHLIGHT); handle_push(); case FL_DRAG: { // figure out the space the slider moves in and where the event is: int mx; if (horizontal()) { w = w-box()->dw(); mx = Fl::event_x()-x-box()->dx(); } else { w = h-box()->dh(); mx = Fl::event_y()-y-box()->dy(); } if (w <= slider_size_) return 1; static int offcenter; int X = slider_position(value(), w); if (event == FL_PUSH) { offcenter = mx-X; // we are done if they clicked on the slider: if (offcenter >= (slider_size() ? 0 : -8) && offcenter <= slider_size_) return 1; if (Fl::event_button() > 1) { // Move the near end of the slider to the cursor. This is good // for scrollbars. offcenter = (offcenter < 0) ? 0 : slider_size_; } else { // Center the slider under the cursor, what most toolkits do offcenter = slider_size_/2; } } double v; RETRY: X = mx-offcenter; if (X < 0) { X = 0; offcenter = mx; if (offcenter < 0) offcenter = 0; } else if (X > (w-slider_size_)) { X = w-slider_size_; offcenter = mx-X; if (offcenter > slider_size_) offcenter = slider_size_; } v = position_value(X, w); handle_drag(v); // make sure a click outside the sliderbar moves it: if (event == FL_PUSH && value() == previous_value()) { offcenter = slider_size_/2; event = FL_DRAG; goto RETRY; } return 1; } case FL_RELEASE: handle_release(); redraw(FL_DAMAGE_HIGHLIGHT); return 1; case FL_KEY: // Only arrows in the correct direction are used. This allows the // opposite arrows to be used to navigate between a set of parellel // sliders. switch (Fl::event_key()) { case FL_Up: case FL_Down: if (horizontal()) return 0; break; case FL_Left: case FL_Right: if (!horizontal()) return 0; } default: return Fl_Valuator::handle(event); } }