From: ewt Date: Wed, 8 Oct 1997 15:39:43 +0000 (+0000) Subject: added newtWinTernary() X-Git-Tag: r0-12~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0989946aab620f251201212f72291b34c57f85e5;p=thirdparty%2Fnewt.git added newtWinTernary() --- diff --git a/newt.h b/newt.h index 7a0a327..386312a 100644 --- 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" { */ diff --git a/windows.c b/windows.c index bda888f..5f31012 100644 --- 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; }