Commit ed6076b2 authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford

new function to handle reordering of trees. Seems to mostly work w/ the

Wed Mar 28 17:27:12 2001  Jonathan Blandford  <jrb@redhat.com>

	* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
	handle reordering of trees.  Seems to mostly work w/ the exception
	of the parity flag.

	* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
	signal.
parent 16e6c16a
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
Wed Mar 28 17:27:12 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkrbtree.c (_gtk_rbtree_reorder): new function to
handle reordering of trees. Seems to mostly work w/ the exception
of the parity flag.
* gtk/gtktreeview.c (gtk_tree_view_reordered): handle "reordered"
signal.
Wed Mar 28 21:12:37 2001 Tim Janik <timj@gtk.org>
* gtk/gtkwidget.h: c++ fixes.
......
......@@ -714,6 +714,101 @@ _gtk_rbtree_node_set_height (GtkRBTree *tree,
}
}
typedef struct _GtkRBReorder
{
GtkRBTree *children;
gint height;
gint flags;
gint order;
} GtkRBReorder;
static int
gtk_rbtree_reorder_sort_func (gconstpointer a,
gconstpointer b)
{
return ((GtkRBReorder *) a)->order > ((GtkRBReorder *) b)->order;
}
static void
gtk_rbtree_reorder_fixup (GtkRBTree *tree,
GtkRBNode *node)
{
if (node == tree->nil)
return;
if (node->left != tree->nil)
{
gtk_rbtree_reorder_fixup (tree, node->left);
node->offset += node->left->offset;
}
if (node->right != tree->nil)
{
gtk_rbtree_reorder_fixup (tree, node->right);
node->offset += node->right->offset;
}
if (node->children)
node->offset += node->children->root->offset;
}
/* It basically pulls everything out of the tree, rearranges it, and puts it
* back together. Our strategy is to keep the old RBTree intact, and just
* rearrange the contents. When that is done, we go through and update the
* heights. There is probably a more elegant way to write this function. If
* anyone wants to spend the time writing it, patches will be accepted.
*/
void
_gtk_rbtree_reorder (GtkRBTree *tree,
gint *new_order,
gint length)
{
GtkRBReorder reorder;
GArray *array;
GtkRBNode *node;
gint i;
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
/* Sort the trees values in the new tree. */
array = g_array_sized_new (FALSE, FALSE, sizeof (GtkRBReorder), length);
for (i = 0; i < length; i++)
{
g_assert (node != tree->nil);
reorder.children = node->children;
reorder.flags = GTK_RBNODE_NON_COLORS & node->flags;
reorder.height = GTK_RBNODE_GET_HEIGHT (node);
reorder.order = new_order[i];
g_array_append_val (array, reorder);
node = _gtk_rbtree_next (tree, node);
}
g_array_sort (array, gtk_rbtree_reorder_sort_func);
/* rewind node*/
node = tree->root;
while (node && node->left != tree->nil)
node = node->left;
/* Go through the tree and change the values to the new ones. */
for (i = 0; i < length; i++)
{
reorder = g_array_index (array, GtkRBReorder, i);
node->children = reorder.children;
node->flags = GTK_RBNODE_GET_COLOR (node) | reorder.flags;
/* We temporarily set the height to this. */
node->offset = reorder.height;
node = _gtk_rbtree_next (tree, node);
}
gtk_rbtree_reorder_fixup (tree, tree->root);
}
gint
_gtk_rbtree_node_find_offset (GtkRBTree *tree,
GtkRBNode *node)
......
......@@ -32,8 +32,7 @@ typedef enum
GTK_RBNODE_IS_PARENT = 1 << 2,
GTK_RBNODE_IS_SELECTED = 1 << 3,
GTK_RBNODE_IS_PRELIT = 1 << 4,
GTK_RBNODE_IS_VIEW = 1 << 5,
GTK_RBNODE_NON_COLORS = GTK_RBNODE_IS_PARENT | GTK_RBNODE_IS_SELECTED | GTK_RBNODE_IS_PRELIT | GTK_RBNODE_IS_VIEW,
GTK_RBNODE_NON_COLORS = GTK_RBNODE_IS_PARENT | GTK_RBNODE_IS_SELECTED | GTK_RBNODE_IS_PRELIT,
} GtkRBNodeColor;
typedef struct _GtkRBTree GtkRBTree;
......@@ -110,6 +109,9 @@ GtkRBNode *_gtk_rbtree_insert_after (GtkRBTree *tree,
gint height);
void _gtk_rbtree_remove_node (GtkRBTree *tree,
GtkRBNode *node);
void _gtk_rbtree_reorder (GtkRBTree *tree,
gint *new_order,
gint length);
GtkRBNode *_gtk_rbtree_find_count (GtkRBTree *tree,
gint count);
void _gtk_rbtree_node_set_height (GtkRBTree *tree,
......
......@@ -3016,7 +3016,8 @@ gtk_tree_view_reordered (GtkTreeModel *model,
gpointer data)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (data);
GArray *array;
GtkRBTree *tree;
GtkRBNode *node;
gint len;
len = gtk_tree_model_iter_n_children (model, iter);
......@@ -3024,7 +3025,25 @@ gtk_tree_view_reordered (GtkTreeModel *model,
if (len < 2)
return;
gtk_widget_queue_draw (GTK_WIDGET (data));
if (_gtk_tree_view_find_node (tree_view,
parent,
&tree,
&node))
return;
/* We need to special case the parent path */
if (tree == NULL)
tree = tree_view->priv->tree;
else
tree = node->children;
if (tree == NULL)
return;
/* FIXME: we need to unprelight our tree, if it's prelit. */
_gtk_rbtree_reorder (tree, new_order, len);
gtk_widget_queue_draw (GTK_WIDGET (tree_view));
}
/* Internal tree functions */
......@@ -3474,9 +3493,7 @@ _gtk_tree_view_find_path (GtkTreeView *tree_view,
return path;
}
/* Returns TRUE if we ran out of tree before finding the node,
* so the returned node is the last node we saw and the returned
* tree is NULL
/* Returns TRUE if we ran out of tree before finding the path.
*/
gboolean
_gtk_tree_view_find_node (GtkTreeView *tree_view,
......@@ -3493,6 +3510,8 @@ _gtk_tree_view_find_node (GtkTreeView *tree_view,
*node = NULL;
*tree = NULL;
if (depth == 0)
return FALSE;
do
{
if (tmptree == NULL)
......
......@@ -16,7 +16,7 @@ static ListSort data[] =
{ "Oranges", "Wicker", "Adamantine", "Convivial" },
{ "Bovine Spongiform Encephilopathy", "Sleazebucket", "Mountaineer", "Pander" },
{ "Foot and Mouth", "Lampshade", "Skim Milk Full Milk", "Viewless" },
{ "Blood, sweat, tears", "The Man", "Horses", "Muckety-Muck" },
{ "Blood,\nsweat,\ntears", "The Man", "Horses", "Muckety-Muck" },
{ "Rare Steak", "Siam", "Watchdog", "Xantippe" },
{ "SIGINT", "Rabbit Breath", "Alligator", "Bloodstained" },
{ "Google", "Chrysanthemums", "Hobnob", "Leapfrog"},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment