int attr_normal; int attr_main_heading; int attr_main_menu_box; int attr_main_menu_fore; int attr_main_menu_back; int attr_main_menu_grey; int attr_main_menu_heading; int attr_scrollwin_text; int attr_scrollwin_heading; int attr_scrollwin_box; int attr_dialog_text; int attr_dialog_menu_fore; int attr_dialog_menu_back; int attr_dialog_box; int attr_input_box; int attr_input_heading; int attr_input_text; int attr_input_field; int attr_function_text; int attr_function_highlight;
/* this changes the windows attributes !!! */ void print_in_middle(WINDOW *win, int y, int width, constchar *str, int attrs)
{
wattrset(win, attrs);
mvwprintw(win, y, (width - strlen(str)) / 2, "%s", str);
}
int get_line_no(constchar *text)
{ int i; int total = 1;
if (!text) return 0;
for (i = 0; text[i] != '\0'; i++) if (text[i] == '\n')
total++; return total;
}
constchar *get_line(constchar *text, int line_no)
{ int i; int lines = 0;
if (!text) return NULL;
for (i = 0; text[i] != '\0' && lines < line_no; i++) if (text[i] == '\n')
lines++; return text+i;
}
int get_line_length(constchar *line)
{ int res = 0; while (*line != '\0' && *line != '\n') {
line++;
res++;
} return res;
}
/* print all lines to the window. */ void fill_window(WINDOW *win, constchar *text)
{ int x, y; int total_lines = get_line_no(text); int i;
getmaxyx(win, y, x); /* do not go over end of line */
total_lines = min(total_lines, y); for (i = 0; i < total_lines; i++) { char tmp[x+10]; constchar *line = get_line(text, i); int len = get_line_length(line);
strncpy(tmp, line, min(len, x));
tmp[len] = '\0';
mvwprintw(win, i, 0, "%s", tmp);
}
}
/* get the message, and buttons. * each button must be a char* * return the selected button * * this dialog is used for 2 different things: * 1) show a text box, no buttons. * 2) show a dialog, with horizontal buttons
*/ int btn_dialog(WINDOW *main_window, constchar *msg, int btn_num, ...)
{
va_list ap; char *btn; int btns_width = 0; int msg_lines = 0; int msg_width = 0; int total_width; int win_rows = 0;
WINDOW *win;
WINDOW *msg_win;
WINDOW *menu_win;
MENU *menu;
ITEM *btns[btn_num+1]; int i, x, y; int res = -1;
va_start(ap, btn_num); for (i = 0; i < btn_num; i++) {
btn = va_arg(ap, char *);
btns[i] = new_item(btn, "");
btns_width += strlen(btn)+1;
}
va_end(ap);
btns[btn_num] = NULL;
/* find the widest line of msg: */
msg_lines = get_line_no(msg); for (i = 0; i < msg_lines; i++) { constchar *line = get_line(msg, i); int len = get_line_length(line); if (msg_width < len)
msg_width = len;
}
total_width = max(msg_width, btns_width); /* place dialog in middle of screen */
y = (getmaxy(stdscr)-(msg_lines+4))/2;
x = (getmaxx(stdscr)-(total_width+4))/2;
/* create the windows */ if (btn_num > 0)
win_rows = msg_lines+4; else
win_rows = msg_lines+2;
touchwin(win);
refresh_all_windows(main_window); while ((res = wgetch(win))) { switch (res) { case KEY_LEFT:
menu_driver(menu, REQ_LEFT_ITEM); break; case KEY_RIGHT:
menu_driver(menu, REQ_RIGHT_ITEM); break; case 9: /* TAB */ if (btn_num > 1) { /* cycle through buttons */ if (item_index(current_item(menu)) == btn_num - 1)
menu_driver(menu, REQ_FIRST_ITEM); else
menu_driver(menu, REQ_NEXT_ITEM);
} break; case 10: /* ENTER */ case 27: /* ESCAPE */ case' ': case KEY_F(F_BACK): case KEY_F(F_EXIT): break;
}
touchwin(win);
refresh_all_windows(main_window);
if (res == 10 || res == ' ') {
res = item_index(current_item(menu)); break;
} elseif (res == 27 || res == KEY_F(F_BACK) ||
res == KEY_F(F_EXIT)) {
res = KEY_EXIT; break;
}
}
unpost_menu(menu);
free_menu(menu); for (i = 0; i < btn_num; i++)
free_item(btns[i]);
delwin(win); return res;
}
int dialog_inputbox(WINDOW *main_window, constchar *title, constchar *prompt, constchar *init, char **resultp, int *result_len)
{ int prompt_lines = 0; int prompt_width = 0;
WINDOW *win;
WINDOW *prompt_win;
WINDOW *form_win;
PANEL *panel; int i, x, y, lines, columns, win_lines, win_cols; int res = -1; int cursor_position = strlen(init); int cursor_form_win; char *result = *resultp;
getmaxyx(stdscr, lines, columns);
if (strlen(init)+1 > *result_len) {
*result_len = strlen(init)+1;
*resultp = result = xrealloc(result, *result_len);
}
/* find the widest line of msg: */
prompt_lines = get_line_no(prompt); for (i = 0; i < prompt_lines; i++) { constchar *line = get_line(prompt, i); int len = get_line_length(line);
prompt_width = max(prompt_width, len);
}
if (title)
prompt_width = max(prompt_width, strlen(title));
/* layman's scrollable window... */ int show_scroll_win_ext(WINDOW *main_window, constchar *title, char *text, int *vscroll, int *hscroll,
extra_key_cb_fn extra_key_cb, void *data)
{ int res; int total_lines = get_line_no(text); int x, y, lines, columns; int start_x = 0, start_y = 0; int text_lines = 0, text_cols = 0; int total_cols = 0; int win_cols = 0; int win_lines = 0; int i = 0;
WINDOW *win;
WINDOW *pad;
PANEL *panel; bool done = false;
if (hscroll)
start_x = *hscroll; if (vscroll)
start_y = *vscroll;
getmaxyx(stdscr, lines, columns);
/* find the widest line of msg: */
total_lines = get_line_no(text); for (i = 0; i < total_lines; i++) { constchar *line = get_line(text, i); int len = get_line_length(line);
total_cols = max(total_cols, len+2);
}
/* create the pad */
pad = newpad(total_lines+10, total_cols+10);
wattrset(pad, attr_scrollwin_text);
fill_window(pad, text);
/* place window in middle of screen */
y = (lines-win_lines)/2;
x = (columns-win_cols)/2;
win = newwin(win_lines, win_cols, y, x);
keypad(win, TRUE); /* show the help in the help window, and show the help panel */
wattrset(win, attr_scrollwin_box);
box(win, 0, 0);
wattrset(win, attr_scrollwin_heading);
mvwprintw(win, 0, 3, " %s ", title);
panel = new_panel(win);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.