Changed GtkTreeViewColumn->requested_width to ->padding

Now we bookkeep the treeview assigned padding asides from the
requested width stored in the GtkCellAreaContext, this removes
the need for bookkeeping the deepest expanded depth in gtktreeview.c

At allocation time, just remove the padding from the allocated width
of the column and feed the rest to the underlying cell area.
This commit is contained in:
Tristan Van Berkom 2010-12-06 16:31:07 +09:00
parent a090d62339
commit bf1aa2ad87
3 changed files with 52 additions and 128 deletions

View File

@ -108,8 +108,7 @@ void _gtk_tree_view_column_set_tree_view (GtkTreeViewColumn *column,
gint _gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column);
void _gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
int x_offset,
int width,
int cell_width);
int width);
void _gtk_tree_view_column_unset_model (GtkTreeViewColumn *column,
GtkTreeModel *old_model);
void _gtk_tree_view_column_unset_tree_view (GtkTreeViewColumn *column);
@ -136,8 +135,8 @@ void _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
gboolean _gtk_tree_view_column_cell_get_dirty (GtkTreeViewColumn *tree_column);
GdkWindow *_gtk_tree_view_column_get_window (GtkTreeViewColumn *column);
void _gtk_tree_view_column_set_requested_width (GtkTreeViewColumn *column,
gint width);
void _gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
gint padding);
gint _gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column);
void _gtk_tree_view_column_set_resized_width (GtkTreeViewColumn *column,
gint width);

View File

