-
Notifications
You must be signed in to change notification settings - Fork 1
/
bfu.c
2383 lines (2274 loc) · 83.1 KB
/
bfu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* bfu.c
* (c) 2002 Mikulas Patocka
* This file is a part of the Links program, released under GPL.
*/
#include "links.h"
static void menu_func(struct window *, struct event *, int);
static void mainmenu_func(struct window *, struct event *, int);
struct memory_list *getml(void *p, ...)
{
struct memory_list *ml;
va_list ap;
int n = 0;
void *q = p;
va_start(ap, p);
while (q) {
if (n == MAXINT) overalloc();
n++, q = va_arg(ap, void *);
}
if ((unsigned)n > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) overalloc();
ml = mem_alloc(sizeof(struct memory_list) + n * sizeof(void *));
ml->n = n;
n = 0;
q = p;
va_end(ap);
va_start(ap, p);
while (q) ml->p[n++] = q, q = va_arg(ap, void *);
va_end(ap);
return ml;
}
void add_to_ml(struct memory_list **ml, ...)
{
struct memory_list *nml;
va_list ap;
int n = 0;
void *q;
if (!*ml) {
*ml = mem_alloc(sizeof(struct memory_list));
(*ml)->n = 0;
}
va_start(ap, ml);
while ((q = va_arg(ap, void *))) {
if (n == MAXINT) overalloc();
n++;
}
if ((unsigned)n + (unsigned)((*ml)->n) > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) overalloc();
nml = mem_realloc(*ml, sizeof(struct memory_list) + (n + (*ml)->n) * sizeof(void *));
va_end(ap);
va_start(ap, ml);
while ((q = va_arg(ap, void *))) nml->p[nml->n++] = q;
*ml = nml;
va_end(ap);
}
void freeml(struct memory_list *ml)
{
int i;
if (!ml) return;
for (i = 0; i < ml->n; i++) mem_free(ml->p[i]);
mem_free(ml);
}
static inline int is_utf_8(struct terminal *term)
{
#ifdef G
if (F) return 1;
#endif
#ifdef ENABLE_UTF8
if (term->spec->charset == utf8_table) return 1;
#endif
return 0;
}
static inline int ttxtlen(struct terminal *term, unsigned char *s)
{
#ifdef ENABLE_UTF8
if (term->spec->charset == utf8_table)
return strlen_utf8(s);
#endif
return (int)strlen(cast_const_char s);
}
static inline int txtlen(struct terminal *term, unsigned char *s)
{
#ifdef G
if (F)
return g_text_width(bfu_style_wb, s);
else
#endif
return ttxtlen(term, s);
}
#ifdef G
struct style *bfu_style_wb, *bfu_style_wb_b, *bfu_style_bw, *bfu_style_bw_u;
struct style *bfu_style_bw_mono;
struct style *bfu_style_wb_mono, *bfu_style_wb_mono_u;
long bfu_fg_color, bfu_bg_color;
static int G_DIALOG_FIELD_WIDTH;
void init_bfu(void)
{
if (!F) return;
bfu_bg_color = dip_get_color_sRGB(G_BFU_BG_COLOR);
bfu_fg_color = dip_get_color_sRGB(G_BFU_FG_COLOR);
bfu_style_wb = g_get_style(G_BFU_BG_COLOR, G_BFU_FG_COLOR, G_BFU_FONT_SIZE, cast_uchar G_BFU_DEFAULT_FONT, 0);
bfu_style_wb_b = g_get_style(G_BFU_BG_COLOR, G_BFU_FG_COLOR, G_BFU_FONT_SIZE, cast_uchar G_BFU_DEFAULT_FONT, 0);
bfu_style_bw = g_get_style(G_BFU_FG_COLOR, G_BFU_BG_COLOR, G_BFU_FONT_SIZE, cast_uchar G_BFU_DEFAULT_FONT, 0);
bfu_style_bw_u = g_get_style(G_BFU_FG_COLOR, G_BFU_BG_COLOR, G_BFU_FONT_SIZE, cast_uchar G_BFU_DEFAULT_FONT, FF_UNDERLINE);
bfu_style_bw_mono = g_get_style(G_BFU_FG_COLOR, G_BFU_BG_COLOR, G_BFU_FONT_SIZE, cast_uchar "monospaced", 0);
bfu_style_wb_mono = g_get_style(G_BFU_BG_COLOR, G_BFU_FG_COLOR, G_BFU_FONT_SIZE, cast_uchar "monospaced", 0);
bfu_style_wb_mono_u = g_get_style(G_BFU_BG_COLOR, G_BFU_FG_COLOR, G_BFU_FONT_SIZE, cast_uchar "monospaced", FF_UNDERLINE);
G_DIALOG_FIELD_WIDTH = g_char_width(bfu_style_wb_mono, ' ');
}
void shutdown_bfu(void)
{
if (!F) return;
g_free_style(bfu_style_wb);
g_free_style(bfu_style_wb_b);
g_free_style(bfu_style_bw);
g_free_style(bfu_style_bw_u);
g_free_style(bfu_style_bw_mono);
g_free_style(bfu_style_wb_mono);
g_free_style(bfu_style_wb_mono_u);
}
#else
void init_bfu(void) {}
void shutdown_bfu(void) {}
#endif
void iinit_bfu(void)
{
#if 0
G_BFU_FG_COLOR=G_DEFAULT_BFU_FG_COLOR;
G_BFU_BG_COLOR=G_DEFAULT_BFU_BG_COLOR;
G_SCROLL_BAR_AREA_COLOR=G_DEFAULT_SCROLL_BAR_AREA_COLOR;
G_SCROLL_BAR_BAR_COLOR=G_DEFAULT_SCROLL_BAR_BAR_COLOR;
G_SCROLL_BAR_FRAME_COLOR=G_DEFAULT_SCROLL_BAR_FRAME_COLOR;
#endif
}
unsigned char m_bar = 0;
static unsigned select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, unsigned *hotkeys, int n)
{
unsigned c;
if (hotkey == M_BAR) return 0;
if (text) {
text = stracpy(_(text, term));
charset_upcase_string(&text, term->spec->charset);
}
hotkey = _(hotkey, term);
while (1) {
int i;
c = GET_TERM_CHAR(term, &hotkey);
if (!c) break;
c = charset_upcase(c, term->spec->charset);
for (i = 0; i < n; i++) if (hotkeys[i] == c) goto cont;
if (!text || cp_strchr(term->spec->charset, text, c)) break;
cont:;
}
if (text) mem_free(text);
return c;
}
void do_menu_selected(struct terminal *term, struct menu_item *items, void *data, int selected, void (*free_function)(void *), void *free_data)
{
int i;
struct menu *menu;
for (i = 0; items[i].text; i++) if (i == (MAXINT - sizeof(struct menu)) / sizeof(unsigned)) overalloc();
menu = mem_alloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = selected;
menu->view = 0;
menu->ni = i;
menu->items = items;
menu->data = data;
menu->free_function = free_function;
menu->free_data = free_data;
for (i = 0; i < menu->ni; i++)
menu->hotkeys[i] = select_hotkey(term, !term->spec->braille ? items[i].text : NULL, items[i].hotkey, menu->hotkeys, i);
#ifdef G
if (F) {
if ((unsigned)menu->ni > MAXINT / sizeof(unsigned char *)) overalloc();
menu->hktxt1 = mem_calloc(menu->ni * sizeof(unsigned char *));
menu->hktxt2 = mem_calloc(menu->ni * sizeof(unsigned char *));
menu->hktxt3 = mem_calloc(menu->ni * sizeof(unsigned char *));
for (i = 0; i < menu->ni; i++) {
unsigned char *txt = _(items[i].text, term);
unsigned char *txt2, *txt3 = txt;
if (items[i].hotkey != M_BAR) while (*txt3) {
unsigned u;
txt2 = txt3;
GET_UTF_8(txt3, u);
u = uni_upcase(u);
if (u == menu->hotkeys[i]) {
menu->hktxt1[i] = memacpy(txt, txt2 - txt);
menu->hktxt2[i] = memacpy(txt2, txt3 - txt2);
menu->hktxt3[i] = stracpy(txt3);
goto x;
}
}
menu->hktxt1[i] = stracpy(txt);
menu->hktxt2[i] = stracpy(cast_uchar "");
menu->hktxt3[i] = stracpy(cast_uchar "");
x:;
}
}
#endif
add_window(term, menu_func, menu);
}
void do_menu(struct terminal *term, struct menu_item *items, void *data)
{
do_menu_selected(term, items, data, 0, NULL, NULL);
}
static void select_menu(struct terminal *term, struct menu *menu)
{
struct menu_item *it;
void (*func)(struct terminal *, void *, void *);
void *data1;
void *data2;
if (menu->selected < 0 || menu->selected >= menu->ni) return;
it = &menu->items[menu->selected];
func = it->func;
data1 = it->data;
data2 = menu->data;
if (it->hotkey == M_BAR) return;
if (!it->in_m) {
struct window *win, *win1;
for (win = term->windows.next; (void *)win != &term->windows && (win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, delete_window(win), win = win1)
;
}
func(term, data1, data2);
}
static unsigned char *get_rtext(unsigned char *rtext)
{
if (!strcmp(cast_const_char rtext, ">")) return MENU_SUBMENU;
return rtext;
}
static void count_menu_size(struct terminal *term, struct menu *menu)
{
int sx = term->x;
int sy = term->y;
int mx = gf_val(4, 2 * (G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER));
int my;
for (my = 0; my < menu->ni; my++) {
int s = txtlen(term, _(menu->items[my].text, term)) + txtlen(term, _(get_rtext(menu->items[my].rtext), term)) + gf_val(MENU_HOTKEY_SPACE, G_MENU_HOTKEY_SPACE) * (_(get_rtext(menu->items[my].rtext), term)[0] != 0) + gf_val(4, 2 * (G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER));
if (s > mx) mx = s;
}
my = gf_val(my, my * G_BFU_FONT_SIZE);
my += gf_val(2, 2 * G_MENU_TOP_BORDER);
if (mx > sx) mx = sx;
if (my > sy) my = sy;
#ifdef G
if (F) {
my -= 2 * G_MENU_TOP_BORDER;
my -= my % G_BFU_FONT_SIZE;
my += 2 * G_MENU_TOP_BORDER;
}
#endif
menu->nview = gf_val(my - 2, (my - 2 * G_MENU_TOP_BORDER) / G_BFU_FONT_SIZE);
menu->xw = mx;
menu->yw = my;
if ((menu->x = menu->xp) < 0) menu->x = 0;
if ((menu->y = menu->yp) < 0) menu->y = 0;
if (menu->x + mx > sx) menu->x = sx - mx;
if (menu->y + my > sy) menu->y = sy - my;
if (term->spec->braille) {
menu->x = -1;
menu->y = -1;
menu->xw = term->x + 2;
menu->yw = term->y + 2;
menu->nview = term->y;
}
#ifdef G
if (F) set_window_pos(menu->win, menu->x, menu->y, menu->x + menu->xw, menu->y + menu->yw);
#endif
}
static void scroll_menu(struct menu *menu, int d)
{
int c = 0;
int w = menu->nview;
int scr_i = SCROLL_ITEMS > (w-1)/2 ? (w-1)/2 : SCROLL_ITEMS;
if (scr_i < 0) scr_i = 0;
if (w < 0) w = 0;
menu->selected += d;
while (1) {
if (c++ > menu->ni) {
menu->selected = -1;
menu->view = 0;
return;
}
if (menu->selected < 0) menu->selected = 0;
if (menu->selected >= menu->ni) menu->selected = menu->ni - 1;
if (menu->ni && menu->items[menu->selected].hotkey != M_BAR) break;
menu->selected += d;
}
if (menu->selected < menu->view + scr_i) menu->view = menu->selected - scr_i;
if (menu->selected >= menu->view + w - scr_i - 1) menu->view = menu->selected - w + scr_i + 1;
if (menu->view > menu->ni - w) menu->view = menu->ni - w;
if (menu->view < 0) menu->view = 0;
}
static void display_menu_txt(struct terminal *term, struct menu *menu)
{
int p, s;
int setc = 0;
fill_area(term, menu->x+1, menu->y+1, menu->xw-2, menu->yw-2, ' ', COLOR_MENU_TEXT);
draw_frame(term, menu->x, menu->y, menu->xw, menu->yw, COLOR_MENU_FRAME, 1);
set_window_ptr(menu->win, menu->x, menu->y);
for (p = menu->view, s = menu->y + 1; p < menu->ni && p < menu->view + menu->yw - 2; p++, s++) {
int x;
int h = 0;
unsigned c;
unsigned char *tmptext = _(menu->items[p].text, term);
unsigned char co = p == menu->selected ? h = 1, COLOR_MENU_SELECTED : COLOR_MENU_TEXT;
if (h) {
setc = 1;
set_cursor(term, menu->x + 1 + !!term->spec->braille, s, term->x - 1, term->y - 1);
/*set_window_ptr(menu->win, menu->x+3, s+1);*/
set_window_ptr(menu->win, menu->x+menu->xw, s);
fill_area(term, menu->x+1, s, menu->xw-2, 1, ' ', co);
}
if (term->spec->braille) h = 1;
if (menu->items[p].hotkey != M_BAR || (tmptext[0])) {
unsigned char *rt = _(get_rtext(menu->items[p].rtext), term);
int l = ttxtlen(term, rt);
for (x = 0;; x++) {
c = GET_TERM_CHAR(term, &rt);
if (!c) break;
if (!term->spec->braille) {
if (menu->xw - 4 >= l - x)
set_char(term, menu->x + menu->xw - 2 - l + x, s, c, co);
} else {
set_char(term, menu->x + ttxtlen(term, tmptext) + 4 + x + 2, s, c, COLOR_MENU_HOTKEY);
}
}
for (x = 0; x < menu->xw - 4; x++) {
c = GET_TERM_CHAR(term, &tmptext);
if (!c) break;
set_char(term, menu->x + x + 2 + 2 * !!term->spec->braille, s, c, !h && charset_upcase(c, term->spec->charset) == menu->hotkeys[p] ? h = 1, COLOR_MENU_HOTKEY : co);
}
if (term->spec->braille && menu->hotkeys[p]) {
set_char(term, menu->x + 2, s, menu->hotkeys[p], COLOR_MENU_HOTKEY);
}
} else {
set_char(term, menu->x, s, 0xc3, COLOR_MENU_FRAME | ATTR_FRAME);
fill_area(term, menu->x+1, s, menu->xw-2, 1, 0xc4, COLOR_MENU_FRAME | ATTR_FRAME);
set_char(term, menu->x+menu->xw-1, s, 0xb4, COLOR_MENU_FRAME | ATTR_FRAME);
}
}
if (!setc && term->spec->braille) {
set_cursor(term, menu->x + 1, menu->y + 1, term->x - 1, term->y - 1);
}
}
static int menu_oldview = -1;
static int menu_oldsel = -1;
#ifdef G
static int menu_ptr_set;
static void display_menu_item_gfx(struct terminal *term, struct menu *menu, int it)
{
struct menu_item *item = &menu->items[it];
struct graphics_device *dev = term->dev;
int y;
if (it < menu->view || it >= menu->ni || it >= menu->view + menu->nview) return;
y = menu->y + G_MENU_TOP_BORDER + (it - menu->view) * G_BFU_FONT_SIZE;
if (item->hotkey == M_BAR && !_(item->text, term)[0]) {
drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + (G_BFU_FONT_SIZE - 1) / 2, bfu_bg_color);
drv->draw_hline(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y + (G_BFU_FONT_SIZE - 1) / 2, menu->x + menu->xw - G_MENU_LEFT_BORDER / 2, bfu_fg_color);
drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y + (G_BFU_FONT_SIZE - 1) / 2 + 1, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color);
} else {
int p;
struct rect r;
unsigned char *rtext = _(get_rtext(item->rtext), term);
if (it != menu->selected) {
drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE, bfu_bg_color);
} else {
menu->xl1 = menu->x;
menu->yl1 = y;
menu->xl2 = menu->x + menu->xw;
menu->yl2 = y + G_BFU_FONT_SIZE;
menu_ptr_set = 1;
set_window_ptr(menu->win, menu->x + menu->xw, y);
drv->fill_area(dev, menu->x + (G_MENU_LEFT_BORDER - 1) / 2 + 1, y, menu->x + G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_bg_color);
drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color);
drv->fill_area(dev, menu->x + G_MENU_LEFT_BORDER, y, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color);
}
restrict_clip_area(dev, &r, menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y + G_BFU_FONT_SIZE);
if (it == menu->selected) {
p = menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER;
g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt1[it], &p);
g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt2[it], &p);
g_print_text(drv, dev, p, y, bfu_style_wb, menu->hktxt3[it], &p);
} else {
p = menu->x + G_MENU_LEFT_BORDER + G_MENU_LEFT_INNER_BORDER;
g_print_text(drv, dev, p, y, bfu_style_bw, menu->hktxt1[it], &p);
g_print_text(drv, dev, p, y, bfu_style_bw_u, menu->hktxt2[it], &p);
g_print_text(drv, dev, p, y, bfu_style_bw, menu->hktxt3[it], &p);
}
if (!*rtext) {
drv->set_clip_area(dev, &r);
if (p > menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER) p = menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER;
if (it != menu->selected)
drv->fill_area(dev, p, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color);
else
drv->fill_area(dev, p, y, menu->x + menu->xw - G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color);
} else {
int s = menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER - g_text_width(bfu_style_wb, rtext);
if (s < p) s = p;
drv->fill_area(dev, p, y, s, y + G_BFU_FONT_SIZE, it != menu->selected ? bfu_bg_color : bfu_fg_color);
g_print_text(drv, dev, s, y, it != menu->selected ? bfu_style_bw : bfu_style_wb, rtext, NULL);
drv->set_clip_area(dev, &r);
if (it != menu->selected)
drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2, y + G_BFU_FONT_SIZE, bfu_bg_color);
else
drv->fill_area(dev, menu->x + menu->xw - G_MENU_LEFT_BORDER - G_MENU_LEFT_INNER_BORDER, y, menu->x + menu->xw - G_MENU_LEFT_BORDER, y + G_BFU_FONT_SIZE, bfu_fg_color);
}
}
}
static void display_menu_gfx(struct terminal *term, struct menu *menu)
{
int p;
struct graphics_device *dev = term->dev;
if (menu_oldview == menu->view) {
if (menu_oldsel >= 0 && menu_oldsel < menu->ni && menu_oldsel < menu->view + menu->nview) display_menu_item_gfx(term, menu, menu_oldsel);
if (menu->selected >= 0 && menu->selected < menu->ni && menu->selected < menu->view + menu->nview) display_menu_item_gfx(term, menu, menu->selected);
return;
}
#define PX1 (menu->x + (G_MENU_LEFT_BORDER - 1) / 2)
#define PX2 (menu->x + menu->xw - (G_MENU_LEFT_BORDER + 1) / 2)
#define PY1 (menu->y + (G_MENU_TOP_BORDER - 1) / 2)
#define PY2 (menu->y + menu->yw - (G_MENU_TOP_BORDER + 1) / 2)
drv->fill_area(dev, menu->x, menu->y, menu->x + menu->xw, PY1, bfu_bg_color);
drv->fill_area(dev, menu->x, PY1, PX1, PY2 + 1, bfu_bg_color);
drv->fill_area(dev, PX2 + 1, PY1, menu->x + menu->xw, PY2 + 1, bfu_bg_color);
drv->fill_area(dev, menu->x, PY2 + 1, menu->x + menu->xw, menu->y + menu->yw, bfu_bg_color);
drv->draw_hline(dev, PX1, PY1, PX2 + 1, bfu_fg_color);
drv->draw_hline(dev, PX1, PY2, PX2 + 1, bfu_fg_color);
drv->draw_vline(dev, PX1, PY1 + 1, PY2, bfu_fg_color);
drv->draw_vline(dev, PX2, PY1 + 1, PY2, bfu_fg_color);
drv->fill_area(dev, PX1 + 1, PY1 + 1, PX2, menu->y + G_MENU_TOP_BORDER, bfu_bg_color);
drv->fill_area(dev, PX1 + 1, menu->y + menu->yw - G_MENU_TOP_BORDER, PX2, PY2, bfu_bg_color);
menu->xl1 = menu->yl1 = menu->xl2 = menu->yl2 = 0;
menu_ptr_set = 0;
for (p = menu->view; p < menu->ni && p < menu->view + menu->nview; p++) display_menu_item_gfx(term, menu, p);
if (!menu_ptr_set) set_window_ptr(menu->win, menu->x, menu->y);
}
#endif
static void menu_func(struct window *win, struct event *ev, int fwd)
{
int s = 0;
int xp, yp;
struct menu *menu = win->data;
struct window *w1;
menu->win = win;
switch ((int)ev->ev) {
case EV_INIT:
case EV_RESIZE:
get_parent_ptr(win, &menu->xp, &menu->yp);
count_menu_size(win->term, menu);
goto xxx;
case EV_REDRAW:
get_parent_ptr(win, &xp, &yp);
if (xp != menu->xp || yp != menu->yp) {
menu->xp = xp;
menu->yp = yp;
count_menu_size(win->term, menu);
}
xxx:
menu->selected--;
scroll_menu(menu, 1);
draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu);
break;
case EV_MOUSE:
if ((ev->b & BM_ACT) == B_MOVE) break;
if (ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y || ev->y >= menu->y+menu->yw) {
int f = 1;
for (w1 = win; (void *)w1 != &win->term->windows; w1 = w1->next) {
struct menu *m1;
if (w1->handler == mainmenu_func) {
#ifdef G
struct mainmenu *m2 = w1->data;
if (F && !f && ev->x >= m2->xl1 && ev->x < m2->xl2 && ev->y >= m2->yl1 && ev->y < m2->yl2) goto bbb;
#endif
if (ev->y < gf_val(1, G_BFU_FONT_SIZE)) goto del;
break;
}
if (w1->handler != menu_func) break;
m1 = w1->data;
#ifdef G
if (F && !f && ev->x >= m1->xl1 && ev->x < m1->xl2 && ev->y >= m1->yl1 && ev->y < m1->yl2) goto bbb;
#endif
if (ev->x > m1->x && ev->x < m1->x+m1->xw-1 && ev->y > m1->y && ev->y < m1->y+m1->yw-1) goto del;
f--;
}
if ((ev->b & BM_ACT) == B_DOWN) goto del;
if (0) del:delete_window_ev(win, ev);
#ifdef G
bbb:;
#endif
} else {
if (!(ev->x < menu->x || ev->x >= menu->x+menu->xw || ev->y < menu->y + gf_val(1, G_MENU_TOP_BORDER) || ev->y >= menu->y + menu->yw - gf_val(1, G_MENU_TOP_BORDER))) {
int s = gf_val(ev->y - menu->y-1 + menu->view, (ev->y - menu->y - G_MENU_TOP_BORDER) / G_BFU_FONT_SIZE + menu->view);
if (s >= 0 && s < menu->ni && menu->items[s].hotkey != M_BAR) {
menu_oldview = menu->view;
menu_oldsel = menu->selected;
menu->selected = s;
scroll_menu(menu, 0);
draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu);
menu_oldview = menu_oldsel = -1;
if ((ev->b & BM_ACT) == B_UP /*|| menu->items[s].in_m*/) select_menu(win->term, menu);
}
}
}
break;
case EV_KBD:
if (ev->x == KBD_LEFT || ev->x == KBD_RIGHT) {
if ((void *)win->next != &win->term->windows && win->next->handler == mainmenu_func) goto mm;
/*for (w1 = win; (void *)w1 != &win->term->windows; w1 = w1->next) {
if (w1->handler == mainmenu_func) goto mm;
if (w1->handler != menu_func) break;
}*/
if (ev->x == KBD_RIGHT) goto enter;
delete_window(win);
break;
}
if ((ev->x >= KBD_F1 && ev->x <= KBD_F12) || ev->y & KBD_ALT) {
mm:
delete_window_ev(win, ev);
break;
}
if (ev->x == KBD_ESC) {
delete_window_ev(win, (void *)win->next != &win->term->windows && win->next->handler == mainmenu_func ? ev : NULL);
break;
}
menu_oldview = menu->view;
menu_oldsel = menu->selected;
if (ev->x == KBD_UP) scroll_menu(menu, -1);
else if (ev->x == KBD_DOWN) scroll_menu(menu, 1);
else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) menu->selected = -1, scroll_menu(menu, 1);
else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) menu->selected = menu->ni, scroll_menu(menu, -1);
else if (ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
if ((menu->selected -= menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 3) < -1) menu->selected = -1;
if ((menu->view -= menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 2) < 0) menu->view = 0;
scroll_menu(menu, -1);
}
else if (ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) {
if ((menu->selected += menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 3) > menu->ni) menu->selected = menu->ni;
if ((menu->view += menu->yw / gf_val(1, G_BFU_FONT_SIZE) - 2) >= menu->ni - menu->yw + 2) menu->view = menu->ni - menu->yw + 2;
scroll_menu(menu, 1);
}
else if (ev->x > ' ') {
int i;
for (i = 0; i < menu->ni; i++) {
if (charset_upcase(ev->x, win->term->spec->charset) == menu->hotkeys[i]) {
menu->selected = i;
scroll_menu(menu, 0);
s = 1;
}
}
}
draw_to_window(win, (void (*)(struct terminal *, void *))gf_val(display_menu_txt, display_menu_gfx), menu);
if (s || ev->x == KBD_ENTER || ev->x == ' ') {
enter:
menu_oldview = menu_oldsel = -1;
select_menu(win->term, menu);
}
menu_oldview = menu_oldsel = -1;
break;
case EV_ABORT:
#ifdef G
if (F) {
int i;
for (i = 0; i < menu->ni; i++) {
mem_free(menu->hktxt1[i]);
mem_free(menu->hktxt2[i]);
mem_free(menu->hktxt3[i]);
}
mem_free(menu->hktxt1);
mem_free(menu->hktxt2);
mem_free(menu->hktxt3);
}
#endif
if (menu->items->free_i) {
int i;
for (i = 0; i < menu->ni; i++) {
if (menu->items[i].free_i & 2) mem_free(menu->items[i].text);
if (menu->items[i].free_i & 4) mem_free(menu->items[i].rtext);
}
mem_free(menu->items);
}
if (menu->free_function)
register_bottom_half(menu->free_function, menu->free_data);
break;
}
}
void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel)
{
int i;
struct mainmenu *menu;
for (i = 0; items[i].text; i++) if (i == (MAXINT - sizeof(struct mainmenu)) / sizeof(unsigned)) overalloc();
menu = mem_alloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = sel == -1 ? 0 : sel;
menu->ni = i;
menu->items = items;
menu->data = data;
for (i = 0; i < menu->ni; i++)
menu->hotkeys[i] = select_hotkey(term, NULL, items[i].hotkey, menu->hotkeys, i);
add_window(term, mainmenu_func, menu);
if (sel != -1) {
/* volatile is workaround for some weird bug in icc or linker,
it results in unaligned sse load */
volatile struct event ev = {EV_KBD, KBD_ENTER, 0, 0};
struct window *win = term->windows.next;
win->handler(win, (struct event *)&ev, 0);
}
}
static void display_mainmenu(struct terminal *term, struct mainmenu *menu)
{
if (!F) {
int i;
int p = 2;
fill_area(term, 0, 0, term->x, 1, ' ', COLOR_MAINMENU);
for (i = 0; i < menu->ni; i++) {
int s = 0;
unsigned c;
unsigned char *tmptext = _(menu->items[i].text, term);
unsigned char co = i == menu->selected ? s = 1, COLOR_MAINMENU_SELECTED : COLOR_MAINMENU;
if (i == menu->selected) {
fill_area(term, p, 0, 2, 1, ' ', co);
menu->sp = p;
set_cursor(term, p, 0, term->x - 1, term->y - 1);
set_window_ptr(menu->win, p, 1);
}
if (term->spec->braille) {
s = 1;
if (menu->hotkeys[i]) set_char(term, p, 0, menu->hotkeys[i], COLOR_MAINMENU_HOTKEY);
}
p += 2;
for (;; p++) {
c = GET_TERM_CHAR(term, &tmptext);
if (!c) break;
set_char(term, p, 0, c, !s && charset_upcase(c, term->spec->charset) == menu->hotkeys[i] ? s = 1, COLOR_MAINMENU_HOTKEY : co);
}
if (i == menu->selected) {
fill_area(term, p, 0, 2, 1, ' ', co);
}
p += 2;
}
#ifdef G
} else {
struct graphics_device *dev = term->dev;
int i, p;
drv->fill_area(dev, 0, 0, p = G_MAINMENU_LEFT_BORDER, G_BFU_FONT_SIZE, bfu_bg_color);
for (i = 0; i < menu->ni; i++) {
int s = i == menu->selected;
unsigned char *text = _(menu->items[i].text, term);
if (s) {
menu->xl1 = p;
menu->yl1 = 0;
set_window_ptr(menu->win, p, G_BFU_FONT_SIZE);
}
drv->fill_area(dev, p, 0, p + G_MAINMENU_BORDER, G_BFU_FONT_SIZE, s ? bfu_fg_color : bfu_bg_color);
p += G_MAINMENU_BORDER;
g_print_text(drv, dev, p, 0, s ? bfu_style_wb : bfu_style_bw, text, &p);
drv->fill_area(dev, p, 0, p + G_MAINMENU_BORDER, G_BFU_FONT_SIZE, s ? bfu_fg_color : bfu_bg_color);
p += G_MAINMENU_BORDER;
if (s) {
menu->xl2 = p;
menu->yl2 = G_BFU_FONT_SIZE;
}
}
drv->fill_area(dev, p, 0, term->x, G_BFU_FONT_SIZE, bfu_bg_color);
#endif
}
}
static void select_mainmenu(struct terminal *term, struct mainmenu *menu)
{
struct menu_item *it;
if (menu->selected < 0 || menu->selected >= menu->ni) return;
it = &menu->items[menu->selected];
if (it->hotkey == M_BAR) return;
if (!it->in_m) {
struct window *win, *win1;
for (win = term->windows.next; (void *)win != &term->windows && (win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, delete_window(win), win = win1)
;
}
it->func(term, it->data, menu->data);
}
static void mainmenu_func(struct window *win, struct event *ev, int fwd)
{
int s = 0;
struct mainmenu *menu = win->data;
menu->win = win;
switch ((int)ev->ev) {
case EV_INIT:
case EV_RESIZE:
#ifdef G
if (F) set_window_pos(win, 0, 0, win->term->x, G_BFU_FONT_SIZE);
#endif
case EV_REDRAW:
draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu);
break;
case EV_MOUSE:
if ((ev->b & BM_ACT) == B_MOVE) break;
if ((ev->b & BM_ACT) == B_DOWN && ev->y >= gf_val(1, G_BFU_FONT_SIZE)) delete_window_ev(win, ev);
else if (ev->y < gf_val(1, G_BFU_FONT_SIZE)) {
int i;
int p = gf_val(2, G_MAINMENU_LEFT_BORDER);
for (i = 0; i < menu->ni; i++) {
int o = p;
unsigned char *tmptext = _(menu->items[i].text, win->term);
p += txtlen(win->term, tmptext) + gf_val(4, 2 * G_MAINMENU_BORDER);
if (ev->x >= o && ev->x < p) {
menu->selected = i;
draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu);
if ((ev->b & BM_ACT) == B_UP || (menu->items[s].in_m && !win->term->spec->braille)) select_mainmenu(win->term, menu);
break;
}
}
}
break;
case EV_KBD:
if (ev->x == ' ' || ev->x == KBD_ENTER || ev->x == KBD_DOWN || ev->x == KBD_UP || ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL) || ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) {
select_mainmenu(win->term, menu);
break;
} else if (ev->x == KBD_LEFT) {
if (!menu->selected--) menu->selected = menu->ni - 1;
s = 1;
if (fwd) s = 2;
} else if (ev->x == KBD_RIGHT) {
if (++menu->selected >= menu->ni) menu->selected = 0;
s = 1;
if (fwd) s = 2;
} else if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {
menu->selected = 0;
s = 1;
} else if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {
menu->selected = menu->ni - 1;
s = 1;
} else if (ev->x > ' ') {
int i;
s = 1;
for (i = 0; i < menu->ni; i++) {
if (charset_upcase(ev->x, win->term->spec->charset) == menu->hotkeys[i]) {
menu->selected = i;
s = 2;
}
}
}
if (!s) {
delete_window_ev(win, (ev->x >= KBD_F1 && ev->x <= KBD_F12) || ev->y & KBD_ALT ? ev : NULL);
break;
}
draw_to_window(win, (void (*)(struct terminal *, void *))display_mainmenu, menu);
if (s == 2) select_mainmenu(win->term, menu);
break;
case EV_ABORT:
break;
}
}
struct menu_item *new_menu(int free_i)
{
struct menu_item *mi;
mi = mem_calloc(sizeof(struct menu_item));
mi->free_i = free_i;
return mi;
}
void add_to_menu(struct menu_item **mi, unsigned char *text, unsigned char *rtext, unsigned char *hotkey, void (*func)(struct terminal *, void *, void *), void *data, int in_m, int pos)
{
struct menu_item *mii;
int n;
if (pos != -1) {
n = pos;
if ((*mi)[n].text) internal("invalid menu position %d", n);
} else {
for (n = 0; (*mi)[n].text; n++) if (n == MAXINT) overalloc();
}
if (((unsigned)n + 2) > MAXINT / sizeof(struct menu_item)) overalloc();
mii = mem_realloc(*mi, (n + 2) * sizeof(struct menu_item));
*mi = mii;
memcpy(mii + n + 1, mii + n, sizeof(struct menu_item));
mii[n].text = text;
mii[n].rtext = rtext;
mii[n].hotkey = hotkey;
mii[n].func = func;
mii[n].data = data;
mii[n].in_m = in_m;
}
void do_dialog(struct terminal *term, struct dialog *dlg, struct memory_list *ml)
{
struct dialog_data *dd;
struct dialog_item *d;
int n = 0;
for (d = dlg->items; d->type != D_END; d++) {
if (n == MAXINT) overalloc();
n++;
}
if ((unsigned)n > (MAXINT - sizeof(struct dialog_data)) / sizeof(struct dialog_item_data)) overalloc();
dd = mem_calloc(sizeof(struct dialog_data) + sizeof(struct dialog_item_data) * n);
dd->dlg = dlg;
dd->n = n;
dd->ml = ml;
add_window(term, dialog_func, dd);
}
void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int sel)
{
struct terminal *term = dlg->win->term;
if (!F) switch (di->item->type) {
unsigned char co;
unsigned char *text, *t;
int vposlen, cposlen;
case D_CHECKBOX:
if (di->item->gid) /* radio */
{
if (di->checked) print_text(term, di->x, di->y, 3, cast_uchar "[X]", COLOR_DIALOG_CHECKBOX);
else print_text(term, di->x, di->y, 3, cast_uchar "[ ]", COLOR_DIALOG_CHECKBOX);
}
else /* checkbox */
{
if (di->checked) print_text(term, di->x, di->y, 3, cast_uchar "[X]", COLOR_DIALOG_CHECKBOX);
else print_text(term, di->x, di->y, 3, cast_uchar "[ ]", COLOR_DIALOG_CHECKBOX);
}
if (sel) {
set_cursor(term, di->x + 1, di->y, di->x + 1, di->y);
set_window_ptr(dlg->win, di->x, di->y);
}
break;
case D_FIELD:
case D_FIELD_PASS:
fill_area(term, di->x, di->y, di->l, 1, ' ', COLOR_DIALOG_FIELD);
if (di->vpos > di->cpos) di->vpos = di->cpos;
vposlen = ttxtlen(term, di->cdata + di->vpos);
cposlen = ttxtlen(term, di->cdata + di->cpos);
if (!di->l) {
di->vpos = di->cpos;
vposlen = cposlen;
} else {
while (vposlen - cposlen > di->l - 1) {
t = di->cdata + di->vpos;
GET_TERM_CHAR(term, &t);
di->vpos = (int)(t - di->cdata);
vposlen--;
}
}
if (di->item->type == D_FIELD_PASS) {
t = mem_alloc(vposlen + 1);
memset(t, '*', vposlen);
t[vposlen] = 0;
} else {
t = di->cdata + di->vpos;
}
print_text(term, di->x, di->y, di->l, t, COLOR_DIALOG_FIELD_TEXT);
if (di->item->type == D_FIELD_PASS) mem_free(t);
if (sel) {
set_cursor(term, di->x + vposlen - cposlen, di->y, di->x + vposlen - cposlen, di->y);
set_window_ptr(dlg->win, di->x, di->y);
}
break;
case D_BUTTON:
co = sel ? COLOR_DIALOG_BUTTON_SELECTED : COLOR_DIALOG_BUTTON;
text = _(di->item->text, term);
print_text(term, di->x, di->y, 2, cast_uchar "[ ", co);
print_text(term, di->x + 2, di->y, ttxtlen(term, text), text, co);
print_text(term, di->x + 2 + ttxtlen(term, text), di->y, 2, cast_uchar " ]", co);
if (sel) {
set_cursor(term, di->x + 2, di->y, di->x + 2, di->y);
set_window_ptr(dlg->win, di->x, di->y);
}
break;
default:
internal("display_dlg_item: unknown item: %d", di->item->type);
#ifdef G
} else {
struct rect rr;
struct graphics_device *dev = term->dev;
if (!dlg->s) restrict_clip_area(dev, &rr, dlg->rr.x1, dlg->rr.y1, dlg->rr.x2, dlg->rr.y2);
switch (di->item->type) {
int p, pp;
struct style *st;
unsigned char *text, *text2, *text3, *tt, *t;
struct rect r;
case D_CHECKBOX:
p = di->x;
if (di->checked) {
if (!sel) g_print_text(drv, dev, di->x, di->y, bfu_style_bw, di->item->gid?cast_uchar(G_DIALOG_RADIO_L G_DIALOG_RADIO_X G_DIALOG_RADIO_R):cast_uchar(G_DIALOG_CHECKBOX_L G_DIALOG_CHECKBOX_X G_DIALOG_CHECKBOX_R), &p);
else {
g_print_text(drv, dev, di->x, di->y, bfu_style_bw, di->item->gid?cast_uchar G_DIALOG_RADIO_L:cast_uchar G_DIALOG_CHECKBOX_L, &p);
g_print_text(drv, dev, p, di->y, bfu_style_bw_u, di->item->gid?cast_uchar G_DIALOG_RADIO_X:cast_uchar G_DIALOG_CHECKBOX_X, &p);
g_print_text(drv, dev, p, di->y, bfu_style_bw, di->item->gid?cast_uchar G_DIALOG_RADIO_R:cast_uchar G_DIALOG_CHECKBOX_R, &p);
}
} else {
int s = g_text_width(bfu_style_bw, di->item->gid?cast_uchar G_DIALOG_RADIO_X:cast_uchar G_DIALOG_CHECKBOX_X);
g_print_text(drv, dev, di->x, di->y, bfu_style_bw, di->item->gid?cast_uchar G_DIALOG_RADIO_L:cast_uchar G_DIALOG_CHECKBOX_L, &p);
if (!sel) drv->fill_area(dev, p, di->y, p + s, di->y + G_BFU_FONT_SIZE, bfu_bg_color), p += s;
else {
restrict_clip_area(dev, &r, p, di->y, p + s, di->y + G_BFU_FONT_SIZE);
g_print_text(drv, dev, p, di->y, bfu_style_bw_u, cast_uchar " ", NULL);
p += s;
drv->set_clip_area(dev, &r);
}
g_print_text(drv, dev, p, di->y, bfu_style_bw, di->item->gid?cast_uchar G_DIALOG_RADIO_R:cast_uchar G_DIALOG_CHECKBOX_R, &p);
}
di->l = p - di->x;
if (sel) set_window_ptr(dlg->win, di->x, di->y + G_BFU_FONT_SIZE);
if (dlg->s) exclude_from_set(&dlg->s, di->x, di->y, p, di->y + G_BFU_FONT_SIZE);
break;
case D_FIELD:
case D_FIELD_PASS:
if (!(text = memacpy(di->cdata, di->cpos))) break;
if (*(text2 = text3 = di->cdata + di->cpos)) {
GET_UTF_8(text3, p);
text2 = memacpy(text2, text3 - text2);
} else {
text2 = stracpy(cast_uchar " ");
text3 = cast_uchar "";
}
if (!text2) {
mem_free(text);
break;
}
text3 = stracpy(text3);
if (di->item->type == D_FIELD_PASS) {
unsigned d;
for (tt = t = text; *tt; ) {
t = tt;
GET_UTF_8(tt, d);
*t++ = '*';
}
*t = 0;
if (di->cdata[di->cpos]) {
for (tt = t = text2; *tt; ) {
t = tt;
GET_UTF_8(tt, d);
*t++ = '*';
}
*t = 0;
for (tt = t = text3; *tt; ) {
t = tt;
GET_UTF_8(tt, d);
*t++ = '*';
}
*t = 0;
}
}
p = g_text_width(bfu_style_wb_mono, text);
pp = g_text_width(bfu_style_wb_mono, text2);
if (di->vpos + di->l < p + pp) di->vpos = p + pp - di->l;
if (di->vpos > p) di->vpos = p;
if (di->vpos < 0) di->vpos = 0;
if (dlg->s) exclude_from_set(&dlg->s, di->x, di->y, di->x + di->l, di->y + G_BFU_FONT_SIZE);
restrict_clip_area(dev, &r, di->x, di->y, di->x + di->l, di->y + G_BFU_FONT_SIZE);
p = di->x - di->vpos;
g_print_text(drv, dev, p, di->y, bfu_style_wb_mono, text, &p);
g_print_text(drv, dev, p, di->y, sel ? bfu_style_wb_mono_u : bfu_style_wb_mono, text2, &p);
g_print_text(drv, dev, p, di->y, bfu_style_wb_mono, text3, &p);
drv->fill_area(dev, p, di->y, di->x + di->l, di->y + G_BFU_FONT_SIZE, bfu_fg_color);
drv->set_clip_area(dev, &r);
mem_free(text);
mem_free(text2);
mem_free(text3);
if (sel) {
set_window_ptr(dlg->win, di->x, di->y);
}
break;
case D_BUTTON:
st = sel ? bfu_style_wb_b : bfu_style_bw;
text = _(di->item->text, term);
text2 = mem_alloc(strlen(cast_const_char text) + 5);
strcpy(cast_char text2, cast_const_char G_DIALOG_BUTTON_L);
strcpy(cast_char(text2 + 2), cast_const_char text);