Subversion Repositories Kolibri OS

Rev

Rev 517 | Rev 814 | 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
;  игнорируются)
180 heavyiron 11
.flags          dd      ?
12
.x              dd      ?
13
.y              dd      ?
14
.width          dd      ?
15
.height         dd      ?
16
.border_size_x  dd      ?
17
.border_size_y  dd      ?
18
.title          dd      ?
19
.main_color     db      ?
20
.border_color   db      ?
21
.header_color   db      ?
22
                db      ?       ; align
183 diamond 23
.size = $
180 heavyiron 24
end virtual
25
 
183 diamond 26
GenericBox:
180 heavyiron 27
        pushad
183 diamond 28
        mov     ebx, [esp+20h+4]
29
; center window if required
474 diamond 30
        push    [ebx+dlgtemplate.x]
31
        push    [ebx+dlgtemplate.y]
183 diamond 32
        cmp     [ebx+dlgtemplate.x], -1
33
        jnz     @f
34
        mov     eax, [cur_width]
35
        sub     eax, [ebx+dlgtemplate.width]
36
        shr     eax, 1
37
        mov     [ebx+dlgtemplate.x], eax
38
@@:
39
        cmp     [ebx+dlgtemplate.y], -1
40
        jnz     @f
41
        mov     eax, [cur_height]
42
        sub     eax, [ebx+dlgtemplate.height]
43
        shr     eax, 1
44
        mov     [ebx+dlgtemplate.y], eax
45
@@:
180 heavyiron 46
; some checks
47
        mov     eax, [ebx+dlgtemplate.x]
48
        cmp     eax, 1
49
        jl      .sizeerr
50
        add     eax, [ebx+dlgtemplate.width]
51
        cmp     eax, [cur_width]
52
        jge     .sizeerr
53
        mov     eax, [ebx+dlgtemplate.y]
54
        cmp     eax, 1
55
        jl      .sizeerr
56
        add     eax, [ebx+dlgtemplate.height]
57
        cmp     eax, [cur_height]
58
        jge     .sizeerr
59
        cmp     [ebx+dlgtemplate.border_size_x], 1
60
        jl      .sizeerr
61
        cmp     [ebx+dlgtemplate.border_size_y], 1
62
        jge     .sizeok
63
.sizeerr:
474 diamond 64
        pop     [ebx+dlgtemplate.y]
65
        pop     [ebx+dlgtemplate.x]
180 heavyiron 66
        popad
67
        or      eax, -1
68
        ret     8
69
.sizeok:
314 diamond 70
; set color if required
71
        test    byte [ebx+dlgtemplate.flags], 1
72
        jz      @f
73
        mov     edi, dialog_colors
74
        jmp     .setcolor
75
@@:
76
        test    byte [ebx+dlgtemplate.flags], 2
77
        jz      @f
78
        mov     edi, warning_colors
79
.setcolor:
474 diamond 80
        mov     al, [edi + dialog_main_color-dialog_colors]
314 diamond 81
        mov     [ebx+dlgtemplate.main_color], al
474 diamond 82
        mov     al, [edi + dialog_border_color-dialog_colors]
314 diamond 83
        mov     [ebx+dlgtemplate.border_color], al
474 diamond 84
        mov     al, [edi + dialog_header_color-dialog_colors]
314 diamond 85
        mov     [ebx+dlgtemplate.header_color], al
86
@@:
180 heavyiron 87
; allocate memory for data under dialog
314 diamond 88
; for 'No memory' dialog use static data area
89
        mov     ebp, nomem_dlgsavearea
90
        cmp     ebx, nomem_dlgdata
91
        jz      .allocated
180 heavyiron 92
        mov     eax, [ebx+dlgtemplate.width]
93
        add     eax, [ebx+dlgtemplate.border_size_x]
94
        add     eax, [ebx+dlgtemplate.border_size_x]
95
        inc     eax
96
        inc     eax
97
        mov     edx, [ebx+dlgtemplate.height]
98
        add     edx, [ebx+dlgtemplate.border_size_y]
99
        add     edx, [ebx+dlgtemplate.border_size_y]
100
        inc     edx
101
        mul     edx
474 diamond 102
        lea     ecx, [eax*2]
103
        call    xpgalloc
180 heavyiron 104
        test    eax, eax
105
        jnz     @f
474 diamond 106
        pop     [ebx+dlgtemplate.y]
107
        pop     [ebx+dlgtemplate.x]
180 heavyiron 108
        popad
109
        or      eax, -1
110
        ret     8
111
@@:
112
        mov     ebp, eax
314 diamond 113
.allocated:
180 heavyiron 114
; save data
115
        mov     eax, [ebx+dlgtemplate.y]
116
        add     eax, [ebx+dlgtemplate.height]
117
        add     eax, [ebx+dlgtemplate.border_size_y]
118
        inc     eax
119
        push    eax
120
        mov     eax, [ebx+dlgtemplate.x]
121
        add     eax, [ebx+dlgtemplate.width]
122
        add     eax, [ebx+dlgtemplate.border_size_x]
123
        inc     eax
124
        inc     eax
125
        push    eax
126
        mov     eax, [ebx+dlgtemplate.y]
127
        sub     eax, [ebx+dlgtemplate.border_size_y]
128
        push    eax
129
        mov     eax, [ebx+dlgtemplate.x]
130
        sub     eax, [ebx+dlgtemplate.border_size_x]
131
        push    eax
132
        call    save_console_data
133
; draw shadow
134
        mov     eax, [ebx+dlgtemplate.x]
135
        sub     eax, [ebx+dlgtemplate.border_size_x]
136
        ja      @f
137
        xor     eax, eax
138
@@:
139
        push    eax     ; save real window left
140
        inc     eax
141
        inc     eax
142
        mov     edx, [ebx+dlgtemplate.y]
143
        sub     edx, [ebx+dlgtemplate.border_size_y]
144
        ja      @f
145
        xor     edx, edx
146
@@:
147
        push    edx     ; save real window top
148
        inc     edx
149
        call    get_console_ptr
150
        mov     ecx, [ebx+dlgtemplate.y]
151
        add     ecx, [ebx+dlgtemplate.height]
152
        add     ecx, [ebx+dlgtemplate.border_size_y]
153
        inc     ecx
154
        cmp     ecx, [cur_height]
155
        jb      @f
156
        mov     ecx, [cur_height]
157
@@:
158
        sub     ecx, edx
159
        mov     edx, ecx
160
        mov     ecx, [ebx+dlgtemplate.x]
161
        add     ecx, [ebx+dlgtemplate.width]
162
        add     ecx, [ebx+dlgtemplate.border_size_x]
163
        inc     ecx
164
        inc     ecx
165
        cmp     ecx, [cur_width]
166
        jb      @f
167
        mov     ecx, [cur_width]
168
@@:
169
        sub     ecx, eax
170
        mov     eax, ecx
171
.shadow_loop:
172
        mov     ecx, eax
173
        push    edi
174
.sl1:
175
        inc     edi
176
        test    byte [edi], 0x0F
177
        jnz     @f
178
        or      byte [edi], 8
179
@@:
180
        and     byte [edi], 0x0F
181
        inc     edi
182
        loop    .sl1
183
        pop     edi
184
        add     edi, [cur_width]
185
        add     edi, [cur_width]
186
        dec     edx
187
        jnz     .shadow_loop
188
; draw area background
189
        pop     edx
190
        pop     eax
191
        call    get_console_ptr
192
        mov     ecx, [ebx+dlgtemplate.x]
