summaryrefslogtreecommitdiff
path: root/gtk/gtkbox.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-02-27 03:35:05 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-02-27 03:35:05 +0000
commita504e62e010dc7e396730a2e377ab16d7cc4b823 (patch)
treeee9c23d02e8814e88d54e54d97d8a188f9f228f8 /gtk/gtkbox.c
parent0205a7bdf2fd7e2c696332c462ec66c15572e01e (diff)
downloadgtk+-a504e62e010dc7e396730a2e377ab16d7cc4b823.tar.gz
Clean up the code so < 0 == end wasn't just a side effect, remove most of
Tue Feb 26 22:22:37 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkbox.c (gtk_box_reorder_child): Clean up the code so < 0 == end wasn't just a side effect, remove most of the manual linked list manipulation code in favor of g_list_* functions. Tue Feb 26 22:01:59 2002 Owen Taylor <otaylor@redhat.com> * gtk/tmpl/gtkbox.sgml: Fix docs to correspond to the code - negative @position indicates the end of the list.
Diffstat (limited to 'gtk/gtkbox.c')
-rw-r--r--gtk/gtkbox.c65
1 files changed, 23 insertions, 42 deletions
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index 82e8aed048..cc0f356702 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -496,62 +496,43 @@ gtk_box_reorder_child (GtkBox *box,
GtkWidget *child,
gint position)
{
- GList *list;
+ GList *old_link;
+ GList *new_link;
+ GtkBoxChild *child_info = NULL;
+ gint old_position;
g_return_if_fail (GTK_IS_BOX (box));
g_return_if_fail (GTK_IS_WIDGET (child));
- list = box->children;
- while (list)
+ old_link = box->children;
+ old_position = 0;
+ while (old_link)
{
- GtkBoxChild *child_info;
-
- child_info = list->data;
+ child_info = old_link->data;
if (child_info->widget == child)
break;
- list = list->next;
+ old_link = old_link->next;
+ old_position++;
}
- if (list && box->children->next)
- {
- GList *tmp_list;
+ g_return_if_fail (old_link != NULL);
- if (list->next)
- list->next->prev = list->prev;
- if (list->prev)
- list->prev->next = list->next;
- else
- box->children = list->next;
+ if (position == old_position)
+ return;
- tmp_list = box->children;
- while (position && tmp_list->next)
- {
- position--;
- tmp_list = tmp_list->next;
- }
+ box->children = g_list_delete_link (box->children, old_link);
- if (position)
- {
- tmp_list->next = list;
- list->prev = tmp_list;
- list->next = NULL;
- }
- else
- {
- if (tmp_list->prev)
- tmp_list->prev->next = list;
- else
- box->children = list;
- list->prev = tmp_list->prev;
- tmp_list->prev = list;
- list->next = tmp_list;
- }
+ if (position < 0)
+ new_link = NULL;
+ else
+ new_link = g_list_nth (box->children, position);
- gtk_widget_child_notify (child, "position");
- if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
- gtk_widget_queue_resize (child);
- }
+ box->children = g_list_insert_before (box->children, new_link, child_info);
+
+ gtk_widget_child_notify (child, "position");
+ if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box))
+ gtk_widget_queue_resize (child);
}
void