Changing the popdown strings of a combo
- From: Cosmin Bonea <cosminb saguaro ro>
- To: gtk-list gnome org
- Subject: Changing the popdown strings of a combo
- Date: Wed, 21 Nov 2001 18:33:48 +0200
Hi all,
I have a problem when I change the popdown strings of a combo.
The popdown strings is changed everytime an option is selected.
After I change it, if I use the mouse to select other option everything's OK,
but if I use the up and down keys to parse the drop down list some warning
message appears, and after a few times a segmentation fault occurs.
The message is:
"Gtk-CRITICAL **: file gtkcontainer.c: line 1209
(gtk_container_set_focus_child): assertion `GTK_IS_WIDGET (widget)' failed. "
Could someone tell what's wrong in my code.
Thank you.
Here is the code:
#include <gtk/gtk.h>
/* pointer to the combo widget */
void *combo = NULL;
void FillCombo()
{
GList *combo1_items = NULL;
gchar *option = NULL;
/* get the current option */
option=gtk_editable_get_chars(GTK_EDITABLE (GTK_COMBO (combo)->entry), 0 , -1);
combo1_items = g_list_append (combo1_items, "item1");
combo1_items = g_list_append (combo1_items, "item2");
combo1_items = g_list_append (combo1_items, "item3");
combo1_items = g_list_append (combo1_items, "item4");
combo1_items = g_list_append (combo1_items, "item5");
combo1_items = g_list_append (combo1_items, "item6");
combo1_items = g_list_append (combo1_items, "item7");
combo1_items = g_list_append (combo1_items, "item8");
combo1_items = g_list_append (combo1_items, "item9");
gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo1_items);
if (combo1_items)
{
g_list_free(combo1_items);
combo1_items=NULL;
}
/* set back the current option */
gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (combo)->entry), option);
if (option)
{
g_free(option);
option=NULL;
}
return;
}
void G_ComboBoxOptionChanged()
{
FillCombo();
return;
}
int main (int argc, char*argv[])
{
GtkWidget *window1;
GtkWidget *hbox1;
GtkWidget *label1;
GtkWidget *combo1;
GtkWidget *combo_entry1;
gtk_init(&argc, &argv);
/* create all the widgets */
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
gtk_window_set_title (GTK_WINDOW (window1), "window1");
gtk_widget_show (window1);
hbox1 = gtk_hbox_new (FALSE, 0);
gtk_widget_ref (hbox1);
gtk_object_set_data_full (GTK_OBJECT (window1), "hbox1", hbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (hbox1);
gtk_container_add (GTK_CONTAINER (window1), hbox1);
label1 = gtk_label_new ("Comb box : ");
gtk_widget_ref (label1);
gtk_object_set_data_full (GTK_OBJECT (window1), "label1", label1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (label1);
gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
combo1 = gtk_combo_new ();
gtk_widget_ref (combo1);
gtk_object_set_data_full (GTK_OBJECT (window1), "combo1", combo1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (combo1);
gtk_box_pack_start (GTK_BOX (hbox1), combo1, FALSE, FALSE, 0);
gtk_combo_set_use_arrows (GTK_COMBO (combo1), FALSE);
gtk_combo_set_value_in_list (GTK_COMBO (combo1), TRUE, FALSE);
/* set the pointer to combo1 */
combo=combo1;
/* connect the "hide" signal of the popwin of the combo box */
gtk_signal_connect_object_after(GTK_OBJECT (GTK_COMBO (combo1)->popwin), "hide", GTK_SIGNAL_FUNC (G_ComboBoxOptionChanged), NULL);
combo_entry1 = GTK_COMBO (combo1)->entry;
gtk_widget_ref (combo_entry1);
gtk_object_set_data_full (GTK_OBJECT (window1), "combo_entry1", combo_entry1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (combo_entry1);
gtk_entry_set_editable (GTK_ENTRY (combo_entry1), FALSE);
/* fill the combo with the options */
FillCombo();
/* set default option */
gtk_entry_set_text (GTK_ENTRY (combo_entry1), "item5");
gtk_main();
return 1;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]