[maemo-commits] [maemo-commits] r11572 - in projects/haf/trunk/gtk+: . gtk
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Thu May 10 15:11:52 EEST 2007
- Previous message: [maemo-commits] r11571 - in projects/haf/trunk/hildon-theme-test: . debian wallpaper
- Next message: [maemo-commits] r11573 - in projects/haf/trunk/gtk+: . gtk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: tko Date: 2007-05-10 15:11:46 +0300 (Thu, 10 May 2007) New Revision: 11572 Modified: projects/haf/trunk/gtk+/ChangeLog projects/haf/trunk/gtk+/gtk/gtkmenu.c Log: Refactor arrow border size calculations The upper and lower border size is calculated independently and the upper/lower border value is used as appropriate. This enables later moving both scroll arrows to the same side of the menu with fewer modifications. * gtk/gtkmenu.c (get_arrows_border): New function to calculate the border sizes needed for the scroll arrows. (gtk_menu_realize, gtk_menu_size_allocate, gtk_menu_scroll_by, gtk_menu_position, gtk_menu_scroll_to, gtk_menu_scroll_item_visible, get_visible_size, get_menu_height, gtk_menu_real_move_scroll): Update callers. (#436533, NB#51958) Modified: projects/haf/trunk/gtk+/ChangeLog =================================================================== --- projects/haf/trunk/gtk+/ChangeLog 2007-05-10 11:54:53 UTC (rev 11571) +++ projects/haf/trunk/gtk+/ChangeLog 2007-05-10 12:11:46 UTC (rev 11572) @@ -1,3 +1,12 @@ +2007-05-10 Tommi Komulainen <tommi.komulainen at nokia.com> + + * gtk/gtkmenu.c (get_arrows_border): New function to calculate the + border sizes needed for the scroll arrows. + (gtk_menu_realize, gtk_menu_size_allocate, gtk_menu_scroll_by, + gtk_menu_position, gtk_menu_scroll_to, gtk_menu_scroll_item_visible, + get_visible_size, get_menu_height, gtk_menu_real_move_scroll): Update + callers. (#436533, NB#51958) + 2007-05-10 Michael Natterer <mitch at gimp.org> * gtk/gtkmenushell.c (gtk_real_menu_shell_move_current): add a Modified: projects/haf/trunk/gtk+/gtk/gtkmenu.c =================================================================== --- projects/haf/trunk/gtk+/gtk/gtkmenu.c 2007-05-10 11:54:53 UTC (rev 11571) +++ projects/haf/trunk/gtk+/gtk/gtkmenu.c 2007-05-10 12:11:46 UTC (rev 11572) @@ -2117,6 +2117,21 @@ } static void +get_arrows_border (GtkMenu *menu, GtkBorder *border) +{ + guint scroll_arrow_height; + + gtk_widget_style_get (GTK_WIDGET (menu), + "scroll-arrow-vlength", &scroll_arrow_height, + NULL); + + border->top = menu->upper_arrow_visible ? scroll_arrow_height : 0; + border->bottom = menu->lower_arrow_visible ? scroll_arrow_height : 0; + + border->left = border->right = 0; +} + +static void gtk_menu_realize (GtkWidget *widget) { GdkWindowAttr attributes; @@ -2127,7 +2142,7 @@ GList *children; guint vertical_padding; guint horizontal_padding; - guint scroll_arrow_height; + GtkBorder arrow_border; g_return_if_fail (GTK_IS_MENU (widget)); @@ -2158,7 +2173,6 @@ gtk_widget_style_get (GTK_WIDGET (menu), "vertical-padding", &vertical_padding, "horizontal-padding", &horizontal_padding, - "scroll-arrow-vlength", &scroll_arrow_height, NULL); attributes.x = border_width + widget->style->xthickness + horizontal_padding; @@ -2166,15 +2180,11 @@ attributes.width = MAX (1, widget->allocation.width - attributes.x * 2); attributes.height = MAX (1, widget->allocation.height - attributes.y * 2); - if (menu->upper_arrow_visible) - { - attributes.y += scroll_arrow_height; - attributes.height -= scroll_arrow_height; - } + get_arrows_border (menu, &arrow_border); + attributes.y += arrow_border.top; + attributes.height -= arrow_border.top; + attributes.height -= arrow_border.bottom; - if (menu->lower_arrow_visible) - attributes.height -= scroll_arrow_height; - menu->view_window = gdk_window_new (widget->window, &attributes, attributes_mask); gdk_window_set_user_data (menu->view_window, menu); @@ -2394,7 +2404,6 @@ gint width, height; guint vertical_padding; guint horizontal_padding; - gint scroll_arrow_height; g_return_if_fail (GTK_IS_MENU (widget)); g_return_if_fail (allocation != NULL); @@ -2409,7 +2418,6 @@ gtk_widget_style_get (GTK_WIDGET (menu), "vertical-padding", &vertical_padding, "horizontal-padding", &horizontal_padding, - "scroll-arrow-vlength", &scroll_arrow_height, NULL); x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness + horizontal_padding; @@ -2424,15 +2432,16 @@ if (menu_shell->active) gtk_menu_scroll_to (menu, menu->scroll_offset); - if (menu->upper_arrow_visible && !menu->tearoff_active) + if (!menu->tearoff_active) { - y += scroll_arrow_height; - height -= scroll_arrow_height; + GtkBorder arrow_border; + + get_arrows_border (menu, &arrow_border); + y += arrow_border.top; + height -= arrow_border.top; + height -= arrow_border.bottom; } - if (menu->lower_arrow_visible && !menu->tearoff_active) - height -= scroll_arrow_height; - if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, @@ -3187,14 +3196,12 @@ gint offset; gint view_width, view_height; gboolean double_arrows; - gint scroll_arrow_height; + GtkBorder arrow_border; widget = GTK_WIDGET (menu); offset = menu->scroll_offset + step; - gtk_widget_style_get (GTK_WIDGET (menu), - "scroll-arrow-vlength", &scroll_arrow_height, - NULL); + get_arrows_border (menu, &arrow_border); double_arrows = get_double_arrows (menu); @@ -3204,7 +3211,7 @@ * screen space than just scrolling to the top. */ if (!double_arrows) - if ((step < 0) && (offset < scroll_arrow_height)) + if ((step < 0) && (offset < arrow_border.top)) offset = 0; /* Don't scroll over the top if we weren't before: */ @@ -3219,13 +3226,13 @@ /* Don't scroll past the bottom if we weren't before: */ if (menu->scroll_offset > 0) - view_height -= scroll_arrow_height; + view_height -= arrow_border.top; /* When both arrows are always shown, reduce * view height even more. */ if (double_arrows) - view_height -= scroll_arrow_height; + view_height -= arrow_border.bottom; if ((menu->scroll_offset + view_height <= widget->requisition.height) && (offset + view_height > widget->requisition.height)) @@ -3973,7 +3980,6 @@ GdkScreen *screen; GdkScreen *pointer_screen; GdkRectangle monitor; - gint scroll_arrow_height; g_return_if_fail (GTK_IS_MENU (menu)); @@ -3982,10 +3988,6 @@ screen = gtk_widget_get_screen (widget); gdk_display_get_pointer (gdk_screen_get_display (screen), &pointer_screen, &x, &y, NULL); - - gtk_widget_style_get (GTK_WIDGET (menu), - "scroll-arrow-vlength", &scroll_arrow_height, - NULL); /* We need the requisition to figure out the right place to * popup the menu. In fact, we always need to ask here, since @@ -4181,7 +4183,12 @@ } if (scroll_offset > 0) - scroll_offset += scroll_arrow_height; + { + GtkBorder arrow_border; + + get_arrows_border (menu, &arrow_border); + scroll_offset += arrow_border.top; + } gtk_window_move (GTK_WINDOW (GTK_MENU_SHELL (menu)->active ? menu->toplevel : menu->tearoff_window), x, y); @@ -4235,7 +4242,7 @@ guint vertical_padding; guint horizontal_padding; gboolean double_arrows; - gint scroll_arrow_height; + GtkBorder arrow_border; widget = GTK_WIDGET (menu); @@ -4256,7 +4263,6 @@ gtk_widget_style_get (GTK_WIDGET (menu), "vertical-padding", &vertical_padding, "horizontal-padding", &horizontal_padding, - "scroll-arrow-vlength", &scroll_arrow_height, NULL); double_arrows = get_double_arrows (menu); @@ -4283,11 +4289,13 @@ if (!menu->upper_arrow_visible || !menu->lower_arrow_visible) gtk_widget_queue_draw (GTK_WIDGET (menu)); - view_height -= 2 * scroll_arrow_height; - y += scroll_arrow_height; - menu->upper_arrow_visible = menu->lower_arrow_visible = TRUE; + get_arrows_border (menu, &arrow_border); + y += arrow_border.top; + view_height -= arrow_border.top; + view_height -= arrow_border.bottom; + if (offset <= 0) priv->upper_arrow_state = GTK_STATE_INSENSITIVE; else if (priv->upper_arrow_state == GTK_STATE_INSENSITIVE) @@ -4344,8 +4352,9 @@ last_visible = menu->upper_arrow_visible; menu->upper_arrow_visible = offset > 0; - if (menu->upper_arrow_visible) - view_height -= scroll_arrow_height; + /* upper_arrow_visible may have changed, so requery the border */ + get_arrows_border (menu, &arrow_border); + view_height -= arrow_border.top; if ((last_visible != menu->upper_arrow_visible) && !menu->upper_arrow_visible) @@ -4363,8 +4372,9 @@ last_visible = menu->lower_arrow_visible; menu->lower_arrow_visible = offset < menu_height - view_height; - if (menu->lower_arrow_visible) - view_height -= scroll_arrow_height; + /* lower_arrow_visible may have changed, so requery the border */ + get_arrows_border (menu, &arrow_border); + view_height -= arrow_border.bottom; if ((last_visible != menu->lower_arrow_visible) && !menu->lower_arrow_visible) @@ -4379,8 +4389,7 @@ } } - if (menu->upper_arrow_visible) - y += scroll_arrow_height; + y += arrow_border.top; } /* Scroll the menu: */ @@ -4458,14 +4467,12 @@ { guint vertical_padding; gboolean double_arrows; - gint scroll_arrow_height; y = menu->scroll_offset; gdk_drawable_get_size (GTK_WIDGET (menu)->window, &width, &height); gtk_widget_style_get (GTK_WIDGET (menu), "vertical-padding", &vertical_padding, - "scroll-arrow-vlength", &scroll_arrow_height, NULL); double_arrows = get_double_arrows (menu); @@ -4481,23 +4488,25 @@ } else { - arrow_height = 0; - if (menu->upper_arrow_visible && !menu->tearoff_active) - arrow_height += scroll_arrow_height; - if (menu->lower_arrow_visible && !menu->tearoff_active) - arrow_height += scroll_arrow_height; + GtkBorder arrow_border; + + arrow_height = 0; + + get_arrows_border (menu, &arrow_border); + if (!menu->tearoff_active) + arrow_height = arrow_border.top + arrow_border.bottom; if (child_offset + child_height > y + height - arrow_height) { arrow_height = 0; if ((!last_child && !menu->tearoff_active) || double_arrows) - arrow_height += scroll_arrow_height; + arrow_height += arrow_border.bottom; y = child_offset + child_height - height + arrow_height; if (((y > 0) && !menu->tearoff_active) || double_arrows) { /* Need upper arrow */ - arrow_height += scroll_arrow_height; + arrow_height += arrow_border.top; y = child_offset + child_height - height + arrow_height; } /* Ignore the enter event we might get if the pointer is on the menu @@ -4849,21 +4858,20 @@ { GtkWidget *widget = GTK_WIDGET (menu); GtkContainer *container = GTK_CONTAINER (menu); - gint scroll_arrow_height; gint menu_height = (widget->allocation.height - 2 * (container->border_width + widget->style->ythickness)); - - gtk_widget_style_get (GTK_WIDGET (menu), - "scroll-arrow-vlength", &scroll_arrow_height, - NULL); - if (menu->upper_arrow_visible && !menu->tearoff_active) - menu_height -= scroll_arrow_height; - if (menu->lower_arrow_visible && !menu->tearoff_active) - menu_height -= scroll_arrow_height; + if (!menu->tearoff_active) + { + GtkBorder arrow_border; + get_arrows_border (menu, &arrow_border); + menu_height -= arrow_border.top; + menu_height -= arrow_border.bottom; + } + return menu_height; } @@ -4916,20 +4924,18 @@ { gint height; GtkWidget *widget = GTK_WIDGET (menu); - gint scroll_arrow_height; - gtk_widget_style_get (GTK_WIDGET (menu), - "scroll-arrow-vlength", &scroll_arrow_height, - NULL); - height = widget->requisition.height; height -= (GTK_CONTAINER (widget)->border_width + widget->style->ythickness) * 2; - if (menu->upper_arrow_visible && !menu->tearoff_active) - height -= scroll_arrow_height; + if (!menu->tearoff_active) + { + GtkBorder arrow_border; - if (menu->lower_arrow_visible && !menu->tearoff_active) - height -= scroll_arrow_height; + get_arrows_border (menu, &arrow_border); + height -= arrow_border.top; + height -= arrow_border.bottom; + } return height; } @@ -4941,11 +4947,6 @@ gint page_size = get_visible_size (menu); gint end_position = get_menu_height (menu); GtkMenuShell *menu_shell = GTK_MENU_SHELL (menu); - gint scroll_arrow_height; - - gtk_widget_style_get (GTK_WIDGET (menu), - "scroll-arrow-vlength", &scroll_arrow_height, - NULL); switch (type) { @@ -4985,11 +4986,14 @@ { GtkWidget *new_child; gboolean new_upper_arrow_visible = menu->upper_arrow_visible && !menu->tearoff_active; + GtkBorder arrow_border; + get_arrows_border (menu, &arrow_border); + if (menu->scroll_offset != old_offset) step = menu->scroll_offset - old_offset; - step -= (new_upper_arrow_visible - old_upper_arrow_visible) * scroll_arrow_height; + step -= (new_upper_arrow_visible - old_upper_arrow_visible) * arrow_border.top; new_child = child_at (menu, child_offset + step); if (new_child)
- Previous message: [maemo-commits] r11571 - in projects/haf/trunk/hildon-theme-test: . debian wallpaper
- Next message: [maemo-commits] r11573 - in projects/haf/trunk/gtk+: . gtk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]