RE: Unable to get all child widgets



Thanks Havoc, I tried your suggestion... unfortunately it didn't fix my
problem.  Is there some special way that I need to pack the hbox and its
child widgets?  The code works fine to create the window and the widgets are
packed as programmed.  Below are the code snippets that are used for the
hbox and subwidgets creation and subsequent attempt to retreive them by
recursively searching the window, then vbox, then hbox, then widgets of
interest.  The really strange part of this is that I can correctly retrieve
the widget pointers to a vruler, hruler, and drawingarea contained with a
table, an hbox, table, and, combo contained within a vbox, but not a combo
within an hbox.  Again any and all help from anyone would be greatly
appreciated.

code snippet creating the window and populating it with widgets:

/* Function to create a histogram window */
void create_histogram(void)
{
        /* Declaring local defines */
        #define EVENT_METHOD(i, x) GTK_WIDGET_CLASS(GTK_OBJECT(i)->klass)->x



        /* Declaring local variables */
        GtkWidget       *histogram_window,
                        *vbox,
                        *hbox,
                        *label,
                        *table,
                        *hruler,
                        *vruler,
                        *drawing_area,
                        *combo;

        GList           *glist = (GList *) NULL;

        int             index,
                        number_of_tests;

        static char     **glist_items = (char **) NULL;



        /* Creating histogram window */
        histogram_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(histogram_window), "STDF
Histogram");
        gtk_container_set_border_width(GTK_CONTAINER(histogram_window), 5);



        /* Creating vbox to hold window widgets */
        vbox = gtk_vbox_new(FALSE, 2);
        gtk_container_add(GTK_CONTAINER(histogram_window),
GTK_WIDGET(vbox));
        gtk_widget_show(GTK_WIDGET(vbox));



        /* Creating hbox to hold window widgets */
        hbox = gtk_hbox_new(FALSE, 2);
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), FALSE, FALSE,
0);
        gtk_widget_show(GTK_WIDGET(hbox));



        /* Creating label for histogram display mode option */
        label = gtk_label_new("Histogram Display: ");
        gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), FALSE, FALSE,
0);
        gtk_widget_show(GTK_WIDGET(label));



        /* Creating Glist to hold histogram display mode options */
        glist = g_list_append(glist, "Data Only");
        glist = g_list_append(glist, "Up to test limits");
        glist = g_list_append(glist, "Data and test limits");



        /* Creating combo box to hold histogram display mode selections */
        combo = gtk_combo_new();
        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
        g_list_free(glist);
        glist = (GList *) NULL;
        gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE);
        gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry),
FALSE);
        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->list),
"select_child", GTK_SIGNAL_FUNC(set_histogram_display_mode), NULL);
        gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), (gint) 2);
        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
GTK_SIGNAL_FUNC(draw_histogram), histogram_window);
        gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(combo), FALSE, FALSE,
0);
        gtk_widget_show(GTK_WIDGET(combo));



        /* Creating label for number of bins option */
        label = gtk_label_new("Histogram Bins: ");
        gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), FALSE, FALSE,
0);
        gtk_widget_show(GTK_WIDGET(label));



        /* Creating Glist to hold number of bin options */
        glist = g_list_append(glist, "5");
        glist = g_list_append(glist, "10");
        glist = g_list_append(glist, "15");
        glist = g_list_append(glist, "20");
        glist = g_list_append(glist, "25");
        glist = g_list_append(glist, "30");
        glist = g_list_append(glist, "35");
        glist = g_list_append(glist, "40");
        glist = g_list_append(glist, "45");
        glist = g_list_append(glist, "50");



        /* Creating combo box to hold histogram bin selections */
        combo = gtk_combo_new();
        gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
        g_list_free(glist);
        glist = (GList *) NULL;
        gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE);
        gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry),
FALSE);
        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
GTK_SIGNAL_FUNC(set_number_of_bins), NULL);
        gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), (gint) 3);
        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
GTK_SIGNAL_FUNC(draw_histogram), histogram_window);
        gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(combo), FALSE, FALSE,
0);
        gtk_widget_show(GTK_WIDGET(combo));


code snippet searching for combo contained within the hbox and the combo
call resulting in an invalid pointer segfault (last line):


