PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/gtk/library/gtk_tree_select_function.e

http://github.com/tybor/Liberty
Specman e | 93 lines | 73 code | 14 blank | 6 comment | 3 complexity | d86c0f839839d1b51715a5ae051408f4 MD5 | raw file
 1indexing
 2	description: "Callback for tree selection functions"
 3	copyright: "[
 4					Copyright (C) 2006 eiffel-libraries team, 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	date: "$Date:$"
22	revision "$Revision:$"
23	
24class GTK_TREE_SELECT_FUNCTION
25
26inherit
27	WRAPPER_HANDLER -- It wraps a callback function
28	
29insert
30	ANY
31	GTK
32	G_OBJECT_FACTORY [GTK_TREE_MODEL]
33	GTK_TREE_SELECTION_EXTERNALS
34	
35creation make
36	
37feature
38	make (a_selection: GTK_TREE_SELECTION; a_function: FUNCTION[ANY,TUPLE[GTK_TREE_SELECTION, GTK_TREE_MODEL, GTK_TREE_PATH, BOOLEAN],BOOLEAN]) is
39		require gtk_initialized: gtk.is_initialized
40		local array: NATIVE_ARRAY [POINTER]; callback_ptr: POINTER
41		do
42			function := a_function
43			gtk_tree_selection_set_select_function (a_selection.handle, 
44																 $low_level_callback, -- selection function
45																 callback_array ($callback), -- The selection function's data.
46																 default_pointer -- destroy function for user data. May be and indeed it is NULL.
47																 )
48		end
49	
50feature {} -- 
51	callback_array (a_callback_pointer: POINTER): POINTER is
52		-- This call is required because we need to build an array with 
53		-- the address of an Eiffel feature (namely callback). `$' 
54		-- operator thought can be used only in a feature call. Hence this.
55		do
56	Result:= {NATIVE_ARRAY[POINTER] <<a_callback_pointer ,Current.to_pointer>>}.to_external
57		end
58	
59	low_level_callback (selection, model, path: POINTER; path_currently_selected: INTEGER; data: POINTER): INTEGER is
60			-- Low level callback will be called by GTK; it will call
61			-- `callback'.
62		external "C use <callbacks.h>"
63		alias "EiffelGtkTreeSelectionFunc"
64		end 
65
66feature
67	callback (selection_ptr, model_ptr,path_ptr: POINTER; path_currently_selected: INTEGER): INTEGER is --; instance: POINTER) is
68		local
69			a_selection: GTK_TREE_SELECTION;
70			a_model: GTK_TREE_MODEL
71			a_path: GTK_TREE_PATH
72			selection_factory: G_OBJECT_EXPANDED_FACTORY [GTK_TREE_SELECTION]
73		do
74			debug
75				print ("Gtk tree select function callback:")
76				print (" selection=") print(selection_ptr.to_string) 
77				print (" model=") print(model_ptr.to_string) 
78				print (" path=") print(path_ptr.to_string) 
79				print (" path_currently_selected=") print(path_currently_selected.to_string) 
80				--print (" instance=") print (instance.to_string)
81				print ("%N")
82			end
83			a_selection := selection_factory.wrapper(selection_ptr)
84			a_model := wrapper (model_ptr)
85				
86			create a_path.from_external_pointer (path_ptr)
87				
88			Result := (function.item ([a_selection,a_model,a_path,
89												path_currently_selected.to_boolean]).to_integer)
90		end
91	
92	function: FUNCTION[ANY,TUPLE[GTK_TREE_SELECTION, GTK_TREE_MODEL, GTK_TREE_PATH, BOOLEAN],BOOLEAN]
93end