10e3d5408SPeter Wemm /**************************************************************************** 2e1865124SBaptiste Daroussin * Copyright 2020 Thomas E. Dickey * 3e1865124SBaptiste Daroussin * Copyright 1998-2016,2017 Free Software Foundation, Inc. * 40e3d5408SPeter Wemm * * 50e3d5408SPeter Wemm * Permission is hereby granted, free of charge, to any person obtaining a * 60e3d5408SPeter Wemm * copy of this software and associated documentation files (the * 70e3d5408SPeter Wemm * "Software"), to deal in the Software without restriction, including * 80e3d5408SPeter Wemm * without limitation the rights to use, copy, modify, merge, publish, * 90e3d5408SPeter Wemm * distribute, distribute with modifications, sublicense, and/or sell * 100e3d5408SPeter Wemm * copies of the Software, and to permit persons to whom the Software is * 110e3d5408SPeter Wemm * furnished to do so, subject to the following conditions: * 120e3d5408SPeter Wemm * * 130e3d5408SPeter Wemm * The above copyright notice and this permission notice shall be included * 140e3d5408SPeter Wemm * in all copies or substantial portions of the Software. * 150e3d5408SPeter Wemm * * 160e3d5408SPeter Wemm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 170e3d5408SPeter Wemm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 180e3d5408SPeter Wemm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 190e3d5408SPeter Wemm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 200e3d5408SPeter Wemm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 210e3d5408SPeter Wemm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 220e3d5408SPeter Wemm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 230e3d5408SPeter Wemm * * 240e3d5408SPeter Wemm * Except as contained in this notice, the name(s) of the above copyright * 250e3d5408SPeter Wemm * holders shall not be used in advertising or otherwise to promote the * 260e3d5408SPeter Wemm * sale, use or other dealings in this Software without prior written * 270e3d5408SPeter Wemm * authorization. * 280e3d5408SPeter Wemm ****************************************************************************/ 290e3d5408SPeter Wemm 300e3d5408SPeter Wemm /**************************************************************************** 314a1a9510SRong-En Fan * Author: Juergen Pfeifer, 1995,1997 * 320e3d5408SPeter Wemm ****************************************************************************/ 330e3d5408SPeter Wemm 34*7a656419SBaptiste Daroussin /* $Id: menu.h,v 1.26 2020/12/12 00:38:02 tom Exp $ */ 354a1a9510SRong-En Fan 360e3d5408SPeter Wemm #ifndef ETI_MENU 370e3d5408SPeter Wemm #define ETI_MENU 380e3d5408SPeter Wemm 3918259542SPeter Wemm #ifdef AMIGA 4018259542SPeter Wemm #define TEXT TEXT_ncurses 4118259542SPeter Wemm #endif 4218259542SPeter Wemm 430e3d5408SPeter Wemm #include <curses.h> 440e3d5408SPeter Wemm #include <eti.h> 450e3d5408SPeter Wemm 460e3d5408SPeter Wemm #ifdef __cplusplus 47*7a656419SBaptiste Daroussin extern "C" 48*7a656419SBaptiste Daroussin { 490e3d5408SPeter Wemm #endif 500e3d5408SPeter Wemm 51*7a656419SBaptiste Daroussin #if defined(BUILDING_MENU) 52*7a656419SBaptiste Daroussin # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_EXPORT 53*7a656419SBaptiste Daroussin #else 54*7a656419SBaptiste Daroussin # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_IMPORT 55*7a656419SBaptiste Daroussin #endif 56*7a656419SBaptiste Daroussin 57*7a656419SBaptiste Daroussin #define MENU_WRAPPED_VAR(type,name) extern MENU_IMPEXP type NCURSES_PUBLIC_VAR(name)(void) 58*7a656419SBaptiste Daroussin 59*7a656419SBaptiste Daroussin #define MENU_EXPORT(type) MENU_IMPEXP type NCURSES_API 60*7a656419SBaptiste Daroussin #define MENU_EXPORT_VAR(type) MENU_IMPEXP type 61*7a656419SBaptiste Daroussin 620e3d5408SPeter Wemm typedef int Menu_Options; 630e3d5408SPeter Wemm typedef int Item_Options; 640e3d5408SPeter Wemm 650e3d5408SPeter Wemm /* Menu options: */ 660e3d5408SPeter Wemm #define O_ONEVALUE (0x01) 670e3d5408SPeter Wemm #define O_SHOWDESC (0x02) 680e3d5408SPeter Wemm #define O_ROWMAJOR (0x04) 690e3d5408SPeter Wemm #define O_IGNORECASE (0x08) 700e3d5408SPeter Wemm #define O_SHOWMATCH (0x10) 710e3d5408SPeter Wemm #define O_NONCYCLIC (0x20) 72aae38d10SBaptiste Daroussin #define O_MOUSE_MENU (0x40) 730e3d5408SPeter Wemm 740e3d5408SPeter Wemm /* Item options: */ 750e3d5408SPeter Wemm #define O_SELECTABLE (0x01) 760e3d5408SPeter Wemm 77aae38d10SBaptiste Daroussin #if !NCURSES_OPAQUE_MENU 780e3d5408SPeter Wemm typedef struct 790e3d5408SPeter Wemm { 800e3d5408SPeter Wemm const char *str; 810e3d5408SPeter Wemm unsigned short length; 82*7a656419SBaptiste Daroussin } 83*7a656419SBaptiste Daroussin TEXT; 84aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */ 85aae38d10SBaptiste Daroussin 86aae38d10SBaptiste Daroussin struct tagMENU; 870e3d5408SPeter Wemm 880e3d5408SPeter Wemm typedef struct tagITEM 89aae38d10SBaptiste Daroussin #if !NCURSES_OPAQUE_MENU 900e3d5408SPeter Wemm { 910e3d5408SPeter Wemm TEXT name; /* name of menu item */ 920e3d5408SPeter Wemm TEXT description; /* description of item, optional in display */ 930e3d5408SPeter Wemm struct tagMENU *imenu; /* Pointer to parent menu */ 940e3d5408SPeter Wemm void *userptr; /* Pointer to user defined per item data */ 950e3d5408SPeter Wemm Item_Options opt; /* Item options */ 960e3d5408SPeter Wemm short index; /* Item number if connected to a menu */ 970e3d5408SPeter Wemm short y; /* y and x location of item in menu */ 980e3d5408SPeter Wemm short x; 990e3d5408SPeter Wemm bool value; /* Selection value */ 1000e3d5408SPeter Wemm 1014a1a9510SRong-En Fan struct tagITEM *left; /* neighbor items */ 1020e3d5408SPeter Wemm struct tagITEM *right; 1030e3d5408SPeter Wemm struct tagITEM *up; 1040e3d5408SPeter Wemm struct tagITEM *down; 1050e3d5408SPeter Wemm 106aae38d10SBaptiste Daroussin } 107aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */ 108aae38d10SBaptiste Daroussin ITEM; 1090e3d5408SPeter Wemm 1100e3d5408SPeter Wemm typedef void (*Menu_Hook) (struct tagMENU *); 1110e3d5408SPeter Wemm 1120e3d5408SPeter Wemm typedef struct tagMENU 113aae38d10SBaptiste Daroussin #if 1 /* not yet: !NCURSES_OPAQUE_MENU */ 1140e3d5408SPeter Wemm { 1150e3d5408SPeter Wemm short height; /* Nr. of chars high */ 1160e3d5408SPeter Wemm short width; /* Nr. of chars wide */ 1170e3d5408SPeter Wemm short rows; /* Nr. of items high */ 1180e3d5408SPeter Wemm short cols; /* Nr. of items wide */ 1190e3d5408SPeter Wemm short frows; /* Nr. of formatted items high */ 1200e3d5408SPeter Wemm short fcols; /* Nr. of formatted items wide */ 1210e3d5408SPeter Wemm short arows; /* Nr. of items high (actual) */ 1220e3d5408SPeter Wemm short namelen; /* Max. name length */ 1230e3d5408SPeter Wemm short desclen; /* Max. description length */ 1240e3d5408SPeter Wemm short marklen; /* Length of mark, if any */ 1250e3d5408SPeter Wemm short itemlen; /* Length of one item */ 1260e3d5408SPeter Wemm short spc_desc; /* Spacing for descriptor */ 1270e3d5408SPeter Wemm short spc_cols; /* Spacing for columns */ 1280e3d5408SPeter Wemm short spc_rows; /* Spacing for rows */ 1290e3d5408SPeter Wemm char *pattern; /* Buffer to store match chars */ 1300e3d5408SPeter Wemm short pindex; /* Index into pattern buffer */ 1310e3d5408SPeter Wemm WINDOW *win; /* Window containing menu */ 1320e3d5408SPeter Wemm WINDOW *sub; /* Subwindow for menu display */ 1330e3d5408SPeter Wemm WINDOW *userwin; /* User's window */ 1340e3d5408SPeter Wemm WINDOW *usersub; /* User's subwindow */ 1350e3d5408SPeter Wemm ITEM **items; /* array of items */ 1360e3d5408SPeter Wemm short nitems; /* Nr. of items in menu */ 1370e3d5408SPeter Wemm ITEM *curitem; /* Current item */ 1380e3d5408SPeter Wemm short toprow; /* Top row of menu */ 1390e3d5408SPeter Wemm chtype fore; /* Selection attribute */ 1400e3d5408SPeter Wemm chtype back; /* Nonselection attribute */ 1410e3d5408SPeter Wemm chtype grey; /* Inactive attribute */ 1420e3d5408SPeter Wemm unsigned char pad; /* Pad character */ 1430e3d5408SPeter Wemm 1440e3d5408SPeter Wemm Menu_Hook menuinit; /* User hooks */ 1450e3d5408SPeter Wemm Menu_Hook menuterm; 1460e3d5408SPeter Wemm Menu_Hook iteminit; 1470e3d5408SPeter Wemm Menu_Hook itemterm; 1480e3d5408SPeter Wemm 1490e3d5408SPeter Wemm void *userptr; /* Pointer to menus user data */ 1500e3d5408SPeter Wemm char *mark; /* Pointer to marker string */ 1510e3d5408SPeter Wemm 1520e3d5408SPeter Wemm Menu_Options opt; /* Menu options */ 1530e3d5408SPeter Wemm unsigned short status; /* Internal state of menu */ 154aae38d10SBaptiste Daroussin } 155aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */ 156aae38d10SBaptiste Daroussin MENU; 1570e3d5408SPeter Wemm 1580e3d5408SPeter Wemm /* Define keys */ 1590e3d5408SPeter Wemm 1600e3d5408SPeter Wemm #define REQ_LEFT_ITEM (KEY_MAX + 1) 1610e3d5408SPeter Wemm #define REQ_RIGHT_ITEM (KEY_MAX + 2) 1620e3d5408SPeter Wemm #define REQ_UP_ITEM (KEY_MAX + 3) 1630e3d5408SPeter Wemm #define REQ_DOWN_ITEM (KEY_MAX + 4) 1640e3d5408SPeter Wemm #define REQ_SCR_ULINE (KEY_MAX + 5) 1650e3d5408SPeter Wemm #define REQ_SCR_DLINE (KEY_MAX + 6) 1660e3d5408SPeter Wemm #define REQ_SCR_DPAGE (KEY_MAX + 7) 1670e3d5408SPeter Wemm #define REQ_SCR_UPAGE (KEY_MAX + 8) 1680e3d5408SPeter Wemm #define REQ_FIRST_ITEM (KEY_MAX + 9) 1690e3d5408SPeter Wemm #define REQ_LAST_ITEM (KEY_MAX + 10) 1700e3d5408SPeter Wemm #define REQ_NEXT_ITEM (KEY_MAX + 11) 1710e3d5408SPeter Wemm #define REQ_PREV_ITEM (KEY_MAX + 12) 1720e3d5408SPeter Wemm #define REQ_TOGGLE_ITEM (KEY_MAX + 13) 1730e3d5408SPeter Wemm #define REQ_CLEAR_PATTERN (KEY_MAX + 14) 1740e3d5408SPeter Wemm #define REQ_BACK_PATTERN (KEY_MAX + 15) 1750e3d5408SPeter Wemm #define REQ_NEXT_MATCH (KEY_MAX + 16) 1760e3d5408SPeter Wemm #define REQ_PREV_MATCH (KEY_MAX + 17) 1770e3d5408SPeter Wemm 1780e3d5408SPeter Wemm #define MIN_MENU_COMMAND (KEY_MAX + 1) 1790e3d5408SPeter Wemm #define MAX_MENU_COMMAND (KEY_MAX + 17) 1800e3d5408SPeter Wemm 1810e3d5408SPeter Wemm /* 1820e3d5408SPeter Wemm * Some AT&T code expects MAX_COMMAND to be out-of-band not 1830e3d5408SPeter Wemm * just for menu commands but for forms ones as well. 1840e3d5408SPeter Wemm */ 1850e3d5408SPeter Wemm #if defined(MAX_COMMAND) 1860e3d5408SPeter Wemm # if (MAX_MENU_COMMAND > MAX_COMMAND) 1870e3d5408SPeter Wemm # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND 1880e3d5408SPeter Wemm # elif (MAX_COMMAND != (KEY_MAX + 128)) 1890e3d5408SPeter Wemm # error Something is wrong -- MAX_COMMAND is already inconsistently defined. 1900e3d5408SPeter Wemm # endif 1910e3d5408SPeter Wemm #else 1920e3d5408SPeter Wemm # define MAX_COMMAND (KEY_MAX + 128) 1930e3d5408SPeter Wemm #endif 1940e3d5408SPeter Wemm 1950e3d5408SPeter Wemm /* --------- prototypes for libmenu functions ----------------------------- */ 1960e3d5408SPeter Wemm 197*7a656419SBaptiste Daroussin extern MENU_EXPORT(ITEM **) menu_items(const MENU *); 198*7a656419SBaptiste Daroussin extern MENU_EXPORT(ITEM *) current_item(const MENU *); 199*7a656419SBaptiste Daroussin extern MENU_EXPORT(ITEM *) new_item(const char *, const char *); 2000e3d5408SPeter Wemm 201*7a656419SBaptiste Daroussin extern MENU_EXPORT(MENU *) new_menu(ITEM **); 2020e3d5408SPeter Wemm 203*7a656419SBaptiste Daroussin extern MENU_EXPORT(Item_Options) item_opts(const ITEM *); 204*7a656419SBaptiste Daroussin extern MENU_EXPORT(Menu_Options) menu_opts(const MENU *); 2050e3d5408SPeter Wemm 206*7a656419SBaptiste Daroussin extern MENU_EXPORT(Menu_Hook) item_init(const MENU *); 207*7a656419SBaptiste Daroussin extern MENU_EXPORT(Menu_Hook) item_term(const MENU *); 208*7a656419SBaptiste Daroussin extern MENU_EXPORT(Menu_Hook) menu_init(const MENU *); 209*7a656419SBaptiste Daroussin extern MENU_EXPORT(Menu_Hook) menu_term(const MENU *); 2100e3d5408SPeter Wemm 211*7a656419SBaptiste Daroussin extern MENU_EXPORT(WINDOW *) menu_sub(const MENU *); 212*7a656419SBaptiste Daroussin extern MENU_EXPORT(WINDOW *) menu_win(const MENU *); 2130e3d5408SPeter Wemm 214*7a656419SBaptiste Daroussin extern MENU_EXPORT(const char *) item_description(const ITEM *); 215*7a656419SBaptiste Daroussin extern MENU_EXPORT(const char *) item_name(const ITEM *); 216*7a656419SBaptiste Daroussin extern MENU_EXPORT(const char *) menu_mark(const MENU *); 217*7a656419SBaptiste Daroussin extern MENU_EXPORT(const char *) menu_request_name(int); 2180e3d5408SPeter Wemm 219*7a656419SBaptiste Daroussin extern MENU_EXPORT(char *) menu_pattern(const MENU *); 2200e3d5408SPeter Wemm 221*7a656419SBaptiste Daroussin extern MENU_EXPORT(void *) menu_userptr(const MENU *); 222*7a656419SBaptiste Daroussin extern MENU_EXPORT(void *) item_userptr(const ITEM *); 2230e3d5408SPeter Wemm 224*7a656419SBaptiste Daroussin extern MENU_EXPORT(chtype) menu_back(const MENU *); 225*7a656419SBaptiste Daroussin extern MENU_EXPORT(chtype) menu_fore(const MENU *); 226*7a656419SBaptiste Daroussin extern MENU_EXPORT(chtype) menu_grey(const MENU *); 2270e3d5408SPeter Wemm 228*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) free_item(ITEM *); 229*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) free_menu(MENU *); 230*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) item_count(const MENU *); 231*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) item_index(const ITEM *); 232*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) item_opts_off(ITEM *, Item_Options); 233*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) item_opts_on(ITEM *, Item_Options); 234*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_driver(MENU *, int); 235*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_opts_off(MENU *, Menu_Options); 236*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_opts_on(MENU *, Menu_Options); 237*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_pad(const MENU *); 238*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) pos_menu_cursor(const MENU *); 239*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) post_menu(MENU *); 240*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) scale_menu(const MENU *, int *, int *); 241*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_current_item(MENU *menu, ITEM *item); 242*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_item_init(MENU *, Menu_Hook); 243*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_item_opts(ITEM *, Item_Options); 244*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_item_term(MENU *, Menu_Hook); 245*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_item_userptr(ITEM *, void *); 246*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_item_value(ITEM *, bool); 247*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_back(MENU *, chtype); 248*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_fore(MENU *, chtype); 249*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_format(MENU *, int, int); 250*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_grey(MENU *, chtype); 251*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_init(MENU *, Menu_Hook); 252*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_items(MENU *, ITEM **); 253*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_mark(MENU *, const char *); 254*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_opts(MENU *, Menu_Options); 255*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_pad(MENU *, int); 256*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_pattern(MENU *, const char *); 257*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_sub(MENU *, WINDOW *); 258*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_term(MENU *, Menu_Hook); 259*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_userptr(MENU *, void *); 260*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_win(MENU *, WINDOW *); 261*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_top_row(MENU *, int); 262*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) top_row(const MENU *); 263*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) unpost_menu(MENU *); 264*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_request_by_name(const char *); 265*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) set_menu_spacing(MENU *, int, int, int); 266*7a656419SBaptiste Daroussin extern MENU_EXPORT(int) menu_spacing(const MENU *, int *, int *, int *); 2670e3d5408SPeter Wemm 268*7a656419SBaptiste Daroussin extern MENU_EXPORT(bool) item_value(const ITEM *); 269*7a656419SBaptiste Daroussin extern MENU_EXPORT(bool) item_visible(const ITEM *); 2700e3d5408SPeter Wemm 271*7a656419SBaptiste Daroussin extern MENU_EXPORT(void) menu_format(const MENU *, int *, int *); 2720e3d5408SPeter Wemm 27306bfebdeSXin LI #if NCURSES_SP_FUNCS 274*7a656419SBaptiste Daroussin extern MENU_EXPORT(MENU *) NCURSES_SP_NAME(new_menu) (SCREEN *, ITEM **); 27506bfebdeSXin LI #endif 27606bfebdeSXin LI 2770e3d5408SPeter Wemm #ifdef __cplusplus 2780e3d5408SPeter Wemm } 2790e3d5408SPeter Wemm #endif 2800e3d5408SPeter Wemm 2810e3d5408SPeter Wemm #endif /* ETI_MENU */ 282