[gtk/wip/otte/builder: 1/6] widget: Change templates to use closure functions
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/builder: 1/6] widget: Change templates to use closure functions
- Date: Fri, 22 Nov 2019 16:50:43 +0000 (UTC)
commit b7ff017f8d79ebcb873263853eb23010781b1c20
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 22 06:54:52 2019 +0100
widget: Change templates to use closure functions
... instead of connect functions.
docs/reference/gtk/gtk4-sections.txt | 2 +-
gtk/gtkwidget.c | 102 ++++++++++++++++-------------------
gtk/gtkwidget.h | 8 +--
3 files changed, 52 insertions(+), 60 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 522494a7a3..c53dfe8c60 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4669,7 +4669,7 @@ gtk_widget_class_bind_template_child_internal_private
gtk_widget_class_bind_template_child_full
gtk_widget_class_bind_template_callback
gtk_widget_class_bind_template_callback_full
-gtk_widget_class_set_connect_func
+gtk_widget_class_set_closure_func
<SUBSECTION>
gtk_widget_observe_children
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index fcb683f050..36d46e3ae4 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -490,9 +490,9 @@ typedef struct {
GBytes *data;
GSList *children;
GSList *callbacks;
- GtkBuilderConnectFunc connect_func;
- gpointer connect_data;
- GDestroyNotify destroy_notify;
+ GtkBuilderClosureFunc closure_func;
+ gpointer closure_data;
+ GDestroyNotify closure_destroy;
} GtkWidgetTemplate;
struct _GtkWidgetClassPrivate
@@ -12027,9 +12027,9 @@ template_data_free (GtkWidgetTemplate *template_data)
g_slist_free_full (template_data->children, (GDestroyNotify)template_child_class_free);
g_slist_free_full (template_data->callbacks, (GDestroyNotify)callback_symbol_free);
- if (template_data->connect_data &&
- template_data->destroy_notify)
- template_data->destroy_notify (template_data->connect_data);
+ if (template_data->closure_data &&
+ template_data->closure_destroy)
+ template_data->closure_destroy (template_data->closure_data);
g_slice_free (GtkWidgetTemplate, template_data);
}
@@ -12113,32 +12113,22 @@ setup_template_child (GtkWidgetTemplate *template_data,
return TRUE;
}
-static void
-gtk_widget_template_connect_func (GtkBuilder *builder,
- GObject *object,
- const gchar *signal_name,
- const gchar *handler_name,
- GObject *connect_object,
- GConnectFlags flags,
- gpointer user_data)
+static GClosure *
+gtk_widget_template_closure_func (GtkBuilder *builder,
+ const char *function_name,
+ gboolean swapped,
+ GObject *object,
+ gpointer user_data,
+ GError **error)
{
- GClosure *closure;
- GError *error = NULL;
-
- closure = gtk_builder_create_closure (builder,
- handler_name,
- flags & G_CONNECT_SWAPPED ? TRUE : FALSE,
- connect_object ? connect_object : user_data,
- &error);
-
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- return;
- }
+ if (object == NULL)
+ object = user_data;
- g_signal_connect_closure (object, signal_name, closure, flags & G_CONNECT_AFTER ? TRUE : FALSE);
+ return gtk_builder_create_cclosure (builder,
+ function_name,
+ swapped,
+ object,
+ error);
}
/**
@@ -12182,6 +12172,17 @@ gtk_widget_init_template (GtkWidget *widget)
builder = gtk_builder_new ();
+ /* Setup closure handling. All signal data from a template receive the
+ * template instance as user data automatically.
+ *
+ * A GtkBuilderClosureFunc can be provided to gtk_widget_class_set_signal_closure_func()
+ * in order for templates to be usable by bindings.
+ */
+ if (template->closure_func)
+ gtk_builder_set_closure_func (builder, template->closure_func, template->closure_data, NULL);
+ else
+ gtk_builder_set_closure_func (builder, gtk_widget_template_closure_func, widget, NULL);
+
/* Add any callback symbols declared for this GType to the GtkBuilder namespace */
for (l = template->callbacks; l; l = l->next)
{
@@ -12231,16 +12232,7 @@ gtk_widget_init_template (GtkWidget *widget)
}
}
- /* Connect signals. All signal data from a template receive the
- * template instance as user data automatically.
- *
- * A GtkBuilderConnectFunc can be provided to gtk_widget_class_set_signal_connect_func()
- * in order for templates to be usable by bindings.
- */
- if (template->connect_func)
- gtk_builder_connect_signals_full (builder, template->connect_func, template->connect_data);
- else
- gtk_builder_connect_signals_full (builder, gtk_widget_template_connect_func, widget);
+ gtk_builder_connect_signals (builder);
g_object_unref (builder);
}
@@ -12360,36 +12352,36 @@ gtk_widget_class_bind_template_callback_full (GtkWidgetClass *widget_class,
}
/**
- * gtk_widget_class_set_connect_func:
+ * gtk_widget_class_set_closure_func:
* @widget_class: A #GtkWidgetClass
- * @connect_func: The #GtkBuilderConnectFunc to use when connecting signals in the class template
- * @connect_data: The data to pass to @connect_func
- * @connect_data_destroy: The #GDestroyNotify to free @connect_data, this will only be used at
+ * @closure_func: The #GtkBuilderClosureFunc to use when creating closure in the class template
+ * @closure_data: The data to pass to @closure_func
+ * @closure_data_destroy: The #GDestroyNotify to free @closure_data, this will only be used at
* class finalization time, when no classes of type @widget_type are in use anymore.
*
- * For use in language bindings, this will override the default #GtkBuilderConnectFunc to be
+ * For use in language bindings, this will override the default #GtkBuilderClosureFunc to be
* used when parsing GtkBuilder XML from this class’s template data.
*
* Note that this must be called from a composite widget classes class
* initializer after calling gtk_widget_class_set_template().
*/
void
-gtk_widget_class_set_connect_func (GtkWidgetClass *widget_class,
- GtkBuilderConnectFunc connect_func,
- gpointer connect_data,
- GDestroyNotify connect_data_destroy)
+gtk_widget_class_set_closure_func (GtkWidgetClass *widget_class,
+ GtkBuilderClosureFunc closure_func,
+ gpointer closure_data,
+ GDestroyNotify closure_data_destroy)
{
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
g_return_if_fail (widget_class->priv->template != NULL);
/* Defensive, destroy any previously set data */
- if (widget_class->priv->template->connect_data &&
- widget_class->priv->template->destroy_notify)
- widget_class->priv->template->destroy_notify (widget_class->priv->template->connect_data);
+ if (widget_class->priv->template->closure_data &&
+ widget_class->priv->template->closure_destroy)
+ widget_class->priv->template->closure_destroy (widget_class->priv->template->closure_data);
- widget_class->priv->template->connect_func = connect_func;
- widget_class->priv->template->connect_data = connect_data;
- widget_class->priv->template->destroy_notify = connect_data_destroy;
+ widget_class->priv->template->closure_func = closure_func;
+ widget_class->priv->template->closure_data = closure_data;
+ widget_class->priv->template->closure_destroy = closure_data_destroy;
}
/**
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 49cf371cf4..ff8ac40027 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -956,10 +956,10 @@ void gtk_widget_class_bind_template_callback_full (GtkWidgetClass *
const gchar *callback_name,
GCallback callback_symbol);
GDK_AVAILABLE_IN_ALL
-void gtk_widget_class_set_connect_func (GtkWidgetClass *widget_class,
- GtkBuilderConnectFunc connect_func,
- gpointer connect_data,
- GDestroyNotify connect_data_destroy);
+void gtk_widget_class_set_closure_func (GtkWidgetClass *widget_class,
+ GtkBuilderClosureFunc closure_func,
+ gpointer closure_data,
+ GDestroyNotify closure_destroy);
GDK_AVAILABLE_IN_ALL
void gtk_widget_class_bind_template_child_full (GtkWidgetClass *widget_class,
const gchar *name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]