[gtk+/refactor: 88/110] gtk/gtkspinbutton.c: use accessor functions to access GtkWidget



commit e5a4b91b8835fc9cfb6ece72bfd296c85a163420
Author: Javier Jardón <jjardon gnome org>
Date:   Wed Aug 11 23:00:21 2010 +0200

    gtk/gtkspinbutton.c: use accessor functions to access GtkWidget

 gtk/gtkspinbutton.c |  107 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 70 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 330f327..d42183b 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -579,8 +579,11 @@ gtk_spin_button_unmap (GtkWidget *widget)
 static void
 gtk_spin_button_realize (GtkWidget *widget)
 {
+  GtkAllocation allocation;
+  GtkRequisition requisition;
   GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
   GtkSpinButtonPriv *priv = spin_button->priv;
+  GtkStyle *style;
   GdkWindowAttr attributes;
   gint attributes_mask;
   gboolean return_val;
@@ -603,18 +606,21 @@ gtk_spin_button_realize (GtkWidget *widget)
 
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
 
-  attributes.x = (widget->allocation.width - arrow_size -
-		  2 * widget->style->xthickness);
-  attributes.y = (widget->allocation.height -
-					 widget->requisition.height) / 2;
-  attributes.width = arrow_size + 2 * widget->style->xthickness;
-  attributes.height = widget->requisition.height;
+  style = gtk_widget_get_style (widget);
+  gtk_widget_get_allocation (widget, &allocation);
+  gtk_widget_get_requisition (widget, &requisition);
 
-  priv->panel = gdk_window_new (widget->window,
+  attributes.x = (allocation.width - arrow_size - 2 * style->xthickness);
+  attributes.y = (allocation.height - requisition.height) / 2;
+  attributes.width = arrow_size + 2 * style->xthickness;
+  attributes.height = requisition.height;
+
+  priv->panel = gdk_window_new (gtk_widget_get_window (widget),
                                 &attributes, attributes_mask);
   gdk_window_set_user_data (priv->panel, widget);
 
-  gtk_style_set_background (widget->style, priv->panel, GTK_STATE_NORMAL);
+  gtk_style_set_background (style,
+                            priv->panel, GTK_STATE_NORMAL);
 
   return_val = FALSE;
   g_signal_emit (spin_button, spinbutton_signals[OUTPUT], 0, &return_val);
@@ -670,8 +676,11 @@ gtk_spin_button_size_request (GtkWidget      *widget,
   GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
   GtkSpinButtonPriv *priv = spin_button->priv;
   GtkEntry *entry = GTK_ENTRY (widget);
+  GtkStyle *style;
   gint arrow_size;
 
+  style = gtk_widget_get_style (widget);
+
   arrow_size = spin_button_get_arrow_size (spin_button);
 
   GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->size_request (widget, requisition);
@@ -697,7 +706,7 @@ gtk_spin_button_size_request (GtkWidget      *widget,
 
       context = gtk_widget_get_pango_context (widget);
       metrics = pango_context_get_metrics (context,
-					   widget->style->font_desc,
+                                           style->font_desc,
 					   pango_context_get_language (context));
 
       digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
@@ -727,7 +736,7 @@ gtk_spin_button_size_request (GtkWidget      *widget,
       requisition->width = width + xborder * 2 + inner_border.left + inner_border.right;
     }
 
-  requisition->width += arrow_size + 2 * widget->style->xthickness;
+  requisition->width += arrow_size + 2 * style->xthickness;
 }
 
 static void
@@ -737,21 +746,23 @@ gtk_spin_button_size_allocate (GtkWidget     *widget,
   GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
   GtkSpinButtonPriv *priv = spin->priv;
   GtkAllocation panel_allocation;
+  GtkRequisition requisition;
   gint arrow_size;
   gint panel_width;
 
   arrow_size = spin_button_get_arrow_size (spin);
-  panel_width = arrow_size + 2 * widget->style->xthickness;
-  
-  widget->allocation = *allocation;
-  
+  panel_width = arrow_size + 2 * gtk_widget_get_style (widget)->xthickness;
+
+  gtk_widget_set_allocation (widget, allocation);
+
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     panel_allocation.x = 0;
   else
     panel_allocation.x = allocation->width - panel_width;
 
+  gtk_widget_get_requisition (widget, &requisition);
   panel_allocation.width = panel_width;
-  panel_allocation.height = MIN (widget->requisition.height, allocation->height);
+  panel_allocation.height = MIN (requisition.height, allocation->height);
 
   panel_allocation.y = 0;
 
@@ -799,7 +810,7 @@ gtk_spin_button_expose (GtkWidget      *widget,
 
 	      gdk_drawable_get_size (priv->panel, &width, &height);
 
-	      gtk_paint_box (widget->style, priv->panel,
+              gtk_paint_box (gtk_widget_get_style (widget), priv->panel,
 			     state, shadow_type,
 			     &event->area, widget, "spinbutton",
 			     0, 0, width, height);
@@ -849,6 +860,8 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
   GtkSpinButtonPriv *priv;
   GtkStateType state_type;
   GtkShadowType shadow_type;
+  GtkRequisition requisition;
+  GtkStyle *style;
   GtkWidget *widget;
   gint x;
   gint y;
@@ -863,21 +876,25 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
 
   if (gtk_widget_is_drawable (widget))
     {
-      width = spin_button_get_arrow_size (spin_button) + 2 * widget->style->xthickness;
+      style = gtk_widget_get_style (widget);
+
+      width = spin_button_get_arrow_size (spin_button) + 2 * style->xthickness;
+
+      gtk_widget_get_requisition (widget, &requisition);
 
       if (arrow_type == GTK_ARROW_UP)
 	{
 	  x = 0;
 	  y = 0;
 
-	  height = widget->requisition.height / 2;
+	  height = requisition.height / 2;
 	}
       else
 	{
 	  x = 0;
-	  y = widget->requisition.height / 2;
+	  y = requisition.height / 2;
 
-	  height = (widget->requisition.height + 1) / 2;
+	  height = (requisition.height + 1) / 2;
 	}
 
       if (spin_button_at_limit (spin_button, arrow_type))
@@ -907,14 +924,14 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
 	      shadow_type = GTK_SHADOW_OUT;
 	    }
 	}
-      
-      gtk_paint_box (widget->style, priv->panel,
+
+      gtk_paint_box (style, priv->panel,
 		     state_type, shadow_type,
 		     area, widget,
 		     (arrow_type == GTK_ARROW_UP)? "spinbutton_up" : "spinbutton_down",
 		     x, y, width, height);
 
-      height = widget->requisition.height;
+      height = requisition.height;
 
       if (arrow_type == GTK_ARROW_DOWN)
 	{
@@ -944,7 +961,7 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
       height = h;
       width = w;
 
-      gtk_paint_arrow (widget->style, priv->panel,
+      gtk_paint_arrow (style, priv->panel,
 		       state_type, shadow_type, 
 		       area, widget, "spinbutton",
 		       arrow_type, TRUE, 
@@ -961,6 +978,7 @@ gtk_spin_button_enter_notify (GtkWidget        *widget,
 
   if (event->window == priv->panel)
     {
+      GtkRequisition requisition;
       GdkDevice *device;
       gint x;
       gint y;
@@ -968,7 +986,8 @@ gtk_spin_button_enter_notify (GtkWidget        *widget,
       device = gdk_event_get_device ((GdkEvent *) event);
       gdk_window_get_device_position (priv->panel, device, &x, &y, NULL);
 
-      if (y <= widget->requisition.height / 2)
+      gtk_widget_get_requisition (widget, &requisition);
+      if (y <= requisition.height / 2)
 	priv->in_child = GTK_ARROW_UP;
       else
 	priv->in_child = GTK_ARROW_DOWN;
@@ -1042,7 +1061,8 @@ gtk_spin_button_style_set (GtkWidget *widget,
   GtkSpinButtonPriv *priv = spin->priv;
 
   if (previous_style && gtk_widget_get_realized (widget))
-    gtk_style_set_background (widget->style, priv->panel, GTK_STATE_NORMAL);
+    gtk_style_set_background (gtk_widget_get_style (widget),
+                              priv->panel, GTK_STATE_NORMAL);
 
   GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->style_set (widget, previous_style);
 }
@@ -1137,14 +1157,17 @@ gtk_spin_button_button_press (GtkWidget      *widget,
     {
       if (event->window == priv->panel)
 	{
+          GtkRequisition requisition;
+
 	  if (!gtk_widget_has_focus (widget))
 	    gtk_widget_grab_focus (widget);
 	  priv->button = event->button;
 	  
 	  if (GTK_ENTRY (widget)->editable)
 	    gtk_spin_button_update (spin);
-	  
-	  if (event->y <= widget->requisition.height / 2)
+
+          gtk_widget_get_requisition (widget, &requisition);
+	  if (event->y <= requisition.height / 2)
 	    {
 	      if (event->button == 1)
 		start_spinning (spin, GTK_ARROW_UP, priv->adjustment->step_increment);
@@ -1188,12 +1211,16 @@ gtk_spin_button_button_release (GtkWidget      *widget,
 
       if (event->button == 3)
 	{
+          GtkRequisition requisition;
+
+          gtk_widget_get_requisition (widget, &requisition);
+
 	  if (event->y >= 0 && event->x >= 0 && 
-	      event->y <= widget->requisition.height &&
-	      event->x <= arrow_size + 2 * widget->style->xthickness)
+	      event->y <= requisition.height &&
+	      event->x <= arrow_size + 2 * gtk_widget_get_style (widget)->xthickness)
 	    {
 	      if (click_child == GTK_ARROW_UP &&
-		  event->y <= widget->requisition.height / 2)
+                  event->y <= requisition.height / 2)
 		{
 		  gdouble diff;
 
@@ -1202,7 +1229,7 @@ gtk_spin_button_button_release (GtkWidget      *widget,
 		    gtk_spin_button_real_spin (spin, diff);
 		}
 	      else if (click_child == GTK_ARROW_DOWN &&
-		       event->y > widget->requisition.height / 2)
+                       event->y > requisition.height / 2)
 		{
 		  gdouble diff;
 
@@ -1232,17 +1259,20 @@ gtk_spin_button_motion_notify (GtkWidget      *widget,
 
   if (event->window == priv->panel)
     {
+      GtkRequisition requisition;
       gint y = event->y;
 
       gdk_event_request_motions (event);
-  
-      if (y <= widget->requisition.height / 2 && 
+
+      gtk_widget_get_requisition (widget, &requisition);
+
+      if (y <= requisition.height / 2 &&
 	  priv->in_child == GTK_ARROW_DOWN)
 	{
 	  priv->in_child = GTK_ARROW_UP;
 	  gtk_widget_queue_draw (GTK_WIDGET (spin));
 	}
-      else if (y > widget->requisition.height / 2 && 
+      else if (y > requisition.height / 2 &&
 	  priv->in_child == GTK_ARROW_UP)
 	{
 	  priv->in_child = GTK_ARROW_DOWN;
@@ -1475,7 +1505,7 @@ gtk_spin_button_get_text_area_size (GtkEntry *entry,
   GTK_ENTRY_CLASS (gtk_spin_button_parent_class)->get_text_area_size (entry, x, y, width, height);
 
   arrow_size = spin_button_get_arrow_size (GTK_SPIN_BUTTON (entry));
-  panel_width = arrow_size + 2 * GTK_WIDGET (entry)->style->xthickness;
+  panel_width = arrow_size + 2 * gtk_widget_get_style (GTK_WIDGET (entry))->xthickness;
 
   if (width)
     *width -= panel_width;
@@ -2221,9 +2251,12 @@ gtk_spin_button_get_wrap (GtkSpinButton *spin_button)
 static gint
 spin_button_get_arrow_size (GtkSpinButton *spin_button)
 {
-  gint size = pango_font_description_get_size (GTK_WIDGET (spin_button)->style->font_desc);
+  GtkStyle *style;
+  gint size;
   gint arrow_size;
 
+  style = gtk_widget_get_style (GTK_WIDGET (spin_button));
+  size = pango_font_description_get_size (style->font_desc);
   arrow_size = MAX (PANGO_PIXELS (size), MIN_ARROW_WIDTH);
 
   return arrow_size - arrow_size % 2; /* force even */



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