Feature request: TextField Gadget

BlitzMax Forums/BlitzMax Programming/Feature request: TextField Gadget

fredborg(Posted 2006) [#1]
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


SebHoll(Posted 2006) [#2]
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:


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


fredborg(Posted 2006) [#3]
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).


JoshK(Posted 2006) [#4]
I agree that this would be a good feature.


Regular K(Posted 2006) [#5]
I agree with the enter part, but a one line textarea? Just use a textfield?


JoshK(Posted 2006) [#6]
Nevermind, this can be fixed using a textarea and SetGadgetFilter.


fredborg(Posted 2006) [#7]
Except tabbing doesn't work natively with TextAreas.


klepto2(Posted 2006) [#8]
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