xref: /freebsd/contrib/ncurses/menu/menu.h (revision aae38d10b4eebf81c0942947e8b83a9bb8651d88)
10e3d5408SPeter Wemm /****************************************************************************
2*aae38d10SBaptiste Daroussin  * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
30e3d5408SPeter Wemm  *                                                                          *
40e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
50e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
60e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
70e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
80e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
90e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
100e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
110e3d5408SPeter Wemm  *                                                                          *
120e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
130e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
140e3d5408SPeter Wemm  *                                                                          *
150e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
160e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
170e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
180e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
190e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
200e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
210e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
220e3d5408SPeter Wemm  *                                                                          *
230e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
240e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
250e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
260e3d5408SPeter Wemm  * authorization.                                                           *
270e3d5408SPeter Wemm  ****************************************************************************/
280e3d5408SPeter Wemm 
290e3d5408SPeter Wemm /****************************************************************************
304a1a9510SRong-En Fan  *   Author:  Juergen Pfeifer, 1995,1997                                    *
310e3d5408SPeter Wemm  ****************************************************************************/
320e3d5408SPeter Wemm 
33*aae38d10SBaptiste Daroussin /* $Id: menu.h,v 1.23 2017/02/11 16:54:04 tom Exp $ */
344a1a9510SRong-En Fan 
350e3d5408SPeter Wemm #ifndef ETI_MENU
360e3d5408SPeter Wemm #define ETI_MENU
370e3d5408SPeter Wemm 
3818259542SPeter Wemm #ifdef AMIGA
3918259542SPeter Wemm #define TEXT TEXT_ncurses
4018259542SPeter Wemm #endif
4118259542SPeter Wemm 
420e3d5408SPeter Wemm #include <curses.h>
430e3d5408SPeter Wemm #include <eti.h>
440e3d5408SPeter Wemm 
450e3d5408SPeter Wemm #ifdef __cplusplus
460e3d5408SPeter Wemm extern "C" {
470e3d5408SPeter Wemm #endif
480e3d5408SPeter Wemm 
490e3d5408SPeter Wemm typedef int Menu_Options;
500e3d5408SPeter Wemm typedef int Item_Options;
510e3d5408SPeter Wemm 
520e3d5408SPeter Wemm /* Menu options: */
530e3d5408SPeter Wemm #define O_ONEVALUE      (0x01)
540e3d5408SPeter Wemm #define O_SHOWDESC      (0x02)
550e3d5408SPeter Wemm #define O_ROWMAJOR      (0x04)
560e3d5408SPeter Wemm #define O_IGNORECASE    (0x08)
570e3d5408SPeter Wemm #define O_SHOWMATCH     (0x10)
580e3d5408SPeter Wemm #define O_NONCYCLIC     (0x20)
59*aae38d10SBaptiste Daroussin #define O_MOUSE_MENU    (0x40)
600e3d5408SPeter Wemm 
610e3d5408SPeter Wemm /* Item options: */
620e3d5408SPeter Wemm #define O_SELECTABLE    (0x01)
630e3d5408SPeter Wemm 
64*aae38d10SBaptiste Daroussin #if !NCURSES_OPAQUE_MENU
650e3d5408SPeter Wemm typedef struct
660e3d5408SPeter Wemm {
670e3d5408SPeter Wemm   const char* str;
680e3d5408SPeter Wemm   unsigned short length;
690e3d5408SPeter Wemm } TEXT;
70*aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */
71*aae38d10SBaptiste Daroussin 
72*aae38d10SBaptiste Daroussin struct tagMENU;
730e3d5408SPeter Wemm 
740e3d5408SPeter Wemm typedef struct tagITEM
75*aae38d10SBaptiste Daroussin #if !NCURSES_OPAQUE_MENU
760e3d5408SPeter Wemm {
770e3d5408SPeter Wemm   TEXT           name;        /* name of menu item                         */
780e3d5408SPeter Wemm   TEXT           description; /* description of item, optional in display  */
790e3d5408SPeter Wemm   struct tagMENU *imenu;      /* Pointer to parent menu                    */
800e3d5408SPeter Wemm   void           *userptr;    /* Pointer to user defined per item data     */
810e3d5408SPeter Wemm   Item_Options   opt;         /* Item options                              */
820e3d5408SPeter Wemm   short          index;       /* Item number if connected to a menu        */
830e3d5408SPeter Wemm   short          y;           /* y and x location of item in menu          */
840e3d5408SPeter Wemm   short          x;
850e3d5408SPeter Wemm   bool           value;       /* Selection value                           */
860e3d5408SPeter Wemm 
874a1a9510SRong-En Fan   struct tagITEM *left;       /* neighbor items                            */
880e3d5408SPeter Wemm   struct tagITEM *right;
890e3d5408SPeter Wemm   struct tagITEM *up;
900e3d5408SPeter Wemm   struct tagITEM *down;
910e3d5408SPeter Wemm 
92*aae38d10SBaptiste Daroussin }
93*aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */
94*aae38d10SBaptiste Daroussin ITEM;
950e3d5408SPeter Wemm 
960e3d5408SPeter Wemm typedef void (*Menu_Hook)(struct tagMENU *);
970e3d5408SPeter Wemm 
980e3d5408SPeter Wemm typedef struct tagMENU
99*aae38d10SBaptiste Daroussin #if 1					/* not yet: !NCURSES_OPAQUE_MENU   */
1000e3d5408SPeter Wemm {
1010e3d5408SPeter Wemm   short          height;                /* Nr. of chars high               */
1020e3d5408SPeter Wemm   short          width;                 /* Nr. of chars wide               */
1030e3d5408SPeter Wemm   short          rows;                  /* Nr. of items high               */
1040e3d5408SPeter Wemm   short          cols;                  /* Nr. of items wide               */
1050e3d5408SPeter Wemm   short          frows;                 /* Nr. of formatted items high     */
1060e3d5408SPeter Wemm   short          fcols;                 /* Nr. of formatted items wide     */
1070e3d5408SPeter Wemm   short          arows;                 /* Nr. of items high (actual)      */
1080e3d5408SPeter Wemm   short          namelen;               /* Max. name length                */
1090e3d5408SPeter Wemm   short          desclen;               /* Max. description length         */
1100e3d5408SPeter Wemm   short          marklen;               /* Length of mark, if any          */
1110e3d5408SPeter Wemm   short          itemlen;               /* Length of one item              */
1120e3d5408SPeter Wemm   short          spc_desc;              /* Spacing for descriptor          */
1130e3d5408SPeter Wemm   short          spc_cols;              /* Spacing for columns             */
1140e3d5408SPeter Wemm   short          spc_rows;              /* Spacing for rows                */
1150e3d5408SPeter Wemm   char          *pattern;               /* Buffer to store match chars     */
1160e3d5408SPeter Wemm   short          pindex;                /* Index into pattern buffer       */
1170e3d5408SPeter Wemm   WINDOW        *win;                   /* Window containing menu          */
1180e3d5408SPeter Wemm   WINDOW        *sub;                   /* Subwindow for menu display      */
1190e3d5408SPeter Wemm   WINDOW        *userwin;               /* User's window                   */
1200e3d5408SPeter Wemm   WINDOW        *usersub;               /* User's subwindow                */
1210e3d5408SPeter Wemm   ITEM          **items;                /* array of items                  */
1220e3d5408SPeter Wemm   short          nitems;                /* Nr. of items in menu            */
1230e3d5408SPeter Wemm   ITEM          *curitem;               /* Current item                    */
1240e3d5408SPeter Wemm   short          toprow;                /* Top row of menu                 */
1250e3d5408SPeter Wemm   chtype         fore;                  /* Selection attribute             */
1260e3d5408SPeter Wemm   chtype         back;                  /* Nonselection attribute          */
1270e3d5408SPeter Wemm   chtype         grey;                  /* Inactive attribute              */
1280e3d5408SPeter Wemm   unsigned char  pad;                   /* Pad character                   */
1290e3d5408SPeter Wemm 
1300e3d5408SPeter Wemm   Menu_Hook      menuinit;              /* User hooks                      */
1310e3d5408SPeter Wemm   Menu_Hook      menuterm;
1320e3d5408SPeter Wemm   Menu_Hook      iteminit;
1330e3d5408SPeter Wemm   Menu_Hook      itemterm;
1340e3d5408SPeter Wemm 
1350e3d5408SPeter Wemm   void          *userptr;               /* Pointer to menus user data      */
1360e3d5408SPeter Wemm   char          *mark;                  /* Pointer to marker string        */
1370e3d5408SPeter Wemm 
1380e3d5408SPeter Wemm   Menu_Options   opt;                   /* Menu options                    */
1390e3d5408SPeter Wemm   unsigned short status;                /* Internal state of menu          */
140*aae38d10SBaptiste Daroussin }
141*aae38d10SBaptiste Daroussin #endif /* !NCURSES_OPAQUE_MENU */
142*aae38d10SBaptiste Daroussin MENU;
1430e3d5408SPeter Wemm 
1440e3d5408SPeter Wemm 
1450e3d5408SPeter Wemm /* Define keys */
1460e3d5408SPeter Wemm 
1470e3d5408SPeter Wemm #define REQ_LEFT_ITEM           (KEY_MAX + 1)
1480e3d5408SPeter Wemm #define REQ_RIGHT_ITEM          (KEY_MAX + 2)
1490e3d5408SPeter Wemm #define REQ_UP_ITEM             (KEY_MAX + 3)
1500e3d5408SPeter Wemm #define REQ_DOWN_ITEM           (KEY_MAX + 4)
1510e3d5408SPeter Wemm #define REQ_SCR_ULINE           (KEY_MAX + 5)
1520e3d5408SPeter Wemm #define REQ_SCR_DLINE           (KEY_MAX + 6)
1530e3d5408SPeter Wemm #define REQ_SCR_DPAGE           (KEY_MAX + 7)
1540e3d5408SPeter Wemm #define REQ_SCR_UPAGE           (KEY_MAX + 8)
1550e3d5408SPeter Wemm #define REQ_FIRST_ITEM          (KEY_MAX + 9)
1560e3d5408SPeter Wemm #define REQ_LAST_ITEM           (KEY_MAX + 10)
1570e3d5408SPeter Wemm #define REQ_NEXT_ITEM           (KEY_MAX + 11)
1580e3d5408SPeter Wemm #define REQ_PREV_ITEM           (KEY_MAX + 12)
1590e3d5408SPeter Wemm #define REQ_TOGGLE_ITEM         (KEY_MAX + 13)
1600e3d5408SPeter Wemm #define REQ_CLEAR_PATTERN       (KEY_MAX + 14)
1610e3d5408SPeter Wemm #define REQ_BACK_PATTERN        (KEY_MAX + 15)
1620e3d5408SPeter Wemm #define REQ_NEXT_MATCH          (KEY_MAX + 16)
1630e3d5408SPeter Wemm #define REQ_PREV_MATCH          (KEY_MAX + 17)
1640e3d5408SPeter Wemm 
1650e3d5408SPeter Wemm #define MIN_MENU_COMMAND        (KEY_MAX + 1)
1660e3d5408SPeter Wemm #define MAX_MENU_COMMAND        (KEY_MAX + 17)
1670e3d5408SPeter Wemm 
1680e3d5408SPeter Wemm /*
1690e3d5408SPeter Wemm  * Some AT&T code expects MAX_COMMAND to be out-of-band not
1700e3d5408SPeter Wemm  * just for menu commands but for forms ones as well.
1710e3d5408SPeter Wemm  */
1720e3d5408SPeter Wemm #if defined(MAX_COMMAND)
1730e3d5408SPeter Wemm #  if (MAX_MENU_COMMAND > MAX_COMMAND)
1740e3d5408SPeter Wemm #    error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
1750e3d5408SPeter Wemm #  elif (MAX_COMMAND != (KEY_MAX + 128))
1760e3d5408SPeter Wemm #    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
1770e3d5408SPeter Wemm #  endif
1780e3d5408SPeter Wemm #else
1790e3d5408SPeter Wemm #  define MAX_COMMAND (KEY_MAX + 128)
1800e3d5408SPeter Wemm #endif
1810e3d5408SPeter Wemm 
1820e3d5408SPeter Wemm 
1830e3d5408SPeter Wemm /* --------- prototypes for libmenu functions ----------------------------- */
1840e3d5408SPeter Wemm 
1857a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM **)	menu_items (const MENU *);
1867a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM *)	current_item (const MENU *);
1877a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM *)	new_item (const char *,const char *);
1880e3d5408SPeter Wemm 
1897a69bbfbSPeter Wemm extern NCURSES_EXPORT(MENU *)	new_menu (ITEM **);
1900e3d5408SPeter Wemm 
1917a69bbfbSPeter Wemm extern NCURSES_EXPORT(Item_Options)	item_opts (const ITEM *);
1927a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Options)	menu_opts (const MENU *);
1930e3d5408SPeter Wemm 
1947a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	item_init (const MENU *);
1957a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	item_term (const MENU *);
1967a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	menu_init (const MENU *);
1977a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	menu_term (const MENU *);
1980e3d5408SPeter Wemm 
1997a69bbfbSPeter Wemm extern NCURSES_EXPORT(WINDOW *)	menu_sub (const MENU *);
2007a69bbfbSPeter Wemm extern NCURSES_EXPORT(WINDOW *)	menu_win (const MENU *);
2010e3d5408SPeter Wemm 
2027a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	item_description (const ITEM *);
2037a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	item_name (const ITEM *);
2047a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	menu_mark (const MENU *);
2057a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	menu_request_name (int);
2060e3d5408SPeter Wemm 
2077a69bbfbSPeter Wemm extern NCURSES_EXPORT(char *)	menu_pattern (const MENU *);
2080e3d5408SPeter Wemm 
2097a69bbfbSPeter Wemm extern NCURSES_EXPORT(void *)	menu_userptr (const MENU *);
2107a69bbfbSPeter Wemm extern NCURSES_EXPORT(void *)	item_userptr (const ITEM *);
2110e3d5408SPeter Wemm 
2127a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_back (const MENU *);
2137a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_fore (const MENU *);
2147a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_grey (const MENU *);
2150e3d5408SPeter Wemm 
2167a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	free_item (ITEM *);
2177a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	free_menu (MENU *);
2187a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_count (const MENU *);
2197a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_index (const ITEM *);
2207a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_opts_off (ITEM *,Item_Options);
2217a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_opts_on (ITEM *,Item_Options);
2227a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_driver (MENU *,int);
2237a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_opts_off (MENU *,Menu_Options);
2247a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_opts_on (MENU *,Menu_Options);
2257a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_pad (const MENU *);
2267a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	pos_menu_cursor (const MENU *);
2277a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	post_menu (MENU *);
2287a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	scale_menu (const MENU *,int *,int *);
2297a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_current_item (MENU *menu,ITEM *item);
2305ca44d1cSRong-En Fan extern NCURSES_EXPORT(int)	set_item_init (MENU *, Menu_Hook);
2317a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_opts (ITEM *,Item_Options);
2325ca44d1cSRong-En Fan extern NCURSES_EXPORT(int)	set_item_term (MENU *, Menu_Hook);
2337a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_userptr (ITEM *, void *);
2347a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_value (ITEM *,bool);
2357a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_back (MENU *,chtype);
2367a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_fore (MENU *,chtype);
2377a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_format (MENU *,int,int);
2387a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_grey (MENU *,chtype);
2395ca44d1cSRong-En Fan extern NCURSES_EXPORT(int)	set_menu_init (MENU *, Menu_Hook);
2407a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_items (MENU *,ITEM **);
2417a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_mark (MENU *, const char *);
2427a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_opts (MENU *,Menu_Options);
2437a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_pad (MENU *,int);
2447a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_pattern (MENU *,const char *);
2457a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_sub (MENU *,WINDOW *);
2465ca44d1cSRong-En Fan extern NCURSES_EXPORT(int)	set_menu_term (MENU *, Menu_Hook);
2477a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_userptr (MENU *,void *);
2487a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_win (MENU *,WINDOW *);
2497a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_top_row (MENU *,int);
2507a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	top_row (const MENU *);
2517a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	unpost_menu (MENU *);
2527a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_request_by_name (const char *);
2537a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_spacing (MENU *,int,int,int);
2547a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_spacing (const MENU *,int *,int *,int *);
2550e3d5408SPeter Wemm 
2560e3d5408SPeter Wemm 
2577a69bbfbSPeter Wemm extern NCURSES_EXPORT(bool)	item_value (const ITEM *);
2587a69bbfbSPeter Wemm extern NCURSES_EXPORT(bool)	item_visible (const ITEM *);
2590e3d5408SPeter Wemm 
2607a69bbfbSPeter Wemm extern NCURSES_EXPORT(void)	menu_format (const MENU *,int *,int *);
2610e3d5408SPeter Wemm 
26206bfebdeSXin LI #if NCURSES_SP_FUNCS
26306bfebdeSXin LI extern NCURSES_EXPORT(MENU *)	NCURSES_SP_NAME(new_menu) (SCREEN*, ITEM **);
26406bfebdeSXin LI #endif
26506bfebdeSXin LI 
2660e3d5408SPeter Wemm #ifdef __cplusplus
2670e3d5408SPeter Wemm   }
2680e3d5408SPeter Wemm #endif
2690e3d5408SPeter Wemm 
2700e3d5408SPeter Wemm #endif /* ETI_MENU */
271