From ab885aabd49f019d7c06255289c661b340150ea7 Mon Sep 17 00:00:00 2001 From: gambas Date: Sun, 12 Dec 2021 00:53:38 +0100 Subject: [PATCH] Hide and show all children of a container when it is mapped, to workaround GTK+3 bugs with widget stacking. [GB.GTK3] * BUG: Hide and show all children of a container when it is mapped, to workaround GTK+3 bugs with widget stacking. --- gb.gtk/src/gcontainer.cpp | 23 +++++++++++++++++++++++ gb.gtk/src/gcontainer.h | 2 +- gb.gtk/src/gcontrol.cpp | 15 +++++++++------ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/gb.gtk/src/gcontainer.cpp b/gb.gtk/src/gcontainer.cpp index 4f7013637..f6dde906d 100644 --- a/gb.gtk/src/gcontainer.cpp +++ b/gb.gtk/src/gcontainer.cpp @@ -70,6 +70,26 @@ static void cb_map(GtkWidget *widget, gContainer *sender) sender->arrangeLater(); } +#if GTK3 +static void cb_remap_children(GtkWidget *widget, GdkEvent *event, gContainer *sender) +{ + int i; + gControl *child; + + //fprintf(stderr, "cb_remap_children: %s\n", sender->name()); + + for (i = 0; i < sender->childCount(); i++) + { + child = sender->child(i); + if (gtk_widget_get_visible(child->border)) + { + child->hideButKeepFocus(); + child->showButKeepFocus(); + } + } +} +#endif + static void cb_unmap(GtkWidget *widget, gContainer *sender) { sender->setShown(false); @@ -750,6 +770,9 @@ void gContainer::connectBorder() { g_signal_connect_after(G_OBJECT(border), "map", G_CALLBACK(cb_map), (gpointer)this); g_signal_connect_after(G_OBJECT(border), "unmap", G_CALLBACK(cb_unmap), (gpointer)this); +#if GTK3 + g_signal_connect_after(G_OBJECT(border), "map-event", G_CALLBACK(cb_remap_children), (gpointer)this); +#endif } bool gContainer::resize(int w, int h, bool no_decide) diff --git a/gb.gtk/src/gcontainer.h b/gb.gtk/src/gcontainer.h index 5c090adc8..ec8c5882b 100644 --- a/gb.gtk/src/gcontainer.h +++ b/gb.gtk/src/gcontainer.h @@ -154,7 +154,7 @@ public: virtual void reparent(gContainer *newpr, int x, int y); void hideHiddenChildren(); virtual GtkWidget *getContainer(); - + void setShown(bool v) { _shown = v; } bool isShown() const { return _shown; } void arrangeLater(); diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index ffa1156d1..4d747d259 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -712,11 +712,14 @@ void gControl::hideButKeepFocus() { //fprintf(stderr, "gControl::hideButKeepFocus: %s\n", gApplication::_active_control ? gApplication::_active_control->name() : "NULL"); - gApplication::_keep_focus = true; - gApplication::_disable_mapping_events = true; - gtk_widget_hide(border); - gApplication::_disable_mapping_events = false; - gApplication::_keep_focus = false; + if (gtk_widget_get_visible(border)) + { + gApplication::_keep_focus = true; + gApplication::_disable_mapping_events = true; + gtk_widget_hide(border); + gApplication::_disable_mapping_events = false; + gApplication::_keep_focus = false; + } } void gControl::showButKeepFocus() @@ -725,7 +728,7 @@ void gControl::showButKeepFocus() //fprintf(stderr, "gControl::showButKeepFocus: %s\n", gApplication::_active_control ? gApplication::_active_control->name() : "NULL"); - if (_allow_show) + if (_allow_show && !gtk_widget_get_visible(border)) { gApplication::_disable_mapping_events = true; gtk_widget_show(border);