( MTextInputForm )

api: FrmGetWindowHandle
api: WinSetWindowBounds
api: FrmSetObjectBounds
api: FrmReturnToForm
api: FrmSetFocus
api: FldGetTextPtr
api: FldGetTextLength
api: FldSetMaxChars
api: FntCharHeight
api: RctSetRectangle
api: FrmUpdateForm
api: FrmPopupForm

needs module: modules
needs Form: gui

module: MTextInputForm

0 value x
0 value y
0 value width
0 value Lines
0 value TextAddr
0 value TextLen
0 value NotifyEvent

: Go
	TextInputFormID
	FrmPopupForm ;

TextInputFormID Form:

firstUserEvent
constant afterOpenEvent

create Rect 8 allot

\ e: keyDownEvent IsEvent e>
\ ev. chr 9 = e>
\	;e

e: frmOpenEvent IsEvent e>
	Rect >abs
	x y width
	FntCharHeight Lines * 13 +
	RctSetRectangle
	FormPtr FrmGetWindowHandle
	Rect >abs WinSetWindowBounds
	afterOpenEvent
	AddNotifyEvent
	unhandled ;e
e: afterOpenEvent IsEvent e>
	FieldID ObjPtr TextLen
	FldSetMaxChars
	FormPtr FieldID ObjIndex
	2dup
	0 Rect !
	Rect 6 + w@ 13 - Rect 6 + w!
	Rect >abs FrmSetObjectBounds
	FrmSetFocus
	Rect >abs
	1 Rect 6 + w@ 1+ width 2- 11
	RctSetRectangle
	FormPtr ButtonID ObjIndex
	Rect >abs FrmSetObjectBounds
	FormID 0x8000 FrmUpdateForm
;e
e: ctlEnterEvent IsEvent e>
ev. controlID ButtonID = e>
	FieldID ObjPtr
	dup FldGetTextPtr >rel
	swap FldGetTextLength
	dup to TextLen TextAddr
	?dup 0= if
		dup 1+ allocate throw
		dup to TextAddr then
	swap move
	TextAddr TextLen + 0 swap c!
	0 FrmReturnToForm
	NotifyEvent AddNotifyEvent ;e
;Form

;module