Subversion Repositories Kolibri OS

Rev

Rev 1656 | Rev 3418 | 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.        
  93.         mov     eax,od_com_area
  94.         test    eax,eax
  95.         jz      .1
  96.         mov     ebx,od_type
  97.         mov     [eax+2],bx
  98.        
  99.         mov     [eax],word 2    ; folder for open
  100.  
  101.         pusha
  102.         mcall   9,od_procinfo,-1
  103.  
  104.         mov     eax,[ebx+42] ;main window x size
  105.         shr     eax,1
  106.         add     eax,[ebx+34] ; main window x start
  107.         mov     cx,od_x_size
  108.         shr     cx,1
  109.         sub     ax,cx
  110.         test    ax,cx
  111.         test    eax,0x8000
  112.         jz      @f
  113.         xor     eax,eax
  114. @@:
  115.         mov     od_x_start,ax
  116.  
  117.         mov     eax,[ebx+46] ;main window y size
  118.         shr     eax,1
  119.         add     eax,[ebx+38] ; main window y start
  120.         mov     cx,od_y_size
  121.         shr     cx,1
  122.         sub     ax,cx
  123.         test    eax,0x8000
  124.         jz      @f
  125.         xor     eax,eax
  126. @@:
  127.         mov     od_y_start,ax
  128.         popa
  129.  
  130.         mov     ebx,dword od_x_size
  131.         mov     [eax+4],ebx
  132.         mov     ebx,dword od_y_size
  133.         mov     [eax+8],ebx
  134.  
  135.         mov     edi,eax
  136.         add     edi,16  ;12
  137.  
  138.         mov     esi,od_opendir_pach
  139.         xor     eax,eax
  140.         mov     al,[esi]
  141.         test    eax,eax
  142.         jnz     @f
  143.         mov     esi,od_dir_default_pach ;communication_area_default_pach
  144. @@:
  145.         call    .copy
  146. ;----------------------------------------------
  147. ; copy file name to shared area
  148.         cmp     od_type,dword 2
  149.         je      .4
  150.         mov     edi,od_com_area
  151.         add     edi,3840 ;4096-256
  152.  
  153.         mov     esi,od_filename_area
  154.         test    esi,esi
  155.         jnz     @f
  156.         xor     eax,eax
  157.         mov     [edi],eax
  158.         jmp     .4
  159. @@:
  160.         call    .copy
  161. .4:
  162. ;----------------------------------------------
  163.         cmp     od_type,dword 2
  164.         je      @f
  165.         call    .get_filter_data
  166. @@:
  167. ;----------------------------------------------
  168.         mov     ebx,od_procinfo
  169.         xor     eax,eax
  170.         mov     edi,ebx
  171.         mov     ecx,6
  172.         cld
  173.         rep     stosd
  174.         mov     [ebx],dword 7
  175.         mov     eax,od_com_area_name
  176.         mov     [ebx+8],eax
  177.         mov     eax,od_start_path
  178.         mov     [ebx+21],eax
  179.         mcall   70
  180.  
  181.         shr     eax,31
  182.         test    eax,eax
  183.         jnz     .1
  184. ;----------------------------------------------
  185. .still:
  186. ; The main window of application sometimes
  187. ; is not present the really. For this reason
  188. ; not use func 10 and 23, because event 1
  189. ; is not cleared without call of func 0.
  190. ; In this case is suitable only func 5 and 11!
  191.         mcall   5,10
  192.         mcall   11
  193.         cmp     eax,1
  194.         je      .draw
  195.         cmp     eax,2
  196.         je      .key
  197.         cmp     eax,3
  198.         je      .button
  199.         jmp     .no_draw
  200. .key:
  201.         mcall   2
  202.         jmp     .no_draw
  203. .button:
  204.         mcall   17
  205.         jmp     .no_draw
  206. ;----------------------------------------------
  207. .draw:
  208.         pusha
  209.         call    od_draw_window
  210.         popa
  211. ;----------------------------------------------
  212.         pusha
  213.         call    .prepare_PID
  214.         jz      @f
  215.  
  216.         mov     ecx,eax ; WINDOW SLOT
  217.         mcall   18,7
  218.         cmp     eax,ecx ; compare ACTIVE and WINDOW SLOT
  219.         jne     @f
  220.  
  221.         mov     eax,od_com_area
  222.         mov     ecx,[eax+12]
  223.         test    ecx,ecx
  224.         jz      @f
  225.         mcall   18,3
  226. @@:
  227.         popa
  228. ;----------------------------------------------
  229. .no_draw:
  230.         mov     eax,od_com_area
  231.         movzx   ebx,word [eax]
  232.         test    ebx,ebx
  233.         jz      .still
  234.         cmp     ebx,3
  235.         je      .2
  236.         cmp     ebx,1
  237.         jne     .still
  238.  
  239.         mov     esi,od_com_area
  240.         add     esi,16  ;12
  241.         mov     edi,od_openfile_pach
  242.         call    .copy
  243.         mov     od_status,1
  244.  
  245.         mov     esi,od_openfile_pach
  246.         mov     edi,od_opendir_pach
  247.         call    .copy_dir_path
  248. ;----------------------------------------------
  249. ; copy file name from shared area
  250.         cmp     od_type,dword 2
  251.         je      @f
  252.         mov     esi,od_com_area
  253.         add     esi,3840
  254.         mov     edi,od_filename_area
  255.         test    edi,edi
  256.         jz      @f
  257.         call    .copy
  258. @@:
  259. ;----------------------------------------------
  260.         jmp     .3
  261. .2:
  262.         mov     od_status,0
  263.         jmp     .3
  264. .1:
  265.         mov     od_status,2
  266. .3:
  267.         mov     eax,od_com_area
  268.         mov     ebx,[eax+4]
  269.         mov     od_x_size,ebx
  270.         mov     ebx,[eax+8]
  271.         mov     od_y_size, ebx
  272.  
  273.         call    .prepare_PID
  274.         jz      @f
  275.         mov     ecx,eax ; WINDOW SLOT
  276.         mcall   18,3
  277. @@:
  278. OpenDialog_exit
  279. ;----------------------------------------------
  280. .prepare_PID:
  281.         mcall   9,od_procinfo,-1
  282.         mov     ecx,[ebx+30]    ; PID
  283.         mcall   18,21
  284.         test    eax,eax
  285.         ret
  286. ;----------------------------------------------
  287. .get_filter_data:
  288.         mov     edi,od_com_area
  289.         test    edi,edi
  290.         jnz     @f
  291.         ret
  292. @@:
  293.         add     edi,4100
  294.         mov     esi,od_filter_area
  295.         mov     ecx,[esi]
  296.         test    ecx,ecx
  297.         jnz     @f
  298.         mov     edi,od_com_area
  299.         mov     [edi+4096],dword 0
  300.         ret
  301. @@:
  302.         inc     ecx
  303.         cld
  304.         rep     movsb
  305.         mov     edi,od_com_area
  306.         mov     [edi+4096],dword 1
  307.         ret
  308. ;----------------------------------------------
  309. .copy:
  310.         xor     eax,eax
  311.         cld
  312. @@:
  313.         lodsb
  314.         stosb
  315.         test    eax,eax
  316.         jnz     @b
  317.         ret
  318. ;----------------------------------------------
  319. .copy_dir_path:
  320.         xor     eax,eax
  321.         cmp     [esi],al
  322.         jne     @f
  323.         mov     [edi],al
  324.         mov     [ebx],al
  325.         xor     ebx,ebx
  326.         inc     ebx
  327.         ret
  328. @@:
  329.         cld
  330.         lodsb
  331.         stosb
  332.         test    eax,eax
  333.         jnz     @b
  334.         cmp     od_type,dword 2
  335.         jne     @f
  336.         ret
  337. @@:
  338.         mov     esi,edi
  339.         dec     esi
  340. @@:
  341.         std
  342.         lodsb
  343.         cmp     al,'/'
  344.         jnz     @b
  345.        
  346.         mov     [esi+1],byte 0
  347.         cld
  348.         ret
  349. ;----------------------------------------------
  350. }
  351. ;*****************************************************************************