[gtk+/refactor: 3/106] gtkarrow: Move public members to private structure



commit 5e233fccbee1cdd3667d3d24b75c65c1fbdc0e42
Author: Javier Jardón <jjardon gnome org>
Date:   Mon May 24 05:18:05 2010 +0200

    gtkarrow: Move public members to private structure

 gtk/gtkarrow.c                  |   60 +++++++++++++++++++++++++++-----------
 gtk/gtkarrow.h                  |   10 +++---
 modules/other/gail/gailbutton.c |   21 +++++++++----
 3 files changed, 61 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkarrow.c b/gtk/gtkarrow.c
index 22e48db..b3cba00 100644
--- a/gtk/gtkarrow.c
+++ b/gtk/gtkarrow.c
@@ -52,6 +52,12 @@
 
 #define MIN_ARROW_SIZE  15
 
+struct _GtkArrowPriv
+{
+  gint16 arrow_type;
+  gint16 shadow_type;
+};
+
 enum {
   PROP_0,
   PROP_ARROW_TYPE,
@@ -112,6 +118,8 @@ gtk_arrow_class_init (GtkArrowClass *class)
                                                                P_("Amount of space used up by arrow"),
                                                                0.0, 1.0, 0.7,
                                                                GTK_PARAM_READABLE));
+
+  g_type_class_add_private (class, sizeof (GtkArrowPriv));
 }
 
 static void
