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