diff options
Diffstat (limited to 'scripts/lxdialog/menubox.c')
-rw-r--r-- | scripts/lxdialog/menubox.c | 83 |
1 files changed, 26 insertions, 57 deletions
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c index 083f13de558c..260cc4dd5dab 100644 --- a/scripts/lxdialog/menubox.c +++ b/scripts/lxdialog/menubox.c | |||
@@ -63,8 +63,8 @@ static int menu_width, item_x; | |||
63 | /* | 63 | /* |
64 | * Print menu item | 64 | * Print menu item |
65 | */ | 65 | */ |
66 | static void | 66 | static void print_item(WINDOW * win, const char *item, int choice, |
67 | print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) | 67 | int selected, int hotkey) |
68 | { | 68 | { |
69 | int j; | 69 | int j; |
70 | char menu_item[menu_width + 1]; | 70 | char menu_item[menu_width + 1]; |
@@ -100,8 +100,8 @@ print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey) | |||
100 | /* | 100 | /* |
101 | * Print the scroll indicators. | 101 | * Print the scroll indicators. |
102 | */ | 102 | */ |
103 | static void | 103 | static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, |
104 | print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height) | 104 | int height) |
105 | { | 105 | { |
106 | int cur_y, cur_x; | 106 | int cur_y, cur_x; |
107 | 107 | ||
@@ -158,10 +158,9 @@ static void print_buttons(WINDOW * win, int height, int width, int selected) | |||
158 | /* | 158 | /* |
159 | * Display a menu for choosing among a number of options | 159 | * Display a menu for choosing among a number of options |
160 | */ | 160 | */ |
161 | int | 161 | int dialog_menu(const char *title, const char *prompt, int height, int width, |
162 | dialog_menu(const char *title, const char *prompt, int height, int width, | 162 | int menu_height, const char *current, int item_no, |
163 | int menu_height, const char *current, int item_no, | 163 | const char *const *items) |
164 | const char *const *items) | ||
165 | { | 164 | { |
166 | int i, j, x, y, box_x, box_y; | 165 | int i, j, x, y, box_x, box_y; |
167 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = | 166 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = |
@@ -283,20 +282,14 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
283 | i = max_choice; | 282 | i = max_choice; |
284 | else { | 283 | else { |
285 | for (i = choice + 1; i < max_choice; i++) { | 284 | for (i = choice + 1; i < max_choice; i++) { |
286 | j = first_alpha(items[(scroll + i) * 2 + 1], | 285 | j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); |
287 | "YyNnMmHh"); | 286 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) |
288 | if (key == | ||
289 | tolower(items[(scroll + i) * 2 + 1][j])) | ||
290 | break; | 287 | break; |
291 | } | 288 | } |
292 | if (i == max_choice) | 289 | if (i == max_choice) |
293 | for (i = 0; i < max_choice; i++) { | 290 | for (i = 0; i < max_choice; i++) { |
294 | j = first_alpha(items | 291 | j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); |
295 | [(scroll + i) * 2 + 1], | 292 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) |
296 | "YyNnMmHh"); | ||
297 | if (key == | ||
298 | tolower(items[(scroll + i) * 2 + 1] | ||
299 | [j])) | ||
300 | break; | 293 | break; |
301 | } | 294 | } |
302 | } | 295 | } |
@@ -319,24 +312,19 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
319 | 312 | ||
320 | scroll--; | 313 | scroll--; |
321 | 314 | ||
322 | print_item(menu, items[scroll * 2 + 1], | 315 | print_item(menu, items[scroll * 2 + 1], 0, FALSE, |
323 | 0, FALSE, | 316 | (items[scroll * 2][0] != ':')); |
324 | (items[scroll * 2][0] != | ||
325 | ':')); | ||
326 | } else | 317 | } else |
327 | choice = MAX(choice - 1, 0); | 318 | choice = MAX(choice - 1, 0); |
328 | 319 | ||
329 | } else if (key == KEY_DOWN || key == '+') { | 320 | } else if (key == KEY_DOWN || key == '+') { |
330 | 321 | ||
331 | print_item(menu, | 322 | print_item(menu, |
332 | items[(scroll + choice) * 2 + 1], | 323 | items[(scroll + choice) * 2 + 1], choice, FALSE, |
333 | choice, FALSE, | 324 | (items[(scroll + choice) * 2][0] != ':')); |
334 | (items[(scroll + choice) * 2][0] != | ||
335 | ':')); | ||
336 | 325 | ||
337 | if ((choice > max_choice - 3) && | 326 | if ((choice > max_choice - 3) && |
338 | (scroll + max_choice < item_no) | 327 | (scroll + max_choice < item_no)) { |
339 | ) { | ||
340 | /* Scroll menu up */ | 328 | /* Scroll menu up */ |
341 | scrollok(menu, TRUE); | 329 | scrollok(menu, TRUE); |
342 | wscrl(menu, 1); | 330 | wscrl(menu, 1); |
@@ -344,16 +332,11 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
344 | 332 | ||
345 | scroll++; | 333 | scroll++; |
346 | 334 | ||
347 | print_item(menu, | 335 | print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], |
348 | items[(scroll + max_choice - | ||
349 | 1) * 2 + 1], | ||
350 | max_choice - 1, FALSE, | 336 | max_choice - 1, FALSE, |
351 | (items | 337 | (items [(scroll + max_choice - 1) * 2][0] != ':')); |
352 | [(scroll + max_choice - | ||
353 | 1) * 2][0] != ':')); | ||
354 | } else | 338 | } else |
355 | choice = | 339 | choice = MIN(choice + 1, max_choice - 1); |
356 | MIN(choice + 1, max_choice - 1); | ||
357 | 340 | ||
358 | } else if (key == KEY_PPAGE) { | 341 | } else if (key == KEY_PPAGE) { |
359 | scrollok(menu, TRUE); | 342 | scrollok(menu, TRUE); |
@@ -361,11 +344,8 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
361 | if (scroll > 0) { | 344 | if (scroll > 0) { |
362 | wscrl(menu, -1); | 345 | wscrl(menu, -1); |
363 | scroll--; | 346 | scroll--; |
364 | print_item(menu, | 347 | print_item(menu, items[scroll * 2 + 1], 0, FALSE, |
365 | items[scroll * 2 + | 348 | (items[scroll * 2][0] != ':')); |
366 | 1], 0, FALSE, | ||
367 | (items[scroll * 2][0] | ||
368 | != ':')); | ||
369 | } else { | 349 | } else { |
370 | if (choice > 0) | 350 | if (choice > 0) |
371 | choice--; | 351 | choice--; |
@@ -380,17 +360,9 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
380 | wscrl(menu, 1); | 360 | wscrl(menu, 1); |
381 | scrollok(menu, FALSE); | 361 | scrollok(menu, FALSE); |
382 | scroll++; | 362 | scroll++; |
383 | print_item(menu, | 363 | print_item(menu, items[(scroll + max_choice - 1) * 2 + 1], |
384 | items[(scroll + | 364 | max_choice - 1, FALSE, |
385 | max_choice - | 365 | (items [(scroll + max_choice - 1) * 2][0] != ':')); |
386 | 1) * 2 + 1], | ||
387 | max_choice - 1, | ||
388 | FALSE, | ||
389 | (items | ||
390 | [(scroll + | ||
391 | max_choice - | ||
392 | 1) * 2][0] != | ||
393 | ':')); | ||
394 | } else { | 366 | } else { |
395 | if (choice + 1 < max_choice) | 367 | if (choice + 1 < max_choice) |
396 | choice++; | 368 | choice++; |
@@ -401,8 +373,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
401 | choice = i; | 373 | choice = i; |
402 | 374 | ||
403 | print_item(menu, items[(scroll + choice) * 2 + 1], | 375 | print_item(menu, items[(scroll + choice) * 2 + 1], |
404 | choice, TRUE, | 376 | choice, TRUE, (items[(scroll + choice) * 2][0] != ':')); |
405 | (items[(scroll + choice) * 2][0] != ':')); | ||
406 | 377 | ||
407 | print_arrows(dialog, item_no, scroll, | 378 | print_arrows(dialog, item_no, scroll, |
408 | box_y, box_x + item_x + 1, menu_height); | 379 | box_y, box_x + item_x + 1, menu_height); |
@@ -460,9 +431,7 @@ dialog_menu(const char *title, const char *prompt, int height, int width, | |||
460 | fprintf(stderr, "%s \"%s\"\n", | 431 | fprintf(stderr, "%s \"%s\"\n", |
461 | items[(scroll + choice) * 2], | 432 | items[(scroll + choice) * 2], |
462 | items[(scroll + choice) * 2 + 1] + | 433 | items[(scroll + choice) * 2 + 1] + |
463 | first_alpha(items | 434 | first_alpha(items [(scroll + choice) * 2 + 1], "")); |
464 | [(scroll + choice) * 2 + 1], | ||
465 | "")); | ||
466 | else | 435 | else |
467 | fprintf(stderr, "%s\n", | 436 | fprintf(stderr, "%s\n", |
468 | items[(scroll + choice) * 2]); | 437 | items[(scroll + choice) * 2]); |