changeset 1907:5f92140e4bce

view and form widget focusing
author corvid <corvid@lavabit.com>
date Wed, 23 Feb 2011 08:19:03 +0000
parents 3d4b69d3eee7
children 8955c455fa01
files dw/fltkviewbase.cc dw/fltkviewbase.hh dw/fltkviewport.cc
diffstat 3 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkviewbase.cc	Fri Feb 18 02:06:35 2011 +0000
+++ b/dw/fltkviewbase.cc	Wed Feb 23 08:19:03 2011 +0000
@@ -29,6 +29,8 @@
 #include <wctype.h>
 #include "../lout/msg.h"
 
+extern Fl_Widget* fl_oldfocus;
+
 using namespace lout::object;
 using namespace lout::container::typed;
 
@@ -71,6 +73,7 @@
    canvasHeight = 1;
    bgColor = FL_WHITE;
    mouse_x = mouse_y = 0;
+   focused_child = NULL;
    exposeArea = NULL;
    if (backBuffer == NULL) {
       backBuffer = new BackBuffer ();
@@ -268,6 +271,17 @@
       theLayout->leaveNotify (this, getDwButtonState ());
       return Fl_Group::handle (event);
 
+   case FL_FOCUS:
+      if (focused_child && find(focused_child) < children()) {
+         /* strangely, find() == children() if the child is not found */
+         focused_child->take_focus();
+      }
+      return 1;
+
+   case FL_UNFOCUS:
+      focused_child = fl_oldfocus;
+      return 0;
+      
    default:
       return Fl_Group::handle (event);
    }
--- a/dw/fltkviewbase.hh	Fri Feb 18 02:06:35 2011 +0000
+++ b/dw/fltkviewbase.hh	Wed Feb 23 08:19:03 2011 +0000
@@ -56,6 +56,7 @@
    core::Layout *theLayout;
    int canvasWidth, canvasHeight;
    int mouse_x, mouse_y;
+   Fl_Widget *focused_child;
 
    virtual int translateViewXToCanvasX (int x) = 0;
    virtual int translateViewYToCanvasY (int y) = 0;
--- a/dw/fltkviewport.cc	Fri Feb 18 02:06:35 2011 +0000
+++ b/dw/fltkviewport.cc	Wed Feb 23 08:19:03 2011 +0000
@@ -223,17 +223,6 @@
 
    case FL_FOCUS:
       /** \bug Draw focus box. */
-#if 0
-PORT1.3
-      /* If the user clicks with the left button we take focus
-       * and thereby unfocus any form widgets.
-       * Otherwise we let fltk do the focus handling.
-       */
-      if (Fl::event_button() == FL_LEFT_MOUSE || focus_index() < 0) {
-         focus_index(-1);
-         return 1;
-      }
-#endif
       break;
 
    case FL_UNFOCUS:
@@ -241,17 +230,15 @@
       break;
 
    case FL_PUSH:
-      take_focus();
-      if (Fl::event_button() == FL_MIDDLE_MOUSE) {
+      if (FltkWidgetView::handle (event) == 0 &&
+          Fl::event_button() == FL_MIDDLE_MOUSE) {
          /* pass event so that middle click can open link in new window */
-         if (FltkWidgetView::handle (event) == 0) {
-            dragScrolling = 1;
-            dragX = Fl::event_x();
-            dragY = Fl::event_y();
-            setCursor (core::style::CURSOR_MOVE);
-         }
-         return 1;
+         dragScrolling = 1;
+         dragX = Fl::event_x();
+         dragY = Fl::event_y();
+         setCursor (core::style::CURSOR_MOVE);
       }
+      return 1;
       break;
 
    case FL_DRAG: