-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmQuery.cc
86 lines (64 loc) · 2.44 KB
/
XmQuery.cc
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
/*
-------------------------------------------------------------------------
OBJECT NAME: XmQuery.c
FULL NAME: Show Selection Box with Message
DESCRIPTION: This routines allow you to Ask the user a question and
get the answer. During Initialization call CreateQuery().
To use, just call QueryUser(question, maxlen_of_input,
callBack to call if the OK buttonis pressed), in the
callBack procedure call ExtractAnswer().
INPUT: String to Display, and callBack for OK
OUTPUT: Question in its own tidy little window.
AUTHOR: websterc@ncar
-------------------------------------------------------------------------
*/
#include "XmQuery.h"
/* -------------------------------------------------------------------- */
static void DismissQuery(Widget w, XtPointer client, XtPointer call)
{
XtUnmanageChild((Widget)client);
XtRemoveGrab((Widget)client);
}
/* -------------------------------------------------------------------- */
void XmQuery::QueryUser(const char str[], int maxlen, void (*callBack)())
{
Widget w;
Arg args[5];
int n;
XmString xStr;
n = 0;
w = XmSelectionBoxGetChild(queryBox, XmDIALOG_SELECTION_LABEL);
xStr = XmStringCreateLtoR(const_cast<char *>(str), XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNlabelString, xStr); ++n;
XtSetValues(w, args, n);
XmStringFree(xStr);
n = 0;
w = XmSelectionBoxGetChild(queryBox, XmDIALOG_TEXT);
XtSetArg(args[n], XmNmaxLength, maxlen); ++n;
XtSetArg(args[n], XmNwidth, 0); ++n;
XtSetArg(args[n], XmNcolumns, maxlen); ++n;
XtSetValues(w, args, n);
XmTextSetString(w, const_cast<char *>(""));
XtRemoveAllCallbacks(queryBox, XmNokCallback);
XtAddCallback(queryBox, XmNokCallback, (XtCallbackProc)callBack, NULL);
XtManageChild(queryBox);
XtPopup(XtParent(queryBox), XtGrabNone);
} /* END QUERYUSER */
/* -------------------------------------------------------------------- */
XmQuery::XmQuery(Widget parent)
{
queryBox = XmCreatePromptDialog(parent, const_cast<char *>("queryBox"), NULL, 0);
XtSetSensitive(XmSelectionBoxGetChild(queryBox, XmDIALOG_HELP_BUTTON), false);
XtAddCallback(queryBox, XmNcancelCallback, DismissQuery,(XtPointer)queryBox);
} /* END CONSTRUCTOR */
/* -------------------------------------------------------------------- */
void XmQuery::ExtractAnswer(char *s)
{
Widget w;
char *a;
w = XmSelectionBoxGetChild(queryBox, XmDIALOG_TEXT);
a = XmTextGetString(w);
strcpy(s, a);
XtFree(a);
} /* END EXTRACTANSWER */
/* END XMQUERY.C */