[gimp/soc-2011-gimpunitentry] GimpUnitEntryTable: add "changed" signal



commit d846a7cdd444502505461558127018b509b04a42
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Sun Jun 19 17:13:54 2011 +0200

    GimpUnitEntryTable: add "changed" signal
    
    "value-changed" signal is replaced by "changed" signal, which is emitted not only when the value of an entry is changed, but also the resolution

 libgimpwidgets/gimpunitadjustment.c |   20 ++++++-------
 libgimpwidgets/gimpunitentrytable.c |   51 ++++++++++++++++++++++++-----------
 libgimpwidgets/gimpunitentrytable.h |    5 ++-
 libgimpwidgets/gimpwidgets.def      |    1 +
 4 files changed, 48 insertions(+), 29 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitadjustment.c b/libgimpwidgets/gimpunitadjustment.c
index 7fa8493..7a3be8c 100644
--- a/libgimpwidgets/gimpunitadjustment.c
+++ b/libgimpwidgets/gimpunitadjustment.c
@@ -51,7 +51,7 @@ G_DEFINE_TYPE (GimpUnitAdjustment, gimp_unit_adjustment, GTK_TYPE_ADJUSTMENT);
 /* converts from one current unit to another */
 static void gimp_unit_adjustment_convert_unit (GimpUnitAdjustment *adj, GimpUnit unit);
 /* handler for unit-changed signal from other entries */
-static void unit_changed_handler (GimpUnitAdjustment *adj, GimpUnit unit, gpointer userData);
+static void unit_changed_handler (GimpUnitAdjustment *adj, gpointer userData);
 
 
 static void
@@ -76,10 +76,9 @@ gimp_unit_adjustment_class_init (GimpUnitAdjustmentClass *klass)
                                               0,
                                               NULL, 
                                               NULL,
-                                              g_cclosure_marshal_VOID__INT,
+                                              g_cclosure_marshal_VOID__VOID,
                                               G_TYPE_NONE, 
-                                              1, 
-                                              G_TYPE_INT);
+                                              0);
 
   klass->sig_resolution_changed_id = g_signal_new ("resolution-changed",
                                                     GIMP_TYPE_UNIT_ADJUSTMENT,
@@ -87,10 +86,9 @@ gimp_unit_adjustment_class_init (GimpUnitAdjustmentClass *klass)
                                                     0,
                                                     NULL, 
                                                     NULL,
-                                                    g_cclosure_marshal_VOID__INT,
+                                                    g_cclosure_marshal_VOID__VOID,
                                                     G_TYPE_NONE, 
-                                                    1, 
-                                                    G_TYPE_DOUBLE);
+                                                    0);
 }
 
 GObject *
@@ -100,9 +98,10 @@ gimp_unit_adjustment_new (void)
 }
 
 static void
-unit_changed_handler (GimpUnitAdjustment *adj, GimpUnit unit, gpointer userData)
+unit_changed_handler (GimpUnitAdjustment *adj, gpointer userData)
 {
   GimpUnitAdjustment *adjustment = GIMP_UNIT_ADJUSTMENT (userData);
+  GimpUnit           unit        = gimp_unit_adjustment_get_unit (adj);
 
   gimp_unit_adjustment_convert_unit (adjustment, unit);
 }
@@ -168,7 +167,7 @@ gimp_unit_adjustment_set_unit (GimpUnitAdjustment *adj, GimpUnit unit)
   gimp_unit_adjustment_convert_unit (adj, unit);
 
   /* emit "unit-changed" */
-  g_signal_emit(adj, GIMP_UNIT_ADJUSTMENT_GET_CLASS(adj)->sig_unit_changed_id, 0, unit);
+  g_signal_emit(adj, GIMP_UNIT_ADJUSTMENT_GET_CLASS(adj)->sig_unit_changed_id, 0);
 }
 
 /* sets/gets the value of an adjustment */
@@ -218,8 +217,7 @@ gimp_unit_adjustment_set_resolution (GimpUnitAdjustment *adj, gdouble res)
     /* emit "resolution-changed" */
     g_signal_emit(adj, 
                   GIMP_UNIT_ADJUSTMENT_GET_CLASS(adj)->sig_resolution_changed_id,
-                  0, 
-                  res);
+                  0);
   }
 }
 gdouble 
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index 01871c5..26d53c9 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -41,7 +41,7 @@ G_DEFINE_TYPE (GimpUnitEntryTable, gimp_unit_entry_table, G_TYPE_OBJECT);
  * signal handler
  **/
 static void label_updater     (GtkAdjustment *adj, gpointer userData);
-static void on_value_changed  (GtkAdjustment *adj, gpointer userData);
+static void on_entry_changed  (GtkAdjustment *adj, gpointer userData);
 
 static void
 gimp_unit_entry_table_init (GimpUnitEntryTable *table)
