Subversion Repositories Kolibri OS

Rev

Rev 1654 | Rev 1658 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;*****************************************************************************
  2. ; Macro for use Open Dialog - for Kolibri OS
  3. ; Copyright (c) 2009 2010, Marat Zakiyanov aka Mario79, aka Mario
  4. ; All rights reserved.
  5. ;
  6. ; Redistribution and use in source and binary forms, with or without
  7. ; modification, are permitted provided that the following conditions are met:
  8. ;        * Redistributions of source code must retain the above copyright
  9. ;          notice, this list of conditions and the following disclaimer.
  10. ;        * Redistributions in binary form must reproduce the above copyright
  11. ;          notice, this list of conditions and the following disclaimer in the
  12. ;          documentation and/or other materials provided with the distribution.
  13. ;        * Neither the name of the <organization> nor the
  14. ;          names of its contributors may be used to endorse or promote products
  15. ;          derived from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
  18. ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. ; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  21. ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. ;*****************************************************************************
  28. ;*****************************************************************************
  29. macro   OpenDialog_exit
  30. {
  31. popa
  32. ret 4
  33. }
  34. ;*****************************************************************************
  35. macro   use_OpenDialog
  36. {
  37. OpenDialog:
  38. od_type                 equ dword [ebp] ; 0-Open, 1-Save, 2-Dir
  39. od_procinfo             equ dword [ebp+4] ; Process info area for function 9
  40. od_com_area_name        equ dword [ebp+8] ; Name for shared area
  41. od_com_area             equ dword [ebp+12] ; Adress of shared area
  42. od_opendir_pach         equ dword [ebp+16] ; Temp area the directory for show
  43. od_dir_default_pach     equ dword [ebp+20] ; Default path of directory,
  44. od_start_path           equ dword [ebp+24] ; Location path to OpenDialog
  45. od_draw_window          equ dword [ebp+28] ; Adress of procedure - draw_window
  46. od_status               equ dword [ebp+32] ; 0-Cancel, 1-Get path OK, 2-Use alternatives
  47. od_openfile_pach        equ dword [ebp+36] ; Getting path to file
  48. od_filename_area        equ dword [ebp+40] ; Adress of file name area
  49. od_filter_area          equ dword [ebp+44] ; Adress of filter area
  50. od_x_size               equ [ebp+48] ; Window X size
  51. od_x_start              equ [ebp+50] ; Window X position
  52. od_y_size               equ [ebp+52] ; Window y size
  53. od_y_start              equ [ebp+54] ; Window Y position
  54. ;*****************************************************************************
  55. .init:
  56.         pusha
  57.         mov   ebp,dword [esp+36]
  58.         mcall   9,od_procinfo,-1
  59.         mov     ebx,[ebx+30]
  60.         mov     edi,od_com_area_name
  61.         add     edi,7
  62.         std
  63.         mov     ecx,4
  64. @@:
  65.         mov     al,bl
  66.         and     al,1111b
  67.         add     al,0x30
  68.         stosb
  69.         mov     al,bl
  70.         shr     al,4
  71.         and     al,1111b
  72.         add     al,0x30
  73.         stosb
  74.         shr     ebx,8
  75.         dec     ecx
  76.         jnz     @r
  77.         cld
  78.        
  79.         mcall   68,22,od_com_area_name,8192,0x09
  80.         mov     od_com_area,eax
  81.        
  82.         mov     esi,od_openfile_pach
  83.         mov     edi,od_opendir_pach
  84.         call    .copy_dir_path
  85.        
  86. OpenDialog_exit
  87. ;*****************************************************************************
  88. ;*****************************************************************************
  89. .start:
  90.         pusha
  91.         mov   ebp,dword [esp+36]
  92.         mcall   40,1b
  93.         push    eax     ; save events mask
  94.        
  95.        
  96.         mov     eax,od_com_area
  97.         test    eax,eax
  98.         jz      .1
  99.         mov     ebx,od_type
  100.         mov     [eax+2],bx
  101.        
  102.         mov     [eax],word 2    ; folder for open
  103.  
  104.         pusha
  105.         mcall   9,od_procinfo,-1
  106.  
  107.         mov     eax,[ebx+42] ;main window x size
  108.         shr     eax,1
  109.         add     eax,[ebx+34] ; main window x start
  110.         mov     cx,od_x_size
  111.         shr     cx,1
  112.         sub     ax,cx
  113.         test    ax,cx
  114.         test    eax,0x8000
  115.         jz      @f
  116.         xor     eax,eax
  117. @@:
  118.         mov     od_x_start,ax
  119.  
  120.         mov     eax,[ebx+46] ;main window y size
  121.         shr     eax,1
  122.         add     eax,[ebx+38] ; main window y start
  123.         mov     cx,od_y_size
  124.         shr     cx,1
  125.         sub     ax,cx
  126.         test    eax,0x8000
  127.         jz      @f
  128.         xor     eax,eax
  129. @@:
  130.         mov     od_y_start,ax
  131.         popa
  132.  
  133.         mov     ebx,dword od_x_size
  134.         mov     [eax+4],ebx
  135.         mov     ebx,dword od_y_size
  136.         mov     [eax+8],ebx
  137.  
  138.         mov     edi,eax
  139.         add     edi,16  ;12
  140.  
  141.         mov     esi,od_opendir_pach
  142.         xor     eax,eax
  143.         mov     al,[esi]
  144.         test    eax,eax
  145.         jnz     @f
  146.         mov     esi,od_dir_default_pach ;communication_area_default_pach
  147. @@:
  148.         call    .copy
  149. ;----------------------------------------------
  150. ; copy file name to shared area
  151.         cmp     od_type,dword 2
  152.         je      .4
  153.         mov     edi,od_com_area
  154.         add     edi,3840 ;4096-256
  155.  
  156.         mov     esi,od_filename_area
  157.         test    esi,esi
  158.         jnz     @f
  159.         xor     eax,eax
  160.         mov     [edi],eax
  161.         jmp     .4
  162. @@:
  163.         call    .copy
  164. .4:
  165. ;----------------------------------------------
  166.         cmp     od_type,dword 2
  167.         je      @f
  168.         call    .get_filter_data
  169. @@:
  170. ;----------------------------------------------
  171.         mov     eax,od_com_area_name
  172.         mov     [start_open_dialog.parameter],eax
  173.  
  174.         mov     eax,od_start_path
  175.         mov     [start_open_dialog.name],eax
  176.  
  177.         mcall   70,dword start_open_dialog
  178.         shr     eax,31
  179.         test    eax,eax
  180.         jnz     .1
  181. ;----------------------------------------------
  182. .still:
  183. ; The main window of application sometimes
  184. ; is not present the really. For this reason
  185. ; not use func 10 and 23, because event 1
  186. ; is not cleared without call of func 0.
  187. ; In this case is suitable only func 5 and 11!
  188.         mcall   5,10
  189.         mcall   11
  190.         cmp     eax,1
  191.         jne     .no_draw
  192. ;----------------------------------------------
  193. .draw:
  194.         pusha
  195.         call    od_draw_window
  196.         popa
  197. ;----------------------------------------------
  198.         pusha
  199.         mcall   9,od_procinfo,-1
  200.         mov     ecx,[ebx+30]    ; PID
  201.         mcall   18,21
  202.         test    eax,eax
  203.         jz      @f
  204.  
  205.         mov     ecx,eax ; WINDOW SLOT
  206.         mcall   18,7
  207.         cmp     eax,ecx ; compare ACTIVE and WINDOW SLOT
  208.         jne     @f
  209.  
  210.         mov     eax,od_com_area
  211.         mov     ecx,[eax+12]
  212.         test    ecx,ecx
  213.         jz      @f
  214.         mcall   18,3
  215. @@:
  216.         popa
  217. ;----------------------------------------------
  218. .no_draw:
  219.         mov     eax,od_com_area
  220.         movzx   ebx,word [eax]
  221.         test    ebx,ebx
  222.         jz      .still
  223.         cmp     ebx,3
  224.         je      .2
  225.         cmp     ebx,1
  226.         jne     .still
  227.  
  228.         mov     esi,od_com_area
  229.         add     esi,16  ;12
  230.         mov     edi,od_openfile_pach
  231.         call    .copy
  232.         mov     od_status,1
  233.  
  234.         mov     esi,od_openfile_pach
  235.         mov     edi,od_opendir_pach
  236.         call    .copy_dir_path
  237. ;----------------------------------------------
  238. ; copy file name from shared area
  239.         cmp     od_type,dword 2
  240.         je      @f
  241.         mov     esi,od_com_area
  242.         add     esi,3840
  243.         mov     edi,od_filename_area
  244.         test    edi,edi
  245.         jz      @f
  246.         call    .copy
  247. @@:
  248. ;----------------------------------------------
  249.         jmp     .3
  250. .2:
  251.         mov     od_status,0
  252.         jmp     .3
  253. .1:
  254.         mov     od_status,2
  255. .3:
  256.         mov     eax,od_com_area
  257.         mov     ebx,[eax+4]
  258.         mov     od_x_size,ebx
  259.         mov     ebx,[eax+8]
  260.         mov     od_y_size, ebx
  261.        
  262.         pop     ebx     ; restore events mask
  263.         mcall   40
  264. OpenDialog_exit
  265. ;----------------------------------------------
  266. .get_filter_data:
  267.         mov     edi,od_com_area
  268.         test    edi,edi
  269.         jnz     @f
  270. ;       add     esp,4
  271. ;       jmp     still
  272.         ret
  273. @@:
  274.         add     edi,4100
  275.         mov     esi,od_filter_area
  276.         mov     ecx,[esi]
  277.         test    ecx,ecx
  278.         jnz     @f
  279.         mov     edi,od_com_area
  280.         mov     [edi+4096],dword 0
  281.         ret
  282. @@:
  283.         inc     ecx
  284.         cld
  285.         rep     movsb
  286.         mov     edi,od_com_area
  287.         mov     [edi+4096],dword 1
  288.         ret
  289. ;----------------------------------------------
  290. .copy:
  291.         xor     eax,eax
  292.         cld
  293. @@:
  294.         lodsb
  295.         stosb
  296.         test    eax,eax
  297.         jnz     @b
  298.         ret
  299. ;----------------------------------------------
  300. .copy_dir_path:
  301.         xor     eax,eax
  302.         cmp     [esi],al
  303.         jne     @f
  304.         mov     [edi],al
  305.         mov     [ebx],al
  306.         xor     ebx,ebx
  307.         inc     ebx
  308.         ret
  309. @@:
  310.         cld
  311.         lodsb
  312.         stosb
  313.         test    eax,eax
  314.         jnz     @b
  315.         cmp     od_type,dword 2
  316.         jne     @f
  317.         ret
  318. @@:
  319.         mov     esi,edi
  320.         dec     esi
  321. @@:
  322.         std
  323.         lodsb
  324.         cmp     al,'/'
  325.         jnz     @b
  326.        
  327.         mov     [esi+1],byte 0
  328.         cld
  329.         ret
  330. ;----------------------------------------------
  331. align   4
  332. start_open_dialog:
  333. .subfunction    dd 7
  334. .flags          dd 0
  335. .parameter      dd 0    ;od_com_area_name
  336. .reserved1      dd 0
  337. .reserved2      dd 0
  338.                 db 0
  339. .name:          dd 0    ;od_start_path
  340. }
  341. ;*****************************************************************************