mirror of
https://git.zap.org.au/git/trader.git
synced 2024-10-27 18:20:13 -04:00
Add the function txdlgbox() to display a dialog box
This commit is contained in:
parent
4e7699f192
commit
6594ff3daa
75
src/intf.c
75
src/intf.c
@ -555,6 +555,78 @@ void txresize (void)
|
|||||||
#endif // HANDLE_RESIZE_EVENTS
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
// txdlgbox: Display a dialog box and wait for any key
|
||||||
|
|
||||||
|
int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x,
|
||||||
|
chtype bkgd_attr, chtype title_attr, chtype norm_attr,
|
||||||
|
chtype alt1_attr, chtype alt2_attr, chtype keywait_attr,
|
||||||
|
const char *restrict boxtitle, const char *restrict format, ...)
|
||||||
|
{
|
||||||
|
bool usetitle = (boxtitle != NULL);
|
||||||
|
|
||||||
|
chtype *chbuf;
|
||||||
|
int *widthbuf;
|
||||||
|
int lines;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
|
||||||
|
assert(maxlines > 0);
|
||||||
|
|
||||||
|
chbuf = malloc(BUFSIZE * sizeof(chtype));
|
||||||
|
if (chbuf == NULL) {
|
||||||
|
err_exit_nomem();
|
||||||
|
}
|
||||||
|
|
||||||
|
widthbuf = malloc(maxlines * sizeof(int));
|
||||||
|
if (widthbuf == NULL) {
|
||||||
|
err_exit_nomem();
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
lines = vprepstr(chbuf, BUFSIZE, norm_attr, alt1_attr, alt2_attr, maxlines,
|
||||||
|
ncols - 4, widthbuf, maxlines, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (lines < 0) {
|
||||||
|
errno_exit("txdlgbox: `%s'", format);
|
||||||
|
}
|
||||||
|
|
||||||
|
newtxwin(usetitle ? lines + 6 : lines + 5, ncols, begin_y, begin_x,
|
||||||
|
true, bkgd_attr);
|
||||||
|
|
||||||
|
if (usetitle) {
|
||||||
|
chtype *titlebuf;
|
||||||
|
int titlewidth;
|
||||||
|
int titlelines;
|
||||||
|
|
||||||
|
titlebuf = malloc(BUFSIZE * sizeof(chtype));
|
||||||
|
if (titlebuf == NULL) {
|
||||||
|
err_exit_nomem();
|
||||||
|
}
|
||||||
|
|
||||||
|
titlelines = prepstr(titlebuf, BUFSIZE, title_attr, bkgd_attr,
|
||||||
|
norm_attr, 1, ncols - 4, &titlewidth, 1,
|
||||||
|
"%s", boxtitle);
|
||||||
|
if (titlelines < 0) {
|
||||||
|
errno_exit("txdlgbox: `%s'", boxtitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_center(curwin, 1, 0, titlebuf, titlelines, &titlewidth);
|
||||||
|
|
||||||
|
free(titlebuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_center(curwin, usetitle ? 3 : 2, 0, chbuf, lines, widthbuf);
|
||||||
|
wait_for_key(curwin, getmaxy(curwin) - 2, keywait_attr);
|
||||||
|
deltxwin();
|
||||||
|
|
||||||
|
free(widthbuf);
|
||||||
|
free(chbuf);
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// prepstr: Prepare a string for printing to screen
|
// prepstr: Prepare a string for printing to screen
|
||||||
|
|
||||||
@ -940,8 +1012,9 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
|
|||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
char *buf = malloc(BUFSIZE);
|
char *buf = malloc(BUFSIZE);
|
||||||
if (buf == NULL)
|
if (buf == NULL) {
|
||||||
err_exit_nomem();
|
err_exit_nomem();
|
||||||
|
}
|
||||||
|
|
||||||
while (inspec && *format != '\0') {
|
while (inspec && *format != '\0') {
|
||||||
char c = *format++;
|
char c = *format++;
|
||||||
|
36
src/intf.h
36
src/intf.h
@ -185,10 +185,10 @@ extern void end_screen (void);
|
|||||||
Function: newtxwin - Create a new window, inserted into window stack
|
Function: newtxwin - Create a new window, inserted into window stack
|
||||||
Parameters: nlines - Number of lines in new window
|
Parameters: nlines - Number of lines in new window
|
||||||
ncols - Number of columns in new window
|
ncols - Number of columns in new window
|
||||||
begin_y - Starting line number (0 to LINES-1)
|
begin_y - Starting line number (0 to LINES-1) or WCENTER
|
||||||
begin_x - Starting column number (0 to COLS-1)
|
begin_x - Starting column number (0 to COLS-1) or WCENTER
|
||||||
dofill - True to draw background and box frame
|
dofill - True to draw background and box frame
|
||||||
bkgd_attr - Background attribute
|
bkgd_attr - Background character rendition
|
||||||
Returns: WINDOW * - Pointer to new window
|
Returns: WINDOW * - Pointer to new window
|
||||||
|
|
||||||
This function creates a window using the Curses newwin() function and
|
This function creates a window using the Curses newwin() function and
|
||||||
@ -254,6 +254,36 @@ extern int delalltxwin (void);
|
|||||||
extern int txrefresh (void);
|
extern int txrefresh (void);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: txdlgbox - Display a dialog box and wait for any key
|
||||||
|
Parameters: maxlines - Maximum number of lines of text in window
|
||||||
|
ncols - Number of columns in dialog box window
|
||||||
|
begin_y - Starting line number (0 to LINES-1) or WCENTER
|
||||||
|
begin_x - Starting column number (0 to COLS-1) or WCENTER
|
||||||
|
bkgd_attr - Background character rendition
|
||||||
|
title_attr - Character rendition to use for dialog box title
|
||||||
|
norm_attr - Normal character rendition in box
|
||||||
|
alt1_attr - Alternate character rendition 1 (highlight)
|
||||||
|
alt2_attr - Alternate character rendition 2 (more highlighted)
|
||||||
|
keywait_attr - "Press any key" character rendition
|
||||||
|
boxtitle - Dialog box title (may be NULL)
|
||||||
|
format - Dialog box text, as passed to prepstr()
|
||||||
|
... - Dialog box text format parameters
|
||||||
|
Returns: int - OK is always returned
|
||||||
|
|
||||||
|
This function creates a dialog box window using newtxwin(), displays
|
||||||
|
boxtitle centered on the first line (if boxtitle is not NULL), displays
|
||||||
|
format (and associated parameters) centered using prepstr(), then waits
|
||||||
|
for the user to press any key before closing the dialog box window.
|
||||||
|
Note that txrefresh() is NOT called once the window is closed.
|
||||||
|
*/
|
||||||
|
extern int txdlgbox (int maxlines, int ncols, int begin_y, int begin_x,
|
||||||
|
chtype bkgd_attr, chtype title_attr, chtype norm_attr,
|
||||||
|
chtype alt1_attr, chtype alt2_attr, chtype keywait_attr,
|
||||||
|
const char *restrict boxtitle,
|
||||||
|
const char *restrict format, ...);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: prepstr - Prepare a string for printing to screen
|
Function: prepstr - Prepare a string for printing to screen
|
||||||
Parameters: chbuf - Pointer to chtype buffer in which to store string
|
Parameters: chbuf - Pointer to chtype buffer in which to store string
|
||||||
|
Loading…
Reference in New Issue
Block a user