-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbeepSevr.c
380 lines (304 loc) · 11.6 KB
/
beepSevr.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* beepSevr.c */
/************************DESCRIPTION***********************************
beepSevr.c: a popup dialog window
This file contains routines for creating beep severity dialog.
**********************************************************************/
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/LabelG.h>
#include <Xm/ToggleB.h>
#include <Xm/PanedW.h>
#include <Xm/Protocols.h>
#include <Xm/RowColumn.h>
#include <Xm/ToggleBG.h>
#include "axArea.h"
#include "alLib.h"
#include "alh.h"
#include "ax.h"
#include "alarm.h"
struct beepSevrWindow {
void *area;
Widget menuButton;
Widget beepSevrDialog;
Widget nameLabelW;
Widget nameTextW;
Widget beepSevrFrameW;
Widget beepSevrToggleButtonW[ALH_ALARM_NSEV-1];
int beepSevr;
};
extern const char * alhAlarmSeverityString[];
/* forward declarations */
static void beepSevrDismissCallback(Widget widget,XtPointer calldata,XtPointer cbs);
static void beepSevrHelpCallback(Widget widget,XtPointer calldata,XtPointer cbs);
static void beepSevrCreateDialog(ALINK*area);
static void beepSevrUpdateDialogWidgets(struct beepSevrWindow *beepSevrWindow);
static void beepSevrChangeCallback( Widget widget,XtPointer calldata,XtPointer cbs);
/******************************************************
beepSevrUpdateDialog
******************************************************/
void beepSevrUpdateDialog(area)
ALINK *area;
{
struct beepSevrWindow *beepSevrWindow;
if (!area->beepSevrWindow) return;
beepSevrWindow = (struct beepSevrWindow *)area->beepSevrWindow;
if (!beepSevrWindow->beepSevrDialog || !XtIsManaged(beepSevrWindow->beepSevrDialog)) return;
beepSevrUpdateDialogWidgets(beepSevrWindow);
}
/******************************************************
beepSevrShowDialog
******************************************************/
void beepSevrShowDialog(area, menuButton)
ALINK *area;
Widget menuButton;
{
struct beepSevrWindow *beepSevrWindow;
beepSevrWindow = (struct beepSevrWindow *)area->beepSevrWindow;
/* Dismiss Dialog */
if (beepSevrWindow && beepSevrWindow->beepSevrDialog &&
XtIsManaged(beepSevrWindow->beepSevrDialog)) {
beepSevrDismissCallback(NULL, (XtPointer)beepSevrWindow, NULL);
return;
}
/* create beepSevrWindow and Dialog Widgets if necessary */
if (!beepSevrWindow) beepSevrCreateDialog(area);
/* update beepSevrWindow */
beepSevrWindow = (struct beepSevrWindow *)area->beepSevrWindow;
beepSevrWindow->menuButton = menuButton;
/* update Dialog Widgets */
beepSevrUpdateDialogWidgets(beepSevrWindow);
/* show Dialog */
if (!beepSevrWindow->beepSevrDialog) return;
if (!XtIsManaged(beepSevrWindow->beepSevrDialog)) {
XtManageChild(beepSevrWindow->beepSevrDialog);
}
XMapWindow(XtDisplay(beepSevrWindow->beepSevrDialog),
XtWindow(XtParent(beepSevrWindow->beepSevrDialog)));
if (menuButton) XtVaSetValues(menuButton, XmNset, TRUE, NULL);
}
/******************************************************
beepSevrUpdateDialogWidgets
******************************************************/
static void beepSevrUpdateDialogWidgets(beepSevrWindow)
struct beepSevrWindow *beepSevrWindow;
{
struct gcData *pgcData;
GCLINK *link;
int i,linkType;
int beepSevr;
XmString string;
if (! beepSevrWindow || !beepSevrWindow->beepSevrDialog ) return;
link = (GCLINK *)getSelectionLinkArea(beepSevrWindow->area);
if (!link) {
string = XmStringCreateSimple("");
XtVaSetValues(beepSevrWindow->nameTextW,XmNlabelString, string, NULL);
XmStringFree(string);
return;
}
linkType = getSelectionLinkTypeArea(beepSevrWindow->area);
pgcData = link->pgcData;
/* ---------------------------------
Group/Channel Name
--------------------------------- */
if (linkType == GROUP) string = XmStringCreateSimple("Group Name:");
else string = XmStringCreateSimple("Channel Name:");
XtVaSetValues(beepSevrWindow->nameLabelW, XmNlabelString, string, NULL);
XmStringFree(string);
if (pgcData->alias){
string = XmStringCreateSimple(pgcData->alias);
} else {
string = XmStringCreateSimple(pgcData->name);
}
XtVaSetValues(beepSevrWindow->nameTextW, XmNlabelString, string, NULL);
XmStringFree(string);
/* ---------------------------------
Beep Severity
--------------------------------- */
beepSevr = pgcData->beepSevr;
if (beepSevr == 0) beepSevr=1;
for (i = 0; i < ALH_ALARM_NSEV-1; i++){
XmToggleButtonGadgetSetState(beepSevrWindow->beepSevrToggleButtonW[i], False, False);
}
XmToggleButtonGadgetSetState(beepSevrWindow->beepSevrToggleButtonW[beepSevr-1], True, False);
}
/******************************************************
beepSevrCreateDialog
******************************************************/
static void beepSevrCreateDialog(area)
ALINK *area;
{
struct beepSevrWindow *beepSevrWindow;
Widget beepSevrDialogShell, beepSevrDialog;
Widget radiobox, form, beepSevrFrameW;
Widget nameLabelW, nameTextW;
Widget beepSevrToggleButtonW[ALH_ALARM_NSEV-1];
int i;
static ActionAreaItem beepSevr_items[] = {
{ "Dismiss", beepSevrDismissCallback, NULL },
{ "Help", beepSevrHelpCallback, NULL },
};
if (!area) return;
beepSevrWindow = (struct beepSevrWindow *)area->beepSevrWindow;
if (beepSevrWindow && beepSevrWindow->beepSevrDialog){
if (XtIsManaged(beepSevrWindow->beepSevrDialog)) return;
else XtManageChild(beepSevrWindow->beepSevrDialog);
}
beepSevrWindow = (struct beepSevrWindow *)calloc(1,sizeof(struct beepSevrWindow));
area->beepSevrWindow = (void *)beepSevrWindow;
beepSevrWindow->area = (void *)area;
beepSevrDialogShell = XtVaCreatePopupShell("Set Beep Severity",
transientShellWidgetClass, area->toplevel,
XmNallowShellResize, TRUE,
NULL);
/* Modify the window manager menu "close" callback */
{
Atom WM_DELETE_WINDOW;
XtVaSetValues(beepSevrDialogShell,
XmNdeleteResponse, XmDO_NOTHING, NULL);
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(beepSevrDialogShell),
"WM_DELETE_WINDOW", False);
XmAddWMProtocolCallback(beepSevrDialogShell,WM_DELETE_WINDOW,
(XtCallbackProc)beepSevrDismissCallback, (XtPointer)beepSevrWindow);
}
beepSevrDialog = XtVaCreateWidget("beepSevrDialog",
xmPanedWindowWidgetClass, beepSevrDialogShell,
XmNallowResize, TRUE,
XmNsashWidth, 1,
XmNsashHeight, 1,
XmNuserData, area,
NULL);
form = XtVaCreateWidget("control_area",
xmFormWidgetClass, beepSevrDialog,
XmNallowResize, TRUE,
NULL);
/* ---------------------------------
Group/Channel Name
--------------------------------- */
nameLabelW = XtVaCreateManagedWidget("nameLabelW",
xmLabelGadgetClass, form,
XmNalignment, XmALIGNMENT_END,
XmNtopAttachment, XmATTACH_FORM,
/*
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 50,
*/
XmNrecomputeSize, True,
NULL);
nameTextW = XtVaCreateManagedWidget("nameTextW",
xmLabelGadgetClass, form,
XmNalignment, XmALIGNMENT_BEGINNING,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, nameLabelW,
XmNrightAttachment, XmATTACH_NONE,
XmNrecomputeSize, True,
NULL);
/* ---------------------------------
Beep Severity
--------------------------------- */
beepSevrFrameW = XtVaCreateManagedWidget("beepSevrFrameW",
xmFrameWidgetClass, form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, nameLabelW,
XmNtopOffset, 5,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 25,
NULL);
radiobox = XmCreateRadioBox (beepSevrFrameW, "radiobox", NULL, 0);
for (i = 0; i < ALH_ALARM_NSEV-1; i++){
long ii=i+1;
beepSevrToggleButtonW[i] = XmCreateToggleButtonGadget (radiobox,
(char *)alhAlarmSeverityString[i+1], NULL, 0);
XtVaSetValues(beepSevrToggleButtonW[i], XmNuserData, area, NULL);
XtAddCallback(beepSevrToggleButtonW[i], XmNvalueChangedCallback,
beepSevrChangeCallback, (XtPointer)ii);
XtManageChild(beepSevrToggleButtonW[i]);
}
XtManageChild(radiobox);
XtManageChild(form);
/* Set the client data "Apply", "Dismiss", "OK", and "Help" button's callbacks. */
beepSevr_items[0].data = (XtPointer)beepSevrWindow;
beepSevr_items[1].data = (XtPointer)beepSevrWindow;
(void)createActionButtons(beepSevrDialog, beepSevr_items, XtNumber(beepSevr_items));
beepSevrWindow->beepSevrDialog = beepSevrDialog;
beepSevrWindow->nameLabelW = nameLabelW;
beepSevrWindow->nameTextW = nameTextW;
beepSevrWindow->beepSevrFrameW = beepSevrFrameW;
for (i = 0; i < ALH_ALARM_NSEV-1; i++){
beepSevrWindow->beepSevrToggleButtonW[i] = beepSevrToggleButtonW[i];
}
XtManageChild(beepSevrDialog);
XtRealizeWidget(beepSevrDialogShell);
}
/******************************************************
beepSevrHelpCallback
******************************************************/
static void beepSevrHelpCallback(Widget widget,XtPointer calldata,XtPointer cbs)
{
char *message1 =
"Set the beep severity level for a group or channel.\n"
"\n"
"Beep severity is the minimum severity level required for beeping.\n"
"Beeping for this group or channel will not occur when the highest\n"
"unacknowledged severity is less than the specified beep severity.\n"
"\n"
"Press the Dismiss button to close the dialog window.\n"
"Press the Help button to get this help description window.\n"
" \n"
;
char * message2 = " ";
createDialog(widget,XmDIALOG_INFORMATION, message1,message2);
}
/******************************************************
beepSevrChangeCallback
******************************************************/
static void beepSevrChangeCallback(Widget widget,XtPointer calldata,XtPointer cbs)
{
int beepSevr=(long)calldata;
ALINK *area;
struct gcData *pgcData;
GCLINK *link;
int linkType;
if (!XmToggleButtonGadgetGetState(widget)) return;
XtVaGetValues(widget, XmNuserData, &area, NULL);
link =getSelectionLinkArea(area);
if (!link) return;
linkType =getSelectionLinkTypeArea(area);
if (linkType == CHANNEL) alSetBeepSevrChan((CLINK *)link,beepSevr);
if (linkType == GROUP) alSetBeepSevrGroup((GLINK *)link,beepSevr);
pgcData = link->pgcData;
alLogOpModMessage(0,link,"Beep Severity set to %s",alhAlarmSeverityString[pgcData->beepSevr]);
link->pmainGroup->modified = 1;
/* ---------------------------------
Update all dialog Windows
--------------------------------- */
axUpdateDialogs(area);
}
/******************************************************
beepSevrDismissCallback
******************************************************/
static void beepSevrDismissCallback(Widget widget,XtPointer calldata,XtPointer cbs)
{
struct beepSevrWindow *beepSevrWindow=(struct beepSevrWindow *)calldata;
Widget beepSevrDialog;
beepSevrDialog = beepSevrWindow->beepSevrDialog;
XtUnmanageChild(beepSevrDialog);
XUnmapWindow(XtDisplay(beepSevrDialog), XtWindow(XtParent(beepSevrDialog)));
if (beepSevrWindow->menuButton)
XtVaSetValues(beepSevrWindow->menuButton, XmNset, FALSE, NULL);
}