#include Once "window9.bi"

Function Listboxgadget( iGadget As Long , iX As Long, iY As Long, iWidth As Long, iHeight As Long  , iStyle As Long = 0  , iStyle2 As Long = 0 ) As Hwnd Export
	
	Dim As HWND listbox , vBox , mainBox , scroll
	
	Dim As GtkListStore Ptr liststore
	
	Dim As GtkCellRenderer Ptr renderer
	
	Dim As GtkTreeViewColumn Ptr column
	
	Dim As ListT Ptr pListTemp
	
	Dim As GtkTreeSelection Ptr selection
	
	Freegadget(iGadget)
	
	pGlobalTypeWindow9->OptGroup = 0 ' reset Group OptionGadget
	
	pListTemp = Cast(ListT Ptr,pGlobalTypeWindow9->ListWinAndContainers->findNodeFunc(Cint(pGlobalTypeWindow9->CurentHwnd)))
	
	mainBox = Cast(hwnd , pListTemp->anyTwoData)	
	
	vbox = gtk_fixed_new()
	
	gtk_container_add (GTK_CONTAINER(mainBox), vbox)	

	scroll = gtk_scrolled_window_new (NULL, NULL)
	
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC)	
	
	liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING)
	
	If iStyle And LBS_SORT Then

		Dim As GtkTreeSortable Ptr sortable
		
		sortable = GTK_TREE_SORTABLE(liststore)
		
		gtk_tree_sortable_set_sort_column_id(sortable, 1 , GTK_SORT_ASCENDING)

	Endif
	
	listbox = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore))

	selection = gtk_tree_view_get_selection (Cast(Any Ptr,listbox))
	
	If iStyle And LBS_EXTENDEDSEL Then
	
		gtk_tree_selection_set_mode (Cast(Any Ptr,selection), GTK_SELECTION_MULTIPLE)
		
	Else
	
		gtk_tree_selection_set_mode (Cast(Any Ptr,selection), GTK_SELECTION_BROWSE)

	Endif		
		
	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (listbox), False)
	
	g_object_unref(liststore)
	
	gtk_container_add (GTK_CONTAINER (scroll), listbox)	
	
	renderer = gtk_cell_renderer_text_new()
	
	column = gtk_tree_view_column_new_with_attributes("Title", renderer, "cell-background", 0, "text", 1 , NULL)
	
	gtk_tree_view_append_column(GTK_TREE_VIEW (listbox), column)
	
	pGlobalTypeWindow9->ListGadgets->addNodeSub(iGadget , Cint(listbox) ,  15)
	
	gtk_widget_set_size_request(scroll, iWidth, iHeight)
	
	gtk_fixed_put(GTK_FIXED(vbox), scroll, iX , iY)
	
	g_object_set_data (Cast(Any Ptr, listBox), "X_SIZE" , Cast(Any Ptr,Cint(iX)))
	
	g_object_set_data (Cast(Any Ptr, listBox), "Y_SIZE" , Cast(Any Ptr,Cint(iY)))
	
	g_object_set_data (Cast(Any Ptr, listBox), "W_SIZE" , Cast(Any Ptr,Cint(iWidth)))
	
	g_object_set_data (Cast(Any Ptr, listBox), "H_SIZE" , Cast(Any Ptr,Cint(iHeight)))	
	
	tree_add_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	Dim As Node Ptr fNode = tree_find_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)	
	
	g_signal_connect(G_OBJECT(listbox), "cursor-changed", G_CALLBACK (@EventsListBoxGadgetSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(scroll), "size-allocate", G_CALLBACK (@size_allocate_signals), @(fNode->x))
	
	gtk_widget_show(vBox)

	gtk_widget_show(listbox)

	gtk_widget_show(scroll)
	
	gtk_widget_modify_font(listBox , pGlobalTypeWindow9->fontCurent)
	
	Return listbox
	
End Function