Subversion Repositories Kolibri OS

Rev

Rev 997 | Rev 9014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
183 diamond 1
; int __stdcall GenericBox(DLGTEMPLATE* dlg, void* DlgProc);
2
;       int __stdcall DlgProc(DLGTEMPLATE* dlg, int msg, int param1, int param2);
180 heavyiron 3
 
4
virtual at 0
5
dlgtemplate:
314 diamond 6
; Флаги:
7
; бит 0: использовать стандартные цвета диалога
8
; бит 1: использовать стандартные цвета предупреждения/ошибки
9
; (если любой из этих битов установлен, поля main_color,border_color,header_color
10
;  игнорируются)
814 diamond 11
; бит 2: не рисовать тень
180 heavyiron 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
814 diamond 24
.dataptr        dd      ?       ; used internally, ignored on input
183 diamond 25
.size = $
180 heavyiron 26
end virtual
27
 
183 diamond 28
GenericBox:
814 diamond 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
@@:
180 heavyiron 40
        pushad
814 diamond 41
; message loop
42
.event:
997 diamond 43
;        call    get_event
8984 IgorA 44
        push    SF_WAIT_EVENT
814 diamond 45
        pop     eax
46
        int     40h
47
        dec     eax
48
        jz      .redraw
49
        dec     eax
50
        jz      .key
8984 IgorA 51
        sub     eax,4
52
        jz      .event ;todo: mouse
814 diamond 53
        jmp     exit
54
.redraw:
55
        call    draw_window
56
        jmp     .event
57
.key:
8984 IgorA 58
        mov     al, SF_GET_KEY
814 diamond 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
183 diamond 159
        mov     ebx, [esp+20h+4]
160
; center window if required
474 diamond 161
        push    [ebx+dlgtemplate.x]
162
        push    [ebx+dlgtemplate.y]
183 diamond 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
@@:
180 heavyiron 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:
474 diamond 195
        pop     [ebx+dlgtemplate.y]
196
        pop     [ebx+dlgtemplate.x]
180 heavyiron 197
        popad
198
        or      eax, -1
199
        ret     8
200
.sizeok:
314 diamond 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:
474 diamond 211
        mov     al, [edi + dialog_main_color-dialog_colors]
314 diamond 212
        mov     [ebx+dlgtemplate.main_color], al
474 diamond 213
        mov     al, [edi + dialog_border_color-dialog_colors]
314 diamond 214
        mov     [ebx+dlgtemplate.border_color], al
474 diamond 215
        mov     al, [edi + dialog_header_color-dialog_colors]
314 diamond 216
        mov     [ebx+dlgtemplate.header_color], al
217
@@:
180 heavyiron 218
; allocate memory for data under dialog
314 diamond 219
; for 'No memory' dialog use static data area
814 diamond 220
        mov     eax, nomem_dlgsavearea
314 diamond 221
        cmp     ebx, nomem_dlgdata
222
        jz      .allocated
180 heavyiron 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
814 diamond 233
        lea     ecx, [eax*2+8]
474 diamond 234
        call    xpgalloc
180 heavyiron 235
        test    eax, eax
236
        jnz     @f
474 diamond 237
        pop     [ebx+dlgtemplate.y]
238
        pop     [ebx+dlgtemplate.x]
180 heavyiron 239
        popad
240
        or      eax, -1
241
        ret     8
242
@@:
314 diamond 243
.allocated:
814 diamond 244
        mov     [ebx+dlgtemplate.dataptr], eax
245
        pop     dword [eax+4]
246
        pop     dword [eax]
247
        lea     ebp, [eax+8]
180 heavyiron 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
814 diamond 268
        test    byte [ebx+dlgtemplate.flags], 4
269
        jnz     .noshadow
997 diamond 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:
180 heavyiron 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
997 diamond 332
        ret
814 diamond 333
 
334
; void __stdcall DrawGenericBox(DLGDATA* dlg, void* DlgProc)
335
DrawGenericBox:
336
        pushad
337
        mov     ebx, [esp+24h]
