PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1indexing
  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
  9class ICON_VIEW_DEMO
 10
 11inherit
 12	GTK
 13	GDK_TYPE_EXTERNALS
 14	G_TYPES
 15	WRAPPER_HANDLER
 16
 17creation make
 18
 19feature -- Columns
 20
 21	pix_col_n: INTEGER is 2
 22	text_col_n: INTEGER is 3
 23
 24feature
 25
 26	model: GTK_LIST_STORE is
 27			-- icon model with some data set
 28		once
 29			create Result.make (<<g_type_int, -- this is column 0
 30			                      g_type_int, -- this is column 1
 31			                      gdk_type_pixbuf, g_type_string,  -- these are columns 2 and 3
 32			                      g_type_int  -- this is column 4
 33			                    >>)
 34			-- We can have as many columns as we need.
 35			-- But at least we need a gdk_type_pixbuf
 36			-- column and a g_type_string column.
 37		ensure
 38			Result /= Void
 39		end
 40
 41	view: GTK_ICON_VIEW is
 42			-- icon view, this has to have two columns
 43		once
 44			create Result.with_model (model)
 45			Result.set_pixbuf_column (pix_col_n)
 46			Result.set_text_column (text_col_n)
 47			Result.set_item_width (30)
 48		ensure
 49			Result /= Void
 50		end
 51
 52feature {}  -- Creation
 53
 54	make is
 55			-- Run the demo
 56		local
 57			window: GTK_WINDOW
 58			iter: GTK_TREE_ITER
 59			pixbuf: GDK_PIXBUF
 60			text: STRING
 61		do
 62			gtk.initialize_gtk
 63			
 64			-- Create a GTK window toplevel window
 65			create window.make
 66			window.set_title (once "This is a nice window title")
 67			
 68			-- It is a good idea to do this for all windows
 69			window.connect_agent_to_destroy_signal (agent on_destroy)
 70			
 71			 -- the following three lines are not necessary when working with glade
 72			view.show
 73			window.add (view)
 74			window.show
 75			
 76			-- here we add things to the icon model, and those things will
 77			-- be shown "automagically" on the icon view
 78			create iter.from_model (model)
 79			
 80			model.append (iter)
 81			create pixbuf.from_file_at_size ("./image1.png", 32, 32)
 82				check pixbuf.is_valid end
 83			set_pixbuf_and_string (model, iter, pix_col_n, pixbuf, text_col_n, once "This is image 1")
 84			
 85			model.append (iter)
 86			create pixbuf.from_file_at_size ("./image2.png", 32, 32)
 87				check pixbuf.is_valid end
 88			set_pixbuf_and_string (model, iter, pix_col_n, pixbuf, text_col_n, once "This is image 2")
 89			
 90			gtk.run_main_loop
 91		end
 92
 93feature -- Agents
 94
 95	on_destroy (a_gtk_object: GTK_OBJECT) is
 96		do
 97			gtk.quit
 98		end
 99
100feature -- Helper -- we need this 'cause we can wrap this directly (it uses varargs)
101
102	set_pixbuf_and_string (a_list_store: GTK_LIST_STORE; an_iter: GTK_TREE_ITER;
103	                       pixbuf_column: INTEGER; a_pixbuf: GDK_PIXBUF;
104	                       text_column: INTEGER; a_string: STRING) is
105		do
106			gtk_list_store_set_pixbuf_and_string (a_list_store.handle, an_iter.handle,
107			                                      pixbuf_column, a_pixbuf.handle,
108			                                      text_column, a_string.to_external, -1)
109		end
110
111feature {} -- Low level
112
113	gtk_list_store_set_pixbuf_and_string (a_gtk_list_store, a_gtk_tree_iter: POINTER;
114	                                      pixbuf_column: INTEGER; a_gdk_pixbuf: POINTER;
115	                                      text_column: INTEGER; a_string: POINTER; a_minus_one: INTEGER) is
116		external "C use <gtk/gtk.h>"
117		alias "gtk_list_store_set"
118		end
119
120end -- class ICON_VIEW_DEMO