MCPcopy Create free account
hub / github.com/NetHack/NetHack / X11_getlin

Function X11_getlin

win/X11/winX.c:1983–2064  ·  view source on GitHub ↗

ask user for a line of text */

Source from the content-addressed store, hash-verified

1981
1982/* ask user for a line of text */
1983void
1984X11_getlin(
1985 const char *question, /* prompt */
1986 char *input) /* user's input, getlin's _output_ buffer */
1987{
1988 unsigned upromptlen;
1989
1990 getline_input = input; /* used by popup actions */
1991
1992 flush_screen(1); /* tell core to make sure that map is up to date */
1993 if (!getline_popup) {
1994 Arg args[1];
1995
1996 XtSetArg(args[0], XtNallowShellResize, True);
1997
1998 getline_popup = XtCreatePopupShell("getline",
1999 transientShellWidgetClass,
2000 toplevel, args, ONE);
2001 XtOverrideTranslations(getline_popup,
2002 XtParseTranslationTable(
2003 "<Message>WM_PROTOCOLS: getline_delete()"));
2004
2005 getline_dialog = CreateDialog(getline_popup, nhStr("dialog"),
2006 done_button, abort_button);
2007
2008 XtRealizeWidget(getline_popup);
2009 XSetWMProtocols(XtDisplay(getline_popup), XtWindow(getline_popup),
2010 &wm_delete_window, 1);
2011 }
2012
2013 /* 64: make the answer widget be wide enough to hold 64 characters,
2014 or the length of the prompt string, whichever is bigger. User's
2015 response can be longer--when limit is reached, value-so-far will
2016 slide left hiding some chars at the beginning of the response but
2017 making room to type more. [Prior to 3.6.1, width wasn't specifiable
2018 and answer box always got sized to match the width of the prompt.] */
2019 upromptlen = (unsigned) strlen(question);
2020 if (upromptlen < 64)
2021 upromptlen = 64;
2022#ifdef EDIT_GETLIN
2023 /* set default answer */
2024 SetDialogResponse(getline_dialog, input, upromptlen);
2025#else
2026 /* no default answer */
2027 SetDialogResponse(getline_dialog, nhStr(""), upromptlen);
2028#endif
2029 SetDialogPrompt(getline_dialog, (String) question); /* set prompt */
2030 positionpopup(getline_popup, TRUE); /* center,bottom */
2031
2032 nh_XtPopup(getline_popup, (int) XtGrabExclusive, getline_dialog);
2033
2034 /* The callback will enable the event loop exit. */
2035 (void) x_event(EXIT_ON_EXIT);
2036
2037 /* we get here after the popup has exited;
2038 put prompt and response into the message window (and into
2039 core's dumplog history) unless play hasn't started yet */
2040 if (program_state.in_moveloop || program_state.gameover) {

Callers 1

search_menuFunction · 0.85

Calls 8

flush_screenFunction · 0.85
CreateDialogFunction · 0.85
SetDialogResponseFunction · 0.85
SetDialogPromptFunction · 0.85
positionpopupFunction · 0.85
nh_XtPopupFunction · 0.85
x_eventFunction · 0.85
plineFunction · 0.50

Tested by

no test coverage detected