Subversion Repositories Kolibri OS

Rev

Rev 1581 | Rev 1656 | 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. .still:
  182.         mcall   23,50
  183.         cmp     eax,1
  184.         jne     .no_draw
  185.  
  186.         pusha
  187.         call    od_draw_window
  188.         popa
  189.  
  190.         pusha
  191.         mcall   9,od_procinfo,-1
  192.         mov     ecx,[ebx+30]    ; PID
  193.         mcall   18,21
  194.         mov     ecx,eax ; WINDOW SLOT
  195.         mcall   18,7
  196.         cmp     eax,ecx ; compare ACTIVE and WINDOW SLOT
  197.         jne     @f
  198.         mov     eax,od_com_area
  199. ;       xor     ecx,ecx
  200.         mov     ecx,[eax+12]
  201.         test    ecx,ecx
  202.         jz      @f
  203.         mcall   18,3
  204. @@:
  205.         popa
  206.  
  207.        
  208. .no_draw:
  209.         mov     eax,od_com_area
  210.         movzx   ebx,word [eax]
  211.         test    ebx,ebx
  212.         jz      .still
  213.         cmp     ebx,3
  214.         je      .2
  215.         cmp     ebx,1
  216.         jne     .still
  217.  
  218.         mov     esi,od_com_area
  219.         add     esi,16  ;12
  220.         mov     edi,od_openfile_pach
  221.         call    .copy
  222.         mov     od_status,1
  223.  
  224.         mov     esi,od_openfile_pach
  225.         mov     edi,od_opendir_pach
  226.         call    .copy_dir_path
  227. ;----------------------------------------------
  228. ; copy file name from shared area
  229.         cmp     od_type,dword 2
  230.         je      @f
  231.         mov     esi,od_com_area
  232.         add     esi,3840
  233.         mov     edi,od_filename_area
  234.         test    edi,edi
  235.         jz      @f
  236.         call    .copy
  237. @@:
  238. ;----------------------------------------------
  239.         jmp     .3
  240. .2:
  241.         mov     od_status,0
  242.         jmp     .3
  243. .1:
  244.         mov     od_status,2
  245. .3:
  246.         mov     eax,od_com_area
  247.         mov     ebx,[eax+4]
  248.         mov     od_x_size,ebx
  249.         mov     ebx,[eax+8]
  250.         mov     od_y_size, ebx
  251.        
  252.         pop     ebx     ; restore events mask
  253.         mcall   40
  254. OpenDialog_exit
  255. ;----------------------------------------------
  256. .get_filter_data:
  257.         mov     edi,od_com_area
  258.         test    edi,edi
  259.         jnz     @f
  260. ;       add     esp,4
  261. ;       jmp     still
  262.         ret
  263. @@:
  264.         add     edi,4100
  265.         mov     esi,od_filter_area
  266.         mov     ecx,[esi]
  267.         test    ecx,ecx
  268.         jnz     @f
  269.         mov     edi,od_com_area
  270.         mov     [edi+4096],dword 0
  271.         ret
  272. @@:
  273.         inc     ecx
  274.         cld
  275.         rep     movsb
  276.         mov     edi,od_com_area
  277.         mov     [edi+4096],dword 1
  278.         ret
  279. ;----------------------------------------------
  280. .copy:
  281.         xor     eax,eax
  282.         cld
  283. @@:
  284.         lodsb
  285.         stosb
  286.         test    eax,eax
  287.         jnz     @b
  288.         ret
  289. ;----------------------------------------------
  290. .copy_dir_path:
  291.         xor     eax,eax
  292.         cmp     [esi],al
  293.         jne     @f
  294.         mov     [edi],al
  295.         mov     [ebx],al
  296.         xor     ebx,ebx
  297.         inc     ebx
  298.         ret
  299. @@:
  300.         cld
  301.         lodsb
  302.         stosb
  303.         test    eax,eax
  304.         jnz     @b
  305.         cmp     od_type,dword 2
  306.         jne     @f
  307.         ret
  308. @@:
  309.         mov     esi,edi
  310.         dec     esi
  311. @@:
  312.         std
  313.         lodsb
  314.         cmp     al,'/'
  315.         jnz     @b
  316.        
  317.         mov     [esi+1],byte 0
  318.         cld
  319.         ret
  320. ;----------------------------------------------
  321. align   4
  322. start_open_dialog:
  323. .subfunction    dd 7
  324. .flags          dd 0
  325. .parameter      dd 0    ;od_com_area_name
  326. .reserved1      dd 0
  327. .reserved2      dd 0
  328.                 db 0
  329. .name:          dd 0    ;od_start_path
  330. }
  331. ;*****************************************************************************