#include ONCE "window9.bi"

Function AddListViewItem( iGadget As Long, sText As String, IDImage As HBITMAP, iPos As Long, iSubItem As Long, iMaskItem As Long =LVIF_TEXT Or LVIF_IMAGE) As long Export 
	
	dim as any ptr listview = GadgetID(iGadget)
	
	dim as GtkTreeIter iter , iter2
	
	dim as any ptr model = gtk_tree_view_get_model(listview)	
	
	dim as Hbitmap pBitmapTemp
	
	dim as zstring ptr pszTempString
	
	if iMaskItem and LVIF_IMAGE then
		
		pBitmapTemp = IDImage
		
	EndIf
	
	if iMaskItem and LVIF_TEXT then
		
		pszTempString = strptr(sText)
		
	EndIf
	
	dim as GtkTreePath ptr path = gtk_tree_path_new_from_indices(iPos, -1)
	
	if path then
		
		gtk_tree_model_get_iter(cast(any ptr,model) , @iter , path)
		
		if iter.stamp then
			
			gtk_list_store_set(model, @iter, iSubItem*2 , pBitmapTemp , iSubItem*2+1, pszTempString,  -1)
			
		else
			
			gtk_list_store_insert(model, @iter2 , iPos)
			
			gtk_list_store_set(model, @iter2, iSubItem*2 , pBitmapTemp, iSubItem*2+1, pszTempString,  -1)			
			
		EndIf
		
		gtk_tree_path_free(path)
		
		return TRUE				
		
	EndIf
	
End Function