[gimp/soc-2011-gimpunitentry: 32/68] GimpUnitEntryTable: add functionality to set position where to add a new entry



commit 87028388348322b708872b65ff35dcdacccbda9c
Author: Enrico Schröder <enni schroeder gmail com>
Date:   Sun Jul 3 20:50:54 2011 +0200

    GimpUnitEntryTable: add functionality to set position where to add a new entry
    
    add_entry() now takes x,y coordinates where to add the new entry. Use add_entry_defaults() to let 
GimpUnitEntryTable handle the position automatically (entries will be lined up vertically).

 app/dialogs/layer-options-dialog.c  |    4 +-
 app/widgets/gimptemplateeditor.c    |   24 +++++++-------
 libgimpwidgets/gimpunitentrytable.c |   63 ++++++++++++++++++++++++----------
 libgimpwidgets/gimpunitentrytable.h |    6 ++-
 libgimpwidgets/gimpwidgets.def      |    1 +
 libgimpwidgets/test-unitentrygui.c  |    8 ++--
 6 files changed, 67 insertions(+), 39 deletions(-)
---
diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c
index 0bbb8f0..f9d30d8 100644
--- a/app/dialogs/layer-options-dialog.c
+++ b/app/dialogs/layer-options-dialog.c
@@ -202,8 +202,8 @@ layer_options_dialog_new (GimpImage    *image,
 
       /* UnitEntry */
       options->size_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
-      entry1 = gimp_unit_entry_table_add_entry (options->size_se, "width", _("Width:"));
-      entry2 = gimp_unit_entry_table_add_entry (options->size_se, "height", _("Height:"));
+      entry1 = gimp_unit_entry_table_add_entry_defaults (options->size_se, "width", _("Width:"));
+      entry2 = gimp_unit_entry_table_add_entry_defaults (options->size_se, "height", _("Height:"));
       gimp_unit_entry_table_add_label (options->size_se, GIMP_UNIT_PIXEL, "width", "height");
       
       gimp_unit_entry_set_unit        (GIMP_UNIT_ENTRY (entry1), GIMP_UNIT_PIXEL);
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index e9daff2..be4a064 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -188,12 +188,12 @@ gimp_template_editor_constructed (GObject *object)
   /*gtk_table_set_row_spacing (GTK_TABLE (private->size_se), 0, 2);
   gtk_table_set_col_spacing (GTK_TABLE (private->size_se), 1, 6);*/
 
-  gimp_unit_entry_table_add_entry (private->size_se, 
-                                   "width", 
-                                   _("Width:"));
-  gimp_unit_entry_table_add_entry (private->size_se,
-                                   "heigth",
-                                   _("Height:"));
+  gimp_unit_entry_table_add_entry_defaults (private->size_se, 
+                                           "width", 
+                                           _("Width:"));
+  gimp_unit_entry_table_add_entry_defaults (private->size_se,
+                                           "heigth",
+                                           _("Height:"));
 
   gimp_prop_coordinates_connect2 (G_OBJECT (template),
                                  "width", "height", "unit",
@@ -289,12 +289,12 @@ gimp_template_editor_constructed (GObject *object)
 
   private->resolution_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ()); 
 
-  gimp_unit_entry_table_add_entry (private->resolution_se,
-                                   "xres",
-                                   _("X resolution:"));
-  gimp_unit_entry_table_add_entry (private->resolution_se,
-                                   "yres",
-                                   _("Y resolution:"));
+  gimp_unit_entry_table_add_entry_defaults (private->resolution_se,
+                                           "xres",
+                                           _("X resolution:"));
+  gimp_unit_entry_table_add_entry_defaults (private->resolution_se,
+                                           "yres",
+                                           _("Y resolution:"));
   gimp_unit_entry_table_set_res_mode (private->resolution_se, TRUE);                              
 
   /*gtk_table_set_row_spacing (GTK_TABLE (private->resolution_se), 0, 2);
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index 92e97e1..d67c953 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -50,6 +50,7 @@ gimp_unit_entry_table_init (GimpUnitEntryTable *table)
   table->table        = gtk_table_new (1, 1, FALSE);
   table->entries      = NULL;
   table->bottom       = 0;
+  table->right        = 0;
 }
 
 static void
@@ -82,17 +83,18 @@ gimp_unit_entry_table_new (void)
 GtkWidget* 
 gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
                                  const gchar *id,
-                                 const gchar *labelStr)
+                                 const gchar *labelStr,
+                                 gint x,
+                                 gint y)
 {
-  GimpUnitEntry *entry = GIMP_UNIT_ENTRY (gimp_unit_entry_new (id)) , *entry2; 
-  gint          count  = g_list_length (table->entries); 
+  GimpUnitEntry *entry = GIMP_UNIT_ENTRY (gimp_unit_entry_new (id)); 
   GtkWidget     *label;
-  gint i;
-  /* position of the entry */
-  gint leftAttach   = 1,
-       rightAttach  = 2,
-       topAttach    = table->bottom,
-       bottomAttach = table->bottom+1;
+
+  /* position of the entry (leave one row/column empty for labels etc) */
+  gint leftAttach   = x + 1,
+       rightAttach  = x + 2,
+       topAttach    = y + 1,
+       bottomAttach = y + 2;
 
   /* remember position in table so that we later can place other widgets around it */
   g_object_set_data (G_OBJECT (entry), "leftAttach", GINT_TO_POINTER (leftAttach));
@@ -108,7 +110,11 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
                              topAttach,
                              bottomAttach);
 
