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



commit 3a005aca0b0f31971e83216b4a9b673eeb012edb
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 |  345 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 208 insertions(+), 137 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index e258f01..a323d6e 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -441,7 +441,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);
@@ -1343,14 +1343,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);
@@ -1358,7 +1361,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);
@@ -1367,7 +1370,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);
     }
 }
@@ -1491,7 +1494,7 @@ gtk_menu_popup_for_device (GtkMenu             *menu,
 	      viewable = FALSE;
 	      break;
 	    }
-	  tmp = tmp->parent;
+	  tmp = gtk_widget_get_parent (tmp);
 	}
       
       if (viewable)
@@ -1523,7 +1526,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;
@@ -1652,7 +1655,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);
 
@@ -2037,6 +2040,7 @@ static void
 gtk_menu_set_tearoff_hints (GtkMenu *menu,
 			    gint     width)
 {
+  GtkRequisition requisition;
   GdkGeometry geometry_hints;
   GtkMenuPrivate *priv;
 
@@ -2048,7 +2052,8 @@ 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;
@@ -2096,7 +2101,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);
@@ -2140,6 +2145,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,
@@ -2168,8 +2174,10 @@ 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,
 						    priv->requested_height,
@@ -2193,7 +2201,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
 	   */
@@ -2324,10 +2333,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);
     }
 }
 
@@ -2369,6 +2381,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;
@@ -2386,51 +2402,62 @@ gtk_menu_realize (GtkWidget *widget)
   priv = gtk_menu_get_private (menu);
 
   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, priv->requested_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, priv->requested_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;
@@ -2441,11 +2468,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),
@@ -2563,7 +2590,7 @@ calculate_line_heights (GtkMenu *menu,
 			NULL);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  avail_width -= (border_width + horizontal_padding + widget->style->xthickness) * 2;
+  avail_width -= (border_width + horizontal_padding + gtk_widget_get_style (widget)->xthickness) * 2;
 
   for (children = menu_shell->children; children; children = children->next)
     {
@@ -2591,7 +2618,6 @@ calculate_line_heights (GtkMenu *menu,
 
       part = MAX (child_nat, toggle_size) / (b - t);
       nat_heights[t] = MAX (nat_heights[t], part);
-
     }
 
   if (ret_min_heights)
@@ -2616,6 +2642,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   GtkWidget *child;
   GtkAllocation child_allocation;
   GtkMenuPrivate *priv;
+  GtkStyle *style;
   GList *children;
   gint x, y, i;
   gint width, height;
@@ -2630,7 +2657,9 @@ 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);
+
+  style = gtk_widget_get_style (widget);
 
   gtk_widget_style_get (GTK_WIDGET (menu),
 			"vertical-padding", &vertical_padding,
@@ -2646,12 +2675,12 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 			    NULL);
 
   /* refresh our cached height request */
-  priv->requested_height = (border_width + vertical_padding + GTK_WIDGET (widget)->style->ythickness) * 2;
+  priv->requested_height = (border_width + vertical_padding + style->ythickness) * 2;
   for (i = 0; i < priv->heights_length; i++)
     priv->requested_height += priv->heights[i];
 
-  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);
@@ -2671,7 +2700,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);
 
@@ -2744,7 +2773,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 
       if (menu->tearoff_active)
 	{
-	  if (allocation->height >= priv->requested_height)
+	  if (height >= priv->requested_height)
 	    {
 	      if (gtk_widget_get_visible (menu->tearoff_scrollbar))
 		{
@@ -2788,12 +2817,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,
@@ -2803,9 +2835,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)
     {
@@ -2851,7 +2884,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
@@ -2860,9 +2893,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));
@@ -2870,9 +2905,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;
@@ -2880,8 +2918,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",
@@ -2889,8 +2927,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",
@@ -2899,22 +2937,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",
@@ -2923,15 +2961,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);
 	}
     }