193
        add     ecx, [ebx+dlgtemplate.width]
194
        add     ecx, [ebx+dlgtemplate.border_size_x]
195
        cmp     ecx, [cur_width]
196
        jb      @f
197
        mov     ecx, [cur_width]
198
@@:
199
        sub     ecx, eax
200
        mov     esi, ecx
201
        mov     ecx, [ebx+dlgtemplate.y]
202
        add     ecx, [ebx+dlgtemplate.height]
203
        add     ecx, [ebx+dlgtemplate.border_size_y]
204
        cmp     ecx, [cur_height]
205
        jb      @f
206
        mov     ecx, [cur_height]
207
@@:
208
        sub     ecx, edx
209
        mov     edx, ecx
210
        mov     al, ' '
211
        mov     ah, [ebx+dlgtemplate.border_color]
212
.1:
213
        mov     ecx, esi
214
        push    edi
215
        rep     stosw
216
        pop     edi
217
        add     edi, [cur_width]
218
        add     edi, [cur_width]
219
        dec     edx
220
        jnz     .1
221
; draw border
222
        mov     eax, [ebx+dlgtemplate.x]
223
        dec     eax
224
        mov     edx, [ebx+dlgtemplate.y]
225
        dec     edx
226
        call    get_console_ptr
227
        mov     edx, [ebx+dlgtemplate.height]
228
        inc     edx
229
        inc     edx
230
        mov     ah, [ebx+dlgtemplate.border_color]
231
        push    ebx
232
        mov     ebx, [ebx+dlgtemplate.width]
233
        inc     ebx
234
        inc     ebx
235
        call    draw_border
236
        pop     ebx
237
; draw header
238
        mov     esi, [ebx+dlgtemplate.title]
239
        test    esi, esi
240
        jz      .noheader
241
        cmp     byte [esi], 0
242
        jz      .noheader
243
        push    esi
244
@@:     lodsb
245
        test    al, al
246
        jnz     @b
247
        mov     eax, esi
248
        pop     esi
249
        sub     eax, esi
283 diamond 250
        inc     eax     ; eax = длина заголовка + 2
180 heavyiron 251
        mov     ecx, [ebx+dlgtemplate.width]
252
        cmp     eax, ecx
253
        jbe     .fullhea
254
        sub     ecx, 5
255
        jb      .noheader
256
        xor     edx, edx
257
        jmp     .drawhea
258
.fullhea:
259
        mov     edx, ecx
260
        sub     edx, eax
261
        shr     edx, 1
262
.drawhea:
263
        mov     eax, [ebx+dlgtemplate.x]
264
        add     eax, edx
265
        mov     edx, [ebx+dlgtemplate.y]
266
        dec     edx
267
        call    get_console_ptr
268
        mov     ah, [ebx+dlgtemplate.header_color]
269
        mov     al, ' '
270
        stosw
283 diamond 271
.2:
180 heavyiron 272
        dec     ecx
283 diamond 273
        jz	.3
180 heavyiron 274
        lodsb
275
        test    al, al
276
        jz      .4
277
        stosw
278
        jmp     .2
279
.3:
280
        mov     al, '.'
281
        stosw
282
        stosw
283
        stosw
284
.4:
285
        mov     al, ' '
286
        stosw
287
.noheader:
288
; draw window background
289
        mov     eax, [ebx+dlgtemplate.x]
290
        mov     edx, [ebx+dlgtemplate.y]
291
        call    get_console_ptr
292
        mov     ah, [ebx+dlgtemplate.main_color]
293
        mov     al, ' '
294
        mov     edx, [ebx+dlgtemplate.height]
295
@@:
296
        mov     ecx, [ebx+dlgtemplate.width]
297
        push    edi
298
        rep     stosw
299
        pop     edi
300
        add     edi, [cur_width]
301
        add     edi, [cur_width]
302
        dec     edx
303
        jnz     @b
304
; send redraw message
474 diamond 305
        mov     eax, [esp+28h+8]
180 heavyiron 306
        push    ebx ebp
307
        push    0
308
        push    0
309
        push    1
183 diamond 310
        push    ebx
180 heavyiron 311
        call    eax
312
        call    draw_image
313
        pop     ebp ebx
314
; message loop
315
.event:
316
        push    10
317
        pop     eax
517 diamond 318
        int     40h
180 heavyiron 319
        dec     eax
320
        jz      .redraw
321
        dec     eax
322
        jz      .key
589 diamond 323
        jmp     exit
180 heavyiron 324
.redraw:
325
        push    ebx ebp
326
        call    draw_window
327
        pop     ebp ebx
328
        jmp     .event
329
.key:
330
        mov     al, 2
517 diamond 331
        int     40h
180 heavyiron 332
        shr     eax, 8
333
        cmp     al, 0xE0
334
        jnz     @f
335
        mov     [bWasE0], 1
336
        jmp     .event
337
@@:
338
        xchg    ah, [bWasE0]
339
        cmp     al, 0x1D
340
        jz      .ctrl_down
341
        cmp     al, 0x9D
342
        jz      .ctrl_up
343
        cmp     al, 0x2A
344
        jz      .lshift_down
345
        cmp     al, 0xAA
346
        jz      .lshift_up
347
        cmp     al, 0x36
348
        jz      .rshift_down
349
        cmp     al, 0xB6
350
        jz      .rshift_up
351
        cmp     al, 0x38
352
        jz      .alt_down
353
        cmp     al, 0xB8
354
        jz      .alt_up
474 diamond 355
        mov     ecx, [esp+28h+8]
180 heavyiron 356
        push    ebx ebp
357
        push    0
358
        push    eax
359
        push    2
183 diamond 360
        push    ebx
180 heavyiron 361
        call    ecx
362
        pop     ebp ebx
363
        test    eax, eax
364
        jz      .event
474 diamond 365
        mov     [esp+8+28], eax
180 heavyiron 366
        jmp     .exit
367
.ctrl_down:
368
        test    ah, ah
369
        jnz     .rctrl_down
370
        or      [ctrlstate], 4
371
        jmp     .event
372
.rctrl_down:
373
        or      [ctrlstate], 8
374
        jmp     .event
375
.ctrl_up:
376
        test    ah, ah
377
        jnz     .rctrl_up
378
        and     [ctrlstate], not 4
379
        jmp     .event
380
.rctrl_up:
381
        and     [ctrlstate], not 8
382
        jmp     .event
383
.lshift_down:
384
        test    ah, ah
385
        jnz     @f
386
        or      [ctrlstate], 1
387
@@:     jmp     .event
388
.lshift_up:
389
        test    ah, ah
390
        jnz     @b
391
        and     [ctrlstate], not 1
392
        jmp     @b
393
.rshift_down:
394
        or      [ctrlstate], 2
395
        jmp     .event
396
.rshift_up:
397
        and     [ctrlstate], not 2
398
        jmp     .event
399
.alt_down:
400
        test    ah, ah
401
        jnz     .ralt_down
402
        or      [ctrlstate], 0x10
403
        jmp     .event
404
.ralt_down:
405
        or      [ctrlstate], 0x20
406
        jmp     .event
407
.alt_up:
408
        test    ah, ah
409
        jnz     .ralt_up
410
        and     [ctrlstate], not 0x10
411
        jmp     .event
412
.ralt_up:
413
        and     [ctrlstate], not 0x20
414
        jmp     .event
415
.exit:
416
; restore data
417
        mov     eax, [ebx+dlgtemplate.y]
418
        add     eax, [ebx+dlgtemplate.height]
419
        add     eax, [ebx+dlgtemplate.border_size_y]
420
        inc     eax
421
        push    eax
422
        mov     eax, [ebx+dlgtemplate.x]
423
        add     eax, [ebx+dlgtemplate.width]
424
        add     eax, [ebx+dlgtemplate.border_size_x]
425
        inc     eax
426
        inc     eax
427
        push    eax
428
        mov     eax, [ebx+dlgtemplate.y]
429
        sub     eax, [ebx+dlgtemplate.border_size_y]
430
        push    eax
431
        mov     eax, [ebx+dlgtemplate.x]
432
        sub     eax, [ebx+dlgtemplate.border_size_x]
433
        push    eax
434
        call    restore_console_data
435
        call    draw_keybar
314 diamond 436
        cmp     ebx, nomem_dlgdata
437
        jz      @f
474 diamond 438
        mov     ecx, ebp
439
        call    pgfree
314 diamond 440
@@:
474 diamond 441
        pop     [ebx+dlgtemplate.y]
442
        pop     [ebx+dlgtemplate.x]
283 diamond 443
        or      [cursor_x], -1
444
        or      [cursor_y], -1
180 heavyiron 445
        call    draw_image
446
        popad
447
        ret     8
448
 
449
save_console_data:
450
        cmp     dword [esp+4], 0
451
        jge     @f
452
        and     dword [esp+4], 0
453
@@:
454
        cmp     dword [esp+8], 0
455
        jge     @f
456
        and     dword [esp+8], 0
457
@@:
458
        mov     eax, [esp+12]
459
        cmp     eax, [cur_width]
460
        jbe     @f
461
        mov     eax, [cur_width]
462
@@:
463
        sub     eax, [esp+4]
464
        ja      @f
465
        ret     16
466
@@:
467
        mov     [esp+12], eax
468
        mov     eax, [esp+16]
469
        cmp     eax, [cur_height]
470
        jbe     @f
471
        mov     eax, [cur_height]
472
@@:
473
        sub     eax, [esp+8]
474
        ja      @f
475
        ret     16
476
@@:
477
        mov     [esp+16], eax
478
        mov     eax, [esp+4]
479
        mov     edx, [esp+8]
480
        call    get_console_ptr
481
        mov     esi, edi
482
        mov     edi, ebp
483
.l:
484
        mov     ecx, [esp+12]
485
        push    esi
486
        shr     ecx, 1
487
        rep     movsd
488
        adc     ecx, ecx
489
        rep     movsw
490
        pop     esi
491
        add     esi, [cur_width]
492
        add     esi, [cur_width]
493
        dec     dword [esp+16]
494
        jnz     .l
495
        ret     16
496
 
497
restore_console_data:
498
        cmp     dword [esp+4], 0
499
        jge     @f
500
        and     dword [esp+4], 0
501
@@:
502
        cmp     dword [esp+8], 0
503
        jge     @f
504
        and     dword [esp+8], 0
505
@@:
506
        mov     eax, [esp+12]
507
        cmp     eax, [cur_width]
508
        jbe     @f
509
        mov     eax, [cur_width]
510
@@:
511
        sub     eax, [esp+4]
512
        ja      @f
513
        ret     16
514
@@:
515
        mov     [esp+12], eax
516
        mov     eax, [esp+16]
517
        cmp     eax, [cur_height]
518
        jbe     @f
519
        mov     eax, [cur_height]
520
@@:
521
        sub     eax, [esp+8]
522
        ja      @f
523
        ret     16
524
@@:
525
        mov     [esp+16], eax
526
        mov     eax, [esp+4]
527
        mov     edx, [esp+8]
528
        call    get_console_ptr
529
        mov     esi, ebp
530
.l:
531
        mov     ecx, [esp+12]
532
        push    edi
533
        shr     ecx, 1
534
        rep     movsd
535
        adc     ecx, ecx
536
        rep     movsw
537
        pop     edi
538
        add     edi, [cur_width]
539
        add     edi, [cur_width]
540
        dec     dword [esp+16]
541
        jnz     .l
542
        ret     16
543
 
544
; int __stdcall menu(void* variants, const char* title, unsigned flags);
545
; variants указывает на текущий элемент в двусвязном линейном списке
546
menu:
547
        pop     eax
548
        push    [cur_height]
549
        push    [cur_width]
550
        push    0
551
        push    0
552
        push    eax
553
 
554
; int __stdcall menu_centered_in(unsigned left, unsigned top, unsigned width, unsigned height,
555
;       void* variants, const char* title, unsigned flags);
556
menu_centered_in:
557
        pushad
474 diamond 558
        mov     ecx, 56
180 heavyiron 559
; 36 bytes for dlgtemplate + additional:
560
; +36: dd cur_variant
561
; +40: dd num_variants
562
; +44: dd begin_variant
563
; +48: dd end_variant
564
; +52: dd cur_variant_idx
474 diamond 565
        call    xpgalloc
180 heavyiron 566
        test    eax, eax
567
        jnz     @f
568
.ret_bad:
569
        popad
570
        or      eax, -1
571
        ret     28
572
@@:
573
        mov     ebx, eax
574
        mov     eax, 1
575
        test    byte [esp+20h+28], 1
576
        jz      @f
577
        mov     al, 3
578
@@:
579
        mov     [ebx+dlgtemplate.border_size_x], eax
580
        inc     eax
581
        shr     eax, 1
582
        mov     [ebx+dlgtemplate.border_size_y], eax
583
; Находим ширину и высоту окна
584
        xor     eax, eax
585
        xor     ecx, ecx
586
        mov     esi, [esp+20h+20]
587
        mov     [ebx+36], esi
588
        and     dword [ebx+52], 0
589
@@:
590
        cmp     dword [esi+4], 0
591
        jz      .find_width
592
        mov     esi, [esi+4]
593
        inc     dword [ebx+52]
594
        jmp     @b
595
.find_width:
596
        mov     [ebx+44], esi
597
        add     esi, 8
598
        push    esi
599
        xor     edx, edx
600
.fw1:
601
        cmp     byte [esi], '&'
602
        jnz     @f
603
        mov     dl, 1
604
@@:
605
        inc     esi
606
        cmp     byte [esi-1], 0
607
        jnz     .fw1
608
        sub     esi, [esp]
609
        sub     esi, edx
610
        dec     esi
611
        cmp     eax, esi
612
        ja      @f
613
        mov     eax, esi
614
@@:
615
        inc     ecx
616
        pop     esi
617
        mov     esi, [esi-8]
618
        test    esi, esi
619
        jnz     .find_width
620
        add     eax, 3
621
        add     eax, [ebx+dlgtemplate.border_size_x]
622
        add     eax, [ebx+dlgtemplate.border_size_x]
623
        cmp     eax, [cur_width]
624
        jb      @f
625
        mov     eax, [cur_width]
626
@@:
627
        sub     eax, [ebx+dlgtemplate.border_size_x]
628
        sub     eax, [ebx+dlgtemplate.border_size_x]
629
        mov     [ebx+dlgtemplate.width], eax
630
        mov     [ebx+dlgtemplate.height], ecx
631
        mov     [ebx+40], ecx
632
        sub     eax, [esp+20h+12]
633
        neg     eax
634
        sar     eax, 1
635
        add     eax, [esp+20h+4]
636
        cmp     eax, [ebx+dlgtemplate.border_size_x]
637
        jge     @f
638
        mov     eax, [ebx+dlgtemplate.border_size_x]
639
@@:
640
        push    eax
641
        add     eax, [ebx+dlgtemplate.width]
642
        add     eax, [ebx+dlgtemplate.border_size_x]
