summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorKristian Rietveld <kris@gtk.org>2002-03-20 22:06:05 +0000
committerKristian Rietveld <kristian@src.gnome.org>2002-03-20 22:06:05 +0000
commit92febe2720cd229749e64e99ea31906bade84a44 (patch)
tree3aae7af7600e2217ec47b0909ee5b42fc250901f /gtk
parent8acfd1e9de927adf2bea546bda55740a2b0cc436 (diff)
downloadgtk+-92febe2720cd229749e64e99ea31906bade84a44.tar.gz
add _gtk_rbtree_set_fixed_height()
Wed Mar 20 22:59:23 2002 Kristian Rietveld <kris@gtk.org> * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height() * gtk/gtktreeprivate.h: add fixed_height_check field * gtk/gtktreeview.c (gtk_tree_view_init): initialize scroll_sync_timer and fixed_height_check (do_validate_rows): add fixed_height_check. If all validated rows in the first cycle have the same height, then we set that height for the entire tree. This is some sort of 'fake' optimization, but helps a lot for the common case. We keep validating the entire tree in the background though. (gtk_tree_view_set_model): reset fixed_height_check
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkrbtree.c26
-rw-r--r--gtk/gtkrbtree.h2
-rw-r--r--gtk/gtktreeprivate.h2
-rw-r--r--gtk/gtktreeview.c28
4 files changed, 57 insertions, 1 deletions
diff --git a/gtk/gtkrbtree.c b/gtk/gtkrbtree.c
index 0170f2cff1..6810183fcb 100644
--- a/gtk/gtkrbtree.c
+++ b/gtk/gtkrbtree.c
@@ -877,6 +877,32 @@ _gtk_rbtree_mark_invalid (GtkRBTree *tree)
while ((node = _gtk_rbtree_next (tree, node)) != NULL);
}
+void
+_gtk_rbtree_set_fixed_height (GtkRBTree *tree,
+ gint height)
+{
+ GtkRBNode *node;
+
+ if (tree == NULL)
+ return;
+
+ node = tree->root;
+ g_assert (node);
+
+ while (node->left != tree->nil)
+ node = node->left;
+
+ do
+ {
+ if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_INVALID))
+ _gtk_rbtree_node_set_height (tree, node, height);
+
+ if (node->children)
+ _gtk_rbtree_set_fixed_height (node->children, height);
+ }
+ while ((node = _gtk_rbtree_next (tree, node)) != NULL);
+}
+
typedef struct _GtkRBReorder
{
GtkRBTree *children;
diff --git a/gtk/gtkrbtree.h b/gtk/gtkrbtree.h
index f3c585b852..c5b4768db6 100644
--- a/gtk/gtkrbtree.h
+++ b/gtk/gtkrbtree.h
@@ -140,6 +140,8 @@ void _gtk_rbtree_node_mark_valid (GtkRBTree *tree,
GtkRBNode *node);
void _gtk_rbtree_column_invalid (GtkRBTree *tree);
void _gtk_rbtree_mark_invalid (GtkRBTree *tree);
+void _gtk_rbtree_set_fixed_height (GtkRBTree *tree,
+ gint height);
gint _gtk_rbtree_node_find_offset (GtkRBTree *tree,
GtkRBNode *node);
gint _gtk_rbtree_node_find_parity (GtkRBTree *tree,
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 75c84db2b1..7fcaa903a0 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -176,6 +176,8 @@ struct _GtkTreeViewPrivate
gfloat scroll_to_col_align;
guint scroll_to_use_align : 1;
+ guint fixed_height_check : 1;
+
guint reorderable : 1;
guint header_has_focus : 1;
guint drag_column_window_state : 3;
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index ec51a0b05e..955342f115 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -928,6 +928,8 @@ gtk_tree_view_init (GtkTreeView *tree_view)
tree_view->priv->press_start_y = -1;
tree_view->priv->reorderable = FALSE;
tree_view->priv->presize_handler_timer = 0;
+ tree_view->priv->scroll_sync_timer = 0;
+ tree_view->priv->fixed_height_check = 0;
gtk_tree_view_set_adjustments (tree_view, NULL, NULL);
tree_view->priv->selection = _gtk_tree_selection_new_with_tree_view (tree_view);
tree_view->priv->enable_search = TRUE;
@@ -3910,6 +3912,10 @@ do_validate_rows (GtkTreeView *tree_view)
GtkTreePath *path = NULL;
GtkTreeIter iter;
gint i = 0;
+
+ gint prev_height = -1;
+ gboolean fixed_height = TRUE;
+
g_assert (tree_view);
if (tree_view->priv->tree == NULL)
@@ -3919,7 +3925,6 @@ do_validate_rows (GtkTreeView *tree_view)
}
do
{
-
if (! GTK_RBNODE_FLAG_SET (tree_view->priv->tree->root, GTK_RBNODE_DESCENDANTS_INVALID))
{
retval = FALSE;
@@ -3979,9 +3984,29 @@ do_validate_rows (GtkTreeView *tree_view)
gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
}
validated_area = validate_row (tree_view, tree, node, &iter, path) | validated_area;
+
+ if (!tree_view->priv->fixed_height_check)
+ {
+ gint height;
+
+ height = MAX (GTK_RBNODE_GET_HEIGHT (node), tree_view->priv->expander_size);
+ if (prev_height < 0)
+ prev_height = height;
+ else if (prev_height != height)
+ fixed_height = FALSE;
+ }
+
i++;
}
while (i < GTK_TREE_VIEW_NUM_ROWS_PER_IDLE);
+
+ if (!tree_view->priv->fixed_height_check)
+ {
+ if (fixed_height)
+ _gtk_rbtree_set_fixed_height (tree_view->priv->tree, prev_height);
+
+ tree_view->priv->fixed_height_check = 1;
+ }
done:
if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
@@ -7455,6 +7480,7 @@ gtk_tree_view_set_model (GtkTreeView *tree_view,
g_object_unref (tree_view->priv->model);
tree_view->priv->search_column = -1;
GTK_TREE_VIEW_SET_FLAG (tree_view, GTK_TREE_VIEW_IS_LIST);
+ tree_view->priv->fixed_height_check = 0;
}
tree_view->priv->model = model;