static void buttonDraw(newtComponent c);
static void buttonDestroy(newtComponent co);
static struct eventResult buttonEvent(newtComponent c,
- struct event ev);
+ struct event ev);
static void buttonPlace(newtComponent co, int newLeft, int newTop);
static struct componentOps buttonOps = {
co = malloc(sizeof(*co));
if (co == NULL)
- return NULL;
+ return NULL;
bu = malloc(sizeof(struct button));
if (bu == NULL) {
- free (co);
- return NULL;
+ free (co);
+ return NULL;
}
co->data = bu;
co->ops = &buttonOps;
if (bu->compact) {
- co->height = 1;
- co->width = width + 3;
+ co->height = 1;
+ co->width = width + 3;
} else {
- co->height = 4;
- co->width = width + 5;
+ co->height = 4;
+ co->width = width + 5;
}
co->top = row;
SLsmg_set_color(NEWT_COLORSET_BUTTON);
if (bu->compact) {
- if (active)
- SLsmg_set_color(NEWT_COLORSET_COMPACTBUTTON);
- else
- SLsmg_set_color(NEWT_COLORSET_BUTTON);
- newtGotorc(co->top+ pushed, co->left + 1 + pushed);
- SLsmg_write_char('<');
- SLsmg_write_string(bu->text);
- SLsmg_write_char('>');
+ if (active)
+ SLsmg_set_color(NEWT_COLORSET_COMPACTBUTTON);
+ else
+ SLsmg_set_color(NEWT_COLORSET_BUTTON);
+ newtGotorc(co->top+ pushed, co->left + 1 + pushed);
+ SLsmg_write_char('<');
+ SLsmg_write_string(bu->text);
+ SLsmg_write_char('>');
} else {
- if (pushed) {
- SLsmg_set_color(NEWT_COLORSET_BUTTON);
- newtDrawBox(co->left + 1, co->top + 1, co->width - 1, 3, 0);
-
- SLsmg_set_color(NEWT_COLORSET_WINDOW);
- newtClearBox(co->left, co->top, co->width, 1);
- newtClearBox(co->left, co->top, 1, co->height);
- } else {
- newtDrawBox(co->left, co->top, co->width - 1, 3, 1);
- }
-
- buttonDrawText(co, active, pushed);
+ if (pushed) {
+ SLsmg_set_color(NEWT_COLORSET_BUTTON);
+ newtDrawBox(co->left + 1, co->top + 1, co->width - 1, 3, 0);
+
+ SLsmg_set_color(NEWT_COLORSET_WINDOW);
+ newtClearBox(co->left, co->top, co->width, 1);
+ newtClearBox(co->left, co->top, 1, co->height);
+ } else {
+ newtDrawBox(co->left, co->top, co->width - 1, 3, 1);
+ }
+
+ buttonDrawText(co, active, pushed);
}
}
if (pushed) pushed = 1;
if (active)
- SLsmg_set_color(NEWT_COLORSET_ACTBUTTON);
+ SLsmg_set_color(NEWT_COLORSET_ACTBUTTON);
else
- SLsmg_set_color(NEWT_COLORSET_BUTTON);
+ SLsmg_set_color(NEWT_COLORSET_BUTTON);
newtGotorc(co->top + 1 + pushed, co->left + 1 + pushed);
SLsmg_write_char(' ');
}
static struct eventResult buttonEvent(newtComponent co,
- struct event ev) {
+ struct event ev) {
struct eventResult er;
struct button * bu = co->data;
if (ev.when == EV_NORMAL) {
- switch (ev.event) {
- case EV_FOCUS:
- buttonDrawIt(co, 1, 0);
- er.result = ER_SWALLOWED;
- break;
-
- case EV_UNFOCUS:
- buttonDrawIt(co, 0, 0);
- er.result = ER_SWALLOWED;
- break;
-
- case EV_KEYPRESS:
- if (ev.u.key == ' ' || ev.u.key == '\r') {
- if (!bu->compact) {
- /* look pushed */
- buttonDrawIt(co, 1, 1);
- newtRefresh();
- newtDelay(150000);
- buttonDrawIt(co, 1, 0);
- newtRefresh();
- newtDelay(150000);
- }
-
- er.result = ER_EXITFORM;
- } else
- er.result = ER_IGNORED;
- break;
- case EV_MOUSE:
- if (ev.u.mouse.type == MOUSE_BUTTON_DOWN &&
- co->top <= ev.u.mouse.y &&
- co->top + co->height - !bu->compact > ev.u.mouse.y &&
- co->left <= ev.u.mouse.x &&
- co->left + co->width - !bu->compact > ev.u.mouse.x) {
- if (!bu->compact) {
- buttonDrawIt(co, 1, 1);
- newtRefresh();
- newtDelay(150000);
- buttonDrawIt(co, 1, 0);
- newtRefresh();
- newtDelay(150000);
- }
- er.result = ER_EXITFORM;
- }
- break;
- }
+ switch (ev.event) {
+ case EV_FOCUS:
+ buttonDrawIt(co, 1, 0);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case EV_UNFOCUS:
+ buttonDrawIt(co, 0, 0);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case EV_KEYPRESS:
+ if (ev.u.key == ' ' || ev.u.key == '\r') {
+ if (!bu->compact) {
+ /* look pushed */
+ buttonDrawIt(co, 1, 1);
+ newtRefresh();
+ newtDelay(150000);
+ buttonDrawIt(co, 1, 0);
+ newtRefresh();
+ newtDelay(150000);
+ }
+
+ er.result = ER_EXITFORM;
+ } else
+ er.result = ER_IGNORED;
+ break;
+ case EV_MOUSE:
+ if (ev.u.mouse.type == MOUSE_BUTTON_DOWN &&
+ co->top <= ev.u.mouse.y &&
+ co->top + co->height - !bu->compact > ev.u.mouse.y &&
+ co->left <= ev.u.mouse.x &&
+ co->left + co->width - !bu->compact > ev.u.mouse.x) {
+ if (!bu->compact) {
+ buttonDrawIt(co, 1, 1);
+ newtRefresh();
+ newtDelay(150000);
+ buttonDrawIt(co, 1, 0);
+ newtRefresh();
+ newtDelay(150000);
+ }
+ er.result = ER_EXITFORM;
+ }
+ break;
+ }
} else
- er.result = ER_IGNORED;
+ er.result = ER_IGNORED;
return er;
}
newtGrid newtButtonBarv(char * button1, newtComponent * b1comp, va_list args) {
newtGrid grid;
struct buttonInfo {
- char * name;
- newtComponent * compPtr;
+ char * name;
+ newtComponent * compPtr;
} buttons[50];
int num;
int i;
buttons[0].name = button1, buttons[0].compPtr = b1comp, num = 1;
while (1) {
- buttons[num].name = va_arg(args, char *);
- if (!buttons[num].name) break;
- buttons[num].compPtr = va_arg(args, newtComponent *);
- num++;
+ buttons[num].name = va_arg(args, char *);
+ if (!buttons[num].name) break;
+ buttons[num].compPtr = va_arg(args, newtComponent *);
+ num++;
}
grid = newtCreateGrid(num, 1);
for (i = 0; i < num; i++) {
- *buttons[i].compPtr = newtButton(-1, -1, buttons[i].name);
- newtGridSetField(grid, i, 0, NEWT_GRID_COMPONENT,
- *buttons[i].compPtr,
- num ? 1 : 0, 0, 0, 0, 0, 0);
+ *buttons[i].compPtr = newtButton(-1, -1, buttons[i].name);
+ newtGridSetField(grid, i, 0, NEWT_GRID_COMPONENT,
+ *buttons[i].compPtr,
+ num ? 1 : 0, 0, 0, 0, 0, 0);
}
return grid;
} ;
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
- newtComponent prevButton) {
+ newtComponent prevButton) {
newtComponent co;
newtComponent curr;
struct checkbox * rb;
char initialValue;
if (isDefault)
- initialValue = '*';
+ initialValue = '*';
else
- initialValue = ' ';
+ initialValue = ' ';
co = newtCheckbox(left, top, text, initialValue, " *", NULL);
rb = co->data;
rb->prevButton = prevButton;
for (curr = co; curr; curr = rb->prevButton) {
- rb = curr->data;
- rb->lastButton = co;
+ rb = curr->data;
+ rb->lastButton = co;
}
return co;
rb = setMember->data;
while (rb && rb->value != '*') {
- setMember = rb->prevButton;
- if (!setMember)
- return NULL;
- rb = setMember->data;
+ setMember = rb->prevButton;
+ if (!setMember)
+ return NULL;
+ rb = setMember->data;
}
return setMember;
* FIXME: Check all calls.
*/
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
- const char * seq, char * result) {
+ const char * seq, char * result) {
newtComponent co;
struct checkbox * cb;
co = malloc(sizeof(*co));
if (co == NULL)
- return NULL;
+ return NULL;
cb = malloc(sizeof(struct checkbox));
if (cb == NULL) {
- free(co);
- return NULL;
+ free(co);
+ return NULL;
}
co->data = cb;
cb->flags = 0;
if (result)
- cb->result = result;
+ cb->result = result;
else
- cb->result = &cb->value;
+ cb->result = &cb->value;
cb->text = strdup(text);
cb->seq = strdup(seq);
cb->flags = newtSetFlags(cb->flags, flags, sense);
if (!(cb->flags & NEWT_FLAG_DISABLED))
- co->takesFocus = 1;
+ co->takesFocus = 1;
else
- co->takesFocus = 0;
+ co->takesFocus = 0;
newtGetrc(&row, &col);
cbDraw(co);
if (c->top == -1 || !c->isMapped) return;
if (cb->flags & NEWT_FLAG_DISABLED) {
- cb->inactive = NEWT_COLORSET_DISENTRY;
- cb->active = NEWT_COLORSET_DISENTRY;
+ cb->inactive = NEWT_COLORSET_DISENTRY;
+ cb->active = NEWT_COLORSET_DISENTRY;
} else {
- cb->inactive = COLORSET_CHECKBOX;
- cb->active = COLORSET_ACTCHECKBOX;
+ cb->inactive = COLORSET_CHECKBOX;
+ cb->active = COLORSET_ACTCHECKBOX;
}
SLsmg_set_color(cb->inactive);
switch (cb->type) {
case RADIO:
- SLsmg_write_string("( ) ");
- break;
+ SLsmg_write_string("( ) ");
+ break;
case CHECK:
- SLsmg_write_string("[ ] ");
- break;
+ SLsmg_write_string("[ ] ");
+ break;
default:
- break;
+ break;
}
SLsmg_write_string(cb->text);
if (cb->hasFocus)
- SLsmg_set_color(cb->active);
+ SLsmg_set_color(cb->active);
newtGotorc(c->top, c->left + 1);
SLsmg_write_char(*cb->result);
const char * cur;
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) {
- makeActive(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) {
- 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) {
- makeActive(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);
- }
- }
- }
+ 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) {
+ makeActive(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) {
+ 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) {
+ makeActive(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;
+ er.result = ER_IGNORED;
return er;
}
curr = cb->lastButton;
rb = curr->data;
while (curr && rb->value == rb->seq[0]) {
- curr = rb->prevButton;
- if (curr) rb = curr->data;
+ curr = rb->prevButton;
+ if (curr) rb = curr->data;
}
if (curr) {
- rb->value = rb->seq[0];
- cbDraw(curr);
+ rb->value = rb->seq[0];
+ cbDraw(curr);
}
cb->value = cb->seq[1];
cbDraw(co);
if (co->callback)
- co->callback(co, co->callbackData);
+ co->callback(co, co->callbackData);
}
enum countWhat { COUNT_EXPOSED=0, COUNT_SELECTED=1 };
static int countItems(struct items * item, enum countWhat justExposed);
static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
- int maxField);
+ int maxField);
static struct componentOps ctOps = {
ctDraw,
} ;
static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
- int maxField) {
+ int maxField) {
ct->curWidth = maxField;
co->width = ct->curWidth + ct->sbAdjust;
if (ct->sb)
- ct->sb->left = co->left + co->width - 1;
+ ct->sb->left = co->left + co->width - 1;
}
static int countItems(struct items * item, enum countWhat what) {
while (item) {
if ((!item->branch && item->selected == what) || (what == COUNT_EXPOSED))
- count++;
- if (item->branch || (what == COUNT_EXPOSED && item->selected))
- count += countItems(item->branch, what);
- item = item->next;
+ count++;
+ if (item->branch || (what == COUNT_EXPOSED && item->selected))
+ count += countItems(item->branch, what);
+ item = item->next;
}
return count;
static void doBuildFlatList(struct CheckboxTree * ct, struct items * item) {
while (item) {
- ct->flatList[ct->flatCount++] = item;
- if (item->branch && item->selected) doBuildFlatList(ct, item->branch);
- item = item->next;
+ ct->flatList[ct->flatCount++] = item;
+ if (item->branch && item->selected) doBuildFlatList(ct, item->branch);
+ item = item->next;
}
}
}
int newtCheckboxTreeAddItem(newtComponent co,
- const char * text, const void * data,
- int flags, int index, ...) {
+ const char * text, const void * data,
+ int flags, int index, ...) {
va_list argList;
int numIndexes;
int * indexes;
numIndexes = 0;
i = index;
while (i != NEWT_ARG_LAST) {
- numIndexes++;
- i = va_arg(argList, int);
+ numIndexes++;
+ i = va_arg(argList, int);
}
va_end(argList);
i = index;
va_start(argList, index);
while (i != NEWT_ARG_LAST) {
- indexes[numIndexes++] = i;
- i = va_arg(argList, int);
+ indexes[numIndexes++] = i;
+ i = va_arg(argList, int);
}
va_end(argList);
}
static int doFindItemPath(struct items * items, void * data, int * path,
- int * len) {
+ int * len) {
int where = 0;
while (items) {
- if (items->data == data) {
- if (path) path[items->depth] = where;
- if (len) *len = items->depth + 1;
- return 1;
- }
-
- if (items->branch && doFindItemPath(items->branch, data, path, len)) {
- if (path) path[items->depth] = where;
- return 1;
- }
-
- items = items->next;
- where++;
+ if (items->data == data) {
+ if (path) path[items->depth] = where;
+ if (len) *len = items->depth + 1;
+ return 1;
+ }
+
+ if (items->branch && doFindItemPath(items->branch, data, path, len)) {
+ if (path) path[items->depth] = where;
+ return 1;
+ }
+
+ items = items->next;
+ where++;
}
return 0;
}
int newtCheckboxTreeAddArray(newtComponent co,
- const char * text, const void * data,
- int flags, int * indexes) {
+ const char * text, const void * data,
+ int flags, int * indexes) {
struct items * curList, * newNode, * item = NULL;
struct items ** listPtr = NULL;
int i, index, numIndexes, width;
while (indexes[numIndexes] != NEWT_ARG_LAST) numIndexes++;
if (!ct->itemlist) {
- if (numIndexes > 1) return -1;
+ if (numIndexes > 1) return -1;
- ct->itemlist = malloc(sizeof(*ct->itemlist)); // FIXME: Error check?
- item = ct->itemlist;
- item->prev = NULL;
- item->next = NULL;
+ ct->itemlist = malloc(sizeof(*ct->itemlist)); // FIXME: Error check?
+ item = ct->itemlist;
+ item->prev = NULL;
+ item->next = NULL;
} else {
- curList = ct->itemlist;
- listPtr = &ct->itemlist;
-
- i = 0;
- index = indexes[i];
- while (i < numIndexes) {
- item = curList;
-
- if (index == NEWT_ARG_APPEND) {
- item = NULL;
- } else {
- while (index && item)
- item = item->next, index--;
- }
-
- i++;
- if (i < numIndexes) {
- curList = item->branch;
- listPtr = &item->branch;
- if (!curList && (i + 1 != numIndexes)) return -1;
-
- index = indexes[i];
- }
- }
-
- if (!curList) { /* create a new branch */
- item = malloc(sizeof(*curList->prev));
- item->next = item->prev = NULL;
- *listPtr = item;
- } else if (!item) { /* append to end */
- item = curList;
- while (item->next) item = item->next;
- item->next = malloc(sizeof(*curList->prev)); // FIXME Error check
- item->next->prev = item;
- item = item->next;
- item->next = NULL;
- } else {
- newNode = malloc(sizeof(*newNode)); // FIXME Error check ?
- newNode->prev = item->prev;
- newNode->next = item;
-
- if (item->prev) item->prev->next = newNode;
- item->prev = newNode;
- item = newNode;
- if (!item->prev) *listPtr = item;
- }
+ curList = ct->itemlist;
+ listPtr = &ct->itemlist;
+
+ i = 0;
+ index = indexes[i];
+ while (i < numIndexes) {
+ item = curList;
+
+ if (index == NEWT_ARG_APPEND) {
+ item = NULL;
+ } else {
+ while (index && item)
+ item = item->next, index--;
+ }
+
+ i++;
+ if (i < numIndexes) {
+ curList = item->branch;
+ listPtr = &item->branch;
+ if (!curList && (i + 1 != numIndexes)) return -1;
+
+ index = indexes[i];
+ }
+ }
+
+ if (!curList) { /* create a new branch */
+ item = malloc(sizeof(*curList->prev));
+ item->next = item->prev = NULL;
+ *listPtr = item;
+ } else if (!item) { /* append to end */
+ item = curList;
+ while (item->next) item = item->next;
+ item->next = malloc(sizeof(*curList->prev)); // FIXME Error check
+ item->next->prev = item;
+ item = item->next;
+ item->next = NULL;
+ } else {
+ newNode = malloc(sizeof(*newNode)); // FIXME Error check ?
+ newNode->prev = item->prev;
+ newNode->next = item;
+
+ if (item->prev) item->prev->next = newNode;
+ item->prev = newNode;
+ item = newNode;
+ if (!item->prev) *listPtr = item;
+ }
}
-
+
item->text = strdup(text);
item->data = data;
if (flags & NEWT_FLAG_SELECTED) {
- item->selected = 1;
+ item->selected = 1;
} else {
- item->selected = 0;
+ item->selected = 0;
}
item->flags = flags;
item->branch = NULL;
width = wstrlen(text, -1);
if ((ct->userHasSetWidth == 0) && ((width + i + ct->sbAdjust) > co->width)) {
- updateWidth(co, ct, width + i);
+ updateWidth(co, ct, width + i);
}
return 0;
struct items * i;
while (items) {
- if (items->data == data) return items;
- if (items->branch) {
- i = findItem(items->branch, data);
- if (i) return i;
- }
+ if (items->data == data) return items;
+ if (items->branch) {
+ i = findItem(items->branch, data);
+ if (i) return i;
+ }
- items = items->next;
+ items = items->next;
}
return NULL;
static void listSelected(struct items * items, int * num, const void ** list, int seqindex) {
while (items) {
- if ((seqindex ? items->selected==seqindex : items->selected) && !items->branch)
- list[(*num)++] = (void *) items->data;
- if (items->branch)
- listSelected(items->branch, num, list, seqindex);
- items = items->next;
+ if ((seqindex ? items->selected==seqindex : items->selected) && !items->branch)
+ list[(*num)++] = (void *) items->data;
+ if (items->branch)
+ listSelected(items->branch, num, list, seqindex);
+ items = items->next;
}
}
if(!co || !numitems) return NULL;
ct = co->data;
-
+
if (seqnum) {
- while( ct->seq[seqindex] && ( ct->seq[seqindex] != seqnum )) seqindex++;
+ while( ct->seq[seqindex] && ( ct->seq[seqindex] != seqnum )) seqindex++;
} else {
- seqindex = 0;
+ seqindex = 0;
}
*numitems = countItems(ct->itemlist, (seqindex ? seqindex : COUNT_SELECTED));
}
newtComponent newtCheckboxTree(int left, int top, int height, int flags) {
- return newtCheckboxTreeMulti(left, top, height, NULL, flags);
+ return newtCheckboxTreeMulti(left, top, height, NULL, flags);
}
newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, int flags) {
ct->flags = flags;
if (seq)
- ct->seq = strdup(seq);
+ ct->seq = strdup(seq);
else
- ct->seq = strdup(" *");
+ ct->seq = strdup(" *");
if (flags & NEWT_FLAG_SCROLL) {
- ct->sb = newtVerticalScrollbar(left, top, height,
- COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
- ct->sbAdjust = 2;
+ ct->sb = newtVerticalScrollbar(left, top, height,
+ COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
+ ct->sbAdjust = 2;
} else {
- ct->sb = NULL;
- ct->sbAdjust = 0;
+ ct->sb = NULL;
+ ct->sbAdjust = 0;
}
return co;
co->isMapped = isMapped;
if (ct->sb)
- ct->sb->ops->mapped(ct->sb, isMapped);
+ ct->sb->ops->mapped(ct->sb, isMapped);
}
static void ctPlace(newtComponent co, int newLeft, int newTop) {
co->left = newLeft;
if (ct->sb)
- ct->sb->ops->place(ct->sb, co->left + co->width - 1, co->top);
+ ct->sb->ops->place(ct->sb, co->left + co->width - 1, co->top);
}
int ctSetItem(newtComponent co, struct items *item, enum newtFlagsSense sense)
struct items * firstItem;
if (!item)
- return 1;
+ return 1;
switch(sense) {
- case NEWT_FLAGS_RESET:
- item->selected = 0;
- break;
- case NEWT_FLAGS_SET:
- item->selected = 1;
- break;
- case NEWT_FLAGS_TOGGLE:
- if (item->branch)
- item->selected = !item->selected;
- else if (!(ct->flags & NEWT_CHECKBOXTREE_UNSELECTABLE)) {
- item->selected++;
- if (item->selected==strlen(ct->seq))
- item->selected = 0;
- }
- break;
+ case NEWT_FLAGS_RESET:
+ item->selected = 0;
+ break;
+ case NEWT_FLAGS_SET:
+ item->selected = 1;
+ break;
+ case NEWT_FLAGS_TOGGLE:
+ if (item->branch)
+ item->selected = !item->selected;
+ else if (!(ct->flags & NEWT_CHECKBOXTREE_UNSELECTABLE)) {
+ item->selected++;
+ if (item->selected==strlen(ct->seq))
+ item->selected = 0;
+ }
+ break;
}
if (item->branch) {
- currItem = *ct->currItem;
- firstItem = *ct->firstItem;
+ currItem = *ct->currItem;
+ firstItem = *ct->firstItem;
- buildFlatList(co);
+ buildFlatList(co);
- ct->currItem = ct->flatList;
- while (*ct->currItem != currItem) ct->currItem++;
+ ct->currItem = ct->flatList;
+ while (*ct->currItem != currItem) ct->currItem++;
- ct->firstItem = ct->flatList;
- if (ct->flatCount > co->height) {
- struct items ** last = ct->flatList + ct->flatCount - co->height;
- while (*ct->firstItem != firstItem && ct->firstItem != last)
- ct->firstItem++;
- }
+ ct->firstItem = ct->flatList;
+ if (ct->flatCount > co->height) {
+ struct items ** last = ct->flatList + ct->flatCount - co->height;
+ while (*ct->firstItem != firstItem && ct->firstItem != last)
+ ct->firstItem++;
+ }
}
return 0;
static void ctSetItems(struct items *item, int selected)
{
for (; item; item = item->next) {
- if (!item->branch)
- item->selected = selected;
- else
- ctSetItems(item->branch, selected);
+ if (!item->branch)
+ item->selected = selected;
+ else
+ ctSetItems(item->branch, selected);
}
}
if (!co->isMapped) return ;
if (!ct->firstItem) {
- buildFlatList(co);
- ct->firstItem = ct->currItem = ct->flatList;
+ buildFlatList(co);
+ ct->firstItem = ct->currItem = ct->flatList;
}
item = ct->firstItem;
newtTrashScreen();
while (*item && i < co->height) {
- newtGotorc(co->top + i, co->left);
- if (*item == *ct->currItem) {
- SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
- currRow = co->top + i;
- } else
- SLsmg_set_color(NEWT_COLORSET_LISTBOX);
-
- for (j = 0; j < (*item)->depth; j++)
- SLsmg_write_string(" ");
-
- if ((*item)->branch) {
- if ((*item)->selected)
- SLsmg_write_string("<-> ");
- else
- SLsmg_write_string("<+> ");
- } else {
- if (ct->flags & NEWT_CHECKBOXTREE_HIDE_BOX) {
- if ((*item)->selected)
- SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
- SLsmg_write_string(" ");
- } else {
- char tmp[5];
- snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]);
- SLsmg_write_string(tmp);
- }
- }
-
- SLsmg_write_nstring((*item)->text, co->width - 4 -
- (3 * (*item)->depth));
-
- SLsmg_set_color(NEWT_COLORSET_LISTBOX);
-
- item++;
- i++;
+ newtGotorc(co->top + i, co->left);
+ if (*item == *ct->currItem) {
+ SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
+ currRow = co->top + i;
+ } else
+ SLsmg_set_color(NEWT_COLORSET_LISTBOX);
+
+ for (j = 0; j < (*item)->depth; j++)
+ SLsmg_write_string(" ");
+
+ if ((*item)->branch) {
+ if ((*item)->selected)
+ SLsmg_write_string("<-> ");
+ else
+ SLsmg_write_string("<+> ");
+ } else {
+ if (ct->flags & NEWT_CHECKBOXTREE_HIDE_BOX) {
+ if ((*item)->selected)
+ SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
+ SLsmg_write_string(" ");
+ } else {
+ char tmp[5];
+ snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]);
+ SLsmg_write_string(tmp);
+ }
+ }
+
+ SLsmg_write_nstring((*item)->text, co->width - 4 -
+ (3 * (*item)->depth));
+
+ SLsmg_set_color(NEWT_COLORSET_LISTBOX);
+
+ item++;
+ i++;
}
/* There could be empty lines left (i.e. if the user closes an expanded
list which is the last thing in the tree, and whose elements are
displayed at the bottom of the screen */
if (i < co->height) {
- spaces = alloca(co->width);
- memset(spaces, ' ', co->width);
- SLsmg_set_color(NEWT_COLORSET_LISTBOX);
+ spaces = alloca(co->width);
+ memset(spaces, ' ', co->width);
+ SLsmg_set_color(NEWT_COLORSET_LISTBOX);
}
while (i < co->height) {
- newtGotorc(co->top + i, co->left);
- SLsmg_write_nstring(spaces, co->width);
- i++;
+ newtGotorc(co->top + i, co->left);
+ SLsmg_write_nstring(spaces, co->width);
+ i++;
}
if(ct->sb) {
- newtScrollbarSet(ct->sb, ct->currItem - ct->flatList,
- ct->flatCount - 1);
- ct->sb->ops->draw(ct->sb);
+ newtScrollbarSet(ct->sb, ct->currItem - ct->flatList,
+ ct->flatCount - 1);
+ ct->sb->ops->draw(ct->sb);
}
newtGotorc(currRow, co->left + 1);
nextitem = item = ct->itemlist;
while (item != NULL) {
- nextitem = item->next;
- free(item->text);
- free(item);
- item = nextitem;
+ nextitem = item->next;
+ free(item->text);
+ free(item);
+ item = nextitem;
}
free(ct->seq);
er.result = ER_IGNORED;
if(ev.when == EV_EARLY || ev.when == EV_LATE) {
- return er;
+ return er;
}
switch(ev.event) {
case EV_KEYPRESS:
- key = ev.u.key;
- if (key == (char) key && key != ' ') {
- for (selnum = 0; ct->seq[selnum]; selnum++)
- if (key == ct->seq[selnum])
- break;
- if (!ct->seq[selnum])
- switch (key) {
- case '-': selnum = 0; break;
- case '+':
- case '*': selnum = 1; break;
- }
- if (ct->seq[selnum])
- key = '*';
- }
- switch(key) {
- case ' ':
- case NEWT_KEY_ENTER:
- ctSetItem(co, *ct->currItem, NEWT_FLAGS_TOGGLE);
- er.result = ER_SWALLOWED;
- if (!(*ct->currItem)->branch || (*ct->currItem)->selected)
- key = NEWT_KEY_DOWN;
- else
- key = '*';
- break;
- case '*':
- if ((*ct->currItem)->branch) {
- ctSetItems((*ct->currItem)->branch, selnum);
- if (!(*ct->currItem)->selected)
- key = NEWT_KEY_DOWN;
- } else {
- (*ct->currItem)->selected = selnum;
- key = NEWT_KEY_DOWN;
- }
- er.result = ER_SWALLOWED;
- break;
- }
- switch (key) {
- case '*':
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- return er;
- case NEWT_KEY_HOME:
- ct->currItem = ct->flatList;
- ct->firstItem = ct->flatList;
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- return er;
- case NEWT_KEY_END:
- ct->currItem = ct->flatList + ct->flatCount - 1;
- if (ct->flatCount <= co->height)
- ct->firstItem = ct->flatList;
- else
- ct->firstItem = ct->flatList + ct->flatCount - co->height;
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- return er;
- case NEWT_KEY_DOWN:
- if (ev.u.key != NEWT_KEY_DOWN) {
- if(co->callback) co->callback(co, co->callbackData);
- if (strlen(ct->seq) != 2) {
- ctDraw(co);
- return er;
- }
- }
- if ((ct->currItem - ct->flatList + 1) < ct->flatCount) {
- ct->currItem++;
-
- if (ct->currItem - ct->firstItem >= co->height)
- ct->firstItem++;
-
- ctDraw(co);
- } else if (ev.u.key != NEWT_KEY_DOWN)
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- return er;
- case NEWT_KEY_UP:
- if (ct->currItem != ct->flatList) {
- ct->currItem--;
-
- if (ct->currItem < ct->firstItem)
- ct->firstItem = ct->currItem;
-
- ctDraw(co);
- }
- er.result = ER_SWALLOWED;
- if(co->callback) co->callback(co, co->callbackData);
- return er;
- case NEWT_KEY_PGUP:
- if (ct->firstItem - co->height < ct->flatList) {
- ct->firstItem = ct->currItem = ct->flatList;
- } else {
- ct->currItem -= co->height;
- ct->firstItem -= co->height;
- }
-
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- return er;
- case NEWT_KEY_PGDN:
- listEnd = ct->flatList + ct->flatCount - 1;
- lastItem = ct->firstItem + co->height - 1;
-
- if (lastItem + co->height > listEnd) {
- ct->firstItem = listEnd - co->height + 1;
- ct->currItem = listEnd;
- } else {
- ct->currItem += co->height;
- ct->firstItem += co->height;
- }
-
- ctDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- return er;
- }
- break;
+ key = ev.u.key;
+ if (key == (char) key && key != ' ') {
+ for (selnum = 0; ct->seq[selnum]; selnum++)
+ if (key == ct->seq[selnum])
+ break;
+ if (!ct->seq[selnum])
+ switch (key) {
+ case '-': selnum = 0; break;
+ case '+':
+ case '*': selnum = 1; break;
+ }
+ if (ct->seq[selnum])
+ key = '*';
+ }
+ switch(key) {
+ case ' ':
+ case NEWT_KEY_ENTER:
+ ctSetItem(co, *ct->currItem, NEWT_FLAGS_TOGGLE);
+ er.result = ER_SWALLOWED;
+ if (!(*ct->currItem)->branch || (*ct->currItem)->selected)
+ key = NEWT_KEY_DOWN;
+ else
+ key = '*';
+ break;
+ case '*':
+ if ((*ct->currItem)->branch) {
+ ctSetItems((*ct->currItem)->branch, selnum);
+ if (!(*ct->currItem)->selected)
+ key = NEWT_KEY_DOWN;
+ } else {
+ (*ct->currItem)->selected = selnum;
+ key = NEWT_KEY_DOWN;
+ }
+ er.result = ER_SWALLOWED;
+ break;
+ }
+ switch (key) {
+ case '*':
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ return er;
+ case NEWT_KEY_HOME:
+ ct->currItem = ct->flatList;
+ ct->firstItem = ct->flatList;
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ return er;
+ case NEWT_KEY_END:
+ ct->currItem = ct->flatList + ct->flatCount - 1;
+ if (ct->flatCount <= co->height)
+ ct->firstItem = ct->flatList;
+ else
+ ct->firstItem = ct->flatList + ct->flatCount - co->height;
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ return er;
+ case NEWT_KEY_DOWN:
+ if (ev.u.key != NEWT_KEY_DOWN) {
+ if(co->callback) co->callback(co, co->callbackData);
+ if (strlen(ct->seq) != 2) {
+ ctDraw(co);
+ return er;
+ }
+ }
+ if ((ct->currItem - ct->flatList + 1) < ct->flatCount) {
+ ct->currItem++;
+
+ if (ct->currItem - ct->firstItem >= co->height)
+ ct->firstItem++;
+
+ ctDraw(co);
+ } else if (ev.u.key != NEWT_KEY_DOWN)
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ return er;
+ case NEWT_KEY_UP:
+ if (ct->currItem != ct->flatList) {
+ ct->currItem--;
+
+ if (ct->currItem < ct->firstItem)
+ ct->firstItem = ct->currItem;
+
+ ctDraw(co);
+ }
+ er.result = ER_SWALLOWED;
+ if(co->callback) co->callback(co, co->callbackData);
+ return er;
+ case NEWT_KEY_PGUP:
+ if (ct->firstItem - co->height < ct->flatList) {
+ ct->firstItem = ct->currItem = ct->flatList;
+ } else {
+ ct->currItem -= co->height;
+ ct->firstItem -= co->height;
+ }
+
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ return er;
+ case NEWT_KEY_PGDN:
+ listEnd = ct->flatList + ct->flatCount - 1;
+ lastItem = ct->firstItem + co->height - 1;
+
+ if (lastItem + co->height > listEnd) {
+ ct->firstItem = listEnd - co->height + 1;
+ ct->currItem = listEnd;
+ } else {
+ ct->currItem += co->height;
+ ct->firstItem += co->height;
+ }
+
+ ctDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ return er;
+ }
+ break;
case EV_FOCUS:
- ctDraw(co);
- er.result = ER_SWALLOWED;
- break;
-
+ ctDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
+
case EV_UNFOCUS:
- ctDraw(co);
- er.result = ER_SWALLOWED;
- break;
+ ctDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
default:
- break;
+ break;
}
return er;
width = wstrlen(text, -1);
if ((ct->userHasSetWidth == 0) && ((width + i + ct->sbAdjust) > co->width)) {
- updateWidth(co, ct, width + i);
+ updateWidth(co, ct, width + i);
}
ctDraw(co);
item = findItem(ct->itemlist, data);
if (!item) return -1;
if (item->branch)
- return item->selected ? NEWT_CHECKBOXTREE_EXPANDED : NEWT_CHECKBOXTREE_COLLAPSED;
+ return item->selected ? NEWT_CHECKBOXTREE_EXPANDED : NEWT_CHECKBOXTREE_COLLAPSED;
else
- return ct->seq[item->selected];
+ return ct->seq[item->selected];
}
void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data, char value)
if (!item || item->branch) return;
for(i = 0; ct->seq[i]; i++)
- if (value == ct->seq[i])
- break;
+ if (value == ct->seq[i])
+ break;
if (!ct->seq[i]) return;
item->selected = i;
/* traverse the path and turn on all of the branches to this point */
for (i = 0, treeTop = ct->itemlist; path[i + 1] != NEWT_ARG_LAST; i++) {
- for (j = 0, item = treeTop; j < path[i]; j++)
- item = item->next;
+ for (j = 0, item = treeTop; j < path[i]; j++)
+ item = item->next;
- item->selected = 1;
- treeTop = item->branch;
+ item->selected = 1;
+ treeTop = item->branch;
}
buildFlatList(co);
-
+
item = findItem(ct->itemlist, data);
i = 0;
j = i - (co->height / 2);
if ((j + co->height) > ct->flatCount)
- j = ct->flatCount - co->height;
+ j = ct->flatCount - co->height;
if (j < 0)
- j = 0;
+ j = 0;
ct->firstItem = ct->flatList + j;
ct->currItem = ct->flatList + i;
/* globals -- ick */
static int buttonHeight = 1;
static newtComponent (*makeButton)(int left, int right, const char * text) =
- newtCompactButton;
+ newtCompactButton;
static void addButtons(int height, int width, newtComponent form,
- newtComponent * okay, newtComponent * cancel,
- int flags) {
+ newtComponent * okay, newtComponent * cancel,
+ int flags) {
if (flags & FLAG_NOCANCEL) {
- *okay = makeButton((width - 8) / 2, height - buttonHeight - 1, "Ok");
- *cancel = NULL;
- newtFormAddComponent(form, *okay);
+ *okay = makeButton((width - 8) / 2, height - buttonHeight - 1, "Ok");
+ *cancel = NULL;
+ newtFormAddComponent(form, *okay);
} else {
- *okay = makeButton((width - 18) / 3, height - buttonHeight - 1, "Ok");
- *cancel = makeButton(((width - 18) / 3) * 2 + 9,
- height - buttonHeight - 1, "Cancel");
- newtFormAddComponents(form, *okay, *cancel, NULL);
+ *okay = makeButton((width - 18) / 3, height - buttonHeight - 1, "Ok");
+ *cancel = makeButton(((width - 18) / 3) * 2 + 9,
+ height - buttonHeight - 1, "Cancel");
+ newtFormAddComponents(form, *okay, *cancel, NULL);
}
}
static newtComponent textbox(int maxHeight, int width, const char * text,
- int flags, int * height) {
+ int flags, int * height) {
newtComponent tb;
int sFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0;
int i;
dst = buf = alloca(strlen(text) + 1);
src = text;
while (*src) {
- if (*src == '\\' && *(src + 1) == 'n') {
- src += 2;
- *dst++ = '\n';
- } else
- *dst++ = *src++;
+ if (*src == '\\' && *(src + 1) == 'n') {
+ src += 2;
+ *dst++ = '\n';
+ } else
+ *dst++ = *src++;
}
*dst++ = '\0';
i = newtTextboxGetNumLines(tb);
if (i < maxHeight) {
- newtTextboxSetHeight(tb, i);
- maxHeight = i;
+ newtTextboxSetHeight(tb, i);
+ maxHeight = i;
}
*height = maxHeight;
}
int gauge(const char * text, int height, int width, poptContext optCon, int fd,
- int flags) {
+ int flags) {
newtComponent form, scale, tb;
int top;
const char * arg;
newtRefresh();
while (fgets(buf, sizeof(buf) - 1, f)) {
- buf[strlen(buf) - 1] = '\0';
-
- if (!strcmp(buf, "XXX")) {
- fgets(buf3, sizeof(buf3) - 1, f);
- buf3[strlen(buf3) - 1] = '\0';
- arg = buf3;
-
- i = 0;
- while (fgets(buf + i, sizeof(buf) - 1 - i, f)) {
- buf[strlen(buf) - 1] = '\0';
- if (!strcmp(buf + i, "XXX")) {
- *(buf + i) = '\0';
- break;
- }
- i = strlen(buf);
- }
-
- newtTextboxSetText(tb, buf);
- } else {
- arg = buf;
- }
-
- val = strtoul(buf, &end, 10);
- if (!*end) {
- newtScaleSet(scale, val);
- newtDrawForm(form);
- newtRefresh();
- }
+ buf[strlen(buf) - 1] = '\0';
+
+ if (!strcmp(buf, "XXX")) {
+ fgets(buf3, sizeof(buf3) - 1, f);
+ buf3[strlen(buf3) - 1] = '\0';
+ arg = buf3;
+
+ i = 0;
+ while (fgets(buf + i, sizeof(buf) - 1 - i, f)) {
+ buf[strlen(buf) - 1] = '\0';
+ if (!strcmp(buf + i, "XXX")) {
+ *(buf + i) = '\0';
+ break;
+ }
+ i = strlen(buf);
+ }
+
+ newtTextboxSetText(tb, buf);
+ } else {
+ arg = buf;
+ }
+
+ val = strtoul(buf, &end, 10);
+ if (!*end) {
+ newtScaleSet(scale, val);
+ newtDrawForm(form);
+ newtRefresh();
+ }
}
return DLG_OKAY;
}
int inputBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result) {
+ int flags, const char ** result) {
newtComponent form, entry, okay, cancel, answer, tb;
const char * val;
int rc = DLG_OKAY;
val = poptGetArg(optCon);
tb = textbox(height - 3 - buttonHeight, width - 2,
- text, flags, &top);
+ text, flags, &top);
form = newtForm(NULL, NULL, 0);
entry = newtEntry(1, top + 1, val, width - 2, &val,
- NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
+ NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
newtFormAddComponents(form, tb, entry, NULL);
answer = newtRunForm(form);
if (answer == cancel)
- rc = DLG_CANCEL;
+ rc = DLG_CANCEL;
*result = val;
}
int listBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result) {
+ int flags, const char ** result) {
newtComponent form, okay, tb, answer, listBox;
newtComponent cancel = NULL;
const char * arg;
int maxTextWidth = 0;
int scrollFlag;
struct {
- const char * text;
- const char * tag;
+ const char * text;
+ const char * tag;
} * itemInfo = malloc(allocedItems * sizeof(*itemInfo));
if (itemInfo == NULL) return DLG_ERROR;
if (*end) return DLG_ERROR;
while ((arg = poptGetArg(optCon))) {
- if (allocedItems == numItems) {
- allocedItems += 5;
- itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems);
- if (itemInfo == NULL) return DLG_ERROR;
- }
-
- itemInfo[numItems].tag = arg;
- if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
-
- if (!(flags & FLAG_NOITEM)) {
- itemInfo[numItems].text = arg;
- } else
- itemInfo[numItems].text = "";
-
- if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth)
- maxTextWidth = wstrlen(itemInfo[numItems].text,-1);
- if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth)
- maxTagWidth = wstrlen(itemInfo[numItems].tag,-1);
-
- numItems++;
+ if (allocedItems == numItems) {
+ allocedItems += 5;
+ itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems);
+ if (itemInfo == NULL) return DLG_ERROR;
+ }
+
+ itemInfo[numItems].tag = arg;
+ if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
+
+ if (!(flags & FLAG_NOITEM)) {
+ itemInfo[numItems].text = arg;
+ } else
+ itemInfo[numItems].text = "";
+
+ if (wstrlen(itemInfo[numItems].text,-1) > (unsigned int)maxTextWidth)
+ maxTextWidth = wstrlen(itemInfo[numItems].text,-1);
+ if (wstrlen(itemInfo[numItems].tag,-1) > (unsigned int)maxTagWidth)
+ maxTagWidth = wstrlen(itemInfo[numItems].tag,-1);
+
+ numItems++;
}
if (numItems == 0)
- return DLG_ERROR;
+ return DLG_ERROR;
if (flags & FLAG_NOTAGS) {
- maxTagWidth = 0;
+ maxTagWidth = 0;
}
form = newtForm(NULL, NULL, 0);
tb = textbox(height - 4 - buttonHeight - listHeight, width - 2,
- text, flags, &top);
+ text, flags, &top);
if (listHeight >= numItems) {
- scrollFlag = 0;
- i = 0;
+ scrollFlag = 0;
+ i = 0;
} else {
- scrollFlag = NEWT_FLAG_SCROLL;
- i = 2;
+ scrollFlag = NEWT_FLAG_SCROLL;
+ i = 2;
}
listBox = newtListbox(3 + ((width - 10 - maxTagWidth - maxTextWidth - i)
- / 2),
- top + 1, listHeight,
- NEWT_FLAG_RETURNEXIT | scrollFlag);
+ / 2),
+ top + 1, listHeight,
+ NEWT_FLAG_RETURNEXIT | scrollFlag);
snprintf(format, MAXFORMAT, "%%-%ds %%s", maxTagWidth);
for (i = 0; i < numItems; i++) {
- snprintf(buf, MAXBUF, format, itemInfo[i].tag, itemInfo[i].text);
- newtListboxAddEntry(listBox, buf, (void *) i);
+ snprintf(buf, MAXBUF, format, itemInfo[i].tag, itemInfo[i].text);
+ newtListboxAddEntry(listBox, buf, (void *) i);
}
newtFormAddComponents(form, tb, listBox, NULL);
answer = newtRunForm(form);
if (answer == cancel)
- rc = DLG_CANCEL;
+ rc = DLG_CANCEL;
i = (int) newtListboxGetCurrent(listBox);
*result = itemInfo[i].tag;
}
int checkList(const char * text, int height, int width, poptContext optCon,
- int useRadio, int flags, const char *** selections) {
+ int useRadio, int flags, const char *** selections) {
newtComponent form, okay, tb, subform, answer;
newtComponent sb = NULL, cancel = NULL;
const char * arg;
int maxWidth = 0;
int top;
struct {
- const char * text;
- const char * tag;
- newtComponent comp;
+ const char * text;
+ const char * tag;
+ newtComponent comp;
} * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo));
char * cbStates = malloc(allocedBoxes * sizeof(cbStates));
if (*end) return DLG_ERROR;
while ((arg = poptGetArg(optCon))) {
- if (allocedBoxes == numBoxes) {
- allocedBoxes += 5;
- cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes);
- cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes);
- if ((cbInfo == NULL) || (cbStates == NULL)) return DLG_ERROR;
- }
-
- cbInfo[numBoxes].tag = arg;
- if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
-
- if (!(flags & FLAG_NOITEM)) {
- cbInfo[numBoxes].text = arg;
- if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
- } else
- cbInfo[numBoxes].text = "";
-
- if (!strcmp(arg, "1") || !strcasecmp(arg, "on") ||
- !strcasecmp(arg, "yes"))
- cbStates[numBoxes] = '*';
- else
- cbStates[numBoxes] = ' ';
-
- if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth)
- maxWidth = wstrlen(cbInfo[numBoxes].tag,-1);
-
- numBoxes++;
+ if (allocedBoxes == numBoxes) {
+ allocedBoxes += 5;
+ cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes);
+ cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes);
+ if ((cbInfo == NULL) || (cbStates == NULL)) return DLG_ERROR;
+ }
+
+ cbInfo[numBoxes].tag = arg;
+ if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
+
+ if (!(flags & FLAG_NOITEM)) {
+ cbInfo[numBoxes].text = arg;
+ if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
+ } else
+ cbInfo[numBoxes].text = "";
+
+ if (!strcmp(arg, "1") || !strcasecmp(arg, "on") ||
+ !strcasecmp(arg, "yes"))
+ cbStates[numBoxes] = '*';
+ else
+ cbStates[numBoxes] = ' ';
+
+ if (wstrlen(cbInfo[numBoxes].tag,-1) > (unsigned int)maxWidth)
+ maxWidth = wstrlen(cbInfo[numBoxes].tag,-1);
+
+ numBoxes++;
}
-
+
form = newtForm(NULL, NULL, 0);
tb = textbox(height - 3 - buttonHeight - listHeight, width - 2,
- text, flags, &top);
+ text, flags, &top);
if (listHeight < numBoxes) {
- sb = newtVerticalScrollbar(width - 4,
- top + 1,
- listHeight, NEWT_COLORSET_CHECKBOX,
- NEWT_COLORSET_ACTCHECKBOX);
- newtFormAddComponent(form, sb);
+ sb = newtVerticalScrollbar(width - 4,
+ top + 1,
+ listHeight, NEWT_COLORSET_CHECKBOX,
+ NEWT_COLORSET_ACTCHECKBOX);
+ newtFormAddComponent(form, sb);
}
subform = newtForm(sb, NULL, 0);
newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);
snprintf(format, MAXFORMAT, "%%-%ds %%s", maxWidth);
for (i = 0; i < numBoxes; i++) {
- snprintf(buf, MAXBUF, format, cbInfo[i].tag, cbInfo[i].text);
+ snprintf(buf, MAXBUF, format, cbInfo[i].tag, cbInfo[i].text);
- if (useRadio)
- cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf,
- cbStates[i] != ' ',
- i ? cbInfo[i - 1].comp : NULL);
- else
- cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf,
- cbStates[i], NULL, cbStates + i);
+ if (useRadio)
+ cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf,
+ cbStates[i] != ' ',
+ i ? cbInfo[i - 1].comp : NULL);
+ else
+ cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf,
+ cbStates[i], NULL, cbStates + i);
- newtFormAddComponent(subform, cbInfo[i].comp);
+ newtFormAddComponent(subform, cbInfo[i].comp);
}
newtFormSetHeight(subform, listHeight);
answer = newtRunForm(form);
if (answer == cancel)
- rc = DLG_CANCEL;
+ rc = DLG_CANCEL;
if (useRadio) {
- answer = newtRadioGetCurrent(cbInfo[0].comp);
- for (i = 0; i < numBoxes; i++)
- if (cbInfo[i].comp == answer) {
- *selections = malloc(sizeof(char *) * 2);
- if (*selections == NULL) return DLG_ERROR;
- (*selections)[0] = cbInfo[i].tag;
- (*selections)[1] = NULL;
- break;
- }
+ answer = newtRadioGetCurrent(cbInfo[0].comp);
+ for (i = 0; i < numBoxes; i++)
+ if (cbInfo[i].comp == answer) {
+ *selections = malloc(sizeof(char *) * 2);
+ if (*selections == NULL) return DLG_ERROR;
+ (*selections)[0] = cbInfo[i].tag;
+ (*selections)[1] = NULL;
+ break;
+ }
} else {
- numSelected = 0;
- for (i = 0; i < numBoxes; i++) {
- if (cbStates[i] != ' ') numSelected++;
- }
+ numSelected = 0;
+ for (i = 0; i < numBoxes; i++) {
+ if (cbStates[i] != ' ') numSelected++;
+ }
- *selections = malloc(sizeof(char *) * (numSelected + 1));
- if (*selections == NULL) return DLG_ERROR;
+ *selections = malloc(sizeof(char *) * (numSelected + 1));
+ if (*selections == NULL) return DLG_ERROR;
- numSelected = 0;
- for (i = 0; i < numBoxes; i++) {
- if (cbStates[i] != ' ')
- (*selections)[numSelected++] = cbInfo[i].tag;
- }
+ numSelected = 0;
+ for (i = 0; i < numBoxes; i++) {
+ if (cbStates[i] != ' ')
+ (*selections)[numSelected++] = cbInfo[i].tag;
+ }
- (*selections)[numSelected] = NULL;
+ (*selections)[numSelected] = NULL;
}
return rc;
form = newtForm(NULL, NULL, 0);
tb = newtTextbox(1, 1, width - 2, height - 3 - buttonHeight,
- NEWT_FLAG_WRAP | tFlag);
+ NEWT_FLAG_WRAP | tFlag);
newtTextboxSetText(tb, text);
newtFormAddComponent(form, tb);
switch ( type ) {
case MSGBOX_INFO:
- break;
+ break;
case MSGBOX_MSG:
- yes = makeButton((width - 8) / 2, height - 1 - buttonHeight, "Ok");
- newtFormAddComponent(form, yes);
- break;
+ yes = makeButton((width - 8) / 2, height - 1 - buttonHeight, "Ok");
+ newtFormAddComponent(form, yes);
+ break;
default:
- yes = makeButton((width - 16) / 3, height - 1 - buttonHeight, "Yes");
- no = makeButton(((width - 16) / 3) * 2 + 9, height - 1 - buttonHeight,
- "No");
- newtFormAddComponents(form, yes, no, NULL);
+ yes = makeButton((width - 16) / 3, height - 1 - buttonHeight, "Yes");
+ no = makeButton(((width - 16) / 3) * 2 + 9, height - 1 - buttonHeight,
+ "No");
+ newtFormAddComponents(form, yes, no, NULL);
- if (flags & FLAG_DEFAULT_NO)
- newtFormSetCurrent(form, no);
+ if (flags & FLAG_DEFAULT_NO)
+ newtFormSetCurrent(form, no);
}
if ( type != MSGBOX_INFO ) {
- newtRunForm(form);
+ newtRunForm(form);
- answer = newtFormGetCurrent(form);
+ answer = newtFormGetCurrent(form);
- if (answer == no)
- return DLG_CANCEL;
+ if (answer == no)
+ return DLG_CANCEL;
}
else {
- newtDrawForm(form);
- newtRefresh();
+ newtDrawForm(form);
+ newtRefresh();
}
-
+
return DLG_OKAY;
void useFullButtons(int state) {
if (state) {
- buttonHeight = 3;
- makeButton = newtButton;
+ buttonHeight = 3;
+ makeButton = newtButton;
} else {
- buttonHeight = 1;
- makeButton = newtCompactButton;
+ buttonHeight = 1;
+ makeButton = newtCompactButton;
}
}
#define MSGBOX_YESNO 1
#define MSGBOX_INFO 2
-#define FLAG_NOITEM (1 << 0)
-#define FLAG_NOCANCEL (1 << 1)
-#define FLAG_SCROLL_TEXT (1 << 2)
-#define FLAG_DEFAULT_NO (1 << 3)
-#define FLAG_NOTAGS (1 << 5)
+#define FLAG_NOITEM (1 << 0)
+#define FLAG_NOCANCEL (1 << 1)
+#define FLAG_SCROLL_TEXT (1 << 2)
+#define FLAG_DEFAULT_NO (1 << 3)
+#define FLAG_NOTAGS (1 << 5)
-#define DLG_ERROR -1
-#define DLG_OKAY 0
-#define DLG_CANCEL 1
+#define DLG_ERROR -1
+#define DLG_OKAY 0
+#define DLG_CANCEL 1
int messageBox(const char * text, int height, int width, int type, int flags);
int checkList(const char * text, int height, int width, poptContext optCon,
- int useRadio, int flags, const char *** selections);
+ int useRadio, int flags, const char *** selections);
int listBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result);
+ int flags, const char ** result);
int inputBox(const char * text, int height, int width, poptContext optCon,
- int flags, const char ** result);
+ int flags, const char ** result);
int gauge(const char * text, int height, int width, poptContext optCon, int fd,
- int flags);
+ int flags);
void useFullButtons(int state);
#endif
static const eaw_db_type eaw_db[] = {
{ 0x0020,0x007E,narrow },
- { 0x00A1,0x00A1,ambiguous }, /*INVERTED EXCLAMATION MARK*/
+ { 0x00A1,0x00A1,ambiguous }, /*INVERTED EXCLAMATION MARK*/
{ 0x00A2,0x00A3,narrow },
- { 0x00A4,0x00A4,ambiguous }, /*CURRENCY SIGN*/
+ { 0x00A4,0x00A4,ambiguous }, /*CURRENCY SIGN*/
{ 0x00A5,0x00A6,narrow },
{ 0x00A7,0x00A8,ambiguous },
- { 0x00AA,0x00AA,ambiguous }, /*FEMININE ORDINAL INDICATOR*/
- { 0x00AC,0x00AC,narrow }, /*NOT SIGN*/
- { 0x00AD,0x00AD,ambiguous }, /*SOFT HYPHEN*/
- { 0x00AF,0x00AF,narrow }, /*MACRON*/
+ { 0x00AA,0x00AA,ambiguous }, /*FEMININE ORDINAL INDICATOR*/
+ { 0x00AC,0x00AC,narrow }, /*NOT SIGN*/
+ { 0x00AD,0x00AD,ambiguous }, /*SOFT HYPHEN*/
+ { 0x00AF,0x00AF,narrow }, /*MACRON*/
{ 0x00B0,0x00B4,ambiguous },
{ 0x00B6,0x00BA,ambiguous },
{ 0x00BC,0x00BF,ambiguous },
- { 0x00C6,0x00C6,ambiguous }, /*LATIN CAPITAL LETTER AE*/
- { 0x00D0,0x00D0,ambiguous }, /*LATIN CAPITAL LETTER ETH*/
+ { 0x00C6,0x00C6,ambiguous }, /*LATIN CAPITAL LETTER AE*/
+ { 0x00D0,0x00D0,ambiguous }, /*LATIN CAPITAL LETTER ETH*/
{ 0x00D7,0x00D8,ambiguous },
{ 0x00DE,0x00E1,ambiguous },
- { 0x00E6,0x00E6,ambiguous }, /*LATIN SMALL LETTER AE*/
+ { 0x00E6,0x00E6,ambiguous }, /*LATIN SMALL LETTER AE*/
{ 0x00E8,0x00EA,ambiguous },
{ 0x00EC,0x00ED,ambiguous },
- { 0x00F0,0x00F0,ambiguous }, /*LATIN SMALL LETTER ETH*/
+ { 0x00F0,0x00F0,ambiguous }, /*LATIN SMALL LETTER ETH*/
{ 0x00F2,0x00F3,ambiguous },
{ 0x00F7,0x00FA,ambiguous },
- { 0x00FC,0x00FC,ambiguous }, /*LATIN SMALL LETTER U WITH DIAERESIS*/
- { 0x00FE,0x00FE,ambiguous }, /*LATIN SMALL LETTER THORN*/
- { 0x0101,0x0101,ambiguous }, /*LATIN SMALL LETTER A WITH MACRON*/
- { 0x0111,0x0111,ambiguous }, /*LATIN SMALL LETTER D WITH STROKE*/
- { 0x0113,0x0113,ambiguous }, /*LATIN SMALL LETTER E WITH MACRON*/
- { 0x011B,0x011B,ambiguous }, /*LATIN SMALL LETTER E WITH CARON*/
+ { 0x00FC,0x00FC,ambiguous }, /*LATIN SMALL LETTER U WITH DIAERESIS*/
+ { 0x00FE,0x00FE,ambiguous }, /*LATIN SMALL LETTER THORN*/
+ { 0x0101,0x0101,ambiguous }, /*LATIN SMALL LETTER A WITH MACRON*/
+ { 0x0111,0x0111,ambiguous }, /*LATIN SMALL LETTER D WITH STROKE*/
+ { 0x0113,0x0113,ambiguous }, /*LATIN SMALL LETTER E WITH MACRON*/
+ { 0x011B,0x011B,ambiguous }, /*LATIN SMALL LETTER E WITH CARON*/
{ 0x0126,0x0127,ambiguous },
- { 0x012B,0x012B,ambiguous }, /*LATIN SMALL LETTER I WITH MACRON*/
+ { 0x012B,0x012B,ambiguous }, /*LATIN SMALL LETTER I WITH MACRON*/
{ 0x0131,0x0133,ambiguous },
- { 0x0138,0x0138,ambiguous }, /*LATIN SMALL LETTER KRA*/
+ { 0x0138,0x0138,ambiguous }, /*LATIN SMALL LETTER KRA*/
{ 0x013F,0x0142,ambiguous },
- { 0x0144,0x0144,ambiguous }, /*LATIN SMALL LETTER N WITH ACUTE*/
+ { 0x0144,0x0144,ambiguous }, /*LATIN SMALL LETTER N WITH ACUTE*/
{ 0x0148,0x014A,ambiguous },
- { 0x014D,0x014D,ambiguous }, /*LATIN SMALL LETTER O WITH MACRON*/
+ { 0x014D,0x014D,ambiguous }, /*LATIN SMALL LETTER O WITH MACRON*/
{ 0x0152,0x0153,ambiguous },
{ 0x0166,0x0167,ambiguous },
- { 0x016B,0x016B,ambiguous }, /*LATIN SMALL LETTER U WITH MACRON*/
- { 0x01CE,0x01CE,ambiguous }, /*LATIN SMALL LETTER A WITH CARON*/
- { 0x01D0,0x01D0,ambiguous }, /*LATIN SMALL LETTER I WITH CARON*/
- { 0x01D2,0x01D2,ambiguous }, /*LATIN SMALL LETTER O WITH CARON*/
- { 0x01D4,0x01D4,ambiguous }, /*LATIN SMALL LETTER U WITH CARON*/
- { 0x01D6,0x01D6,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+MACRON*/
- { 0x01D8,0x01D8,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+ACUTE*/
- { 0x01DA,0x01DA,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+CARON*/
- { 0x01DC,0x01DC,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+GRAVE*/
- { 0x0251,0x0251,ambiguous }, /*LATIN SMALL LETTER ALPHA*/
- { 0x0261,0x0261,ambiguous }, /*LATIN SMALL LETTER SCRIPT G*/
- { 0x02C7,0x02C7,ambiguous }, /*CARON*/
+ { 0x016B,0x016B,ambiguous }, /*LATIN SMALL LETTER U WITH MACRON*/
+ { 0x01CE,0x01CE,ambiguous }, /*LATIN SMALL LETTER A WITH CARON*/
+ { 0x01D0,0x01D0,ambiguous }, /*LATIN SMALL LETTER I WITH CARON*/
+ { 0x01D2,0x01D2,ambiguous }, /*LATIN SMALL LETTER O WITH CARON*/
+ { 0x01D4,0x01D4,ambiguous }, /*LATIN SMALL LETTER U WITH CARON*/
+ { 0x01D6,0x01D6,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+MACRON*/
+ { 0x01D8,0x01D8,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+ACUTE*/
+ { 0x01DA,0x01DA,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+CARON*/
+ { 0x01DC,0x01DC,ambiguous }, /*LATIN SMALL LETTER U W/DIAERESIS+GRAVE*/
+ { 0x0251,0x0251,ambiguous }, /*LATIN SMALL LETTER ALPHA*/
+ { 0x0261,0x0261,ambiguous }, /*LATIN SMALL LETTER SCRIPT G*/
+ { 0x02C7,0x02C7,ambiguous }, /*CARON*/
{ 0x02C9,0x02CB,ambiguous },
- { 0x02CD,0x02CD,ambiguous }, /*MODIFIER LETTER LOW MACRON*/
- { 0x02D0,0x02D0,ambiguous }, /*MODIFIER LETTER TRIANGULAR COLON*/
+ { 0x02CD,0x02CD,ambiguous }, /*MODIFIER LETTER LOW MACRON*/
+ { 0x02D0,0x02D0,ambiguous }, /*MODIFIER LETTER TRIANGULAR COLON*/
{ 0x02D8,0x02DB,ambiguous },
- { 0x02DD,0x02DD,ambiguous }, /*DOUBLE ACUTE ACCENT*/
+ { 0x02DD,0x02DD,ambiguous }, /*DOUBLE ACUTE ACCENT*/
{ 0x0300,0x0362,ambiguous },
{ 0x0391,0x03A9,ambiguous },
{ 0x03B1,0x03C1,ambiguous },
{ 0x03C3,0x03C9,ambiguous },
- { 0x0401,0x0401,ambiguous }, /*CYRILLIC CAPITAL LETTER IO*/
+ { 0x0401,0x0401,ambiguous }, /*CYRILLIC CAPITAL LETTER IO*/
{ 0x0410,0x044F,ambiguous },
- { 0x0451,0x0451,ambiguous }, /*CYRILLIC SMALL LETTER IO*/
+ { 0x0451,0x0451,ambiguous }, /*CYRILLIC SMALL LETTER IO*/
{ 0x1100,0x115F,wide },
- { 0x2010,0x2010,ambiguous }, /*HYPHEN*/
+ { 0x2010,0x2010,ambiguous }, /*HYPHEN*/
{ 0x2013,0x2016,ambiguous },
{ 0x2018,0x2019,ambiguous },
{ 0x201C,0x201D,ambiguous },
{ 0x2020,0x2021,ambiguous },
{ 0x2025,0x2027,ambiguous },
- { 0x2030,0x2030,ambiguous }, /*PER MILLE SIGN*/
+ { 0x2030,0x2030,ambiguous }, /*PER MILLE SIGN*/
{ 0x2032,0x2033,ambiguous },
- { 0x2035,0x2035,ambiguous }, /*REVERSED PRIME*/
- { 0x203B,0x203B,ambiguous }, /*REFERENCE MARK*/
- { 0x2074,0x2074,ambiguous }, /*SUPERSCRIPT FOUR*/
- { 0x207F,0x207F,ambiguous }, /*SUPERSCRIPT LATIN SMALL LETTER N*/
+ { 0x2035,0x2035,ambiguous }, /*REVERSED PRIME*/
+ { 0x203B,0x203B,ambiguous }, /*REFERENCE MARK*/
+ { 0x2074,0x2074,ambiguous }, /*SUPERSCRIPT FOUR*/
+ { 0x207F,0x207F,ambiguous }, /*SUPERSCRIPT LATIN SMALL LETTER N*/
{ 0x2081,0x2084,ambiguous },
- { 0x20A9,0x20A9,half_width }, /*WON SIGN*/
- { 0x20AC,0x20AC,ambiguous }, /*EURO SIGN*/
- { 0x2103,0x2103,ambiguous }, /*DEGREE CELSIUS*/
- { 0x2105,0x2105,ambiguous }, /*CARE OF*/
- { 0x2109,0x2109,ambiguous }, /*DEGREE FAHRENHEIT*/
- { 0x2113,0x2113,ambiguous }, /*SCRIPT SMALL L*/
+ { 0x20A9,0x20A9,half_width }, /*WON SIGN*/
+ { 0x20AC,0x20AC,ambiguous }, /*EURO SIGN*/
+ { 0x2103,0x2103,ambiguous }, /*DEGREE CELSIUS*/
+ { 0x2105,0x2105,ambiguous }, /*CARE OF*/
+ { 0x2109,0x2109,ambiguous }, /*DEGREE FAHRENHEIT*/
+ { 0x2113,0x2113,ambiguous }, /*SCRIPT SMALL L*/
{ 0x2121,0x2122,ambiguous },
- { 0x2126,0x2126,ambiguous }, /*OHM SIGN*/
- { 0x212B,0x212B,ambiguous }, /*ANGSTROM SIGN*/
+ { 0x2126,0x2126,ambiguous }, /*OHM SIGN*/
+ { 0x212B,0x212B,ambiguous }, /*ANGSTROM SIGN*/
{ 0x2154,0x2155,ambiguous },
- { 0x215B,0x215B,ambiguous }, /*VULGAR FRACTION ONE EIGHTH*/
- { 0x215E,0x215E,ambiguous }, /*VULGAR FRACTION SEVEN EIGHTHS*/
+ { 0x215B,0x215B,ambiguous }, /*VULGAR FRACTION ONE EIGHTH*/
+ { 0x215E,0x215E,ambiguous }, /*VULGAR FRACTION SEVEN EIGHTHS*/
{ 0x2160,0x216B,ambiguous },
{ 0x2170,0x2179,ambiguous },
{ 0x2190,0x2199,ambiguous },
- { 0x21D2,0x21D2,ambiguous }, /*RIGHTWARDS DOUBLE ARROW*/
- { 0x21D4,0x21D4,ambiguous }, /*LEFT RIGHT DOUBLE ARROW*/
- { 0x2200,0x2200,ambiguous }, /*FOR ALL*/
+ { 0x21D2,0x21D2,ambiguous }, /*RIGHTWARDS DOUBLE ARROW*/
+ { 0x21D4,0x21D4,ambiguous }, /*LEFT RIGHT DOUBLE ARROW*/
+ { 0x2200,0x2200,ambiguous }, /*FOR ALL*/
{ 0x2202,0x2203,ambiguous },
{ 0x2207,0x2208,ambiguous },
- { 0x220B,0x220B,ambiguous }, /*CONTAINS AS MEMBER*/
- { 0x220F,0x220F,ambiguous }, /*N-ARY PRODUCT*/
- { 0x2211,0x2211,ambiguous }, /*N-ARY SUMMATION*/
- { 0x2215,0x2215,ambiguous }, /*DIVISION SLASH*/
- { 0x221A,0x221A,ambiguous }, /*SQUARE ROOT*/
+ { 0x220B,0x220B,ambiguous }, /*CONTAINS AS MEMBER*/
+ { 0x220F,0x220F,ambiguous }, /*N-ARY PRODUCT*/
+ { 0x2211,0x2211,ambiguous }, /*N-ARY SUMMATION*/
+ { 0x2215,0x2215,ambiguous }, /*DIVISION SLASH*/
+ { 0x221A,0x221A,ambiguous }, /*SQUARE ROOT*/
{ 0x221D,0x2220,ambiguous },
- { 0x2223,0x2223,ambiguous }, /*DIVIDES*/
- { 0x2225,0x2225,ambiguous }, /*PARALLEL TO*/
+ { 0x2223,0x2223,ambiguous }, /*DIVIDES*/
+ { 0x2225,0x2225,ambiguous }, /*PARALLEL TO*/
{ 0x2227,0x222C,ambiguous },
- { 0x222E,0x222E,ambiguous }, /*CONTOUR INTEGRAL*/
+ { 0x222E,0x222E,ambiguous }, /*CONTOUR INTEGRAL*/
{ 0x2234,0x2237,ambiguous },
{ 0x223C,0x223D,ambiguous },
- { 0x2248,0x2248,ambiguous }, /*ALMOST EQUAL TO*/
- { 0x224C,0x224C,ambiguous }, /*ALL EQUAL TO*/
- { 0x2252,0x2252,ambiguous }, /*APPROXIMATELY EQUAL TO OR THE IMAGE OF*/
+ { 0x2248,0x2248,ambiguous }, /*ALMOST EQUAL TO*/
+ { 0x224C,0x224C,ambiguous }, /*ALL EQUAL TO*/
+ { 0x2252,0x2252,ambiguous }, /*APPROXIMATELY EQUAL TO OR THE IMAGE OF*/
{ 0x2260,0x2261,ambiguous },
{ 0x2264,0x2267,ambiguous },
{ 0x226A,0x226B,ambiguous },
{ 0x226E,0x226F,ambiguous },
{ 0x2282,0x2283,ambiguous },
{ 0x2286,0x2287,ambiguous },
- { 0x2295,0x2295,ambiguous }, /*CIRCLED PLUS*/
- { 0x2299,0x2299,ambiguous }, /*CIRCLED DOT OPERATOR*/
- { 0x22A5,0x22A5,ambiguous }, /*UP TACK*/
- { 0x22BF,0x22BF,ambiguous }, /*RIGHT TRIANGLE*/
- { 0x2312,0x2312,ambiguous }, /*ARC*/
+ { 0x2295,0x2295,ambiguous }, /*CIRCLED PLUS*/
+ { 0x2299,0x2299,ambiguous }, /*CIRCLED DOT OPERATOR*/
+ { 0x22A5,0x22A5,ambiguous }, /*UP TACK*/
+ { 0x22BF,0x22BF,ambiguous }, /*RIGHT TRIANGLE*/
+ { 0x2312,0x2312,ambiguous }, /*ARC*/
{ 0x2460,0x24BF,ambiguous },
{ 0x24D0,0x24E9,ambiguous },
{ 0x2500,0x254B,ambiguous },
{ 0x25BC,0x25BD,ambiguous },
{ 0x25C0,0x25C1,ambiguous },
{ 0x25C6,0x25C8,ambiguous },
- { 0x25CB,0x25CB,ambiguous }, /*WHITE CIRCLE*/
+ { 0x25CB,0x25CB,ambiguous }, /*WHITE CIRCLE*/
{ 0x25CE,0x25D1,ambiguous },
{ 0x25E2,0x25E5,ambiguous },
- { 0x25EF,0x25EF,ambiguous }, /*LARGE CIRCLE*/
+ { 0x25EF,0x25EF,ambiguous }, /*LARGE CIRCLE*/
{ 0x2605,0x2606,ambiguous },
- { 0x2609,0x2609,ambiguous }, /*SUN*/
+ { 0x2609,0x2609,ambiguous }, /*SUN*/
{ 0x260E,0x260F,ambiguous },
- { 0x261C,0x261C,ambiguous }, /*WHITE LEFT POINTING INDEX*/
- { 0x261E,0x261E,ambiguous }, /*WHITE RIGHT POINTING INDEX*/
- { 0x2640,0x2640,ambiguous }, /*FEMALE SIGN*/
- { 0x2642,0x2642,ambiguous }, /*MALE SIGN*/
+ { 0x261C,0x261C,ambiguous }, /*WHITE LEFT POINTING INDEX*/
+ { 0x261E,0x261E,ambiguous }, /*WHITE RIGHT POINTING INDEX*/
+ { 0x2640,0x2640,ambiguous }, /*FEMALE SIGN*/
+ { 0x2642,0x2642,ambiguous }, /*MALE SIGN*/
{ 0x2660,0x2661,ambiguous },
{ 0x2663,0x2665,ambiguous },
{ 0x2667,0x266A,ambiguous },
{ 0x266C,0x266D,ambiguous },
- { 0x266F,0x266F,ambiguous }, /*MUSIC SHARP SIGN*/
+ { 0x266F,0x266F,ambiguous }, /*MUSIC SHARP SIGN*/
{ 0x2E80,0x3009,wide },
{ 0x300A,0x300B,ambiguous },
{ 0x300C,0x3019,wide },
int
east_asia_mblen (const char *locale_name, const char *s, size_t n, int x)
{
- wchar_t *wcs, *p;
- int width = 0;
+ wchar_t *wcs, *p;
+ int width = 0;
- if (NULL == s) s = "";
+ if (NULL == s) s = "";
- /*
- * Getting the locale name via setlocale() is expensive, so we prefer
- * to have it passed to us.
- */
- if (NULL == locale_name) {
- locale_name = setlocale(LC_CTYPE, NULL);
- if (NULL == locale_name) return INT_MAX;
- }
+ /*
+ * Getting the locale name via setlocale() is expensive, so we prefer
+ * to have it passed to us.
+ */
+ if (NULL == locale_name) {
+ locale_name = setlocale(LC_CTYPE, NULL);
+ if (NULL == locale_name) return INT_MAX;
+ }
- wcs = (wchar_t *) calloc(n, sizeof(wchar_t));
- if (NULL == wcs) return INT_MAX;
+ wcs = (wchar_t *) calloc(n, sizeof(wchar_t));
+ if (NULL == wcs) return INT_MAX;
#if defined __GLIBC__ && !__GLIBC_PREREQ(2,2)
#warning wide character support is broken. Glibc 2.2 or better needed.
#endif
- if ((size_t) -1 == mbstowcs(wcs, s, n)) return INT_MAX;
-
- switch (get_east_asia_type(*wcs)) {
- case neutral:
-
- /*
- * Put characters that print nothing here.
- *
- * XXX: Yes, I know there are a lot more than this in ISO-10646, but
- * this function is intended to calculate the width of strings for
- * fixed width terminals displaying legacy CJK character sets.
- * State-of-the-art Unicode handling terminals probably won't need
- * this function anyway.
- */
- if (0x0000 == *wcs) break; /* NULL */
- if (0x0007 == *wcs) break; /* BELL */
-
- /* FIXME: there will probably be ASCII chars after the escape
- * code, which will be counted as part of the width even though they
- * aren't displayed.
- */
- if (0x001B == *wcs) break; /* ESC */
- if (0xFEFF == *wcs) break; /* ZWNBSP aka BOM (magic, signature) */
-
- /*
- * Special characters go here
- */
- if (0x0008 == *wcs) { /* BACKSPACE */
- width = -1;
- break;
- }
- if (0x0009 == *wcs) { /* TAB */
- if (tab_width < 0) width = x % abs(tab_width);
- else width = tab_width;
- break;
- }
-
- /*FALLTHRU*/
- case narrow:
- case half_width:
- width = 1;
- break;
- case wide:
- case full_width:
- width = 2;
- break;
- case ambiguous:
- width = is_cjk_locale(locale_name) ? 2 : 1;
- break;
- default:
- width = INT_MAX;
+ if ((size_t) -1 == mbstowcs(wcs, s, n)) return INT_MAX;
+
+ switch (get_east_asia_type(*wcs)) {
+ case neutral:
+
+ /*
+ * Put characters that print nothing here.
+ *
+ * XXX: Yes, I know there are a lot more than this in ISO-10646, but
+ * this function is intended to calculate the width of strings for
+ * fixed width terminals displaying legacy CJK character sets.
+ * State-of-the-art Unicode handling terminals probably won't need
+ * this function anyway.
+ */
+ if (0x0000 == *wcs) break; /* NULL */
+ if (0x0007 == *wcs) break; /* BELL */
+
+ /* FIXME: there will probably be ASCII chars after the escape
+ * code, which will be counted as part of the width even though they
+ * aren't displayed.
+ */
+ if (0x001B == *wcs) break; /* ESC */
+ if (0xFEFF == *wcs) break; /* ZWNBSP aka BOM (magic, signature) */
+
+ /*
+ * Special characters go here
+ */
+ if (0x0008 == *wcs) { /* BACKSPACE */
+ width = -1;
+ break;
+ }
+ if (0x0009 == *wcs) { /* TAB */
+ if (tab_width < 0) width = x % abs(tab_width);
+ else width = tab_width;
+ break;
+ }
+
+ /*FALLTHRU*/
+ case narrow:
+ case half_width:
+ width = 1;
+ break;
+ case wide:
+ case full_width:
+ width = 2;
+ break;
+ case ambiguous:
+ width = is_cjk_locale(locale_name) ? 2 : 1;
+ break;
+ default:
+ width = INT_MAX;
}
- free(wcs);
- return width;
+ free(wcs);
+ return width;
}
int
char * buf;
const char ** resultPtr;
int bufAlloced;
- int bufUsed; /* amount of the buffer that's been used */
- int cursorPosition; /* cursor *in the string* on on screen */
- int firstChar; /* first character position being shown */
+ int bufUsed; /* amount of the buffer that's been used */
+ int cursorPosition; /* cursor *in the string* on on screen */
+ int firstChar; /* first character position being shown */
newtEntryFilter filter;
void * filterData;
};
static void entryDraw(newtComponent co);
static void entryDestroy(newtComponent co);
static struct eventResult entryEvent(newtComponent co,
- struct event ev);
+ struct event ev);
static struct eventResult entryHandleKey(newtComponent co, int key);
struct entry * en = co->data;
if ((strlen(value) + 1) > (unsigned int)en->bufAlloced) {
- free(en->buf);
- en->bufAlloced = strlen(value) + 1;
- en->buf = malloc(en->bufAlloced);
- if (en->resultPtr) *en->resultPtr = en->buf;
+ free(en->buf);
+ en->bufAlloced = strlen(value) + 1;
+ en->buf = malloc(en->bufAlloced);
+ if (en->resultPtr) *en->resultPtr = en->buf;
}
- memset(en->buf, 0, en->bufAlloced); /* clear the buffer */
+ memset(en->buf, 0, en->bufAlloced); /* clear the buffer */
strcpy(en->buf, value);
en->bufUsed = strlen(value);
en->firstChar = 0;
if (cursorAtEnd)
- en->cursorPosition = en->bufUsed;
+ en->cursorPosition = en->bufUsed;
else
- en->cursorPosition = 0;
+ en->cursorPosition = 0;
entryDraw(co);
} ;
newtComponent newtEntry(int left, int top, const char * initialValue, int width,
- const char ** resultPtr, int flags) {
+ const char ** resultPtr, int flags) {
newtComponent co;
struct entry * en;
en->filter = NULL;
if (!(en->flags & NEWT_FLAG_DISABLED))
- co->takesFocus = 1;
+ co->takesFocus = 1;
else
- co->takesFocus = 0;
+ co->takesFocus = 0;
if (initialValue && wstrlen(initialValue,-1) > (unsigned int)width) {
- en->bufAlloced = wstrlen(initialValue,-1) + 1;
+ en->bufAlloced = wstrlen(initialValue,-1) + 1;
}
en->buf = malloc(en->bufAlloced);
en->resultPtr = resultPtr;
memset(en->buf, 0, en->bufAlloced);
if (initialValue) {
- strcpy(en->buf, initialValue);
- en->bufUsed = strlen(initialValue);
- en->cursorPosition = en->bufUsed;
+ strcpy(en->buf, initialValue);
+ en->bufUsed = strlen(initialValue);
+ en->cursorPosition = en->bufUsed;
} else {
- *en->buf = '\0';
- en->bufUsed = 0;
- en->cursorPosition = 0;
+ *en->buf = '\0';
+ en->bufUsed = 0;
+ en->cursorPosition = 0;
}
return co;
if (!co->isMapped) return;
if (en->flags & NEWT_FLAG_DISABLED)
- SLsmg_set_color(NEWT_COLORSET_DISENTRY);
+ SLsmg_set_color(NEWT_COLORSET_DISENTRY);
else
- SLsmg_set_color(NEWT_COLORSET_ENTRY);
+ SLsmg_set_color(NEWT_COLORSET_ENTRY);
if (en->flags & NEWT_FLAG_HIDDEN) {
- newtGotorc(co->top, co->left);
- for (i = 0; i < co->width; i++)
- SLsmg_write_char('_');
- newtGotorc(co->top, co->left);
+ newtGotorc(co->top, co->left);
+ for (i = 0; i < co->width; i++)
+ SLsmg_write_char('_');
+ newtGotorc(co->top, co->left);
- return;
+ return;
}
newtGotorc(co->top, co->left);
if (en->cursorPosition < en->firstChar) {
- /* scroll to the left */
- en->firstChar = en->cursorPosition;
+ /* scroll to the left */
+ en->firstChar = en->cursorPosition;
} else if ((en->firstChar + co->width) <= en->cursorPosition) {
- /* scroll to the right */
- en->firstChar = en->cursorPosition - co->width + 1;
+ /* scroll to the right */
+ en->firstChar = en->cursorPosition - co->width + 1;
}
chptr = en->buf + en->firstChar;
if (en->flags & NEWT_FLAG_PASSWORD) {
- char *tmpptr, *p;
+ char *tmpptr, *p;
- tmpptr = alloca(strlen(chptr)+2);
- strcpy(tmpptr, chptr);
- for (p = tmpptr; *p; p++)
- *p = '*';
- chptr = tmpptr;
- }
+ tmpptr = alloca(strlen(chptr)+2);
+ strcpy(tmpptr, chptr);
+ for (p = tmpptr; *p; p++)
+ *p = '*';
+ chptr = tmpptr;
+ }
len = wstrlen(chptr, -1);
if (len <= co->width) {
- i = len;
- SLsmg_write_string(chptr);
- while (i < co->width) {
- SLsmg_write_char('_');
- i++;
- }
+ i = len;
+ SLsmg_write_string(chptr);
+ while (i < co->width) {
+ SLsmg_write_char('_');
+ i++;
+ }
} else {
- SLsmg_write_nstring(chptr, co->width);
+ SLsmg_write_nstring(chptr, co->width);
}
if (en->flags & NEWT_FLAG_HIDDEN)
- newtGotorc(co->top, co->left);
+ newtGotorc(co->top, co->left);
else
- newtGotorc(co->top, co->left + (en->cursorPosition - en->firstChar));
+ newtGotorc(co->top, co->left + (en->cursorPosition - en->firstChar));
}
void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense) {
en->flags = newtSetFlags(en->flags, flags, sense);
if (!(en->flags & NEWT_FLAG_DISABLED))
- co->takesFocus = 1;
+ co->takesFocus = 1;
else
- co->takesFocus = 0;
+ co->takesFocus = 0;
newtGetrc(&row, &col);
entryDraw(co);
}
static struct eventResult entryEvent(newtComponent co,
- struct event ev) {
+ struct event ev) {
struct entry * en = co->data;
struct eventResult er;
int ch;
if (ev.when == EV_NORMAL) {
- switch (ev.event) {
- case EV_FOCUS:
- newtCursorOn();
- if (en->flags & NEWT_FLAG_HIDDEN)
- newtGotorc(co->top, co->left);
- else
- newtGotorc(co->top, co->left +
- (en->cursorPosition - en->firstChar));
- er.result = ER_SWALLOWED;
- break;
-
- case EV_UNFOCUS:
- newtCursorOff();
- newtGotorc(0, 0);
- er.result = ER_SWALLOWED;
- if (co->callback)
- co->callback(co, co->callbackData);
- break;
-
- case EV_KEYPRESS:
- ch = ev.u.key;
- if (en->filter)
- ch = en->filter(co, en->filterData, ch, en->cursorPosition);
- if (ch) er = entryHandleKey(co, ch);
- break;
-
- case EV_MOUSE:
- if ((ev.u.mouse.type == MOUSE_BUTTON_DOWN) &&
- (en->flags ^ NEWT_FLAG_HIDDEN)) {
- if (strlen(en->buf) >= ev.u.mouse.x - co->left) {
- en->cursorPosition = ev.u.mouse.x - co->left;
- newtGotorc(co->top,
- co->left +(en->cursorPosition - en->firstChar));
- } else {
- en->cursorPosition = strlen(en->buf);
- newtGotorc(co->top,
- co->left +(en->cursorPosition - en->firstChar));
- }
- }
- break;
- }
+ switch (ev.event) {
+ case EV_FOCUS:
+ newtCursorOn();
+ if (en->flags & NEWT_FLAG_HIDDEN)
+ newtGotorc(co->top, co->left);
+ else
+ newtGotorc(co->top, co->left +
+ (en->cursorPosition - en->firstChar));
+ er.result = ER_SWALLOWED;
+ break;
+
+ case EV_UNFOCUS:
+ newtCursorOff();
+ newtGotorc(0, 0);
+ er.result = ER_SWALLOWED;
+ if (co->callback)
+ co->callback(co, co->callbackData);
+ break;
+
+ case EV_KEYPRESS:
+ ch = ev.u.key;
+ if (en->filter)
+ ch = en->filter(co, en->filterData, ch, en->cursorPosition);
+ if (ch) er = entryHandleKey(co, ch);
+ break;
+
+ case EV_MOUSE:
+ if ((ev.u.mouse.type == MOUSE_BUTTON_DOWN) &&
+ (en->flags ^ NEWT_FLAG_HIDDEN)) {
+ if (strlen(en->buf) >= ev.u.mouse.x - co->left) {
+ en->cursorPosition = ev.u.mouse.x - co->left;
+ newtGotorc(co->top,
+ co->left +(en->cursorPosition - en->firstChar));
+ } else {
+ en->cursorPosition = strlen(en->buf);
+ newtGotorc(co->top,
+ co->left +(en->cursorPosition - en->firstChar));
+ }
+ }
+ break;
+ }
} else
- er.result = ER_IGNORED;
+ er.result = ER_IGNORED;
return er;
}
er.result = ER_SWALLOWED;
switch (key) {
- case '\r': /* Return */
- if (en->flags & NEWT_FLAG_RETURNEXIT) {
- er.result = ER_EXITFORM;
- } else {
- er.result = ER_NEXTCOMP;
- }
- break;
-
- case '\001': /* ^A */
+ case '\r': /* Return */
+ if (en->flags & NEWT_FLAG_RETURNEXIT) {
+ er.result = ER_EXITFORM;
+ } else {
+ er.result = ER_NEXTCOMP;
+ }
+ break;
+
+ case '\001': /* ^A */
case NEWT_KEY_HOME:
- en->cursorPosition = 0;
- break;
+ en->cursorPosition = 0;
+ break;
- case '\005': /* ^E */
+ case '\005': /* ^E */
case NEWT_KEY_END:
- en->cursorPosition = en->bufUsed;
- break;
+ en->cursorPosition = en->bufUsed;
+ break;
- case '\013': /* ^K */
- en->bufUsed = en->cursorPosition;
- memset(en->buf + en->bufUsed, 0, en->bufAlloced - en->bufUsed);
- break;
+ case '\013': /* ^K */
+ en->bufUsed = en->cursorPosition;
+ memset(en->buf + en->bufUsed, 0, en->bufAlloced - en->bufUsed);
+ break;
- case '\002': /* ^B */
+ case '\002': /* ^B */
case NEWT_KEY_LEFT:
- if (en->cursorPosition)
- en->cursorPosition--;
- break;
+ if (en->cursorPosition)
+ en->cursorPosition--;
+ break;
case '\004':
case NEWT_KEY_DELETE:
- chptr = en->buf + en->cursorPosition;
- if (*chptr) {
- chptr++;
- while (*chptr) {
- *(chptr - 1) = *chptr;
- chptr++;
- }
- *(chptr - 1) = '\0';
- en->bufUsed--;
- }
- break;
+ chptr = en->buf + en->cursorPosition;
+ if (*chptr) {
+ chptr++;
+ while (*chptr) {
+ *(chptr - 1) = *chptr;
+ chptr++;
+ }
+ *(chptr - 1) = '\0';
+ en->bufUsed--;
+ }
+ break;
case NEWT_KEY_BKSPC:
- if (en->cursorPosition) {
- /* if this isn't true, there's nothing to erase */
- chptr = en->buf + en->cursorPosition;
- en->bufUsed--;
- en->cursorPosition--;
- while (*chptr) {
- *(chptr - 1) = *chptr;
- chptr++;
- }
- *(chptr - 1) = '\0';
- }
- break;
-
- case '\006': /* ^B */
+ if (en->cursorPosition) {
+ /* if this isn't true, there's nothing to erase */
+ chptr = en->buf + en->cursorPosition;
+ en->bufUsed--;
+ en->cursorPosition--;
+ while (*chptr) {
+ *(chptr - 1) = *chptr;
+ chptr++;
+ }
+ *(chptr - 1) = '\0';
+ }
+ break;
+
+ case '\006': /* ^B */
case NEWT_KEY_RIGHT:
- if (en->cursorPosition < en->bufUsed)
- en->cursorPosition++;
- break;
+ if (en->cursorPosition < en->bufUsed)
+ en->cursorPosition++;
+ break;
default:
- if ((key >= 0x20 && key <= 0x7e) || (key >= 0xa0 && key <= 0xff)) {
- if (!(en->flags & NEWT_FLAG_SCROLL) && en->bufUsed >= co->width) {
- SLtt_beep();
- break;
- }
-
- if ((en->bufUsed + 1) == en->bufAlloced) {
- en->bufAlloced += 20;
- en->buf = realloc(en->buf, en->bufAlloced);
- if (en->resultPtr) *en->resultPtr = en->buf;
- memset(en->buf + en->bufUsed + 1, 0, 20);
- }
-
- if (en->cursorPosition == en->bufUsed) {
- en->bufUsed++;
- } else {
- /* insert the new character */
-
- /* chptr is the last character in the string */
- chptr = (en->buf + en->bufUsed) - 1;
- if ((en->bufUsed + 1) == en->bufAlloced) {
- /* this string fills the buffer, so clip it */
- chptr--;
- } else
- en->bufUsed++;
-
- insPoint = en->buf + en->cursorPosition;
-
- while (chptr >= insPoint) {
- *(chptr + 1) = *chptr;
- chptr--;
- }
-
- }
-
- en->buf[en->cursorPosition++] = key;
- } else {
- er.result = ER_IGNORED;
- }
+ if ((key >= 0x20 && key <= 0x7e) || (key >= 0xa0 && key <= 0xff)) {
+ if (!(en->flags & NEWT_FLAG_SCROLL) && en->bufUsed >= co->width) {
+ SLtt_beep();
+ break;
+ }
+
+ if ((en->bufUsed + 1) == en->bufAlloced) {
+ en->bufAlloced += 20;
+ en->buf = realloc(en->buf, en->bufAlloced);
+ if (en->resultPtr) *en->resultPtr = en->buf;
+ memset(en->buf + en->bufUsed + 1, 0, 20);
+ }
+
+ if (en->cursorPosition == en->bufUsed) {
+ en->bufUsed++;
+ } else {
+ /* insert the new character */
+
+ /* chptr is the last character in the string */
+ chptr = (en->buf + en->bufUsed) - 1;
+ if ((en->bufUsed + 1) == en->bufAlloced) {
+ /* this string fills the buffer, so clip it */
+ chptr--;
+ } else
+ en->bufUsed++;
+
+ insPoint = en->buf + en->cursorPosition;
+
+ while (chptr >= insPoint) {
+ *(chptr + 1) = *chptr;
+ chptr--;
+ }
+
+ }
+
+ en->buf[en->cursorPosition++] = key;
+ } else {
+ er.result = ER_IGNORED;
+ }
}
entryDraw(co);
*****************************************************************************/
struct element {
- int top, left; /* Actual, not virtual. These are translated */
- newtComponent co; /* into actual through vertOffset */
+ int top, left; /* Actual, not virtual. These are translated */
+ newtComponent co; /* into actual through vertOffset */
};
struct fdInfo {
if ((co->top + form->vertOffset) > el->top) return 0;
if ((co->top + form->vertOffset + co->height) <
- (el->top + el->co->height)) return 0;
+ (el->top + el->co->height)) return 0;
return 1;
}
co->left = -1;
co->isMapped = 0;
- co->takesFocus = 0; /* we may have 0 components */
+ co->takesFocus = 0; /* we may have 0 components */
co->ops = &formOps;
form->help = help;
form->timer = 0;
form->lastTimeout.tv_sec = form->lastTimeout.tv_usec = 0;
if (!(form->flags & NEWT_FLAG_NOF12)) {
- newtFormAddHotKey(co, NEWT_KEY_F12);
+ newtFormAddHotKey(co, NEWT_KEY_F12);
}
if (vertBar)
- form->vertBar = vertBar;
+ form->vertBar = vertBar;
else
- form->vertBar = NULL;
+ form->vertBar = NULL;
form->helpTag = help;
form->helpCb = helpCallback;
int i, new;
for (i = 0; i < form->numComps; i++) {
- if (form->elements[i].co == subco) break;
+ if (form->elements[i].co == subco) break;
}
if (form->elements[i].co != subco) return;
new = i;
if (co->isMapped && !componentFits(co, new)) {
- gotoComponent(form, -1);
- form->vertOffset = form->elements[new].top - co->top - 1;
- if (form->vertOffset > (form->numRows - co->height))
- form->vertOffset = form->numRows - co->height;
+ gotoComponent(form, -1);
+ form->vertOffset = form->elements[new].top - co->top - 1;
+ if (form->vertOffset > (form->numRows - co->height))
+ form->vertOffset = form->numRows - co->height;
}
gotoComponent(form, new);
co->takesFocus = 1;
if (form->numCompsAlloced == form->numComps) {
- form->numCompsAlloced += 5;
- form->elements = realloc(form->elements,
- sizeof(*(form->elements)) * form->numCompsAlloced);
+ form->numCompsAlloced += 5;
+ form->elements = realloc(form->elements,
+ sizeof(*(form->elements)) * form->numCompsAlloced);
}
/* we grab real values for these a bit later */
form->elements[form->numComps].co = newco;
if (newco->takesFocus && form->currComp == -1)
- form->currComp = form->numComps;
+ form->currComp = form->numComps;
form->numComps++;
}
va_start(ap, co);
while ((subco = va_arg(ap, newtComponent)))
- newtFormAddComponent(co, subco);
+ newtFormAddComponent(co, subco);
va_end(ap);
}
co->left = left;
for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
- el->co->top += vertDelta;
- el->top += vertDelta;
- el->co->left += horizDelta;
- el->left += horizDelta;
+ el->co->top += vertDelta;
+ el->top += vertDelta;
+ el->co->left += horizDelta;
+ el->left += horizDelta;
}
}
newtClearBox(co->left, co->top, co->width, co->height);
for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
- /* the scrollbar *always* fits somewhere */
- if (el->co == form->vertBar) {
- el->co->ops->mapped(el->co, 1);
- el->co->ops->draw(el->co);
- } else {
- /* only draw it if it'll fit on the screen vertically */
- if (componentFits(co, i)) {
- el->co->top = el->top - form->vertOffset;
- el->co->ops->mapped(el->co, 1);
- el->co->ops->draw(el->co);
- } else {
- el->co->ops->mapped(el->co, 0);
- }
- }
+ /* the scrollbar *always* fits somewhere */
+ if (el->co == form->vertBar) {
+ el->co->ops->mapped(el->co, 1);
+ el->co->ops->draw(el->co);
+ } else {
+ /* only draw it if it'll fit on the screen vertically */
+ if (componentFits(co, i)) {
+ el->co->top = el->top - form->vertOffset;
+ el->co->ops->mapped(el->co, 1);
+ el->co->ops->draw(el->co);
+ } else {
+ el->co->ops->mapped(el->co, 0);
+ }
+ }
}
if (form->vertBar)
- newtScrollbarSet(form->vertBar, form->vertOffset,
- form->numRows - co->height);
+ newtScrollbarSet(form->vertBar, form->vertOffset,
+ form->numRows - co->height);
}
static struct eventResult formEvent(newtComponent co, struct event ev) {
switch (ev.when) {
case EV_EARLY:
- if (ev.event == EV_KEYPRESS) {
- if (ev.u.key == NEWT_KEY_TAB) {
- er.result = ER_SWALLOWED;
- dir = 1;
- wrap = 1;
- } else if (ev.u.key == NEWT_KEY_UNTAB) {
- er.result = ER_SWALLOWED;
- dir = -1;
- wrap = 1;
- }
- }
-
- if (form->numComps) {
- i = form->currComp;
- num = 0;
- while (er.result == ER_IGNORED && num != form->numComps ) {
- er = form->elements[i].co->ops->event(form->elements[i].co, ev);
-
- num++;
- i++;
- if (i == form->numComps) i = 0;
- }
- }
-
- break;
+ if (ev.event == EV_KEYPRESS) {
+ if (ev.u.key == NEWT_KEY_TAB) {
+ er.result = ER_SWALLOWED;
+ dir = 1;
+ wrap = 1;
+ } else if (ev.u.key == NEWT_KEY_UNTAB) {
+ er.result = ER_SWALLOWED;
+ dir = -1;
+ wrap = 1;
+ }
+ }
+
+ if (form->numComps) {
+ i = form->currComp;
+ num = 0;
+ while (er.result == ER_IGNORED && num != form->numComps ) {
+ er = form->elements[i].co->ops->event(form->elements[i].co, ev);
+
+ num++;
+ i++;
+ if (i == form->numComps) i = 0;
+ }
+ }
+
+ break;
case EV_NORMAL:
- if (ev.event == EV_MOUSE) {
- found = 0;
- for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
- if ((el->co->top <= ev.u.mouse.y) &&
- (el->co->top + el->co->height > ev.u.mouse.y) &&
- (el->co->left <= ev.u.mouse.x) &&
- (el->co->left + el->co->width > ev.u.mouse.x)) {
- found = 1;
- if (el->co->takesFocus) {
- gotoComponent(form, i);
- subco = form->elements[form->currComp].co;
- }
- }
- /* If we did not find a co to send this event to, we
- should just swallow the event here. */
- }
- if (!found) {
- er.result = ER_SWALLOWED;
-
- return er;
- }
- }
- er = subco->ops->event(subco, ev);
- switch (er.result) {
- case ER_NEXTCOMP:
- er.result = ER_SWALLOWED;
- dir = 1;
- break;
-
- case ER_EXITFORM:
- form->exitComp = subco;
- break;
-
- default:
- break;
- }
- break;
+ if (ev.event == EV_MOUSE) {
+ found = 0;
+ for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
+ if ((el->co->top <= ev.u.mouse.y) &&
+ (el->co->top + el->co->height > ev.u.mouse.y) &&
+ (el->co->left <= ev.u.mouse.x) &&
+ (el->co->left + el->co->width > ev.u.mouse.x)) {
+ found = 1;
+ if (el->co->takesFocus) {
+ gotoComponent(form, i);
+ subco = form->elements[form->currComp].co;
+ }
+ }
+ /* If we did not find a co to send this event to, we
+ should just swallow the event here. */
+ }
+ if (!found) {
+ er.result = ER_SWALLOWED;
+
+ return er;
+ }
+ }
+ er = subco->ops->event(subco, ev);
+ switch (er.result) {
+ case ER_NEXTCOMP:
+ er.result = ER_SWALLOWED;
+ dir = 1;
+ break;
+
+ case ER_EXITFORM:
+ form->exitComp = subco;
+ break;
+
+ default:
+ break;
+ }
+ break;
case EV_LATE:
- er = subco->ops->event(subco, ev);
-
- if (er.result == ER_IGNORED) {
- switch (ev.u.key) {
- case NEWT_KEY_UP:
- case NEWT_KEY_LEFT:
- case NEWT_KEY_BKSPC:
- er.result = ER_SWALLOWED;
- dir = -1;
- break;
-
- case NEWT_KEY_DOWN:
- case NEWT_KEY_RIGHT:
- er.result = ER_SWALLOWED;
- dir = 1;
- break;
-
- case NEWT_KEY_PGUP:
- er.result = ER_SWALLOWED;
- dir = -1;
- page = 1;
- break;
-
- case NEWT_KEY_PGDN:
- er.result = ER_SWALLOWED;
- dir = 1;
- page = 1;
- break;
- }
- }
+ er = subco->ops->event(subco, ev);
+
+ if (er.result == ER_IGNORED) {
+ switch (ev.u.key) {
+ case NEWT_KEY_UP:
+ case NEWT_KEY_LEFT:
+ case NEWT_KEY_BKSPC:
+ er.result = ER_SWALLOWED;
+ dir = -1;
+ break;
+
+ case NEWT_KEY_DOWN:
+ case NEWT_KEY_RIGHT:
+ er.result = ER_SWALLOWED;
+ dir = 1;
+ break;
+
+ case NEWT_KEY_PGUP:
+ er.result = ER_SWALLOWED;
+ dir = -1;
+ page = 1;
+ break;
+
+ case NEWT_KEY_PGDN:
+ er.result = ER_SWALLOWED;
+ dir = 1;
+ page = 1;
+ break;
+ }
+ }
}
if (dir) {
- new = form->currComp;
-
- if (page) {
- new += dir * co->height;
- if (new < 0)
- new = 0;
- else if (new >= form->numComps)
- new = (form->numComps - 1);
-
- while (!form->elements[new].co->takesFocus)
- new = new - dir;
- } else {
- do {
- new += dir;
-
- if (wrap) {
- if (new < 0)
- new = form->numComps - 1;
- else if (new >= form->numComps)
- new = 0;
- } else if (new < 0 || new >= form->numComps)
- return er;
- } while (!form->elements[new].co->takesFocus);
- }
-
- /* make sure this component is visible */
- if (!componentFits(co, new)) {
- gotoComponent(form, -1);
-
- if (dir < 0) {
- /* make the new component the first one */
- form->vertOffset = form->elements[new].top - co->top;
- } else {
- /* make the new component the last one */
- form->vertOffset = (form->elements[new].top +
- form->elements[new].co->height) -
- (co->top + co->height);
- }
-
- if (form->vertOffset < 0) form->vertOffset = 0;
- if (form->vertOffset > (form->numRows - co->height))
- form->vertOffset = form->numRows - co->height;
-
- newtDrawForm(co);
- }
-
- gotoComponent(form, new);
- er.result = ER_SWALLOWED;
+ new = form->currComp;
+
+ if (page) {
+ new += dir * co->height;
+ if (new < 0)
+ new = 0;
+ else if (new >= form->numComps)
+ new = (form->numComps - 1);
+
+ while (!form->elements[new].co->takesFocus)
+ new = new - dir;
+ } else {
+ do {
+ new += dir;
+
+ if (wrap) {
+ if (new < 0)
+ new = form->numComps - 1;
+ else if (new >= form->numComps)
+ new = 0;
+ } else if (new < 0 || new >= form->numComps)
+ return er;
+ } while (!form->elements[new].co->takesFocus);
+ }
+
+ /* make sure this component is visible */
+ if (!componentFits(co, new)) {
+ gotoComponent(form, -1);
+
+ if (dir < 0) {
+ /* make the new component the first one */
+ form->vertOffset = form->elements[new].top - co->top;
+ } else {
+ /* make the new component the last one */
+ form->vertOffset = (form->elements[new].top +
+ form->elements[new].co->height) -
+ (co->top + co->height);
+ }
+
+ if (form->vertOffset < 0) form->vertOffset = 0;
+ if (form->vertOffset > (form->numRows - co->height))
+ form->vertOffset = form->numRows - co->height;
+
+ newtDrawForm(co);
+ }
+
+ gotoComponent(form, new);
+ er.result = ER_SWALLOWED;
}
return er;
/* first, destroy all of the components */
for (i = 0; i < form->numComps; i++) {
- subco = form->elements[i].co;
- if (subco->ops->destroy) {
- subco->ops->destroy(subco);
- } else {
- if (subco->data) free(subco->data);
- free(subco);
- }
+ subco = form->elements[i].co;
+ if (subco->ops->destroy) {
+ subco->ops->destroy(subco);
+ } else {
+ if (subco->data) free(subco->data);
+ free(subco);
+ }
}
if (form->hotKeys) free(form->hotKeys);
newtFormRun(co, &es);
if (es.reason == NEWT_EXIT_HOTKEY) {
- if (es.u.key == NEWT_KEY_F12) {
- es.reason = NEWT_EXIT_COMPONENT;
- es.u.co = co;
- } else {
- return NULL;
- }
+ if (es.u.key == NEWT_KEY_F12) {
+ es.reason = NEWT_EXIT_COMPONENT;
+ es.u.co = co;
+ } else {
+ return NULL;
+ }
}
return es.u.co;
co->top = form->elements[0].co->top;
co->left = form->elements[0].co->left;
for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
- if (el->co->ops == &formOps)
- newtFormSetSize(el->co);
-
- el->left = el->co->left;
- el->top = el->co->top;
-
- if (co->left > el->co->left) {
- delta = co->left - el->co->left;
- co->left -= delta;
- co->width += delta;
- }
-
- if (co->top > el->co->top) {
- delta = co->top - el->co->top;
- co->top -= delta;
- if (!form->fixedHeight)
- co->height += delta;
- }
-
- if ((co->left + co->width) < (el->co->left + el->co->width))
- co->width = (el->co->left + el->co->width) - co->left;
-
- if (!form->fixedHeight) {
- if ((co->top + co->height) < (el->co->top + el->co->height))
- co->height = (el->co->top + el->co->height) - co->top;
- }
-
- if ((el->co->top + el->co->height - co->top) > form->numRows) {
- form->numRows = el->co->top + el->co->height - co->top;
- }
+ if (el->co->ops == &formOps)
+ newtFormSetSize(el->co);
+
+ el->left = el->co->left;
+ el->top = el->co->top;
+
+ if (co->left > el->co->left) {
+ delta = co->left - el->co->left;
+ co->left -= delta;
+ co->width += delta;
+ }
+
+ if (co->top > el->co->top) {
+ delta = co->top - el->co->top;
+ co->top -= delta;
+ if (!form->fixedHeight)
+ co->height += delta;
+ }
+
+ if ((co->left + co->width) < (el->co->left + el->co->width))
+ co->width = (el->co->left + el->co->width) - co->left;
+
+ if (!form->fixedHeight) {
+ if ((co->top + co->height) < (el->co->top + el->co->height))
+ co->height = (el->co->top + el->co->height) - co->top;
+ }
+
+ if ((el->co->top + el->co->height - co->top) > form->numRows) {
+ form->numRows = el->co->top + el->co->height - co->top;
+ }
}
}
newtDrawForm(co);
if (form->currComp == -1) {
- gotoComponent(form, 0);
+ gotoComponent(form, 0);
} else
- gotoComponent(form, form->currComp);
+ gotoComponent(form, form->currComp);
while (!done) {
- newtRefresh();
+ newtRefresh();
- FD_ZERO(&readSet);
- FD_ZERO(&writeSet);
- FD_ZERO(&exceptSet);
- FD_SET(0, &readSet);
+ FD_ZERO(&readSet);
+ FD_ZERO(&writeSet);
+ FD_ZERO(&exceptSet);
+ FD_SET(0, &readSet);
#ifdef USE_GPM
- if (gpm_fd > 0) {
- FD_SET(gpm_fd, &readSet);
- }
- max = form->maxFd > gpm_fd ? form->maxFd : gpm_fd;
+ if (gpm_fd > 0) {
+ FD_SET(gpm_fd, &readSet);
+ }
+ max = form->maxFd > gpm_fd ? form->maxFd : gpm_fd;
#else
- max = form->maxFd;
+ max = form->maxFd;
#endif
- for (i = 0; i < form->numFds; i++) {
- if (form->fds[i].flags & NEWT_FD_READ)
- FD_SET(form->fds[i].fd, &readSet);
- if (form->fds[i].flags & NEWT_FD_WRITE)
- FD_SET(form->fds[i].fd, &writeSet);
- if (form->fds[i].flags & NEWT_FD_EXCEPT)
- FD_SET(form->fds[i].fd, &exceptSet);
- }
-
- if (form->timer) {
- /* Calculate when we next need to return with a timeout. Do
- this inside the loop in case a callback resets the timer. */
- if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec)
- gettimeofday(&form->lastTimeout, NULL);
-
- nextTimeout.tv_sec = form->lastTimeout.tv_sec +
- (form->timer / 1000);
- nextTimeout.tv_usec = form->lastTimeout.tv_usec +
- (form->timer % 1000) * 1000;
-
- gettimeofday(&now, 0);
-
- if (now.tv_sec > nextTimeout.tv_sec) {
- timeout.tv_sec = timeout.tv_usec = 0;
- } else if (now.tv_sec == nextTimeout.tv_sec) {
- timeout.tv_sec = 0;
- if (now.tv_usec > nextTimeout.tv_usec)
- timeout.tv_usec = 0;
- else
- timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
- } else if (now.tv_sec < nextTimeout.tv_sec) {
- timeout.tv_sec = nextTimeout.tv_sec - now.tv_sec;
- if (now.tv_usec > nextTimeout.tv_usec)
- timeout.tv_sec--,
- timeout.tv_usec = nextTimeout.tv_usec + 1000000 -
- now.tv_usec;
- else
- timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
- }
- } else {
- timeout.tv_sec = timeout.tv_usec = 0;
- }
-
- i = select(max + 1, &readSet, &writeSet, &exceptSet,
- form->timer ? &timeout : NULL);
- if (i < 0) continue; /* ?? What should we do here? */
-
- if (i == 0) {
- done = 1;
- es->reason = NEWT_EXIT_TIMER;
- gettimeofday(&form->lastTimeout, NULL);
- } else
+ for (i = 0; i < form->numFds; i++) {
+ if (form->fds[i].flags & NEWT_FD_READ)
+ FD_SET(form->fds[i].fd, &readSet);
+ if (form->fds[i].flags & NEWT_FD_WRITE)
+ FD_SET(form->fds[i].fd, &writeSet);
+ if (form->fds[i].flags & NEWT_FD_EXCEPT)
+ FD_SET(form->fds[i].fd, &exceptSet);
+ }
+
+ if (form->timer) {
+ /* Calculate when we next need to return with a timeout. Do
+ this inside the loop in case a callback resets the timer. */
+ if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec)
+ gettimeofday(&form->lastTimeout, NULL);
+
+ nextTimeout.tv_sec = form->lastTimeout.tv_sec +
+ (form->timer / 1000);
+ nextTimeout.tv_usec = form->lastTimeout.tv_usec +
+ (form->timer % 1000) * 1000;
+
+ gettimeofday(&now, 0);
+
+ if (now.tv_sec > nextTimeout.tv_sec) {
+ timeout.tv_sec = timeout.tv_usec = 0;
+ } else if (now.tv_sec == nextTimeout.tv_sec) {
+ timeout.tv_sec = 0;
+ if (now.tv_usec > nextTimeout.tv_usec)
+ timeout.tv_usec = 0;
+ else
+ timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
+ } else if (now.tv_sec < nextTimeout.tv_sec) {
+ timeout.tv_sec = nextTimeout.tv_sec - now.tv_sec;
+ if (now.tv_usec > nextTimeout.tv_usec)
+ timeout.tv_sec--,
+ timeout.tv_usec = nextTimeout.tv_usec + 1000000 -
+ now.tv_usec;
+ else
+ timeout.tv_usec = nextTimeout.tv_usec - now.tv_usec;
+ }
+ } else {
+ timeout.tv_sec = timeout.tv_usec = 0;
+ }
+
+ i = select(max + 1, &readSet, &writeSet, &exceptSet,
+ form->timer ? &timeout : NULL);
+ if (i < 0) continue; /* ?? What should we do here? */
+
+ if (i == 0) {
+ done = 1;
+ es->reason = NEWT_EXIT_TIMER;
+ gettimeofday(&form->lastTimeout, NULL);
+ } else
#ifdef USE_GPM
- if (gpm_fd > 0 && FD_ISSET(gpm_fd, &readSet)) {
- Gpm_GetEvent(&event);
+ if (gpm_fd > 0 && FD_ISSET(gpm_fd, &readSet)) {
+ Gpm_GetEvent(&event);
- if (event.type & GPM_DOWN) {
- /* Transform coordinates to current window */
- newtGetWindowPos(&x, &y);
+ if (event.type & GPM_DOWN) {
+ /* Transform coordinates to current window */
+ newtGetWindowPos(&x, &y);
- ev.event = EV_MOUSE;
- ev.u.mouse.type = MOUSE_BUTTON_DOWN;
- ev.u.mouse.x = event.x - x - 1;
- ev.u.mouse.y = event.y - y - 1;
+ ev.event = EV_MOUSE;
+ ev.u.mouse.type = MOUSE_BUTTON_DOWN;
+ ev.u.mouse.x = event.x - x - 1;
+ ev.u.mouse.y = event.y - y - 1;
- /* Send the form the event */
- er = sendEvent(co, ev);
+ /* Send the form the event */
+ er = sendEvent(co, ev);
- if (er.result == ER_EXITFORM) {
- done = 1;
- es->reason = NEWT_EXIT_COMPONENT;
- es->u.co = form->exitComp;
- }
+ if (er.result == ER_EXITFORM) {
+ done = 1;
+ es->reason = NEWT_EXIT_COMPONENT;
+ es->u.co = form->exitComp;
+ }
- }
- } else
+ }
+ } else
#endif
- {
- if (FD_ISSET(0, &readSet)) {
-
- key = newtGetKey();
-
- if (key == NEWT_KEY_RESIZE) {
- newtResizeScreen(1);
- continue;
- }
-
- for (i = 0; i < form->numHotKeys; i++) {
- if (form->hotKeys[i] == key) {
- es->reason = NEWT_EXIT_HOTKEY;
- es->u.key = key;
- done = 1;
- break;
- }
- }
-
- if (key == NEWT_KEY_F1 && form->helpTag && form->helpCb)
- form->helpCb(co, form->helpTag);
-
- if (!done) {
- ev.event = EV_KEYPRESS;
- ev.u.key = key;
-
- er = sendEvent(co, ev);
-
- if (er.result == ER_EXITFORM) {
- done = 1;
- es->reason = NEWT_EXIT_COMPONENT;
- es->u.co = form->exitComp;
- }
- }
- } else {
- for (i = 0; i < form->numFds; i++) {
- if (((form->fds[i].flags & NEWT_FD_READ)
- && FD_ISSET(form->fds[i].fd, &readSet))
- || ((form->fds[i].flags & NEWT_FD_WRITE)
- && FD_ISSET(form->fds[i].fd, &writeSet))
- || ((form->fds[i].flags & NEWT_FD_EXCEPT)
- && FD_ISSET(form->fds[i].fd, &exceptSet))) break;
- }
- if(i < form->numFds)
- es->u.watch = form->fds[i].fd;
- else
- es->u.watch = -1;
-
- es->reason = NEWT_EXIT_FDREADY;
- done = 1;
- }
- }
+ {
+ if (FD_ISSET(0, &readSet)) {
+
+ key = newtGetKey();
+
+ if (key == NEWT_KEY_RESIZE) {
+ newtResizeScreen(1);
+ continue;
+ }
+
+ for (i = 0; i < form->numHotKeys; i++) {
+ if (form->hotKeys[i] == key) {
+ es->reason = NEWT_EXIT_HOTKEY;
+ es->u.key = key;
+ done = 1;
+ break;
+ }
+ }
+
+ if (key == NEWT_KEY_F1 && form->helpTag && form->helpCb)
+ form->helpCb(co, form->helpTag);
+
+ if (!done) {
+ ev.event = EV_KEYPRESS;
+ ev.u.key = key;
+
+ er = sendEvent(co, ev);
+
+ if (er.result == ER_EXITFORM) {
+ done = 1;
+ es->reason = NEWT_EXIT_COMPONENT;
+ es->u.co = form->exitComp;
+ }
+ }
+ } else {
+ for (i = 0; i < form->numFds; i++) {
+ if (((form->fds[i].flags & NEWT_FD_READ)
+ && FD_ISSET(form->fds[i].fd, &readSet))
+ || ((form->fds[i].flags & NEWT_FD_WRITE)
+ && FD_ISSET(form->fds[i].fd, &writeSet))
+ || ((form->fds[i].flags & NEWT_FD_EXCEPT)
+ && FD_ISSET(form->fds[i].fd, &exceptSet))) break;
+ }
+ if(i < form->numFds)
+ es->u.watch = form->fds[i].fd;
+ else
+ es->u.watch = -1;
+
+ es->reason = NEWT_EXIT_FDREADY;
+ done = 1;
+ }
+ }
}
newtRefresh();
#ifdef USE_GPM
er = co->ops->event(co, ev);
if (er.result == ER_IGNORED) {
- ev.when = EV_NORMAL;
- er = co->ops->event(co, ev);
+ ev.when = EV_NORMAL;
+ er = co->ops->event(co, ev);
}
if (er.result == ER_IGNORED) {
- ev.when = EV_LATE;
- er = co->ops->event(co, ev);
+ ev.when = EV_LATE;
+ er = co->ops->event(co, ev);
}
return er;
struct event ev;
if (form->currComp != -1) {
- ev.event = EV_UNFOCUS;
- sendEvent(form->elements[form->currComp].co, ev);
+ ev.event = EV_UNFOCUS;
+ sendEvent(form->elements[form->currComp].co, ev);
}
form->currComp = newComp;
if (form->currComp != -1) {
- ev.event = EV_FOCUS;
- ev.when = EV_NORMAL;
- sendEvent(form->elements[form->currComp].co, ev);
+ ev.event = EV_FOCUS;
+ ev.when = EV_NORMAL;
+ sendEvent(form->elements[form->currComp].co, ev);
}
}
for (i = 0; i < form->numFds; i++)
if (form->fds[i].fd == fd)
- break;
+ break;
if(i >= form->numFds)
form->fds = realloc(form->fds, (++form->numFds) * sizeof(*form->fds));
struct gridField {
enum newtGridElement type;
union {
- newtGrid grid;
- newtComponent co;
+ newtGrid grid;
+ newtComponent co;
} u;
int padLeft, padTop, padRight, padBottom;
int anchor;
struct grid_s {
int rows, cols;
- int width, height; /* totals, -1 means unknown */
+ int width, height; /* totals, -1 means unknown */
struct gridField ** fields;
};
grid->fields = malloc(sizeof(*grid->fields) * cols);
while (cols--) {
- grid->fields[cols] = malloc(sizeof(**(grid->fields)) * rows);
- memset(grid->fields[cols], 0, sizeof(**(grid->fields)) * rows);
+ grid->fields[cols] = malloc(sizeof(**(grid->fields)) * rows);
+ memset(grid->fields[cols], 0, sizeof(**(grid->fields)) * rows);
}
grid->width = grid->height = -1;
}
void newtGridSetField(newtGrid grid, int col, int row,
- enum newtGridElement type, void * val, int padLeft,
- int padTop, int padRight, int padBottom, int anchor,
- int flags) {
+ enum newtGridElement type, void * val, int padLeft,
+ int padTop, int padRight, int padBottom, int anchor,
+ int flags) {
struct gridField * field = &grid->fields[col][row];
if (field->type == NEWT_GRID_SUBGRID)
- newtGridFree(field->u.grid, 1);
+ newtGridFree(field->u.grid, 1);
field->type = type;
field->u.co = (void *) val;
all = extra / items;
some = extra % items;
for (i = 0; i < items; i++) {
- list[i] += all;
- if (some) {
- list[i]++;
- some--;
- }
+ list[i] += all;
+ if (some) {
+ list[i]++;
+ some--;
+ }
}
}
minWidth = 0;
for (row = 0; row < grid->rows; row++) {
- i = 0;
- for (col = 0; col < grid->cols; col++) {
- field = &grid->fields[col][row];
- if (field->type == NEWT_GRID_SUBGRID) {
- /* we'll have to redo this later */
- if (field->u.grid->width == -1)
- shuffleGrid(field->u.grid, left, top, 0);
- j = field->u.grid->width;
- } else if (field->type == NEWT_GRID_COMPONENT) {
- if (field->u.co->ops == formOps)
- newtFormSetSize(field->u.co);
- j = field->u.co->width;
- } else
- j = 0;
-
- j += field->padLeft + field->padRight;
-
- if (j > widths[col]) widths[col] = j;
- i += widths[col];
- }
-
- if (i > minWidth) minWidth = i;
+ i = 0;
+ for (col = 0; col < grid->cols; col++) {
+ field = &grid->fields[col][row];
+ if (field->type == NEWT_GRID_SUBGRID) {
+ /* we'll have to redo this later */
+ if (field->u.grid->width == -1)
+ shuffleGrid(field->u.grid, left, top, 0);
+ j = field->u.grid->width;
+ } else if (field->type == NEWT_GRID_COMPONENT) {
+ if (field->u.co->ops == formOps)
+ newtFormSetSize(field->u.co);
+ j = field->u.co->width;
+ } else
+ j = 0;
+
+ j += field->padLeft + field->padRight;
+
+ if (j > widths[col]) widths[col] = j;
+ i += widths[col];
+ }
+
+ if (i > minWidth) minWidth = i;
}
minHeight = 0;
for (col = 0; col < grid->cols; col++) {
- i = 0;
- for (row = 0; row < grid->rows; row++) {
- field = &grid->fields[col][row];
- if (field->type == NEWT_GRID_SUBGRID) {
- /* we'll have to redo this later */
- if (field->u.grid->height == -1)
- shuffleGrid(field->u.grid, 0, 0, 0);
- j = field->u.grid->height;
- } else if (field->type == NEWT_GRID_COMPONENT){
- j = field->u.co->height;
- } else
- j = 0;
-
- j += field->padTop + field->padBottom;
-
- if (j > heights[row]) heights[row] = j;
- i += heights[row];
- }
-
- if (i > minHeight) minHeight = i;
+ i = 0;
+ for (row = 0; row < grid->rows; row++) {
+ field = &grid->fields[col][row];
+ if (field->type == NEWT_GRID_SUBGRID) {
+ /* we'll have to redo this later */
+ if (field->u.grid->height == -1)
+ shuffleGrid(field->u.grid, 0, 0, 0);
+ j = field->u.grid->height;
+ } else if (field->type == NEWT_GRID_COMPONENT){
+ j = field->u.co->height;
+ } else
+ j = 0;
+
+ j += field->padTop + field->padBottom;
+
+ if (j > heights[row]) heights[row] = j;
+ i += heights[row];
+ }
+
+ if (i > minHeight) minHeight = i;
}
/* this catches the -1 case */
- if (grid->width < minWidth) grid->width = minWidth; /* ack! */
- if (grid->height < minHeight) grid->height = minHeight; /* ditto! */
+ if (grid->width < minWidth) grid->width = minWidth; /* ack! */
+ if (grid->height < minHeight) grid->height = minHeight; /* ditto! */
if (!set) return;
thisTop = top;
for (row = 0; row < grid->rows; row++) {
- i = 0;
- thisLeft = left;
- for (col = 0; col < grid->cols; col++) {
- field = &grid->fields[col][row];
-
- if (field->type == NEWT_GRID_EMPTY) continue;
-
- x = thisLeft + field->padLeft;
- remx = widths[col] - field->padLeft - field->padRight;
- y = thisTop + field->padTop;
- remy = heights[row] - field->padTop - field->padBottom;
-
- if (field->type == NEWT_GRID_SUBGRID) {
- remx -= field->u.grid->width;
- remy -= field->u.grid->height;
- } else if (field->type == NEWT_GRID_COMPONENT) {
- remx -= field->u.co->width;
- remy -= field->u.co->height;
- }
-
- if (!(field->flags & NEWT_GRID_FLAG_GROWX)) {
- if (field->anchor & NEWT_ANCHOR_RIGHT)
- x += remx;
- else if (!(field->anchor & NEWT_ANCHOR_LEFT))
- x += (remx / 2);
- }
-
- if (!(field->flags & NEWT_GRID_FLAG_GROWY)) {
- if (field->anchor & NEWT_ANCHOR_BOTTOM)
- y += remx;
- else if (!(field->anchor & NEWT_ANCHOR_TOP))
- y += (remy / 2);
- }
-
- if (field->type == NEWT_GRID_SUBGRID) {
- if (field->flags & NEWT_GRID_FLAG_GROWX)
- field->u.grid->width = widths[col] - field->padLeft
- - field->padRight;
- if (field->flags & NEWT_GRID_FLAG_GROWY)
- field->u.grid->height = heights[col] - field->padTop
- - field->padBottom;
-
- shuffleGrid(field->u.grid, x, y, 1);
- } else if (field->type == NEWT_GRID_COMPONENT) {
- field->u.co->ops->place(field->u.co, x, y);
- }
-
- thisLeft += widths[col];
- }
-
- thisTop += heights[row];
+ i = 0;
+ thisLeft = left;
+ for (col = 0; col < grid->cols; col++) {
+ field = &grid->fields[col][row];
+
+ if (field->type == NEWT_GRID_EMPTY) continue;
+
+ x = thisLeft + field->padLeft;
+ remx = widths[col] - field->padLeft - field->padRight;
+ y = thisTop + field->padTop;
+ remy = heights[row] - field->padTop - field->padBottom;
+
+ if (field->type == NEWT_GRID_SUBGRID) {
+ remx -= field->u.grid->width;
+ remy -= field->u.grid->height;
+ } else if (field->type == NEWT_GRID_COMPONENT) {
+ remx -= field->u.co->width;
+ remy -= field->u.co->height;
+ }
+
+ if (!(field->flags & NEWT_GRID_FLAG_GROWX)) {
+ if (field->anchor & NEWT_ANCHOR_RIGHT)
+ x += remx;
+ else if (!(field->anchor & NEWT_ANCHOR_LEFT))
+ x += (remx / 2);
+ }
+
+ if (!(field->flags & NEWT_GRID_FLAG_GROWY)) {
+ if (field->anchor & NEWT_ANCHOR_BOTTOM)
+ y += remx;
+ else if (!(field->anchor & NEWT_ANCHOR_TOP))
+ y += (remy / 2);
+ }
+
+ if (field->type == NEWT_GRID_SUBGRID) {
+ if (field->flags & NEWT_GRID_FLAG_GROWX)
+ field->u.grid->width = widths[col] - field->padLeft
+ - field->padRight;
+ if (field->flags & NEWT_GRID_FLAG_GROWY)
+ field->u.grid->height = heights[col] - field->padTop
+ - field->padBottom;
+
+ shuffleGrid(field->u.grid, x, y, 1);
+ } else if (field->type == NEWT_GRID_COMPONENT) {
+ field->u.co->ops->place(field->u.co, x, y);
+ }
+
+ thisLeft += widths[col];
+ }
+
+ thisTop += heights[row];
}
}
int row, col;
for (col = 0; col < grid->cols; col++) {
- if (recurse) {
- for (row = 0; row < grid->rows; row++) {
- if (grid->fields[col][row].type == NEWT_GRID_SUBGRID)
- newtGridFree(grid->fields[col][row].u.grid, 1);
- }
- }
-
- free(grid->fields[col]);
+ if (recurse) {
+ for (row = 0; row < grid->rows; row++) {
+ if (grid->fields[col][row].type == NEWT_GRID_SUBGRID)
+ newtGridFree(grid->fields[col][row].u.grid, 1);
+ }
+ }
+
+ free(grid->fields[col]);
}
free(grid->fields);
void newtGridGetSize(newtGrid grid, int * width, int * height) {
if (grid->width == -1 || grid->height == -1) {
- grid->width = grid->height = -1;
- shuffleGrid(grid, 0, 0, 1);
+ grid->width = grid->height = -1;
+ shuffleGrid(grid, 0, 0, 1);
}
*width = grid->width;
newtGridGetSize(grid, &width, &height);
w = wstrlen(title,-1);
if (width < w + 2) {
- offset = ((w + 2) - width) / 2;
- width = w + 2;
+ offset = ((w + 2) - width) / 2;
+ width = w + 2;
}
newtCenteredWindow(width + 2, height + 2, title);
newtGridPlace(grid, 1 + offset, 1);
}
void newtGridAddComponentsToForm(newtGrid grid, newtComponent form,
- int recurse) {
+ int recurse) {
int row, col;
for (col = 0; col < grid->cols; col++) {
- for (row = 0; row < grid->rows; row++) {
- if (grid->fields[col][row].type == NEWT_GRID_SUBGRID && recurse)
- newtGridAddComponentsToForm(grid->fields[col][row].u.grid,
- form, 1);
- else if (grid->fields[col][row].type == NEWT_GRID_COMPONENT)
- newtFormAddComponent(form, grid->fields[col][row].u.co);
- }
+ for (row = 0; row < grid->rows; row++) {
+ if (grid->fields[col][row].type == NEWT_GRID_SUBGRID && recurse)
+ newtGridAddComponentsToForm(grid->fields[col][row].u.grid,
+ form, 1);
+ else if (grid->fields[col][row].type == NEWT_GRID_COMPONENT)
+ newtFormAddComponent(form, grid->fields[col][row].u.co);
+ }
}
}
/* this handles up to 50 items */
static newtGrid stackem(int isVert, enum newtGridElement type1, void * what1,
- va_list args, int close) {
+ va_list args, int close) {
struct item {
- enum newtGridElement type;
- void * what;
+ enum newtGridElement type;
+ void * what;
} items[50];
int i, num;
newtGrid grid;
items[0].type = type1, items[0].what = what1, num = 1;
while (1) {
- items[num].type = va_arg(args, enum newtGridElement);
- if (items[num].type == NEWT_GRID_EMPTY) break;
+ items[num].type = va_arg(args, enum newtGridElement);
+ if (items[num].type == NEWT_GRID_EMPTY) break;
- items[num].what = va_arg(args, void *);
- num++;
+ items[num].what = va_arg(args, void *);
+ num++;
}
grid = newtCreateGrid(isVert ? 1 : num, isVert ? num : 1);
for (i = 0; i < num; i++) {
- newtGridSetField(grid, isVert ? 0 : i, isVert ? i : 0,
- items[i].type, items[i].what,
- close ? 0 : (i ? (isVert ? 0 : 1) : 0),
- close ? 0 : (i ? (isVert ? 1 : 0) : 0), 0, 0, 0, 0);
+ newtGridSetField(grid, isVert ? 0 : i, isVert ? i : 0,
+ items[i].type, items[i].what,
+ close ? 0 : (i ? (isVert ? 0 : 1) : 0),
+ close ? 0 : (i ? (isVert ? 1 : 0) : 0), 0, 0, 0, 0);
}
return grid;
}
newtGrid newtGridBasicWindow(newtComponent text, newtGrid middle,
- newtGrid buttons) {
+ newtGrid buttons) {
newtGrid grid;
grid = newtCreateGrid(1, 3);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
- 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
+ 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, middle,
- 0, 1, 0, 0, 0, 0);
+ 0, 1, 0, 0, 0, 0);
newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons,
- 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
+ 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
return grid;
}
newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle,
- newtGrid buttons) {
+ newtGrid buttons) {
newtGrid grid;
grid = newtCreateGrid(1, 3);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
- 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
+ 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, middle,
- 0, 1, 0, 0, 0, 0);
+ 0, 1, 0, 0, 0, 0);
newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons,
- 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
+ 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
return grid;
}
co->width = wstrlen(text,-1);
newLength = strlen(text);
if (newLength <= la->length) {
- memset(la->text, ' ', la->length);
- memcpy(la->text, text, newLength);
+ memset(la->text, ' ', la->length);
+ memcpy(la->text, text, newLength);
} else {
- free(la->text);
- la->text = strdup(text);
- la->length = newLength;
+ free(la->text);
+ la->text = strdup(text);
+ la->length = newLength;
}
labelDraw(co);
/* Holds all the relevant information for this listbox */
struct listbox {
newtComponent sb; /* Scrollbar on right side of listbox */
- int curWidth; /* size of text w/o scrollbar or border*/
- int curHeight; /* size of text w/o border */
+ int curWidth; /* size of text w/o scrollbar or border*/
+ int curHeight; /* size of text w/o border */
int sbAdjust;
int bdxAdjust, bdyAdjust;
int numItems, numSelected;
int userHasSetWidth;
int currItem, startShowItem; /* startShowItem is the first item displayed
- on the screen */
+ on the screen */
int isActive; /* If we handle key events all the time, it seems
- to do things even when they are supposed to be for
- another button/whatever */
+ to do things even when they are supposed to be for
+ another button/whatever */
struct items *boxItems;
int grow;
int flags; /* flags for this listbox, right now just
- NEWT_FLAG_RETURNEXIT */
+ NEWT_FLAG_RETURNEXIT */
};
static void listboxDraw(newtComponent co);
static void newtListboxRealSetCurrent(newtComponent co);
static void listboxPlace(newtComponent co, int newLeft, int newTop);
static inline void updateWidth(newtComponent co, struct listbox * li,
- int maxField);
+ int maxField);
static void listboxMapped(newtComponent co, int isMapped);
static struct componentOps listboxOps = {
co->isMapped = isMapped;
if (li->sb)
- li->sb->ops->mapped(li->sb, isMapped);
+ li->sb->ops->mapped(li->sb, isMapped);
}
static void listboxPlace(newtComponent co, int newLeft, int newTop) {
co->left = newLeft;
if (li->sb)
- li->sb->ops->place(li->sb, co->left + co->width - li->bdxAdjust - 1,
- co->top);
+ li->sb->ops->place(li->sb, co->left + co->width - li->bdxAdjust - 1,
+ co->top);
}
newtComponent newtListbox(int left, int top, int height, int flags) {
struct listbox * li;
if (!(co = malloc(sizeof(*co))))
- return NULL;
+ return NULL;
if (!(li = malloc(sizeof(struct listbox)))) {
- free(co);
- return NULL;
+ free(co);
+ return NULL;
}
li->boxItems = NULL;
li->bdxAdjust = 0;
li->bdyAdjust = 0;
li->flags = flags & (NEWT_FLAG_RETURNEXIT | NEWT_FLAG_BORDER |
- NEWT_FLAG_MULTIPLE | NEWT_FLAG_SHOWCURSOR);
+ NEWT_FLAG_MULTIPLE | NEWT_FLAG_SHOWCURSOR);
if (li->flags & NEWT_FLAG_BORDER) {
- li->bdxAdjust = 2;
- li->bdyAdjust = 1;
+ li->bdxAdjust = 2;
+ li->bdyAdjust = 1;
}
co->height = height;
li->curHeight = co->height - (2 * li->bdyAdjust);
if (height) {
- li->grow = 0;
- if (flags & NEWT_FLAG_SCROLL) {
- sb = newtVerticalScrollbar(left, top + li->bdyAdjust,
- li->curHeight,
- COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
- li->sbAdjust = 3;
- } else {
- sb = NULL;
- }
+ li->grow = 0;
+ if (flags & NEWT_FLAG_SCROLL) {
+ sb = newtVerticalScrollbar(left, top + li->bdyAdjust,
+ li->curHeight,
+ COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
+ li->sbAdjust = 3;
+ } else {
+ sb = NULL;
+ }
} else {
- li->grow = 1;
- sb = NULL;
+ li->grow = 1;
+ sb = NULL;
}
li->sb = sb;
}
static inline void updateWidth(newtComponent co, struct listbox * li,
- int maxField) {
+ int maxField) {
li->curWidth = maxField;
co->width = li->curWidth + li->sbAdjust + 2 * li->bdxAdjust;
if (li->sb)
- li->sb->left = co->left + co->width - li->bdxAdjust - 1;
+ li->sb->left = co->left + co->width - li->bdxAdjust - 1;
}
void newtListboxSetCurrentByKey(newtComponent co, void * key) {
item = li->boxItems, i = 0;
while (item && item->data != key)
- item = item->next, i++;
+ item = item->next, i++;
if (item)
- newtListboxSetCurrent(co, i);
+ newtListboxSetCurrent(co, i);
}
void newtListboxSetCurrent(newtComponent co, int num)
struct listbox * li = co->data;
if (num >= li->numItems)
- li->currItem = li->numItems - 1;
+ li->currItem = li->numItems - 1;
else if (num < 0)
- li->currItem = 0;
+ li->currItem = 0;
else
- li->currItem = num;
+ li->currItem = num;
if (li->currItem < li->startShowItem)
- li->startShowItem = li->currItem;
+ li->startShowItem = li->currItem;
else if (li->currItem - li->startShowItem > li->curHeight - 1)
- li->startShowItem = li->currItem - li->curHeight + 1;
+ li->startShowItem = li->currItem - li->curHeight + 1;
if (li->startShowItem + li->curHeight > li->numItems)
- li->startShowItem = li->numItems - li->curHeight;
+ li->startShowItem = li->numItems - li->curHeight;
if(li->startShowItem < 0)
- li->startShowItem = 0;
+ li->startShowItem = 0;
newtListboxRealSetCurrent(co);
}
struct listbox * li = co->data;
if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
listboxDraw(co);
if(co->callback) co->callback(co, co->callbackData);
}
struct items *item;
for(i = 0, item = li->boxItems; item != NULL && i < li->currItem;
- i++, item = item->next);
+ i++, item = item->next);
if (item)
- return (void *)item->data;
+ return (void *)item->data;
else
- return NULL;
+ return NULL;
}
void newtListboxSelectItem(newtComponent co, const void * key,
- enum newtFlagsSense sense)
+ enum newtFlagsSense sense)
{
struct listbox * li = co->data;
int i;
item = li->boxItems, i = 0;
while (item && item->data != key)
- item = item->next, i++;
+ item = item->next, i++;
if (!item) return;
if (item->isSelected)
- li->numSelected--;
+ li->numSelected--;
switch(sense) {
- case NEWT_FLAGS_RESET:
- item->isSelected = 0; break;
- case NEWT_FLAGS_SET:
- item->isSelected = 1; break;
- case NEWT_FLAGS_TOGGLE:
- item->isSelected = !item->isSelected;
+ case NEWT_FLAGS_RESET:
+ item->isSelected = 0; break;
+ case NEWT_FLAGS_SET:
+ item->isSelected = 1; break;
+ case NEWT_FLAGS_TOGGLE:
+ item->isSelected = !item->isSelected;
}
if (item->isSelected)
- li->numSelected++;
+ li->numSelected++;
listboxDraw(co);
}
struct listbox * li = co->data;
for(item = li->boxItems; item != NULL;
- item = item->next)
- item->isSelected = 0;
+ item = item->next)
+ item->isSelected = 0;
li->numSelected = 0;
listboxDraw(co);
}
retval = malloc(li->numSelected * sizeof(void *));
for(i = 0, item = li->boxItems; item != NULL;
- item = item->next)
- if(item->isSelected)
- retval[i++] = (void *)item->data;
+ item = item->next)
+ if(item->isSelected)
+ retval[i++] = (void *)item->data;
*numitems = li->numSelected;
return retval;
}
struct items *item;
for(i = 0, item = li->boxItems; item != NULL && i < num;
- i++, item = item->next);
+ i++, item = item->next);
if(!item)
- return;
+ return;
else {
- free(item->text);
- item->text = strdup(text);
+ free(item->text);
+ item->text = strdup(text);
}
if (li->userHasSetWidth == 0 && wstrlen(text,-1) > li->curWidth) {
- updateWidth(co, li, wstrlen(text,-1));
+ updateWidth(co, li, wstrlen(text,-1));
}
if (num >= li->startShowItem && num <= li->startShowItem + co->height)
- listboxDraw(co);
+ listboxDraw(co);
}
void newtListboxSetData(newtComponent co, int num, void * data) {
struct items *item;
for(i = 0, item = li->boxItems; item != NULL && i < num;
- i++, item = item->next);
+ i++, item = item->next);
item->data = data;
}
int newtListboxAppendEntry(newtComponent co, const char * text,
- const void * data) {
+ const void * data) {
struct listbox * li = co->data;
struct items *item;
if(li->boxItems) {
- for (item = li->boxItems; item->next != NULL; item = item->next);
+ for (item = li->boxItems; item->next != NULL; item = item->next);
- item = item->next = malloc(sizeof(struct items));
+ item = item->next = malloc(sizeof(struct items));
} else {
- item = li->boxItems = malloc(sizeof(struct items));
+ item = li->boxItems = malloc(sizeof(struct items));
}
if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth))
- updateWidth(co, li, wstrlen(text,-1));
+ updateWidth(co, li, wstrlen(text,-1));
item->text = strdup(text); item->data = data; item->next = NULL;
item->isSelected = 0;
if (li->grow)
- co->height++, li->curHeight++;
+ co->height++, li->curHeight++;
li->numItems++;
return 0;
}
int newtListboxInsertEntry(newtComponent co, const char * text,
- const void * data, void * key) {
+ const void * data, void * key) {
struct listbox * li = co->data;
struct items *item, *t;
if (li->boxItems) {
- if (key) {
- item = li->boxItems;
- while (item && item->data != key) item = item->next;
-
- if (!item) return 1;
-
- t = item->next;
- item = item->next = malloc(sizeof(struct items));
- item->next = t;
- } else {
- t = li->boxItems;
- item = li->boxItems = malloc(sizeof(struct items));
- item->next = t;
- }
+ if (key) {
+ item = li->boxItems;
+ while (item && item->data != key) item = item->next;
+
+ if (!item) return 1;
+
+ t = item->next;
+ item = item->next = malloc(sizeof(struct items));
+ item->next = t;
+ } else {
+ t = li->boxItems;
+ item = li->boxItems = malloc(sizeof(struct items));
+ item->next = t;
+ }
} else if (key) {
- return 1;
+ return 1;
} else {
- item = li->boxItems = malloc(sizeof(struct items));
- item->next = NULL;
+ item = li->boxItems = malloc(sizeof(struct items));
+ item->next = NULL;
}
if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth))
- updateWidth(co, li, wstrlen(text,-1));
+ updateWidth(co, li, wstrlen(text,-1));
item->text = strdup(text?text:"(null)"); item->data = data;
item->isSelected = 0;
if (li->sb)
- li->sb->left = co->left + co->width - li->bdxAdjust - 1;
+ li->sb->left = co->left + co->width - li->bdxAdjust - 1;
li->numItems++;
listboxDraw(co);
int num;
if (li->boxItems == NULL || li->numItems <= 0)
- return 0;
+ return 0;
num = 0;
item2 = NULL, item = li->boxItems;
while (item && item->data != key) {
- item2 = item;
- item = item->next;
- num++;
+ item2 = item;
+ item = item->next;
+ num++;
}
if (!item)
- return -1;
+ return -1;
if (item2)
- item2->next = item->next;
+ item2->next = item->next;
else
- li->boxItems = item->next;
+ li->boxItems = item->next;
free(item->text);
free(item);
li->numItems--;
if (!li->userHasSetWidth) {
- widest = 0;
- for (item = li->boxItems; item != NULL; item = item->next)
- if ((t = wstrlen(item->text,-1)) > widest) widest = t;
+ widest = 0;
+ for (item = li->boxItems; item != NULL; item = item->next)
+ if ((t = wstrlen(item->text,-1)) > widest) widest = t;
}
if (li->currItem >= num)
- li->currItem--;
+ li->currItem--;
if (!li->userHasSetWidth) {
- updateWidth(co, li, widest);
+ updateWidth(co, li, widest);
}
listboxDraw(co);
struct listbox * li;
struct items *anitem, *nextitem;
if(co == NULL || (li = co->data) == NULL)
- return;
+ return;
for(anitem = li->boxItems; anitem != NULL; anitem = nextitem) {
- nextitem = anitem->next;
- free(anitem->text);
- free(anitem);
+ nextitem = anitem->next;
+ free(anitem->text);
+ free(anitem);
}
li->numItems = li->numSelected = li->currItem = li->startShowItem = 0;
li->boxItems = NULL;
if (!li->userHasSetWidth)
- updateWidth(co, li, 5);
+ updateWidth(co, li, 5);
}
int newtListboxItemCount(newtComponent co)
struct items *item;
if (!li->boxItems || num >= li->numItems) {
- if(text)
- *text = NULL;
- if(data)
- *data = NULL;
- return;
+ if(text)
+ *text = NULL;
+ if(data)
+ *data = NULL;
+ return;
}
i = 0;
item = li->boxItems;
while (item && i < num) {
- i++, item = item->next;
+ i++, item = item->next;
}
if (item) {
- if (text)
- *text = item->text;
- if (data)
- *data = (void *)item->data;
+ if (text)
+ *text = item->text;
+ if (data)
+ *data = (void *)item->data;
}
}
if(li->flags & NEWT_FLAG_BORDER) {
if(li->isActive)
- SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
+ SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
else
SLsmg_set_color(NEWT_COLORSET_LISTBOX);
}
if(li->sb)
- li->sb->ops->draw(li->sb);
+ li->sb->ops->draw(li->sb);
SLsmg_set_color(NEWT_COLORSET_LISTBOX);
for(i = 0, item = li->boxItems; item != NULL && i < li->startShowItem;
- i++, item = item->next);
+ i++, item = item->next);
j = i;
for (i = 0; item != NULL && i < li->curHeight; i++, item = item->next) {
- if (!item->text) continue;
+ if (!item->text) continue;
- newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust);
- if(j + i == li->currItem) {
- if(item->isSelected)
- SLsmg_set_color(NEWT_COLORSET_ACTSELLISTBOX);
- else
- SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
- } else if(item->isSelected)
- SLsmg_set_color(NEWT_COLORSET_SELLISTBOX);
- else
- SLsmg_set_color(NEWT_COLORSET_LISTBOX);
+ newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust);
+ if(j + i == li->currItem) {
+ if(item->isSelected)
+ SLsmg_set_color(NEWT_COLORSET_ACTSELLISTBOX);
+ else
+ SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX);
+ } else if(item->isSelected)
+ SLsmg_set_color(NEWT_COLORSET_SELLISTBOX);
+ else
+ SLsmg_set_color(NEWT_COLORSET_LISTBOX);
- SLsmg_write_nstring(item->text, li->curWidth);
+ SLsmg_write_nstring(item->text, li->curWidth);
}
newtGotorc(co->top + (li->currItem - li->startShowItem) + li->bdyAdjust,
er.result = ER_IGNORED;
if(ev.when == EV_EARLY || ev.when == EV_LATE) {
- return er;
+ return er;
}
switch(ev.event) {
case EV_KEYPRESS:
- if (!li->isActive) break;
-
- switch(ev.u.key) {
- case ' ':
- if(!(li->flags & NEWT_FLAG_MULTIPLE)) break;
- newtListboxSelectItem(co, newtListboxGetCurrent(co),
- NEWT_FLAGS_TOGGLE);
- er.result = ER_SWALLOWED;
- /* We don't break here, because it is cool to be able to
- hold space to select a bunch of items in a list at once */
-
- case NEWT_KEY_DOWN:
- if(li->numItems <= 0) break;
- if(li->currItem < li->numItems - 1) {
- li->currItem++;
- if(li->currItem > (li->startShowItem + li->curHeight - 1)) {
- li->startShowItem = li->currItem - li->curHeight + 1;
- if(li->startShowItem + li->curHeight > li->numItems)
- li->startShowItem = li->numItems - li->curHeight;
- }
- if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
- listboxDraw(co);
- }
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_ENTER:
- if(li->numItems <= 0) break;
- if(li->flags & NEWT_FLAG_RETURNEXIT)
- er.result = ER_EXITFORM;
- break;
-
- case NEWT_KEY_UP:
- if(li->numItems <= 0) break;
- if(li->currItem > 0) {
- li->currItem--;
- if(li->currItem < li->startShowItem)
- li->startShowItem = li->currItem;
- if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
- listboxDraw(co);
- }
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_PGUP:
- if(li->numItems <= 0) break;
- li->startShowItem -= li->curHeight - 1;
- if(li->startShowItem < 0)
- li->startShowItem = 0;
- li->currItem -= li->curHeight - 1;
- if(li->currItem < 0)
- li->currItem = 0;
- newtListboxRealSetCurrent(co);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_PGDN:
- if(li->numItems <= 0) break;
- li->startShowItem += li->curHeight;
- if(li->startShowItem > (li->numItems - li->curHeight)) {
- li->startShowItem = li->numItems - li->curHeight;
- }
- li->currItem += li->curHeight;
- if(li->currItem >= li->numItems) {
- li->currItem = li->numItems - 1;
- }
- newtListboxRealSetCurrent(co);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_HOME:
- if(li->numItems <= 0) break;
- newtListboxSetCurrent(co, 0);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_END:
- if(li->numItems <= 0) break;
- li->startShowItem = li->numItems - li->curHeight;
- if(li->startShowItem < 0)
- li->startShowItem = 0;
- li->currItem = li->numItems - 1;
- newtListboxRealSetCurrent(co);
- er.result = ER_SWALLOWED;
- break;
- default:
- if (li->numItems <= 0) break;
+ if (!li->isActive) break;
+
+ switch(ev.u.key) {
+ case ' ':
+ if(!(li->flags & NEWT_FLAG_MULTIPLE)) break;
+ newtListboxSelectItem(co, newtListboxGetCurrent(co),
+ NEWT_FLAGS_TOGGLE);
+ er.result = ER_SWALLOWED;
+ /* We don't break here, because it is cool to be able to
+ hold space to select a bunch of items in a list at once */
+
+ case NEWT_KEY_DOWN:
+ if(li->numItems <= 0) break;
+ if(li->currItem < li->numItems - 1) {
+ li->currItem++;
+ if(li->currItem > (li->startShowItem + li->curHeight - 1)) {
+ li->startShowItem = li->currItem - li->curHeight + 1;
+ if(li->startShowItem + li->curHeight > li->numItems)
+ li->startShowItem = li->numItems - li->curHeight;
+ }
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_ENTER:
+ if(li->numItems <= 0) break;
+ if(li->flags & NEWT_FLAG_RETURNEXIT)
+ er.result = ER_EXITFORM;
+ break;
+
+ case NEWT_KEY_UP:
+ if(li->numItems <= 0) break;
+ if(li->currItem > 0) {
+ li->currItem--;
+ if(li->currItem < li->startShowItem)
+ li->startShowItem = li->currItem;
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_PGUP:
+ if(li->numItems <= 0) break;
+ li->startShowItem -= li->curHeight - 1;
+ if(li->startShowItem < 0)
+ li->startShowItem = 0;
+ li->currItem -= li->curHeight - 1;
+ if(li->currItem < 0)
+ li->currItem = 0;
+ newtListboxRealSetCurrent(co);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_PGDN:
+ if(li->numItems <= 0) break;
+ li->startShowItem += li->curHeight;
+ if(li->startShowItem > (li->numItems - li->curHeight)) {
+ li->startShowItem = li->numItems - li->curHeight;
+ }
+ li->currItem += li->curHeight;
+ if(li->currItem >= li->numItems) {
+ li->currItem = li->numItems - 1;
+ }
+ newtListboxRealSetCurrent(co);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_HOME:
+ if(li->numItems <= 0) break;
+ newtListboxSetCurrent(co, 0);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_END:
+ if(li->numItems <= 0) break;
+ li->startShowItem = li->numItems - li->curHeight;
+ if(li->startShowItem < 0)
+ li->startShowItem = 0;
+ li->currItem = li->numItems - 1;
+ newtListboxRealSetCurrent(co);
+ er.result = ER_SWALLOWED;
+ break;
+ default:
+ if (li->numItems <= 0) break;
if (ev.u.key < NEWT_KEY_EXTRA_BASE && isalpha(ev.u.key)) {
- for(i = 0, item = li->boxItems; item != NULL &&
- i < li->currItem; i++, item = item->next);
-
- if (item && item->text && (toupper(*item->text) == toupper(ev.u.key))) {
- item = item->next;
- i++;
- } else {
- item = li->boxItems;
- i = 0;
- }
- while (item && item->text &&
- toupper(*item->text) != toupper(ev.u.key)) {
- item = item->next;
- i++;
- }
- if (item) {
- li->currItem = i;
- if(li->currItem < li->startShowItem ||
- li->currItem > li->startShowItem)
- li->startShowItem =
- li->currItem > li->numItems - li->curHeight ?
- li->startShowItem = li->numItems - li->curHeight :
- li->currItem;
- if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
- newtListboxRealSetCurrent(co);
- er.result = ER_SWALLOWED;
- }
- }
- }
- break;
+ for(i = 0, item = li->boxItems; item != NULL &&
+ i < li->currItem; i++, item = item->next);
+
+ if (item && item->text && (toupper(*item->text) == toupper(ev.u.key))) {
+ item = item->next;
+ i++;
+ } else {
+ item = li->boxItems;
+ i = 0;
+ }
+ while (item && item->text &&
+ toupper(*item->text) != toupper(ev.u.key)) {
+ item = item->next;
+ i++;
+ }
+ if (item) {
+ li->currItem = i;
+ if(li->currItem < li->startShowItem ||
+ li->currItem > li->startShowItem)
+ li->startShowItem =
+ li->currItem > li->numItems - li->curHeight ?
+ li->startShowItem = li->numItems - li->curHeight :
+ li->currItem;
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ newtListboxRealSetCurrent(co);
+ er.result = ER_SWALLOWED;
+ }
+ }
+ }
+ break;
case EV_FOCUS:
- li->isActive = 1;
- listboxDraw(co);
- if(li->flags & NEWT_FLAG_SHOWCURSOR)
- newtCursorOn();
- er.result = ER_SWALLOWED;
- break;
+ li->isActive = 1;
+ listboxDraw(co);
+ if(li->flags & NEWT_FLAG_SHOWCURSOR)
+ newtCursorOn();
+ er.result = ER_SWALLOWED;
+ break;
case EV_UNFOCUS:
- li->isActive = 0;
- listboxDraw(co);
- if(li->flags & NEWT_FLAG_SHOWCURSOR)
- newtCursorOff();
- er.result = ER_SWALLOWED;
- break;
+ li->isActive = 0;
+ listboxDraw(co);
+ if(li->flags & NEWT_FLAG_SHOWCURSOR)
+ newtCursorOff();
+ er.result = ER_SWALLOWED;
+ break;
case EV_MOUSE:
- /* if this mouse click was within the listbox, make the current
- item the item clicked on. */
- /* Up scroll arrow */
- if (li->sb &&
- ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
- ev.u.mouse.y == co->top + li->bdyAdjust) {
- if(li->numItems <= 0) break;
- if(li->currItem > 0) {
- li->currItem--;
- if(li->currItem < li->startShowItem)
- li->startShowItem = li->currItem;
- if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
- listboxDraw(co);
- }
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- break;
- }
- /* Down scroll arrow */
- if (li->sb &&
- ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
- ev.u.mouse.y == co->top + co->height - li->bdyAdjust - 1) {
- if(li->numItems <= 0) break;
- if(li->currItem < li->numItems - 1) {
- li->currItem++;
- if(li->currItem > (li->startShowItem + li->curHeight - 1)) {
- li->startShowItem = li->currItem - li->curHeight + 1;
- if(li->startShowItem + li->curHeight > li->numItems)
- li->startShowItem = li->numItems - li->curHeight;
- }
- if(li->sb)
- newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
- listboxDraw(co);
- }
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- break;
- }
- if ((ev.u.mouse.y >= co->top + li->bdyAdjust) &&
- (ev.u.mouse.y <= co->top + co->height - (li->bdyAdjust * 2)) &&
- (ev.u.mouse.x >= co->left + li->bdxAdjust) &&
- (ev.u.mouse.x <= co->left + co->width + (li->bdxAdjust * 2))) {
- li->currItem = li->startShowItem +
- (ev.u.mouse.y - li->bdyAdjust - co->top);
- newtListboxRealSetCurrent(co);
- listboxDraw(co);
- if(co->callback) co->callback(co, co->callbackData);
- er.result = ER_SWALLOWED;
- break;
- }
+ /* if this mouse click was within the listbox, make the current
+ item the item clicked on. */
+ /* Up scroll arrow */
+ if (li->sb &&
+ ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
+ ev.u.mouse.y == co->top + li->bdyAdjust) {
+ if(li->numItems <= 0) break;
+ if(li->currItem > 0) {
+ li->currItem--;
+ if(li->currItem < li->startShowItem)
+ li->startShowItem = li->currItem;
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
+ /* Down scroll arrow */
+ if (li->sb &&
+ ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
+ ev.u.mouse.y == co->top + co->height - li->bdyAdjust - 1) {
+ if(li->numItems <= 0) break;
+ if(li->currItem < li->numItems - 1) {
+ li->currItem++;
+ if(li->currItem > (li->startShowItem + li->curHeight - 1)) {
+ li->startShowItem = li->currItem - li->curHeight + 1;
+ if(li->startShowItem + li->curHeight > li->numItems)
+ li->startShowItem = li->numItems - li->curHeight;
+ }
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
+ if ((ev.u.mouse.y >= co->top + li->bdyAdjust) &&
+ (ev.u.mouse.y <= co->top + co->height - (li->bdyAdjust * 2)) &&
+ (ev.u.mouse.x >= co->left + li->bdxAdjust) &&
+ (ev.u.mouse.x <= co->left + co->width + (li->bdxAdjust * 2))) {
+ li->currItem = li->startShowItem +
+ (ev.u.mouse.y - li->bdyAdjust - co->top);
+ newtListboxRealSetCurrent(co);
+ listboxDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
}
return er;
nextitem = item = li->boxItems;
while (item != NULL) {
- nextitem = item->next;
- free(item->text);
- free(item);
- item = nextitem;
+ nextitem = item->next;
+ free(item->text);
+ free(item);
+ item = nextitem;
}
if (li->sb) li->sb->ops->destroy(li->sb);
;
const struct newtColors newtDefaultColorPalette = {
- "white", "blue", /* root fg, bg */
- "black", "lightgray", /* border fg, bg */
- "black", "lightgray", /* window fg, bg */
- "white", "black", /* shadow fg, bg */
- "red", "lightgray", /* title fg, bg */
- "lightgray", "red", /* button fg, bg */
- "red", "lightgray", /* active button fg, bg */
- "yellow", "blue", /* checkbox fg, bg */
- "blue", "brown", /* active checkbox fg, bg */
- "yellow", "blue", /* entry box fg, bg */
- "blue", "lightgray", /* label fg, bg */
- "black", "lightgray", /* listbox fg, bg */
- "yellow", "blue", /* active listbox fg, bg */
- "black", "lightgray", /* textbox fg, bg */
- "lightgray", "black", /* active textbox fg, bg */
- "white", "blue", /* help line */
- "yellow", "blue", /* root text */
- "blue", /* scale full */
- "red", /* scale empty */
- "blue", "lightgray", /* disabled entry fg, bg */
- "white", "blue", /* compact button fg, bg */
- "yellow", "red", /* active & sel listbox */
- "black", "brown" /* selected listbox */
+ "white", "blue", /* root fg, bg */
+ "black", "lightgray", /* border fg, bg */
+ "black", "lightgray", /* window fg, bg */
+ "white", "black", /* shadow fg, bg */
+ "red", "lightgray", /* title fg, bg */
+ "lightgray", "red", /* button fg, bg */
+ "red", "lightgray", /* active button fg, bg */
+ "yellow", "blue", /* checkbox fg, bg */
+ "blue", "brown", /* active checkbox fg, bg */
+ "yellow", "blue", /* entry box fg, bg */
+ "blue", "lightgray", /* label fg, bg */
+ "black", "lightgray", /* listbox fg, bg */
+ "yellow", "blue", /* active listbox fg, bg */
+ "black", "lightgray", /* textbox fg, bg */
+ "lightgray", "black", /* active textbox fg, bg */
+ "white", "blue", /* help line */
+ "yellow", "blue", /* root text */
+ "blue", /* scale full */
+ "red", /* scale empty */
+ "blue", "lightgray", /* disabled entry fg, bg */
+ "white", "blue", /* compact button fg, bg */
+ "yellow", "red", /* active & sel listbox */
+ "black", "brown" /* selected listbox */
};
static const struct keymap keymap[] = {
- { "\033OA", NEWT_KEY_UP, "kh" },
- { "\033[A", NEWT_KEY_UP, "ku" },
- { "\033OB", NEWT_KEY_DOWN, "kd" },
- { "\033[B", NEWT_KEY_DOWN, "kd" },
- { "\033[C", NEWT_KEY_RIGHT, "kr" },
- { "\033OC", NEWT_KEY_RIGHT, "kr" },
- { "\033[D", NEWT_KEY_LEFT, "kl" },
- { "\033OD", NEWT_KEY_LEFT, "kl" },
- { "\033[H", NEWT_KEY_HOME, "kh" },
- { "\033[1~", NEWT_KEY_HOME, "kh" },
- { "\033Ow", NEWT_KEY_END, "kH" },
- { "\033[4~", NEWT_KEY_END, "kH" },
-
- { "\033[3~", NEWT_KEY_DELETE, "kl" },
- { "\033[2~", NEWT_KEY_INSERT, NULL },
-
- { "\033\t", NEWT_KEY_UNTAB, NULL },
-
- { "\033[5~", NEWT_KEY_PGUP, NULL },
- { "\033[6~", NEWT_KEY_PGDN, NULL },
- { "\033V", NEWT_KEY_PGUP, "kH" },
- { "\033v", NEWT_KEY_PGUP, "kH" },
-
- { "\033[[A", NEWT_KEY_F1, NULL },
- { "\033[[B", NEWT_KEY_F2, NULL },
- { "\033[[C", NEWT_KEY_F3, NULL },
- { "\033[[D", NEWT_KEY_F4, NULL },
- { "\033[[E", NEWT_KEY_F5, NULL },
-
- { "\033OP", NEWT_KEY_F1, NULL },
- { "\033OQ", NEWT_KEY_F2, NULL },
- { "\033OR", NEWT_KEY_F3, NULL },
- { "\033OS", NEWT_KEY_F4, NULL },
-
- { "\033[11~", NEWT_KEY_F1, NULL },
- { "\033[12~", NEWT_KEY_F2, NULL },
- { "\033[13~", NEWT_KEY_F3, NULL },
- { "\033[14~", NEWT_KEY_F4, NULL },
- { "\033[15~", NEWT_KEY_F5, NULL },
- { "\033[17~", NEWT_KEY_F6, NULL },
- { "\033[18~", NEWT_KEY_F7, NULL },
- { "\033[19~", NEWT_KEY_F8, NULL },
- { "\033[20~", NEWT_KEY_F9, NULL },
- { "\033[21~", NEWT_KEY_F10, NULL },
- { "\033[23~", NEWT_KEY_F11, NULL },
- { "\033[24~", NEWT_KEY_F12, NULL },
- { "\033", NEWT_KEY_ESCAPE, NULL },
-
- { 0 }, /* LEAVE this one */
+ { "\033OA", NEWT_KEY_UP, "kh" },
+ { "\033[A", NEWT_KEY_UP, "ku" },
+ { "\033OB", NEWT_KEY_DOWN, "kd" },
+ { "\033[B", NEWT_KEY_DOWN, "kd" },
+ { "\033[C", NEWT_KEY_RIGHT, "kr" },
+ { "\033OC", NEWT_KEY_RIGHT, "kr" },
+ { "\033[D", NEWT_KEY_LEFT, "kl" },
+ { "\033OD", NEWT_KEY_LEFT, "kl" },
+ { "\033[H", NEWT_KEY_HOME, "kh" },
+ { "\033[1~", NEWT_KEY_HOME, "kh" },
+ { "\033Ow", NEWT_KEY_END, "kH" },
+ { "\033[4~", NEWT_KEY_END, "kH" },
+
+ { "\033[3~", NEWT_KEY_DELETE, "kl" },
+ { "\033[2~", NEWT_KEY_INSERT, NULL },
+
+ { "\033\t", NEWT_KEY_UNTAB, NULL },
+
+ { "\033[5~", NEWT_KEY_PGUP, NULL },
+ { "\033[6~", NEWT_KEY_PGDN, NULL },
+ { "\033V", NEWT_KEY_PGUP, "kH" },
+ { "\033v", NEWT_KEY_PGUP, "kH" },
+
+ { "\033[[A", NEWT_KEY_F1, NULL },
+ { "\033[[B", NEWT_KEY_F2, NULL },
+ { "\033[[C", NEWT_KEY_F3, NULL },
+ { "\033[[D", NEWT_KEY_F4, NULL },
+ { "\033[[E", NEWT_KEY_F5, NULL },
+
+ { "\033OP", NEWT_KEY_F1, NULL },
+ { "\033OQ", NEWT_KEY_F2, NULL },
+ { "\033OR", NEWT_KEY_F3, NULL },
+ { "\033OS", NEWT_KEY_F4, NULL },
+
+ { "\033[11~", NEWT_KEY_F1, NULL },
+ { "\033[12~", NEWT_KEY_F2, NULL },
+ { "\033[13~", NEWT_KEY_F3, NULL },
+ { "\033[14~", NEWT_KEY_F4, NULL },
+ { "\033[15~", NEWT_KEY_F5, NULL },
+ { "\033[17~", NEWT_KEY_F6, NULL },
+ { "\033[18~", NEWT_KEY_F7, NULL },
+ { "\033[19~", NEWT_KEY_F8, NULL },
+ { "\033[20~", NEWT_KEY_F9, NULL },
+ { "\033[21~", NEWT_KEY_F10, NULL },
+ { "\033[23~", NEWT_KEY_F11, NULL },
+ { "\033[24~", NEWT_KEY_F12, NULL },
+ { "\033", NEWT_KEY_ESCAPE, NULL },
+
+ { 0 }, /* LEAVE this one */
};
static char keyPrefix = '\033';
}
int wstrlen(const char *str, int len) {
- mbstate_t ps;
- wchar_t tmp;
- int nchars = 0;
-
- if (!str) return 0;
- if (!len) return 0;
- if (len < 0) len = strlen(str);
- memset(&ps,0,sizeof(mbstate_t));
- while (len > 0) {
- int x,y;
-
- x = mbrtowc(&tmp,str,len,&ps);
- if (x >0) {
- str += x;
- len -= x;
- y = wcwidth(tmp);
- if (y>0)
- nchars+=y;
- } else break;
- }
- return nchars;
+ mbstate_t ps;
+ wchar_t tmp;
+ int nchars = 0;
+
+ if (!str) return 0;
+ if (!len) return 0;
+ if (len < 0) len = strlen(str);
+ memset(&ps,0,sizeof(mbstate_t));
+ while (len > 0) {
+ int x,y;
+
+ x = mbrtowc(&tmp,str,len,&ps);
+ if (x >0) {
+ str += x;
+ len -= x;
+ y = wcwidth(tmp);
+ if (y>0)
+ nchars+=y;
+ } else break;
+ }
+ return nchars;
}
static int getkey() {
void newtFlushInput(void) {
while (SLang_input_pending(0)) {
- getkey();
+ getkey();
}
}
if ((lang = getenv("LANG")) == NULL)
lang = "";
if (strstr (lang, ".euc") != NULL)
- trashScreen = 1;
+ trashScreen = 1;
(void) strlen(ident);
MonoValue = getenv(MonoEnv);
if ( MonoValue == NULL ) {
- SLtt_Use_Ansi_Colors = 1;
+ SLtt_Use_Ansi_Colors = 1;
} else {
- SLtt_Use_Ansi_Colors = 0;
+ SLtt_Use_Ansi_Colors = 0;
}
if ((ret = SLsmg_init_smg()) < 0)
- return ret;
+ return ret;
if ((ret = SLang_init_tty(0, 0, 0)) < 0)
- return ret;
+ return ret;
newtSetColors(newtDefaultColorPalette);
newtCursorOff();
SLtt_set_color(NEWT_COLORSET_TITLE, "", colors.titleFg, colors.titleBg);
SLtt_set_color(NEWT_COLORSET_BUTTON, "", colors.buttonFg, colors.buttonBg);
SLtt_set_color(NEWT_COLORSET_ACTBUTTON, "", colors.actButtonFg,
- colors.actButtonBg);
+ colors.actButtonBg);
SLtt_set_color(NEWT_COLORSET_CHECKBOX, "", colors.checkboxFg,
- colors.checkboxBg);
+ colors.checkboxBg);
SLtt_set_color(NEWT_COLORSET_ACTCHECKBOX, "", colors.actCheckboxFg,
- colors.actCheckboxBg);
+ colors.actCheckboxBg);
SLtt_set_color(NEWT_COLORSET_ENTRY, "", colors.entryFg, colors.entryBg);
SLtt_set_color(NEWT_COLORSET_LABEL, "", colors.labelFg, colors.labelBg);
SLtt_set_color(NEWT_COLORSET_LISTBOX, "", colors.listboxFg,
- colors.listboxBg);
+ colors.listboxBg);
SLtt_set_color(NEWT_COLORSET_ACTLISTBOX, "", colors.actListboxFg,
- colors.actListboxBg);
+ colors.actListboxBg);
SLtt_set_color(NEWT_COLORSET_TEXTBOX, "", colors.textboxFg,
- colors.textboxBg);
+ colors.textboxBg);
SLtt_set_color(NEWT_COLORSET_ACTTEXTBOX, "", colors.actTextboxFg,
- colors.actTextboxBg);
+ colors.actTextboxBg);
SLtt_set_color(NEWT_COLORSET_HELPLINE, "", colors.helpLineFg,
- colors.helpLineBg);
+ colors.helpLineBg);
SLtt_set_color(NEWT_COLORSET_ROOTTEXT, "", colors.rootTextFg,
- colors.rootTextBg);
+ colors.rootTextBg);
SLtt_set_color(NEWT_COLORSET_EMPTYSCALE, "", "white",
- colors.emptyScale);
+ colors.emptyScale);
SLtt_set_color(NEWT_COLORSET_FULLSCALE, "", "white",
- colors.fullScale);
+ colors.fullScale);
SLtt_set_color(NEWT_COLORSET_DISENTRY, "", colors.disabledEntryFg,
- colors.disabledEntryBg);
+ colors.disabledEntryBg);
SLtt_set_color(NEWT_COLORSET_COMPACTBUTTON, "", colors.compactButtonFg,
- colors.compactButtonBg);
+ colors.compactButtonBg);
SLtt_set_color(NEWT_COLORSET_ACTSELLISTBOX, "", colors.actSelListboxFg,
- colors.actSelListboxBg);
+ colors.actSelListboxBg);
SLtt_set_color(NEWT_COLORSET_SELLISTBOX, "", colors.selListboxFg,
- colors.selListboxBg);
+ colors.selListboxBg);
}
int newtGetKey(void) {
const struct keymap * curr;
do {
- key = getkey();
- if (key == SLANG_GETKEY_ERROR) {
- /* Either garbage was read, or stdin disappeared
- * (the parent terminal was proably closed)
- * if the latter, die.
- */
- if (feof(stdin))
- exit(1);
- if (needResize) {
+ key = getkey();
+ if (key == SLANG_GETKEY_ERROR) {
+ /* Either garbage was read, or stdin disappeared
+ * (the parent terminal was proably closed)
+ * if the latter, die.
+ */
+ if (feof(stdin))
+ exit(1);
+ if (needResize) {
needResize = 0;
- return NEWT_KEY_RESIZE;
+ return NEWT_KEY_RESIZE;
}
- /* ignore other signals */
- continue;
- }
+ /* ignore other signals */
+ continue;
+ }
- if (key == NEWT_KEY_SUSPEND && suspendCallback)
- suspendCallback(suspendCallbackData);
+ if (key == NEWT_KEY_SUSPEND && suspendCallback)
+ suspendCallback(suspendCallbackData);
} while (key == NEWT_KEY_SUSPEND);
switch (key) {
case 'v' | 0x80:
case 'V' | 0x80:
- return NEWT_KEY_PGUP;
+ return NEWT_KEY_PGUP;
case 22:
- return NEWT_KEY_PGDN;
+ return NEWT_KEY_PGDN;
- return NEWT_KEY_BKSPC;
+ return NEWT_KEY_BKSPC;
case 0x7f:
- return NEWT_KEY_BKSPC;
+ return NEWT_KEY_BKSPC;
case 0x08:
- return NEWT_KEY_BKSPC;
+ return NEWT_KEY_BKSPC;
default:
- if (key != keyPrefix) return key;
+ if (key != keyPrefix) return key;
}
memset(buf, 0, sizeof(buf));
*chptr++ = key;
while (SLang_input_pending(5)) {
- key = getkey();
- if (key == keyPrefix) {
- /* he hit unknown keys too many times -- start over */
- memset(buf, 0, sizeof(buf));
- chptr = buf;
- }
-
- *chptr++ = key;
-
- /* this search should use bsearch(), but when we only look through
- a list of 20 (or so) keymappings, it's probably faster just to
- do a inline linear search */
-
- for (curr = keymap; curr->code; curr++) {
- if (curr->str) {
- if (!strcmp(curr->str, buf))
- return curr->code;
- }
- }
+ key = getkey();
+ if (key == keyPrefix) {
+ /* he hit unknown keys too many times -- start over */
+ memset(buf, 0, sizeof(buf));
+ chptr = buf;
+ }
+
+ *chptr++ = key;
+
+ /* this search should use bsearch(), but when we only look through
+ a list of 20 (or so) keymappings, it's probably faster just to
+ do a inline linear search */
+
+ for (curr = keymap; curr->code; curr++) {
+ if (curr->str) {
+ if (!strcmp(curr->str, buf))
+ return curr->code;
+ }
+ }
}
for (curr = keymap; curr->code; curr++) {
- if (curr->str) {
- if (!strcmp(curr->str, buf))
- return curr->code;
- }
+ if (curr->str) {
+ if (!strcmp(curr->str, buf))
+ return curr->code;
+ }
}
/* Looks like we were a bit overzealous in reading characters. Return
chptr--;
while (chptr > buf)
- SLang_ungetkey(*chptr--);
+ SLang_ungetkey(*chptr--);
return *chptr;
}
*/
void newtClearKeyBuffer(void) {
while (SLang_input_pending(1)) {
- getkey();
+ getkey();
}
}
* @return zero on success (currently no errors reported)
*/
int newtOpenWindow(unsigned left, unsigned top, unsigned width, unsigned height,
- const char * title) {
+ const char * title) {
int j, row, col;
int n;
int i;
newtFlushInput();
if (!currentWindow) {
- currentWindow = windowStack;
+ currentWindow = windowStack;
} else {
- currentWindow++;
+ currentWindow++;
}
currentWindow->left = left;
col = left - 1;
/* clip to the current screen bounds - msw */
if (row < 0)
- row = 0;
+ row = 0;
if (col < 0)
- col = 0;
+ col = 0;
if (left + width > SLtt_Screen_Cols)
- width = SLtt_Screen_Cols - left;
+ width = SLtt_Screen_Cols - left;
if (top + height > SLtt_Screen_Rows)
- height = SLtt_Screen_Rows - top;
+ height = SLtt_Screen_Rows - top;
n = 0;
for (j = 0; j < height + 3; j++, row++) {
- SLsmg_gotorc(row, col);
- SLsmg_read_raw(currentWindow->buffer + n,
- currentWindow->width + 3);
- n += currentWindow->width + 3;
+ SLsmg_gotorc(row, col);
+ SLsmg_read_raw(currentWindow->buffer + n,
+ currentWindow->width + 3);
+ n += currentWindow->width + 3;
}
newtTrashScreen();
SLsmg_draw_box(top - 1, left - 1, height + 2, width + 2);
if (currentWindow->title) {
- i = wstrlen(currentWindow->title,-1) + 4;
- i = ((width - i) / 2) + left;
- SLsmg_gotorc(top - 1, i);
- SLsmg_set_char_set(1);
- SLsmg_write_char(SLSMG_RTEE_CHAR);
- SLsmg_set_char_set(0);
- SLsmg_write_char(' ');
- SLsmg_set_color(NEWT_COLORSET_TITLE);
- SLsmg_write_string((char *)currentWindow->title);
- SLsmg_set_color(NEWT_COLORSET_BORDER);
- SLsmg_write_char(' ');
- SLsmg_set_char_set(1);
- SLsmg_write_char(SLSMG_LTEE_CHAR);
- SLsmg_set_char_set(0);
+ i = wstrlen(currentWindow->title,-1) + 4;
+ i = ((width - i) / 2) + left;
+ SLsmg_gotorc(top - 1, i);
+ SLsmg_set_char_set(1);
+ SLsmg_write_char(SLSMG_RTEE_CHAR);
+ SLsmg_set_char_set(0);
+ SLsmg_write_char(' ');
+ SLsmg_set_color(NEWT_COLORSET_TITLE);
+ SLsmg_write_string((char *)currentWindow->title);
+ SLsmg_set_color(NEWT_COLORSET_BORDER);
+ SLsmg_write_char(' ');
+ SLsmg_set_char_set(1);
+ SLsmg_write_char(SLSMG_LTEE_CHAR);
+ SLsmg_set_char_set(0);
}
SLsmg_set_color(NEWT_COLORSET_WINDOW);
SLsmg_fill_region(top, left + width + 1, height + 1, 1, ' ');
for (i = top; i < (top + height + 1); i++) {
- SLsmg_gotorc(i, left + width + 1);
- SLsmg_write_string(" ");
+ SLsmg_gotorc(i, left + width + 1);
+ SLsmg_write_string(" ");
}
return 0;
row = currentWindow->top - 1;
col = currentWindow->left - 1;
if (row < 0)
- row = 0;
+ row = 0;
if (col < 0)
- col = 0;
+ col = 0;
for (j = 0; j < currentWindow->height + 3; j++, row++) {
- SLsmg_gotorc(row, col);
- SLsmg_write_raw(currentWindow->buffer + n,
- currentWindow->width + 3);
- n += currentWindow->width + 3;
+ SLsmg_gotorc(row, col);
+ SLsmg_write_raw(currentWindow->buffer + n,
+ currentWindow->width + 3);
+ n += currentWindow->width + 3;
}
free(currentWindow->buffer);
free(currentWindow->title);
if (currentWindow == windowStack)
- currentWindow = NULL;
+ currentWindow = NULL;
else
- currentWindow--;
+ currentWindow--;
SLsmg_set_char_set(0);
void newtGetWindowPos(int * x, int * y) {
if (currentWindow) {
- *x = currentWindow->left;
- *y = currentWindow->top;
+ *x = currentWindow->left;
+ *y = currentWindow->top;
} else
- *x = *y = 0;
+ *x = *y = 0;
}
void newtGetrc(int * row, int * col) {
void newtGotorc(int newRow, int newCol) {
if (currentWindow) {
- newRow += currentWindow->top;
- newCol += currentWindow->left;
+ newRow += currentWindow->top;
+ newCol += currentWindow->left;
}
cursorRow = newRow;
void newtDrawBox(int left, int top, int width, int height, int shadow) {
if (currentWindow) {
- top += currentWindow->top;
- left += currentWindow->left;
+ top += currentWindow->top;
+ left += currentWindow->left;
}
SLsmg_draw_box(top, left, height, width);
if (shadow) {
- SLsmg_set_color(NEWT_COLORSET_SHADOW);
- SLsmg_fill_region(top + height, left + 1, 1, width - 1, ' ');
- SLsmg_fill_region(top + 1, left + width, height, 1, ' ');
+ SLsmg_set_color(NEWT_COLORSET_SHADOW);
+ SLsmg_fill_region(top + height, left + 1, 1, width - 1, ' ');
+ SLsmg_fill_region(top + 1, left + width, height, 1, ' ');
}
}
void newtClearBox(int left, int top, int width, int height) {
if (currentWindow) {
- top += currentWindow->top;
- left += currentWindow->left;
+ top += currentWindow->top;
+ left += currentWindow->left;
}
SLsmg_fill_region(top, left, height, width, ' ');
struct keymap * curr;
for (curr = keymap; curr->code; curr++) {
- if (!curr->str)
- curr->str = SLtt_tgetstr(curr->tc);
+ if (!curr->str)
+ curr->str = SLtt_tgetstr(curr->tc);
}
/* Newt's keymap handling is a bit broken. It assumes that any extended
will probably need to fix this, or just yell at me and I'll be so
ashamed of myself for doing it this way I'll fix it */
- keyPrefix = 0x1b; /* ESC */
+ keyPrefix = 0x1b; /* ESC */
}
#endif
}
struct eventResult newtDefaultEventHandler(newtComponent c,
- struct event ev) {
+ struct event ev) {
struct eventResult er;
er.result = ER_IGNORED;
SLsmg_set_color(NEWT_COLORSET_HELPLINE);
if (currentHelpline) {
- /* buffer size needs to be wide enough to hold all the multibyte
- currentHelpline + all the single byte ' ' to fill the line */
- int wlen = wstrlen(*currentHelpline, -1);
- int len;
-
- if (wlen > SLtt_Screen_Cols)
- wlen = SLtt_Screen_Cols;
- len = strlen(*currentHelpline) + (SLtt_Screen_Cols - wlen);
- buf = alloca(len + 1);
- memset(buf, ' ', len);
- memcpy(buf, *currentHelpline, strlen(*currentHelpline));
- buf[len] = '\0';
+ /* buffer size needs to be wide enough to hold all the multibyte
+ currentHelpline + all the single byte ' ' to fill the line */
+ int wlen = wstrlen(*currentHelpline, -1);
+ int len;
+
+ if (wlen > SLtt_Screen_Cols)
+ wlen = SLtt_Screen_Cols;
+ len = strlen(*currentHelpline) + (SLtt_Screen_Cols - wlen);
+ buf = alloca(len + 1);
+ memset(buf, ' ', len);
+ memcpy(buf, *currentHelpline, strlen(*currentHelpline));
+ buf[len] = '\0';
} else {
- buf = alloca(SLtt_Screen_Cols + 1);
- memset(buf, ' ', SLtt_Screen_Cols);
- buf[SLtt_Screen_Cols] = '\0';
+ buf = alloca(SLtt_Screen_Cols + 1);
+ memset(buf, ' ', SLtt_Screen_Cols);
+ buf[SLtt_Screen_Cols] = '\0';
}
SLsmg_gotorc(SLtt_Screen_Rows - 1, 0);
SLsmg_write_string(buf);
void newtPushHelpLine(const char * text) {
if (!text)
- text = defaultHelpLine;
+ text = defaultHelpLine;
if (currentHelpline)
- (*(++currentHelpline)) = strdup(text);
+ (*(++currentHelpline)) = strdup(text);
else {
- currentHelpline = helplineStack;
- *currentHelpline = strdup(text);
+ currentHelpline = helplineStack;
+ *currentHelpline = strdup(text);
}
newtRedrawHelpLine();
free(*currentHelpline);
if (currentHelpline == helplineStack)
- currentHelpline = NULL;
+ currentHelpline = NULL;
else
- currentHelpline--;
+ currentHelpline--;
newtRedrawHelpLine();
}
SLsmg_set_color(NEWT_COLORSET_ROOTTEXT);
if (col < 0) {
- col = SLtt_Screen_Cols + col;
+ col = SLtt_Screen_Cols + col;
}
if (row < 0) {
- row = SLtt_Screen_Rows + row;
+ row = SLtt_Screen_Rows + row;
}
SLsmg_gotorc(row, col);
int newtSetFlags(int oldFlags, int newFlags, enum newtFlagsSense sense) {
switch (sense) {
case NEWT_FLAGS_SET:
- return oldFlags | newFlags;
+ return oldFlags | newFlags;
case NEWT_FLAGS_RESET:
- return oldFlags & (~newFlags);
+ return oldFlags & (~newFlags);
case NEWT_FLAGS_TOGGLE:
- return oldFlags ^ newFlags;
+ return oldFlags ^ newFlags;
default:
- return oldFlags;
+ return oldFlags;
}
}
void newtTrashScreen(void) {
if (trashScreen)
- SLsmg_touch_lines (0, SLtt_Screen_Rows - 1);
+ SLsmg_touch_lines (0, SLtt_Screen_Rows - 1);
}
#include <stdarg.h>
-#define NEWT_COLORSET_ROOT 2
-#define NEWT_COLORSET_BORDER 3
-#define NEWT_COLORSET_WINDOW 4
-#define NEWT_COLORSET_SHADOW 5
-#define NEWT_COLORSET_TITLE 6
-#define NEWT_COLORSET_BUTTON 7
-#define NEWT_COLORSET_ACTBUTTON 8
-#define NEWT_COLORSET_CHECKBOX 9
-#define NEWT_COLORSET_ACTCHECKBOX 10
-#define NEWT_COLORSET_ENTRY 11
-#define NEWT_COLORSET_LABEL 12
-#define NEWT_COLORSET_LISTBOX 13
-#define NEWT_COLORSET_ACTLISTBOX 14
-#define NEWT_COLORSET_TEXTBOX 15
-#define NEWT_COLORSET_ACTTEXTBOX 16
-#define NEWT_COLORSET_HELPLINE 17
-#define NEWT_COLORSET_ROOTTEXT 18
-#define NEWT_COLORSET_EMPTYSCALE 19
-#define NEWT_COLORSET_FULLSCALE 20
-#define NEWT_COLORSET_DISENTRY 21
-#define NEWT_COLORSET_COMPACTBUTTON 22
-#define NEWT_COLORSET_ACTSELLISTBOX 23
-#define NEWT_COLORSET_SELLISTBOX 24
-
-#define NEWT_ARG_LAST -100000
-#define NEWT_ARG_APPEND -1
+#define NEWT_COLORSET_ROOT 2
+#define NEWT_COLORSET_BORDER 3
+#define NEWT_COLORSET_WINDOW 4
+#define NEWT_COLORSET_SHADOW 5
+#define NEWT_COLORSET_TITLE 6
+#define NEWT_COLORSET_BUTTON 7
+#define NEWT_COLORSET_ACTBUTTON 8
+#define NEWT_COLORSET_CHECKBOX 9
+#define NEWT_COLORSET_ACTCHECKBOX 10
+#define NEWT_COLORSET_ENTRY 11
+#define NEWT_COLORSET_LABEL 12
+#define NEWT_COLORSET_LISTBOX 13
+#define NEWT_COLORSET_ACTLISTBOX 14
+#define NEWT_COLORSET_TEXTBOX 15
+#define NEWT_COLORSET_ACTTEXTBOX 16
+#define NEWT_COLORSET_HELPLINE 17
+#define NEWT_COLORSET_ROOTTEXT 18
+#define NEWT_COLORSET_EMPTYSCALE 19
+#define NEWT_COLORSET_FULLSCALE 20
+#define NEWT_COLORSET_DISENTRY 21
+#define NEWT_COLORSET_COMPACTBUTTON 22
+#define NEWT_COLORSET_ACTSELLISTBOX 23
+#define NEWT_COLORSET_SELLISTBOX 24
+
+#define NEWT_ARG_LAST -100000
+#define NEWT_ARG_APPEND -1
struct newtColors {
char * rootFg, * rootBg;
enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
-#define NEWT_FLAG_RETURNEXIT (1 << 0)
-#define NEWT_FLAG_HIDDEN (1 << 1)
-#define NEWT_FLAG_SCROLL (1 << 2)
-#define NEWT_FLAG_DISABLED (1 << 3)
-/* OBSOLETE #define NEWT_FLAG_NOSCROLL (1 << 4) for listboxes */
-#define NEWT_FLAG_BORDER (1 << 5)
-#define NEWT_FLAG_WRAP (1 << 6)
-#define NEWT_FLAG_NOF12 (1 << 7)
+#define NEWT_FLAG_RETURNEXIT (1 << 0)
+#define NEWT_FLAG_HIDDEN (1 << 1)
+#define NEWT_FLAG_SCROLL (1 << 2)
+#define NEWT_FLAG_DISABLED (1 << 3)
+/* OBSOLETE #define NEWT_FLAG_NOSCROLL (1 << 4) for listboxes */
+#define NEWT_FLAG_BORDER (1 << 5)
+#define NEWT_FLAG_WRAP (1 << 6)
+#define NEWT_FLAG_NOF12 (1 << 7)
#define NEWT_FLAG_MULTIPLE (1 << 8)
-#define NEWT_FLAG_SELECTED (1 << 9)
-#define NEWT_FLAG_CHECKBOX (1 << 10)
+#define NEWT_FLAG_SELECTED (1 << 9)
+#define NEWT_FLAG_CHECKBOX (1 << 10)
#define NEWT_FLAG_PASSWORD (1 << 11) /* draw '*' of chars in entrybox */
#define NEWT_FLAG_SHOWCURSOR (1 << 12) /* Only applies to listbox for now */
-#define NEWT_FD_READ (1 << 0)
-#define NEWT_FD_WRITE (1 << 1)
-#define NEWT_FD_EXCEPT (1 << 2)
+#define NEWT_FD_READ (1 << 0)
+#define NEWT_FD_WRITE (1 << 1)
+#define NEWT_FD_EXCEPT (1 << 2)
-#define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12)
-#define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13)
+#define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12)
+#define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13)
-#define NEWT_CHECKBOXTREE_COLLAPSED '\0'
-#define NEWT_CHECKBOXTREE_EXPANDED '\1'
-#define NEWT_CHECKBOXTREE_UNSELECTED ' '
-#define NEWT_CHECKBOXTREE_SELECTED '*'
+#define NEWT_CHECKBOXTREE_COLLAPSED '\0'
+#define NEWT_CHECKBOXTREE_EXPANDED '\1'
+#define NEWT_CHECKBOXTREE_UNSELECTED ' '
+#define NEWT_CHECKBOXTREE_SELECTED '*'
/* Backwards compatibility */
#define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
-#define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
-#define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
-#define NEWT_ENTRY_RETURNEXIT NEWT_FLAG_RETURNEXIT
-#define NEWT_ENTRY_DISABLED NEWT_FLAG_DISABLED
+#define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
+#define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
+#define NEWT_ENTRY_RETURNEXIT NEWT_FLAG_RETURNEXIT
+#define NEWT_ENTRY_DISABLED NEWT_FLAG_DISABLED
-#define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
-#define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
-#define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
+#define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
+#define NEWT_TEXTBOX_SCROLL NEWT_FLAG_SCROLL
+#define NEWT_FORM_NOF12 NEWT_FLAG_NOF12
-#define newtListboxAddEntry newtListboxAppendEntry
+#define newtListboxAddEntry newtListboxAppendEntry
typedef struct newtComponent_struct * newtComponent;
void newtDelay(unsigned int usecs);
/* top, left are *not* counting the border */
int newtOpenWindow(unsigned int left,unsigned int top,
- unsigned int width,unsigned int height,
- const char * title);
+ unsigned int width,unsigned int height,
+ const char * title);
int newtCenteredWindow(unsigned int width,unsigned int height, const char * title);
void newtPopWindow(void);
void newtSetColors(struct newtColors colors);
newtComponent newtCompactButton(int left, int top, const char * text);
newtComponent newtButton(int left, int top, const char * text);
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
- const char * seq, char * result);
+ const char * seq, char * result);
char newtCheckboxGetValue(newtComponent co);
void newtCheckboxSetValue(newtComponent co, char value);
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
- newtComponent prevButton);
+ newtComponent prevButton);
newtComponent newtRadioGetCurrent(newtComponent setMember);
newtComponent newtListitem(int left, int top, const char * text, int isDefault,
- newtComponent prevItem, const void * data, int flags);
+ newtComponent prevItem, const void * data, int flags);
void newtListitemSet(newtComponent co, const char * text);
void * newtListitemGetData(newtComponent co);
void newtGetScreenSize(int * cols, int * rows);
newtComponent newtLabel(int left, int top, const char * text);
void newtLabelSetText(newtComponent co, const char * text);
newtComponent newtVerticalScrollbar(int left, int top, int height,
- int normalColorset, int thumbColorset);
+ int normalColorset, int thumbColorset);
void newtScrollbarSet(newtComponent co, int where, int total);
newtComponent newtListbox(int left, int top, int height, int flags);
void newtListboxSetWidth(newtComponent co, int width);
void newtListboxSetData(newtComponent co, int num, void * data);
int newtListboxAppendEntry(newtComponent co, const char * text,
- const void * data);
+ const void * data);
/* Send the key to insert after, or NULL to insert at the top */
int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, void * key);
int newtListboxDeleteEntry(newtComponent co, void * data);
void **newtListboxGetSelection(newtComponent co, int *numitems);
void newtListboxClearSelection(newtComponent co);
void newtListboxSelectItem(newtComponent co, const void * key,
- enum newtFlagsSense sense);
+ enum newtFlagsSense sense);
/* Returns number of items currently in listbox. */
int newtListboxItemCount(newtComponent co);
const void ** newtCheckboxTreeGetMultiSelection(newtComponent co, int *numitems, char seqnum);
/* last item is NEWT_ARG_LAST for all of these */
int newtCheckboxTreeAddItem(newtComponent co,
- const char * text, const void * data,
- int flags, int index, ...);
+ const char * text, const void * data,
+ int flags, int index, ...);
int newtCheckboxTreeAddArray(newtComponent co,
- const char * text, const void * data,
- int flags, int * indexes);
+ const char * text, const void * data,
+ int flags, int * indexes);
int * newtCheckboxTreeFindItem(newtComponent co, void * data);
void newtCheckboxTreeSetEntry(newtComponent co, const void * data,
- const char * text);
+ const char * text);
void newtCheckboxTreeSetWidth(newtComponent co, int width);
char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data);
void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data,
- char value);
+ char value);
newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
- int flexDown, int flexUp, int flags);
+ int flexDown, int flexUp, int flags);
newtComponent newtTextbox(int left, int top, int width, int height, int flags);
void newtTextboxSetText(newtComponent co, const char * text);
void newtTextboxSetHeight(newtComponent co, int height);
int newtTextboxGetNumLines(newtComponent co);
char * newtReflowText(char * text, int width, int flexDown, int flexUp,
- int * actualWidth, int * actualHeight);
+ int * actualWidth, int * actualHeight);
struct newtExitStruct {
enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,
- NEWT_EXIT_TIMER } reason;
+ NEWT_EXIT_TIMER } reason;
union {
- int watch;
- int key;
- newtComponent co;
+ int watch;
+ int key;
+ newtComponent co;
} u;
} ;
void newtFormAddComponents(newtComponent form, ...);
void newtFormSetHeight(newtComponent co, int height);
void newtFormSetWidth(newtComponent co, int width);
-newtComponent newtRunForm(newtComponent form); /* obsolete */
+newtComponent newtRunForm(newtComponent form); /* obsolete */
void newtFormRun(newtComponent co, struct newtExitStruct * es);
void newtDrawForm(newtComponent form);
void newtFormAddHotKey(newtComponent co, int key);
typedef int (*newtEntryFilter)(newtComponent entry, void * data, int ch,
- int cursor);
+ int cursor);
newtComponent newtEntry(int left, int top, const char * initialValue, int width,
- const char ** resultPtr, int flags);
+ const char ** resultPtr, int flags);
void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
char * newtEntryGetValue(newtComponent co);
/* this also destroys all of the components (including other forms) on the
form */
-void newtFormDestroy(newtComponent form);
+void newtFormDestroy(newtComponent form);
/* Key codes */
-#define NEWT_KEY_TAB '\t'
-#define NEWT_KEY_ENTER '\r'
-#define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
-#define NEWT_KEY_ESCAPE '\e'
-#define NEWT_KEY_RETURN NEWT_KEY_ENTER
-
-#define NEWT_KEY_EXTRA_BASE 0x8000
-#define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
-#define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
-#define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
-#define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
-#define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
-#define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
-#define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
-#define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
-#define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
-#define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
-#define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
-#define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
-
-#define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
-#define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
-#define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
-#define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
-#define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
-#define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
-#define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
-#define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
-#define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
-#define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
-#define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
-#define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
+#define NEWT_KEY_TAB '\t'
+#define NEWT_KEY_ENTER '\r'
+#define NEWT_KEY_SUSPEND '\032' /* ctrl - z*/
+#define NEWT_KEY_ESCAPE '\e'
+#define NEWT_KEY_RETURN NEWT_KEY_ENTER
+
+#define NEWT_KEY_EXTRA_BASE 0x8000
+#define NEWT_KEY_UP NEWT_KEY_EXTRA_BASE + 1
+#define NEWT_KEY_DOWN NEWT_KEY_EXTRA_BASE + 2
+#define NEWT_KEY_LEFT NEWT_KEY_EXTRA_BASE + 4
+#define NEWT_KEY_RIGHT NEWT_KEY_EXTRA_BASE + 5
+#define NEWT_KEY_BKSPC NEWT_KEY_EXTRA_BASE + 6
+#define NEWT_KEY_DELETE NEWT_KEY_EXTRA_BASE + 7
+#define NEWT_KEY_HOME NEWT_KEY_EXTRA_BASE + 8
+#define NEWT_KEY_END NEWT_KEY_EXTRA_BASE + 9
+#define NEWT_KEY_UNTAB NEWT_KEY_EXTRA_BASE + 10
+#define NEWT_KEY_PGUP NEWT_KEY_EXTRA_BASE + 11
+#define NEWT_KEY_PGDN NEWT_KEY_EXTRA_BASE + 12
+#define NEWT_KEY_INSERT NEWT_KEY_EXTRA_BASE + 13
+
+#define NEWT_KEY_F1 NEWT_KEY_EXTRA_BASE + 101
+#define NEWT_KEY_F2 NEWT_KEY_EXTRA_BASE + 102
+#define NEWT_KEY_F3 NEWT_KEY_EXTRA_BASE + 103
+#define NEWT_KEY_F4 NEWT_KEY_EXTRA_BASE + 104
+#define NEWT_KEY_F5 NEWT_KEY_EXTRA_BASE + 105
+#define NEWT_KEY_F6 NEWT_KEY_EXTRA_BASE + 106
+#define NEWT_KEY_F7 NEWT_KEY_EXTRA_BASE + 107
+#define NEWT_KEY_F8 NEWT_KEY_EXTRA_BASE + 108
+#define NEWT_KEY_F9 NEWT_KEY_EXTRA_BASE + 109
+#define NEWT_KEY_F10 NEWT_KEY_EXTRA_BASE + 110
+#define NEWT_KEY_F11 NEWT_KEY_EXTRA_BASE + 111
+#define NEWT_KEY_F12 NEWT_KEY_EXTRA_BASE + 112
/* not really a key, but newtGetKey returns it */
-#define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
+#define NEWT_KEY_RESIZE NEWT_KEY_EXTRA_BASE + 113
-#define NEWT_ANCHOR_LEFT (1 << 0)
-#define NEWT_ANCHOR_RIGHT (1 << 1)
-#define NEWT_ANCHOR_TOP (1 << 2)
-#define NEWT_ANCHOR_BOTTOM (1 << 3)
+#define NEWT_ANCHOR_LEFT (1 << 0)
+#define NEWT_ANCHOR_RIGHT (1 << 1)
+#define NEWT_ANCHOR_TOP (1 << 2)
+#define NEWT_ANCHOR_BOTTOM (1 << 3)
-#define NEWT_GRID_FLAG_GROWX (1 << 0)
-#define NEWT_GRID_FLAG_GROWY (1 << 1)
+#define NEWT_GRID_FLAG_GROWX (1 << 0)
+#define NEWT_GRID_FLAG_GROWY (1 << 1)
typedef struct grid_s * newtGrid;
enum newtGridElement { NEWT_GRID_EMPTY = 0,
- NEWT_GRID_COMPONENT, NEWT_GRID_SUBGRID };
+ NEWT_GRID_COMPONENT, NEWT_GRID_SUBGRID };
newtGrid newtCreateGrid(int cols, int rows);
/* TYPE, what, TYPE, what, ..., NULL */
newtGrid newtGridHStacked(enum newtGridElement type1, void * what1, ...);
newtGrid newtGridHCloseStacked(enum newtGridElement type1, void * what1, ...);
newtGrid newtGridBasicWindow(newtComponent text, newtGrid middle,
- newtGrid buttons);
+ newtGrid buttons);
newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle,
- newtGrid buttons);
+ newtGrid buttons);
void newtGridSetField(newtGrid grid, int col, int row,
- enum newtGridElement type, void * val, int padLeft,
- int padTop, int padRight, int padBottom, int anchor,
- int flags);
+ enum newtGridElement type, void * val, int padLeft,
+ int padTop, int padRight, int padBottom, int anchor,
+ int flags);
void newtGridPlace(newtGrid grid, int left, int top);
#define newtGridDestroy newtGridFree
void newtGridFree(newtGrid grid, int recurse);
void newtGridWrappedWindow(newtGrid grid, char * title);
void newtGridWrappedWindowAt(newtGrid grid, char * title, int left, int top);
void newtGridAddComponentsToForm(newtGrid grid, newtComponent form,
- int recurse);
+ int recurse);
/* convienve */
newtGrid newtButtonBarv(char * button1, newtComponent * b1comp, va_list args);
/* automatically centered and shrink wrapped */
void newtWinMessage(char * title, char * buttonText, char * text, ...);
void newtWinMessagev(char * title, char * buttonText, char * text,
- va_list argv);
+ va_list argv);
/* having separate calls for these two seems silly, but having two separate
variable length-arg lists seems like a bad idea as well */
/* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
int newtWinChoice(char * title, char * button1, char * button2,
- char * text, ...);
+ char * text, ...);
/* Returns 0 if F12 was pressed, 1 for button1, 2 for button2,
3 for button3 */
int newtWinTernary(char * title, char * button1, char * button2,
- char * button3, char * message, ...);
+ char * button3, char * message, ...);
/* Returns the button number pressed, 0 on F12 */
int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown,
- int flexUp, int maxListHeight, char ** items, int * listItem,
- char * button1, ...);
+ int flexUp, int maxListHeight, char ** items, int * listItem,
+ char * button1, ...);
struct newtWinEntry {
char * text;
- const char ** value; /* may be initialized to set default */
+ const char ** value; /* may be initialized to set default */
int flags;
};
/* Returns the button number pressed, 0 on F12. The final values are
dynamically allocated, and need to be freed. */
int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown,
- int flexUp, int dataWidth,
- struct newtWinEntry * items, char * button1, ...);
+ int flexUp, int dataWidth,
+ struct newtWinEntry * items, char * button1, ...);
#ifdef __cplusplus
} /* End of extern "C" { */
#ifndef H_NEWT_PR
#define H_NEWT_PR
-#define COLORSET_ROOT NEWT_COLORSET_ROOT
-#define COLORSET_BORDER NEWT_COLORSET_BORDER
-#define COLORSET_WINDOW NEWT_COLORSET_WINDOW
-#define COLORSET_SHADOW NEWT_COLORSET_SHADOW
-#define COLORSET_TITLE NEWT_COLORSET_TITLE
-#define COLORSET_BUTTON NEWT_COLORSET_BUTTON
-#define COLORSET_ACTBUTTON NEWT_COLORSET_ACTBUTTON
-#define COLORSET_CHECKBOX NEWT_COLORSET_CHECKBOX
-#define COLORSET_ACTCHECKBOX NEWT_COLORSET_ACTCHECKBOX
-#define COLORSET_ENTRY NEWT_COLORSET_ENTRY
-#define COLORSET_LABEL NEWT_COLORSET_LABEL
-#define COLORSET_LISTBOX NEWT_COLORSET_LISTBOX
-#define COLORSET_ACTLISTBOX NEWT_COLORSET_ACTLISTBOX
-#define COLORSET_TEXTBOX NEWT_COLORSET_TEXTBOX
-#define COLORSET_ACTTEXTBOX NEWT_COLORSET_ACTTEXTBOX
+#define COLORSET_ROOT NEWT_COLORSET_ROOT
+#define COLORSET_BORDER NEWT_COLORSET_BORDER
+#define COLORSET_WINDOW NEWT_COLORSET_WINDOW
+#define COLORSET_SHADOW NEWT_COLORSET_SHADOW
+#define COLORSET_TITLE NEWT_COLORSET_TITLE
+#define COLORSET_BUTTON NEWT_COLORSET_BUTTON
+#define COLORSET_ACTBUTTON NEWT_COLORSET_ACTBUTTON
+#define COLORSET_CHECKBOX NEWT_COLORSET_CHECKBOX
+#define COLORSET_ACTCHECKBOX NEWT_COLORSET_ACTCHECKBOX
+#define COLORSET_ENTRY NEWT_COLORSET_ENTRY
+#define COLORSET_LABEL NEWT_COLORSET_LABEL
+#define COLORSET_LISTBOX NEWT_COLORSET_LISTBOX
+#define COLORSET_ACTLISTBOX NEWT_COLORSET_ACTLISTBOX
+#define COLORSET_TEXTBOX NEWT_COLORSET_TEXTBOX
+#define COLORSET_ACTTEXTBOX NEWT_COLORSET_ACTTEXTBOX
int newtSetFlags(int oldFlags, int newFlags, enum newtFlagsSense sense);
} ;
enum eventResultTypes { ER_IGNORED, ER_SWALLOWED, ER_EXITFORM, ER_SETFOCUS,
- ER_NEXTCOMP };
+ ER_NEXTCOMP };
struct eventResult {
enum eventResultTypes result;
union {
- newtComponent focus;
+ newtComponent focus;
} u;
};
enum eventTypes event;
enum eventSequence when;
union {
- int key;
- struct {
- enum { MOUSE_MOTION, MOUSE_BUTTON_DOWN, MOUSE_BUTTON_UP } type;
- int x, y;
- } mouse;
+ int key;
+ struct {
+ enum { MOUSE_MOTION, MOUSE_BUTTON_DOWN, MOUSE_BUTTON_UP } type;
+ int x, y;
+ } mouse;
} u;
} ;
void newtDefaultPlaceHandler(newtComponent c, int newLeft, int newTop);
void newtDefaultMappedHandler(newtComponent c, int isMapped);
struct eventResult newtDefaultEventHandler(newtComponent c,
- struct event ev);
+ struct event ev);
int wstrlen(const char *str, int len);
newPercentage = (amount * 100) / sc->fullValue;
if (newPercentage > 100)
- newPercentage = 100;
+ newPercentage = 100;
if (newPercentage != sc->percentage) {
- sc->percentage = newPercentage;
- scaleDraw(co);
+ sc->percentage = newPercentage;
+ scaleDraw(co);
}
}
int new;
if (sb->arrows)
- new = (where * (co->height - 3)) / (total ? total : 1) + 1;
+ new = (where * (co->height - 3)) / (total ? total : 1) + 1;
else
- new = (where * (co->height - 1)) / (total ? total : 1);
+ new = (where * (co->height - 1)) / (total ? total : 1);
if (new != sb->curr) {
- sbDrawThumb(co, 0);
- sb->curr = new;
- sbDrawThumb(co, 1);
+ sbDrawThumb(co, 0);
+ sb->curr = new;
+ sbDrawThumb(co, 1);
}
}
newtComponent newtVerticalScrollbar(int left, int top, int height,
- int normalColorset, int thumbColorset) {
+ int normalColorset, int thumbColorset) {
newtComponent co;
struct scrollbar * sb;
co->data = sb;
if (!strcmp(getenv("TERM"), "linux") && height >= 2) {
- sb->arrows = 1;
- sb->curr = 1;
+ sb->arrows = 1;
+ sb->curr = 1;
} else {
- sb->arrows = 0;
- sb->curr = 0;
+ sb->arrows = 0;
+ sb->curr = 0;
}
sb->cs = normalColorset;
sb->csThumb = thumbColorset;
SLsmg_set_char_set(1);
if (sb->arrows) {
- newtGotorc(co->top, co->left);
- SLsmg_write_char(SLSMG_UARROW_CHAR);
- for (i = 1; i < co->height - 1; i++) {
- newtGotorc(i + co->top, co->left);
- SLsmg_write_char(SLSMG_CKBRD_CHAR);
- }
- newtGotorc(co->top + co->height - 1, co->left);
- SLsmg_write_char(SLSMG_DARROW_CHAR);
+ newtGotorc(co->top, co->left);
+ SLsmg_write_char(SLSMG_UARROW_CHAR);
+ for (i = 1; i < co->height - 1; i++) {
+ newtGotorc(i + co->top, co->left);
+ SLsmg_write_char(SLSMG_CKBRD_CHAR);
+ }
+ newtGotorc(co->top + co->height - 1, co->left);
+ SLsmg_write_char(SLSMG_DARROW_CHAR);
} else {
- for (i = 0; i < co->height; i++) {
- newtGotorc(i + co->top, co->left);
- SLsmg_write_char(SLSMG_CKBRD_CHAR);
- }
+ for (i = 0; i < co->height; i++) {
+ newtGotorc(i + co->top, co->left);
+ SLsmg_write_char(SLSMG_CKBRD_CHAR);
+ }
}
SLsmg_set_char_set(0);
SLsmg_set_char_set(1);
/*if (isOn)
- SLsmg_set_color(sb->csThumb);
+ SLsmg_set_color(sb->csThumb);
else*/
- SLsmg_set_color(sb->cs);
+ SLsmg_set_color(sb->cs);
SLsmg_write_char(ch);
SLsmg_set_char_set(0);
SLsmg_gotorc(0, offset);
SLsmg_write_string(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
for (i = 0; i < 16; i++) {
- SLsmg_gotorc(i + 1, offset);
- SLsmg_printf("%x", i);
- for (j = 0; j < 16; j++) {
- SLsmg_gotorc(i + 1, (j + 1) * 2 + offset);
- SLsmg_write_char(n++);
- }
+ SLsmg_gotorc(i + 1, offset);
+ SLsmg_printf("%x", i);
+ for (j = 0; j < 16; j++) {
+ SLsmg_gotorc(i + 1, (j + 1) * 2 + offset);
+ SLsmg_write_char(n++);
+ }
}
}
buf = SLtt_tgetstr("ku");
if (!buf) {
- printf("termcap entry not found for kl\n\r");
+ printf("termcap entry not found for kl\n\r");
} else {
- printf("termcap entry found for kl: %s", buf);
- while (*buf) {
- printf("0x%02x ", *buf++);
- }
- printf("\n\r");
+ printf("termcap entry found for kl: %s", buf);
+ while (*buf) {
+ printf("0x%02x ", *buf++);
+ }
+ printf("\n\r");
}
printf("\n\r");
printf("You pressed: ");
while (SLang_input_pending(1)) {
- i = SLang_getkey();
- printf("0x%02x ", i);
+ i = SLang_getkey();
+ printf("0x%02x ", i);
}
printf("\n\r");
"snackgrid", /* tp_name */
sizeof(snackGrid), /* tp_size */
0, /* tp_itemsize */
- emptyDestructor, /* tp_dealloc */
+ emptyDestructor, /* tp_dealloc */
0, /* tp_print */
- gridGetAttr, /* tp_getattr */
+ gridGetAttr, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
+ 0, /* tp_as_mapping */
};
struct snackForm_s {
"snackform", /* tp_name */
sizeof(snackForm), /* tp_size */
0, /* tp_itemsize */
- emptyDestructor, /* tp_dealloc */
+ emptyDestructor, /* tp_dealloc */
0, /* tp_print */
- formGetAttr, /* tp_getattr */
+ formGetAttr, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
+ 0, /* tp_as_mapping */
};
struct snackWidget_s {
"snackwidget", /* tp_name */
sizeof(snackWidget), /* tp_size */
0, /* tp_itemsize */
- widgetDestructor, /* tp_dealloc */
+ widgetDestructor, /* tp_dealloc */
0, /* tp_print */
- widgetGetAttr, /* tp_getattr */
+ widgetGetAttr, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
+ 0, /* tp_as_mapping */
};
static snackWidget * snackWidgetNew (void) {
int width, height;
if (!PyArg_ParseTuple(args, ""))
- return NULL;
+ return NULL;
newtGetScreenSize(&width, &height);
PyObject * args, * result;
if (scs->data) {
- args = Py_BuildValue("(O)", scs->data);
- result = PyEval_CallObject(scs->cb, args);
- Py_DECREF (args);
+ args = Py_BuildValue("(O)", scs->data);
+ result = PyEval_CallObject(scs->cb, args);
+ Py_DECREF (args);
} else
- result = PyEval_CallObject(scs->cb, NULL);
+ result = PyEval_CallObject(scs->cb, NULL);
if (!result) {
- PyErr_Print();
- PyErr_Clear();
+ PyErr_Print();
+ PyErr_Clear();
}
Py_XDECREF(result);
PyObject * args, * result;
if (scs->data) {
- args = Py_BuildValue("(O)", scs->data);
- result = PyEval_CallObject(scs->cb, args);
- Py_DECREF (args);
+ args = Py_BuildValue("(O)", scs->data);
+ result = PyEval_CallObject(scs->cb, args);
+ Py_DECREF (args);
} else
- result = PyEval_CallObject(scs->cb, NULL);
+ result = PyEval_CallObject(scs->cb, NULL);
if (!result) {
- PyErr_Print();
- PyErr_Clear();
+ PyErr_Print();
+ PyErr_Clear();
}
Py_XDECREF(result);
static PyObject * setSuspendCallback(PyObject * s, PyObject * args) {
if (!PyArg_ParseTuple(args, "O|O", &suspend.cb, &suspend.data))
- return NULL;
+ return NULL;
Py_INCREF (suspend.cb);
Py_XINCREF (suspend.data);
static PyObject * setHelpCallback(PyObject * s, PyObject * args) {
if (!PyArg_ParseTuple(args, "O", &helpCallback.cb))
- return NULL;
+ return NULL;
/*if (helpCallback.cb) {
- Py_DECREF (helpCallback.cb);
+ Py_DECREF (helpCallback.cb);
}*/
Py_INCREF (helpCallback.cb);
char * text;
if (!PyArg_ParseTuple(args, "iis", &left, &top, &text))
- return NULL;
+ return NULL;
newtDrawRootText(left, top, text);
char * text;
if (!PyArg_ParseTuple(args, "s", &text))
- return NULL;
+ return NULL;
if (!strcmp(text, "*default*"))
- newtPushHelpLine(NULL);
+ newtPushHelpLine(NULL);
else
- newtPushHelpLine(text);
+ newtPushHelpLine(text);
Py_INCREF(Py_None);
return Py_None;
PyObject * tuple;
if (!PyArg_ParseTuple(args, "si|ii", &text, &width, &minus, &plus))
- return NULL;
+ return NULL;
new = newtReflowText(text, width, minus, plus, &realWidth, &realHeight);
char * title;
if (!PyArg_ParseTuple(args, "iis", &width, &height, &title))
- return NULL;
+ return NULL;
newtCenteredWindow(width, height, title);
int x = -1, y = -1;
if (!PyArg_ParseTuple(args, "O!s|ii", &snackGridType, &grid, &title,
- &x, &y))
- return NULL;
+ &x, &y))
+ return NULL;
if (y == -1)
- newtGridWrappedWindow(grid->grid, title);
+ newtGridWrappedWindow(grid->grid, title);
else
- newtGridWrappedWindowAt(grid->grid, title, x, y);
+ newtGridWrappedWindowAt(grid->grid, title, x, y);
Py_INCREF(Py_None);
return Py_None;
char * title;
if (!PyArg_ParseTuple(args, "iiiis", &left, &top, &width, &height, &title))
- return NULL;
+ return NULL;
newtOpenWindow(left, top, width, height, title);
char * okbutton = "Ok";
if (!PyArg_ParseTuple(args, "ss|s", &title, &text, &okbutton))
- return NULL;
+ return NULL;
newtWinMessage(title, okbutton, text);
int rc;
if (!PyArg_ParseTuple(args, "ss|ss", &title, &text, &okbutton,
- &cancelbutton))
- return NULL;
+ &cancelbutton))
+ return NULL;
rc = newtWinChoice(title, okbutton, cancelbutton, text);
int rc;
if (!PyArg_ParseTuple(args, "sssss", &title, &text, &button1, &button2,
- &button3))
- return NULL;
+ &button3))
+ return NULL;
rc = newtWinTernary(title, button1, button2, button3, text);
int doScroll = 0, returnExit = 0, showCursor = 0 ;
if (!PyArg_ParseTuple(args, "i|iii", &height, &doScroll, &returnExit, &showCursor))
- return NULL;
+ return NULL;
widget = snackWidgetNew ();
widget->co = newtListbox(-1, -1, height,
- (doScroll ? NEWT_FLAG_SCROLL : 0) |
- (returnExit ? NEWT_FLAG_RETURNEXIT : 0) |
- (showCursor ? NEWT_FLAG_SHOWCURSOR : 0)
- );
+ (doScroll ? NEWT_FLAG_SCROLL : 0) |
+ (returnExit ? NEWT_FLAG_RETURNEXIT : 0) |
+ (showCursor ? NEWT_FLAG_SHOWCURSOR : 0)
+ );
widget->anint = 1;
return widget;
snackWidget * widget;
if (!PyArg_ParseTuple(args, "iis|ii", &width, &height, &text, &scrollBar, &wrap))
- return NULL;
+ return NULL;
widget = snackWidgetNew ();
widget->co = newtTextbox(-1, -1, width, height,
- (scrollBar ? NEWT_FLAG_SCROLL : 0) |
- (wrap ? NEWT_FLAG_WRAP : 0));
+ (scrollBar ? NEWT_FLAG_SCROLL : 0) |
+ (wrap ? NEWT_FLAG_WRAP : 0));
newtTextboxSetText(widget->co, text);
return widget;
int isOn;
if (!PyArg_ParseTuple(args, "sOi", &text, &group, &isOn))
- return NULL;
+ return NULL;
widget = snackWidgetNew ();
if ((PyObject *) group == Py_None)
- widget->co = newtRadiobutton(-1, -1, text, isOn, NULL);
+ widget->co = newtRadiobutton(-1, -1, text, isOn, NULL);
else
- widget->co = newtRadiobutton(-1, -1, text, isOn, group->co);
+ widget->co = newtRadiobutton(-1, -1, text, isOn, group->co);
return widget;
}
widget = snackWidgetNew ();
widget->co = newtCheckbox(-1, -1, text, isOn ? '*' : ' ', NULL,
- &widget->achar);
+ &widget->achar);
return widget;
}
int isHidden, isScrolled, returnExit, isPassword;
if (!PyArg_ParseTuple(args, "isiiii", &width, &initial,
- &isHidden, &isPassword, &isScrolled, &returnExit)) return NULL;
+ &isHidden, &isPassword, &isScrolled, &returnExit)) return NULL;
widget = snackWidgetNew ();
widget->co = newtEntry(-1, -1, initial, width,
(const char **) &widget->apointer,
- (isHidden ? NEWT_FLAG_HIDDEN : 0) |
- (isPassword ? NEWT_FLAG_PASSWORD : 0) |
- (returnExit ? NEWT_FLAG_RETURNEXIT : 0) |
- (isScrolled ? NEWT_FLAG_SCROLL : 0));
+ (isHidden ? NEWT_FLAG_HIDDEN : 0) |
+ (isPassword ? NEWT_FLAG_PASSWORD : 0) |
+ (returnExit ? NEWT_FLAG_RETURNEXIT : 0) |
+ (isScrolled ? NEWT_FLAG_SCROLL : 0));
return widget;
}
if (!PyArg_ParseTuple(args, "|O", &help)) return NULL;
if (help == Py_None)
- help = NULL;
+ help = NULL;
form = PyObject_NEW(snackForm, &snackFormType);
form->fo = newtForm(NULL, help, 0);
int anchorFlags = 0, growFlags = 0;
if (!PyArg_ParseTuple(args, "iiO|(iiii)ii", &x, &y,
- &w, &pLeft, &pTop, &pRight, &pBottom,
- &anchorFlags, &growFlags))
- return NULL;
+ &w, &pLeft, &pTop, &pRight, &pBottom,
+ &anchorFlags, &growFlags))
+ return NULL;
if (w->ob_type == &snackWidgetType) {
- newtGridSetField(grid->grid, x, y, NEWT_GRID_COMPONENT,
- w->co, pLeft, pTop, pRight, pBottom, anchorFlags,
- growFlags);
+ newtGridSetField(grid->grid, x, y, NEWT_GRID_COMPONENT,
+ w->co, pLeft, pTop, pRight, pBottom, anchorFlags,
+ growFlags);
} else {
- g = (snackGrid *) w;
- newtGridSetField(grid->grid, x, y, NEWT_GRID_SUBGRID,
- g->grid, pLeft, pTop, pRight, pBottom, anchorFlags,
- growFlags);
+ g = (snackGrid *) w;
+ newtGridSetField(grid->grid, x, y, NEWT_GRID_SUBGRID,
+ g->grid, pLeft, pTop, pRight, pBottom, anchorFlags,
+ growFlags);
}
Py_INCREF(Py_None);
int size = PyTuple_Size(args), i;
if (!size) {
- /* this is a hack, I should give an error directly */
- if (!PyArg_ParseTuple(args, "O!", &snackWidgetType, &w))
- return NULL;
+ /* this is a hack, I should give an error directly */
+ if (!PyArg_ParseTuple(args, "O!", &snackWidgetType, &w))
+ return NULL;
}
for (i = 0; i < size; i++) {
- w = (snackWidget *) PyTuple_GET_ITEM(args, i);
- newtFormAddComponent(s->fo, w->co);
+ w = (snackWidget *) PyTuple_GET_ITEM(args, i);
+ newtFormAddComponent(s->fo, w->co);
}
Py_INCREF(Py_None);
newtFormRun(s->fo, &result);
if (result.reason == NEWT_EXIT_HOTKEY)
- return Py_BuildValue("(si)", "hotkey", result.u.key);
+ return Py_BuildValue("(si)", "hotkey", result.u.key);
else if (result.reason == NEWT_EXIT_TIMER)
- return Py_BuildValue("(si)", "timer", 0);
+ return Py_BuildValue("(si)", "timer", 0);
else if (result.reason == NEWT_EXIT_FDREADY)
- return Py_BuildValue("(si)", "fdready", result.u.watch);
+ return Py_BuildValue("(si)", "fdready", result.u.watch);
else
- return Py_BuildValue("(si)", "widget", result.u.co);
+ return Py_BuildValue("(si)", "widget", result.u.co);
}
static PyObject * formHotKey(snackForm * s, PyObject * args) {
int key;
if (!PyArg_ParseTuple(args, "i", &key))
- return NULL;
+ return NULL;
newtFormAddHotKey(s->fo, key);
int millisecs;
if (!PyArg_ParseTuple(args, "i", &millisecs))
- return NULL;
+ return NULL;
newtFormSetTimer(form->fo, millisecs);
int fd, fdflags;
if (!PyArg_ParseTuple(args, "ii", &fd, &fdflags))
- return NULL;
+ return NULL;
newtFormWatchFd(form->fo, fd, fdflags);
snackWidget * w;
if (!PyArg_ParseTuple(args, "O", &w))
- return NULL;
+ return NULL;
newtFormSetCurrent(form->fo, w->co);
snackWidget * w = (snackWidget *) s;
if (!strcmp(name, "key")) {
- return Py_BuildValue("i", w->co);
+ return Py_BuildValue("i", w->co);
} else if (!strcmp(name, "entryValue")) {
- return Py_BuildValue("s", w->apointer);
+ return Py_BuildValue("s", w->apointer);
} else if (!strcmp(name, "checkboxValue")) {
- return Py_BuildValue("i", w->achar == ' ' ? 0 : 1);
+ return Py_BuildValue("i", w->achar == ' ' ? 0 : 1);
} else if (!strcmp(name, "radioValue")) {
- return Py_BuildValue("i", newtRadioGetCurrent(w->co));
+ return Py_BuildValue("i", newtRadioGetCurrent(w->co));
}
return Py_FindMethod(widgetMethods, s, name);
s->scs.data = NULL;
if (!PyArg_ParseTuple(args, "O|O", &s->scs.cb, &s->scs.data))
- return NULL;
+ return NULL;
Py_INCREF (s->scs.cb);
Py_XINCREF (s->scs.data);
char * val;
if (!PyArg_ParseTuple(args, "s", &val))
- return NULL;
+ return NULL;
newtEntrySet(s->co, val, 1);
char * text;
if (!PyArg_ParseTuple(args, "s", &text))
- return NULL;
+ return NULL;
newtListboxAddEntry(s->co, text, I2P(s->anint));
int key;
if (!PyArg_ParseTuple(args, "si", &text, &key))
- return NULL;
+ return NULL;
newtListboxInsertEntry(s->co, text, I2P(s->anint), I2P(key));
int key;
if (!PyArg_ParseTuple(args, "i", &key))
- return NULL;
+ return NULL;
newtListboxDeleteEntry(s->co, I2P(key));
static PyObject * widgetListboxGet(snackWidget * s, PyObject * args) {
if (!PyArg_ParseTuple(args, ""))
- return NULL;
+ return NULL;
return PyInt_FromLong((long) newtListboxGetCurrent(s->co));
}
int index;
if (!PyArg_ParseTuple(args, "i", &index))
- return NULL;
+ return NULL;
newtListboxSetCurrentByKey(s->co, I2P(index));
int width;
if (!PyArg_ParseTuple(args, "i", &width))
- return NULL;
+ return NULL;
newtListboxSetWidth(s->co, width);
const char *kw[] = {"height", "scrollbar", "hide_checkbox", "unselectable", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii", (char **) kw,
- &height, &scrollBar, &hide_checkbox, &unselectable))
- return NULL;
+ &height, &scrollBar, &hide_checkbox, &unselectable))
+ return NULL;
flags = (scrollBar ? NEWT_FLAG_SCROLL : 0) |
- (hide_checkbox ? NEWT_CHECKBOXTREE_HIDE_BOX : 0) |
- (unselectable ? NEWT_CHECKBOXTREE_UNSELECTABLE : 0);
+ (hide_checkbox ? NEWT_CHECKBOXTREE_HIDE_BOX : 0) |
+ (unselectable ? NEWT_CHECKBOXTREE_UNSELECTABLE : 0);
widget = snackWidgetNew ();
widget->co = newtCheckboxTree(-1, -1, height, flags);
int i;
if (!PyArg_ParseTuple(args, "sOi", &text, &pathList, &selected))
- return NULL;
+ return NULL;
len = PyTuple_Size(pathList);
path = alloca(sizeof(*path) * (len + 1));
for (i = 0; i < len; i++) {
o = PyTuple_GetItem(pathList, i);
- path[i] = PyInt_AsLong(o);
+ path[i] = PyInt_AsLong(o);
}
path[len] = NEWT_ARG_LAST;
newtCheckboxTreeAddArray(s->co, text, I2P(s->anint),
- selected ? NEWT_FLAG_SELECTED : 0, path);
+ selected ? NEWT_FLAG_SELECTED : 0, path);
return PyInt_FromLong(s->anint++);
}
static PyObject * widgetCheckboxTreeGetCur(snackWidget * s, PyObject * args) {
if (!PyArg_ParseTuple(args, ""))
- return NULL;
+ return NULL;
return PyInt_FromLong((long)newtCheckboxTreeGetCurrent(s->co));
}
int width;
if (!PyArg_ParseTuple(args, "i", &width))
- return NULL;
+ return NULL;
newtCheckboxTreeSetWidth(s->co, width);
if (!PyArg_ParseTuple(args, "i|i", &data, &isOn)) return NULL;
newtCheckboxTreeSetEntryValue(s->co, I2P(data),
- isOn ? NEWT_CHECKBOXTREE_SELECTED :
- NEWT_CHECKBOXTREE_UNSELECTED);
+ isOn ? NEWT_CHECKBOXTREE_SELECTED :
+ NEWT_CHECKBOXTREE_UNSELECTED);
Py_INCREF(Py_None);
return Py_None;
switch (selection) {
case NEWT_CHECKBOXTREE_EXPANDED:
- isOn = 1;
+ isOn = 1;
case NEWT_CHECKBOXTREE_COLLAPSED:
- isBranch = 1;
- break;
+ isBranch = 1;
+ break;
case NEWT_CHECKBOXTREE_UNSELECTED:
- break;
+ break;
default:
- isOn = 1;
- break;
+ isOn = 1;
+ break;
}
return Py_BuildValue("(ii)", isBranch, isOn);
}
static PyObject * widgetCheckboxTreeGetSel(snackWidget * s,
- PyObject * args) {
+ PyObject * args) {
void ** selection;
int numselected;
int i;
PyObject * sel;
if (!PyArg_ParseTuple(args, ""))
- return NULL;
+ return NULL;
selection = (void **) newtCheckboxTreeGetSelection(s->co, &numselected);
sel = PyList_New(0);
if (!selection) {
- return sel;
+ return sel;
}
sel = PyList_New(0);
for (i = 0; i < numselected; i++) {
- PyList_Append(sel, PyInt_FromLong((long) selection[i]));
+ PyList_Append(sel, PyInt_FromLong((long) selection[i]));
}
free(selection);
PyDict_SetItemString(d, "ANCHOR_TOP", PyInt_FromLong(NEWT_ANCHOR_TOP));
PyDict_SetItemString(d, "ANCHOR_RIGHT", PyInt_FromLong(NEWT_ANCHOR_RIGHT));
PyDict_SetItemString(d, "ANCHOR_BOTTOM",
- PyInt_FromLong(NEWT_ANCHOR_BOTTOM));
+ PyInt_FromLong(NEWT_ANCHOR_BOTTOM));
PyDict_SetItemString(d, "GRID_GROWX", PyInt_FromLong(NEWT_GRID_FLAG_GROWX));
PyDict_SetItemString(d, "GRID_GROWY", PyInt_FromLong(NEWT_GRID_FLAG_GROWY));
struct callbackInfo * cbi = data;
if (*cbi->state == ' ') {
- newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
+ newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
} else {
- newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
+ newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
}
newtRefresh();
newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);
for (i = 0; i < 10; i++) {
- sprintf(buf, "Check %d", i);
- cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
- newtFormAddComponent(chklist, cs[i]);
+ sprintf(buf, "Check %d", i);
+ cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);
+ newtFormAddComponent(chklist, cs[i]);
}
l1 = newtLabel(3, 6, "Scale:");
newtFormAddComponents(f, rsf, scale, NULL);
lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
- NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
+ NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
newtListboxAppendEntry(lb, "First", (void *) 1);
newtListboxAppendEntry(lb, "Second", (void *) 2);
newtListboxAppendEntry(lb, "Third", (void *) 3);
newtFormSetTimer(f, 200);
do {
- newtFormRun(f, &es);
-
- if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
- newtScaleSet(scale, atoi(scaleVal));
- newtRefresh();
- answer = NULL;
- } else if (es.reason == NEWT_EXIT_TIMER) {
- spinState++;
- if (!*spinState) spinState = spinner;
- sprintf(buf, "Spinner: %c", *spinState);
- newtLabelSetText(timeLabel, buf);
- }
+ newtFormRun(f, &es);
+
+ if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
+ newtScaleSet(scale, atoi(scaleVal));
+ newtRefresh();
+ answer = NULL;
+ } else if (es.reason == NEWT_EXIT_TIMER) {
+ spinState++;
+ if (!*spinState) spinState = spinner;
+ sprintf(buf, "Spinner: %c", *spinState);
+ newtLabelSetText(timeLabel, buf);
+ }
} while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);
scaleVal = strdup(scaleVal);
printf("\nSelected listbox items (%d):\n", numsel);
if(selectedList) {
- for(i = 0; i < numsel; i++)
- printf("#%d\n", (int) selectedList[i]);
+ for(i = 0; i < numsel; i++)
+ printf("#%d\n", (int) selectedList[i]);
}
return 0;
char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
const char * entries[10];
struct newtWinEntry autoEntries[] = {
- { "An entry", entries + 0, 0 },
- { "Another entry", entries + 1, 0 },
- { "Third entry", entries + 2, 0 },
- { "Fourth entry", entries + 3, 0 },
- { NULL, NULL, 0 } };
+ { "An entry", entries + 0, 0 },
+ { "Another entry", entries + 1, 0 },
+ { "Third entry", entries + 2, 0 },
+ { "Fourth entry", entries + 3, 0 },
+ { NULL, NULL, 0 } };
memset(entries, 0, sizeof(entries));
grid = newtCreateGrid(2, 2);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0,
- NEWT_ANCHOR_RIGHT, 0);
+ NEWT_ANCHOR_RIGHT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
newtGridFree(grid, 1);
answer = newtRunForm(f);
-
+
newtFormDestroy(f);
newtPopWindow();
flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
- "columns long, so some wrapping should be "
- "done. Did you know that the quick, brown "
- "fox jumped over the lazy dog?\n\n"
- "In other news, it's pretty important that we "
- "can properly force a line break.",
- 40, 5, 5, &textWidth, &textHeight);
+ "columns long, so some wrapping should be "
+ "done. Did you know that the quick, brown "
+ "fox jumped over the lazy dog?\n\n"
+ "In other news, it's pretty important that we "
+ "can properly force a line break.",
+ 40, 5, 5, &textWidth, &textHeight);
t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
newtTextboxSetText(t, flowedText);
free(flowedText);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
- NEWT_GRID_FLAG_GROWX);
+ NEWT_GRID_FLAG_GROWX);
newtGridWrappedWindow(grid, "another example");
newtGridDestroy(grid, 1);
textWidth = 0;
rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
- "newtWinMenu() call. It may or may not have a scrollbar, "
- "depending on the need for one.", 50, 5, 5, 3,
- menuContents, &textWidth, "Ok", "Cancel", NULL);
+ "newtWinMenu() call. It may or may not have a scrollbar, "
+ "depending on the need for one.", 50, 5, 5, 3,
+ menuContents, &textWidth, "Ok", "Cancel", NULL);
rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
- "newtWinEntries() call. It lets you get a lot of input "
- "quite easily.", 50, 5, 5, 20, autoEntries, "Ok",
- "Cancel", NULL);
+ "newtWinEntries() call. It lets you get a lot of input "
+ "quite easily.", 50, 5, 5, 20, autoEntries, "Ok",
+ "Cancel", NULL);
newtFinished();
checktree = newtCheckboxTreeMulti(-1, -1, 10, " ab", NEWT_FLAG_SCROLL);
newtCheckboxTreeAddItem(checktree, "Numbers", (void *) 2, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Really really long thing",
- (void *) 3, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ (void *) 3, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 5", (void *) 5,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 6", (void *) 6, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 7", (void *) 7,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 8", (void *) 8, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 9", (void *) 9, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 10", (void *) 10,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 11", (void *) 11, 0,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Donuts", (void *) 12,
- NEWT_FLAG_SELECTED,
- NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Bavarian Cream", (void *) 301,
- NEWT_FLAG_SELECTED,
- 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Honey dipped", (void *) 302,
- NEWT_FLAG_SELECTED,
- 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Jelly", (void *) 303,
- NEWT_FLAG_SELECTED,
- 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ NEWT_FLAG_SELECTED,
+ 9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Colors", (void *) 1, 0,
- 0, NEWT_ARG_LAST);
+ 0, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Red", (void *) 100, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "White", (void *) 101, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Blue", (void *) 102, 0,
- 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "number 4", (void *) 4, 0,
- 3, NEWT_ARG_LAST);
+ 3, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Single digit", (void *) 200, 0,
- 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "One", (void *) 201, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Two", (void *) 202, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Three", (void *) 203, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Four", (void *) 204, 0,
- 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Double digit", (void *) 300, 0,
- 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Ten", (void *) 210, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Eleven", (void *) 211, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Twelve", (void *) 212, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeAddItem(checktree, "Thirteen", (void *) 213, 0,
- 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
+ 1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
newtCheckboxTreeSetCurrent(checktree, (void *) 12);
grid = newtCreateGrid(1, 2);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, checktree, 0, 0, 0, 1,
- NEWT_ANCHOR_RIGHT, 0);
+ NEWT_ANCHOR_RIGHT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, button, 0, 0, 0, 0,
- 0, 0);
+ 0, 0);
newtGridWrappedWindow(grid, "Checkbox Tree Test");
newtGridFree(grid, 1);
result = newtCheckboxTreeGetSelection(checktree, &numselected);
ptr = result;
if (!result || !numselected)
- printf("none selected\n");
+ printf("none selected\n");
else
- printf("Current selection (all) (%d):\n", numselected);
+ printf("Current selection (all) (%d):\n", numselected);
for (i = 0; i < numselected; i++) {
- j = (int) *ptr++;
- printf("%d\n", j);
+ j = (int) *ptr++;
+ printf("%d\n", j);
}
result = newtCheckboxTreeGetMultiSelection(checktree, &numselected, 'b');
ptr = result;
if (!result || !numselected)
- printf("none selected\n");
+ printf("none selected\n");
else
- printf("Current selection (b) (%d):\n",numselected);
+ printf("Current selection (b) (%d):\n",numselected);
for (i = 0; i < numselected; i++) {
- j = (int) *ptr++;
- printf("%d\n", j);
+ j = (int) *ptr++;
+ printf("%d\n", j);
}
-
+
if (result)
- free(result);
+ free(result);
list = newtCheckboxTreeFindItem(checktree, (void *) 213);
printf("path:");
static void textboxDraw(newtComponent co);
static void addLine(newtComponent co, const char * s, int len);
static void doReflow(const char * text, char ** resultPtr, int width,
- int * badness, int * heightPtr);
+ int * badness, int * heightPtr);
static struct eventResult textboxEvent(newtComponent c,
- struct event ev);
+ struct event ev);
static void textboxDestroy(newtComponent co);
static void textboxPlace(newtComponent co, int newLeft, int newTop);
static void textboxMapped(newtComponent co, int isMapped);
co->isMapped = isMapped;
if (tb->sb)
- tb->sb->ops->mapped(tb->sb, isMapped);
+ tb->sb->ops->mapped(tb->sb, isMapped);
}
static void textboxPlace(newtComponent co, int newLeft, int newTop) {
co->left = newLeft;
if (tb->sb)
- tb->sb->ops->place(tb->sb, co->left + co->width - 1, co->top);
+ tb->sb->ops->place(tb->sb, co->left + co->width - 1, co->top);
}
void newtTextboxSetHeight(newtComponent co, int height) {
}
newtComponent newtTextboxReflowed(int left, int top, char * text, int width,
- int flexDown, int flexUp, int flags) {
+ int flexDown, int flexUp, int flags) {
newtComponent co;
char * reflowedText;
int actWidth, actHeight;
reflowedText = newtReflowText(text, width, flexDown, flexUp,
- &actWidth, &actHeight);
+ &actWidth, &actHeight);
co = newtTextbox(left, top, actWidth, actHeight, NEWT_FLAG_WRAP);
newtTextboxSetText(co, reflowedText);
tb->blankline[width] = '\0';
if (flags & NEWT_FLAG_SCROLL) {
- co->width += 2;
- tb->sb = newtVerticalScrollbar(co->left + co->width - 1, co->top,
- co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX);
+ co->width += 2;
+ tb->sb = newtVerticalScrollbar(co->left + co->width - 1, co->top,
+ co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX);
} else {
- tb->sb = NULL;
+ tb->sb = NULL;
}
return co;
buf = malloc(bufAlloced + 1);
for (src = text, dest = buf; *src; src++) {
- if ((bufUsed + 10) > bufAlloced) {
- bufAlloced += strlen(text) / 2;
- buf = realloc(buf, bufAlloced + 1);
- dest = buf + bufUsed;
- }
- if (*src == '\t') {
- i = 8 - (linePos & 8);
- memset(dest, ' ', i);
- dest += i, bufUsed += i, linePos += i;
- } else {
- if (*src == '\n')
- linePos = 0;
- else
- linePos++;
-
- *dest++ = *src;
- bufUsed++;
- }
+ if ((bufUsed + 10) > bufAlloced) {
+ bufAlloced += strlen(text) / 2;
+ buf = realloc(buf, bufAlloced + 1);
+ dest = buf + bufUsed;
+ }
+ if (*src == '\t') {
+ i = 8 - (linePos & 8);
+ memset(dest, ' ', i);
+ dest += i, bufUsed += i, linePos += i;
+ } else {
+ if (*src == '\n')
+ linePos = 0;
+ else
+ linePos++;
+
+ *dest++ = *src;
+ bufUsed++;
+ }
}
*dest = '\0';
}
static void doReflow(const char * text, char ** resultPtr, int width,
- int * badness, int * heightPtr) {
+ int * badness, int * heightPtr) {
char * result = NULL;
const char * chptr, * end;
int i;
mbstate_t ps;
if (resultPtr) {
- /* XXX I think this will work */
- result = malloc(strlen(text) + (strlen(text) / width) + 2);
- *result = '\0';
+ /* XXX I think this will work */
+ result = malloc(strlen(text) + (strlen(text) / width) + 2);
+ *result = '\0';
}
-
+
memset(&ps,0,sizeof(mbstate_t));
while (*text) {
- end = strchr(text, '\n');
- if (!end)
- end = text + strlen(text);
-
- while (*text && text <= end) {
- int len;
-
- len = wstrlen(text, end - text);
- if (len < width) {
- if (result) {
- strncat(result, text, end - text);
- strcat(result, "\n");
- height++;
- }
-
- if (len < (width / 2)) {
-#ifdef DEBUG_WRAP
- fprintf(stderr,"adding %d\n",((width / 2) - (len)) / 2);
-#endif
- howbad += ((width / 2) - (len)) / 2;
- }
- text = end;
- if (*text) text++;
- } else {
- const char *spcptr = NULL;
- int spc =0,w2, x;
-
- chptr = text;
- w2 = 0;
- for (i = 0; i < width - 1;) {
- if ((x=mbrtowc(&tmp,chptr,end-chptr,&ps))<=0)
- break;
- if (spc && !iswspace(tmp))
- spc = 0;
- else if (!spc && iswspace(tmp)) {
- spc = 1;
- spcptr = chptr;
- w2 = i;
- }
- chptr += x;
- x = wcwidth(tmp);
- if (x>0)
- i+=x;
- }
- howbad += width - w2 + 1;
-#ifdef DEBUG_WRAP
- fprintf(stderr,"adding %d\n",width - w2 + 1, chptr);
-#endif
- if (spcptr) chptr = spcptr;
- if (result) {
- strncat(result, text, chptr - text );
- strcat(result, "\n");
- height++;
- }
-
- text = chptr;
- while (1) {
- if ((x=mbrtowc(&tmp,text,end-text,NULL))<=0)
- break;
- if (!iswspace(tmp)) break;
- text += x;
- }
- }
- }
+ end = strchr(text, '\n');
+ if (!end)
+ end = text + strlen(text);
+
+ while (*text && text <= end) {
+ int len;
+
+ len = wstrlen(text, end - text);
+ if (len < width) {
+ if (result) {
+ strncat(result, text, end - text);
+ strcat(result, "\n");
+ height++;
+ }
+
+ if (len < (width / 2)) {
+#ifdef DEBUG_WRAP
+ fprintf(stderr,"adding %d\n",((width / 2) - (len)) / 2);
+#endif
+ howbad += ((width / 2) - (len)) / 2;
+ }
+ text = end;
+ if (*text) text++;
+ } else {
+ const char *spcptr = NULL;
+ int spc =0,w2, x;
+
+ chptr = text;
+ w2 = 0;
+ for (i = 0; i < width - 1;) {
+ if ((x=mbrtowc(&tmp,chptr,end-chptr,&ps))<=0)
+ break;
+ if (spc && !iswspace(tmp))
+ spc = 0;
+ else if (!spc && iswspace(tmp)) {
+ spc = 1;
+ spcptr = chptr;
+ w2 = i;
+ }
+ chptr += x;
+ x = wcwidth(tmp);
+ if (x>0)
+ i+=x;
+ }
+ howbad += width - w2 + 1;
+#ifdef DEBUG_WRAP
+ fprintf(stderr,"adding %d\n",width - w2 + 1, chptr);
+#endif
+ if (spcptr) chptr = spcptr;
+ if (result) {
+ strncat(result, text, chptr - text );
+ strcat(result, "\n");
+ height++;
+ }
+
+ text = chptr;
+ while (1) {
+ if ((x=mbrtowc(&tmp,text,end-text,NULL))<=0)
+ break;
+ if (!iswspace(tmp)) break;
+ text += x;
+ }
+ }
+ }
}
if (badness) *badness = howbad;
}
char * newtReflowText(char * text, int width, int flexDown, int flexUp,
- int * actualWidth, int * actualHeight) {
+ int * actualWidth, int * actualHeight) {
int min, max;
int i;
char * result;
expandedText = expandTabs(text);
if (flexDown || flexUp) {
- min = width - flexDown;
- max = width + flexUp;
+ min = width - flexDown;
+ max = width + flexUp;
- minbad = -1;
- minbadwidth = width;
+ minbad = -1;
+ minbadwidth = width;
- for (i = min; i <= max; i++) {
- doReflow(expandedText, NULL, i, &howbad, NULL);
+ for (i = min; i <= max; i++) {
+ doReflow(expandedText, NULL, i, &howbad, NULL);
- if (minbad == -1 || howbad < minbad) {
- minbad = howbad;
- minbadwidth = i;
- }
- }
+ if (minbad == -1 || howbad < minbad) {
+ minbad = howbad;
+ minbadwidth = i;
+ }
+ }
- width = minbadwidth;
+ width = minbadwidth;
}
doReflow(expandedText, &result, width, NULL, actualHeight);
int badness, height;
if (tb->lines) {
- free(tb->lines);
- tb->linesAlloced = tb->numLines = 0;
+ free(tb->lines);
+ tb->linesAlloced = tb->numLines = 0;
}
expanded = expandTabs(text);
if (tb->doWrap) {
- doReflow(expanded, &reflowed, tb->textWidth, &badness, &height);
- free(expanded);
- expanded = reflowed;
+ doReflow(expanded, &reflowed, tb->textWidth, &badness, &height);
+ free(expanded);
+ expanded = reflowed;
}
for (start = expanded; *start; start++)
- if (*start == '\n') tb->linesAlloced++;
+ if (*start == '\n') tb->linesAlloced++;
/* This ++ leaves room for an ending line w/o a \n */
tb->linesAlloced++;
start = expanded;
while ((end = strchr(start, '\n'))) {
- addLine(co, start, end - start);
- start = end + 1;
+ addLine(co, start, end - start);
+ start = end + 1;
}
if (*start)
- addLine(co, start, strlen(start));
+ addLine(co, start, strlen(start));
free(expanded);
struct textbox * tb = co->data;
while (wstrlen(s,len) > tb->textWidth) {
- len--;
+ len--;
}
tb->lines[tb->numLines] = malloc(len + 1);
memcpy(tb->lines[tb->numLines], s, len);
int size;
if (tb->sb) {
- size = tb->numLines - c->height;
- newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0);
- tb->sb->ops->draw(tb->sb);
+ size = tb->numLines - c->height;
+ newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0);
+ tb->sb->ops->draw(tb->sb);
}
SLsmg_set_color(NEWT_COLORSET_TEXTBOX);
for (i = 0; (i + tb->topLine) < tb->numLines && i < c->height; i++) {
- newtGotorc(c->top + i, c->left);
- SLsmg_write_string(tb->blankline);
- newtGotorc(c->top + i, c->left);
- SLsmg_write_string(tb->lines[i + tb->topLine]);
+ newtGotorc(c->top + i, c->left);
+ SLsmg_write_string(tb->blankline);
+ newtGotorc(c->top + i, c->left);
+ SLsmg_write_string(tb->lines[i + tb->topLine]);
}
}
static struct eventResult textboxEvent(newtComponent co,
- struct event ev) {
+ struct event ev) {
struct textbox * tb = co->data;
struct eventResult er;
er.result = ER_IGNORED;
if (ev.when == EV_EARLY && ev.event == EV_KEYPRESS && tb->sb) {
- newtTrashScreen();
- switch (ev.u.key) {
- case NEWT_KEY_UP:
- if (tb->topLine) tb->topLine--;
- textboxDraw(co);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_DOWN:
- if (tb->topLine < (tb->numLines - co->height)) tb->topLine++;
- textboxDraw(co);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_PGDN:
- tb->topLine += co->height;
- if (tb->topLine > (tb->numLines - co->height)) {
- tb->topLine = tb->numLines - co->height;
- if (tb->topLine < 0) tb->topLine = 0;
- }
- textboxDraw(co);
- er.result = ER_SWALLOWED;
- break;
-
- case NEWT_KEY_PGUP:
- tb->topLine -= co->height;
- if (tb->topLine < 0) tb->topLine = 0;
- textboxDraw(co);
- er.result = ER_SWALLOWED;
- break;
- }
+ newtTrashScreen();
+ switch (ev.u.key) {
+ case NEWT_KEY_UP:
+ if (tb->topLine) tb->topLine--;
+ textboxDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_DOWN:
+ if (tb->topLine < (tb->numLines - co->height)) tb->topLine++;
+ textboxDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_PGDN:
+ tb->topLine += co->height;
+ if (tb->topLine > (tb->numLines - co->height)) {
+ tb->topLine = tb->numLines - co->height;
+ if (tb->topLine < 0) tb->topLine = 0;
+ }
+ textboxDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
+
+ case NEWT_KEY_PGUP:
+ tb->topLine -= co->height;
+ if (tb->topLine < 0) tb->topLine = 0;
+ textboxDraw(co);
+ er.result = ER_SWALLOWED;
+ break;
+ }
}
if (ev.when == EV_EARLY && ev.event == EV_MOUSE && tb->sb) {
- /* Top scroll arrow */
- if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top) {
- if (tb->topLine) tb->topLine--;
- textboxDraw(co);
-
- er.result = ER_SWALLOWED;
- }
- /* Bottom scroll arrow */
- if (ev.u.mouse.x == co->width &&
- ev.u.mouse.y == co->top + co->height - 1) {
- if (tb->topLine < (tb->numLines - co->height)) tb->topLine++;
- textboxDraw(co);
-
- er.result = ER_SWALLOWED;
- }
+ /* Top scroll arrow */
+ if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top) {
+ if (tb->topLine) tb->topLine--;
+ textboxDraw(co);
+
+ er.result = ER_SWALLOWED;
+ }
+ /* Bottom scroll arrow */
+ if (ev.u.mouse.x == co->width &&
+ ev.u.mouse.y == co->top + co->height - 1) {
+ if (tb->topLine < (tb->numLines - co->height)) tb->topLine++;
+ textboxDraw(co);
+
+ er.result = ER_SWALLOWED;
+ }
}
return er;
}
struct textbox * tb = co->data;
for (i = 0; i < tb->numLines; i++)
- free(tb->lines[i]);
+ free(tb->lines[i]);
free(tb->lines);
free(tb->blankline);
free(tb);
#include "newt.h"
enum mode { MODE_NONE, MODE_INFOBOX, MODE_MSGBOX, MODE_YESNO, MODE_CHECKLIST,
- MODE_INPUTBOX, MODE_RADIOLIST, MODE_MENU, MODE_GAUGE,
+ MODE_INPUTBOX, MODE_RADIOLIST, MODE_MENU, MODE_GAUGE,
MODE_TEXTBOX };
-#define OPT_MSGBOX 1000
-#define OPT_CHECKLIST 1001
-#define OPT_YESNO 1002
-#define OPT_INPUTBOX 1003
-#define OPT_FULLBUTTONS 1004
-#define OPT_MENU 1005
-#define OPT_RADIOLIST 1006
-#define OPT_GAUGE 1007
-#define OPT_INFOBOX 1008
-#define OPT_TEXTBOX 1009
+#define OPT_MSGBOX 1000
+#define OPT_CHECKLIST 1001
+#define OPT_YESNO 1002
+#define OPT_INPUTBOX 1003
+#define OPT_FULLBUTTONS 1004
+#define OPT_MENU 1005
+#define OPT_RADIOLIST 1006
+#define OPT_GAUGE 1007
+#define OPT_INFOBOX 1008
+#define OPT_TEXTBOX 1009
static void usage(void) {
newtFinished();
char * title = NULL;
char * backtitle = NULL;
struct poptOption optionsTable[] = {
- { "backtitle", '\0', POPT_ARG_STRING, &backtitle, 0 },
- { "checklist", '\0', 0, 0, OPT_CHECKLIST },
- { "clear", '\0', 0, &clear, 0 },
- { "defaultno", '\0', 0, &defaultNo, 0 },
- { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
- { "fb", '\0', 0, 0, OPT_FULLBUTTONS },
- { "fullbuttons", '\0', 0, 0, OPT_FULLBUTTONS },
- { "gauge", '\0', 0, 0, OPT_GAUGE },
- { "infobox", '\0', 0, 0, OPT_INFOBOX },
- { "menu", '\0', 0, 0, OPT_MENU },
- { "msgbox", '\0', 0, 0, OPT_MSGBOX },
- { "nocancel", '\0', 0, &noCancel, 0 },
- { "noitem", '\0', 0, &noItem, 0 },
- { "notags", '\0', 0, &noTags, 0 },
- { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
- { "scrolltext", '\0', 0, &scrollText, 0 },
- { "separate-output", '\0', 0, &separateOutput, 0 },
- { "title", '\0', POPT_ARG_STRING, &title, 0 },
- { "yesno", '\0', 0, 0, OPT_YESNO },
- { "textbox", '\0', 0, 0, OPT_TEXTBOX },
- { 0, 0, 0, 0, 0 }
+ { "backtitle", '\0', POPT_ARG_STRING, &backtitle, 0 },
+ { "checklist", '\0', 0, 0, OPT_CHECKLIST },
+ { "clear", '\0', 0, &clear, 0 },
+ { "defaultno", '\0', 0, &defaultNo, 0 },
+ { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
+ { "fb", '\0', 0, 0, OPT_FULLBUTTONS },
+ { "fullbuttons", '\0', 0, 0, OPT_FULLBUTTONS },
+ { "gauge", '\0', 0, 0, OPT_GAUGE },
+ { "infobox", '\0', 0, 0, OPT_INFOBOX },
+ { "menu", '\0', 0, 0, OPT_MENU },
+ { "msgbox", '\0', 0, 0, OPT_MSGBOX },
+ { "nocancel", '\0', 0, &noCancel, 0 },
+ { "noitem", '\0', 0, &noItem, 0 },
+ { "notags", '\0', 0, &noTags, 0 },
+ { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
+ { "scrolltext", '\0', 0, &scrollText, 0 },
+ { "separate-output", '\0', 0, &separateOutput, 0 },
+ { "title", '\0', POPT_ARG_STRING, &title, 0 },
+ { "yesno", '\0', 0, 0, OPT_YESNO },
+ { "textbox", '\0', 0, 0, OPT_TEXTBOX },
+ { 0, 0, 0, 0, 0 }
};
optCon = poptGetContext("whiptail", argc, argv, optionsTable, 0);
while ((arg = poptGetNextOpt(optCon)) > 0) {
- optArg = poptGetOptArg(optCon);
-
- switch (arg) {
- case OPT_INFOBOX:
- if (mode != MODE_NONE) usage();
- mode = MODE_INFOBOX;
- break;
-
- case OPT_MENU:
- if (mode != MODE_NONE) usage();
- mode = MODE_MENU;
- break;
-
- case OPT_MSGBOX:
- if (mode != MODE_NONE) usage();
- mode = MODE_MSGBOX;
- break;
+ optArg = poptGetOptArg(optCon);
+
+ switch (arg) {
+ case OPT_INFOBOX:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_INFOBOX;
+ break;
+
+ case OPT_MENU:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_MENU;
+ break;
+
+ case OPT_MSGBOX:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_MSGBOX;
+ break;
case OPT_TEXTBOX:
if (mode != MODE_NONE) usage();
mode = MODE_TEXTBOX;
break;
- case OPT_RADIOLIST:
- if (mode != MODE_NONE) usage();
- mode = MODE_RADIOLIST;
- break;
-
- case OPT_CHECKLIST:
- if (mode != MODE_NONE) usage();
- mode = MODE_CHECKLIST;
- break;
-
- case OPT_FULLBUTTONS:
- useFullButtons(1);
- break;
-
- case OPT_YESNO:
- if (mode != MODE_NONE) usage();
- mode = MODE_YESNO;
- break;
-
- case OPT_GAUGE:
- if (mode != MODE_NONE) usage();
- mode = MODE_GAUGE;
- break;
-
- case OPT_INPUTBOX:
- if (mode != MODE_NONE) usage();
- mode = MODE_INPUTBOX;
- break;
- }
+ case OPT_RADIOLIST:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_RADIOLIST;
+ break;
+
+ case OPT_CHECKLIST:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_CHECKLIST;
+ break;
+
+ case OPT_FULLBUTTONS:
+ useFullButtons(1);
+ break;
+
+ case OPT_YESNO:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_YESNO;
+ break;
+
+ case OPT_GAUGE:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_GAUGE;
+ break;
+
+ case OPT_INPUTBOX:
+ if (mode != MODE_NONE) usage();
+ mode = MODE_INPUTBOX;
+ break;
+ }
}
if (arg < -1) {
- fprintf(stderr, "%s: %s\n",
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(arg));
- exit(1);
+ fprintf(stderr, "%s: %s\n",
+ poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror(arg));
+ exit(1);
}
output = fdopen (outputfd, "w");
if (*end) usage();
if (mode == MODE_GAUGE) {
- fd = dup(0);
- close(0);
- if (open("/dev/tty", O_RDWR) != 0) perror("open /dev/tty");
+ fd = dup(0);
+ close(0);
+ if (open("/dev/tty", O_RDWR) != 0) perror("open /dev/tty");
}
newtInit();
newtOpenWindow((80 - width) / 2, (24 - height) / 2, width, height, title);
if (backtitle)
- newtDrawRootText(0, 0, backtitle);
+ newtDrawRootText(0, 0, backtitle);
if (noCancel) flags |= FLAG_NOCANCEL;
if (noItem) flags |= FLAG_NOITEM;
switch (mode) {
case MODE_MSGBOX:
case MODE_TEXTBOX:
- rc = messageBox(text, height, width, MSGBOX_MSG, flags);
- break;
+ rc = messageBox(text, height, width, MSGBOX_MSG, flags);
+ break;
case MODE_INFOBOX:
- rc = messageBox(text, height, width, MSGBOX_INFO, flags);
- break;
+ rc = messageBox(text, height, width, MSGBOX_INFO, flags);
+ break;
case MODE_YESNO:
- rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
- break;
+ rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
+ break;
case MODE_INPUTBOX:
- rc = inputBox(text, height, width, optCon, flags, &result);
+ rc = inputBox(text, height, width, optCon, flags, &result);
if (rc == DLG_OKAY) fprintf(output, "%s", result);
- break;
+ break;
case MODE_MENU:
- rc = listBox(text, height, width, optCon, flags, &result);
- if (rc == DLG_OKAY) fprintf(output, "%s", result);
- break;
+ rc = listBox(text, height, width, optCon, flags, &result);
+ if (rc == DLG_OKAY) fprintf(output, "%s", result);
+ break;
case MODE_RADIOLIST:
- rc = checkList(text, height, width, optCon, 1, flags, &selections);
+ rc = checkList(text, height, width, optCon, 1, flags, &selections);
if (rc == DLG_OKAY) {
fprintf(output, "%s", selections[0]);
- free(selections);
- }
- break;
+ free(selections);
+ }
+ break;
case MODE_CHECKLIST:
- rc = checkList(text, height, width, optCon, 0, flags, &selections);
-
- if (!rc) {
- for (next = selections; *next; next++) {
- if (!separateOutput) {
- if (needSpace) putc(' ', output);
- fprintf(output, "\"%s\"", *next);
- needSpace = 1;
- } else {
- fprintf(output, "%s\n", *next);
- }
- }
-
- free(selections);
- }
- break;
+ rc = checkList(text, height, width, optCon, 0, flags, &selections);
+
+ if (!rc) {
+ for (next = selections; *next; next++) {
+ if (!separateOutput) {
+ if (needSpace) putc(' ', output);
+ fprintf(output, "\"%s\"", *next);
+ needSpace = 1;
+ } else {
+ fprintf(output, "%s\n", *next);
+ }
+ }
+
+ free(selections);
+ }
+ break;
case MODE_GAUGE:
- rc = gauge(text, height, width, optCon, fd, flags);
- break;
+ rc = gauge(text, height, width, optCon, fd, flags);
+ break;
default:
- usage();
+ usage();
}
if (rc == -1) usage();
if (clear)
- newtPopWindow();
+ newtPopWindow();
newtFinished();
return rc;
#include "tcl.h"
enum mode { MODE_NONE, MODE_MSGBOX, MODE_YESNO, MODE_CHECKLIST, MODE_INPUTBOX,
- MODE_RADIOLIST, MODE_MENU };
+ MODE_RADIOLIST, MODE_MENU };
-#define OPT_MSGBOX 1000
-#define OPT_CHECKLIST 1001
-#define OPT_YESNO 1002
-#define OPT_INPUTBOX 1003
-#define OPT_MENU 1005
-#define OPT_RADIOLIST 1006
+#define OPT_MSGBOX 1000
+#define OPT_CHECKLIST 1001
+#define OPT_YESNO 1002
+#define OPT_INPUTBOX 1003
+#define OPT_MENU 1005
+#define OPT_RADIOLIST 1006
static char * setBacktext(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags);
+ char * name1, char * name2, int flags);
static char * setHelptext(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags);
+ char * name1, char * name2, int flags);
static char * setFullButtons(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags);
+ char * name1, char * name2, int flags);
static int wtFinish(ClientData clientData, Tcl_Interp * interp, int argc,
char ** argv) {
newtPushHelpLine("");
Tcl_TraceVar(interp, "whiptcl_backtext",
- TCL_TRACE_WRITES | TCL_GLOBAL_ONLY, setBacktext, NULL);
+ TCL_TRACE_WRITES | TCL_GLOBAL_ONLY, setBacktext, NULL);
Tcl_TraceVar(interp, "whiptcl_helpline",
- TCL_TRACE_WRITES | TCL_TRACE_UNSETS | TCL_GLOBAL_ONLY,
- setHelptext, NULL);
+ TCL_TRACE_WRITES | TCL_TRACE_UNSETS | TCL_GLOBAL_ONLY,
+ setHelptext, NULL);
Tcl_TraceVar(interp, "whiptcl_fullbuttons",
- TCL_TRACE_WRITES | TCL_TRACE_UNSETS | TCL_GLOBAL_ONLY,
- setFullButtons, NULL);
+ TCL_TRACE_WRITES | TCL_TRACE_UNSETS | TCL_GLOBAL_ONLY,
+ setFullButtons, NULL);
Tcl_SetVar(interp, "whiptcl_helpline", "", TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "whiptcl_fullbuttons", "1", TCL_GLOBAL_ONLY);
const char ** selections, ** next;
char * title = NULL;
struct poptOption optionsTable[] = {
- { "checklist", '\0', 0, 0, OPT_CHECKLIST },
- { "defaultno", '\0', 0, &defaultNo, 0 },
- { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
- { "menu", '\0', 0, 0, OPT_MENU },
- { "msgbox", '\0', 0, 0, OPT_MSGBOX },
- { "nocancel", '\0', 0, &noCancel, 0 },
- { "noitem", '\0', 0, &noItem, 0 },
- { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
- { "scrolltext", '\0', 0, &scrollText, 0 },
- { "title", '\0', POPT_ARG_STRING, &title, 0 },
- { "yesno", '\0', 0, 0, OPT_YESNO },
- { 0, 0, 0, 0, 0 }
+ { "checklist", '\0', 0, 0, OPT_CHECKLIST },
+ { "defaultno", '\0', 0, &defaultNo, 0 },
+ { "inputbox", '\0', 0, 0, OPT_INPUTBOX },
+ { "menu", '\0', 0, 0, OPT_MENU },
+ { "msgbox", '\0', 0, 0, OPT_MSGBOX },
+ { "nocancel", '\0', 0, &noCancel, 0 },
+ { "noitem", '\0', 0, &noItem, 0 },
+ { "radiolist", '\0', 0, 0, OPT_RADIOLIST },
+ { "scrolltext", '\0', 0, &scrollText, 0 },
+ { "title", '\0', POPT_ARG_STRING, &title, 0 },
+ { "yesno", '\0', 0, 0, OPT_YESNO },
+ { 0, 0, 0, 0, 0 }
};
optCon = poptGetContext("whiptcl", argc, argv, optionsTable, 0);
while ((arg = poptGetNextOpt(optCon)) > 0) {
- optArg = poptGetOptArg(optCon);
-
- switch (arg) {
- case OPT_MENU:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_MENU;
- break;
-
- case OPT_MSGBOX:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_MSGBOX;
- break;
-
- case OPT_RADIOLIST:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_RADIOLIST;
- break;
-
- case OPT_CHECKLIST:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_CHECKLIST;
- break;
-
- case OPT_YESNO:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_YESNO;
- break;
-
- case OPT_INPUTBOX:
- if (mode != MODE_NONE) rc = -1;
- mode = MODE_INPUTBOX;
- break;
- }
+ optArg = poptGetOptArg(optCon);
+
+ switch (arg) {
+ case OPT_MENU:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_MENU;
+ break;
+
+ case OPT_MSGBOX:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_MSGBOX;
+ break;
+
+ case OPT_RADIOLIST:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_RADIOLIST;
+ break;
+
+ case OPT_CHECKLIST:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_CHECKLIST;
+ break;
+
+ case OPT_YESNO:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_YESNO;
+ break;
+
+ case OPT_INPUTBOX:
+ if (mode != MODE_NONE) rc = -1;
+ mode = MODE_INPUTBOX;
+ break;
+ }
}
if (arg < -1) {
- /* this could buffer oveflow, bug we're not setuid so I don't care */
- interp->result = malloc(200);
- interp->freeProc = TCL_DYNAMIC;
- sprintf(interp->result, "%s: %s\n",
- poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(arg));
-
- return TCL_ERROR;
+ /* this could buffer oveflow, bug we're not setuid so I don't care */
+ interp->result = malloc(200);
+ interp->freeProc = TCL_DYNAMIC;
+ sprintf(interp->result, "%s: %s\n",
+ poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror(arg));
+
+ return TCL_ERROR;
}
if (mode == MODE_NONE) {
- interp->result = "no dialog mode was specified";
- return TCL_ERROR;
+ interp->result = "no dialog mode was specified";
+ return TCL_ERROR;
} else if (rc) {
- interp->result = "multiple modes were specified";
- return TCL_ERROR;
+ interp->result = "multiple modes were specified";
+ return TCL_ERROR;
}
if (!(text = poptGetArg(optCon))) {
- interp->result = "missing text parameter";
- return TCL_ERROR;
+ interp->result = "missing text parameter";
+ return TCL_ERROR;
}
if (!(nextArg = poptGetArg(optCon))) {
- interp->result = "height missing";
- return TCL_ERROR;
+ interp->result = "height missing";
+ return TCL_ERROR;
}
height = strtoul(nextArg, &end, 10);
if (*end) {
- interp->result = "height is not a number";
- return TCL_ERROR;
+ interp->result = "height is not a number";
+ return TCL_ERROR;
}
if (!(nextArg = poptGetArg(optCon))) {
- interp->result = "width missing";
- return TCL_ERROR;
+ interp->result = "width missing";
+ return TCL_ERROR;
}
width = strtoul(nextArg, &end, 10);
if (*end) {
- interp->result = "width is not a number";
- return TCL_ERROR;
+ interp->result = "width is not a number";
+ return TCL_ERROR;
}
width -= 2;
switch (mode) {
case MODE_MSGBOX:
- rc = messageBox(text, height, width, MSGBOX_MSG, flags);
- break;
+ rc = messageBox(text, height, width, MSGBOX_MSG, flags);
+ break;
case MODE_YESNO:
- rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
- if (rc == DLG_OKAY)
- interp->result = "yes";
- else
- interp->result = "no";
- if (rc == DLG_ERROR) rc = 0;
- break;
+ rc = messageBox(text, height, width, MSGBOX_YESNO, flags);
+ if (rc == DLG_OKAY)
+ interp->result = "yes";
+ else
+ interp->result = "no";
+ if (rc == DLG_ERROR) rc = 0;
+ break;
case MODE_INPUTBOX:
- rc = inputBox(text, height, width, optCon, flags, &result);
- if (!rc) {
- interp->result = strdup(result);
- interp->freeProc = TCL_DYNAMIC;
- }
- break;
+ rc = inputBox(text, height, width, optCon, flags, &result);
+ if (!rc) {
+ interp->result = strdup(result);
+ interp->freeProc = TCL_DYNAMIC;
+ }
+ break;
case MODE_MENU:
- rc = listBox(text, height, width, optCon, flags, &result);
- if (!rc) {
- interp->result = strdup(result);
- interp->freeProc = TCL_DYNAMIC;
- }
- break;
+ rc = listBox(text, height, width, optCon, flags, &result);
+ if (!rc) {
+ interp->result = strdup(result);
+ interp->freeProc = TCL_DYNAMIC;
+ }
+ break;
case MODE_RADIOLIST:
- rc = checkList(text, height, width, optCon, 1, flags, &selections);
- if (!rc) {
- interp->result = strdup(selections[0]);
- interp->freeProc = TCL_DYNAMIC;
- }
- break;
+ rc = checkList(text, height, width, optCon, 1, flags, &selections);
+ if (!rc) {
+ interp->result = strdup(selections[0]);
+ interp->freeProc = TCL_DYNAMIC;
+ }
+ break;
case MODE_CHECKLIST:
- rc = checkList(text, height, width, optCon, 0, flags, &selections);
+ rc = checkList(text, height, width, optCon, 0, flags, &selections);
- if (!rc) {
- for (next = selections; *next; next++)
- Tcl_AppendElement(interp, *next);
+ if (!rc) {
+ for (next = selections; *next; next++)
+ Tcl_AppendElement(interp, *next);
- free(selections);
- }
- break;
+ free(selections);
+ }
+ break;
case MODE_NONE:
- /* this can't happen */
+ /* this can't happen */
break;
}
newtPopWindow();
if (rc == DLG_ERROR) {
- interp->result = "bad paramter for whiptcl dialog box";
- return TCL_ERROR;
+ interp->result = "bad paramter for whiptcl dialog box";
+ return TCL_ERROR;
}
Tcl_SetVar(interp, "whiptcl_canceled", (rc == DLG_CANCEL) ? "1" : "0",
- 0);
+ 0);
return TCL_OK;
}
static char * setBacktext(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags) {
+ char * name1, char * name2, int flags) {
static char blankLine[81] = " "
" ";
newtDrawRootText(0, 0, blankLine);
newtDrawRootText(0, 0, Tcl_GetVar(interp, "whiptcl_backtext",
- TCL_GLOBAL_ONLY));
+ TCL_GLOBAL_ONLY));
return NULL;
}
static char * setHelptext(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags) {
+ char * name1, char * name2, int flags) {
char * text = Tcl_GetVar(interp, "whiptcl_helpline", TCL_GLOBAL_ONLY);
if (!text)
- text = "";
+ text = "";
else if (!strlen(text))
- text = NULL;
+ text = NULL;
newtPopHelpLine();
newtPushHelpLine(text);
}
static char * setFullButtons(ClientData data, Tcl_Interp * interp,
- char * name1, char * name2, int flags) {
+ char * name1, char * name2, int flags) {
char * val = Tcl_GetVar(interp, "whiptcl_fullbuttons", TCL_GLOBAL_ONLY);
int rc;
int state;
if ((rc = Tcl_ExprBoolean(interp, val, &state))) {
- Tcl_FreeResult(interp);
- return "whiptcl_fullbuttons may only contain a boolean value";
+ Tcl_FreeResult(interp);
+ return "whiptcl_fullbuttons may only contain a boolean value";
}
useFullButtons(state);
#include "newt.h"
static void * newtvwindow(char * title, char * button1, char * button2,
- char * button3, char * message, va_list args) {
+ char * button3, char * message, va_list args) {
newtComponent b1, b2 = NULL, b3 = NULL, t, f, answer;
char * buf = NULL;
int size = 0;
newtGrid grid, buttonGrid;
do {
- size += 1000;
- if (buf) free(buf);
- buf = malloc(size);
- i = vsnprintf(buf, size, message, args);
+ size += 1000;
+ if (buf) free(buf);
+ buf = malloc(size);
+ i = vsnprintf(buf, size, message, args);
} while (i >= size || i == -1);
flowedText = newtReflowText(buf, 35, 5, 5, &width, &height);
if (height > 6) {
- free(flowedText);
- flowedText = newtReflowText(buf, 60, 5, 5, &width, &height);
+ free(flowedText);
+ flowedText = newtReflowText(buf, 60, 5, 5, &width, &height);
}
free(buf);
if (height > 12) {
- height = 12;
- scroll = NEWT_FLAG_SCROLL;
+ height = 12;
+ scroll = NEWT_FLAG_SCROLL;
}
t = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP | scroll);
newtTextboxSetText(t, flowedText);
free(flowedText);
if (button3) {
- buttonGrid = newtButtonBar(button1, &b1, button2, &b2,
- button3, &b3, NULL);
+ buttonGrid = newtButtonBar(button1, &b1, button2, &b2,
+ button3, &b3, NULL);
} else if (button2) {
- buttonGrid = newtButtonBar(button1, &b1, button2, &b2, NULL);
+ buttonGrid = newtButtonBar(button1, &b1, button2, &b2, NULL);
} else {
- buttonGrid = newtButtonBar(button1, &b1, NULL);
+ buttonGrid = newtButtonBar(button1, &b1, NULL);
}
newtGridSetField(buttonGrid, 0, 0, NEWT_GRID_COMPONENT, b1,
- 0, 0, button2 ? 1 : 0, 0, 0, 0);
+ 0, 0, button2 ? 1 : 0, 0, 0, 0);
grid = newtCreateGrid(1, 2);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 0, 0, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, buttonGrid,
- 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
+ 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
newtGridWrappedWindow(grid, title);
f = newtForm(NULL, NULL, 0);
newtFormAddComponents(f, t, b1, NULL);
if (button2)
- newtFormAddComponent(f, b2);
+ newtFormAddComponent(f, b2);
if (button3)
- newtFormAddComponent(f, b3);
+ newtFormAddComponent(f, b3);
answer = newtRunForm(f);
newtGridFree(grid, 1);
newtPopWindow();
if (answer == f)
- return NULL;
+ return NULL;
else if (answer == b1)
- return button1;
+ return button1;
else if (answer == b2)
- return button2;
+ return button2;
return button3;
}
int newtWinChoice(char * title, char * button1, char * button2,
- char * message, ...) {
+ char * message, ...) {
va_list args;
void * rc;
va_end(args);
if (rc == button1)
- return 1;
+ return 1;
else if (rc == button2)
- return 2;
+ return 2;
return 0;
}
}
void newtWinMessagev(char * title, char * buttonText, char * text,
- va_list argv) {
+ va_list argv) {
newtvwindow(title, buttonText, NULL, NULL, text, argv);
}
int newtWinTernary(char * title, char * button1, char * button2,
- char * button3, char * message, ...) {
+ char * button3, char * message, ...) {
va_list args;
void * rc;
va_end(args);
if (rc == button1)
- return 1;
+ return 1;
else if (rc == button2)
- return 2;
+ return 2;
else if (rc == button3)
- return 3;
+ return 3;
return 0;
}
int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown,
- int flexUp, int maxListHeight, char ** items, int * listItem,
- char * button1, ...) {
+ int flexUp, int maxListHeight, char ** items, int * listItem,
+ char * button1, ...) {
newtComponent textbox, listbox, result, form;
va_list args;
newtComponent *buttons = NULL;
char * buttonName;
textbox = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
- flexUp, 0);
+ flexUp, 0);
for (i = 0; items[i]; i++) ;
if (i < maxListHeight) maxListHeight = i;
needScroll = i > maxListHeight;
listbox = newtListbox(-1, -1, maxListHeight,
- (needScroll ? NEWT_FLAG_SCROLL : 0) | NEWT_FLAG_RETURNEXIT);
+ (needScroll ? NEWT_FLAG_SCROLL : 0) | NEWT_FLAG_RETURNEXIT);
for (i = 0; items[i]; i++) {
- newtListboxAddEntry(listbox, items[i], (void *) i);
+ newtListboxAddEntry(listbox, items[i], (void *) i);
}
newtListboxSetCurrent(listbox, *listItem);
buttonBar = newtCreateGrid(numButtons, 1);
for (i = 0; i < numButtons; i++) {
- newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
- buttons[i],
- i ? 1 : 0, 0, 0, 0, 0, 0);
+ newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
+ buttons[i],
+ i ? 1 : 0, 0, 0, 0, 0, 0);
}
grid = newtGridSimpleWindow(textbox, listbox, buttonBar);
for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
if (rc == numButtons)
- rc = 0; /* F12 or return-on-exit (which are the same for us) */
+ rc = 0; /* F12 or return-on-exit (which are the same for us) */
else
- rc++;
+ rc++;
newtFormDestroy(form);
newtPopWindow();
}
int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown,
- int flexUp, int dataWidth,
- struct newtWinEntry * items, char * button1, ...) {
+ int flexUp, int dataWidth,
+ struct newtWinEntry * items, char * button1, ...) {
newtComponent *buttons, result, form, textw;
newtGrid grid, buttonBar, subgrid;
int numItems;
va_list args;
textw = newtTextboxReflowed(-1, -1, text, suggestedWidth, flexDown,
- flexUp, 0);
+ flexUp, 0);
for (numItems = 0; items[numItems].text; numItems++);
buttonBar = newtCreateGrid(numButtons, 1);
for (i = 0; i < numButtons; i++) {
- newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
- buttons[i],
- i ? 1 : 0, 0, 0, 0, 0, 0);
+ newtGridSetField(buttonBar, i, 0, NEWT_GRID_COMPONENT,
+ buttons[i],
+ i ? 1 : 0, 0, 0, 0, 0, 0);
}
subgrid = newtCreateGrid(2, numItems);
for (i = 0; i < numItems; i++) {
- newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT,
- newtLabel(-1, -1, items[i].text),
- 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
- newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT,
- newtEntry(-1, -1, items[i].value ?
- *items[i].value : NULL, dataWidth,
- items[i].value, items[i].flags),
- 1, 0, 0, 0, 0, 0);
+ newtGridSetField(subgrid, 0, i, NEWT_GRID_COMPONENT,
+ newtLabel(-1, -1, items[i].text),
+ 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
+ newtGridSetField(subgrid, 1, i, NEWT_GRID_COMPONENT,
+ newtEntry(-1, -1, items[i].value ?
+ *items[i].value : NULL, dataWidth,
+ items[i].value, items[i].flags),
+ 1, 0, 0, 0, 0, 0);
}
grid = newtCreateGrid(1, 3);
form = newtForm(NULL, 0, 0);
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, textw,
- 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
+ 0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid,
- 0, 1, 0, 0, 0, 0);
+ 0, 1, 0, 0, 0, 0);
newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttonBar,
- 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
+ 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
newtGridAddComponentsToForm(grid, form, 1);
newtGridWrappedWindow(grid, title);
newtGridFree(grid, 1);
result = newtRunForm(form);
for (rc = 0; rc < numItems; rc++)
- *items[rc].value = strdup(*items[rc].value);
+ *items[rc].value = strdup(*items[rc].value);
for (rc = 0; result != buttons[rc] && rc < numButtons; rc++);
if (rc == numButtons)
- rc = 0; /* F12 */
+ rc = 0; /* F12 */
else
- rc++;
+ rc++;
newtFormDestroy(form);
newtPopWindow();