[gtk+/refactor: 51/138] gtk/gtkmenu.c: use accessor functions to access GtkWidget



commit 4bfdf7d727c2005856fe9471df0960fd0a8ec9dd
Author: Javier Jardón <jjardon gnome org>
Date:   Wed Aug 11 23:08:37 2010 +0200

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

 gtk/gtkmenu.c |  358 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 219 insertions(+), 139 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 39c83f2..fb98f98 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -424,7 +424,7 @@ get_effective_child_attach (GtkWidget *child,
 			    int       *t,
 			    int       *b)
 {
-  GtkMenu *menu = GTK_MENU (child->parent);
+  GtkMenu *menu = GTK_MENU (gtk_widget_get_parent (child));
   AttachInfo *ai;
   
   menu_ensure_layout (menu);
@@ -1350,14 +1350,17 @@ gtk_menu_tearoff_bg_copy (GtkMenu *menu)
   if (menu->torn_off)
     {
       GdkPixmap *pixmap;
+      GdkWindow *window;
       cairo_t *cr;
 
       menu->tearoff_active = FALSE;
       menu->saved_scroll_offset = menu->scroll_offset;
-      
-      gdk_drawable_get_size (menu->tearoff_window->window, &width, &height);
-      
-      pixmap = gdk_pixmap_new (menu->tearoff_window->window,
+
+      window = gtk_widget_get_window (menu->tearoff_window);
+
+      gdk_drawable_get_size (window, &width, &height);
+
+      pixmap = gdk_pixmap_new (window,
 			       width,
 			       height,
 			       -1);
@@ -1365,7 +1368,7 @@ gtk_menu_tearoff_bg_copy (GtkMenu *menu)
       cr = gdk_cairo_create (pixmap);
       /* Let's hope that function never notices we're not passing it a pixmap */
       gdk_cairo_set_source_pixmap (cr,
-                                   menu->tearoff_window->window,
+                                   window,
                                    0, 0);
       cairo_paint (cr);
       cairo_destroy (cr);
@@ -1374,7 +1377,7 @@ gtk_menu_tearoff_bg_copy (GtkMenu *menu)
 				   width,
 				   height);
 
-      gdk_window_set_back_pixmap (menu->tearoff_window->window, pixmap, FALSE);
+      gdk_window_set_back_pixmap (window, pixmap, FALSE);
       g_object_unref (pixmap);
     }
 }
@@ -1498,7 +1501,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
 	      viewable = FALSE;
 	      break;
 	    }
-	  tmp = tmp->parent;
+	  tmp = gtk_widget_get_parent (tmp);
 	}
       
       if (viewable)
