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