Subversion Repositories Kolibri OS

Rev

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