include	doszip/doszip.inc
include	string.inc
include	conio.inc
include	mouse.inc
include	keyb.inc
include	tinfo.inc

	public	dzmodal
	public	cmctrlenter
	public	MOBJ_STATUSLINE

	extrn	com_info:	dword;S_TINFO
	extrn	menus_getevent:	NEAR

S_MSOBJ	STRUC
	mo_rect		dd ?
	mo_proc		PF ?
  ifndef LPROG
	mo_align8	dw ?
  endif
S_MSOBJ	ENDS

_DZIP	SEGMENT

cmctrlenter PROC DIST
	les	bx,DLG_Commandline
	test	byte ptr es:[bx],_D_ONSCR
	jz	cmctrlenter_nul
	mov	ax,cpanel
	call	panel_curobj
	jz	cmctrlenter_nul
	pushm	com_info
	push	dx
	push	ax
	mov	bx,word ptr com_info
	.if	byte ptr [bx] != 0
		invoke	strtrim, com_info
		invoke	strcat, com_info, addr cp_space
	.endif
	call	strcat
	invoke	strcat, dx::ax, addr cp_space
	invoke	comevent, KEY_END
	ret
    cmctrlenter_nul:
	xor	ax,ax
	ret
cmctrlenter ENDP

ifdef __MOUSE__

PANEL_SCROLLUP PROC
	push	bp
	mov	bp,sp
	mov	ax,cpanel
	cmp	ax,[bp+4]
	jnz	scrollup_03
    scrollup_00:
	xor	ax,ax
	mov	bx,[bp+4]
	cmp	[bx.pn_cel_index],ax
	jz	scrollup_01
	mov	[bx.pn_cel_index],ax
	mov	ax,bx
	call	pcell_update
	call	scroll_delay
	jmp	scrollup_02
    scrollup_01:
	push	word ptr [bp+4]
	push	KEY_UP
	call	panel_event
    scrollup_02:
	call	scroll_delay
	call	mousep
	cmp	ax,1
	je	scrollup_00
	mov	ax,1
	jmp	scrollup_04
    scrollup_03:
	mov	ax,[bp+4]
	call	panel_setactive
	xor	ax,ax
    scrollup_04:
	pop	bp
	ret	2
PANEL_SCROLLUP ENDP

PANEL_SCROLLDN PROC
	push	bp
	mov	bp,sp
	mov	ax,cpanel
	cmp	ax,[bp+4]
	jnz	scrolldn_03
    scrolldn_00:
	mov	bx,[bp+4]
	mov	ax,[bx.pn_cel_count]
	dec	ax
	cmp	[bx.pn_cel_index],ax
	jnl	scrolldn_01
	mov	[bx.pn_cel_index],ax
	mov	ax,bx
	call	pcell_update
	call	scroll_delay
	jmp	scrolldn_02
    scrolldn_01:
	push	word ptr [bp+4]
	push	KEY_DOWN
	call	panel_event
    scrolldn_02:
	call	scroll_delay
	call	mousep
	cmp	ax,1
	je	scrolldn_00
	mov	ax,1
	jmp	scrolldn_04
    scrolldn_03:
	mov	ax,[bp+4]
	call	panel_setactive
	xor	ax,ax
    scrolldn_04:
	pop	bp
	ret	2
PANEL_SCROLLDN ENDP

endif

CTRLEVENT PROC
	push	bp
	mov	bp,sp
	sub	sp,168
	push	si
	push	di
	les	bx,keyshift
	mov	al,es:[bx]
	and	al,KEY_ALT
	jz	ctrlevent_00
	call	cmquicksearch
	jmp	ctrlevent_06
    ctrlevent_00:
	xor	ax,ax
	test	cflag,_C_STATUSLINE
	jz	ctrlevent_01
	invoke	getcursor, addr [bp-168]
	call	cursoroff
	invoke	wcpushst, addr [bp-164], addr cp_stlctrl
	jmp	ctrlevent_03
    ctrlevent_01:
	call	tupdate
	call	getkey
	mov	di,ax
	or	ax,ax
	jnz	ctrlevent_04
  ifdef __MOUSE__
	call	mousep
	jz	ctrlevent_03
	call	mousey
	mov	[bp-4],ax
	mov	dx,ax
	call	mousex
	mov	[bp-2],ax
	mov	cx,8
	mov	bx,offset MOBJ_STLCTRL
	mov	di,MOUSECMD
	call	STATUSLINE_XY
	jz	ctrlevent_02
	call	[bx.mo_proc]
    ctrlevent_02:
	call	msloop
	jmp	ctrlevent_04
  endif
    ctrlevent_03:
	les	bx,keyshift
	mov	al,es:[bx]
	and	al,00001100B
	cmp	al,KEY_CTRL
	je	ctrlevent_01
    ctrlevent_04:
	test	cflag,_C_STATUSLINE
	jz	ctrlevent_05
	invoke	wcpopst, addr [bp-164]
	invoke	setcursor, [bp-168]
    ctrlevent_05:
	mov	ax,di
    ctrlevent_06:
	pop	di
	pop	si
	mov	sp,bp
	pop	bp
	ret
CTRLEVENT ENDP

ifdef __MOUSE__

