summaryrefslogtreecommitdiffstats
path: root/gnu/lib/libdialog/TESTS/menu3.c
blob: 5f42b151c8fb0dc141e3dcb5a4be2de36c57baad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * small test-driver for new dialog functionality
 *
 * Copyright (c) 1995, Jordan Hubbard
 *
 * All rights reserved.
 *
 * This source code may be used, modified, copied, distributed, and
 * sold, in both source and binary form provided that the above
 * copyright and these terms are retained, verbatim, as the first
 * lines of this file.  Under no circumstances is the author
 * responsible for the proper functioning of the software nor does
 * the author assume any responsibility for damages incurred with
 * its use.
 *
 * $FreeBSD$
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <dialog.h>

/* Hook functions */

static int
stop(dialogMenuItem *self)
{
    dialog_mesgbox("!", "I'm no idiot!", -1, -1);
    return DITEM_SUCCESS;
}

static int
maybe(dialogMenuItem *self)
{
    dialog_mesgbox("!", "I said don't rush me!  I'm THINKING!", -1, -1);
    return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
}

/* Dummy menu just to show of the ability */
static char *insurance[] = {
    "1,000,000",	"Mondo insurance policy", "Off",
    "5,000,000",	"Mega insurance policy", "Off",
    "10,000,000",	"Friend!  Most Favored customer!"
};

static void
preinsure(dialogMenuItem *self, int is_selected)
{
    if (is_selected) {
	static WINDOW *w;
	
	/* This has to be here first if you want to see selection traverse properly in the invoking menu */
	refresh();

	w = dupwin(newscr);
	DialogX = 1;
	DialogY = 13;
	dialog_radiolist("How much insurance would you like to take out?",
			 "If you're really going to do this, we recommend some insurance\n"
			 "first!  What kind of life insurance policy would you like?",
			 -1, -1, 3, 3, insurance, NULL);
	touchwin(w);
	wrefresh(w);
	delwin(w);
    }
}

/*
 * Show a simple menu that puts up a sub menu when a certain item is traversed to
 */

/* prompt	title						checked		fire		sel  */
static dialogMenuItem doit[] = {
    { "Rah!" },
    { "No way!" },
    { "Stop",	"No, I'm not going to do that!",		NULL,		stop,		NULL	},
    { "Maybe",	"I'm still thinking about it, don't rush me!",	NULL,		maybe,		NULL,	},
    { "Go",	"Yes!  Yes!  I want to do it!",			NULL,		NULL, 		preinsure },
};

/* End of hook functions */

/* Kick it off, James! */
int
main(int argc, unsigned char *argv[])
{
    int retval;
    
    init_dialog();
    
    
    DialogX = 5;
    DialogY = 1;
    retval = dialog_menu("Do you have the GUTS?",
			 "C'mon, macho man!  Do you have what it takes to do something REALLY\n"
			 "dangerous and stupid?  WHAT ARE YOU WAITING FOR?!",
			 -1, -1, 3, -3, doit + 2, (char *)TRUE, NULL, NULL);
    dialog_clear();
    fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
    
    end_dialog();
    return 0;
}
OpenPOWER on IntegriCloud