@@ -121,17 +129,18 @@ gtk_arrow_set_property (GObject         *object,
 			GParamSpec      *pspec)
 {
   GtkArrow *arrow = GTK_ARROW (object);
+  GtkArrowPriv *priv = arrow->priv;
 
   switch (prop_id)
     {
     case PROP_ARROW_TYPE:
       gtk_arrow_set (arrow,
 		     g_value_get_enum (value),
-		     arrow->shadow_type);
+		     priv->shadow_type);
       break;
     case PROP_SHADOW_TYPE:
       gtk_arrow_set (arrow,
-		     arrow->arrow_type,
+		     priv->arrow_type,
 		     g_value_get_enum (value));
       break;
     default:
@@ -147,14 +156,15 @@ gtk_arrow_get_property (GObject         *object,
 			GParamSpec      *pspec)
 {
   GtkArrow *arrow = GTK_ARROW (object);
+  GtkArrowPriv *priv = arrow->priv;
 
   switch (prop_id)
     {
     case PROP_ARROW_TYPE:
-      g_value_set_enum (value, arrow->arrow_type);
+      g_value_set_enum (value, priv->arrow_type);
       break;
     case PROP_SHADOW_TYPE:
-      g_value_set_enum (value, arrow->shadow_type);
+      g_value_set_enum (value, priv->shadow_type);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -165,13 +175,20 @@ gtk_arrow_get_property (GObject         *object,
 static void
 gtk_arrow_init (GtkArrow *arrow)
 {
+  GtkArrowPriv *priv;
+
+  arrow->priv = G_TYPE_INSTANCE_GET_PRIVATE (arrow,
+                                             GTK_TYPE_ARROW,
+                                             GtkArrowPriv);
+  priv = arrow->priv;
+
   gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
 
   GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
   GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
 
-  arrow->arrow_type = GTK_ARROW_RIGHT;
-  arrow->shadow_type = GTK_SHADOW_OUT;
+  priv->arrow_type = GTK_ARROW_RIGHT;
+  priv->shadow_type = GTK_SHADOW_OUT;
 }
 
 /**
@@ -187,12 +204,15 @@ GtkWidget*
 gtk_arrow_new (GtkArrowType  arrow_type,
 	       GtkShadowType shadow_type)
 {
+  GtkArrowPriv *priv;
   GtkArrow *arrow;
 
   arrow = g_object_new (GTK_TYPE_ARROW, NULL);
 
-  arrow->arrow_type = arrow_type;
-  arrow->shadow_type = shadow_type;
+  priv = arrow->priv;
+
+  priv->arrow_type = arrow_type;
+  priv->shadow_type = shadow_type;
 
   return GTK_WIDGET (arrow);
 }
@@ -210,24 +230,27 @@ gtk_arrow_set (GtkArrow      *arrow,
 	       GtkArrowType   arrow_type,
 	       GtkShadowType  shadow_type)
 {
+  GtkArrowPriv *priv;
   GtkWidget *widget;
 
   g_return_if_fail (GTK_IS_ARROW (arrow));
 
-  if (   ((GtkArrowType) arrow->arrow_type != arrow_type)
-      || ((GtkShadowType) arrow->shadow_type != shadow_type))
+  priv = arrow->priv;
+
+  if (priv->arrow_type != arrow_type
+      || priv->shadow_type != shadow_type)
     {
       g_object_freeze_notify (G_OBJECT (arrow));
 
-      if ((GtkArrowType) arrow->arrow_type != arrow_type)
+      if ((GtkArrowType) priv->arrow_type != arrow_type)
         {
-          arrow->arrow_type = arrow_type;
+          priv->arrow_type = arrow_type;
           g_object_notify (G_OBJECT (arrow), "arrow-type");
         }
 
-      if ((GtkShadowType) arrow->shadow_type != shadow_type)
+      if (priv->shadow_type != shadow_type)
         {
-          arrow->shadow_type = shadow_type;
+          priv->shadow_type = shadow_type;
           g_object_notify (G_OBJECT (arrow), "shadow-type");
         }
 
@@ -247,6 +270,7 @@ gtk_arrow_expose (GtkWidget      *widget,
   if (gtk_widget_is_drawable (widget))
     {
       GtkArrow *arrow = GTK_ARROW (widget);
+      GtkArrowPriv *priv = arrow->priv;
       GtkMisc *misc = GTK_MISC (widget);
       GtkShadowType shadow_type;
       gint width, height;
@@ -261,16 +285,16 @@ gtk_arrow_expose (GtkWidget      *widget,
       width = widget->allocation.width - misc->xpad * 2;
       height = widget->allocation.height - misc->ypad * 2;
       extent = MIN (width, height) * arrow_scaling;
-      effective_arrow_type = arrow->arrow_type;
+      effective_arrow_type = priv->arrow_type;
 
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
 	xalign = misc->xalign;
       else
 	{
 	  xalign = 1.0 - misc->xalign;
-	  if (arrow->arrow_type == GTK_ARROW_LEFT)
+	  if (priv->arrow_type == GTK_ARROW_LEFT)
 	    effective_arrow_type = GTK_ARROW_RIGHT;
-	  else if (arrow->arrow_type == GTK_ARROW_RIGHT)
+	  else if (priv->arrow_type == GTK_ARROW_RIGHT)
 	    effective_arrow_type = GTK_ARROW_LEFT;
 	}
 
@@ -279,7 +303,7 @@ gtk_arrow_expose (GtkWidget      *widget,
       y = floor (widget->allocation.y + misc->ypad
 		 + ((widget->allocation.height - extent) * misc->yalign));
 
-      shadow_type = arrow->shadow_type;
+      shadow_type = priv->shadow_type;
 
       if (widget->state == GTK_STATE_ACTIVE)
 	{
diff --git a/gtk/gtkarrow.h b/gtk/gtkarrow.h
index 3140d58..9188448 100644
--- a/gtk/gtkarrow.h
+++ b/gtk/gtkarrow.h
@@ -45,16 +45,16 @@ G_BEGIN_DECLS
 #define GTK_IS_ARROW_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ARROW))
 #define GTK_ARROW_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ARROW, GtkArrowClass))
 
-
-typedef struct _GtkArrow       GtkArrow;
-typedef struct _GtkArrowClass  GtkArrowClass;
+typedef struct _GtkArrow        GtkArrow;
+typedef struct _GtkArrowPriv    GtkArrowPriv;
+typedef struct _GtkArrowClass   GtkArrowClass;
 
 struct _GtkArrow
 {
   GtkMisc misc;
 
-  gint16 GSEAL (arrow_type);
-  gint16 GSEAL (shadow_type);
+  /*< private >*/
+  GtkArrowPriv *priv;
 };
 
 struct _GtkArrowClass
diff --git a/modules/other/gail/gailbutton.c b/modules/other/gail/gailbutton.c
index 9b579e0..33bdaea 100644
--- a/modules/other/gail/gailbutton.c
+++ b/modules/other/gail/gailbutton.c
@@ -234,21 +234,28 @@ gail_button_get_name (AtkObject *obj)
 static gboolean
 gail_button_is_default_press (GtkWidget *widget)
 {
+  GtkArrowType arrow_type;
   GtkWidget  *child;
   GtkWidget  *parent;
   gboolean ret = FALSE;
   const gchar *parent_type_name;
 
   child = GTK_BIN (widget)->child;
-  if (GTK_IS_ARROW (child) &&
-      GTK_ARROW (child)->arrow_type == GTK_ARROW_DOWN)
+  if (GTK_IS_ARROW (child))
     {
-      parent = gtk_widget_get_parent (widget);
-      if (parent)
+      g_object_get (child,
+                    "arrow_type", &arrow_type,
+                    NULL);
+
+      if (arrow_type == GTK_ARROW_DOWN)
         {
-          parent_type_name = g_type_name (G_OBJECT_TYPE (parent));
-          if (strcmp (parent_type_name, "ColorCombo"))
-            return TRUE;
+          parent = gtk_widget_get_parent (widget);
+          if (parent)
+            {
+              parent_type_name = g_type_name (G_OBJECT_TYPE (parent));
+              if (g_strcmp0 (parent_type_name, "ColorCombo"))
+                return TRUE;
+            }
         }
     }
 



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