X11_getlin()

Two cosmetic changes for the X11 version of the getlin() routine:
1) Make the text entry box big enough to hold 60 characters before
   sliding the beginning input off the left edge, instead of just 13,
   so that user can see much more of what is being typed;
2) Make the cancel button be a little wider, and the okay button be
   the same width as the cancel button so they look a little nicer.
This commit is contained in:
PatR
2016-01-21 23:13:49 -08:00
parent 93f7df6848
commit 2bf652dd0f
3 changed files with 41 additions and 13 deletions

View File

@@ -147,6 +147,8 @@ MacOSX: force TIMED_DELAY build option on so that 'runmode' run-time option
X11: core bug for '`' (backtick) and #terrain commands was only noticed by
X11 interface: impossible "add_menu: called before start_menu"
X11: enable a scroll bar in menu windows
X11: make the extended command menu be easier to use and look a little nicer
X11: make the getline text entry widget display a bigger text entry area
General New Features

View File

@@ -48,7 +48,13 @@
* target type" issued by 'gcc -Wwrite-strings' as used by nethack.
* (For this file, always the second parameter to XtSetArg().)
*
* $NHDT-Date: 1452594032 2016/01/12 10:20:32 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.7 $
* Modified 1/2016, Pat Rankin.
* + Added minimum width argument to SetDialogResponse() so that the
* text entry widget can be forced to wider than the default response.
* + Make 'okay' button same width as 'cancel', and both wider than
* default by a small arbitrary amount.
*
* $NHDT-Date: 1453446809 2016/01/22 07:13:29 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.8 $
*/
#ifndef SYSV
@@ -99,6 +105,7 @@ XtCallbackProc cancel_callback;
Widget form, prompt, response, okay, cancel;
Arg args[20];
Cardinal num_args;
Dimension owidth, cwidth;
num_args = 0;
#ifdef SPECIAL_CMAP
@@ -191,6 +198,8 @@ XtCallbackProc cancel_callback;
okay = XtCreateManagedWidget("okay", commandWidgetClass, form, args,
num_args);
XtAddCallback(okay, XtNcallback, okay_callback, form);
XtSetArg(args[0], XtNwidth, &owidth);
XtGetValues(okay, args, ONE);
/* Only create cancel button if there is a callback for it. */
if (cancel_callback) {
@@ -224,7 +233,18 @@ XtCallbackProc cancel_callback;
args, num_args);
XtAddCallback(cancel, XtNcallback, cancel_callback, form);
XtInstallAccelerators(response, cancel);
}
XtSetArg(args[0], XtNwidth, &cwidth);
XtGetValues(cancel, args, ONE);
/* widen the cancel button */
cwidth += 25;
XtSetArg(args[0], XtNwidth, cwidth);
XtSetValues(cancel, args, ONE);
} else
cwidth = owidth + 25;
/* make okay button same width as cancel, or widen it if no cancel */
XtSetArg(args[0], XtNwidth, cwidth);
XtSetValues(okay, args, ONE);
XtInstallAccelerators(response, okay);
XtSetKeyboardFocus(form, response);
@@ -279,18 +299,21 @@ Widget w;
return XtNewString(s);
}
#define max(a, b) (((a) > (b)) ? (a) : (b))
/* set the default reponse */
void
SetDialogResponse(w, s)
SetDialogResponse(w, s, ln)
Widget w;
String s;
unsigned ln;
{
Arg args[4];
Widget response;
XFontStruct *font;
Dimension width, nwidth, leftMargin, rightMargin;
unsigned s_len = strlen(s);
if (s_len < ln)
s_len = ln;
response = XtNameToWidget(w, "response");
XtSetArg(args[0], nhStr(XtNfont), &font);
XtSetArg(args[1], nhStr(XtNleftMargin), &leftMargin);
@@ -298,7 +321,7 @@ String s;
XtSetArg(args[3], nhStr(XtNwidth), &width);
XtGetValues(response, args, FOUR);
/* width includes margins as per Xaw documentation */
nwidth = (font->max_bounds.width * strlen(s)) + leftMargin + rightMargin;
nwidth = font->max_bounds.width * (s_len + 1) + leftMargin + rightMargin;
if (nwidth < width)
nwidth = width;
@@ -395,3 +418,5 @@ boolean bottom; /* position y on bottom? */
XSetWMNormalHints(XtDisplay(w), XtWindow(w), hints);
XFree(hints);
}
/*dialogs.c*/

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winX.c $NHDT-Date: 1432512808 2015/05/25 00:13:28 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */
/* NetHack 3.6 winX.c $NHDT-Date: 1453446819 2016/01/22 07:13:39 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.35 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -1294,7 +1294,7 @@ X11_askname()
(XtCallbackProc) 0);
SetDialogPrompt(dialog, nhStr("What is your name?")); /* set prompt */
SetDialogResponse(dialog, nhStr("")); /* set default answer */
SetDialogResponse(dialog, nhStr(""), PL_NSIZ); /* set default answer */
XtRealizeWidget(popup);
positionpopup(popup, TRUE); /* center,bottom */
@@ -1396,11 +1396,12 @@ char *input;
XtSetArg(args[0], XtNallowShellResize, True);
getline_popup = XtCreatePopupShell(
"getline", transientShellWidgetClass, toplevel, args, ONE);
XtOverrideTranslations(
getline_popup, XtParseTranslationTable(
"<Message>WM_PROTOCOLS: getline_delete()"));
getline_popup = XtCreatePopupShell("getline",
transientShellWidgetClass,
toplevel, args, ONE);
XtOverrideTranslations(getline_popup,
XtParseTranslationTable(
"<Message>WM_PROTOCOLS: getline_delete()"));
getline_dialog = CreateDialog(getline_popup, nhStr("dialog"),
done_button, abort_button);
@@ -1410,7 +1411,7 @@ char *input;
&wm_delete_window, 1);
}
SetDialogPrompt(getline_dialog, (String) question); /* set prompt */
SetDialogResponse(getline_dialog, nhStr("")); /* set default answer */
SetDialogResponse(getline_dialog, nhStr(""), 60); /* set default answer */
positionpopup(getline_popup, TRUE); /* center,bottom */
nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog);