2010-07-01 09:35:54 +02:00
|
|
|
;*****************************************************************************
|
2024-05-22 12:10:18 +02:00
|
|
|
; Macro for use Open Dialog - for KolibriOS
|
2013-03-26 06:20:40 +01:00
|
|
|
; Copyright (c) 2009-2013, Marat Zakiyanov aka Mario79, aka Mario
|
2010-07-01 09:35:54 +02:00
|
|
|
; All rights reserved.
|
|
|
|
;
|
|
|
|
; Redistribution and use in source and binary forms, with or without
|
|
|
|
; modification, are permitted provided that the following conditions are met:
|
|
|
|
; * Redistributions of source code must retain the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer.
|
|
|
|
; * Redistributions in binary form must reproduce the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer in the
|
|
|
|
; documentation and/or other materials provided with the distribution.
|
|
|
|
; * Neither the name of the <organization> nor the
|
|
|
|
; names of its contributors may be used to endorse or promote products
|
|
|
|
; derived from this software without specific prior written permission.
|
|
|
|
;
|
|
|
|
; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
|
|
|
|
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
|
|
|
|
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
;*****************************************************************************
|
2013-03-26 06:20:40 +01:00
|
|
|
;---------------------------------------------------------------------
|
|
|
|
;Some documentation for memory
|
|
|
|
;
|
|
|
|
;area name db 'FFFFFFFF_open_dialog',0 ; FFFFFFFF = PID
|
|
|
|
;
|
|
|
|
; communication area data
|
|
|
|
; flag ; +0
|
|
|
|
; dw 0 ; 0 - empty, 1 - file for open, 2 -folder for open,
|
|
|
|
; 3 - cancel, 4 - path=name of area 6822.
|
|
|
|
;
|
|
|
|
; type of dialog: 0-Open, 1-Save, 2-Dir
|
|
|
|
; dw 0 ; +2
|
|
|
|
;
|
|
|
|
; window X size ; +4
|
|
|
|
; dw 0
|
|
|
|
;
|
|
|
|
; window X position ; +6
|
|
|
|
; dw 0
|
|
|
|
;
|
|
|
|
; window y size ; +8
|
|
|
|
; dw 0
|
|
|
|
;
|
|
|
|
; window Y position ; +10
|
|
|
|
; dw 0
|
|
|
|
;
|
|
|
|
; OpenDialog WINDOW SLOT ; +12
|
|
|
|
; dd 0
|
|
|
|
;
|
|
|
|
; file_path ; +16
|
|
|
|
; rb 3824 ; path to file
|
|
|
|
;
|
|
|
|
; file name ; +3840
|
|
|
|
; rb 256
|
|
|
|
;
|
|
|
|
; filtration flag ; +4096
|
|
|
|
; dd 0 ; flag 0 - no filtration, 1 - filtering
|
|
|
|
;
|
|
|
|
; area for storage of filtering values ; +4100
|
|
|
|
; rb 4092
|
|
|
|
;---------------------------------------------------------------------
|
2010-07-01 09:35:54 +02:00
|
|
|
;*****************************************************************************
|
|
|
|
macro OpenDialog_exit
|
|
|
|
{
|
|
|
|
popa
|
|
|
|
ret 4
|
|
|
|
}
|
|
|
|
;*****************************************************************************
|
|
|
|
macro use_OpenDialog
|
|
|
|
{
|
|
|
|
OpenDialog:
|
|
|
|
od_type equ dword [ebp] ; 0-Open, 1-Save, 2-Dir
|
|
|
|
od_procinfo equ dword [ebp+4] ; Process info area for function 9
|
|
|
|
od_com_area_name equ dword [ebp+8] ; Name for shared area
|
|
|
|
od_com_area equ dword [ebp+12] ; Adress of shared area
|
|
|
|
od_opendir_pach equ dword [ebp+16] ; Temp area the directory for show
|
|
|
|
od_dir_default_pach equ dword [ebp+20] ; Default path of directory,
|
|
|
|
od_start_path equ dword [ebp+24] ; Location path to OpenDialog
|
|
|
|
od_draw_window equ dword [ebp+28] ; Adress of procedure - draw_window
|
|
|
|
od_status equ dword [ebp+32] ; 0-Cancel, 1-Get path OK, 2-Use alternatives
|
|
|
|
od_openfile_pach equ dword [ebp+36] ; Getting path to file
|
|
|
|
od_filename_area equ dword [ebp+40] ; Adress of file name area
|
|
|
|
od_filter_area equ dword [ebp+44] ; Adress of filter area
|
2010-08-24 10:27:26 +02:00
|
|
|
od_x_size equ [ebp+48] ; Window X size
|
|
|
|
od_x_start equ [ebp+50] ; Window X position
|
|
|
|
od_y_size equ [ebp+52] ; Window y size
|
|
|
|
od_y_start equ [ebp+54] ; Window Y position
|
2010-07-01 09:35:54 +02:00
|
|
|
;*****************************************************************************
|
|
|
|
.init:
|
|
|
|
pusha
|
|
|
|
mov ebp,dword [esp+36]
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_THREAD_INFO,od_procinfo,-1
|
2010-07-01 09:35:54 +02:00
|
|
|
mov ebx,[ebx+30]
|
|
|
|
mov edi,od_com_area_name
|
|
|
|
add edi,7
|
|
|
|
std
|
|
|
|
mov ecx,4
|
|
|
|
@@:
|
|
|
|
mov al,bl
|
|
|
|
and al,1111b
|
|
|
|
add al,0x30
|
|
|
|
stosb
|
|
|
|
mov al,bl
|
|
|
|
shr al,4
|
|
|
|
and al,1111b
|
|
|
|
add al,0x30
|
|
|
|
stosb
|
|
|
|
shr ebx,8
|
|
|
|
dec ecx
|
|
|
|
jnz @r
|
|
|
|
cld
|
|
|
|
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYS_MISC,SSF_MEM_OPEN,od_com_area_name,8192,0x09
|
2010-07-01 09:35:54 +02:00
|
|
|
mov od_com_area,eax
|
|
|
|
|
|
|
|
mov esi,od_openfile_pach
|
|
|
|
mov edi,od_opendir_pach
|
|
|
|
call .copy_dir_path
|
|
|
|
|
|
|
|
OpenDialog_exit
|
|
|
|
;*****************************************************************************
|
|
|
|
;*****************************************************************************
|
|
|
|
.start:
|
|
|
|
pusha
|
|
|
|
mov ebp,dword [esp+36]
|
2010-10-11 16:00:08 +02:00
|
|
|
|
2010-07-01 09:35:54 +02:00
|
|
|
mov eax,od_com_area
|
|
|
|
test eax,eax
|
|
|
|
jz .1
|
|
|
|
mov ebx,od_type
|
|
|
|
mov [eax+2],bx
|
|
|
|
|
|
|
|
mov [eax],word 2 ; folder for open
|
2010-08-24 10:27:26 +02:00
|
|
|
|
|
|
|
pusha
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_THREAD_INFO,od_procinfo,-1
|
2010-08-24 10:27:26 +02:00
|
|
|
|
|
|
|
mov eax,[ebx+42] ;main window x size
|
|
|
|
shr eax,1
|
|
|
|
add eax,[ebx+34] ; main window x start
|
|
|
|
mov cx,od_x_size
|
|
|
|
shr cx,1
|
|
|
|
sub ax,cx
|
|
|
|
test ax,cx
|
|
|
|
test eax,0x8000
|
|
|
|
jz @f
|
|
|
|
xor eax,eax
|
|
|
|
@@:
|
|
|
|
mov od_x_start,ax
|
|
|
|
|
|
|
|
mov eax,[ebx+46] ;main window y size
|
|
|
|
shr eax,1
|
|
|
|
add eax,[ebx+38] ; main window y start
|
|
|
|
mov cx,od_y_size
|
|
|
|
shr cx,1
|
|
|
|
sub ax,cx
|
|
|
|
test eax,0x8000
|
|
|
|
jz @f
|
|
|
|
xor eax,eax
|
|
|
|
@@:
|
|
|
|
mov od_y_start,ax
|
|
|
|
popa
|
|
|
|
|
|
|
|
mov ebx,dword od_x_size
|
|
|
|
mov [eax+4],ebx
|
|
|
|
mov ebx,dword od_y_size
|
|
|
|
mov [eax+8],ebx
|
|
|
|
|
2010-07-01 09:35:54 +02:00
|
|
|
mov edi,eax
|
2010-10-11 16:00:08 +02:00
|
|
|
add edi,16 ;12
|
2010-07-01 09:35:54 +02:00
|
|
|
|
|
|
|
mov esi,od_opendir_pach
|
|
|
|
xor eax,eax
|
|
|
|
mov al,[esi]
|
|
|
|
test eax,eax
|
|
|
|
jnz @f
|
|
|
|
mov esi,od_dir_default_pach ;communication_area_default_pach
|
|
|
|
@@:
|
|
|
|
call .copy
|
|
|
|
;----------------------------------------------
|
|
|
|
; copy file name to shared area
|
|
|
|
cmp od_type,dword 2
|
|
|
|
je .4
|
|
|
|
mov edi,od_com_area
|
2010-08-24 10:27:26 +02:00
|
|
|
add edi,3840 ;4096-256
|
2010-07-01 09:35:54 +02:00
|
|
|
|
|
|
|
mov esi,od_filename_area
|
|
|
|
test esi,esi
|
|
|
|
jnz @f
|
|
|
|
xor eax,eax
|
|
|
|
mov [edi],eax
|
|
|
|
jmp .4
|
|
|
|
@@:
|
|
|
|
call .copy
|
|
|
|
.4:
|
|
|
|
;----------------------------------------------
|
|
|
|
cmp od_type,dword 2
|
|
|
|
je @f
|
|
|
|
call .get_filter_data
|
|
|
|
@@:
|
|
|
|
;----------------------------------------------
|
2010-10-12 14:12:42 +02:00
|
|
|
mov ebx,od_procinfo
|
|
|
|
xor eax,eax
|
|
|
|
mov edi,ebx
|
|
|
|
mov ecx,6
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
mov [ebx],dword 7
|
2010-07-01 09:35:54 +02:00
|
|
|
mov eax,od_com_area_name
|
2010-10-12 14:12:42 +02:00
|
|
|
mov [ebx+8],eax
|
2010-07-01 09:35:54 +02:00
|
|
|
mov eax,od_start_path
|
2010-10-12 14:12:42 +02:00
|
|
|
mov [ebx+21],eax
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_FILE
|
2010-07-01 09:35:54 +02:00
|
|
|
|
|
|
|
shr eax,31
|
|
|
|
test eax,eax
|
|
|
|
jnz .1
|
2010-10-12 01:19:35 +02:00
|
|
|
;----------------------------------------------
|
2010-07-01 09:35:54 +02:00
|
|
|
.still:
|
2010-10-12 01:19:35 +02:00
|
|
|
; The main window of application sometimes
|
|
|
|
; is not present the really. For this reason
|
|
|
|
; not use func 10 and 23, because event 1
|
|
|
|
; is not cleared without call of func 0.
|
2013-03-26 20:46:18 +01:00
|
|
|
; In this case is suitable only func 5 and 11,
|
|
|
|
; or 68.1 and 11 for better response.
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYS_MISC,SSF_SWITCH_TASK
|
|
|
|
mcall SF_SLEEP,10 ; because OS uses a new scheduler for kernel(SVN r.3534)
|
|
|
|
mcall SF_CHECK_EVENT
|
2010-07-01 09:35:54 +02:00
|
|
|
cmp eax,1
|
2010-10-12 14:12:42 +02:00
|
|
|
je .draw
|
|
|
|
cmp eax,2
|
|
|
|
je .key
|
|
|
|
cmp eax,3
|
|
|
|
je .button
|
|
|
|
jmp .no_draw
|
|
|
|
.key:
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_GET_KEY
|
2010-10-12 14:12:42 +02:00
|
|
|
jmp .no_draw
|
|
|
|
.button:
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_GET_BUTTON
|
2010-10-12 14:12:42 +02:00
|
|
|
jmp .no_draw
|
2010-10-12 01:19:35 +02:00
|
|
|
;----------------------------------------------
|
|
|
|
.draw:
|
2010-07-01 09:35:54 +02:00
|
|
|
pusha
|
|
|
|
call od_draw_window
|
|
|
|
popa
|
2010-10-12 01:19:35 +02:00
|
|
|
;----------------------------------------------
|
2010-10-11 16:00:08 +02:00
|
|
|
pusha
|
2010-10-12 14:12:42 +02:00
|
|
|
call .prepare_PID
|
2010-10-12 01:19:35 +02:00
|
|
|
jz @f
|
|
|
|
|
2010-10-11 16:00:08 +02:00
|
|
|
mov ecx,eax ; WINDOW SLOT
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYSTEM,SSF_GET_ACTIVE_WINDOW
|
2010-10-11 16:00:08 +02:00
|
|
|
cmp eax,ecx ; compare ACTIVE and WINDOW SLOT
|
|
|
|
jne @f
|
2010-10-12 01:19:35 +02:00
|
|
|
|
2010-10-11 16:00:08 +02:00
|
|
|
mov eax,od_com_area
|
|
|
|
mov ecx,[eax+12]
|
|
|
|
test ecx,ecx
|
|
|
|
jz @f
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYSTEM,SSF_FOCUS_WINDOW
|
2010-07-01 09:35:54 +02:00
|
|
|
@@:
|
2010-10-11 16:00:08 +02:00
|
|
|
popa
|
2010-10-12 01:19:35 +02:00
|
|
|
;----------------------------------------------
|
2010-10-11 16:00:08 +02:00
|
|
|
.no_draw:
|
2010-07-01 09:35:54 +02:00
|
|
|
mov eax,od_com_area
|
|
|
|
movzx ebx,word [eax]
|
|
|
|
test ebx,ebx
|
|
|
|
jz .still
|
|
|
|
cmp ebx,3
|
|
|
|
je .2
|
|
|
|
cmp ebx,1
|
|
|
|
jne .still
|
|
|
|
|
|
|
|
mov esi,od_com_area
|
2010-10-11 16:00:08 +02:00
|
|
|
add esi,16 ;12
|
2010-07-01 09:35:54 +02:00
|
|
|
mov edi,od_openfile_pach
|
|
|
|
call .copy
|
|
|
|
mov od_status,1
|
2010-08-24 10:27:26 +02:00
|
|
|
|
2010-07-01 09:35:54 +02:00
|
|
|
mov esi,od_openfile_pach
|
|
|
|
mov edi,od_opendir_pach
|
|
|
|
call .copy_dir_path
|
|
|
|
;----------------------------------------------
|
|
|
|
; copy file name from shared area
|
|
|
|
cmp od_type,dword 2
|
|
|
|
je @f
|
|
|
|
mov esi,od_com_area
|
2010-08-24 10:27:26 +02:00
|
|
|
add esi,3840
|
2010-07-01 09:35:54 +02:00
|
|
|
mov edi,od_filename_area
|
|
|
|
test edi,edi
|
|
|
|
jz @f
|
|
|
|
call .copy
|
|
|
|
@@:
|
|
|
|
;----------------------------------------------
|
|
|
|
jmp .3
|
|
|
|
.2:
|
|
|
|
mov od_status,0
|
|
|
|
jmp .3
|
|
|
|
.1:
|
|
|
|
mov od_status,2
|
|
|
|
.3:
|
2010-08-24 10:27:26 +02:00
|
|
|
mov eax,od_com_area
|
|
|
|
mov ebx,[eax+4]
|
|
|
|
mov od_x_size,ebx
|
|
|
|
mov ebx,[eax+8]
|
|
|
|
mov od_y_size, ebx
|
2010-10-12 14:12:42 +02:00
|
|
|
|
|
|
|
call .prepare_PID
|
|
|
|
jz @f
|
|
|
|
mov ecx,eax ; WINDOW SLOT
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYSTEM,SSF_FOCUS_WINDOW
|
2010-10-12 14:12:42 +02:00
|
|
|
@@:
|
2010-07-01 09:35:54 +02:00
|
|
|
OpenDialog_exit
|
|
|
|
;----------------------------------------------
|
2010-10-12 14:12:42 +02:00
|
|
|
.prepare_PID:
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_THREAD_INFO,od_procinfo,-1
|
2010-10-12 14:12:42 +02:00
|
|
|
mov ecx,[ebx+30] ; PID
|
2017-10-04 15:16:04 +02:00
|
|
|
mcall SF_SYSTEM,SSF_GET_THREAD_SLOT
|
2010-10-12 14:12:42 +02:00
|
|
|
test eax,eax
|
|
|
|
ret
|
|
|
|
;----------------------------------------------
|
2010-07-01 09:35:54 +02:00
|
|
|
.get_filter_data:
|
|
|
|
mov edi,od_com_area
|
|
|
|
test edi,edi
|
|
|
|
jnz @f
|
|
|
|
ret
|
|
|
|
@@:
|
2010-08-24 10:27:26 +02:00
|
|
|
add edi,4100
|
2010-07-01 09:35:54 +02:00
|
|
|
mov esi,od_filter_area
|
|
|
|
mov ecx,[esi]
|
|
|
|
test ecx,ecx
|
|
|
|
jnz @f
|
|
|
|
mov edi,od_com_area
|
|
|
|
mov [edi+4096],dword 0
|
|
|
|
ret
|
2017-10-04 15:16:04 +02:00
|
|
|
@@:
|
|
|
|
cmp ecx,4091 ;max filter len = 8192-4100-1
|
|
|
|
jle @f
|
|
|
|
;todo ... error message: corrypt filter
|
|
|
|
mov edi,od_com_area
|
|
|
|
mov [edi+4096],dword 0
|
|
|
|
ret
|
2010-07-01 09:35:54 +02:00
|
|
|
@@:
|
|
|
|
inc ecx
|
|
|
|
cld
|
|
|
|
rep movsb
|
|
|
|
mov edi,od_com_area
|
|
|
|
mov [edi+4096],dword 1
|
|
|
|
ret
|
|
|
|
;----------------------------------------------
|
|
|
|
.copy:
|
|
|
|
xor eax,eax
|
|
|
|
cld
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test eax,eax
|
|
|
|
jnz @b
|
|
|
|
ret
|
|
|
|
;----------------------------------------------
|
|
|
|
.copy_dir_path:
|
|
|
|
xor eax,eax
|
|
|
|
cmp [esi],al
|
|
|
|
jne @f
|
|
|
|
mov [edi],al
|
|
|
|
mov [ebx],al
|
|
|
|
xor ebx,ebx
|
|
|
|
inc ebx
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cld
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test eax,eax
|
|
|
|
jnz @b
|
|
|
|
cmp od_type,dword 2
|
|
|
|
jne @f
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov esi,edi
|
|
|
|
dec esi
|
|
|
|
@@:
|
|
|
|
std
|
|
|
|
lodsb
|
|
|
|
cmp al,'/'
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov [esi+1],byte 0
|
|
|
|
cld
|
|
|
|
ret
|
|
|
|
;----------------------------------------------
|
2019-03-23 09:31:59 +01:00
|
|
|
align 4
|
|
|
|
.set_file_name:
|
|
|
|
push ebp
|
|
|
|
mov ebp,esp
|
|
|
|
push eax ecx edi esi
|
|
|
|
mov edi,[ebp+8] ;open dlg struct
|
|
|
|
mov edi,[edi+40] ;+40 - filename_area
|
|
|
|
mov esi,[ebp+12] ;file name
|
|
|
|
mov ecx,256
|
|
|
|
;copy file name in dialog
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test eax,eax
|
|
|
|
loop @b
|
|
|
|
pop esi edi ecx eax
|
|
|
|
pop ebp
|
|
|
|
ret 8
|
|
|
|
;----------------------------------------------
|
|
|
|
align 4
|
|
|
|
.set_file_ext:
|
|
|
|
push ebp
|
|
|
|
mov ebp,esp
|
|
|
|
push eax ecx edi esi
|
|
|
|
mov esi,[ebp+8] ;open dlg struct
|
|
|
|
|
|
|
|
xor eax,eax
|
|
|
|
mov ecx,256
|
|
|
|
mov edi,[esi+40] ;+40 - filename_area
|
|
|
|
repne scasb
|
|
|
|
@@: ;found position of '.'
|
|
|
|
dec edi
|
|
|
|
cmp byte[edi],'.'
|
|
|
|
je @f
|
|
|
|
cmp edi,[esi+40]
|
|
|
|
ja @b
|
|
|
|
jmp .no_dot
|
|
|
|
@@:
|
|
|
|
inc edi
|
|
|
|
mov esi,[ebp+12] ;file ext
|
|
|
|
;copy file ext in dialog
|
|
|
|
@@:
|
|
|
|
lodsb
|
|
|
|
stosb
|
|
|
|
test eax,eax
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
.no_dot:
|
|
|
|
pop esi edi ecx eax
|
|
|
|
pop ebp
|
|
|
|
ret 8
|
2010-07-01 09:35:54 +02:00
|
|
|
}
|
|
|
|
;*****************************************************************************
|