643
        cmp     eax, [cur_width]
644
        jbe     @f
645
        pop     eax
646
        mov     eax, [cur_width]
647
        sub     eax, [ebx+dlgtemplate.width]
648
        sub     eax, [ebx+dlgtemplate.border_size_x]
649
        push    eax
650
@@:
651
        pop     [ebx+dlgtemplate.x]
652
        sub     ecx, [esp+20h+16]
653
        neg     ecx
654
        sar     ecx, 1
655
        add     ecx, [esp+20h+8]
656
        cmp     ecx, [ebx+dlgtemplate.border_size_y]
657
        jge     @f
658
        mov     ecx, [ebx+dlgtemplate.border_size_y]
659
@@:
660
        push    ecx
661
        add     ecx, [ebx+dlgtemplate.height]
662
        add     ecx, [ebx+dlgtemplate.border_size_y]
663
        cmp     ecx, [cur_height]
664
        jbe     @f
665
        pop     ecx
666
        mov     ecx, [cur_height]
667
        sub     ecx, [ebx+dlgtemplate.height]
668
        sub     ecx, [ebx+dlgtemplate.border_size_y]
669
        push    ecx
670
@@:
671
        pop     [ebx+dlgtemplate.y]
672
        mov     eax, [cur_height]
673
        sub     eax, 6
674
        cmp     [ebx+dlgtemplate.height], eax
675
        jbe     .small_height
676
        mov     [ebx+dlgtemplate.height], eax
677
        mov     [ebx+dlgtemplate.y], 3
678
.small_height:
679
        mov     ecx, [ebx+dlgtemplate.height]
680
        mov     eax, [ebx+36]
681
        mov     [ebx+44], eax
682
        dec     ecx
683
        jz      .skip
684
        push    ecx
685
@@:
686
        cmp     dword [eax+4], 0
687
        jz      @f
688
        mov     eax, [eax+4]
689
        loop    @b
690
@@:
691
        mov     [ebx+44], eax
692
        pop     ecx
693
.loop:
694
        mov     eax, [eax]
695
        loop    .loop
696
.skip:
697
        mov     [ebx+48], eax
698
        mov     eax, [esp+20h+24]
699
        mov     [ebx+dlgtemplate.title], eax
700
        mov     al, [menu_normal_color]
701
        mov     [ebx+dlgtemplate.main_color], al
702
        mov     al, [menu_border_color]
703
        mov     [ebx+dlgtemplate.border_color], al
704
        mov     al, [menu_header_color]
705
        mov     [ebx+dlgtemplate.header_color], al
706
        push    MenuDlgProc
707
        push    ebx
183 diamond 708
        call    GenericBox
180 heavyiron 709
        mov     [esp+28], eax
474 diamond 710
        mov     ecx, ebx
711
        call    pgfree
180 heavyiron 712
        popad
713
        ret     28
714
 
715
MenuDlgProc:
183 diamond 716
        mov     eax, [esp+8]
180 heavyiron 717
        cmp     al, 1
718
        jz      .draw
719
        cmp     al, 2
720
        jz      .key
183 diamond 721
        ret     16
180 heavyiron 722
.draw:
723
        call    .dodraw
183 diamond 724
        ret     16
474 diamond 725
.prev:
726
        mov     eax, [ebx+36]
727
        cmp     dword [eax+4], 0
728
        jz      .end
729
        call    .line_prev
730
.posret:
731
        mov     [ebx+36], eax
732
.redraw:
733
        call    .dodraw
734
        call    draw_image
735
        xor     eax, eax
736
        ret     16
737
.next:
738
        mov     eax, [ebx+36]
739
        cmp     dword [eax], 0
740
        jz      .home
741
        call    .line_next
742
        jmp     .posret
743
.pgdn:
744
        mov     eax, [ebx+36]
745
        mov     ecx, [ebx+dlgtemplate.height]
746
.pgdnl:
747
        cmp     dword [eax], 0
748
        jz      .posret
749
        call    .line_next
750
        loop    .pgdnl
751
        jmp     .posret
180 heavyiron 752
.key:
183 diamond 753
        mov     al, [esp+12]
180 heavyiron 754
        cmp     al, 0x48
755
        jz      .prev
756
        cmp     al, 0x4B
757
        jz      .prev
758
        cmp     al, 0x4D
759
        jz      .next
760
        cmp     al, 0x50
761
        jz      .next
762
        cmp     al, 0x1C
763
        jz      .enter
764
        cmp     al, 1
765
        jz      .esc
766
        cmp     al, 0x47
767
        jz      .home
768
        cmp     al, 0x4F
769
        jz      .end
770
        cmp     al, 0x51
771
        jz      .pgdn
772
        cmp     al, 0x49
773
        jz      .pgup
589 diamond 774
        cmp     al, 0x52
775
        jz      .ins
776
        cmp     al, 0x53
777
        jz      .del
180 heavyiron 778
        mov     edx, [ebx+36]
779
@@:
780
        cmp     dword [edx+4], 0
781
        jz      @f
782
        mov     edx, [edx+4]
783
        jmp     @b
784
@@:
785
.l:
786
        lea     esi, [edx+7]
787
@@:
788
        inc     esi
789
        cmp     byte [esi], 0
790
        jz      .n
791
        cmp     byte [esi], '&'
792
        jnz     @b
793
        movzx   ecx, byte [esi+1]
794
        cmp     [ascii2scan+ecx], al
795
        jnz     .n
796
        mov     eax, edx
183 diamond 797
        ret     16
180 heavyiron 798
.n:
799
        mov     edx, [edx]
800
        test    edx, edx
801
        jnz     .l
802
.ret:
803
        xor     eax, eax
183 diamond 804
        ret     16
180 heavyiron 805
.pgup:
806
        mov     eax, [ebx+36]
807
        mov     ecx, [ebx+dlgtemplate.height]
808
.pgupl:
809
        cmp     dword [eax+4], 0
810
        jz      .posret
811
        call    .line_prev
812
        loop    .pgupl
813
        jmp     .posret
814
.home:
815
        mov     eax, [ebx+36]
816
@@:
817
        cmp     dword [eax+4], 0
818
        jz      @f
819
        mov     eax, [eax+4]
820
        jmp     @b
821
@@:
822
        mov     [ebx+44], eax
823
        push    eax
824
        mov     ecx, [ebx+dlgtemplate.height]
825
        dec     ecx
826
        jz      .h1
827
.h2:
828
        mov     eax, [eax]
829
        loop    .h2
830
.h1:
831
        mov     [ebx+48], eax
832
        pop     eax
833
        and     dword [ebx+52], 0
834
        jmp     .posret
835
.end:
836
        mov     eax, [ebx+36]
837
@@:
838
        cmp     dword [eax], 0
839
        jz      @f
840
        mov     eax, [eax]
841
        jmp     @b
842
@@:
843
        mov     [ebx+48], eax
844
        push    eax
845
        mov     ecx, [ebx+dlgtemplate.height]
846
        dec     ecx
847
        jz      .e1
848
.e2:
849
        mov     eax, [eax+4]
850
        loop    .e2
851
.e1:
852
        mov     [ebx+44], eax
853
        mov     eax, [ebx+40]
854
        dec     eax
855
        mov     [ebx+52], eax
856
        pop     eax
857
        jmp     .posret
858
.esc:
859
        or      eax, -1
183 diamond 860
        ret     16
180 heavyiron 861
.enter:
862
        mov     eax, [ebx+36]
183 diamond 863
        ret     16
