[gtk+/gtk-2-90: 118/146] Move GSEAL'd members of GtkAccelLabel into private struct.



commit 02211b7995e4b33728a0555575c0e8a98d4db49c
Author: Cody Russell <bratsche gnome org>
Date:   Thu Oct 22 16:05:52 2009 -0500

    Move GSEAL'd members of GtkAccelLabel into private struct.

 gtk/gtkaccellabel.c |  156 +++++++++++++++++++++++++++++---------------------
 gtk/gtkaccellabel.h |   14 +---
 2 files changed, 94 insertions(+), 76 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 1c71935..65f3d25 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -44,6 +44,16 @@ enum {
   PROP_ACCEL_WIDGET
 };
 
+struct _GtkAccelLabelPrivate
+{
+  guint          accel_padding;      /* should be style property? */
+  GtkWidget     *accel_widget;       /* done*/
+  GClosure      *accel_closure;      /* has set function */
+  GtkAccelGroup *accel_group;        /* set by set_accel_closure() */
+  gchar         *accel_string;       /* has set function */
+  guint16        accel_string_width; /* seems to be private */
+};
+
 static void         gtk_accel_label_set_property (GObject            *object,
 						  guint               prop_id,
 						  const GValue       *value,
@@ -60,6 +70,7 @@ static gboolean     gtk_accel_label_expose_event (GtkWidget          *widget,
 						  GdkEventExpose     *event);
 static const gchar *gtk_accel_label_get_string   (GtkAccelLabel      *accel_label);
 
+#define GTK_ACCEL_LABEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ACCEL_LABEL, GtkAccelLabelPrivate))
 
 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
 
@@ -131,6 +142,8 @@ gtk_accel_label_class_init (GtkAccelLabelClass *class)
                                                         P_("The widget to be monitored for accelerator changes"),
                                                         GTK_TYPE_WIDGET,
                                                         GTK_PARAM_READWRITE));
+
+  g_type_class_add_private (gobject_class, sizeof (GtkAccelLabelPrivate));
 }
 
 static void
