diff options
author | Matthias Clasen <maclas@gmx.de> | 2004-01-07 22:19:51 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-01-07 22:19:51 +0000 |
commit | 5c919e50d3c197daa2e5524315f08adf0108c291 (patch) | |
tree | 54b3db66f53913bfa97dd44db3769124c73790d8 /demos | |
parent | bdc6765be7414666910f990106679b49a4756098 (diff) | |
download | gtk+-5c919e50d3c197daa2e5524315f08adf0108c291.tar.gz |
Add entry_completion.c
Wed Jan 7 23:20:06 2004 Matthias Clasen <maclas@gmx.de>
* demos/gtk-demo/Makefile.am (demos): Add entry_completion.c
* demos/gtk-demo/entry_completion.c: New demo for GtkEntryCompletion
by Anders Carlsson (#130464).
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/Makefile.am | 1 | ||||
-rw-r--r-- | demos/gtk-demo/entry_completion.c | 97 |
2 files changed, 98 insertions, 0 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index 4fbf6bb8bd..d79ba01693 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -12,6 +12,7 @@ demos = \ dialog.c \ drawingarea.c \ editable_cells.c \ + entry_completion.c \ hypertext.c \ images.c \ list_store.c \ diff --git a/demos/gtk-demo/entry_completion.c b/demos/gtk-demo/entry_completion.c new file mode 100644 index 0000000000..fbcd856d0f --- /dev/null +++ b/demos/gtk-demo/entry_completion.c @@ -0,0 +1,97 @@ +/* Entry Completion + * + * GtkEntryCompletion provides a mechanism for adding support for + * completion in GtkEntry. + * + */ + +#include <gtk/gtk.h> + +static GtkWidget *window = NULL; + +/* Creates a tree model containing the completions */ +GtkTreeModel * +create_completion_model (void) +{ + GtkListStore *store; + GtkTreeIter iter; + + store = gtk_list_store_new (1, G_TYPE_STRING); + + /* Append one word */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "GNOME", -1); + + /* Append another word */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "total", -1); + + /* And another word */ + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, "totally", -1); + + return GTK_TREE_MODEL (store); +} + + +GtkWidget * +do_entry_completion (GtkWidget *do_widget) +{ + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *entry; + GtkEntryCompletion *completion; + GtkTreeModel *completion_model; + + if (!window) + { + window = gtk_dialog_new_with_buttons ("GtkEntryCompletion", + GTK_WINDOW (do_widget), + 0, + GTK_STOCK_CLOSE, + GTK_RESPONSE_NONE, + NULL); + gtk_window_set_resizable (GTK_WINDOW (window), FALSE); + + g_signal_connect (window, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + g_signal_connect (window, "destroy", + G_CALLBACK (gtk_widget_destroyed), &window); + + vbox = gtk_vbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); + + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example."); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + + /* Create our entry */ + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0); + + /* Create the completion object */ + completion = gtk_entry_completion_new (); + + /* Assign the completion to the entry */ + gtk_entry_set_completion (GTK_ENTRY (entry), completion); + g_object_unref (completion); + + /* Create a tree model and use it as the completion model */ + completion_model = create_completion_model (); + gtk_entry_completion_set_model (completion, completion_model); + g_object_unref (completion_model); + + /* Use model column 0 as the text column */ + gtk_entry_completion_set_text_column (completion, 0); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + gtk_widget_destroy (window); + + return window; +} + + |