[gtk+/refactor: 14/106] gtkcellrenderer: Move public members to private structure



commit 495bad1d103925b197de7bce127f6d6b11cdd764
Author: Javier Jardón <jjardon gnome org>
Date:   Sun May 30 22:21:33 2010 +0200

    gtkcellrenderer: Move public members to private structure

 gtk/gtkcellrenderer.c |  242 +++++++++++++++++++++++++++++++------------------
 gtk/gtkcellrenderer.h |   21 +----
 2 files changed, 159 insertions(+), 104 deletions(-)
---
diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c
index d9d95a1..17744e8 100644
--- a/gtk/gtkcellrenderer.c
+++ b/gtk/gtkcellrenderer.c
@@ -37,11 +37,25 @@ static void set_cell_bg_color               (GtkCellRenderer      *cell,
 					     GdkColor             *color);
 
 
-#define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate))
-
-typedef struct _GtkCellRendererPrivate GtkCellRendererPrivate;
-struct _GtkCellRendererPrivate
+struct _GtkCellRendererPriv
 {
+  gfloat xalign;
+  gfloat yalign;
+
+  gint width;
+  gint height;
+
+  guint16 xpad;
+  guint16 ypad;
+
+  guint mode                : 2;
+  guint visible             : 1;
+  guint is_expander         : 1;
+  guint is_expanded         : 1;
+  guint cell_background_set : 1;
+  guint sensitive           : 1;
+  guint editing             : 1;
+
   GdkColor cell_background;
 };
 
@@ -79,18 +93,25 @@ G_DEFINE_ABSTRACT_TYPE (GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT)
 static void
 gtk_cell_renderer_init (GtkCellRenderer *cell)
 {
-  cell->mode = GTK_CELL_RENDERER_MODE_INERT;
-  cell->visible = TRUE;
-  cell->width = -1;
-  cell->height = -1;
-  cell->xalign = 0.5;
-  cell->yalign = 0.5;
-  cell->xpad = 0;
-  cell->ypad = 0;
-  cell->sensitive = TRUE;
-  cell->is_expander = FALSE;
-  cell->is_expanded = FALSE;
-  cell->editing = FALSE;
+  GtkCellRendererPriv *priv;
+
+  cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
+                                            GTK_TYPE_CELL_RENDERER,
+                                            GtkCellRendererPriv);
+  priv = cell->priv;
+
+  priv->mode = GTK_CELL_RENDERER_MODE_INERT;
+  priv->visible = TRUE;
+  priv->width = -1;
+  priv->height = -1;
+  priv->xalign = 0.5;
+  priv->yalign = 0.5;
+  priv->xpad = 0;
+  priv->ypad = 0;
+  priv->sensitive = TRUE;
+  priv->is_expander = FALSE;
+  priv->is_expanded = FALSE;
+  priv->editing = FALSE;
 }
 
 static void
@@ -303,7 +324,7 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class)
                 P_("Cell background set"),
                 P_("Whether this tag affects the cell background color"));
 
-  g_type_class_add_private (object_class, sizeof (GtkCellRendererPrivate));
+  g_type_class_add_private (class, sizeof (GtkCellRendererPriv));
 }
 
 static void
