summaryrefslogtreecommitdiff
path: root/misc/dialog/patches/patch-af
blob: d842935b1166a6ad69906e18f6939daf9561d4e5 (plain)
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
$NetBSD: patch-af,v 1.3 2000/07/28 20:30:11 jlam Exp $

--- menubox.c.orig	Thu Aug 17 22:21:00 1995
+++ menubox.c	Fri Jul 28 15:30:22 2000
@@ -53,12 +53,32 @@
 dialog_menu (const char *title, const char *prompt, int height, int width,
 		int menu_height, int item_no, const char * const * items)
 {
-    int i, x, y, cur_x, cur_y, box_x, box_y;
-    int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
+    int i, j, x, y, cur_x, cur_y, box_x, box_y;
+    int key = 0, button = 0, choice = 0, d_scroll = 0, max_choice;
     WINDOW *dialog, *menu;
 
     max_choice = MIN (menu_height, item_no);
 
+    /* Find length of longest item in order to center menu */
+    tag_x = 0;
+    item_x = 0;
+    for (i = 0; i < item_no; i++) {
+        tag_x = MAX (tag_x,
+                     strlen (items[i * 2]) + strlen (items[i * 2 + 1]) + 2);
+        item_x = MAX (item_x, strlen (items[i * 2]));
+    }
+
+    /* Choose useful default height and width if they are negative */
+    if (height < 0)
+        height = strheight(prompt) + menu_height + 4 + 2;
+    if (width < 0) {
+        i = strwidth(prompt);
+        j = ((title != NULL) ? strwidth(title) : 0);
+        width = MAX (i, j);
+        width = MAX (width, tag_x + 4) + 4;
+    }
+    width = MAX (width, MIN_DIALOG_WIDTH);
+
     /* center dialog box on screen */
     x = (COLS - width) / 2;
     y = (LINES - height) / 2;
@@ -107,14 +127,6 @@
     draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,
 	      menubox_border_attr, menubox_attr);
 
-    tag_x = 0;
-    item_x = 0;
-    /* Find length of longest item in order to center menu */
-    for (i = 0; i < item_no; i++) {
-	tag_x = MAX (tag_x,
-		     strlen (items[i * 2]) + strlen (items[i * 2 + 1]) + 2);
-	item_x = MAX (item_x, strlen (items[i * 2]));
-    }
     tag_x = (menu_width - tag_x) / 2;
     item_x = tag_x + item_x + 2;
 
@@ -146,7 +158,7 @@
 	/* Check if key pressed matches first character of any
 	   item tag in menu */
 	for (i = 0; i < max_choice; i++)
