diff options
author | corvid <corvid@lavabit.com> | 2011-02-23 08:19:03 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2011-02-23 08:19:03 +0000 |
commit | 144a37853adef52ba8024329859daea1c5c96c6f (patch) | |
tree | f994a3cb8cde2fc11ada937652663ebb0c544640 | |
parent | 151ad1018b0c1481474617ca96d393d95dd8a07e (diff) |
view and form widget focusing
-rw-r--r-- | dw/fltkviewbase.cc | 14 | ||||
-rw-r--r-- | dw/fltkviewbase.hh | 1 | ||||
-rw-r--r-- | dw/fltkviewport.cc | 27 |
3 files changed, 22 insertions, 20 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc index b7fed76c..02494fff 100644 --- a/dw/fltkviewbase.cc +++ b/dw/fltkviewbase.cc @@ -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 @@ FltkViewBase::FltkViewBase (int x, int y, int w, int h, const char *label): 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 @@ int FltkViewBase::handle (int event) 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); } diff --git a/dw/fltkviewbase.hh b/dw/fltkviewbase.hh index 3f9ba4b4..64697736 100644 --- a/dw/fltkviewbase.hh +++ b/dw/fltkviewbase.hh @@ -56,6 +56,7 @@ protected: 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; diff --git a/dw/fltkviewport.cc b/dw/fltkviewport.cc index 12796405..d0080a05 100644 --- a/dw/fltkviewport.cc +++ b/dw/fltkviewport.cc @@ -223,17 +223,6 @@ int FltkViewport::handle (int event) 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 @@ PORT1.3 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: |