include doszip/doszip.inc
include	dir.inc
include	fblk.inc
include	stdio.inc
include	stdlib.inc
include	string.inc
include	conio.inc
include	mouse.inc
include	keyb.inc
include	wsub.inc
include	format.inc

	public	cmfilter
	public	cmafilter
	public	cmbfilter
	public	cmfilter_load
	public	cmloadpath

	extrn	IDD_DZPanelFilter:dword
	extrn	IDD_DZFindFile:dword

_DATA	SEGMENT

path_ax		dw ?
path_dx		dw ?
cp_directory	db 'Directory',0
cp_filter 	db 'Filter',0
filter_keys	label word
GCMD KEY_F3,	cmfilter_load
GCMD KEY_F4,	cmfilter_date
		dw	0

_DATA	ENDS

ID_READCOUNT	equ	1*16
ID_READMASK	equ	2*16
ID_DIRECTORY	equ	3*16
ID_OK		equ	4*16
ID_LOADPATH	equ	5*16
ID_CANCEL	equ	6*16

_DZIP	SEGMENT

event_loadpath proc dist
	push	bp
	mov	bp,sp
	sub	sp,WMAXPATH+4
	mov	ax,sp
	push	si
	push	di
	mov	di,ax
	push	WMAXPATH
	push	ss
	push	ax
	push	ds
	push	offset cp_directory
	call	TOOLS_IDD
	mov	si,ax
	call	msloop
	or	si,si
	jz	event_loadpath_00
	cmp	si,MOUSECMD
	jne	event_loadpath_do
    event_loadpath_00:
	mov	ax,_C_NORMAL
	jmp	event_loadpath_end
    event_loadpath_do:
	push	ss
	push	di
	call	expand_environ
	push	path_dx
	push	path_ax
	push	dx
	push	ax
	call	strcpy
	mov	ax,_C_REOPEN
    event_loadpath_end:
	pop	di
	pop	si
	mov	sp,bp
	pop	bp
	ret
event_loadpath endp

PanelFilter proc pascal Panel:word, xpos:byte
	push	si
	push	di
	mov	si,word ptr IDD_DZPanelFilter
	mov	al,xpos
	mov	[si+6],al
	invoke	rsopen, ds::si
	jz	PANEL_FILTER_04
	push	dx
	push	ax
	push	dx
	push	ax
	push	dx
	push	ax
	mov	bx,[bp+6]
	mov	si,word ptr [bx.pn_wsub]
	mov	di,ax
	mov	ax,offset event_loadpath
	mov	es:[di+ID_LOADPATH+TO_OPROC],ax
	LMOV	es:[di+ID_LOADPATH+TO_SPROC],cs
	mov	dx,es
	mov	ax,es:[di+ID_DIRECTORY+TO_ODATA]
	mov	path_dx,dx
	mov	path_ax,ax
	push	dx
	push	ax
	pushm	[si.ws_path]
	invoke	strcpy, es:[di+ID_READMASK+TO_ODATA], [si.ws_mask]
	call	strcpy
	push	[si.ws_maxfb]
	mov	ax,offset format_d
	mov	dx,es:[di+ID_READCOUNT+TO_SDATA]
	mov	bx,es:[di+ID_READCOUNT+TO_ODATA]
	call	@sprintf
	add	sp,2
	call	dlinit
	call	dlevent
	or	ax,ax
	jz	PANEL_FILTER_01
	pushm	[si.ws_mask]
	pushm	es:[di+ID_READMASK+TO_ODATA]
	pushm	[si.ws_path]
	pushm	es:[di+ID_DIRECTORY+TO_ODATA]
	invoke	atol, es:[di+ID_READCOUNT+TO_ODATA]
	mov	di,ax
	call	strcpy
	call	strcpy
	call	dlclose
	cmp	di,[si.ws_maxfb]
	je	PANEL_FILTER_02
	cmp	di,10
	jng	PANEL_FILTER_02
	cmp	di,WMAXFBLOCK
	jnl	PANEL_FILTER_02
	cmp	word ptr [si.ws_fcb],0
	jz	PANEL_FILTER_02
	invoke	wsclose, ds::si
	push	[si.ws_maxfb]
	mov	[si.ws_maxfb],di
	invoke	wsopen, ds::si
	or	ax,ax
	pop	ax
	jnz	PANEL_FILTER_02
	mov	[si.ws_maxfb],ax
	invoke	wsopen, ds::si
	xor	ax,ax
	jmp	PANEL_FILTER_04
    PANEL_FILTER_01:
	call	dlclose
	xor	ax,ax
	jmp	PANEL_FILTER_04
    PANEL_FILTER_02:
	mov	ax,[bp+6]
	call	panel_reread
	mov	ax,[bp+6]
	cmp	ax,cpanel
	jnz	PANEL_FILTER_03
	push	ds
	push	si
	call	cominit
    PANEL_FILTER_03:
	mov	ax,1
    PANEL_FILTER_04:
	pop	di
	pop	si
	ret
