diff options
author | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-11-19 13:13:34 -0500 |
---|---|---|
committer | Sam Ravnborg <sam@mars.ravnborg.org> | 2005-11-19 13:13:34 -0500 |
commit | b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2 (patch) | |
tree | 7325e59c16a2b90fd6f78ab491f7ef48bfd409b9 /scripts/lxdialog/menubox.c | |
parent | b286e39207237e2f6929959372bf66d9a8d05a82 (diff) |
kconfig: Lindent scripts/lxdialog
The lxdialog code was not easy to read. So as first step the code
was run through Lindent.
Fix-ups will come in next patchset.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/lxdialog/menubox.c')
-rw-r--r-- | scripts/lxdialog/menubox.c | 724 |
1 files changed, 381 insertions, 343 deletions
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c index 91d82ba17f8d..083f13de558c 100644 --- a/scripts/lxdialog/menubox.c +++ b/scripts/lxdialog/menubox.c | |||
@@ -64,382 +64,420 @@ static int menu_width, item_x; | |||
64 | * Print menu item | 64 | * Print menu item |
65 | */ | 65 | */ |
66 | static void | 66 | static void |
67 | print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey) | 67 | print_item(WINDOW * win, const char *item, int choice, 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]; |
71 | 71 | ||
72 | strncpy(menu_item, item, menu_width); | 72 | strncpy(menu_item, item, menu_width); |
73 | menu_item[menu_width] = 0; | 73 | menu_item[menu_width] = 0; |
74 | j = first_alpha(menu_item, "YyNnMmHh"); | 74 | j = first_alpha(menu_item, "YyNnMmHh"); |
75 | 75 | ||
76 | /* Clear 'residue' of last item */ | 76 | /* Clear 'residue' of last item */ |
77 | wattrset (win, menubox_attr); | 77 | wattrset(win, menubox_attr); |
78 | wmove (win, choice, 0); | 78 | wmove(win, choice, 0); |
79 | #if OLD_NCURSES | 79 | #if OLD_NCURSES |
80 | { | 80 | { |
81 | int i; | 81 | int i; |
82 | for (i = 0; i < menu_width; i++) | 82 | for (i = 0; i < menu_width; i++) |
83 | waddch (win, ' '); | 83 | waddch(win, ' '); |
84 | } | 84 | } |
85 | #else | 85 | #else |
86 | wclrtoeol(win); | 86 | wclrtoeol(win); |
87 | #endif | 87 | #endif |
88 | wattrset (win, selected ? item_selected_attr : item_attr); | 88 | wattrset(win, selected ? item_selected_attr : item_attr); |
89 | mvwaddstr (win, choice, item_x, menu_item); | 89 | mvwaddstr(win, choice, item_x, menu_item); |
90 | if (hotkey) { | 90 | if (hotkey) { |
91 | wattrset (win, selected ? tag_key_selected_attr : tag_key_attr); | 91 | wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); |
92 | mvwaddch(win, choice, item_x+j, menu_item[j]); | 92 | mvwaddch(win, choice, item_x + j, menu_item[j]); |
93 | } | 93 | } |
94 | if (selected) { | 94 | if (selected) { |
95 | wmove (win, choice, item_x+1); | 95 | wmove(win, choice, item_x + 1); |
96 | wrefresh (win); | 96 | wrefresh(win); |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | /* | 100 | /* |
101 | * Print the scroll indicators. | 101 | * Print the scroll indicators. |
102 | */ | 102 | */ |
103 | static void | 103 | static void |
104 | print_arrows (WINDOW * win, int item_no, int scroll, | 104 | print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height) |
105 | int y, int x, int height) | ||
106 | { | 105 | { |
107 | int cur_y, cur_x; | 106 | int cur_y, cur_x; |
108 | 107 | ||
109 | getyx(win, cur_y, cur_x); | 108 | getyx(win, cur_y, cur_x); |
110 | 109 | ||
111 | wmove(win, y, x); | 110 | wmove(win, y, x); |
112 | 111 | ||
113 | if (scroll > 0) { | 112 | if (scroll > 0) { |
114 | wattrset (win, uarrow_attr); | 113 | wattrset(win, uarrow_attr); |
115 | waddch (win, ACS_UARROW); | 114 | waddch(win, ACS_UARROW); |
116 | waddstr (win, "(-)"); | 115 | waddstr(win, "(-)"); |
117 | } | 116 | } else { |
118 | else { | 117 | wattrset(win, menubox_attr); |
119 | wattrset (win, menubox_attr); | 118 | waddch(win, ACS_HLINE); |
120 | waddch (win, ACS_HLINE); | 119 | waddch(win, ACS_HLINE); |
121 | waddch (win, ACS_HLINE); | 120 | waddch(win, ACS_HLINE); |
122 | waddch (win, ACS_HLINE); | 121 | waddch(win, ACS_HLINE); |
123 | waddch (win, ACS_HLINE); | 122 | } |
124 | } | 123 | |
125 | 124 | y = y + height + 1; | |
126 | y = y + height + 1; | 125 | wmove(win, y, x); |
127 | wmove(win, y, x); | 126 | |
128 | 127 | if ((height < item_no) && (scroll + height < item_no)) { | |
129 | if ((height < item_no) && (scroll + height < item_no)) { | 128 | wattrset(win, darrow_attr); |
130 | wattrset (win, darrow_attr); | 129 | waddch(win, ACS_DARROW); |
131 | waddch (win, ACS_DARROW); | 130 | waddstr(win, "(+)"); |
132 | waddstr (win, "(+)"); | 131 | } else { |
133 | } | 132 | wattrset(win, menubox_border_attr); |
134 | else { | 133 | waddch(win, ACS_HLINE); |
135 | wattrset (win, menubox_border_attr); | 134 | waddch(win, ACS_HLINE); |
136 | waddch (win, ACS_HLINE); | 135 | waddch(win, ACS_HLINE); |
137 | waddch (win, ACS_HLINE); | 136 | waddch(win, ACS_HLINE); |
138 | waddch (win, ACS_HLINE); | 137 | } |
139 | waddch (win, ACS_HLINE); | 138 | |
140 | } | 139 | wmove(win, cur_y, cur_x); |
141 | |||
142 | wmove(win, cur_y, cur_x); | ||
143 | } | 140 | } |
144 | 141 | ||
145 | /* | 142 | /* |
146 | * Display the termination buttons. | 143 | * Display the termination buttons. |
147 | */ | 144 | */ |
148 | static void | 145 | static void print_buttons(WINDOW * win, int height, int width, int selected) |
149 | print_buttons (WINDOW *win, int height, int width, int selected) | ||
150 | { | 146 | { |
151 | int x = width / 2 - 16; | 147 | int x = width / 2 - 16; |
152 | int y = height - 2; | 148 | int y = height - 2; |
153 | 149 | ||
154 | print_button (win, "Select", y, x, selected == 0); | 150 | print_button(win, "Select", y, x, selected == 0); |
155 | print_button (win, " Exit ", y, x + 12, selected == 1); | 151 | print_button(win, " Exit ", y, x + 12, selected == 1); |
156 | print_button (win, " Help ", y, x + 24, selected == 2); | 152 | print_button(win, " Help ", y, x + 24, selected == 2); |
157 | 153 | ||
158 | wmove(win, y, x+1+12*selected); | 154 | wmove(win, y, x + 1 + 12 * selected); |
159 | wrefresh (win); | 155 | wrefresh(win); |
160 | } | 156 | } |
161 | 157 | ||
162 | /* | 158 | /* |
163 | * Display a menu for choosing among a number of options | 159 | * Display a menu for choosing among a number of options |
164 | */ | 160 | */ |
165 | int | 161 | int |
166 | 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, |
167 | int menu_height, const char *current, int item_no, | 163 | int menu_height, const char *current, int item_no, |
168 | const char * const * items) | 164 | const char *const *items) |
169 | |||
170 | { | 165 | { |
171 | int i, j, x, y, box_x, box_y; | 166 | int i, j, x, y, box_x, box_y; |
172 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice; | 167 | int key = 0, button = 0, scroll = 0, choice = 0, first_item = |
173 | WINDOW *dialog, *menu; | 168 | 0, max_choice; |
174 | FILE *f; | 169 | WINDOW *dialog, *menu; |
175 | 170 | FILE *f; | |
176 | max_choice = MIN (menu_height, item_no); | 171 | |
177 | 172 | max_choice = MIN(menu_height, item_no); | |
178 | /* center dialog box on screen */ | 173 | |
179 | x = (COLS - width) / 2; | 174 | /* center dialog box on screen */ |
180 | y = (LINES - height) / 2; | 175 | x = (COLS - width) / 2; |
181 | 176 | y = (LINES - height) / 2; | |
182 | draw_shadow (stdscr, y, x, height, width); | 177 | |
183 | 178 | draw_shadow(stdscr, y, x, height, width); | |
184 | dialog = newwin (height, width, y, x); | 179 | |
185 | keypad (dialog, TRUE); | 180 | dialog = newwin(height, width, y, x); |
186 | 181 | keypad(dialog, TRUE); | |
187 | draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); | 182 | |
188 | wattrset (dialog, border_attr); | 183 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); |
189 | mvwaddch (dialog, height - 3, 0, ACS_LTEE); | 184 | wattrset(dialog, border_attr); |
190 | for (i = 0; i < width - 2; i++) | 185 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
191 | waddch (dialog, ACS_HLINE); | 186 | for (i = 0; i < width - 2; i++) |
192 | wattrset (dialog, dialog_attr); | 187 | waddch(dialog, ACS_HLINE); |
193 | wbkgdset (dialog, dialog_attr & A_COLOR); | 188 | wattrset(dialog, dialog_attr); |
194 | waddch (dialog, ACS_RTEE); | 189 | wbkgdset(dialog, dialog_attr & A_COLOR); |
195 | 190 | waddch(dialog, ACS_RTEE); | |
196 | if (title != NULL && strlen(title) >= width-2 ) { | 191 | |
197 | /* truncate long title -- mec */ | 192 | if (title != NULL && strlen(title) >= width - 2) { |
198 | char * title2 = malloc(width-2+1); | 193 | /* truncate long title -- mec */ |
199 | memcpy( title2, title, width-2 ); | 194 | char *title2 = malloc(width - 2 + 1); |
200 | title2[width-2] = '\0'; | 195 | memcpy(title2, title, width - 2); |
201 | title = title2; | 196 | title2[width - 2] = '\0'; |
202 | } | 197 | title = title2; |
203 | |||
204 | 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, ' '); | ||
209 | } | ||
210 | |||
211 | wattrset (dialog, dialog_attr); | ||
212 | print_autowrap (dialog, prompt, width - 2, 1, 3); | ||
213 | |||
214 | menu_width = width - 6; | ||
215 | box_y = height - menu_height - 5; | ||
216 | box_x = (width - menu_width) / 2 - 1; | ||
217 | |||
218 | /* create new window for the menu */ | ||
219 | menu = subwin (dialog, menu_height, menu_width, | ||
220 | y + box_y + 1, x + box_x + 1); | ||
221 | keypad (menu, TRUE); | ||
222 | |||
223 | /* draw a box around the menu items */ | ||
224 | draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2, | ||
225 | menubox_border_attr, menubox_attr); | ||
226 | |||
227 | /* | ||
228 | * Find length of longest item in order to center menu. | ||
229 | * Set 'choice' to default item. | ||
230 | */ | ||
231 | item_x = 0; | ||
232 | 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; | ||
235 | } | ||
236 | |||
237 | item_x = (menu_width - item_x) / 2; | ||
238 | |||
239 | /* get the scroll info from the temp file */ | ||
240 | 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 | } | 198 | } |
253 | } | 199 | |
254 | if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) { | 200 | if (title != NULL) { |
255 | if (choice >= item_no-max_choice/2) | 201 | wattrset(dialog, title_attr); |
256 | scroll = first_item = item_no-max_choice; | 202 | mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' '); |
257 | else | 203 | waddstr(dialog, (char *)title); |
258 | scroll = first_item = choice - max_choice/2; | 204 | waddch(dialog, ' '); |
259 | choice = choice - scroll; | ||
260 | } | ||
261 | |||
262 | /* Print the menu */ | ||
263 | for (i=0; i < max_choice; i++) { | ||
264 | print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice, | ||
265 | (items[(first_item + i)*2][0] != ':')); | ||
266 | } | ||
267 | |||
268 | wnoutrefresh (menu); | ||
269 | |||
270 | print_arrows(dialog, item_no, scroll, | ||
271 | box_y, box_x+item_x+1, menu_height); | ||
272 | |||
273 | print_buttons (dialog, height, width, 0); | ||
274 | wmove (menu, choice, item_x+1); | ||
275 | wrefresh (menu); | ||
276 | |||
277 | while (key != ESC) { | ||
278 | key = wgetch(menu); | ||
279 | |||
280 | if (key < 256 && isalpha(key)) key = tolower(key); | ||
281 | |||
282 | if (strchr("ynmh", key)) | ||
283 | i = max_choice; | ||
284 | else { | ||
285 | for (i = choice+1; i < max_choice; i++) { | ||
286 | j = first_alpha(items[(scroll+i)*2+1], "YyNnMmHh"); | ||
287 | if (key == tolower(items[(scroll+i)*2+1][j])) | ||
288 | break; | ||
289 | } | 205 | } |
290 | if (i == max_choice) | 206 | |
291 | for (i = 0; i < max_choice; i++) { | 207 | wattrset(dialog, dialog_attr); |
292 | j = first_alpha(items[(scroll+i)*2+1], "YyNnMmHh"); | 208 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
293 | if (key == tolower(items[(scroll+i)*2+1][j])) | 209 | |
294 | break; | 210 | menu_width = width - 6; |
211 | box_y = height - menu_height - 5; | ||
212 | box_x = (width - menu_width) / 2 - 1; | ||
213 | |||
214 | /* create new window for the menu */ | ||
215 | menu = subwin(dialog, menu_height, menu_width, | ||
216 | y + box_y + 1, x + box_x + 1); | ||
217 | keypad(menu, TRUE); | ||
218 | |||
219 | /* draw a box around the menu items */ | ||
220 | draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, | ||
221 | menubox_border_attr, menubox_attr); | ||
222 | |||
223 | /* | ||
224 | * Find length of longest item in order to center menu. | ||
225 | * Set 'choice' to default item. | ||
226 | */ | ||
227 | item_x = 0; | ||
228 | for (i = 0; i < item_no; i++) { | ||
229 | item_x = | ||
230 | MAX(item_x, MIN(menu_width, strlen(items[i * 2 + 1]) + 2)); | ||
231 | if (strcmp(current, items[i * 2]) == 0) | ||
232 | choice = i; | ||
233 | } | ||
234 | |||
235 | item_x = (menu_width - item_x) / 2; | ||
236 | |||
237 | /* get the scroll info from the temp file */ | ||
238 | if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { | ||
239 | if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && | ||
240 | (scroll + max_choice > choice) && (scroll >= 0) && | ||
241 | (scroll + max_choice <= item_no)) { | ||
242 | first_item = scroll; | ||
243 | choice = choice - scroll; | ||
244 | fclose(f); | ||
245 | } else { | ||
246 | scroll = 0; | ||
247 | remove("lxdialog.scrltmp"); | ||
248 | fclose(f); | ||
249 | f = NULL; | ||
295 | } | 250 | } |
296 | } | 251 | } |
252 | if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { | ||
253 | if (choice >= item_no - max_choice / 2) | ||
254 | scroll = first_item = item_no - max_choice; | ||
255 | else | ||
256 | scroll = first_item = choice - max_choice / 2; | ||
257 | choice = choice - scroll; | ||
258 | } | ||
297 | 259 | ||
298 | if (i < max_choice || | 260 | /* Print the menu */ |
299 | key == KEY_UP || key == KEY_DOWN || | 261 | for (i = 0; i < max_choice; i++) { |
300 | key == '-' || key == '+' || | 262 | print_item(menu, items[(first_item + i) * 2 + 1], i, |
301 | key == KEY_PPAGE || key == KEY_NPAGE) { | 263 | i == choice, |
302 | 264 | (items[(first_item + i) * 2][0] != ':')); | |
303 | print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, | 265 | } |
304 | (items[(scroll+choice)*2][0] != ':')); | 266 | |
305 | 267 | wnoutrefresh(menu); | |
306 | if (key == KEY_UP || key == '-') { | 268 | |
307 | if (choice < 2 && scroll) { | 269 | print_arrows(dialog, item_no, scroll, |
308 | /* Scroll menu down */ | 270 | box_y, box_x + item_x + 1, menu_height); |
309 | scrollok (menu, TRUE); | 271 | |
310 | wscrl (menu, -1); | 272 | print_buttons(dialog, height, width, 0); |
311 | scrollok (menu, FALSE); | 273 | wmove(menu, choice, item_x + 1); |
312 | 274 | wrefresh(menu); | |
313 | scroll--; | 275 | |
314 | 276 | while (key != ESC) { | |
315 | print_item (menu, items[scroll * 2 + 1], 0, FALSE, | 277 | key = wgetch(menu); |
316 | (items[scroll*2][0] != ':')); | 278 | |
317 | } else | 279 | if (key < 256 && isalpha(key)) |
318 | choice = MAX(choice - 1, 0); | 280 | key = tolower(key); |
319 | 281 | ||
320 | } else if (key == KEY_DOWN || key == '+') { | 282 | if (strchr("ynmh", key)) |
321 | 283 | i = max_choice; | |
322 | print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, | 284 | else { |
323 | (items[(scroll+choice)*2][0] != ':')); | 285 | for (i = choice + 1; i < max_choice; i++) { |
324 | 286 | j = first_alpha(items[(scroll + i) * 2 + 1], | |
325 | if ((choice > max_choice-3) && | 287 | "YyNnMmHh"); |
326 | (scroll + max_choice < item_no) | 288 | if (key == |
327 | ) { | 289 | tolower(items[(scroll + i) * 2 + 1][j])) |
328 | /* Scroll menu up */ | 290 | break; |
329 | scrollok (menu, TRUE); | 291 | } |
330 | wscrl (menu, 1); | 292 | if (i == max_choice) |
331 | scrollok (menu, FALSE); | 293 | for (i = 0; i < max_choice; i++) { |
332 | 294 | j = first_alpha(items | |
333 | scroll++; | 295 | [(scroll + i) * 2 + 1], |
334 | 296 | "YyNnMmHh"); | |
335 | print_item (menu, items[(scroll+max_choice-1)*2+1], | 297 | if (key == |
336 | max_choice-1, FALSE, | 298 | tolower(items[(scroll + i) * 2 + 1] |
337 | (items[(scroll+max_choice-1)*2][0] != ':')); | 299 | [j])) |
338 | } else | 300 | break; |
339 | choice = MIN(choice+1, max_choice-1); | 301 | } |
340 | 302 | } | |
341 | } else if (key == KEY_PPAGE) { | 303 | |
342 | scrollok (menu, TRUE); | 304 | if (i < max_choice || |
343 | for (i=0; (i < max_choice); i++) { | 305 | key == KEY_UP || key == KEY_DOWN || |
344 | if (scroll > 0) { | 306 | key == '-' || key == '+' || |
345 | wscrl (menu, -1); | 307 | key == KEY_PPAGE || key == KEY_NPAGE) { |
346 | scroll--; | 308 | |
347 | print_item (menu, items[scroll * 2 + 1], 0, FALSE, | 309 | print_item(menu, items[(scroll + choice) * 2 + 1], |
348 | (items[scroll*2][0] != ':')); | 310 | choice, FALSE, |
349 | } else { | 311 | (items[(scroll + choice) * 2][0] != ':')); |
350 | if (choice > 0) | 312 | |
351 | choice--; | 313 | if (key == KEY_UP || key == '-') { |
352 | } | 314 | if (choice < 2 && scroll) { |
353 | } | 315 | /* Scroll menu down */ |
354 | scrollok (menu, FALSE); | 316 | scrollok(menu, TRUE); |
355 | 317 | wscrl(menu, -1); | |
356 | } else if (key == KEY_NPAGE) { | 318 | scrollok(menu, FALSE); |
357 | for (i=0; (i < max_choice); i++) { | 319 | |
358 | if (scroll+max_choice < item_no) { | 320 | scroll--; |
359 | scrollok (menu, TRUE); | 321 | |
360 | wscrl (menu, 1); | 322 | print_item(menu, items[scroll * 2 + 1], |
361 | scrollok (menu, FALSE); | 323 | 0, FALSE, |
362 | scroll++; | 324 | (items[scroll * 2][0] != |
363 | print_item (menu, items[(scroll+max_choice-1)*2+1], | 325 | ':')); |
364 | max_choice-1, FALSE, | 326 | } else |
365 | (items[(scroll+max_choice-1)*2][0] != ':')); | 327 | choice = MAX(choice - 1, 0); |
366 | } else { | 328 | |
367 | if (choice+1 < max_choice) | 329 | } else if (key == KEY_DOWN || key == '+') { |
368 | choice++; | 330 | |
369 | } | 331 | print_item(menu, |
370 | } | 332 | items[(scroll + choice) * 2 + 1], |
371 | 333 | choice, FALSE, | |
372 | } else | 334 | (items[(scroll + choice) * 2][0] != |
373 | choice = i; | 335 | ':')); |
374 | 336 | ||
375 | print_item (menu, items[(scroll+choice)*2+1], choice, TRUE, | 337 | if ((choice > max_choice - 3) && |
376 | (items[(scroll+choice)*2][0] != ':')); | 338 | (scroll + max_choice < item_no) |
377 | 339 | ) { | |
378 | print_arrows(dialog, item_no, scroll, | 340 | /* Scroll menu up */ |
379 | box_y, box_x+item_x+1, menu_height); | 341 | scrollok(menu, TRUE); |
380 | 342 | wscrl(menu, 1); | |
381 | wnoutrefresh (dialog); | 343 | scrollok(menu, FALSE); |
382 | wrefresh (menu); | 344 | |
383 | 345 | scroll++; | |
384 | continue; /* wait for another key press */ | 346 | |
385 | } | 347 | print_item(menu, |
386 | 348 | items[(scroll + max_choice - | |
387 | switch (key) { | 349 | 1) * 2 + 1], |
388 | case KEY_LEFT: | 350 | max_choice - 1, FALSE, |
389 | case TAB: | 351 | (items |
390 | case KEY_RIGHT: | 352 | [(scroll + max_choice - |
391 | button = ((key == KEY_LEFT ? --button : ++button) < 0) | 353 | 1) * 2][0] != ':')); |
392 | ? 2 : (button > 2 ? 0 : button); | 354 | } else |
393 | 355 | choice = | |
394 | print_buttons(dialog, height, width, button); | 356 | MIN(choice + 1, max_choice - 1); |
395 | wrefresh (menu); | 357 | |
396 | break; | 358 | } else if (key == KEY_PPAGE) { |
397 | case ' ': | 359 | scrollok(menu, TRUE); |
398 | case 's': | 360 | for (i = 0; (i < max_choice); i++) { |
399 | case 'y': | 361 | if (scroll > 0) { |
400 | case 'n': | 362 | wscrl(menu, -1); |
401 | case 'm': | 363 | scroll--; |
402 | case '/': | 364 | print_item(menu, |
403 | /* save scroll info */ | 365 | items[scroll * 2 + |
404 | if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { | 366 | 1], 0, FALSE, |
405 | fprintf(f,"%d\n",scroll); | 367 | (items[scroll * 2][0] |
406 | fclose(f); | 368 | != ':')); |
407 | } | 369 | } else { |
408 | delwin (dialog); | 370 | if (choice > 0) |
409 | fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | 371 | choice--; |
410 | switch (key) { | 372 | } |
411 | case 's': return 3; | 373 | } |
412 | case 'y': return 3; | 374 | scrollok(menu, FALSE); |
413 | case 'n': return 4; | 375 | |
414 | case 'm': return 5; | 376 | } else if (key == KEY_NPAGE) { |
415 | case ' ': return 6; | 377 | for (i = 0; (i < max_choice); i++) { |
416 | case '/': return 7; | 378 | if (scroll + max_choice < item_no) { |
417 | } | 379 | scrollok(menu, TRUE); |
418 | return 0; | 380 | wscrl(menu, 1); |
419 | case 'h': | 381 | scrollok(menu, FALSE); |
420 | case '?': | 382 | scroll++; |
421 | button = 2; | 383 | print_item(menu, |
422 | case '\n': | 384 | items[(scroll + |
423 | delwin (dialog); | 385 | max_choice - |
424 | if (button == 2) | 386 | 1) * 2 + 1], |
425 | fprintf(stderr, "%s \"%s\"\n", | 387 | max_choice - 1, |
426 | items[(scroll + choice) * 2], | 388 | FALSE, |
427 | items[(scroll + choice) * 2 + 1] + | 389 | (items |
428 | first_alpha(items[(scroll + choice) * 2 + 1],"")); | 390 | [(scroll + |
429 | else | 391 | max_choice - |
430 | fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | 392 | 1) * 2][0] != |
431 | 393 | ':')); | |
432 | remove("lxdialog.scrltmp"); | 394 | } else { |
433 | return button; | 395 | if (choice + 1 < max_choice) |
434 | case 'e': | 396 | choice++; |
435 | case 'x': | 397 | } |
436 | key = ESC; | 398 | } |
437 | case ESC: | 399 | |
438 | break; | 400 | } else |
401 | choice = i; | ||
402 | |||
403 | print_item(menu, items[(scroll + choice) * 2 + 1], | ||
404 | choice, TRUE, | ||
405 | (items[(scroll + choice) * 2][0] != ':')); | ||
406 | |||
407 | print_arrows(dialog, item_no, scroll, | ||
408 | box_y, box_x + item_x + 1, menu_height); | ||
409 | |||
410 | wnoutrefresh(dialog); | ||
411 | wrefresh(menu); | ||
412 | |||
413 | continue; /* wait for another key press */ | ||
414 | } | ||
415 | |||
416 | switch (key) { | ||
417 | case KEY_LEFT: | ||
418 | case TAB: | ||
419 | case KEY_RIGHT: | ||
420 | button = ((key == KEY_LEFT ? --button : ++button) < 0) | ||
421 | ? 2 : (button > 2 ? 0 : button); | ||
422 | |||
423 | print_buttons(dialog, height, width, button); | ||
424 | wrefresh(menu); | ||
425 | break; | ||
426 | case ' ': | ||
427 | case 's': | ||
428 | case 'y': | ||
429 | case 'n': | ||
430 | case 'm': | ||
431 | case '/': | ||
432 | /* save scroll info */ | ||
433 | if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { | ||
434 | fprintf(f, "%d\n", scroll); | ||
435 | fclose(f); | ||
436 | } | ||
437 | delwin(dialog); | ||
438 | fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | ||
439 | switch (key) { | ||
440 | case 's': | ||
441 | return 3; | ||
442 | case 'y': | ||
443 | return 3; | ||
444 | case 'n': | ||
445 | return 4; | ||
446 | case 'm': | ||
447 | return 5; | ||
448 | case ' ': | ||
449 | return 6; | ||
450 | case '/': | ||
451 | return 7; | ||
452 | } | ||
453 | return 0; | ||
454 | case 'h': | ||
455 | case '?': | ||
456 | button = 2; | ||
457 | case '\n': | ||
458 | delwin(dialog); | ||
459 | if (button == 2) | ||
460 | fprintf(stderr, "%s \"%s\"\n", | ||
461 | items[(scroll + choice) * 2], | ||
462 | items[(scroll + choice) * 2 + 1] + | ||
463 | first_alpha(items | ||
464 | [(scroll + choice) * 2 + 1], | ||
465 | "")); | ||
466 | else | ||
467 | fprintf(stderr, "%s\n", | ||
468 | items[(scroll + choice) * 2]); | ||
469 | |||
470 | remove("lxdialog.scrltmp"); | ||
471 | return button; | ||
472 | case 'e': | ||
473 | case 'x': | ||
474 | key = ESC; | ||
475 | case ESC: | ||
476 | break; | ||
477 | } | ||
439 | } | 478 | } |
440 | } | ||
441 | 479 | ||
442 | delwin (dialog); | 480 | delwin(dialog); |
443 | remove("lxdialog.scrltmp"); | 481 | remove("lxdialog.scrltmp"); |
444 | return -1; /* ESC pressed */ | 482 | return -1; /* ESC pressed */ |
445 | } | 483 | } |