From: ewt Date: Sat, 11 Dec 1999 18:59:15 +0000 (+0000) Subject: version 0.50.1 X-Git-Tag: r0-50~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e67a6cabed01d8476d8291b9d56fd24e9b374d9d;p=thirdparty%2Fnewt.git version 0.50.1 --- diff --git a/CHANGES b/CHANGES index b96b3e3..36a8aa6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +0.50 -> 0.51 + - added newtFormSetTimer() (and test case, and python) + 0.40 -> 0.50 - added CheckboxTree widget - vastly improved python bindings diff --git a/form.c b/form.c index 67ae70a..d4a966b 100644 --- a/form.c +++ b/form.c @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef USE_GPM #include @@ -395,6 +396,8 @@ struct form { int numFds; struct fdInfo * fds; int maxFd; + int timer; /* in milliseconds */ + struct timeval lastTimeout; }; static void gotoComponent(struct form * form, int newComp); @@ -494,6 +497,12 @@ void newtFormSetCurrent(newtComponent co, newtComponent subco) { gotoComponent(form, new); } +void newtFormSetTimer(newtComponent co, int millisecs) { + struct form * form = co->data; + + form->timer = millisecs; +} + void newtFormSetHeight(newtComponent co, int height) { struct form * form = co->data; @@ -864,6 +873,7 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { int key, i, max; int done = 0; fd_set readSet, writeSet; + struct timeval nextTimeout, now, timeout; #ifdef USE_GPM int x, y; Gpm_Connect conn; @@ -887,6 +897,16 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { } else gotoComponent(form, form->currComp); + /* Calculate when we next need to return with a timeout */ + if (form->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; + } + while (!done) { newtRefresh(); @@ -909,9 +929,39 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { FD_SET(form->fds[i].fd, &writeSet); } - i = select(max + 1, &readSet, &writeSet, NULL, NULL); + if (form->timer) { + 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, NULL, + form->timer ? &timeout : NULL); if (i < 0) continue; /* ?? What should we do here? */ + if (i == 0) { + done = 1; + es->reason = NEWT_EXIT_TIMEOUT; + gettimeofday(&form->lastTimeout, NULL); + } else #ifdef USE_GPM if (gpm_fd > 0 && FD_ISSET(gpm_fd, &readSet)) { Gpm_GetEvent(&event); diff --git a/newt.h b/newt.h index b58ba0d..4511df3 100644 --- a/newt.h +++ b/newt.h @@ -189,7 +189,8 @@ char * newtReflowText(char * text, int width, int flexDown, int flexUp, int * actualWidth, int * actualHeight); struct newtExitStruct { - enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY } reason; + enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY, + NEWT_EXIT_TIMEOUT } reason; union { int key; newtComponent co; @@ -197,6 +198,7 @@ struct newtExitStruct { } ; newtComponent newtForm(newtComponent vertBar, const char * help, int flags); +void newtFormSetTimer(newtComponent form, int millisecs); void newtFormWatchFd(newtComponent form, int fd, int fdFlags); void newtFormSetSize(newtComponent co); newtComponent newtFormGetCurrent(newtComponent co); diff --git a/newt.spec b/newt.spec index b2dc719..70879f5 100644 --- a/newt.spec +++ b/newt.spec @@ -1,6 +1,6 @@ Summary: A development library for text mode user interfaces. Name: newt -%define version 0.50 +%define version 0.50.1 Version: %{version} Release: 14 Copyright: LGPL diff --git a/test.c b/test.c index e88a279..1455b98 100644 --- a/test.c +++ b/test.c @@ -30,7 +30,7 @@ void suspend(void * d) { int main(void) { newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale; - newtComponent lb, t, rsf, answer; + newtComponent lb, t, rsf, answer, timeLabel; newtComponent cs[10]; newtComponent f, chklist, e1; struct callbackInfo cbis[3]; @@ -39,6 +39,9 @@ int main(void) { void ** selectedList; int i, numsel; char buf[20]; + const char * spinner = "-\\|/\\|/"; + const char * spinState; + struct newtExitStruct es; newtInit(); newtCls(); @@ -104,21 +107,30 @@ int main(void) { newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10); newtListboxDeleteEntry(lb, (void *) 11); + spinState = spinner; + timeLabel = newtLabel(45, 8, "Spinner: -"); + t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP); newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed"); - newtFormAddComponents(f, lb, t, NULL); + newtFormAddComponents(f, lb, timeLabel, t, NULL); newtRefresh(); + newtFormSetTimer(f, 200); do { - answer = newtRunForm(f); + newtFormRun(f, &es); - if (answer == b2) { + if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) { newtScaleSet(scale, atoi(scaleVal)); newtRefresh(); answer = NULL; + } else if (es.reason == NEWT_EXIT_TIMEOUT) { + spinState++; + if (!*spinState) spinState = spinner; + sprintf(buf, "Spinner: %c", *spinState); + newtLabelSetText(timeLabel, buf); } - } while (!answer); + } while (es.reason != NEWT_EXIT_COMPONENT); scaleVal = strdup(scaleVal); enr2 = strdup(enr2);