[gimp/soc-2011-gimpunitentry: 22/68] GimpUnitEntryTable: "value-changed" signal added



commit 932a75e2012683d3279f1b1b48b9a926d412e48e
Author: Enrico Schröder <enni schroeder gmail com>
Date:   Thu Jun 16 13:39:45 2011 +0200

    GimpUnitEntryTable: "value-changed" signal added
    
    added a value-changed signal which is emitted whenever one of the tables entries changes its value

 libgimpwidgets/gimpunitentrytable.c |   84 +++++++++++++++++++++++++++++++++-
 libgimpwidgets/gimpunitentrytable.h |    9 ++++
 2 files changed, 90 insertions(+), 3 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index 004504f..67ca71d 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -40,7 +40,8 @@ G_DEFINE_TYPE (GimpUnitEntryTable, gimp_unit_entry_table, G_TYPE_OBJECT);
 /**
  * signal handler
  **/
-static void label_updater (GtkAdjustment *adj, gpointer userData);
+static void label_updater     (GtkAdjustment *adj, gpointer userData);
+static void on_value_changed  (GtkAdjustment *adj, gpointer userData);
 
 static void
 gimp_unit_entry_table_init (GimpUnitEntryTable *table)
@@ -52,8 +53,18 @@ gimp_unit_entry_table_init (GimpUnitEntryTable *table)
 }
 
 static void
-gimp_unit_entry_table_class_init (GimpUnitEntryTableClass *class)
+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);
 }
 
 GObject*
@@ -118,6 +129,10 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
     gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry2), GIMP_UNIT_ENTRY (entry));
   }
   
+  /* connect to ourselves */
+  g_signal_connect (gimp_unit_entry_get_adjustment (entry), "value-changed",
+                    G_CALLBACK (on_value_changed), (gpointer) table);
+
   gtk_widget_show_all (table->table); 
 
   table->entries = g_list_append (table->entries, (gpointer) entry);
@@ -154,9 +169,15 @@ gimp_unit_entry_table_add_label (GimpUnitEntryTable *table,
                     label,
                     leftAttach, rightAttach, 
                     topAttach, bottomAttach,
-                    GTK_SHRINK, GTK_EXPAND | GTK_FILL,
+                    GTK_FILL, GTK_SHRINK,
                     10, 0);
 
+  /* set alignment */
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
+  /*gimp_label_set_attributes (GTK_LABEL (label),
+                             PANGO_ATTR_SCALE,  PANGO_SCALE_SMALL,
+                             -1);*/
+
   table->bottom++;
 
   gtk_widget_show (GTK_WIDGET (label));
@@ -257,3 +278,60 @@ 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 */
+static 
+void on_value_changed  (GtkAdjustment *adj, gpointer userData)
+{
+  GimpUnitEntryTable *table = GIMP_UNIT_ENTRY_TABLE (userData);
+  GimpUnitEntry *entry;
+  gint i, count = g_list_length (table->entries);
+
+  /* find corresponding entry */
+  for (i = 0; i < count; i++) 
+  {
+    entry = gimp_unit_entry_table_get_nth_entry (table, i);
+    if (gimp_unit_entry_get_adjustment (entry) == GIMP_UNIT_ADJUSTMENT (adj))
+      i = count;
+  }
+
+  /* emit "value-changed" */
+  g_signal_emit(table, GIMP_UNIT_ENTRY_TABLE_GET_CLASS(table)->sig_value_changed_id, 0, entry);
+}
+
+/* get count of attached unit entries */
+gint
+gimp_unit_entry_table_get_entry_count (GimpUnitEntryTable *table)
+{
+  return g_list_length (table->entries);
+}
+
+/* sets the unit of all entries */
+void 
+gimp_unit_entry_table_set_unit (GimpUnitEntryTable *table, GimpUnit unit)
+{
+  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_unit (entry, unit);
+  }
+}
+
+/* sets the resolution of all entries */
+void 
+gimp_unit_entry_table_set_resolution (GimpUnitEntryTable *table, gdouble res)
+{
+  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_resolution (entry, res);
+  }
+}
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 2f7f0f9..6db56b8 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -57,6 +57,9 @@ struct _GimpUnitEntryTable
 struct _GimpUnitEntryTableClass
 {
   GObjectClass parent_class;
+
+  /* signals */
+  guint sig_value_changed_id;
 };
 
 /**
@@ -76,6 +79,12 @@ GtkWidget* gimp_unit_entry_table_add_chain_button (GimpUnitEntryTable *table, co
 GimpUnitEntry* gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table, const gchar* id);
 /* get UnitEntry by index */
 GimpUnitEntry* gimp_unit_entry_table_get_nth_entry (GimpUnitEntryTable *table, gint index);
+/* get count of attached unit entries */
+gint gimp_unit_entry_table_get_entry_count (GimpUnitEntryTable *table);
+/* sets the unit of all entries */
+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);
 
 G_END_DECLS
 


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