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 */ 1713136Sjkh 18114603Sobrien#include <sys/cdefs.h> 19114603Sobrien__FBSDID("$FreeBSD$"); 20114603Sobrien 2113136Sjkh#include <sys/wait.h> 2213136Sjkh#include <dialog.h> 2313136Sjkh 2413136Sjkh/* Hook functions */ 2513136Sjkh 2613136Sjkhstatic int 2713136SjkhgetBool(dialogMenuItem *self) 2813136Sjkh{ 2915273Sjkh if (self->data && *((int *)self->data)) 3015273Sjkh return TRUE; 3115273Sjkh return FALSE; 3213136Sjkh} 3313136Sjkh 3413136Sjkhstatic int 3513136SjkhsetBool(dialogMenuItem *self) 3613136Sjkh{ 3715273Sjkh if (self->data) { 3815273Sjkh *((int *)self->data) = !*((int *)self->data); 3915273Sjkh return DITEM_SUCCESS; 4015273Sjkh } 4115273Sjkh return DITEM_FAILURE; 4213136Sjkh} 4313136Sjkh 4413136Sjkhstatic int german_book, italian_book, slang_book; 4513136Sjkhstatic int spending; 4613136Sjkh 4713136Sjkhstatic int 4813136Sjkhcheck(dialogMenuItem *self) 4913136Sjkh{ 50209200Sae return ((int)(intptr_t)self->data == spending); 5113136Sjkh} 5213136Sjkh 5313136Sjkhstatic int 5413136Sjkhspend(dialogMenuItem *self) 5513136Sjkh{ 56209200Sae spending = (int)(intptr_t)self->data; 5715273Sjkh return DITEM_SUCCESS | DITEM_REDRAW; 5813136Sjkh} 5913136Sjkh 6013136Sjkh/* menu4 - Show off a simulated compound menu (group at top is checklist, group at bottom radio) */ 6115273Sjkh/* prompt title checked fire sel, data lbra mark rbra */ 6213136Sjkhstatic dialogMenuItem menu4[] = { 6315273Sjkh { "German", "Buy books on learning German", getBool, setBool, NULL, &german_book }, 6415273Sjkh { "Italian","Buy books on learning Italian", getBool, setBool, NULL, &italian_book }, 6515273Sjkh { "Slang", "Buy books on commonly used insults", getBool, setBool, NULL, &slang_book }, 6615273Sjkh { "-----", "----------------------------------", NULL, NULL, NULL, NULL, ' ', ' ', ' ' }, 6715273Sjkh { "1000", "Spend $1,000", check, spend, NULL, (void *)1000, '(', '*', ')' }, 6815273Sjkh { "500", "Spend $500", check, spend, NULL, (void *)500, '(', '*', ')' }, 6915273Sjkh { "100", "Spend $100", check, spend, NULL, (void *)100, '(', '*', ')' }, 7013136Sjkh}; 7113136Sjkh 7213136Sjkh/* End of hook functions */ 7313136Sjkh 7413136Sjkh/* Kick it off, James! */ 7513136Sjkhint 7655752Sphantommain(int argc, char **argv) 7713136Sjkh{ 7815273Sjkh int retval; 7915273Sjkh 8015273Sjkh init_dialog(); 8115273Sjkh 8215273Sjkh 8315273Sjkh retval = dialog_checklist("this is dialog_checklist() in action, test #3", 8415273Sjkh "Now we show off some of the button 'styles' one can create.", 8515273Sjkh -1, -1, 7, -7, menu4, NULL); 8615273Sjkh dialog_clear(); 8715273Sjkh fprintf(stderr, "spent $%d on %s%s%s books\n", spending, german_book ? " german" : "", 8815273Sjkh italian_book ? " italian" : "", slang_book ? " slang" : ""); 8915273Sjkh 9015273Sjkh end_dialog(); 9115273Sjkh return 0; 9213136Sjkh} 93