[gimp/soc-2011-gimpunitentry] GimpUnitEntry/Table: add a few convenience functions and minor code clean-up



commit 78bd6828207c63339ec55c7ca7c2f720faf926fa
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Mon Jul 11 17:18:06 2011 +0200

    GimpUnitEntry/Table: add a few convenience functions and minor code clean-up

 app/widgets/gimptemplateeditor.c    |    4 +-
 libgimpwidgets/gimppropwidgets.c    |   74 ++++++++++++++++++-----------------
 libgimpwidgets/gimpunitentry.c      |   13 ++++++
 libgimpwidgets/gimpunitentry.h      |    5 ++-
 libgimpwidgets/gimpunitentrytable.c |   67 +++++++++++++++++++++++++++++--
 libgimpwidgets/gimpunitentrytable.h |   16 +++++++-
 libgimpwidgets/gimpwidgets.def      |    9 ++++-
 libgimpwidgets/test-unitentrygui.c  |    2 +-
 8 files changed, 144 insertions(+), 46 deletions(-)
---
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index a834d10..1e423ba 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -301,8 +301,8 @@ gimp_template_editor_constructed (GObject *object)
                                   gimp_template_get_resolution_y (template));
 
   /*  the resolution chainbutton  */
-  chainbutton = gimp_unit_entry_table_add_chainbutton (private->resolution_entries,
-                                                       "xres", "yres");
+  chainbutton = gimp_unit_entry_table_add_chain_button (private->resolution_entries,
+                                                        "xres", "yres");
 
   gimp_prop_coordinates_connect2 (G_OBJECT (template),
                                  "xresolution", "yresolution",
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index c84d78c..d433723 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -2904,17 +2904,17 @@ gimp_prop_coordinates_new2 (GObject                   *config,
                            gdouble                    yresolution,
                            gboolean                   has_chainbutton)
 {
-  GimpUnitEntryTable *UETable;
+  GimpUnitEntryTable *unit_entry_table;
   GtkWidget          *chainbutton = NULL;
 
-  UETable = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
+  unit_entry_table = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
 
-  gimp_unit_entry_table_add_entry_defaults (UETable, x_property_name, x_label_str);
-  gimp_unit_entry_table_add_entry_defaults (UETable, y_property_name, y_label_str);
+  gimp_unit_entry_table_add_entry_defaults (unit_entry_table, x_property_name, x_label_str);
+  gimp_unit_entry_table_add_entry_defaults (unit_entry_table, y_property_name, y_label_str);
 
   if (has_chainbutton)
     {
-      chainbutton = gimp_unit_entry_table_add_chainbutton  (UETable,
+      chainbutton = gimp_unit_entry_table_add_chain_button  (unit_entry_table,
                                                             x_property_name,
                                                             y_property_name);
     }
@@ -2923,16 +2923,18 @@ gimp_prop_coordinates_new2 (GObject                   *config,
                                        x_property_name,
                                        y_property_name,
                                        unit_property_name,
-                                       G_OBJECT (UETable),
+                                       G_OBJECT (unit_entry_table),
                                        chainbutton,
                                        xresolution,
                                        yresolution))
     {
-      gtk_widget_destroy (UETable->table);
+      gtk_widget_destroy (unit_entry_table->table);
       return NULL;
     }
 
-  return G_OBJECT (UETable);
+  gimp_prop_coordinates_callback2 (unit_entry_table, NULL, config);
+
+  return G_OBJECT (unit_entry_table);
 }
 
 gboolean
@@ -3114,11 +3116,11 @@ gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
   GimpUnit            *old_unit_value;
   gboolean            chain_checked;
   GimpUnitEntry       *entry1, *entry2;
-  GimpUnitEntryTable  *ue_table;
+  GimpUnitEntryTable  *unit_entry_table;
 
   g_return_val_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (unitentrytable), FALSE);
-  ue_table = GIMP_UNIT_ENTRY_TABLE (unitentrytable);
-  g_return_val_if_fail (gimp_unit_entry_table_get_entry_count(ue_table) == 2, FALSE);
+  unit_entry_table = GIMP_UNIT_ENTRY_TABLE (unitentrytable);
+  g_return_val_if_fail (gimp_unit_entry_table_get_entry_count(unit_entry_table) == 2, FALSE);
   g_return_val_if_fail (chainbutton == NULL ||
                         GIMP_IS_CHAIN_BUTTON (chainbutton), FALSE);
 
@@ -3153,8 +3155,8 @@ gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
       unit_value      = GIMP_UNIT_INCH;
     }
 
