[gimp/soc-2011-gimpunitentry] libgimpwidgets: port GimpPropWidgets to GimpUnitEntry



commit 6209c35c63a08acc6f2ef8a50a40406c1e0a6a86
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Sun Jul 3 20:59:54 2011 +0200

    libgimpwidgets: port GimpPropWidgets to GimpUnitEntry
    
    Finished porting of GimpPropWidgets to UnitEntry. The old functions are still there to maintain compatibility for the classes which have not been ported yet (namely GimpSizeBox).

 libgimpwidgets/gimppropwidgets.c |  176 +++++++++++++++++++++++++-------------
 libgimpwidgets/gimppropwidgets.h |   11 ++-
 libgimpwidgets/gimpwidgets.def   |    2 +
 3 files changed, 128 insertions(+), 61 deletions(-)
---
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index c94f121..c84d78c 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -2893,6 +2893,48 @@ gimp_prop_coordinates_new (GObject                   *config,
   return entry;
 }
 
+GObject *
+gimp_prop_coordinates_new2 (GObject                   *config,
+                           const gchar               *x_property_name,
+                           const gchar               *y_property_name,
+                           const gchar               *x_label_str,
+                           const gchar               *y_label_str,
+                           const gchar               *unit_property_name,
+                           gdouble                    xresolution,
+                           gdouble                    yresolution,
+                           gboolean                   has_chainbutton)
+{
+  GimpUnitEntryTable *UETable;
+  GtkWidget          *chainbutton = NULL;
+
+  UETable = 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);
+
+  if (has_chainbutton)
+    {
+      chainbutton = gimp_unit_entry_table_add_chainbutton  (UETable,
+                                                            x_property_name,
+                                                            y_property_name);
+    }
+
+  if (! gimp_prop_coordinates_connect2 (config,
+                                       x_property_name,
+                                       y_property_name,
+                                       unit_property_name,
+                                       G_OBJECT (UETable),
+                                       chainbutton,
+                                       xresolution,
+                                       yresolution))
+    {
+      gtk_widget_destroy (UETable->table);
+      return NULL;
+    }
+
+  return G_OBJECT (UETable);
+}
+
 gboolean
 gimp_prop_coordinates_connect (GObject     *config,
                                const gchar *x_property_name,
@@ -3052,31 +3094,31 @@ gimp_prop_coordinates_connect (GObject     *config,
   return TRUE;
 }
 
-gboolean        gimp_prop_coordinates_connect2     (GObject       *config,
+gboolean        gimp_prop_coordinates_connect2    (GObject       *config,
                                                    const gchar   *x_property_name,
                                                    const gchar   *y_property_name,
                                                    const gchar   *unit_property_name,
-                                                   GObject       *sizeentry,
+                                                   GObject       *unitentrytable,
                                                    GtkWidget     *chainbutton,
                                                    gdouble        xresolution,
                                                    gdouble        yresolution)
 {
-  GParamSpec *x_param_spec;
-  GParamSpec *y_param_spec;
-  GParamSpec *unit_param_spec;
-  gdouble     x_value, x_lower, x_upper;
-  gdouble     y_value, y_lower, y_upper;
-  GimpUnit    unit_value;
-  gdouble    *old_x_value;
-  gdouble    *old_y_value;
-  GimpUnit   *old_unit_value;
-  gboolean    chain_checked;
-  GimpUnitEntry *entry1, *entry2;
-  GimpUnitEntryTable *entry;
-
-  g_return_val_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (sizeentry), FALSE);
-  entry = GIMP_UNIT_ENTRY_TABLE (sizeentry);
-  g_return_val_if_fail (gimp_unit_entry_table_get_entry_count(entry) == 2, FALSE);
+  GParamSpec          *x_param_spec;
+  GParamSpec          *y_param_spec;
+  GParamSpec          *unit_param_spec;
+  gdouble             x_value, x_lower, x_upper;
+  gdouble             y_value, y_lower, y_upper;
+  GimpUnit            unit_value;
+  gdouble             *old_x_value;
+  gdouble             *old_y_value;
+  GimpUnit            *old_unit_value;
+  gboolean            chain_checked;
+  GimpUnitEntry       *entry1, *entry2;
+  GimpUnitEntryTable  *ue_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);
   g_return_val_if_fail (chainbutton == NULL ||
                         GIMP_IS_CHAIN_BUTTON (chainbutton), FALSE);
 
@@ -3111,8 +3153,10 @@ gboolean        gimp_prop_coordinates_connect2     (GObject       *config,
       unit_value      = GIMP_UNIT_INCH;
     }
 
-  entry1 = gimp_unit_entry_table_get_nth_entry (entry, 0);
-  entry2 = gimp_unit_entry_table_get_nth_entry (entry, 1);
+  entry1 = gimp_unit_entry_table_get_nth_entry (ue_table, 0);
+  entry2 = gimp_unit_entry_table_get_nth_entry (ue_table, 1);
+  g_return_val_if_fail (GIMP_IS_UNIT_ENTRY (entry1), FALSE);
+  g_return_val_if_fail (GIMP_IS_UNIT_ENTRY (entry2), FALSE);
 
   set_param_spec (NULL,
                   GTK_WIDGET (entry1),
@@ -3121,7 +3165,7 @@ gboolean        gimp_prop_coordinates_connect2     (GObject       *config,
                   GTK_WIDGET (entry2),
                   y_param_spec);
 
-  gimp_unit_entry_table_set_unit (entry, unit_value);
+  gimp_unit_entry_table_set_unit (ue_table, unit_value);
 
   gimp_unit_entry_set_resolution (entry1, xresolution);
   gimp_unit_entry_set_resolution (entry2, yresolution);
@@ -3129,32 +3173,32 @@ gboolean        gimp_prop_coordinates_connect2     (GObject       *config,
   chain_checked = (ABS (x_value - y_value) < 1);
 
   gimp_unit_entry_set_bounds (entry1,
-                              unit_value,
+                              GIMP_UNIT_PIXEL,
                               x_upper,
                               x_lower);
 
   gimp_unit_entry_set_bounds (entry2,
-                              unit_value,
+                              GIMP_UNIT_PIXEL,
                               y_upper,
                               y_lower);
 
   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 (entry), "gimp-config-param-spec-x",
+  g_object_set_data (G_OBJECT (ue_table), "gimp-config-param-spec-x",
                      x_param_spec);
-  g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-y",
+  g_object_set_data (G_OBJECT (ue_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 (entry), "old-x-value",
+  g_object_set_data_full (G_OBJECT (ue_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 (entry), "old-y-value",
+  g_object_set_data_full (G_OBJECT (ue_table), "old-y-value",
                           old_y_value,
                           (GDestroyNotify) g_free);
 
@@ -3163,38 +3207,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 (entry), "chainbutton", chainbutton);
+      g_object_set_data (G_OBJECT (ue_table), "chainbutton", chainbutton);
     }
 
-  g_signal_connect (entry, "changed",
+  g_signal_connect (ue_table, "changed",
                     G_CALLBACK (gimp_prop_coordinates_callback2),
                     config);
 
   connect_notify (config, x_property_name,
                   G_CALLBACK (gimp_prop_coordinates_notify_x2),
-                  entry);
+                  ue_table);
   connect_notify (config, y_property_name,
                   G_CALLBACK (gimp_prop_coordinates_notify_y2),
-                  entry);
+                  ue_table);
 
   if (unit_property_name)
     {
-      g_object_set_data (G_OBJECT (entry), "gimp-config-param-spec-unit",
+      g_object_set_data (G_OBJECT (ue_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 (entry), "old-unit-value",
+      g_object_set_data_full (G_OBJECT (ue_table), "old-unit-value",
                               old_unit_value,
                               (GDestroyNotify) g_free);
 
-      g_signal_connect (entry1, "changed",
+      g_signal_connect (ue_table, "changed",
                         G_CALLBACK (gimp_prop_coordinates_callback2),
                         config);
 
       connect_notify (config, unit_property_name,
                       G_CALLBACK (gimp_prop_coordinates_notify_unit2),
-                      entry);
+                      ue_table);
     }
 
   return TRUE;
@@ -3310,8 +3354,8 @@ gimp_prop_coordinates_callback (GimpSizeEntry *entry,
 
 static void
 gimp_prop_coordinates_callback2 (GimpUnitEntryTable *entry,
-                                 GimpUnitEntry  *e,
-                                 GObject       *config)
+                                 GimpUnitEntry      *e,
+                                 GObject            *config)
 {
   GParamSpec *x_param_spec;
   GParamSpec *y_param_spec;
@@ -3336,7 +3380,7 @@ gimp_prop_coordinates_callback2 (GimpUnitEntryTable *entry,
                                        "gimp-config-param-spec-unit");
 
   entry1 = gimp_unit_entry_table_get_nth_entry (entry, 0);
-  entry2 = gimp_unit_entry_table_get_nth_entry (entry, 1);                                        
+  entry2 = gimp_unit_entry_table_get_nth_entry (entry, 1);                                    
 
   x_value    = gimp_unit_entry_get_value_in_unit (entry1, GIMP_UNIT_PIXEL);
   y_value    = gimp_unit_entry_get_value_in_unit (entry2, GIMP_UNIT_PIXEL);
@@ -3545,8 +3589,12 @@ gimp_prop_coordinates_notify_unit2 (GObject             *config,
                                     GParamSpec          *param_spec,
                                     GimpUnitEntryTable  *entryTable)
 {
-  GimpUnit value;
-  GimpUnitEntry *entry = gimp_unit_entry_table_get_nth_entry (entryTable, 0);
+  GimpUnit       value;
+  GimpUnitEntry *entry;
+  
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (entryTable));
+  entry = gimp_unit_entry_table_get_nth_entry (entryTable, 0);
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY (entry));
 
   g_object_get (config,
                 param_spec->name, &value,
@@ -3567,12 +3615,16 @@ gimp_prop_coordinates_notify_unit2 (GObject             *config,
 }
 
 static void
-gimp_prop_coordinates_notify_x2 (GObject       *config,
-                                GParamSpec    *param_spec,
-                                GimpUnitEntryTable *entry)
+gimp_prop_coordinates_notify_x2 (GObject           *config,
+                                 GParamSpec         *param_spec,
+                                 GimpUnitEntryTable *entryTable)
 {
-  gdouble value;
-  GimpUnitEntry *entry1 = gimp_unit_entry_table_get_nth_entry (entry, 0);
+  gdouble        value;
+  GimpUnitEntry *entry;
+  
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (entryTable));
+  entry = gimp_unit_entry_table_get_nth_entry (entryTable, 0);
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY (entry));
 
   if (G_IS_PARAM_SPEC_INT (param_spec))
     {
@@ -3591,33 +3643,37 @@ gimp_prop_coordinates_notify_x2 (GObject       *config,
                     NULL);
     }
 
-  if (value != gimp_unit_entry_get_value_in_unit (entry1, GIMP_UNIT_PIXEL))
+  if (value != gimp_unit_entry_get_value_in_unit (entry, GIMP_UNIT_PIXEL))
     {
-      gdouble *old_x_value = g_object_get_data (G_OBJECT (entry),
+      gdouble *old_x_value = g_object_get_data (G_OBJECT (entryTable),
                                                 "old-x-value");
 
-      g_signal_handlers_block_by_func (entry,
+      g_signal_handlers_block_by_func (entryTable,
                                        gimp_prop_coordinates_callback2,
                                        config);
 
-      gimp_unit_entry_set_value_in_unit (entry1, value, GIMP_UNIT_PIXEL);
+      gimp_unit_entry_set_value_in_unit (entry, value, GIMP_UNIT_PIXEL);
 
       if (old_x_value)
         *old_x_value = value;
 
-      g_signal_handlers_unblock_by_func (entry,
+      g_signal_handlers_unblock_by_func (entryTable,
                                          gimp_prop_coordinates_callback2,
                                          config);
     }
 }
 
 static void
-gimp_prop_coordinates_notify_y2 (GObject       *config,
-                                GParamSpec    *param_spec,
-                                GimpUnitEntryTable *entry)
+gimp_prop_coordinates_notify_y2 (GObject           *config,
+                                GParamSpec         *param_spec,
+                                GimpUnitEntryTable *entryTable)
 {
-  gdouble value;
-  GimpUnitEntry *entry1 = gimp_unit_entry_table_get_nth_entry (entry, 1);
+  gdouble        value;
+  GimpUnitEntry *entry;
+  
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY_TABLE (entryTable));
+  entry = gimp_unit_entry_table_get_nth_entry (entryTable, 1);
+  g_return_if_fail (GIMP_IS_UNIT_ENTRY (entry));
 
   if (G_IS_PARAM_SPEC_INT (param_spec))
     {
@@ -3636,21 +3692,21 @@ gimp_prop_coordinates_notify_y2 (GObject       *config,
                     NULL);
     }
 
-  if (value != gimp_unit_entry_get_value_in_unit (entry1, GIMP_UNIT_PIXEL))
+  if (value != gimp_unit_entry_get_value_in_unit (entry, GIMP_UNIT_PIXEL))
     {
-      gdouble *old_y_value = g_object_get_data (G_OBJECT (entry),
+      gdouble *old_y_value = g_object_get_data (G_OBJECT (entryTable),
                                                 "old-y-value");
 
-      g_signal_handlers_block_by_func (entry,
+      g_signal_handlers_block_by_func (entryTable,
                                        gimp_prop_coordinates_callback2,
                                        config);
 
-      gimp_unit_entry_set_value_in_unit (entry1, value, GIMP_UNIT_PIXEL);
+      gimp_unit_entry_set_value_in_unit (entry, value, GIMP_UNIT_PIXEL);
 
       if (old_y_value)
         *old_y_value = value;
 
-      g_signal_handlers_unblock_by_func (entry,
+      g_signal_handlers_unblock_by_func (entryTable,
                                          gimp_prop_coordinates_callback2,
                                          config);
     }
diff --git a/libgimpwidgets/gimppropwidgets.h b/libgimpwidgets/gimppropwidgets.h
index 621a085..bc1aa10 100644
--- a/libgimpwidgets/gimppropwidgets.h
+++ b/libgimpwidgets/gimppropwidgets.h
@@ -177,7 +177,7 @@ GtkWidget     * gimp_prop_size_entry_new          (GObject       *config,
 
 /*  x,y: GParamInt, GParamDouble   unit: GimpParamUnit  */
 
-GtkWidget     * gimp_prop_coordinates_new         (GObject       *config,
+GtkWidget      * gimp_prop_coordinates_new         (GObject       *config,
                                                    const gchar   *x_property_name,
                                                    const gchar   *y_property_name,
                                                    const gchar   *unit_property_name,
@@ -186,6 +186,15 @@ GtkWidget     * gimp_prop_coordinates_new         (GObject       *config,
                                                    gdouble        xresolution,
                                                    gdouble        yresolution,
                                                    gboolean       has_chainbutton);
+GObject       * gimp_prop_coordinates_new2         (GObject       *config,
+                                                   const gchar   *x_property_name,
+                                                   const gchar   *y_property_name,
+                                                   const gchar   *x_label_str,
+                                                   const gchar   *y_label_str,
+                                                   const gchar   *unit_property_name,
+                                                   gdouble        xresolution,
+                                                   gdouble        yresolution,
+                                                   gboolean       has_chainbutton);                                                   
 gboolean        gimp_prop_coordinates_connect     (GObject       *config,
                                                    const gchar   *x_property_name,
                                                    const gchar   *y_property_name,
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index 87e9177..2105a9c 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -267,7 +267,9 @@ EXPORTS
 	gimp_prop_check_button_new
 	gimp_prop_color_area_new
 	gimp_prop_coordinates_connect
+	gimp_prop_coordinates_connect2
 	gimp_prop_coordinates_new
+	gimp_prop_coordinates_new2
 	gimp_prop_entry_new
 	gimp_prop_enum_check_button_new
 	gimp_prop_enum_combo_box_new



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