RE: [gtk-list] Re: question about resizing & combos




Question 1: none of the alternatives you state :-)

What it does is iterate through the glist constructing list elements
using the data elements. It is then up to you to destroy the glist
(or whatever you want to do with it).

Question 2: well, it doesn't free the glist because it never had
ownership of it in the first place. It clears the contents of the
list and builds a new one using the new list.

Question 3: moot.

-tony


On 27-Oct-99 Gustavo Joćo Alves Marques Carneiro wrote:
>       I can't find any other problem, maybe because there isn't
enough
> documentation available on GtkCombo. I, myself, have some doubts
> about its
> usage, and I hope one of the developers can englighten me:
> 
>       1.- The function 'gtk_combo_set_popdown_strings(
GTK_COMBO(combo),
> glist)': 
>       o does it copy the glist we supply but not the data pointed
to by
> its elements, or,
>       o does it copy the glist and the data (strings), or,
>       o it doesn't copy anything and takes ownership of the glist
and
> the strings, or,
>       o it takes ownership of the glist but not its data.
> 
>       2.- The function 'gtk_combo_set_popdown_strings(
GTK_COMBO(combo),
> glist)', when the combo already has a glist of strings
>       o does it free the previous glist? If so, its data also?
> 
>       3.- In case the combo takes ownership of the glist, do
changes in
> the glist automatically appear in the widget?
> 
>       So, as you can see, I'm also a bit confused about Combos :).
> 
> On Wed, 27 Oct 1999, Giaslas Georgios wrote:
> 
>> i think you have right Gustavo, but this code is just a sample
>> from
>> a part of a program i'm writing
>> in my real programm the strings are `dynamic` so there
>> must be another problem
>> 
>> On Wed, 27 Oct 1999, [ISO-8859-1] Gustavo Joćo Alves Marques
>> Carneiro wrote:
>> 
>> >    Ok. I think I found another problem. You have created a glist
>> >    that
>> > contains a list of 'static' strings. Those strings are embedded
>> > in the
>> > program code by the compiler and can't be freed. Each item of
>> > glist->data
>> > is a pointer to one of those static strings. It's not dynamic
>> > memory
>> > allocation, so you don't have to bother releasing it -- it will
>> > be done
>> > automatically. Just remove the g_free. 
>> > 
>> > 
>> > On Wed, 27 Oct 1999, Giaslas Georgios wrote:
>> > 
>> > > Thank you Gustavo for replying so quick 
>> > > 
>> > > i tried to put g_free(l->data) before g_list_remove
>> > > but i get a segmentation fault when the program tries to
>> > > execute g_free
>> > > 
>> > > i also checked with gdb that 'while' doesn't ever result 
>> > > in an endless loop.
>> > > 
>> > > So, there must be another problem
>> > > 
>> > > Thanx anyway
>> > > -----------------------------------------
>> > > > 2) i have a combo box and when the user selects
>> > > >    a string i want all the strings before this to be
>> > > >    removed.
>> > > >    i've done it and when i change the comboentry using
>> > > >    arrow keys it's ok. but when it's changed using the
>> > > >    mouse i get a segmentation fault.
>> > > >    Is it a bug or it's my fault?
>> > > >    please try the following little program to see what
>> > > >    i mean exactly.
>> > > >
>> > > > (I use gtk+ version 1.2.6)
>> > > >
>> > > > Please reply this time...
>> > > >
>> > > > Thank you all
>> > > >
>> > > > -----------------------------
>> > > > #include <gtk/gtk.h>
>> > > >
>> > > > GList *glist=NULL;
>> > > >    gint active=0;
>> > > >    GtkWidget *combo;
>> > > >    GtkWidget *window;
>> > > >
>> > > >    static gint delete_callback(GtkWidget *widget, gpointer
>> > > >    data)
>> > > >    {
>> > > >        gtk_main_quit();
>> > > >        return(FALSE);
>> > > >    }
>> > > >
>> > > >    void callback(GtkEntry *comboentry, gpointer data)
>> > > >    {
>> > > >        GList *l;
>> > > >        gint cnt=0;
>> > > >        if (active)
>> > > >        {
>> > > >            l=g_list_first(glist);
>> > > >            while (g_strcasecmp(l->data,
>> > > >            gtk_entry_get_text(comboentry)))
>> > > >            {
>> > > >                g_print("data %s deleted\n", (gchar *)
>> > > >                l->data);
>> > > >                glist=g_list_remove(glist, l->data);
>> > > >                g_free(l->data);
>> > > 
>> > > >        g_free(l->data) should come before g_list_remove
>> > > >        because it is
>> > > >not guaranteed that the location pointed by 'l' is valid
>> > > >after you remove
>> > > 
>> > > >it from the list.
>> > > 
>> > > >                cnt++;
>> > > >                l=g_list_first(glist);
>> > > >            }
>> > > >        Also, you should take care that this previous 'while'
>> > > >        doesn't
>> > > ever
>> > > >result in an endless loop.
>> > > 
>> > > >            gtk_combo_set_popdown_strings(GTK_COMBO(combo),
>> > > >            glist);
>> > > >        }
>> > > >    }
>> > > >
>> > > >    int main (int argc, char *argv[])
>> > > >    {
>> > > >        gtk_init(&argc, &argv);
>> > > >        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
>> > > >        gtk_signal_connect(GTK_OBJECT(window),
>> > > >        "delete_event",
>> > > >                            GTK_SIGNAL_FUNC(delete_callback),
>> > > >                            NULL);
>> > > >        combo=gtk_combo_new();
>> > > >        glist = g_list_append(glist, "String 1");
>> > > >        glist = g_list_append(glist, "String 2");
>> > > >        glist = g_list_append(glist, "String 3");
>> > > >        glist = g_list_append(glist, "String 4");
>> > > >        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry)
>> > > >        ,
>> > > "changed",
>> > > >  GTK_SIGNAL_FUNC(callback), NULL);
>> > > >
>> > > >        gtk_combo_set_popdown_strings( GTK_COMBO(combo),
>> > > >        glist);
>> > > >        gtk_container_add(GTK_CONTAINER(window), combo);
>> > > >        gtk_widget_show_all(window);
>> > > >        active=1;
>> > > >        gtk_main();
>> > > >        return 0;
>> > > >    }
>> > > > --------------------------
>> > > >
>> > > 
>> > > 
>> > > 
>> > 
>> > -- 
>> > Gustavo J.A.M. Carneiro
>> > World::Portugal::FEUP::DEEC::LEEC::TEC
>> > [reinolinux.fe.up.pt/~ee96090]
>> >                                        
>> > 
>> > -- 
>> > To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com
>> > < /dev/null
>> > 
>> > 
>> 
>> --
>> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
>> /dev/null
>> 
>> 
> 
> -- 
> Gustavo J.A.M. Carneiro
> World::Portugal::FEUP::DEEC::LEEC::TEC
> [reinolinux.fe.up.pt/~ee96090]
>                                        
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
> /dev/null

---
E-Mail: trog@gtk.org
It matters not whether you win or lose; what matters is whether II win or lose.
		-- Darrin Weinberg

Go Bezerk! http://www.gtk.org/~trog



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]