X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=lxdialog%2Fmenubox.c;h=a234e9f3b56c507153119d9f6d16210c3b32e683;hb=96b4ee1ee2da310e9ea951a29672a7609dbf831e;hp=80f2e22feab999e2b94f2e67df7acea40378c004;hpb=6ee1e193fd896ab9a4729fde14f009d9ce629815;p=vlc diff --git a/lxdialog/menubox.c b/lxdialog/menubox.c index 80f2e22fea..a234e9f3b5 100644 --- a/lxdialog/menubox.c +++ b/lxdialog/menubox.c @@ -26,7 +26,7 @@ * * *) A bugfix for the Page-Down problem * - * *) Formerly when I used Page Down and Page Up, the cursor would be set + * *) Formerly when I used Page Down and Page Up, the cursor would be set * to the first position in the menu box. Now lxdialog is a bit * smarter and works more like other menu systems (just have a look at * it). @@ -80,7 +80,7 @@ print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey { int i; for (i = 0; i < menu_width; i++) - waddch (win, ' '); + waddch (win, ' '); } #else wclrtoeol(win); @@ -88,12 +88,12 @@ print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey wattrset (win, selected ? item_selected_attr : item_attr); mvwaddstr (win, choice, item_x, menu_item); if (hotkey) { - wattrset (win, selected ? tag_key_selected_attr : tag_key_attr); - mvwaddch(win, choice, item_x+j, menu_item[j]); + wattrset (win, selected ? tag_key_selected_attr : tag_key_attr); + mvwaddch(win, choice, item_x+j, menu_item[j]); } if (selected) { - wmove (win, choice, item_x+1); - wrefresh (win); + wmove (win, choice, item_x+1); + wrefresh (win); } } @@ -102,7 +102,7 @@ print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey */ static void print_arrows (WINDOW * win, int item_no, int scroll, - int y, int x, int height) + int y, int x, int height) { int cur_y, cur_x; @@ -111,32 +111,32 @@ print_arrows (WINDOW * win, int item_no, int scroll, wmove(win, y, x); if (scroll > 0) { - wattrset (win, uarrow_attr); - waddch (win, ACS_UARROW); - waddstr (win, "(-)"); + wattrset (win, uarrow_attr); + waddch (win, ACS_UARROW); + waddstr (win, "(-)"); } else { - wattrset (win, menubox_attr); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); + wattrset (win, menubox_attr); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); } y = y + height + 1; wmove(win, y, x); if ((height < item_no) && (scroll + height < item_no)) { - wattrset (win, darrow_attr); - waddch (win, ACS_DARROW); - waddstr (win, "(+)"); + wattrset (win, darrow_attr); + waddch (win, ACS_DARROW); + waddstr (win, "(+)"); } else { - wattrset (win, menubox_border_attr); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); - waddch (win, ACS_HLINE); + wattrset (win, menubox_border_attr); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); + waddch (win, ACS_HLINE); } wmove(win, cur_y, cur_x); @@ -164,8 +164,8 @@ print_buttons (WINDOW *win, int height, int width, int selected) */ int dialog_menu (const char *title, const char *prompt, int height, int width, - int menu_height, const char *current, int item_no, - const char * const * items) + int menu_height, const char *current, int item_no, + const char * const * items) { int i, j, x, y, box_x, box_y; @@ -188,24 +188,24 @@ dialog_menu (const char *title, const char *prompt, int height, int width, wattrset (dialog, border_attr); mvwaddch (dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) - waddch (dialog, ACS_HLINE); + waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); wbkgdset (dialog, dialog_attr & A_COLOR); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { - /* truncate long title -- mec */ - char * title2 = malloc(width-2+1); - memcpy( title2, title, width-2 ); - title2[width-2] = '\0'; - title = title2; + /* truncate long title -- mec */ + char * title2 = malloc(width-2+1); + memcpy( title2, title, width-2 ); + title2[width-2] = '\0'; + title = title2; } if (title != NULL) { - wattrset (dialog, title_attr); - mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); - waddstr (dialog, (char *)title); - waddch (dialog, ' '); + wattrset (dialog, title_attr); + mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); + waddstr (dialog, (char *)title); + waddch (dialog, ' '); } wattrset (dialog, dialog_attr); @@ -217,85 +217,85 @@ dialog_menu (const char *title, const char *prompt, int height, int width, /* create new window for the menu */ menu = subwin (dialog, menu_height, menu_width, - y + box_y + 1, x + box_x + 1); + y + box_y + 1, x + box_x + 1); keypad (menu, TRUE); /* draw a box around the menu items */ draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2, - menubox_border_attr, menubox_attr); + menubox_border_attr, menubox_attr); /* * Find length of longest item in order to center menu. - * Set 'choice' to default item. + * Set 'choice' to default item. */ item_x = 0; for (i = 0; i < item_no; i++) { - item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2)); - if (strcmp(current, items[i*2]) == 0) choice = i; + item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2)); + if (strcmp(current, items[i*2]) == 0) choice = i; } item_x = (menu_width - item_x) / 2; /* get the scroll info from the temp file */ if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) { - if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) && - (scroll+max_choice > choice) && (scroll >= 0) && - (scroll+max_choice <= item_no) ) { - first_item = scroll; - choice = choice - scroll; - fclose(f); - } else { - scroll=0; - remove("lxdialog.scrltmp"); - fclose(f); - f=NULL; - } + if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) && + (scroll+max_choice > choice) && (scroll >= 0) && + (scroll+max_choice <= item_no) ) { + first_item = scroll; + choice = choice - scroll; + fclose(f); + } else { + scroll=0; + remove("lxdialog.scrltmp"); + fclose(f); + f=NULL; + } } if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) { - if (choice >= item_no-max_choice/2) - scroll = first_item = item_no-max_choice; - else - scroll = first_item = choice - max_choice/2; - choice = choice - scroll; + if (choice >= item_no-max_choice/2) + scroll = first_item = item_no-max_choice; + else + scroll = first_item = choice - max_choice/2; + choice = choice - scroll; } /* Print the menu */ for (i=0; i < max_choice; i++) { - print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice, + print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice, (items[(first_item + i)*2][0] != ':')); } wnoutrefresh (menu); print_arrows(dialog, item_no, scroll, - box_y, box_x+item_x+1, menu_height); + box_y, box_x+item_x+1, menu_height); print_buttons (dialog, height, width, 0); wmove (menu, choice, item_x+1); wrefresh (menu); while (key != ESC) { - key = wgetch(menu); + key = wgetch(menu); - if (key < 256 && isalpha(key)) key = tolower(key); + if (key < 256 && isalpha(key)) key = tolower(key); - if (strchr("ynm", key)) - i = max_choice; - else { + if (strchr("ynm", key)) + i = max_choice; + else { for (i = choice+1; i < max_choice; i++) { - j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); - if (key == tolower(items[(scroll+i)*2+1][j])) - break; - } - if (i == max_choice) - for (i = 0; i < max_choice; i++) { - j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); - if (key == tolower(items[(scroll+i)*2+1][j])) - break; - } - } - - if (i < max_choice || + j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); + if (key == tolower(items[(scroll+i)*2+1][j])) + break; + } + if (i == max_choice) + for (i = 0; i < max_choice; i++) { + j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); + if (key == tolower(items[(scroll+i)*2+1][j])) + break; + } + } + + if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { @@ -303,9 +303,9 @@ dialog_menu (const char *title, const char *prompt, int height, int width, print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, (items[(scroll+choice)*2][0] != ':')); - if (key == KEY_UP || key == '-') { + if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { - /* Scroll menu down */ + /* Scroll menu down */ scrollok (menu, TRUE); wscrl (menu, -1); scrollok (menu, FALSE); @@ -314,19 +314,19 @@ dialog_menu (const char *title, const char *prompt, int height, int width, print_item (menu, items[scroll * 2 + 1], 0, FALSE, (items[scroll*2][0] != ':')); - } else - choice = MAX(choice - 1, 0); + } else + choice = MAX(choice - 1, 0); - } else if (key == KEY_DOWN || key == '+') { + } else if (key == KEY_DOWN || key == '+') { - print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, + print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, (items[(scroll+choice)*2][0] != ':')); if ((choice > max_choice-3) && (scroll + max_choice < item_no) ) { - /* Scroll menu up */ - scrollok (menu, TRUE); + /* Scroll menu up */ + scrollok (menu, TRUE); scroll (menu); scrollok (menu, FALSE); @@ -338,14 +338,14 @@ dialog_menu (const char *title, const char *prompt, int height, int width, } else choice = MIN(choice+1, max_choice-1); - } else if (key == KEY_PPAGE) { - scrollok (menu, TRUE); + } else if (key == KEY_PPAGE) { + scrollok (menu, TRUE); for (i=0; (i < max_choice); i++) { if (scroll > 0) { - wscrl (menu, -1); - scroll--; - print_item (menu, items[scroll * 2 + 1], 0, FALSE, - (items[scroll*2][0] != ':')); + wscrl (menu, -1); + scroll--; + print_item (menu, items[scroll * 2 + 1], 0, FALSE, + (items[scroll*2][0] != ':')); } else { if (choice > 0) choice--; @@ -356,17 +356,17 @@ dialog_menu (const char *title, const char *prompt, int height, int width, } else if (key == KEY_NPAGE) { for (i=0; (i < max_choice); i++) { if (scroll+max_choice < item_no) { - scrollok (menu, TRUE); - scroll(menu); - scrollok (menu, FALSE); - scroll++; - print_item (menu, items[(scroll+max_choice-1)*2+1], - max_choice-1, FALSE, - (items[(scroll+max_choice-1)*2][0] != ':')); - } else { - if (choice+1 < max_choice) - choice++; - } + scrollok (menu, TRUE); + scroll(menu); + scrollok (menu, FALSE); + scroll++; + print_item (menu, items[(scroll+max_choice-1)*2+1], + max_choice-1, FALSE, + (items[(scroll+max_choice-1)*2][0] != ':')); + } else { + if (choice+1 < max_choice) + choice++; + } } } else @@ -381,30 +381,30 @@ dialog_menu (const char *title, const char *prompt, int height, int width, wnoutrefresh (dialog); wrefresh (menu); - continue; /* wait for another key press */ + continue; /* wait for another key press */ } - switch (key) { - case KEY_LEFT: - case TAB: - case KEY_RIGHT: - button = ((key == KEY_LEFT ? --button : ++button) < 0) - ? 2 : (button > 2 ? 0 : button); - - print_buttons(dialog, height, width, button); - wrefresh (menu); - break; - case ' ': - case 's': - case 'y': - case 'n': - case 'm': - /* save scroll info */ - if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { - fprintf(f,"%d\n",scroll); - fclose(f); - } - delwin (dialog); + switch (key) { + case KEY_LEFT: + case TAB: + case KEY_RIGHT: + button = ((key == KEY_LEFT ? --button : ++button) < 0) + ? 2 : (button > 2 ? 0 : button); + + print_buttons(dialog, height, width, button); + wrefresh (menu); + break; + case ' ': + case 's': + case 'y': + case 'n': + case 'm': + /* save scroll info */ + if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { + fprintf(f,"%d\n",scroll); + fclose(f); + } + delwin (dialog); fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); switch (key) { case 's': return 3; @@ -413,31 +413,31 @@ dialog_menu (const char *title, const char *prompt, int height, int width, case 'm': return 5; case ' ': return 6; } - return 0; - case 'h': - case '?': - button = 2; - case '\n': - delwin (dialog); - if (button == 2) - fprintf(stderr, "%s \"%s\"\n", - items[(scroll + choice) * 2], - items[(scroll + choice) * 2 + 1] + - first_alpha(items[(scroll + choice) * 2 + 1],"")); - else - fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); - - remove("lxdialog.scrltmp"); - return button; - case 'e': - case 'x': - key = ESC; - case ESC: - break; - } + return 0; + case 'h': + case '?': + button = 2; + case '\n': + delwin (dialog); + if (button == 2) + fprintf(stderr, "%s \"%s\"\n", + items[(scroll + choice) * 2], + items[(scroll + choice) * 2 + 1] + + first_alpha(items[(scroll + choice) * 2 + 1],"")); + else + fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); + + remove("lxdialog.scrltmp"); + return button; + case 'e': + case 'x': + key = ESC; + case ESC: + break; + } } delwin (dialog); remove("lxdialog.scrltmp"); - return -1; /* ESC pressed */ + return -1; /* ESC pressed */ }