PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/examples/gtk-demo/entry_completion.e

http://github.com/tybor/Liberty
Specman e | 122 lines | 21 code | 27 blank | 74 comment | 2 complexity | 4f016377af3dc22b03ce7d51d276a527 MD5 | raw file
  1indexing
  2	description: "."
  3	copyright: "[
  4					Copyright (C) 2006 Paolo Redaelli, GTK+ team
  5					
  6					This library is free software; you can redistribute it and/or
  7					modify it under the terms of the GNU Lesser General Public License
  8					as published by the Free Software Foundation; either version 2.1 of
  9					the License, or (at your option) any later version.
 10					
 11					This library is distributed in the hope that it will be useful, but
 12					WITHOUT ANY WARRANTY; without even the implied warranty of
 13					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14					Lesser General Public License for more details.
 15
 16					You should have received a copy of the GNU Lesser General Public
 17					License along with this library; if not, write to the Free Software
 18					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 19					02110-1301 USA
 20			]"
 21
 22class ENTRY_COMPLETION
 23
 24creation make
 25
 26feature
 27-- /* Entry Completion
 28--  *
 29--  * GtkEntryCompletion provides a mechanism for adding support for
 30--  * completion in GtkEntry.
 31--  *
 32--  */
 33
 34-- #include <gtk/gtk.h>
 35
 36-- static GtkWidget *window = NULL;
 37
 38-- /* Creates a tree model containing the completions */
 39-- GtkTreeModel *
 40-- create_completion_model (void)
 41-- {
 42--   GtkListStore *store;
 43--   GtkTreeIter iter;
 44  
 45--   store = gtk_list_store_new (1, G_TYPE_STRING);
 46
 47--   /* Append one word */
 48--   gtk_list_store_append (store, &iter);
 49--   gtk_list_store_set (store, &iter, 0, "GNOME", -1);
 50
 51--   /* Append another word */
 52--   gtk_list_store_append (store, &iter);
 53--   gtk_list_store_set (store, &iter, 0, "total", -1);
 54
 55--   /* And another word */
 56--   gtk_list_store_append (store, &iter);
 57--   gtk_list_store_set (store, &iter, 0, "totally", -1);
 58  
 59--   return GTK_TREE_MODEL (store);
 60-- }
 61
 62
 63-- GtkWidget *
 64-- do_entry_completion (GtkWidget *do_widget)
 65-- {
 66--   GtkWidget *vbox;
 67--   GtkWidget *label;
 68--   GtkWidget *entry;
 69--   GtkEntryCompletion *completion;
 70--   GtkTreeModel *completion_model;
 71  
 72--   if (!window)
 73--   {
 74--     window = gtk_dialog_new_with_buttons ("GtkEntryCompletion",
 75-- 					  GTK_WINDOW (do_widget),
 76-- 					  0,
 77-- 					  GTK_STOCK_CLOSE,
 78-- 					  GTK_RESPONSE_NONE,
 79-- 					  NULL);
 80--     gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
 81
 82--     g_signal_connect (window, "response",
 83-- 		      G_CALLBACK (gtk_widget_destroy), NULL);
 84--     g_signal_connect (window, "destroy",
 85-- 		      G_CALLBACK (gtk_widget_destroyed), &window);
 86
 87--     vbox = gtk_vbox_new (FALSE, 5);
 88--     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE, 0);
 89--     gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
 90
 91--     label = gtk_label_new (NULL);
 92--     gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example.");
 93--     gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 94
 95--     /* Create our entry */
 96--     entry = gtk_entry_new ();
 97--     gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
 98
 99--     /* Create the completion object */
100--     completion = gtk_entry_completion_new ();
101
102--     /* Assign the completion to the entry */
103--     gtk_entry_set_completion (GTK_ENTRY (entry), completion);
104--     g_object_unref (completion);
105	
106--     /* Create a tree model and use it as the completion model */
107--     completion_model = create_completion_model ();
108--     gtk_entry_completion_set_model (completion, completion_model);
109--     g_object_unref (completion_model);
110	
111--     /* Use model column 0 as the text column */
112--     gtk_entry_completion_set_text_column (completion, 0);
113--   }
114
115--   if (!GTK_WIDGET_VISIBLE (window))
116--     gtk_widget_show_all (window);
117--   else
118--     gtk_widget_destroy (window);
119
120--   return window;
121-- }
122end