Commit e80c90e1 authored by Michael Natterer's avatar Michael Natterer 😴

libgimpwidgets: change gimp_int_store_new()'s signature

to match gimp_int_combo_box_new(), and add gimp_int_store_new_valist().

Move the va_list of (name, value) parsing code to
gimp_int_store_new_valist() and use it from
gimp_int_combo_box_new_valist().

This makes the entire GimpIntStore/GimpIntComboBox stuff useable much
more generically for the price of an incompatible change of a public
function that is used exactly once outside of libgimpwidgets.
parent f3eef8fe
......@@ -138,7 +138,7 @@ gimp_symmetry_editor_set_image (GimpImageEditor *image_editor,
GList *sym_iter;
GimpSymmetry *symmetry;
store = gimp_int_store_new ();
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
/* The menu of available symmetries. */
syms = gimp_image_symmetry_list ();
......
......@@ -158,7 +158,7 @@ gimp_int_combo_box_init (GimpIntComboBox *combo_box)
combo_box->priv = priv = gimp_int_combo_box_get_instance_private (combo_box);
store = gimp_int_store_new ();
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
g_object_unref (store);
......@@ -292,7 +292,7 @@ gimp_int_combo_box_new (const gchar *first_label,
* @values: a va_list with more values
*
* A variant of gimp_int_combo_box_new() that takes a va_list of
* label/value pairs. Probably only useful for language bindings.
* label/value pairs.
*
* Returns: a new #GimpIntComboBox.
*
......@@ -305,25 +305,14 @@ gimp_int_combo_box_new_valist (const gchar *first_label,
{
GtkWidget *combo_box;
GtkListStore *store;
const gchar *label;
gint value;
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL);
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
store = gimp_int_store_new_valist (first_label, first_value, values);
for (label = first_label, value = first_value;
label;
label = va_arg (values, const gchar *), value = va_arg (values, gint))
{
GtkTreeIter iter = { 0, };
combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX,
"model", store,
NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, value,
GIMP_INT_STORE_LABEL, label,
-1);
}
g_object_unref (store);
return combo_box;
}
......
......@@ -260,19 +260,76 @@ gimp_int_store_add_empty (GimpIntStore *store)
/**
* gimp_int_store_new:
* @first_label: the label of the first item
* @first_value: the value of the first item
* @...: a %NULL terminated list of more label, value pairs
*
* Creates a #GtkListStore with a number of useful columns.
* #GimpIntStore is especially useful if the items you want to store
* are identified using an integer value.
*
* If you need to construct an empty #GimpIntStore, it's best to use
* g_object_new (GIMP_TYPE_INT_STORE, NULL).
*
* Returns: a new #GimpIntStore.
*
* Since: 2.2
**/
GtkListStore *
gimp_int_store_new (void)
gimp_int_store_new (const gchar *first_label,
gint first_value,
...)
{
GtkListStore *store;
va_list args;
va_start (args, first_value);
store = gimp_int_store_new_valist (first_label, first_value, args);
va_end (args);
return store;
}
/**
* gimp_int_store_new_valist:
* @first_label: the label of the first item
* @first_value: the value of the first item
* @values: a va_list with more values
*
* A variant of gimp_int_store_new() that takes a va_list of
* label/value pairs.
*
* Returns: a new #GimpIntStore.
*
* Since: 3.0
**/
GtkListStore *
gimp_int_store_new_valist (const gchar *first_label,
gint first_value,
va_list values)
{
return g_object_new (GIMP_TYPE_INT_STORE, NULL);
GtkListStore *store;
const gchar *label;
gint value;
store = g_object_new (GIMP_TYPE_INT_STORE, NULL);
for (label = first_label, value = first_value;
label;
label = va_arg (values, const gchar *), value = va_arg (values, gint))
{
GtkTreeIter iter = { 0, };
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
GIMP_INT_STORE_VALUE, value,
GIMP_INT_STORE_LABEL, label,
-1);
}
return store;
}
/**
......
......@@ -89,7 +89,12 @@ struct _GimpIntStoreClass
GType gimp_int_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_int_store_new (void);
GtkListStore * gimp_int_store_new (const gchar *first_label,
gint first_value,
...) G_GNUC_NULL_TERMINATED;
GtkListStore * gimp_int_store_new_valist (const gchar *first_label,
gint first_value,
va_list values);
gboolean gimp_int_store_lookup_by_value (GtkTreeModel *model,
gint value,
......
......@@ -223,6 +223,7 @@ EXPORTS
gimp_int_store_lookup_by_user_data
gimp_int_store_lookup_by_value
gimp_int_store_new
gimp_int_store_new_valist
gimp_label_set_attributes
gimp_memsize_entry_get_spinbutton
gimp_memsize_entry_get_type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment