[gimp/soc-2011-gimpunitentry] GimpUnitEntries: make some setters var-arg methods



commit c25f9e4ac2ce510bf4ea13cf4d61eebc85f48f36
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Sat Aug 20 13:18:55 2011 +0200

    GimpUnitEntries: make some setters var-arg methods
    
    ...and some other refactoring

 app/dialogs/layer-options-dialog.c        |   25 +++---
 app/dialogs/offset-dialog.c               |   14 ++--
 app/dialogs/resize-dialog.c               |   27 ++++--
 app/dialogs/resolution-calibrate-dialog.c |   38 +++++----
 app/tools/gimprotatetool.c                |    8 +-
 app/widgets/gimpsizebox.c                 |   23 ++++--
 libgimpwidgets/gimpunitentries.c          |  141 +++++++++++++++++++----------
 libgimpwidgets/gimpunitentries.h          |   10 +--
 libgimpwidgets/test-unitentrygui.c        |    8 ++
 9 files changed, 182 insertions(+), 112 deletions(-)
---
diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c
index 38539a8..4d92520 100644
--- a/app/dialogs/layer-options-dialog.c
+++ b/app/dialogs/layer-options-dialog.c
@@ -133,20 +133,23 @@ layer_options_dialog_new (GimpImage    *image,
       gimp_image_get_resolution (image, &xres, &yres);
 
       /* the size unit-entries */
-      options->unit_entries = GIMP_UNIT_ENTRIES (gimp_unit_entries_new ());
+      options->unit_entries = gimp_unit_entries_new ();
       gimp_unit_entries_add_entry (options->unit_entries, GIMP_UNIT_ENTRIES_WIDTH, _("Width:"));
       gimp_unit_entries_add_entry (options->unit_entries, GIMP_UNIT_ENTRIES_HEIGHT, _("Height:"));
       
-      gimp_unit_entries_set_unit        (options->unit_entries, GIMP_UNIT_PIXEL);
-
-      gimp_unit_adjustment_set_resolution  (gimp_unit_entries_get_adjustment (options->unit_entries, GIMP_UNIT_ENTRIES_WIDTH),
-                                            xres);
-      gimp_unit_adjustment_set_resolution  (gimp_unit_entries_get_adjustment (options->unit_entries, GIMP_UNIT_ENTRIES_HEIGHT),
-                                            yres);
-
-      gimp_unit_entries_set_pixels  (options->unit_entries, GIMP_UNIT_ENTRIES_WIDTH, gimp_image_get_width  (image));
-      gimp_unit_entries_set_pixels  (options->unit_entries, GIMP_UNIT_ENTRIES_HEIGHT, gimp_image_get_height  (image));
-      gimp_unit_entries_set_bounds  (options->unit_entries, GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
+      gimp_unit_entries_set_unit (options->unit_entries, GIMP_UNIT_PIXEL);
+      gimp_unit_entries_set_resolution (options->unit_entries,
+                                        GIMP_UNIT_ENTRIES_WIDTH,  xres,
+                                        GIMP_UNIT_ENTRIES_HEIGHT, yres,
+                                        NULL);
+      gimp_unit_entries_set_pixels     (options->unit_entries,
+                                        GIMP_UNIT_ENTRIES_WIDTH,  (gdouble) gimp_image_get_width (image),
+                                        GIMP_UNIT_ENTRIES_HEIGHT, (gdouble) gimp_image_get_height (image),
+                                        NULL);
+      gimp_unit_entries_set_bounds     (options->unit_entries, GIMP_UNIT_PIXEL,
+                                        GIMP_UNIT_ENTRIES_WIDTH,  (gdouble) GIMP_MIN_IMAGE_SIZE, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                        GIMP_UNIT_ENTRIES_HEIGHT, (gdouble) GIMP_MIN_IMAGE_SIZE, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                        NULL);
 
       gtk_table_attach (GTK_TABLE (table), gimp_unit_entries_get_table (options->unit_entries), 0, 2, 1, 3,
                         GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
diff --git a/app/dialogs/offset-dialog.c b/app/dialogs/offset-dialog.c
index 9f1843f..50d4c50 100644
--- a/app/dialogs/offset-dialog.c
+++ b/app/dialogs/offset-dialog.c
@@ -234,10 +234,10 @@ offset_response (GtkWidget    *widget,
           gint          offset_y;
 
           offset_x =
-            RINT (gimp_unit_entries_get_pixels (GIMP_UNIT_ENTRIES (dialog->offset_entries),
+            RINT (gimp_unit_entries_get_pixels (dialog->offset_entries,
                                                 GIMP_UNIT_ENTRIES_OFFSET_X));
           offset_y =
-            RINT (gimp_unit_entries_get_pixels (GIMP_UNIT_ENTRIES (dialog->offset_entries),
+            RINT (gimp_unit_entries_get_pixels (dialog->offset_entries,
                                                 GIMP_UNIT_ENTRIES_OFFSET_Y));
 
           gimp_drawable_offset (drawable,
@@ -262,12 +262,10 @@ offset_halfheight_callback (GtkWidget    *widget,
     {
       GimpItem *item = GIMP_ITEM (gimp_image_get_active_drawable (image));
 
-      gimp_unit_entries_set_pixels (GIMP_UNIT_ENTRIES (dialog->offset_entries),
-                                    GIMP_UNIT_ENTRIES_OFFSET_X,
-                                    gimp_item_get_width (item) / 2);
-      gimp_unit_entries_set_pixels (GIMP_UNIT_ENTRIES (dialog->offset_entries),
-                                    GIMP_UNIT_ENTRIES_OFFSET_Y,
-                                    gimp_item_get_height (item) / 2);
+      gimp_unit_entries_set_pixels (dialog->offset_entries,
+                                    GIMP_UNIT_ENTRIES_OFFSET_X, (gdouble) (gimp_item_get_width (item) / 2),
+                                    GIMP_UNIT_ENTRIES_OFFSET_Y, (gdouble) (gimp_item_get_height (item) / 2),
+                                    NULL);
    }
 }
 
diff --git a/app/dialogs/resize-dialog.c b/app/dialogs/resize-dialog.c
index 0692129..21a2045 100644
--- a/app/dialogs/resize-dialog.c
+++ b/app/dialogs/resize-dialog.c
@@ -213,13 +213,16 @@ resize_dialog_new (GimpViewable       *viewable,
 
   gtk_box_pack_start (GTK_BOX (vbox), gimp_unit_entries_get_table (unit_entries), FALSE, FALSE, 0);
 
-  gimp_unit_adjustment_set_resolution (gimp_unit_entries_get_adjustment (unit_entries, GIMP_UNIT_ENTRIES_OFFSET_X), 
-                                       xres);
-  gimp_unit_adjustment_set_resolution (gimp_unit_entries_get_adjustment (unit_entries, GIMP_UNIT_ENTRIES_OFFSET_Y), 
-                                       yres);
+  gimp_unit_entries_set_resolution (unit_entries,
+                                    GIMP_UNIT_ENTRIES_OFFSET_X, xres,
+                                    GIMP_UNIT_ENTRIES_OFFSET_Y, yres,
+                                    NULL);
 
-  gimp_unit_entries_set_unit (unit_entries, GIMP_UNIT_PIXEL);
-  gimp_unit_entries_set_bounds (unit_entries, GIMP_UNIT_PIXEL, 0 , 0);
+  gimp_unit_entries_set_unit       (unit_entries, GIMP_UNIT_PIXEL);
+  gimp_unit_entries_set_bounds     (unit_entries, GIMP_UNIT_PIXEL, 
+                                    GIMP_UNIT_ENTRIES_OFFSET_X, 0.0, 0.0,
+                                    GIMP_UNIT_ENTRIES_OFFSET_Y, 0.0, 0.0,
+                                    NULL);
 
   g_signal_connect (unit_entries, "changed",
                     G_CALLBACK (offset_update),
@@ -430,8 +433,10 @@ offsets_changed (GtkWidget    *area,
                  gint          off_y,
                  ResizeDialog *private)
 {
-  gimp_unit_entries_set_pixels (private->offset_unit_entries, GIMP_UNIT_ENTRIES_OFFSET_X, off_x);
-  gimp_unit_entries_set_pixels (private->offset_unit_entries, GIMP_UNIT_ENTRIES_OFFSET_Y, off_y);
+  gimp_unit_entries_set_pixels (private->offset_unit_entries, 
+                                GIMP_UNIT_ENTRIES_OFFSET_X, (gdouble) off_x,
+                                GIMP_UNIT_ENTRIES_OFFSET_Y, (gdouble) off_y,
+                                NULL);
 }
 
 static void
@@ -445,8 +450,10 @@ offset_center_clicked (GtkWidget    *widget,
   off_x = resize_bound_off_x (private, (box->width  - private->old_width)  / 2);
   off_y = resize_bound_off_y (private, (box->height - private->old_height) / 2);
 
-  gimp_unit_entries_set_pixels (private->offset_unit_entries, GIMP_UNIT_ENTRIES_OFFSET_X, off_x);
-  gimp_unit_entries_set_pixels (private->offset_unit_entries, GIMP_UNIT_ENTRIES_OFFSET_Y, off_y);
+  gimp_unit_entries_set_pixels (private->offset_unit_entries, 
+                                GIMP_UNIT_ENTRIES_OFFSET_X, (gdouble) off_x,
+                                GIMP_UNIT_ENTRIES_OFFSET_Y, (gdouble) off_y,
+                                NULL);
 
   g_signal_emit_by_name (private->offset_unit_entries, "changed", 0);
 }
diff --git a/app/dialogs/resolution-calibrate-dialog.c b/app/dialogs/resolution-calibrate-dialog.c
index b3d8610..6973853 100644
--- a/app/dialogs/resolution-calibrate-dialog.c
+++ b/app/dialogs/resolution-calibrate-dialog.c
@@ -57,7 +57,6 @@ resolution_calibrate_dialog (GimpUnitEntries   *resolution_entries,
   GdkScreen           *screen;
   GdkRectangle         rect;
   gint                 monitor;
-  GimpUnitEntry       *horizontal_entry, *vertical_entry;
 
   g_return_if_fail (GIMP_IS_UNIT_ENTRIES (resolution_entries));
   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
@@ -144,19 +143,22 @@ resolution_calibrate_dialog (GimpUnitEntries   *resolution_entries,
   calibrate_yres =
     gimp_unit_entries_get_pixels (resolution_entries,  "monitor-yresolution");
 
-  calibrate_entries = 
-    GIMP_UNIT_ENTRIES (gimp_unit_entries_new ()); 
-  gimp_unit_entries_set_bounds (calibrate_entries, GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, 1);
+  calibrate_entries = gimp_unit_entries_new ();   
+  gimp_unit_entries_add_entry (calibrate_entries, "horizontal", _("Horizontal"));  
+  gimp_unit_entries_add_entry (calibrate_entries, "vertical", _("Vertical"));     
+  gimp_unit_entries_set_bounds     (calibrate_entries, GIMP_UNIT_PIXEL, 
+                                    "horizontal", 1.0, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                    "vertical",   1.0, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                    NULL);                  
+  gimp_unit_entries_set_resolution (calibrate_entries,
+                                    "horizontal", calibrate_xres,
+                                    "vertical",   calibrate_yres,
+                                    NULL);
+  gimp_unit_entries_set_pixels     (calibrate_entries,
+                                    "horizontal", (gdouble) ruler_width,
+                                    "vertical",   (gdouble) ruler_height,
+                                    NULL);                                 
   
-  horizontal_entry = 
-    GIMP_UNIT_ENTRY (gimp_unit_entries_add_entry (calibrate_entries, "horizontal", _("Horizontal")));  
-  vertical_entry = 
-    GIMP_UNIT_ENTRY (gimp_unit_entries_add_entry (calibrate_entries, "vertical", _("Vertical")));                       
-  gimp_unit_adjustment_set_resolution (gimp_unit_entry_get_adjustment (horizontal_entry), calibrate_xres);
-  gimp_unit_adjustment_set_resolution (gimp_unit_entry_get_adjustment (vertical_entry),   calibrate_yres);
-  gimp_unit_entry_set_pixels             (horizontal_entry, ruler_width);
-  gimp_unit_entry_set_pixels             (vertical_entry,   ruler_height);
-
   g_signal_connect (dialog, "destroy",
                     G_CALLBACK (gtk_widget_destroyed),
                     &calibrate_entries);
@@ -172,8 +174,8 @@ resolution_calibrate_dialog (GimpUnitEntries   *resolution_entries,
         GtkWidget *chain_button;
         gdouble    x, y;
 
-        x = gimp_unit_entry_get_pixels (horizontal_entry);
-        y = gimp_unit_entry_get_pixels (vertical_entry);
+        x = gimp_unit_entries_get_pixels (calibrate_entries, "horizontal");
+        y = gimp_unit_entries_get_pixels (calibrate_entries, "vertical");
 
         calibrate_xres = (gdouble) ruler_width  * calibrate_xres / x;
         calibrate_yres = (gdouble) ruler_height * calibrate_yres / y;
@@ -184,8 +186,10 @@ resolution_calibrate_dialog (GimpUnitEntries   *resolution_entries,
           gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chain_button),
                                         FALSE);
 
-        gimp_unit_entries_set_pixels (resolution_entries, "monitor-xresolution", calibrate_xres);
-        gimp_unit_entries_set_pixels (resolution_entries, "monitor-xresolution", calibrate_yres);
+        gimp_unit_entries_set_pixels (resolution_entries, 
+                                      "monitor-xresolution", calibrate_xres,
+                                      "monitor-yresolution", calibrate_yres,
+                                      NULL);
       }
 
     default:
diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c
index 2b88ae4..ff1cade 100644
--- a/app/tools/gimprotatetool.c
+++ b/app/tools/gimprotatetool.c
@@ -223,10 +223,10 @@ gimp_rotate_tool_dialog_update (GimpTransformTool *tr_tool)
                                    rotate_center_changed,
                                    tr_tool);
 
-  gimp_unit_entries_set_pixels (GIMP_UNIT_ENTRIES (rotate->unit_entries), "center_x",
-                                tr_tool->trans_info[CENTER_X]);
-  gimp_unit_entries_set_pixels (GIMP_UNIT_ENTRIES (rotate->unit_entries), "center_y",
-                                tr_tool->trans_info[CENTER_Y]);
+  gimp_unit_entries_set_pixels (rotate->unit_entries, 
+                                "center_x", (gdouble) tr_tool->trans_info[CENTER_X],
+                                "center_y", (gdouble) tr_tool->trans_info[CENTER_Y],
+                                NULL);
 
   g_signal_handlers_unblock_by_func (rotate->unit_entries,
                                      rotate_center_changed,
diff --git a/app/widgets/gimpsizebox.c b/app/widgets/gimpsizebox.c
index 454a00d..f5672a5 100644
--- a/app/widgets/gimpsizebox.c
+++ b/app/widgets/gimpsizebox.c
@@ -193,9 +193,14 @@ gimp_size_box_constructed (GObject *object)
                                     box->xresolution, box->yresolution,
                                     TRUE));
 
-  gimp_unit_entries_set_bounds (unit_entries, GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
-  gimp_unit_entries_set_pixels (unit_entries, GIMP_UNIT_ENTRIES_WIDTH, box->width);
-  gimp_unit_entries_set_pixels (unit_entries, GIMP_UNIT_ENTRIES_HEIGHT, box->height);
+  gimp_unit_entries_set_bounds (unit_entries, GIMP_UNIT_PIXEL, 
+                                GIMP_UNIT_ENTRIES_WIDTH,  (gdouble) GIMP_MIN_IMAGE_SIZE, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                GIMP_UNIT_ENTRIES_HEIGHT, (gdouble) GIMP_MIN_IMAGE_SIZE, (gdouble) GIMP_MAX_IMAGE_SIZE,
+                                NULL);
+  gimp_unit_entries_set_pixels (unit_entries,
+                                GIMP_UNIT_ENTRIES_WIDTH,  (gdouble) box->width,
+                                GIMP_UNIT_ENTRIES_HEIGHT, (gdouble) box->height,
+                                NULL);
 
   priv->chain_button = GIMP_CHAIN_BUTTON (gimp_unit_entries_get_chain_button (unit_entries));
 
@@ -236,8 +241,10 @@ gimp_size_box_constructed (GObject *object)
                                     TRUE));   
                                  
       gimp_unit_entries_set_mode   (unit_entries, GIMP_UNIT_ENTRY_MODE_RESOLUTION);                           
-      gimp_unit_entries_set_pixels (unit_entries, "xresolution", box->xresolution);
-      gimp_unit_entries_set_pixels (unit_entries, "xresolution", box->yresolution);                            
+      gimp_unit_entries_set_pixels (unit_entries, 
+                                    "xresolution", box->xresolution,
+                                    "yresolution", box->yresolution,
+                                    NULL);
 
       gtk_box_pack_start (GTK_BOX (hbox), gimp_unit_entries_get_table (unit_entries), FALSE, FALSE, 0);
       gtk_widget_show (gimp_unit_entries_get_table (unit_entries));
@@ -414,8 +421,10 @@ gimp_size_box_update_resolution (GimpSizeBox *box)
 
   if (priv->unit_entries)
     {
-      gimp_unit_entries_set_pixels (priv->unit_entries, GIMP_UNIT_ENTRIES_WIDTH, box->width);
-      gimp_unit_entries_set_pixels (priv->unit_entries, GIMP_UNIT_ENTRIES_HEIGHT, box->height);
+      gimp_unit_entries_set_pixels (priv->unit_entries, 
+                                    GIMP_UNIT_ENTRIES_WIDTH,  (gdouble) box->width,
+                                    GIMP_UNIT_ENTRIES_HEIGHT, (gdouble) box->height,
+                                    NULL);
     }
 
   if (priv->res_label)
diff --git a/libgimpwidgets/gimpunitentries.c b/libgimpwidgets/gimpunitentries.c
index 58d8e9e..4078253 100644
--- a/libgimpwidgets/gimpunitentries.c
+++ b/libgimpwidgets/gimpunitentries.c
@@ -35,8 +35,7 @@
 #define DEBUG(x) /* nothing */
 #endif
 
-#define UNIT_ENTRIES_LEFT_ATTACH  2
-#define UNIT_ENTRIES_RIGHT_ATTACH 3
+#define UNIT_ENTRIES_ENTRY_COLUMN  2
 
 enum
 {
@@ -51,6 +50,14 @@ typedef struct
   GHashTable *entries_store;
 } GimpUnitEntriesPrivate;
 
+typedef struct
+{
+  GtkWidget     *label;
+  GimpUnitEntry *entry1;
+  GimpUnitEntry *entry2;
+  GimpUnit       unit;
+} PreviewLabelData;
+
 #define GIMP_UNIT_ENTRIES_GET_PRIVATE(obj) \
   ((GimpUnitEntriesPrivate *) ((GimpUnitEntries *) (obj))->private)
 
@@ -72,7 +79,7 @@ gimp_unit_entries_init (GimpUnitEntries *entries)
 
   private = GIMP_UNIT_ENTRIES_GET_PRIVATE (entries);   
 
-  private->table          = gtk_table_new     (1, 1, FALSE);
+  private->table          = gtk_table_new     (0, 0, FALSE);
   private->entries_store  = g_hash_table_new  (g_str_hash, g_str_equal);
   private->chain_button   = NULL;
 }
@@ -128,16 +135,13 @@ gimp_unit_entries_add_entry (GimpUnitEntries *entries,
   gtk_table_get_size (GTK_TABLE (gimp_unit_entries_get_table (entries)), &bottom, NULL);
 
   /* position of the entry (leave one row/column empty for labels etc) */
-  left_attach   = UNIT_ENTRIES_LEFT_ATTACH,
-  right_attach  = UNIT_ENTRIES_RIGHT_ATTACH,
+  left_attach   = UNIT_ENTRIES_ENTRY_COLUMN,
+  right_attach  = left_attach + 1,
   top_attach    = bottom,
   bottom_attach = bottom + 1;
 
   /* remember position in table so that we later can place other widgets around it */
-  g_object_set_data (G_OBJECT (entry), "left_attach", GINT_TO_POINTER (left_attach));
-  g_object_set_data (G_OBJECT (entry), "right_attach", GINT_TO_POINTER (right_attach));
-  g_object_set_data (G_OBJECT (entry), "top_attach", GINT_TO_POINTER (top_attach));
-  g_object_set_data (G_OBJECT (entry), "bottom_attach", GINT_TO_POINTER (bottom_attach));
+  g_object_set_data (G_OBJECT (entry), "row", GINT_TO_POINTER (bottom_attach));
 
   /* add entry to table at position (1, count) */
   gtk_table_attach_defaults (GTK_TABLE (gimp_unit_entries_get_table (entries)),
@@ -187,13 +191,13 @@ gimp_unit_entries_add_preview_label (GimpUnitEntries *entries,
                                      const gchar     *id1,
                                      const gchar     *id2)
 {
-  GtkWidget     *label  = gtk_label_new("preview");
-  GimpUnitEntry *entry1 = gimp_unit_entries_get_entry (entries, id1);
-  GimpUnitEntry *entry2 = gimp_unit_entries_get_entry (entries, id2);
-  gint          left_attach, 
-                right_attach, 
-                top_attach, 
-                bottom_attach;
+  GtkWidget         *label  = gtk_label_new ("preview");
+  GimpUnitEntry     *entry1 = gimp_unit_entries_get_entry (entries, id1);
+  GimpUnitEntry     *entry2 = gimp_unit_entries_get_entry (entries, id2);
+  gint               left_attach, 
+                     right_attach, 
+                     top_attach, 
+                     bottom_attach;
 
   /* save unit */
   g_object_set_data (G_OBJECT (label), "unit", GINT_TO_POINTER (unit));
@@ -201,10 +205,10 @@ gimp_unit_entries_add_preview_label (GimpUnitEntries *entries,
   g_object_set_data (G_OBJECT (label), "entry1", (gpointer) entry1);
   g_object_set_data (G_OBJECT (label), "entry2", (gpointer) entry2);
 
-  /* get the position of the entries and set label accordingly */
-  left_attach   = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "left_attach"));
-  right_attach  = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "right_attach"));
-  top_attach    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "bottom_attach"));
+  /* place label below second entry */
+  left_attach   = UNIT_ENTRIES_ENTRY_COLUMN;
+  right_attach  = left_attach + 1;
+  top_attach    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "row"));
   bottom_attach = top_attach + 1;
 
   /* add label below unit entries */
@@ -244,17 +248,18 @@ gimp_unit_entries_add_chain_button  (GimpUnitEntries *entries,
   GimpUnitEntry           *entry1         = gimp_unit_entries_get_entry (entries, id1);
   GimpUnitEntry           *entry2         = gimp_unit_entries_get_entry (entries, id2);
 
-  /* retrieve position of entries */
-  gint right_attach  = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "right_attach"));
-  gint top_attach    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "top_attach"));
-  gint bottom_attach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "bottom_attach"));
+  /* place chain button right of entries */
+  gint left_attach   = UNIT_ENTRIES_ENTRY_COLUMN + 1;
+  gint right_attach  = left_attach + 1;
+  gint top_attach    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "row")) - 1;
+  gint bottom_attach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "row"));
 
   chain_button = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
 
   /* add chain_button to right of entries, spanning from the first to the second */
   gtk_table_attach (GTK_TABLE (gimp_unit_entries_get_table (entries)),
                     GTK_WIDGET (chain_button),
-                    right_attach, right_attach + 1,
+                    left_attach, right_attach,
                     top_attach, bottom_attach,
                     GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
@@ -272,17 +277,18 @@ GimpUnitEntry*
 gimp_unit_entries_get_entry (GimpUnitEntries *entries,
                              const gchar     *id)
 {
-  GimpUnitEntriesPrivate  *private = GIMP_UNIT_ENTRIES_GET_PRIVATE (entries);
-  GimpUnitEntry           *entry;
+  GimpUnitEntriesPrivate  *private        = GIMP_UNIT_ENTRIES_GET_PRIVATE (entries);
+  gpointer                *entry_pointer;
 
-  entry = GIMP_UNIT_ENTRY (g_hash_table_lookup (private->entries_store, id));
+  entry_pointer = g_hash_table_lookup (private->entries_store, id);
 
-  if (entry == NULL)
+  if (!GIMP_IS_UNIT_ENTRY (entry_pointer))
   {
     g_warning ("gimp_unit_entries_get_entry: entry with id '%s' does not exist", id);
+    return NULL;
   }
 
-  return entry;
+  return GIMP_UNIT_ENTRY (entry_pointer);
 }
 
 /* get UnitEntry by index */
@@ -409,17 +415,27 @@ gimp_unit_entries_set_unit (GimpUnitEntries *entries,
 /* sets the resolution of all entries */
 void 
 gimp_unit_entries_set_resolution (GimpUnitEntries *entries,
-                                  gdouble          res)
+                                  ...)
 {
   GimpUnitAdjustment *adj;
-  gint                i, count = gimp_unit_entries_get_entry_count (entries);
+  va_list             args;
+  gchar              *entry_name;
+  gdouble             resolution;
 
-  /* iterate over list of entries */
-  for (i = 0; i < count; i++) 
+  va_start (args, entries);
+
+  while ((entry_name = va_arg (args, gchar*)) != NULL)
   {
-    adj = gimp_unit_entries_get_nth_adjustment (entries, i);
-    gimp_unit_adjustment_set_resolution (adj, res);
+    adj = gimp_unit_entries_get_adjustment (entries, entry_name);
+
+    if (adj == NULL)
+      break;
+
+    resolution = va_arg (args, gdouble);
+    gimp_unit_adjustment_set_resolution (adj, resolution);
   }
+
+  va_end (args);
 }
 
 /* sets resolution mode for all entries */
@@ -457,18 +473,29 @@ gimp_unit_entries_set_activates_default (GimpUnitEntries *entries,
 void            
 gimp_unit_entries_set_bounds (GimpUnitEntries *entries, 
                               GimpUnit         unit, 
-                              gdouble          lower, 
-                              gdouble          upper)
+                              ...)
 {
-  GimpUnitEntry *entry;
-  gint           i, count = gimp_unit_entries_get_entry_count (entries);
+  GimpUnitAdjustment *adj;
+  va_list             args;
+  gchar              *entry_name;
+  gdouble             lower;
+  gdouble             upper;
 
-  /* iterate over list of entries */
-  for (i = 0; i < count; i++) 
+  va_start (args, unit);
+
+  while ((entry_name = va_arg (args, gchar*)))
   {
-    entry = gimp_unit_entries_get_nth_entry (entries, i);
-    gimp_unit_entry_set_bounds (entry, unit, lower, upper);
+    adj = gimp_unit_entries_get_adjustment (entries, entry_name);
+
+    if (adj == NULL)
+      break;
+
+    lower = va_arg (args, gdouble);
+    upper = va_arg (args, gdouble);
+    gimp_unit_adjustment_set_bounds (adj, unit, lower, upper);
   }
+
+  va_end (args);
 }                                  
 
 void 
@@ -496,14 +523,27 @@ gimp_unit_entries_get_chain_button  (GimpUnitEntries *entries)
 
 void            
 gimp_unit_entries_set_pixels (GimpUnitEntries *entries, 
-                              const gchar     *id,
-                              gdouble          value)
+                              ...)
 {
   GimpUnitAdjustment *adj;
+  va_list             args;
+  gchar              *entry_name;
+  gdouble             pixels;
 
-  adj = gimp_unit_entries_get_adjustment (entries, id);
+  va_start (args, entries);
 
-  gimp_unit_adjustment_set_value_in_unit (adj, value, GIMP_UNIT_PIXEL);
+  while ((entry_name = va_arg (args, gchar*)) != NULL)
+  {
+    adj = gimp_unit_entries_get_adjustment (entries, entry_name);
+
+    if (adj == NULL)
+      break;
+
+    pixels = va_arg (args, gdouble);
+    gimp_unit_adjustment_set_value_in_unit (adj, pixels, GIMP_UNIT_PIXEL);
+  }
+
+  va_end (args);
 }               
                    
 void            
