scale: Add a destroy notify to set_format_value_func

Closes #2098
This commit is contained in:
Timm Bäder 2019-08-15 17:21:47 +02:00
parent d2f76d689f
commit ee27587428
3 changed files with 15 additions and 4 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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