8
enum type { CHECK, RADIO };
14
newtComponent prevButton, lastButton;
23
static void makeActive(newtComponent co);
25
static void cbDraw(newtComponent c);
26
static void cbDestroy(newtComponent co);
27
struct eventResult cbEvent(newtComponent co, struct event ev);
29
static struct componentOps cbOps = {
33
newtDefaultPlaceHandler,
34
newtDefaultMappedHandler,
37
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
38
newtComponent prevButton) {
49
co = newtCheckbox(left, top, text, initialValue, " *", NULL);
53
rb->prevButton = prevButton;
55
for (curr = co; curr; curr = rb->prevButton) {
63
newtComponent newtRadioGetCurrent(newtComponent setMember) {
64
struct checkbox * rb = setMember->data;
66
setMember = rb->lastButton;
69
while (rb && rb->value != '*') {
70
setMember = rb->prevButton;
79
char newtCheckboxGetValue(newtComponent co) {
80
struct checkbox * cb = co->data;
85
void newtCheckboxSetValue(newtComponent co, char value) {
86
struct checkbox * cb = co->data;
92
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
93
const char * seq, char * result) {
99
co = malloc(sizeof(*co));
100
cb = malloc(sizeof(struct checkbox));
106
cb->result = &cb->value;
108
cb->text = strdup(text);
109
cb->seq = strdup(seq);
112
cb->inactive = COLORSET_CHECKBOX;
113
cb->active = COLORSET_ACTCHECKBOX;
114
defValue ? (*cb->result = defValue) : (*cb->result = cb->seq[0]);
121
co->width = strwidth(text) + 4;
123
co->width = strlen(text) + 4;
132
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense) {
133
struct checkbox * cb = co->data;
136
cb->flags = newtSetFlags(cb->flags, flags, sense);
138
if (!(cb->flags & NEWT_FLAG_DISABLED))
143
newtGetrc(&row, &col);
145
newtGotorc(row, col);
148
static void cbDraw(newtComponent c) {
149
struct checkbox * cb = c->data;
151
if (c->top == -1 || !c->isMapped) return;
153
if (cb->flags & NEWT_FLAG_DISABLED) {
154
cb->inactive = NEWT_COLORSET_DISENTRY;
155
cb->active = NEWT_COLORSET_DISENTRY;
157
cb->inactive = COLORSET_CHECKBOX;
158
cb->active = COLORSET_ACTCHECKBOX;
161
newtColor(cb->inactive);
163
newtGotorc(c->top, c->left);
167
SLsmg_write_string("( ) ");
171
SLsmg_write_string("[ ] ");
178
SLsmg_write_string(cb->text);
181
newtColor(cb->active);
183
newtGotorc(c->top, c->left + 1);
184
SLsmg_write_char(*cb->result);
187
static void cbDestroy(newtComponent co) {
188
struct checkbox * cb = co->data;
196
struct eventResult cbEvent(newtComponent co, struct event ev) {
197
struct checkbox * cb = co->data;
198
struct eventResult er;
201
if (ev.when == EV_NORMAL) {
206
er.result = ER_SWALLOWED;
212
er.result = ER_SWALLOWED;
216
if (ev.u.key == ' ') {
217
if (cb->type == RADIO) {
219
} else if (cb->type == CHECK) {
220
cur = strchr(cb->seq, *cb->result);
222
*cb->result = *cb->seq;
226
*cb->result = *cb->seq;
231
er.result = ER_SWALLOWED;
234
co->callback(co, co->callbackData);
236
er.result = ER_IGNORED;
238
} else if(ev.u.key == NEWT_KEY_ENTER) {
239
er.result = ER_IGNORED;
241
er.result = ER_IGNORED;
245
if (ev.u.mouse.type == MOUSE_BUTTON_DOWN) {
246
if (cb->type == RADIO) {
248
} else if (cb->type == CHECK) {
249
cur = strchr(cb->seq, *cb->result);
251
*cb->result = *cb->seq;
255
*cb->result = *cb->seq;
260
er.result = ER_SWALLOWED;
263
co->callback(co, co->callbackData);
268
er.result = ER_IGNORED;
273
static void makeActive(newtComponent co) {
274
struct checkbox * cb = co->data;
275
struct checkbox * rb;
278
/* find the one that's turned off */
279
curr = cb->lastButton;
281
while (curr && rb->value == rb->seq[0]) {
282
curr = rb->prevButton;
283
if (curr) rb = curr->data;
286
rb->value = rb->seq[0];
289
cb->value = cb->seq[1];
293
co->callback(co, co->callbackData);