From 15a5a231fce34fdc571fb708c2483edc5d25714c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 13 Sep 2010 02:50:04 +0200 Subject: [PATCH] Do not use deprecated gtk_cell_renderer_get_size() Use gtk_cell_size_request_get_size() instead Fixes https://bugzilla.gnome.org/show_bug.cgi?id=629785 --- gtk/gtkiconview.c | 54 ++++++++++++++++------------ gtk/gtktreeviewcolumn.c | 79 ++++++++++++++++++++++------------------- 2 files changed, 74 insertions(+), 59 deletions(-) diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c index 2d97dce272..522c5173b9 100644 --- a/gtk/gtkiconview.c +++ b/gtk/gtkiconview.c @@ -29,6 +29,7 @@ #include "gtkcellrenderer.h" #include "gtkcellrenderertext.h" #include "gtkcellrendererpixbuf.h" +#include "gtkcellsizerequest.h" #include "gtkmarshalers.h" #include "gtkbindings.h" #include "gtkdnd.h" @@ -2963,24 +2964,22 @@ adjust_wrap_width (GtkIconView *icon_view, { GtkIconViewCellInfo *text_info; GtkIconViewCellInfo *pixbuf_info; - gint pixbuf_width, wrap_width; - + gint wrap_width; + if (icon_view->priv->text_cell != -1 && icon_view->priv->pixbuf_cell != -1) { + GtkRequisition min_size; gint item_width; text_info = g_list_nth_data (icon_view->priv->cell_list, icon_view->priv->text_cell); pixbuf_info = g_list_nth_data (icon_view->priv->cell_list, icon_view->priv->pixbuf_cell); - - gtk_cell_renderer_get_size (pixbuf_info->cell, - GTK_WIDGET (icon_view), - NULL, NULL, NULL, - &pixbuf_width, - NULL); - + + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (pixbuf_info->cell), + GTK_WIDGET (icon_view), + &min_size, NULL); if (icon_view->priv->item_width > 0) item_width = icon_view->priv->item_width; @@ -2991,9 +2990,9 @@ adjust_wrap_width (GtkIconView *icon_view, wrap_width = item_width; else { if (item->width == -1 && item_width <= 0) - wrap_width = MAX (2 * pixbuf_width, 50); + wrap_width = MAX (2 * min_size.width, 50); else - wrap_width = item_width - pixbuf_width - icon_view->priv->spacing; + wrap_width = item_width - min_size.width - icon_view->priv->spacing; } wrap_width -= icon_view->priv->item_padding * 2; @@ -3007,6 +3006,7 @@ static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view, GtkIconViewItem *item) { + GtkRequisition min_size; gint spacing; GList *l; @@ -3038,11 +3038,12 @@ gtk_icon_view_calculate_item_size (GtkIconView *icon_view, if (!gtk_cell_renderer_get_visible (info->cell)) continue; - - gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view), - NULL, NULL, NULL, - &item->box[info->position].width, - &item->box[info->position].height); + + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell), + GTK_WIDGET (icon_view), + &min_size, NULL); + item->box[info->position].width = min_size.width; + item->box[info->position].height = min_size.height; if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL) { @@ -3066,6 +3067,7 @@ gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view, GtkIconViewItem *item, gint *max_height) { + GtkRequisition min_size; GdkRectangle cell_area; gint spacing; GList *l; @@ -3094,7 +3096,7 @@ gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view, for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++) { GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data; - + if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END)) continue; @@ -3118,14 +3120,20 @@ gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view, cell_area.width = item->width - 2 * icon_view->priv->item_padding; cell_area.height = max_height[i]; } - - gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view), - &cell_area, - &item->box[info->position].x, &item->box[info->position].y, - &item->box[info->position].width, &item->box[info->position].height); - + + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell), + GTK_WIDGET (icon_view), + &min_size, NULL); + item->box[info->position].width = min_size.width; + item->box[info->position].height = min_size.height; + + _gtk_cell_renderer_calc_offset (info->cell, &cell_area, + gtk_widget_get_direction (GTK_WIDGET (icon_view)), + item->box[info->position].width, item->box[info->position].height, + &item->box[info->position].x, &item->box[info->position].y); item->box[info->position].x += cell_area.x; item->box[info->position].y += cell_area.y; + if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL) { item->before[info->position] = item->box[info->position].x - cell_area.x; diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c index ebc054d43e..bd5b36e68e 100644 --- a/gtk/gtktreeviewcolumn.c +++ b/gtk/gtktreeviewcolumn.c @@ -18,8 +18,12 @@ */ #include "config.h" -#include + #include "gtktreeviewcolumn.h" + +#include + +#include "gtkcellsizerequest.h" #include "gtktreeview.h" #include "gtktreeprivate.h" #include "gtkcelllayout.h" @@ -2611,6 +2615,7 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, gint *width, gint *height) { + GtkRequisition min_size; GList *list; gboolean first_cell = TRUE; gint focus_line_width; @@ -2628,8 +2633,6 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, { GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *) list->data; gboolean visible; - gint new_height = 0; - gint new_width = 0; g_object_get (info->cell, "visible", &visible, NULL); if (visible == FALSE) @@ -2638,17 +2641,13 @@ gtk_tree_view_column_cell_get_size (GtkTreeViewColumn *tree_column, if (first_cell == FALSE && width) *width += tree_column->spacing; - gtk_cell_renderer_get_size (info->cell, - tree_column->tree_view, - cell_area, - x_offset, - y_offset, - &new_width, - &new_height); + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell), + GTK_WIDGET (tree_column->tree_view), + &min_size, NULL); if (height) - * height = MAX (*height, new_height + focus_line_width * 2); - info->requested_width = MAX (info->requested_width, new_width + focus_line_width * 2); + * height = MAX (*height, min_size.height + focus_line_width * 2); + info->requested_width = MAX (info->requested_width, min_size.width + focus_line_width * 2); if (width) * width += info->requested_width; first_cell = FALSE; @@ -2839,34 +2838,38 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, /* FOCUS */ else if (action == CELL_ACTION_FOCUS) { - gint x_offset, y_offset, width, height; + gint x_offset, y_offset; + GtkRequisition min_size; - gtk_cell_renderer_get_size (info->cell, - tree_column->tree_view, - &rtl_cell_area, - &x_offset, &y_offset, - &width, &height); + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell), + tree_column->tree_view, + &min_size, NULL); + + _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area, + gtk_widget_get_direction (tree_column->tree_view), + min_size.width, min_size.height, + &x_offset, &y_offset); if (special_cells > 1) { if (info->has_focus) { min_x = rtl_cell_area.x + x_offset; - max_x = min_x + width; + max_x = min_x + min_size.width; min_y = rtl_cell_area.y + y_offset; - max_y = min_y + height; + max_y = min_y + min_size.height; } } else { if (min_x > (rtl_cell_area.x + x_offset)) min_x = rtl_cell_area.x + x_offset; - if (max_x < rtl_cell_area.x + x_offset + width) - max_x = rtl_cell_area.x + x_offset + width; + if (max_x < rtl_cell_area.x + x_offset + min_size.width) + max_x = rtl_cell_area.x + x_offset + min_size.width; if (min_y > (rtl_cell_area.y + y_offset)) min_y = rtl_cell_area.y + y_offset; - if (max_y < rtl_cell_area.y + y_offset + height) - max_y = rtl_cell_area.y + y_offset + height; + if (max_y < rtl_cell_area.y + y_offset + min_size.height) + max_y = rtl_cell_area.y + y_offset + min_size.height; } } /* EVENT */ @@ -3004,34 +3007,38 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column, /* FOCUS */ else if (action == CELL_ACTION_FOCUS) { - gint x_offset, y_offset, width, height; + gint x_offset, y_offset; + GtkRequisition min_size; - gtk_cell_renderer_get_size (info->cell, - tree_column->tree_view, - &rtl_cell_area, - &x_offset, &y_offset, - &width, &height); + gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell), + tree_column->tree_view, + &min_size, NULL); + + _gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area, + gtk_widget_get_direction (tree_column->tree_view), + min_size.width, min_size.height, + &x_offset, &y_offset); if (special_cells > 1) { if (info->has_focus) { min_x = rtl_cell_area.x + x_offset; - max_x = min_x + width; + max_x = min_x + min_size.width; min_y = rtl_cell_area.y + y_offset; - max_y = min_y + height; + max_y = min_y + min_size.height; } } else { if (min_x > (rtl_cell_area.x + x_offset)) min_x = rtl_cell_area.x + x_offset; - if (max_x < rtl_cell_area.x + x_offset + width) - max_x = rtl_cell_area.x + x_offset + width; + if (max_x < rtl_cell_area.x + x_offset + min_size.width) + max_x = rtl_cell_area.x + x_offset + min_size.width; if (min_y > (rtl_cell_area.y + y_offset)) min_y = rtl_cell_area.y + y_offset; - if (max_y < rtl_cell_area.y + y_offset + height) - max_y = rtl_cell_area.y + y_offset + height; + if (max_y < rtl_cell_area.y + y_offset + min_size.height) + max_y = rtl_cell_area.y + y_offset + min_size.height; } } /* EVENT */