int active, inactive;
const void * data;
int flags;
+ int hasFocus;
};
-static void cbDrawIt(newtComponent c, int active);
static void makeActive(newtComponent co);
static void cbDraw(newtComponent c);
return cb->value;
}
+void newtCheckboxSetValue(newtComponent co, char value) {
+ struct checkbox * cb = co->data;
+
+ *cb->result = value;
+ cbDraw(co);
+}
+
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
const char * seq, char * result) {
newtComponent co;
cb->text = strdup(text);
cb->seq = strdup(seq);
cb->type = CHECK;
+ cb->hasFocus = 0;
cb->inactive = COLORSET_CHECKBOX;
cb->active = COLORSET_ACTCHECKBOX;
defValue ? (*cb->result = defValue) : (*cb->result = cb->seq[0]);
}
static void cbDraw(newtComponent c) {
- cbDrawIt(c, 0);
-}
-
-static void cbDrawIt(newtComponent c, int active) {
struct checkbox * cb = c->data;
- if (c->top == -1) return;
+ if (c->top == -1 || !c->isMapped) return;
SLsmg_set_color(cb->inactive);
SLsmg_write_string(cb->text);
- if (active)
+ if (cb->hasFocus)
SLsmg_set_color(cb->active);
newtGotorc(c->top, c->left + 1);
if (ev.when == EV_NORMAL) {
switch (ev.event) {
case EV_FOCUS:
- cbDrawIt(co, 1);
+ cb->hasFocus = 1;
+ cbDraw(co);
er.result = ER_SWALLOWED;
break;
case EV_UNFOCUS:
- cbDrawIt(co, 0);
+ cb->hasFocus = 0;
+ cbDraw(co);
er.result = ER_SWALLOWED;
break;
else
*cb->result = *cur;
}
- cbDrawIt(co, 1);
+ cbDraw(co);
er.result = ER_SWALLOWED;
+
+ if (co->callback)
+ co->callback(co, co->callbackData);
} else {
er.result = ER_IGNORED;
}
} else
er.result = ER_IGNORED;
- if (er.result == ER_SWALLOWED && co->callback)
- co->callback(co, co->callbackData);
-
return er;
}
}
if (curr) {
rb->value = rb->seq[0];
- cbDrawIt(curr, 0);
+ cbDraw(curr);
}
cb->value = cb->seq[1];
- cbDrawIt(co, 1);
+ cbDraw(co);
+
+ if (co->callback)
+ co->callback(co, co->callbackData);
}
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
const char * seq, char * result);
char newtCheckboxGetValue(newtComponent co);
+void newtCheckboxSetValue(newtComponent co, char value);
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
newtComponent prevButton);
newtComponent newtRadioGetCurrent(newtComponent setMember);