Show
Ignore:
Timestamp:
09/11/07 12:55:01 (1 year ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1189508101 +0000
git-parent:

[d6008a8bb8e5e76d77dd15a654fc2fabef8910e9]

git-author:
Rafaël Carré <funman@videolan.org> 1189508101 +0000
Message:

Same for lxdialog and xvmc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lxdialog/menubox.c

    r6ee1e19 rf102b57  
    2727 *    *)  A bugfix for the Page-Down problem 
    2828 * 
    29  *    *)  Formerly when I used Page Down and Page Up, the cursor would be set 
     29 *    *)  Formerly when I used Page Down and Page Up, the cursor would be set  
    3030 *        to the first position in the menu box.  Now lxdialog is a bit 
    3131 *        smarter and works more like other menu systems (just have a look at 
     
    8181        int i; 
    8282        for (i = 0; i < menu_width; i++) 
    83         waddch (win, ' '); 
     83       waddch (win, ' '); 
    8484    } 
    8585#else 
     
    8989    mvwaddstr (win, choice, item_x, menu_item); 
    9090    if (hotkey) { 
    91         wattrset (win, selected ? tag_key_selected_attr : tag_key_attr); 
    92         mvwaddch(win, choice, item_x+j, menu_item[j]); 
     91       wattrset (win, selected ? tag_key_selected_attr : tag_key_attr); 
     92       mvwaddch(win, choice, item_x+j, menu_item[j]); 
    9393    } 
    9494    if (selected) { 
    95     wmove (win, choice, item_x+1); 
    96     wrefresh (win); 
     95   wmove (win, choice, item_x+1); 
     96   wrefresh (win); 
    9797    } 
    9898} 
     
    103103static void 
    104104print_arrows (WINDOW * win, int item_no, int scroll, 
    105         int y, int x, int height) 
     105       int y, int x, int height) 
    106106{ 
    107107    int cur_y, cur_x; 
     
    112112 
    113113    if (scroll > 0) { 
    114     wattrset (win, uarrow_attr); 
    115     waddch (win, ACS_UARROW); 
    116     waddstr (win, "(-)"); 
     114   wattrset (win, uarrow_attr); 
     115   waddch (win, ACS_UARROW); 
     116   waddstr (win, "(-)"); 
    117117    } 
    118118    else { 
    119     wattrset (win, menubox_attr); 
    120     waddch (win, ACS_HLINE); 
    121     waddch (win, ACS_HLINE); 
    122     waddch (win, ACS_HLINE); 
    123     waddch (win, ACS_HLINE); 
     119   wattrset (win, menubox_attr); 
     120   waddch (win, ACS_HLINE); 
     121   waddch (win, ACS_HLINE); 
     122   waddch (win, ACS_HLINE); 
     123   waddch (win, ACS_HLINE); 
    124124    } 
    125125 
     
    128128 
    129129   if ((height < item_no) && (scroll + height < item_no)) { 
    130     wattrset (win, darrow_attr); 
    131     waddch (win, ACS_DARROW); 
    132     waddstr (win, "(+)"); 
     130   wattrset (win, darrow_attr); 
     131   waddch (win, ACS_DARROW); 
     132   waddstr (win, "(+)"); 
    133133    } 
    134134    else { 
    135     wattrset (win, menubox_border_attr); 
    136     waddch (win, ACS_HLINE); 
    137     waddch (win, ACS_HLINE); 
    138     waddch (win, ACS_HLINE); 
    139     waddch (win, ACS_HLINE); 
     135   wattrset (win, menubox_border_attr); 
     136   waddch (win, ACS_HLINE); 
     137   waddch (win, ACS_HLINE); 
     138   waddch (win, ACS_HLINE); 
     139   waddch (win, ACS_HLINE); 
    140140   } 
    141141 
     
    165165int 
    166166dialog_menu (const char *title, const char *prompt, int height, int width, 
    167         int menu_height, const char *current, int item_no, 
    168         const char * const * items) 
     167       int menu_height, const char *current, int item_no, 
     168       const char * const * items) 
    169169 
    170170{ 
     
    189189    mvwaddch (dialog, height - 3, 0, ACS_LTEE); 
    190190    for (i = 0; i < width - 2; i++) 
    191     waddch (dialog, ACS_HLINE); 
     191   waddch (dialog, ACS_HLINE); 
    192192    wattrset (dialog, dialog_attr); 
    193193    wbkgdset (dialog, dialog_attr & A_COLOR); 
     
    195195 
    196196    if (title != NULL && strlen(title) >= width-2 ) { 
    197     /* truncate long title -- mec */ 
    198     char * title2 = malloc(width-2+1); 
    199     memcpy( title2, title, width-2 ); 
    200     title2[width-2] = '\0'; 
    201     title = title2; 
     197   /* truncate long title -- mec */ 
     198   char * title2 = malloc(width-2+1); 
     199   memcpy( title2, title, width-2 ); 
     200   title2[width-2] = '\0'; 
     201   title = title2; 
    202202    } 
    203203 
    204204    if (title != NULL) { 
    205     wattrset (dialog, title_attr); 
    206     mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
    207     waddstr (dialog, (char *)title); 
    208     waddch (dialog, ' '); 
     205   wattrset (dialog, title_attr); 
     206   mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
     207   waddstr (dialog, (char *)title); 
     208   waddch (dialog, ' '); 
    209209    } 
    210210 
     
    218218    /* create new window for the menu */ 
    219219    menu = subwin (dialog, menu_height, menu_width, 
    220         y + box_y + 1, x + box_x + 1); 
     220       y + box_y + 1, x + box_x + 1); 
    221221    keypad (menu, TRUE); 
    222222 
    223223    /* draw a box around the menu items */ 
    224224    draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2, 
    225           menubox_border_attr, menubox_attr); 
     225         menubox_border_attr, menubox_attr); 
    226226 
    227227    /* 
    228228     * Find length of longest item in order to center menu. 
    229      * Set 'choice' to default item. 
     229     * Set 'choice' to default item.  
    230230     */ 
    231231    item_x = 0; 
    232232    for (i = 0; i < item_no; i++) { 
    233     item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2)); 
    234     if (strcmp(current, items[i*2]) == 0) choice = i; 
     233   item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2)); 
     234   if (strcmp(current, items[i*2]) == 0) choice = i; 
    235235    } 
    236236 
     
    239239    /* get the scroll info from the temp file */ 
    240240    if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) { 
    241     if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) && 
    242          (scroll+max_choice > choice) && (scroll >= 0) && 
    243          (scroll+max_choice <= item_no) ) { 
    244         first_item = scroll; 
    245         choice = choice - scroll; 
    246         fclose(f); 
    247     } else { 
    248         scroll=0; 
    249         remove("lxdialog.scrltmp"); 
    250         fclose(f); 
    251         f=NULL; 
    252    
     241   if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) && 
     242        (scroll+max_choice > choice) && (scroll >= 0) && 
     243        (scroll+max_choice <= item_no) ) { 
     244       first_item = scroll; 
     245       choice = choice - scroll; 
     246       fclose(f); 
     247   } else { 
     248       scroll=0; 
     249       remove("lxdialog.scrltmp"); 
     250       fclose(f); 
     251       f=NULL; 
     252   
    253253    } 
    254254    if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) { 
    255     if (choice >= item_no-max_choice/2) 
    256         scroll = first_item = item_no-max_choice; 
    257     else 
    258         scroll = first_item = choice - max_choice/2; 
    259     choice = choice - scroll; 
     255   if (choice >= item_no-max_choice/2) 
     256       scroll = first_item = item_no-max_choice; 
     257   else 
     258       scroll = first_item = choice - max_choice/2; 
     259   choice = choice - scroll; 
    260260    } 
    261261 
    262262    /* Print the menu */ 
    263263    for (i=0; i < max_choice; i++) { 
    264     print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice, 
     264   print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice, 
    265265                    (items[(first_item + i)*2][0] != ':')); 
    266266    } 
     
    269269 
    270270    print_arrows(dialog, item_no, scroll, 
    271         box_y, box_x+item_x+1, menu_height); 
     271        box_y, box_x+item_x+1, menu_height); 
    272272 
    273273    print_buttons (dialog, height, width, 0); 
     
    276276 
    277277    while (key != ESC) { 
    278     key = wgetch(menu); 
    279  
    280     if (key < 256 && isalpha(key)) key = tolower(key); 
    281  
    282     if (strchr("ynm", key)) 
    283         i = max_choice; 
    284     else { 
     278   key = wgetch(menu); 
     279 
     280   if (key < 256 && isalpha(key)) key = tolower(key); 
     281 
     282   if (strchr("ynm", key)) 
     283       i = max_choice; 
     284   else { 
    285285        for (i = choice+1; i < max_choice; i++) { 
    286         j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); 
    287         if (key == tolower(items[(scroll+i)*2+1][j])) 
    288                     break; 
    289    
    290     if (i == max_choice) 
    291                for (i = 0; i < max_choice; i++) { 
    292             j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); 
    293             if (key == tolower(items[(scroll+i)*2+1][j])) 
    294                         break; 
    295        
    296    
    297  
    298     if (i < max_choice || 
     286       j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); 
     287       if (key == tolower(items[(scroll+i)*2+1][j])) 
     288                   break; 
     289   
     290   if (i == max_choice) 
     291               for (i = 0; i < max_choice; i++) { 
     292           j = first_alpha(items[(scroll+i)*2+1], "YyNnMm"); 
     293           if (key == tolower(items[(scroll+i)*2+1][j])) 
     294                       break; 
     295       
     296   
     297 
     298    if (i < max_choice ||  
    299299            key == KEY_UP || key == KEY_DOWN || 
    300300            key == '-' || key == '+' || 
     
    304304                       (items[(scroll+choice)*2][0] != ':')); 
    305305 
    306         if (key == KEY_UP || key == '-') { 
     306       if (key == KEY_UP || key == '-') { 
    307307                if (choice < 2 && scroll) { 
    308                 /* Scroll menu down */ 
     308               /* Scroll menu down */ 
    309309                    scrollok (menu, TRUE); 
    310310                    wscrl (menu, -1); 
     
    315315                    print_item (menu, items[scroll * 2 + 1], 0, FALSE, 
    316316                               (items[scroll*2][0] != ':')); 
    317         } else 
    318             choice = MAX(choice - 1, 0); 
    319  
    320         } else if (key == KEY_DOWN || key == '+')  { 
    321  
    322         print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, 
     317       } else 
     318           choice = MAX(choice - 1, 0); 
     319 
     320       } else if (key == KEY_DOWN || key == '+')  { 
     321 
     322       print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, 
    323323                                (items[(scroll+choice)*2][0] != ':')); 
    324324 
     
    326326                    (scroll + max_choice < item_no) 
    327327                   ) { 
    328             /* Scroll menu up */ 
    329             scrollok (menu, TRUE); 
     328           /* Scroll menu up */ 
     329           scrollok (menu, TRUE); 
    330330                    scroll (menu); 
    331331                    scrollok (menu, FALSE); 
     
    339339                    choice = MIN(choice+1, max_choice-1); 
    340340 
    341         } else if (key == KEY_PPAGE) { 
    342             scrollok (menu, TRUE); 
     341       } else if (key == KEY_PPAGE) { 
     342           scrollok (menu, TRUE); 
    343343                for (i=0; (i < max_choice); i++) { 
    344344                    if (scroll > 0) { 
    345                     wscrl (menu, -1); 
    346                     scroll--; 
    347                     print_item (menu, items[scroll * 2 + 1], 0, FALSE, 
    348                     (items[scroll*2][0] != ':')); 
     345                   wscrl (menu, -1); 
     346                   scroll--; 
     347                   print_item (menu, items[scroll * 2 + 1], 0, FALSE, 
     348                   (items[scroll*2][0] != ':')); 
    349349                    } else { 
    350350                        if (choice > 0) 
     
    357357                for (i=0; (i < max_choice); i++) { 
    358358                    if (scroll+max_choice < item_no) { 
    359             scrollok (menu, TRUE); 
    360             scroll(menu); 
    361             scrollok (menu, FALSE); 
    362                     scroll++; 
    363                     print_item (menu, items[(scroll+max_choice-1)*2+1], 
    364                         max_choice-1, FALSE, 
    365                         (items[(scroll+max_choice-1)*2][0] != ':')); 
    366             } else { 
    367             if (choice+1 < max_choice) 
    368                 choice++; 
    369             } 
     359           scrollok (menu, TRUE); 
     360           scroll(menu); 
     361           scrollok (menu, FALSE); 
     362                   scroll++; 
     363                   print_item (menu, items[(scroll+max_choice-1)*2+1], 
     364                       max_choice-1, FALSE, 
     365                       (items[(scroll+max_choice-1)*2][0] != ':')); 
     366           } else { 
     367           if (choice+1 < max_choice) 
     368               choice++; 
     369           } 
    370370                } 
    371371 
     
    382382            wrefresh (menu); 
    383383 
    384         continue;        /* wait for another key press */ 
     384       continue;       /* wait for another key press */ 
    385385        } 
    386386 
    387     switch (key) { 
    388     case KEY_LEFT: 
    389     case TAB: 
    390     case KEY_RIGHT: 
    391         button = ((key == KEY_LEFT ? --button : ++button) < 0) 
    392             ? 2 : (button > 2 ? 0 : button); 
    393  
    394         print_buttons(dialog, height, width, button); 
    395         wrefresh (menu); 
    396         break; 
    397     case ' ': 
    398     case 's': 
    399     case 'y': 
    400     case 'n': 
    401     case 'm': 
    402         /* save scroll info */ 
    403         if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { 
    404         fprintf(f,"%d\n",scroll); 
    405         fclose(f); 
    406         } 
    407         delwin (dialog); 
     387   switch (key) { 
     388   case KEY_LEFT: 
     389   case TAB: 
     390   case KEY_RIGHT: 
     391       button = ((key == KEY_LEFT ? --button : ++button) < 0) 
     392           ? 2 : (button > 2 ? 0 : button); 
     393 
     394       print_buttons(dialog, height, width, button); 
     395       wrefresh (menu); 
     396       break; 
     397   case ' ': 
     398   case 's': 
     399   case 'y': 
     400   case 'n': 
     401   case 'm': 
     402       /* save scroll info */ 
     403       if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { 
     404       fprintf(f,"%d\n",scroll); 
     405       fclose(f); 
     406       } 
     407       delwin (dialog); 
    408408            fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 
    409409            switch (key) { 
     
    414414            case ' ': return 6; 
    415415            } 
    416         return 0; 
    417     case 'h': 
    418     case '?': 
    419         button = 2; 
    420     case '\n': 
    421         delwin (dialog); 
    422         if (button == 2) 
    423                 fprintf(stderr, "%s \"%s\"\n", 
    424             items[(scroll + choice) * 2], 
    425             items[(scroll + choice) * 2 + 1] + 
    426             first_alpha(items[(scroll + choice) * 2 + 1],"")); 
    427         else 
    428                 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 
    429  
    430         remove("lxdialog.scrltmp"); 
    431         return button; 
    432     case 'e': 
    433     case 'x': 
    434         key = ESC; 
    435     case ESC: 
    436         break; 
    437    
     416       return 0; 
     417   case 'h': 
     418   case '?': 
     419       button = 2; 
     420   case '\n': 
     421       delwin (dialog); 
     422        if (button == 2)  
     423               fprintf(stderr, "%s \"%s\"\n",  
     424           items[(scroll + choice) * 2], 
     425           items[(scroll + choice) * 2 + 1] + 
     426           first_alpha(items[(scroll + choice) * 2 + 1],"")); 
     427       else 
     428               fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 
     429 
     430       remove("lxdialog.scrltmp"); 
     431       return button; 
     432   case 'e': 
     433   case 'x': 
     434       key = ESC; 
     435   case ESC: 
     436       break; 
     437   
    438438    } 
    439439 
    440440    delwin (dialog); 
    441441    remove("lxdialog.scrltmp"); 
    442     return -1;            /* ESC pressed */ 
     442    return -1;         /* ESC pressed */ 
    443443}