-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
2115 lines (1896 loc) · 51.9 KB
/
menu.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
/* $Id: menu.c,v 1.46 2007/05/23 12:34:20 inu Exp $ */
/*
* w3m menu.c
*/
#include <stdio.h>
#include "fm.h"
#include "menu.h"
#include "func.h"
#include "myctype.h"
#include "regex.h"
#ifdef USE_MOUSE
#ifdef USE_GPM
#include <gpm.h>
static int gpm_process_menu_mouse(Gpm_Event * event, void *data);
extern int gpm_process_mouse(Gpm_Event *, void *);
#endif /* USE_GPM */
#ifdef USE_SYSMOUSE
extern int (*sysm_handler) (int x, int y, int nbs, int obs);
static int sysm_process_menu_mouse(int, int, int, int);
extern int sysm_process_mouse(int, int, int, int);
#endif /* USE_SYSMOUSE */
#if defined(USE_GPM) || defined(USE_SYSMOUSE)
#define X_MOUSE_SELECTED (char)0xff
static int X_Mouse_Selection;
extern int do_getch();
#define getch() do_getch()
#endif /* defined(USE_GPM) || defined(USE_SYSMOUSE) */
#endif /* USE_MOUSE */
#ifdef USE_MENU
static char **FRAME;
static int FRAME_WIDTH;
static int graph_mode = FALSE;
#define G_start {if (graph_mode) graphstart();}
#define G_end {if (graph_mode) graphend();}
static int mEsc(char c);
static int mEscB(char c);
static int mEscD(char c);
static int mNull(char c);
static int mSelect(char c);
static int mDown(char c);
static int mUp(char c);
static int mLast(char c);
static int mTop(char c);
static int mNext(char c);
static int mPrev(char c);
static int mFore(char c);
static int mBack(char c);
static int mLineU(char c);
static int mLineD(char c);
static int mOk(char c);
static int mCancel(char c);
static int mClose(char c);
static int mSusp(char c);
static int mMouse(char c);
static int mSgrMouse(char c);
static int mSrchF(char c);
static int mSrchB(char c);
static int mSrchN(char c);
static int mSrchP(char c);
#ifdef __EMX__
static int mPc(char c);
#endif
/* *INDENT-OFF* */
static int (*MenuKeymap[128]) (char c) = {
/* C-@ C-a C-b C-c C-d C-e C-f C-g */
#ifdef __EMX__
mPc, mTop, mPrev, mClose, mNull, mLast, mNext, mNull,
#else
mNull, mTop, mPrev, mClose, mNull, mLast, mNext, mNull,
#endif
/* C-h C-i C-j C-k C-l C-m C-n C-o */
mCancel,mNull, mOk, mNull, mNull, mOk, mDown, mNull,
/* C-p C-q C-r C-s C-t C-u C-v C-w */
mUp, mNull, mSrchB, mSrchF, mNull, mNull, mNext, mNull,
/* C-x C-y C-z C-[ C-\ C-] C-^ C-_ */
mNull, mNull, mSusp, mEsc, mNull, mNull, mNull, mNull,
/* SPC ! " # $ % & ' */
mOk, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* ( ) * + , - . / */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mSrchF,
/* 0 1 2 3 4 5 6 7 */
mNull, mNull, mNull, mNull, mNull, mNull , mNull, mNull,
/* 8 9 : ; < = > ? */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mSrchB,
/* @ A B C D E F G */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* H I J K L M N O */
mNull, mNull, mLineU, mLineD, mNull, mNull, mSrchP, mNull,
/* P Q R S T U V W */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* X Y Z [ \ ] ^ _ */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* ` a b c d e f g */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* h i j k l m n o */
mCancel,mNull, mDown, mUp, mOk, mNull, mSrchN, mNull,
/* p q r s t u v w */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* x y z { | } ~ DEL */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mCancel,
};
static int (*MenuEscKeymap[128]) (char c) = {
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* O */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mEscB,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* [ */
mNull, mNull, mNull, mEscB, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* v */
mNull, mNull, mNull, mNull, mNull, mNull, mPrev, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
};
static int (*MenuEscBKeymap[128]) (char c) = {
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* 8 9 : ; < = > ? */
mNull, mNull, mNull, mNull, mSgrMouse,mNull,mNull, mNull,
/* A B C D E */
mNull, mUp, mDown, mOk, mCancel,mClose, mNull, mNull,
/* L M */
mNull, mNull, mNull, mNull, mClose, mMouse, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
};
static int (*MenuEscDKeymap[128]) (char c) = {
/* 0 1 INS 3 4 PgUp, PgDn 7 */
mNull, mNull, mClose, mNull, mNull, mBack, mFore, mNull,
/* 8 9 10 F1 F2 F3 F4 F5 */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* 16 F6 F7 F8 F9 F10 22 23 */
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
/* 24 25 26 27 HELP 29 30 31 */
mNull, mNull, mNull, mNull, mClose, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
};
#ifdef __EMX__
static int (*MenuPcKeymap[256])(char c)={
// Null
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// S-Tab
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-q A-w A-E A-r A-t A-y A-u A-i
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-o A-p A-[ A-] A-a A-s
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-d A-f A-g A-h A-j A-k A-l A-;
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-' A-' A-\ A-x A-c A-v
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mPrev,
// A-b A-n A-m A-, A-. A-/ A-+
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// F1 F2 F3 F4 F5
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// F6 F7 F8 F9 F10 Home
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mTop,
// Up PgUp A-/ Left 5 Right C-* End
mUp, mUp, mNull, mCancel,mNull, mOk, mNull, mLast,
// Down PgDn Ins Del S-F1 S-F2 S-F3 S-F4
mDown, mDown, mClose, mCancel,mNull, mNull, mNull, mNull,
// S-F5 S-F6 S-F7 S-F8 S-F9 S-F10 C-F1 C-F2
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// C-F3 C-F4 C-F5 C-F6 C-F7 C-F8 C-F9 C-F10
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-F1 A-F2 A-F3 A-F4 A-F5 A-F6 A-F7 A-F8
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-F9 A-F10 PrtSc C-Left C-Right C-End C-PgDn C-Home
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-1 A-2 A-3 A-4 A-5 A-6 A-7/8 A-9
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A-0 A - A-= C-PgUp F11 F12 S-F11
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// S-F12 C-F11 C-F12 A-F11 A-F12 C-Up C-/ C-5
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// S-* C-Down C-Ins C-Del C-Tab C - C-+
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull,
// A - A-Tab A-Enter
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 160
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 168
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 176
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 184
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 192
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 200
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 208
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 216
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 224
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 232
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull, // 240
mNull, mNull, mNull, mNull, mNull, mNull, mNull, mNull // 248
};
#endif
/* *INDENT-ON* */
/* --- SelectMenu --- */
static Menu SelectMenu;
static int SelectV = 0;
static void initSelectMenu(void);
static void smChBuf(void);
static int smDelBuf(char c);
/* --- SelectMenu (END) --- */
/* --- SelTabMenu --- */
static Menu SelTabMenu;
static int SelTabV = 0;
static void initSelTabMenu(void);
static void smChTab(void);
static int smDelTab(char c);
/* --- SelTabMenu (END) --- */
/* --- MainMenu --- */
static Menu MainMenu;
#ifdef USE_M17N
/* FIXME: gettextize here */
static wc_ces MainMenuCharset = WC_CES_US_ASCII; /* FIXME: charset of source code */
static int MainMenuEncode = FALSE;
#endif
static MenuItem MainMenuItem[] = {
/* type label variable value func popup keys data */
{MENU_FUNC, N_(" Back (b) "), NULL, 0, backBf, NULL, "b", NULL},
{MENU_POPUP, N_(" Select Buffer(s) "), NULL, 0, NULL, &SelectMenu, "s",
NULL},
{MENU_POPUP, N_(" Select Tab (t) "), NULL, 0, NULL, &SelTabMenu, "tT",
NULL},
{MENU_FUNC, N_(" View Source (v) "), NULL, 0, vwSrc, NULL, "vV", NULL},
{MENU_FUNC, N_(" Edit Source (e) "), NULL, 0, editBf, NULL, "eE", NULL},
{MENU_FUNC, N_(" Save Source (S) "), NULL, 0, svSrc, NULL, "S", NULL},
{MENU_FUNC, N_(" Reload (r) "), NULL, 0, reload, NULL, "rR", NULL},
{MENU_NOP, N_(" ---------------- "), NULL, 0, nulcmd, NULL, "", NULL},
{MENU_FUNC, N_(" Go Link (a) "), NULL, 0, followA, NULL, "a", NULL},
{MENU_FUNC, N_(" on New Tab (n) "), NULL, 0, tabA, NULL, "nN", NULL},
{MENU_FUNC, N_(" Save Link (A) "), NULL, 0, svA, NULL, "A", NULL},
{MENU_FUNC, N_(" View Image (i) "), NULL, 0, followI, NULL, "i", NULL},
{MENU_FUNC, N_(" Save Image (I) "), NULL, 0, svI, NULL, "I", NULL},
{MENU_FUNC, N_(" View Frame (f) "), NULL, 0, rFrame, NULL, "fF", NULL},
{MENU_NOP, N_(" ---------------- "), NULL, 0, nulcmd, NULL, "", NULL},
{MENU_FUNC, N_(" Bookmark (B) "), NULL, 0, ldBmark, NULL, "B", NULL},
{MENU_FUNC, N_(" Help (h) "), NULL, 0, ldhelp, NULL, "hH", NULL},
{MENU_FUNC, N_(" Option (o) "), NULL, 0, ldOpt, NULL, "oO", NULL},
{MENU_NOP, N_(" ---------------- "), NULL, 0, nulcmd, NULL, "", NULL},
{MENU_FUNC, N_(" Quit (q) "), NULL, 0, qquitfm, NULL, "qQ", NULL},
{MENU_END, "", NULL, 0, nulcmd, NULL, "", NULL},
};
/* --- MainMenu (END) --- */
static MenuList *w3mMenuList;
static Menu *CurrentMenu = NULL;
#define mvaddch(y, x, c) (move(y, x), addch(c))
#define mvaddstr(y, x, str) (move(y, x), addstr(str))
#define mvaddnstr(y, x, str, n) (move(y, x), addnstr_sup(str, n))
void
new_menu(Menu *menu, MenuItem *item)
{
int i, l;
char *p;
menu->cursorX = 0;
menu->cursorY = 0;
menu->x = 0;
menu->y = 0;
menu->nitem = 0;
menu->item = item;
menu->initial = 0;
menu->select = 0;
menu->offset = 0;
menu->active = 0;
if (item == NULL)
return;
for (i = 0; item[i].type != MENU_END; i++) ;
menu->nitem = i;
menu->height = menu->nitem;
for (i = 0; i < 128; i++)
menu->keymap[i] = MenuKeymap[i];
menu->width = 0;
for (i = 0; i < menu->nitem; i++) {
if ((p = item[i].keys) != NULL) {
while (*p) {
if (IS_ASCII(*p)) {
menu->keymap[(int)*p] = mSelect;
menu->keyselect[(int)*p] = i;
}
p++;
}
}
l = get_strwidth(item[i].label);
if (l > menu->width)
menu->width = l;
}
}
void
geom_menu(Menu *menu, int x, int y, int mselect)
{
int win_x, win_y, win_w, win_h;
menu->select = mselect;
if (menu->width % FRAME_WIDTH)
menu->width = (menu->width / FRAME_WIDTH + 1) * FRAME_WIDTH;
win_x = menu->x - FRAME_WIDTH;
win_w = menu->width + 2 * FRAME_WIDTH;
if (win_x + win_w > COLS)
win_x = COLS - win_w;
if (win_x < 0) {
win_x = 0;
if (win_w > COLS) {
menu->width = COLS - 2 * FRAME_WIDTH;
menu->width -= menu->width % FRAME_WIDTH;
}
}
menu->x = win_x + FRAME_WIDTH;
win_y = menu->y - mselect - 1;
win_h = menu->height + 2;
if (win_y + win_h > LASTLINE)
win_y = LASTLINE - win_h;
if (win_y < 0) {
win_y = 0;
if (win_y + win_h > LASTLINE) {
win_h = LASTLINE - win_y;
menu->height = win_h - 2;
if (menu->height <= mselect)
menu->offset = mselect - menu->height + 1;
}
}
menu->y = win_y + 1;
}
void
draw_all_menu(Menu *menu)
{
if (menu->parent != NULL)
draw_all_menu(menu->parent);
draw_menu(menu);
}
void
draw_menu(Menu *menu)
{
int x, y, w;
int i, j;
x = menu->x - FRAME_WIDTH;
w = menu->width + 2 * FRAME_WIDTH;
y = menu->y - 1;
if (menu->offset == 0) {
G_start;
mvaddstr(y, x, FRAME[3]);
for (i = FRAME_WIDTH; i < w - FRAME_WIDTH; i += FRAME_WIDTH)
mvaddstr(y, x + i, FRAME[10]);
mvaddstr(y, x + i, FRAME[6]);
G_end;
}
else {
G_start;
mvaddstr(y, x, FRAME[5]);
G_end;
for (i = FRAME_WIDTH; i < w - FRAME_WIDTH; i++)
mvaddstr(y, x + i, " ");
G_start;
mvaddstr(y, x + i, FRAME[5]);
G_end;
i = (w / 2 - 1) / FRAME_WIDTH * FRAME_WIDTH;
mvaddstr(y, x + i, ":");
}
for (j = 0; j < menu->height; j++) {
y++;
G_start;
mvaddstr(y, x, FRAME[5]);
G_end;
draw_menu_item(menu, menu->offset + j);
G_start;
mvaddstr(y, x + w - FRAME_WIDTH, FRAME[5]);
G_end;
}
y++;
if (menu->offset + menu->height == menu->nitem) {
G_start;
mvaddstr(y, x, FRAME[9]);
for (i = FRAME_WIDTH; i < w - FRAME_WIDTH; i += FRAME_WIDTH)
mvaddstr(y, x + i, FRAME[10]);
mvaddstr(y, x + i, FRAME[12]);
G_end;
}
else {
G_start;
mvaddstr(y, x, FRAME[5]);
G_end;
for (i = FRAME_WIDTH; i < w - FRAME_WIDTH; i++)
mvaddstr(y, x + i, " ");
G_start;
mvaddstr(y, x + i, FRAME[5]);
G_end;
i = (w / 2 - 1) / FRAME_WIDTH * FRAME_WIDTH;
mvaddstr(y, x + i, ":");
}
}
void
draw_menu_item(Menu *menu, int mselect)
{
mvaddnstr(menu->y + mselect - menu->offset, menu->x,
menu->item[mselect].label, menu->width);
}
int
select_menu(Menu *menu, int mselect)
{
if (mselect < 0 || mselect >= menu->nitem)
return (MENU_NOTHING);
if (mselect < menu->offset)
up_menu(menu, menu->offset - mselect);
else if (mselect >= menu->offset + menu->height)
down_menu(menu, mselect - menu->offset - menu->height + 1);
if (menu->select >= menu->offset &&
menu->select < menu->offset + menu->height)
draw_menu_item(menu, menu->select);
menu->select = mselect;
standout();
draw_menu_item(menu, menu->select);
standend();
/*
* move(menu->cursorY, menu->cursorX); */
move(menu->y + mselect - menu->offset, menu->x);
toggle_stand();
refresh();
return (menu->select);
}
void
goto_menu(Menu *menu, int mselect, int down)
{
int select_in;
if (mselect >= menu->nitem)
mselect = menu->nitem - 1;
else if (mselect < 0)
mselect = 0;
select_in = mselect;
while (menu->item[mselect].type == MENU_NOP) {
if (down > 0) {
if (++mselect >= menu->nitem) {
down_menu(menu, select_in - menu->select);
mselect = menu->select;
break;
}
}
else if (down < 0) {
if (--mselect < 0) {
up_menu(menu, menu->select - select_in);
mselect = menu->select;
break;
}
}
else {
return;
}
}
select_menu(menu, mselect);
}
void
up_menu(Menu *menu, int n)
{
if (n < 0 || menu->offset == 0)
return;
menu->offset -= n;
if (menu->offset < 0)
menu->offset = 0;
draw_menu(menu);
}
void
down_menu(Menu *menu, int n)
{
if (n < 0 || menu->offset + menu->height == menu->nitem)
return;
menu->offset += n;
if (menu->offset + menu->height > menu->nitem)
menu->offset = menu->nitem - menu->height;
draw_menu(menu);
}
int
action_menu(Menu *menu)
{
char c;
int mselect;
MenuItem item;
if (menu->active == 0) {
if (menu->parent != NULL)
menu->parent->active = 0;
return (0);
}
draw_all_menu(menu);
select_menu(menu, menu->select);
while (1) {
#ifdef USE_MOUSE
if (use_mouse)
mouse_active();
#endif /* USE_MOUSE */
c = getch();
#ifdef USE_MOUSE
if (use_mouse)
mouse_inactive();
#if defined(USE_GPM) || defined(USE_SYSMOUSE)
if (c == X_MOUSE_SELECTED) {
mselect = X_Mouse_Selection;
if (mselect != MENU_NOTHING)
break;
}
#endif /* defined(USE_GPM) || defined(USE_SYSMOUSE) */
#endif /* USE_MOUSE */
if (IS_ASCII(c)) { /* Ascii */
mselect = (*menu->keymap[(int)c]) (c);
if (mselect != MENU_NOTHING)
break;
}
}
if (mselect >= 0 && mselect < menu->nitem) {
item = menu->item[mselect];
if (item.type & MENU_POPUP) {
popup_menu(menu, item.popup);
return (1);
}
if (menu->parent != NULL)
menu->parent->active = 0;
if (item.type & MENU_VALUE)
*item.variable = item.value;
if (item.type & MENU_FUNC) {
CurrentKey = -1;
CurrentKeyData = NULL;
CurrentCmdData = item.data;
(*item.func) ();
CurrentCmdData = NULL;
}
}
else if (mselect == MENU_CLOSE) {
if (menu->parent != NULL)
menu->parent->active = 0;
}
return (0);
}
void
popup_menu(Menu *parent, Menu *menu)
{
int active = 1;
if (menu->item == NULL || menu->nitem == 0)
return;
if (menu->active)
return;
#ifdef USE_MOUSE
#ifdef USE_GPM
gpm_handler = gpm_process_menu_mouse;
#endif /* USE_GPM */
#ifdef USE_SYSMOUSE
sysm_handler = sysm_process_menu_mouse;
#endif /* USE_SYSMOUSE */
#endif /* USE_MOUSE */
menu->parent = parent;
menu->select = menu->initial;
menu->offset = 0;
menu->active = 1;
if (parent != NULL) {
menu->cursorX = parent->cursorX;
menu->cursorY = parent->cursorY;
guess_menu_xy(parent, menu->width, &menu->x, &menu->y);
}
geom_menu(menu, menu->x, menu->y, menu->select);
CurrentMenu = menu;
while (active) {
active = action_menu(CurrentMenu);
displayBuffer(Currentbuf, B_FORCE_REDRAW);
}
menu->active = 0;
CurrentMenu = parent;
#ifdef USE_MOUSE
#ifdef USE_GPM
if (CurrentMenu == NULL)
gpm_handler = gpm_process_mouse;
#endif /* USE_GPM */
#ifdef USE_SYSMOUSE
if (CurrentMenu == NULL)
sysm_handler = sysm_process_mouse;
#endif /* USE_SYSMOUSE */
#endif /* USE_MOUSE */
}
void
guess_menu_xy(Menu *parent, int width, int *x, int *y)
{
*x = parent->x + parent->width + FRAME_WIDTH - 1;
if (*x + width + FRAME_WIDTH > COLS) {
*x = COLS - width - FRAME_WIDTH;
if ((parent->x + parent->width / 2 > *x) &&
(parent->x + parent->width / 2 > COLS / 2))
*x = parent->x - width - FRAME_WIDTH + 1;
}
*y = parent->y + parent->select - parent->offset;
}
void
new_option_menu(Menu *menu, char **label, int *variable, void (*func) ())
{
int i, nitem;
char **p;
MenuItem *item;
if (label == NULL || *label == NULL)
return;
for (i = 0, p = label; *p != NULL; i++, p++) ;
nitem = i;
item = New_N(MenuItem, nitem + 1);
for (i = 0, p = label; i < nitem; i++, p++) {
if (func != NULL)
item[i].type = MENU_VALUE | MENU_FUNC;
else
item[i].type = MENU_VALUE;
item[i].label = *p;
item[i].variable = variable;
item[i].value = i;
item[i].func = func;
item[i].popup = NULL;
item[i].keys = "";
}
item[nitem].type = MENU_END;
new_menu(menu, item);
}
static void
set_menu_frame(void)
{
if (graph_ok()) {
graph_mode = TRUE;
FRAME_WIDTH = 1;
FRAME = graph_symbol;
}
else {
graph_mode = FALSE;
#ifdef USE_M17N
FRAME_WIDTH = 0;
FRAME = get_symbol(DisplayCharset, &FRAME_WIDTH);
if (!WcOption.use_wide)
FRAME_WIDTH = 1;
#else
FRAME_WIDTH = 1;
FRAME = get_symbol();
#endif
}
}
/* --- MenuFunctions --- */
#ifdef __EMX__
static int
mPc(char c)
{
c = getch();
return (MenuPcKeymap[(int)c] (c));
}
#endif
static int
mEsc(char c)
{
c = getch();
return (MenuEscKeymap[(int)c] (c));
}
static int
mEscB(char c)
{
c = getch();
if (IS_DIGIT(c))
return (mEscD(c));
else
return (MenuEscBKeymap[(int)c] (c));
}
static int
mEscD(char c)
{
int d;
d = (int)c - (int)'0';
c = getch();
if (IS_DIGIT(c)) {
d = d * 10 + (int)c - (int)'0';
c = getch();
}
if (c == '~')
return (MenuEscDKeymap[d] (c));
else
return (MENU_NOTHING);
}
static int
mNull(char c)
{
return (MENU_NOTHING);
}
static int
mSelect(char c)
{
if (IS_ASCII(c))
return (select_menu(CurrentMenu, CurrentMenu->keyselect[(int)c]));
else
return (MENU_NOTHING);
}
static int
mDown(char c)
{
if (CurrentMenu->select >= CurrentMenu->nitem - 1)
return (MENU_NOTHING);
goto_menu(CurrentMenu, CurrentMenu->select + 1, 1);
return (MENU_NOTHING);
}
static int
mUp(char c)
{
if (CurrentMenu->select <= 0)
return (MENU_NOTHING);
goto_menu(CurrentMenu, CurrentMenu->select - 1, -1);
return (MENU_NOTHING);
}
static int
mLast(char c)
{
goto_menu(CurrentMenu, CurrentMenu->nitem - 1, -1);
return (MENU_NOTHING);
}
static int
mTop(char c)
{
goto_menu(CurrentMenu, 0, 1);
return (MENU_NOTHING);
}
static int
mNext(char c)
{
int mselect = CurrentMenu->select + CurrentMenu->height;
if (mselect >= CurrentMenu->nitem)
return mLast(c);
down_menu(CurrentMenu, CurrentMenu->height);
goto_menu(CurrentMenu, mselect, -1);
return (MENU_NOTHING);
}
static int
mPrev(char c)
{
int mselect = CurrentMenu->select - CurrentMenu->height;
if (mselect < 0)
return mTop(c);
up_menu(CurrentMenu, CurrentMenu->height);
goto_menu(CurrentMenu, mselect, 1);
return (MENU_NOTHING);
}
static int
mFore(char c)
{
if (CurrentMenu->select >= CurrentMenu->nitem - 1)
return (MENU_NOTHING);
goto_menu(CurrentMenu, (CurrentMenu->select + CurrentMenu->height - 1),
(CurrentMenu->height + 1));
return (MENU_NOTHING);
}
static int
mBack(char c)
{
if (CurrentMenu->select <= 0)
return (MENU_NOTHING);
goto_menu(CurrentMenu, (CurrentMenu->select - CurrentMenu->height + 1),
(-1 - CurrentMenu->height));
return (MENU_NOTHING);
}
static int
mLineU(char c)
{
int mselect = CurrentMenu->select;
if (mselect >= CurrentMenu->nitem)
return mLast(c);
if (CurrentMenu->offset + CurrentMenu->height >= CurrentMenu->nitem)
mselect++;
else {
down_menu(CurrentMenu, 1);
if (mselect < CurrentMenu->offset)
mselect++;
}
goto_menu(CurrentMenu, mselect, 1);
return (MENU_NOTHING);
}
static int
mLineD(char c)
{
int mselect = CurrentMenu->select;
if (mselect <= 0)
return mTop(c);
if (CurrentMenu->offset <= 0)
mselect--;
else {
up_menu(CurrentMenu, 1);
if (mselect >= CurrentMenu->offset + CurrentMenu->height)
mselect--;
}
goto_menu(CurrentMenu, mselect, -1);
return (MENU_NOTHING);
}
static int
mOk(char c)
{
int mselect = CurrentMenu->select;
if (CurrentMenu->item[mselect].type == MENU_NOP)
return (MENU_NOTHING);
return (mselect);
}
static int
mCancel(char c)
{
return (MENU_CANCEL);
}
static int
mClose(char c)
{
return (MENU_CLOSE);
}
static int
mSusp(char c)
{
susp();
draw_all_menu(CurrentMenu);
select_menu(CurrentMenu, CurrentMenu->select);
return (MENU_NOTHING);
}
static char *SearchString = NULL;
int (*menuSearchRoutine) (Menu *, char *, int);
static int
menuForwardSearch(Menu *menu, char *str, int from)
{
int i;
char *p;
if ((p = regexCompile(str, IgnoreCase)) != NULL) {
message(p, 0, 0);
return -1;
}
if (from < 0)
from = 0;
for (i = from; i < menu->nitem; i++)
if (menu->item[i].type != MENU_NOP &&
regexMatch(menu->item[i].label, -1, 1) == 1)
return i;
return -1;
}
static int
menu_search_forward(Menu *menu, int from)
{
char *str;
int found;
str = inputStrHist("Forward: ", NULL, TextHist);
if (str != NULL && *str == '\0')
str = SearchString;
if (str == NULL || *str == '\0')
return -1;
SearchString = str;
str = conv_search_string(str, DisplayCharset);
menuSearchRoutine = menuForwardSearch;
found = menuForwardSearch(menu, str, from + 1);
if (WrapSearch && found == -1)
found = menuForwardSearch(menu, str, 0);
if (found >= 0)
return found;
disp_message("Not found", TRUE);
return -1;
}
static int
mSrchF(char c)
{
int mselect;
mselect = menu_search_forward(CurrentMenu, CurrentMenu->select);
if (mselect >= 0)
goto_menu(CurrentMenu, mselect, 1);
return (MENU_NOTHING);
}
static int
menuBackwardSearch(Menu *menu, char *str, int from)
{
int i;
char *p;
if ((p = regexCompile(str, IgnoreCase)) != NULL) {
message(p, 0, 0);
return -1;
}
if (from >= menu->nitem)
from = menu->nitem - 1;
for (i = from; i >= 0; i--)
if (menu->item[i].type != MENU_NOP &&
regexMatch(menu->item[i].label, -1, 1) == 1)
return i;
return -1;
}
static int
menu_search_backward(Menu *menu, int from)
{
char *str;