xref: /freebsd/contrib/ncurses/menu/menu.h (revision e18651243efbc1fe285af34e4937fd697612f1c7)
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.24 2020/02/02 23:34:34 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 #endif
49 
50 typedef int Menu_Options;
51 typedef int Item_Options;
52 
53 /* Menu options: */
54 #define O_ONEVALUE      (0x01)
55 #define O_SHOWDESC      (0x02)
56 #define O_ROWMAJOR      (0x04)
57 #define O_IGNORECASE    (0x08)
58 #define O_SHOWMATCH     (0x10)
59 #define O_NONCYCLIC     (0x20)
60 #define O_MOUSE_MENU    (0x40)
61 
62 /* Item options: */
63 #define O_SELECTABLE    (0x01)
64 
65 #if !NCURSES_OPAQUE_MENU
66 typedef struct
67 {
68   const char* str;
69   unsigned short length;
70 } TEXT;
71 #endif /* !NCURSES_OPAQUE_MENU */
72 
73 struct tagMENU;
74 
75 typedef struct tagITEM
76 #if !NCURSES_OPAQUE_MENU
77 {
78   TEXT           name;        /* name of menu item                         */
79   TEXT           description; /* description of item, optional in display  */
80   struct tagMENU *imenu;      /* Pointer to parent menu                    */
81   void           *userptr;    /* Pointer to user defined per item data     */
82   Item_Options   opt;         /* Item options                              */
83   short          index;       /* Item number if connected to a menu        */
84   short          y;           /* y and x location of item in menu          */
85   short          x;
86   bool           value;       /* Selection value                           */
87 
88   struct tagITEM *left;       /* neighbor items                            */
89   struct tagITEM *right;
90   struct tagITEM *up;
91   struct tagITEM *down;
92 
93 }
94 #endif /* !NCURSES_OPAQUE_MENU */
95 ITEM;
96 
97 typedef void (*Menu_Hook)(struct tagMENU *);
98 
99 typedef struct tagMENU
100 #if 1					/* not yet: !NCURSES_OPAQUE_MENU   */
101 {
102   short          height;                /* Nr. of chars high               */
103   short          width;                 /* Nr. of chars wide               */
104   short          rows;                  /* Nr. of items high               */
105   short          cols;                  /* Nr. of items wide               */
106   short          frows;                 /* Nr. of formatted items high     */
107   short          fcols;                 /* Nr. of formatted items wide     */
108   short          arows;                 /* Nr. of items high (actual)      */
109   short          namelen;               /* Max. name length                */
110   short          desclen;               /* Max. description length         */
111   short          marklen;               /* Length of mark, if any          */
112   short          itemlen;               /* Length of one item              */
113   short          spc_desc;              /* Spacing for descriptor          */
114   short          spc_cols;              /* Spacing for columns             */
115   short          spc_rows;              /* Spacing for rows                */
116   char          *pattern;               /* Buffer to store match chars     */
117   short          pindex;                /* Index into pattern buffer       */
118   WINDOW        *win;                   /* Window containing menu          */
119   WINDOW        *sub;                   /* Subwindow for menu display      */
120   WINDOW        *userwin;               /* User's window                   */
121   WINDOW        *usersub;               /* User's subwindow                */
122   ITEM          **items;                /* array of items                  */
123   short          nitems;                /* Nr. of items in menu            */
124   ITEM          *curitem;               /* Current item                    */
125   short          toprow;                /* Top row of menu                 */
126   chtype         fore;                  /* Selection attribute             */
127   chtype         back;                  /* Nonselection attribute          */
128   chtype         grey;                  /* Inactive attribute              */
129   unsigned char  pad;                   /* Pad character                   */
130 
131   Menu_Hook      menuinit;              /* User hooks                      */
132   Menu_Hook      menuterm;
133   Menu_Hook      iteminit;
134   Menu_Hook      itemterm;
135 
136   void          *userptr;               /* Pointer to menus user data      */
137   char          *mark;                  /* Pointer to marker string        */
138 
139   Menu_Options   opt;                   /* Menu options                    */
140   unsigned short status;                /* Internal state of menu          */
141 }
142 #endif /* !NCURSES_OPAQUE_MENU */
143 MENU;
144 
145 
146 /* Define keys */
147 
148 #define REQ_LEFT_ITEM           (KEY_MAX + 1)
149 #define REQ_RIGHT_ITEM          (KEY_MAX + 2)
150 #define REQ_UP_ITEM             (KEY_MAX + 3)
151 #define REQ_DOWN_ITEM           (KEY_MAX + 4)
152 #define REQ_SCR_ULINE           (KEY_MAX + 5)
153 #define REQ_SCR_DLINE           (KEY_MAX + 6)
154 #define REQ_SCR_DPAGE           (KEY_MAX + 7)
155 #define REQ_SCR_UPAGE           (KEY_MAX + 8)
156 #define REQ_FIRST_ITEM          (KEY_MAX + 9)
157 #define REQ_LAST_ITEM           (KEY_MAX + 10)
158 #define REQ_NEXT_ITEM           (KEY_MAX + 11)
159 #define REQ_PREV_ITEM           (KEY_MAX + 12)
160 #define REQ_TOGGLE_ITEM         (KEY_MAX + 13)
161 #define REQ_CLEAR_PATTERN       (KEY_MAX + 14)
162 #define REQ_BACK_PATTERN        (KEY_MAX + 15)
163 #define REQ_NEXT_MATCH          (KEY_MAX + 16)
164 #define REQ_PREV_MATCH          (KEY_MAX + 17)
165 
166 #define MIN_MENU_COMMAND        (KEY_MAX + 1)
167 #define MAX_MENU_COMMAND        (KEY_MAX + 17)
168 
169 /*
170  * Some AT&T code expects MAX_COMMAND to be out-of-band not
171  * just for menu commands but for forms ones as well.
172  */
173 #if defined(MAX_COMMAND)
174 #  if (MAX_MENU_COMMAND > MAX_COMMAND)
175 #    error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
176 #  elif (MAX_COMMAND != (KEY_MAX + 128))
177 #    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
178 #  endif
179 #else
180 #  define MAX_COMMAND (KEY_MAX + 128)
181 #endif
182 
183 
184 /* --------- prototypes for libmenu functions ----------------------------- */
185 
186 extern NCURSES_EXPORT(ITEM **)	menu_items (const MENU *);
187 extern NCURSES_EXPORT(ITEM *)	current_item (const MENU *);
188 extern NCURSES_EXPORT(ITEM *)	new_item (const char *,const char *);
189 
190 extern NCURSES_EXPORT(MENU *)	new_menu (ITEM **);
191 
192 extern NCURSES_EXPORT(Item_Options)	item_opts (const ITEM *);
193 extern NCURSES_EXPORT(Menu_Options)	menu_opts (const MENU *);
194 
195 extern NCURSES_EXPORT(Menu_Hook)	item_init (const MENU *);
196 extern NCURSES_EXPORT(Menu_Hook)	item_term (const MENU *);
197 extern NCURSES_EXPORT(Menu_Hook)	menu_init (const MENU *);
198 extern NCURSES_EXPORT(Menu_Hook)	menu_term (const MENU *);
199 
200 extern NCURSES_EXPORT(WINDOW *)	menu_sub (const MENU *);
201 extern NCURSES_EXPORT(WINDOW *)	menu_win (const MENU *);
202 
203 extern NCURSES_EXPORT(const char *)	item_description (const ITEM *);
204 extern NCURSES_EXPORT(const char *)	item_name (const ITEM *);
205 extern NCURSES_EXPORT(const char *)	menu_mark (const MENU *);
206 extern NCURSES_EXPORT(const char *)	menu_request_name (int);
207 
208 extern NCURSES_EXPORT(char *)	menu_pattern (const MENU *);
209 
210 extern NCURSES_EXPORT(void *)	menu_userptr (const MENU *);
211 extern NCURSES_EXPORT(void *)	item_userptr (const ITEM *);
212 
213 extern NCURSES_EXPORT(chtype)	menu_back (const MENU *);
214 extern NCURSES_EXPORT(chtype)	menu_fore (const MENU *);
215 extern NCURSES_EXPORT(chtype)	menu_grey (const MENU *);
216 
217 extern NCURSES_EXPORT(int)	free_item (ITEM *);
218 extern NCURSES_EXPORT(int)	free_menu (MENU *);
219 extern NCURSES_EXPORT(int)	item_count (const MENU *);
220 extern NCURSES_EXPORT(int)	item_index (const ITEM *);
221 extern NCURSES_EXPORT(int)	item_opts_off (ITEM *,Item_Options);
222 extern NCURSES_EXPORT(int)	item_opts_on (ITEM *,Item_Options);
223 extern NCURSES_EXPORT(int)	menu_driver (MENU *,int);
224 extern NCURSES_EXPORT(int)	menu_opts_off (MENU *,Menu_Options);
225 extern NCURSES_EXPORT(int)	menu_opts_on (MENU *,Menu_Options);
226 extern NCURSES_EXPORT(int)	menu_pad (const MENU *);
227 extern NCURSES_EXPORT(int)	pos_menu_cursor (const MENU *);
228 extern NCURSES_EXPORT(int)	post_menu (MENU *);
229 extern NCURSES_EXPORT(int)	scale_menu (const MENU *,int *,int *);
230 extern NCURSES_EXPORT(int)	set_current_item (MENU *menu,ITEM *item);
231 extern NCURSES_EXPORT(int)	set_item_init (MENU *, Menu_Hook);
232 extern NCURSES_EXPORT(int)	set_item_opts (ITEM *,Item_Options);
233 extern NCURSES_EXPORT(int)	set_item_term (MENU *, Menu_Hook);
234 extern NCURSES_EXPORT(int)	set_item_userptr (ITEM *, void *);
235 extern NCURSES_EXPORT(int)	set_item_value (ITEM *,bool);
236 extern NCURSES_EXPORT(int)	set_menu_back (MENU *,chtype);
237 extern NCURSES_EXPORT(int)	set_menu_fore (MENU *,chtype);
238 extern NCURSES_EXPORT(int)	set_menu_format (MENU *,int,int);
239 extern NCURSES_EXPORT(int)	set_menu_grey (MENU *,chtype);
240 extern NCURSES_EXPORT(int)	set_menu_init (MENU *, Menu_Hook);
241 extern NCURSES_EXPORT(int)	set_menu_items (MENU *,ITEM **);
242 extern NCURSES_EXPORT(int)	set_menu_mark (MENU *, const char *);
243 extern NCURSES_EXPORT(int)	set_menu_opts (MENU *,Menu_Options);
244 extern NCURSES_EXPORT(int)	set_menu_pad (MENU *,int);
245 extern NCURSES_EXPORT(int)	set_menu_pattern (MENU *,const char *);
246 extern NCURSES_EXPORT(int)	set_menu_sub (MENU *,WINDOW *);
247 extern NCURSES_EXPORT(int)	set_menu_term (MENU *, Menu_Hook);
248 extern NCURSES_EXPORT(int)	set_menu_userptr (MENU *,void *);
249 extern NCURSES_EXPORT(int)	set_menu_win (MENU *,WINDOW *);
250 extern NCURSES_EXPORT(int)	set_top_row (MENU *,int);
251 extern NCURSES_EXPORT(int)	top_row (const MENU *);
252 extern NCURSES_EXPORT(int)	unpost_menu (MENU *);
253 extern NCURSES_EXPORT(int)	menu_request_by_name (const char *);
254 extern NCURSES_EXPORT(int)	set_menu_spacing (MENU *,int,int,int);
255 extern NCURSES_EXPORT(int)	menu_spacing (const MENU *,int *,int *,int *);
256 
257 
258 extern NCURSES_EXPORT(bool)	item_value (const ITEM *);
259 extern NCURSES_EXPORT(bool)	item_visible (const ITEM *);
260 
261 extern NCURSES_EXPORT(void)	menu_format (const MENU *,int *,int *);
262 
263 #if NCURSES_SP_FUNCS
264 extern NCURSES_EXPORT(MENU *)	NCURSES_SP_NAME(new_menu) (SCREEN*, ITEM **);
265 #endif
266 
267 #ifdef __cplusplus
268   }
269 #endif
270 
271 #endif /* ETI_MENU */
272