PanelFilter endp

cmafilter proc dist
	invoke	PanelFilter, panela, 3
	ret
cmafilter endp

cmbfilter proc dist
	invoke	PanelFilter, panelb, 42
	ret
cmbfilter endp

cmfilter_load proc dist pascal uses si di
local	filt[FILT_MAXSTRING]:byte
local	dialog:dword
	movmx dialog,tdialog
	mov di,word ptr IDD_DZFindFile
	mov dl,[di.rs_count]
	les bx,tdialog
	mov ax,1
	.if es:[bx.dl_count] == dl
	    mov	ax,0D0Dh
	.endif
	mov di,ax
	.if es:[bx.dl_index] <= al
	    invoke tools_idd, 128, addr filt, addr cp_filter
	    mov	si,ax
	    call msloop
	    mov	ax,_C_NORMAL
	    .if si
		.if si != MOUSECMD
		    les bx,dialog
		    mov dx,di
		    .if es:[bx.dl_index] != dl
			mov es:[bx.dl_index],dh
		    .endif
		    mov al,es:[bx.dl_index]
		    shl ax,4
		    les bx,es:[bx.dl_object]
		    add bx,ax
		    invoke strcpy, es:[bx.to_data], addr filt
		    mov	ax,_C_REOPEN
		.endif
	    .endif
	.else
	    mov ax,_C_NORMAL
	.endif
	ret
cmfilter_load endp

cmfilter_date proc dist
  ifdef __CAL__
	les	bx,tdialog
	cmp	es:[bx.dl_index],2
	jb	cmfilter_date_00
	cmp	es:[bx.dl_index],3
	ja	cmfilter_date_00
	call	cmcalendar
	or	ax,ax
	jz	cmfilter_date_00
	push	cx
	push	bx
	push	dx
	les	bx,tdialog
	mov	dl,es:[bx.dl_index]
	mov	dh,00h
	inc	dx
	shl	dx,4
	add	bx,dx
	mov	dx,es:[bx+TO_SDATA]
	mov	bx,es:[bx+TO_ODATA]
	mov	ax,offset cp_datefrm
	call	@sprintf
	add	sp,6
	mov	ax,_C_REOPEN
	jmp	cmfilter_date_01
  endif
    cmfilter_date_00:
	mov	ax,_C_NORMAL
    cmfilter_date_01:
	ret
cmfilter_date endp

cmfilter proc dist
	invoke	filter_edit, addr opfilter, addr filter_keys
	ret
cmfilter endp

cmloadpath proc dist
	sub	sp,WMAXPATH
	mov	ax,sp
	mov	path_ax,ax
	mov	path_dx,ss
	push	ax
	call	event_loadpath
	cmp	ax,_C_REOPEN
	pop	ax
	jne	cmloadpath_end
	mov	dx,ss
	call	cpanel_setpath
    cmloadpath_end:
	add	sp,WMAXPATH
	ret
cmloadpath endp

_DZIP	ENDS

	END