180 heavyiron 338
; draw area background
814 diamond 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
@@:
180 heavyiron 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
283 diamond 408
        inc     eax     ; eax = длина заголовка + 2
180 heavyiron 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
283 diamond 429
.2:
180 heavyiron 430
        dec     ecx
283 diamond 431
        jz	.3
180 heavyiron 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
814 diamond 463
        mov     eax, [esp+28h]
180 heavyiron 464
        push    0
465
        push    0
466
        push    1
183 diamond 467
        push    ebx
180 heavyiron 468
        call    eax
469
        call    draw_image
814 diamond 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
180 heavyiron 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
814 diamond 501
        lea     ecx, [ebp-8]
502
        push    dword [ecx]
503
        push    dword [ecx+4]
504
        pop     [ebx+dlgtemplate.y]
505
        pop     [ebx+dlgtemplate.x]
314 diamond 506
        cmp     ebx, nomem_dlgdata
507
        jz      @f
474 diamond 508
        call    pgfree
314 diamond 509
@@:
283 diamond 510
        or      [cursor_x], -1
511
        or      [cursor_y], -1
814 diamond 512
        cmp     dword [esp+28h], 0
513
        jz      @f
180 heavyiron 514
        call    draw_image
814 diamond 515
@@:
180 heavyiron 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
814 diamond 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
474 diamond 635
        call    xpgalloc
180 heavyiron 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]
814 diamond 657
        mov     [ebx+40], esi
997 diamond 658
        mov     dword [ebx+56], eax
180 heavyiron 659
@@:
997 diamond 660
        cmp     dword [esi+4], eax
180 heavyiron 661
        jz      .find_width
662
        mov     esi, [esi+4]
814 diamond 663
        inc     dword [ebx+56]
180 heavyiron 664
        jmp     @b
665
.find_width:
814 diamond 666
        mov     [ebx+48], esi
180 heavyiron 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
814 diamond 701
        mov     [ebx+44], ecx
180 heavyiron 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]
814 diamond 750
        mov     eax, [ebx+40]
751
        mov     [ebx+48], eax
180 heavyiron 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
@@:
814 diamond 761
        mov     [ebx+48], eax
180 heavyiron 762
        pop     ecx
763
.loop:
764
        mov     eax, [eax]
765
        loop    .loop
766
.skip:
814 diamond 767
        mov     [ebx+52], eax
180 heavyiron 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
183 diamond 778
        call    GenericBox
180 heavyiron 779
        mov     [esp+28], eax
474 diamond 780
        mov     ecx, ebx
781
        call    pgfree
180 heavyiron 782
        popad
783
        ret     28
784
 
785
MenuDlgProc:
183 diamond 786
        mov     eax, [esp+8]
180 heavyiron 787
        cmp     al, 1
788
        jz      .draw
789
        cmp     al, 2
790
        jz      .key
183 diamond 791
        ret     16
180 heavyiron 792
.draw:
793
        call    .dodraw
183 diamond 794
        ret     16
474 diamond 795
.prev:
814 diamond 796
        mov     eax, [ebx+40]
474 diamond 797
        cmp     dword [eax+4], 0
798
        jz      .end
799
        call    .line_prev
800
.posret:
814 diamond 801
        mov     [ebx+40], eax
474 diamond 802
.redraw:
803
        call    .dodraw
804
        call    draw_image
805
        xor     eax, eax
806
        ret     16
807
.next:
814 diamond 808
        mov     eax, [ebx+40]
474 diamond 809
        cmp     dword [eax], 0
810
        jz      .home
811
        call    .line_next
812
        jmp     .posret
813
.pgdn:
814 diamond 814
        mov     eax, [ebx+40]
474 diamond 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
180 heavyiron 822
.key:
183 diamond 823
        mov     al, [esp+12]
180 heavyiron 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
589 diamond 844
        cmp     al, 0x52
845
        jz      .ins
846
        cmp     al, 0x53
847
        jz      .del
814 diamond 848
        mov     edx, [ebx+40]
