[gtk+/wip/baedert/children: 21/22] Add and use gtk_widget_set_focus_child
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/children: 21/22] Add and use gtk_widget_set_focus_child
- Date: Wed, 23 Nov 2016 11:43:27 +0000 (UTC)
commit cdb8c552092077bd8a73d34e8c5962e4208269ca
Author: Timm Bäder <mail baedert org>
Date: Wed Nov 23 09:16:39 2016 +0100
Add and use gtk_widget_set_focus_child
WIP
gtk/gtkcontainer.c | 38 --------------------------------------
gtk/gtkpopover.c | 2 +-
gtk/gtkwidget.c | 41 ++++++++++++++++++++++++++++-------------
gtk/gtkwidget.h | 3 +++
gtk/gtkwidgetprivate.h | 2 ++
gtk/gtkwindow.c | 4 ++--
6 files changed, 36 insertions(+), 54 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 0627464..55cb6e3 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -290,7 +290,6 @@ enum {
ADD,
REMOVE,
CHECK_RESIZE,
- SET_FOCUS_CHILD,
LAST_SIGNAL
};
@@ -314,8 +313,6 @@ static void gtk_container_compute_expand (GtkWidget *widget,
gboolean *vexpand_p);
static gboolean gtk_container_focus (GtkWidget *widget,
GtkDirectionType direction);
-static void gtk_container_real_set_focus_child (GtkContainer *container,
- GtkWidget *widget);
static gboolean gtk_container_focus_move (GtkContainer *container,
GList *children,
@@ -469,7 +466,6 @@ gtk_container_class_init (GtkContainerClass *class)
class->remove = gtk_container_remove_unimplemented;
class->check_resize = gtk_container_real_check_resize;
class->forall = NULL;
- class->set_focus_child = gtk_container_real_set_focus_child;
class->child_type = NULL;
class->get_path_for_child = gtk_container_real_get_path_for_child;
@@ -499,15 +495,6 @@ gtk_container_class_init (GtkContainerClass *class)
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
- container_signals[SET_FOCUS_CHILD] =
- g_signal_new (I_("set-focus-child"),
- G_OBJECT_CLASS_TYPE (gobject_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkContainerClass, set_focus_child),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 1,
- GTK_TYPE_WIDGET);
if (GtkContainer_private_offset != 0)
g_type_class_adjust_private_offset (class, &GtkContainer_private_offset);
@@ -1963,31 +1950,6 @@ gtk_container_foreach (GtkContainer *container,
}
/**
- * gtk_container_set_focus_child:
- * @container: a #GtkContainer
- * @child: (allow-none): a #GtkWidget, or %NULL
- *
- * Sets, or unsets if @child is %NULL, the focused child of @container.
- *
- * This function emits the GtkContainer::set_focus_child signal of
- * @container. Implementations of #GtkContainer can override the
- * default behaviour by overriding the class closure of this signal.
- *
- * This is function is mostly meant to be used by widgets. Applications can use
- * gtk_widget_grab_focus() to manually set the focus to a specific widget.
- */
-void
-gtk_container_set_focus_child (GtkContainer *container,
- GtkWidget *child)
-{
- g_return_if_fail (GTK_IS_CONTAINER (container));
- if (child)
- g_return_if_fail (GTK_IS_WIDGET (child));
-
- g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, child);
-}
-
-/**
* gtk_container_get_focus_child:
* @container: a #GtkContainer
*
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index b4a84c9..3a6626a 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -1515,7 +1515,7 @@ gtk_popover_focus (GtkWidget *widget,
*/
while (focus && focus != widget)
{
- gtk_container_set_focus_child (GTK_CONTAINER (focus), NULL);
+ gtk_widget_set_focus_child (focus, NULL);
focus = gtk_widget_get_parent (focus);
}
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 10364ed..270b930 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4030,7 +4030,7 @@ gtk_widget_unparent (GtkWidget *widget)
if (GTK_IS_CONTAINER (priv->parent))
{
if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
- gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
+ gtk_widget_set_focus_child (priv->parent, NULL);
}
if (_gtk_widget_is_drawable (priv->parent))
@@ -7296,17 +7296,11 @@ static void
reset_focus_recurse (GtkWidget *widget,
gpointer data)
{
- if (GTK_IS_CONTAINER (widget))
- {
- GtkContainer *container;
+ gtk_widget_set_focus_child (widget, NULL);
- container = GTK_CONTAINER (widget);
- gtk_container_set_focus_child (container, NULL);
-
- gtk_container_foreach (container,
- reset_focus_recurse,
- NULL);
- }
+ gtk_container_foreach (GTK_CONTAINER (widget),
+ reset_focus_recurse,
+ NULL);
}
static void
@@ -7347,7 +7341,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;
}
@@ -7371,7 +7365,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 (_gtk_widget_get_parent (widget), widget);
widget = widget->priv->parent;
}
if (GTK_IS_WINDOW (widget))
@@ -16000,3 +15994,24 @@ gtk_widget_propagate_draw (GtkWidget *widget,
cairo_restore (cr);
}
+
+void
+gtk_widget_set_focus_child (GtkWidget *widget,
+ GtkWidget *child)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
+
+ if (child != priv->focus_child)
+ {
+ if (priv->focus_child)
+ g_object_unref (priv->focus_child);
+ priv->focus_child = child;
+ if (priv->focus_child)
+ g_object_ref (priv->focus_child);
+ }
+
+
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 80824ce..6235936 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -1325,6 +1325,9 @@ GDK_AVAILABLE_IN_3_90
void gtk_widget_propagate_draw (GtkWidget *widget,
GtkWidget *child,
cairo_t *cr);
+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/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 6ffa5c4..3e15d87 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -159,6 +159,8 @@ struct _GtkWidgetPrivate
GtkWidget *next_sibling;
GtkWidget *first_child;
GtkWidget *last_child;
+
+ GtkWidget *focus_child;
};
GtkCssNode * gtk_widget_get_css_node (GtkWidget *widget);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0d5dfc1..0ecd6bd 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);
}
}
@@ -8007,7 +8007,7 @@ gtk_window_focus (GtkWidget *widget,
parent = _gtk_widget_get_parent (priv->focus_widget);
while (parent)
{
- gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
+ gtk_widget_set_focus_child (parent, NULL);
parent = _gtk_widget_get_parent (parent);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]