]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added newtWinTernary()
authorewt <ewt>
Wed, 8 Oct 1997 15:39:43 +0000 (15:39 +0000)
committerewt <ewt>
Wed, 8 Oct 1997 15:39:43 +0000 (15:39 +0000)
newt.h
windows.c

diff --git a/newt.h b/newt.h
index 7a0a327dabe21623fbc7bd53ec9dc4e8ecd2c57a..386312af0b8dbb1794773e4fde290d4a111badb8 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -260,6 +260,11 @@ void newtWinMessagev(char * title, char * buttonText, char * text,
 int newtWinChoice(char * title, char * button1, char * button2, 
                   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, ...);
+
 
 #ifdef __cplusplus
 } /* End of extern "C" { */
index bda888f35a7c46b1043812a724ce503b266bd59b..5f31012fa1f6b6be20ed59104ad581fa09ffa998 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -7,9 +7,9 @@
 #include "errno.h"
 #include "newt.h"
 
-static int newtvwindow(char * title, char * button1, char * button2, 
-                  char * message, va_list args) {
-    newtComponent b1, b2 = NULL, t, f, answer;
+static void * newtvwindow(char * title, char * button1, char * button2, 
+                      char * button3, char * message, va_list args) {
+    newtComponent b1, b2 = NULL, b3 = NULL, t, f, answer;
     char * buf = NULL;
     int size = 0;
     int i = 0;
@@ -35,7 +35,10 @@ static int newtvwindow(char * title, char * button1, char * button2,
     newtTextboxSetText(t, flowedText);
     free(flowedText);
 
-    if (button2) {
+    if (button3) {
+       buttonGrid = newtButtonBar(button1, &b1, button2, &b2, 
+                                  button3, &b3, NULL);
+    } else if (button2) {
        buttonGrid = newtButtonBar(button1, &b1, button2, &b2, NULL);
     } else {
        buttonGrid = newtButtonBar(button1, &b1, NULL);
@@ -55,6 +58,8 @@ static int newtvwindow(char * title, char * button1, char * button2,
 
     if (button2)
        newtFormAddComponent(f, b2);
+    if (button3)
+       newtFormAddComponent(f, b3);
 
     answer = newtRunForm(f);
     newtGridFree(grid, 1);
@@ -63,34 +68,60 @@ static int newtvwindow(char * title, char * button1, char * button2,
     newtPopWindow();
 
     if (answer == f)
-       return 2;
+       return NULL;
+    else if (answer == b1)
+       return button1;
     else if (answer == b2)
-       return 1;
+       return button2;
 
-    return 0;
+    return button3;
 }
 
 int newtWinChoice(char * title, char * button1, char * button2, 
                   char * message, ...) {
     va_list args;
-    int rc;
+    void * rc;
 
     va_start(args, message);
-    rc = newtvwindow(title, button1, button2, message, args);
+    rc = newtvwindow(title, button1, button2, NULL, message, args);
     va_end(args);
 
-    return rc;
+    if (rc == button1)
+       return 0;
+    else if (rc == button2)
+       return 1;
+
+    return 2;
 }
 
 void newtWinMessage(char * title, char * buttonText, char * text, ...) {
     va_list args;
 
     va_start(args, text);
-    newtvwindow(title, buttonText, NULL, text, args);
+    newtvwindow(title, buttonText, NULL, NULL, text, args);
     va_end(args);
 }
 
 void newtWinMessagev(char * title, char * buttonText, char * text, 
                     va_list argv) {
-    newtvwindow(title, buttonText, NULL, text, argv);
+    newtvwindow(title, buttonText, NULL, NULL, text, argv);
+}
+
+int newtWinTernary(char * title, char * button1, char * button2, 
+                  char * button3, char * message, ...) {
+    va_list args;
+    void * rc;
+
+    va_start(args, message);
+    rc = newtvwindow(title, button1, button2, button3, message, args);
+    va_end(args);
+
+    if (rc == button1)
+       return 1;
+    else if (rc == button2)
+       return 2;
+    else if (rc == button3)
+       return 3;
+
+    return 0;
 }