180 heavyiron 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
183 diamond 867
        ret     16
180 heavyiron 868
.n:
869
        mov     edx, [edx]
870
        test    edx, edx
871
        jnz     .l
872
.ret:
873
        xor     eax, eax
183 diamond 874
        ret     16
180 heavyiron 875
.pgup:
814 diamond 876
        mov     eax, [ebx+40]
180 heavyiron 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:
814 diamond 885
        mov     eax, [ebx+40]
180 heavyiron 886
@@:
887
        cmp     dword [eax+4], 0
888
        jz      @f
889
        mov     eax, [eax+4]
890
        jmp     @b
891
@@:
814 diamond 892
        mov     [ebx+48], eax
180 heavyiron 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:
814 diamond 901
        mov     [ebx+52], eax
180 heavyiron 902
        pop     eax
814 diamond 903
        and     dword [ebx+56], 0
180 heavyiron 904
        jmp     .posret
905
.end:
814 diamond 906
        mov     eax, [ebx+40]
180 heavyiron 907
@@:
908
        cmp     dword [eax], 0
909
        jz      @f
910
        mov     eax, [eax]
911
        jmp     @b
912
@@:
814 diamond 913
        mov     [ebx+52], eax
180 heavyiron 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:
814 diamond 922
        mov     [ebx+48], eax
923
        mov     eax, [ebx+44]
180 heavyiron 924
        dec     eax
814 diamond 925
        mov     [ebx+56], eax
180 heavyiron 926
        pop     eax
927
        jmp     .posret
928
.esc:
929
        or      eax, -1
183 diamond 930
        ret     16
180 heavyiron 931
.enter:
814 diamond 932
        mov     eax, [ebx+40]
183 diamond 933
        ret     16
589 diamond 934
.ins:
935
        push    5
936
        pop     edx
937
        jmp     @f
938
.del:
939
        push    4
940
        pop     edx
941
@@:
814 diamond 942
        mov     eax, [ebx+40]
589 diamond 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'
8984 IgorA 949
        push    SF_CD
589 diamond 950
        pop     eax
951
        mov     ebx, edx
952
        int     40h
953
@@:
954
        xor     eax, eax
955
        ret     16
180 heavyiron 956
 
957
.line_prev:
814 diamond 958
        cmp     eax, [ebx+48]
180 heavyiron 959
        jnz     @f
960
        mov     edx, [ebx+48]
961
        mov     edx, [edx+4]
962
        mov     [ebx+48], edx
814 diamond 963
        mov     edx, [ebx+52]
964
        mov     edx, [edx+4]
965
        mov     [ebx+52], edx
180 heavyiron 966
@@:
967
        mov     eax, [eax+4]
814 diamond 968
        dec     dword [ebx+56]
180 heavyiron 969
        ret
970
.line_next:
814 diamond 971
        cmp     eax, [ebx+52]
180 heavyiron 972
        jnz     @f
973
        mov     edx, [ebx+48]
974
        mov     edx, [edx]
975
        mov     [ebx+48], edx
814 diamond 976
        mov     edx, [ebx+52]
977
        mov     edx, [edx]
978
        mov     [ebx+52], edx
180 heavyiron 979
@@:
980
        mov     eax, [eax]
814 diamond 981
        inc     dword [ebx+56]
180 heavyiron 982
        ret
983
 
984
.dodraw:
985
        mov     eax, [ebx+dlgtemplate.x]
986
        mov     edx, [ebx+dlgtemplate.y]
987
        call    get_console_ptr
814 diamond 988
        mov     esi, [ebx+48]
180 heavyiron 989
.0:
990
        xor     edx, edx
991
        mov     ah, [menu_selected_color]
814 diamond 992
        cmp     esi, [ebx+40]
180 heavyiron 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]
814 diamond 1020
        cmp     ecx, [ebx+40]
180 heavyiron 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]
814 diamond 1046
        cmp     esi, [ebx+52]
180 heavyiron 1047
        jz      @f
1048
        mov     esi, [esi]
