[gimp/gtk3-port: 164/231] libgimpwidgets: move all GimpMemsizeEntry members to a private struct



commit 79871ae0b44404ddd2eeb503c20a11dffd98d401
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jan 3 14:03:00 2011 +0100

    libgimpwidgets: move all GimpMemsizeEntry members to a private struct

 libgimpwidgets/gimpmemsizeentry.c |  159 ++++++++++++++++++++++++-------------
 libgimpwidgets/gimpmemsizeentry.h |   29 +++-----
 libgimpwidgets/gimppropwidgets.c  |    4 +-
 3 files changed, 116 insertions(+), 76 deletions(-)
---
diff --git a/libgimpwidgets/gimpmemsizeentry.c b/libgimpwidgets/gimpmemsizeentry.c
index b03dfb2..cb65ccb 100644
--- a/libgimpwidgets/gimpmemsizeentry.c
+++ b/libgimpwidgets/gimpmemsizeentry.c
@@ -51,6 +51,26 @@ enum
 };
 
 
+typedef struct _GimpMemsizeEntryPrivate GimpMemsizeEntryPrivate;
+
+struct _GimpMemsizeEntryPrivate
+{
+  guint64        value;
+  guint64        lower;
+  guint64        upper;
+
+  guint          shift;
+
+  GtkAdjustment *adjustment;
+  GtkWidget     *spinbutton;
+  GtkWidget     *menu;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+                                                      GIMP_TYPE_MEMSIZE_ENTRY, \
+                                                      GimpMemsizeEntryPrivate)
+
+
 static void  gimp_memsize_entry_finalize      (GObject          *object);
 
 static void  gimp_memsize_entry_adj_callback  (GtkAdjustment    *adj,
@@ -83,33 +103,37 @@ gimp_memsize_entry_class_init (GimpMemsizeEntryClass *klass)
                   NULL, NULL,
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
+
+  g_type_class_add_private (object_class, sizeof (GimpMemsizeEntryPrivate));
 }
 
 static void
 gimp_memsize_entry_init (GimpMemsizeEntry *entry)
 {
+  GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+
   gtk_orientable_set_orientation (GTK_ORIENTABLE (entry),
                                   GTK_ORIENTATION_HORIZONTAL);
 
   gtk_box_set_spacing (GTK_BOX (entry), 4);
 
-  entry->value      = 0;
-  entry->lower      = 0;
-  entry->upper      = 0;
-  entry->shift      = 0;
-  entry->adjustment = NULL;
-  entry->menu       = NULL;
+  private->value      = 0;
+  private->lower      = 0;
+  private->upper      = 0;
+  private->shift      = 0;
+  private->adjustment = NULL;
+  private->menu       = NULL;
 }
 
 static void
 gimp_memsize_entry_finalize (GObject *object)
 {
-  GimpMemsizeEntry *entry = (GimpMemsizeEntry *) object;
+  GimpMemsizeEntryPrivate *private = GET_PRIVATE (object);
 
-  if (entry->adjustment)
+  if (private->adjustment)
     {
-      g_object_unref (entry->adjustment);
-      entry->adjustment = NULL;
+      g_object_unref (private->adjustment);
+      private->adjustment = NULL;
     }
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -119,9 +143,10 @@ static void
 gimp_memsize_entry_adj_callback (GtkAdjustment    *adj,
                                  GimpMemsizeEntry *entry)
 {
-  guint64 size = gtk_adjustment_get_value (adj);
+  GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+  guint64                  size    = gtk_adjustment_get_value (adj);
 
-  entry->value = size << entry->shift;
+  private->value = size << private->shift;
 
   g_signal_emit (entry, gimp_memsize_entry_signals[VALUE_CHANGED], 0);
 }
@@ -130,7 +155,8 @@ static void
 gimp_memsize_entry_unit_callback (GtkWidget        *widget,
                                   GimpMemsizeEntry *entry)
 {
-  guint  shift;
+  GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+  guint                    shift;
 
   gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) &shift);
 
