changeset 2098:092bbfdbd6d5

Made dillorc's middle_click_drags_page=NO operative again * Added setDragScroll(bool) to the viewport to enable/disable it * Made middle-click paste URL upon FL_RELEASE
author Jorge Arellano Cid <jcid@dillo.org>
date Sat, 18 Jun 2011 10:07:29 -0400
parents 133dedffca47
children ffc58a024f5e
files dw/fltkviewport.cc dw/fltkviewport.hh src/ui.cc src/uicmd.cc
diffstat 4 files changed, 32 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkviewport.cc	Thu Jun 16 03:30:57 2011 +0000
+++ b/dw/fltkviewport.cc	Sat Jun 18 10:07:29 2011 -0400
@@ -23,6 +23,7 @@
 
 #include <FL/Fl.H>
 #include <FL/fl_draw.H>
+#include <FL/names.h>
 
 #include <stdio.h>
 #include "../lout/msg.h"
@@ -64,6 +65,7 @@
    vscrollbar->hide();
    add (vscrollbar);
 
+   hasDragScroll = 1;
    scrollX = scrollY = scrollDX = scrollDY = 0;
    horScrolling = verScrolling = dragScrolling = 0;
 
@@ -223,7 +225,7 @@
 
 int FltkViewport::handle (int event)
 {
-   _MSG("FltkViewport::handle %d\n", event);
+   _MSG("FltkViewport::handle %s\n", fl_eventnames[event]);
 
    switch(event) {
    case FL_KEYBOARD:
@@ -249,13 +251,18 @@
       } else if (hscrollbar->visible() && Fl::event_inside(hscrollbar)) {
          if (hscrollbar->handle(event))
             horScrolling = 1;
-      } else if (FltkWidgetView::handle (event) == 0 &&
-          Fl::event_button() == FL_MIDDLE_MOUSE) {
-         /* pass event so that middle click can open link in new window */
-         dragScrolling = 1;
-         dragX = Fl::event_x();
-         dragY = Fl::event_y();
-         setCursor (core::style::CURSOR_MOVE);
+      } else if (FltkWidgetView::handle(event) == 0 &&
+                 Fl::event_button() == FL_MIDDLE_MOUSE) {
+         if (!hasDragScroll) {
+            /* let the parent widget handle it... */
+            return 0;
+         } else {
+            /* receive FL_DRAG and FL_RELEASE */
+            dragScrolling = 1;
+            dragX = Fl::event_x();
+            dragY = Fl::event_y();
+            setCursor (core::style::CURSOR_MOVE);
+         }
       }
       return 1;
       break;
--- a/dw/fltkviewport.hh	Thu Jun 16 03:30:57 2011 +0000
+++ b/dw/fltkviewport.hh	Sat Jun 18 10:07:29 2011 -0400
@@ -21,7 +21,7 @@
 
    int scrollX, scrollY;
    int scrollDX, scrollDY;
-   int dragScrolling, dragX, dragY;
+   int hasDragScroll, dragScrolling, dragX, dragY;
    int horScrolling, verScrolling;
 
    Fl_Scrollbar *vscrollbar, *hscrollbar;
@@ -70,6 +70,7 @@
 
    void setGadgetOrientation (bool hscrollbarVisible, bool vscrollbarVisible,
                               GadgetOrientation gadgetOrientation);
+   void setDragScroll (bool enable) { hasDragScroll = enable ? 1 : 0; }
    void addGadget (Fl_Widget *gadget);
 };
 
--- a/src/ui.cc	Thu Jun 16 03:30:57 2011 +0000
+++ b/src/ui.cc	Sat Jun 18 10:07:29 2011 -0400
@@ -23,6 +23,7 @@
 #include <FL/Fl.H>
 #include <FL/Fl_Pixmap.H>
 #include <FL/Fl_Box.H>
+#include <FL/names.h>
 
 // Include image data
 #include "pixmaps.h"
@@ -780,7 +781,7 @@
  */
 int UI::handle(int event)
 {
-   _MSG("UI::handle event=%d (%d,%d)\n", event, Fl::event_x(), Fl::event_y());
+   _MSG("UI::handle event=%s\n", fl_eventnames[event]);
 
    int ret = 0;
    if (event == FL_KEYBOARD) {
@@ -840,28 +841,23 @@
          a_UIcmd_file_popup(a_UIcmd_get_bw_by_widget(this), FileButton);
          ret = 1;
       }
-   }
-#if 0
-   } else if (event == FL_PUSH) {
-      if (prefs.middle_click_drags_page == 0 &&
-          Fl::event_button() == FL_MIDDLE_MOUSE &&
-          !a_UIcmd_pointer_on_link(a_UIcmd_get_bw_by_widget(this))) {
-         if (Main->contains(Fl::belowmouse())) {
-            /* Offer the event to Main's children (form widgets) */
-            /* TODO: Try just offering it to Fl::belowmouse() */
-            ret = ((Fl_Group *)Main)->Fl_Group::handle(event);
-         }
-         if (!ret) {
-            /* middle click was not on a link or a form widget */
-            paste_url();
-            ret = 1;
-         }
+   } else if (event == FL_RELEASE) {
+      if (Fl::event_button() == FL_MIDDLE_MOUSE &&
+          prefs.middle_click_drags_page == 0) {
+         /* nobody claimed the event; try paste */
+         paste_url();
+         ret = 1;
       }
    }
-#endif
+
    if (!ret) {
       ret = Fl_Group::handle(event);
    }
+   if (!ret && event == FL_PUSH && !prefs.middle_click_drags_page) {
+      /* nobody claimed FL_PUSH: ask for FL_RELEASE,
+       * which is necessary for middle-click paste URL) */
+      ret = 1;
+   }
 
    return ret;
 }
--- a/src/uicmd.cc	Thu Jun 16 03:30:57 2011 +0000
+++ b/src/uicmd.cc	Sat Jun 18 10:07:29 2011 -0400
@@ -438,6 +438,7 @@
    FltkViewport *viewport = new FltkViewport (0, 0, 0, 1);
    viewport->box(FL_NO_BOX);
    viewport->setBufferedDrawing (prefs.buffered_drawing ? true : false);
+   viewport->setDragScroll (prefs.middle_click_drags_page ? true : false);
    layout->attachView (viewport);
    new_ui->set_render_layout(viewport);
    viewport->setScrollStep((int) rint(28.0 * prefs.font_factor));