1049
        test    esi, esi
1050
        jnz     .0
1051
@@:
1052
; Линейка прокрутки
1053
        mov     ecx, [ebx+dlgtemplate.height]
814 diamond 1054
        cmp     ecx, [ebx+44]
180 heavyiron 1055
        jz      .noscrollbar
1056
        sub     ecx, 2
1057
        jbe     .noscrollbar
814 diamond 1058
        mov     eax, [ebx+56]
180 heavyiron 1059
        mul     ecx
814 diamond 1060
        div     dword [ebx+44]
180 heavyiron 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
183 diamond 1087
 
814 diamond 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
8984 IgorA 1096
        push    SF_SYSTEM_GET
814 diamond 1097
        pop     eax
8984 IgorA 1098
        push    SSF_KEYBOARD_LAYOUT
814 diamond 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
 
183 diamond 1107
virtual at 0
1108
dlgitemtemplate:
1109
; Элементы:
1110
;       1 = статический текст
283 diamond 1111
;       2 = кнопка
1112
;       3 = поле редактирования
997 diamond 1113
;       4 = горизонтальный разделитель
1114
;       5 = флажок
1115
;       6 = список
183 diamond 1116
.type           dd      ?
1117
.x1             dd      ?
1118
.y1             dd      ?
1119
.x2             dd      ?
1120
.y2             dd      ?
283 diamond 1121
; Данные:
1122
; для текста: const char* data - ASCIIZ-строка
997 diamond 1123
; для кнопки и флажка: const char* data - заголовок
283 diamond 1124
; для редактора: struct {unsigned maxlength; unsigned pos; unsigned start;
1125
;                        char data[maxlength+1];}* data;
997 diamond 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[];};)
183 diamond 1131
.data           dd      ?
1132
.flags          dd      ?
1133
; Флаги:
1134
;       0 = выравнивание влево
1135
;       1 = выравнивание по центру
1136
;       2 = выравнивание вправо
1137
;       4 = элемент имеет фокус ввода
283 diamond 1138
;       8 = элемент может иметь фокус ввода
1139
;       10h: для кнопки = кнопка по умолчанию (Enter на не-кнопке)
1140
;            для поля ввода = данные были модифицированы
997 diamond 1141
;            для флажка = флажок установлен
589 diamond 1142
;       20h: для поля ввода = не отображать вводимые данные (показывать '*')
183 diamond 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
314 diamond 1159
        ret     4
183 diamond 1160
 
814 diamond 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
 
183 diamond 1175
ManagerDlgProc:
314 diamond 1176
        mov     ebp, ebx
183 diamond 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
283 diamond 1208
        cmp     al, 0x50
1209
        jz      .down
997 diamond 1210
        jecxz   .nobtns2
283 diamond 1211
        cmp     [ebx+dlgitemtemplate.type], 3
1212
        jz      .key_edit
997 diamond 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
283 diamond 1219
@@:
997 diamond 1220
.nobtns2:
183 diamond 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:
283 diamond 1232
        cmp     [ebx+dlgitemtemplate.type], 2
1233
        jnz     @f
1234
.enter_found:
183 diamond 1235
        mov     eax, ebx
1236
        ret     16
283 diamond 1237
@@:
314 diamond 1238
        lea     ebx, [ebp+dlgtemplate.size+12]
474 diamond 1239
        mov     ecx, [ebx-4]
283 diamond 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
474 diamond 1247
        loop    .enter_find
1248
        jmp     .enter_found
183 diamond 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
283 diamond 1260
        test    [ebx+dlgitemtemplate.flags], 8
1261
        jnz     .btn_found
183 diamond 1262
        loop    @b
1263
.find_first_btn:
314 diamond 1264
        lea     ebx, [ebp+dlgtemplate.size+12]
183 diamond 1265
@@:
283 diamond 1266
        test    [ebx+dlgitemtemplate.flags], 8
1267
        jnz     .btn_found
183 diamond 1268
        add     ebx, dlgitemtemplate.size
1269
        jmp     @b
