include	clib.inc
include	conio.inc
include	mouse.inc
include	keyb.inc

PPROC	tgetline, ttl:dword, buf:dword, lsize:word, bsize:word
local	dobj:S_DOBJ
local	rc:S_RECT
	push	si
	push	di
	mov	dobj.dl_flag,_D_STDDLG
	mov	dobj.dl_rect.rc_row,5
	mov	dobj.dl_rect.rc_y,5
	mov	ax,lsize
	mov	rc.rc_col,al
	add	al,8
	mov	dobj.dl_rect.rc_col,al
	shr	al,1
	mov	ah,40
	sub	ah,al
	mov	dobj.dl_rect.rc_x,ah
	mov	rc.rc_row,1
	mov	rc.rc_x,4
	mov	rc.rc_y,2
	mov	dl,at_background[B_Dialog]
	or	dl,at_foreground[F_Dialog]
	invoke	dlopen, addr dobj, dx, ttl
	test	ax,ax
	jz	tgetline_end
	les	bx,dobj.dl_wp
	mov	cl,rc.rc_col
	mov	ch,0
	mov	ax,cx
	add	ax,8
	add	ax,ax
	add	ax,ax
	add	ax,8
	add	bx,ax
	mov	al,07h
	call	@wcputa
	invoke	dlshow, addr dobj
  ifdef __MOUSE__
	call	msloop
  else
	xor	ax,ax
  endif
	mov	si,ax
	mov	di,ax
	jmp	tgetline_04
    tgetline_01:
	mov	ax,word ptr rc
	add	ax,word ptr dobj.dl_rect
	pushm	buf
	push	word ptr rc+2
	push	ax
	mov	ax,bsize
	xor	dx,dx
	test	ah,80h
	jz	tgetline_td
	mov	dx,_O_DTEXT
	and	ax,7FFFh
    tgetline_td:
	push	ax
	push	dx
	call	dledit
	mov	si,ax
	cmp	si,KEY_ENTER
	je	tgetline_02
	cmp	si,KEY_KPENTER
	jne	tgetline_03
    tgetline_02:
	inc	di
	jmp	tgetline_05
    tgetline_03:
  ifdef __MOUSE__
	cmp	si,MOUSECMD
	jne	tgetline_04
	pushm	dobj.dl_rect
	call	mousex
	push	ax
	call	mousey
	push	ax
	call	rcxyrow
	jz	tgetline_05
	push	ss
	lea	ax,dobj
	push	ax
	call	dlmove
  endif
    tgetline_04:
	cmp	si,KEY_ESC
	jne	tgetline_01
    tgetline_05:
	push	ss
	lea	ax,dobj
	push	ax
	call	dlclose
    tgetline_end:
	mov	ax,di
	pop	di
	pop	si
	ret
PEND	tgetline

	END
