void newtRadioSetCurrent(newtComponent setMember) { struct checkbox * cb = setMember->data; struct checkbox * rb; newtComponent curr; /* find the one that's turned on */ curr = cb->lastButton; rb = curr->data; while (curr && rb->value == rb->seq[0]) { curr = rb->prevButton; if (curr) rb = curr->data; } if (curr) { rb->value = rb->seq[0]; cbDraw(curr); } cb->value = cb->seq[1]; cbDraw(setMember); if (setMember->callback) setMember->callback(setMember, setMember->callbackData); }
static void makeActive(newtComponent co) { struct checkbox * cb = co->data; struct checkbox * rb; newtComponent curr; /* find the one that's turned off */ curr = cb->lastButton; rb = curr->data; while (curr && rb->value == rb->seq[0]) { curr = rb->prevButton; if (curr) rb = curr->data; } if (curr) { rb->value = rb->seq[0]; cbDraw(curr); } cb->value = cb->seq[1]; cbDraw(co); if (co->callback) co->callback(co, co->callbackData); }
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense) { struct checkbox * cb = co->data; int row, col; cb->flags = newtSetFlags(cb->flags, flags, sense); if (!(cb->flags & NEWT_FLAG_DISABLED)) co->takesFocus = 1; else co->takesFocus = 0; newtGetrc(&row, &col); cbDraw(co); newtGotorc(row, col); }
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense) { struct checkbox * cb = co->data; int row, col; cb->flags = newtSetFlags(cb->flags, flags, sense); // If the flag just sets a property (eg. NEWT_FLAG_RETURNEXIT), // don't redraw, etc. as the component might be 'hidden' and not to // be drawn (eg. in a scrolled list) if (flags == NEWT_FLAG_RETURNEXIT) return; if (!(cb->flags & NEWT_FLAG_DISABLED)) co->takesFocus = 1; else co->takesFocus = 0; newtGetrc(&row, &col); cbDraw(co); newtGotorc(row, col); }
struct eventResult cbEvent(newtComponent co, struct event ev) { struct checkbox * cb = co->data; struct eventResult er; const char * cur; er.result = ER_IGNORED; if (ev.when == EV_NORMAL) { switch (ev.event) { case EV_FOCUS: cb->hasFocus = 1; cbDraw(co); er.result = ER_SWALLOWED; break; case EV_UNFOCUS: cb->hasFocus = 0; cbDraw(co); er.result = ER_SWALLOWED; break; case EV_KEYPRESS: if (ev.u.key == ' ') { if (cb->type == RADIO) { newtRadioSetCurrent(co); } else if (cb->type == CHECK) { cur = strchr(cb->seq, *cb->result); if (!cur) *cb->result = *cb->seq; else { cur++; if (! *cur) *cb->result = *cb->seq; else *cb->result = *cur; } cbDraw(co); er.result = ER_SWALLOWED; if (co->callback) co->callback(co, co->callbackData); } else { er.result = ER_IGNORED; } } else if(ev.u.key == NEWT_KEY_ENTER) { if (cb->flags & NEWT_FLAG_RETURNEXIT) er.result = ER_EXITFORM; else er.result = ER_IGNORED; } else { er.result = ER_IGNORED; } break; case EV_MOUSE: if (ev.u.mouse.type == MOUSE_BUTTON_DOWN) { if (cb->type == RADIO) { newtRadioSetCurrent(co); } else if (cb->type == CHECK) { cur = strchr(cb->seq, *cb->result); if (!cur) *cb->result = *cb->seq; else { cur++; if (! *cur) *cb->result = *cb->seq; else *cb->result = *cur; } cbDraw(co); er.result = ER_SWALLOWED; if (co->callback) co->callback(co, co->callbackData); } } } } return er; }
void newtCheckboxSetValue(newtComponent co, char value) { struct checkbox * cb = co->data; *cb->result = value; cbDraw(co); }