589 diamond 864
.ins:
865
        push    5
866
        pop     edx
867
        jmp     @f
868
.del:
869
        push    4
870
        pop     edx
871
@@:
872
        mov     eax, [ebx+36]
873
        cmp     byte [eax+8], '/'
874
        jnz     @f
875
        cmp     word [eax+9], 'cd'
876
        jnz     @f
877
        movzx   ecx, byte [eax+11]
878
        sub     ecx, '0'
879
        push    24
880
        pop     eax
881
        mov     ebx, edx
882
        int     40h
883
@@:
884
        xor     eax, eax
885
        ret     16
180 heavyiron 886
 
887
.line_prev:
888
        cmp     eax, [ebx+44]
889
        jnz     @f
890
        mov     edx, [ebx+44]
891
        mov     edx, [edx+4]
892
        mov     [ebx+44], edx
893
        mov     edx, [ebx+48]
894
        mov     edx, [edx+4]
895
        mov     [ebx+48], edx
896
@@:
897
        mov     eax, [eax+4]
898
        dec     dword [ebx+52]
899
        ret
900
.line_next:
901
        cmp     eax, [ebx+48]
902
        jnz     @f
903
        mov     edx, [ebx+44]
904
        mov     edx, [edx]
905
        mov     [ebx+44], edx
906
        mov     edx, [ebx+48]
907
        mov     edx, [edx]
908
        mov     [ebx+48], edx
909
@@:
910
        mov     eax, [eax]
911
        inc     dword [ebx+52]
912
        ret
913
 
914
.dodraw:
915
        mov     eax, [ebx+dlgtemplate.x]
916
        mov     edx, [ebx+dlgtemplate.y]
917
        call    get_console_ptr
918
        mov     esi, [ebx+44]
919
.0:
920
        xor     edx, edx
921
        mov     ah, [menu_selected_color]
922
        cmp     esi, [ebx+36]
923
        jz      @f
924
        mov     ah, [menu_normal_color]
925
@@:
926
        push    edi
927
        mov     ecx, [ebx+dlgtemplate.width]
928
        mov     al, ' '
929
        stosw
930
        dec     ecx
931
        stosw
932
        dec     ecx
933
        dec     ecx
934
        push    esi
935
        add     esi, 8
936
@@:
937
        lodsb
938
        test    al, al
939
        jz      @f
940
        cmp     al, '&'
941
        jnz     .noamp
942
        test    dl, dl
943
        jnz     .noamp
944
        mov     dl, 1
945
        lodsb
946
        push    eax
947
        mov     ah, [menu_selected_highlight_color]
948
        push    ecx
949
        mov     ecx, [esp+8]
950
        cmp     ecx, [ebx+36]
951
        pop     ecx
952
        jz      .amp1
953
        mov     ah, [menu_highlight_color]
954
.amp1:
955
        stosw
956
        pop     eax
957
        jmp     .amp2
958
.noamp:
959
        stosw
960
.amp2:
961
        loop    @b
962
        mov     al, ' '
963
        cmp     byte [esi], 0
964
        jnz     .1
965
        lodsb
966
        jmp     .1
967
@@:
968
        mov     al, ' '
969
.1:
970
        stosw
971
        mov     al, ' '
972
        rep     stosw
973
        pop     esi edi
974
        add     edi, [cur_width]
975
        add     edi, [cur_width]
976
        cmp     esi, [ebx+48]
977
        jz      @f
978
        mov     esi, [esi]
979
        test    esi, esi
980
        jnz     .0
981
@@:
982
; Линейка прокрутки
983
        mov     ecx, [ebx+dlgtemplate.height]
984
        cmp     ecx, [ebx+40]
985
        jz      .noscrollbar
986
        sub     ecx, 2
987
        jbe     .noscrollbar
988
        mov     eax, [ebx+52]
989
        mul     ecx
990
        div     dword [ebx+40]
991
        push    eax
992
        mov     eax, [ebx+dlgtemplate.x]
993
        add     eax, [ebx+dlgtemplate.width]
994
        mov     edx, [ebx+dlgtemplate.y]
995
        call    get_console_ptr
996
        pop     edx
997
        inc     edx
998
        mov     al, 0x1E
999
        mov     ah, [menu_scrollbar_color]
1000
        mov     [edi], ax
1001
        add     edi, [cur_width]
1002
        add     edi, [cur_width]
1003
.2:
1004
        mov     al, 0xB2
1005
        dec     edx
1006
        jz      @f
1007
        mov     al, 0xB0
1008
@@:
1009
        mov     [edi], ax
1010
        add     edi, [cur_width]
1011
        add     edi, [cur_width]
1012
        loop    .2
1013
        mov     al, 0x1F
1014
        stosw
1015
.noscrollbar:
1016
        ret
183 diamond 1017
 
1018
virtual at 0
1019
dlgitemtemplate:
1020
; Элементы:
1021
;       1 = статический текст
283 diamond 1022
;       2 = кнопка
1023
;       3 = поле редактирования
183 diamond 1024
.type           dd      ?
1025
.x1             dd      ?
1026
.y1             dd      ?
1027
.x2             dd      ?
1028
.y2             dd      ?
283 diamond 1029
; Данные:
1030
; для текста: const char* data - ASCIIZ-строка
1031
; для кнопки: const char* data - заголовок
1032
; для редактора: struct {unsigned maxlength; unsigned pos; unsigned start;
1033
;                        char data[maxlength+1];}* data;
183 diamond 1034
.data           dd      ?
1035
.flags          dd      ?
1036
; Флаги:
1037
;       0 = выравнивание влево
1038
;       1 = выравнивание по центру
1039
;       2 = выравнивание вправо
1040
;       4 = элемент имеет фокус ввода
283 diamond 1041
;       8 = элемент может иметь фокус ввода
1042
;       10h: для кнопки = кнопка по умолчанию (Enter на не-кнопке)
1043
;            для поля ввода = данные были модифицированы
589 diamond 1044
;       20h: для поля ввода = не отображать вводимые данные (показывать '*')
183 diamond 1045
.size = $
1046
end virtual
1047
;       struct DLGDATA
1048
;       {
1049
;               DLGTEMPLATE dialog;     /* window description */
1050
;               void* DlgProc;          /* dialog procedure */
1051
; /* int __stdcall DlgProc(DLGDATA* dlg, int msg, int param1, int param2); */
1052
;               void* user_data;        /* arbitrary user data */
1053
;               unsigned num_items;     /* number of items in the following array */
1054
;               DLGITEMTEMPLATE items[]; /* array of dialog items */
1055
;       }
1056
; int __stdcall DialogBox(DLGDATA* dlg);
1057
DialogBox:
1058
        push    ManagerDlgProc
1059
        push    dword [esp+8]
1060
        call    GenericBox
314 diamond 1061
        ret     4
183 diamond 1062
 
1063
ManagerDlgProc:
314 diamond 1064
        mov     ebp, ebx
183 diamond 1065
        mov     eax, [esp+8]
1066
        dec     eax
1067
        jz      .draw
1068
        dec     eax
1069
        jz      .key
1070
        xor     eax, eax
1071
        ret     16
1072
.draw:
1073
        call    .dodraw
1074
        ret     16
1075
.key:
1076
; find item with focus
1077
        add     ebx, dlgtemplate.size+12
1078
        mov     ecx, [ebx-4]
1079
        jecxz   .nobtns
1080
@@:
1081
        test    [ebx+dlgitemtemplate.flags], 4
1082
        jnz     @f
1083
        add     ebx, dlgitemtemplate.size
1084
        loop    @b
1085
@@:
1086
.nobtns:
1087
        mov     al, [esp+12]
1088
        cmp     al, 1
1089
        jz      .esc
1090
        cmp     al, 0x1C
1091
        jz      .enter
1092
        cmp     al, 0xF
1093
        jz      .tab
1094
        cmp     al, 0x48
1095
        jz      .up
283 diamond 1096
        cmp     al, 0x50
1097
        jz      .down
1098
        jecxz   @f
1099
        cmp     [ebx+dlgitemtemplate.type], 3
1100
        jz      .key_edit
1101
@@:
183 diamond 1102
        cmp     al, 0x4B
1103
        jz      .left
1104
        cmp     al, 0x4D
1105
        jz      .right
1106
.ret0:
1107
        xor     eax, eax
1108
        ret     16
1109
.esc:
1110
        or      eax, -1
1111
        ret     16
1112
.enter:
283 diamond 1113
        cmp     [ebx+dlgitemtemplate.type], 2
1114
        jnz     @f
1115
.enter_found:
183 diamond 1116
        mov     eax, ebx
1117
        ret     16
283 diamond 1118
@@:
314 diamond 1119
        lea     ebx, [ebp+dlgtemplate.size+12]
474 diamond 1120
        mov     ecx, [ebx-4]
283 diamond 1121
.enter_find:
1122
        cmp     [ebx+dlgitemtemplate.type], 2
1123
        jnz     @f
1124
        test    [ebx+dlgitemtemplate.flags], 0x10
1125
        jnz     .enter_found
1126
@@:
1127
        add     ebx, dlgitemtemplate.size
474 diamond 1128
        loop    .enter_find
1129
        jmp     .enter_found
183 diamond 1130
.tab:
1131
        test    [ctrlstate], 3
1132
        jnz     .shift_tab
1133
.right:
1134
.down:
1135
        jecxz   .ret0
1136
        and     byte [ebx+dlgitemtemplate.flags], not 4
1137
        dec     ecx
1138
        jz      .find_first_btn
1139
@@:
1140
        add     ebx, dlgitemtemplate.size
283 diamond 1141
        test    [ebx+dlgitemtemplate.flags], 8
1142
        jnz     .btn_found
183 diamond 1143
        loop    @b
1144
.find_first_btn:
314 diamond 1145
        lea     ebx, [ebp+dlgtemplate.size+12]
183 diamond 1146
@@:
283 diamond 1147
        test    [ebx+dlgitemtemplate.flags], 8
1148
        jnz     .btn_found
183 diamond 1149
        add     ebx, dlgitemtemplate.size
1150
        jmp     @b
1151
.btn_found:
1152
        or      byte [ebx+dlgitemtemplate.flags], 4
283 diamond 1153
.ret_draw:
314 diamond 1154
        mov     ebx, ebp
183 diamond 1155
        call    .dodraw
1156
        call    draw_image
1157
        xor     eax, eax
1158
        ret     16
1159
.shift_tab:
1160
.left:
1161
.up:
1162
        jecxz   .ret0
1163
        and     byte [ebx+dlgitemtemplate.flags], not 4
314 diamond 1164
        sub     ecx, [ebp+dlgtemplate.size+8]
183 diamond 1165
        neg     ecx
1166
        jz      .find_last_btn
1167
@@:
1168
        sub     ebx, dlgitemtemplate.size
283 diamond 1169
        test    [ebx+dlgitemtemplate.flags], 8
1170
        loopz   @b
1171
        jnz     .btn_found
183 diamond 1172
.find_last_btn:
314 diamond 1173
        mov     ebx, [ebp+dlgtemplate.size+8]
183 diamond 1174
        imul    ebx, dlgitemtemplate.size
314 diamond 1175
        lea     ebx, [ebx+ebp+dlgtemplate.size+12]
183 diamond 1176
@@:
1177
        sub     ebx, dlgitemtemplate.size
283 diamond 1178
        test    [ebx+dlgitemtemplate.flags], 8
1179
        jz      @b
1180
        jmp     .btn_found
1181
.key_edit:
1182
; обработка клавиш в поле ввода
1183
        test    al, 0x80
1184
        jnz     .ret0
1185
        or      [ebx+dlgitemtemplate.flags], 0x10
1186
        mov     edx, [ebx+dlgitemtemplate.data]
1187
        cmp     al, 0x4B
1188
        jz      .editor_left
1189
        cmp     al, 0x4D
1190
        jz      .editor_right
1191
        cmp     al, 0x47
1192
        jz      .editor_home
1193
        cmp     al, 0x4F
1194
        jz      .editor_end
1195
        cmp     al, 0x0E
1196
        jz      .editor_backspace
1197
        cmp     al, 0x53
474 diamond 1198
        jnz     .editor_char
1199
.editor_del:
1200
        mov     ecx, [edx+4]
1201
        lea     edi, [ecx+edx+12]
1202
        lea     esi, [edi+1]
1203
        cmp     byte [edi], 0
1204
        jz      .ret_test
1205
        jmp     .copy_and_ret_test
283 diamond 1206
.editor_left:
1207
        mov     ecx, [edx+4]
1208
        jecxz   @f
1209
        dec     dword [edx+4]
1210
@@:     jmp     .ret_test
1211
.editor_right:
1212
        mov     ecx, [edx+4]
1213
        cmp     byte [edx+ecx+12], 0
1214
        jz      @b
1215
        inc     dword [edx+4]
1216
        jmp     @b
1217
.editor_home:
1218
        and     dword [edx+4], 0
1219
        jmp     @b
1220
.editor_end:
1221
        lea     edi, [edx+12]
1222
        xor     eax, eax
1223
        or      ecx, -1
1224
        repnz   scasb
1225
        not     ecx
1226
        dec     ecx
1227
        mov     [edx+4], ecx
1228
.ret_test:
1229
        mov     eax, [edx+4]
1230
        cmp     [edx+8], eax
1231
        jl      .ret_test.l1
1232
        mov     [edx+8], eax
1233
        jmp     .ret_test.l2
1234
.ret_test.l1:
1235
        add     eax, [ebx+dlgitemtemplate.x1]
1236
        sub     eax, [ebx+dlgitemtemplate.x2]
1237
        cmp     [edx+8], eax
1238
        jge     .ret_test.l2
1239
        mov     [edx+8], eax
1240
.ret_test.l2:
1241
        jmp     .ret_draw
1242
.editor_backspace:
1243
        mov     ecx, [edx+4]
1244
        jecxz   .ret_test
1245
        dec     dword [edx+4]
1246
        lea     esi, [edx+ecx+12]
1247
        lea     edi, [esi-1]
1248
.copy_and_ret_test:
1249
@@:
1250
        lodsb
1251
        stosb
1252
        test    al, al
183 diamond 1253
        jnz     @b
283 diamond 1254
        jmp     .ret_test
474 diamond 1255
.editor_char:
1256
        test    [ctrlstate], 0x3C
1257
        jnz     .ret_draw
1258
; query keyboard layout
1259
        pushad
1260
        push    26
1261
        pop     eax
1262
        push    2
1263
        pop     ebx
1264
        xor     ecx, ecx
1265
        cmp     [ctrlstate], 1
1266
        sbb     ecx, -2
1267
        mov     edx, layout
517 diamond 1268
        int     0x40
474 diamond 1269
        popad
1270
; translate scancode to ASCII
1271
        movzx   eax, al
1272
        movzx   eax, byte [layout+eax]
1273
        push    eax
1274
; insert entered symbol
1275
        xor     eax, eax
1276
        lea     edi, [edx+12]
1277
        or      ecx, -1
1278
        repnz   scasb
1279
        not     ecx
1280
        pop     eax
1281
        cmp     ecx, [edx]
1282
        ja      .ret_test       ; buffer capacity exceeded
1283
        lea     edi, [edx+ecx+12-1]
1284
        mov     esi, [edx+4]
1285
        lea     esi, [edx+esi+12]
1286
@@:
1287
        mov     cl, [edi]
1288
        mov     [edi+1], cl
1289
        dec     edi
1290
        cmp     edi, esi
1291
        jae     @b
1292
        mov     [esi], al
1293
        inc     dword [edx+4]
1294
@@:     jmp     .ret_test
183 diamond 1295
 
1296
.dodraw:
283 diamond 1297
        or      [cursor_x], -1
1298
        or      [cursor_y], -1
183 diamond 1299
        add     ebx, dlgtemplate.size+8
1300
        mov     ecx, [ebx]
1301
        add     ebx, 4
1302
        jecxz   .done_draw
1303
.draw_loop:
1304
        push    ecx
1305
        mov     eax, [ebx+dlgitemtemplate.type]
1306
        dec     eax
1307
        jz      .draw_text
1308
        dec     eax
283 diamond 1309
        jz      .draw_button
1310
        dec     eax
183 diamond 1311
        jnz     .draw_loop_continue
283 diamond 1312
        call    draw_editbox
1313
        jmp     .draw_loop_continue
1314
.draw_button:
183 diamond 1315
        call    draw_button
1316
        jmp     .draw_loop_continue
1317
.draw_text:
1318
        call    draw_static_text
1319
.draw_loop_continue:
1320
        pop     ecx
1321
        add     ebx, dlgitemtemplate.size
1322
        loop    .draw_loop
1323
.done_draw:
1324
        ret
1325
 
1326
draw_static_text:
1327
; рисуем статический текст
1328
        mov     ah, [dialog_main_color]
314 diamond 1329
        test    byte [ebp+dlgtemplate.flags], 2
1330
        jz      draw_text
1331
        mov     ah, [warning_main_color]
183 diamond 1332
draw_text:
1333
; определяем длину строки
1334
        mov     esi, [ebx+dlgitemtemplate.data]
283 diamond 1335
draw_text_esi:
183 diamond 1336
        test    esi, esi
1337
        jz      .ret
589 diamond 1338
        push    -1
1339
        pop     ecx
183 diamond 1340
@@:
1341
        inc     ecx
1342
        cmp     byte [ecx+esi], 0
1343
        jnz     @b
1344
; в ecx длина строки
1345
        push    eax
1346
        xor     eax, eax
1347
        mov     edx, [ebx+dlgitemtemplate.x2]
1348
        sub     edx, [ebx+dlgitemtemplate.x1]
1349
        inc     edx
1350
        cmp     ecx, edx
1351
        jae     .text_draw
1352
        mov     al, byte [ebx+dlgitemtemplate.flags]
1353
        and     al, 3
1354
        jz      .text_align_left
1355
        cmp     al, 1
1356
        jz      .text_align_center
1357
; текст выровнен вправо
1358
        mov     eax, edx
1359
        sub     eax, ecx
1360
        jmp     .text_draw
1361
.text_align_center:
1362
        mov     eax, edx
1363
        sub     eax, ecx
1364
        shr     eax, 1
1365
        jmp     .text_draw
1366
.text_align_left:
1367
        xor     eax, eax
1368
.text_draw:
1369
        push    ecx
1370
        push    eax
1371
        mov     eax, [ebx+dlgitemtemplate.x1]
314 diamond 1372
        add     eax, [ebp+dlgtemplate.x]
183 diamond 1373
        push    edx
1374
        mov     edx, [ebx+dlgitemtemplate.y1]
314 diamond 1375
        add     edx, [ebp+dlgtemplate.y]
183 diamond 1376
        call    get_console_ptr
1377
        pop     edx
1378
        pop     ecx
1379
        mov     ah, [esp+5]
1380
        mov     al, ' '
1381
        rep     stosw
1382
        pop     ecx
1383
        cmp     ecx, edx
1384
        jbe     .text_copy
283 diamond 1385
        cmp     [ebx+dlgitemtemplate.type], 3
1386
        jnz     @f
1387
        mov     ecx, edx
1388
        jmp     .text_copy
1389
@@:
183 diamond 1390
        cmp     edx, 3
1391
        jb      .ret
1392
        mov     al, '.'
1393
        stosw
1394
        stosw
1395
        stosw
1396
        add     esi, ecx
1397
        mov     ecx, edx
1398
        sub     ecx, 3
1399
        sub     esi, ecx
1400
.text_copy:
1401
        jecxz   .ret
589 diamond 1402
; check for password editboxes
1403
        cmp     [ebx+dlgitemtemplate.type], 3
1404
        jnz     @f
1405
        test    [ebx+dlgitemtemplate.flags], 20h
1406
        jz      @f
1407
        mov     al, '*'
1408
        rep     stosw
1409
        jmp     .ret
183 diamond 1410
@@:
1411
        lodsb
1412
        stosw
1413
        loop    @b
1414
.ret:
314 diamond 1415
        mov     eax, [ebp+dlgtemplate.x]
1416
        mov     edx, [ebp+dlgtemplate.y]
183 diamond 1417
        add     eax, [ebx+dlgitemtemplate.x2]
1418
        inc     eax
1419
        add     edx, [ebx+dlgitemtemplate.y1]
1420
        mov     ecx, edi
1421
        call    get_console_ptr
1422
        xchg    ecx, edi
1423
        sub     ecx, edi
1424
        shr     ecx, 1
1425
        pop     eax
1426
        mov     al, ' '
1427
        rep     stosw
1428
        ret
1429
 
1430
draw_button:
314 diamond 1431
        mov     ecx, dialog_colors
1432
        test    byte [ebp+dlgtemplate.flags], 2
1433
        jz      @f
1434
        mov     ecx, warning_colors
1435
@@:
1436
        mov     ah, [dialog_normal_btn_color-dialog_colors+ecx]
183 diamond 1437
        test    [ebx+dlgitemtemplate.flags], 4
1438
        jz      @f
314 diamond 1439
        mov     ah, [dialog_selected_btn_color-dialog_colors+ecx]
183 diamond 1440
@@:
1441
        jmp     draw_text
283 diamond 1442
 
1443
draw_editbox:
1444
        mov     edx, [ebx+dlgitemtemplate.data]
1445
        test    [ebx+dlgitemtemplate.flags], 4
1446
        jz      @f
1447
        mov     eax, [ebx+dlgitemtemplate.x1]
1448
        add     eax, [edx+4]
1449
        sub     eax, [edx+8]
314 diamond 1450
        add     eax, [ebp+dlgtemplate.x]
283 diamond 1451
        mov     [cursor_x], eax
1452
        mov     eax, [ebx+dlgitemtemplate.y1]
314 diamond 1453
        add     eax, [ebp+dlgtemplate.y]
283 diamond 1454
        mov     [cursor_y], eax
1455
@@:
314 diamond 1456
        mov     ecx, dialog_colors
1457
        test    byte [ebp+dlgtemplate.flags], 2
1458
        jz      @f
1459
        mov     ecx, warning_colors
1460
@@:
1461
        mov     ah, [dialog_edit_color-dialog_colors+ecx]
283 diamond 1462
        test    [ebx+dlgitemtemplate.flags], 10h
1463
        jnz     @f
