1*b618a1eeSThomas Cort /* $NetBSD: menu.h,v 1.13 2004/03/22 19:01:09 jdc Exp $ */ 2*b618a1eeSThomas Cort 3*b618a1eeSThomas Cort /*- 4*b618a1eeSThomas Cort * Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@yahoo.com.au) 5*b618a1eeSThomas Cort * All rights reserved. 6*b618a1eeSThomas Cort * 7*b618a1eeSThomas Cort * Redistribution and use in source and binary forms, with or without 8*b618a1eeSThomas Cort * modification, are permitted provided that the following conditions 9*b618a1eeSThomas Cort * are met: 10*b618a1eeSThomas Cort * 1. Redistributions of source code must retain the above copyright 11*b618a1eeSThomas Cort * notice, this list of conditions and the following disclaimer. 12*b618a1eeSThomas Cort * 2. The name of the author may not be used to endorse or promote products 13*b618a1eeSThomas Cort * derived from this software without specific prior written permission 14*b618a1eeSThomas Cort * 15*b618a1eeSThomas Cort * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16*b618a1eeSThomas Cort * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*b618a1eeSThomas Cort * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*b618a1eeSThomas Cort * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19*b618a1eeSThomas Cort * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*b618a1eeSThomas Cort * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*b618a1eeSThomas Cort * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*b618a1eeSThomas Cort * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*b618a1eeSThomas Cort * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*b618a1eeSThomas Cort * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*b618a1eeSThomas Cort * 26*b618a1eeSThomas Cort * 27*b618a1eeSThomas Cort */ 28*b618a1eeSThomas Cort 29*b618a1eeSThomas Cort #ifndef _MENU_H_ 30*b618a1eeSThomas Cort #define _MENU_H_ 31*b618a1eeSThomas Cort 32*b618a1eeSThomas Cort #include <curses.h> 33*b618a1eeSThomas Cort #include <eti.h> 34*b618a1eeSThomas Cort 35*b618a1eeSThomas Cort /* requests for the menu_driver call */ 36*b618a1eeSThomas Cort #define REQ_BASE_NUM (KEY_MAX + 0x200) 37*b618a1eeSThomas Cort #define REQ_LEFT_ITEM (KEY_MAX + 0x201) 38*b618a1eeSThomas Cort #define REQ_RIGHT_ITEM (KEY_MAX + 0x202) 39*b618a1eeSThomas Cort #define REQ_UP_ITEM (KEY_MAX + 0x203) 40*b618a1eeSThomas Cort #define REQ_DOWN_ITEM (KEY_MAX + 0x204) 41*b618a1eeSThomas Cort #define REQ_SCR_ULINE (KEY_MAX + 0x205) 42*b618a1eeSThomas Cort #define REQ_SCR_DLINE (KEY_MAX + 0x206) 43*b618a1eeSThomas Cort #define REQ_SCR_DPAGE (KEY_MAX + 0x207) 44*b618a1eeSThomas Cort #define REQ_SCR_UPAGE (KEY_MAX + 0x208) 45*b618a1eeSThomas Cort #define REQ_FIRST_ITEM (KEY_MAX + 0x209) 46*b618a1eeSThomas Cort #define REQ_LAST_ITEM (KEY_MAX + 0x20a) 47*b618a1eeSThomas Cort #define REQ_NEXT_ITEM (KEY_MAX + 0x20b) 48*b618a1eeSThomas Cort #define REQ_PREV_ITEM (KEY_MAX + 0x20c) 49*b618a1eeSThomas Cort #define REQ_TOGGLE_ITEM (KEY_MAX + 0x20d) 50*b618a1eeSThomas Cort #define REQ_CLEAR_PATTERN (KEY_MAX + 0x20e) 51*b618a1eeSThomas Cort #define REQ_BACK_PATTERN (KEY_MAX + 0x20f) 52*b618a1eeSThomas Cort #define REQ_NEXT_MATCH (KEY_MAX + 0x210) 53*b618a1eeSThomas Cort #define REQ_PREV_MATCH (KEY_MAX + 0x211) 54*b618a1eeSThomas Cort 55*b618a1eeSThomas Cort #define MAX_COMMAND (KEY_MAX + 0x211) /* last menu driver request 56*b618a1eeSThomas Cort - for application defined 57*b618a1eeSThomas Cort commands */ 58*b618a1eeSThomas Cort 59*b618a1eeSThomas Cort /* Menu options */ 60*b618a1eeSThomas Cort typedef unsigned int OPTIONS; 61*b618a1eeSThomas Cort 62*b618a1eeSThomas Cort /* and the values they can have */ 63*b618a1eeSThomas Cort #define O_ONEVALUE (0x1) 64*b618a1eeSThomas Cort #define O_SHOWDESC (0x2) 65*b618a1eeSThomas Cort #define O_ROWMAJOR (0x4) 66*b618a1eeSThomas Cort #define O_IGNORECASE (0x8) 67*b618a1eeSThomas Cort #define O_SHOWMATCH (0x10) 68*b618a1eeSThomas Cort #define O_NONCYCLIC (0x20) 69*b618a1eeSThomas Cort #define O_SELECTABLE (0x40) 70*b618a1eeSThomas Cort #define O_RADIO (0x80) 71*b618a1eeSThomas Cort 72*b618a1eeSThomas Cort typedef struct __menu_str { 73*b618a1eeSThomas Cort char *string; 74*b618a1eeSThomas Cort int length; 75*b618a1eeSThomas Cort } MENU_STR; 76*b618a1eeSThomas Cort 77*b618a1eeSThomas Cort typedef struct __menu MENU; 78*b618a1eeSThomas Cort typedef struct __item ITEM; 79*b618a1eeSThomas Cort 80*b618a1eeSThomas Cort typedef void (*Menu_Hook) (MENU *); 81*b618a1eeSThomas Cort 82*b618a1eeSThomas Cort struct __item { 83*b618a1eeSThomas Cort MENU_STR name; 84*b618a1eeSThomas Cort MENU_STR description; 85*b618a1eeSThomas Cort char *userptr; 86*b618a1eeSThomas Cort int visible; /* set if item is visible */ 87*b618a1eeSThomas Cort int selected; /* set if item has been selected */ 88*b618a1eeSThomas Cort int row; /* menu row this item is on */ 89*b618a1eeSThomas Cort int col; /* menu column this item is on */ 90*b618a1eeSThomas Cort OPTIONS opts; 91*b618a1eeSThomas Cort MENU *parent; /* menu this item is bound to */ 92*b618a1eeSThomas Cort int index; /* index number for this item, if attached */ 93*b618a1eeSThomas Cort /* The following are the item's neighbours - makes menu 94*b618a1eeSThomas Cort navigation easier */ 95*b618a1eeSThomas Cort ITEM *left; 96*b618a1eeSThomas Cort ITEM *right; 97*b618a1eeSThomas Cort ITEM *up; 98*b618a1eeSThomas Cort ITEM *down; 99*b618a1eeSThomas Cort }; 100*b618a1eeSThomas Cort 101*b618a1eeSThomas Cort struct __menu { 102*b618a1eeSThomas Cort int rows; /* max number of rows to be displayed */ 103*b618a1eeSThomas Cort int cols; /* max number of columns to be displayed */ 104*b618a1eeSThomas Cort int item_rows; /* number of item rows we have */ 105*b618a1eeSThomas Cort int item_cols; /* number of item columns we have */ 106*b618a1eeSThomas Cort int cur_row; /* current cursor row */ 107*b618a1eeSThomas Cort int cur_col; /* current cursor column */ 108*b618a1eeSThomas Cort MENU_STR mark; /* menu mark string */ 109*b618a1eeSThomas Cort MENU_STR unmark; /* menu unmark string */ 110*b618a1eeSThomas Cort OPTIONS opts; /* options for the menu */ 111*b618a1eeSThomas Cort char *pattern; /* the pattern buffer */ 112*b618a1eeSThomas Cort int plen; /* pattern buffer length */ 113*b618a1eeSThomas Cort int match_len; /* length of pattern matched */ 114*b618a1eeSThomas Cort int posted; /* set if menu is posted */ 115*b618a1eeSThomas Cort attr_t fore; /* menu foreground */ 116*b618a1eeSThomas Cort attr_t back; /* menu background */ 117*b618a1eeSThomas Cort attr_t grey; /* greyed out (nonselectable) menu item */ 118*b618a1eeSThomas Cort int pad; /* filler char between name and description */ 119*b618a1eeSThomas Cort char *userptr; 120*b618a1eeSThomas Cort int top_row; /* the row that is at the top of the menu */ 121*b618a1eeSThomas Cort int max_item_width; /* widest item */ 122*b618a1eeSThomas Cort int col_width; /* width of the menu columns - this is not always 123*b618a1eeSThomas Cort the same as the widest item */ 124*b618a1eeSThomas Cort int item_count; /* number of items attached */ 125*b618a1eeSThomas Cort ITEM **items; /* items associated with this menu */ 126*b618a1eeSThomas Cort int cur_item; /* item cursor is currently positioned at */ 127*b618a1eeSThomas Cort int in_init; /* set when processing an init or term function call */ 128*b618a1eeSThomas Cort Menu_Hook menu_init; /* call this when menu is posted */ 129*b618a1eeSThomas Cort Menu_Hook menu_term; /* call this when menu is unposted */ 130*b618a1eeSThomas Cort Menu_Hook item_init; /* call this when menu posted & after 131*b618a1eeSThomas Cort current item changes */ 132*b618a1eeSThomas Cort Menu_Hook item_term; /* call this when menu unposted & just 133*b618a1eeSThomas Cort before current item changes */ 134*b618a1eeSThomas Cort WINDOW *menu_win; /* the menu window */ 135*b618a1eeSThomas Cort WINDOW *menu_subwin; /* the menu subwindow */ 136*b618a1eeSThomas Cort WINDOW *scrwin; /* the window to write to */ 137*b618a1eeSThomas Cort }; 138*b618a1eeSThomas Cort 139*b618a1eeSThomas Cort 140*b618a1eeSThomas Cort /* Public function prototypes. */ 141*b618a1eeSThomas Cort __BEGIN_DECLS 142*b618a1eeSThomas Cort int menu_driver(MENU *, int); 143*b618a1eeSThomas Cort int scale_menu(MENU *, int *, int *); 144*b618a1eeSThomas Cort int set_top_row(MENU *, int); 145*b618a1eeSThomas Cort int pos_menu_cursor(MENU *); 146*b618a1eeSThomas Cort int top_row(MENU *); 147*b618a1eeSThomas Cort 148*b618a1eeSThomas Cort int free_menu(MENU *); 149*b618a1eeSThomas Cort char menu_back(MENU *); 150*b618a1eeSThomas Cort char menu_fore(MENU *); 151*b618a1eeSThomas Cort void menu_format(MENU *, int *, int *); 152*b618a1eeSThomas Cort char menu_grey(MENU *); 153*b618a1eeSThomas Cort Menu_Hook menu_init(MENU *); 154*b618a1eeSThomas Cort char *menu_mark(MENU *); 155*b618a1eeSThomas Cort OPTIONS menu_opts(MENU *); 156*b618a1eeSThomas Cort int menu_opts_off(MENU *, OPTIONS); 157*b618a1eeSThomas Cort int menu_opts_on(MENU *, OPTIONS); 158*b618a1eeSThomas Cort int menu_pad(MENU *); 159*b618a1eeSThomas Cort char *menu_pattern(MENU *); 160*b618a1eeSThomas Cort WINDOW *menu_sub(MENU *); 161*b618a1eeSThomas Cort Menu_Hook menu_term(MENU *); 162*b618a1eeSThomas Cort char *menu_unmark (MENU *); 163*b618a1eeSThomas Cort char *menu_userptr(MENU *); 164*b618a1eeSThomas Cort WINDOW *menu_win(MENU *); 165*b618a1eeSThomas Cort MENU *new_menu(ITEM **); 166*b618a1eeSThomas Cort int post_menu(MENU *); 167*b618a1eeSThomas Cort int set_menu_back(MENU *, attr_t); 168*b618a1eeSThomas Cort int set_menu_fore(MENU *, attr_t); 169*b618a1eeSThomas Cort int set_menu_format(MENU *, int, int); 170*b618a1eeSThomas Cort int set_menu_grey(MENU *, attr_t); 171*b618a1eeSThomas Cort int set_menu_init(MENU *, Menu_Hook); 172*b618a1eeSThomas Cort int set_menu_items(MENU *, ITEM **); 173*b618a1eeSThomas Cort int set_menu_mark(MENU *, char *); 174*b618a1eeSThomas Cort int set_menu_opts(MENU *, OPTIONS); 175*b618a1eeSThomas Cort int set_menu_pad(MENU *, int); 176*b618a1eeSThomas Cort int set_menu_pattern(MENU *, char *); 177*b618a1eeSThomas Cort int set_menu_sub(MENU *, WINDOW *); 178*b618a1eeSThomas Cort int set_menu_term(MENU *, Menu_Hook); 179*b618a1eeSThomas Cort int set_menu_unmark(MENU *, char *); 180*b618a1eeSThomas Cort int set_menu_userptr(MENU *, char *); 181*b618a1eeSThomas Cort int set_menu_win(MENU *, WINDOW *); 182*b618a1eeSThomas Cort int unpost_menu(MENU *); 183*b618a1eeSThomas Cort 184*b618a1eeSThomas Cort ITEM *current_item(MENU *); 185*b618a1eeSThomas Cort int free_item(ITEM *); 186*b618a1eeSThomas Cort int item_count(MENU *); 187*b618a1eeSThomas Cort char *item_description(ITEM *); 188*b618a1eeSThomas Cort int item_index(ITEM *); 189*b618a1eeSThomas Cort Menu_Hook item_init(MENU *); 190*b618a1eeSThomas Cort char *item_name(ITEM *); 191*b618a1eeSThomas Cort OPTIONS item_opts(ITEM *); 192*b618a1eeSThomas Cort int item_opts_off(ITEM *, OPTIONS); 193*b618a1eeSThomas Cort int item_opts_on(ITEM *, OPTIONS); 194*b618a1eeSThomas Cort int item_selected(MENU *, int **); /* return the item index of selected */ 195*b618a1eeSThomas Cort Menu_Hook item_term(MENU *); 196*b618a1eeSThomas Cort char *item_userptr(ITEM *); 197*b618a1eeSThomas Cort int item_value(ITEM *); 198*b618a1eeSThomas Cort int item_visible(ITEM *); 199*b618a1eeSThomas Cort ITEM **menu_items(MENU *); 200*b618a1eeSThomas Cort ITEM *new_item(char *, char *); 201*b618a1eeSThomas Cort int set_current_item(MENU *, ITEM *); 202*b618a1eeSThomas Cort int set_item_init(MENU *, Menu_Hook); 203*b618a1eeSThomas Cort int set_item_opts(ITEM *, OPTIONS); 204*b618a1eeSThomas Cort int set_item_term(MENU *, Menu_Hook); 205*b618a1eeSThomas Cort int set_item_userptr(ITEM *, char *); 206*b618a1eeSThomas Cort int set_item_value(ITEM *, int); 207*b618a1eeSThomas Cort 208*b618a1eeSThomas Cort __END_DECLS 209*b618a1eeSThomas Cort 210*b618a1eeSThomas Cort #endif /* !_MENU_H_ */ 211