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



commit 0779d0a37ee0183e461e8a42977f36afb7beefea
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 |  152 +++++++++++++++++++++++++++++---------------------
 gtk/gtkaccellabel.h |   14 +---
 2 files changed, 92 insertions(+), 74 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index da982bd..49cdbee 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -99,6 +99,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,
@@ -115,6 +125,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)
 
@@ -186,6 +197,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
@@ -225,10 +238,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);
@@ -239,11 +252,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;
 }
 
 /**
@@ -284,8 +301,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);
 }
 
@@ -303,7 +320,7 @@ 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;
 }
 
 /**
@@ -320,9 +337,9 @@ 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
@@ -337,8 +354,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);
 }
 
@@ -368,10 +385,14 @@ gtk_accel_label_expose_event (GtkWidget      *widget,
   if (gtk_widget_is_drawable (widget))
     {
       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;
@@ -379,12 +400,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) 
@@ -393,17 +415,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);
 
@@ -411,8 +435,8 @@ 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_paint_layout (gtk_widget_get_style (widget),
+                            gtk_widget_get_window (widget),
                             gtk_widget_get_state (widget),
 			    FALSE,
                             &event->area,
@@ -440,9 +464,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 */
@@ -468,21 +492,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);
@@ -494,10 +518,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));
@@ -510,7 +534,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);
 }
 
@@ -530,22 +554,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);
 	}
@@ -565,10 +589,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
@@ -838,19 +862,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)
 	{
@@ -861,15 +885,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 97a839d..3ad0a37 100644
--- a/gtk/gtkaccellabel.h
+++ b/gtk/gtkaccellabel.h
@@ -48,8 +48,9 @@ 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;
 
 /**
  * GtkAccelLabel:
@@ -60,14 +61,7 @@ typedef struct _GtkAccelLabelClass  GtkAccelLabelClass;
 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]