Initial import from FreeBSD RELENG_4:
[games.git] / gnu / lib / libdialog / TESTS / radio3.c
1 /*
2  * small test-driver for new dialog functionality
3  *
4  * Copyright (c) 1995, Jordan Hubbard
5  *
6  * All rights reserved.
7  *
8  * This source code may be used, modified, copied, distributed, and
9  * sold, in both source and binary form provided that the above
10  * copyright and these terms are retained, verbatim, as the first
11  * lines of this file.  Under no circumstances is the author
12  * responsible for the proper functioning of the software nor does
13  * the author assume any responsibility for damages incurred with
14  * its use.
15  *
16  * $FreeBSD: src/gnu/lib/libdialog/TESTS/radio3.c,v 1.7 2000/01/10 11:52:09 phantom Exp $
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <sys/wait.h>
24 #include <dialog.h>
25
26 /* Hook functions */
27
28 static int spending;
29
30 static int
31 check(dialogMenuItem *self)
32 {
33     return ((int)self->data == spending);
34 }
35
36 static int
37 spend(dialogMenuItem *self)
38 {
39     spending = (int)self->data;
40     return DITEM_SUCCESS | DITEM_REDRAW;
41 }
42
43 static void
44 ask(dialogMenuItem *self, int is_selected)
45 {
46     if (is_selected) {
47         char *str;
48         
49         if (!strcmp(self->prompt, "1000"))
50             str = "You'd better ask both your parents first! ";
51         else if (!strcmp(self->prompt, "500"))
52             str = "You'd better at least ask your Dad!       ";
53         else
54             str = "Yes, being frugal is probably a good idea!";
55         DialogX = 15;
56         DialogY = 17;
57         dialog_msgbox("Free Advice", str, -1, -1, 0);
58     }
59 }
60
61 /*
62  * menu5 - Show a simple radiolist menu that inherits the radio appearance by default and appears at
63  * a different location, leaving room for a msg box below it.  This shows off the DialogX/DialogY extensions.
64  */
65
66 /* prompt       title                   checked         fire            sel     data */
67 static dialogMenuItem menu5[] = {
68     { "1000",   "Spend $1,000",         check,          spend,          ask,    (void *)1000 },
69     { "500",    "Spend $500",           check,          spend,          ask,    (void *)500 },
70     { "100",    "Spend $100",           check,          spend,          ask,    (void *)100 },
71 };
72
73 /* End of hook functions */
74
75 /* Kick it off, James! */
76 int
77 main(int argc, char **argv)
78 {
79     int retval;
80     
81     init_dialog();
82     
83     
84     DialogX = 5;
85     DialogY = 1;
86     retval = dialog_radiolist("this is dialog_radiolist() in action, test #3",
87                               "This radio menu shows off the ability to put dialog menus and other\n"
88                               "controls at different locations, as well as the `selected' hook which\n"
89                               "lets you follow the traversal of the selection bar as well as what's\n"
90                               "selected.",
91                               -1, -1, 3, -3, menu5, NULL);
92     dialog_clear();
93     fprintf(stderr, "returned value for dialog_radiolist was %d (money set to %d)\n", retval, spending);
94     
95     end_dialog();
96     return 0;
97 }