summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2012-12-25 23:23:40 +0000
committercorvid <corvid@lavabit.com>2012-12-25 23:23:40 +0000
commitb9c38a5dbf173a16d8636adc4524f388da291ee4 (patch)
tree56a5dc3a2ef982e48adeeaeb0f1d4369424a477f
parent7affd0dd3fcca04ef15b90fce2d89e5c5329863d (diff)
move this tabbing focus stuff to a separate function
-rw-r--r--dw/fltkviewbase.cc138
-rw-r--r--dw/fltkviewbase.hh1
2 files changed, 75 insertions, 64 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc
index b08d012b..3293dcc9 100644
--- a/dw/fltkviewbase.cc
+++ b/dw/fltkviewbase.cc
@@ -216,6 +216,78 @@ core::ButtonState getDwButtonState ()
return (core::ButtonState)s2;
}
+/*
+ * We handle Tab to determine which FLTK widget should get focus.
+ *
+ * Presumably a proper solution that allows focusing links, etc., would live
+ * in Textblock and use iterators.
+ */
+int FltkViewBase::manageTabToFocus()
+{
+ int i, ret = 0;
+ Fl_Widget *old_child = NULL;
+
+ if (this == Fl::focus()) {
+ // if we have focus, give it to a child. Go forward typically,
+ // or backward with Shift pressed.
+ if (!(Fl::event_state() & FL_SHIFT)) {
+ for (i = 0; i < children(); i++) {
+ if (child(i)->take_focus()) {
+ ret = 1;
+ break;
+ }
+ }
+ } else {
+ for (i = children() - 1; i >= 0; i--) {
+ if (child(i)->take_focus()) {
+ ret = 1;
+ break;
+ }
+ }
+ }
+ } else {
+ // tabbing between children
+ old_child = Fl::focus();
+
+ if (!(ret = Fl_Group::handle (FL_KEYBOARD))) {
+ // group didn't have any more children to focus.
+ Fl::focus(this);
+ return 1;
+ } else {
+ // which one did it focus?
+ for (i = 0; i < children(); i++)
+ if (child(i) == Fl::focus())
+ break;
+ }
+ }
+ if (ret) {
+ if (i >= 0 && i < children()) {
+ Fl_Widget *c = child(i);
+ int canvasX = translateViewXToCanvasX(c->x()),
+ canvasY = translateViewYToCanvasY(c->y());
+
+ theLayout->scrollTo(core::HPOS_INTO_VIEW, core::VPOS_INTO_VIEW,
+ canvasX, canvasY, c->w(), c->h());
+
+ // Draw the children who gained and lost focus. Otherwise a
+ // widget that had been only partly visible still shows its old
+ // appearance in the previously-visible portion.
+ core::Rectangle r(canvasX, canvasY, c->w(), c->h());
+
+ queueDraw(&r);
+
+ if (old_child) {
+ r.x = translateViewXToCanvasX(old_child->x());
+ r.y = translateViewYToCanvasY(old_child->y());
+ r.width = old_child->w();
+ r.height = old_child->h();
+ queueDraw(&r);
+ }
+ }
+ }
+ return ret;
+}
+
int FltkViewBase::handle (int event)
{
bool processed;
@@ -297,70 +369,8 @@ int FltkViewBase::handle (int event)
focused_child = fl_oldfocus;
return 0;
case FL_KEYBOARD:
- if (Fl::event_key() == FL_Tab) {
- int i, ret = 0;
- Fl_Widget *old_child = NULL;
-
- if (this == Fl::focus()) {
- // if we have focus, give it to a child. Go forward typically,
- // or backward with Shift pressed.
- if (!(Fl::event_state() & FL_SHIFT)) {
- for (i = 0; i < children(); i++) {
- if (child(i)->take_focus()) {
- ret = 1;
- break;
- }
- }
- } else {
- for (i = children() - 1; i >= 0; i--) {
- if (child(i)->take_focus()) {
- ret = 1;
- break;
- }
- }
- }
- } else {
- // tabbing between children
- old_child = Fl::focus();
-
- if (!(ret = Fl_Group::handle (event))) {
- // group didn't have any more children to focus.
- Fl::focus(this);
- return 1;
- } else {
- // which one did it focus?
- for (i = 0; i < children(); i++)
- if (child(i) == Fl::focus())
- break;
- }
- }
- if (ret) {
- if (i >= 0 && i < children()) {
- Fl_Widget *c = child(i);
- int canvasX = translateViewXToCanvasX(c->x()),
- canvasY = translateViewYToCanvasY(c->y());
-
- theLayout->scrollTo(core::HPOS_INTO_VIEW, core::VPOS_INTO_VIEW,
- canvasX, canvasY, c->w(), c->h());
-
- // Draw the children who gained and lost focus. Otherwise a
- // widget that had been only partly visible still shows its old
- // appearance in the previously-visible portion.
- core::Rectangle r(canvasX, canvasY, c->w(), c->h());
-
- queueDraw(&r);
-
- if (old_child) {
- r.x = translateViewXToCanvasX(old_child->x());
- r.y = translateViewYToCanvasY(old_child->y());
- r.width = old_child->w();
- r.height = old_child->h();
- queueDraw(&r);
- }
- }
- return 1;
- }
- }
+ if (Fl::event_key() == FL_Tab)
+ return manageTabToFocus();
break;
default:
break;
diff --git a/dw/fltkviewbase.hh b/dw/fltkviewbase.hh
index 2b248803..eb4ec322 100644
--- a/dw/fltkviewbase.hh
+++ b/dw/fltkviewbase.hh
@@ -39,6 +39,7 @@ private:
void draw (const core::Rectangle *rect, DrawType type);
void drawChildWidgets ();
+ int manageTabToFocus();
inline void clipPoint (int *x, int *y, int border) {
if (exposeArea) {
if (*x < exposeArea->x - border)