@@ -1530,7 +1533,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
 
   if (xgrab_shell && xgrab_shell != widget)
     {
-      if (popup_grab_on_window (xgrab_shell->window, keyboard, pointer, activate_time))
+      if (popup_grab_on_window (gtk_widget_get_window (xgrab_shell), keyboard, pointer, activate_time))
         {
           _gtk_menu_shell_set_grab_device (GTK_MENU_SHELL (xgrab_shell), pointer);
           GTK_MENU_SHELL (xgrab_shell)->have_xgrab = TRUE;
@@ -1656,7 +1659,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
   gtk_widget_show (menu->toplevel);
 
   if (xgrab_shell == widget)
-    popup_grab_on_window (widget->window, keyboard, pointer, activate_time); /* Should always succeed */
+    popup_grab_on_window (gtk_widget_get_window (widget), keyboard, pointer, activate_time); /* Should always succeed */
 
   gtk_device_grab_add (GTK_WIDGET (menu), pointer, TRUE);
 
@@ -2041,6 +2044,7 @@ static void
 gtk_menu_set_tearoff_hints (GtkMenu *menu,
 			    gint     width)
 {
+  GtkRequisition requisition;
   GdkGeometry geometry_hints;
   
   if (!menu->tearoff_window)
@@ -2049,14 +2053,16 @@ gtk_menu_set_tearoff_hints (GtkMenu *menu,
   if (gtk_widget_get_visible (menu->tearoff_scrollbar))
     {
       gtk_widget_size_request (menu->tearoff_scrollbar, NULL);
-      width += menu->tearoff_scrollbar->requisition.width;
+      gtk_widget_get_requisition (menu->tearoff_scrollbar, &requisition);
+      width += requisition.width;
     }
 
   geometry_hints.min_width = width;
   geometry_hints.max_width = width;
     
   geometry_hints.min_height = 0;
-  geometry_hints.max_height = GTK_WIDGET (menu)->requisition.height;
+  gtk_widget_get_requisition (GTK_WIDGET (menu), &requisition);
+  geometry_hints.max_height = requisition.height;
 
   gtk_window_set_geometry_hints (GTK_WINDOW (menu->tearoff_window),
 				 NULL,
@@ -2097,7 +2103,7 @@ gtk_menu_get_toplevel (GtkWidget *menu)
   attach = gtk_menu_get_attach_widget (GTK_MENU (menu));
 
   if (GTK_IS_MENU_ITEM (attach))
-    attach = attach->parent;
+    attach = gtk_widget_get_parent (attach);
 
   if (GTK_IS_MENU (attach))
     return gtk_menu_get_toplevel (attach);
@@ -2138,6 +2144,7 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
 
 	  if (!menu->tearoff_window)
 	    {
+              GtkRequisition requisition;
 	      GtkWidget *toplevel;
 
 	      menu->tearoff_window = g_object_new (GTK_TYPE_WINDOW,
@@ -2166,11 +2173,13 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
 	      menu->tearoff_hbox = gtk_hbox_new (FALSE, FALSE);
 	      gtk_container_add (GTK_CONTAINER (menu->tearoff_window), menu->tearoff_hbox);
 
-	      gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
-	      menu->tearoff_adjustment =
+              gdk_drawable_get_size (gtk_widget_get_window (GTK_WIDGET (menu)),
+                                     &width, &height);
+              gtk_widget_get_requisition (GTK_WIDGET (menu), &requisition);
+              menu->tearoff_adjustment =
 		GTK_ADJUSTMENT (gtk_adjustment_new (0,
 						    0,
-						    GTK_WIDGET (menu)->requisition.height,
+						    requisition.height,
 						    MENU_SCROLL_STEP2,
 						    height/2,
 						    height));
@@ -2191,7 +2200,8 @@ gtk_menu_set_tearoff_state (GtkMenu  *menu,
 	  
 	  gtk_menu_reparent (menu, menu->tearoff_hbox, FALSE);
 
-	  gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, NULL);
+          gdk_drawable_get_size (gtk_widget_get_window (GTK_WIDGET (menu)),
+                                 &width, NULL);
 
 	  /* Update menu->requisition
 	   */
@@ -2322,10 +2332,13 @@ gtk_menu_style_set (GtkWidget *widget,
   if (gtk_widget_get_realized (widget))
     {
       GtkMenu *menu = GTK_MENU (widget);
-      
-      gtk_style_set_background (widget->style, menu->bin_window, GTK_STATE_NORMAL);
-      gtk_style_set_background (widget->style, menu->view_window, GTK_STATE_NORMAL);
-      gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+      GtkStyle *style;
+
+      style = gtk_widget_get_style (widget);
+
+      gtk_style_set_background (style, menu->bin_window, GTK_STATE_NORMAL);
+      gtk_style_set_background (style, menu->view_window, GTK_STATE_NORMAL);
+      gtk_style_set_background (style, gtk_widget_get_window (widget), GTK_STATE_NORMAL);
     }
 }
 
@@ -2367,6 +2380,10 @@ get_arrows_border (GtkMenu   *menu,
 static void
 gtk_menu_realize (GtkWidget *widget)
 {
+  GtkAllocation allocation;
+  GtkRequisition requisition;
+  GtkStyle *style;
+  GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
   gint border_width;
@@ -2382,51 +2399,62 @@ gtk_menu_realize (GtkWidget *widget)
   menu = GTK_MENU (widget);
   
   gtk_widget_set_realized (widget, TRUE);
-  
+
+  gtk_widget_get_allocation (widget, &allocation);
+
   attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.x = widget->allocation.x;
-  attributes.y = widget->allocation.y;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
+  attributes.x = allocation.x;
+  attributes.y = allocation.y;
+  attributes.width = allocation.width;
+  attributes.height = allocation.height;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
   attributes.colormap = gtk_widget_get_colormap (widget);
-  
   attributes.event_mask = gtk_widget_get_events (widget);
-
   attributes.event_mask |= (GDK_EXPOSURE_MASK | GDK_KEY_PRESS_MASK |
 			    GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
-  
+
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
-  gdk_window_set_user_data (widget->window, widget);
-  
+
+  window = gdk_window_new (gtk_widget_get_parent_window (widget),
+                           &attributes, attributes_mask);
+  gtk_widget_set_window (widget, window);
+  gdk_window_set_user_data (window, widget);
+
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
+  style = gtk_widget_get_style (widget);
   gtk_widget_style_get (GTK_WIDGET (menu),
 			"vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
 			NULL);
 
-  attributes.x = border_width + widget->style->xthickness + horizontal_padding;
-  attributes.y = border_width + widget->style->ythickness + vertical_padding;
-  attributes.width = MAX (1, widget->allocation.width - attributes.x * 2);
-  attributes.height = MAX (1, widget->allocation.height - attributes.y * 2);
+  gtk_widget_get_allocation (widget, &allocation);
+
+  attributes.x = border_width + style->xthickness + horizontal_padding;
+  attributes.y = border_width + style->ythickness + vertical_padding;
+  attributes.width = MAX (1, allocation.width - attributes.x * 2);
+  attributes.height = MAX (1, allocation.height - attributes.y * 2);
 
   get_arrows_border (menu, &arrow_border);
   attributes.y += arrow_border.top;
   attributes.height -= arrow_border.top;
   attributes.height -= arrow_border.bottom;
 
-  menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask);
+  menu->view_window = gdk_window_new (window,
+                                      &attributes, attributes_mask);
   gdk_window_set_user_data (menu->view_window, menu);
 
+  gtk_widget_get_allocation (widget, &allocation);
+  gtk_widget_get_requisition (widget, &requisition);
+
   attributes.x = 0;
   attributes.y = 0;
-  attributes.width = MAX (1, widget->allocation.width - (border_width + widget->style->xthickness + horizontal_padding) * 2);
-  attributes.height = MAX (1, widget->requisition.height - (border_width + widget->style->ythickness + vertical_padding) * 2);
-  
-  menu->bin_window = gdk_window_new (menu->view_window, &attributes, attributes_mask);
+  attributes.width = MAX (1, allocation.width - (border_width + style->xthickness + horizontal_padding) * 2);
+  attributes.height = MAX (1, requisition.height - (border_width + style->ythickness + vertical_padding) * 2);
+
+  menu->bin_window = gdk_window_new (menu->view_window,
+                                     &attributes, attributes_mask);
   gdk_window_set_user_data (menu->bin_window, menu);
 
   children = GTK_MENU_SHELL (menu)->children;
@@ -2437,11 +2465,11 @@ gtk_menu_realize (GtkWidget *widget)
 	  
       gtk_widget_set_parent_window (child, menu->bin_window);
     }
-  
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, menu->bin_window, GTK_STATE_NORMAL);
-  gtk_style_set_background (widget->style, menu->view_window, GTK_STATE_NORMAL);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+
+  gtk_widget_style_attach (widget);
+  gtk_style_set_background (style, menu->bin_window, GTK_STATE_NORMAL);
+  gtk_style_set_background (style, menu->view_window, GTK_STATE_NORMAL);
+  gtk_style_set_background (style, window, GTK_STATE_NORMAL);
 
   if (GTK_MENU_SHELL (widget)->active_menu_item)
     gtk_menu_scroll_item_visible (GTK_MENU_SHELL (widget),
@@ -2532,6 +2560,7 @@ gtk_menu_size_request (GtkWidget      *widget,
   gint i;
   GtkMenu *menu;
   GtkMenuShell *menu_shell;
+  GtkStyle *style;
   GtkWidget *child;
   GList *children;
   guint max_toggle_size;
@@ -2548,7 +2577,9 @@ gtk_menu_size_request (GtkWidget      *widget,
   menu = GTK_MENU (widget);
   menu_shell = GTK_MENU_SHELL (widget);
   priv = gtk_menu_get_private (menu);
-  
+
+  style = gtk_widget_get_style (widget);
+
   requisition->width = 0;
   requisition->height = 0;
   
@@ -2607,7 +2638,7 @@ gtk_menu_size_request (GtkWidget      *widget,
       guint toggle_spacing;
       guint indicator_size;
 
-      gtk_style_get (widget->style,
+      gtk_style_get (style,
                      GTK_TYPE_CHECK_MENU_ITEM,
                      "toggle-spacing", &toggle_spacing,
                      "indicator-size", &indicator_size,
@@ -2628,9 +2659,9 @@ gtk_menu_size_request (GtkWidget      *widget,
 			NULL);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  requisition->width += (border_width + horizontal_padding + widget->style->xthickness) * 2;
-  requisition->height += (border_width + vertical_padding + widget->style->ythickness) * 2;
-  
+  requisition->width += (border_width + horizontal_padding + style->xthickness) * 2;
+  requisition->height += (border_width + vertical_padding + style->ythickness) * 2;
+
   menu->toggle_size = max_toggle_size;
 
   /* Don't resize the tearoff if it is not active, because it won't redraw (it is only a background pixmap).
@@ -2649,6 +2680,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   GtkAllocation child_allocation;
   GtkRequisition child_requisition;
   GtkMenuPrivate *priv;
+  GtkStyle *style;
   GList *children;
   gint x, y;
   gint width, height;
@@ -2663,17 +2695,19 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   menu_shell = GTK_MENU_SHELL (widget);
   priv = gtk_menu_get_private (menu);
 
-  widget->allocation = *allocation;
+  gtk_widget_set_allocation (widget, allocation);
+
   gtk_widget_get_child_requisition (GTK_WIDGET (menu), &child_requisition);
 
+  style = gtk_widget_get_style (widget);
   gtk_widget_style_get (GTK_WIDGET (menu),
 			"vertical-padding", &vertical_padding,
                         "horizontal-padding", &horizontal_padding,
 			NULL);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  x = border_width + widget->style->xthickness + horizontal_padding;
-  y = border_width + widget->style->ythickness + vertical_padding;
+  x = border_width + style->xthickness + horizontal_padding;
+  y = border_width + style->ythickness + vertical_padding;
 
   width = MAX (1, allocation->width - x * 2);
   height = MAX (1, allocation->height - y * 2);
@@ -2696,7 +2730,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
   if (gtk_widget_get_realized (widget))
     {
-      gdk_window_move_resize (widget->window,
+      gdk_window_move_resize (gtk_widget_get_window (widget),
 			      allocation->x, allocation->y,
 			      allocation->width, allocation->height);
 
@@ -2769,7 +2803,11 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
       if (menu->tearoff_active)
 	{
-	  if (allocation->height >= widget->requisition.height)
+          GtkRequisition requisition;
+
+          gtk_widget_get_requisition (widget, &requisition);
+
+	  if (allocation->height >= requisition.height)
 	    {
 	      if (gtk_widget_get_visible (menu->tearoff_scrollbar))
 		{
@@ -2781,7 +2819,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 	    }
 	  else
 	    {
-	      menu->tearoff_adjustment->upper = widget->requisition.height;
+	      menu->tearoff_adjustment->upper = requisition.height;
 	      menu->tearoff_adjustment->page_size = allocation->height;
 	      
 	      if (menu->tearoff_adjustment->value + menu->tearoff_adjustment->page_size >
@@ -2813,12 +2851,15 @@ get_arrows_visible_area (GtkMenu      *menu,
                          GdkRectangle *lower,
                          gint         *arrow_space)
 {
+  GtkArrowPlacement arrow_placement;
+  GtkStyle *style;
   GtkWidget *widget = GTK_WIDGET (menu);
   guint border_width;
   guint vertical_padding;
   guint horizontal_padding;
   gint scroll_arrow_height;
-  GtkArrowPlacement arrow_placement;
+
+  style = gtk_widget_get_style (widget);
 
   gtk_widget_style_get (widget,
                         "vertical-padding", &vertical_padding,
@@ -2828,9 +2869,10 @@ get_arrows_visible_area (GtkMenu      *menu,
                         NULL);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-  border->x = border_width + widget->style->xthickness + horizontal_padding;
-  border->y = border_width + widget->style->ythickness + vertical_padding;
-  gdk_drawable_get_size (widget->window, &border->width, &border->height);
+  border->x = border_width + style->xthickness + horizontal_padding;
+  border->y = border_width + style->ythickness + vertical_padding;
+  gdk_drawable_get_size (gtk_widget_get_window (widget),
+                         &border->width, &border->height);
 
   switch (arrow_placement)
     {
@@ -2876,7 +2918,7 @@ get_arrows_visible_area (GtkMenu      *menu,
        lower->x = lower->y = lower->width = lower->height = 0;
     }
 
-  *arrow_space = scroll_arrow_height - 2 * widget->style->ythickness;
+  *arrow_space = scroll_arrow_height - 2 * style->ythickness;
 }
 
 static void
@@ -2885,9 +2927,11 @@ gtk_menu_paint (GtkWidget      *widget,
 {
   GtkMenu *menu;
   GtkMenuPrivate *priv;
+  GtkStyle *style;
   GdkRectangle border;
   GdkRectangle upper;
   GdkRectangle lower;
+  GdkWindow *window;
   gint arrow_space;
   
   g_return_if_fail (GTK_IS_MENU (widget));
@@ -2895,9 +2939,12 @@ gtk_menu_paint (GtkWidget      *widget,
   menu = GTK_MENU (widget);
   priv = gtk_menu_get_private (menu);
 
+  style = gtk_widget_get_style (widget);
+  window = gtk_widget_get_window (widget);
+
   get_arrows_visible_area (menu, &border, &upper, &lower, &arrow_space);
 
-  if (event->window == widget->window)
+  if (event->window == window)
     {
       gfloat arrow_scaling;
       gint arrow_size;
@@ -2905,8 +2952,8 @@ gtk_menu_paint (GtkWidget      *widget,
       gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
       arrow_size = arrow_scaling * arrow_space;
 
-      gtk_paint_box (widget->style,
-		     widget->window,
+      gtk_paint_box (style,
+                     window,
 		     GTK_STATE_NORMAL,
 		     GTK_SHADOW_OUT,
 		     &event->area, widget, "menu",
@@ -2914,8 +2961,8 @@ gtk_menu_paint (GtkWidget      *widget,
 
       if (menu->upper_arrow_visible && !menu->tearoff_active)
 	{
-	  gtk_paint_box (widget->style,
-			 widget->window,
+          gtk_paint_box (style,
+                         window,
 			 priv->upper_arrow_state,
                          GTK_SHADOW_OUT,
 			 &event->area, widget, "menu_scroll_arrow_up",
@@ -2924,22 +2971,22 @@ gtk_menu_paint (GtkWidget      *widget,
                          upper.width,
                          upper.height);
 
-	  gtk_paint_arrow (widget->style,
-			   widget->window,
+          gtk_paint_arrow (style,
+                           window,
 			   priv->upper_arrow_state,
 			   GTK_SHADOW_OUT,
 			   &event->area, widget, "menu_scroll_arrow_up",
 			   GTK_ARROW_UP,
 			   TRUE,
                            upper.x + (upper.width - arrow_size) / 2,
-                           upper.y + widget->style->ythickness + (arrow_space - arrow_size) / 2,
+                           upper.y + style->ythickness + (arrow_space - arrow_size) / 2,
 			   arrow_size, arrow_size);
 	}
 
       if (menu->lower_arrow_visible && !menu->tearoff_active)
 	{
-	  gtk_paint_box (widget->style,
-			 widget->window,
+          gtk_paint_box (style,
+                         window,
 			 priv->lower_arrow_state,
                          GTK_SHADOW_OUT,
 			 &event->area, widget, "menu_scroll_arrow_down",
@@ -2948,15 +2995,15 @@ gtk_menu_paint (GtkWidget      *widget,
                          lower.width,
                          lower.height);
 
-	  gtk_paint_arrow (widget->style,
-			   widget->window,
+          gtk_paint_arrow (style,
+                           window,
 			   priv->lower_arrow_state,
 			   GTK_SHADOW_OUT,
 			   &event->area, widget, "menu_scroll_arrow_down",
 			   GTK_ARROW_DOWN,
 			   TRUE,
                            lower.x + (lower.width - arrow_size) / 2,
-			   lower.y + widget->style->ythickness + (arrow_space - arrow_size) / 2,
+                           lower.y + style->ythickness + (arrow_space - arrow_size) / 2,
 			   arrow_size, arrow_size);
 	}
     }
@@ -2972,7 +3019,7 @@ gtk_menu_paint (GtkWidget      *widget,
           y -= arrow_border.top;
         }
 
-      gtk_paint_box (widget->style,
+      gtk_paint_box (style,
 		     menu->bin_window,
 		     GTK_STATE_NORMAL,
 		     GTK_SHADOW_OUT,
@@ -3038,6 +3085,7 @@ pointer_in_menu_window (GtkWidget *widget,
                         gdouble    x_root,
                         gdouble    y_root)
 {
+  GtkAllocation allocation;
   GtkMenu *menu = GTK_MENU (widget);
 
   if (gtk_widget_get_mapped (menu->toplevel))
@@ -3045,10 +3093,12 @@ pointer_in_menu_window (GtkWidget *widget,
       GtkMenuShell *menu_shell;
       gint          window_x, window_y;
 
-      gdk_window_get_position (menu->toplevel->window, &window_x, &window_y);
+      gdk_window_get_position (gtk_widget_get_window (menu->toplevel),
+                               &window_x, &window_y);
 
-      if (x_root >= window_x && x_root < window_x + widget->allocation.width &&
-          y_root >= window_y && y_root < window_y + widget->allocation.height)
+      gtk_widget_get_allocation (widget, &allocation);
+      if (x_root >= window_x && x_root < window_x + allocation.width &&
+          y_root >= window_y && y_root < window_y + allocation.height)
         return TRUE;
 
       menu_shell = GTK_MENU_SHELL (widget);
@@ -3348,6 +3398,7 @@ gtk_menu_motion_notify (GtkWidget      *widget,
   GtkWidget *menu_item;
   GtkMenu *menu;
   GtkMenuShell *menu_shell;
+  GtkWidget *parent;
 
   gboolean need_enter;
 
@@ -3372,11 +3423,12 @@ gtk_menu_motion_notify (GtkWidget      *widget,
    * which may be different from 'widget'.
    */
   menu_item = gtk_get_event_widget ((GdkEvent*) event);
+  parent = gtk_widget_get_parent (menu_item);
   if (!GTK_IS_MENU_ITEM (menu_item) ||
-      !GTK_IS_MENU (menu_item->parent))
+      !GTK_IS_MENU (parent))
     return FALSE;
 
-  menu_shell = GTK_MENU_SHELL (menu_item->parent);
+  menu_shell = GTK_MENU_SHELL (parent);
   menu = GTK_MENU (menu_shell);
 
   if (definitely_within_item (menu_item, event->x, event->y))
@@ -3466,12 +3518,13 @@ static void
 gtk_menu_scroll_by (GtkMenu *menu, 
 		    gint     step)
 {
+  GtkBorder arrow_border;
+  GtkRequisition requisition;
   GtkWidget *widget;
   gint offset;
   gint view_width, view_height;
   gboolean double_arrows;
-  GtkBorder arrow_border;
-  
+
   widget = GTK_WIDGET (menu);
   offset = menu->scroll_offset + step;
 
@@ -3492,10 +3545,13 @@ gtk_menu_scroll_by (GtkMenu *menu,
   if ((menu->scroll_offset >= 0) && (offset < 0))
     offset = 0;
 
-  gdk_drawable_get_size (widget->window, &view_width, &view_height);
+  gdk_drawable_get_size (gtk_widget_get_window (widget),
+                         &view_width, &view_height);
+
+  gtk_widget_get_requisition (widget, &requisition);
 
   if (menu->scroll_offset == 0 &&
-      view_height >= widget->requisition.height)
+      view_height >= requisition.height)
     return;
 
   /* Don't scroll past the bottom if we weren't before: */
@@ -3508,9 +3564,9 @@ gtk_menu_scroll_by (GtkMenu *menu,
   if (double_arrows)
     view_height -= arrow_border.bottom;
 
-  if ((menu->scroll_offset + view_height <= widget->requisition.height) &&
-      (offset + view_height > widget->requisition.height))
-    offset = widget->requisition.height - view_height;
+  if ((menu->scroll_offset + view_height <= requisition.height) &&
+      (offset + view_height > requisition.height))
+    offset = requisition.height - view_height;
 
   if (offset != menu->scroll_offset)
     gtk_menu_scroll_to (menu, offset);
@@ -3627,25 +3683,29 @@ get_arrows_sensitive_area (GtkMenu      *menu,
                            GdkRectangle *upper,
                            GdkRectangle *lower)
 {
+  GtkArrowPlacement arrow_placement;
+  GtkWidget *widget = GTK_WIDGET (menu);
+  GdkWindow *window;
   gint width, height;
   guint border;
   guint vertical_padding;
   gint win_x, win_y;
   gint scroll_arrow_height;
-  GtkArrowPlacement arrow_placement;
 
-  gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
+  window = gtk_widget_get_window (widget);
 
-  gtk_widget_style_get (GTK_WIDGET (menu),
+  gdk_drawable_get_size (window, &width, &height);
+
+  gtk_widget_style_get (widget,
                         "vertical-padding", &vertical_padding,
                         "scroll-arrow-vlength", &scroll_arrow_height,
                         "arrow-placement", &arrow_placement,
                         NULL);
 
   border = gtk_container_get_border_width (GTK_CONTAINER (menu)) +
-    GTK_WIDGET (menu)->style->ythickness + vertical_padding;
+           gtk_widget_get_style (widget)->ythickness + vertical_padding;
 
-  gdk_window_get_position (GTK_WIDGET (menu)->window, &win_x, &win_y);
+  gdk_window_get_position (window, &win_x, &win_y);
 
   switch (arrow_placement)
     {
@@ -3729,7 +3789,8 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
                 "gtk-touchscreen-mode", &touchscreen_mode,
                 NULL);
 
-  gdk_window_get_position (menu->toplevel->window, &top_x, &top_y);
+  gdk_window_get_position (gtk_widget_get_window (menu->toplevel),
+                           &top_x, &top_y);
   x -= top_x;
   y -= top_y;
 
@@ -3835,7 +3896,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
             {
               priv->upper_arrow_state = arrow_state;
 
-              gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+              gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (menu)),
                                           &rect, FALSE);
             }
         }
@@ -3943,7 +4004,7 @@ gtk_menu_handle_scrolling (GtkMenu *menu,
             {
               priv->lower_arrow_state = arrow_state;
 
-              gdk_window_invalidate_rect (GTK_WIDGET (menu)->window,
+              gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (menu)),
                                           &rect, FALSE);
             }
         }
@@ -3955,6 +4016,7 @@ gtk_menu_enter_notify (GtkWidget        *widget,
 		       GdkEventCrossing *event)
 {
   GtkWidget *menu_item;
+  GtkWidget *parent;
   gboolean   touchscreen_mode;
 
   if (event->mode == GDK_CROSSING_GTK_GRAB ||
@@ -3978,7 +4040,7 @@ gtk_menu_enter_notify (GtkWidget        *widget,
 
   if (!touchscreen_mode && GTK_IS_MENU_ITEM (menu_item))
     {
-      GtkWidget *menu = menu_item->parent;
+      GtkWidget *menu = gtk_widget_get_parent (menu_item);
       
       if (GTK_IS_MENU (menu))
 	{
@@ -4016,8 +4078,9 @@ gtk_menu_enter_notify (GtkWidget        *widget,
    * will not correspond to the event widget's parent.  Check to see
    * if we are in the parent's navigation region.
    */
-  if (GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (menu_item->parent) &&
-      gtk_menu_navigating_submenu (GTK_MENU (menu_item->parent),
+  parent = gtk_widget_get_parent (menu_item);
+  if (GTK_IS_MENU_ITEM (menu_item) && GTK_IS_MENU (parent) &&
+      gtk_menu_navigating_submenu (GTK_MENU (parent),
                                    event->x_root, event->y_root))
     return TRUE;
 
@@ -4194,6 +4257,7 @@ gtk_menu_set_submenu_navigation_region (GtkMenu          *menu,
   GtkWidget *event_widget;
   GtkMenuPopdownData *popdown_data;
   GtkMenuPrivate *priv;
+  GdkWindow *window;
 
   g_return_if_fail (menu_item->submenu != NULL);
   g_return_if_fail (event != NULL);
@@ -4201,15 +4265,17 @@ gtk_menu_set_submenu_navigation_region (GtkMenu          *menu,
   priv = gtk_menu_get_private (menu);
 
   event_widget = gtk_get_event_widget ((GdkEvent*) event);
-  
-  gdk_window_get_origin (menu_item->submenu->window, &submenu_left, &submenu_top);
-  gdk_drawable_get_size (menu_item->submenu->window, &width, &height);
-  
+
+  window = gtk_widget_get_window (menu_item->submenu);
+  gdk_window_get_origin (window, &submenu_left, &submenu_top);
+  gdk_drawable_get_size (window, &width, &height);
+
   submenu_right = submenu_left + width;
   submenu_bottom = submenu_top + height;
-  
-  gdk_drawable_get_size (event_widget->window, &width, &height);
-  
+
+  gdk_drawable_get_size (gtk_widget_get_window (event_widget),
+                         &width, &height);
+
   if (event->x >= 0 && event->x < width)
     {
       gint popdown_delay;
@@ -4347,11 +4413,12 @@ gtk_menu_position (GtkMenu *menu)
     }
   else
     {
+      GtkStyle *style = gtk_widget_get_style (widget);
       gint space_left, space_right, space_above, space_below;
       gint needed_width;
       gint needed_height;
-      gint xthickness = widget->style->xthickness;
-      gint ythickness = widget->style->ythickness;
+      gint xthickness = style->xthickness;
+      gint ythickness = style->ythickness;
       gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
       /* The placement of popup menus horizontally works like this (with
@@ -4467,7 +4534,8 @@ gtk_menu_position (GtkMenu *menu)
 
   if (private->initially_pushed_in)
     {
-      menu_height = GTK_WIDGET (menu)->requisition.height;
+      gtk_widget_get_requisition (GTK_WIDGET (menu), &requisition);
+      menu_height = requisition.height;
 
       if (y + menu_height > monitor.y + monitor.height)
 	{
@@ -4554,6 +4622,8 @@ static void
 gtk_menu_scroll_to (GtkMenu *menu,
 		    gint    offset)
 {
+  GtkAllocation allocation;
+  GtkRequisition requisition;
   GtkWidget *widget;
   gint x, y;
   gint view_width, view_height;
@@ -4563,7 +4633,8 @@ gtk_menu_scroll_to (GtkMenu *menu,
   guint horizontal_padding;
   gboolean double_arrows;
   GtkBorder arrow_border;
-  
+  GtkStyle *style;
+
   widget = GTK_WIDGET (menu);
 
   if (menu->tearoff_active &&
@@ -4577,8 +4648,9 @@ gtk_menu_scroll_to (GtkMenu *menu,
     }
   
   /* Move/resize the viewport according to arrows: */
-  view_width = widget->allocation.width;
-  view_height = widget->allocation.height;
+  gtk_widget_get_allocation (widget, &allocation);
+  view_width = allocation.width;
+  view_height = allocation.height;
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                         "vertical-padding", &vertical_padding,
@@ -4588,13 +4660,14 @@ gtk_menu_scroll_to (GtkMenu *menu,
   double_arrows = get_double_arrows (menu);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  view_width -= (border_width + widget->style->xthickness + horizontal_padding) * 2;
-  view_height -= (border_width + widget->style->ythickness + vertical_padding) * 2;
-  menu_height = widget->requisition.height -
-    (border_width + widget->style->ythickness + vertical_padding) * 2;
+  style = gtk_widget_get_style (widget);
+  view_width -= (border_width + style->xthickness + horizontal_padding) * 2;
+  view_height -= (border_width + style->ythickness + vertical_padding) * 2;
+  gtk_widget_get_requisition (widget, &requisition);
+  menu_height = requisition.height - (border_width + style->ythickness + vertical_padding) * 2;
 
-  x = border_width + widget->style->xthickness + horizontal_padding;
-  y = border_width + widget->style->ythickness + vertical_padding;
+  x = border_width + style->xthickness + horizontal_padding;
+  y = border_width + style->ythickness + vertical_padding;
 
   if (double_arrows && !menu->tearoff_active)
     {
@@ -4768,14 +4841,13 @@ static void
 gtk_menu_scroll_item_visible (GtkMenuShell *menu_shell,
 			      GtkWidget    *menu_item)
 {
-  GtkMenu *menu;
+  GtkMenu *menu = GTK_MENU (menu_shell);
+  GtkWidget *widget = GTK_WIDGET (menu_shell);
   gint child_offset, child_height;
   gint width, height;
   gint y;
   gint arrow_height;
   gboolean last_child = 0;
-  
-  menu = GTK_MENU (menu_shell);
 
   /* We need to check if the selected item fully visible.
    * If not we need to scroll the menu so that it becomes fully
@@ -4789,16 +4861,18 @@ gtk_menu_scroll_item_visible (GtkMenuShell *menu_shell,
       gboolean double_arrows;
       
       y = menu->scroll_offset;
-      gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height);
+      gdk_drawable_get_size (gtk_widget_get_window (widget),
+                             &width, &height);
 
-      gtk_widget_style_get (GTK_WIDGET (menu),
+      gtk_widget_style_get (widget,
 			    "vertical-padding", &vertical_padding,
                             NULL);
 
       double_arrows = get_double_arrows (menu);
 
-      height -= 2*gtk_container_get_border_width (GTK_CONTAINER (menu)) + 2*GTK_WIDGET (menu)->style->ythickness + 2*vertical_padding;
-      
+      height -= 2 * gtk_container_get_border_width (GTK_CONTAINER (menu)) +
+                2 * gtk_widget_get_style (widget)->ythickness +
+                2 * vertical_padding;
       if (child_offset < y)
 	{
 	  /* Ignore the enter event we might get if the pointer is on the menu
@@ -4896,7 +4970,7 @@ gtk_menu_reparent (GtkMenu   *menu,
   if (unrealize)
     {
       g_object_ref (object);
-      gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
+      gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (widget)), widget);
       gtk_container_add (GTK_CONTAINER (new_parent), widget);
       g_object_unref (object);
     }
@@ -4983,17 +5057,18 @@ gtk_menu_attach (GtkMenu   *menu,
                  guint      bottom_attach)
 {
   GtkMenuShell *menu_shell;
-  
+  GtkWidget *parent;
+
   g_return_if_fail (GTK_IS_MENU (menu));
   g_return_if_fail (GTK_IS_MENU_ITEM (child));
-  g_return_if_fail (child->parent == NULL || 
-		    child->parent == GTK_WIDGET (menu));
+  parent = gtk_widget_get_parent (child);
+  g_return_if_fail (parent == NULL || parent == GTK_WIDGET (menu));
   g_return_if_fail (left_attach < right_attach);
   g_return_if_fail (top_attach < bottom_attach);
 
   menu_shell = GTK_MENU_SHELL (menu);
-  
-  if (!child->parent)
+
+  if (!parent)
     {
       AttachInfo *ai = get_attach_info (child);
       
@@ -5010,7 +5085,7 @@ gtk_menu_attach (GtkMenu   *menu,
     }
   else
     {
-      gtk_container_child_set (GTK_CONTAINER (child->parent), child,
+      gtk_container_child_set (GTK_CONTAINER (parent), child,
 			       "left-attach",   left_attach,
 			       "right-attach",  right_attach,
 			       "top-attach",    top_attach,
@@ -5176,12 +5251,15 @@ gtk_menu_move_current (GtkMenuShell         *menu_shell,
 static gint
 get_visible_size (GtkMenu *menu)
 {
+  GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (menu);
   GtkContainer *container = GTK_CONTAINER (menu);
-  
-  gint menu_height = (widget->allocation.height
-		      - 2 * (gtk_container_get_border_width (container)
-			     + widget->style->ythickness));
+  gint menu_height;
+
+  gtk_widget_get_allocation (widget, &allocation);
+  menu_height = (allocation.height
+                 - 2 * (gtk_container_get_border_width (container)
+                        + gtk_widget_get_style (widget)->ythickness));
 
   if (!menu->tearoff_active)
     {
@@ -5242,11 +5320,13 @@ child_at (GtkMenu *menu,
 static gint
 get_menu_height (GtkMenu *menu)
 {
-  gint height;
+  GtkRequisition requisition;
   GtkWidget *widget = GTK_WIDGET (menu);
+  gint height;
 
-  height = widget->requisition.height;
-  height -= gtk_container_get_border_width (GTK_CONTAINER (widget) + widget->style->ythickness) * 2;
+  gtk_widget_get_requisition (widget, &requisition);
+  height = requisition.height;
+  height -= gtk_container_get_border_width (GTK_CONTAINER (widget) + gtk_widget_get_style (widget)->ythickness) * 2;
 
   if (!menu->tearoff_active)
     {



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