Feature request: TextField Gadget

BlitzMax Forums/BlitzMax Programming/Feature request: TextField Gadget

Hi,

Can we please have the TextField gadget respond to Enter/Return being hit?

In addition an event on using tab to switch to another gadget would be nice.

Tweak for return/enter on windows is here: http://www.blitzbasic.com/Community/posts.php?topic=57075

Can't you just make a button with the BUTTON_OK flag set, that is hidden, then check to see if it is emitting an event. If so, the user has hit Enter in the textbox. Have a look in the documentation regarding CreateButton. Try typing in something and hitting enter:

Strict 

Local window:TGadget
Local button:TGadget
Local textfield:TGadget

window=CreateWindow("Catching Enter in TextFields",40,40,240,300,Null,WINDOW_TITLEBAR)
textfield=CreateTextField(10,10,220,20,window)
button=CreateButton("",0,0,0,0,window,BUTTON_OK)

HideGadget(button)

While True
	WaitEvent 
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_GADGETACTION
			
			Select EventSource()
			
				Case button;Notify("Enter Pressed in TextField: " + TextFieldText$(textfield))
				
			EndSelect
			
	End Select
Wend

Is this any help? - It should also be multi-platform compatible as it is using native MaxGUI commands.

While that might be acceptable if you had one textfield, it doesn't really cut it when you have ten.

Alternatively can you add a flag to TextArea, that makes it remove the scrollbar (ie. a one line TextArea).

I agree that this would be a good feature.

I agree with the enter part, but a one line textarea? Just use a textfield?

Nevermind, this can be fixed using a textarea and SetGadgetFilter.

Except tabbing doesn't work natively with TextAreas.

Hi, maybe i have found a solution which supports events on enter and also it is tabbing through the created Ext. Textfields.

SuperStrict

Type TExtTextField
	Global Group:TList = New TList
	Field Gadget:TGadget
	Field ChangeonEnter:Int = False

	
	
	Function Create:TExtTextField(X:Int , Y:Int , Width:Int , Parent:TGadget, COE:Int = True)
		Local TF:TExtTextField = New TExtTextField
		TF.Gadget = CreateTextArea(X , Y , Width , 20 , Parent)
		SetGadgetFilter(TF.Gadget , TExtTextField.Filter)
		TF.ChangeonEnter = COE
		TF.Gadget.context = TF
		TExtTextField.Group.Addlast(TF.Gadget)
		Return TF
	End Function
	
	Function filter:Int(event:TEvent,context:Object)
		Select event.id
			Case EVENT_KEYDOWN
				If event.data=9 Then Return 0
				If event.data=13 Return 0
			Case EVENT_KEYCHAR
				If event.data = KEY_ENTER Then
					If TExtTextField(TGadget(Event.source).context).ChangeonEnter = True Then
						Local SLink:TLink = TExtTextField.Group.FindLink(event.source)
					If SLink.NextLink() <> Null Then
						Local TField:TGadget = TGadget(SLink.NextLink().Value() )
						ActivateGadget(TField)
					Else
						Local TField:TGadget = TGadget(TExtTextField.Group.FirstLink().Value() )
						ActivateGadget(TField)
					EndIf
				EndIf
					Local MyEVent:TEvent = CreateEvent(EVENT_GADGETDONE , event.source , 13 , 0 , 0 , 0 , TextAreaText(TGadget(event.source) ) )
					EmitEvent MyEvent
					Return 0
				EndIf
				If event.data = KEY_TAB Then
					Local SLink:TLink = TExtTextField.Group.FindLink(event.source)
					If SLink.NextLink() <> Null Then
						Local TField:TGadget = TGadget(SLink.NextLink().Value() )
						ActivateGadget(TField)
					Else
						Local TField:TGadget = TGadget(TExtTextField.Group.FirstLink().Value() )
						ActivateGadget(TField)
					EndIf
					Local MyEVent:TEvent = CreateEvent(EVENT_GADGETLOSTFOCUS , event.source , 9 , 0 , 0 , 0 , "Tabbed")
					EmitEvent MyEvent
					Return 0
				EndIf
		End Select
		Return 1
	End Function
	


End Type

Local Main:TGadget = CreateWindow("Test" , 0 , 0 , 400 , 400)
Local TF:TExtTextField = TExtTextField.Create(40 , 40 , 200 , Main)
Local TF2:TExtTextField = TExtTextField.Create(40 , 80 , 200 , Main)



While True
	WaitEvent 
	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend