Add gtk_widget_set_focus_child

With a very useful implementation, but at least now we don't get runtime
warnings.
This commit is contained in:
Timm Bäder 2017-01-06 17:06:51 +01:00
parent 52aed5d607
commit 5f98597a0c
3 changed files with 24 additions and 3 deletions

View File

@ -7231,7 +7231,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
while (widget->priv->parent) while (widget->priv->parent)
{ {
widget = 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) if (widget == common_ancestor)
break; break;
} }
@ -7255,7 +7255,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget)
widget = focus_widget; widget = focus_widget;
while (widget->priv->parent) 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; widget = widget->priv->parent;
} }
if (GTK_IS_WINDOW (widget)) if (GTK_IS_WINDOW (widget))
@ -15804,3 +15804,21 @@ gtk_widget_snapshot_child (GtkWidget *widget,
gtk_widget_snapshot (child, snapshot); gtk_widget_snapshot (child, snapshot);
gtk_snapshot_translate_2d (snapshot, -x, -y); 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: ??? */
}

View File

@ -1258,6 +1258,9 @@ GDK_AVAILABLE_IN_3_90
GtkWidget * gtk_widget_get_next_sibling (GtkWidget *widget); GtkWidget * gtk_widget_get_next_sibling (GtkWidget *widget);
GDK_AVAILABLE_IN_3_90 GDK_AVAILABLE_IN_3_90
GtkWidget * gtk_widget_get_prev_sibling (GtkWidget *widget); 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(GtkWidget, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)

View File

@ -2539,7 +2539,7 @@ gtk_window_set_focus (GtkWindow *window,
while ((parent = _gtk_widget_get_parent (widget))) while ((parent = _gtk_widget_get_parent (widget)))
{ {
widget = parent; widget = parent;
gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL); gtk_widget_set_focus_child (widget, NULL);
} }
} }