314 diamond 1464
        mov     ah, [dialog_unmodified_edit_color-dialog_colors+ecx]
283 diamond 1465
@@:
1466
        mov     esi, [ebx+dlgitemtemplate.data]
1467
        add     esi, [edx+8]
1468
        add     esi, 12
1469
        jmp     draw_text_esi
314 diamond 1470
 
1471
; void __stdcall SayNoMem(void);
1472
SayNoMem:
1473
        or      dword [nomem_dlgdata+4], -1
1474
        or      dword [nomem_dlgdata+8], -1
1475
        push    nomem_dlgdata
1476
        call    DialogBox
1477
        ret
1478
 
589 diamond 1479
; int __stdcall SayErr(int num_strings, const char* strings[],
1480
;                      int num_buttons, const char* buttons[]);
474 diamond 1481
SayErr:
589 diamond 1482
        pop     eax
1483
        push    aError
1484
        push    eax
474 diamond 1485
        push    2
1486
        jmp     @f
1487
 
589 diamond 1488
; int __stdcall Message(const char* title,
474 diamond 1489
;                       int num_strings, const char* strings[],
1490
;                       int num_buttons, const char* buttons[]);
1491
Message:
1492
        push    1
1493
@@:
589 diamond 1494
        pop     eax
314 diamond 1495
; [esp+4] = title
589 diamond 1496
; [esp+8] = num_strings
1497
; [esp+12] = strings
1498
; [esp+16] = num_buttons
1499
; [esp+20] = buttons
474 diamond 1500
        pushad
589 diamond 1501
        mov     ecx, [esp+32+8]
1502
        add     ecx, [esp+32+16]
474 diamond 1503
        imul    ecx, dlgitemtemplate.size
1504
        add     ecx, dlgtemplate.size+12
1505
        call    xpgalloc
314 diamond 1506
        test    eax, eax
1507
        jnz     @f
474 diamond 1508
        popad
314 diamond 1509
        or      eax, -1
1510
        ret     28
1511
@@:
1512
        mov     ebx, eax
1513
        mov     edi, eax
474 diamond 1514
        mov     eax, [esp+28]
314 diamond 1515
        stosd                           ; dlgtemplate.flags
589 diamond 1516
        or      eax, -1
314 diamond 1517
        stosd                           ; dlgtemplate.x
1518
        stosd                           ; dlgtemplate.y
1519
; calculate width
589 diamond 1520
        mov     ecx, [esp+32+8]
1521
        mov     esi, [esp+32+12]
314 diamond 1522
        xor     edx, edx
1523
.calcwidth:
1524
        lodsd
1525
@@:
1526
        inc     eax
1527
        cmp     byte [eax-1], 0
1528
        jnz     @b
1529
        sub     eax, [esi-4]
1530
        inc     eax
1531
        cmp     edx, eax
1532
        ja      @f
1533
        mov     edx, eax
1534
@@:
1535
        loop    .calcwidth
589 diamond 1536
        mov     ecx, [esp+32+16]
1537
        mov     esi, [esp+32+20]
314 diamond 1538
        xor     ebp, ebp
1539
.calcwidth2:
1540
        lodsd
1541
@@:
1542
        inc     eax
1543
        cmp     byte [eax-1], 0
1544
        jnz     @b
1545
        sub     eax, [esi-4]
1546
        inc     eax
1547
        add     ebp, eax
1548
        loop    .calcwidth2
1549
        inc     ebp
1550
        inc     ebp
1551
        cmp     edx, ebp
1552
        ja      @f
1553
        mov     edx, ebp
1554
@@:
1555
        mov     eax, [cur_width]
1556
        sub     eax, 8
1557
        cmp     edx, eax
1558
        jb      @f
1559
        mov     edx, eax
1560
@@:
1561
        mov     eax, edx
1562
        stosd                           ; dlgtemplate.width
589 diamond 1563
        mov     eax, [esp+32+8]
314 diamond 1564
        inc     eax
1565
        stosd                           ; dlgtemplate.height
1566
        mov     eax, 3
1567
        stosd                           ; dlgtemplate.border_size_x
1568
        mov     al, 2
1569
        stosd                           ; dlgtemplate.border_size_y
1570
        mov     eax, [esp+32+4]
1571
        stosd                           ; dlgtemplate.title
1572
        xor     eax, eax
1573
        stosd                           ; (ignored)
1574
        stosd                           ; DlgProc
1575
        stosd                           ; userdata
589 diamond 1576
        mov     eax, [esp+32+8]
1577
        add     eax, [esp+32+16]
314 diamond 1578
        stosd                           ; num_items
1579
; fill strings
1580
        xor     ecx, ecx
589 diamond 1581
        mov     esi, [esp+32+12]
314 diamond 1582
@@:
1583
        mov     eax, 1
1584
        stosd                           ; dlgitemtemplate.type
1585
        dec     eax
1586
        stosd                           ; dlgitemtemplate.x1
1587
        mov     eax, ecx
1588
        stosd                           ; dlgitemtemplate.y1
1589
        lea     eax, [edx-1]
1590
        stosd                           ; dlgitemtemplate.x2
1591
        mov     eax, ecx
1592
        stosd                           ; dlgitemtemplate.y2
1593
        movsd                           ; dlgitemtemplate.data
1594
        mov     eax, 1
1595
        stosd                           ; dlgitemtemplate.flags
1596
        inc     ecx
589 diamond 1597
        cmp     ecx, [esp+32+8]
314 diamond 1598
        jb      @b
1599
; fill buttons
589 diamond 1600
        mov     ecx, [esp+32+16]
1601
        mov     esi, [esp+32+20]
314 diamond 1602
        sub     edx, ebp
1603
        jc      .big
1604
        shr     edx, 1
1605
        inc     edx
1606
        jmp     .fillbtns
1607
.big:
1608
        xor     edx, edx
1609
.fillbtns:
1610
        mov     eax, 2
1611
        stosd                           ; dlgitemtemplate.type
1612
        mov     eax, edx
1613
        stosd                           ; dlgitemtemplate.x1
1614
        mov     eax, [ebx+dlgtemplate.height]
1615
        dec     eax
1616
        stosd                           ; dlgitemtemplate.y1
1617
        push    eax
1618
        lodsd
1619
        sub     eax, edx
1620
@@:
1621
        inc     edx
1622
        cmp     byte [eax+edx-1], 0
1623
        jnz     @b
1624
        mov     eax, edx
1625
        inc     edx
1626
        stosd                           ; dlgitemtemplate.x2
1627
        pop     eax
1628
        stosd                           ; dlgitemtemplate.y2
1629
        mov     eax, [esi-4]
1630
        stosd                           ; dlgitemtemplate.data
1631
        mov     eax, 9
589 diamond 1632
        cmp     ecx, [esp+32+16]
314 diamond 1633
        jnz     @f
1634
        or      al, 4
1635
@@:
1636
        stosd                           ; dlgitemtemplate.flags
1637
        loop    .fillbtns
1638
        push    ebx
1639
        call    DialogBox
1640
        cmp     eax, -1
1641
        jz      @f
1642
        sub     eax, ebx
1643
        sub     eax, dlgtemplate.size+12
1644
        xor     edx, edx
1645
        mov     ecx, dlgitemtemplate.size
1646
        div     ecx
589 diamond 1647
        sub     eax, [esp+32+8]
314 diamond 1648
@@:
1649
        mov     [esp+28], eax
474 diamond 1650
        mov     ecx, ebx
1651
        call    pgfree
314 diamond 1652
        popad
589 diamond 1653
        ret     20