113136Sjkh/*
213136Sjkh * small test-driver for new dialog functionality
313136Sjkh *
413136Sjkh * Copyright (c) 1995, Jordan Hubbard
513136Sjkh *
613136Sjkh * All rights reserved.
713136Sjkh *
813136Sjkh * This source code may be used, modified, copied, distributed, and
913136Sjkh * sold, in both source and binary form provided that the above
1013136Sjkh * copyright and these terms are retained, verbatim, as the first
1113136Sjkh * lines of this file.  Under no circumstances is the author
1213136Sjkh * responsible for the proper functioning of the software nor does
1313136Sjkh * the author assume any responsibility for damages incurred with
1413136Sjkh * its use.
1513136Sjkh */
1613136Sjkh
17114603Sobrien#include <sys/cdefs.h>
18114603Sobrien__FBSDID("$FreeBSD$");
19114603Sobrien
2013136Sjkh#include <stdio.h>
2113136Sjkh#include <stdlib.h>
2213136Sjkh#include <string.h>
2313136Sjkh#include <unistd.h>
2413136Sjkh#include <sys/wait.h>
2513136Sjkh#include <dialog.h>
2613136Sjkh
2713136Sjkh/* Hook functions */
2813136Sjkh
2913136Sjkhstatic int
3013136Sjkhstop(dialogMenuItem *self)
3113136Sjkh{
3215273Sjkh    dialog_mesgbox("!", "I'm no idiot!", -1, -1);
3315273Sjkh    return DITEM_SUCCESS;
3413136Sjkh}
3513136Sjkh
3613136Sjkhstatic int
3713136Sjkhmaybe(dialogMenuItem *self)
3813136Sjkh{
3915273Sjkh    dialog_mesgbox("!", "I said don't rush me!  I'm THINKING!", -1, -1);
4015289Sjkh    return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
4113136Sjkh}
4213136Sjkh
4313136Sjkh/* Dummy menu just to show of the ability */
4413136Sjkhstatic char *insurance[] = {
4515273Sjkh    "1,000,000",	"Mondo insurance policy", "Off",
4615273Sjkh    "5,000,000",	"Mega insurance policy", "Off",
47209200Sae    "10,000,000",	"Friend!  Most Favored customer!", "On"
4813136Sjkh};
4913136Sjkh
5013136Sjkhstatic void
5113136Sjkhpreinsure(dialogMenuItem *self, int is_selected)
5213136Sjkh{
5315273Sjkh    if (is_selected) {
5415273Sjkh	static WINDOW *w;
5515273Sjkh
5615273Sjkh	/* This has to be here first if you want to see selection traverse properly in the invoking menu */
5715273Sjkh	refresh();
5815289Sjkh
5915273Sjkh	w = dupwin(newscr);
6015273Sjkh	DialogX = 1;
6115273Sjkh	DialogY = 13;
6215273Sjkh	dialog_radiolist("How much insurance would you like to take out?",
6315273Sjkh			 "If you're really going to do this, we recommend some insurance\n"
6415273Sjkh			 "first!  What kind of life insurance policy would you like?",
6515273Sjkh			 -1, -1, 3, 3, insurance, NULL);
6615273Sjkh	touchwin(w);
6715273Sjkh	wrefresh(w);
6815273Sjkh	delwin(w);
6915273Sjkh    }
7013136Sjkh}
7113136Sjkh
7213136Sjkh/*
7313136Sjkh * Show a simple menu that puts up a sub menu when a certain item is traversed to
7413136Sjkh */
7513136Sjkh
7615273Sjkh/* prompt	title						checked		fire		sel  */
7713136Sjkhstatic dialogMenuItem doit[] = {
7816888Sjkh    { "Rah!" },
7916888Sjkh    { "No way!" },
8015273Sjkh    { "Stop",	"No, I'm not going to do that!",		NULL,		stop,		NULL	},
8115273Sjkh    { "Maybe",	"I'm still thinking about it, don't rush me!",	NULL,		maybe,		NULL,	},
8215273Sjkh    { "Go",	"Yes!  Yes!  I want to do it!",			NULL,		NULL, 		preinsure },
8313136Sjkh};
8413136Sjkh
8513136Sjkh/* End of hook functions */
8613136Sjkh
8713136Sjkh/* Kick it off, James! */
8813136Sjkhint
8955752Sphantommain(int argc, char **argv)
9013136Sjkh{
9115273Sjkh    int retval;
9215273Sjkh
9315273Sjkh    init_dialog();
9415273Sjkh
9515273Sjkh
9615273Sjkh    DialogX = 5;
9715273Sjkh    DialogY = 1;
9815273Sjkh    retval = dialog_menu("Do you have the GUTS?",
9915273Sjkh			 "C'mon, macho man!  Do you have what it takes to do something REALLY\n"
10015273Sjkh			 "dangerous and stupid?  WHAT ARE YOU WAITING FOR?!",
10116888Sjkh			 -1, -1, 3, -3, doit + 2, (char *)TRUE, NULL, NULL);
10215273Sjkh    dialog_clear();
10315273Sjkh    fprintf(stderr, "returned value for dialog_menu was %d\n", retval);
10415273Sjkh
10515273Sjkh    end_dialog();
10615273Sjkh    return 0;
10713136Sjkh}
108