-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobeButtons.c
177 lines (151 loc) · 4.34 KB
/
probeButtons.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
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* 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.
\*************************************************************************/
/*
* $Id$
*/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/ToggleB.h>
/*
* System includes for CA
*/
#include <caerr.h>
#include <cadef.h>
#include <db_access.h>
#include <stdio.h>
#include <string.h>
#include <alarm.h>
#include "probe.h"
/*
* X's stuff
*/
extern XmFontList fontList;
extern XFontStruct *font;
extern XmFontList fontList1;
extern XFontStruct *font1;
char *stateButtonLabels[] = {
"state 0",
"state 1",
"state 2",
"state 3",
"state 4",
"state 5",
"state 6",
"state 7",
"state 8",
"state 9",
"state 10",
"state 11",
"state 12",
"state 13",
"state 14",
"state 15"};
void adjustButtonsCallback(
Widget w,
XtPointer clientData,
XtPointer callbackData)
{
short i;
atom *ch = (atom *) clientData;
XmToggleButtonCallbackStruct *callData = (XmToggleButtonCallbackStruct *) callbackData;
Buttons *b = &(ch->adjust.buttons);
if (!callData->set) return;
for (i=0; i < ch->info.data.E.no_str; i++) {
if (w == b->buttons[i]) break;
}
if (i == ch->info.data.E.no_str) {
xerrmsg("adjustButtonsCallback : buttons out of range.\n");
return;
}
b->buttonsSelected = i;
ch->updateMask |= UPDATE_DISPLAY | UPDATE_TEXT;
ch->data.E.value = i;
probeCASetValue(ch);
updateDisplay(ch);
}
void updateButtons(atom *ch, int dummy)
{
Buttons *b = &(ch->adjust.buttons);
/* Return if the dialog is not up */
if ((ch->adjust.upMask & ADJUST_BUTTONS_UP) == 0) return;
/* Return if this value is already selected */
if (b->buttonsSelected == ch->data.E.value) return;
/* Return if there are no buttons */
if(ch->info.data.E.no_str == 0) return;
/* Return if the current value is out of range */
if (ch->data.E.value >= MAX_ADJUST_BUTTONS || ch->data.E.value <= 0) {
xerrmsg("updateButtons: Enum value [%d] out of range",
ch->data.E.value);
return;
}
/* Return if there is no button defined */
if (!b->buttons[b->buttonsSelected]) {
xerrmsg("updateButtons: No button for enum value=%d",
ch->data.E.value);
return;
}
XtVaSetValues(b->buttons[b->buttonsSelected],
XmNset,False,
NULL);
XtVaSetValues(b->buttons[ch->data.E.value],
XmNset,True,
NULL);
b->buttonsSelected = ch->data.E.value;
}
void destroyButtons(atom *ch)
{
short i;
Buttons *b = &(ch->adjust.buttons);
XtUnmanageChild(b->panel);
XtDestroyWidget(b->panel);
b->panel = NULL;
for (i=0; i<MAX_ADJUST_BUTTONS; i++)
b->buttons[i] = NULL;
b->buttonsSelected = -1;
ch->d[BUTTON].w = NULL;
ch->d[BUTTON].proc = NULL;
ch->adjust.upMask &= ~ADJUST_BUTTONS_UP;
}
void createButtons(atom *ch)
{
short i, n;
Arg wargs[5];
Buttons *b = &(ch->adjust.buttons);
if ((ch->adjust.upMask & ADJUST_BUTTONS_UP)) {
xerrmsg("createButtons: Buttons not destroyed yet.\n");
return;
}
n = 0;
XtSetArg(wargs[n], XmNentryClass, xmToggleButtonWidgetClass); n++;
XtSetArg(wargs[n], XmNnumColumns, 4); n++;
b->panel = XmCreateRadioBox(ch->adjust.panel, "stateButton", wargs, n);
for (i=0; i < ch->info.data.E.no_str; i++) {
n = 0;
if (i == ch->data.E.value) {
b->buttonsSelected = i;
XtSetArg(wargs[n],XmNset,TRUE); n++;
}
if (strlen(ch->info.data.E.strs[i]) > (size_t)0) {
b->buttons[i] = XmCreateToggleButton(b->panel,
ch->info.data.E.strs[i],wargs,n);
} else {
b->buttons[i] = XmCreateToggleButton(b->panel,
stateButtonLabels[i],wargs,n);
}
XtAddCallback(b->buttons[i],
XmNvalueChangedCallback,adjustButtonsCallback,ch);
}
ch->d[BUTTON].w = b->panel;
ch->d[BUTTON].proc = updateButtons;
ch->adjust.upMask |= ADJUST_BUTTONS_UP;
XtManageChild(b->panel);
XtManageChildren(b->buttons,ch->info.data.E.no_str);
}