Subversion Repositories Kolibri OS

Rev

Rev 1658 | Rev 3424 | 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-2013, 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. ;Some documentation for memory
  30. ;
  31. ;area name db 'FFFFFFFF_open_dialog',0 ; FFFFFFFF = PID
  32. ;
  33. ; communication area data
  34. ; flag  ; +0
  35. ; dw 0   ; 0 - empty, 1 - file for open, 2 -folder for open,
  36. ;          3 - cancel, 4 - path=name of area 6822.
  37. ;
  38. ; type of dialog:  0-Open, 1-Save, 2-Dir
  39. ; dw 0 ; +2
  40. ;
  41. ; window X size ; +4
  42. ; dw 0
  43. ;
  44. ; window X position ; +6
  45. ; dw 0
  46. ;
  47. ; window y size ; +8
  48. ; dw 0
  49. ;
  50. ; window Y position ; +10
  51. ; dw 0
  52. ;
  53. ; OpenDialog WINDOW SLOT ; +12
  54. ; dd 0
  55. ;
  56. ; file_path ; +16
  57. ; rb 3824 ; path to file
  58. ;
  59. ; file name ; +3840
  60. ; rb 256
  61. ;
  62. ; filtration flag ; +4096
  63. ; dd 0 ; flag 0 - no filtration,  1 - filtering
  64. ;
  65. ; area for storage of filtering values ; +4100
  66. ; rb 4092
  67. ;---------------------------------------------------------------------
  68. ;*****************************************************************************
  69. macro   OpenDialog_exit
  70. {
  71. popa
  72. ret 4
  73. }
  74. ;*****************************************************************************
  75. macro   use_OpenDialog
  76. {
  77. OpenDialog:
  78. od_type                 equ dword [ebp] ; 0-Open, 1-Save, 2-Dir
  79. od_procinfo             equ dword [ebp+4] ; Process info area for function 9
  80. od_com_area_name        equ dword [ebp+8] ; Name for shared area
  81. od_com_area             equ dword [ebp+12] ; Adress of shared area
  82. od_opendir_pach         equ dword [ebp+16] ; Temp area the directory for show
  83. od_dir_default_pach     equ dword [ebp+20] ; Default path of directory,
  84. od_start_path           equ dword [ebp+24] ; Location path to OpenDialog
  85. od_draw_window          equ dword [ebp+28] ; Adress of procedure - draw_window
  86. od_status               equ dword [ebp+32] ; 0-Cancel, 1-Get path OK, 2-Use alternatives
  87. od_openfile_pach        equ dword [ebp+36] ; Getting path to file
  88. od_filename_area        equ dword [ebp+40] ; Adress of file name area
  89. od_filter_area          equ dword [ebp+44] ; Adress of filter area
  90. od_x_size               equ [ebp+48] ; Window X size
  91. od_x_start              equ [ebp+50] ; Window X position
  92. od_y_size               equ [ebp+52] ; Window y size
  93. od_y_start              equ [ebp+54] ; Window Y position
  94. ;*****************************************************************************
  95. .init:
  96.         pusha
  97.         mov   ebp,dword [esp+36]
  98.         mcall   9,od_procinfo,-1
  99.         mov     ebx,[ebx+30]
  100.         mov     edi,od_com_area_name
  101.         add     edi,7
  102.         std
  103.         mov     ecx,4
  104. @@:
  105.         mov     al,bl
  106.         and     al,1111b
  107.         add     al,0x30
  108.         stosb
  109.         mov     al,bl
  110.         shr     al,4
  111.         and     al,1111b
  112.         add     al,0x30
  113.         stosb
  114.         shr     ebx,8
  115.         dec     ecx
  116.         jnz     @r
  117.         cld
  118.        
  119.         mcall   68,22,od_com_area_name,8192,0x09
  120.         mov     od_com_area,eax
  121.        
  122.         mov     esi,od_openfile_pach
  123.         mov     edi,od_opendir_pach
  124.         call    .copy_dir_path
  125.        
  126. OpenDialog_exit
  127. ;*****************************************************************************
  128. ;*****************************************************************************
  129. .start:
  130.         pusha
  131.         mov   ebp,dword [esp+36]
  132.        
  133.         mov     eax,od_com_area
  134.         test    eax,eax
  135.         jz      .1
  136.         mov     ebx,od_type
  137.         mov     [eax+2],bx
  138.        
  139.         mov     [eax],word 2    ; folder for open
  140.  
  141.         pusha
  142.         mcall   9,od_procinfo,-1
  143.  
  144.         mov     eax,[ebx+42] ;main window x size
  145.         shr     eax,1
  146.         add     eax,[ebx+34] ; main window x start
  147.         mov     cx,od_x_size
  148.         shr     cx,1
  149.         sub     ax,cx
  150.         test    ax,cx
  151.         test    eax,0x8000
  152.         jz      @f
  153.         xor     eax,eax
  154. @@:
  155.         mov     od_x_start,ax
  156.  
  157.         mov     eax,[ebx+46] ;main window y size
  158.         shr     eax,1
  159.         add     eax,[ebx+38] ; main window y start
  160.         mov     cx,od_y_size
  161.         shr     cx,1
  162.         sub     ax,cx
  163.         test    eax,0x8000
  164.         jz      @f
  165.         xor     eax,eax
  166. @@:
  167.         mov     od_y_start,ax
  168.         popa
  169.  
  170.         mov     ebx,dword od_x_size
  171.         mov     [eax+4],ebx
  172.         mov     ebx,dword od_y_size
  173.         mov     [eax+8],ebx
  174.  
  175.         mov     edi,eax
  176.         add     edi,16  ;12
  177.  
  178.         mov     esi,od_opendir_pach
  179.         xor     eax,eax
  180.         mov     al,[esi]
  181.         test    eax,eax
  182.         jnz     @f
  183.         mov     esi,od_dir_default_pach ;communication_area_default_pach
  184. @@:
  185.         call    .copy
  186. ;----------------------------------------------
  187. ; copy file name to shared area
  188.         cmp     od_type,dword 2
  189.         je      .4
  190.         mov     edi,od_com_area
  191.         add     edi,3840 ;4096-256
  192.  
  193.         mov     esi,od_filename_area
  194.         test    esi,esi
  195.         jnz     @f
  196.         xor     eax,eax
  197.         mov     [edi],eax
  198.         jmp     .4
  199. @@:
  200.         call    .copy
  201. .4:
  202. ;----------------------------------------------
  203.         cmp     od_type,dword 2
  204.         je      @f
  205.         call    .get_filter_data
  206. @@:
  207. ;----------------------------------------------
  208.         mov     ebx,od_procinfo
  209.         xor     eax,eax
  210.         mov     edi,ebx
  211.         mov     ecx,6
  212.         cld
  213.         rep     stosd
  214.         mov     [ebx],dword 7
  215.         mov     eax,od_com_area_name
  216.         mov     [ebx+8],eax
  217.         mov     eax,od_start_path
  218.         mov     [ebx+21],eax
  219.         mcall   70
  220.  
  221.         shr     eax,31
  222.         test    eax,eax
  223.         jnz     .1
  224. ;----------------------------------------------
  225. .still:
  226. ; The main window of application sometimes
  227. ; is not present the really. For this reason
  228. ; not use func 10 and 23, because event 1
  229. ; is not cleared without call of func 0.
  230. ; In this case is suitable only func 5 and 11!
  231.         mcall   5,10
  232.         mcall   11
  233.         cmp     eax,1
  234.         je      .draw
  235.         cmp     eax,2
  236.         je      .key
  237.         cmp     eax,3
  238.         je      .button
  239.         jmp     .no_draw
  240. .key:
  241.         mcall   2
  242.         jmp     .no_draw
  243. .button:
  244.         mcall   17
  245.         jmp     .no_draw
  246. ;----------------------------------------------
  247. .draw:
  248.         pusha
  249.         call    od_draw_window
  250.         popa
  251. ;----------------------------------------------
  252.         pusha
  253.         call    .prepare_PID
  254.         jz      @f
  255.  
  256.         mov     ecx,eax ; WINDOW SLOT
  257.         mcall   18,7
  258.         cmp     eax,ecx ; compare ACTIVE and WINDOW SLOT
  259.         jne     @f
  260.  
  261.         mov     eax,od_com_area
  262.         mov     ecx,[eax+12]
  263.         test    ecx,ecx
  264.         jz      @f
  265.         mcall   18,3
  266. @@:
  267.         popa
  268. ;----------------------------------------------
  269. .no_draw:
  270.         mov     eax,od_com_area
  271.         movzx   ebx,word [eax]
  272.         test    ebx,ebx
  273.         jz      .still
  274.         cmp     ebx,3
  275.         je      .2
  276.         cmp     ebx,1
  277.         jne     .still
  278.  
  279.         mov     esi,od_com_area
  280.         add     esi,16  ;12
  281.         mov     edi,od_openfile_pach
  282.         call    .copy
  283.         mov     od_status,1
  284.  
  285.         mov     esi,od_openfile_pach
  286.         mov     edi,od_opendir_pach
  287.         call    .copy_dir_path
  288. ;----------------------------------------------
  289. ; copy file name from shared area
  290.         cmp     od_type,dword 2
  291.         je      @f
  292.         mov     esi,od_com_area
  293.         add     esi,3840
  294.         mov     edi,od_filename_area
  295.         test    edi,edi
  296.         jz      @f
  297.         call    .copy
  298. @@:
  299. ;----------------------------------------------
  300.         jmp     .3
  301. .2:
  302.         mov     od_status,0
  303.         jmp     .3
  304. .1:
  305.         mov     od_status,2
  306. .3:
  307.         mov     eax,od_com_area
  308.         mov     ebx,[eax+4]
  309.         mov     od_x_size,ebx
  310.         mov     ebx,[eax+8]
  311.         mov     od_y_size, ebx
  312.  
  313.         call    .prepare_PID
  314.         jz      @f
  315.         mov     ecx,eax ; WINDOW SLOT
  316.         mcall   18,3
  317. @@:
  318. OpenDialog_exit
  319. ;----------------------------------------------
  320. .prepare_PID:
  321.         mcall   9,od_procinfo,-1
  322.         mov     ecx,[ebx+30]    ; PID
  323.         mcall   18,21
  324.         test    eax,eax
  325.         ret
  326. ;----------------------------------------------
  327. .get_filter_data:
  328.         mov     edi,od_com_area
  329.         test    edi,edi
  330.         jnz     @f
  331.         ret
  332. @@:
  333.         add     edi,4100
  334.         mov     esi,od_filter_area
  335.         mov     ecx,[esi]
  336.         test    ecx,ecx
  337.         jnz     @f
  338.         mov     edi,od_com_area
  339.         mov     [edi+4096],dword 0
  340.         ret
  341. @@:
  342.         inc     ecx
  343.         cld
  344.         rep     movsb
  345.         mov     edi,od_com_area
  346.         mov     [edi+4096],dword 1
  347.         ret
  348. ;----------------------------------------------
  349. .copy:
  350.         xor     eax,eax
  351.         cld
  352. @@:
  353.         lodsb
  354.         stosb
  355.         test    eax,eax
  356.         jnz     @b
  357.         ret
  358. ;----------------------------------------------
  359. .copy_dir_path:
  360.         xor     eax,eax
  361.         cmp     [esi],al
  362.         jne     @f
  363.         mov     [edi],al
  364.         mov     [ebx],al
  365.         xor     ebx,ebx
  366.         inc     ebx
  367.         ret
  368. @@:
  369.         cld
  370.         lodsb
  371.         stosb
  372.         test    eax,eax
  373.         jnz     @b
  374.         cmp     od_type,dword 2
  375.         jne     @f
  376.         ret
  377. @@:
  378.         mov     esi,edi
  379.         dec     esi
  380. @@:
  381.         std
  382.         lodsb
  383.         cmp     al,'/'
  384.         jnz     @b
  385.        
  386.         mov     [esi+1],byte 0
  387.         cld
  388.         ret
  389. ;----------------------------------------------
  390. }
  391. ;*****************************************************************************