xref: /freebsd/contrib/ncurses/menu/menu.h (revision 7a69bbfb278952228c9aa1eca241e65fcdef425e)
10e3d5408SPeter Wemm /****************************************************************************
27a69bbfbSPeter Wemm  * Copyright (c) 1998,2000 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 /****************************************************************************
300e3d5408SPeter Wemm  *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997            *
310e3d5408SPeter Wemm  ****************************************************************************/
320e3d5408SPeter Wemm 
330e3d5408SPeter Wemm #ifndef ETI_MENU
340e3d5408SPeter Wemm #define ETI_MENU
350e3d5408SPeter Wemm 
3618259542SPeter Wemm #ifdef AMIGA
3718259542SPeter Wemm #define TEXT TEXT_ncurses
3818259542SPeter Wemm #endif
3918259542SPeter Wemm 
400e3d5408SPeter Wemm #include <curses.h>
410e3d5408SPeter Wemm #include <eti.h>
420e3d5408SPeter Wemm 
430e3d5408SPeter Wemm #ifdef __cplusplus
440e3d5408SPeter Wemm extern "C" {
450e3d5408SPeter Wemm #endif
460e3d5408SPeter Wemm 
470e3d5408SPeter Wemm typedef int Menu_Options;
480e3d5408SPeter Wemm typedef int Item_Options;
490e3d5408SPeter Wemm 
500e3d5408SPeter Wemm /* Menu options: */
510e3d5408SPeter Wemm #define O_ONEVALUE      (0x01)
520e3d5408SPeter Wemm #define O_SHOWDESC      (0x02)
530e3d5408SPeter Wemm #define O_ROWMAJOR      (0x04)
540e3d5408SPeter Wemm #define O_IGNORECASE    (0x08)
550e3d5408SPeter Wemm #define O_SHOWMATCH     (0x10)
560e3d5408SPeter Wemm #define O_NONCYCLIC     (0x20)
570e3d5408SPeter Wemm 
580e3d5408SPeter Wemm /* Item options: */
590e3d5408SPeter Wemm #define O_SELECTABLE    (0x01)
600e3d5408SPeter Wemm 
610e3d5408SPeter Wemm typedef struct
620e3d5408SPeter Wemm {
630e3d5408SPeter Wemm   const char* str;
640e3d5408SPeter Wemm   unsigned short length;
650e3d5408SPeter Wemm } TEXT;
660e3d5408SPeter Wemm 
670e3d5408SPeter Wemm typedef struct tagITEM
680e3d5408SPeter Wemm {
690e3d5408SPeter Wemm   TEXT           name;        /* name of menu item                         */
700e3d5408SPeter Wemm   TEXT           description; /* description of item, optional in display  */
710e3d5408SPeter Wemm   struct tagMENU *imenu;      /* Pointer to parent menu                    */
720e3d5408SPeter Wemm   void           *userptr;    /* Pointer to user defined per item data     */
730e3d5408SPeter Wemm   Item_Options   opt;         /* Item options                              */
740e3d5408SPeter Wemm   short          index;       /* Item number if connected to a menu        */
750e3d5408SPeter Wemm   short          y;           /* y and x location of item in menu          */
760e3d5408SPeter Wemm   short          x;
770e3d5408SPeter Wemm   bool           value;       /* Selection value                           */
780e3d5408SPeter Wemm 
790e3d5408SPeter Wemm   struct tagITEM *left;       /* neighbour items                           */
800e3d5408SPeter Wemm   struct tagITEM *right;
810e3d5408SPeter Wemm   struct tagITEM *up;
820e3d5408SPeter Wemm   struct tagITEM *down;
830e3d5408SPeter Wemm 
840e3d5408SPeter Wemm } ITEM;
850e3d5408SPeter Wemm 
860e3d5408SPeter Wemm typedef void (*Menu_Hook)(struct tagMENU *);
870e3d5408SPeter Wemm 
880e3d5408SPeter Wemm typedef struct tagMENU
890e3d5408SPeter Wemm {
900e3d5408SPeter Wemm   short          height;                /* Nr. of chars high               */
910e3d5408SPeter Wemm   short          width;                 /* Nr. of chars wide               */
920e3d5408SPeter Wemm   short          rows;                  /* Nr. of items high               */
930e3d5408SPeter Wemm   short          cols;                  /* Nr. of items wide               */
940e3d5408SPeter Wemm   short          frows;                 /* Nr. of formatted items high     */
950e3d5408SPeter Wemm   short          fcols;                 /* Nr. of formatted items wide     */
960e3d5408SPeter Wemm   short          arows;                 /* Nr. of items high (actual)      */
970e3d5408SPeter Wemm   short          namelen;               /* Max. name length                */
980e3d5408SPeter Wemm   short          desclen;               /* Max. description length         */
990e3d5408SPeter Wemm   short          marklen;               /* Length of mark, if any          */
1000e3d5408SPeter Wemm   short          itemlen;               /* Length of one item              */
1010e3d5408SPeter Wemm   short          spc_desc;              /* Spacing for descriptor          */
1020e3d5408SPeter Wemm   short          spc_cols;              /* Spacing for columns             */
1030e3d5408SPeter Wemm   short          spc_rows;              /* Spacing for rows                */
1040e3d5408SPeter Wemm   char          *pattern;               /* Buffer to store match chars     */
1050e3d5408SPeter Wemm   short          pindex;                /* Index into pattern buffer       */
1060e3d5408SPeter Wemm   WINDOW        *win;                   /* Window containing menu          */
1070e3d5408SPeter Wemm   WINDOW        *sub;                   /* Subwindow for menu display      */
1080e3d5408SPeter Wemm   WINDOW        *userwin;               /* User's window                   */
1090e3d5408SPeter Wemm   WINDOW        *usersub;               /* User's subwindow                */
1100e3d5408SPeter Wemm   ITEM          **items;                /* array of items                  */
1110e3d5408SPeter Wemm   short          nitems;                /* Nr. of items in menu            */
1120e3d5408SPeter Wemm   ITEM          *curitem;               /* Current item                    */
1130e3d5408SPeter Wemm   short          toprow;                /* Top row of menu                 */
1140e3d5408SPeter Wemm   chtype         fore;                  /* Selection attribute             */
1150e3d5408SPeter Wemm   chtype         back;                  /* Nonselection attribute          */
1160e3d5408SPeter Wemm   chtype         grey;                  /* Inactive attribute              */
1170e3d5408SPeter Wemm   unsigned char  pad;                   /* Pad character                   */
1180e3d5408SPeter Wemm 
1190e3d5408SPeter Wemm   Menu_Hook      menuinit;              /* User hooks                      */
1200e3d5408SPeter Wemm   Menu_Hook      menuterm;
1210e3d5408SPeter Wemm   Menu_Hook      iteminit;
1220e3d5408SPeter Wemm   Menu_Hook      itemterm;
1230e3d5408SPeter Wemm 
1240e3d5408SPeter Wemm   void          *userptr;               /* Pointer to menus user data      */
1250e3d5408SPeter Wemm   char          *mark;                  /* Pointer to marker string        */
1260e3d5408SPeter Wemm 
1270e3d5408SPeter Wemm   Menu_Options   opt;                   /* Menu options                    */
1280e3d5408SPeter Wemm   unsigned short status;                /* Internal state of menu          */
1290e3d5408SPeter Wemm 
1300e3d5408SPeter Wemm } MENU;
1310e3d5408SPeter Wemm 
1320e3d5408SPeter Wemm 
1330e3d5408SPeter Wemm /* Define keys */
1340e3d5408SPeter Wemm 
1350e3d5408SPeter Wemm #define REQ_LEFT_ITEM           (KEY_MAX + 1)
1360e3d5408SPeter Wemm #define REQ_RIGHT_ITEM          (KEY_MAX + 2)
1370e3d5408SPeter Wemm #define REQ_UP_ITEM             (KEY_MAX + 3)
1380e3d5408SPeter Wemm #define REQ_DOWN_ITEM           (KEY_MAX + 4)
1390e3d5408SPeter Wemm #define REQ_SCR_ULINE           (KEY_MAX + 5)
1400e3d5408SPeter Wemm #define REQ_SCR_DLINE           (KEY_MAX + 6)
1410e3d5408SPeter Wemm #define REQ_SCR_DPAGE           (KEY_MAX + 7)
1420e3d5408SPeter Wemm #define REQ_SCR_UPAGE           (KEY_MAX + 8)
1430e3d5408SPeter Wemm #define REQ_FIRST_ITEM          (KEY_MAX + 9)
1440e3d5408SPeter Wemm #define REQ_LAST_ITEM           (KEY_MAX + 10)
1450e3d5408SPeter Wemm #define REQ_NEXT_ITEM           (KEY_MAX + 11)
1460e3d5408SPeter Wemm #define REQ_PREV_ITEM           (KEY_MAX + 12)
1470e3d5408SPeter Wemm #define REQ_TOGGLE_ITEM         (KEY_MAX + 13)
1480e3d5408SPeter Wemm #define REQ_CLEAR_PATTERN       (KEY_MAX + 14)
1490e3d5408SPeter Wemm #define REQ_BACK_PATTERN        (KEY_MAX + 15)
1500e3d5408SPeter Wemm #define REQ_NEXT_MATCH          (KEY_MAX + 16)
1510e3d5408SPeter Wemm #define REQ_PREV_MATCH          (KEY_MAX + 17)
1520e3d5408SPeter Wemm 
1530e3d5408SPeter Wemm #define MIN_MENU_COMMAND        (KEY_MAX + 1)
1540e3d5408SPeter Wemm #define MAX_MENU_COMMAND        (KEY_MAX + 17)
1550e3d5408SPeter Wemm 
1560e3d5408SPeter Wemm /*
1570e3d5408SPeter Wemm  * Some AT&T code expects MAX_COMMAND to be out-of-band not
1580e3d5408SPeter Wemm  * just for menu commands but for forms ones as well.
1590e3d5408SPeter Wemm  */
1600e3d5408SPeter Wemm #if defined(MAX_COMMAND)
1610e3d5408SPeter Wemm #  if (MAX_MENU_COMMAND > MAX_COMMAND)
1620e3d5408SPeter Wemm #    error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
1630e3d5408SPeter Wemm #  elif (MAX_COMMAND != (KEY_MAX + 128))
1640e3d5408SPeter Wemm #    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
1650e3d5408SPeter Wemm #  endif
1660e3d5408SPeter Wemm #else
1670e3d5408SPeter Wemm #  define MAX_COMMAND (KEY_MAX + 128)
1680e3d5408SPeter Wemm #endif
1690e3d5408SPeter Wemm 
1700e3d5408SPeter Wemm 
1710e3d5408SPeter Wemm /* --------- prototypes for libmenu functions ----------------------------- */
1720e3d5408SPeter Wemm 
1737a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM **)	menu_items (const MENU *);
1747a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM *)	current_item (const MENU *);
1757a69bbfbSPeter Wemm extern NCURSES_EXPORT(ITEM *)	new_item (const char *,const char *);
1760e3d5408SPeter Wemm 
1777a69bbfbSPeter Wemm extern NCURSES_EXPORT(MENU *)	new_menu (ITEM **);
1780e3d5408SPeter Wemm 
1797a69bbfbSPeter Wemm extern NCURSES_EXPORT(Item_Options)	item_opts (const ITEM *);
1807a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Options)	menu_opts (const MENU *);
1810e3d5408SPeter Wemm 
1827a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	item_init (const MENU *);
1837a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	item_term (const MENU *);
1847a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	menu_init (const MENU *);
1857a69bbfbSPeter Wemm extern NCURSES_EXPORT(Menu_Hook)	menu_term (const MENU *);
1860e3d5408SPeter Wemm 
1877a69bbfbSPeter Wemm extern NCURSES_EXPORT(WINDOW *)	menu_sub (const MENU *);
1887a69bbfbSPeter Wemm extern NCURSES_EXPORT(WINDOW *)	menu_win (const MENU *);
1890e3d5408SPeter Wemm 
1907a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	item_description (const ITEM *);
1917a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	item_name (const ITEM *);
1927a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	menu_mark (const MENU *);
1937a69bbfbSPeter Wemm extern NCURSES_EXPORT(const char *)	menu_request_name (int);
1940e3d5408SPeter Wemm 
1957a69bbfbSPeter Wemm extern NCURSES_EXPORT(char *)	menu_pattern (const MENU *);
1960e3d5408SPeter Wemm 
1977a69bbfbSPeter Wemm extern NCURSES_EXPORT(void *)	menu_userptr (const MENU *);
1987a69bbfbSPeter Wemm extern NCURSES_EXPORT(void *)	item_userptr (const ITEM *);
1990e3d5408SPeter Wemm 
2007a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_back (const MENU *);
2017a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_fore (const MENU *);
2027a69bbfbSPeter Wemm extern NCURSES_EXPORT(chtype)	menu_grey (const MENU *);
2030e3d5408SPeter Wemm 
2047a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	free_item (ITEM *);
2057a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	free_menu (MENU *);
2067a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_count (const MENU *);
2077a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_index (const ITEM *);
2087a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_opts_off (ITEM *,Item_Options);
2097a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	item_opts_on (ITEM *,Item_Options);
2107a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_driver (MENU *,int);
2117a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_opts_off (MENU *,Menu_Options);
2127a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_opts_on (MENU *,Menu_Options);
2137a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_pad (const MENU *);
2147a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	pos_menu_cursor (const MENU *);
2157a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	post_menu (MENU *);
2167a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	scale_menu (const MENU *,int *,int *);
2177a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_current_item (MENU *menu,ITEM *item);
2187a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_init (MENU *,void(*)(MENU *));
2197a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_opts (ITEM *,Item_Options);
2207a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_term (MENU *,void(*)(MENU *));
2217a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_userptr (ITEM *, void *);
2227a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_item_value (ITEM *,bool);
2237a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_back (MENU *,chtype);
2247a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_fore (MENU *,chtype);
2257a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_format (MENU *,int,int);
2267a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_grey (MENU *,chtype);
2277a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_init (MENU *,void(*)(MENU *));
2287a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_items (MENU *,ITEM **);
2297a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_mark (MENU *, const char *);
2307a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_opts (MENU *,Menu_Options);
2317a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_pad (MENU *,int);
2327a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_pattern (MENU *,const char *);
2337a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_sub (MENU *,WINDOW *);
2347a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_term (MENU *,void(*)(MENU *));
2357a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_userptr (MENU *,void *);
2367a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_win (MENU *,WINDOW *);
2377a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_top_row (MENU *,int);
2387a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	top_row (const MENU *);
2397a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	unpost_menu (MENU *);
2407a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_request_by_name (const char *);
2417a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	set_menu_spacing (MENU *,int,int,int);
2427a69bbfbSPeter Wemm extern NCURSES_EXPORT(int)	menu_spacing (const MENU *,int *,int *,int *);
2430e3d5408SPeter Wemm 
2440e3d5408SPeter Wemm 
2457a69bbfbSPeter Wemm extern NCURSES_EXPORT(bool)	item_value (const ITEM *);
2467a69bbfbSPeter Wemm extern NCURSES_EXPORT(bool)	item_visible (const ITEM *);
2470e3d5408SPeter Wemm 
2487a69bbfbSPeter Wemm extern NCURSES_EXPORT(void)	menu_format (const MENU *,int *,int *);
2490e3d5408SPeter Wemm 
2500e3d5408SPeter Wemm #ifdef __cplusplus
2510e3d5408SPeter Wemm   }
2520e3d5408SPeter Wemm #endif
2530e3d5408SPeter Wemm 
2540e3d5408SPeter Wemm #endif /* ETI_MENU */
255