1270
.btn_found:
1271
        or      byte [ebx+dlgitemtemplate.flags], 4
283 diamond 1272
.ret_draw:
314 diamond 1273
        mov     ebx, ebp
183 diamond 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
314 diamond 1283
        sub     ecx, [ebp+dlgtemplate.size+8]
183 diamond 1284
        neg     ecx
1285
        jz      .find_last_btn
1286
@@:
1287
        sub     ebx, dlgitemtemplate.size
283 diamond 1288
        test    [ebx+dlgitemtemplate.flags], 8
1289
        loopz   @b
1290
        jnz     .btn_found
183 diamond 1291
.find_last_btn:
314 diamond 1292
        mov     ebx, [ebp+dlgtemplate.size+8]
183 diamond 1293
        imul    ebx, dlgitemtemplate.size
314 diamond 1294
        lea     ebx, [ebx+ebp+dlgtemplate.size+12]
183 diamond 1295
@@:
1296
        sub     ebx, dlgitemtemplate.size
283 diamond 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
474 diamond 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
283 diamond 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
183 diamond 1372
        jnz     @b
283 diamond 1373
        jmp     .ret_test
474 diamond 1374
.editor_char:
1375
        test    [ctrlstate], 0x3C
1376
        jnz     .ret_draw
1377
        movzx   eax, al
814 diamond 1378
        call    get_ascii_char
474 diamond 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
183 diamond 1401
 
1402
.dodraw:
283 diamond 1403
        or      [cursor_x], -1
1404
        or      [cursor_y], -1
183 diamond 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]
997 diamond 1412
        cmp     eax, draw_functions_num
1413
        jae     .draw_loop_continue
1414
        call    [draw_functions + eax*4]
183 diamond 1415
.draw_loop_continue:
1416
        pop     ecx
1417
        add     ebx, dlgitemtemplate.size
1418
        loop    .draw_loop
1419
.done_draw:
1420
        ret
1421
 
997 diamond 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
 
183 diamond 1435
draw_static_text:
1436
; рисуем статический текст
1437
        mov     ah, [dialog_main_color]
314 diamond 1438
        test    byte [ebp+dlgtemplate.flags], 2
1439
        jz      draw_text
1440
        mov     ah, [warning_main_color]
183 diamond 1441
draw_text:
1442
; определяем длину строки
1443
        mov     esi, [ebx+dlgitemtemplate.data]
283 diamond 1444
draw_text_esi:
183 diamond 1445
        test    esi, esi
997 diamond 1446
        jz      .ret2
1447
        push    eax
589 diamond 1448
        push    -1
1449
        pop     ecx
183 diamond 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
997 diamond 1481
        call    dlgitem_get_console_ptr
183 diamond 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
283 diamond 1490
        cmp     [ebx+dlgitemtemplate.type], 3
1491
        jnz     @f
1492
        mov     ecx, edx
1493
        jmp     .text_copy
1494
@@:
183 diamond 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
589 diamond 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
183 diamond 1515
@@:
1516
        lodsb
1517
        stosw
1518
        loop    @b
1519
.ret:
314 diamond 1520
        mov     eax, [ebp+dlgtemplate.x]
1521
        mov     edx, [ebp+dlgtemplate.y]
183 diamond 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
997 diamond 1533
.ret2:
183 diamond 1534
        ret
1535
 
1536
draw_button:
314 diamond 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]
183 diamond 1543
        test    [ebx+dlgitemtemplate.flags], 4
1544
        jz      @f
314 diamond 1545
        mov     ah, [dialog_selected_btn_color-dialog_colors+ecx]
183 diamond 1546
@@:
1547
        jmp     draw_text
283 diamond 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]
314 diamond 1556
        add     eax, [ebp+dlgtemplate.x]
283 diamond 1557
        mov     [cursor_x], eax
1558
        mov     eax, [ebx+dlgitemtemplate.y1]
314 diamond 1559
        add     eax, [ebp+dlgtemplate.y]
283 diamond 1560
        mov     [cursor_y], eax
1561
@@:
314 diamond 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]
283 diamond 1568
        test    [ebx+dlgitemtemplate.flags], 10h
1569
        jnz     @f
314 diamond 1570
        mov     ah, [dialog_unmodified_edit_color-dialog_colors+ecx]
283 diamond 1571
@@:
1572
        mov     esi, [ebx+dlgitemtemplate.data]
1573
        add     esi, [edx+8]
1574
        add     esi, 12
1575
        jmp     draw_text_esi
314 diamond 1576
 
997 diamond 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
 
314 diamond 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
 
997 diamond 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
 
589 diamond 1901
; int __stdcall SayErr(int num_strings, const char* strings[],
1902
;                      int num_buttons, const char* buttons[]);
474 diamond 1903
SayErr:
589 diamond 1904
        pop     eax
1905
        push    aError
1906
        push    eax
814 diamond 1907
; int __stdcall SayErrTitle(const char* title,
1908
;                       int num_strings, const char* strings[],
1909
;                       int num_buttons, const char* buttons[]);
1910
SayErrTitle:
474 diamond 1911
        push    2
1912
        jmp     @f
1913
 
589 diamond 1914
; int __stdcall Message(const char* title,
474 diamond 1915
;                       int num_strings, const char* strings[],
1916
;                       int num_buttons, const char* buttons[]);
1917
Message:
1918
        push    1
1919
@@:
589 diamond 1920
        pop     eax
314 diamond 1921
; [esp+4] = title
589 diamond 1922
; [esp+8] = num_strings
1923
; [esp+12] = strings
1924
; [esp+16] = num_buttons
1925
; [esp+20] = buttons
474 diamond 1926
        pushad
589 diamond 1927
        mov     ecx, [esp+32+8]
1928
        add     ecx, [esp+32+16]
474 diamond 1929
        imul    ecx, dlgitemtemplate.size
1930
        add     ecx, dlgtemplate.size+12
1931
        call    xpgalloc
314 diamond 1932
        test    eax, eax
1933
        jnz     @f
474 diamond 1934
        popad
314 diamond 1935
        or      eax, -1
1936
        ret     28
1937
@@:
1938
        mov     ebx, eax
1939
        mov     edi, eax
474 diamond 1940
        mov     eax, [esp+28]
314 diamond 1941
        stosd                           ; dlgtemplate.flags
589 diamond 1942
        or      eax, -1
314 diamond 1943
        stosd                           ; dlgtemplate.x
1944
        stosd                           ; dlgtemplate.y
1945
; calculate width
589 diamond 1946
        mov     ecx, [esp+32+8]
1947
        mov     esi, [esp+32+12]
314 diamond 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
589 diamond 1962
        mov     ecx, [esp+32+16]
1963
        mov     esi, [esp+32+20]
314 diamond 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
589 diamond 1989
        mov     eax, [esp+32+8]
314 diamond 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)
814 diamond 2000
        stosd                           ; (ignored)
314 diamond 2001
        stosd                           ; DlgProc
2002
        stosd                           ; userdata
589 diamond 2003
        mov     eax, [esp+32+8]
2004
        add     eax, [esp+32+16]
314 diamond 2005
        stosd                           ; num_items
2006
; fill strings
2007
        xor     ecx, ecx
589 diamond 2008
        mov     esi, [esp+32+12]
314 diamond 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
589 diamond 2024
        cmp     ecx, [esp+32+8]
314 diamond 2025
        jb      @b
2026
; fill buttons
589 diamond 2027
        mov     ecx, [esp+32+16]
2028
        mov     esi, [esp+32+20]
314 diamond 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
589 diamond 2059
        cmp     ecx, [esp+32+16]
314 diamond 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
589 diamond 2074
        sub     eax, [esp+32+8]
314 diamond 2075
@@:
2076
        mov     [esp+28], eax
474 diamond 2077
        mov     ecx, ebx
2078
        call    pgfree
314 diamond 2079
        popad
589 diamond 2080
        ret     20