#include Once "window9.bi"

Function Trackbargadget( iGadget As Long , x As Long, y As Long, width_ As Long, height_ As Long  , iMin As Long , iMax As Long , iStyle As Long = TBS_HORZ ) As Hwnd Export
	
	Dim As HWND track , vBox , mainBox
	
	Dim As ListT Ptr pListTemp
	
	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)	
	
	If iStyle = TBS_HORZ Then
		
		track = gtk_hscale_new_with_range(iMin , iMax , 1)
		
	Else
		
		track = gtk_vscale_new_with_range(iMin , iMax , 1)
		
	Endif
	
	If pGlobalTypeWindow9->ListRangeForSliders = 0 Then
		
		pGlobalTypeWindow9->ListRangeForSliders = New LinList
		
		if pGlobalTypeWindow9->ListRangeForSliders = 0 then
			
			print "Allocated memory error in Trackbargadget!"
			
			return cast(hwnd , 0)
			
		EndIf
		
	Endif
	
	pGlobalTypeWindow9->ListRangeForSliders->addNodeSub(iGadget , iMin ,  iMax)
	
	pGlobalTypeWindow9->ListGadgets->addNodeSub(iGadget , Cint(track) ,  12)
	
	gtk_widget_set_size_request(track, width_, height_)
	
	gtk_fixed_put(GTK_FIXED(vbox), track, x , y)
	
	g_object_set_data (Cast(Any Ptr, track), "X_SIZE" , Cast(Any Ptr,Cint(x)))
	
	g_object_set_data (Cast(Any Ptr, track), "Y_SIZE" , Cast(Any Ptr,Cint(y)))
	
	g_object_set_data (Cast(Any Ptr, track), "W_SIZE" , Cast(Any Ptr,Cint(width_)))
	
	g_object_set_data (Cast(Any Ptr, track), "H_SIZE" , Cast(Any Ptr,Cint(height_)))	
	
	tree_add_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)
	
	Dim As Node Ptr fNode = tree_find_node(iGadget,pGlobalTypeWindow9->treeNumberGadgets)	
	
	g_signal_connect(G_OBJECT(track), "value-changed", G_CALLBACK (@EventsTrackBarGadgetSub), @(fNode->x))
	
	g_signal_connect(G_OBJECT(track), "size-allocate", G_CALLBACK (@size_allocate_signals), @(fNode->x))
	
	gtk_widget_show(vbox)
	
	gtk_widget_show(track)
	
	Return track
	
End Function