3 * GtkEntryCompletion provides a mechanism for adding support for
4 * completion in GtkEntry.
11 static GtkWidget *window = NULL;
13 /* Creates a tree model containing the completions */
15 create_completion_model (void)
20 store = gtk_list_store_new (1, G_TYPE_STRING);
23 gtk_list_store_append (store, &iter);
24 gtk_list_store_set (store, &iter, 0, "GNOME", -1);
26 /* Append another word */
27 gtk_list_store_append (store, &iter);
28 gtk_list_store_set (store, &iter, 0, "total", -1);
30 /* And another word */
31 gtk_list_store_append (store, &iter);
32 gtk_list_store_set (store, &iter, 0, "totally", -1);
34 return GTK_TREE_MODEL (store);
39 do_entry_completion (GtkWidget *do_widget)
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 vbox = gtk_vbox_new (FALSE, 5);
63 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0);
64 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
66 label = gtk_label_new (NULL);
67 gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
68 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
70 /* Create our entry */
71 entry = gtk_entry_new ();
72 gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
74 /* Create the completion object */
75 completion = gtk_entry_completion_new ();
77 /* Assign the completion to the entry */
78 gtk_entry_set_completion (GTK_ENTRY (entry), completion);
79 g_object_unref (completion);
81 /* Create a tree model and use it as the completion model */
82 completion_model = create_completion_model ();
83 gtk_entry_completion_set_model (completion, completion_model);
84 g_object_unref (completion_model);
86 /* Use model column 0 as the text column */
87 gtk_entry_completion_set_text_column (completion, 0);
90 if (!GTK_WIDGET_VISIBLE (window))
91 gtk_widget_show_all (window);
93 gtk_widget_destroy (window);