@@ -55,16 +55,16 @@ gimp_unit_entry_table_init (GimpUnitEntryTable *table)
 static void
 gimp_unit_entry_table_class_init (GimpUnitEntryTableClass *klass)
 {
-  klass->sig_value_changed_id = g_signal_new ("value-changed",
-                                              GIMP_TYPE_UNIT_ENTRY_TABLE,
-                                              G_SIGNAL_RUN_LAST,
-                                              0,
-                                              NULL, 
-                                              NULL,
-                                              g_cclosure_marshal_VOID__OBJECT,
-                                              G_TYPE_NONE, 
-                                              1, 
-                                              G_TYPE_OBJECT);
+  klass->sig_changed_id = g_signal_new ("changed",
+                                        GIMP_TYPE_UNIT_ENTRY_TABLE,
+                                        G_SIGNAL_RUN_LAST,
+                                        0,
+                                        NULL, 
+                                        NULL,
+                                        g_cclosure_marshal_VOID__OBJECT,
+                                        G_TYPE_NONE, 
+                                        1, 
+                                        G_TYPE_OBJECT);
 }
 
 GObject*
@@ -119,6 +119,7 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
                       leftAttach-1 , leftAttach, topAttach, bottomAttach,
                       GTK_SHRINK, GTK_EXPAND | GTK_FILL,
                       10, 0);
+    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   }
 
   /* connect entry to others */
@@ -131,7 +132,9 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
   
   /* connect to ourselves */
   g_signal_connect (gimp_unit_entry_get_adjustment (entry), "value-changed",
-                    G_CALLBACK (on_value_changed), (gpointer) table);
+                    G_CALLBACK (on_entry_changed), (gpointer) table);
+  g_signal_connect (gimp_unit_entry_get_adjustment (entry), "resolution-changed",
+                    G_CALLBACK (on_entry_changed), (gpointer) table);                 
 
   gtk_widget_show_all (table->table); 
 
@@ -279,9 +282,9 @@ void label_updater (GtkAdjustment *adj, gpointer userData)
   gtk_label_set_text (label, str);
 }
 
-/* signal handler for value changed signal of one of our entries/adjustments */
+/* signal handler for signals of one of our entries/adjustments */
 static 
-void on_value_changed  (GtkAdjustment *adj, gpointer userData)
+void on_entry_changed  (GtkAdjustment *adj, gpointer userData)
 {
   GimpUnitEntryTable *table = GIMP_UNIT_ENTRY_TABLE (userData);
   GimpUnitEntry *entry;
@@ -295,8 +298,8 @@ void on_value_changed  (GtkAdjustment *adj, gpointer userData)
       i = count;
   }
 
-  /* emit "value-changed" */
-  g_signal_emit(table, GIMP_UNIT_ENTRY_TABLE_GET_CLASS(table)->sig_value_changed_id, 0, entry);
+  /* emit "changed" */
+  g_signal_emit(table, GIMP_UNIT_ENTRY_TABLE_GET_CLASS(table)->sig_changed_id, 0, entry);
 }
 
 /* get count of attached unit entries */
@@ -335,3 +338,19 @@ gimp_unit_entry_table_set_resolution (GimpUnitEntryTable *table, gdouble res)
     gimp_unit_entry_set_resolution (entry, res);
   }
 }
+
+/* sets resolution mode for all entries */
+void 
+gimp_unit_entry_table_set_res_mode (GimpUnitEntryTable *table,
+                                    gboolean enable)
+{
+  GimpUnitEntry *entry;
+  gint i, count = g_list_length (table->entries);
+
+  /* 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_res_mode (entry, enable);
+  }
+}
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 5b26fb0..f055475 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -59,7 +59,7 @@ struct _GimpUnitEntryTableClass
   GObjectClass parent_class;
 
   /* signals */
-  guint sig_value_changed_id;
+  guint sig_changed_id;
 };
 
 /**
@@ -85,7 +85,8 @@ gint gimp_unit_entry_table_get_entry_count (GimpUnitEntryTable *table);
 void gimp_unit_entry_table_set_unit (GimpUnitEntryTable *table, GimpUnit unit);
 /* sets the resolution of all entries */
 void gimp_unit_entry_table_set_resolution (GimpUnitEntryTable *table, gdouble res);
-
+/* sets resolution mode for all entries */
+void gimp_unit_entry_table_set_res_mode (GimpUnitEntryTable *table, gboolean enable);
 G_END_DECLS
 
 #endif /*__GIMP_UNIT_ENTRY_TABLE_H__*/
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index bc97347..493cd30 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -395,6 +395,7 @@ EXPORTS
 	gimp_unit_entry_table_get_type
 	gimp_unit_entry_table_new
 	gimp_unit_entry_table_set_resolution
+	gimp_unit_entry_table_set_res_mode
 	gimp_unit_entry_table_set_unit
 	gimp_unit_menu_get_pixel_digits
 	gimp_unit_menu_get_type



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