-  entry1 = gimp_unit_entry_table_get_nth_entry (ue_table, 0);
-  entry2 = gimp_unit_entry_table_get_nth_entry (ue_table, 1);
+  entry1 = gimp_unit_entry_table_get_nth_entry (unit_entry_table, 0);
+  entry2 = gimp_unit_entry_table_get_nth_entry (unit_entry_table, 1);
   g_return_val_if_fail (GIMP_IS_UNIT_ENTRY (entry1), FALSE);
   g_return_val_if_fail (GIMP_IS_UNIT_ENTRY (entry2), FALSE);
 
@@ -3165,7 +3167,7 @@ gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
                   GTK_WIDGET (entry2),
                   y_param_spec);
 
-  gimp_unit_entry_table_set_unit (ue_table, unit_value);
+  gimp_unit_entry_table_set_unit (unit_entry_table, unit_value);
 
   gimp_unit_entry_set_resolution (entry1, xresolution);
   gimp_unit_entry_set_resolution (entry2, yresolution);
@@ -3185,20 +3187,20 @@ gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
   gimp_unit_entry_set_value_in_unit (entry1, x_value, GIMP_UNIT_PIXEL);
   gimp_unit_entry_set_value_in_unit (entry2, y_value, GIMP_UNIT_PIXEL);                                       
 
