From a504e62e010dc7e396730a2e377ab16d7cc4b823 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 27 Feb 2002 03:35:05 +0000 Subject: [PATCH] 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 * 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 * gtk/tmpl/gtkbox.sgml: Fix docs to correspond to the code - negative @position indicates the end of the list. --- ChangeLog | 7 ++++ ChangeLog.pre-2-0 | 7 ++++ ChangeLog.pre-2-10 | 7 ++++ ChangeLog.pre-2-2 | 7 ++++ ChangeLog.pre-2-4 | 7 ++++ ChangeLog.pre-2-6 | 7 ++++ ChangeLog.pre-2-8 | 7 ++++ docs/reference/ChangeLog | 5 +++ docs/reference/gtk/tmpl/gtkbox.sgml | 5 +-- gtk/gtkbox.c | 65 ++++++++++------------------- 10 files changed, 79 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 84beffbc84..4e1f61af9f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Tue Feb 26 22:22:37 2002 Owen Taylor + + * 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 21:44:01 2002 Owen Taylor * config.status config.guess: Remove these files diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 3ccf8db271..cdae15cf5b 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +Tue Feb 26 22:01:59 2002 Owen Taylor + + * gtk/tmpl/gtkbox.sgml: Fix docs to correspond to the code - + negative @position indicates the end of the list. + 2002-02-26 Matthias Clasen Fixes for #72478: diff --git a/docs/reference/gtk/tmpl/gtkbox.sgml b/docs/reference/gtk/tmpl/gtkbox.sgml index 01dfc126ce..09c0cec709 100644 --- a/docs/reference/gtk/tmpl/gtkbox.sgml +++ b/docs/reference/gtk/tmpl/gtkbox.sgml @@ -326,15 +326,14 @@ were added to @box. A widget's position in the @box children list determines where the widget is packed into @box. A child widget at some position in the list will be packed just after all other widgets of the same packing -type that appear earlier in the list. A negative value of @position is -interpreted as position 0. +type that appear earlier in the list. @box: a #GtkBox. @child: the #GtkWidget to move. @position: the new position for @child in the children list of #GtkBox-struct, starting -from 0. +from 0. If negative, indicates the end of the list. 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