-
Notifications
You must be signed in to change notification settings - Fork 0
/
Xwarn.c
96 lines (70 loc) · 2.47 KB
/
Xwarn.c
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
/*
-------------------------------------------------------------------------
OBJECT NAME: Xwarn.c
FULL NAME: Show Warning Box with Message
DESCRIPTION: CreateWarn should be called once where you initialize
your X stuff. To use just call WarnUser(ErrMsg, callBack)
INPUT: String to Display. Callback to call if user hits OK.
OUTPUT: Warning message in its own tidy little window.
AUTHOR: websterc@ncar
-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/MessageB.h>
#define nWarnings 3
static Widget warnBox[nWarnings];
static int inUse[nWarnings];
/* -------------------------------------------------------------------- */
void CancelWarning(Widget w, XtPointer clientData, XtPointer callData)
{
XtUnmanageChild(warnBox[(size_t)clientData]);
XtPopdown(XtParent(warnBox[(size_t)clientData]));
inUse[(size_t)clientData] = FALSE;
} /* END CANCELWARNING */
/* -------------------------------------------------------------------- */
void WarnUser(char str[], XtCallbackProc okCB, XtCallbackProc cancelCB)
{
size_t i;
Widget label;
Arg args[5];
XmString xStr;
for (i = 0; i < nWarnings; ++i)
if (inUse[i] == FALSE)
break;
if (i == nWarnings)
{
fprintf(stderr, "WarnUser: Out of warning boxes.\n");
i = 0;
}
inUse[i] = TRUE;
label = XmMessageBoxGetChild(warnBox[i], XmDIALOG_MESSAGE_LABEL);
xStr = XmStringCreateLocalized(str);
XtSetArg(args[0], XmNlabelString, xStr);
XtSetValues(label, args, 1);
XmStringFree(xStr);
XtRemoveAllCallbacks(warnBox[i], XmNokCallback);
XtAddCallback(warnBox[i], XmNokCallback, CancelWarning, (XtPointer)i);
XtRemoveAllCallbacks(warnBox[i], XmNcancelCallback);
XtAddCallback(warnBox[i],XmNcancelCallback,CancelWarning,(XtPointer)i);
if (okCB)
XtAddCallback(warnBox[i], XmNokCallback, (XtCallbackProc)okCB,
(XtPointer)i);
if (cancelCB)
XtAddCallback(warnBox[i], XmNcancelCallback,
(XtCallbackProc)cancelCB, (XtPointer)i);
XtManageChild(warnBox[i]);
XtPopup(XtParent(warnBox[i]), XtGrabNonexclusive);
} /* END WARNUSER */
/* -------------------------------------------------------------------- */
void CreateWarningBox(Widget parent)
{
int i;
for (i = 0; i < nWarnings; ++i) {
inUse[i] = FALSE;
warnBox[i] = XmCreateWarningDialog(parent, "warnBox", NULL, 0);
XtSetSensitive(XmMessageBoxGetChild(warnBox[i],
XmDIALOG_HELP_BUTTON), FALSE);
}
} /* END CREATEWARNINGBOX */
/* END XWARN.C */