]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtEntrySet(), newtEntryAddCallback()
authorewt <ewt>
Thu, 13 Jun 1996 21:15:19 +0000 (21:15 +0000)
committerewt <ewt>
Thu, 13 Jun 1996 21:15:19 +0000 (21:15 +0000)
entry.c

diff --git a/entry.c b/entry.c
index 9e9f9faf114f14708e032abb6ca8775010acf910..1341d1b76a320b2a5173a824e6e748801e41c8ed 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -13,6 +13,8 @@ struct entry {
     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 */
+    void * callbackData;
+    newtCallback callback;
 };
 
 static void entryDraw(newtComponent co);
@@ -28,6 +30,26 @@ static struct componentOps entryOps = {
     entryDestroy,
 } ;
 
+void newtEntrySet(newtComponent co, char * value, int cursorAtEnd) {
+    struct entry * en = co->data;
+
+    if ((strlen(value) + 1) > en->bufAlloced) {
+       free(en->buf);
+       en->bufAlloced = strlen(value) + 1;
+       en->buf = malloc(en->bufAlloced);
+       *en->resultPtr = en->buf;
+    }
+    strcpy(en->buf, value);
+    en->bufUsed = strlen(value);
+    en->firstChar = 0;
+    if (cursorAtEnd)
+       en->cursorPosition = en->bufUsed;
+    else
+       en->cursorPosition = 0;
+
+    entryDraw(co);
+} ;
+
 newtComponent newtEntry(int left, int top, char * initialValue, int width,
                        char ** resultPtr, int flags) {
     newtComponent co;
@@ -50,6 +72,7 @@ newtComponent newtEntry(int left, int top, char * initialValue, int width,
     en->firstChar = 0;
     en->bufUsed = 0;
     en->bufAlloced = width + 1;
+    en->callback = NULL;
 
     if (initialValue && strlen(initialValue) > width) {
        en->bufAlloced = strlen(initialValue) + 1;
@@ -67,6 +90,13 @@ newtComponent newtEntry(int left, int top, char * initialValue, int width,
     return co;
 }
 
+void newtEntryAddCallback(newtComponent co, newtCallback f, void * data) {
+    struct entry * en = co->data;
+
+    en->callback = f;
+    en->callbackData = data;
+}
+
 static void entryDraw(newtComponent co) {
     struct entry * en = co->data;
     int i;
@@ -139,6 +169,7 @@ static struct eventResult entryEvent(struct newtComponent * co,
            /*SLtt_set_cursor_visibility(1);*/
            newtGotorc(0, 0);
            er.result = ER_SWALLOWED;
+           if (en->callback) en->callback(co, en->callbackData);
            break;
 
          case EV_KEYPRESS: