Merge branch 'NetHack-3.6.2'

This commit is contained in:
nhmall
2018-10-27 19:30:23 -04:00
17 changed files with 283 additions and 251 deletions

View File

@@ -164,8 +164,6 @@ static void FDECL(done_button, (Widget, XtPointer, XtPointer));
static void FDECL(getline_delete, (Widget, XEvent *, String *, Cardinal *));
static void FDECL(abort_button, (Widget, XtPointer, XtPointer));
static void NDECL(release_getline_widgets);
static void FDECL(delete_file, (Widget, XEvent *, String *, Cardinal *));
static void FDECL(dismiss_file, (Widget, XEvent *, String *, Cardinal *));
static void FDECL(yn_delete, (Widget, XEvent *, String *, Cardinal *));
static void FDECL(yn_key, (Widget, XEvent *, String *, Cardinal *));
static void NDECL(release_yn_widgets);
@@ -1077,6 +1075,7 @@ int type;
wp->nh_colors_inited = FALSE;
wp->boldfs = (XFontStruct *) 0;
wp->boldfs_dpy = (Display *) 0;
wp->title = (char *) 0;
switch (type) {
case NHW_MAP:
@@ -1227,6 +1226,11 @@ winid window;
wp->boldfs_dpy = (Display *) 0;
}
if (wp->title) {
free(wp->title);
wp->title = (char *) 0;
}
switch (wp->type) {
case NHW_MAP:
destroy_map_window(wp);
@@ -1369,8 +1373,6 @@ Widget toplevel = (Widget) 0; /* toplevel widget */
Atom wm_delete_window; /* pop down windows */
static XtActionsRec actions[] = {
{ nhStr("dismiss_file"), dismiss_file }, /* file viewing widget */
{ nhStr("delete_file"), delete_file }, /* file delete-window */
{ nhStr("dismiss_text"), dismiss_text }, /* text widget button action */
{ nhStr("delete_text"), delete_text }, /* text widget delete action */
{ nhStr("key_dismiss_text"), key_dismiss_text }, /* text key action */
@@ -1917,46 +1919,6 @@ char *input;
}
/* Display file ----------------------------------------------------------- */
static const char display_translations[] = "#override\n\
<Key>q: dismiss_file()\n\
<Key>Escape: dismiss_file()\n\
<BtnDown>: dismiss_file()";
/* WM_DELETE_WINDOW callback for file dismissal. */
/*ARGSUSED*/
static void
delete_file(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
nhUse(event);
nhUse(params);
nhUse(num_params);
nh_XtPopdown(w);
XtDestroyWidget(w);
}
/* Callback for file dismissal. */
/*ARGSUSED*/
static void
dismiss_file(w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
{
Widget popup = XtParent(w);
nhUse(event);
nhUse(params);
nhUse(num_params);
nh_XtPopdown(popup);
XtDestroyWidget(popup);
}
void
X11_display_file(str, complain)
@@ -1964,17 +1926,8 @@ const char *str;
boolean complain;
{
dlb *fp;
Arg args[12];
Cardinal num_args;
Widget popup, dispfile;
Position top_margin, bottom_margin, left_margin, right_margin;
XFontStruct *fs;
int new_width, new_height;
#define LLEN 128
char line[LLEN];
int num_lines;
char *textlines, *bp;
int charcount;
/* Use the port-independent file opener to see if the file exists. */
fp = dlb_fopen(str, RDTMODE);
@@ -1985,92 +1938,26 @@ boolean complain;
return; /* it doesn't exist, ignore */
}
/*
* Count the number of lines and characters in the file.
*/
num_lines = 0;
charcount = 1;
winid newwin = X11_create_nhwindow(NHW_MENU);
struct xwindow *wp = &window_list[newwin];
anything any = zeroany;
menu_item *menu_list;
X11_start_menu(newwin);
while (dlb_fgets(line, LLEN, fp)) {
num_lines++;
charcount += strlen(line);
X11_add_menu(newwin, NO_GLYPH, &any, 0, 0, ATR_NONE, line, MENU_UNSELECTED);
}
(void) dlb_fclose(fp);
/* Ignore empty files */
if (num_lines == 0)
return;
/* show file name as the window title */
if (str)
wp->title = dupstr(str);
/* If over the max window size, truncate the window size to the max */
if (num_lines >= DISPLAY_FILE_SIZE)
num_lines = DISPLAY_FILE_SIZE;
/*
* Re-open the file and read the data into a buffer. Cannot use
* the XawAsciiFile type of widget, because that is not DLB-aware.
*/
textlines = (char *) alloc((unsigned int) charcount);
textlines[0] = '\0';
fp = dlb_fopen(str, RDTMODE);
bp = textlines;
while (dlb_fgets(line, LLEN, fp)) {
Strcpy((bp = eos(bp)), line);
}
(void) dlb_fclose(fp);
num_args = 0;
XtSetArg(args[num_args], nhStr(XtNtitle), str); num_args++;
popup = XtCreatePopupShell("display_file", topLevelShellWidgetClass,
toplevel, args, num_args);
XtOverrideTranslations(popup,
XtParseTranslationTable("<Message>WM_PROTOCOLS: delete_file()"));
num_args = 0;
XtSetArg(args[num_args], nhStr(XtNscrollHorizontal),
XawtextScrollWhenNeeded); num_args++;
XtSetArg(args[num_args], nhStr(XtNscrollVertical), XawtextScrollAlways);
num_args++;
XtSetArg(args[num_args], nhStr(XtNtype), XawAsciiString); num_args++;
XtSetArg(args[num_args], nhStr(XtNstring), textlines); num_args++;
XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++;
XtSetArg(args[num_args], nhStr(XtNtranslations),
XtParseTranslationTable(display_translations)); num_args++;
dispfile = XtCreateManagedWidget("text", /* name */
asciiTextWidgetClass, popup, /* parent */
args, num_args);
/* Get font and border information. */
num_args = 0;
XtSetArg(args[num_args], nhStr(XtNfont), &fs); num_args++;
XtSetArg(args[num_args], nhStr(XtNtopMargin), &top_margin); num_args++;
XtSetArg(args[num_args], nhStr(XtNbottomMargin), &bottom_margin);
num_args++;
XtSetArg(args[num_args], nhStr(XtNleftMargin), &left_margin); num_args++;
XtSetArg(args[num_args], nhStr(XtNrightMargin), &right_margin);
num_args++;
XtGetValues(dispfile, args, num_args);
/*
* The data files are currently set up assuming an 80 char wide window
* and a fixed width font. Soo..
*/
new_height =
num_lines * nhFontHeight(dispfile) + top_margin + bottom_margin;
new_width = 80 * fs->max_bounds.width + left_margin + right_margin;
/* Set the new width and height. */
num_args = 0;
XtSetArg(args[num_args], XtNwidth, new_width); num_args++;
XtSetArg(args[num_args], XtNheight, new_height); num_args++;
XtSetValues(dispfile, args, num_args);
nh_XtPopup(popup, (int) XtGrabNone, (Widget) 0);
free(textlines);
wp->menu_information->permi = FALSE;
(void) X11_select_menu(newwin, PICK_NONE, &menu_list);
X11_destroy_nhwindow(newwin);
}
/* yn_function ------------------------------------------------------------ */

View File

@@ -819,6 +819,9 @@ menu_item **menu_list;
XtSetArg(args[num_args], nhStr(XtNheight), menu_info->permi_h);
num_args++;
}
if (wp->title) {
XtSetArg(args[num_args], nhStr(XtNtitle), wp->title); num_args++;
}
wp->popup = XtCreatePopupShell((window == WIN_INVEN)
? "inventory" : "menu",
(how == PICK_NONE)