RE: Moving tree items
- From: "Lachac, Gerry" <G Lachac dialogic com>
- To: 'Owen Taylor' <otaylor gtk org>
- Cc: "'gtk-list redhat com'" <gtk-list redhat com>
- Subject: RE: Moving tree items
- Date: Thu, 14 May 1998 12:16:04 -0400
Owen Taylor [mailto:otaylor@gtk.org] writes:
> "Lachac, Gerry" <G.Lachac@dialogic.com> writes:
>> Can a similar change also be made for a GtkList as well? I
>> recently had to
>> implement moving things up and down a list by allocating a
>> new GtkListItem,
>> copying the old one and remove it from the list, inserting
>> the new one
>
> For a GtkList no recreation, copying is needed:
>
> GList *items_to_move = g_list_append (NULL, item_to_remove);
>
> gtk_widget_ref (item_to_remove);
> gtk_list_remove_items (GtkList (list), items_to_move);
> gtk_list_insert_items (GtkList (list), items_to_move, new_position);
> gtk_widget_unref (item_to_remove);
>
> To explain the code:
>
> - creates a GList with a single item.
>
> - increments the reference count on the item, so that
> when it is removed from its parent, it is not freed. (Even though
> it is an orphan, somebody cares about it...)
>
> - removes the item from the list
>
> - inserts it in the new position
>
> - unreferences it, since the List now references it again.
>
Have you done this before? I swear I tried this technique (it's the first
thing I thought of). When I tried to insert() the removed item I got
runtime errors from gtk (1.0.1). I discovered that the list->next field was
not NULL after the remove() so re-inserting wreaked all kinds of havoc. I
may have been doing something else wrong, so I'll double check. Thanks for
the tip.
-ger
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]