MOUSEEVENT PROC
	push	si
	push	di
	call	mousep
	jz	mouseevent_end
	call	mousex
	mov	di,ax
	call	mousey
	mov	si,ax
  ifdef __CAL__
	test	cflag,_C_MENUSLINE
	jz	calendar_00
	or	ax,ax
	jnz	calendar_00
	cmp	di,62
	jle	calendar_00
	call	cmcalendar
	jmp	mouseevent_end
    calendar_00:
  endif
	mov	cx,9
	mov	bx,offset MOBJ_STATUSLINE
	mov	ax,di
	mov	dx,si
	call	STATUSLINE_XY
	jz	mouseevent_do
	call	msloop
	call	[bx.mo_proc]
	jmp	mouseevent_end
    mouseevent_do:
	invoke	panel_xycmd, panela, di, si
	mov	bx,panela
	or	ax,ax
	jnz	XY1_INSIDE
    mouseevent_B:
	invoke	panel_xycmd, panelb, di, si
	mov	bx,panelb
	or	ax,ax
	jnz	XY1_INSIDE
	jmp	mouseevent_end
    XY1_INSIDE:
	dec	ax
	jz	XY2_FILE
	dec	ax
	jnz	XY3_MOVEDOWN
    XY2_FILE:
	push	bx
	push	di
	push	si
	mov	ax,bx
	call	panel_setactive
	call	pcell_setxy
	jmp	mouseevent_null
    XY3_MOVEDOWN:
	dec	ax
	jnz	XY4_MOVEUP
	push	bx
	call	PANEL_SCROLLDN
	jmp	mouseevent_null
    XY4_MOVEUP:
	dec	ax
	jnz	XY5_NEWDISK
	push	bx
	call	PANEL_SCROLLUP
	jmp	mouseevent_null
    XY5_NEWDISK:
	dec	ax
	jnz	XY6_MINISTATUS
	cmp	bx,panela
	je	XY5_NEWDISKA
	call	cmbchdrv
	jmp	mouseevent_null
      XY5_NEWDISKA:
	call	cmachdrv
	jmp	mouseevent_null
    XY6_MINISTATUS:
	dec	ax
	jnz	XY7_CONFIG
	mov	ax,bx
	call	panel_xormini
	jmp	mouseevent_null
    XY7_CONFIG:
	dec	ax
	jnz	XY8_DRVINFO
	cmp	bx,panela
	je	XY7_CONFIGA
	call	cmbfilter
	jmp	mouseevent_null
      XY7_CONFIGA:
	call	cmafilter
	jmp	mouseevent_null
    XY8_DRVINFO:
	dec	ax
	jnz	mouseevent_B
	mov	ax,bx
	call	panel_xorinfo
    mouseevent_null:
	xor	ax,ax
    mouseevent_end:
	pop	di
	pop	si
	ret
MOUSEEVENT ENDP

endif

panel_toggleact proc public
	call panel_stateab
	.if !ZERO?
	    call history_save
	    mov	ax,panela
	    .if	ax == cpanel
		mov ax,panelb
	    .endif
	    call panel_setactive
	    mov ax,1
	.endif
	or ax,ax
	ret
panel_toggleact endp

globalcmd proc
	mov	bx,offset global_key
    @@:
	mov	ax,[bx.gl_key]
	or	ax,ax
	jz	@F
	mov	dx,bx
	add	bx,SIZE S_GLCMD
	cmp	ax,si
	jne	@B
	mov	bx,dx
	call	[bx.gl_proc]
	mov	ax,1
    @@:
	ret
globalcmd endp

dzmodal	PROC
	push si
	.while mainswitch == 0
	    call tupdate
	    les bx,keyshift
	    .if byte ptr es:[bx] & KEY_CTRL
		call ctrlevent
	    .else
		call menus_getevent
	    .endif
	    mov si,ax
	    .if ax == KEY_ENTER || ax == KEY_KPENTER
		.if com_base
		    call doskey_save
		    .if ax
			invoke command, addr com_base
		    .endif
		    .if !ax
			invoke comevent, KEY_END
		    .endif
		    .continue
		.endif
	    .endif
	    .if com_base
		invoke comevent, si
		.if ax
		    .continue
		.endif
	    .endif
	    call cpanel_state
	    .if !ZERO?
		invoke panel_event, cpanel, si
		.if ax
		    .continue
		.endif
	    .endif
	    .break .if mainswitch != 0
	  ifdef __MOUSE__
	    .if si == MOUSECMD
		call mouseevent
		call msloop
		.continue
	    .endif
	  endif
	    .if si == KEY_TAB
		call panel_toggleact
		.continue
	    .endif
	    call globalcmd
	    .if !ax
		invoke comevent, si
	    .else
		call msloop
		.continue
	    .endif
	    .if si == KEY_KPPLUS || si == KEY_KPMIN || si == KEY_KPSTAR
		invoke comevent, si
	    .endif
	.endw
	pop si
	ret
dzmodal	ENDP

_DZIP	ENDS

_DATA	SEGMENT

MSOBJ	macro	rc, name
	dd	rc
	dw	offset name
	dw	SEG _DZIP
	endm

MOBJ_STLCTRL label word
	MSOBJ	01071801h, cmatoggle
	MSOBJ	0106180Ch, cmbtoggle
	MSOBJ	01071817h, cmview
	MSOBJ	01071820h, cmedit
	MSOBJ	01071829h, cmcname
	MSOBJ	01071832h, cmctype
	MSOBJ	0107183Ah, cmcdate
	MSOBJ	01071844h, cmcsize

MOBJ_STATUSLINE	label word
	MSOBJ	01071801h, cmhelp
	MSOBJ	0106180Ah, cmrename
	MSOBJ	01071812h, cmview
	MSOBJ	0107181Bh, cmedit
	MSOBJ	01071824h, cmcopy
	MSOBJ	0107182Dh, cmmove
	MSOBJ	01071836h, cmmkdir
	MSOBJ	01071840h, cmdelete
	MSOBJ	01071848h, cmexit

cp_stlctrl label byte
	db '&F&1 PanelA  &F&2 PanelB  &F&3 View  &F&4 Edit  '
	db '&F&5 Name  &F&6 Type  &F&7 Date  &F&8 Size',0

cp_space db ' ',0

_DATA	ENDS

	END
