Subversion Repositories Kolibri OS

Rev

Rev 997 | Rev 9014 | 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. ; ”« £¨:
  7. ; ¡¨â 0: ¨á¯®«ì§®¢ âì áâ ­¤ àâ­ë¥ æ¢¥â  ¤¨ «®£ 
  8. ; ¡¨â 1: ¨á¯®«ì§®¢ âì áâ ­¤ àâ­ë¥ æ¢¥â  ¯à¥¤ã¯à¥¦¤¥­¨ï/®è¨¡ª¨
  9. ; (¥á«¨ «î¡®© ¨§ íâ¨å ¡¨â®¢ ãáâ ­®¢«¥­, ¯®«ï main_color,border_color,header_color
  10. ;  ¨£­®à¨àãîâáï)
  11. ; ¡¨â 2: ­¥ à¨á®¢ âì ⥭ì
  12. .flags          dd      ?
  13. .x              dd      ?
  14. .y              dd      ?
  15. .width          dd      ?
  16. .height         dd      ?
  17. .border_size_x  dd      ?
  18. .border_size_y  dd      ?
  19. .title          dd      ?
  20. .main_color     db      ?
  21. .border_color   db      ?
  22. .header_color   db      ?
  23.                 db      ?       ; align
  24. .dataptr        dd      ?       ; used internally, ignored on input
  25. .size = $
  26. end virtual
  27.  
  28. GenericBox:
  29.         push    [cursor_x]
  30.         push    [cursor_y]
  31.         push    dword [esp+8+8]
  32.         push    dword [esp+8+8]
  33.         call    ShowGenericBox
  34.         test    eax, eax
  35.         jz      @f
  36.         pop     [cursor_y]
  37.         pop     [cursor_x]
  38.         ret
  39. @@:
  40.         pushad
  41. ; message loop
  42. .event:
  43. ;        call    get_event
  44.         push    SF_WAIT_EVENT
  45.         pop     eax
  46.         int     40h
  47.         dec     eax
  48.         jz      .redraw
  49.         dec     eax
  50.         jz      .key
  51.         sub     eax,4
  52.         jz      .event ;todo: mouse
  53.         jmp     exit
  54. .redraw:
  55.         call    draw_window
  56.         jmp     .event
  57. .key:
  58.         mov     al, SF_GET_KEY
  59.         int     40h
  60.         shr     eax, 8
  61.         cmp     al, 0xE0
  62.         jnz     @f
  63.         mov     [bWasE0], 1
  64.         jmp     .event
  65. @@:
  66.         xchg    ah, [bWasE0]
  67.         cmp     al, 0x1D
  68.         jz      .ctrl_down
  69.         cmp     al, 0x9D
  70.         jz      .ctrl_up
  71.         cmp     al, 0x2A
  72.         jz      .lshift_down
  73.         cmp     al, 0xAA
  74.         jz      .lshift_up
  75.         cmp     al, 0x36
  76.         jz      .rshift_down
  77.         cmp     al, 0xB6
  78.         jz      .rshift_up
  79.         cmp     al, 0x38
  80.         jz      .alt_down
  81.         cmp     al, 0xB8
  82.         jz      .alt_up
  83.         mov     ebx, [esp+24h+8]
  84.         mov     ecx, [esp+28h+8]
  85.         push    0
  86.         push    eax
  87.         push    2
  88.         push    ebx
  89.         call    ecx
  90.         test    eax, eax
  91.         jz      .event
  92.         mov     [esp+28], eax
  93.         jmp     .exit
  94. .ctrl_down:
  95.         test    ah, ah
  96.         jnz     .rctrl_down
  97.         or      [ctrlstate], 4
  98.         jmp     .event
  99. .rctrl_down:
  100.         or      [ctrlstate], 8
  101.         jmp     .event
  102. .ctrl_up:
  103.         test    ah, ah
  104.         jnz     .rctrl_up
  105.         and     [ctrlstate], not 4
  106.         jmp     .event
  107. .rctrl_up:
  108.         and     [ctrlstate], not 8
  109.         jmp     .event
  110. .lshift_down:
  111.         test    ah, ah
  112.         jnz     @f
  113.         or      [ctrlstate], 1
  114. @@:     jmp     .event
  115. .lshift_up:
  116.         test    ah, ah
  117.         jnz     @b
  118.         and     [ctrlstate], not 1
  119.         jmp     @b
  120. .rshift_down:
  121.         or      [ctrlstate], 2
  122.         jmp     .event
  123. .rshift_up:
  124.         and     [ctrlstate], not 2
  125.         jmp     .event
  126. .alt_down:
  127.         test    ah, ah
  128.         jnz     .ralt_down
  129.         or      [ctrlstate], 0x10
  130.         jmp     .event
  131. .ralt_down:
  132.         or      [ctrlstate], 0x20
  133.         jmp     .event
  134. .alt_up:
  135.         test    ah, ah
  136.         jnz     .ralt_up
  137.         and     [ctrlstate], not 0x10
  138.         jmp     .event
  139. .ralt_up:
  140.         and     [ctrlstate], not 0x20
  141.         jmp     .event
  142. .exit:
  143.         popad
  144.         push    eax
  145.         push    0
  146.         push    dword [esp+12+8]
  147.         call    HideGenericBox
  148.         pop     eax
  149.         pop     [cursor_y]
  150.         pop     [cursor_x]
  151.         pushad
  152.         call    draw_image
  153.         popad
  154.         ret     8
  155.  
  156. ; int __stdcall ShowGenericBox(DLGTEMPLATE* dlg, void* DlgProc);
  157. ShowGenericBox:
  158.         pushad
  159.         mov     ebx, [esp+20h+4]
  160. ; center window if required
  161.         push    [ebx+dlgtemplate.x]
  162.         push    [ebx+dlgtemplate.y]
  163.         cmp     [ebx+dlgtemplate.x], -1
  164.         jnz     @f
  165.         mov     eax, [cur_width]
  166.         sub     eax, [ebx+dlgtemplate.width]
  167.         shr     eax, 1
  168.         mov     [ebx+dlgtemplate.x], eax
  169. @@:
  170.         cmp     [ebx+dlgtemplate.y], -1
  171.         jnz     @f
  172.         mov     eax, [cur_height]
  173.         sub     eax, [ebx+dlgtemplate.height]
  174.         shr     eax, 1
  175.         mov     [ebx+dlgtemplate.y], eax
  176. @@:
  177. ; some checks
  178.         mov     eax, [ebx+dlgtemplate.x]
  179.         cmp     eax, 1
  180.         jl      .sizeerr
  181.         add     eax, [ebx+dlgtemplate.width]
  182.         cmp     eax, [cur_width]
  183.         jge     .sizeerr
  184.         mov     eax, [ebx+dlgtemplate.y]
  185.         cmp     eax, 1
  186.         jl      .sizeerr
  187.         add     eax, [ebx+dlgtemplate.height]
  188.         cmp     eax, [cur_height]
  189.         jge     .sizeerr
  190.         cmp     [ebx+dlgtemplate.border_size_x], 1
  191.         jl      .sizeerr
  192.         cmp     [ebx+dlgtemplate.border_size_y], 1
  193.         jge     .sizeok
  194. .sizeerr:
  195.         pop     [ebx+dlgtemplate.y]
  196.         pop     [ebx+dlgtemplate.x]
  197.         popad
  198.         or      eax, -1
  199.         ret     8
  200. .sizeok:
  201. ; set color if required
  202.         test    byte [ebx+dlgtemplate.flags], 1
  203.         jz      @f
  204.         mov     edi, dialog_colors
  205.         jmp     .setcolor
  206. @@:
  207.         test    byte [ebx+dlgtemplate.flags], 2
  208.         jz      @f
  209.         mov     edi, warning_colors
  210. .setcolor:
  211.         mov     al, [edi + dialog_main_color-dialog_colors]
  212.         mov     [ebx+dlgtemplate.main_color], al
  213.         mov     al, [edi + dialog_border_color-dialog_colors]
  214.         mov     [ebx+dlgtemplate.border_color], al
  215.         mov     al, [edi + dialog_header_color-dialog_colors]
  216.         mov     [ebx+dlgtemplate.header_color], al
  217. @@:
  218. ; allocate memory for data under dialog
  219. ; for 'No memory' dialog use static data area
  220.         mov     eax, nomem_dlgsavearea
  221.         cmp     ebx, nomem_dlgdata
  222.         jz      .allocated
  223.         mov     eax, [ebx+dlgtemplate.width]
  224.         add     eax, [ebx+dlgtemplate.border_size_x]
  225.         add     eax, [ebx+dlgtemplate.border_size_x]
  226.         inc     eax
  227.         inc     eax
  228.         mov     edx, [ebx+dlgtemplate.height]
  229.         add     edx, [ebx+dlgtemplate.border_size_y]
  230.         add     edx, [ebx+dlgtemplate.border_size_y]
  231.         inc     edx
  232.         mul     edx
  233.         lea     ecx, [eax*2+8]
  234.         call    xpgalloc
  235.         test    eax, eax
  236.         jnz     @f
  237.         pop     [ebx+dlgtemplate.y]
  238.         pop     [ebx+dlgtemplate.x]
  239.         popad
  240.         or      eax, -1
  241.         ret     8
  242. @@:
  243. .allocated:
  244.         mov     [ebx+dlgtemplate.dataptr], eax
  245.         pop     dword [eax+4]
  246.         pop     dword [eax]
  247.         lea     ebp, [eax+8]
  248. ; save data
  249.         mov     eax, [ebx+dlgtemplate.y]
  250.         add     eax, [ebx+dlgtemplate.height]
  251.         add     eax, [ebx+dlgtemplate.border_size_y]
  252.         inc     eax
  253.         push    eax
  254.         mov     eax, [ebx+dlgtemplate.x]
  255.         add     eax, [ebx+dlgtemplate.width]
  256.         add     eax, [ebx+dlgtemplate.border_size_x]
  257.         inc     eax
  258.         inc     eax
  259.         push    eax
  260.         mov     eax, [ebx+dlgtemplate.y]
  261.         sub     eax, [ebx+dlgtemplate.border_size_y]
  262.         push    eax
  263.         mov     eax, [ebx+dlgtemplate.x]
  264.         sub     eax, [ebx+dlgtemplate.border_size_x]
  265.         push    eax
  266.         call    save_console_data
  267. ; draw shadow
  268.         test    byte [ebx+dlgtemplate.flags], 4
  269.         jnz     .noshadow
  270.         call    draw_dialog_shadow
  271. .noshadow:
  272.         popad
  273.         push    dword [esp+8]
  274.         push    dword [esp+8]
  275.         call    DrawGenericBox
  276.         xor     eax, eax
  277.         ret     8
  278.  
  279. draw_dialog_shadow:
  280.         mov     eax, [ebx+dlgtemplate.x]
  281.         sub     eax, [ebx+dlgtemplate.border_size_x]
  282.         ja      @f
  283.         xor     eax, eax
  284. @@:
  285.         inc     eax
  286.         inc     eax
  287.         mov     edx, [ebx+dlgtemplate.y]
  288.         sub     edx, [ebx+dlgtemplate.border_size_y]
  289.         ja      @f
  290.         xor     edx, edx
  291. @@:
  292.         inc     edx
  293.         call    get_console_ptr
  294.         mov     ecx, [ebx+dlgtemplate.y]
  295.         add     ecx, [ebx+dlgtemplate.height]
  296.         add     ecx, [ebx+dlgtemplate.border_size_y]
  297.         inc     ecx
  298.         cmp     ecx, [cur_height]
  299.         jb      @f
  300.         mov     ecx, [cur_height]
  301. @@:
  302.         sub     ecx, edx
  303.         mov     edx, ecx
  304.         mov     ecx, [ebx+dlgtemplate.x]
  305.         add     ecx, [ebx+dlgtemplate.width]
  306.         add     ecx, [ebx+dlgtemplate.border_size_x]
  307.         inc     ecx
  308.         inc     ecx
  309.         cmp     ecx, [cur_width]
  310.         jb      @f
  311.         mov     ecx, [cur_width]
  312. @@:
  313.         sub     ecx, eax
  314.         mov     eax, ecx
  315. .shadow_loop:
  316.         mov     ecx, eax
  317.         push    edi
  318. .sl1:
  319.         inc     edi
  320.         test    byte [edi], 0x0F
  321.         jnz     @f
  322.         or      byte [edi], 8
  323. @@:
  324.         and     byte [edi], 0x0F
  325.         inc     edi
  326.         loop    .sl1
  327.         pop     edi
  328.         add     edi, [cur_width]
  329.         add     edi, [cur_width]
  330.         dec     edx
  331.         jnz     .shadow_loop
  332.         ret
  333.  
  334. ; void __stdcall DrawGenericBox(DLGDATA* dlg, void* DlgProc)
  335. DrawGenericBox:
  336.         pushad
  337.         mov     ebx, [esp+24h]
  338. ; draw area background
  339.         mov     eax, [ebx+dlgtemplate.x]
  340.         sub     eax, [ebx+dlgtemplate.border_size_x]
  341.         ja      @f
  342.         xor     eax, eax
  343. @@:
  344.         mov     edx, [ebx+dlgtemplate.y]
  345.         sub     edx, [ebx+dlgtemplate.border_size_y]
  346.         ja      @f
  347.         xor     edx, edx
  348. @@:
  349.         call    get_console_ptr
  350.         mov     ecx, [ebx+dlgtemplate.x]
  351.         add     ecx, [ebx+dlgtemplate.width]
  352.         add     ecx, [ebx+dlgtemplate.border_size_x]
  353.         cmp     ecx, [cur_width]
  354.         jb      @f
  355.         mov     ecx, [cur_width]
  356. @@:
  357.         sub     ecx, eax
  358.         mov     esi, ecx
  359.         mov     ecx, [ebx+dlgtemplate.y]
  360.         add     ecx, [ebx+dlgtemplate.height]
  361.         add     ecx, [ebx+dlgtemplate.border_size_y]
  362.         cmp     ecx, [cur_height]
  363.         jb      @f
  364.         mov     ecx, [cur_height]
  365. @@:
  366.         sub     ecx, edx
  367.         mov     edx, ecx
  368.         mov     al, ' '
  369.         mov     ah, [ebx+dlgtemplate.border_color]
  370. .1:
  371.         mov     ecx, esi
  372.         push    edi
  373.         rep     stosw
  374.         pop     edi
  375.         add     edi, [cur_width]
  376.         add     edi, [cur_width]
  377.         dec     edx
  378.         jnz     .1
  379. ; draw border
  380.         mov     eax, [ebx+dlgtemplate.x]
  381.         dec     eax
  382.         mov     edx, [ebx+dlgtemplate.y]
  383.         dec     edx
  384.         call    get_console_ptr
  385.         mov     edx, [ebx+dlgtemplate.height]
  386.         inc     edx
  387.         inc     edx
  388.         mov     ah, [ebx+dlgtemplate.border_color]
  389.         push    ebx
  390.         mov     ebx, [ebx+dlgtemplate.width]
  391.         inc     ebx
  392.         inc     ebx
  393.         call    draw_border
  394.         pop     ebx
  395. ; draw header
  396.         mov     esi, [ebx+dlgtemplate.title]
  397.         test    esi, esi
  398.         jz      .noheader
  399.         cmp     byte [esi], 0
  400.         jz      .noheader
  401.         push    esi
  402. @@:     lodsb
  403.         test    al, al
  404.         jnz     @b
  405.         mov     eax, esi
  406.         pop     esi
  407.         sub     eax, esi
  408.         inc     eax     ; eax = ¤«¨­  § £®«®¢ª  + 2
  409.         mov     ecx, [ebx+dlgtemplate.width]
  410.         cmp     eax, ecx
  411.         jbe     .fullhea
  412.         sub     ecx, 5
  413.         jb      .noheader
  414.         xor     edx, edx
  415.         jmp     .drawhea
  416. .fullhea:
  417.         mov     edx, ecx
  418.         sub     edx, eax
  419.         shr     edx, 1
  420. .drawhea:
  421.         mov     eax, [ebx+dlgtemplate.x]
  422.         add     eax, edx
  423.         mov     edx, [ebx+dlgtemplate.y]
  424.         dec     edx
  425.         call    get_console_ptr
  426.         mov     ah, [ebx+dlgtemplate.header_color]
  427.         mov     al, ' '
  428.         stosw
  429. .2:
  430.         dec     ecx
  431.         jz      .3
  432.         lodsb
  433.         test    al, al
  434.         jz      .4
  435.         stosw
  436.         jmp     .2
  437. .3:
  438.         mov     al, '.'
  439.         stosw
  440.         stosw
  441.         stosw
  442. .4:
  443.         mov     al, ' '
  444.         stosw
  445. .noheader:
  446. ; draw window background
  447.         mov     eax, [ebx+dlgtemplate.x]
  448.         mov     edx, [ebx+dlgtemplate.y]
  449.         call    get_console_ptr
  450.         mov     ah, [ebx+dlgtemplate.main_color]
  451.         mov     al, ' '
  452.         mov     edx, [ebx+dlgtemplate.height]
  453. @@:
  454.         mov     ecx, [ebx+dlgtemplate.width]
  455.         push    edi
  456.         rep     stosw
  457.         pop     edi
  458.         add     edi, [cur_width]
  459.         add     edi, [cur_width]
  460.         dec     edx
  461.         jnz     @b
  462. ; send redraw message
  463.         mov     eax, [esp+28h]
  464.         push    0
  465.         push    0
  466.         push    1
  467.         push    ebx
  468.         call    eax
  469.         call    draw_image
  470.         popad
  471.         ret     8
  472.  
  473. ; void __stdcall HideGenericBox(DLGTEMPLATE* dlg, int bRedrawWindow);
  474. HideGenericBox:
  475. ; void __stdcall HideDialogBox(DLGDATA* dlg, int bRedrawWindow);
  476. HideDialogBox:
  477.         pushad
  478.         mov     ebx, [esp+24h]
  479.         mov     ebp, [ebx+dlgtemplate.dataptr]
  480.         add     ebp, 8
  481. ; restore data
  482.         mov     eax, [ebx+dlgtemplate.y]
  483.         add     eax, [ebx+dlgtemplate.height]
  484.         add     eax, [ebx+dlgtemplate.border_size_y]
  485.         inc     eax
  486.         push    eax
  487.         mov     eax, [ebx+dlgtemplate.x]
  488.         add     eax, [ebx+dlgtemplate.width]
  489.         add     eax, [ebx+dlgtemplate.border_size_x]
  490.         inc     eax
  491.         inc     eax
  492.         push    eax
  493.         mov     eax, [ebx+dlgtemplate.y]
  494.         sub     eax, [ebx+dlgtemplate.border_size_y]
  495.         push    eax
  496.         mov     eax, [ebx+dlgtemplate.x]
  497.         sub     eax, [ebx+dlgtemplate.border_size_x]
  498.         push    eax
  499.         call    restore_console_data
  500.         call    draw_keybar
  501.         lea     ecx, [ebp-8]
  502.         push    dword [ecx]
  503.         push    dword [ecx+4]
  504.         pop     [ebx+dlgtemplate.y]
  505.         pop     [ebx+dlgtemplate.x]
  506.         cmp     ebx, nomem_dlgdata
  507.         jz      @f
  508.         call    pgfree
  509. @@:
  510.         or      [cursor_x], -1
  511.         or      [cursor_y], -1
  512.         cmp     dword [esp+28h], 0
  513.         jz      @f
  514.         call    draw_image
  515. @@:
  516.         popad
  517.         ret     8
  518.  
  519. save_console_data:
  520.         cmp     dword [esp+4], 0
  521.         jge     @f
  522.         and     dword [esp+4], 0
  523. @@:
  524.         cmp     dword [esp+8], 0
  525.         jge     @f
  526.         and     dword [esp+8], 0
  527. @@:
  528.         mov     eax, [esp+12]
  529.         cmp     eax, [cur_width]
  530.         jbe     @f
  531.         mov     eax, [cur_width]
  532. @@:
  533.         sub     eax, [esp+4]
  534.         ja      @f
  535.         ret     16
  536. @@:
  537.         mov     [esp+12], eax
  538.         mov     eax, [esp+16]
  539.         cmp     eax, [cur_height]
  540.         jbe     @f
  541.         mov     eax, [cur_height]
  542. @@:
  543.         sub     eax, [esp+8]
  544.         ja      @f
  545.         ret     16
  546. @@:
  547.         mov     [esp+16], eax
  548.         mov     eax, [esp+4]
  549.         mov     edx, [esp+8]
  550.         call    get_console_ptr
  551.         mov     esi, edi
  552.         mov     edi, ebp
  553. .l:
  554.         mov     ecx, [esp+12]
  555.         push    esi
  556.         shr     ecx, 1
  557.         rep     movsd
  558.         adc     ecx, ecx
  559.         rep     movsw
  560.         pop     esi
  561.         add     esi, [cur_width]
  562.         add     esi, [cur_width]
  563.         dec     dword [esp+16]
  564.         jnz     .l
  565.         ret     16
  566.  
  567. restore_console_data:
  568.         cmp     dword [esp+4], 0
  569.         jge     @f
  570.         and     dword [esp+4], 0
  571. @@:
  572.         cmp     dword [esp+8], 0
  573.         jge     @f
  574.         and     dword [esp+8], 0
  575. @@:
  576.         mov     eax, [esp+12]
  577.         cmp     eax, [cur_width]
  578.         jbe     @f
  579.         mov     eax, [cur_width]
  580. @@:
  581.         sub     eax, [esp+4]
  582.         ja      @f
  583.         ret     16
  584. @@:
  585.         mov     [esp+12], eax
  586.         mov     eax, [esp+16]
  587.         cmp     eax, [cur_height]
  588.         jbe     @f
  589.         mov     eax, [cur_height]
  590. @@:
  591.         sub     eax, [esp+8]
  592.         ja      @f
  593.         ret     16
  594. @@:
  595.         mov     [esp+16], eax
  596.         mov     eax, [esp+4]
  597.         mov     edx, [esp+8]
  598.         call    get_console_ptr
  599.         mov     esi, ebp
  600. .l:
  601.         mov     ecx, [esp+12]
  602.         push    edi
  603.         shr     ecx, 1
  604.         rep     movsd
  605.         adc     ecx, ecx
  606.         rep     movsw
  607.         pop     edi
  608.         add     edi, [cur_width]
  609.         add     edi, [cur_width]
  610.         dec     dword [esp+16]
  611.         jnz     .l
  612.         ret     16
  613.  
  614. ; int __stdcall menu(void* variants, const char* title, unsigned flags);
  615. ; variants 㪠§ë¢ ¥â ­  ⥪ã騩 í«¥¬¥­â ¢ ¤¢ãá¢ï§­®¬ «¨­¥©­®¬ ᯨ᪥
  616. menu:
  617.         pop     eax
  618.         push    [cur_height]
  619.         push    [cur_width]
  620.         push    0
  621.         push    0
  622.         push    eax
  623.  
  624. ; int __stdcall menu_centered_in(unsigned left, unsigned top, unsigned width, unsigned height,
  625. ;       void* variants, const char* title, unsigned flags);
  626. menu_centered_in:
  627.         pushad
  628.         mov     ecx, 60
  629. ; 40 bytes for dlgtemplate + additional:
  630. ; +40: dd cur_variant
  631. ; +44: dd num_variants
  632. ; +48: dd begin_variant
  633. ; +52: dd end_variant
  634. ; +56: dd cur_variant_idx
  635.         call    xpgalloc
  636.         test    eax, eax
  637.         jnz     @f
  638. .ret_bad:
  639.         popad
  640.         or      eax, -1
  641.         ret     28
  642. @@:
  643.         mov     ebx, eax
  644.         mov     eax, 1
  645.         test    byte [esp+20h+28], 1
  646.         jz      @f
  647.         mov     al, 3
  648. @@:
  649.         mov     [ebx+dlgtemplate.border_size_x], eax
  650.         inc     eax
  651.         shr     eax, 1
  652.         mov     [ebx+dlgtemplate.border_size_y], eax
  653. ;  å®¤¨¬ è¨à¨­ã ¨ ¢ëá®âã ®ª­ 
  654.         xor     eax, eax
  655.         xor     ecx, ecx
  656.         mov     esi, [esp+20h+20]
  657.         mov     [ebx+40], esi
  658.         mov     dword [ebx+56], eax
  659. @@:
  660.         cmp     dword [esi+4], eax
  661.         jz      .find_width
  662.         mov     esi, [esi+4]
  663.         inc     dword [ebx+56]
  664.         jmp     @b
  665. .find_width:
  666.         mov     [ebx+48], esi
  667.         add     esi, 8
  668.         push    esi
  669.         xor     edx, edx
  670. .fw1:
  671.         cmp     byte [esi], '&'
  672.         jnz     @f
  673.         mov     dl, 1
  674. @@:
  675.         inc     esi
  676.         cmp     byte [esi-1], 0
  677.         jnz     .fw1
  678.         sub     esi, [esp]
  679.         sub     esi, edx
  680.         dec     esi
  681.         cmp     eax, esi
  682.         ja      @f
  683.         mov     eax, esi
  684. @@:
  685.         inc     ecx
  686.         pop     esi
  687.         mov     esi, [esi-8]
  688.         test    esi, esi
  689.         jnz     .find_width
  690.         add     eax, 3
  691.         add     eax, [ebx+dlgtemplate.border_size_x]
  692.         add     eax, [ebx+dlgtemplate.border_size_x]
  693.         cmp     eax, [cur_width]
  694.         jb      @f
  695.         mov     eax, [cur_width]
  696. @@:
  697.         sub     eax, [ebx+dlgtemplate.border_size_x]
  698.         sub     eax, [ebx+dlgtemplate.border_size_x]
  699.         mov     [ebx+dlgtemplate.width], eax
  700.         mov     [ebx+dlgtemplate.height], ecx
  701.         mov     [ebx+44], ecx
  702.         sub     eax, [esp+20h+12]
  703.         neg     eax
  704.         sar     eax, 1
  705.         add     eax, [esp+20h+4]
  706.         cmp     eax, [ebx+dlgtemplate.border_size_x]
  707.         jge     @f
  708.         mov     eax, [ebx+dlgtemplate.border_size_x]
  709. @@:
  710.         push    eax
  711.         add     eax, [ebx+dlgtemplate.width]
  712.         add     eax, [ebx+dlgtemplate.border_size_x]
  713.         cmp     eax, [cur_width]
  714.         jbe     @f
  715.         pop     eax
  716.         mov     eax, [cur_width]
  717.         sub     eax, [ebx+dlgtemplate.width]
  718.         sub     eax, [ebx+dlgtemplate.border_size_x]
  719.         push    eax
  720. @@:
  721.         pop     [ebx+dlgtemplate.x]
  722.         sub     ecx, [esp+20h+16]
  723.         neg     ecx
  724.         sar     ecx, 1
  725.         add     ecx, [esp+20h+8]
  726.         cmp     ecx, [ebx+dlgtemplate.border_size_y]
  727.         jge     @f
  728.         mov     ecx, [ebx+dlgtemplate.border_size_y]
  729. @@:
  730.         push    ecx
  731.         add     ecx, [ebx+dlgtemplate.height]
  732.         add     ecx, [ebx+dlgtemplate.border_size_y]
  733.         cmp     ecx, [cur_height]
  734.         jbe     @f
  735.         pop     ecx
  736.         mov     ecx, [cur_height]
  737.         sub     ecx, [ebx+dlgtemplate.height]
  738.         sub     ecx, [ebx+dlgtemplate.border_size_y]
  739.         push    ecx
  740. @@:
  741.         pop     [ebx+dlgtemplate.y]
  742.         mov     eax, [cur_height]
  743.         sub     eax, 6
  744.         cmp     [ebx+dlgtemplate.height], eax
  745.         jbe     .small_height
  746.         mov     [ebx+dlgtemplate.height], eax
  747.         mov     [ebx+dlgtemplate.y], 3
  748. .small_height:
  749.         mov     ecx, [ebx+dlgtemplate.height]
  750.         mov     eax, [ebx+40]
  751.         mov     [ebx+48], eax
  752.         dec     ecx
  753.         jz      .skip
  754.         push    ecx
  755. @@:
  756.         cmp     dword [eax+4], 0
  757.         jz      @f
  758.         mov     eax, [eax+4]
  759.         loop    @b
  760. @@:
  761.         mov     [ebx+48], eax
  762.         pop     ecx
  763. .loop:
  764.         mov     eax, [eax]
  765.         loop    .loop
  766. .skip:
  767.         mov     [ebx+52], eax
  768.         mov     eax, [esp+20h+24]
  769.         mov     [ebx+dlgtemplate.title], eax
  770.         mov     al, [menu_normal_color]
  771.         mov     [ebx+dlgtemplate.main_color], al
  772.         mov     al, [menu_border_color]
  773.         mov     [ebx+dlgtemplate.border_color], al
  774.         mov     al, [menu_header_color]
  775.         mov     [ebx+dlgtemplate.header_color], al
  776.         push    MenuDlgProc
  777.         push    ebx
  778.         call    GenericBox
  779.         mov     [esp+28], eax
  780.         mov     ecx, ebx
  781.         call    pgfree
  782.         popad
  783.         ret     28
  784.  
  785. MenuDlgProc:
  786.         mov     eax, [esp+8]
  787.         cmp     al, 1
  788.         jz      .draw
  789.         cmp     al, 2
  790.         jz      .key
  791.         ret     16
  792. .draw:
  793.         call    .dodraw
  794.         ret     16
  795. .prev:
  796.         mov     eax, [ebx+40]
  797.         cmp     dword [eax+4], 0
  798.         jz      .end
  799.         call    .line_prev
  800. .posret:
  801.         mov     [ebx+40], eax
  802. .redraw:
  803.         call    .dodraw
  804.         call    draw_image
  805.         xor     eax, eax
  806.         ret     16
  807. .next:
  808.         mov     eax, [ebx+40]
  809.         cmp     dword [eax], 0
  810.         jz      .home
  811.         call    .line_next
  812.         jmp     .posret
  813. .pgdn:
  814.         mov     eax, [ebx+40]
  815.         mov     ecx, [ebx+dlgtemplate.height]
  816. .pgdnl:
  817.         cmp     dword [eax], 0
  818.         jz      .posret
  819.         call    .line_next
  820.         loop    .pgdnl
  821.         jmp     .posret
  822. .key:
  823.         mov     al, [esp+12]
  824.         cmp     al, 0x48
  825.         jz      .prev
  826.         cmp     al, 0x4B
  827.         jz      .prev
  828.         cmp     al, 0x4D
  829.         jz      .next
  830.         cmp     al, 0x50
  831.         jz      .next
  832.         cmp     al, 0x1C
  833.         jz      .enter
  834.         cmp     al, 1
  835.         jz      .esc
  836.         cmp     al, 0x47
  837.         jz      .home
  838.         cmp     al, 0x4F
  839.         jz      .end
  840.         cmp     al, 0x51
  841.         jz      .pgdn
  842.         cmp     al, 0x49
  843.         jz      .pgup
  844.         cmp     al, 0x52
  845.         jz      .ins
  846.         cmp     al, 0x53
  847.         jz      .del
  848.         mov     edx, [ebx+40]
  849. @@:
  850.         cmp     dword [edx+4], 0
  851.         jz      @f
  852.         mov     edx, [edx+4]
  853.         jmp     @b
  854. @@:
  855. .l:
  856.         lea     esi, [edx+7]
  857. @@:
  858.         inc     esi
  859.         cmp     byte [esi], 0
  860.         jz      .n
  861.         cmp     byte [esi], '&'
  862.         jnz     @b
  863.         movzx   ecx, byte [esi+1]
  864.         cmp     [ascii2scan+ecx], al
  865.         jnz     .n
  866.         mov     eax, edx
  867.         ret     16
  868. .n:
  869.         mov     edx, [edx]
  870.         test    edx, edx
  871.         jnz     .l
  872. .ret:
  873.         xor     eax, eax
  874.         ret     16
  875. .pgup:
  876.         mov     eax, [ebx+40]
  877.         mov     ecx, [ebx+dlgtemplate.height]
  878. .pgupl:
  879.         cmp     dword [eax+4], 0
  880.         jz      .posret
  881.         call    .line_prev
  882.         loop    .pgupl
  883.         jmp     .posret
  884. .home:
  885.         mov     eax, [ebx+40]
  886. @@:
  887.         cmp     dword [eax+4], 0
  888.         jz      @f
  889.         mov     eax, [eax+4]
  890.         jmp     @b
  891. @@:
  892.         mov     [ebx+48], eax
  893.         push    eax
  894.         mov     ecx, [ebx+dlgtemplate.height]
  895.         dec     ecx
  896.         jz      .h1
  897. .h2:
  898.         mov     eax, [eax]
  899.         loop    .h2
  900. .h1:
  901.         mov     [ebx+52], eax
  902.         pop     eax
  903.         and     dword [ebx+56], 0
  904.         jmp     .posret
  905. .end:
  906.         mov     eax, [ebx+40]
  907. @@:
  908.         cmp     dword [eax], 0
  909.         jz      @f
  910.         mov     eax, [eax]
  911.         jmp     @b
  912. @@:
  913.         mov     [ebx+52], eax
  914.         push    eax
  915.         mov     ecx, [ebx+dlgtemplate.height]
  916.         dec     ecx
  917.         jz      .e1
  918. .e2:
  919.         mov     eax, [eax+4]
  920.         loop    .e2
  921. .e1:
  922.         mov     [ebx+48], eax
  923.         mov     eax, [ebx+44]
  924.         dec     eax
  925.         mov     [ebx+56], eax
  926.         pop     eax
  927.         jmp     .posret
  928. .esc:
  929.         or      eax, -1
  930.         ret     16
  931. .enter:
  932.         mov     eax, [ebx+40]
  933.         ret     16
  934. .ins:
  935.         push    5
  936.         pop     edx
  937.         jmp     @f
  938. .del:
  939.         push    4
  940.         pop     edx
  941. @@:
  942.         mov     eax, [ebx+40]
  943.         cmp     byte [eax+8], '/'
  944.         jnz     @f
  945.         cmp     word [eax+9], 'cd'
  946.         jnz     @f
  947.         movzx   ecx, byte [eax+11]
  948.         sub     ecx, '0'
  949.         push    SF_CD
  950.         pop     eax
  951.         mov     ebx, edx
  952.         int     40h
  953. @@:
  954.         xor     eax, eax
  955.         ret     16
  956.  
  957. .line_prev:
  958.         cmp     eax, [ebx+48]
  959.         jnz     @f
  960.         mov     edx, [ebx+48]
  961.         mov     edx, [edx+4]
  962.         mov     [ebx+48], edx
  963.         mov     edx, [ebx+52]
  964.         mov     edx, [edx+4]
  965.         mov     [ebx+52], edx
  966. @@:
  967.         mov     eax, [eax+4]
  968.         dec     dword [ebx+56]
  969.         ret
  970. .line_next:
  971.         cmp     eax, [ebx+52]
  972.         jnz     @f
  973.         mov     edx, [ebx+48]
  974.         mov     edx, [edx]
  975.         mov     [ebx+48], edx
  976.         mov     edx, [ebx+52]
  977.         mov     edx, [edx]
  978.         mov     [ebx+52], edx
  979. @@:
  980.         mov     eax, [eax]
  981.         inc     dword [ebx+56]
  982.         ret
  983.  
  984. .dodraw:
  985.         mov     eax, [ebx+dlgtemplate.x]
  986.         mov     edx, [ebx+dlgtemplate.y]
  987.         call    get_console_ptr
  988.         mov     esi, [ebx+48]
  989. .0:
  990.         xor     edx, edx
  991.         mov     ah, [menu_selected_color]
  992.         cmp     esi, [ebx+40]
  993.         jz      @f
  994.         mov     ah, [menu_normal_color]
  995. @@:
  996.         push    edi
  997.         mov     ecx, [ebx+dlgtemplate.width]
  998.         mov     al, ' '
  999.         stosw
  1000.         dec     ecx
  1001.         stosw
  1002.         dec     ecx
  1003.         dec     ecx
  1004.         push    esi
  1005.         add     esi, 8
  1006. @@:
  1007.         lodsb
  1008.         test    al, al
  1009.         jz      @f
  1010.         cmp     al, '&'
  1011.         jnz     .noamp
  1012.         test    dl, dl
  1013.         jnz     .noamp
  1014.         mov     dl, 1
  1015.         lodsb
  1016.         push    eax
  1017.         mov     ah, [menu_selected_highlight_color]
  1018.         push    ecx
  1019.         mov     ecx, [esp+8]
  1020.         cmp     ecx, [ebx+40]
  1021.         pop     ecx
  1022.         jz      .amp1
  1023.         mov     ah, [menu_highlight_color]
  1024. .amp1:
  1025.         stosw
  1026.         pop     eax
  1027.         jmp     .amp2
  1028. .noamp:
  1029.         stosw
  1030. .amp2:
  1031.         loop    @b
  1032.         mov     al, ' '
  1033.         cmp     byte [esi], 0
  1034.         jnz     .1
  1035.         lodsb
  1036.         jmp     .1
  1037. @@:
  1038.         mov     al, ' '
  1039. .1:
  1040.         stosw
  1041.         mov     al, ' '
  1042.         rep     stosw
  1043.         pop     esi edi
  1044.         add     edi, [cur_width]
  1045.         add     edi, [cur_width]
  1046.         cmp     esi, [ebx+52]
  1047.         jz      @f
  1048.         mov     esi, [esi]
  1049.         test    esi, esi
  1050.         jnz     .0
  1051. @@:
  1052. ; ‹¨­¥©ª  ¯à®ªàã⪨
  1053.         mov     ecx, [ebx+dlgtemplate.height]
  1054.         cmp     ecx, [ebx+44]
  1055.         jz      .noscrollbar
  1056.         sub     ecx, 2
  1057.         jbe     .noscrollbar
  1058.         mov     eax, [ebx+56]
  1059.         mul     ecx
  1060.         div     dword [ebx+44]
  1061.         push    eax
  1062.         mov     eax, [ebx+dlgtemplate.x]
  1063.         add     eax, [ebx+dlgtemplate.width]
  1064.         mov     edx, [ebx+dlgtemplate.y]
  1065.         call    get_console_ptr
  1066.         pop     edx
  1067.         inc     edx
  1068.         mov     al, 0x1E
  1069.         mov     ah, [menu_scrollbar_color]
  1070.         mov     [edi], ax
  1071.         add     edi, [cur_width]
  1072.         add     edi, [cur_width]
  1073. .2:
  1074.         mov     al, 0xB2
  1075.         dec     edx
  1076.         jz      @f
  1077.         mov     al, 0xB0
  1078. @@:
  1079.         mov     [edi], ax
  1080.         add     edi, [cur_width]
  1081.         add     edi, [cur_width]
  1082.         loop    .2
  1083.         mov     al, 0x1F
  1084.         stosw
  1085. .noscrollbar:
  1086.         ret
  1087.  
  1088. get_ascii_char:
  1089. ; query keyboard layout
  1090.         pushad
  1091.         mov     al, [ctrlstate]
  1092.         and     al, 3
  1093.         xor     ecx, ecx
  1094.         cmp     al, 1
  1095.         sbb     ecx, -2
  1096.         push    SF_SYSTEM_GET
  1097.         pop     eax
  1098.         push    SSF_KEYBOARD_LAYOUT
  1099.         pop     ebx
  1100.         mov     edx, layout
  1101.         int     0x40
  1102.         popad
  1103. ; translate scancode to ASCII
  1104.         movzx   eax, byte [layout+eax]
  1105.         ret
  1106.  
  1107. virtual at 0
  1108. dlgitemtemplate:
  1109. ; «¥¬¥­âë:
  1110. ;       1 = áâ â¨ç¥áª¨© ⥪áâ
  1111. ;       2 = ª­®¯ª 
  1112. ;       3 = ¯®«¥ । ªâ¨à®¢ ­¨ï
  1113. ;       4 = £®à¨§®­â «ì­ë© à §¤¥«¨â¥«ì
  1114. ;       5 = ä« ¦®ª
  1115. ;       6 = ᯨ᮪
  1116. .type           dd      ?
  1117. .x1             dd      ?
  1118. .y1             dd      ?
  1119. .x2             dd      ?
  1120. .y2             dd      ?
  1121. ; „ ­­ë¥:
  1122. ; ¤«ï ⥪áâ : const char* data - ASCIIZ-áâப 
  1123. ; ¤«ï ª­®¯ª¨ ¨ ä« ¦ª : const char* data - § £®«®¢®ª
  1124. ; ¤«ï । ªâ®à : struct {unsigned maxlength; unsigned pos; unsigned start;
  1125. ;                        char data[maxlength+1];}* data;
  1126. ; ¤«ï ᯨ᪠: struct {listitem* curitemptr; unsigned numitems;
  1127. ;               listitem *head; unsigned curitem;}* data;
  1128. ; head = 㪠§ â¥«ì ­  ¯¥à¢ë© ®â®¡à ¦ ¥¬ë© í«¥¬¥­â,
  1129. ; curitemptr = 㪠§ â¥«ì ­  ¢ë¤¥«¥­­ë© í«¥¬¥­â, curitem = ¥£® ¨­¤¥ªá ¢ ᯨ᪥ (®â 0)
  1130. ; (£¤¥ struct listitem {listitem* next; listitem* prev; char text[];};)
  1131. .data           dd      ?
  1132. .flags          dd      ?
  1133. ; ”« £¨:
  1134. ;       0 = ¢ëà ¢­¨¢ ­¨¥ ¢«¥¢®
  1135. ;       1 = ¢ëà ¢­¨¢ ­¨¥ ¯® 業âàã
  1136. ;       2 = ¢ëà ¢­¨¢ ­¨¥ ¢¯à ¢®
  1137. ;       4 = í«¥¬¥­â ¨¬¥¥â 䮪ãá ¢¢®¤ 
  1138. ;       8 = í«¥¬¥­â ¬®¦¥â ¨¬¥âì 䮪ãá ¢¢®¤ 
  1139. ;       10h: ¤«ï ª­®¯ª¨ = ª­®¯ª  ¯® 㬮«ç ­¨î (Enter ­  ­¥-ª­®¯ª¥)
  1140. ;            ¤«ï ¯®«ï ¢¢®¤  = ¤ ­­ë¥ ¡ë«¨ ¬®¤¨ä¨æ¨à®¢ ­ë
  1141. ;            ¤«ï ä« ¦ª  = ä« ¦®ª ãáâ ­®¢«¥­
  1142. ;       20h: ¤«ï ¯®«ï ¢¢®¤  = ­¥ ®â®¡à ¦ âì ¢¢®¤¨¬ë¥ ¤ ­­ë¥ (¯®ª §ë¢ âì '*')
  1143. .size = $
  1144. end virtual
  1145. ;       struct DLGDATA
  1146. ;       {
  1147. ;               DLGTEMPLATE dialog;     /* window description */
  1148. ;               void* DlgProc;          /* dialog procedure */
  1149. ; /* int __stdcall DlgProc(DLGDATA* dlg, int msg, int param1, int param2); */
  1150. ;               void* user_data;        /* arbitrary user data */
  1151. ;               unsigned num_items;     /* number of items in the following array */
  1152. ;               DLGITEMTEMPLATE items[]; /* array of dialog items */
  1153. ;       }
  1154. ; int __stdcall DialogBox(DLGDATA* dlg);
  1155. DialogBox:
  1156.         push    ManagerDlgProc
  1157.         push    dword [esp+8]
  1158.         call    GenericBox
  1159.         ret     4
  1160.  
  1161. ; int __stdcall ShowDialogBox(DLGDATA* dlg);
  1162. ShowDialogBox:
  1163.         push    ManagerDlgProc
  1164.         push    dword [esp+8]
  1165.         call    ShowGenericBox
  1166.         ret     4
  1167.  
  1168. ; void __stdcall DrawDialogBox(DLGDATA* dlg);
  1169. DrawDialogBox:
  1170.         push    ManagerDlgProc
  1171.         push    dword [esp+8]
  1172.         call    DrawGenericBox
  1173.         ret     4
  1174.  
  1175. ManagerDlgProc:
  1176.         mov     ebp, ebx
  1177.         mov     eax, [esp+8]
  1178.         dec     eax
  1179.         jz      .draw
  1180.         dec     eax
  1181.         jz      .key
  1182.         xor     eax, eax
  1183.         ret     16
  1184. .draw:
  1185.         call    .dodraw
  1186.         ret     16
  1187. .key:
  1188. ; find item with focus
  1189.         add     ebx, dlgtemplate.size+12
  1190.         mov     ecx, [ebx-4]
  1191.         jecxz   .nobtns
  1192. @@:
  1193.         test    [ebx+dlgitemtemplate.flags], 4
  1194.         jnz     @f
  1195.         add     ebx, dlgitemtemplate.size
  1196.         loop    @b
  1197. @@:
  1198. .nobtns:
  1199.         mov     al, [esp+12]
  1200.         cmp     al, 1
  1201.         jz      .esc
  1202.         cmp     al, 0x1C
  1203.         jz      .enter
  1204.         cmp     al, 0xF
  1205.         jz      .tab
  1206.         cmp     al, 0x48
  1207.         jz      .up
  1208.         cmp     al, 0x50
  1209.         jz      .down
  1210.         jecxz   .nobtns2
  1211.         cmp     [ebx+dlgitemtemplate.type], 3
  1212.         jz      .key_edit
  1213.         cmp     [ebx+dlgitemtemplate.type], 5
  1214.         jnz     @f
  1215.         cmp     al, 0x39
  1216.         jnz     @f
  1217.         xor     [ebx+dlgitemtemplate.flags], 10h
  1218.         jmp     .ret_draw
  1219. @@:
  1220. .nobtns2:
  1221.         cmp     al, 0x4B
  1222.         jz      .left
  1223.         cmp     al, 0x4D
  1224.         jz      .right
  1225. .ret0:
  1226.         xor     eax, eax
  1227.         ret     16
  1228. .esc:
  1229.         or      eax, -1
  1230.         ret     16
  1231. .enter:
  1232.         cmp     [ebx+dlgitemtemplate.type], 2
  1233.         jnz     @f
  1234. .enter_found:
  1235.         mov     eax, ebx
  1236.         ret     16
  1237. @@:
  1238.         lea     ebx, [ebp+dlgtemplate.size+12]
  1239.         mov     ecx, [ebx-4]
  1240. .enter_find:
  1241.         cmp     [ebx+dlgitemtemplate.type], 2
  1242.         jnz     @f
  1243.         test    [ebx+dlgitemtemplate.flags], 0x10
  1244.         jnz     .enter_found
  1245. @@:
  1246.         add     ebx, dlgitemtemplate.size
  1247.         loop    .enter_find
  1248.         jmp     .enter_found
  1249. .tab:
  1250.         test    [ctrlstate], 3
  1251.         jnz     .shift_tab
  1252. .right:
  1253. .down:
  1254.         jecxz   .ret0
  1255.         and     byte [ebx+dlgitemtemplate.flags], not 4
  1256.         dec     ecx
  1257.         jz      .find_first_btn
  1258. @@:
  1259.         add     ebx, dlgitemtemplate.size
  1260.         test    [ebx+dlgitemtemplate.flags], 8
  1261.         jnz     .btn_found
  1262.         loop    @b
  1263. .find_first_btn:
  1264.         lea     ebx, [ebp+dlgtemplate.size+12]
  1265. @@:
  1266.         test    [ebx+dlgitemtemplate.flags], 8
  1267.         jnz     .btn_found
  1268.         add     ebx, dlgitemtemplate.size
  1269.         jmp     @b
  1270. .btn_found:
  1271.         or      byte [ebx+dlgitemtemplate.flags], 4
  1272. .ret_draw:
  1273.         mov     ebx, ebp
  1274.         call    .dodraw
  1275.         call    draw_image
  1276.         xor     eax, eax
  1277.         ret     16
  1278. .shift_tab:
  1279. .left:
  1280. .up:
  1281.         jecxz   .ret0
  1282.         and     byte [ebx+dlgitemtemplate.flags], not 4
  1283.         sub     ecx, [ebp+dlgtemplate.size+8]
  1284.         neg     ecx
  1285.         jz      .find_last_btn
  1286. @@:
  1287.         sub     ebx, dlgitemtemplate.size
  1288.         test    [ebx+dlgitemtemplate.flags], 8
  1289.         loopz   @b
  1290.         jnz     .btn_found
  1291. .find_last_btn:
  1292.         mov     ebx, [ebp+dlgtemplate.size+8]
  1293.         imul    ebx, dlgitemtemplate.size
  1294.         lea     ebx, [ebx+ebp+dlgtemplate.size+12]
  1295. @@:
  1296.         sub     ebx, dlgitemtemplate.size
  1297.         test    [ebx+dlgitemtemplate.flags], 8
  1298.         jz      @b
  1299.         jmp     .btn_found
  1300. .key_edit:
  1301. ; ®¡à ¡®âª  ª« ¢¨è ¢ ¯®«¥ ¢¢®¤ 
  1302.         test    al, 0x80
  1303.         jnz     .ret0
  1304.         or      [ebx+dlgitemtemplate.flags], 0x10
  1305.         mov     edx, [ebx+dlgitemtemplate.data]
  1306.         cmp     al, 0x4B
  1307.         jz      .editor_left
  1308.         cmp     al, 0x4D
  1309.         jz      .editor_right
  1310.         cmp     al, 0x47
  1311.         jz      .editor_home
  1312.         cmp     al, 0x4F
  1313.         jz      .editor_end
  1314.         cmp     al, 0x0E
  1315.         jz      .editor_backspace
  1316.         cmp     al, 0x53
  1317.         jnz     .editor_char
  1318. .editor_del:
  1319.         mov     ecx, [edx+4]
  1320.         lea     edi, [ecx+edx+12]
  1321.         lea     esi, [edi+1]
  1322.         cmp     byte [edi], 0
  1323.         jz      .ret_test
  1324.         jmp     .copy_and_ret_test
  1325. .editor_left:
  1326.         mov     ecx, [edx+4]
  1327.         jecxz   @f
  1328.         dec     dword [edx+4]
  1329. @@:     jmp     .ret_test
  1330. .editor_right:
  1331.         mov     ecx, [edx+4]
  1332.         cmp     byte [edx+ecx+12], 0
  1333.         jz      @b
  1334.         inc     dword [edx+4]
  1335.         jmp     @b
  1336. .editor_home:
  1337.         and     dword [edx+4], 0
  1338.         jmp     @b
  1339. .editor_end:
  1340.         lea     edi, [edx+12]
  1341.         xor     eax, eax
  1342.         or      ecx, -1
  1343.         repnz   scasb
  1344.         not     ecx
  1345.         dec     ecx
  1346.         mov     [edx+4], ecx
  1347. .ret_test:
  1348.         mov     eax, [edx+4]
  1349.         cmp     [edx+8], eax
  1350.         jl      .ret_test.l1
  1351.         mov     [edx+8], eax
  1352.         jmp     .ret_test.l2
  1353. .ret_test.l1:
  1354.         add     eax, [ebx+dlgitemtemplate.x1]
  1355.         sub     eax, [ebx+dlgitemtemplate.x2]
  1356.         cmp     [edx+8], eax
  1357.         jge     .ret_test.l2
  1358.         mov     [edx+8], eax
  1359. .ret_test.l2:
  1360.         jmp     .ret_draw
  1361. .editor_backspace:
  1362.         mov     ecx, [edx+4]
  1363.         jecxz   .ret_test
  1364.         dec     dword [edx+4]
  1365.         lea     esi, [edx+ecx+12]
  1366.         lea     edi, [esi-1]
  1367. .copy_and_ret_test:
  1368. @@:
  1369.         lodsb
  1370.         stosb
  1371.         test    al, al
  1372.         jnz     @b
  1373.         jmp     .ret_test
  1374. .editor_char:
  1375.         test    [ctrlstate], 0x3C
  1376.         jnz     .ret_draw
  1377.         movzx   eax, al
  1378.         call    get_ascii_char
  1379.         push    eax
  1380. ; insert entered symbol
  1381.         xor     eax, eax
  1382.         lea     edi, [edx+12]
  1383.         or      ecx, -1
  1384.         repnz   scasb
  1385.         not     ecx
  1386.         pop     eax
  1387.         cmp     ecx, [edx]
  1388.         ja      .ret_test       ; buffer capacity exceeded
  1389.         lea     edi, [edx+ecx+12-1]
  1390.         mov     esi, [edx+4]
  1391.         lea     esi, [edx+esi+12]
  1392. @@:
  1393.         mov     cl, [edi]
  1394.         mov     [edi+1], cl
  1395.         dec     edi
  1396.         cmp     edi, esi
  1397.         jae     @b
  1398.         mov     [esi], al
  1399.         inc     dword [edx+4]
  1400. @@:     jmp     .ret_test
  1401.  
  1402. .dodraw:
  1403.         or      [cursor_x], -1
  1404.         or      [cursor_y], -1
  1405.         add     ebx, dlgtemplate.size+8
  1406.         mov     ecx, [ebx]
  1407.         add     ebx, 4
  1408.         jecxz   .done_draw
  1409. .draw_loop:
  1410.         push    ecx
  1411.         mov     eax, [ebx+dlgitemtemplate.type]
  1412.         cmp     eax, draw_functions_num
  1413.         jae     .draw_loop_continue
  1414.         call    [draw_functions + eax*4]
  1415. .draw_loop_continue:
  1416.         pop     ecx
  1417.         add     ebx, dlgitemtemplate.size
  1418.         loop    .draw_loop
  1419. .done_draw:
  1420.         ret
  1421.  
  1422. iglobal
  1423. align 4
  1424. label draw_functions dword
  1425.         dd      ManagerDlgProc.done_draw
  1426.         dd      draw_static_text
  1427.         dd      draw_button
  1428.         dd      draw_editbox
  1429.         dd      draw_h_separator
  1430.         dd      draw_checkbox
  1431.         dd      draw_listbox
  1432. draw_functions_num = ($ - draw_functions) / 4
  1433. endg
  1434.  
  1435. draw_static_text:
  1436. ; à¨á㥬 áâ â¨ç¥áª¨© ⥪áâ
  1437.         mov     ah, [dialog_main_color]
  1438.         test    byte [ebp+dlgtemplate.flags], 2
  1439.         jz      draw_text
  1440.         mov     ah, [warning_main_color]
  1441. draw_text:
  1442. ; ®¯à¥¤¥«ï¥¬ ¤«¨­ã áâப¨
  1443.         mov     esi, [ebx+dlgitemtemplate.data]
  1444. draw_text_esi:
  1445.         test    esi, esi
  1446.         jz      .ret2
  1447.         push    eax
  1448.         push    -1
  1449.         pop     ecx
  1450. @@:
  1451.         inc     ecx
  1452.         cmp     byte [ecx+esi], 0
  1453.         jnz     @b
  1454. ; ¢ ecx ¤«¨­  áâப¨
  1455.         xor     eax, eax
  1456.         mov     edx, [ebx+dlgitemtemplate.x2]
  1457.         sub     edx, [ebx+dlgitemtemplate.x1]
  1458.         inc     edx
  1459.         cmp     ecx, edx
  1460.         jae     .text_draw
  1461.         mov     al, byte [ebx+dlgitemtemplate.flags]
  1462.         and     al, 3
  1463.         jz      .text_align_left
  1464.         cmp     al, 1
  1465.         jz      .text_align_center
  1466. ; ⥪áâ ¢ë஢­¥­ ¢¯à ¢®
  1467.         mov     eax, edx
  1468.         sub     eax, ecx
  1469.         jmp     .text_draw
  1470. .text_align_center:
  1471.         mov     eax, edx
  1472.         sub     eax, ecx
  1473.         shr     eax, 1
  1474.         jmp     .text_draw
  1475. .text_align_left:
  1476.         xor     eax, eax
  1477. .text_draw:
  1478.         push    ecx
  1479.         push    eax
  1480.         push    edx
  1481.         call    dlgitem_get_console_ptr
  1482.         pop     edx
  1483.         pop     ecx
  1484.         mov     ah, [esp+5]
  1485.         mov     al, ' '
  1486.         rep     stosw
  1487.         pop     ecx
  1488.         cmp     ecx, edx
  1489.         jbe     .text_copy
  1490.         cmp     [ebx+dlgitemtemplate.type], 3
  1491.         jnz     @f
  1492.         mov     ecx, edx
  1493.         jmp     .text_copy
  1494. @@:
  1495.         cmp     edx, 3
  1496.         jb      .ret
  1497.         mov     al, '.'
  1498.         stosw
  1499.         stosw
  1500.         stosw
  1501.         add     esi, ecx
  1502.         mov     ecx, edx
  1503.         sub     ecx, 3
  1504.         sub     esi, ecx
  1505. .text_copy:
  1506.         jecxz   .ret
  1507. ; check for password editboxes
  1508.         cmp     [ebx+dlgitemtemplate.type], 3
  1509.         jnz     @f
  1510.         test    [ebx+dlgitemtemplate.flags], 20h
  1511.         jz      @f
  1512.         mov     al, '*'
  1513.         rep     stosw
  1514.         jmp     .ret
  1515. @@:
  1516.         lodsb
  1517.         stosw
  1518.         loop    @b
  1519. .ret:
  1520.         mov     eax, [ebp+dlgtemplate.x]
  1521.         mov     edx, [ebp+dlgtemplate.y]
  1522.         add     eax, [ebx+dlgitemtemplate.x2]
  1523.         inc     eax
  1524.         add     edx, [ebx+dlgitemtemplate.y1]
  1525.         mov     ecx, edi
  1526.         call    get_console_ptr
  1527.         xchg    ecx, edi
  1528.         sub     ecx, edi
  1529.         shr     ecx, 1
  1530.         pop     eax
  1531.         mov     al, ' '
  1532.         rep     stosw
  1533. .ret2:
  1534.         ret
  1535.  
  1536. draw_button:
  1537.         mov     ecx, dialog_colors
  1538.         test    byte [ebp+dlgtemplate.flags], 2
  1539.         jz      @f
  1540.         mov     ecx, warning_colors
  1541. @@:
  1542.         mov     ah, [dialog_normal_btn_color-dialog_colors+ecx]
  1543.         test    [ebx+dlgitemtemplate.flags], 4
  1544.         jz      @f
  1545.         mov     ah, [dialog_selected_btn_color-dialog_colors+ecx]
  1546. @@:
  1547.         jmp     draw_text
  1548.  
  1549. draw_editbox:
  1550.         mov     edx, [ebx+dlgitemtemplate.data]
  1551.         test    [ebx+dlgitemtemplate.flags], 4
  1552.         jz      @f
  1553.         mov     eax, [ebx+dlgitemtemplate.x1]
  1554.         add     eax, [edx+4]
  1555.         sub     eax, [edx+8]
  1556.         add     eax, [ebp+dlgtemplate.x]
  1557.         mov     [cursor_x], eax
  1558.         mov     eax, [ebx+dlgitemtemplate.y1]
  1559.         add     eax, [ebp+dlgtemplate.y]
  1560.         mov     [cursor_y], eax
  1561. @@:
  1562.         mov     ecx, dialog_colors
  1563.         test    byte [ebp+dlgtemplate.flags], 2
  1564.         jz      @f
  1565.         mov     ecx, warning_colors
  1566. @@:
  1567.         mov     ah, [dialog_edit_color-dialog_colors+ecx]
  1568.         test    [ebx+dlgitemtemplate.flags], 10h
  1569.         jnz     @f
  1570.         mov     ah, [dialog_unmodified_edit_color-dialog_colors+ecx]
  1571. @@:
  1572.         mov     esi, [ebx+dlgitemtemplate.data]
  1573.         add     esi, [edx+8]
  1574.         add     esi, 12
  1575.         jmp     draw_text_esi
  1576.  
  1577. dlgitem_get_console_ptr:
  1578.         mov     eax, [ebx+dlgitemtemplate.x1]
  1579.         mov     edx, [ebx+dlgitemtemplate.y1]
  1580.         mov     ecx, eax
  1581.         add     eax, [ebp+dlgtemplate.x]
  1582.         add     edx, [ebp+dlgtemplate.y]
  1583.         jmp     get_console_ptr
  1584.  
  1585. draw_h_separator:
  1586. ; à¨á㥬 £®à¨§®­â «ì­ë© à §¤¥«¨â¥«ì
  1587.         call    dlgitem_get_console_ptr
  1588. .scan:
  1589.         mov     al, 0xC7
  1590.         test    ecx, ecx
  1591.         js      @f
  1592.         mov     al, 0xB6
  1593.         cmp     ecx, [ebp+dlgtemplate.width]
  1594.         jz      @f
  1595.         mov     al, 0xC4
  1596. @@:
  1597.         stosb
  1598.         jz      .done
  1599.         inc     ecx
  1600.         inc     edi
  1601.         cmp     ecx, [ebx+dlgitemtemplate.x2]
  1602.         jb      .scan
  1603. .done:
  1604.         ret
  1605.  
  1606. draw_checkbox:
  1607. ; à¨á㥬 ä« ¦®ª
  1608.         call    dlgitem_get_console_ptr
  1609.         test    byte [ebx+dlgitemtemplate.flags], 4
  1610.         jz      @f
  1611.         inc     eax
  1612.         mov     [cursor_x], eax
  1613.         mov     [cursor_y], edx
  1614. @@:
  1615.         mov     ah, [dialog_main_color]
  1616.         test    byte [ebp+dlgtemplate.flags], 2
  1617.         jz      @f
  1618.         mov     ah, [warning_main_color]
  1619. @@:
  1620.         mov     al, '['
  1621.         stosw
  1622.         mov     al, 'x'
  1623.         test    byte [ebx+dlgitemtemplate.flags], 10h
  1624.         jnz     @f
  1625.         mov     al, ' '
  1626. @@:
  1627.         stosw
  1628.         mov     al, ']'
  1629.         stosw
  1630.         mov     al, ' '
  1631.         stosw
  1632.         mov     ecx, [ebx+dlgitemtemplate.x2]
  1633.         sub     ecx, [ebx+dlgitemtemplate.x1]
  1634.         jb      .ret
  1635.         sub     ecx, 3
  1636.         jbe     .ret
  1637.         mov     esi, [ebx+dlgitemtemplate.data]
  1638. @@:
  1639.         lodsb
  1640.         test    al, al
  1641.         jz      .ret
  1642.         stosw
  1643.         loop    @b
  1644. .ret:
  1645.         ret
  1646.  
  1647. draw_listbox:
  1648. ; à¨á㥬 ᯨ᮪
  1649.         call    dlgitem_get_console_ptr
  1650.         mov     edx, [ebx+dlgitemtemplate.data]
  1651.         mov     esi, [edx+8]
  1652.         mov     eax, [ebx+dlgitemtemplate.y2]
  1653.         sub     eax, [ebx+dlgitemtemplate.y1]
  1654.         push    eax
  1655.         push    eax
  1656. .0:
  1657.         test    esi, esi
  1658.         jz      .listdone
  1659.         push    esi edi
  1660.         push    edx
  1661.         or      edx, -1
  1662.         mov     ecx, [ebx+dlgitemtemplate.x2]
  1663.         sub     ecx, [ebx+dlgitemtemplate.x1]
  1664.         inc     ecx
  1665.         xor     eax, eax
  1666. @@:
  1667.         inc     edx
  1668.         cmp     byte [esi+8+edx], al
  1669.         jnz     @b
  1670. @@:
  1671.         cmp     ecx, edx
  1672.         jae     .text_draw
  1673.         mov     al, byte [ebx+dlgitemtemplate.flags]
  1674.         and     al, 3
  1675.         jz      .text_align_left
  1676.         cmp     al, 1
  1677.         jz      .text_align_center
  1678. ; ⥪áâ ¢ë஢­¥­ ¢¯à ¢®
  1679.         mov     eax, edx
  1680.         sub     eax, ecx
  1681.         jmp     .text_draw
  1682. .text_align_center:
  1683.         mov     eax, edx
  1684.         sub     eax, ecx
  1685.         shr     eax, 1
  1686.         jmp     .text_draw
  1687. .text_align_left:
  1688. ;        xor     eax, eax
  1689. .text_draw:
  1690.         pop     edx
  1691.         cmp     esi, [edx]
  1692.         lea     esi, [esi+8+eax]
  1693.         mov     ah, [dialog_selected_list_color]
  1694.         jz      @f
  1695.         mov     ah, [dialog_list_color]
  1696. @@:
  1697.         jecxz   .next
  1698. @@:
  1699.         lodsb
  1700.         test    al, al
  1701.         jz      @f
  1702.         stosw
  1703.         loop    @b
  1704. @@:
  1705.         mov     al, ' '
  1706.         rep     stosw
  1707. .next:
  1708.         pop     edi esi
  1709.         add     edi, [cur_width]
  1710.         add     edi, [cur_width]
  1711.         mov     esi, [esi]
  1712.         dec     dword [esp]
  1713.         jns     .0
  1714. .listdone:
  1715.         pop     eax
  1716. ; ‹¨­¥©ª  ¯à®ªàã⪨
  1717.         pop     ecx
  1718.         inc     ecx
  1719.         mov     esi, [edx+4]
  1720.         cmp     ecx, esi
  1721.         jae     .noscrollbar
  1722.         sub     ecx, 2
  1723.         jbe     .noscrollbar
  1724.         mov     eax, [edx+12]
  1725.         mul     ecx
  1726.         div     esi
  1727.         push    eax
  1728.         mov     eax, [ebx+dlgitemtemplate.x2]
  1729.         add     eax, [ebp+dlgtemplate.x]
  1730.         mov     edx, [ebx+dlgitemtemplate.y1]
  1731.         add     edx, [ebp+dlgtemplate.y]
  1732.         call    get_console_ptr
  1733.         pop     edx
  1734.         inc     edx
  1735.         mov     al, 0x1E
  1736.         mov     ah, [dialog_scroll_list_color]
  1737.         mov     [edi], ax
  1738.         add     edi, [cur_width]
  1739.         add     edi, [cur_width]
  1740. .2:
  1741.         mov     al, 0xB1
  1742.         dec     edx
  1743.         jz      @f
  1744.         mov     al, 0xB0
  1745. @@:
  1746.         mov     [edi], ax
  1747.         add     edi, [cur_width]
  1748.         add     edi, [cur_width]
  1749.         loop    .2
  1750.         mov     al, 0x1F
  1751.         stosw
  1752. .noscrollbar:
  1753.         ret
  1754.  
  1755. listbox_key:
  1756.         mov     edx, [ebx+dlgitemtemplate.data]
  1757.         cmp     al, 0x48
  1758.         jz      .prev
  1759.         cmp     al, 0x50
  1760.         jz      .next
  1761.         cmp     al, 0x47
  1762.         jz      .home
  1763.         cmp     al, 0x4F
  1764.         jz      .end
  1765.         cmp     al, 0x51
  1766.         jz      .pgdn
  1767.         cmp     al, 0x49
  1768.         jz      .pgup
  1769.         ret
  1770. .next:
  1771.         call    .calc_last_line
  1772.         mov     eax, [edx]
  1773.         cmp     dword [eax], 0
  1774.         jz      @f
  1775.         call    .line_next
  1776. @@:
  1777.         mov     [edx], eax
  1778.         ret
  1779. .pgdn:
  1780.         call    .calc_last_line
  1781.         mov     eax, [edx]
  1782.         mov     ecx, [ebx+dlgitemtemplate.y2]
  1783.         sub     ecx, [ebx+dlgitemtemplate.y1]
  1784. .pgdnl:
  1785.         cmp     dword [eax], 0
  1786.         jz      @f
  1787.         call    .line_next
  1788.         loop    .pgdnl
  1789. @@:
  1790.         mov     [edx], eax
  1791.         ret
  1792. .prev:
  1793.         mov     eax, [edx]
  1794.         cmp     dword [eax+4], 0
  1795.         jz      @f
  1796.         call    .line_prev
  1797. @@:
  1798.         mov     [edx], eax
  1799.         ret
  1800. .pgup:
  1801.         mov     eax, [edx]
  1802.         mov     ecx, [ebx+dlgitemtemplate.y2]
  1803.         sub     ecx, [ebx+dlgitemtemplate.y1]
  1804. ;        inc     ecx
  1805. .pgupl:
  1806.         cmp     dword [eax+4], 0
  1807.         jz      @f
  1808.         call    .line_prev
  1809.         loop    .pgupl
  1810. @@:
  1811.         mov     [edx], eax
  1812.         ret
  1813. .home:
  1814.         mov     eax, [edx]
  1815. @@:
  1816.         cmp     dword [eax+4], 0
  1817.         jz      @f
  1818.         mov     eax, [eax+4]
  1819.         jmp     @b
  1820. @@:
  1821.         mov     [edx], eax
  1822.         mov     [edx+8], eax
  1823.         and     dword [edx+12], 0
  1824.         ret
  1825. .end:
  1826.         mov     eax, [edx]
  1827. @@:
  1828.         cmp     dword [eax], 0
  1829.         jz      @f
  1830.         mov     eax, [eax]
  1831.         jmp     @b
  1832. @@:
  1833.         mov     [edx], eax
  1834.         mov     ecx, [ebx+dlgitemtemplate.y2]
  1835.         sub     ecx, [ebx+dlgitemtemplate.y1]
  1836.         jz      .e1
  1837. .e2:
  1838.         mov     eax, [eax+4]
  1839.         loop    .e2
  1840. .e1:
  1841.         mov     [edx+8], eax
  1842.         mov     eax, [edx+4]
  1843.         dec     eax
  1844.         mov     [edx+12], eax
  1845.         ret
  1846.  
  1847. .line_prev:
  1848.         cmp     eax, [edx+8]
  1849.         mov     eax, [eax+4]
  1850.         jnz     @f
  1851.         mov     [edx+8], eax
  1852. @@:
  1853.         dec     dword [edx+12]
  1854.         ret
  1855. .calc_last_line:
  1856.         mov     esi, [edx+8]
  1857.         mov     ecx, [ebx+dlgitemtemplate.y2]
  1858.         sub     ecx, [ebx+dlgitemtemplate.y1]
  1859.         jz      .clldone
  1860. @@:
  1861.         mov     esi, [esi]
  1862.         test    esi, esi
  1863.         jz      @f
  1864.         loop    @b
  1865. .clldone:
  1866.         ret
  1867. .line_next:
  1868.         cmp     eax, esi
  1869.         mov     eax, [eax]
  1870.         jnz     @f
  1871.         push    eax
  1872.         mov     eax, [edx+8]
  1873.         mov     eax, [eax]
  1874.         mov     [edx+8], eax
  1875.         pop     eax
  1876.         mov     esi, eax
  1877. @@:
  1878.         inc     dword [edx+12]
  1879.         ret
  1880.  
  1881. ; void __stdcall SayNoMem(void);
  1882. SayNoMem:
  1883.         or      dword [nomem_dlgdata+4], -1
  1884.         or      dword [nomem_dlgdata+8], -1
  1885.         push    nomem_dlgdata
  1886.         call    DialogBox
  1887.         ret
  1888.  
  1889. ; int __stdcall ConfirmCancel(void);
  1890. ; return value: 0 = the user is sure, nonzero = the user wants to continue
  1891. ConfirmCancel:
  1892.         push    YesOrNoBtn
  1893.         push    2
  1894.         push    ConfirmCancelMsg
  1895.         push    1
  1896.         push    aCancelled
  1897.         call    SayErrTitle
  1898.         test    eax, eax
  1899.         ret
  1900.  
  1901. ; int __stdcall SayErr(int num_strings, const char* strings[],
  1902. ;                      int num_buttons, const char* buttons[]);
  1903. SayErr:
  1904.         pop     eax
  1905.         push    aError
  1906.         push    eax
  1907. ; int __stdcall SayErrTitle(const char* title,
  1908. ;                       int num_strings, const char* strings[],
  1909. ;                       int num_buttons, const char* buttons[]);
  1910. SayErrTitle:
  1911.         push    2
  1912.         jmp     @f
  1913.  
  1914. ; int __stdcall Message(const char* title,
  1915. ;                       int num_strings, const char* strings[],
  1916. ;                       int num_buttons, const char* buttons[]);
  1917. Message:
  1918.         push    1
  1919. @@:
  1920.         pop     eax
  1921. ; [esp+4] = title
  1922. ; [esp+8] = num_strings
  1923. ; [esp+12] = strings
  1924. ; [esp+16] = num_buttons
  1925. ; [esp+20] = buttons
  1926.         pushad
  1927.         mov     ecx, [esp+32+8]
  1928.         add     ecx, [esp+32+16]
  1929.         imul    ecx, dlgitemtemplate.size
  1930.         add     ecx, dlgtemplate.size+12
  1931.         call    xpgalloc
  1932.         test    eax, eax
  1933.         jnz     @f
  1934.         popad
  1935.         or      eax, -1
  1936.         ret     28
  1937. @@:
  1938.         mov     ebx, eax
  1939.         mov     edi, eax
  1940.         mov     eax, [esp+28]
  1941.         stosd                           ; dlgtemplate.flags
  1942.         or      eax, -1
  1943.         stosd                           ; dlgtemplate.x
  1944.         stosd                           ; dlgtemplate.y
  1945. ; calculate width
  1946.         mov     ecx, [esp+32+8]
  1947.         mov     esi, [esp+32+12]
  1948.         xor     edx, edx
  1949. .calcwidth:
  1950.         lodsd
  1951. @@:
  1952.         inc     eax
  1953.         cmp     byte [eax-1], 0
  1954.         jnz     @b
  1955.         sub     eax, [esi-4]
  1956.         inc     eax
  1957.         cmp     edx, eax
  1958.         ja      @f
  1959.         mov     edx, eax
  1960. @@:
  1961.         loop    .calcwidth
  1962.         mov     ecx, [esp+32+16]
  1963.         mov     esi, [esp+32+20]
  1964.         xor     ebp, ebp
  1965. .calcwidth2:
  1966.         lodsd
  1967. @@:
  1968.         inc     eax
  1969.         cmp     byte [eax-1], 0
  1970.         jnz     @b
  1971.         sub     eax, [esi-4]
  1972.         inc     eax
  1973.         add     ebp, eax
  1974.         loop    .calcwidth2
  1975.         inc     ebp
  1976.         inc     ebp
  1977.         cmp     edx, ebp
  1978.         ja      @f
  1979.         mov     edx, ebp
  1980. @@:
  1981.         mov     eax, [cur_width]
  1982.         sub     eax, 8
  1983.         cmp     edx, eax
  1984.         jb      @f
  1985.         mov     edx, eax
  1986. @@:
  1987.         mov     eax, edx
  1988.         stosd                           ; dlgtemplate.width
  1989.         mov     eax, [esp+32+8]
  1990.         inc     eax
  1991.         stosd                           ; dlgtemplate.height
  1992.         mov     eax, 3
  1993.         stosd                           ; dlgtemplate.border_size_x
  1994.         mov     al, 2
  1995.         stosd                           ; dlgtemplate.border_size_y
  1996.         mov     eax, [esp+32+4]
  1997.         stosd                           ; dlgtemplate.title
  1998.         xor     eax, eax
  1999.         stosd                           ; (ignored)
  2000.         stosd                           ; (ignored)
  2001.         stosd                           ; DlgProc
  2002.         stosd                           ; userdata
  2003.         mov     eax, [esp+32+8]
  2004.         add     eax, [esp+32+16]
  2005.         stosd                           ; num_items
  2006. ; fill strings
  2007.         xor     ecx, ecx
  2008.         mov     esi, [esp+32+12]
  2009. @@:
  2010.         mov     eax, 1
  2011.         stosd                           ; dlgitemtemplate.type
  2012.         dec     eax
  2013.         stosd                           ; dlgitemtemplate.x1
  2014.         mov     eax, ecx
  2015.         stosd                           ; dlgitemtemplate.y1
  2016.         lea     eax, [edx-1]
  2017.         stosd                           ; dlgitemtemplate.x2
  2018.         mov     eax, ecx
  2019.         stosd                           ; dlgitemtemplate.y2
  2020.         movsd                           ; dlgitemtemplate.data
  2021.         mov     eax, 1
  2022.         stosd                           ; dlgitemtemplate.flags
  2023.         inc     ecx
  2024.         cmp     ecx, [esp+32+8]
  2025.         jb      @b
  2026. ; fill buttons
  2027.         mov     ecx, [esp+32+16]
  2028.         mov     esi, [esp+32+20]
  2029.         sub     edx, ebp
  2030.         jc      .big
  2031.         shr     edx, 1
  2032.         inc     edx
  2033.         jmp     .fillbtns
  2034. .big:
  2035.         xor     edx, edx
  2036. .fillbtns:
  2037.         mov     eax, 2
  2038.         stosd                           ; dlgitemtemplate.type
  2039.         mov     eax, edx
  2040.         stosd                           ; dlgitemtemplate.x1
  2041.         mov     eax, [ebx+dlgtemplate.height]
  2042.         dec     eax
  2043.         stosd                           ; dlgitemtemplate.y1
  2044.         push    eax
  2045.         lodsd
  2046.         sub     eax, edx
  2047. @@:
  2048.         inc     edx
  2049.         cmp     byte [eax+edx-1], 0
  2050.         jnz     @b
  2051.         mov     eax, edx
  2052.         inc     edx
  2053.         stosd                           ; dlgitemtemplate.x2
  2054.         pop     eax
  2055.         stosd                           ; dlgitemtemplate.y2
  2056.         mov     eax, [esi-4]
  2057.         stosd                           ; dlgitemtemplate.data
  2058.         mov     eax, 9
  2059.         cmp     ecx, [esp+32+16]
  2060.         jnz     @f
  2061.         or      al, 4
  2062. @@:
  2063.         stosd                           ; dlgitemtemplate.flags
  2064.         loop    .fillbtns
  2065.         push    ebx
  2066.         call    DialogBox
  2067.         cmp     eax, -1
  2068.         jz      @f
  2069.         sub     eax, ebx
  2070.         sub     eax, dlgtemplate.size+12
  2071.         xor     edx, edx
  2072.         mov     ecx, dlgitemtemplate.size
  2073.         div     ecx
  2074.         sub     eax, [esp+32+8]
  2075. @@:
  2076.         mov     [esp+28], eax
  2077.         mov     ecx, ebx
  2078.         call    pgfree
  2079.         popad
  2080.         ret     20
  2081.