Re: Patch for #59222, and small code cleanup
- From: Kristian Rietveld <kristian planet nl>
- To: Jonathan Blandford <jrb redhat com>
- Cc: GTK Development list <gtk-devel-list gnome org>
- Subject: Re: Patch for #59222, and small code cleanup
- Date: Sun, 2 Sep 2001 20:56:55 +0200 (CEST)
On 2 Sep 2001, Jonathan Blandford wrote:
> Kristian Rietveld <kristian planet nl> writes:
>
> > Hi,
> >
> > Here's a patch that fixes #59222. It also contains some small code
> > cleanups of the treeview search code. Details are in ChangeLog.
>
> Doesn't apply. You seem to have half added user_data to the search
> func, and not added the destroy -- check out current CVS. Secondly, you
> seem to be getting the path every time, and then looking up the tree.
> This is pretty inefficient. I think I would walk the RBTree and keep
> the iter in sync internally. This is done in a number of places. The
> easiest to copy is probably the code in gtk_tree_selection_foreach.
Fixed, new patch appended.
Ok to commit?
regards,
Kris
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2237
diff -u -r1.2237 ChangeLog
--- ChangeLog 2001/09/01 20:56:40 1.2237
+++ ChangeLog 2001/09/02 18:53:03
@@ -1,3 +1,12 @@
+Sun Sep 2 13:15:07 2001 Kristian Rietveld <kristian planet nl>
+
+ * gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
+ fix for bug #59222.
+
+ * gtk/gtktreeview.c (gtk_tree_view_search_equal_func): add
+ gpointer search_data argument to function definition and
+ prototype, to match GtkTreeViewSearchEqualFunc typedef.
+
Sat Sep 1 21:57:27 2001 Kristian Rietveld <kristian planet nl>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): add warnings
Index: gtk/gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.131
diff -u -r1.131 gtktreeview.c
--- gtk/gtktreeview.c 2001/09/01 04:14:24 1.131
+++ gtk/gtktreeview.c 2001/09/02 18:53:12
@@ -364,7 +364,8 @@
static gboolean gtk_tree_view_search_equal_func (GtkTreeModel *model,
gint column,
gchar *key,
- GtkTreeIter *iter);
+ GtkTreeIter *iter,
+ gpointer search_data);
static gboolean gtk_tree_view_search_iter (GtkTreeModel *model,
GtkTreeSelection *selection,
GtkTreeIter *iter,
@@ -8865,7 +8866,8 @@
gtk_tree_view_search_equal_func (GtkTreeModel *model,
gint column,
gchar *key,
- GtkTreeIter *iter)
+ GtkTreeIter *iter,
+ gpointer search_data)
{
gboolean retval = TRUE;
gchar *normalized_string;
@@ -8903,78 +8905,108 @@
gint *count,
gint n)
{
+ GtkRBTree *tree = NULL;
+ GtkRBNode *node = NULL;
+ GtkTreePath *path;
+
GtkTreeView *tree_view = gtk_tree_selection_get_tree_view (selection);
GtkTreeViewColumn *column =
gtk_tree_view_get_column (tree_view, tree_view->priv->search_column);
-
- if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
- {
- (*count)++;
-
- if (*count == n)
- {
- GtkTreePath *path;
-
- gtk_tree_selection_select_iter (selection, iter);
-
- path = gtk_tree_model_get_path (model, iter);
- gtk_tree_view_scroll_to_cell (tree_view, path, column, TRUE, 0.5, 0.5);
- gtk_tree_view_real_set_cursor (tree_view, path, FALSE);
- gtk_tree_path_free (path);
-
- return TRUE;
- }
- }
-
- if (gtk_tree_model_iter_has_child (model, iter))
- {
- gboolean ret;
- GtkTreeIter child;
-
- gtk_tree_model_iter_children (model, &child, iter);
- ret = gtk_tree_view_search_iter (model, selection,
- &child, text,
- count, n);
-
- if (ret)
- return TRUE; /* iter found and selected */
- }
-
- while (gtk_tree_model_iter_next (model, iter))
+
+ path = gtk_tree_model_get_path (model, iter);
+ _gtk_tree_view_find_node (tree_view, path, &tree, &node);
+
+ do
{
if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
{
(*count)++;
if (*count == n)
{
- GtkTreePath *path;
-
gtk_tree_selection_select_iter (selection, iter);
-
- path = gtk_tree_model_get_path (model, iter);
- gtk_tree_view_scroll_to_cell (tree_view, path, column, TRUE, 0.5, 0.5);
+ gtk_tree_view_scroll_to_cell (tree_view, path, column,
+ TRUE, 0.5, 0.5);
gtk_tree_view_real_set_cursor (tree_view, path, FALSE);
- gtk_tree_path_free (path);
+
+ if (path)
+ gtk_tree_path_free (path);
return TRUE;
}
}
-
- if (gtk_tree_model_iter_has_child (model, iter))
- {
- gboolean ret;
- GtkTreeIter child;
-
- gtk_tree_model_iter_children (model, &child, iter);
- ret = gtk_tree_view_search_iter (model, selection,
- &child, text,
- count, n);
- if (ret)
- return TRUE; /* iter found and selected */
- }
+ if (node->children)
+ {
+ gboolean has_child;
+ GtkTreeIter tmp;
+
+ tree = node->children;
+ node = tree->root;
+
+ while (node->left != tree->nil)
+ node = node->left;
+
+ tmp = *iter;
+ has_child = gtk_tree_model_iter_children (model, iter, &tmp);
+ gtk_tree_path_append_index (path, 0);
+
+ /* sanity check */
+ TREE_VIEW_INTERNAL_ASSERT (has_child, FALSE);
+ }
+ else
+ {
+ gboolean done = FALSE;
+
+ do
+ {
+ node = _gtk_rbtree_next (tree, node);
+
+ if (node)
+ {
+ gboolean has_next;
+
+ has_next = gtk_tree_model_iter_next (model, iter);
+
+ done = TRUE;
+ gtk_tree_path_next (path);
+
+ /* sanity check */
+ TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
+ }
+ else
+ {
+ gboolean has_parent;
+ GtkTreeIter tmp_iter = *iter;
+
+ node = tree->parent_node;
+ tree = tree->parent_tree;
+
+ if (!tree)
+ {
+ if (path)
+ gtk_tree_path_free (path);
+
+ /* we've run out of tree, done with this func */
+ return FALSE;
+ }
+
+ has_parent = gtk_tree_model_iter_parent (model,
+ iter,
+ &tmp_iter);
+ gtk_tree_path_up (path);
+
+ /* sanity check */
+ TREE_VIEW_INTERNAL_ASSERT (has_parent, FALSE);
+ }
+ }
+ while (!done);
+ }
}
+ while (1);
+ if (path)
+ gtk_tree_path_free (path);
+
return FALSE;
}
--
Odi et amo. Quare id faciam, fortasse requiris?
Nescio, sed fieri sentio et excrucior.
-Catullus (Carmen 85)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]