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);
free(en->buf);
en->bufAlloced = strlen(value) + 1;
en->buf = malloc(en->bufAlloced);
- *en->resultPtr = en->buf;
+ if (en->resultPtr) *en->resultPtr = en->buf;
}
memset(en->buf, 0, en->bufAlloced); /* clear the buffer */
strcpy(en->buf, value);
en->firstChar = 0;
en->bufUsed = 0;
en->bufAlloced = width + 1;
+ en->filter = NULL;
if (!(en->flags & NEWT_FLAG_DISABLED))
co->takesFocus = 1;
en->bufAlloced = strlen(initialValue) + 1;
}
en->buf = malloc(en->bufAlloced);
- *resultPtr = en->buf;
en->resultPtr = resultPtr;
+ if (en->resultPtr) *en->resultPtr = en->buf;
memset(en->buf, 0, en->bufAlloced);
if (initialValue) {
struct event ev) {
struct entry * en = co->data;
struct eventResult er;
+ int ch;
if (ev.when == EV_NORMAL) {
switch (ev.event) {
break;
case EV_KEYPRESS:
- er = entryHandleKey(co, ev.u.key);
+ ch = ev.u.key;
+ if (en->filter)
+ ch = en->filter(co, en->filterData, ch, en->cursorPosition);
+ if (ch) er = entryHandleKey(co, ch);
break;
}
} else
if ((en->bufUsed + 1) == en->bufAlloced) {
en->bufAlloced += 20;
en->buf = realloc(en->buf, en->bufAlloced);
- *en->resultPtr = en->buf;
+ if (en->resultPtr) *en->resultPtr = en->buf;
memset(en->buf + en->bufUsed + 1, 0, 20);
}
return er;
}
+
+char * newtEntryGetValue(newtComponent co) {
+ struct entry * en = co->data;
+
+ return en->buf;
+}
+
+void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data) {
+ struct entry * en = co->data;
+ en->filter = filter;
+ en->filterData = data;
+}