-  g_object_set_data (G_OBJECT (ue_table), "gimp-config-param-spec-x",
+  g_object_set_data (G_OBJECT (unit_entry_table), "gimp-config-param-spec-x",
                      x_param_spec);
-  g_object_set_data (G_OBJECT (ue_table), "gimp-config-param-spec-y",
+  g_object_set_data (G_OBJECT (unit_entry_table), "gimp-config-param-spec-y",
                      y_param_spec);
 
   old_x_value  = g_new0 (gdouble, 1);
   *old_x_value = x_value;
-  g_object_set_data_full (G_OBJECT (ue_table), "old-x-value",
+  g_object_set_data_full (G_OBJECT (unit_entry_table), "old-x-value",
                           old_x_value,
                           (GDestroyNotify) g_free);
 
   old_y_value  = g_new0 (gdouble, 1);
   *old_y_value = y_value;
-  g_object_set_data_full (G_OBJECT (ue_table), "old-y-value",
+  g_object_set_data_full (G_OBJECT (unit_entry_table), "old-y-value",
                           old_y_value,
                           (GDestroyNotify) g_free);
 
@@ -3207,38 +3209,38 @@ gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
       if (chain_checked)
         gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainbutton), TRUE);
 
-      g_object_set_data (G_OBJECT (ue_table), "chainbutton", chainbutton);
+      g_object_set_data (G_OBJECT (unit_entry_table), "chainbutton", chainbutton);
     }
 
-  g_signal_connect (ue_table, "changed",
+  g_signal_connect (unit_entry_table, "changed",
                     G_CALLBACK (gimp_prop_coordinates_callback2),
                     config);
 
   connect_notify (config, x_property_name,
                   G_CALLBACK (gimp_prop_coordinates_notify_x2),
-                  ue_table);
+                  unit_entry_table);
   connect_notify (config, y_property_name,
                   G_CALLBACK (gimp_prop_coordinates_notify_y2),
-                  ue_table);
+                  unit_entry_table);
 
   if (unit_property_name)
     {
-      g_object_set_data (G_OBJECT (ue_table), "gimp-config-param-spec-unit",
+      g_object_set_data (G_OBJECT (unit_entry_table), "gimp-config-param-spec-unit",
                          unit_param_spec);
 
       old_unit_value  = g_new0 (GimpUnit, 1);
       *old_unit_value = unit_value;
-      g_object_set_data_full (G_OBJECT (ue_table), "old-unit-value",
+      g_object_set_data_full (G_OBJECT (unit_entry_table), "old-unit-value",
                               old_unit_value,
                               (GDestroyNotify) g_free);
 
-      g_signal_connect (ue_table, "changed",
+      g_signal_connect (unit_entry_table, "changed",
                         G_CALLBACK (gimp_prop_coordinates_callback2),
                         config);
 
       connect_notify (config, unit_property_name,
                       G_CALLBACK (gimp_prop_coordinates_notify_unit2),
-                      ue_table);
+                      unit_entry_table);
     }
 
   return TRUE;
@@ -3357,16 +3359,16 @@ gimp_prop_coordinates_callback2 (GimpUnitEntryTable *entry,
                                  GimpUnitEntry      *e,
                                  GObject            *config)
 {
-  GParamSpec *x_param_spec;
-  GParamSpec *y_param_spec;
-  GParamSpec *unit_param_spec;
-  gdouble     x_value;
-  gdouble     y_value;
-  GimpUnit    unit_value;
-  gdouble    *old_x_value;
-  gdouble    *old_y_value;
-  GimpUnit   *old_unit_value;
-  gboolean    backwards;
+  GParamSpec    *x_param_spec;
+  GParamSpec    *y_param_spec;
+  GParamSpec    *unit_param_spec;
+  gdouble        x_value;
+  gdouble        y_value;
+  GimpUnit       unit_value;
+  gdouble       *old_x_value;
+  gdouble       *old_y_value;
+  GimpUnit      *old_unit_value;
+  gboolean       backwards;
   GimpUnitEntry *entry1, *entry2;
 
   x_param_spec = g_object_get_data (G_OBJECT (entry),
diff --git a/libgimpwidgets/gimpunitentry.c b/libgimpwidgets/gimpunitentry.c
index 1a23cd7..7767f12 100644
--- a/libgimpwidgets/gimpunitentry.c
+++ b/libgimpwidgets/gimpunitentry.c
@@ -335,6 +335,12 @@ gimp_unit_entry_get_value (GimpUnitEntry *entry)
 }
 
 gdouble
+gimp_unit_entry_get_pixels (GimpUnitEntry *entry)
+{
+  return gimp_unit_entry_get_value_in_unit (entry, GIMP_UNIT_PIXEL);
+}
+
+gdouble
 gimp_unit_entry_get_value_in_unit (GimpUnitEntry *entry, 
                                    GimpUnit       unit)
 {
@@ -369,6 +375,13 @@ gimp_unit_entry_set_bounds (GimpUnitEntry *entry,
 }
 
 void
+gimp_unit_entry_set_pixels (GimpUnitEntry      *entry,
+                            gdouble             value)
+{
+  gimp_unit_entry_set_value_in_unit (entry, value, GIMP_UNIT_PIXEL);
+}                           
+
+void
 gimp_unit_entry_set_mode (GimpUnitEntry     *entry,
                           GimpUnitEntryMode  mode)
 {
diff --git a/libgimpwidgets/gimpunitentry.h b/libgimpwidgets/gimpunitentry.h
index 39ed115..748acf8 100644
--- a/libgimpwidgets/gimpunitentry.h
+++ b/libgimpwidgets/gimpunitentry.h
@@ -72,6 +72,7 @@ GtkWidget *           gimp_unit_entry_new               (void);
 
 GimpUnitAdjustment *  gimp_unit_entry_get_adjustment    (GimpUnitEntry      *entry);
 gdouble               gimp_unit_entry_get_value         (GimpUnitEntry      *entry);
+gdouble               gimp_unit_entry_get_pixels        (GimpUnitEntry      *entry);
 gdouble               gimp_unit_entry_get_value_in_unit (GimpUnitEntry      *entry, 
                                                          GimpUnit            unit);
 GimpUnit              gimp_unit_entry_get_unit          (GimpUnitEntry      *entry);
@@ -90,7 +91,9 @@ void                  gimp_unit_entry_set_value         (GimpUnitEntry      *ent
                                                          gdouble             value);
 void                  gimp_unit_entry_set_value_in_unit (GimpUnitEntry      *entry, 
                                                          gdouble             value, 
-                                                         GimpUnit            unit);  
+                                                         GimpUnit            unit);
+void                  gimp_unit_entry_set_pixels        (GimpUnitEntry      *entry,
+                                                         gdouble             value);                                                           
                                                          
 void                  gimp_unit_entry_connect           (GimpUnitEntry      *entry, 
                                                          GimpUnitEntry      *target);                                                                                                               
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index dfe5dfb..cf8705f 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -48,7 +48,8 @@ gimp_unit_entry_table_init (GimpUnitEntryTable *table)
 {
    /* initialize our fields */
   table->table        = gtk_table_new     (1, 1, FALSE);
-  table->entries      = g_hash_table_new  (NULL, NULL);;
+  table->entries      = g_hash_table_new  (NULL, NULL);
+  table->chain_button = NULL;
   table->bottom       = 0;
   table->right        = 0;
 }
@@ -220,7 +221,7 @@ gimp_unit_entry_table_add_label (GimpUnitEntryTable *table,
 
 /* add chain button connecting the two given UnitEntries */
 GtkWidget* 
-gimp_unit_entry_table_add_chainbutton  (GimpUnitEntryTable *table,
+gimp_unit_entry_table_add_chain_button  (GimpUnitEntryTable *table,
                                         const char* id1,
                                         const char* id2)
 {
@@ -235,7 +236,7 @@ gimp_unit_entry_table_add_chainbutton  (GimpUnitEntryTable *table,
 
   chainButton = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
 
-  /* add chainbutton to right of entries, spanning from the first to the second */
+  /* add chain_button to right of entries, spanning from the first to the second */
   gtk_table_attach (GTK_TABLE (table->table),
                              GTK_WIDGET (chainButton),
                              rightAttach,
@@ -246,7 +247,9 @@ gimp_unit_entry_table_add_chainbutton  (GimpUnitEntryTable *table,
 
   gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (chainButton), TRUE);
 
-  gtk_widget_show (chainButton);                          
+  gtk_widget_show (chainButton);  
+  
+  table->chain_button = chainButton;                        
 
   return chainButton;
 }
@@ -356,6 +359,14 @@ gimp_unit_entry_table_get_pixels (GimpUnitEntryTable *table,
 {
   return gimp_unit_entry_table_get_value_in_unit (table, id, GIMP_UNIT_PIXEL);
 }
+
+gdouble         
+gimp_unit_entry_table_get_nth_pixels (GimpUnitEntryTable *table, 
+                                      gint               index)
+{
+  return gimp_unit_entry_get_pixels (gimp_unit_entry_table_get_nth_entry (table, index));
+}
+
 gdouble 
 gimp_unit_entry_table_get_value_in_unit (GimpUnitEntryTable *table,
                                          const gchar *id, 
@@ -430,6 +441,24 @@ gimp_unit_entry_table_set_activates_default (GimpUnitEntryTable *table,
     gtk_entry_set_activates_default (GTK_ENTRY (entry), setting);
   }
 }
+
+void            
+gimp_unit_entry_table_set_bounds (GimpUnitEntryTable *table, 
+                                  GimpUnit            unit, 
+                                  gdouble             upper, 
+                                  gdouble             lower)
+{
+  GimpUnitEntry *entry;
+  gint           i, count = gimp_unit_entry_table_get_entry_count (table);
+
+  /* iterate over list of entries */
+  for (i = 0; i < count; i++) 
+  {
+    entry = gimp_unit_entry_table_get_nth_entry (table, i);
+    gimp_unit_entry_set_bounds (entry, unit, upper, lower);
+  }
+}                                  
+
 void 
 gimp_unit_entry_table_grab_focus (GimpUnitEntryTable *table)
 {
@@ -441,3 +470,33 @@ gimp_unit_entry_table_get_table  (GimpUnitEntryTable *table)
 {
   return table->table;
 }
+
+GtkWidget*      
+gimp_unit_entry_table_get_chain_button  (GimpUnitEntryTable *table)
+{
+  return table->chain_button;
+}
+
+void            
+gimp_unit_entry_table_set_pixels (GimpUnitEntryTable *table, 
+                                  const gchar        *id,
+                                  gdouble             value)
+{
+  GimpUnitEntry *entry;
+
+  entry = gimp_unit_entry_table_get_entry (table, id);
+
+  gimp_unit_entry_set_value_in_unit (entry, value, GIMP_UNIT_PIXEL);
+}               
+                   
+void            
+gimp_unit_entry_table_set_nth_pixels (GimpUnitEntryTable *table, 
+                                      gint                index,
+                                      gdouble             value)
+{
+  GimpUnitEntry *entry;
+
+  entry = gimp_unit_entry_table_get_nth_entry (table, index);
+
+  gimp_unit_entry_set_value_in_unit (entry, value, GIMP_UNIT_PIXEL);
+}                                       
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 121e12e..212bc39 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -49,6 +49,7 @@ struct _GimpUnitEntryTable
 
   /* private */
   GtkWidget  *table;
+  GtkWidget  *chain_button;
   GHashTable *entries;
 
   /* dimensions of "sub-table" containing the actual entries */ 
@@ -78,7 +79,7 @@ void            gimp_unit_entry_table_add_label             (GimpUnitEntryTable
                                                              GimpUnit            unit, 
                                                              const char         *id1, 
                                                              const char         *id2);
-GtkWidget*      gimp_unit_entry_table_add_chainbutton       (GimpUnitEntryTable *table,
+GtkWidget*      gimp_unit_entry_table_add_chain_button      (GimpUnitEntryTable *table,
                                                              const char         *id1, 
                                                              const char         *id2);
 
@@ -89,10 +90,13 @@ GimpUnitEntry*  gimp_unit_entry_table_get_nth_entry         (GimpUnitEntryTable
 gint            gimp_unit_entry_table_get_entry_count       (GimpUnitEntryTable *table);
 gdouble         gimp_unit_entry_table_get_pixels            (GimpUnitEntryTable *table, 
                                                              const gchar        *id);
+gdouble         gimp_unit_entry_table_get_nth_pixels        (GimpUnitEntryTable *table, 
+                                                             gint               index);                                                             
 GtkWidget*      gimp_unit_entry_table_get_table             (GimpUnitEntryTable *table);                                                             
 gdouble         gimp_unit_entry_table_get_value_in_unit     (GimpUnitEntryTable *table,
                                                              const gchar        *id,
                                                              GimpUnit            unit);
+GtkWidget*      gimp_unit_entry_table_get_chain_button      (GimpUnitEntryTable *table);                                                              
 
 void            gimp_unit_entry_table_set_unit              (GimpUnitEntryTable *table, 
                                                              GimpUnit            unit);
@@ -102,6 +106,16 @@ void            gimp_unit_entry_table_set_mode              (GimpUnitEntryTable
                                                              GimpUnitEntryMode   mode);
 void            gimp_unit_entry_table_set_activates_default (GimpUnitEntryTable *table, 
                                                              gboolean            setting);
+void            gimp_unit_entry_table_set_bounds            (GimpUnitEntryTable *table, 
+                                                             GimpUnit            unit, 
+                                                             gdouble             upper, 
+                                                             gdouble             lower);
+void            gimp_unit_entry_table_set_pixels            (GimpUnitEntryTable *table, 
+                                                             const gchar        *id,
+                                                             gdouble             value);
+void            gimp_unit_entry_table_set_nth_pixels        (GimpUnitEntryTable *table, 
+                                                             gint                index,
+                                                             gdouble             value);                                                                                                                          
 
 void            gimp_unit_entry_table_grab_focus            (GimpUnitEntryTable *table);
 
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index c3b9294..0fcd14c 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -376,6 +376,7 @@ EXPORTS
 	gimp_unit_combo_box_set_active
 	gimp_unit_entry_connect
 	gimp_unit_entry_get_adjustment
+	gimp_unit_entry_get_pixels
 	gimp_unit_entry_get_type
 	gimp_unit_entry_get_unit
 	gimp_unit_entry_get_value
@@ -383,17 +384,20 @@ EXPORTS
 	gimp_unit_entry_new
 	gimp_unit_entry_set_bounds
 	gimp_unit_entry_set_mode
+	gimp_unit_entry_set_pixels
 	gimp_unit_entry_set_resolution
 	gimp_unit_entry_set_unit
 	gimp_unit_entry_set_value
 	gimp_unit_entry_set_value_in_unit
-	gimp_unit_entry_table_add_chainbutton
+	gimp_unit_entry_table_add_chain_button
 	gimp_unit_entry_table_add_entry
 	gimp_unit_entry_table_add_entry_defaults
 	gimp_unit_entry_table_add_label
+	gimp_unit_entry_table_get_chain_button
 	gimp_unit_entry_table_get_entry
 	gimp_unit_entry_table_get_entry_count
 	gimp_unit_entry_table_get_nth_entry
+	gimp_unit_entry_table_get_nth_pixels
 	gimp_unit_entry_table_get_pixels
 	gimp_unit_entry_table_get_table
 	gimp_unit_entry_table_get_type
@@ -401,7 +405,10 @@ EXPORTS
 	gimp_unit_entry_table_grab_focus
 	gimp_unit_entry_table_new
 	gimp_unit_entry_table_set_activates_default
+	gimp_unit_entry_table_set_bounds
 	gimp_unit_entry_table_set_mode
+	gimp_unit_entry_table_set_nth_pixels
+	gimp_unit_entry_table_set_pixels
 	gimp_unit_entry_table_set_resolution
 	gimp_unit_entry_table_set_unit
 	gimp_unit_menu_get_pixel_digits
diff --git a/libgimpwidgets/test-unitentrygui.c b/libgimpwidgets/test-unitentrygui.c
index 0f8aaa0..fe1b5f6 100644
--- a/libgimpwidgets/test-unitentrygui.c
+++ b/libgimpwidgets/test-unitentrygui.c
@@ -45,7 +45,7 @@ create_interface(void)
   gimp_unit_entry_table_add_entry_defaults (entryTable, "height", "Height");
   gimp_unit_entry_table_add_label (entryTable, GIMP_UNIT_PIXEL, "width", "height");
 
-  gimp_unit_entry_table_add_chainbutton (entryTable, "width", "height");
+  gimp_unit_entry_table_add_chain_button (entryTable, "width", "height");
 
   /* set some default values */
   a = gimp_unit_entry_table_get_entry (entryTable, "width");



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