[gtk] scale: Add a destroy notify to set_format_value_func
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] scale: Add a destroy notify to set_format_value_func
- Date: Thu, 15 Aug 2019 15:23:33 +0000 (UTC)
commit ee275874281be37b5fe4ef7533b5e567ae96dbd0
Author: Timm Bäder <mail baedert org>
Date: Thu Aug 15 17:21:47 2019 +0200
scale: Add a destroy notify to set_format_value_func
Closes #2098
demos/widget-factory/widget-factory.c | 4 ++--
gtk/gtkscale.c | 12 +++++++++++-
gtk/gtkscale.h | 3 ++-
3 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 50bcc8c600..781f63f7cd 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -1944,10 +1944,10 @@ activate (GApplication *app)
g_timeout_add (100, (GSourceFunc)pulse_it, widget);
widget = (GtkWidget *)gtk_builder_get_object (builder, "scale3");
- gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value, NULL);
+ gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value, NULL, NULL);
widget = (GtkWidget *)gtk_builder_get_object (builder, "scale4");
- gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value_blank, NULL);
+ gtk_scale_set_format_value_func (GTK_SCALE (widget), scale_format_value_blank, NULL, NULL);
widget = (GtkWidget *)gtk_builder_get_object (builder, "box_for_context");
model = (GMenuModel *)gtk_builder_get_object (builder, "new_style_context_menu_model");
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index c7922e8591..fafcfab3bb 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -150,6 +150,7 @@ struct _GtkScalePrivate
GtkScaleFormatValueFunc format_value_func;
gpointer format_value_func_user_data;
+ GDestroyNotify format_value_func_destroy_notify;
guint draw_value : 1;
guint value_pos : 2;
@@ -1553,6 +1554,9 @@ gtk_scale_finalize (GObject *object)
g_clear_pointer (&priv->value_widget, gtk_widget_unparent);
+ if (priv->format_value_func_destroy_notify)
+ priv->format_value_func_destroy_notify (priv->format_value_func_user_data);
+
G_OBJECT_CLASS (gtk_scale_parent_class)->finalize (object);
}
@@ -2040,6 +2044,7 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
* @scale: a #GtkScale
* @func: (nullable): function that formats the value
* @user_data: (nullable): user data to pass to @func
+ * @destroy_notify: (nullable): destroy function for @user_data
*
* @func allows you to change how the scale value is displayed. The given
* function will return an allocated string representing @value.
@@ -2051,7 +2056,8 @@ gtk_scale_buildable_custom_finished (GtkBuildable *buildable,
void
gtk_scale_set_format_value_func (GtkScale *scale,
GtkScaleFormatValueFunc func,
- gpointer user_data)
+ gpointer user_data,
+ GDestroyNotify destroy_notify)
{
GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
GtkAdjustment *adjustment;
@@ -2059,8 +2065,12 @@ gtk_scale_set_format_value_func (GtkScale *scale,
g_return_if_fail (GTK_IS_SCALE (scale));
+ if (priv->format_value_func_destroy_notify)
+ priv->format_value_func_destroy_notify (priv->format_value_func_user_data);
+
priv->format_value_func = func;
priv->format_value_func_user_data = user_data;
+ priv->format_value_func_destroy_notify = destroy_notify;
if (!priv->value_widget)
return;
diff --git a/gtk/gtkscale.h b/gtk/gtkscale.h
index c18a82ecff..36f5fc2bfc 100644
--- a/gtk/gtkscale.h
+++ b/gtk/gtkscale.h
@@ -128,7 +128,8 @@ void gtk_scale_clear_marks (GtkScale *scale);
GDK_AVAILABLE_IN_ALL
void gtk_scale_set_format_value_func (GtkScale *scale,
GtkScaleFormatValueFunc func,
- gpointer user_data);
+ gpointer user_data,
+ GDestroyNotify destroy_notify);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]