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



commit 0f1e0fdf2ad98684919664ad7dd2aa36d582ad50
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 |  155 ++++++++++++++++++++++++-------------
 libgimpwidgets/gimpmemsizeentry.h |   29 +++-----
 libgimpwidgets/gimppropwidgets.c  |    4 +-
 3 files changed, 114 insertions(+), 74 deletions(-)
---
diff --git a/libgimpwidgets/gimpmemsizeentry.c b/libgimpwidgets/gimpmemsizeentry.c
index bc41536..405c926 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,30 +103,34 @@ 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);
 
-  g_clear_object (&entry->adjustment);
+  g_clear_object (&private->adjustment);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -115,9 +139,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);
 }
@@ -126,7 +151,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);
 
@@ -136,17 +162,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
@@ -169,9 +195,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)
@@ -183,6 +210,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) &&
@@ -190,45 +219,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);
 }
@@ -245,10 +274,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)
     {
@@ -257,12 +290,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
@@ -271,7 +304,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
 }
@@ -289,5 +322,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 6a81eb5..df95798 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -1778,7 +1778,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",
@@ -1828,7 +1828,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]