[gtk+/refactor: 77/96] gtk/gtkcombobox.c: use accessor functions to access GtkWidget



commit 612cf2c2e29bec9a4a9c1e3128c4b7de932ef57e
Author: Javier Jardón <jjardon gnome org>
Date:   Wed Aug 11 23:14:32 2010 +0200

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

 gtk/gtkcombobox.c |  170 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 105 insertions(+), 65 deletions(-)
---
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index e8a535f..652a45a 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -1104,7 +1104,7 @@ gtk_combo_box_state_changed (GtkWidget    *widget,
     {
       if (priv->tree_view && priv->cell_view)
 	gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view), 
-					    &widget->style->base[gtk_widget_get_state (widget)]);
+					    &gtk_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
     }
 
   gtk_widget_queue_draw (widget);
@@ -1188,7 +1188,7 @@ gtk_combo_box_style_set (GtkWidget *widget,
 
   if (priv->tree_view && priv->cell_view)
     gtk_cell_view_set_background_color (GTK_CELL_VIEW (priv->cell_view), 
-					&widget->style->base[gtk_widget_get_state (widget)]);
+					&gtk_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
 
   child = gtk_bin_get_child (GTK_BIN (combo_box));
   if (GTK_IS_ENTRY (child))
@@ -1219,7 +1219,8 @@ gtk_combo_box_add (GtkContainer *container,
   GtkComboBox *combo_box = GTK_COMBO_BOX (container);
   GtkComboBoxPrivate *priv = combo_box->priv;
 
-  if (priv->cell_view && priv->cell_view->parent)
+  if (priv->cell_view &&
+      gtk_widget_get_parent (priv->cell_view))
     {
       gtk_widget_unparent (priv->cell_view);
       _gtk_bin_set_child (GTK_BIN (container), NULL);
@@ -1237,8 +1238,8 @@ gtk_combo_box_add (GtkContainer *container,
 
       if (!priv->tree_view && priv->separator)
         {
-	  gtk_container_remove (GTK_CONTAINER (priv->separator->parent),
-				priv->separator);
+          gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),
+                                priv->separator);
 	  priv->separator = NULL;
 
           gtk_widget_queue_resize (GTK_WIDGET (container));
@@ -1483,6 +1484,7 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
 				   gpointer  user_data)
 {
   GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
+  GtkAllocation child_allocation;
   gint sx, sy;
   GtkWidget *child;
   GtkRequisition req;
@@ -1495,28 +1497,31 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
 
   sx = sy = 0;
 
+  gtk_widget_get_allocation (child, &child_allocation);
+
   if (!gtk_widget_get_has_window (child))
     {
-      sx += child->allocation.x;
-      sy += child->allocation.y;
+      sx += child_allocation.x;
+      sy += child_allocation.y;
     }
 
-  gdk_window_get_root_coords (child->window, sx, sy, &sx, &sy);
+  gdk_window_get_root_coords (gtk_widget_get_window (child),
+                              sx, sy, &sx, &sy);
 
   if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
-    sx -= GTK_WIDGET (combo_box)->style->xthickness;
+    sx -= gtk_widget_get_style (GTK_WIDGET (combo_box))->xthickness;
 
   gtk_widget_size_request (GTK_WIDGET (menu), &req);
 
   if (gtk_widget_get_direction (GTK_WIDGET (combo_box)) == GTK_TEXT_DIR_LTR)
     *x = sx;
   else
-    *x = sx + child->allocation.width - req.width;
+    *x = sx + child_allocation.width - req.width;
   *y = sy;
 
   screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
   monitor_num = gdk_screen_get_monitor_at_window (screen, 
-						  GTK_WIDGET (combo_box)->window);
+                                                  gtk_widget_get_window (GTK_WIDGET (combo_box)));
   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
   
   if (*x < monitor.x)
@@ -1524,12 +1529,12 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
   else if (*x + req.width > monitor.x + monitor.width)
     *x = monitor.x + monitor.width - req.width;
   
-  if (monitor.y + monitor.height - *y - child->allocation.height >= req.height)
-    *y += child->allocation.height;
+  if (monitor.y + monitor.height - *y - child_allocation.height >= req.height)
+    *y += child_allocation.height;
   else if (*y - monitor.y >= req.height)
     *y -= req.height;
-  else if (monitor.y + monitor.height - *y - child->allocation.height > *y - monitor.y) 
-    *y += child->allocation.height;
+  else if (monitor.y + monitor.height - *y - child_allocation.height > *y - monitor.y)
+    *y += child_allocation.height;
   else
     *y -= req.height;
 
@@ -1543,6 +1548,7 @@ gtk_combo_box_menu_position_over (GtkMenu  *menu,
 				  gboolean *push_in,
 				  gpointer  user_data)
 {
+  GtkAllocation allocation;
   GtkComboBox *combo_box;
   GtkWidget *active;
   GtkWidget *child;
@@ -1562,8 +1568,10 @@ gtk_combo_box_menu_position_over (GtkMenu  *menu,
 
   active = gtk_menu_get_active (GTK_MENU (combo_box->priv->popup_widget));
 
-  menu_xpos = widget->allocation.x;
-  menu_ypos = widget->allocation.y + widget->allocation.height / 2 - 2;
+  gtk_widget_get_allocation (widget, &allocation);
+
+  menu_xpos = allocation.x;
+  menu_ypos = allocation.y + allocation.height / 2 - 2;
 
   if (active != NULL)
     {
@@ -1589,9 +1597,10 @@ gtk_combo_box_menu_position_over (GtkMenu  *menu,
     }
 
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-    menu_xpos = menu_xpos + widget->allocation.width - menu_width;
+    menu_xpos = menu_xpos + allocation.width - menu_width;
 
-  gdk_window_get_root_coords (widget->window, menu_xpos, menu_ypos,
+  gdk_window_get_root_coords (gtk_widget_get_window (widget),
+                              menu_xpos, menu_ypos,
 			      &menu_xpos, &menu_ypos);
 
   /* Clamp the position on screen */
@@ -1646,27 +1655,34 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
 			     gint        *height)
 {
   GtkComboBoxPrivate *priv = combo_box->priv;
+  GtkAllocation allocation;
   GdkScreen *screen;
   gint monitor_num;
   GdkRectangle monitor;
   GtkRequisition popup_req;
   GtkPolicyType hpolicy, vpolicy;
-  
+  GdkWindow *window;
+
   /* under windows, the drop down list is as wide as the combo box itself.
      see bug #340204 */
-  GtkWidget *sample = GTK_WIDGET (combo_box);
+  GtkWidget *widget = GTK_WIDGET (combo_box);
 
   *x = *y = 0;
 
-  if (!gtk_widget_get_has_window (sample))
+  gtk_widget_get_allocation (widget, &allocation);
+
+  if (!gtk_widget_get_has_window (widget))
     {
-      *x += sample->allocation.x;
-      *y += sample->allocation.y;
+      *x += allocation.x;
+      *y += allocation.y;
     }
-  
-  gdk_window_get_root_coords (sample->window, *x, *y, x, y);
 
-  *width = sample->allocation.width;
+  window = gtk_widget_get_window (widget);
+
+  gdk_window_get_root_coords (gtk_widget_get_window (widget),
+                              *x, *y, x, y);
+
+  *width = allocation.width;
 
   hpolicy = vpolicy = GTK_POLICY_NEVER;
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
@@ -1684,8 +1700,7 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
   *height = popup_req.height;
 
   screen = gtk_widget_get_screen (GTK_WIDGET (combo_box));
-  monitor_num = gdk_screen_get_monitor_at_window (screen, 
-						  GTK_WIDGET (combo_box)->window);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, window);
   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
   if (*x < monitor.x)
@@ -1693,13 +1708,13 @@ gtk_combo_box_list_position (GtkComboBox *combo_box,
   else if (*x + *width > monitor.x + monitor.width)
     *x = monitor.x + monitor.width - *width;
   
-  if (*y + sample->allocation.height + *height <= monitor.y + monitor.height)
-    *y += sample->allocation.height;
+  if (*y + allocation.height + *height <= monitor.y + monitor.height)
+    *y += allocation.height;
   else if (*y - *height >= monitor.y)
     *y -= *height;
-  else if (monitor.y + monitor.height - (*y + sample->allocation.height) > *y - monitor.y)
+  else if (monitor.y + monitor.height - (*y + allocation.height) > *y - monitor.y)
     {
-      *y += sample->allocation.height;
+      *y += allocation.height;
       *height = monitor.y + monitor.height - *y;
     }
   else 
@@ -1851,7 +1866,10 @@ gtk_combo_box_menu_popup (GtkComboBox *combo_box,
   
   if (priv->wrap_width == 0)
     {
-      width = GTK_WIDGET (combo_box)->allocation.width;
+      GtkAllocation allocation;
+
+      gtk_widget_get_allocation (GTK_WIDGET (combo_box), &allocation);
+      width = allocation.width;
       gtk_widget_set_size_request (priv->popup_widget, -1, -1);
       gtk_widget_size_request (priv->popup_widget, &requisition);
       
@@ -2008,7 +2026,7 @@ gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
   if (!gtk_widget_has_focus (priv->tree_view))
     gtk_widget_grab_focus (priv->tree_view);
 
-  if (!popup_grab_on_window (priv->popup_window->window,
+  if (!popup_grab_on_window (gtk_widget_get_window (priv->popup_window),
 			     keyboard, pointer, time))
     {
       gtk_widget_hide (priv->popup_window);
@@ -2169,6 +2187,8 @@ gtk_combo_box_size_request (GtkWidget      *widget,
   gint arrow_size;
   guint border_width;
   GtkRequisition bin_req;
+  GtkStyle *style;
+  GtkWidget *child;
   PangoContext *context;
   PangoFontMetrics *metrics;
   PangoFontDescription *font_desc;
@@ -2188,7 +2208,8 @@ gtk_combo_box_size_request (GtkWidget      *widget,
 			"arrow-size", &arrow_size,
 			NULL);
 
-  font_desc = gtk_bin_get_child (GTK_BIN (widget))->style->font_desc;
+  child = gtk_bin_get_child (GTK_BIN (widget));
+  font_desc = gtk_widget_get_style (child)->font_desc;
   context = gtk_widget_get_pango_context (widget);
   metrics = pango_context_get_metrics (context, font_desc,
 				       pango_context_get_language (context));
@@ -2211,8 +2232,9 @@ gtk_combo_box_size_request (GtkWidget      *widget,
 
           gtk_widget_size_request (priv->button, &button_req);
           border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-          xthickness = priv->button->style->xthickness;
-          ythickness = priv->button->style->ythickness;
+          style = gtk_widget_get_style (priv->button);
+          xthickness = style->xthickness;
+          ythickness = style->ythickness;
 
           bin_req.width = MAX (bin_req.width, priv->width);
           bin_req.height = MAX (bin_req.height, priv->height);
@@ -2258,8 +2280,9 @@ gtk_combo_box_size_request (GtkWidget      *widget,
 	    {
               border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
 
-	      requisition->width += 2 * (border_width + GTK_WIDGET (priv->cell_view_frame)->style->xthickness);
-	      requisition->height += 2 * (border_width + GTK_WIDGET (priv->cell_view_frame)->style->ythickness);
+              style = gtk_widget_get_style (priv->cell_view_frame);
+	      requisition->width += 2 * (border_width + style->xthickness);
+	      requisition->height += 2 * (border_width + style->ythickness);
 	    }
         }
 
@@ -2272,8 +2295,9 @@ gtk_combo_box_size_request (GtkWidget      *widget,
 
   if (GTK_SHADOW_NONE != priv->shadow_type)
     {
-      requisition->height += 2 * widget->style->ythickness;
-      requisition->width += 2 * widget->style->xthickness;
+      style = gtk_widget_get_style (widget);
+      requisition->height += 2 * style->ythickness;
+      requisition->width += 2 * style->xthickness;
     }
 }
 
@@ -2304,20 +2328,22 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
   gint focus_width, focus_pad;
   GtkAllocation child;
   GtkRequisition req;
+  GtkStyle *style;
   gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
 
-  widget->allocation = *allocation;
+  gtk_widget_set_allocation (widget, allocation);
   child_widget = gtk_bin_get_child (GTK_BIN (widget));
 
-  gtk_widget_style_get (GTK_WIDGET (widget),
+  style = gtk_widget_get_style (widget);
+  gtk_widget_style_get (widget,
 			"focus-line-width", &focus_width,
 			"focus-padding", &focus_pad,
 			NULL);
 
   if (GTK_SHADOW_NONE != priv->shadow_type)
     {
-      shadow_width = widget->style->xthickness;
-      shadow_height = widget->style->ythickness;
+      shadow_width = style->xthickness;
+      shadow_height = style->ythickness;
     }
   else
     {
@@ -2343,8 +2369,9 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
 
           /* set some things ready */
           border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
-          xthickness = priv->button->style->xthickness;
-          ythickness = priv->button->style->ythickness;
+          style = gtk_widget_get_style (priv->button);
+          xthickness = style->xthickness;
+          ythickness = style->ythickness;
 
           child.x = allocation->x;
           child.y = allocation->y;
@@ -2402,7 +2429,10 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
               gtk_menu_reposition (GTK_MENU (priv->popup_widget));
               if (priv->wrap_width == 0)
                 {
-                  width = GTK_WIDGET (combo_box)->allocation.width;
+                  GtkAllocation combo_box_allocation;
+
+                  gtk_widget_get_allocation (GTK_WIDGET (combo_box), &combo_box_allocation);
+                  width = combo_box_allocation.width;
                   gtk_widget_set_size_request (priv->popup_widget, -1, -1);
                   gtk_widget_size_request (priv->popup_widget, &requisition);
                   gtk_widget_set_size_request (priv->popup_widget,
@@ -2463,8 +2493,9 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
           if (priv->has_frame)
             {
               border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-              delta_x = border_width + GTK_WIDGET (priv->cell_view_frame)->style->xthickness;
-              delta_y = border_width + GTK_WIDGET (priv->cell_view_frame)->style->ythickness;
+              style = gtk_widget_get_style (priv->cell_view_frame);
+              delta_x = border_width + style->xthickness;
+              delta_y = border_width + style->ythickness;
 
               child.x += delta_x;
               child.y += delta_y;
@@ -2592,11 +2623,16 @@ gtk_combo_box_expose_event (GtkWidget      *widget,
   if (gtk_widget_is_drawable (widget) &&
       GTK_SHADOW_NONE != priv->shadow_type)
     {
-      gtk_paint_shadow (widget->style, widget->window,
+      GtkAllocation allocation;
+
+      gtk_widget_get_allocation (widget, &allocation);
+
+      gtk_paint_shadow (gtk_widget_get_style (widget),
+                        gtk_widget_get_window (widget),
                         GTK_STATE_NORMAL, priv->shadow_type,
                         NULL, widget, "combobox",
-                        widget->allocation.x, widget->allocation.y,
-                        widget->allocation.width, widget->allocation.height);
+                        allocation.x, allocation.y,
+                        allocation.width, allocation.height);
     }
 
   gtk_container_propagate_expose (GTK_CONTAINER (widget),
@@ -3711,7 +3747,8 @@ gtk_combo_box_menu_row_changed (GtkTreeModel *model,
       gtk_combo_box_menu_row_inserted (model, path, iter, combo_box);
     }
 
-  if (priv->wrap_width && item->parent == priv->popup_widget)
+  if (priv->wrap_width &&
+      gtk_widget_get_parent (item) == priv->popup_widget)
     {
       GtkWidget *pitem = NULL;
       GtkTreePath *prev;
@@ -4130,23 +4167,26 @@ gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
 				gint         x, 
 				gint         y)
 {
-  GtkWidget *tree_view = combo_box->priv->tree_view;
   GtkAdjustment *adj;
+  GtkAllocation allocation;
+  GtkWidget *tree_view = combo_box->priv->tree_view;
   gdouble value;
 
+  gtk_widget_get_allocation (tree_view, &allocation);
+
   adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
   if (adj && adj->upper - adj->lower > adj->page_size)
     {
-      if (x <= tree_view->allocation.x && 
+      if (x <= allocation.x &&
 	  adj->lower < adj->value)
 	{
-	  value = adj->value - (tree_view->allocation.x - x + 1);
+	  value = adj->value - (allocation.x - x + 1);
 	  gtk_adjustment_set_value (adj, value);
 	}
-      else if (x >= tree_view->allocation.x + tree_view->allocation.width &&
+      else if (x >= allocation.x + allocation.width &&
 	       adj->upper - adj->page_size > adj->value)
 	{
-	  value = adj->value + (x - tree_view->allocation.x - tree_view->allocation.width + 1);
+	  value = adj->value + (x - allocation.x - allocation.width + 1);
 	  gtk_adjustment_set_value (adj, MAX (value, 0.0));
 	}
     }
@@ -4154,16 +4194,16 @@ gtk_combo_box_list_auto_scroll (GtkComboBox *combo_box,
   adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (combo_box->priv->scrolled_window));
   if (adj && adj->upper - adj->lower > adj->page_size)
     {
-      if (y <= tree_view->allocation.y && 
+      if (y <= allocation.y &&
 	  adj->lower < adj->value)
 	{
-	  value = adj->value - (tree_view->allocation.y - y + 1);
+	  value = adj->value - (allocation.y - y + 1);
 	  gtk_adjustment_set_value (adj, value);
 	}
-      else if (y >= tree_view->allocation.height &&
+      else if (y >= allocation.height &&
 	       adj->upper - adj->page_size > adj->value)
 	{
-	  value = adj->value + (y - tree_view->allocation.height + 1);
+	  value = adj->value + (y - allocation.height + 1);
 	  gtk_adjustment_set_value (adj, MAX (value, 0.0));
 	}
     }
@@ -4177,7 +4217,7 @@ gtk_combo_box_list_scroll_timeout (GtkComboBox *combo_box)
 
   if (priv->auto_scroll)
     {
-      gdk_window_get_device_position (priv->tree_view->window,
+      gdk_window_get_device_position (gtk_widget_get_window (priv->tree_view),
                                       priv->grab_pointer,
                                       &x, &y, NULL);
       gtk_combo_box_list_auto_scroll (combo_box, x, y);



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