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

_DATA	SEGMENT

	extrn	tclrascii:byte

init_procs label word
	dw	init_pushbutton
	dw	init_radiobutton
	dw	init_chechbox
	dw	init_textedit
	dw	init_textedit
	dw	init_menus

_DATA	ENDS

_TEXT	SEGMENT

init_pushbutton:
	lds	si,[bp-6]
	and	ax,_O_DEACT
	mov	di,ax
    init_pushbutton_00:
	mov	ax,[si]
	inc	si
	mov	al,ah
	and	al,0Fh
	test	di,di
	jz	init_pushbutton_01
	test	al,al
	jnz	init_pushbutton_03
	and	ah,070h
	or	ah,008h
	jmp	init_pushbutton_02
    init_pushbutton_01:
	cmp	al,8
	jne	init_pushbutton_03
	and	ah,070h
    init_pushbutton_02:
	mov	[si],ah
    init_pushbutton_03:
	inc	si
	dec	cx
	jnz	init_pushbutton_00
	ret

init_radiobutton:
	and	al,_O_RADIO
	mov	al,' '
	jz	init_radiobutton_set
	mov	al,7
    init_radiobutton_set:
	les	bx,[bp-6]
	mov	es:[bx+2],al
	ret

init_chechbox:
	and	ax,_O_FLAGB
	mov	al,' '
	jz	init_radiobutton_set
	mov	al,'x'
	jmp	init_radiobutton_set

init_textedit:
	mov	dl,tclrascii
	mov	ax,si
	lds	si,es:[bx+TO_ODATA]
	mov	bx,ax
	les	di,[bp-6]
	mov	ax,es:[di]
	mov	al,dl
	mov	dx,cx
	.if bx != _O_TEDIT
	    mov al,' '
	.endif

	.repeat
	    stosb
	    inc di
	.untilcxz
	mov	cx,dx
	test	si,si
	jz	init_textedit_02
	mov	di,[bp-6]
	cmp	bx,_O_TEDIT
	je	init_textedit_01
	add	di,2
	dec	cx
    init_textedit_01:
	lodsb
	test	al,al
	jz	init_textedit_02
	stosb
	inc	di
	dec	cx
	jnz	init_textedit_01
    init_textedit_02:
	ret

init_menus:
	test	al,_O_FLAGB
	jz	init_menus_00
	mov	al,175
	jmp	init_menus_01
    init_menus_00:
	and	ax,_O_RADIO
	jz	init_menus_02
	mov	al,7
    init_menus_01:
	les	bx,[bp-6]
	mov	es:[bx-2],al
    init_menus_02:
	ret

_TEXT	ENDS

PPROC	dlinitobj, dobj:dword, tobj:dword
local	lc[6]:byte
	push	ds
	push	si
	push	di
  ifdef __MOUSE__
	call	mousehide
  endif
	les	bx,tobj
	mov	dx,es:[bx+4]
	les	bx,dobj
	mov	ch,0
	mov	cl,es:[bx+6]
	mov	di,es:[bx.dl_flag]
	test	di,_D_ONSCR
	jz	@F
	add	dx,es:[bx+4]
	mov	cl,_scrcol
    @@:
	add	dx,dx
	mov	al,dh
	mul	cl
	mov	cl,es:[bx+6]
	mov	dh,0
	add	ax,dx
	mov	dx,_scrseg
	add	cx,cx
	test	di,_D_ONSCR
	jnz	@F
	add	ax,word ptr es:[bx.dl_wp]
	mov	dx,word ptr es:[bx.dl_wp+2]
    @@:
	mov	[bp-2],cx
	mov	[bp-4],dx
	mov	[bp-6],ax
	les	bx,tobj
	mov	ch,0
	mov	cl,es:[bx+6]
	mov	ax,es:[bx]
	mov	di,ax
	and	di,000Fh
	mov	si,di
	cld
	cmp	di,_O_MENUS
	ja	@F
	add	di,di
	call	[di+init_procs]
	mov	ax,1
	jmp	dlinitobj_end
    @@:
	xor	ax,ax
    dlinitobj_end:
	mov	di,ax
  ifdef __MOUSE__
	call	mouseshow
  endif
	les	bx,tobj
	mov	ax,di
	pop	di
	pop	si
	pop	ds
	ret
PEND	dlinitobj

PPROC	dlinit, td:dword
	push	si
	push	di
	les	bx,td
	mov	ah,0
	mov	al,es:[bx.dl_count]
	mov	si,ax
	mov     di,word ptr es:[bx.dl_object+2]
	mov     bx,word ptr es:[bx.dl_object]
    @@:
	test	si,si
	jz	@F
	invoke	dlinitobj, td, di::bx
	add	bx,16
	dec	si
	jnz	@B
    @@:
	les	bx,td
	pop	di
	pop	si
	ret
PEND	dlinit

	END