aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog/menubox.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/lxdialog/menubox.c')
-rw-r--r--scripts/kconfig/lxdialog/menubox.c166
1 files changed, 87 insertions, 79 deletions
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index bf8052f4fd4a..0d83159d9012 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -63,19 +63,19 @@ static int menu_width, item_x;
63/* 63/*
64 * Print menu item 64 * Print menu item
65 */ 65 */
66static void do_print_item(WINDOW * win, const char *item, int choice, 66static void do_print_item(WINDOW * win, const char *item, int line_y,
67 int selected, int hotkey) 67 int selected, int hotkey)
68{ 68{
69 int j; 69 int j;
70 char *menu_item = malloc(menu_width + 1); 70 char *menu_item = malloc(menu_width + 1);
71 71
72 strncpy(menu_item, item, menu_width - item_x); 72 strncpy(menu_item, item, menu_width - item_x);
73 menu_item[menu_width] = 0; 73 menu_item[menu_width - item_x] = '\0';
74 j = first_alpha(menu_item, "YyNnMmHh"); 74 j = first_alpha(menu_item, "YyNnMmHh");
75 75
76 /* Clear 'residue' of last item */ 76 /* Clear 'residue' of last item */
77 wattrset(win, menubox_attr); 77 wattrset(win, dlg.menubox.atr);
78 wmove(win, choice, 0); 78 wmove(win, line_y, 0);
79#if OLD_NCURSES 79#if OLD_NCURSES
80 { 80 {
81 int i; 81 int i;
@@ -85,23 +85,24 @@ static void do_print_item(WINDOW * win, const char *item, int choice,
85#else 85#else
86 wclrtoeol(win); 86 wclrtoeol(win);
87#endif 87#endif
88 wattrset(win, selected ? item_selected_attr : item_attr); 88 wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
89 mvwaddstr(win, choice, item_x, menu_item); 89 mvwaddstr(win, line_y, item_x, menu_item);
90 if (hotkey) { 90 if (hotkey) {
91 wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); 91 wattrset(win, selected ? dlg.tag_key_selected.atr
92 mvwaddch(win, choice, item_x + j, menu_item[j]); 92 : dlg.tag_key.atr);
93 mvwaddch(win, line_y, item_x + j, menu_item[j]);
93 } 94 }
94 if (selected) { 95 if (selected) {
95 wmove(win, choice, item_x + 1); 96 wmove(win, line_y, item_x + 1);
96 } 97 }
97 free(menu_item); 98 free(menu_item);
98 wrefresh(win); 99 wrefresh(win);
99} 100}
100 101
101#define print_item(index, choice, selected) \ 102#define print_item(index, choice, selected) \
102do {\ 103do { \
103 int hotkey = (items[(index) * 2][0] != ':'); \ 104 item_set(index); \
104 do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ 105 do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
105} while (0) 106} while (0)
106 107
107/* 108/*
@@ -117,11 +118,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
117 wmove(win, y, x); 118 wmove(win, y, x);
118 119
119 if (scroll > 0) { 120 if (scroll > 0) {
120 wattrset(win, uarrow_attr); 121 wattrset(win, dlg.uarrow.atr);
121 waddch(win, ACS_UARROW); 122 waddch(win, ACS_UARROW);
122 waddstr(win, "(-)"); 123 waddstr(win, "(-)");
123 } else { 124 } else {
124 wattrset(win, menubox_attr); 125 wattrset(win, dlg.menubox.atr);
125 waddch(win, ACS_HLINE); 126 waddch(win, ACS_HLINE);
126 waddch(win, ACS_HLINE); 127 waddch(win, ACS_HLINE);
127 waddch(win, ACS_HLINE); 128 waddch(win, ACS_HLINE);
@@ -133,11 +134,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
133 wrefresh(win); 134 wrefresh(win);
134 135
135 if ((height < item_no) && (scroll + height < item_no)) { 136 if ((height < item_no) && (scroll + height < item_no)) {
136 wattrset(win, darrow_attr); 137 wattrset(win, dlg.darrow.atr);
137 waddch(win, ACS_DARROW); 138 waddch(win, ACS_DARROW);
138 waddstr(win, "(+)"); 139 waddstr(win, "(+)");
139 } else { 140 } else {
140 wattrset(win, menubox_border_attr); 141 wattrset(win, dlg.menubox_border.atr);
141 waddch(win, ACS_HLINE); 142 waddch(win, ACS_HLINE);
142 waddch(win, ACS_HLINE); 143 waddch(win, ACS_HLINE);
143 waddch(win, ACS_HLINE); 144 waddch(win, ACS_HLINE);
@@ -178,17 +179,26 @@ static void do_scroll(WINDOW *win, int *scroll, int n)
178/* 179/*
179 * Display a menu for choosing among a number of options 180 * Display a menu for choosing among a number of options
180 */ 181 */
181int dialog_menu(const char *title, const char *prompt, int height, int width, 182int dialog_menu(const char *title, const char *prompt,
182 int menu_height, const char *current, int item_no, 183 const void *selected, int *s_scroll)
183 const char *const *items)
184{ 184{
185 int i, j, x, y, box_x, box_y; 185 int i, j, x, y, box_x, box_y;
186 int height, width, menu_height;
186 int key = 0, button = 0, scroll = 0, choice = 0; 187 int key = 0, button = 0, scroll = 0, choice = 0;
187 int first_item = 0, max_choice; 188 int first_item = 0, max_choice;
188 WINDOW *dialog, *menu; 189 WINDOW *dialog, *menu;
189 FILE *f;
190 190
191 max_choice = MIN(menu_height, item_no); 191do_resize:
192 height = getmaxy(stdscr);
193 width = getmaxx(stdscr);
194 if (height < 15 || width < 65)
195 return -ERRDISPLAYTOOSMALL;
196
197 height -= 4;
198 width -= 5;
199 menu_height = height - 10;
200
201 max_choice = MIN(menu_height, item_count());
192 202
193 /* center dialog box on screen */ 203 /* center dialog box on screen */
194 x = (COLS - width) / 2; 204 x = (COLS - width) / 2;
@@ -199,18 +209,19 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
199 dialog = newwin(height, width, y, x); 209 dialog = newwin(height, width, y, x);
200 keypad(dialog, TRUE); 210 keypad(dialog, TRUE);
201 211
202 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 212 draw_box(dialog, 0, 0, height, width,
203 wattrset(dialog, border_attr); 213 dlg.dialog.atr, dlg.border.atr);
214 wattrset(dialog, dlg.border.atr);
204 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 215 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
205 for (i = 0; i < width - 2; i++) 216 for (i = 0; i < width - 2; i++)
206 waddch(dialog, ACS_HLINE); 217 waddch(dialog, ACS_HLINE);
207 wattrset(dialog, dialog_attr); 218 wattrset(dialog, dlg.dialog.atr);
208 wbkgdset(dialog, dialog_attr & A_COLOR); 219 wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
209 waddch(dialog, ACS_RTEE); 220 waddch(dialog, ACS_RTEE);
210 221
211 print_title(dialog, title, width); 222 print_title(dialog, title, width);
212 223
213 wattrset(dialog, dialog_attr); 224 wattrset(dialog, dlg.dialog.atr);
214 print_autowrap(dialog, prompt, width - 2, 1, 3); 225 print_autowrap(dialog, prompt, width - 2, 1, 3);
215 226
216 menu_width = width - 6; 227 menu_width = width - 6;
@@ -224,33 +235,29 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
224 235
225 /* draw a box around the menu items */ 236 /* draw a box around the menu items */
226 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, 237 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
227 menubox_border_attr, menubox_attr); 238 dlg.menubox_border.atr, dlg.menubox.atr);
228 239
229 item_x = (menu_width - 70) / 2; 240 if (menu_width >= 80)
241 item_x = (menu_width - 70) / 2;
242 else
243 item_x = 4;
230 244
231 /* Set choice to default item */ 245 /* Set choice to default item */
232 for (i = 0; i < item_no; i++) 246 item_foreach()
233 if (strcmp(current, items[i * 2]) == 0) 247 if (selected && (selected == item_data()))
234 choice = i; 248 choice = item_n();
235 249 /* get the saved scroll info */
236 /* get the scroll info from the temp file */ 250 scroll = *s_scroll;
237 if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { 251 if ((scroll <= choice) && (scroll + max_choice > choice) &&
238 if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && 252 (scroll >= 0) && (scroll + max_choice <= item_count())) {
239 (scroll + max_choice > choice) && (scroll >= 0) && 253 first_item = scroll;
240 (scroll + max_choice <= item_no)) { 254 choice = choice - scroll;
241 first_item = scroll; 255 } else {
242 choice = choice - scroll; 256 scroll = 0;
243 fclose(f);
244 } else {
245 scroll = 0;
246 remove("lxdialog.scrltmp");
247 fclose(f);
248 f = NULL;
249 }
250 } 257 }
251 if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { 258 if ((choice >= max_choice)) {
252 if (choice >= item_no - max_choice / 2) 259 if (choice >= item_count() - max_choice / 2)
253 scroll = first_item = item_no - max_choice; 260 scroll = first_item = item_count() - max_choice;
254 else 261 else
255 scroll = first_item = choice - max_choice / 2; 262 scroll = first_item = choice - max_choice / 2;
256 choice = choice - scroll; 263 choice = choice - scroll;
@@ -263,14 +270,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
263 270
264 wnoutrefresh(menu); 271 wnoutrefresh(menu);
265 272
266 print_arrows(dialog, item_no, scroll, 273 print_arrows(dialog, item_count(), scroll,
267 box_y, box_x + item_x + 1, menu_height); 274 box_y, box_x + item_x + 1, menu_height);
268 275
269 print_buttons(dialog, height, width, 0); 276 print_buttons(dialog, height, width, 0);
270 wmove(menu, choice, item_x + 1); 277 wmove(menu, choice, item_x + 1);
271 wrefresh(menu); 278 wrefresh(menu);
272 279
273 while (key != ESC) { 280 while (key != KEY_ESC) {
274 key = wgetch(menu); 281 key = wgetch(menu);
275 282
276 if (key < 256 && isalpha(key)) 283 if (key < 256 && isalpha(key))
@@ -280,14 +287,16 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
280 i = max_choice; 287 i = max_choice;
281 else { 288 else {
282 for (i = choice + 1; i < max_choice; i++) { 289 for (i = choice + 1; i < max_choice; i++) {
283 j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); 290 item_set(scroll + i);
284 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 291 j = first_alpha(item_str(), "YyNnMmHh");
292 if (key == tolower(item_str()[j]))
285 break; 293 break;
286 } 294 }
287 if (i == max_choice) 295 if (i == max_choice)
288 for (i = 0; i < max_choice; i++) { 296 for (i = 0; i < max_choice; i++) {
289 j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); 297 item_set(scroll + i);
290 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 298 j = first_alpha(item_str(), "YyNnMmHh");
299 if (key == tolower(item_str()[j]))
291 break; 300 break;
292 } 301 }
293 } 302 }
@@ -312,7 +321,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
312 print_item(scroll+choice, choice, FALSE); 321 print_item(scroll+choice, choice, FALSE);
313 322
314 if ((choice > max_choice - 3) && 323 if ((choice > max_choice - 3) &&
315 (scroll + max_choice < item_no)) { 324 (scroll + max_choice < item_count())) {
316 /* Scroll menu up */ 325 /* Scroll menu up */
317 do_scroll(menu, &scroll, 1); 326 do_scroll(menu, &scroll, 1);
318 327
@@ -335,7 +344,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
335 344
336 } else if (key == KEY_NPAGE) { 345 } else if (key == KEY_NPAGE) {
337 for (i = 0; (i < max_choice); i++) { 346 for (i = 0; (i < max_choice); i++) {
338 if (scroll + max_choice < item_no) { 347 if (scroll + max_choice < item_count()) {
339 do_scroll(menu, &scroll, 1); 348 do_scroll(menu, &scroll, 1);
340 print_item(scroll+max_choice-1, 349 print_item(scroll+max_choice-1,
341 max_choice - 1, FALSE); 350 max_choice - 1, FALSE);
@@ -349,7 +358,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
349 358
350 print_item(scroll + choice, choice, TRUE); 359 print_item(scroll + choice, choice, TRUE);
351 360
352 print_arrows(dialog, item_no, scroll, 361 print_arrows(dialog, item_count(), scroll,
353 box_y, box_x + item_x + 1, menu_height); 362 box_y, box_x + item_x + 1, menu_height);
354 363
355 wnoutrefresh(dialog); 364 wnoutrefresh(dialog);
@@ -375,12 +384,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
375 case 'm': 384 case 'm':
376 case '/': 385 case '/':
377 /* save scroll info */ 386 /* save scroll info */
378 if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { 387 *s_scroll = scroll;
379 fprintf(f, "%d\n", scroll); 388 delwin(menu);
380 fclose(f);
381 }
382 delwin(dialog); 389 delwin(dialog);
383 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 390 item_set(scroll + choice);
391 item_set_selected(1);
384 switch (key) { 392 switch (key) {
385 case 's': 393 case 's':
386 return 3; 394 return 3;
@@ -400,27 +408,27 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
400 case '?': 408 case '?':
401 button = 2; 409 button = 2;
402 case '\n': 410 case '\n':
411 *s_scroll = scroll;
412 delwin(menu);
403 delwin(dialog); 413 delwin(dialog);
404 if (button == 2) 414 item_set(scroll + choice);
405 fprintf(stderr, "%s \"%s\"\n", 415 item_set_selected(1);
406 items[(scroll + choice) * 2],
407 items[(scroll + choice) * 2 + 1] +
408 first_alpha(items [(scroll + choice) * 2 + 1], ""));
409 else
410 fprintf(stderr, "%s\n",
411 items[(scroll + choice) * 2]);
412
413 remove("lxdialog.scrltmp");
414 return button; 416 return button;
415 case 'e': 417 case 'e':
416 case 'x': 418 case 'x':
417 key = ESC; 419 key = KEY_ESC;
418 case ESC: 420 break;
421 case KEY_ESC:
422 key = on_key_esc(menu);
419 break; 423 break;
424 case KEY_RESIZE:
425 on_key_resize();
426 delwin(menu);
427 delwin(dialog);
428 goto do_resize;
420 } 429 }
421 } 430 }
422 431 delwin(menu);
423 delwin(dialog); 432 delwin(dialog);
424 remove("lxdialog.scrltmp"); 433 return key; /* ESC pressed */
425 return -1; /* ESC pressed */
426} 434}