1 /* $OpenBSD: menu.h,v 1.10 2023/10/17 09:52:10 nicm Exp $ */ 2 /**************************************************************************** 3 * Copyright 2020 Thomas E. Dickey * 4 * Copyright 1998-2016,2017 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer, 1995,1997 * 33 ****************************************************************************/ 34 35 /* $Id: menu.h,v 1.10 2023/10/17 09:52:10 nicm Exp $ */ 36 37 #ifndef ETI_MENU 38 #define ETI_MENU 39 40 #ifdef AMIGA 41 #define TEXT TEXT_ncurses 42 #endif 43 44 #include <curses.h> 45 #include <eti.h> 46 47 #ifdef __cplusplus 48 extern "C" 49 { 50 #endif 51 52 #if defined(BUILDING_MENU) 53 # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_EXPORT 54 #else 55 # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_IMPORT 56 #endif 57 58 #define MENU_WRAPPED_VAR(type,name) extern MENU_IMPEXP type NCURSES_PUBLIC_VAR(name)(void) 59 60 #define MENU_EXPORT(type) MENU_IMPEXP type NCURSES_API 61 #define MENU_EXPORT_VAR(type) MENU_IMPEXP type 62 63 typedef int Menu_Options; 64 typedef int Item_Options; 65 66 /* Menu options: */ 67 #define O_ONEVALUE (0x01) 68 #define O_SHOWDESC (0x02) 69 #define O_ROWMAJOR (0x04) 70 #define O_IGNORECASE (0x08) 71 #define O_SHOWMATCH (0x10) 72 #define O_NONCYCLIC (0x20) 73 #define O_MOUSE_MENU (0x40) 74 75 /* Item options: */ 76 #define O_SELECTABLE (0x01) 77 78 #if !NCURSES_OPAQUE_MENU 79 typedef struct 80 { 81 const char *str; 82 unsigned short length; 83 } 84 TEXT; 85 #endif /* !NCURSES_OPAQUE_MENU */ 86 87 struct tagMENU; 88 89 typedef struct tagITEM 90 #if !NCURSES_OPAQUE_MENU 91 { 92 TEXT name; /* name of menu item */ 93 TEXT description; /* description of item, optional in display */ 94 struct tagMENU *imenu; /* Pointer to parent menu */ 95 void *userptr; /* Pointer to user defined per item data */ 96 Item_Options opt; /* Item options */ 97 short index; /* Item number if connected to a menu */ 98 short y; /* y and x location of item in menu */ 99 short x; 100 bool value; /* Selection value */ 101 102 struct tagITEM *left; /* neighbor items */ 103 struct tagITEM *right; 104 struct tagITEM *up; 105 struct tagITEM *down; 106 107 } 108 #endif /* !NCURSES_OPAQUE_MENU */ 109 ITEM; 110 111 typedef void (*Menu_Hook) (struct tagMENU *); 112 113 typedef struct tagMENU 114 #if 1 /* not yet: !NCURSES_OPAQUE_MENU */ 115 { 116 short height; /* Nr. of chars high */ 117 short width; /* Nr. of chars wide */ 118 short rows; /* Nr. of items high */ 119 short cols; /* Nr. of items wide */ 120 short frows; /* Nr. of formatted items high */ 121 short fcols; /* Nr. of formatted items wide */ 122 short arows; /* Nr. of items high (actual) */ 123 short namelen; /* Max. name length */ 124 short desclen; /* Max. description length */ 125 short marklen; /* Length of mark, if any */ 126 short itemlen; /* Length of one item */ 127 short spc_desc; /* Spacing for descriptor */ 128 short spc_cols; /* Spacing for columns */ 129 short spc_rows; /* Spacing for rows */ 130 char *pattern; /* Buffer to store match chars */ 131 short pindex; /* Index into pattern buffer */ 132 WINDOW *win; /* Window containing menu */ 133 WINDOW *sub; /* Subwindow for menu display */ 134 WINDOW *userwin; /* User's window */ 135 WINDOW *usersub; /* User's subwindow */ 136 ITEM **items; /* array of items */ 137 short nitems; /* Nr. of items in menu */ 138 ITEM *curitem; /* Current item */ 139 short toprow; /* Top row of menu */ 140 chtype fore; /* Selection attribute */ 141 chtype back; /* Nonselection attribute */ 142 chtype grey; /* Inactive attribute */ 143 unsigned char pad; /* Pad character */ 144 145 Menu_Hook menuinit; /* User hooks */ 146 Menu_Hook menuterm; 147 Menu_Hook iteminit; 148 Menu_Hook itemterm; 149 150 void *userptr; /* Pointer to menus user data */ 151 char *mark; /* Pointer to marker string */ 152 153 Menu_Options opt; /* Menu options */ 154 unsigned short status; /* Internal state of menu */ 155 } 156 #endif /* !NCURSES_OPAQUE_MENU */ 157 MENU; 158 159 /* Define keys */ 160 161 #define REQ_LEFT_ITEM (KEY_MAX + 1) 162 #define REQ_RIGHT_ITEM (KEY_MAX + 2) 163 #define REQ_UP_ITEM (KEY_MAX + 3) 164 #define REQ_DOWN_ITEM (KEY_MAX + 4) 165 #define REQ_SCR_ULINE (KEY_MAX + 5) 166 #define REQ_SCR_DLINE (KEY_MAX + 6) 167 #define REQ_SCR_DPAGE (KEY_MAX + 7) 168 #define REQ_SCR_UPAGE (KEY_MAX + 8) 169 #define REQ_FIRST_ITEM (KEY_MAX + 9) 170 #define REQ_LAST_ITEM (KEY_MAX + 10) 171 #define REQ_NEXT_ITEM (KEY_MAX + 11) 172 #define REQ_PREV_ITEM (KEY_MAX + 12) 173 #define REQ_TOGGLE_ITEM (KEY_MAX + 13) 174 #define REQ_CLEAR_PATTERN (KEY_MAX + 14) 175 #define REQ_BACK_PATTERN (KEY_MAX + 15) 176 #define REQ_NEXT_MATCH (KEY_MAX + 16) 177 #define REQ_PREV_MATCH (KEY_MAX + 17) 178 179 #define MIN_MENU_COMMAND (KEY_MAX + 1) 180 #define MAX_MENU_COMMAND (KEY_MAX + 17) 181 182 /* 183 * Some AT&T code expects MAX_COMMAND to be out-of-band not 184 * just for menu commands but for forms ones as well. 185 */ 186 #if defined(MAX_COMMAND) 187 # if (MAX_MENU_COMMAND > MAX_COMMAND) 188 # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND 189 # elif (MAX_COMMAND != (KEY_MAX + 128)) 190 # error Something is wrong -- MAX_COMMAND is already inconsistently defined. 191 # endif 192 #else 193 # define MAX_COMMAND (KEY_MAX + 128) 194 #endif 195 196 /* --------- prototypes for libmenu functions ----------------------------- */ 197 198 extern MENU_EXPORT(ITEM **) menu_items(const MENU *); 199 extern MENU_EXPORT(ITEM *) current_item(const MENU *); 200 extern MENU_EXPORT(ITEM *) new_item(const char *, const char *); 201 202 extern MENU_EXPORT(MENU *) new_menu(ITEM **); 203 204 extern MENU_EXPORT(Item_Options) item_opts(const ITEM *); 205 extern MENU_EXPORT(Menu_Options) menu_opts(const MENU *); 206 207 extern MENU_EXPORT(Menu_Hook) item_init(const MENU *); 208 extern MENU_EXPORT(Menu_Hook) item_term(const MENU *); 209 extern MENU_EXPORT(Menu_Hook) menu_init(const MENU *); 210 extern MENU_EXPORT(Menu_Hook) menu_term(const MENU *); 211 212 extern MENU_EXPORT(WINDOW *) menu_sub(const MENU *); 213 extern MENU_EXPORT(WINDOW *) menu_win(const MENU *); 214 215 extern MENU_EXPORT(const char *) item_description(const ITEM *); 216 extern MENU_EXPORT(const char *) item_name(const ITEM *); 217 extern MENU_EXPORT(const char *) menu_mark(const MENU *); 218 extern MENU_EXPORT(const char *) menu_request_name(int); 219 220 extern MENU_EXPORT(char *) menu_pattern(const MENU *); 221 222 extern MENU_EXPORT(void *) menu_userptr(const MENU *); 223 extern MENU_EXPORT(void *) item_userptr(const ITEM *); 224 225 extern MENU_EXPORT(chtype) menu_back(const MENU *); 226 extern MENU_EXPORT(chtype) menu_fore(const MENU *); 227 extern MENU_EXPORT(chtype) menu_grey(const MENU *); 228 229 extern MENU_EXPORT(int) free_item(ITEM *); 230 extern MENU_EXPORT(int) free_menu(MENU *); 231 extern MENU_EXPORT(int) item_count(const MENU *); 232 extern MENU_EXPORT(int) item_index(const ITEM *); 233 extern MENU_EXPORT(int) item_opts_off(ITEM *, Item_Options); 234 extern MENU_EXPORT(int) item_opts_on(ITEM *, Item_Options); 235 extern MENU_EXPORT(int) menu_driver(MENU *, int); 236 extern MENU_EXPORT(int) menu_opts_off(MENU *, Menu_Options); 237 extern MENU_EXPORT(int) menu_opts_on(MENU *, Menu_Options); 238 extern MENU_EXPORT(int) menu_pad(const MENU *); 239 extern MENU_EXPORT(int) pos_menu_cursor(const MENU *); 240 extern MENU_EXPORT(int) post_menu(MENU *); 241 extern MENU_EXPORT(int) scale_menu(const MENU *, int *, int *); 242 extern MENU_EXPORT(int) set_current_item(MENU *menu, ITEM *item); 243 extern MENU_EXPORT(int) set_item_init(MENU *, Menu_Hook); 244 extern MENU_EXPORT(int) set_item_opts(ITEM *, Item_Options); 245 extern MENU_EXPORT(int) set_item_term(MENU *, Menu_Hook); 246 extern MENU_EXPORT(int) set_item_userptr(ITEM *, void *); 247 extern MENU_EXPORT(int) set_item_value(ITEM *, bool); 248 extern MENU_EXPORT(int) set_menu_back(MENU *, chtype); 249 extern MENU_EXPORT(int) set_menu_fore(MENU *, chtype); 250 extern MENU_EXPORT(int) set_menu_format(MENU *, int, int); 251 extern MENU_EXPORT(int) set_menu_grey(MENU *, chtype); 252 extern MENU_EXPORT(int) set_menu_init(MENU *, Menu_Hook); 253 extern MENU_EXPORT(int) set_menu_items(MENU *, ITEM **); 254 extern MENU_EXPORT(int) set_menu_mark(MENU *, const char *); 255 extern MENU_EXPORT(int) set_menu_opts(MENU *, Menu_Options); 256 extern MENU_EXPORT(int) set_menu_pad(MENU *, int); 257 extern MENU_EXPORT(int) set_menu_pattern(MENU *, const char *); 258 extern MENU_EXPORT(int) set_menu_sub(MENU *, WINDOW *); 259 extern MENU_EXPORT(int) set_menu_term(MENU *, Menu_Hook); 260 extern MENU_EXPORT(int) set_menu_userptr(MENU *, void *); 261 extern MENU_EXPORT(int) set_menu_win(MENU *, WINDOW *); 262 extern MENU_EXPORT(int) set_top_row(MENU *, int); 263 extern MENU_EXPORT(int) top_row(const MENU *); 264 extern MENU_EXPORT(int) unpost_menu(MENU *); 265 extern MENU_EXPORT(int) menu_request_by_name(const char *); 266 extern MENU_EXPORT(int) set_menu_spacing(MENU *, int, int, int); 267 extern MENU_EXPORT(int) menu_spacing(const MENU *, int *, int *, int *); 268 269 extern MENU_EXPORT(bool) item_value(const ITEM *); 270 extern MENU_EXPORT(bool) item_visible(const ITEM *); 271 272 extern MENU_EXPORT(void) menu_format(const MENU *, int *, int *); 273 274 #if NCURSES_SP_FUNCS 275 extern MENU_EXPORT(MENU *) NCURSES_SP_NAME(new_menu) (SCREEN *, ITEM **); 276 #endif 277 278 #ifdef __cplusplus 279 } 280 #endif 281 282 #endif /* ETI_MENU */ 283