[gimp] libgimpwidgets: change gimp_int_store_new()'s signature



commit e80c90e17defa4a6a0a3100bcf976d1d30031d71
Author: Michael Natterer <mitch gimp org>
Date:   Tue Sep 24 00:16:55 2019 +0200

    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.

 app/widgets/gimpsymmetryeditor.c |  2 +-
 libgimpwidgets/gimpintcombobox.c | 25 +++++-----------
 libgimpwidgets/gimpintstore.c    | 61 ++++++++++++++++++++++++++++++++++++++--
 libgimpwidgets/gimpintstore.h    |  7 ++++-
 libgimpwidgets/gimpwidgets.def   |  1 +
 5 files changed, 74 insertions(+), 22 deletions(-)
---
diff --git a/app/widgets/gimpsymmetryeditor.c b/app/widgets/gimpsymmetryeditor.c
index 64c90f6857..934b539be4 100644
--- a/app/widgets/gimpsymmetryeditor.c
+++ b/app/widgets/gimpsymmetryeditor.c
@@ -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 ();
diff --git a/libgimpwidgets/gimpintcombobox.c b/libgimpwidgets/gimpintcombobox.c
index bf7819a389..c77daccee1 100644
--- a/libgimpwidgets/gimpintcombobox.c
+++ b/libgimpwidgets/gimpintcombobox.c
@@ -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;
 }
diff --git a/libgimpwidgets/gimpintstore.c b/libgimpwidgets/gimpintstore.c
index 45bd0ca7ea..627db640e9 100644
--- a/libgimpwidgets/gimpintstore.c
+++ b/libgimpwidgets/gimpintstore.c
@@ -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;
 }
 
 /**
diff --git a/libgimpwidgets/gimpintstore.h b/libgimpwidgets/gimpintstore.h
index 190460e1f0..0456b4005b 100644
--- a/libgimpwidgets/gimpintstore.h
+++ b/libgimpwidgets/gimpintstore.h
@@ -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,
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index 3d1ffb8f30..78643cd54f 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]