Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / lib / libdialog / TESTS / menu3.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/menu3.c,v 1.9 2000/01/10 11:52:07 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
29 stop(dialogMenuItem *self)
30 {
31     dialog_mesgbox("!", "I'm no idiot!", -1, -1);
32     return DITEM_SUCCESS;
33 }
34
35 static int
36 maybe(dialogMenuItem *self)
37 {
38     dialog_mesgbox("!", "I said don't rush me!  I'm THINKING!", -1, -1);
39     return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
40 }
41
42 /* Dummy menu just to show of the ability */
43 static char *insurance[] = {
44     "1,000,000",        "Mondo insurance policy", "Off",
45     "5,000,000",        "Mega insurance policy", "Off",
46     "10,000,000",       "Friend!  Most Favored customer!"
47 };
48
49 static void
50 preinsure(dialogMenuItem *self, int is_selected)
51 {
52     if (is_selected) {
53         static WINDOW *w;
54         
55         /* This has to be here first if you want to see selection traverse properly in the invoking menu */
56         refresh();
57
58         w = dupwin(newscr);
59         DialogX = 1;
60         DialogY = 13;
61         dialog_radiolist("How much insurance would you like to take out?",
62                          "If you're really going to do this, we recommend some insurance\n"
63                          "first!  What kind of life insurance policy would you like?",
64                          -1, -1, 3, 3, insurance, NULL);
65         touchwin(w);
66         wrefresh(w);
67         delwin(w);
68     }
69 }
70
71 /*
72  * Show a simple menu that puts up a sub menu when a certain item is traversed to
73  */
74
75 /* prompt       title                                           checked         fire            sel  */
76 static dialogMenuItem doit[] = {
77     { "Rah!" },
78     { "No way!" },
79     { "Stop",   "No, I'm not going to do that!",                NULL,           stop,           NULL    },
80     { "Maybe",  "I'm still thinking about it, don't rush me!",  NULL,           maybe,          NULL,   },
81     { "Go",     "Yes!  Yes!  I want to do it!",                 NULL,           NULL,           preinsure },
82 };
83
84 /* End of hook functions */
85
86 /* Kick it off, James! */
87 int
88 main(int argc, char **argv)
89 {
90     int retval;
91     
92     init_dialog();
93     
94     
95     DialogX = 5;
96     DialogY = 1;
97     retval = dialog_menu("Do you have the GUTS?",
98                          "C'mon, macho man!  Do you have what it takes to do something REALLY\n"
99                          "dangerous and stupid?  WHAT ARE YOU WAITING FOR?!",
100                          -1, -1, 3, -3, doit + 2, (char *)TRUE, NULL, NULL);
101     dialog_clear();
102     fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
103     
104     end_dialog();
105     return 0;
106 }