1 #include <X11/Intrinsic.h>
2 #include <X11/StringDefs.h>
4 #include <X11/Xaw/Form.h>
5 #include <X11/Xaw/Label.h>
6 #include <X11/Xaw/AsciiText.h>
7 #include <X11/Xaw/Command.h>
11 #define XVCMW XtVaCreateManagedWidget
13 static int accepted, cancelled;
14 static void Accept(), Cancel(), Focus();
18 static XtActionsRec actionTable[] = {
19 {"Accept", (XtActionProc) Accept},
20 {"Cancel", (XtActionProc) Cancel},
21 {"Focus", (XtActionProc) Focus},
24 Widget InitGetString(parent, name)
28 static int first_time = 1;
29 Widget getStringWindow, form, title, edit, accept, cancel;
32 XtAppAddActions(XtWidgetToApplicationContext(parent), actionTable,
33 XtNumber(actionTable));
37 getStringWindow = XtVaCreatePopupShell(name, transientShellWidgetClass,
41 form = XVCMW("getStringForm", formWidgetClass, getStringWindow, NULL);
42 title = XVCMW("getStringTitle", labelWidgetClass, form, NULL);
43 edit = XVCMW("getStringEdit", asciiTextWidgetClass, form, NULL);
44 accept = XVCMW("getStringAccept", commandWidgetClass, form, NULL);
45 cancel = XVCMW("getStringCancel", commandWidgetClass, form, NULL);
46 XtSetKeyboardFocus(form, edit);
48 return getStringWindow;
51 int GetString(getStringWindow, label, value, pop_type, buf, len)
52 Widget getStringWindow;
62 app_con = XtWidgetToApplicationContext(getStringWindow);
63 title = XtNameToWidget(getStringWindow, "getStringForm.getStringTitle");
64 edit = XtNameToWidget(getStringWindow, "getStringForm.getStringEdit");
66 XtVaSetValues(title, XtNlabel, label, NULL);
67 XtVaSetValues(edit, XtNstring, value, NULL);
69 XtRealizeWidget(getStringWindow);
70 Popup(getStringWindow, XtGrabExclusive, pop_type);
72 accepted = cancelled = 0;
73 while (! accepted && ! cancelled) {
74 XtAppNextEvent(app_con, &event);
75 XtDispatchEvent(&event);
78 XtPopdown(getStringWindow);
84 XtVaGetValues(edit, XtNstring, (XtArgVal) &s, XtNtextSource,
85 (XtArgVal) &text_source, NULL);
86 strncpy(buf, s, len-2);
88 XawAsciiSourceFreeString(text_source);
90 return GETSTRING_ACCEPT;
93 return GETSTRING_CANCEL;
97 static void Accept(w, e, p, n)
107 static void Cancel(w, e, p, n)
117 static void Focus(w, e, p, n)
123 XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToPointerRoot,