libgimp: add GDestroyNotify for image and item combo box data

This commit is contained in:
Michael Natterer 2019-08-07 23:16:25 +02:00
parent cbefd8e5bb
commit c6bcb3114f
15 changed files with 105 additions and 64 deletions

View File

@ -56,6 +56,7 @@ struct _GimpImageComboBox
GimpImageConstraintFunc constraint;
gpointer data;
GDestroyNotify data_destroy;
};
struct _GimpImageComboBoxClass
@ -64,6 +65,8 @@ struct _GimpImageComboBoxClass
};
static void gimp_image_combo_box_finalize (GObject *object);
static void gimp_image_combo_box_populate (GimpImageComboBox *combo_box);
static void gimp_image_combo_box_model_add (GtkListStore *store,
gint num_images,
@ -85,14 +88,20 @@ static void gimp_image_combo_box_changed (GimpImageComboBox *combo_box);
static const GtkTargetEntry target = { "application/x-gimp-image-id", 0 };
G_DEFINE_TYPE (GimpImageComboBox, gimp_image_combo_box, GIMP_TYPE_INT_COMBO_BOX)
G_DEFINE_TYPE (GimpImageComboBox, gimp_image_combo_box,
GIMP_TYPE_INT_COMBO_BOX)
#define parent_class gimp_image_combo_box_parent_class
static void
gimp_image_combo_box_class_init (GimpImageComboBoxClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gimp_image_combo_box_finalize;
widget_class->drag_data_received = gimp_image_combo_box_drag_data_received;
}
@ -107,10 +116,22 @@ gimp_image_combo_box_init (GimpImageComboBox *combo_box)
GDK_ACTION_COPY);
}
static void
gimp_image_combo_box_finalize (GObject *object)
{
GimpImageComboBox *combo = GIMP_IMAGE_COMBO_BOX (object);
if (combo->data_destroy)
combo->data_destroy (combo->data);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gimp_image_combo_box_new:
* @constraint: a #GimpImageConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @constraint: a #GimpImageConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @data_destroy: Destroy function for @data.
*
* Creates a new #GimpIntComboBox filled with all currently opened
* images. If a @constraint function is specified, it is called for
@ -128,7 +149,8 @@ gimp_image_combo_box_init (GimpImageComboBox *combo_box)
**/
GtkWidget *
gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data)
gpointer data,
GDestroyNotify data_destroy)
{
GimpImageComboBox *combo_box;
@ -137,8 +159,9 @@ gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
"ellipsize", PANGO_ELLIPSIZE_MIDDLE,
NULL);
combo_box->constraint = constraint;
combo_box->data = data;
combo_box->constraint = constraint;
combo_box->data = data;
combo_box->data_destroy = data_destroy;
gimp_image_combo_box_populate (combo_box);

View File

@ -43,7 +43,8 @@ typedef gboolean (* GimpImageConstraintFunc) (gint32 image_id,
GType gimp_image_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_image_combo_box_new (GimpImageConstraintFunc constraint,
gpointer data);
gpointer data,
GDestroyNotify data_destroy);
G_END_DECLS

View File

@ -110,7 +110,8 @@ struct _GimpVectorsComboBoxClass
static GtkWidget * gimp_item_combo_box_new (GType type,
GimpItemConstraintFunc constraint,
gpointer data);
gpointer data,
GDestroyNotify data_destroy);
static void gimp_item_combo_box_populate (GimpIntComboBox *combo_box);
static void gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
@ -167,8 +168,9 @@ gimp_drawable_combo_box_init (GimpDrawableComboBox *combo_box)
/**
* gimp_drawable_combo_box_new:
* @constraint: a #GimpDrawableConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @constraint: a #GimpItemConstraintFunc or %NULL
* @data : a pointer that is passed to @constraint
* @data_destroy: Destroy function for @data
*
* Creates a new #GimpIntComboBox filled with all currently opened
* drawables. If a @constraint function is specified, it is called for
@ -185,11 +187,12 @@ gimp_drawable_combo_box_init (GimpDrawableComboBox *combo_box)
* Since: 2.2
**/
GtkWidget *
gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
gimp_drawable_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy)
{
return gimp_item_combo_box_new (GIMP_TYPE_DRAWABLE_COMBO_BOX,
constraint, data);
constraint, data, data_destroy);
}
@ -221,8 +224,9 @@ gimp_channel_combo_box_init (GimpChannelComboBox *combo_box)
/**
* gimp_channel_combo_box_new:
* @constraint: a #GimpDrawableConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @constraint: a #GimpItemConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @data_destroy: Destroy function for @data
*
* Creates a new #GimpIntComboBox filled with all currently opened
* channels. See gimp_drawable_combo_box_new() for more information.
@ -232,11 +236,12 @@ gimp_channel_combo_box_init (GimpChannelComboBox *combo_box)
* Since: 2.2
**/
GtkWidget *
gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
gimp_channel_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy)
{
return gimp_item_combo_box_new (GIMP_TYPE_CHANNEL_COMBO_BOX,
constraint, data);
constraint, data, data_destroy);
}
@ -268,8 +273,9 @@ gimp_layer_combo_box_init (GimpLayerComboBox *combo_box)
/**
* gimp_layer_combo_box_new:
* @constraint: a #GimpDrawableConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @constraint: a #GimpItemConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @data_destroy: Destroy function for @data
*
* Creates a new #GimpIntComboBox filled with all currently opened
* layers. See gimp_drawable_combo_box_new() for more information.
@ -279,11 +285,12 @@ gimp_layer_combo_box_init (GimpLayerComboBox *combo_box)
* Since: 2.2
**/
GtkWidget *
gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data)
gimp_layer_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy)
{
return gimp_item_combo_box_new (GIMP_TYPE_LAYER_COMBO_BOX,
constraint, data);
constraint, data, data_destroy);
}
@ -316,8 +323,9 @@ gimp_vectors_combo_box_init (GimpVectorsComboBox *combo_box)
/**
* gimp_vectors_combo_box_new:
* @constraint: a #GimpVectorsConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @constraint: a #GimpItemConstraintFunc or %NULL
* @data: a pointer that is passed to @constraint
* @data_destroy: Destroy function for @data
*
* Creates a new #GimpIntComboBox filled with all currently opened
* vectors objects. If a @constraint function is specified, it is called for
@ -334,18 +342,20 @@ gimp_vectors_combo_box_init (GimpVectorsComboBox *combo_box)
* Since: 2.4
**/
GtkWidget *
gimp_vectors_combo_box_new (GimpVectorsConstraintFunc constraint,
gpointer data)
gimp_vectors_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy)
{
return gimp_item_combo_box_new (GIMP_TYPE_VECTORS_COMBO_BOX,
constraint, data);
constraint, data, data_destroy);
}
static GtkWidget *
gimp_item_combo_box_new (GType type,
GimpItemConstraintFunc constraint,
gpointer data)
gpointer data,
GDestroyNotify data_destroy)
{
GimpIntComboBox *combo_box;
GimpItemComboBoxPrivate *private;
@ -360,6 +370,8 @@ gimp_item_combo_box_new (GType type,
private->constraint = constraint;
private->data = data;
g_object_weak_ref (G_OBJECT (combo_box), (GWeakNotify) data_destroy, data);
gimp_item_combo_box_populate (combo_box);
g_signal_connect (combo_box, "changed",

View File

@ -53,23 +53,24 @@ typedef gboolean (* GimpItemConstraintFunc) (gint32 image_id,
gint32 item_id,
gpointer data);
typedef GimpItemConstraintFunc GimpVectorsConstraintFunc;
typedef GimpItemConstraintFunc GimpDrawableConstraintFunc;
GType gimp_drawable_combo_box_get_type (void) G_GNUC_CONST;
GType gimp_channel_combo_box_get_type (void) G_GNUC_CONST;
GType gimp_layer_combo_box_get_type (void) G_GNUC_CONST;
GType gimp_vectors_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_drawable_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_channel_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_layer_combo_box_new (GimpDrawableConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_vectors_combo_box_new (GimpVectorsConstraintFunc constraint,
gpointer data);
GtkWidget * gimp_drawable_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy);
GtkWidget * gimp_channel_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy);
GtkWidget * gimp_layer_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy);
GtkWidget * gimp_vectors_combo_box_new (GimpItemConstraintFunc constraint,
gpointer data,
GDestroyNotify data_destroy);
G_END_DECLS

View File

@ -1191,7 +1191,7 @@ compose_dialog (const gchar *compose_type,
composeint.selected[j].is_ID = TRUE;
combo = gimp_drawable_combo_box_new (check_gray, NULL);
combo = gimp_drawable_combo_box_new (check_gray, NULL, NULL);
composeint.channel_menu[j] = combo;
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

View File

@ -669,7 +669,7 @@ DepthMerge_dialog (DepthMerge *dm)
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (dm_constraint, dm);
combo = gimp_drawable_combo_box_new (dm_constraint, dm, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dm->params.source1,
G_CALLBACK (dialogSource1ChangedCallback),
dm);
@ -683,7 +683,7 @@ DepthMerge_dialog (DepthMerge *dm)
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (dm_constraint, dm);
combo = gimp_drawable_combo_box_new (dm_constraint, dm, NULL);
gtk_widget_set_margin_bottom (combo, 6);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dm->params.depthMap1,
G_CALLBACK (dialogDepthMap1ChangedCallback),
@ -697,7 +697,7 @@ DepthMerge_dialog (DepthMerge *dm)
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (dm_constraint, dm);
combo = gimp_drawable_combo_box_new (dm_constraint, dm, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dm->params.source2,
G_CALLBACK (dialogSource2ChangedCallback),
dm);
@ -711,7 +711,7 @@ DepthMerge_dialog (DepthMerge *dm)
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (dm_constraint, dm);
combo = gimp_drawable_combo_box_new (dm_constraint, dm, NULL);
gtk_widget_set_margin_bottom (combo, 6);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dm->params.depthMap2,
G_CALLBACK (dialogDepthMap2ChangedCallback),

View File

@ -972,7 +972,7 @@ gui_multi (void)
h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
img_combo = gimp_image_combo_box_new (NULL, NULL);
img_combo = gimp_image_combo_box_new (NULL, NULL, NULL);
gtk_box_pack_start (GTK_BOX (h_box), img_combo, FALSE, FALSE, 0);
add_image = gtk_button_new_with_label (_("Add this image"));

View File

@ -1356,7 +1356,7 @@ smp_dialog (void)
gtk_grid_attach (GTK_GRID (grid), label, 0, ty, 1, 1);
gtk_widget_show (label);
combo = gimp_layer_combo_box_new (smp_constrain, NULL);
combo = gimp_layer_combo_box_new (smp_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), g_values.dst_id,
G_CALLBACK (smp_dest_combo_callback),
NULL);
@ -1370,7 +1370,7 @@ smp_dialog (void)
gtk_grid_attach (GTK_GRID (grid), label, 3, ty, 1, 1);
gtk_widget_show (label);
combo = gimp_layer_combo_box_new (smp_constrain, NULL);
combo = gimp_layer_combo_box_new (smp_constrain, NULL, NULL);
gimp_int_combo_box_prepend (GIMP_INT_COMBO_BOX (combo),
GIMP_INT_STORE_VALUE, SMP_INV_GRADIENT,

View File

@ -712,7 +712,7 @@ create_main_dialog (void)
gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
gtk_widget_show (grid);
combo = gimp_drawable_combo_box_new (effect_image_constrain, NULL);
combo = gimp_drawable_combo_box_new (effect_image_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
licvals.effect_image_id,
G_CALLBACK (gimp_int_combo_box_get_active),

View File

@ -460,7 +460,8 @@ warp_dialog (gint32 drawable_id)
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (warp_map_constrain,
GINT_TO_POINTER (drawable_id));
GINT_TO_POINTER (drawable_id),
NULL);
gtk_widget_set_margin_start (combo, 12);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dvals.warp_map,
G_CALLBACK (gimp_int_combo_box_get_active),
@ -608,7 +609,8 @@ warp_dialog (gint32 drawable_id)
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (warp_map_constrain,
GINT_TO_POINTER (drawable_id));
GINT_TO_POINTER (drawable_id),
NULL);
gtk_widget_set_margin_start (combo, 12);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), dvals.mag_map,
G_CALLBACK (gimp_int_combo_box_get_active),
@ -666,7 +668,8 @@ warp_dialog (gint32 drawable_id)
/* --------- Gradient map menu ---------------- */
combo = gimp_drawable_combo_box_new (warp_map_constrain,
GINT_TO_POINTER (drawable_id));
GINT_TO_POINTER (drawable_id),
NULL);
gtk_widget_set_margin_start (combo, 12);
gtk_grid_attach (GTK_GRID (grid), combo, 2, 0, 1, 1);
// GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
@ -711,7 +714,8 @@ warp_dialog (gint32 drawable_id)
/* --------- Vector map menu ---------------- */
combo = gimp_drawable_combo_box_new (warp_map_constrain,
GINT_TO_POINTER (drawable_id));
GINT_TO_POINTER (drawable_id),
NULL);
gtk_widget_set_margin_start (combo, 12);
gtk_grid_attach (GTK_GRID (grid), combo, 2, 1, 1, 1);
// GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

View File

@ -1173,7 +1173,7 @@ flame_dialog (void)
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
combo = gimp_drawable_combo_box_new (cmap_constrain, NULL);
combo = gimp_drawable_combo_box_new (cmap_constrain, NULL, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);

View File

@ -597,7 +597,7 @@ create_brushpage (GtkNotebook *notebook)
gtk_size_group_add_widget (group, tmpw);
g_object_unref (group);
combo = gimp_drawable_combo_box_new (validdrawable, NULL);
combo = gimp_drawable_combo_box_new (validdrawable, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), -1,
G_CALLBACK (brushdmenuselect),
NULL);

View File

@ -839,7 +839,7 @@ create_bump_page (void)
grid, "sensitive",
G_BINDING_SYNC_CREATE);
combo = gimp_drawable_combo_box_new (bumpmap_constrain, NULL);
combo = gimp_drawable_combo_box_new (bumpmap_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), mapvals.bumpmap_id,
G_CALLBACK (gimp_int_combo_box_get_active),
&mapvals.bumpmap_id);
@ -932,7 +932,7 @@ create_environment_page (void)
grid, "sensitive",
G_BINDING_SYNC_CREATE);
combo = gimp_drawable_combo_box_new (envmap_constrain, NULL);
combo = gimp_drawable_combo_box_new (envmap_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo), mapvals.envmap_id,
G_CALLBACK (envmap_combo_callback),
NULL);

