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