/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

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