#include ONCE "window9.bi"

#ifdef __USE_GTK3__

function GetGadgetColor(iGadget as Long , iFlag as Long) as Long export
	
	dim as GtkStyle ptr style
	
	style = gtk_widget_Get_style(GadgetId(iGadget))
	
	if iFlag = 1 then 
		
		return bgr(style->bg(0).red shr 8 , style->bg(0).green shr 8, style->bg(0).blue shr 8)
		
	elseif iFlag = 2 then
		
		return bgr(style->fg(0).red shr 8 , style->fg(0).green shr 8 , style->fg(0).blue shr 8)
		
	EndIf
	
End Function

#else

function GetGadgetColor(iGadget as Long , iFlag as Long) as Long export
	
	dim as GtkStyle ptr style
	
	dim as hwnd pWidget 
	
	dim as long classWidget
	
	dim as ListT ptr pTemp = pGlobalTypeWindow9->ListGadgets->findNodeFunc(iGadget)
	
	if pTemp <> 0 then
		
		pWidget = cast(hwnd,pTemp->anyTwoData)
		
		classWidget = pTemp->anyThreeData
		
	else
		
		return 0
		
	endif		
	
	select case classWidget
		
		Case 1 , 9 , 10
		
			dim as GtkWidget ptr child = gtk_bin_get_child(GTK_BIN(pWidget))
		
			style = gtk_widget_Get_style(child)
		
			if iFlag = 2 then
			
				return bgr(style->fg(0).red shr 8 , style->fg(0).green shr 8 , style->fg(0).blue shr 8)	
			
			EndIf
		
		Case 2 , 6 , 7 , 15 , 19 , 20
		
			style = gtk_widget_Get_style(pWidget)
		
			if iFlag = 1 then 
			
				return bgr(style->base(0).red shr 8 , style->base(0).green shr 8, style->base(0).blue shr 8)
			
			elseif iFlag = 2 then
			
				return bgr(style->text(0).red shr 8 , style->text(0).green shr 8 , style->text(0).blue shr 8)
			
			EndIf					
		
		case 5	
		
			if iFlag = 1 then
			
				style = gtk_widget_Get_style(gtk_widget_get_parent(pWidget))
			
				return bgr(style->bg(0).red shr 8 , style->bg(0).green shr 8 , style->bg(0).blue shr 8)
			
			elseif iFlag = 2 then	
			
				style = gtk_widget_Get_style(pWidget)
			
				return bgr(style->fg(0).red shr 8 , style->fg(0).green shr 8 , style->fg(0).blue shr 8)
			
			endif
		
		case 8 , 21
		
			style = gtk_widget_Get_style(pWidget)
		
			if iFlag = 1 then 
			
				return bgr(style->bg(0).red shr 8 , style->bg(0).green shr 8, style->bg(0).blue shr 8)
			
			elseif iFlag = 2 then
			
				return bgr(style->fg(0).red shr 8 , style->fg(0).green shr 8 , style->fg(0).blue shr 8)
			
			EndIf
		
		case 16
		
			dim as GList ptr children = gtk_container_get_children(cast(any ptr,pWidget))
		
			pWidget = children->data
		
			style = gtk_widget_Get_style(pWidget)	
		
			if iFlag = 2 then
			
				return bgr(style->fg(0).red shr 8 , style->fg(0).green shr 8 , style->fg(0).blue shr 8)	
			
			endif				
		
		case 18
		
			style = gtk_widget_Get_style(pWidget)
		
			if iFlag = 1 then
			
				return bgr(style->bg(GTK_STATE_ACTIVE).red shr 8 , style->bg(GTK_STATE_ACTIVE).green shr 8, style->bg(GTK_STATE_ACTIVE).blue shr 8)
			
			EndIf
		
			if iFlag = 2 then
			
				return bgr(style->bg(GTK_STATE_SELECTED).red shr 8 , style->bg(GTK_STATE_SELECTED).green shr 8, style->bg(GTK_STATE_SELECTED).blue shr 8)
			
			EndIf			
		
	End Select
	
End Function

#endif