/src/wrappers/gtk/examples/iconview/icon_view_demo.e

http://github.com/tybor/Liberty · Specman e · 120 lines · 85 code · 24 blank · 11 comment · 0 complexity · 23db3a0ea0f863a0859a4ca015021d03 MD5 · raw file

  1. indexing
  2. description: "IconView example"
  3. copyright: "Copyright (c) 2003-2004 Tim-Philipp M?ller <tim at centricular dot net>, Copyright (c) 2005, Paolo Redaelli"
  4. license: "LGPL v2 or later"
  5. date: "$Date:$"
  6. revision: "$Revision:$"
  7. original_version_url: "http://scentric.net/tutorial/treeview-tutorial.html"
  8. class ICON_VIEW_DEMO
  9. inherit
  10. GTK
  11. GDK_TYPE_EXTERNALS
  12. G_TYPES
  13. WRAPPER_HANDLER
  14. creation make
  15. feature -- Columns
  16. pix_col_n: INTEGER is 2
  17. text_col_n: INTEGER is 3
  18. feature
  19. model: GTK_LIST_STORE is
  20. -- icon model with some data set
  21. once
  22. create Result.make (<<g_type_int, -- this is column 0
  23. g_type_int, -- this is column 1
  24. gdk_type_pixbuf, g_type_string, -- these are columns 2 and 3
  25. g_type_int -- this is column 4
  26. >>)
  27. -- We can have as many columns as we need.
  28. -- But at least we need a gdk_type_pixbuf
  29. -- column and a g_type_string column.
  30. ensure
  31. Result /= Void
  32. end
  33. view: GTK_ICON_VIEW is
  34. -- icon view, this has to have two columns
  35. once
  36. create Result.with_model (model)
  37. Result.set_pixbuf_column (pix_col_n)
  38. Result.set_text_column (text_col_n)
  39. Result.set_item_width (30)
  40. ensure
  41. Result /= Void
  42. end
  43. feature {} -- Creation
  44. make is
  45. -- Run the demo
  46. local
  47. window: GTK_WINDOW
  48. iter: GTK_TREE_ITER
  49. pixbuf: GDK_PIXBUF
  50. text: STRING
  51. do
  52. gtk.initialize_gtk
  53. -- Create a GTK window toplevel window
  54. create window.make
  55. window.set_title (once "This is a nice window title")
  56. -- It is a good idea to do this for all windows
  57. window.connect_agent_to_destroy_signal (agent on_destroy)
  58. -- the following three lines are not necessary when working with glade
  59. view.show
  60. window.add (view)
  61. window.show
  62. -- here we add things to the icon model, and those things will
  63. -- be shown "automagically" on the icon view
  64. create iter.from_model (model)
  65. model.append (iter)
  66. create pixbuf.from_file_at_size ("./image1.png", 32, 32)
  67. check pixbuf.is_valid end
  68. set_pixbuf_and_string (model, iter, pix_col_n, pixbuf, text_col_n, once "This is image 1")
  69. model.append (iter)
  70. create pixbuf.from_file_at_size ("./image2.png", 32, 32)
  71. check pixbuf.is_valid end
  72. set_pixbuf_and_string (model, iter, pix_col_n, pixbuf, text_col_n, once "This is image 2")
  73. gtk.run_main_loop
  74. end
  75. feature -- Agents
  76. on_destroy (a_gtk_object: GTK_OBJECT) is
  77. do
  78. gtk.quit
  79. end
  80. feature -- Helper -- we need this 'cause we can wrap this directly (it uses varargs)
  81. set_pixbuf_and_string (a_list_store: GTK_LIST_STORE; an_iter: GTK_TREE_ITER;
  82. pixbuf_column: INTEGER; a_pixbuf: GDK_PIXBUF;
  83. text_column: INTEGER; a_string: STRING) is
  84. do
  85. gtk_list_store_set_pixbuf_and_string (a_list_store.handle, an_iter.handle,
  86. pixbuf_column, a_pixbuf.handle,
  87. text_column, a_string.to_external, -1)
  88. end
  89. feature {} -- Low level
  90. gtk_list_store_set_pixbuf_and_string (a_gtk_list_store, a_gtk_tree_iter: POINTER;
  91. pixbuf_column: INTEGER; a_gdk_pixbuf: POINTER;
  92. text_column: INTEGER; a_string: POINTER; a_minus_one: INTEGER) is
  93. external "C use <gtk/gtk.h>"
  94. alias "gtk_list_store_set"
  95. end
  96. end -- class ICON_VIEW_DEMO