From 79fbe6c0a8799da4bdd930ec2b30a604ddfe3bdf Mon Sep 17 00:00:00 2001 From: gambas Date: Wed, 5 Jan 2022 16:07:57 +0100 Subject: [PATCH] Fix tab focus management. [GB.GTK] * BUG: Fix tab focus management. [GB.GTK3] * BUG: Fix tab focus management. --- gb.gtk/src/gcontrol.cpp | 55 +++++++++++++++++--------------------- gb.gtk/src/gcontrol.h | 1 + gb.gtk/src/gmainwindow.cpp | 1 - gb.gtk/src/gsignals.cpp | 8 +++--- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index b750e2e99..1689a4b3b 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -2638,9 +2638,6 @@ void gControl::setNoTabFocus(bool v) return; } - if (_no_tab_focus == v) - return; - _no_tab_focus = v; } @@ -2652,6 +2649,11 @@ bool gControl::isNoTabFocus() const return _no_tab_focus; } +bool gControl::isNoTabFocusRec() const +{ + return isNoTabFocus() || (parent() && parent()->isNoTabFocusRec()); +} + #ifdef GTK3 void gControl::onEnterEvent() { @@ -2861,50 +2863,41 @@ gControl *gControl::nextFocus() gControl *ctrl; gControl *next_ctrl; - //fprintf(stderr, "next: %s\n", name()); - - if (isContainer()) - { - ctrl = ((gContainer *)this)->firstChild(); - if (ctrl) - { - //fprintf(stderr, "==> %s\n", ctrl->name()); - return ctrl; - } - } - ctrl = this; + if (ctrl->isContainer() && ((gContainer *)ctrl)->childCount()) + return ((gContainer *)ctrl)->firstChild(); + for(;;) { next_ctrl = ctrl->next(); if (next_ctrl) return next_ctrl; - + if (ctrl->isTopLevel()) + return ctrl; ctrl = ctrl->parent(); - if (!ctrl) - return NULL; - /*if (!ctrl->parent()) - return ctrl->nextFocus();*/ } } gControl *gControl::previousFocus() { - gControl *ctrl = previous(); + gControl *ctrl; + gControl *next_ctrl; - if (!ctrl) + ctrl = this; + + if (ctrl->isContainer() && ((gContainer *)ctrl)->childCount()) + return ((gContainer *)ctrl)->lastChild(); + + for(;;) { - if (!isTopLevel()) - return parent()->previousFocus(); - - ctrl = this; + next_ctrl = ctrl->previous(); + if (next_ctrl) + return next_ctrl; + if (ctrl->isTopLevel()) + return ctrl; + ctrl = ctrl->parent(); } - - while (ctrl->isContainer() && ((gContainer *)ctrl)->childCount()) - ctrl = ((gContainer *)ctrl)->lastChild(); - - return ctrl; } void gControl::createWidget() diff --git a/gb.gtk/src/gcontrol.h b/gb.gtk/src/gcontrol.h index 397ebd554..6e16b24dd 100644 --- a/gb.gtk/src/gcontrol.h +++ b/gb.gtk/src/gcontrol.h @@ -133,6 +133,7 @@ public: void setTracking(bool vl); bool isNoTabFocus() const; + bool isNoTabFocusRec() const; void setNoTabFocus(bool v); gColor background() const { return _bg; } diff --git a/gb.gtk/src/gmainwindow.cpp b/gb.gtk/src/gmainwindow.cpp index 014aef784..8395a99da 100644 --- a/gb.gtk/src/gmainwindow.cpp +++ b/gb.gtk/src/gmainwindow.cpp @@ -474,7 +474,6 @@ void gMainWindow::initWindow() have_cursor = true; //parent() == 0 && !_xembed; setCanFocus(true); - setNoTabFocus(true); } diff --git a/gb.gtk/src/gsignals.cpp b/gb.gtk/src/gsignals.cpp index 02b8fe060..acbab794d 100644 --- a/gb.gtk/src/gsignals.cpp +++ b/gb.gtk/src/gsignals.cpp @@ -98,13 +98,15 @@ gboolean gcb_focus(GtkWidget *widget, GtkDirectionType direction, gControl *data if (!ctrl) break; - if (ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus() && !ctrl->isNoTabFocus()) + //fprintf(stderr, "gcb_focus: %s / %d %d %d %d\n", ctrl->name(), ctrl->isReallyVisible(), ctrl->isEnabled(), ctrl->canFocus(), !ctrl->isNoTabFocusRec()); + + if (!ctrl->isTopLevel() && ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus() && !ctrl->isNoTabFocusRec()) { - //fprintf(stderr, "cb_focus: --> %s\n", ctrl->name()); + //fprintf(stderr, "cb_focus: --> %s / %d\n", ctrl->name(), ctrl->isNoTabFocusRec()); ctrl->setFocus(); break; } - if (ctrl == data) + if (ctrl == gApplication::activeControl()) break; } }