diff options
Diffstat (limited to 'dw/fltkviewport.cc')
-rw-r--r-- | dw/fltkviewport.cc | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc index 19e28854..2dcc199b 100644 --- a/dw/fltkviewport.cc +++ b/dw/fltkviewport.cc @@ -275,7 +275,9 @@ int FltkViewport::handle (int event) break; case FL_DRAG: - if (dragScrolling && Fl::event_button() == FL_MIDDLE_MOUSE) { + if (Fl::event_inside(this)) + Fl::remove_timeout(selectionScroll); + if (dragScrolling) { scroll(dragX - Fl::event_x(), dragY - Fl::event_y()); dragX = Fl::event_x(); dragY = Fl::event_y(); @@ -286,6 +288,11 @@ int FltkViewport::handle (int event) } else if (horScrolling) { hscrollbar->handle(event); return 1; + } else if (!Fl::event_inside(this)) { + mouse_x = Fl::event_x(); + mouse_y = Fl::event_y(); + if (!Fl::has_timeout(selectionScroll, this)) + Fl::add_timeout(0.025, selectionScroll, this); } break; @@ -294,6 +301,7 @@ int FltkViewport::handle (int event) break; case FL_RELEASE: + Fl::remove_timeout(selectionScroll); if (Fl::event_button() == FL_MIDDLE_MOUSE) { setCursor (core::style::CURSOR_DEFAULT); } else if (verScrolling) { @@ -310,10 +318,6 @@ int FltkViewport::handle (int event) mouse_y = Fl::event_y(); positionChanged(); break; - - case FL_LEAVE: - mouse_x = mouse_y = -1; - break; } return FltkWidgetView::handle (event); @@ -332,7 +336,8 @@ void FltkViewport::setCanvasSize (int width, int ascent, int descent) */ void FltkViewport::positionChanged () { - if (mouse_x != -1 && dragScrolling == false) + if (!dragScrolling && mouse_x >= x() && mouse_x < x()+w() && mouse_y >= y() + && mouse_y < y()+h()) (void)theLayout->motionNotify (this, translateViewXToCanvasX (mouse_x), translateViewYToCanvasY (mouse_y), @@ -425,6 +430,30 @@ void FltkViewport::scroll (core::ScrollCommand cmd) } } +/* + * Scrolling in response to selection where the cursor is outside the view. + */ +void FltkViewport::selectionScroll () +{ + int dx = 0, dy = 0; + + if (mouse_x < x()) + dx = -hscrollbar->linesize (); + else if (mouse_x >= x() + w()) + dx = hscrollbar->linesize (); + if (mouse_y < y()) + dy = -vscrollbar->linesize (); + else if (mouse_y >= y() + h()) + dy = vscrollbar->linesize (); + scroll (dx, dy); +} + +void FltkViewport::selectionScroll (void *data) +{ + ((FltkViewport *)data)->selectionScroll (); + Fl::repeat_timeout(0.025, selectionScroll, data); +} + void FltkViewport::setViewportSize (int width, int height, int hScrollbarThickness, int vScrollbarThickness) |