#include Once "window9.bi"

#ifdef __USE_GTK3__

Sub Setgadgetcolor(iGadget As Long , ColorBG As Long, ColorText As Long , iFlag As Long) Export
	
	Dim As GdkColor TcolorBg , TcolorFg 
	
	Dim As Hwnd pWidget = Gadgetid(iGadget)
	
	Dim As String sClassWidget = *Cast(Zstring Ptr , g_object_get_data (Cast(Any Ptr,pWidget), "widget"))
	
	If iFlag = 1 Orelse iFlag = 3 Then
		
		If sClassWidget = "layout" Then
			
			g_object_set_data (Cast(Any Ptr,pWidget), "fcol"  , Cast(Any Ptr ,Cast(Integer , 1)))
			
			g_object_set_data (Cast(Any Ptr,pWidget), "color" , Cast(Any Ptr ,Cast(Integer ,ColorBG)))
			
		Else
		
			TcolorBg.red = Cast(Short,((ColorBG And &h000000FF)Shl 8) Or (ColorBG And &h000000FF))
			
			TcolorBg.blue = Cast(Short,((ColorBG And &h00FF0000) Shr 8) Or (ColorBG And &h00FF0000) Shr 16)
			
			TcolorBg.green = Cast(Short,(ColorBG And &h0000FF00) Or (ColorBG And &h0000FF00) Shr 8)		
			
			gtk_widget_modify_bg (pWidget, GTK_STATE_NORMAL, @TcolorBg)				
			
		Endif

	Endif
	
	If iFlag = 2 Orelse iFlag = 3 Then
	
		TcolorFg.red = Cast(Short,((ColorText And &h000000FF)Shl 8) Or (ColorText And &h000000FF))
		
		TcolorFg.blue = Cast(Short,((ColorText And &h00FF0000) Shr 8) Or (ColorText And &h00FF0000) Shr 16)
		
		TcolorFg.green = Cast(Short,(ColorText And &h0000FF00) Or (ColorText And &h0000FF00) Shr 8)		
		
		gtk_widget_modify_fg (pWidget, GTK_STATE_NORMAL, @TcolorFg)		

	Endif
	
End Sub

#else

Sub Setgadgetcolor(iGadget As Long , ColorBG As Long, ColorText As Long , iFlag As Long) Export
	
	Dim As GdkColor TcolorBg , TcolorFg
	
	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
	
		Exit Sub
	
	Endif		
	
	TcolorBg.red = Cast(Short,((ColorBG And &h000000FF)Shl 8) Or (ColorBG And &h000000FF))

	TcolorBg.blue = Cast(Short,((ColorBG And &h00FF0000) Shr 8) Or (ColorBG And &h00FF0000) Shr 16)

	TcolorBg.green = Cast(Short,(ColorBG And &h0000FF00) Or (ColorBG And &h0000FF00) Shr 8)		
		

	TcolorFg.red = Cast(Short,((ColorText And &h000000FF)Shl 8) Or (ColorText And &h000000FF))

	TcolorFg.blue = Cast(Short,((ColorText And &h00FF0000) Shr 8) Or (ColorText And &h00FF0000) Shr 16)

	TcolorFg.green = Cast(Short,(ColorText And &h0000FF00) Or (ColorText And &h0000FF00) Shr 8)			
	
	Select Case classWidget
	
		Case 2 , 6 , 7 , 15 , 19 , 20
		
			If iFlag = 1 Orelse iFlag = 3 Then
			
				gtk_widget_modify_base (pWidget, GTK_STATE_NORMAL, @TcolorBg)
			
			Endif
			
			If iFlag = 2 Orelse iFlag = 3 Then
	
				gtk_widget_modify_text (pWidget, GTK_STATE_NORMAL, @TcolorFg)	

			Endif
			
		Case 5 

			If iFlag = 1 Orelse iFlag = 3 Then
			
				gtk_widget_modify_bg (gtk_widget_get_parent(pWidget), GTK_STATE_NORMAL, @TcolorBg)
			
			Endif	
			
			If iFlag = 2 Orelse iFlag = 3 Then
	
				gtk_widget_modify_fg (pWidget, GTK_STATE_NORMAL, @TcolorFg)	

			Endif	
			
		Case 8 , 21
		
			If iFlag = 1 Orelse iFlag = 3 Then
	
				gtk_widget_modify_base (pWidget, GTK_STATE_NORMAL, @TcolorBg)
				
				gtk_widget_modify_bg (pWidget, GTK_STATE_NORMAL, @TcolorBg)

			Endif
			
			If iFlag = 2 Orelse iFlag = 3 Then
	
				gtk_widget_modify_text (pWidget, GTK_STATE_NORMAL, @TcolorFg)
				
				gtk_widget_modify_fg (pWidget, GTK_STATE_NORMAL, @TcolorFg)	

			Endif
			
		Case 1 , 9 , 10
		
			Dim As GtkWidget Ptr child = gtk_bin_get_child(GTK_BIN(pWidget))
			
			If iFlag = 2 Orelse iFlag = 3 Then
	
				For i As Long = 0 To 4
	
					gtk_widget_modify_fg (child, i, @TcolorFg)

				Next			

			Endif
			
		Case 16
		
			 Dim As GList Ptr children = gtk_container_get_children(Cast(Any Ptr,pWidget))
				
			 pWidget = children->Data
			 
			 If iFlag = 2 Orelse iFlag = 3 Then
	
			 	gtk_widget_modify_fg (pWidget, GTK_STATE_NORMAL, @TcolorFg)	

			 Endif
			 	
		Case 18
		
			If iFlag = 1 Orelse iFlag = 3 Then
	
				gtk_widget_modify_bg(pWidget,GTK_STATE_ACTIVE, @TcolorBg) 

			Endif
			
			If iFlag = 2 Orelse iFlag = 3 Then
				
				gtk_widget_modify_bg (pWidget, GTK_STATE_SELECTED, @TcolorFg)	

			Endif			

	End Select	
	
End Sub

#endif