#include ONCE "window9.bi"

function InputBox(sCaption as string  = "" , sMessageText as string = "EnterText:" , sDefaultText as string = "" , iFlag as long = 0 , iFlag2 as long = 0  , hParentWin as Hwnd = 0) as string export 
	
	dim as GtkWidget  ptr dialog
	
	dim as GtkWidget  ptr label
	
	dim as GtkWidget  ptr entry
	
	dim as GtkWidget  ptr button
	
	dim as GtkWidget  ptr hBoxDialog , vBox , hBox1 , hBox2 , hBox3 , vboxfill
	
	dialog = gtk_dialog_new ()
	
	if hParentWin then
		
		gtk_window_set_transient_for(GTK_WINDOW(dialog) , cast(any ptr,hParentWin))
		
	EndIf
	
	hBoxDialog = gtk_dialog_get_action_area(GTK_DIALOG(dialog))
	
	gtk_window_set_title (GTK_WINDOW (dialog), sCaption)
	
	label = gtk_label_new (sMessageText)
	
	entry = gtk_entry_new ()
	
	button = gtk_button_new_with_label("OK")
	
	vBox = gtk_vbox_new( 0 , 5)
	
	hBox1 = gtk_hbox_new( 1 , 180)
	
	hBox2 = gtk_hbox_new( 1 , 0)
	
	hBox3 = gtk_hbox_new( 1 , 0)
	
	vboxfill = gtk_vbox_new( 0 , 0)
	
	gtk_box_pack_start(cast(any ptr , vbox), hBox1 , 0 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , vbox), hBox2 , 1 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , vbox), hBox3 , 1 , 1, 6)
	
	gtk_box_pack_start(cast(any ptr , hBoxDialog), vBox , 1 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , hBox1), label , 0 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , hBox1), vboxfill , 1 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , hBox2), entry , 1 , 1, 0)
	
	gtk_box_pack_start(cast(any ptr , hBox3), button ,1 , 1, 100)
	
	gtk_widget_set_size_request(entry, 300, 30)	
	
	if len(sDefaultText) then
		
		gtk_entry_set_text (cast(any ptr,entry) , sDefaultText)
		
	EndIf
	
	dim as TinputBox ptr tib = new TinputBox
	
	if tib then
		
		tib->dialog = dialog
		
		tib->entry = entry
		
		g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK (@EventbuttonInputBoxSub),tib)
		
		if iFlag2 then
			
			g_signal_connect(G_OBJECT(entry), "event", G_CALLBACK (@EventEntryInputBoxFunc), tib)
			
		EndIf
		
		gtk_widget_show_all (dialog)
		
		if gtk_dialog_run (cast(any ptr ,dialog)) = GTK_RESPONSE_OK then
			
			function = trim(tib->sText, chr(0))
			
		EndIf
		
		delete tib
		
	else
		
		print "Allocated memory error in InputBox!"
		
	endif
	
	gtk_widget_destroy(dialog)
	
end function