View File

@ -1094,7 +1094,7 @@ create_box_page (void)
{
GtkWidget *combo;
combo = gimp_drawable_combo_box_new (box_constrain, NULL);
combo = gimp_drawable_combo_box_new (box_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
mapvals.boxmap_id[i],
G_CALLBACK (gimp_int_combo_box_get_active),
@ -1186,7 +1186,7 @@ create_cylinder_page (void)
GtkWidget *combo;
GtkWidget *label;
combo = gimp_drawable_combo_box_new (cylinder_constrain, NULL);
combo = gimp_drawable_combo_box_new (cylinder_constrain, NULL, NULL);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
mapvals.cylindermap_id[i],
G_CALLBACK (gimp_int_combo_box_get_active),

View File

@ -302,27 +302,27 @@ script_fu_interface (SFScript *script,
switch (arg->type)
{
case SF_IMAGE:
widget = gimp_image_combo_box_new (NULL, NULL);
widget = gimp_image_combo_box_new (NULL, NULL, NULL);
ID_ptr = &arg->value.sfa_image;
break;
case SF_DRAWABLE:
widget = gimp_drawable_combo_box_new (NULL, NULL);
widget = gimp_drawable_combo_box_new (NULL, NULL, NULL);
ID_ptr = &arg->value.sfa_drawable;
break;
case SF_LAYER:
widget = gimp_layer_combo_box_new (NULL, NULL);
widget = gimp_layer_combo_box_new (NULL, NULL, NULL);
ID_ptr = &arg->value.sfa_layer;
break;
case SF_CHANNEL:
widget = gimp_channel_combo_box_new (NULL, NULL);
widget = gimp_channel_combo_box_new (NULL, NULL, NULL);
ID_ptr = &arg->value.sfa_channel;
break;
case SF_VECTORS:
widget = gimp_vectors_combo_box_new (NULL, NULL);
widget = gimp_vectors_combo_box_new (NULL, NULL, NULL);
ID_ptr = &arg->value.sfa_vectors;
break;