From 47208e1da2fa8c0ebc21aebeb9a12ba2e087da70 Mon Sep 17 00:00:00 2001 From: gambas Date: Sat, 29 Jan 2022 22:58:27 +0100 Subject: [PATCH] Fix focus management when a control is hidden. [GB.GTK] * BUG: Fix focus management when a control is hidden. [GB.GTK3] * BUG: Fix focus management when a control is hidden. --- gb.gtk/src/gapplication.cpp | 7 +++++-- gb.gtk/src/gcontrol.cpp | 18 ++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/gb.gtk/src/gapplication.cpp b/gb.gtk/src/gapplication.cpp index 505e389bf..f75955928 100644 --- a/gb.gtk/src/gapplication.cpp +++ b/gb.gtk/src/gapplication.cpp @@ -342,7 +342,7 @@ static void gambas_handle_event(GdkEvent *event) //if (GTK_IS_WINDOW(widget)) { - control = gt_get_control(widget); + //control = gt_get_control(widget); if (control) gApplication::setActiveControl(control, event->focus_change.in); else if (event->focus_change.in) @@ -1383,9 +1383,12 @@ void gApplication::setActiveControl(gControl *control, bool on) return; #if DEBUG_FOCUS - fprintf(stderr, "setActiveControl: %s %d / %d\n", control->name(), on, _focus_change); + fprintf(stderr, "setActiveControl: %s %s %d / %d\n", GB.GetClassName(control->hFree), control->name(), on, _focus_change); #endif + /*if (!::strcmp(GB.GetClassName(control->hFree), "FEditor") && !on) + BREAKPOINT();*/ + if (_active_control && !_focus_change) _previous_control = _active_control; diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index b28415c4e..6f03abaa8 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -543,9 +543,12 @@ void gControl::setVisibility(bool vl) } else { - if (parent() && hasFocus()) - gcb_focus(widget, GTK_DIR_TAB_FORWARD, this); - gApplication::setActiveControl(this, false); + if (hasFocus()) + { + if (parent()) + gcb_focus(widget, GTK_DIR_TAB_FORWARD, this); + gApplication::setActiveControl(this, false); + } if (gtk_widget_has_grab(border)) gtk_grab_remove(border); gtk_widget_hide(border); @@ -694,9 +697,6 @@ void gControl::move(int x, int y) updateGeometry(); #endif - /*if (name() && !::strcmp(name(), "txtTagEditor") && y == 43) - BREAKPOINT();*/ - checkVisibility(); send_configure(this); // needed for Watcher and Form Move events @@ -1342,18 +1342,16 @@ void gControl::setFocus() if (win->isVisible()) { - //if (isVisible() && bufW > 0 && bufH > 0) #if DEBUG_FOCUS - fprintf(stderr, "setFocus now %s %p\n", name(), widget); + fprintf(stderr, "setFocus NOW: %s %s %p\n", GB.GetClassName(hFree), name(), hFree); #endif - //win->activate(); gtk_widget_grab_focus(widget); } else { #if DEBUG_FOCUS - fprintf(stderr, "setFocus later %s\n", name()); + fprintf(stderr, "setFocus later: %s %s %p\n", GB.GetClassName(hFree), name(), hFree); #endif win->_initial_focus = this; }