@@ -140,17 +166,17 @@ gimp_memsize_entry_unit_callback (GtkWidget        *widget,
 #  define CAST
 #endif
 
-  if (shift != entry->shift)
+  if (shift != private->shift)
     {
-      entry->shift = shift;
-
-      gtk_adjustment_configure (entry->adjustment,
-                                CAST entry->value >> shift,
-                                CAST entry->lower >> shift,
-                                CAST entry->upper >> shift,
-                                gtk_adjustment_get_step_increment (entry->adjustment),
-                                gtk_adjustment_get_page_increment (entry->adjustment),
-                                gtk_adjustment_get_page_size (entry->adjustment));
+      private->shift = shift;
+
+      gtk_adjustment_configure (private->adjustment,
+                                CAST private->value >> shift,
+                                CAST private->lower >> shift,
+                                CAST private->upper >> shift,
+                                gtk_adjustment_get_step_increment (private->adjustment),
+                                gtk_adjustment_get_page_increment (private->adjustment),
+                                gtk_adjustment_get_page_size (private->adjustment));
     }
 
 #undef CAST
@@ -173,9 +199,10 @@ gimp_memsize_entry_new (guint64  value,
                         guint64  lower,
                         guint64  upper)
 {
-  GimpMemsizeEntry *entry;
-  GtkAdjustment    *adj;
-  guint             shift;
+  GimpMemsizeEntry        *entry;
+  GimpMemsizeEntryPrivate *private;
+  GtkAdjustment           *adj;
+  guint                    shift;
 
 #if _MSC_VER < 1300
 #  define CAST (gint64)
@@ -187,6 +214,8 @@ gimp_memsize_entry_new (guint64  value,
 
   entry = g_object_new (GIMP_TYPE_MEMSIZE_ENTRY, NULL);
 
+  private = GET_PRIVATE (entry);
+
   for (shift = 30; shift > 10; shift -= 10)
     {
       if (value > (G_GUINT64_CONSTANT (1) << shift) &&
@@ -194,45 +223,45 @@ gimp_memsize_entry_new (guint64  value,
         break;
     }
 
-  entry->value = value;
-  entry->lower = lower;
-  entry->upper = upper;
-  entry->shift = shift;
+  private->value = value;
+  private->lower = lower;
+  private->upper = upper;
+  private->shift = shift;
 
-  adj = (GtkAdjustment *) gtk_adjustment_new (CAST (value >> shift),
-                                              CAST (lower >> shift),
-                                              CAST (upper >> shift),
-                                              1, 8, 0);
+  adj = gtk_adjustment_new (CAST (value >> shift),
+                            CAST (lower >> shift),
+                            CAST (upper >> shift),
+                            1, 8, 0);
 
-  entry->spinbutton = gtk_spin_button_new (adj, 1.0, 0);
-  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (entry->spinbutton), TRUE);
+  private->spinbutton = gtk_spin_button_new (adj, 1.0, 0);
+  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (private->spinbutton), TRUE);
 
 #undef CAST
 
-  entry->adjustment = GTK_ADJUSTMENT (adj);
-  g_object_ref_sink (entry->adjustment);
+  private->adjustment = GTK_ADJUSTMENT (adj);
+  g_object_ref_sink (private->adjustment);
 
-  gtk_entry_set_width_chars (GTK_ENTRY (entry->spinbutton), 7);
-  gtk_box_pack_start (GTK_BOX (entry), entry->spinbutton, FALSE, FALSE, 0);
-  gtk_widget_show (entry->spinbutton);
+  gtk_entry_set_width_chars (GTK_ENTRY (private->spinbutton), 7);
+  gtk_box_pack_start (GTK_BOX (entry), private->spinbutton, FALSE, FALSE, 0);
+  gtk_widget_show (private->spinbutton);
 
-  g_signal_connect (entry->adjustment, "value-changed",
+  g_signal_connect (private->adjustment, "value-changed",
                     G_CALLBACK (gimp_memsize_entry_adj_callback),
                     entry);
 
-  entry->menu = gimp_int_combo_box_new (_("Kilobytes"), 10,
+  private->menu = gimp_int_combo_box_new (_("Kilobytes"), 10,
                                         _("Megabytes"), 20,
                                         _("Gigabytes"), 30,
                                         NULL);
 
-  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (entry->menu), shift);
+  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->menu), shift);
 
-  g_signal_connect (entry->menu, "changed",
+  g_signal_connect (private->menu, "changed",
                     G_CALLBACK (gimp_memsize_entry_unit_callback),
                     entry);
 
-  gtk_box_pack_start (GTK_BOX (entry), entry->menu, FALSE, FALSE, 0);
-  gtk_widget_show (entry->menu);
+  gtk_box_pack_start (GTK_BOX (entry), private->menu, FALSE, FALSE, 0);
+  gtk_widget_show (private->menu);
 
   return GTK_WIDGET (entry);
 }
@@ -249,10 +278,14 @@ void
 gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
                               guint64           value)
 {
-  guint shift;
+  GimpMemsizeEntryPrivate *private;
+  guint                    shift;
 
   g_return_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry));
-  g_return_if_fail (value >= entry->lower && value <= entry->upper);
+
+  private = GET_PRIVATE (entry);
+
+  g_return_if_fail (value >= private->lower && value <= private->upper);
 
   for (shift = 30; shift > 10; shift -= 10)
     {
@@ -261,12 +294,12 @@ gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
         break;
     }
 
-  if (shift != entry->shift)
+  if (shift != private->shift)
     {
-      entry->shift = shift;
-      entry->value = value;
+      private->shift = shift;
+      private->value = value;
 
-      gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (entry->menu), shift);
+      gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->menu), shift);
     }
 
 #if _MSC_VER < 1300
@@ -275,7 +308,7 @@ gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
 #  define CAST
 #endif
 
-  gtk_adjustment_set_value (entry->adjustment, CAST (value >> shift));
+  gtk_adjustment_set_value (private->adjustment, CAST (value >> shift));
 
 #undef CASE
 }
@@ -293,5 +326,21 @@ gimp_memsize_entry_get_value (GimpMemsizeEntry *entry)
 {
   g_return_val_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry), 0);
 
-  return entry->value;
+  return GET_PRIVATE (entry)->value;
+}
+
+/**
+ * gimp_memsize_entry_get_spinbutton:
+ * @entry: a #GimpMemsizeEntry
+ *
+ * Returns: the entry's #GtkSpinbutton.
+ *
+ * Since: GIMP 3.0
+ **/
+GtkWidget *
+gimp_memsize_entry_get_spinbutton (GimpMemsizeEntry *entry)
+{
+  g_return_val_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry), 0);
+
+  return GET_PRIVATE (entry)->spinbutton;
 }
diff --git a/libgimpwidgets/gimpmemsizeentry.h b/libgimpwidgets/gimpmemsizeentry.h
index 6473da5..a231bd6 100644
--- a/libgimpwidgets/gimpmemsizeentry.h
+++ b/libgimpwidgets/gimpmemsizeentry.h
@@ -41,18 +41,7 @@ typedef struct _GimpMemsizeEntryClass  GimpMemsizeEntryClass;
 
 struct _GimpMemsizeEntry
 {
-  GtkBox         parent_instance;
-
-  /*< private >*/
-  guint64        value;
-  guint64        lower;
-  guint64        upper;
-
-  guint          shift;
-
-  GtkAdjustment *adjustment;
-  GtkWidget     *spinbutton;
-  GtkWidget     *menu;
+  GtkBox  parent_instance;
 };
 
 struct _GimpMemsizeEntryClass
@@ -69,14 +58,16 @@ struct _GimpMemsizeEntryClass
 };
 
 
-GType       gimp_memsize_entry_get_type  (void) G_GNUC_CONST;
+GType       gimp_memsize_entry_get_type       (void) G_GNUC_CONST;
+
+GtkWidget * gimp_memsize_entry_new            (guint64           value,
+                                               guint64           lower,
+                                               guint64           upper);
+void        gimp_memsize_entry_set_value      (GimpMemsizeEntry *entry,
+                                               guint64           value);
+guint64     gimp_memsize_entry_get_value      (GimpMemsizeEntry *entry);
 
-GtkWidget * gimp_memsize_entry_new       (guint64           value,
-                                          guint64           lower,
-                                          guint64           upper);
-void        gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
-                                          guint64           value);
-guint64     gimp_memsize_entry_get_value (GimpMemsizeEntry *entry);
+GtkWidget * gimp_memsize_entry_get_spinbutton (GimpMemsizeEntry *entry);
 
 
 G_END_DECLS
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index 5bf3b84..66c1aa4 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -1585,7 +1585,7 @@ gimp_prop_memsize_entry_new (GObject     *config,
                                   uint64_spec->maximum);
 
   set_param_spec (G_OBJECT (entry),
-                  GIMP_MEMSIZE_ENTRY (entry)->spinbutton,
+                  gimp_memsize_entry_get_spinbutton (GIMP_MEMSIZE_ENTRY (entry)),
                   param_spec);
 
   g_signal_connect (entry, "value-changed",
@@ -1630,7 +1630,7 @@ gimp_prop_memsize_notify (GObject          *config,
                 param_spec->name, &value,
                 NULL);
 
-  if (entry->value != value)
+  if (gimp_memsize_entry_get_value (entry) != value)
     {
       g_signal_handlers_block_by_func (entry,
                                        gimp_prop_memsize_callback,


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