]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtCheckboxSetValue()
authorewt <ewt>
Sun, 2 Aug 1998 18:45:55 +0000 (18:45 +0000)
committerewt <ewt>
Sun, 2 Aug 1998 18:45:55 +0000 (18:45 +0000)
checkbox.c
newt.h

index 1b155d3ca5dee24900c8796d11f02da164c86ac5..80aeb900257be4c29ff8f45f95acf8b4a71a5f19 100644 (file)
@@ -17,9 +17,9 @@ struct checkbox {
     int active, inactive;
     const void * data;
     int flags;
+    int hasFocus;
 };
 
-static void cbDrawIt(newtComponent c, int active);
 static void makeActive(newtComponent co);
 
 static void cbDraw(newtComponent c);
@@ -80,6 +80,13 @@ char newtCheckboxGetValue(newtComponent co) {
     return cb->value;
 }
 
+void newtCheckboxSetValue(newtComponent co, char value) {
+    struct checkbox * cb = co->data;
+
+    *cb->result = value;
+    cbDraw(co);
+}
+
 newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
                           const char * seq, char * result) {
     newtComponent co;
@@ -99,6 +106,7 @@ newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
     cb->text = strdup(text);
     cb->seq = strdup(seq);
     cb->type = CHECK;
+    cb->hasFocus = 0;
     cb->inactive = COLORSET_CHECKBOX;
     cb->active = COLORSET_ACTCHECKBOX;
     defValue ? (*cb->result = defValue) : (*cb->result = cb->seq[0]);
@@ -116,13 +124,9 @@ newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
 }
 
 static void cbDraw(newtComponent c) {
-    cbDrawIt(c, 0);
-}
-
-static void cbDrawIt(newtComponent c, int active) {
     struct checkbox * cb = c->data;
 
-    if (c->top == -1) return;
+    if (c->top == -1 || !c->isMapped) return;
 
     SLsmg_set_color(cb->inactive);
 
@@ -143,7 +147,7 @@ static void cbDrawIt(newtComponent c, int active) {
 
     SLsmg_write_string(cb->text);
 
-    if (active
+    if (cb->hasFocus
        SLsmg_set_color(cb->active);
 
     newtGotorc(c->top, c->left + 1);
@@ -167,12 +171,14 @@ struct eventResult cbEvent(newtComponent co, struct event ev) {
     if (ev.when == EV_NORMAL) {
        switch (ev.event) {
          case EV_FOCUS:
-           cbDrawIt(co, 1);
+           cb->hasFocus = 1;
+           cbDraw(co);
            er.result = ER_SWALLOWED;
            break;
 
          case EV_UNFOCUS:
-           cbDrawIt(co, 0);
+           cb->hasFocus = 0;
+           cbDraw(co);
            er.result = ER_SWALLOWED;
            break;
 
@@ -191,8 +197,11 @@ struct eventResult cbEvent(newtComponent co, struct event ev) {
                        else
                            *cb->result = *cur;
                    }
-                   cbDrawIt(co, 1);
+                   cbDraw(co);
                    er.result = ER_SWALLOWED;
+
+                   if (co->callback)
+                       co->callback(co, co->callbackData);
                } else {
                    er.result = ER_IGNORED;
                }
@@ -206,9 +215,6 @@ struct eventResult cbEvent(newtComponent co, struct event ev) {
     } else 
        er.result = ER_IGNORED;
 
-    if (er.result == ER_SWALLOWED && co->callback)
-       co->callback(co, co->callbackData);
-
     return er;
 }
 
@@ -226,8 +232,11 @@ static void makeActive(newtComponent co) {
     }
     if (curr) {
        rb->value = rb->seq[0];
-       cbDrawIt(curr, 0);
+       cbDraw(curr);
     } 
     cb->value = cb->seq[1];
-    cbDrawIt(co, 1);
+    cbDraw(co);
+
+    if (co->callback)
+       co->callback(co, co->callbackData);
 }
diff --git a/newt.h b/newt.h
index 5ac374bffc80167697ba770a3acea3b71e9e22b8..1e408d5ee2533db850a291e5c1685e149c10ccd6 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -123,6 +123,7 @@ 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);
 char newtCheckboxGetValue(newtComponent co);
+void newtCheckboxSetValue(newtComponent co, char value);
 newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault,
                              newtComponent prevButton);
 newtComponent newtRadioGetCurrent(newtComponent setMember);