61 static int menu_width, item_x;
66 static void do_print_item(
WINDOW *
win,
const char *
item,
int line_y,
70 char *menu_item =
malloc(menu_width + 1);
72 strncpy(menu_item, item, menu_width - item_x);
73 menu_item[menu_width - item_x] =
'\0';
77 wattrset(win,
dlg.menubox.atr);
78 wmove(win, line_y, 0);
82 for (i = 0; i < menu_width; i++)
88 wattrset(win, selected ?
dlg.item_selected.atr :
dlg.item.atr);
89 mvwaddstr(win, line_y, item_x, menu_item);
91 wattrset(win, selected ?
dlg.tag_key_selected.atr
93 mvwaddch(win, line_y, item_x + j, menu_item[j]);
96 wmove(win, line_y, item_x + 1);
102 #define print_item(index, choice, selected) \
105 do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
111 static void print_arrows(
WINDOW * win,
int item_no,
int scroll,
int y,
int x,
116 getyx(win, cur_y, cur_x);
121 wattrset(win,
dlg.uarrow.atr);
125 wattrset(win,
dlg.menubox.atr);
136 if ((height < item_no) && (scroll + height < item_no)) {
137 wattrset(win,
dlg.darrow.atr);
141 wattrset(win,
dlg.menubox_border.atr);
148 wmove(win, cur_y, cur_x);
157 int x = width / 2 - 16;
160 print_button(win, gettext(
"Select"), y, x, selected == 0);
161 print_button(win, gettext(
" Exit "), y, x + 12, selected == 1);
162 print_button(win, gettext(
" Help "), y, x + 24, selected == 2);
164 wmove(win, y, x + 1 + 12 * selected);
169 static void do_scroll(
WINDOW *win,
int *scroll,
int n)
174 scrollok(win,
FALSE);
175 *scroll = *scroll +
n;
183 const void *selected,
int *s_scroll)
185 int i,
j,
x,
y, box_x, box_y;
187 int key = 0,
button = 0, scroll = 0, choice = 0;
188 int first_item = 0, max_choice;
192 height = getmaxy(stdscr);
193 width = getmaxx(stdscr);
194 if (height < 15 || width < 65)
199 menu_height = height - 10;
209 dialog = newwin(height, width, y, x);
210 keypad(dialog,
TRUE);
212 draw_box(dialog, 0, 0, height, width,
213 dlg.dialog.atr,
dlg.border.atr);
214 wattrset(dialog,
dlg.border.atr);
215 mvwaddch(dialog, height - 3, 0,
ACS_LTEE);
216 for (i = 0; i < width - 2; i++)
218 wattrset(dialog,
dlg.dialog.atr);
219 wbkgdset(dialog,
dlg.dialog.atr & A_COLOR);
224 wattrset(dialog,
dlg.dialog.atr);
227 menu_width = width - 6;
228 box_y = height - menu_height - 5;
229 box_x = (width - menu_width) / 2 - 1;
232 menu = subwin(dialog, menu_height, menu_width,
233 y + box_y + 1, x + box_x + 1);
237 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
238 dlg.menubox_border.atr,
dlg.menubox.atr);
240 if (menu_width >= 80)
241 item_x = (menu_width - 70) / 2;
247 if (selected && (selected ==
item_data()))
251 if ((scroll <= choice) && (scroll + max_choice > choice) &&
252 (scroll >= 0) && (scroll + max_choice <=
item_count())) {
254 choice = choice - scroll;
258 if ((choice >= max_choice)) {
260 scroll = first_item =
item_count() - max_choice;
262 scroll = first_item = choice - max_choice / 2;
263 choice = choice - scroll;
267 for (i = 0; i < max_choice; i++) {
274 box_y, box_x + item_x + 1, menu_height);
276 print_buttons(dialog, height, width, 0);
277 wmove(menu, choice, item_x + 1);
289 for (i = choice + 1; i < max_choice; i++) {
296 for (i = 0; i < max_choice; i++) {
304 if (i < max_choice ||
306 key ==
'-' || key ==
'+' ||
307 key == KEY_PPAGE || key == KEY_NPAGE) {
311 if (key ==
KEY_UP || key ==
'-') {
312 if (choice < 2 && scroll) {
314 do_scroll(menu, &scroll, -1);
318 choice =
MAX(choice - 1, 0);
320 }
else if (key ==
KEY_DOWN || key ==
'+') {
323 if ((choice > max_choice - 3) &&
326 do_scroll(menu, &scroll, 1);
329 max_choice - 1,
FALSE);
331 choice =
MIN(choice + 1, max_choice - 1);
333 }
else if (key == KEY_PPAGE) {
334 scrollok(menu,
TRUE);
335 for (i = 0; (i < max_choice); i++) {
337 do_scroll(menu, &scroll, -1);
345 }
else if (key == KEY_NPAGE) {
346 for (i = 0; (i < max_choice); i++) {
348 do_scroll(menu, &scroll, 1);
350 max_choice - 1,
FALSE);
352 if (choice + 1 < max_choice)
362 box_y, box_x + item_x + 1, menu_height);
364 wnoutrefresh(dialog);
377 print_buttons(dialog, height, width,
button);