@ -344,7 +344,6 @@ struct _GtkTreeViewPrivate
GtkRBNode *expanded_collapsed_node;
GtkRBTree *expanded_collapsed_tree;
guint expand_collapse_timeout;
gint deepest_depth;
/* Auto expand/collapse timeout in hover mode */
guint auto_expand_timeout;
@ -1759,8 +1758,6 @@ gtk_tree_view_init (GtkTreeView *tree_view)
tree_view->priv->event_last_x = -10000;
tree_view->priv->event_last_y = -10000;
tree_view->priv->deepest_depth = 1;
gtk_tree_view_set_vadjustment (tree_view, NULL);
gtk_tree_view_set_hadjustment (tree_view, NULL);
}
@ -2541,56 +2538,6 @@ invalidate_last_column (GtkTreeView *tree_view)
}
}
static gboolean
gtk_tree_view_column_is_edge (GtkTreeView *tree_view,
GtkTreeViewColumn *column)
{
GtkTreeViewColumn *first_column = tree_view->priv->columns->data;
GtkTreeViewColumn *last_column = g_list_last (tree_view->priv->columns)->data;
return (column == first_column || column == last_column);
}
/* Gets the space in a column that is not actually distributed to
* the internal cell area, i.e. total indentation expander size
* grid line widths and horizontal separators */
static gint
gtk_tree_view_get_column_padding (GtkTreeView *tree_view,
GtkTreeViewColumn *column)
{
gint padding;
gint grid_line_width;
gint horizontal_separator;
/* Get the deepest depth */
gtk_widget_style_get (GTK_WIDGET (tree_view),
"horizontal-separator", &horizontal_separator,
"grid-line-width", &grid_line_width,
NULL);
padding = horizontal_separator;
if (gtk_tree_view_is_expander_column (tree_view, column))
{
padding += (tree_view->priv->deepest_depth - 1) * tree_view->priv->level_indentation;
if (gtk_tree_view_draw_expanders (tree_view))
padding += tree_view->priv->deepest_depth * tree_view->priv->expander_size;
}
if (tree_view->priv->grid_lines == GTK_TREE_VIEW_GRID_LINES_VERTICAL ||
tree_view->priv->grid_lines == GTK_TREE_VIEW_GRID_LINES_BOTH)
{
if (gtk_tree_view_column_is_edge (tree_view, column))
padding += grid_line_width / 2.0;
else
padding += grid_line_width;
}
return padding;
}
/* GtkWidget::size_allocate helper */
static void
gtk_tree_view_size_allocate_columns (GtkWidget *widget,
@ -2681,7 +2628,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
list != (rtl ? first_column->prev : last_column->next);
list = (rtl ? list->prev : list->next))
{
gint column_cell_width = 0;
gint old_width, column_width;
column = list->data;
@ -2737,13 +2683,7 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
if (extra_for_last > 0 && list == last_column)
column_width += extra_for_last;
/* Remove any padding that we add to the column around the cell area
* and give the correct internal cell area to the column.
*/
column_cell_width =
column_width - gtk_tree_view_get_column_padding (tree_view, column);
_gtk_tree_view_column_allocate (column, width, column_width, column_cell_width);
_gtk_tree_view_column_allocate (column, width, column_width);
width += column_width;
@ -3187,7 +3127,10 @@ gtk_tree_view_button_press (GtkWidget *widget,
if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
tree_view->priv->shift_pressed = TRUE;
/* This needs an x and a y ! */
focus_cell = _gtk_tree_view_column_get_cell_at_pos (column, event->x - background_area.x);
if (focus_cell)
gtk_tree_view_column_focus_cell (column, focus_cell);
@ -6178,8 +6121,10 @@ validate_row (GtkTreeView *tree_view,
for (list = tree_view->priv->columns; list; list = list->next)
{
gint tmp_width;
gint tmp_height;
gint padding = 0;
gint original_width;
gint new_width;
gint row_height;
column = list->data;
@ -6190,17 +6135,19 @@ validate_row (GtkTreeView *tree_view,
!_gtk_tree_view_column_cell_get_dirty (column))
continue;
original_width = _gtk_tree_view_column_get_requested_width (column);
gtk_tree_view_column_cell_set_cell_data (column, tree_view->priv->model, iter,
GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_PARENT),
node->children?TRUE:FALSE);
gtk_tree_view_column_cell_get_size (column,
NULL, NULL, NULL,
&tmp_width, &tmp_height);
NULL, &row_height);
if (!is_separator)
{
tmp_height += vertical_separator;
height = MAX (height, tmp_height);
padding += vertical_separator;
height = MAX (height, row_height);
height = MAX (height, tree_view->priv->expander_size);
}
else
@ -6213,27 +6160,28 @@ validate_row (GtkTreeView *tree_view,
if (gtk_tree_view_is_expander_column (tree_view, column))
{
tmp_width = tmp_width + horizontal_separator + (depth - 1) * tree_view->priv->level_indentation;
padding += horizontal_separator + (depth - 1) * tree_view->priv->level_indentation;
if (gtk_tree_view_draw_expanders (tree_view))
tmp_width += depth * tree_view->priv->expander_size;
padding += depth * tree_view->priv->expander_size;
}
else
tmp_width = tmp_width + horizontal_separator;
padding += horizontal_separator;
if (draw_vgrid_lines)
{
if (list->data == first_column || list->data == last_column)
tmp_width += grid_line_width / 2.0;
padding += grid_line_width / 2.0;
else
tmp_width += grid_line_width;
padding += grid_line_width;
}
if (tmp_width > _gtk_tree_view_column_get_requested_width (column))
{
retval = TRUE;
_gtk_tree_view_column_set_requested_width (column, tmp_width);
}
/* Update the padding for the column */
_gtk_tree_view_column_push_padding (column, padding);
new_width = _gtk_tree_view_column_get_requested_width (column);
if (new_width > original_width)
retval = TRUE;
}
if (draw_hgrid_lines)
@ -12789,10 +12737,6 @@ gtk_tree_view_real_expand_row (GtkTreeView *tree_view,
gtk_tree_path_get_depth (path) + 1,
open_all);
/* Update the deepest expanded row depth */
if (tree_view->priv->deepest_depth < gtk_tree_path_get_depth (path) + 1)
tree_view->priv->deepest_depth = gtk_tree_path_get_depth (path) + 1;
remove_expand_collapse_timeout (tree_view);
if (animate)
@ -12847,17 +12791,6 @@ gtk_tree_view_expand_row (GtkTreeView *tree_view,
return FALSE;
}
static void
gtk_tree_view_deepest_expanded_depth (GtkTreeView *tree_view,
GtkTreePath *path,
gint *deepest)
{
gint children_depth = gtk_tree_path_get_depth (path) + 1;
if (children_depth > *deepest)
*deepest = children_depth;
}
static gboolean
gtk_tree_view_real_collapse_row (GtkTreeView *tree_view,
GtkTreePath *path,
@ -13010,17 +12943,6 @@ gtk_tree_view_real_collapse_row (GtkTreeView *tree_view,
}
}
/* If we're collapsing one of the deepest expanded rows,
* we need to recalculate the deepest_depth
*/
if (tree_view->priv->deepest_depth == gtk_tree_path_get_depth (path) + 1)
{
tree_view->priv->deepest_depth = 1;
gtk_tree_view_map_expanded_rows (tree_view,
(GtkTreeViewMappingFunc)gtk_tree_view_deepest_expanded_depth,
&tree_view->priv->deepest_depth);
}
return TRUE;
}

View File

@ -136,7 +136,7 @@ struct _GtkTreeViewColumnPrivate
/* Sizing fields */
/* see gtk+/doc/tree-column-sizing.txt for more information on them */
GtkTreeViewColumnSizing column_type;
gint requested_width;
gint padding;
gint resized_width;
gint width;
gint fixed_width;
@ -451,7 +451,7 @@ gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
priv->button = NULL;
priv->xalign = 0.0;
priv->width = 0;
priv->requested_width = -1;
priv->padding = -1;
priv->min_width = -1;
priv->max_width = -1;
priv->resized_width = 0;
@ -1903,16 +1903,6 @@ gtk_tree_view_column_set_sizing (GtkTreeViewColumn *tree_column,
if (type == GTK_TREE_VIEW_COLUMN_AUTOSIZE)
gtk_tree_view_column_set_resizable (tree_column, FALSE);
#if 0
/* I was clearly on crack when I wrote this. I'm not sure what's supposed to
* be below so I'll leave it until I figure it out.
*/
if (priv->column_type == GTK_TREE_VIEW_COLUMN_AUTOSIZE &&
priv->requested_width != -1)
{
gtk_tree_view_column_set_sizing (tree_column, priv->requested_width);
}
#endif
priv->column_type = type;
gtk_tree_view_column_update_button (tree_column);
@ -1971,13 +1961,22 @@ _gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column)
else if (gtk_tree_view_get_headers_visible (GTK_TREE_VIEW (priv->tree_view)))
{
gint button_request;
gint requested_width;
gtk_cell_area_context_get_preferred_width (priv->cell_area_context, &requested_width, NULL);
requested_width += priv->padding;
gtk_widget_get_preferred_width (priv->button, &button_request, NULL);
real_requested_width = MAX (priv->requested_width, button_request);
real_requested_width = MAX (requested_width, button_request);
}
else
{
real_requested_width = priv->requested_width;
gint requested_width;
gtk_cell_area_context_get_preferred_width (priv->cell_area_context, &requested_width, NULL);
requested_width += priv->padding;
real_requested_width = requested_width;
if (real_requested_width < 0)
real_requested_width = 0;
}
@ -1994,8 +1993,7 @@ _gtk_tree_view_column_request_width (GtkTreeViewColumn *tree_column)
void
_gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
int x_offset,
int width,
int cell_width)
int width)
{
GtkTreeViewColumnPrivate *priv;
GtkAllocation allocation;
@ -2007,7 +2005,7 @@ _gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
priv->width = width;
gtk_cell_area_context_allocate (priv->cell_area_context, cell_width, -1);
gtk_cell_area_context_allocate (priv->cell_area_context, priv->width - priv->padding, -1);
allocation.x = x_offset;
allocation.y = 0;
@ -2891,7 +2889,7 @@ _gtk_tree_view_column_cell_set_dirty (GtkTreeViewColumn *tree_column,
GtkTreeViewColumnPrivate *priv = tree_column->priv;
priv->dirty = TRUE;
priv->requested_width = -1;
priv->padding = 0;
priv->width = 0;
if (priv->tree_view &&
@ -3017,18 +3015,23 @@ _gtk_tree_view_column_get_window (GtkTreeViewColumn *column)
}
void
_gtk_tree_view_column_set_requested_width (GtkTreeViewColumn *column,
gint width)
_gtk_tree_view_column_push_padding (GtkTreeViewColumn *column,
gint padding)
{
column->priv->requested_width = width;
column->priv->padding = MAX (column->priv->padding, padding);
}
gint
_gtk_tree_view_column_get_requested_width (GtkTreeViewColumn *column)
{
return column->priv->requested_width;
gint requested_width;
gtk_cell_area_context_get_preferred_width (column->priv->cell_area_context, &requested_width, NULL);
return requested_width + column->priv->padding;
}
void
_gtk_tree_view_column_set_resized_width (GtkTreeViewColumn *column,
gint width)