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.c95
1 files changed, 40 insertions, 55 deletions
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index ff991db827bd..f39ae29f4fcc 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -99,10 +99,10 @@ static void do_print_item(WINDOW * win, const char *item, int choice,
99 wrefresh(win); 99 wrefresh(win);
100} 100}
101 101
102#define print_item(index, choice, selected) \ 102#define print_item(index, choice, selected) \
103do {\ 103do { \
104 int hotkey = (items[(index) * 2][0] != ':'); \ 104 item_set(index); \
105 do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ 105 do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
106} while (0) 106} while (0)
107 107
108/* 108/*
@@ -180,16 +180,14 @@ static void do_scroll(WINDOW *win, int *scroll, int n)
180 * Display a menu for choosing among a number of options 180 * Display a menu for choosing among a number of options
181 */ 181 */
182int dialog_menu(const char *title, const char *prompt, int height, int width, 182int dialog_menu(const char *title, const char *prompt, int height, int width,
183 int menu_height, const char *current, int item_no, 183 int menu_height, const void *selected, int *s_scroll)
184 const char *const *items)
185{ 184{
186 int i, j, x, y, box_x, box_y; 185 int i, j, x, y, box_x, box_y;
187 int key = 0, button = 0, scroll = 0, choice = 0; 186 int key = 0, button = 0, scroll = 0, choice = 0;
188 int first_item = 0, max_choice; 187 int first_item = 0, max_choice;
189 WINDOW *dialog, *menu; 188 WINDOW *dialog, *menu;
190 FILE *f;
191 189
192 max_choice = MIN(menu_height, item_no); 190 max_choice = MIN(menu_height, item_count());
193 191
194 /* center dialog box on screen */ 192 /* center dialog box on screen */
195 x = (COLS - width) / 2; 193 x = (COLS - width) / 2;
@@ -231,28 +229,21 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
231 item_x = (menu_width - 70) / 2; 229 item_x = (menu_width - 70) / 2;
232 230
233 /* Set choice to default item */ 231 /* Set choice to default item */
234 for (i = 0; i < item_no; i++) 232 item_foreach()
235 if (strcmp(current, items[i * 2]) == 0) 233 if (selected && (selected == item_data()))
236 choice = i; 234 choice = item_n();
237 235 /* get the saved scroll info */
238 /* get the scroll info from the temp file */ 236 scroll = *s_scroll;
239 if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { 237 if ((scroll <= choice) && (scroll + max_choice > choice) &&
240 if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && 238 (scroll >= 0) && (scroll + max_choice <= item_count())) {
241 (scroll + max_choice > choice) && (scroll >= 0) && 239 first_item = scroll;
242 (scroll + max_choice <= item_no)) { 240 choice = choice - scroll;
243 first_item = scroll; 241 } else {
244 choice = choice - scroll; 242 scroll = 0;
245 fclose(f);
246 } else {
247 scroll = 0;
248 remove("lxdialog.scrltmp");
249 fclose(f);
250 f = NULL;
251 }
252 } 243 }
253 if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { 244 if ((choice >= max_choice)) {
254 if (choice >= item_no - max_choice / 2) 245 if (choice >= item_count() - max_choice / 2)
255 scroll = first_item = item_no - max_choice; 246 scroll = first_item = item_count() - max_choice;
256 else 247 else
257 scroll = first_item = choice - max_choice / 2; 248 scroll = first_item = choice - max_choice / 2;
258 choice = choice - scroll; 249 choice = choice - scroll;
@@ -265,7 +256,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
265 256
266 wnoutrefresh(menu); 257 wnoutrefresh(menu);
267 258
268 print_arrows(dialog, item_no, scroll, 259 print_arrows(dialog, item_count(), scroll,
269 box_y, box_x + item_x + 1, menu_height); 260 box_y, box_x + item_x + 1, menu_height);
270 261
271 print_buttons(dialog, height, width, 0); 262 print_buttons(dialog, height, width, 0);
@@ -282,14 +273,16 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
282 i = max_choice; 273 i = max_choice;
283 else { 274 else {
284 for (i = choice + 1; i < max_choice; i++) { 275 for (i = choice + 1; i < max_choice; i++) {
285 j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); 276 item_set(scroll + i);
286 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 277 j = first_alpha(item_str(), "YyNnMmHh");
278 if (key == tolower(item_str()[j]))
287 break; 279 break;
288 } 280 }
289 if (i == max_choice) 281 if (i == max_choice)
290 for (i = 0; i < max_choice; i++) { 282 for (i = 0; i < max_choice; i++) {
291 j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); 283 item_set(scroll + i);
292 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 284 j = first_alpha(item_str(), "YyNnMmHh");
285 if (key == tolower(item_str()[j]))
293 break; 286 break;
294 } 287 }
295 } 288 }
@@ -314,7 +307,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
314 print_item(scroll+choice, choice, FALSE); 307 print_item(scroll+choice, choice, FALSE);
315 308
316 if ((choice > max_choice - 3) && 309 if ((choice > max_choice - 3) &&
317 (scroll + max_choice < item_no)) { 310 (scroll + max_choice < item_count())) {
318 /* Scroll menu up */ 311 /* Scroll menu up */
319 do_scroll(menu, &scroll, 1); 312 do_scroll(menu, &scroll, 1);
320 313
@@ -337,7 +330,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
337 330
338 } else if (key == KEY_NPAGE) { 331 } else if (key == KEY_NPAGE) {
339 for (i = 0; (i < max_choice); i++) { 332 for (i = 0; (i < max_choice); i++) {
340 if (scroll + max_choice < item_no) { 333 if (scroll + max_choice < item_count()) {
341 do_scroll(menu, &scroll, 1); 334 do_scroll(menu, &scroll, 1);
342 print_item(scroll+max_choice-1, 335 print_item(scroll+max_choice-1,
343 max_choice - 1, FALSE); 336 max_choice - 1, FALSE);
@@ -351,7 +344,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
351 344
352 print_item(scroll + choice, choice, TRUE); 345 print_item(scroll + choice, choice, TRUE);
353 346
354 print_arrows(dialog, item_no, scroll, 347 print_arrows(dialog, item_count(), scroll,
355 box_y, box_x + item_x + 1, menu_height); 348 box_y, box_x + item_x + 1, menu_height);
356 349
357 wnoutrefresh(dialog); 350 wnoutrefresh(dialog);
@@ -377,12 +370,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
377 case 'm': 370 case 'm':
378 case '/': 371 case '/':
379 /* save scroll info */ 372 /* save scroll info */
380 if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { 373 *s_scroll = scroll;
381 fprintf(f, "%d\n", scroll); 374 delwin(menu);
382 fclose(f);
383 }
384 delwin(dialog); 375 delwin(dialog);
385 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 376 item_set(scroll + choice);
377 item_set_selected(1);
386 switch (key) { 378 switch (key) {
387 case 's': 379 case 's':
388 return 3; 380 return 3;
@@ -402,17 +394,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
402 case '?': 394 case '?':
403 button = 2; 395 button = 2;
404 case '\n': 396 case '\n':
397 *s_scroll = scroll;
398 delwin(menu);
405 delwin(dialog); 399 delwin(dialog);
406 if (button == 2) 400 item_set(scroll + choice);
407 fprintf(stderr, "%s \"%s\"\n", 401 item_set_selected(1);
408 items[(scroll + choice) * 2],
409 items[(scroll + choice) * 2 + 1] +
410 first_alpha(items [(scroll + choice) * 2 + 1], ""));
411 else
412 fprintf(stderr, "%s\n",
413 items[(scroll + choice) * 2]);
414
415 remove("lxdialog.scrltmp");
416 return button; 402 return button;
417 case 'e': 403 case 'e':
418 case 'x': 404 case 'x':
@@ -421,8 +407,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
421 break; 407 break;
422 } 408 }
423 } 409 }
424 410 delwin(menu);
425 delwin(dialog); 411 delwin(dialog);
426 remove("lxdialog.scrltmp"); 412 return 255; /* ESC pressed */
427 return -1; /* ESC pressed */
428} 413}