Subversion Repositories Kolibri OS

Rev

Rev 1509 | Rev 1654 | 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.         mov     eax,od_com_area
  93.         test    eax,eax
  94.         jz      .1
  95.         mov     ebx,od_type
  96.         mov     [eax+2],bx
  97.        
  98.         mov     [eax],word 2    ; folder for open
  99.  
  100.         pusha
  101.         mcall   9,od_procinfo,-1
  102.  
  103.         mov     eax,[ebx+42] ;main window x size
  104.         shr     eax,1
  105.         add     eax,[ebx+34] ; main window x start
  106.         mov     cx,od_x_size
  107.         shr     cx,1
  108.         sub     ax,cx
  109.         test    ax,cx
  110.         test    eax,0x8000
  111.         jz      @f
  112.         xor     eax,eax
  113. @@:
  114.         mov     od_x_start,ax
  115.  
  116.         mov     eax,[ebx+46] ;main window y size
  117.         shr     eax,1
  118.         add     eax,[ebx+38] ; main window y start
  119.         mov     cx,od_y_size
  120.         shr     cx,1
  121.         sub     ax,cx
  122.         test    eax,0x8000
  123.         jz      @f
  124.         xor     eax,eax
  125. @@:
  126.         mov     od_y_start,ax
  127.         popa
  128.  
  129.         mov     ebx,dword od_x_size
  130.         mov     [eax+4],ebx
  131.         mov     ebx,dword od_y_size
  132.         mov     [eax+8],ebx
  133.  
  134.         mov     edi,eax
  135.         add     edi,12
  136.  
  137.         mov     esi,od_opendir_pach
  138.         xor     eax,eax
  139.         mov     al,[esi]
  140.         test    eax,eax
  141.         jnz     @f
  142.         mov     esi,od_dir_default_pach ;communication_area_default_pach
  143. @@:
  144.         call    .copy
  145. ;----------------------------------------------
  146. ; copy file name to shared area
  147.         cmp     od_type,dword 2
  148.         je      .4
  149.         mov     edi,od_com_area
  150.         add     edi,3840 ;4096-256
  151.  
  152.         mov     esi,od_filename_area
  153.         test    esi,esi
  154.         jnz     @f
  155.         xor     eax,eax
  156.         mov     [edi],eax
  157.         jmp     .4
  158. @@:
  159.         call    .copy
  160. .4:
  161. ;----------------------------------------------
  162.         cmp     od_type,dword 2
  163.         je      @f
  164.         call    .get_filter_data
  165. @@:
  166. ;----------------------------------------------
  167.         mov     eax,od_com_area_name
  168.         mov     [start_open_dialog.parameter],eax
  169.  
  170.         mov     eax,od_start_path
  171.         mov     [start_open_dialog.name],eax
  172.  
  173.         mcall   70,dword start_open_dialog
  174.         shr     eax,31
  175.         test    eax,eax
  176.         jnz     .1
  177. .still:
  178.         mcall   23,50
  179.         cmp     eax,1
  180.         jne     @f
  181.         pusha
  182.         call    od_draw_window
  183.         popa
  184. @@:
  185.         mov     eax,od_com_area
  186.         movzx   ebx,word [eax]
  187.         test    ebx,ebx
  188.         jz      .still
  189.         cmp     ebx,3
  190.         je      .2
  191.         cmp     ebx,1
  192.         jne     .still
  193.  
  194.         mov     esi,od_com_area
  195.         add     esi,12
  196.         mov     edi,od_openfile_pach
  197.         call    .copy
  198.         mov     od_status,1
  199.  
  200.         mov     esi,od_openfile_pach
  201.         mov     edi,od_opendir_pach
  202.         call    .copy_dir_path
  203. ;----------------------------------------------
  204. ; copy file name from shared area
  205.         cmp     od_type,dword 2
  206.         je      @f
  207.         mov     esi,od_com_area
  208.         add     esi,3840
  209.         mov     edi,od_filename_area
  210.         test    edi,edi
  211.         jz      @f
  212.         call    .copy
  213. @@:
  214. ;----------------------------------------------
  215.         jmp     .3
  216. .2:
  217.         mov     od_status,0
  218.         jmp     .3
  219. .1:
  220.         mov     od_status,2
  221. .3:
  222.         mov     eax,od_com_area
  223.         mov     ebx,[eax+4]
  224.         mov     od_x_size,ebx
  225.         mov     ebx,[eax+8]
  226.         mov     od_y_size, ebx
  227. OpenDialog_exit
  228. ;----------------------------------------------
  229. .get_filter_data:
  230.         mov     edi,od_com_area
  231.         test    edi,edi
  232.         jnz     @f
  233. ;       add     esp,4
  234. ;       jmp     still
  235.         ret
  236. @@:
  237.         add     edi,4100
  238.         mov     esi,od_filter_area
  239.         mov     ecx,[esi]
  240.         test    ecx,ecx
  241.         jnz     @f
  242.         mov     edi,od_com_area
  243.         mov     [edi+4096],dword 0
  244.         ret
  245. @@:
  246.         inc     ecx
  247.         cld
  248.         rep     movsb
  249.         mov     edi,od_com_area
  250.         mov     [edi+4096],dword 1
  251.         ret
  252. ;----------------------------------------------
  253. .copy:
  254.         xor     eax,eax
  255.         cld
  256. @@:
  257.         lodsb
  258.         stosb
  259.         test    eax,eax
  260.         jnz     @b
  261.         ret
  262. ;----------------------------------------------
  263. .copy_dir_path:
  264.         xor     eax,eax
  265.         cmp     [esi],al
  266.         jne     @f
  267.         mov     [edi],al
  268.         mov     [ebx],al
  269.         xor     ebx,ebx
  270.         inc     ebx
  271.         ret
  272. @@:
  273.         cld
  274.         lodsb
  275.         stosb
  276.         test    eax,eax
  277.         jnz     @b
  278.         cmp     od_type,dword 2
  279.         jne     @f
  280.         ret
  281. @@:
  282.         mov     esi,edi
  283.         dec     esi
  284. @@:
  285.         std
  286.         lodsb
  287.         cmp     al,'/'
  288.         jnz     @b
  289.        
  290.         mov     [esi+1],byte 0
  291.         cld
  292.         ret
  293. ;----------------------------------------------
  294. align   4
  295. start_open_dialog:
  296. .subfunction    dd 7
  297. .flags          dd 0
  298. .parameter      dd 0    ;od_com_area_name
  299. .reserved1      dd 0
  300. .reserved2      dd 0
  301.                 db 0
  302. .name:          dd 0    ;od_start_path
  303. }
  304. ;*****************************************************************************