#include ONCE "window9.bi"

Function ColorRequester(ByVal iBgrColor As long = 0, ByVal iFlag As Long = 0, ByVal hWin As HWND = 0) As Long Export	
	
	static as Long iSaveColor
	
	dim as GtkWidget ptr colorseldlg
	
	dim as GdkColor color_
	
	dim as gint response
	
	dim as GtkColorSelection ptr colorsel
	
	if iFlag and CC_RGBINIT then
		
		iSaveColor = iBgrColor
		
	EndIf
	
	color_.red = cast(SHORT,((iSaveColor and &h000000FF)shl 8) or (iSaveColor and &h000000FF))
	
	color_.blue =  cast(SHORT,((iSaveColor and &h00FF0000) shr 8) or (iSaveColor and &h00FF0000)shr 16)
	
	color_.green =  cast(SHORT,(iSaveColor and &h0000FF00) or (iSaveColor and &h0000FF00) shr 8)
	
	colorseldlg = gtk_color_selection_dialog_new ("Select color")
	
	colorsel = cast(any ptr, gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG (colorseldlg)))
	
	gtk_color_selection_set_previous_color (colorsel, @color_)
	
	gtk_color_selection_set_current_color (colorsel, @color_)
	
	gtk_color_selection_set_has_palette (colorsel, TRUE)
	
	gtk_window_set_transient_for(GTK_WINDOW(colorseldlg) , cast(any ptr,hWin))
	
	'g_signal_connect (colorsel, "color_changed",
	'G_CALLBACK (color_changed_cb), (gpointer) colorsel);
	
	
	response = gtk_dialog_run (GTK_DIALOG(colorseldlg))
	
	if response = GTK_RESPONSE_OK then
		
		gtk_color_selection_get_current_color (colorsel, @color_)
		
		iSaveColor = bgr(color_.red shr 8 , color_.green shr 8, color_.blue shr 8)
		
	EndIf
	
	gtk_widget_destroy(cast(any ptr,colorseldlg))
	
	return iSaveColor	 
	
End Function