@@ -170,10 +183,10 @@ gtk_accel_label_get_property (GObject    *object,
   switch (prop_id)
     {
     case PROP_ACCEL_CLOSURE:
-      g_value_set_boxed (value, accel_label->accel_closure);
+      g_value_set_boxed (value, accel_label->priv->accel_closure);
       break;
     case PROP_ACCEL_WIDGET:
-      g_value_set_object (value, accel_label->accel_widget);
+      g_value_set_object (value, accel_label->priv->accel_widget);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -184,11 +197,15 @@ gtk_accel_label_get_property (GObject    *object,
 static void
 gtk_accel_label_init (GtkAccelLabel *accel_label)
 {
-  accel_label->accel_padding = 3;
-  accel_label->accel_widget = NULL;
-  accel_label->accel_closure = NULL;
-  accel_label->accel_group = NULL;
-  accel_label->accel_string = NULL;
+  GtkAccelLabelPrivate *priv = GTK_ACCEL_LABEL_GET_PRIVATE (accel_label);
+
+  priv->accel_padding = 3;
+  priv->accel_widget = NULL;
+  priv->accel_closure = NULL;
+  priv->accel_group = NULL;
+  priv->accel_string = NULL;
+
+  accel_label->priv = priv;
 }
 
 GtkWidget*
@@ -221,8 +238,8 @@ gtk_accel_label_finalize (GObject *object)
 {
   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
 
-  g_free (accel_label->accel_string);
-  
+  g_free (accel_label->priv->accel_string);
+
   G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
 }
 
@@ -241,16 +258,16 @@ gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
 {
   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
 
-  return accel_label->accel_widget;
+  return accel_label->priv->accel_widget;
 }
 
 guint
 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
 {
   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
-  
-  return (accel_label->accel_string_width +
-	  (accel_label->accel_string_width ? accel_label->accel_padding : 0));
+
+  return (accel_label->priv->accel_string_width +
+	  (accel_label->priv->accel_string_width ? accel_label->priv->accel_padding : 0));
 }
 
 static void
@@ -265,8 +282,8 @@ gtk_accel_label_size_request (GtkWidget	     *widget,
 
   layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
   pango_layout_get_pixel_size (layout, &width, NULL);
-  accel_label->accel_string_width = width;
-  
+  accel_label->priv->accel_string_width = width;
+
   g_object_unref (layout);
 }
 
@@ -293,13 +310,17 @@ gtk_accel_label_expose_event (GtkWidget      *widget,
 
   direction = gtk_widget_get_direction (widget);
 
-  if (GTK_WIDGET_DRAWABLE (accel_label))
+  if (gtk_widget_is_drawable (accel_label))
     {
       guint ac_width;
-      
+      GtkAllocation allocation;
+      GtkRequisition requisition;
+
       ac_width = gtk_accel_label_get_accel_width (accel_label);
-      
-      if (widget->allocation.width >= widget->requisition.width + ac_width)
+      gtk_widget_get_allocation (widget, &allocation);
+      gtk_widget_size_request (widget, &requisition);
+
+      if (allocation.width >= requisition.width + ac_width)
 	{
 	  PangoLayout *label_layout;
 	  PangoLayout *accel_layout;
@@ -307,12 +328,13 @@ gtk_accel_label_expose_event (GtkWidget      *widget,
 
 	  gint x;
 	  gint y;
-	  
+	  gint xpad;
+
 	  label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
 
 	  if (direction == GTK_TEXT_DIR_RTL)
-	    widget->allocation.x += ac_width;
-	  widget->allocation.width -= ac_width;
+	    allocation.x += ac_width;
+	  allocation.width -= ac_width;
 	  if (gtk_label_get_ellipsize (label))
 	    pango_layout_set_width (label_layout,
 				    pango_layout_get_width (label_layout) 
@@ -321,17 +343,19 @@ gtk_accel_label_expose_event (GtkWidget      *widget,
 	  if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
 	    GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
 	  if (direction == GTK_TEXT_DIR_RTL)
-	    widget->allocation.x -= ac_width;
-	  widget->allocation.width += ac_width;
+	    allocation.x -= ac_width;
+	  allocation.width += ac_width;
 	  if (gtk_label_get_ellipsize (label))
 	    pango_layout_set_width (label_layout,
 				    pango_layout_get_width (label_layout) 
 				    + ac_width * PANGO_SCALE);
-	  
+
+	  gtk_misc_get_padding (misc, &xpad, NULL);
+
 	  if (direction == GTK_TEXT_DIR_RTL)
-	    x = widget->allocation.x + misc->xpad;
+	    x = allocation.x + xpad;
 	  else
-	    x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
+	    x = allocation.x + allocation.width - xpad - ac_width;
 
 	  gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
 
@@ -339,9 +363,9 @@ gtk_accel_label_expose_event (GtkWidget      *widget,
 
 	  y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
 
-          gtk_paint_layout (widget->style,
-                            widget->window,
-                            GTK_WIDGET_STATE (widget),
+          gtk_paint_layout (gtk_widget_get_style (widget),
+                            gtk_widget_get_window (widget),
+                            gtk_widget_get_state (widget),
 			    FALSE,
                             &event->area,
                             widget,
@@ -368,9 +392,9 @@ refetch_widget_accel_closure (GtkAccelLabel *accel_label)
   GList *clist, *list;
   
   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
-  g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
+  g_return_if_fail (GTK_IS_WIDGET (accel_label->priv->accel_widget));
   
-  clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
+  clist = gtk_widget_list_accel_closures (accel_label->priv->accel_widget);
   for (list = clist; list; list = list->next)
     {
       /* we just take the first closure used */
@@ -396,21 +420,21 @@ gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
   if (accel_widget)
     g_return_if_fail (GTK_IS_WIDGET (accel_widget));
     
-  if (accel_widget != accel_label->accel_widget)
+  if (accel_widget != accel_label->priv->accel_widget)
     {
-      if (accel_label->accel_widget)
+      if (accel_label->priv->accel_widget)
 	{
 	  gtk_accel_label_set_accel_closure (accel_label, NULL);
-	  g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
+	  g_signal_handlers_disconnect_by_func (accel_label->priv->accel_widget,
 						refetch_widget_accel_closure,
 						accel_label);
-	  g_object_unref (accel_label->accel_widget);
+	  g_object_unref (accel_label->priv->accel_widget);
 	}
-      accel_label->accel_widget = accel_widget;
-      if (accel_label->accel_widget)
+      accel_label->priv->accel_widget = accel_widget;
+      if (accel_label->priv->accel_widget)
 	{
-	  g_object_ref (accel_label->accel_widget);
-	  g_signal_connect_object (accel_label->accel_widget, "accel-closures-changed",
+	  g_object_ref (accel_label->priv->accel_widget);
+	  g_signal_connect_object (accel_label->priv->accel_widget, "accel-closures-changed",
 				   G_CALLBACK (refetch_widget_accel_closure),
 				   accel_label, G_CONNECT_SWAPPED);
 	  refetch_widget_accel_closure (accel_label);
@@ -422,10 +446,10 @@ gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
 static void
 gtk_accel_label_reset (GtkAccelLabel *accel_label)
 {
-  if (accel_label->accel_string)
+  if (accel_label->priv->accel_string)
     {
-      g_free (accel_label->accel_string);
-      accel_label->accel_string = NULL;
+      g_free (accel_label->priv->accel_string);
+      accel_label->priv->accel_string = NULL;
     }
   
   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
@@ -438,7 +462,7 @@ check_accel_changed (GtkAccelGroup  *accel_group,
 		     GClosure       *accel_closure,
 		     GtkAccelLabel  *accel_label)
 {
-  if (accel_closure == accel_label->accel_closure)
+  if (accel_closure == accel_label->priv->accel_closure)
     gtk_accel_label_reset (accel_label);
 }
 
@@ -458,22 +482,22 @@ gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
   if (accel_closure)
     g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
 
-  if (accel_closure != accel_label->accel_closure)
+  if (accel_closure != accel_label->priv->accel_closure)
     {
-      if (accel_label->accel_closure)
+      if (accel_label->priv->accel_closure)
 	{
-	  g_signal_handlers_disconnect_by_func (accel_label->accel_group,
+	  g_signal_handlers_disconnect_by_func (accel_label->priv->accel_group,
 						check_accel_changed,
 						accel_label);
-	  accel_label->accel_group = NULL;
-	  g_closure_unref (accel_label->accel_closure);
+	  accel_label->priv->accel_group = NULL;
+	  g_closure_unref (accel_label->priv->accel_closure);
 	}
-      accel_label->accel_closure = accel_closure;
-      if (accel_label->accel_closure)
+      accel_label->priv->accel_closure = accel_closure;
+      if (accel_label->priv->accel_closure)
 	{
-	  g_closure_ref (accel_label->accel_closure);
-	  accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
-	  g_signal_connect_object (accel_label->accel_group, "accel-changed",
+	  g_closure_ref (accel_label->priv->accel_closure);
+	  accel_label->priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
+	  g_signal_connect_object (accel_label->priv->accel_group, "accel-changed",
 				   G_CALLBACK (check_accel_changed),
 				   accel_label, 0);
 	}
@@ -493,10 +517,10 @@ find_accel (GtkAccelKey *key,
 static const gchar *
 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
 {
-  if (!accel_label->accel_string)
+  if (!accel_label->priv->accel_string)
     gtk_accel_label_refetch (accel_label);
   
-  return accel_label->accel_string;
+  return accel_label->priv->accel_string;
 }
 
 /* Underscores in key names are better displayed as spaces
@@ -756,19 +780,19 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
 
   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
 
-  if (accel_label->accel_string)
+  if (accel_label->priv->accel_string)
     {
-      g_free (accel_label->accel_string);
-      accel_label->accel_string = NULL;
+      g_free (accel_label->priv->accel_string);
+      accel_label->priv->accel_string = NULL;
     }
 
   g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
                 "gtk-enable-accels", &enable_accels,
                 NULL);
 
-  if (enable_accels && accel_label->accel_closure)
+  if (enable_accels && accel_label->priv->accel_closure)
     {
-      GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
+      GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
 
       if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
 	{
@@ -779,15 +803,15 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label)
 	  tmp = _gtk_accel_label_class_get_accelerator_label (klass,
 							      key->accel_key,
 							      key->accel_mods);
-	  accel_label->accel_string = g_strconcat ("   ", tmp, NULL);
+	  accel_label->priv->accel_string = g_strconcat ("   ", tmp, NULL);
 	  g_free (tmp);
 	}
-      if (!accel_label->accel_string)
-	accel_label->accel_string = g_strdup ("-/-");
+      if (!accel_label->priv->accel_string)
+	accel_label->priv->accel_string = g_strdup ("-/-");
     }
   
-  if (!accel_label->accel_string)
-    accel_label->accel_string = g_strdup ("");
+  if (!accel_label->priv->accel_string)
+    accel_label->priv->accel_string = g_strdup ("");
 
   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
 
diff --git a/gtk/gtkaccellabel.h b/gtk/gtkaccellabel.h
index bc6efc5..6903bc5 100644
--- a/gtk/gtkaccellabel.h
+++ b/gtk/gtkaccellabel.h
@@ -48,20 +48,14 @@ G_BEGIN_DECLS
 #define GTK_ACCEL_LABEL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ACCEL_LABEL, GtkAccelLabelClass))
 
 
-typedef struct _GtkAccelLabel	    GtkAccelLabel;
-typedef struct _GtkAccelLabelClass  GtkAccelLabelClass;
+typedef struct _GtkAccelLabel	     GtkAccelLabel;
+typedef struct _GtkAccelLabelClass   GtkAccelLabelClass;
+typedef struct _GtkAccelLabelPrivate GtkAccelLabelPrivate;
 
 struct _GtkAccelLabel
 {
   GtkLabel label;
-
-  guint          GSEAL (gtk_reserved);
-  guint          GSEAL (accel_padding);      /* should be style property? */
-  GtkWidget     *GSEAL (accel_widget);       /* done*/
-  GClosure      *GSEAL (accel_closure);      /* has set function */
-  GtkAccelGroup *GSEAL (accel_group);        /* set by set_accel_closure() */
-  gchar         *GSEAL (accel_string);       /* has set function */
-  guint16        GSEAL (accel_string_width); /* seems to be private */
+  GtkAccelLabelPrivate *priv;
 };
 
 struct _GtkAccelLabelClass



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