include	clib.inc
include	dos.inc
include	fblk.inc
include	string.inc
include	filter.inc
include	conio.inc
include	time.inc
include	stdio.inc
include	stdlib.inc
include	format.inc

	public	filter_edit

	extrn	cp_stdmask: byte
	extrn	view_readme: DIST
	extrn	IDD_OperationFilters:DWORD

ID_INCLUDE	equ	1*16
ID_EXCLUDE	equ	2*16
ID_MIN_DATE	equ	3*16
ID_MAX_DATE	equ	4*16
ID_MIN_SIZE	equ	5*16
ID_MAX_SIZE	equ	6*16
ID_RDONLY	equ	7*16
ID_HIDDEN	equ	8*16
ID_SYSTEM	equ	9*16
ID_VOLID	equ	10*16
ID_SUBDIR	equ	11*16
ID_ARCH		equ	12*16
ID_OK		equ	13*16
ID_CLEAR	equ	14*16
ID_CANCEL	equ	15*16

_TEXT	SEGMENT

event_help PROC DIST
	mov	ax,12796
	call	view_readme
	ret
event_help ENDP

event_clear PROC DIST
	mov	dx,ds
	mov	cx,si
	lds	si,tdialog
	xor	ax,ax
	mov	bx,[si+ID_MIN_DATE+TO_ODATA]
	mov	[bx],al
	mov	bx,[si+ID_MAX_DATE+TO_ODATA]
	mov	[bx],al
	mov	bx,[si+ID_MIN_SIZE+TO_ODATA]
	mov	[bx],al
	mov	bx,[si+ID_MAX_SIZE+TO_ODATA]
	mov	[bx],al
	mov	ds,dx
	mov	si,cx
	lodm	filter
	push	dx
	mov	bx,ax
	add	ax,of_include
	push	ax
	push	ds
	push	offset cp_stdmask
	invoke	memzero, dx::bx, SIZE S_FILT
	call	strcpy
	les	bx,filter
	mov	es:[bx.of_flag],-1
	mov	dx,word ptr tdialog+2
	mov	ax,ID_RDONLY
	invoke	tosetbitflag, dx::ax, 6, _O_FLAGB, 0FFFFFFFFh
	mov	ax,_C_REOPEN
	ret
event_clear ENDP

filter_edit proc dist pascal public uses si di filt:dword, glcmd:dword
local	DLG_OperationFilters:dword
	xor ax,ax
	mov word ptr filter,ax
	invoke rsopen, IDD_OperationFilters
	jz filter_edit_end
	stom DLG_OperationFilters
	mov di,ax
	lodm filt
	add ax,of_include
	stom es:[di.to_data+ID_INCLUDE]
	mov es:[di.to_count+ID_INCLUDE],8
	add ax,128
	stom es:[di.to_data+ID_EXCLUDE]
	mov es:[di.to_count+ID_EXCLUDE],8
	LPUSH cs
	push offset event_help
	call thelp_set
	mov ax,word ptr glcmd
	stoso es:[di.to_data+ID_OK],ds,ax
	fpmov es:[di.to_proc+ID_CLEAR],event_clear
	mov si,word ptr filt
	.if [si.of_min_date]
	    invoke dwtolstr, es:[di.to_data+ID_MIN_DATE], [si.of_min_date]
	.endif
	.if [si.of_max_date]
	    invoke dwtolstr, es:[di.to_data+ID_MAX_DATE], [si.of_max_date]
	.endif
	lodm [si.of_min_size]
	.if ax
	    push dx
	    push ax
	    mov ax,offset format_lu
	    mov bx,word ptr es:[di.to_data+ID_MIN_SIZE]
	    mov dx,word ptr es:[di.to_data+ID_MIN_SIZE+2]
	    call @sprintf
	    add sp,4
	.endif
	lodm [si.of_max_size]
	.if ax || dx
	    push dx
	    push ax
	    mov ax,offset format_lu
	    mov bx,word ptr es:[di.to_data+ID_MAX_SIZE]
	    mov dx,word ptr es:[di.to_data+ID_MAX_SIZE+2]
	    call @sprintf
	    add sp,4
	.endif
	mov bx,ID_RDONLY+4
	mov ax,[si.of_flag]
	invoke tosetbitflag, es::bx, 6, _O_FLAGB, ax::ax
	invoke dlinit, DLG_OperationFilters
	movmx filter, filt
	invoke rsevent, IDD_OperationFilters, DLG_OperationFilters
	.if ax
	    pushm es:[di].to_data[ID_MIN_DATE]
	    pushm es:[di].to_data[ID_MAX_DATE]
	    pushm es:[di].to_data[ID_MIN_SIZE]
	    pushm es:[di].to_data[ID_MAX_SIZE]
	    push es
	    push ID_RDONLY+4
	    push 6
	    push _O_FLAGB
	    call togetbitflag
	    or ax,0FFC0h
	    mov [si.of_flag],ax
	    call strtol
	    stom [si.of_max_size]
	    call strtol
	    stom [si.of_min_size]
	    call strtodw
	    mov [si.of_max_date],ax
	    call strtodw
	    mov [si.of_min_date],ax
	.else
	    mov word ptr filter,ax
	    mov word ptr filter+2,ax
	.endif
	call thelp_pop
	invoke dlclose, DLG_OperationFilters
	mov ax,_C_NORMAL
    filter_edit_end:
	ret
filter_edit endp

_TEXT	ENDS

	END
