From 5f98597a0c3878801c12e630755be327263064e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 6 Jan 2017 17:06:51 +0100 Subject: [PATCH] Add gtk_widget_set_focus_child With a very useful implementation, but at least now we don't get runtime warnings. --- gtk/gtkwidget.c | 22 ++++++++++++++++++++-- gtk/gtkwidget.h | 3 +++ gtk/gtkwindow.c | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 8bebdfb048..e61ea43406 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -7231,7 +7231,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget) while (widget->priv->parent) { widget = widget->priv->parent; - gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL); + gtk_widget_set_focus_child (widget, NULL); if (widget == common_ancestor) break; } @@ -7255,7 +7255,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget) widget = focus_widget; while (widget->priv->parent) { - gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget); + gtk_widget_set_focus_child (widget->priv->parent, widget); widget = widget->priv->parent; } if (GTK_IS_WINDOW (widget)) @@ -15804,3 +15804,21 @@ gtk_widget_snapshot_child (GtkWidget *widget, gtk_widget_snapshot (child, snapshot); gtk_snapshot_translate_2d (snapshot, -x, -y); } + +void +gtk_widget_set_focus_child (GtkWidget *widget, + GtkWidget *child) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (child != NULL) + { + g_return_if_fail (GTK_IS_WIDGET (child)); + g_return_if_fail (gtk_widget_get_parent (child) == widget); + } + + if (GTK_IS_CONTAINER (widget)) + gtk_container_set_focus_child (GTK_CONTAINER (widget), child); + + /* TODO: ??? */ +} diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 33db17d6e4..319c7d76d4 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -1258,6 +1258,9 @@ GDK_AVAILABLE_IN_3_90 GtkWidget * gtk_widget_get_next_sibling (GtkWidget *widget); GDK_AVAILABLE_IN_3_90 GtkWidget * gtk_widget_get_prev_sibling (GtkWidget *widget); +GDK_AVAILABLE_IN_3_90 +void gtk_widget_set_focus_child (GtkWidget *widget, + GtkWidget *child); G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 1d03a667b5..dbdeb18880 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -2539,7 +2539,7 @@ gtk_window_set_focus (GtkWindow *window, while ((parent = _gtk_widget_get_parent (widget))) { widget = parent; - gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL); + gtk_widget_set_focus_child (widget, NULL); } }