#include Once "window9.bi"

Function Treeviewgadget(iGadget As Long , iX As Long, iY As Long, iWidth As Long, iHeight As Long  , iStyle As Long = 0 , iStyle2 As Long  = 0, iSizeIcon As Long  = 0) As Hwnd Export
	
	Dim As HWND treeview , vBox , mainBox , scroll
	
	Dim As GtkTreeStore Ptr treestore
	
	Dim As ListT Ptr pListTemp
	
	Dim As GtkTreeSelection Ptr selection
	
	Dim As  GtkTreeViewColumn Ptr column
	
	Dim As  GtkCellRenderer   Ptr renderer	
	
	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)	
	
	treestore = gtk_tree_store_new(2, GDK_TYPE_PIXBUF, G_TYPE_STRING)
	
	treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(treestore))
	
	selection = gtk_tree_view_get_selection (Cast(Any Ptr,treeview))
	
	gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (treeview), False)	
	
	g_object_unref(treestore)
	
	column = gtk_tree_view_column_new()
	
	renderer = gtk_cell_renderer_pixbuf_new()
	
	gtk_tree_view_column_pack_start(column, renderer, False)
	
	gtk_tree_view_column_set_attributes(column, renderer, "pixbuf", 0, NULL)
	
	renderer = gtk_cell_renderer_text_new()
	
	gtk_tree_view_column_pack_start(column, renderer, True)
	
	gtk_tree_view_column_set_attributes(column, renderer, "text", 1 , NULL)	
	
	Dim As Integer iIndex = gtk_tree_view_append_column (Cast(Any Ptr,treeview) , column )
	
	gtk_container_add (GTK_CONTAINER (scroll), treeview)		
	
	pGlobalTypeWindow9->ListGadgets->addNodeSub(iGadget , Cint(treeview) ,  20)
	
	gtk_widget_set_size_request(scroll, iWidth, iHeight)
	
	gtk_fixed_put(GTK_FIXED(vbox), scroll, iX , iY)
	
	g_object_set_data (Cast(Any Ptr, treeview), "X_SIZE" , Cast(Any Ptr,Cint(iX)))
	
	g_object_set_data (Cast(Any Ptr, treeview), "Y_SIZE" , Cast(Any Ptr,Cint(iY)))
	
	g_object_set_data (Cast(Any Ptr, treeview), "W_SIZE" , Cast(Any Ptr,Cint(iWidth)))
	
	g_object_set_data (Cast(Any Ptr, treeview), "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(treeview), "row-collapsed", G_CALLBACK (@RowCollapsedTreeViewSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(treeview), "row-expanded", G_CALLBACK (@RowExpandedTreeViewSub), @(fNode->x))			
	
	g_signal_connect(G_OBJECT(treeview), "button-press-event", G_CALLBACK (@MousePresslistviewSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(treeview), "cursor-changed", G_CALLBACK (@EventCursorChangesListViewGadgetSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(scroll), "size-allocate", G_CALLBACK (@size_allocate_signals), @(fNode->x))
	
	gtk_widget_show(vbox)

	gtk_widget_show(treeview)
	
	gtk_widget_show(scroll)
	
	If treeview Then
		
		Dim As LinList Ptr imglist = New LinList
		
		if imglist then
			
			g_object_set_data( Cast(Any Ptr,treestore) , "tree_img_list" , Cast(Any Ptr,imglist))
			
		else
		
			print "Allocated memory error in Treeviewgadget!"
			
		EndIf
		
	Endif
	
	gtk_widget_modify_font(treeview, pGlobalTypeWindow9->fontCurent)
	
	Return treeview
	
End Function