[gimp/soc-2011-gimpunitentry] Some refactoring of classes using GimpUnitEntry



commit 4dc553e5e41f84ae743b311a5fde9d9b69ceaeff
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Fri Jul 8 13:37:20 2011 +0200

    Some refactoring of classes using GimpUnitEntry

 app/actions/layers-commands.c      |    4 +-
 app/dialogs/image-new-dialog.c     |    2 +-
 app/dialogs/layer-options-dialog.c |   98 +++++++-----------------------------
 app/dialogs/layer-options-dialog.h |   24 ++++----
 app/widgets/gimptemplateeditor.c   |   74 ++++++++++++---------------
 app/widgets/gimptemplateeditor.h   |   16 +++---
 6 files changed, 74 insertions(+), 144 deletions(-)
---
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index ecdb57f..770bf1b 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -984,10 +984,10 @@ layers_new_layer_response (GtkWidget          *widget,
       layer_fill_type = dialog->fill_type;
 
       dialog->xsize =
-        RINT (gimp_unit_entry_table_get_pixels (dialog->size_se, "width"));
+        RINT (gimp_unit_entry_table_get_pixels (dialog->unit_entries, "width"));
 
       dialog->ysize =
-        RINT (gimp_unit_entry_table_get_pixels (dialog->size_se, "height"));
+        RINT (gimp_unit_entry_table_get_pixels (dialog->unit_entries, "height"));
 
       layer = gimp_layer_new (dialog->image,
                               dialog->xsize,
diff --git a/app/dialogs/image-new-dialog.c b/app/dialogs/image-new-dialog.c
index dd99c61..c516e0d 100644
--- a/app/dialogs/image-new-dialog.c
+++ b/app/dialogs/image-new-dialog.c
@@ -154,7 +154,7 @@ image_new_dialog_new (GimpContext *context)
   gtk_box_pack_start (GTK_BOX (main_vbox), dialog->editor, FALSE, FALSE, 0);
   gtk_widget_show (dialog->editor);
 
-  unit_entry_table = gimp_template_editor_get_size_se (GIMP_TEMPLATE_EDITOR (dialog->editor));
+  unit_entry_table = gimp_template_editor_get_unit_entries (GIMP_TEMPLATE_EDITOR (dialog->editor));
   gimp_unit_entry_table_set_activates_default (unit_entry_table, TRUE);
   gimp_unit_entry_table_grab_focus (unit_entry_table);
 
diff --git a/app/dialogs/layer-options-dialog.c b/app/dialogs/layer-options-dialog.c
index c4967d6..668b212 100644
--- a/app/dialogs/layer-options-dialog.c
+++ b/app/dialogs/layer-options-dialog.c
@@ -65,13 +65,10 @@ layer_options_dialog_new (GimpImage    *image,
   GimpViewable       *viewable;
   GtkWidget          *vbox;
   GtkWidget          *table;
-  GtkWidget          *label;
-  GtkObject          *adjustment;
-  GtkWidget          *spinbutton;
   GtkWidget          *frame;
   GtkWidget          *button;
-  GtkWidget          *entry1;
-  GtkWidget          *entry2;
+  GtkWidget          *width_entry;
+  GtkWidget          *height_entry;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (layer == NULL || GIMP_IS_LAYER (layer), NULL);
@@ -115,7 +112,7 @@ layer_options_dialog_new (GimpImage    *image,
                       vbox, TRUE, TRUE, 0);
   gtk_widget_show (vbox);
 
-  table = gtk_table_new (layer ? 1 : 4, 2, FALSE);
+  table = gtk_table_new (layer ? 1 : 3, 2, FALSE);
   gtk_table_set_col_spacing (GTK_TABLE (table), 0, 6);
   gtk_table_set_row_spacing (GTK_TABLE (table), 0, 6);
   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
@@ -137,83 +134,24 @@ layer_options_dialog_new (GimpImage    *image,
 
       gimp_image_get_resolution (image, &xres, &yres);
 
-      /*  The size labels  */
-      /*label = gtk_label_new (_("Width:"));
-      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-      gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
-                        GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
-      gtk_widget_show (label);
-
-      label = gtk_label_new (_("Height:"));
-      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-      gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
-                        GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
-      gtk_widget_show (label);*/
-
-      /*  The size sizeentry  */
-      /*spinbutton = gimp_spin_button_new (&adjustment,
-                                         1, 1, 1, 1, 10, 0,
-                                         1, 2);
-      gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 10);
-
-      options->size_se = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a",
-                                              TRUE, TRUE, FALSE, 10,
-                                              GIMP_SIZE_ENTRY_UPDATE_SIZE);
-      gtk_table_set_col_spacing (GTK_TABLE (options->size_se), 1, 4);
-      gtk_table_set_row_spacing (GTK_TABLE (options->size_se), 0, 2);
-
-      gimp_size_entry_add_field (GIMP_SIZE_ENTRY (options->size_se),
-                                 GTK_SPIN_BUTTON (spinbutton), NULL);
-      gtk_table_attach_defaults (GTK_TABLE (options->size_se), spinbutton,
-                                 1, 2, 0, 1);
-      gtk_widget_show (spinbutton);
-
-      /*gtk_table_attach (GTK_TABLE (table), options->size_se, 1, 2, 1, 3,
-                        GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
-      gtk_widget_show (options->size_se);
-
-      gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (options->size_se),
-                                GIMP_UNIT_PIXEL);
-
-      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 0,
-                                      xres, FALSE);
-      gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (options->size_se), 1,
-                                      yres, FALSE);
-
-      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 0,
-                                             GIMP_MIN_IMAGE_SIZE,
-                                             GIMP_MAX_IMAGE_SIZE);
-      gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (options->size_se), 1,
-                                             GIMP_MIN_IMAGE_SIZE,
-                                             GIMP_MAX_IMAGE_SIZE);
-
-      gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 0,
-                                0, gimp_image_get_width  (image));
-      gimp_size_entry_set_size (GIMP_SIZE_ENTRY (options->size_se), 1,
-                                0, gimp_image_get_height (image));
-
-      gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 0,
-                                  gimp_image_get_width  (image));
-      gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (options->size_se), 1,
-                                  gimp_image_get_height (image));*/
-
       /* UnitEntry */
-      options->size_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
-      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");
+      options->unit_entries = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
+      width_entry = gimp_unit_entry_table_add_entry_defaults  (options->unit_entries, "width", _("Width:"));
+      height_entry = gimp_unit_entry_table_add_entry_defaults (options->unit_entries, "height", _("Height:"));
+      gimp_unit_entry_table_add_label (options->unit_entries, GIMP_UNIT_PIXEL, "width", "height");
+      
+      gimp_unit_entry_set_unit        (GIMP_UNIT_ENTRY (width_entry), GIMP_UNIT_PIXEL);
       
-      gimp_unit_entry_set_unit        (GIMP_UNIT_ENTRY (entry1), GIMP_UNIT_PIXEL);
-      gimp_unit_entry_set_resolution  (GIMP_UNIT_ENTRY (entry1), xres);
-      gimp_unit_entry_set_resolution  (GIMP_UNIT_ENTRY (entry2), yres);
-      gimp_unit_entry_set_value       (GIMP_UNIT_ENTRY (entry1), gimp_image_get_width  (image));
-      gimp_unit_entry_set_value       (GIMP_UNIT_ENTRY (entry2), gimp_image_get_height  (image));
-      gimp_unit_entry_set_bounds      (GIMP_UNIT_ENTRY (entry1), GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
-      gimp_unit_entry_set_bounds      (GIMP_UNIT_ENTRY (entry2), GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
-
-      gtk_table_attach (GTK_TABLE (table), options->size_se->table, 0, 2, 1, 3,
+      gimp_unit_entry_set_resolution  (GIMP_UNIT_ENTRY (width_entry), xres);
+      gimp_unit_entry_set_resolution  (GIMP_UNIT_ENTRY (height_entry), yres);
+      gimp_unit_entry_set_value       (GIMP_UNIT_ENTRY (width_entry), gimp_image_get_width  (image));
+      gimp_unit_entry_set_value       (GIMP_UNIT_ENTRY (height_entry), gimp_image_get_height  (image));
+      gimp_unit_entry_set_bounds      (GIMP_UNIT_ENTRY (width_entry), GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
+      gimp_unit_entry_set_bounds      (GIMP_UNIT_ENTRY (height_entry), GIMP_UNIT_PIXEL, GIMP_MAX_IMAGE_SIZE, GIMP_MIN_IMAGE_SIZE);
+
+      gtk_table_attach (GTK_TABLE (table), gimp_unit_entry_table_get_table (options->unit_entries), 0, 2, 1, 3,
                         GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
-      gtk_widget_show (options->size_se->table);
+      gtk_widget_show (gimp_unit_entry_table_get_table (options->unit_entries));
 
       /*  The radio frame  */
       frame = gimp_enum_radio_frame_new_with_range (GIMP_TYPE_FILL_TYPE,
diff --git a/app/dialogs/layer-options-dialog.h b/app/dialogs/layer-options-dialog.h
index c47a295..5974cca 100644
--- a/app/dialogs/layer-options-dialog.h
+++ b/app/dialogs/layer-options-dialog.h
@@ -24,18 +24,18 @@ typedef struct _LayerOptionsDialog LayerOptionsDialog;
 
 struct _LayerOptionsDialog
 {
-  GtkWidget    *dialog;
-  GtkWidget    *name_entry;
-  GimpUnitEntryTable    *size_se;
-  GtkWidget    *rename_toggle;
-
-  GimpFillType  fill_type;
-  gint          xsize;
-  gint          ysize;
-
-  GimpImage    *image;
-  GimpContext  *context;
-  GimpLayer    *layer;
+  GtkWidget             *dialog;
+  GtkWidget             *name_entry;
+  GimpUnitEntryTable    *unit_entries;
+  GtkWidget             *rename_toggle;
+
+  GimpFillType          fill_type;
+  gint                  xsize;
+  gint                  ysize;
+
+  GimpImage             *image;
+  GimpContext           *context;
+  GimpLayer             *layer;
 };
 
 
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index 330b796..bdfc52e 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -52,17 +52,17 @@ typedef struct _GimpTemplateEditorPrivate GimpTemplateEditorPrivate;
 
 struct _GimpTemplateEditorPrivate
 {
-  GimpTemplate  *template;
+  GimpTemplate          *template;
 
-  GtkWidget     *aspect_button;
-  gboolean       block_aspect;
+  GtkWidget             *aspect_button;
+  gboolean               block_aspect;
 
-  GtkWidget     *expander;
-  GimpUnitEntryTable     *size_se;
-  GtkWidget     *memsize_label;
-  GtkWidget     *pixel_label;
-  GtkWidget     *more_label;
-  GimpUnitEntryTable     *resolution_se;
+  GtkWidget             *expander;
+  GimpUnitEntryTable    *unit_entries;
+  GtkWidget             *memsize_label;
+  GtkWidget             *pixel_label;
+  GtkWidget             *more_label;
+  GimpUnitEntryTable    *resolution_entries;
 };
 
 #define GET_PRIVATE(editor) \
@@ -178,26 +178,22 @@ gimp_template_editor_constructed (GObject *object)
 
   /*  create the sizeentry which keeps it all together  */
   hbox = gtk_hbox_new (FALSE, 0);
-  //gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 0, 2);
   gtk_widget_show (hbox);
 
-  private->size_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
+  private->unit_entries = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ());
                         
-  gtk_table_attach_defaults (GTK_TABLE (table), private->size_se->table, 0, 2, 0, 2);
+  gtk_table_attach_defaults (GTK_TABLE (table), private->unit_entries->table, 0, 2, 0, 2);
 
-  /*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_defaults (private->size_se, 
+  gimp_unit_entry_table_add_entry_defaults (private->unit_entries, 
                                            "width", 
                                            _("Width:"));
-  gimp_unit_entry_table_add_entry_defaults (private->size_se,
-                                           "heigth",
+  gimp_unit_entry_table_add_entry_defaults (private->unit_entries,
+                                           "height",
                                            _("Height:"));
 
   gimp_prop_coordinates_connect2 (G_OBJECT (template),
                                  "width", "height", "unit",
-                                 G_OBJECT (private->size_se), NULL,
+                                 G_OBJECT (private->unit_entries), NULL,
                                  gimp_template_get_resolution_x (template),
                                  gimp_template_get_resolution_y (template));
 
@@ -287,45 +283,41 @@ gimp_template_editor_constructed (GObject *object)
   gtk_table_attach_defaults (GTK_TABLE (table), hbox, 0, 2, 0, 2);
   gtk_widget_show (hbox);
 
-  private->resolution_se = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ()); 
+  private->resolution_entries = GIMP_UNIT_ENTRY_TABLE (gimp_unit_entry_table_new ()); 
 
-  gimp_unit_entry_table_add_entry_defaults (private->resolution_se,
+  gimp_unit_entry_table_add_entry_defaults (private->resolution_entries,
                                            "xres",
                                            _("X resolution:"));
-  gimp_unit_entry_table_add_entry_defaults (private->resolution_se,
+  gimp_unit_entry_table_add_entry_defaults (private->resolution_entries,
                                            "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);
-  gtk_table_set_col_spacing (GTK_TABLE (private->resolution_se), 1, 2);
-  gtk_table_set_col_spacing (GTK_TABLE (private->resolution_se), 2, 2);*/
+  gimp_unit_entry_table_set_res_mode (private->resolution_entries, TRUE);                              
 
-  gtk_box_pack_start (GTK_BOX (hbox), private->resolution_se->table, TRUE, TRUE, 0);
-  gtk_widget_show (private->resolution_se->table);
+  gtk_box_pack_start (GTK_BOX (hbox), private->resolution_entries->table, TRUE, TRUE, 0);
+  gtk_widget_show (private->resolution_entries->table);
 
-  gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 0),
+  gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 0),
                                   gimp_template_get_resolution_x (template));
-  gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 1),
+  gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 1),
                                   gimp_template_get_resolution_y (template));
 
   /*  the resolution chainbutton  */
-  chainbutton = gimp_unit_entry_table_add_chainbutton (private->resolution_se,
+  chainbutton = gimp_unit_entry_table_add_chainbutton (private->resolution_entries,
                                                        "xres", "yres");
 
   gimp_prop_coordinates_connect2 (G_OBJECT (template),
                                  "xresolution", "yresolution",
                                  "resolution-unit",
-                                 G_OBJECT (private->resolution_se), chainbutton,
+                                 G_OBJECT (private->resolution_entries), chainbutton,
                                  1.0, 1.0);
 
   /*focus_chain = g_list_prepend (focus_chain,
-                                GIMP_SIZE_ENTRY (private->resolution_se)->unitmenu);
+                                GIMP_SIZE_ENTRY (private->resolution_entries)->unitmenu);
   focus_chain = g_list_prepend (focus_chain, chainbutton);
   focus_chain = g_list_prepend (focus_chain, yres);
   focus_chain = g_list_prepend (focus_chain, xres);
 
-  gtk_container_set_focus_chain (GTK_CONTAINER (private->resolution_se),
+  gtk_container_set_focus_chain (GTK_CONTAINER (private->resolution_entries),
                                  focus_chain);*/
   g_list_free (focus_chain);
 
@@ -494,11 +486,11 @@ gimp_template_editor_show_advanced (GimpTemplateEditor *editor,
 }
 
 GimpUnitEntryTable *
-gimp_template_editor_get_size_se (GimpTemplateEditor *editor)
+gimp_template_editor_get_unit_entries (GimpTemplateEditor *editor)
 {
   g_return_val_if_fail (GIMP_IS_TEMPLATE_EDITOR (editor), NULL);
 
-  return GET_PRIVATE (editor)->size_se;
+  return GET_PRIVATE (editor)->unit_entries;
 }
 
 
@@ -548,9 +540,9 @@ gimp_template_editor_aspect_callback (GtkWidget          *widget,
                                        gimp_template_editor_template_notify,
                                        editor);
 
-      gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 0),
+      gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 0),
                                       yresolution); 
-      gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 1),
+      gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 1),
                                       xresolution);                                                                
 
       g_object_set (template,
@@ -586,12 +578,12 @@ gimp_template_editor_template_notify (GimpTemplate       *template,
     {
       if (! strcmp (param_spec->name, "xresolution"))
         {
-          gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 0),
+          gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 0),
                                           gimp_template_get_resolution_x (template));
         }
       else if (! strcmp (param_spec->name, "yresolution"))
         {
-          gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->size_se, 1),
+          gimp_unit_entry_set_resolution (gimp_unit_entry_table_get_nth_entry (private->unit_entries, 1),
                                           gimp_template_get_resolution_y (template));                               
         }
     }
diff --git a/app/widgets/gimptemplateeditor.h b/app/widgets/gimptemplateeditor.h
index a804f70..7a8ee46 100644
--- a/app/widgets/gimptemplateeditor.h
+++ b/app/widgets/gimptemplateeditor.h
@@ -43,17 +43,17 @@ struct _GimpTemplateEditorClass
 };
 
 
-GType          gimp_template_editor_get_type      (void) G_GNUC_CONST;
+GType                   gimp_template_editor_get_type          (void) G_GNUC_CONST;
 
-GtkWidget    * gimp_template_editor_new           (GimpTemplate       *template,
-                                                   Gimp               *gimp,
-                                                   gboolean            edit_template);
+GtkWidget             * gimp_template_editor_new               (GimpTemplate       *template,
+                                                                Gimp               *gimp,
+                                                                gboolean            edit_template);
 
-GimpTemplate * gimp_template_editor_get_template  (GimpTemplateEditor *editor);
+GimpTemplate          * gimp_template_editor_get_template      (GimpTemplateEditor *editor);
 
-void           gimp_template_editor_show_advanced (GimpTemplateEditor *editor,
-                                                   gboolean            expanded);
-GimpUnitEntryTable    * gimp_template_editor_get_size_se   (GimpTemplateEditor *editor);
+void                    gimp_template_editor_show_advanced     (GimpTemplateEditor *editor,
+                                                                gboolean            expanded);
+GimpUnitEntryTable    * gimp_template_editor_get_unit_entries  (GimpTemplateEditor *editor);
 
 
 #endif  /*  __GIMP_TEMPLATE_EDITOR_H__  */



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