#include ONCE "window9.bi"

function GetGadgetState(iGadget as Long) 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
			
				if gtk_toggle_button_get_active (cast(any ptr,pWidget)) then 
	
					return 1
					
				else
				
					return 0

				EndIf
				
				
			case 7 'SpinGadget
			
				dim as GtkAdjustment ptr adj = gtk_spin_button_get_adjustment(cast(any ptr,pWidget))
				
				return gtk_adjustment_get_value(adj)
			
			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
				
					dim as double iStep =  (iEnd - iBegin)/100
				
					dim as single iValue = gtk_progress_bar_get_fraction(cast(any ptr, pWidget))
					
					dim as long iState = 100*iValue*iStep + iBegin
					
					return iState
				
				EndIf
			
		End Select
		
	endif	
	
End function