#include ONCE "window9.bi"

function GetItemListBox (iGadget as Long) as Long export

	dim as GtkTreeSelection ptr selection

	dim as GtkListStore ptr liststore
	
	dim as GtkTreePath ptr path
	
	dim as GtkTreeIter iter
	
	dim as Long iIndex
	
	dim as Long iRet
	
	dim as Hwnd listbox = GadgetId(iGadget)	
	
	liststore = cast(any ptr , gtk_tree_view_get_model(cast(any ptr,listbox)))	

	selection = gtk_tree_view_get_selection (cast(any ptr,listbox))
	
	
	
	gtk_tree_selection_get_selected(selection , cast(any ptr,@liststore) , @iter)
	
	if iter.stamp = 0 then return -1
	
	path = gtk_tree_model_get_path ( cast(any ptr,liststore) , @iter )
	
	dim as long ptr piIndex = gtk_tree_path_get_indices ( path )

	
	if piIndex = 0 then 
	
		function = -1
		
	else
	
		function = *piIndex	

	EndIf	
	
	gtk_tree_path_free(path)	
			
End Function