aboutsummaryrefslogtreecommitdiff
path: root/dw/fltkviewport.cc
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2012-11-05 00:30:16 +0000
committercorvid <corvid@lavabit.com>2012-11-05 00:30:16 +0000
commit953f81e651465603f537270859732ccee038ea52 (patch)
treed0e7cc96af223264c85cd6bc6793b4cb6bc816c8 /dw/fltkviewport.cc
parent256fc10e8e58c44baf1fe9c5ea0d65649199b116 (diff)
scroll when cursor is outside of viewport during selection
Diffstat (limited to 'dw/fltkviewport.cc')
-rw-r--r--dw/fltkviewport.cc41
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)