1 /* Entry/Entry Completion
3 * GtkEntryCompletion provides a mechanism for adding support for
4 * completion in GtkEntry.
10 static GtkWidget *window = NULL;
12 /* Creates a tree model containing the completions */
14 create_completion_model (void)
19 store = gtk_list_store_new (1, G_TYPE_STRING);
22 gtk_list_store_append (store, &iter);
23 gtk_list_store_set (store, &iter, 0, "GNOME", -1);
25 /* Append another word */
26 gtk_list_store_append (store, &iter);
27 gtk_list_store_set (store, &iter, 0, "total", -1);
29 /* And another word */
30 gtk_list_store_append (store, &iter);
31 gtk_list_store_set (store, &iter, 0, "totally", -1);
33 return GTK_TREE_MODEL (store);
38 do_entry_completion (GtkWidget *do_widget)
40 GtkWidget *content_area;
44 GtkEntryCompletion *completion;
45 GtkTreeModel *completion_model;
49 window = gtk_dialog_new_with_buttons ("GtkEntryCompletion",
50 GTK_WINDOW (do_widget),
55 gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
57 g_signal_connect (window, "response",
58 G_CALLBACK (gtk_widget_destroy), NULL);
59 g_signal_connect (window, "destroy",
60 G_CALLBACK (gtk_widget_destroyed), &window);
62 content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
64 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
65 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
66 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
68 label = gtk_label_new (NULL);
69 gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
70 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
72 /* Create our entry */
73 entry = gtk_entry_new ();
74 gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
76 /* Create the completion object */
77 completion = gtk_entry_completion_new ();
79 /* Assign the completion to the entry */
80 gtk_entry_set_completion (GTK_ENTRY (entry), completion);
81 g_object_unref (completion);
83 /* Create a tree model and use it as the completion model */
84 completion_model = create_completion_model ();
85 gtk_entry_completion_set_model (completion, completion_model);
86 g_object_unref (completion_model);
88 /* Use model column 0 as the text column */
89 gtk_entry_completion_set_text_column (completion, 0);
92 if (!gtk_widget_get_visible (window))
93 gtk_widget_show_all (window);
95 gtk_widget_destroy (window);