Subversion Repositories Kolibri OS

Rev

Rev 180 | Rev 283 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; int __stdcall GenericBox(DLGTEMPLATE* dlg, void* DlgProc);
  2. ;       int __stdcall DlgProc(DLGTEMPLATE* dlg, int msg, int param1, int param2);
  3.  
  4. virtual at 0
  5. dlgtemplate:
  6. .flags          dd      ?
  7. .x              dd      ?
  8. .y              dd      ?
  9. .width          dd      ?
  10. .height         dd      ?
  11. .border_size_x  dd      ?
  12. .border_size_y  dd      ?
  13. .title          dd      ?
  14. .main_color     db      ?
  15. .border_color   db      ?
  16. .header_color   db      ?
  17.                 db      ?       ; align
  18. .size = $
  19. end virtual
  20.  
  21. GenericBox:
  22.         pushad
  23.         mov     ebx, [esp+20h+4]
  24. ; center window if required
  25.         cmp     [ebx+dlgtemplate.x], -1
  26.         jnz     @f
  27.         mov     eax, [cur_width]
  28.         sub     eax, [ebx+dlgtemplate.width]
  29.         shr     eax, 1
  30.         mov     [ebx+dlgtemplate.x], eax
  31. @@:
  32.         cmp     [ebx+dlgtemplate.y], -1
  33.         jnz     @f
  34.         mov     eax, [cur_height]
  35.         sub     eax, [ebx+dlgtemplate.height]
  36.         shr     eax, 1
  37.         mov     [ebx+dlgtemplate.y], eax
  38. @@:
  39. ; some checks
  40.         mov     eax, [ebx+dlgtemplate.x]
  41.         cmp     eax, 1
  42.         jl      .sizeerr
  43.         add     eax, [ebx+dlgtemplate.width]
  44.         cmp     eax, [cur_width]
  45.         jge     .sizeerr
  46.         mov     eax, [ebx+dlgtemplate.y]
  47.         cmp     eax, 1
  48.         jl      .sizeerr
  49.         add     eax, [ebx+dlgtemplate.height]
  50.         cmp     eax, [cur_height]
  51.         jge     .sizeerr
  52.         cmp     [ebx+dlgtemplate.border_size_x], 1
  53.         jl      .sizeerr
  54.         cmp     [ebx+dlgtemplate.border_size_y], 1
  55.         jge     .sizeok
  56. .sizeerr:
  57.         popad
  58.         or      eax, -1
  59.         ret     8
  60. .sizeok:
  61. ; allocate memory for data under dialog
  62.         mov     eax, [ebx+dlgtemplate.width]
  63.         add     eax, [ebx+dlgtemplate.border_size_x]
  64.         add     eax, [ebx+dlgtemplate.border_size_x]
  65.         inc     eax
  66.         inc     eax
  67.         mov     edx, [ebx+dlgtemplate.height]
  68.         add     edx, [ebx+dlgtemplate.border_size_y]
  69.         add     edx, [ebx+dlgtemplate.border_size_y]
  70.         inc     edx
  71.         mul     edx
  72.         add     eax, eax
  73.         call    mf_alloc
  74.         test    eax, eax
  75.         jnz     @f
  76. ; TODO: add error message
  77.         popad
  78.         or      eax, -1
  79.         ret     8
  80. @@:
  81.         mov     ebp, eax
  82. ; save data
  83.         mov     eax, [ebx+dlgtemplate.y]
  84.         add     eax, [ebx+dlgtemplate.height]
  85.         add     eax, [ebx+dlgtemplate.border_size_y]
  86.         inc     eax
  87.         push    eax
  88.         mov     eax, [ebx+dlgtemplate.x]
  89.         add     eax, [ebx+dlgtemplate.width]
  90.         add     eax, [ebx+dlgtemplate.border_size_x]
  91.         inc     eax
  92.         inc     eax
  93.         push    eax
  94.         mov     eax, [ebx+dlgtemplate.y]
  95.         sub     eax, [ebx+dlgtemplate.border_size_y]
  96.         push    eax
  97.         mov     eax, [ebx+dlgtemplate.x]
  98.         sub     eax, [ebx+dlgtemplate.border_size_x]
  99.         push    eax
  100.         call    save_console_data
  101. ; draw shadow
  102.         mov     eax, [ebx+dlgtemplate.x]
  103.         sub     eax, [ebx+dlgtemplate.border_size_x]
  104.         ja      @f
  105.         xor     eax, eax
  106. @@:
  107.         push    eax     ; save real window left
  108.         inc     eax
  109.         inc     eax
  110.         mov     edx, [ebx+dlgtemplate.y]
  111.         sub     edx, [ebx+dlgtemplate.border_size_y]
  112.         ja      @f
  113.         xor     edx, edx
  114. @@:
  115.         push    edx     ; save real window top
  116.         inc     edx
  117.         call    get_console_ptr
  118.         mov     ecx, [ebx+dlgtemplate.y]
  119.         add     ecx, [ebx+dlgtemplate.height]
  120.         add     ecx, [ebx+dlgtemplate.border_size_y]
  121.         inc     ecx
  122.         cmp     ecx, [cur_height]
  123.         jb      @f
  124.         mov     ecx, [cur_height]
  125. @@:
  126.         sub     ecx, edx
  127.         mov     edx, ecx
  128.         mov     ecx, [ebx+dlgtemplate.x]
  129.         add     ecx, [ebx+dlgtemplate.width]
  130.         add     ecx, [ebx+dlgtemplate.border_size_x]
  131.         inc     ecx
  132.         inc     ecx
  133.         cmp     ecx, [cur_width]
  134.         jb      @f
  135.         mov     ecx, [cur_width]
  136. @@:
  137.         sub     ecx, eax
  138.         mov     eax, ecx
  139. .shadow_loop:
  140.         mov     ecx, eax
  141.         push    edi
  142. .sl1:
  143.         inc     edi
  144.         test    byte [edi], 0x0F
  145.         jnz     @f
  146.         or      byte [edi], 8
  147. @@:
  148.         and     byte [edi], 0x0F
  149.         inc     edi
  150.         loop    .sl1
  151.         pop     edi
  152.         add     edi, [cur_width]
  153.         add     edi, [cur_width]
  154.         dec     edx
  155.         jnz     .shadow_loop
  156. ; draw area background
  157.         pop     edx
  158.         pop     eax
  159.         call    get_console_ptr
  160.         mov     ecx, [ebx+dlgtemplate.x]
  161.         add     ecx, [ebx+dlgtemplate.width]
  162.         add     ecx, [ebx+dlgtemplate.border_size_x]
  163.         cmp     ecx, [cur_width]
  164.         jb      @f
  165.         mov     ecx, [cur_width]
  166. @@:
  167.         sub     ecx, eax
  168.         mov     esi, ecx
  169.         mov     ecx, [ebx+dlgtemplate.y]
  170.         add     ecx, [ebx+dlgtemplate.height]
  171.         add     ecx, [ebx+dlgtemplate.border_size_y]
  172.         cmp     ecx, [cur_height]
  173.         jb      @f
  174.         mov     ecx, [cur_height]
  175. @@:
  176.         sub     ecx, edx
  177.         mov     edx, ecx
  178.         mov     al, ' '
  179.         mov     ah, [ebx+dlgtemplate.border_color]
  180. .1:
  181.         mov     ecx, esi
  182.         push    edi
  183.         rep     stosw
  184.         pop     edi
  185.         add     edi, [cur_width]
  186.         add     edi, [cur_width]
  187.         dec     edx
  188.         jnz     .1
  189. ; draw border
  190.         mov     eax, [ebx+dlgtemplate.x]
  191.         dec     eax
  192.         mov     edx, [ebx+dlgtemplate.y]
  193.         dec     edx
  194.         call    get_console_ptr
  195.         mov     edx, [ebx+dlgtemplate.height]
  196.         inc     edx
  197.         inc     edx
  198.         mov     ah, [ebx+dlgtemplate.border_color]
  199.         push    ebx
  200.         mov     ebx, [ebx+dlgtemplate.width]
  201.         inc     ebx
  202.         inc     ebx
  203.         call    draw_border
  204.         pop     ebx
  205. ; draw header
  206.         mov     esi, [ebx+dlgtemplate.title]
  207.         test    esi, esi
  208.         jz      .noheader
  209.         cmp     byte [esi], 0
  210.         jz      .noheader
  211.         push    esi
  212. @@:     lodsb
  213.         test    al, al
  214.         jnz     @b
  215.         mov     eax, esi
  216.         pop     esi
  217.         sub     eax, esi
  218.         inc     eax     ; eax = äëèíà çàãîëîâêà + 2
  219.         mov     ecx, [ebx+dlgtemplate.width]
  220.         cmp     eax, ecx
  221.         jbe     .fullhea
  222.         sub     ecx, 5
  223.         jb      .noheader
  224.         xor     edx, edx
  225.         jmp     .drawhea
  226. .fullhea:
  227.         mov     edx, ecx
  228.         sub     edx, eax
  229.         shr     edx, 1
  230. .drawhea:
  231.         mov     eax, [ebx+dlgtemplate.x]
  232.         add     eax, edx
  233.         mov     edx, [ebx+dlgtemplate.y]
  234.         dec     edx
  235.         call    get_console_ptr
  236.         mov     ah, [ebx+dlgtemplate.header_color]
  237.         mov     al, ' '
  238.         stosw
  239.         dec     ecx
  240. .2:
  241.         jecxz   .3
  242.         lodsb
  243.         test    al, al
  244.         jz      .4
  245.         stosw
  246.         jmp     .2
  247. .3:
  248.         mov     al, '.'
  249.         stosw
  250.         stosw
  251.         stosw
  252. .4:
  253.         mov     al, ' '
  254.         stosw
  255. .noheader:
  256. ; draw window background
  257.         mov     eax, [ebx+dlgtemplate.x]
  258.         mov     edx, [ebx+dlgtemplate.y]
  259.         call    get_console_ptr
  260.         mov     ah, [ebx+dlgtemplate.main_color]
  261.         mov     al, ' '
  262.         mov     edx, [ebx+dlgtemplate.height]
  263. @@:
  264.         mov     ecx, [ebx+dlgtemplate.width]
  265.         push    edi
  266.         rep     stosw
  267.         pop     edi
  268.         add     edi, [cur_width]
  269.         add     edi, [cur_width]
  270.         dec     edx
  271.         jnz     @b
  272. ; send redraw message
  273.         mov     eax, [esp+20h+8]
  274.         push    ebx ebp
  275.         push    0
  276.         push    0
  277.         push    1
  278.         push    ebx
  279.         call    eax
  280.         call    draw_image
  281.         pop     ebp ebx
  282. ; message loop
  283. .event:
  284.         push    10
  285.         pop     eax
  286.         int     40h
  287.         dec     eax
  288.         jz      .redraw
  289.         dec     eax
  290.         jz      .key
  291.         or      eax, -1
  292.         int     40h
  293. .redraw:
  294.         push    ebx ebp
  295.         call    draw_window
  296.         pop     ebp ebx
  297.         jmp     .event
  298. .key:
  299.         mov     al, 2
  300.         int     40h
  301.         shr     eax, 8
  302.         cmp     al, 0xE0
  303.         jnz     @f
  304.         mov     [bWasE0], 1
  305.         jmp     .event
  306. @@:
  307.         xchg    ah, [bWasE0]
  308.         cmp     al, 0x1D
  309.         jz      .ctrl_down
  310.         cmp     al, 0x9D
  311.         jz      .ctrl_up
  312.         cmp     al, 0x2A
  313.         jz      .lshift_down
  314.         cmp     al, 0xAA
  315.         jz      .lshift_up
  316.         cmp     al, 0x36
  317.         jz      .rshift_down
  318.         cmp     al, 0xB6
  319.         jz      .rshift_up
  320.         cmp     al, 0x38
  321.         jz      .alt_down
  322.         cmp     al, 0xB8
  323.         jz      .alt_up
  324.         mov     ecx, [esp+20h+8]
  325.         push    ebx ebp
  326.         push    0
  327.         push    eax
  328.         push    2
  329.         push    ebx
  330.         call    ecx
  331.         pop     ebp ebx
  332.         test    eax, eax
  333.         jz      .event
  334.         mov     [esp+28], eax
  335.         jmp     .exit
  336. .ctrl_down:
  337.         test    ah, ah
  338.         jnz     .rctrl_down
  339.         or      [ctrlstate], 4
  340.         jmp     .event
  341. .rctrl_down:
  342.         or      [ctrlstate], 8
  343.         jmp     .event
  344. .ctrl_up:
  345.         test    ah, ah
  346.         jnz     .rctrl_up
  347.         and     [ctrlstate], not 4
  348.         jmp     .event
  349. .rctrl_up:
  350.         and     [ctrlstate], not 8
  351.         jmp     .event
  352. .lshift_down:
  353.         test    ah, ah
  354.         jnz     @f
  355.         or      [ctrlstate], 1
  356. @@:     jmp     .event
  357. .lshift_up:
  358.         test    ah, ah
  359.         jnz     @b
  360.         and     [ctrlstate], not 1
  361.         jmp     @b
  362. .rshift_down:
  363.         or      [ctrlstate], 2
  364.         jmp     .event
  365. .rshift_up:
  366.         and     [ctrlstate], not 2
  367.         jmp     .event
  368. .alt_down:
  369.         test    ah, ah
  370.         jnz     .ralt_down
  371.         or      [ctrlstate], 0x10
  372.         jmp     .event
  373. .ralt_down:
  374.         or      [ctrlstate], 0x20
  375.         jmp     .event
  376. .alt_up:
  377.         test    ah, ah
  378.         jnz     .ralt_up
  379.         and     [ctrlstate], not 0x10
  380.         jmp     .event
  381. .ralt_up:
  382.         and     [ctrlstate], not 0x20
  383.         jmp     .event
  384. .exit:
  385. ; restore data
  386.         mov     eax, [ebx+dlgtemplate.y]
  387.         add     eax, [ebx+dlgtemplate.height]
  388.         add     eax, [ebx+dlgtemplate.border_size_y]
  389.         inc     eax
  390.         push    eax
  391.         mov     eax, [ebx+dlgtemplate.x]
  392.         add     eax, [ebx+dlgtemplate.width]
  393.         add     eax, [ebx+dlgtemplate.border_size_x]
  394.         inc     eax
  395.         inc     eax
  396.         push    eax
  397.         mov     eax, [ebx+dlgtemplate.y]
  398.         sub     eax, [ebx+dlgtemplate.border_size_y]
  399.         push    eax
  400.         mov     eax, [ebx+dlgtemplate.x]
  401.         sub     eax, [ebx+dlgtemplate.border_size_x]
  402.         push    eax
  403.         call    restore_console_data
  404.         call    draw_keybar
  405.         mov     eax, ebp
  406.         call    mf_free
  407.         call    draw_image
  408.         popad
  409.         ret     8
  410.  
  411. save_console_data:
  412.         cmp     dword [esp+4], 0
  413.         jge     @f
  414.         and     dword [esp+4], 0
  415. @@:
  416.         cmp     dword [esp+8], 0
  417.         jge     @f
  418.         and     dword [esp+8], 0
  419. @@:
  420.         mov     eax, [esp+12]
  421.         cmp     eax, [cur_width]
  422.         jbe     @f
  423.         mov     eax, [cur_width]
  424. @@:
  425.         sub     eax, [esp+4]
  426.         ja      @f
  427.         ret     16
  428. @@:
  429.         mov     [esp+12], eax
  430.         mov     eax, [esp+16]
  431.         cmp     eax, [cur_height]
  432.         jbe     @f
  433.         mov     eax, [cur_height]
  434. @@:
  435.         sub     eax, [esp+8]
  436.         ja      @f
  437.         ret     16
  438. @@:
  439.         mov     [esp+16], eax
  440.         mov     eax, [esp+4]
  441.         mov     edx, [esp+8]
  442.         call    get_console_ptr
  443.         mov     esi, edi
  444.         mov     edi, ebp
  445. .l:
  446.         mov     ecx, [esp+12]
  447.         push    esi
  448.         shr     ecx, 1
  449.         rep     movsd
  450.         adc     ecx, ecx
  451.         rep     movsw
  452.         pop     esi
  453.         add     esi, [cur_width]
  454.         add     esi, [cur_width]
  455.         dec     dword [esp+16]
  456.         jnz     .l
  457.         ret     16
  458.  
  459. restore_console_data:
  460.         cmp     dword [esp+4], 0
  461.         jge     @f
  462.         and     dword [esp+4], 0
  463. @@:
  464.         cmp     dword [esp+8], 0
  465.         jge     @f
  466.         and     dword [esp+8], 0
  467. @@:
  468.         mov     eax, [esp+12]
  469.         cmp     eax, [cur_width]
  470.         jbe     @f
  471.         mov     eax, [cur_width]
  472. @@:
  473.         sub     eax, [esp+4]
  474.         ja      @f
  475.         ret     16
  476. @@:
  477.         mov     [esp+12], eax
  478.         mov     eax, [esp+16]
  479.         cmp     eax, [cur_height]
  480.         jbe     @f
  481.         mov     eax, [cur_height]
  482. @@:
  483.         sub     eax, [esp+8]
  484.         ja      @f
  485.         ret     16
  486. @@:
  487.         mov     [esp+16], eax
  488.         mov     eax, [esp+4]
  489.         mov     edx, [esp+8]
  490.         call    get_console_ptr
  491.         mov     esi, ebp
  492. .l:
  493.         mov     ecx, [esp+12]
  494.         push    edi
  495.         shr     ecx, 1
  496.         rep     movsd
  497.         adc     ecx, ecx
  498.         rep     movsw
  499.         pop     edi
  500.         add     edi, [cur_width]
  501.         add     edi, [cur_width]
  502.         dec     dword [esp+16]
  503.         jnz     .l
  504.         ret     16
  505.  
  506. ; int __stdcall menu(void* variants, const char* title, unsigned flags);
  507. ; variants 㪠§ë¢ ¥â ­  ⥪ã騩 í«¥¬¥­â ¢ ¤¢ãá¢ï§­®¬ «¨­¥©­®¬ ᯨ᪥
  508. menu:
  509.         pop     eax
  510.         push    [cur_height]
  511.         push    [cur_width]
  512.         push    0
  513.         push    0
  514.         push    eax
  515.  
  516. ; int __stdcall menu_centered_in(unsigned left, unsigned top, unsigned width, unsigned height,
  517. ;       void* variants, const char* title, unsigned flags);
  518. menu_centered_in:
  519.         pushad
  520.         mov     eax, 56
  521. ; 36 bytes for dlgtemplate + additional:
  522. ; +36: dd cur_variant
  523. ; +40: dd num_variants
  524. ; +44: dd begin_variant
  525. ; +48: dd end_variant
  526. ; +52: dd cur_variant_idx
  527.         call    mf_alloc
  528.         test    eax, eax
  529.         jnz     @f
  530. .ret_bad:
  531.         popad
  532.         or      eax, -1
  533.         ret     28
  534. @@:
  535.         mov     ebx, eax
  536.         mov     eax, 1
  537.         test    byte [esp+20h+28], 1
  538.         jz      @f
  539.         mov     al, 3
  540. @@:
  541.         mov     [ebx+dlgtemplate.border_size_x], eax
  542.         inc     eax
  543.         shr     eax, 1
  544.         mov     [ebx+dlgtemplate.border_size_y], eax
  545. ;  å®¤¨¬ è¨à¨­ã ¨ ¢ëá®âã ®ª­ 
  546.         xor     eax, eax
  547.         xor     ecx, ecx
  548.         mov     esi, [esp+20h+20]
  549.         mov     [ebx+36], esi
  550.         and     dword [ebx+52], 0
  551. @@:
  552.         cmp     dword [esi+4], 0
  553.         jz      .find_width
  554.         mov     esi, [esi+4]
  555.         inc     dword [ebx+52]
  556.         jmp     @b
  557. .find_width:
  558.         mov     [ebx+44], esi
  559.         add     esi, 8
  560.         push    esi
  561.         xor     edx, edx
  562. .fw1:
  563.         cmp     byte [esi], '&'
  564.         jnz     @f
  565.         mov     dl, 1
  566. @@:
  567.         inc     esi
  568.         cmp     byte [esi-1], 0
  569.         jnz     .fw1
  570.         sub     esi, [esp]
  571.         sub     esi, edx
  572.         dec     esi
  573.         cmp     eax, esi
  574.         ja      @f
  575.         mov     eax, esi
  576. @@:
  577.         inc     ecx
  578.         pop     esi
  579.         mov     esi, [esi-8]
  580.         test    esi, esi
  581.         jnz     .find_width
  582.         add     eax, 3
  583.         add     eax, [ebx+dlgtemplate.border_size_x]
  584.         add     eax, [ebx+dlgtemplate.border_size_x]
  585.         cmp     eax, [cur_width]
  586.         jb      @f
  587.         mov     eax, [cur_width]
  588. @@:
  589.         sub     eax, [ebx+dlgtemplate.border_size_x]
  590.         sub     eax, [ebx+dlgtemplate.border_size_x]
  591.         mov     [ebx+dlgtemplate.width], eax
  592.         mov     [ebx+dlgtemplate.height], ecx
  593.         mov     [ebx+40], ecx
  594.         sub     eax, [esp+20h+12]
  595.         neg     eax
  596.         sar     eax, 1
  597.         add     eax, [esp+20h+4]
  598.         cmp     eax, [ebx+dlgtemplate.border_size_x]
  599.         jge     @f
  600.         mov     eax, [ebx+dlgtemplate.border_size_x]
  601. @@:
  602.         push    eax
  603.         add     eax, [ebx+dlgtemplate.width]
  604.         add     eax, [ebx+dlgtemplate.border_size_x]
  605.         cmp     eax, [cur_width]
  606.         jbe     @f
  607.         pop     eax
  608.         mov     eax, [cur_width]
  609.         sub     eax, [ebx+dlgtemplate.width]
  610.         sub     eax, [ebx+dlgtemplate.border_size_x]
  611.         push    eax
  612. @@:
  613.         pop     [ebx+dlgtemplate.x]
  614.         sub     ecx, [esp+20h+16]
  615.         neg     ecx
  616.         sar     ecx, 1
  617.         add     ecx, [esp+20h+8]
  618.         cmp     ecx, [ebx+dlgtemplate.border_size_y]
  619.         jge     @f
  620.         mov     ecx, [ebx+dlgtemplate.border_size_y]
  621. @@:
  622.         push    ecx
  623.         add     ecx, [ebx+dlgtemplate.height]
  624.         add     ecx, [ebx+dlgtemplate.border_size_y]
  625.         cmp     ecx, [cur_height]
  626.         jbe     @f
  627.         pop     ecx
  628.         mov     ecx, [cur_height]
  629.         sub     ecx, [ebx+dlgtemplate.height]
  630.         sub     ecx, [ebx+dlgtemplate.border_size_y]
  631.         push    ecx
  632. @@:
  633.         pop     [ebx+dlgtemplate.y]
  634.         mov     eax, [cur_height]
  635.         sub     eax, 6
  636.         cmp     [ebx+dlgtemplate.height], eax
  637.         jbe     .small_height
  638.         mov     [ebx+dlgtemplate.height], eax
  639.         mov     [ebx+dlgtemplate.y], 3
  640. .small_height:
  641.         mov     ecx, [ebx+dlgtemplate.height]
  642.         mov     eax, [ebx+36]
  643.         mov     [ebx+44], eax
  644.         dec     ecx
  645.         jz      .skip
  646.         push    ecx
  647. @@:
  648.         cmp     dword [eax+4], 0
  649.         jz      @f
  650.         mov     eax, [eax+4]
  651.         loop    @b
  652. @@:
  653.         mov     [ebx+44], eax
  654.         pop     ecx
  655. .loop:
  656.         mov     eax, [eax]
  657.         loop    .loop
  658. .skip:
  659.         mov     [ebx+48], eax
  660.         mov     eax, [esp+20h+24]
  661.         mov     [ebx+dlgtemplate.title], eax
  662.         mov     al, [menu_normal_color]
  663.         mov     [ebx+dlgtemplate.main_color], al
  664.         mov     al, [menu_border_color]
  665.         mov     [ebx+dlgtemplate.border_color], al
  666.         mov     al, [menu_header_color]
  667.         mov     [ebx+dlgtemplate.header_color], al
  668.         push    MenuDlgProc
  669.         push    ebx
  670.         call    GenericBox
  671.         mov     [esp+28], eax
  672.         mov     eax, ebx
  673.         call    mf_free
  674.         popad
  675.         ret     28
  676.  
  677. MenuDlgProc:
  678.         mov     eax, [esp+8]
  679.         cmp     al, 1
  680.         jz      .draw
  681.         cmp     al, 2
  682.         jz      .key
  683.         ret     16
  684. .draw:
  685.         call    .dodraw
  686.         ret     16
  687. .key:
  688.         mov     al, [esp+12]
  689.         cmp     al, 0x48
  690.         jz      .prev
  691.         cmp     al, 0x4B
  692.         jz      .prev
  693.         cmp     al, 0x4D
  694.         jz      .next
  695.         cmp     al, 0x50
  696.         jz      .next
  697.         cmp     al, 0x1C
  698.         jz      .enter
  699.         cmp     al, 1
  700.         jz      .esc
  701.         cmp     al, 0x47
  702.         jz      .home
  703.         cmp     al, 0x4F
  704.         jz      .end
  705.         cmp     al, 0x51
  706.         jz      .pgdn
  707.         cmp     al, 0x49
  708.         jz      .pgup
  709.         mov     edx, [ebx+36]
  710. @@:
  711.         cmp     dword [edx+4], 0
  712.         jz      @f
  713.         mov     edx, [edx+4]
  714.         jmp     @b
  715. @@:
  716. .l:
  717.         lea     esi, [edx+7]
  718. @@:
  719.         inc     esi
  720.         cmp     byte [esi], 0
  721.         jz      .n
  722.         cmp     byte [esi], '&'
  723.         jnz     @b
  724.         movzx   ecx, byte [esi+1]
  725.         cmp     [ascii2scan+ecx], al
  726.         jnz     .n
  727.         mov     eax, edx
  728.         ret     16
  729. .n:
  730.         mov     edx, [edx]
  731.         test    edx, edx
  732.         jnz     .l
  733. .ret:
  734.         xor     eax, eax
  735.         ret     16
  736. .pgup:
  737.         mov     eax, [ebx+36]
  738.         mov     ecx, [ebx+dlgtemplate.height]
  739. .pgupl:
  740.         cmp     dword [eax+4], 0
  741.         jz      .posret
  742.         call    .line_prev
  743.         loop    .pgupl
  744.         jmp     .posret
  745. .prev:
  746.         mov     eax, [ebx+36]
  747.         cmp     dword [eax+4], 0
  748.         jz      .end
  749.         call    .line_prev
  750. .posret:
  751.         mov     [ebx+36], eax
  752. .redraw:
  753.         call    .dodraw
  754.         call    draw_image
  755.         xor     eax, eax
  756.         ret     16
  757. .next:
  758.         mov     eax, [ebx+36]
  759.         cmp     dword [eax], 0
  760.         jz      .home
  761.         call    .line_next
  762.         jmp     .posret
  763. .pgdn:
  764.         mov     eax, [ebx+36]
  765.         mov     ecx, [ebx+dlgtemplate.height]
  766. .pgdnl:
  767.         cmp     dword [eax], 0
  768.         jz      .posret
  769.         call    .line_next
  770.         loop    .pgdnl
  771.         jmp     .posret
  772. .home:
  773.         mov     eax, [ebx+36]
  774. @@:
  775.         cmp     dword [eax+4], 0
  776.         jz      @f
  777.         mov     eax, [eax+4]
  778.         jmp     @b
  779. @@:
  780.         mov     [ebx+44], eax
  781.         push    eax
  782.         mov     ecx, [ebx+dlgtemplate.height]
  783.         dec     ecx
  784.         jz      .h1
  785. .h2:
  786.         mov     eax, [eax]
  787.         loop    .h2
  788. .h1:
  789.         mov     [ebx+48], eax
  790.         pop     eax
  791.         and     dword [ebx+52], 0
  792.         jmp     .posret
  793. .end:
  794.         mov     eax, [ebx+36]
  795. @@:
  796.         cmp     dword [eax], 0
  797.         jz      @f
  798.         mov     eax, [eax]
  799.         jmp     @b
  800. @@:
  801.         mov     [ebx+48], eax
  802.         push    eax
  803.         mov     ecx, [ebx+dlgtemplate.height]
  804.         dec     ecx
  805.         jz      .e1
  806. .e2:
  807.         mov     eax, [eax+4]
  808.         loop    .e2
  809. .e1:
  810.         mov     [ebx+44], eax
  811.         mov     eax, [ebx+40]
  812.         dec     eax
  813.         mov     [ebx+52], eax
  814.         pop     eax
  815.         jmp     .posret
  816. .esc:
  817.         or      eax, -1
  818.         ret     16
  819. .enter:
  820.         mov     eax, [ebx+36]
  821.         ret     16
  822.  
  823. .line_prev:
  824.         cmp     eax, [ebx+44]
  825.         jnz     @f
  826.         mov     edx, [ebx+44]
  827.         mov     edx, [edx+4]
  828.         mov     [ebx+44], edx
  829.         mov     edx, [ebx+48]
  830.         mov     edx, [edx+4]
  831.         mov     [ebx+48], edx
  832. @@:
  833.         mov     eax, [eax+4]
  834.         dec     dword [ebx+52]
  835.         ret
  836. .line_next:
  837.         cmp     eax, [ebx+48]
  838.         jnz     @f
  839.         mov     edx, [ebx+44]
  840.         mov     edx, [edx]
  841.         mov     [ebx+44], edx
  842.         mov     edx, [ebx+48]
  843.         mov     edx, [edx]
  844.         mov     [ebx+48], edx
  845. @@:
  846.         mov     eax, [eax]
  847.         inc     dword [ebx+52]
  848.         ret
  849.  
  850. .dodraw:
  851.         mov     eax, [ebx+dlgtemplate.x]
  852.         mov     edx, [ebx+dlgtemplate.y]
  853.         call    get_console_ptr
  854.         mov     esi, [ebx+44]
  855. .0:
  856.         xor     edx, edx
  857.         mov     ah, [menu_selected_color]
  858.         cmp     esi, [ebx+36]
  859.         jz      @f
  860.         mov     ah, [menu_normal_color]
  861. @@:
  862.         push    edi
  863.         mov     ecx, [ebx+dlgtemplate.width]
  864.         mov     al, ' '
  865.         stosw
  866.         dec     ecx
  867.         stosw
  868.         dec     ecx
  869.         dec     ecx
  870.         push    esi
  871.         add     esi, 8
  872. @@:
  873.         lodsb
  874.         test    al, al
  875.         jz      @f
  876.         cmp     al, '&'
  877.         jnz     .noamp
  878.         test    dl, dl
  879.         jnz     .noamp
  880.         mov     dl, 1
  881.         lodsb
  882.         push    eax
  883.         mov     ah, [menu_selected_highlight_color]
  884.         push    ecx
  885.         mov     ecx, [esp+8]
  886.         cmp     ecx, [ebx+36]
  887.         pop     ecx
  888.         jz      .amp1
  889.         mov     ah, [menu_highlight_color]
  890. .amp1:
  891.         stosw
  892.         pop     eax
  893.         jmp     .amp2
  894. .noamp:
  895.         stosw
  896. .amp2:
  897.         loop    @b
  898.         mov     al, ' '
  899.         cmp     byte [esi], 0
  900.         jnz     .1
  901.         lodsb
  902.         jmp     .1
  903. @@:
  904.         mov     al, ' '
  905. .1:
  906.         stosw
  907.         mov     al, ' '
  908.         rep     stosw
  909.         pop     esi edi
  910.         add     edi, [cur_width]
  911.         add     edi, [cur_width]
  912.         cmp     esi, [ebx+48]
  913.         jz      @f
  914.         mov     esi, [esi]
  915.         test    esi, esi
  916.         jnz     .0
  917. @@:
  918. ; ‹¨­¥©ª  ¯à®ªàã⪨
  919.         mov     ecx, [ebx+dlgtemplate.height]
  920.         cmp     ecx, [ebx+40]
  921.         jz      .noscrollbar
  922.         sub     ecx, 2
  923.         jbe     .noscrollbar
  924.         mov     eax, [ebx+52]
  925.         mul     ecx
  926.         div     dword [ebx+40]
  927.         push    eax
  928.         mov     eax, [ebx+dlgtemplate.x]
  929.         add     eax, [ebx+dlgtemplate.width]
  930.         mov     edx, [ebx+dlgtemplate.y]
  931.         call    get_console_ptr
  932.         pop     edx
  933.         inc     edx
  934.         mov     al, 0x1E
  935.         mov     ah, [menu_scrollbar_color]
  936.         mov     [edi], ax
  937.         add     edi, [cur_width]
  938.         add     edi, [cur_width]
  939. .2:
  940.         mov     al, 0xB2
  941.         dec     edx
  942.         jz      @f
  943.         mov     al, 0xB0
  944. @@:
  945.         mov     [edi], ax
  946.         add     edi, [cur_width]
  947.         add     edi, [cur_width]
  948.         loop    .2
  949.         mov     al, 0x1F
  950.         stosw
  951. .noscrollbar:
  952.         ret
  953.  
  954. virtual at 0
  955. dlgitemtemplate:
  956. ; «¥¬¥­âë:
  957. ;       1 = áâ â¨ç¥áª¨© ⥪áâ
  958. .type           dd      ?
  959. .x1             dd      ?
  960. .y1             dd      ?
  961. .x2             dd      ?
  962. .y2             dd      ?
  963. .data           dd      ?
  964. .flags          dd      ?
  965. ; ”« £¨:
  966. ;       0 = ¢ëà ¢­¨¢ ­¨¥ ¢«¥¢®
  967. ;       1 = ¢ëà ¢­¨¢ ­¨¥ ¯® 業âàã
  968. ;       2 = ¢ëà ¢­¨¢ ­¨¥ ¢¯à ¢®
  969. ;       4 = í«¥¬¥­â ¨¬¥¥â 䮪ãá ¢¢®¤ 
  970. .size = $
  971. end virtual
  972. ;       struct DLGDATA
  973. ;       {
  974. ;               DLGTEMPLATE dialog;     /* window description */
  975. ;               void* DlgProc;          /* dialog procedure */
  976. ; /* int __stdcall DlgProc(DLGDATA* dlg, int msg, int param1, int param2); */
  977. ;               void* user_data;        /* arbitrary user data */
  978. ;               unsigned num_items;     /* number of items in the following array */
  979. ;               DLGITEMTEMPLATE items[]; /* array of dialog items */
  980. ;       }
  981. ; int __stdcall DialogBox(DLGDATA* dlg);
  982. DialogBox:
  983.         push    ManagerDlgProc
  984.         push    dword [esp+8]
  985.         call    GenericBox
  986.         ret     8
  987.  
  988. ManagerDlgProc:
  989.         mov     eax, [esp+8]
  990.         dec     eax
  991.         jz      .draw
  992.         dec     eax
  993.         jz      .key
  994.         xor     eax, eax
  995.         ret     16
  996. .draw:
  997.         call    .dodraw
  998.         ret     16
  999. .key:
  1000. ; find item with focus
  1001.         add     ebx, dlgtemplate.size+12
  1002.         mov     ecx, [ebx-4]
  1003.         jecxz   .nobtns
  1004. @@:
  1005.         test    [ebx+dlgitemtemplate.flags], 4
  1006.         jnz     @f
  1007.         add     ebx, dlgitemtemplate.size
  1008.         loop    @b
  1009. @@:
  1010. .nobtns:
  1011.         mov     al, [esp+12]
  1012.         cmp     al, 1
  1013.         jz      .esc
  1014.         cmp     al, 0x1C
  1015.         jz      .enter
  1016.         cmp     al, 0xF
  1017.         jz      .tab
  1018.         cmp     al, 0x48
  1019.         jz      .up
  1020.         cmp     al, 0x4B
  1021.         jz      .left
  1022.         cmp     al, 0x4D
  1023.         jz      .right
  1024.         cmp     al, 0x50
  1025.         jz      .down
  1026. .ret0:
  1027.         xor     eax, eax
  1028.         ret     16
  1029. .esc:
  1030.         or      eax, -1
  1031.         ret     16
  1032. .enter:
  1033.         mov     eax, ebx
  1034.         ret     16
  1035. .tab:
  1036.         test    [ctrlstate], 3
  1037.         jnz     .shift_tab
  1038. .right:
  1039. .down:
  1040.         jecxz   .ret0
  1041.         and     byte [ebx+dlgitemtemplate.flags], not 4
  1042.         dec     ecx
  1043.         jz      .find_first_btn
  1044. @@:
  1045.         add     ebx, dlgitemtemplate.size
  1046.         cmp     [ebx+dlgitemtemplate.type], 2
  1047.         jz      .btn_found
  1048.         loop    @b
  1049. .find_first_btn:
  1050.         mov     ebx, [esp+4]
  1051.         add     ebx, dlgtemplate.size+12
  1052. @@:
  1053.         cmp     [ebx+dlgitemtemplate.type], 2
  1054.         jz      .btn_found
  1055.         add     ebx, dlgitemtemplate.size
  1056.         jmp     @b
  1057. .btn_found:
  1058.         or      byte [ebx+dlgitemtemplate.flags], 4
  1059.         mov     ebx, [esp+4]
  1060.         call    .dodraw
  1061.         call    draw_image
  1062.         xor     eax, eax
  1063.         ret     16
  1064. .shift_tab:
  1065. .left:
  1066. .up:
  1067.         jecxz   .ret0
  1068.         and     byte [ebx+dlgitemtemplate.flags], not 4
  1069.         mov     eax, [esp+4]
  1070.         sub     ecx, [eax+dlgtemplate.size+8]
  1071.         neg     ecx
  1072.         jz      .find_last_btn
  1073. @@:
  1074.         sub     ebx, dlgitemtemplate.size
  1075.         cmp     [ebx+dlgitemtemplate.type], 2
  1076.         loopnz  @b
  1077.         jz      .btn_found
  1078. .find_last_btn:
  1079.         mov     ebx, [eax+dlgtemplate.size+8]
  1080.         imul    ebx, dlgitemtemplate.size
  1081.         lea     ebx, [ebx+eax+dlgtemplate.size+12]
  1082. @@:
  1083.         sub     ebx, dlgitemtemplate.size
  1084.         cmp     [ebx+dlgitemtemplate.type], 2
  1085.         jnz     @b
  1086.         jmp     .btn_found
  1087.  
  1088. .dodraw:
  1089.         add     ebx, dlgtemplate.size+8
  1090.         mov     ecx, [ebx]
  1091.         add     ebx, 4
  1092.         jecxz   .done_draw
  1093. .draw_loop:
  1094.         push    ecx
  1095.         mov     eax, [ebx+dlgitemtemplate.type]
  1096.         dec     eax
  1097.         jz      .draw_text
  1098.         dec     eax
  1099.         jnz     .draw_loop_continue
  1100.         call    draw_button
  1101.         jmp     .draw_loop_continue
  1102. .draw_text:
  1103.         call    draw_static_text
  1104. .draw_loop_continue:
  1105.         pop     ecx
  1106.         add     ebx, dlgitemtemplate.size
  1107.         loop    .draw_loop
  1108. .done_draw:
  1109.         ret
  1110.  
  1111. draw_static_text:
  1112. ; à¨á㥬 áâ â¨ç¥áª¨© ⥪áâ
  1113.         mov     ah, [dialog_main_color]
  1114. draw_text:
  1115. ; ®¯à¥¤¥«ï¥¬ ¤«¨­ã áâப¨
  1116.         mov     esi, [ebx+dlgitemtemplate.data]
  1117.         test    esi, esi
  1118.         jz      .ret
  1119.         or      ecx, -1
  1120. @@:
  1121.         inc     ecx
  1122.         cmp     byte [ecx+esi], 0
  1123.         jnz     @b
  1124. ; ¢ ecx ¤«¨­  áâப¨
  1125.         push    eax
  1126.         xor     eax, eax
  1127.         mov     edx, [ebx+dlgitemtemplate.x2]
  1128.         sub     edx, [ebx+dlgitemtemplate.x1]
  1129.         inc     edx
  1130.         cmp     ecx, edx
  1131.         jae     .text_draw
  1132.         mov     al, byte [ebx+dlgitemtemplate.flags]
  1133.         and     al, 3
  1134.         jz      .text_align_left
  1135.         cmp     al, 1
  1136.         jz      .text_align_center
  1137. ; ⥪áâ ¢ë஢­¥­ ¢¯à ¢®
  1138.         mov     eax, edx
  1139.         sub     eax, ecx
  1140.         jmp     .text_draw
  1141. .text_align_center:
  1142.         mov     eax, edx
  1143.         sub     eax, ecx
  1144.         shr     eax, 1
  1145.         jmp     .text_draw
  1146. .text_align_left:
  1147.         xor     eax, eax
  1148. .text_draw:
  1149.         push    ecx
  1150.         mov     ecx, [esp+24]
  1151.         push    eax
  1152.         mov     eax, [ebx+dlgitemtemplate.x1]
  1153.         add     eax, [ecx+dlgtemplate.x]
  1154.         push    edx
  1155.         mov     edx, [ebx+dlgitemtemplate.y1]
  1156.         add     edx, [ecx+dlgtemplate.y]
  1157.         call    get_console_ptr
  1158.         pop     edx
  1159.         pop     ecx
  1160.         mov     ah, [esp+5]
  1161.         mov     al, ' '
  1162.         rep     stosw
  1163.         pop     ecx
  1164.         cmp     ecx, edx
  1165.         jbe     .text_copy
  1166.         cmp     edx, 3
  1167.         jb      .ret
  1168.         mov     al, '.'
  1169.         stosw
  1170.         stosw
  1171.         stosw
  1172.         add     esi, ecx
  1173.         mov     ecx, edx
  1174.         sub     ecx, 3
  1175.         sub     esi, ecx
  1176. .text_copy:
  1177.         jecxz   .ret
  1178. @@:
  1179.         lodsb
  1180.         stosw
  1181.         loop    @b
  1182. .ret:
  1183.         mov     ecx, [esp+20]
  1184.         mov     eax, [ecx+dlgtemplate.x]
  1185.         mov     edx, [ecx+dlgtemplate.y]
  1186.         add     eax, [ebx+dlgitemtemplate.x2]
  1187.         inc     eax
  1188.         add     edx, [ebx+dlgitemtemplate.y1]
  1189.         mov     ecx, edi
  1190.         call    get_console_ptr
  1191.         xchg    ecx, edi
  1192.         sub     ecx, edi
  1193.         shr     ecx, 1
  1194.         pop     eax
  1195.         mov     al, ' '
  1196.         rep     stosw
  1197.         ret
  1198.  
  1199. draw_button:
  1200.         mov     ah, [dialog_normal_btn_color]
  1201.         test    [ebx+dlgitemtemplate.flags], 4
  1202.         jz      @f
  1203.         mov     ah, [dialog_selected_btn_color]
  1204. @@:
  1205.         jmp     draw_text
  1206.