1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Command.h>
#include "GetString.h"
#define XVCMW XtVaCreateManagedWidget
static int accepted, cancelled;
static void Accept(), Cancel(), Focus();
extern void Popup();
static XtActionsRec actionTable[] = {
{"Accept", (XtActionProc) Accept},
{"Cancel", (XtActionProc) Cancel},
{"Focus", (XtActionProc) Focus},
};
Widget InitGetString(parent, name)
Widget parent;
char *name;
{
static int first_time = 1;
Widget getStringWindow, form, title, edit, accept, cancel;
if (first_time) {
XtAppAddActions(XtWidgetToApplicationContext(parent), actionTable,
XtNumber(actionTable));
first_time = 0;
};
getStringWindow = XtVaCreatePopupShell(name, transientShellWidgetClass,
parent,
XtNinput, True,
NULL);
form = XVCMW("getStringForm", formWidgetClass, getStringWindow, NULL);
title = XVCMW("getStringTitle", labelWidgetClass, form, NULL);
edit = XVCMW("getStringEdit", asciiTextWidgetClass, form, NULL);
accept = XVCMW("getStringAccept", commandWidgetClass, form, NULL);
cancel = XVCMW("getStringCancel", commandWidgetClass, form, NULL);
XtSetKeyboardFocus(form, edit);
return getStringWindow;
}
int GetString(getStringWindow, label, value, pop_type, buf, len)
Widget getStringWindow;
String label, value;
int pop_type;
char *buf;
int len;
{
XtAppContext app_con;
Widget title, edit;
XEvent event;
app_con = XtWidgetToApplicationContext(getStringWindow);
title = XtNameToWidget(getStringWindow, "getStringForm.getStringTitle");
edit = XtNameToWidget(getStringWindow, "getStringForm.getStringEdit");
XtVaSetValues(title, XtNlabel, label, NULL);
XtVaSetValues(edit, XtNstring, value, NULL);
XtRealizeWidget(getStringWindow);
Popup(getStringWindow, XtGrabExclusive, pop_type);
accepted = cancelled = 0;
while (! accepted && ! cancelled) {
XtAppNextEvent(app_con, &event);
XtDispatchEvent(&event);
}
XtPopdown(getStringWindow);
if (accepted) {
char *s;
Widget text_source;
XtVaGetValues(edit, XtNstring, (XtArgVal) &s, XtNtextSource,
(XtArgVal) &text_source, NULL);
strncpy(buf, s, len-2);
buf[len-1] = '\0';
XawAsciiSourceFreeString(text_source);
return GETSTRING_ACCEPT;
}
else
return GETSTRING_CANCEL;
}
/* ARGSUSED */
static void Accept(w, e, p, n)
Widget w;
XEvent *e;
String *p;
Cardinal *n;
{
accepted = 1;
}
/* ARGSUSED */
static void Cancel(w, e, p, n)
Widget w;
XEvent *e;
String *p;
Cardinal *n;
{
cancelled = 1;
}
/* ARGSUSED */
static void Focus(w, e, p, n)
Widget w;
XEvent *e;
String *p;
Cardinal *n;
{
XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToPointerRoot,
CurrentTime);
}
|