[gimp/gtk3-port: 170/224] libgimpwidgets: move all GimpEnumLabel members to a private struct



commit 776dd15f744666b5063351b2fa95deb0c7e958a7
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jan 3 13:08:25 2011 +0100

    libgimpwidgets: move all GimpEnumLabel members to a private struct

 libgimpwidgets/gimpenumlabel.c |   44 ++++++++++++++++++++++++++++++----------
 libgimpwidgets/gimpenumlabel.h |   11 ++++++---
 2 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/libgimpwidgets/gimpenumlabel.c b/libgimpwidgets/gimpenumlabel.c
index 84ca4c7..1afa4a7 100644
--- a/libgimpwidgets/gimpenumlabel.c
+++ b/libgimpwidgets/gimpenumlabel.c
@@ -47,6 +47,19 @@ enum
 };
 
 
+
+typedef struct _GimpEnumLabelPrivate GimpEnumLabelPrivate;
+
+struct _GimpEnumLabelPrivate
+{
+  GEnumClass *enum_class;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+                                                      GIMP_TYPE_ENUM_LABEL, \
+                                                      GimpEnumLabelPrivate)
+
+
 static void   gimp_enum_label_finalize     (GObject      *object);
 static void   gimp_enum_label_get_property (GObject      *object,
                                             guint         property_id,
@@ -97,6 +110,8 @@ gimp_enum_label_class_init (GimpEnumLabelClass *klass)
                                                      G_MININT, G_MAXINT, 0,
                                                      GIMP_PARAM_WRITABLE |
                                                      G_PARAM_CONSTRUCT));
+
+  g_type_class_add_private (object_class, sizeof (GimpEnumLabelPrivate));
 }
 
 static void
@@ -107,10 +122,13 @@ gimp_enum_label_init (GimpEnumLabel *enum_label)
 static void
 gimp_enum_label_finalize (GObject *object)
 {
-  GimpEnumLabel *enum_label = GIMP_ENUM_LABEL (object);
+  GimpEnumLabelPrivate *private = GET_PRIVATE (object);
 
-  if (enum_label->enum_class)
-    g_type_class_unref (enum_label->enum_class);
+  if (private->enum_class)
+    {
+      g_type_class_unref (private->enum_class);
+      private->enum_class = NULL;
+    }
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -121,13 +139,13 @@ gimp_enum_label_get_property (GObject    *object,
                               GValue     *value,
                               GParamSpec *pspec)
 {
-  GimpEnumLabel *label = GIMP_ENUM_LABEL (object);
+  GimpEnumLabelPrivate *private = GET_PRIVATE (object);
 
   switch (property_id)
     {
     case PROP_ENUM_TYPE:
-      if (label->enum_class)
-        g_value_set_gtype (value, G_TYPE_FROM_CLASS (label->enum_class));
+      if (private->enum_class)
+        g_value_set_gtype (value, G_TYPE_FROM_CLASS (private->enum_class));
       else
         g_value_set_gtype (value, G_TYPE_NONE);
       break;
@@ -144,12 +162,13 @@ gimp_enum_label_set_property (GObject      *object,
                               const GValue *value,
                               GParamSpec   *pspec)
 {
-  GimpEnumLabel *label = GIMP_ENUM_LABEL (object);
+  GimpEnumLabel        *label   = GIMP_ENUM_LABEL (object);
+  GimpEnumLabelPrivate *private = GET_PRIVATE (label);
 
   switch (property_id)
     {
     case PROP_ENUM_TYPE:
-      label->enum_class = g_type_class_ref (g_value_get_gtype (value));
+      private->enum_class = g_type_class_ref (g_value_get_gtype (value));
       break;
 
     case PROP_ENUM_VALUE:
@@ -194,16 +213,19 @@ void
 gimp_enum_label_set_value (GimpEnumLabel *label,
                            gint           value)
 {
-  const gchar *desc;
+  GimpEnumLabelPrivate *private;
+  const gchar          *desc;
 
   g_return_if_fail (GIMP_IS_ENUM_LABEL (label));
 
-  if (! gimp_enum_get_value (G_TYPE_FROM_CLASS (label->enum_class), value,
+  private = GET_PRIVATE (label);
+
+  if (! gimp_enum_get_value (G_TYPE_FROM_CLASS (private->enum_class), value,
                              NULL, NULL, &desc, NULL))
     {
       g_warning ("%s: %d is not valid for enum of type '%s'",
                  G_STRLOC, value,
-                 g_type_name (G_TYPE_FROM_CLASS (label->enum_class)));
+                 g_type_name (G_TYPE_FROM_CLASS (private->enum_class)));
       return;
     }
 
diff --git a/libgimpwidgets/gimpenumlabel.h b/libgimpwidgets/gimpenumlabel.h
index 9469017..11139e0 100644
--- a/libgimpwidgets/gimpenumlabel.h
+++ b/libgimpwidgets/gimpenumlabel.h
@@ -41,15 +41,18 @@ typedef struct _GimpEnumLabelClass  GimpEnumLabelClass;
 
 struct _GimpEnumLabel
 {
-  GtkLabel       parent_instance;
-
-  /*< private >*/
-  GEnumClass    *enum_class;
+  GtkLabel  parent_instance;
 };
 
 struct _GimpEnumLabelClass
 {
   GtkLabelClass  parent_class;
+
+  /* Padding for future expansion */
+  void (* _gimp_reserved1) (void);
+  void (* _gimp_reserved2) (void);
+  void (* _gimp_reserved3) (void);
+  void (* _gimp_reserved4) (void);
 };
 
 



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