Subversion Repositories Kolibri OS

Rev

Rev 7048 | 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   SF_THREAD_INFO,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   SF_SYS_MISC,SSF_MEM_OPEN,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   SF_THREAD_INFO,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   SF_FILE
  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. ; or 68.1 and 11 for better response.
  232.         mcall   SF_SYS_MISC,SSF_SWITCH_TASK
  233.         mcall   SF_SLEEP,10 ; because OS uses a new scheduler for kernel(SVN r.3534)
  234.         mcall   SF_CHECK_EVENT
  235.         cmp     eax,1
  236.         je      .draw
  237.         cmp     eax,2
  238.         je      .key
  239.         cmp     eax,3
  240.         je      .button
  241.         jmp     .no_draw
  242. .key:
  243.         mcall   SF_GET_KEY
  244.         jmp     .no_draw
  245. .button:
  246.         mcall   SF_GET_BUTTON
  247.         jmp     .no_draw
  248. ;----------------------------------------------
  249. .draw:
  250.         pusha
  251.         call    od_draw_window
  252.         popa
  253. ;----------------------------------------------
  254.         pusha
  255.         call    .prepare_PID
  256.         jz      @f
  257.  
  258.         mov     ecx,eax ; WINDOW SLOT
  259.         mcall   SF_SYSTEM,SSF_GET_ACTIVE_WINDOW
  260.         cmp     eax,ecx ; compare ACTIVE and WINDOW SLOT
  261.         jne     @f
  262.  
  263.         mov     eax,od_com_area
  264.         mov     ecx,[eax+12]
  265.         test    ecx,ecx
  266.         jz      @f
  267.         mcall   SF_SYSTEM,SSF_FOCUS_WINDOW
  268. @@:
  269.         popa
  270. ;----------------------------------------------
  271. .no_draw:
  272.         mov     eax,od_com_area
  273.         movzx   ebx,word [eax]
  274.         test    ebx,ebx
  275.         jz      .still
  276.         cmp     ebx,3
  277.         je      .2
  278.         cmp     ebx,1
  279.         jne     .still
  280.  
  281.         mov     esi,od_com_area
  282.         add     esi,16  ;12
  283.         mov     edi,od_openfile_pach
  284.         call    .copy
  285.         mov     od_status,1
  286.  
  287.         mov     esi,od_openfile_pach
  288.         mov     edi,od_opendir_pach
  289.         call    .copy_dir_path
  290. ;----------------------------------------------
  291. ; copy file name from shared area
  292.         cmp     od_type,dword 2
  293.         je      @f
  294.         mov     esi,od_com_area
  295.         add     esi,3840
  296.         mov     edi,od_filename_area
  297.         test    edi,edi
  298.         jz      @f
  299.         call    .copy
  300. @@:
  301. ;----------------------------------------------
  302.         jmp     .3
  303. .2:
  304.         mov     od_status,0
  305.         jmp     .3
  306. .1:
  307.         mov     od_status,2
  308. .3:
  309.         mov     eax,od_com_area
  310.         mov     ebx,[eax+4]
  311.         mov     od_x_size,ebx
  312.         mov     ebx,[eax+8]
  313.         mov     od_y_size, ebx
  314.  
  315.         call    .prepare_PID
  316.         jz      @f
  317.         mov     ecx,eax ; WINDOW SLOT
  318.         mcall   SF_SYSTEM,SSF_FOCUS_WINDOW
  319. @@:
  320. OpenDialog_exit
  321. ;----------------------------------------------
  322. .prepare_PID:
  323.         mcall   SF_THREAD_INFO,od_procinfo,-1
  324.         mov     ecx,[ebx+30]    ; PID
  325.         mcall   SF_SYSTEM,SSF_GET_THREAD_SLOT
  326.         test    eax,eax
  327.         ret
  328. ;----------------------------------------------
  329. .get_filter_data:
  330.         mov     edi,od_com_area
  331.         test    edi,edi
  332.         jnz     @f
  333.         ret
  334. @@:
  335.         add     edi,4100
  336.         mov     esi,od_filter_area
  337.         mov     ecx,[esi]
  338.         test    ecx,ecx
  339.         jnz     @f
  340.         mov     edi,od_com_area
  341.         mov     [edi+4096],dword 0
  342.         ret
  343. @@:
  344.         cmp     ecx,4091 ;max filter len = 8192-4100-1
  345.         jle     @f
  346.         ;todo ... error message: corrypt filter
  347.         mov     edi,od_com_area
  348.         mov     [edi+4096],dword 0
  349.         ret
  350. @@:
  351.         inc     ecx
  352.         cld
  353.         rep     movsb
  354.         mov     edi,od_com_area
  355.         mov     [edi+4096],dword 1
  356.         ret
  357. ;----------------------------------------------
  358. .copy:
  359.         xor     eax,eax
  360.         cld
  361. @@:
  362.         lodsb
  363.         stosb
  364.         test    eax,eax
  365.         jnz     @b
  366.         ret
  367. ;----------------------------------------------
  368. .copy_dir_path:
  369.         xor     eax,eax
  370.         cmp     [esi],al
  371.         jne     @f
  372.         mov     [edi],al
  373.         mov     [ebx],al
  374.         xor     ebx,ebx
  375.         inc     ebx
  376.         ret
  377. @@:
  378.         cld
  379.         lodsb
  380.         stosb
  381.         test    eax,eax
  382.         jnz     @b
  383.         cmp     od_type,dword 2
  384.         jne     @f
  385.         ret
  386. @@:
  387.         mov     esi,edi
  388.         dec     esi
  389. @@:
  390.         std
  391.         lodsb
  392.         cmp     al,'/'
  393.         jnz     @b
  394.        
  395.         mov     [esi+1],byte 0
  396.         cld
  397.         ret
  398. ;----------------------------------------------
  399. align 4
  400. .set_file_name:
  401.         push ebp
  402.         mov ebp,esp
  403.         push eax ecx edi esi
  404.         mov edi,[ebp+8] ;open dlg struct
  405.         mov edi,[edi+40] ;+40 - filename_area
  406.         mov esi,[ebp+12] ;file name
  407.         mov ecx,256
  408.         ;copy file name in dialog
  409.         @@:
  410.                 lodsb
  411.                 stosb
  412.                 test eax,eax
  413.                 loop @b
  414.         pop esi edi ecx eax
  415.         pop ebp
  416.         ret 8
  417. ;----------------------------------------------
  418. align 4
  419. .set_file_ext:
  420.         push ebp
  421.         mov ebp,esp
  422.         push eax ecx edi esi
  423.         mov esi,[ebp+8] ;open dlg struct
  424.  
  425.         xor eax,eax
  426.         mov ecx,256
  427.         mov edi,[esi+40] ;+40 - filename_area
  428.         repne scasb
  429.         @@: ;found position of '.'
  430.                 dec edi
  431.                 cmp byte[edi],'.'
  432.                 je @f
  433.                 cmp edi,[esi+40]
  434.                 ja @b
  435.                 jmp .no_dot
  436.         @@:
  437.         inc edi
  438.         mov esi,[ebp+12] ;file ext
  439.         ;copy file ext in dialog
  440.         @@:
  441.                 lodsb
  442.                 stosb
  443.                 test eax,eax
  444.                 jnz @b
  445.        
  446.         .no_dot:
  447.         pop esi edi ecx eax
  448.         pop ebp
  449.         ret 8
  450. }
  451. ;*****************************************************************************