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