* 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
Widget form, prompt, response, okay, cancel;
Arg args[20];
Cardinal num_args;
+ Dimension owidth, cwidth;
num_args = 0;
#ifdef SPECIAL_CMAP
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) {
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);
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);
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;
XSetWMNormalHints(XtDisplay(w), XtWindow(w), hints);
XFree(hints);
}
+
+/*dialogs.c*/
-/* 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. */
(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 */
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);
&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);