diff options
Diffstat (limited to 'scripts/kconfig/lxdialog/checklist.c')
-rw-r--r-- | scripts/kconfig/lxdialog/checklist.c | 136 |
1 files changed, 55 insertions, 81 deletions
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c index b90e888a2bc0..282511020bcb 100644 --- a/scripts/kconfig/lxdialog/checklist.c +++ b/scripts/kconfig/lxdialog/checklist.c | |||
@@ -28,8 +28,7 @@ static int list_width, check_x, item_x; | |||
28 | /* | 28 | /* |
29 | * Print list item | 29 | * Print list item |
30 | */ | 30 | */ |
31 | static void print_item(WINDOW * win, const char *item, int status, int choice, | 31 | static void print_item(WINDOW * win, int choice, int selected) |
32 | int selected) | ||
33 | { | 32 | { |
34 | int i; | 33 | int i; |
35 | 34 | ||
@@ -42,12 +41,12 @@ static void print_item(WINDOW * win, const char *item, int status, int choice, | |||
42 | wmove(win, choice, check_x); | 41 | wmove(win, choice, check_x); |
43 | wattrset(win, selected ? dlg.check_selected.atr | 42 | wattrset(win, selected ? dlg.check_selected.atr |
44 | : dlg.check.atr); | 43 | : dlg.check.atr); |
45 | wprintw(win, "(%c)", status ? 'X' : ' '); | 44 | wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); |
46 | 45 | ||
47 | wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); | 46 | wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); |
48 | mvwaddch(win, choice, item_x, item[0]); | 47 | mvwaddch(win, choice, item_x, item_str()[0]); |
49 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); | 48 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); |
50 | waddstr(win, (char *)item + 1); | 49 | waddstr(win, (char *)item_str() + 1); |
51 | if (selected) { | 50 | if (selected) { |
52 | wmove(win, choice, check_x + 1); | 51 | wmove(win, choice, check_x + 1); |
53 | wrefresh(win); | 52 | wrefresh(win); |
@@ -110,32 +109,23 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) | |||
110 | * in the style of radiolist (only one option turned on at a time). | 109 | * in the style of radiolist (only one option turned on at a time). |
111 | */ | 110 | */ |
112 | int dialog_checklist(const char *title, const char *prompt, int height, | 111 | int dialog_checklist(const char *title, const char *prompt, int height, |
113 | int width, int list_height, int item_no, | 112 | int width, int list_height) |
114 | const char *const *items) | ||
115 | { | 113 | { |
116 | int i, x, y, box_x, box_y; | 114 | int i, x, y, box_x, box_y; |
117 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; | 115 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice; |
118 | WINDOW *dialog, *list; | 116 | WINDOW *dialog, *list; |
119 | 117 | ||
120 | /* Allocate space for storing item on/off status */ | 118 | /* which item to highlight */ |
121 | if ((status = malloc(sizeof(int) * item_no)) == NULL) { | 119 | item_foreach() { |
122 | endwin(); | 120 | if (item_is_tag('X')) |
123 | fprintf(stderr, | 121 | choice = item_n(); |
124 | "\nCan't allocate memory in dialog_checklist().\n"); | 122 | if (item_is_selected()) { |
125 | exit(-1); | 123 | choice = item_n(); |
126 | } | 124 | break; |
127 | 125 | } | |
128 | /* Initializes status */ | ||
129 | for (i = 0; i < item_no; i++) { | ||
130 | status[i] = !strcasecmp(items[i * 3 + 2], "on"); | ||
131 | if ((!choice && status[i]) | ||
132 | || !strcasecmp(items[i * 3 + 2], "selected")) | ||
133 | choice = i + 1; | ||
134 | } | 126 | } |
135 | if (choice) | ||
136 | choice--; | ||
137 | 127 | ||
138 | max_choice = MIN(list_height, item_no); | 128 | max_choice = MIN(list_height, item_count()); |
139 | 129 | ||
140 | /* center dialog box on screen */ | 130 | /* center dialog box on screen */ |
141 | x = (COLS - width) / 2; | 131 | x = (COLS - width) / 2; |
@@ -176,8 +166,8 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
176 | 166 | ||
177 | /* Find length of longest item in order to center checklist */ | 167 | /* Find length of longest item in order to center checklist */ |
178 | check_x = 0; | 168 | check_x = 0; |
179 | for (i = 0; i < item_no; i++) | 169 | item_foreach() |
180 | check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); | 170 | check_x = MAX(check_x, strlen(item_str()) + 4); |
181 | 171 | ||
182 | check_x = (list_width - check_x) / 2; | 172 | check_x = (list_width - check_x) / 2; |
183 | item_x = check_x + 4; | 173 | item_x = check_x + 4; |
@@ -189,14 +179,11 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
189 | 179 | ||
190 | /* Print the list */ | 180 | /* Print the list */ |
191 | for (i = 0; i < max_choice; i++) { | 181 | for (i = 0; i < max_choice; i++) { |
192 | if (i != choice) | 182 | item_set(scroll + i); |
193 | print_item(list, items[(scroll + i) * 3 + 1], | 183 | print_item(list, i, i == choice); |
194 | status[i + scroll], i, 0); | ||
195 | } | 184 | } |
196 | print_item(list, items[(scroll + choice) * 3 + 1], | ||
197 | status[choice + scroll], choice, 1); | ||
198 | 185 | ||
199 | print_arrows(dialog, choice, item_no, scroll, | 186 | print_arrows(dialog, choice, item_count(), scroll, |
200 | box_y, box_x + check_x + 5, list_height); | 187 | box_y, box_x + check_x + 5, list_height); |
201 | 188 | ||
202 | print_buttons(dialog, height, width, 0); | 189 | print_buttons(dialog, height, width, 0); |
@@ -208,10 +195,11 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
208 | while (key != ESC) { | 195 | while (key != ESC) { |
209 | key = wgetch(dialog); | 196 | key = wgetch(dialog); |
210 | 197 | ||
211 | for (i = 0; i < max_choice; i++) | 198 | for (i = 0; i < max_choice; i++) { |
212 | if (toupper(key) == | 199 | item_set(i + scroll); |
213 | toupper(items[(scroll + i) * 3 + 1][0])) | 200 | if (toupper(key) == toupper(item_str()[0])) |
214 | break; | 201 | break; |
202 | } | ||
215 | 203 | ||
216 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || | 204 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || |
217 | key == '+' || key == '-') { | 205 | key == '+' || key == '-') { |
@@ -222,15 +210,16 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
222 | /* Scroll list down */ | 210 | /* Scroll list down */ |
223 | if (list_height > 1) { | 211 | if (list_height > 1) { |
224 | /* De-highlight current first item */ | 212 | /* De-highlight current first item */ |
225 | print_item(list, items[scroll * 3 + 1], | 213 | item_set(scroll); |
226 | status[scroll], 0, FALSE); | 214 | print_item(list, 0, FALSE); |
227 | scrollok(list, TRUE); | 215 | scrollok(list, TRUE); |
228 | wscrl(list, -1); | 216 | wscrl(list, -1); |
229 | scrollok(list, FALSE); | 217 | scrollok(list, FALSE); |
230 | } | 218 | } |
231 | scroll--; | 219 | scroll--; |
232 | print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); | 220 | item_set(scroll); |
233 | print_arrows(dialog, choice, item_no, | 221 | print_item(list, 0, TRUE); |
222 | print_arrows(dialog, choice, item_count(), | ||
234 | scroll, box_y, box_x + check_x + 5, list_height); | 223 | scroll, box_y, box_x + check_x + 5, list_height); |
235 | 224 | ||
236 | wnoutrefresh(dialog); | 225 | wnoutrefresh(dialog); |
@@ -241,23 +230,24 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
241 | i = choice - 1; | 230 | i = choice - 1; |
242 | } else if (key == KEY_DOWN || key == '+') { | 231 | } else if (key == KEY_DOWN || key == '+') { |
243 | if (choice == max_choice - 1) { | 232 | if (choice == max_choice - 1) { |
244 | if (scroll + choice >= item_no - 1) | 233 | if (scroll + choice >= item_count() - 1) |
245 | continue; | 234 | continue; |
246 | /* Scroll list up */ | 235 | /* Scroll list up */ |
247 | if (list_height > 1) { | 236 | if (list_height > 1) { |
248 | /* De-highlight current last item before scrolling up */ | 237 | /* De-highlight current last item before scrolling up */ |
249 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 238 | item_set(scroll + max_choice - 1); |
250 | status[scroll + max_choice - 1], | 239 | print_item(list, |
251 | max_choice - 1, FALSE); | 240 | max_choice - 1, |
241 | FALSE); | ||
252 | scrollok(list, TRUE); | 242 | scrollok(list, TRUE); |
253 | wscrl(list, 1); | 243 | wscrl(list, 1); |
254 | scrollok(list, FALSE); | 244 | scrollok(list, FALSE); |
255 | } | 245 | } |
256 | scroll++; | 246 | scroll++; |
257 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 247 | item_set(scroll + max_choice - 1); |
258 | status[scroll + max_choice - 1], max_choice - 1, TRUE); | 248 | print_item(list, max_choice - 1, TRUE); |
259 | 249 | ||
260 | print_arrows(dialog, choice, item_no, | 250 | print_arrows(dialog, choice, item_count(), |
261 | scroll, box_y, box_x + check_x + 5, list_height); | 251 | scroll, box_y, box_x + check_x + 5, list_height); |
262 | 252 | ||
263 | wnoutrefresh(dialog); | 253 | wnoutrefresh(dialog); |
@@ -269,12 +259,12 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
269 | } | 259 | } |
270 | if (i != choice) { | 260 | if (i != choice) { |
271 | /* De-highlight current item */ | 261 | /* De-highlight current item */ |
272 | print_item(list, items[(scroll + choice) * 3 + 1], | 262 | item_set(scroll + choice); |
273 | status[scroll + choice], choice, FALSE); | 263 | print_item(list, choice, FALSE); |
274 | /* Highlight new item */ | 264 | /* Highlight new item */ |
275 | choice = i; | 265 | choice = i; |
276 | print_item(list, items[(scroll + choice) * 3 + 1], | 266 | item_set(scroll + choice); |
277 | status[scroll + choice], choice, TRUE); | 267 | print_item(list, choice, TRUE); |
278 | wnoutrefresh(dialog); | 268 | wnoutrefresh(dialog); |
279 | wrefresh(list); | 269 | wrefresh(list); |
280 | } | 270 | } |
@@ -284,10 +274,19 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
284 | case 'H': | 274 | case 'H': |
285 | case 'h': | 275 | case 'h': |
286 | case '?': | 276 | case '?': |
287 | fprintf(stderr, "%s", items[(scroll + choice) * 3]); | 277 | button = 1; |
278 | /* fall-through */ | ||
279 | case 'S': | ||
280 | case 's': | ||
281 | case ' ': | ||
282 | case '\n': | ||
283 | item_foreach() | ||
284 | item_set_selected(0); | ||
285 | item_set(scroll + choice); | ||
286 | item_set_selected(1); | ||
287 | delwin(list); | ||
288 | delwin(dialog); | 288 | delwin(dialog); |
289 | free(status); | 289 | return button; |
290 | return 1; | ||
291 | case TAB: | 290 | case TAB: |
292 | case KEY_LEFT: | 291 | case KEY_LEFT: |
293 | case KEY_RIGHT: | 292 | case KEY_RIGHT: |
@@ -297,30 +296,6 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
297 | print_buttons(dialog, height, width, button); | 296 | print_buttons(dialog, height, width, button); |
298 | wrefresh(dialog); | 297 | wrefresh(dialog); |
299 | break; | 298 | break; |
300 | case 'S': | ||
301 | case 's': | ||
302 | case ' ': | ||
303 | case '\n': | ||
304 | if (!button) { | ||
305 | if (!status[scroll + choice]) { | ||
306 | for (i = 0; i < item_no; i++) | ||
307 | status[i] = 0; | ||
308 | status[scroll + choice] = 1; | ||
309 | for (i = 0; i < max_choice; i++) | ||
310 | print_item(list, items[(scroll + i) * 3 + 1], | ||
311 | status[scroll + i], i, i == choice); | ||
312 | } | ||
313 | wnoutrefresh(dialog); | ||
314 | wrefresh(list); | ||
315 | |||
316 | for (i = 0; i < item_no; i++) | ||
317 | if (status[i]) | ||
318 | fprintf(stderr, "%s", items[i * 3]); | ||
319 | } else | ||
320 | fprintf(stderr, "%s", items[(scroll + choice) * 3]); | ||
321 | delwin(dialog); | ||
322 | free(status); | ||
323 | return button; | ||
324 | case 'X': | 299 | case 'X': |
325 | case 'x': | 300 | case 'x': |
326 | key = ESC; | 301 | key = ESC; |
@@ -331,8 +306,7 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
331 | /* Now, update everything... */ | 306 | /* Now, update everything... */ |
332 | doupdate(); | 307 | doupdate(); |
333 | } | 308 | } |
334 | 309 | delwin(list); | |
335 | delwin(dialog); | 310 | delwin(dialog); |
336 | free(status); | 311 | return 255; /* ESC pressed */ |
337 | return -1; /* ESC pressed */ | ||
338 | } | 312 | } |