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