Created _gtk_cell_renderer_calc_offset()

Created an internal helper to replace the meaningless 'cell_area',
'x_offset' and 'y_offset' from gtk_cell_renderer_get_size() which
will be deprecated in favor of the new h4w api. At this point GTK+
does no longer depend on renderers calculating this alignment and
its safe to change the calls to gtk_extended_cell_get_desired_size().
This commit is contained in:
Tristan Van Berkom
2010-06-16 16:52:16 -04:00
parent c20c3fd757
commit c2abe27b03
4 changed files with 59 additions and 8 deletions

View File

@@ -1124,6 +1124,39 @@ gtk_cell_renderer_get_width_for_height (GtkExtendedCell *cell,
gtk_extended_cell_get_desired_width (cell, widget, minimum_width, natural_width);
}
/* An internal convenience function for some containers to peek at the
* cell alignment in a target allocation (used to draw focus and align
* cells in the icon view).
*
* Note this is only a trivial 'align * (allocation - request)' operation.
*/
void
_gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
GdkRectangle *cell_area,
GtkTextDirection direction,
gint width,
gint height,
gint *x_offset,
gint *y_offset)
{
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
g_return_if_fail (cell_area != NULL);
g_return_if_fail (x_offset || y_offset);
if (x_offset)
{
*x_offset = (((direction == GTK_TEXT_DIR_RTL) ?
(1.0 - cell->xalign) : cell->xalign) *
(cell_area->width - width));
*x_offset = MAX (*x_offset, 0);
}
if (y_offset)
{
*y_offset = (cell->yalign *
(cell_area->height - height));
*y_offset = MAX (*y_offset, 0);
}
}
#define __GTK_CELL_RENDERER_C__
#include "gtkaliasdef.c"

View File

@@ -187,6 +187,14 @@ void gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
gboolean canceled);
void _gtk_cell_renderer_calc_offset (GtkCellRenderer *cell,
GdkRectangle *cell_area,
GtkTextDirection direction,
gint width,
gint height,
gint *x_offset,
gint *y_offset);
G_END_DECLS
#endif /* __GTK_CELL_RENDERER_H__ */

View File

@@ -3094,10 +3094,13 @@ gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
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,
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_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;

View File

@@ -2874,12 +2874,16 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn *tree_column,
{
gint x_offset, y_offset, width, height;
gtk_cell_renderer_get_size (info->cell,
tree_column->tree_view,
&rtl_cell_area,
&x_offset, &y_offset,
NULL, NULL, NULL,
&width, &height);
_gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
gtk_widget_get_direction (tree_column->tree_view),
width, height, &x_offset, &y_offset);
if (special_cells > 1)
{
if (info->has_focus)
@@ -3037,14 +3041,17 @@ 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 width, height, x_offset, y_offset;
gtk_cell_renderer_get_size (info->cell,
tree_column->tree_view,
&rtl_cell_area,
&x_offset, &y_offset,
NULL, NULL, NULL,
&width, &height);
_gtk_cell_renderer_calc_offset (info->cell, &rtl_cell_area,
gtk_widget_get_direction (tree_column->tree_view),
width, height, &x_offset, &y_offset);
if (special_cells > 1)
{
if (info->has_focus)