#include ONCE "window9.bi"

sub SetGadgetState(iGadget as Long , iState as Long) export
	
	dim as ListT ptr pTemp = pGlobalTypeWindow9->ListGadgets->findNodeFunc(iGadget)
	
	if pTemp <> 0 then
		
		dim as hwnd pWidget = cast(hwnd,pTemp->anyTwoData)
		
		dim as Long iClass = pTemp->anyThreeData
		
		select case iClass	
			
			Case 1 , 3 , 9 , 10  ' ButtonGadget , ButtonImageGadget, CheckBoxGadget , OptionGadget
			
				gtk_toggle_button_set_active (cast(any ptr,pWidget) , iState)
				
			case 7 ' SpinGadget
			
				dim as GtkAdjustment ptr adj = gtk_spin_button_get_adjustment(cast(any ptr,pWidget))
				
				gtk_adjustment_set_value(adj , iState)
			
			Case 18 ' ProgressBarGadget
			
				pTemp = cast(ListT ptr,pGlobalTypeWindow9->ListRangeForSliders->findNodeFunc(iGadget))
			
				if pTemp <> 0 then
				
					dim as Long iBegin = pTemp->anyTwoData
				
					dim as Long iEnd = pTemp->anyThreeData
				
					if iState < iBegin then iState = iBegin
				
					if iState > iEnd then iState = iEnd
				
					dim as double iStep =  (iEnd - iBegin)/100
				
					dim as Double iValue = ((iState - iBegin)/iStep)/100
				
					gtk_progress_bar_set_fraction(cast(any ptr, pWidget) , cast(single,iValue))
				
				EndIf
			
		End Select
		
	endif	
	
End Sub