-	    if (toupper (key) == toupper (items[(scroll + i) * 2][0]))
+	    if (toupper (key) == toupper (items[(d_scroll + i) * 2][0]))
 		break;
 
 	if (i < max_choice ||
@@ -159,33 +171,33 @@
 		i = key - M_EVENT;
 	    else if (key == KEY_UP || key == '-') {
 		if (!choice) {
-		    if (scroll) {
+		    if (d_scroll) {
 
 			/* Scroll menu down */
 			getyx (dialog, cur_y, cur_x);
 			if (menu_height > 1) {
 			    /* De-highlight current first item */
-			    print_item (menu, items[scroll * 2],
-					items[scroll * 2 + 1], 0, FALSE);
+			    print_item (menu, items[d_scroll * 2],
+					items[d_scroll * 2 + 1], 0, FALSE);
 			    scrollok (menu, TRUE);
 			    wscrl (menu, -1);
 			    scrollok (menu, FALSE);
 			}
-			scroll--;
-			print_item (menu, items[scroll * 2],
-				    items[scroll * 2 + 1], 0, TRUE);
+			d_scroll--;
+			print_item (menu, items[d_scroll * 2],
+				    items[d_scroll * 2 + 1], 0, TRUE);
 			wnoutrefresh (menu);
 
 			/* print the up/down arrows */
 			wmove (dialog, box_y, box_x + tag_x + 1);
-			wattrset (dialog, scroll ? uarrow_attr : menubox_attr);
-			waddch (dialog, scroll ? ACS_UARROW : ACS_HLINE);
+			wattrset (dialog, d_scroll ? uarrow_attr : menubox_attr);
+			waddch (dialog, d_scroll ? ACS_UARROW : ACS_HLINE);
 			wmove (dialog, box_y, box_x + tag_x + 2);
-			waddch (dialog, scroll ? '(' : ACS_HLINE);
+			waddch (dialog, d_scroll ? '(' : ACS_HLINE);
 			wmove (dialog, box_y, box_x + tag_x + 3);
-			waddch (dialog, scroll ? '-' : ACS_HLINE);
+			waddch (dialog, d_scroll ? '-' : ACS_HLINE);
 			wmove (dialog, box_y, box_x + tag_x + 4);
-			waddch (dialog, scroll ? ')' : ACS_HLINE);
+			waddch (dialog, d_scroll ? ')' : ACS_HLINE);
 			wattrset (dialog, darrow_attr);
 			wmove (dialog, box_y + menu_height + 1,
 			       box_x + tag_x + 1);
@@ -201,21 +213,21 @@
 		    i = choice - 1;
 	    } else if (key == KEY_DOWN || key == '+')
 		if (choice == max_choice - 1) {
-		    if (scroll + choice < item_no - 1) {
+		    if (d_scroll + choice < item_no - 1) {
 			/* Scroll menu up */
 			getyx (dialog, cur_y, cur_x);
 			if (menu_height > 1) {
 			    /* De-highlight current last item */
-			    print_item (menu, items[(scroll + max_choice - 1)
-				       * 2], items[(scroll + max_choice - 1)
+			    print_item (menu, items[(d_scroll + max_choice - 1)
+				       * 2], items[(d_scroll + max_choice - 1)
 					   * 2 + 1], max_choice - 1, FALSE);
 			    scrollok (menu, TRUE);
 			    scroll (menu);
 			    scrollok (menu, FALSE);
 			}
-			scroll++;
-			print_item (menu, items[(scroll + max_choice - 1) * 2],
-				    items[(scroll + max_choice - 1) * 2 + 1],
+			d_scroll++;
+			print_item (menu, items[(d_scroll + max_choice - 1) * 2],
+				    items[(d_scroll + max_choice - 1) * 2 + 1],
 				    max_choice - 1, TRUE);
 			wnoutrefresh (menu);
 
@@ -227,21 +239,21 @@
 			waddstr (dialog, "(-)");
 			wmove (dialog, box_y + menu_height + 1,
 			       box_x + tag_x + 1);
-			wattrset (dialog, scroll + choice < item_no - 1 ?
+			wattrset (dialog, d_scroll + choice < item_no - 1 ?
 				  darrow_attr : menubox_border_attr);
-			waddch (dialog, scroll + choice < item_no - 1 ?
+			waddch (dialog, d_scroll + choice < item_no - 1 ?
 				ACS_DARROW : ACS_HLINE);
 			wmove (dialog, box_y + menu_height + 1,
 			       box_x + tag_x + 2);
-			waddch (dialog, scroll + choice < item_no - 1 ?
+			waddch (dialog, d_scroll + choice < item_no - 1 ?
 				'(' : ACS_HLINE);
 			wmove (dialog, box_y + menu_height + 1,
 			       box_x + tag_x + 3);
-			waddch (dialog, scroll + choice < item_no - 1 ?
+			waddch (dialog, d_scroll + choice < item_no - 1 ?
 				'+' : ACS_HLINE);
 			wmove (dialog, box_y + menu_height + 1,
 			       box_x + tag_x + 4);
-			waddch (dialog, scroll + choice < item_no - 1 ?
+			waddch (dialog, d_scroll + choice < item_no - 1 ?
 				')' : ACS_HLINE);
 			wmove (dialog, cur_y, cur_x);
 			wrefresh (dialog);
@@ -253,13 +265,13 @@
 	    if (i != choice) {
 		/* De-highlight current item */
 		getyx (dialog, cur_y, cur_x);	/* Save cursor position */
-		print_item (menu, items[(scroll + choice) * 2],
-			    items[(scroll + choice) * 2 + 1], choice, FALSE);
+		print_item (menu, items[(d_scroll + choice) * 2],
+			    items[(d_scroll + choice) * 2 + 1], choice, FALSE);
 
 		/* Highlight new item */
 		choice = i;
-		print_item (menu, items[(scroll + choice) * 2],
-			    items[(scroll + choice) * 2 + 1], choice, TRUE);
+		print_item (menu, items[(d_scroll + choice) * 2],
+			    items[(d_scroll + choice) * 2 + 1], choice, TRUE);
 		wnoutrefresh (menu);
 		wmove (dialog, cur_y, cur_x);
 		wrefresh (dialog);
@@ -271,7 +283,7 @@
 	case 'o':
 	case M_EVENT + 'O':
 	    delwin (dialog);
-	    return scroll + choice;
+	    return d_scroll + choice;
 	case 'C':
 	case 'c':
 	case M_EVENT + 'C':
@@ -297,7 +309,7 @@
 	    break;
 	case '\n':
 	    delwin (dialog);
-	    return (button? -2 : (scroll + choice));
+	    return (button? -2 : (d_scroll + choice));
 	case ESC:
 	    break;
 	}