Replace broken, overly clever implementation with one that works.

Sat Oct 23 16:07:46 2004  Søren Sandmann  <sandmann@redhat.com>

	* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
	clever implementation with one that works.

	* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
	instead of "changed" twice.

	Bug 153479
This commit is contained in:
Søren Sandmann 2004-10-23 20:10:40 +00:00 committed by Søren Sandmann Pedersen
parent 8ebef872f3
commit 38df3fec77
6 changed files with 107 additions and 48 deletions

View File

@ -1,3 +1,13 @@
Sat Oct 23 16:07:46 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
clever implementation with one that works.
* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
instead of "changed" twice.
Bug 153479
Sat Oct 23 15:17:55 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check

View File

@ -1,3 +1,13 @@
Sat Oct 23 16:07:46 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
clever implementation with one that works.
* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
instead of "changed" twice.
Bug 153479
Sat Oct 23 15:17:55 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check

View File

@ -1,3 +1,13 @@
Sat Oct 23 16:07:46 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
clever implementation with one that works.
* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
instead of "changed" twice.
Bug 153479
Sat Oct 23 15:17:55 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check

View File

@ -1,3 +1,13 @@
Sat Oct 23 16:07:46 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtksequence.c (_gtk_sequence_swap): Replace broken, overly
clever implementation with one that works.
* gtk/gtkliststore.c (gtk_list_store_swap): emit "rows_reordered"
instead of "changed" twice.
Bug 153479
Sat Oct 23 15:17:55 2004 Søren Sandmann <sandmann@redhat.com>
* gtk/gtkmenutoolbutton.c (button_state_changed_cb): Remove check

View File

@ -1426,43 +1426,6 @@ gtk_list_store_reorder (GtkListStore *store,
gtk_tree_path_free (path);
}
/**
* gtk_list_store_swap:
* @store: A #GtkListStore.
* @a: A #GtkTreeIter.
* @b: Another #GtkTreeIter.
*
* Swaps @a and @b in @store. Note that this function only works with
* unsorted stores.
*
* Since: 2.2
**/
void
gtk_list_store_swap (GtkListStore *store,
GtkTreeIter *a,
GtkTreeIter *b)
{
GtkTreePath *path;
g_return_if_fail (GTK_IS_LIST_STORE (store));
g_return_if_fail (!GTK_LIST_STORE_IS_SORTED (store));
g_return_if_fail (VALID_ITER (a, store));
g_return_if_fail (VALID_ITER (b, store));
if (a->user_data == b->user_data)
return;
_gtk_sequence_swap (a->user_data, b->user_data);
/* emit signal */
path = gtk_tree_path_new ();
gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, a);
gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, b);
gtk_tree_path_free (path);
}
static GHashTable *
save_positions (GtkSequence *seq)
{
@ -1502,6 +1465,48 @@ generate_order (GtkSequence *seq,
return order;
}
/**
* gtk_list_store_swap:
* @store: A #GtkListStore.
* @a: A #GtkTreeIter.
* @b: Another #GtkTreeIter.
*
* Swaps @a and @b in @store. Note that this function only works with
* unsorted stores.
*
* Since: 2.2
**/
void
gtk_list_store_swap (GtkListStore *store,
GtkTreeIter *a,
GtkTreeIter *b)
{
GHashTable *old_positions;
gint *order;
GtkTreePath *path;
g_return_if_fail (GTK_IS_LIST_STORE (store));
g_return_if_fail (!GTK_LIST_STORE_IS_SORTED (store));
g_return_if_fail (VALID_ITER (a, store));
g_return_if_fail (VALID_ITER (b, store));
if (a->user_data == b->user_data)
return;
old_positions = save_positions (store->seq);
_gtk_sequence_swap (a->user_data, b->user_data);
order = generate_order (store->seq, old_positions);
path = gtk_tree_path_new ();
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (store),
path, NULL, order);
gtk_tree_path_free (path);
g_free (order);
}
static void
gtk_list_store_move_to (GtkListStore *store,
GtkTreeIter *iter,

View File

@ -1070,21 +1070,35 @@ void
_gtk_sequence_swap (GtkSequencePtr a,
GtkSequencePtr b)
{
GtkSequenceNode temp;
gpointer temp_data;
GtkSequenceNode *leftmost, *rightmost, *rightmost_next;
int a_pos, b_pos;
g_return_if_fail (!_gtk_sequence_ptr_is_end (a));
g_return_if_fail (!_gtk_sequence_ptr_is_end (b));
if (a == b)
return;
a_pos = _gtk_sequence_ptr_get_position (a);
b_pos = _gtk_sequence_ptr_get_position (b);
if (a_pos > b_pos)
{
leftmost = b;
rightmost = a;
}
else
{
leftmost = a;
rightmost = b;
}
rightmost_next = _gtk_sequence_node_next (rightmost);
/* Situation now: ..., leftmost, ......., rightmost, rightmost_next, ... */
/* swap contents of the nodes */
temp = *a;
*a = *b;
*b = temp;
/* swap data back */
temp_data = a->data;
a->data = b->data;
b->data = temp_data;
_gtk_sequence_move (rightmost, leftmost);
_gtk_sequence_move (leftmost, rightmost_next);
}
void