#include ONCE "window9.bi"

function AddTreeViewItem (iGadget As Long, sText As String, IDImage As HBITMAP, IDImageSelect As HBITMAP , iPos As integer, iParent As integer = 0) As integer Export
	
	dim as any ptr treeview = GadgetID(iGadget)
	
	dim as GtkTreeIter iter , iter_parent , iter_temp
	
	dim as any ptr model = gtk_tree_view_get_model(treeview)	
	
	dim as Hbitmap pBitmapTemp
	
	dim as zstring ptr pszTempString
	
	if IDImage then
		
		pBitmapTemp = IDImage
		
	EndIf
	
	if len(sText) then
		
		pszTempString = strptr(sText)
		
	EndIf
	
	if iParent then
		
		gtk_tree_model_get_iter_first(model , @iter_temp)
		
		iter_parent.stamp = iter_temp.stamp
		
		iter_parent.user_data = cast(any ptr ,iParent)
		
		if iter_parent.stamp then			
			
			gtk_tree_store_insert(model, @iter , @iter_parent , iPos)
			
			gtk_tree_store_set(model, @iter, 0 , pBitmapTemp, 1, pszTempString,  -1)				
			
		EndIf
		
	else
		
		gtk_tree_store_insert(model, @iter , 0 , iPos)
		
		gtk_tree_store_set(model, @iter, 0 , pBitmapTemp, 1, pszTempString,  -1)		
		
	EndIf
	
	if iter.stamp then
		
		function =  cast(integer,iter.user_data)
		
		dim as LinList ptr imglist = cast(any ptr, g_object_get_data (cast(any ptr,model), "tree_img_list"))
		
		imglist->addNodeSub(cast(integer,iter.user_data)  , cast(integer,iter.stamp) , cast(integer , IDImage) ,cast(integer , IDImageSelect))
		
	EndIf			
	
End Function