Changeset f102b57751534d544f1270a3c10a048a29b3b3b7

Show
Ignore:
Timestamp:
11/09/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/checklist.c

    r6ee1e19 rf102b57  
    3131static void 
    3232print_item (WINDOW * win, const char *item, int status, 
    33         int choice, int selected) 
     33       int choice, int selected) 
    3434{ 
    3535    int i; 
     
    3939    wmove (win, choice, 0); 
    4040    for (i = 0; i < list_width; i++) 
    41     waddch (win, ' '); 
     41   waddch (win, ' '); 
    4242 
    4343    wmove (win, choice, check_x); 
    4444    wattrset (win, selected ? check_selected_attr : check_attr); 
    4545    if (checkflag == FLAG_CHECK) 
    46     wprintw (win, "[%c]", status ? 'X' : ' '); 
     46   wprintw (win, "[%c]", status ? 'X' : ' '); 
    4747    else 
    48     wprintw (win, "(%c)", status ? 'X' : ' '); 
     48   wprintw (win, "(%c)", status ? 'X' : ' '); 
    4949 
    5050    wattrset (win, selected ? tag_selected_attr : tag_attr); 
     
    5353    waddstr (win, (char *)item+1); 
    5454    if (selected) { 
    55         wmove (win, choice, check_x+1); 
    56         wrefresh (win); 
     55       wmove (win, choice, check_x+1); 
     56       wrefresh (win); 
    5757    } 
    5858} 
     
    6363static void 
    6464print_arrows (WINDOW * win, int choice, int item_no, int scroll, 
    65         int y, int x, int height) 
     65       int y, int x, int height) 
    6666{ 
    6767    wmove(win, y, x); 
    6868 
    6969    if (scroll > 0) { 
    70     wattrset (win, uarrow_attr); 
    71     waddch (win, ACS_UARROW); 
    72     waddstr (win, "(-)"); 
     70   wattrset (win, uarrow_attr); 
     71   waddch (win, ACS_UARROW); 
     72   waddstr (win, "(-)"); 
    7373    } 
    7474    else { 
    75     wattrset (win, menubox_attr); 
    76     waddch (win, ACS_HLINE); 
    77     waddch (win, ACS_HLINE); 
    78     waddch (win, ACS_HLINE); 
    79     waddch (win, ACS_HLINE); 
     75   wattrset (win, menubox_attr); 
     76   waddch (win, ACS_HLINE); 
     77   waddch (win, ACS_HLINE); 
     78   waddch (win, ACS_HLINE); 
     79   waddch (win, ACS_HLINE); 
    8080    } 
    8181 
     
    8484 
    8585   if ((height < item_no) && (scroll + choice < item_no - 1)) { 
    86     wattrset (win, darrow_attr); 
    87     waddch (win, ACS_DARROW); 
    88     waddstr (win, "(+)"); 
     86   wattrset (win, darrow_attr); 
     87   waddch (win, ACS_DARROW); 
     88   waddstr (win, "(+)"); 
    8989    } 
    9090    else { 
    91     wattrset (win, menubox_border_attr); 
    92     waddch (win, ACS_HLINE); 
    93     waddch (win, ACS_HLINE); 
    94     waddch (win, ACS_HLINE); 
    95     waddch (win, ACS_HLINE); 
     91   wattrset (win, menubox_border_attr); 
     92   waddch (win, ACS_HLINE); 
     93   waddch (win, ACS_HLINE); 
     94   waddch (win, ACS_HLINE); 
     95   waddch (win, ACS_HLINE); 
    9696   } 
    9797} 
     
    119119int 
    120120dialog_checklist (const char *title, const char *prompt, int height, int width, 
    121     int list_height, int item_no, const char * const * items, int flag) 
    122      
     121   int list_height, int item_no, const char * const * items, int flag) 
     122     
    123123{ 
    124124    int i, x, y, box_x, box_y; 
     
    130130    /* Allocate space for storing item on/off status */ 
    131131    if ((status = malloc (sizeof (int) * item_no)) == NULL) { 
    132     endwin (); 
    133     fprintf (stderr, 
    134         "\nCan't allocate memory in dialog_checklist().\n"); 
    135     exit (-1); 
     132   endwin (); 
     133   fprintf (stderr, 
     134        "\nCan't allocate memory in dialog_checklist().\n"); 
     135   exit (-1); 
    136136    } 
    137137 
    138138    /* Initializes status */ 
    139139    for (i = 0; i < item_no; i++) { 
    140     status[i] = !strcasecmp (items[i * 3 + 2], "on"); 
    141     if (!choice && status[i]) 
     140   status[i] = !strcasecmp (items[i * 3 + 2], "on"); 
     141   if (!choice && status[i]) 
    142142            choice = i; 
    143143    } 
     
    158158    mvwaddch (dialog, height-3, 0, ACS_LTEE); 
    159159    for (i = 0; i < width - 2; i++) 
    160     waddch (dialog, ACS_HLINE); 
     160   waddch (dialog, ACS_HLINE); 
    161161    wattrset (dialog, dialog_attr); 
    162162    waddch (dialog, ACS_RTEE); 
    163163 
    164164    if (title != NULL && strlen(title) >= width-2 ) { 
    165     /* truncate long title -- mec */ 
    166     char * title2 = malloc(width-2+1); 
    167     memcpy( title2, title, width-2 ); 
    168     title2[width-2] = '\0'; 
    169     title = title2; 
     165   /* truncate long title -- mec */ 
     166   char * title2 = malloc(width-2+1); 
     167   memcpy( title2, title, width-2 ); 
     168   title2[width-2] = '\0'; 
     169   title = title2; 
    170170    } 
    171171 
    172172    if (title != NULL) { 
    173     wattrset (dialog, title_attr); 
    174     mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
    175     waddstr (dialog, (char *)title); 
    176     waddch (dialog, ' '); 
     173   wattrset (dialog, title_attr); 
     174   mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
     175   waddstr (dialog, (char *)title); 
     176   waddch (dialog, ' '); 
    177177    } 
    178178 
     
    191191    /* draw a box around the list items */ 
    192192    draw_box (dialog, box_y, box_x, list_height + 2, list_width + 2, 
    193           menubox_border_attr, menubox_attr); 
     193         menubox_border_attr, menubox_attr); 
    194194 
    195195    /* Find length of longest item in order to center checklist */ 
    196196    check_x = 0; 
    197     for (i = 0; i < item_no; i++) 
    198     check_x = MAX (check_x, + strlen (items[i * 3 + 1]) + 4); 
     197    for (i = 0; i < item_no; i++)  
     198   check_x = MAX (check_x, + strlen (items[i * 3 + 1]) + 4); 
    199199 
    200200    check_x = (list_width - check_x) / 2; 
     
    202202 
    203203    if (choice >= list_height) { 
    204     scroll = choice - list_height + 1; 
    205     choice -= scroll; 
     204   scroll = choice - list_height + 1; 
     205   choice -= scroll; 
    206206    } 
    207207 
    208208    /* Print the list */ 
    209209    for (i = 0; i < max_choice; i++) { 
    210     print_item (list, items[(scroll+i) * 3 + 1], 
    211             status[i+scroll], i, i == choice); 
     210   print_item (list, items[(scroll+i) * 3 + 1], 
     211           status[i+scroll], i, i == choice); 
    212212    } 
    213213 
    214214    print_arrows(dialog, choice, item_no, scroll, 
    215             box_y, box_x + check_x + 5, list_height); 
     215           box_y, box_x + check_x + 5, list_height); 
    216216 
    217217    print_buttons(dialog, height, width, 0); 
     
    222222 
    223223    while (key != ESC) { 
    224     key = wgetch (dialog); 
    225  
    226         for (i = 0; i < max_choice; i++) 
     224   key = wgetch (dialog); 
     225 
     226       for (i = 0; i < max_choice; i++) 
    227227            if (toupper(key) == toupper(items[(scroll+i)*3+1][0])) 
    228228                break; 
    229229 
    230230 
    231     if ( i < max_choice || key == KEY_UP || key == KEY_DOWN || 
    232         key == '+' || key == '-' ) { 
    233         if (key == KEY_UP || key == '-') { 
    234         if (!choice) { 
    235             if (!scroll) 
    236             continue; 
    237             /* Scroll list down */ 
    238             if (list_height > 1) { 
    239             /* De-highlight current first item */ 
    240             print_item (list, items[scroll * 3 + 1], 
    241                     status[scroll], 0, FALSE); 
    242             scrollok (list, TRUE); 
    243             wscrl (list, -1); 
    244             scrollok (list, FALSE); 
     231    if ( i < max_choice || key == KEY_UP || key == KEY_DOWN ||  
     232        key == '+' || key == '-' ) { 
     233        if (key == KEY_UP || key == '-') { 
     234        if (!choice) { 
     235            if (!scroll) 
     236            continue; 
     237            /* Scroll list down */ 
     238            if (list_height > 1) { 
     239            /* De-highlight current first item */ 
     240            print_item (list, items[scroll * 3 + 1], 
     241                    status[scroll], 0, FALSE); 
     242            scrollok (list, TRUE); 
     243            wscrl (list, -1); 
     244            scrollok (list, FALSE); 
     245            } 
     246            scroll--; 
     247            print_item (list, items[scroll * 3 + 1], 
     248                status[scroll], 0, TRUE); 
     249            wnoutrefresh (list); 
     250 
     251                print_arrows(dialog, choice, item_no, scroll, 
     252                box_y, box_x + check_x + 5, list_height); 
     253 
     254            wrefresh (dialog); 
     255 
     256            continue;   /* wait for another key press */ 
     257        } else 
     258            i = choice - 1; 
     259        } else if (key == KEY_DOWN || key == '+') { 
     260        if (choice == max_choice - 1) { 
     261            if (scroll + choice >= item_no - 1) 
     262            continue; 
     263            /* Scroll list up */ 
     264            if (list_height > 1) { 
     265            /* De-highlight current last item before scrolling up */ 
     266            print_item (list, items[(scroll + max_choice - 1) * 3 + 1], 
     267                    status[scroll + max_choice - 1], 
     268                    max_choice - 1, FALSE); 
     269            scrollok (list, TRUE); 
     270            scroll (list); 
     271            scrollok (list, FALSE); 
     272            } 
     273            scroll++; 
     274            print_item (list, items[(scroll + max_choice - 1) * 3 + 1], 
     275                status[scroll + max_choice - 1], 
     276                max_choice - 1, TRUE); 
     277            wnoutrefresh (list); 
     278 
     279                print_arrows(dialog, choice, item_no, scroll, 
     280                box_y, box_x + check_x + 5, list_height); 
     281 
     282            wrefresh (dialog); 
     283 
     284            continue;   /* wait for another key press */ 
     285        } else 
     286            i = choice + 1; 
     287        } 
     288        if (i != choice) { 
     289        /* De-highlight current item */ 
     290        print_item (list, items[(scroll + choice) * 3 + 1], 
     291                status[scroll + choice], choice, FALSE); 
     292        /* Highlight new item */ 
     293        choice = i; 
     294        print_item (list, items[(scroll + choice) * 3 + 1], 
     295                status[scroll + choice], choice, TRUE); 
     296        wnoutrefresh (list); 
     297        wrefresh (dialog); 
     298        } 
     299        continue;       /* wait for another key press */ 
     300    } 
     301    switch (key) { 
     302    case 'H': 
     303    case 'h': 
     304    case '?': 
     305        delwin (dialog); 
     306        free (status); 
     307        return 1; 
     308    case TAB: 
     309    case KEY_LEFT: 
     310    case KEY_RIGHT: 
     311        button = ((key == KEY_LEFT ? --button : ++button) < 0) 
     312            ? 1 : (button > 1 ? 0 : button); 
     313 
     314        print_buttons(dialog, height, width, button); 
     315        wrefresh (dialog); 
     316        break; 
     317    case 'S': 
     318    case 's': 
     319    case ' ': 
     320    case '\n': 
     321        if (!button) { 
     322        if (flag == FLAG_CHECK) { 
     323            status[scroll + choice] = !status[scroll + choice]; 
     324            wmove (list, choice, check_x); 
     325            wattrset (list, check_selected_attr); 
     326            wprintw (list, "[%c]", status[scroll + choice] ? 'X' : ' '); 
     327        } else { 
     328            if (!status[scroll + choice]) { 
     329            for (i = 0; i < item_no; i++) 
     330                status[i] = 0; 
     331            status[scroll + choice] = 1; 
     332            for (i = 0; i < max_choice; i++) 
     333                print_item (list, items[(scroll + i) * 3 + 1], 
     334                    status[scroll + i], i, i == choice); 
     335            } 
     336        } 
     337        wnoutrefresh (list); 
     338        wrefresh (dialog); 
     339             
     340        for (i = 0; i < item_no; i++) { 
     341            if (status[i]) { 
     342            if (flag == FLAG_CHECK) { 
     343                fprintf (stderr, "\"%s\" ", items[i * 3]); 
     344            } else { 
     345                fprintf (stderr, "%s", items[i * 3]); 
     346            } 
     347 
     348            } 
     349        } 
    245350            } 
    246             scroll--; 
    247             print_item (list, items[scroll * 3 + 1], 
    248                 status[scroll], 0, TRUE); 
    249             wnoutrefresh (list); 
    250  
    251                 print_arrows(dialog, choice, item_no, scroll, 
    252                 box_y, box_x + check_x + 5, list_height); 
    253  
    254             wrefresh (dialog); 
    255  
    256             continue;    /* wait for another key press */ 
    257         } else 
    258             i = choice - 1; 
    259         } else if (key == KEY_DOWN || key == '+') { 
    260         if (choice == max_choice - 1) { 
    261             if (scroll + choice >= item_no - 1) 
    262             continue; 
    263             /* Scroll list up */ 
    264             if (list_height > 1) { 
    265             /* De-highlight current last item before scrolling up */ 
    266             print_item (list, items[(scroll + max_choice - 1) * 3 + 1], 
    267                     status[scroll + max_choice - 1], 
    268                     max_choice - 1, FALSE); 
    269             scrollok (list, TRUE); 
    270             scroll (list); 
    271             scrollok (list, FALSE); 
    272             } 
    273             scroll++; 
    274             print_item (list, items[(scroll + max_choice - 1) * 3 + 1], 
    275                 status[scroll + max_choice - 1], 
    276                 max_choice - 1, TRUE); 
    277             wnoutrefresh (list); 
    278  
    279                 print_arrows(dialog, choice, item_no, scroll, 
    280                 box_y, box_x + check_x + 5, list_height); 
    281  
    282             wrefresh (dialog); 
    283  
    284             continue;    /* wait for another key press */ 
    285         } else 
    286             i = choice + 1; 
    287         } 
    288         if (i != choice) { 
    289         /* De-highlight current item */ 
    290         print_item (list, items[(scroll + choice) * 3 + 1], 
    291                 status[scroll + choice], choice, FALSE); 
    292         /* Highlight new item */ 
    293         choice = i; 
    294         print_item (list, items[(scroll + choice) * 3 + 1], 
    295                 status[scroll + choice], choice, TRUE); 
    296         wnoutrefresh (list); 
    297         wrefresh (dialog); 
    298         } 
    299         continue;        /* wait for another key press */ 
    300     } 
    301     switch (key) { 
    302     case 'H': 
    303     case 'h': 
    304     case '?': 
    305         delwin (dialog); 
    306         free (status); 
    307         return 1; 
    308     case TAB: 
    309     case KEY_LEFT: 
    310     case KEY_RIGHT: 
    311         button = ((key == KEY_LEFT ? --button : ++button) < 0) 
    312             ? 1 : (button > 1 ? 0 : button); 
    313  
    314         print_buttons(dialog, height, width, button); 
    315         wrefresh (dialog); 
    316         break; 
    317     case 'S': 
    318     case 's': 
    319     case ' ': 
    320     case '\n': 
    321         if (!button) { 
    322         if (flag == FLAG_CHECK) { 
    323             status[scroll + choice] = !status[scroll + choice]; 
    324             wmove (list, choice, check_x); 
    325             wattrset (list, check_selected_attr); 
    326             wprintw (list, "[%c]", status[scroll + choice] ? 'X' : ' '); 
    327         } else { 
    328             if (!status[scroll + choice]) { 
    329             for (i = 0; i < item_no; i++) 
    330                 status[i] = 0; 
    331             status[scroll + choice] = 1; 
    332             for (i = 0; i < max_choice; i++) 
    333                 print_item (list, items[(scroll + i) * 3 + 1], 
    334                     status[scroll + i], i, i == choice); 
    335             } 
    336         } 
    337         wnoutrefresh (list); 
    338         wrefresh (dialog); 
    339   
    340         for (i = 0; i < item_no; i++) { 
    341             if (status[i]) { 
    342             if (flag == FLAG_CHECK) { 
    343                 fprintf (stderr, "\"%s\" ", items[i * 3]); 
    344             } else { 
    345                 fprintf (stderr, "%s", items[i * 3]); 
    346             } 
    347  
    348             } 
    349         } 
    350             } 
    351         delwin (dialog); 
    352         free (status); 
    353         return button; 
    354     case 'X': 
    355     case 'x': 
    356         key = ESC; 
    357     case ESC: 
    358         break; 
    359     } 
    360  
    361     /* Now, update everything... */ 
    362     doupdate (); 
    363     } 
    364   
     351        delwin (dialog); 
     352        free (status); 
     353        return button; 
     354    case 'X': 
     355    case 'x': 
     356        key = ESC; 
     357    case ESC: 
     358        break; 
     359    } 
     360 
     361    /* Now, update everything... */ 
     362    doupdate (); 
     363    } 
     364     
    365365 
    366366    delwin (dialog); 
    367367    free (status); 
    368     return -1;            /* ESC pressed */ 
     368    return -1;         /* ESC pressed */ 
    369369} 
  • lxdialog/dialog.h

    r6ee1e19 rf102b57  
    8686#endif 
    8787 
    88 /* 
     88/*  
    8989 * Attribute names 
    9090 */ 
     
    147147void print_button (WINDOW * win, const char *label, int y, int x, int selected); 
    148148void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box, 
    149         chtype border); 
     149       chtype border); 
    150150void draw_shadow (WINDOW * win, int y, int x, int height, int width); 
    151151 
     
    153153int dialog_yesno (const char *title, const char *prompt, int height, int width); 
    154154int dialog_msgbox (const char *title, const char *prompt, int height, 
    155         int width, int pause); 
     155       int width, int pause); 
    156156int dialog_textbox (const char *title, const char *file, int height, int width); 
    157157int dialog_menu (const char *title, const char *prompt, int height, int width, 
    158         int menu_height, const char *choice, int item_no, 
    159         const char * const * items); 
     158        int menu_height, const char *choice, int item_no,  
     159       const char * const * items); 
    160160int dialog_checklist (const char *title, const char *prompt, int height, 
    161         int width, int list_height, int item_no, 
    162         const char * const * items, int flag); 
     161       int width, int list_height, int item_no, 
     162       const char * const * items, int flag); 
    163163extern unsigned char dialog_input_result[]; 
    164164int dialog_inputbox (const char *title, const char *prompt, int height, 
    165         int width, const char *init); 
     165       int width, const char *init); 
    166166 
    167167/* 
  • lxdialog/inputbox.c

    r6ee1e19 rf102b57  
    4545int 
    4646dialog_inputbox (const char *title, const char *prompt, int height, int width, 
    47         const char *init) 
     47        const char *init) 
    4848{ 
    4949    int i, x, y, box_y, box_x, box_width; 
     
    6666    mvwaddch (dialog, height-3, 0, ACS_LTEE); 
    6767    for (i = 0; i < width - 2; i++) 
    68     waddch (dialog, ACS_HLINE); 
     68   waddch (dialog, ACS_HLINE); 
    6969    wattrset (dialog, dialog_attr); 
    7070    waddch (dialog, ACS_RTEE); 
    7171 
    7272    if (title != NULL && strlen(title) >= width-2 ) { 
    73     /* truncate long title -- mec */ 
    74     char * title2 = malloc(width-2+1); 
    75     memcpy( title2, title, width-2 ); 
    76     title2[width-2] = '\0'; 
    77     title = title2; 
     73   /* truncate long title -- mec */ 
     74   char * title2 = malloc(width-2+1); 
     75   memcpy( title2, title, width-2 ); 
     76   title2[width-2] = '\0'; 
     77   title = title2; 
    7878    } 
    7979 
    8080    if (title != NULL) { 
    81     wattrset (dialog, title_attr); 
    82     mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
    83     waddstr (dialog, (char *)title); 
    84     waddch (dialog, ' '); 
     81   wattrset (dialog, title_attr); 
     82   mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 
     83   waddstr (dialog, (char *)title); 
     84   waddch (dialog, ' '); 
    8585    } 
    8686 
     
    9494    box_x = (width - box_width) / 2; 
    9595    draw_box (dialog, y + 1, box_x - 1, 3, box_width + 2, 
    96           border_attr, dialog_attr); 
     96         border_attr, dialog_attr); 
    9797 
    9898    print_buttons(dialog, height, width, 0); 
     
    103103 
    104104    if (!init) 
    105     instr[0] = '\0'; 
     105   instr[0] = '\0'; 
    106106    else 
    107     strcpy (instr, init); 
     107   strcpy (instr, init); 
    108108 
    109109    input_x = strlen (instr); 
    110110 
    111111    if (input_x >= box_width) { 
    112     scroll = input_x - box_width + 1; 
    113     input_x = box_width - 1; 
    114     for (i = 0; i < box_width - 1; i++) 
    115         waddch (dialog, instr[scroll + i]); 
     112   scroll = input_x - box_width + 1; 
     113   input_x = box_width - 1; 
     114   for (i = 0; i < box_width - 1; i++) 
     115       waddch (dialog, instr[scroll + i]); 
    116116    } else 
    117     waddstr (dialog, instr); 
     117   waddstr (dialog, instr); 
    118118 
    119119    wmove (dialog, box_y, box_x + input_x); 
     
    122122 
    123123    while (key != ESC) { 
    124     key = wgetch (dialog); 
    125  
    126     if (button == -1) {    /* Input box selected */ 
    127         switch (key) { 
    128         case TAB: 
    129         case KEY_UP: 
    130         case KEY_DOWN: 
    131         break; 
    132         case KEY_LEFT: 
    133         continue; 
    134         case KEY_RIGHT: 
    135         continue; 
    136         case KEY_BACKSPACE: 
    137         case 127: 
    138         if (input_x || scroll) { 
    139             wattrset (dialog, inputbox_attr); 
    140             if (!input_x) { 
    141             scroll = scroll < box_width - 1 ? 
    142                 0 : scroll - (box_width - 1); 
    143             wmove (dialog, box_y, box_x); 
    144             for (i = 0; i < box_width; i++) 
    145                 waddch (dialog, instr[scroll + input_x + i] ? 
    146                     instr[scroll + input_x + i] : ' '); 
    147             input_x = strlen (instr) - scroll; 
    148             } else 
    149             input_x--; 
    150             instr[scroll + input_x] = '\0'; 
    151             mvwaddch (dialog, box_y, input_x + box_x, ' '); 
    152             wmove (dialog, box_y, input_x + box_x); 
    153             wrefresh (dialog); 
    154         } 
    155         continue; 
    156         default: 
    157         if (key < 0x100 && isprint (key)) { 
    158             if (scroll + input_x < MAX_LEN) { 
    159             wattrset (dialog, inputbox_attr); 
    160             instr[scroll + input_x] = key; 
    161             instr[scroll + input_x + 1] = '\0'; 
    162             if (input_x == box_width - 1) { 
    163                 scroll++; 
    164                 wmove (dialog, box_y, box_x); 
    165                 for (i = 0; i < box_width - 1; i++) 
    166                 waddch (dialog, instr[scroll + i]); 
    167             } else { 
    168                 wmove (dialog, box_y, input_x++ + box_x); 
    169                 waddch (dialog, key); 
    170             } 
    171             wrefresh (dialog); 
    172             } else 
    173             flash ();    /* Alarm user about overflow */ 
    174             continue; 
    175         } 
    176         } 
     124    key = wgetch (dialog); 
     125 
     126    if (button == -1) { /* Input box selected */ 
     127        switch (key) { 
     128        case TAB: 
     129        case KEY_UP: 
     130        case KEY_DOWN: 
     131        break; 
     132        case KEY_LEFT: 
     133        continue; 
     134        case KEY_RIGHT: 
     135        continue; 
     136        case KEY_BACKSPACE: 
     137        case 127: 
     138        if (input_x || scroll) { 
     139            wattrset (dialog, inputbox_attr); 
     140            if (!input_x) { 
     141            scroll = scroll < box_width - 1 ? 
     142                0 : scroll - (box_width - 1); 
     143            wmove (dialog, box_y, box_x); 
     144            for (i = 0; i < box_width; i++) 
     145                waddch (dialog, instr[scroll + input_x + i] ? 
     146                    instr[scroll + input_x + i] : ' '); 
     147            input_x = strlen (instr) - scroll; 
     148            } else 
     149            input_x--; 
     150            instr[scroll + input_x] = '\0'; 
     151            mvwaddch (dialog, box_y, input_x + box_x, ' '); 
     152            wmove (dialog, box_y, input_x + box_x); 
     153            wrefresh (dialog); 
     154        } 
     155        continue; 
     156        default: 
     157        if (key < 0x100 && isprint (key)) { 
     158            if (scroll + input_x < MAX_LEN) { 
     159            wattrset (dialog, inputbox_attr); 
     160            instr[scroll + input_x] = key; 
     161            instr[scroll + input_x + 1] = '\0'; 
     162            if (input_x == box_width - 1) { 
     163                scroll++; 
     164                wmove (dialog, box_y, box_x); 
     165                for (i = 0; i < box_width - 1; i++) 
     166                waddch (dialog, instr[scroll + i]); 
     167            } else { 
     168                wmove (dialog, box_y, input_x++ + box_x); 
     169                waddch (dialog, key); 
     170            } 
     171            wrefresh (dialog); 
     172            } else 
     173            flash ();   /* Alarm user about overflow */ 
     174            continue; 
     175        } 
     176        } 
     177    } 
     178    switch (key) { 
     179    case 'O': 
     180    case 'o': 
     181        delwin (dialog); 
     182        return 0; 
     183    case 'H': 
     184    case 'h': 
     185        delwin (dialog); 
     186        return 1; 
     187    case KEY_UP: 
     188    case KEY_LEFT: 
     189        switch (button) { 
     190        case -1: 
     191        button = 1; /* Indicates "Cancel" button is selected */ 
     192        print_buttons(dialog, height, width, 1); 
     193        break; 
     194        case 0: 
     195        button = -1;    /* Indicates input box is selected */ 
     196        print_buttons(dialog, height, width, 0); 
     197        wmove (dialog, box_y, box_x + input_x); 
     198        wrefresh (dialog); 
     199        break; 
     200        case 1: 
     201        button = 0; /* Indicates "OK" button is selected */ 
     202        print_buttons(dialog, height, width, 0); 
     203        break; 
     204        } 
     205        break; 
     206    case TAB: 
     207    case KEY_DOWN: 
     208    case KEY_RIGHT: 
     209        switch (button) { 
     210        case -1: 
     211        button = 0; /* Indicates "OK" button is selected */ 
     212        print_buttons(dialog, height, width, 0); 
     213        break; 
     214        case 0: 
     215        button = 1; /* Indicates "Cancel" button is selected */ 
     216        print_buttons(dialog, height, width, 1); 
     217        break; 
     218        case 1: 
     219        button = -1;    /* Indicates input box is selected */ 
     220        print_buttons(dialog, height, width, 0); 
     221        wmove (dialog, box_y, box_x + input_x); 
     222        wrefresh (dialog); 
     223        break; 
     224        } 
     225        break; 
     226    case ' ': 
     227    case '\n': 
     228        delwin (dialog); 
     229        return (button == -1 ? 0 : button); 
     230    case 'X': 
     231    case 'x': 
     232        key = ESC; 
     233    case ESC: 
     234        break; 
     235    } 
    177236    } 
    178     switch (key) { 
    179     case 'O': 
    180     case 'o': 
    181         delwin (dialog); 
    182         return 0; 
    183     case 'H': 
    184     case 'h': 
    185         delwin (dialog); 
    186         return 1; 
    187     case KEY_UP: 
    188     case KEY_LEFT: 
    189         switch (button) { 
    190         case -1: 
    191         button = 1;    /* Indicates "Cancel" button is selected */ 
    192         print_buttons(dialog, height, width, 1); 
    193         break; 
    194         case 0: 
    195         button = -1;    /* Indicates input box is selected */ 
    196         print_buttons(dialog, height, width, 0); 
    197         wmove (dialog, box_y, box_x + input_x); 
    198         wrefresh (dialog); 
    199         break; 
    200         case 1: 
    201         button = 0;    /* Indicates "OK" button is selected */ 
    202         print_buttons(dialog, height, width, 0); 
    203         break; 
    204         } 
    205         break; 
    206     case TAB: 
    207     case KEY_DOWN: 
    208     case KEY_RIGHT: 
    209         switch (button) { 
    210         case -1: 
    211         button = 0;    /* Indicates "OK" button is selected */ 
    212         print_buttons(dialog, height, width, 0); 
    213         break; 
    214         case 0: 
    215         button = 1;    /* Indicates "Cancel" button is selected */ 
    216         print_buttons(dialog, height, width, 1); 
    217         break; 
    218         case 1: 
    219         button = -1;    /* Indicates input box is selected */ 
    220         print_buttons(dialog, height, width, 0); 
    221         wmove (dialog, box_y, box_x + input_x); 
    222         wrefresh (dialog); 
    223         break; 
    224         } 
    225         break; 
    226     case ' ': 
    227     case '\n': 
    228         delwin (dialog); 
    229         return (button == -1 ? 0 : button); 
    230     case 'X': 
    231     case 'x': 
    232         key = ESC; 
    233     case ESC: 
    234         break; 
    235     } 
    236     } 
    237237 
    238238    delwin (dialog); 
    239     return -1;            /* ESC pressed */ 
     239    return -1;         /* ESC pressed */ 
    240240} 
  • lxdialog/lxdialog.c

    r6ee1e19 rf102b57  
    6868#endif 
    6969    if (argc < 2) { 
    70     Usage (argv[0]); 
    71     exit (-1); 
    72     } 
    73  
    74     while (offset < argc - 1 && !end_common_opts) {    /* Common options */ 
    75     if (!strcmp (argv[offset + 1], "--title")) { 
    76         if (argc - offset < 3 || title != NULL) { 
    77         Usage (argv[0]); 
    78         exit (-1); 
    79         } else { 
    80         title = argv[offset + 2]; 
    81         offset += 2; 
    82         } 
     70   Usage (argv[0]); 
     71   exit (-1); 
     72    } 
     73 
     74    while (offset < argc - 1 && !end_common_opts) {    /* Common options */ 
     75   if (!strcmp (argv[offset + 1], "--title")) { 
     76       if (argc - offset < 3 || title != NULL) { 
     77       Usage (argv[0]); 
     78       exit (-1); 
     79       } else { 
     80       title = argv[offset + 2]; 
     81       offset += 2; 
     82       } 
    8383        } else if (!strcmp (argv[offset + 1], "--backtitle")) { 
    8484            if (backtitle != NULL) { 
     
    8989                offset += 2; 
    9090            } 
    91     } else if (!strcmp (argv[offset + 1], "--clear")) { 
    92         if (clear_screen) {    /* Hey, "--clear" can't appear twice! */ 
    93         Usage (argv[0]); 
    94         exit (-1); 
    95         } else if (argc == 2) {    /* we only want to clear the screen */ 
    96         init_dialog (); 
    97         refresh ();    /* init_dialog() will clear the screen for us */ 
    98         end_dialog (); 
    99         return 0; 
    100         } else { 
    101         clear_screen = 1; 
    102         offset++; 
    103         } 
    104     } else            /* no more common options */ 
    105         end_common_opts = 1; 
    106     } 
    107  
    108     if (argc - 1 == offset) {    /* no more options */ 
    109     Usage (argv[0]); 
    110     exit (-1); 
     91   } else if (!strcmp (argv[offset + 1], "--clear")) { 
     92       if (clear_screen) { /* Hey, "--clear" can't appear twice! */ 
     93       Usage (argv[0]); 
     94       exit (-1); 
     95       } else if (argc == 2) { /* we only want to clear the screen */ 
     96       init_dialog (); 
     97       refresh (); /* init_dialog() will clear the screen for us */ 
     98       end_dialog (); 
     99       return 0; 
     100       } else { 
     101       clear_screen = 1; 
     102       offset++; 
     103       } 
     104   } else          /* no more common options */ 
     105       end_common_opts = 1; 
     106    } 
     107 
     108    if (argc - 1 == offset) {  /* no more options */ 
     109   Usage (argv[0]); 
     110   exit (-1); 
    111111    } 
    112112    /* use a table to look for the requested mode, to avoid code duplication */ 
    113113 
    114     for (modePtr = modes; modePtr->name; modePtr++)    /* look for the mode */ 
    115     if (!strcmp (argv[offset + 1], modePtr->name)) 
    116         break; 
     114    for (modePtr = modes; modePtr->name; modePtr++)    /* look for the mode */ 
     115   if (!strcmp (argv[offset + 1], modePtr->name)) 
     116       break; 
    117117 
    118118    if (!modePtr->name) 
    119     Usage (argv[0]); 
     119   Usage (argv[0]); 
    120120    if (argc - offset < modePtr->argmin) 
    121     Usage (argv[0]); 
     121   Usage (argv[0]); 
    122122    if (modePtr->argmax && argc - offset > modePtr->argmax) 
    123     Usage (argv[0]); 
     123   Usage (argv[0]); 
    124124 
    125125 
     
    128128    retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); 
    129129 
    130     if (clear_screen) {        /* clear screen before exit */ 
    131     attr_clear (stdscr, LINES, COLS, screen_attr); 
    132     refresh (); 
     130    if (clear_screen) {        /* clear screen before exit */ 
     131   attr_clear (stdscr, LINES, COLS, screen_attr); 
     132   refresh (); 
    133133    } 
    134134    end_dialog(); 
     
    174174{ 
    175175    return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]), 
    176             atoi (av[5]), av[6], (ac - 6) / 2, av + 7); 
     176           atoi (av[5]), av[6], (ac - 6) / 2, av + 7); 
    177177} 
    178178 
     
    181181{ 
    182182    return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 
    183     atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); 
     183   atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); 
    184184} 
    185185 
     
    188188{ 
    189189    return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 
    190     atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); 
     190   atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); 
    191191} 
    192192 
  • 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