@@ -313,45 +334,45 @@ gtk_cell_renderer_get_property (GObject     *object,
 				GParamSpec  *pspec)
 {
   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
-  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (object);
+  GtkCellRendererPriv *priv = cell->priv;
 
   switch (param_id)
     {
     case PROP_MODE:
-      g_value_set_enum (value, cell->mode);
+      g_value_set_enum (value, priv->mode);
       break;
     case PROP_VISIBLE:
-      g_value_set_boolean (value, cell->visible);
+      g_value_set_boolean (value, priv->visible);
       break;
     case PROP_SENSITIVE:
-      g_value_set_boolean (value, cell->sensitive);
+      g_value_set_boolean (value, priv->sensitive);
       break;
     case PROP_EDITING:
-      g_value_set_boolean (value, cell->editing);
+      g_value_set_boolean (value, priv->editing);
       break;
     case PROP_XALIGN:
-      g_value_set_float (value, cell->xalign);
+      g_value_set_float (value, priv->xalign);
       break;
     case PROP_YALIGN:
-      g_value_set_float (value, cell->yalign);
+      g_value_set_float (value, priv->yalign);
       break;
     case PROP_XPAD:
-      g_value_set_uint (value, cell->xpad);
+      g_value_set_uint (value, priv->xpad);
       break;
     case PROP_YPAD:
-      g_value_set_uint (value, cell->ypad);
+      g_value_set_uint (value, priv->ypad);
       break;
     case PROP_WIDTH:
-      g_value_set_int (value, cell->width);
+      g_value_set_int (value, priv->width);
       break;
     case PROP_HEIGHT:
-      g_value_set_int (value, cell->height);
+      g_value_set_int (value, priv->height);
       break;
     case PROP_IS_EXPANDER:
-      g_value_set_boolean (value, cell->is_expander);
+      g_value_set_boolean (value, priv->is_expander);
       break;
     case PROP_IS_EXPANDED:
-      g_value_set_boolean (value, cell->is_expanded);
+      g_value_set_boolean (value, priv->is_expanded);
       break;
     case PROP_CELL_BACKGROUND_GDK:
       {
@@ -365,7 +386,7 @@ gtk_cell_renderer_get_property (GObject     *object,
       }
       break;
     case PROP_CELL_BACKGROUND_SET:
-      g_value_set_boolean (value, cell->cell_background_set);
+      g_value_set_boolean (value, priv->cell_background_set);
       break;
     case PROP_CELL_BACKGROUND:
     default:
@@ -382,44 +403,45 @@ gtk_cell_renderer_set_property (GObject      *object,
 				GParamSpec   *pspec)
 {
   GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
+  GtkCellRendererPriv *priv = cell->priv;
 
   switch (param_id)
     {
     case PROP_MODE:
-      cell->mode = g_value_get_enum (value);
+      priv->mode = g_value_get_enum (value);
       break;
     case PROP_VISIBLE:
-      cell->visible = g_value_get_boolean (value);
+      priv->visible = g_value_get_boolean (value);
       break;
     case PROP_SENSITIVE:
-      cell->sensitive = g_value_get_boolean (value);
+      priv->sensitive = g_value_get_boolean (value);
       break;
     case PROP_EDITING:
-      cell->editing = g_value_get_boolean (value);
+      priv->editing = g_value_get_boolean (value);
       break;
     case PROP_XALIGN:
-      cell->xalign = g_value_get_float (value);
+      priv->xalign = g_value_get_float (value);
       break;
     case PROP_YALIGN:
-      cell->yalign = g_value_get_float (value);
+      priv->yalign = g_value_get_float (value);
       break;
     case PROP_XPAD:
-      cell->xpad = g_value_get_uint (value);
+      priv->xpad = g_value_get_uint (value);
       break;
     case PROP_YPAD:
-      cell->ypad = g_value_get_uint (value);
+      priv->ypad = g_value_get_uint (value);
       break;
     case PROP_WIDTH:
-      cell->width = g_value_get_int (value);
+      priv->width = g_value_get_int (value);
       break;
     case PROP_HEIGHT:
-      cell->height = g_value_get_int (value);
+      priv->height = g_value_get_int (value);
       break;
     case PROP_IS_EXPANDER:
-      cell->is_expander = g_value_get_boolean (value);
+      priv->is_expander = g_value_get_boolean (value);
       break;
     case PROP_IS_EXPANDED:
-      cell->is_expanded = g_value_get_boolean (value);
+      priv->is_expanded = g_value_get_boolean (value);
       break;
     case PROP_CELL_BACKGROUND:
       {
@@ -439,7 +461,7 @@ gtk_cell_renderer_set_property (GObject      *object,
       set_cell_bg_color (cell, g_value_get_boxed (value));
       break;
     case PROP_CELL_BACKGROUND_SET:
-      cell->cell_background_set = g_value_get_boolean (value);
+      priv->cell_background_set = g_value_get_boolean (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -451,13 +473,13 @@ static void
 set_cell_bg_color (GtkCellRenderer *cell,
 		   GdkColor        *color)
 {
-  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
+  GtkCellRendererPriv *priv = cell->priv;
 
   if (color)
     {
-      if (!cell->cell_background_set)
+      if (!priv->cell_background_set)
         {
-	  cell->cell_background_set = TRUE;
+	  priv->cell_background_set = TRUE;
 	  g_object_notify (G_OBJECT (cell), "cell-background-set");
 	}
 
@@ -467,9 +489,9 @@ set_cell_bg_color (GtkCellRenderer *cell,
     }
   else
     {
-      if (cell->cell_background_set)
+      if (priv->cell_background_set)
         {
-	  cell->cell_background_set = FALSE;
+	  priv->cell_background_set = FALSE;
 	  g_object_notify (G_OBJECT (cell), "cell-background-set");
 	}
     }
@@ -502,21 +524,24 @@ gtk_cell_renderer_get_size (GtkCellRenderer    *cell,
 			    gint               *width,
 			    gint               *height)
 {
+  GtkCellRendererPriv *priv;
   gint *real_width = width;
   gint *real_height = height;
 
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
 
-  if (width && cell->width != -1)
+  priv = cell->priv;
+
+  if (width && priv->width != -1)
     {
       real_width = NULL;
-      *width = cell->width;
+      *width = priv->width;
     }
-  if (height && cell->height != -1)
+  if (height && priv->height != -1)
     {
       real_height = NULL;
-      *height = cell->height;
+      *height = priv->height;
     }
 
   GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell,
@@ -557,14 +582,14 @@ gtk_cell_renderer_render (GtkCellRenderer      *cell,
 			  GtkCellRendererState  flags)
 {
   gboolean selected = FALSE;
-  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
+  GtkCellRendererPriv *priv = cell->priv;
 
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
   g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
 
   selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
 
-  if (cell->cell_background_set && !selected)
+  if (priv->cell_background_set && !selected)
     {
       cairo_t *cr = gdk_cairo_create (window);
 
@@ -610,9 +635,13 @@ gtk_cell_renderer_activate (GtkCellRenderer      *cell,
 			    const GdkRectangle   *cell_area,
 			    GtkCellRendererState  flags)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
 
-  if (cell->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
+  priv = cell->priv;
+
+  if (priv->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
     return FALSE;
 
   if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
@@ -652,11 +681,14 @@ gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
 				 GtkCellRendererState  flags)
 
 {
+  GtkCellRendererPriv *priv;
   GtkCellEditable *editable;
 
   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
 
-  if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
+  priv = cell->priv;
+
+  if (priv->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
     return NULL;
 
   if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
@@ -674,7 +706,7 @@ gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
 		 cell_renderer_signals[EDITING_STARTED], 0,
 		 editable, path);
 
-  cell->editing = TRUE;
+  priv->editing = TRUE;
 
   return editable;
 }
@@ -692,22 +724,26 @@ gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
 				  gint             width,
 				  gint             height)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
   g_return_if_fail (width >= -1 && height >= -1);
 
-  if ((width != cell->width) || (height != cell->height))
+  priv = cell->priv;
+
+  if ((width != priv->width) || (height != priv->height))
     {
       g_object_freeze_notify (G_OBJECT (cell));
 
-      if (width != cell->width)
+      if (width != priv->width)
         {
-          cell->width = width;
+          priv->width = width;
           g_object_notify (G_OBJECT (cell), "width");
         }
 
-      if (height != cell->height)
+      if (height != priv->height)
         {
-          cell->height = height;
+          priv->height = height;
           g_object_notify (G_OBJECT (cell), "height");
         }
 
@@ -728,12 +764,16 @@ gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
 				  gint            *width,
 				  gint            *height)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
+  priv = cell->priv;
+
   if (width)
-    *width = cell->width;
+    *width = priv->width;
   if (height)
-    *height = cell->height;
+    *height = priv->height;
 }
 
 /**
@@ -751,23 +791,27 @@ gtk_cell_renderer_set_alignment (GtkCellRenderer *cell,
                                  gfloat           xalign,
                                  gfloat           yalign)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
   g_return_if_fail (xalign >= 0.0 && xalign <= 1.0);
   g_return_if_fail (yalign >= 0.0 && yalign <= 1.0);
 
-  if ((xalign != cell->xalign) || (yalign != cell->yalign))
+  priv = cell->priv;
+
+  if ((xalign != priv->xalign) || (yalign != priv->yalign))
     {
       g_object_freeze_notify (G_OBJECT (cell));
 
-      if (xalign != cell->xalign)
+      if (xalign != priv->xalign)
         {
-          cell->xalign = xalign;
+          priv->xalign = xalign;
           g_object_notify (G_OBJECT (cell), "xalign");
         }
 
-      if (yalign != cell->yalign)
+      if (yalign != priv->yalign)
         {
-          cell->yalign = yalign;
+          priv->yalign = yalign;
           g_object_notify (G_OBJECT (cell), "yalign");
         }
 
@@ -790,12 +834,16 @@ gtk_cell_renderer_get_alignment (GtkCellRenderer *cell,
                                  gfloat          *xalign,
                                  gfloat          *yalign)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
+  priv = cell->priv;
+
   if (xalign)
-    *xalign = cell->xalign;
+    *xalign = priv->xalign;
   if (yalign)
-    *yalign = cell->yalign;
+    *yalign = priv->yalign;
 }
 
 /**
@@ -813,22 +861,26 @@ gtk_cell_renderer_set_padding (GtkCellRenderer *cell,
                                gint             xpad,
                                gint             ypad)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
   g_return_if_fail (xpad >= 0 && xpad >= 0);
 
-  if ((xpad != cell->xpad) || (ypad != cell->ypad))
+  priv = cell->priv;
+
+  if ((xpad != priv->xpad) || (ypad != priv->ypad))
     {
       g_object_freeze_notify (G_OBJECT (cell));
 
-      if (xpad != cell->xpad)
+      if (xpad != priv->xpad)
         {
-          cell->xpad = xpad;
+          priv->xpad = xpad;
           g_object_notify (G_OBJECT (cell), "xpad");
         }
 
-      if (ypad != cell->ypad)
+      if (ypad != priv->ypad)
         {
-          cell->ypad = ypad;
+          priv->ypad = ypad;
           g_object_notify (G_OBJECT (cell), "ypad");
         }
 
@@ -851,12 +903,16 @@ gtk_cell_renderer_get_padding (GtkCellRenderer *cell,
                                gint            *xpad,
                                gint            *ypad)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
+  priv = cell->priv;
+
   if (xpad)
-    *xpad = cell->xpad;
+    *xpad = priv->xpad;
   if (ypad)
-    *ypad = cell->ypad;
+    *ypad = priv->ypad;
 }
 
 /**
@@ -872,11 +928,15 @@ void
 gtk_cell_renderer_set_visible (GtkCellRenderer *cell,
                                gboolean         visible)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
-  if (cell->visible != visible)
+  priv = cell->priv;
+
+  if (priv->visible != visible)
     {
-      cell->visible = visible ? TRUE : FALSE;
+      priv->visible = visible ? TRUE : FALSE;
       g_object_notify (G_OBJECT (cell), "visible");
     }
 }
@@ -896,7 +956,7 @@ gtk_cell_renderer_get_visible (GtkCellRenderer *cell)
 {
   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
 
-  return cell->visible;
+  return cell->priv->visible;
 }
 
 /**
@@ -912,11 +972,15 @@ void
 gtk_cell_renderer_set_sensitive (GtkCellRenderer *cell,
                                  gboolean         sensitive)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
-  if (cell->sensitive != sensitive)
+  priv = cell->priv;
+
+  if (priv->sensitive != sensitive)
     {
-      cell->sensitive = sensitive ? TRUE : FALSE;
+      priv->sensitive = sensitive ? TRUE : FALSE;
       g_object_notify (G_OBJECT (cell), "sensitive");
     }
 }
@@ -936,7 +1000,7 @@ gtk_cell_renderer_get_sensitive (GtkCellRenderer *cell)
 {
   g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
 
-  return cell->sensitive;
+  return cell->priv->sensitive;
 }
 
 /**
@@ -958,11 +1022,15 @@ void
 gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
 				gboolean         canceled)
 {
+  GtkCellRendererPriv *priv;
+
   g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
-  if (cell->editing)
+  priv = cell->priv;
+
+  if (priv->editing)
     {
-      cell->editing = FALSE;
+      priv->editing = FALSE;
       if (canceled)
 	g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
     }
diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h
index d16f3d4..9e3dff8 100644
--- a/gtk/gtkcellrenderer.h
+++ b/gtk/gtkcellrenderer.h
@@ -52,29 +52,16 @@ typedef enum
 #define GTK_IS_CELL_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CELL_RENDERER))
 #define GTK_CELL_RENDERER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererClass))
 
-typedef struct _GtkCellRenderer GtkCellRenderer;
+typedef struct _GtkCellRenderer      GtkCellRenderer;
+typedef struct _GtkCellRendererPriv  GtkCellRendererPriv;
 typedef struct _GtkCellRendererClass GtkCellRendererClass;
 
 struct _GtkCellRenderer
 {
   GtkObject parent;
 
-  gfloat GSEAL (xalign);
-  gfloat GSEAL (yalign);
-
-  gint GSEAL (width);
-  gint GSEAL (height);
-
-  guint16 GSEAL (xpad);
-  guint16 GSEAL (ypad);
-
-  guint GSEAL (mode) : 2;
-  guint GSEAL (visible) : 1;
-  guint GSEAL (is_expander) : 1;
-  guint GSEAL (is_expanded) : 1;
-  guint GSEAL (cell_background_set) : 1;
-  guint GSEAL (sensitive) : 1;
-  guint GSEAL (editing) : 1;
+  /* <private> */
+  GtkCellRendererPriv *priv;
 };
 
 struct _GtkCellRendererClass



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