@@ -526,6 +566,9 @@ gimp_unit_entries_get_adjustment (GimpUnitEntries *entries,
 
   entry = gimp_unit_entries_get_entry (entries, id);
 
+  if (entry == NULL)
+    return NULL;
+
   return gimp_unit_entry_get_adjustment (entry);
 }
 
@@ -538,4 +581,4 @@ gimp_unit_entries_get_nth_adjustment  (GimpUnitEntries *entries,
   entry = gimp_unit_entries_get_nth_entry (entries, index);
   
   return gimp_unit_entry_get_adjustment (entry);  
-}                       
+}       
diff --git a/libgimpwidgets/gimpunitentries.h b/libgimpwidgets/gimpunitentries.h
index f90abc2..3376557 100644
--- a/libgimpwidgets/gimpunitentries.h
+++ b/libgimpwidgets/gimpunitentries.h
@@ -93,18 +93,16 @@ GtkWidget*           gimp_unit_entries_get_chain_button      (GimpUnitEntries *e
 void                 gimp_unit_entries_set_unit              (GimpUnitEntries *entries, 
                                                               GimpUnit         unit);
 void                 gimp_unit_entries_set_resolution        (GimpUnitEntries *entries, 
-                                                              gdouble          res);
+                                                              ...);
 void                 gimp_unit_entries_set_mode              (GimpUnitEntries *entries, 
                                                               GimpUnitEntryMode mode);
 void                 gimp_unit_entries_set_activates_default (GimpUnitEntries *entries, 
-                                                              gboolean         setting);
+                                                              gboolean         setting);                                                                  
 void                 gimp_unit_entries_set_bounds            (GimpUnitEntries *entries, 
                                                               GimpUnit         unit, 
-                                                              gdouble          upper, 
-                                                              gdouble          lower);
+                                                              ...);                                                              
 void                 gimp_unit_entries_set_pixels            (GimpUnitEntries *entries, 
-                                                              const gchar     *id,
-                                                              gdouble          value);
+                                                              ...);
 void                 gimp_unit_entries_set_nth_pixels        (GimpUnitEntries *entries, 
                                                               gint             index,
                                                               gdouble          value);                                                                                                                          
diff --git a/libgimpwidgets/test-unitentrygui.c b/libgimpwidgets/test-unitentrygui.c
index d643d6f..d546972 100644
--- a/libgimpwidgets/test-unitentrygui.c
+++ b/libgimpwidgets/test-unitentrygui.c
@@ -52,6 +52,14 @@ create_interface(void)
   b = gimp_unit_entries_get_entry (entries, "height");
   gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (a), 20);
   gimp_unit_adjustment_set_value (gimp_unit_entry_get_adjustment (b), 20);
+  gimp_unit_entries_set_resolution (entries,
+                                    "width",  100.0,
+                                    "height", 100.0,
+                                    NULL);
+  gimp_unit_entries_set_bounds (entries, GIMP_UNIT_PIXEL,
+                                "width", 0.0, 1000.0,
+                                "height", 0.0, 2000.0,
+                                NULL);
 
   gtk_box_pack_start (GTK_BOX (vbox), gimp_unit_entries_get_table (entries), FALSE, TRUE, 0);
 



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