@@ -2947,7 +2985,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,
@@ -3002,6 +3040,7 @@ gtk_menu_get_width (GtkSizeRequest      *widget,
   GtkMenu        *menu;
   GtkMenuShell   *menu_shell;
   GtkMenuPrivate *priv;
+  GtkStyle       *style;
   GtkWidget      *child;
   GList          *children;
   guint           max_toggle_size;
@@ -3014,7 +3053,9 @@ gtk_menu_get_width (GtkSizeRequest      *widget,
   menu       = GTK_MENU (widget);
   menu_shell = GTK_MENU_SHELL (widget);
   priv       = gtk_menu_get_private (menu);
-  
+
+  style = gtk_widget_get_style (GTK_WIDGET (widget));
+
   min_width = nat_width = 0;
   
   max_toggle_size = 0;
@@ -3068,7 +3109,7 @@ gtk_menu_get_width (GtkSizeRequest      *widget,
       guint toggle_spacing;
       guint indicator_size;
 
-      gtk_style_get (GTK_WIDGET (widget)->style,
+      gtk_style_get (style,
                      GTK_TYPE_CHECK_MENU_ITEM,
                      "toggle-spacing", &toggle_spacing,
                      "indicator-size", &indicator_size,
@@ -3088,8 +3129,8 @@ gtk_menu_get_width (GtkSizeRequest      *widget,
 			NULL);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  min_width   += (border_width + horizontal_padding + GTK_WIDGET (widget)->style->xthickness) * 2;
-  nat_width   += (border_width + horizontal_padding + GTK_WIDGET (widget)->style->xthickness) * 2;
+  min_width   += (border_width + horizontal_padding + style->xthickness) * 2;
+  nat_width   += (border_width + horizontal_padding + style->xthickness) * 2;
   
   menu->toggle_size = max_toggle_size;
   priv->accel_size  = max_accel_width;
@@ -3134,7 +3175,7 @@ gtk_menu_get_height_for_width (GtkSizeRequest      *widget,
   gtk_widget_style_get (GTK_WIDGET (menu), "vertical-padding", &vertical_padding, NULL);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
 
-  min_height = nat_height = (border_width + vertical_padding + GTK_WIDGET (widget)->style->ythickness) * 2;
+  min_height = nat_height = (border_width + vertical_padding + gtk_widget_get_style (GTK_WIDGET (widget))->ythickness) * 2;
 
   n_heights = 
     calculate_line_heights (menu, for_size, &min_heights, &nat_heights);
@@ -3206,6 +3247,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))
@@ -3213,10 +3255,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);
@@ -3516,6 +3560,7 @@ gtk_menu_motion_notify (GtkWidget      *widget,
   GtkWidget *menu_item;
   GtkMenu *menu;
   GtkMenuShell *menu_shell;
+  GtkWidget *parent;
 
   gboolean need_enter;
 
@@ -3540,11 +3585,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))
@@ -3634,13 +3680,14 @@ static void
 gtk_menu_scroll_by (GtkMenu *menu, 
 		    gint     step)
 {
+  GtkMenuPrivate *priv;
+  GtkBorder arrow_border;
+  GtkRequisition requisition;
   GtkWidget *widget;
   gint offset;
   gint view_width, view_height;
   gboolean double_arrows;
-  GtkBorder arrow_border;
-  GtkMenuPrivate *priv;
-  
+
   widget = GTK_WIDGET (menu);
   offset = menu->scroll_offset + step;
   priv   = gtk_menu_get_private (menu);
@@ -3662,7 +3709,10 @@ 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 >= priv->requested_height)
@@ -3797,25 +3847,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)
     {
@@ -3899,7 +3953,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;
 
@@ -4005,7 +4060,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);
             }
         }
@@ -4113,7 +4168,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);
             }
         }
@@ -4125,6 +4180,7 @@ gtk_menu_enter_notify (GtkWidget        *widget,
 		       GdkEventCrossing *event)
 {
   GtkWidget *menu_item;
+  GtkWidget *parent;
   gboolean   touchscreen_mode;
 
   if (event->mode == GDK_CROSSING_GTK_GRAB ||
@@ -4148,7 +4204,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))
 	{
@@ -4186,8 +4242,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;
 
@@ -4364,6 +4421,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);
@@ -4371,15 +4429,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;
@@ -4515,11 +4575,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
@@ -4722,6 +4783,10 @@ static void
 gtk_menu_scroll_to (GtkMenu *menu,
 		    gint    offset)
 {
+  GtkMenuPrivate *priv;
+  GtkAllocation allocation;
+  GtkBorder arrow_border;
+  GtkStyle *style;
   GtkWidget *widget;
   gint x, y;
   gint view_width, view_height;
@@ -4730,9 +4795,7 @@ gtk_menu_scroll_to (GtkMenu *menu,
   guint vertical_padding;
   guint horizontal_padding;
   gboolean double_arrows;
-  GtkBorder arrow_border;
-  GtkMenuPrivate *priv;
-  
+
   widget = GTK_WIDGET (menu);
   priv   = gtk_menu_get_private (menu);
 
@@ -4747,8 +4810,11 @@ 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;
+
+  style = gtk_widget_get_style (widget);
 
   gtk_widget_style_get (GTK_WIDGET (menu),
                         "vertical-padding", &vertical_padding,
@@ -4758,13 +4824,13 @@ 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 = priv->requested_height -
-    (border_width + widget->style->ythickness + vertical_padding) * 2;
 
-  x = border_width + widget->style->xthickness + horizontal_padding;
-  y = border_width + widget->style->ythickness + vertical_padding;
+  view_width -= (border_width + style->xthickness + horizontal_padding) * 2;
+  view_height -= (border_width + style->ythickness + vertical_padding) * 2;
+  menu_height = priv->requested_height - (border_width + style->ythickness + vertical_padding) * 2;
+
+  x = border_width + style->xthickness + horizontal_padding;
+  y = border_width + style->ythickness + vertical_padding;
 
   if (double_arrows && !menu->tearoff_active)
     {
@@ -4938,14 +5004,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
@@ -4959,16 +5024,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
@@ -5066,7 +5133,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);
     }
@@ -5153,17 +5220,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);
       
@@ -5180,7 +5248,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,
@@ -5346,12 +5414,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)
     {
@@ -5412,14 +5483,14 @@ child_at (GtkMenu *menu,
 static gint
 get_menu_height (GtkMenu *menu)
 {
-  gint height;
-  GtkWidget *widget = GTK_WIDGET (menu);
   GtkAllocation allocation;
+  GtkWidget *widget = GTK_WIDGET (menu);
+  gint height;
 
   gtk_widget_get_allocation (widget, &allocation);
 
   height = allocation.height;
-  height -= gtk_container_get_border_width (GTK_CONTAINER (widget) + widget->style->ythickness) * 2;
+  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]