-  table->bottom++;
+  /* save new size of our table if neccessary */                           
+  if (bottomAttach > table->bottom)                           
+    table->bottom = bottomAttach;
+  if (rightAttach > table->right)
+    table->right = rightAttach;
 
   /* if label string is given, create label and attach to the left of entry */
   if (labelStr != NULL)
@@ -121,14 +127,6 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
                       10, 0);
     gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   }
-
-  /* connect entry to others */
-  for (i = 0; i < count; i++)
-  {
-    entry2 = gimp_unit_entry_table_get_nth_entry (table, i);
-    gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry), GIMP_UNIT_ENTRY (entry2));
-    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",
@@ -143,6 +141,31 @@ gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table,
   return GTK_WIDGET (entry);
 }
 
+GtkWidget* 
+gimp_unit_entry_table_add_entry_defaults (GimpUnitEntryTable *table,
+                                          const gchar *id,
+                                          const gchar *labelStr)
+{
+  GimpUnitEntry *entry, *entry2;
+  gint i;
+
+  entry = GIMP_UNIT_ENTRY (gimp_unit_entry_table_add_entry (table,
+                                                           id,
+                                                           labelStr,
+                                                           1,
+                                                           table->bottom));
+
+  /* connect entry to others */
+  for (i = 0; i < g_list_length (table->entries); i++)
+  {
+    entry2 = gimp_unit_entry_table_get_nth_entry (table, i);
+    gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry), GIMP_UNIT_ENTRY (entry2));
+    gimp_unit_entry_connect (GIMP_UNIT_ENTRY (entry2), GIMP_UNIT_ENTRY (entry));
+  }                                         
+
+  return GTK_WIDGET (entry);
+}
+
 /* add preview label showing value of the two given entries in given unit */
 void 
 gimp_unit_entry_table_add_label (GimpUnitEntryTable *table,
@@ -201,7 +224,7 @@ gimp_unit_entry_table_add_chainbutton  (GimpUnitEntryTable *table,
                                         const char* id1,
                                         const char* id2)
 {
-  GtkWidget        *chainButton = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
+  GtkWidget        *chainButton;
   GimpUnitEntry    *entry1      = gimp_unit_entry_table_get_entry (table, id1);
   GimpUnitEntry    *entry2      = gimp_unit_entry_table_get_entry (table, id2);
 
@@ -210,6 +233,8 @@ gimp_unit_entry_table_add_chainbutton  (GimpUnitEntryTable *table,
   gint topAttach    = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry1), "topAttach"));
   gint bottomAttach = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (entry2), "bottomAttach"));
 
+  chainButton = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
+
   /* add chainbutton to right of entries, spanning from the first to the second */
   gtk_table_attach (GTK_TABLE (table->table),
                              GTK_WIDGET (chainButton),
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 913b4b1..722e115 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -51,7 +51,8 @@ struct _GimpUnitEntryTable
   GtkWidget  *table;
   GList      *entries;        /* list of entries */
 
-  gint       bottom;          /* bottom row of our table */
+  /* dimensions of "sub-table" containing the actual entries */ 
+  gint       bottom, right;
 };
 
 struct _GimpUnitEntryTableClass
@@ -69,7 +70,8 @@ GType     gimp_unit_entry_table_get_type (void);
 GObject   *gimp_unit_entry_table_new (void);
 
 /* add UnitEntry */
-GtkWidget* gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table, const gchar* id, const gchar *label);
+GtkWidget* gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table, const gchar* id, const gchar *label, 
gint x, gint y);
+GtkWidget* gimp_unit_entry_table_add_entry_defaults (GimpUnitEntryTable *table, const gchar* id, const gchar 
*label);
 //void gimp_unit_entry_table_add_entries ()
 /* add preview label showing the current value of two entries in given unit */
 void gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit, const char* id1, const char* 
id2);
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index d8f9f4d..779d242 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -393,6 +393,7 @@ EXPORTS
        gimp_unit_entry_set_value_in_unit
        gimp_unit_entry_table_add_chainbutton
        gimp_unit_entry_table_add_entry
+       gimp_unit_entry_table_add_entry_defaults
        gimp_unit_entry_table_add_label
        gimp_unit_entry_table_get_entry
        gimp_unit_entry_table_get_entry_count
diff --git a/libgimpwidgets/test-unitentrygui.c b/libgimpwidgets/test-unitentrygui.c
index 3e23338..a16f85e 100644
--- a/libgimpwidgets/test-unitentrygui.c
+++ b/libgimpwidgets/test-unitentrygui.c
@@ -41,8 +41,8 @@ create_interface(void)
 
   /* entry table */
   entryTable = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
-  gimp_unit_entry_table_add_entry (entryTable, "width", "Width");
-  gimp_unit_entry_table_add_entry (entryTable, "height", "Height");
+  gimp_unit_entry_table_add_entry_defaults (entryTable, "width", "Width");
+  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");
@@ -57,8 +57,8 @@ create_interface(void)
 
   /* resolution entry */
   entryTable = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
-  gimp_unit_entry_table_add_entry (entryTable, "xres", "X Resolution");
-  gimp_unit_entry_table_add_entry (entryTable, "yres", "Y Resolution");
+  gimp_unit_entry_table_add_entry_defaults (entryTable, "xres", "X Resolution");
+  gimp_unit_entry_table_add_entry_defaults (entryTable, "yres", "Y Resolution");
 
   /* set some default values */
   a = gimp_unit_entry_table_get_entry (entryTable, "xres");


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