#include #include static void select_callback (GtkList *list, GtkWidget *item) { gint index = gtk_list_child_position (list, item); g_print ("selected %d\n", index); } static void text_changed (GtkEntry *entry, GtkList *list) { int count; GList *popdown; const char *text = gtk_entry_get_text (entry); g_print ("entry text is \"%s\"\n", text); for (count = 0, popdown = list->children; popdown; count++, popdown = popdown->next) { /* WARNING: this only works if you *know* that the item * is a label. You really *should* test for it! */ GtkLabel *label = GTK_LABEL (GTK_BIN (popdown->data)->child); char *label_string; gtk_label_get (label, &label_string); if (strcmp (text, label_string) == 0) { g_print ("text \"%s\" found at index %d\n", text, count); return; } } g_print ("text \"%s\" not found in list\n", text); } int main (int argc, char *argv[]) { GtkWidget *win; GtkWidget *combo; GList *popdown_list; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); // create popdown items popdown_list = NULL; popdown_list = g_list_prepend (popdown_list, "three"); popdown_list = g_list_prepend (popdown_list, "two"); popdown_list = g_list_prepend (popdown_list, "one"); combo = gtk_combo_new (); gtk_combo_set_popdown_strings (GTK_COMBO (combo), popdown_list); gtk_container_add (GTK_CONTAINER (win), combo); gtk_signal_connect (GTK_OBJECT (GTK_COMBO(combo)->list), "select-child", GTK_SIGNAL_FUNC (select_callback), NULL); gtk_signal_connect (GTK_OBJECT (GTK_COMBO(combo)->entry), "changed", GTK_SIGNAL_FUNC (text_changed), GTK_COMBO(combo)->list); gtk_widget_show_all (win); gtk_main (); return 0; }