/* Function to plot histogram */
void draw_histogram(GtkWidget *calling_widget, GtkWidget *histogram_window)
{
/* Declaring local variables */
        gint    left_edge = 0,
                top_edge = 0,
                rectangle_width,
                rectangle_height,
                x_start, y_start, x_end, y_end;

        gchar   *entry_text;

        int     index;

        GtkWidget       *vbox = (GtkWidget *) NULL,
                        *hbox = (GtkWidget *) NULL,
                        *table = (GtkWidget *) NULL,
                        *drawing_area = (GtkWidget *) NULL,
                        *test_list_combo = (GtkWidget *) NULL,
                        *histogram_bins_combo = (GtkWidget *) NULL,
                        *vruler = (GtkWidget *) NULL,
                        *hruler = (GtkWidget *) NULL;

        GList           *widget_list;

        double          *results = (double *) NULL,
                        scalar,
                        upper_limit,
                        lower_limit;

        static double   lower_bin_limit,
                        upper_bin_limit,
                        bin_width;

        int             number_of_data_values,
                        memory_index,
                        bin_index;

        static GtkStyle *test_limit_style = (GtkStyle *) NULL;

        GdkColor        red = {0, 0xffff, 0x0000, 0x0000};

        gboolean        color_allocation_ok;



        /* Setting widget address' to local variable names */
        for ( widget_list =
gtk_container_children(GTK_CONTAINER(histogram_window)) ; widget_list !=
NULL ; widget_list = widget_list->next )
        {
                if ( GTK_IS_VBOX(GTK_OBJECT(widget_list->data)) )
                        vbox = GTK_WIDGET(widget_list->data);
        }
        g_list_free(widget_list);
        for ( widget_list = gtk_container_children(GTK_CONTAINER(vbox)) ;
widget_list != NULL ; widget_list = widget_list->next )
        {
                if ( GTK_IS_HBOX(GTK_OBJECT(widget_list->data)) )
                        hbox = GTK_WIDGET(widget_list->data);
                if ( GTK_IS_TABLE(GTK_OBJECT(widget_list->data)) )
                        table = GTK_WIDGET(widget_list->data);
                if ( GTK_IS_COMBO(GTK_OBJECT(widget_list->data)) )
                        test_list_combo = GTK_WIDGET(widget_list->data);
        }
        g_list_free(widget_list);
        for ( widget_list = gtk_container_children(GTK_CONTAINER(hbox)) ;
widget_list != NULL ; widget_list = widget_list->next )
        {
                if ( GTK_IS_COMBO(GTK_OBJECT(widget_list->data)) )
                        histogram_bins_combo =
GTK_WIDGET(widget_list->data);
        }
        g_list_free(widget_list);
        for ( widget_list = gtk_container_children(GTK_CONTAINER(table)) ;
widget_list != NULL ; widget_list = widget_list->next )
        {
                if ( GTK_IS_DRAWING_AREA(GTK_OBJECT(widget_list->data)) )
                        drawing_area = GTK_WIDGET(widget_list->data);
                if ( GTK_IS_HRULER(GTK_OBJECT(widget_list->data)) )
                        hruler = GTK_WIDGET(widget_list->data);
                if ( GTK_IS_VRULER(GTK_OBJECT(widget_list->data)) )
                        vruler = GTK_WIDGET(widget_list->data);
        }
        g_list_free(widget_list);



        /* Clearing GtkDrawingArea widget */
        rectangle_width = GTK_WIDGET(drawing_area)->allocation.width;
        rectangle_height = GTK_WIDGET(drawing_area)->allocation.height;
        gdk_draw_rectangle(GTK_WIDGET(drawing_area)->window,
GTK_WIDGET(drawing_area)->style->white_gc, TRUE,
                           0, 0, rectangle_width, rectangle_height);



        /* Checking wheither to refresh image or recalculate histogram */
        entry_text =
gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(test_list_combo)->entry));
        if ( strcmp(entry_text, "Select a test") == 0 )
                return;



        /* Changing cursor to let user know application is busy */
        gdk_window_set_cursor(GTK_WIDGET(drawing_area)->window,
watch_cursor);



        /* Setting up x-axis boundaries */
        results = test_data[atoi(entry_text)]->results;
        number_of_data_values = test_data[atoi(entry_text)]->exec_cnt;
        histogram_data.number_of_bins =
atoi(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(histogram_bins_combo)->entry)));


----------
From:         Havoc Pennington[SMTP:hp redhat com]
Sent:         Thursday, September 21, 2000 12:13 AM
To:   Dugas, Alan
Cc:   gtk-app-devel-list gnome org; gtk-list gnome org
Subject:      Re: Unable to get all child widgets


"Dugas, Alan" <alan dugas analog com> writes:
g_free(widget_list);

Use g_list_free(widget_list), the above line corrupts memory so could
cause all sorts of fun effects.

Havoc

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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