| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
#include "dialog.h" |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
int |
|---|
| 29 |
dialog_msgbox (const char *title, const char *prompt, int height, int width, |
|---|
| 30 |
int pause) |
|---|
| 31 |
{ |
|---|
| 32 |
int i, x, y, key = 0; |
|---|
| 33 |
WINDOW *dialog; |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
x = (COLS - width) / 2; |
|---|
| 37 |
y = (LINES - height) / 2; |
|---|
| 38 |
|
|---|
| 39 |
draw_shadow (stdscr, y, x, height, width); |
|---|
| 40 |
|
|---|
| 41 |
dialog = newwin (height, width, y, x); |
|---|
| 42 |
keypad (dialog, TRUE); |
|---|
| 43 |
|
|---|
| 44 |
draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); |
|---|
| 45 |
|
|---|
| 46 |
if (title != NULL && strlen(title) >= width-2 ) { |
|---|
| 47 |
|
|---|
| 48 |
char * title2 = malloc(width-2+1); |
|---|
| 49 |
memcpy( title2, title, width-2 ); |
|---|
| 50 |
title2[width-2] = '\0'; |
|---|
| 51 |
title = title2; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
if (title != NULL) { |
|---|
| 55 |
wattrset (dialog, title_attr); |
|---|
| 56 |
mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); |
|---|
| 57 |
waddstr (dialog, (char *)title); |
|---|
| 58 |
waddch (dialog, ' '); |
|---|
| 59 |
} |
|---|
| 60 |
wattrset (dialog, dialog_attr); |
|---|
| 61 |
print_autowrap (dialog, prompt, width - 2, 1, 2); |
|---|
| 62 |
|
|---|
| 63 |
if (pause) { |
|---|
| 64 |
wattrset (dialog, border_attr); |
|---|
| 65 |
mvwaddch (dialog, height - 3, 0, ACS_LTEE); |
|---|
| 66 |
for (i = 0; i < width - 2; i++) |
|---|
| 67 |
waddch (dialog, ACS_HLINE); |
|---|
| 68 |
wattrset (dialog, dialog_attr); |
|---|
| 69 |
waddch (dialog, ACS_RTEE); |
|---|
| 70 |
|
|---|
| 71 |
print_button (dialog, " Ok ", |
|---|
| 72 |
height - 2, width / 2 - 4, TRUE); |
|---|
| 73 |
|
|---|
| 74 |
wrefresh (dialog); |
|---|
| 75 |
while (key != ESC && key != '\n' && key != ' ' && |
|---|
| 76 |
key != 'O' && key != 'o' && key != 'X' && key != 'x') |
|---|
| 77 |
key = wgetch (dialog); |
|---|
| 78 |
} else { |
|---|
| 79 |
key = '\n'; |
|---|
| 80 |
wrefresh (dialog); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
delwin (dialog); |
|---|
| 84 |
return key == ESC ? -1 : 0; |
|---|
| 85 |
} |
|---|