summaryrefslogtreecommitdiff
path: root/dw/fltkviewport.cc
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-10-13 19:28:17 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-10-13 20:02:51 +0200
commit9315c26bb248157d0b37ef933e3d16779aed7dd9 (patch)
treef9b7f57c163b431d23c44d86108a2dfc006f3aec /dw/fltkviewport.cc
parentf73a9c1a1967318a33cc91f588552574dc7c3f01 (diff)
Repeat page scrolling when holding the button
When the page scroll mode is enabled, pressing and holding the scrollbar will keep scrolling pages on that direction until the mouse button is released.
Diffstat (limited to 'dw/fltkviewport.cc')
-rw-r--r--dw/fltkviewport.cc34
1 files changed, 29 insertions, 5 deletions
diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc
index e9169495..fc9a0bed 100644
--- a/dw/fltkviewport.cc
+++ b/dw/fltkviewport.cc
@@ -74,6 +74,10 @@ FltkViewport::FltkViewport (int X, int Y, int W, int H, const char *label):
horScrolling = verScrolling = dragScrolling = 0;
scrollbarPageMode = false;
pageOverlap = 50;
+ pageScrolling = core::NONE_CMD;
+
+ pageScrollDelay = 0.300;
+ pageScrollInterval = 0.100;
gadgetOrientation[0] = GADGET_HORIZONTAL;
gadgetOrientation[1] = GADGET_HORIZONTAL;
@@ -296,11 +300,19 @@ int FltkViewport::handle (int event)
case FL_PUSH:
if (vscrollbar->visible() && Fl::event_inside(vscrollbar)) {
if (scrollbarPageMode ^ (bool) Fl::event_shift()) {
- if (Fl::event_button() == FL_LEFT_MOUSE) {
- scroll(core::SCREEN_DOWN_CMD);
- return 1;
- } else if (Fl::event_button() == FL_RIGHT_MOUSE) {
- scroll(core::SCREEN_UP_CMD);
+ if (Fl::event_button() == FL_LEFT_MOUSE)
+ pageScrolling = core::SCREEN_DOWN_CMD;
+ else if (Fl::event_button() == FL_RIGHT_MOUSE)
+ pageScrolling = core::SCREEN_UP_CMD;
+ else
+ pageScrolling = core::NONE_CMD;
+
+ if (pageScrolling != core::NONE_CMD) {
+ scroll(pageScrolling);
+ /* Repeat until released */
+ if (!Fl::has_timeout(repeatPageScroll, this))
+ Fl::add_timeout(pageScrollDelay, repeatPageScroll, this);
+
return 1;
}
}
@@ -363,6 +375,7 @@ int FltkViewport::handle (int event)
break;
case FL_RELEASE:
+ Fl::remove_timeout(repeatPageScroll);
Fl::remove_timeout(selectionScroll);
if (Fl::event_button() == FL_MIDDLE_MOUSE) {
setCursor (core::style::CURSOR_DEFAULT);
@@ -547,6 +560,17 @@ void FltkViewport::selectionScroll (void *data)
Fl::repeat_timeout(0.025, selectionScroll, data);
}
+void FltkViewport::repeatPageScroll ()
+{
+ scroll(pageScrolling);
+ Fl::repeat_timeout(pageScrollInterval, repeatPageScroll, this);
+}
+
+void FltkViewport::repeatPageScroll (void *data)
+{
+ ((FltkViewport *)data)->repeatPageScroll ();
+}
+
void FltkViewport::setScrollbarOnLeft (bool enable)
{
scrollbarOnLeft = enable ? 1 : 0;