]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/menu.h
ncurses 6.2 - patch 20200912
[ncurses.git] / menu / menu.h
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.25 2020/07/04 20:38:43 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 #if defined(BUILDING_MENU)
51 # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_EXPORT
52 #else
53 # define MENU_IMPEXP NCURSES_EXPORT_GENERAL_IMPORT
54 #endif
55
56 #define MENU_WRAPPED_VAR(type,name) extern MENU_IMPEXP type NCURSES_PUBLIC_VAR(name)(void)
57
58 #define MENU_EXPORT(type) MENU_IMPEXP type NCURSES_API
59 #define MENU_EXPORT_VAR(type) MENU_IMPEXP type
60
61 typedef int Menu_Options;
62 typedef int Item_Options;
63
64 /* Menu options: */
65 #define O_ONEVALUE      (0x01)
66 #define O_SHOWDESC      (0x02)
67 #define O_ROWMAJOR      (0x04)
68 #define O_IGNORECASE    (0x08)
69 #define O_SHOWMATCH     (0x10)
70 #define O_NONCYCLIC     (0x20)
71 #define O_MOUSE_MENU    (0x40)
72
73 /* Item options: */
74 #define O_SELECTABLE    (0x01)
75
76 #if !NCURSES_OPAQUE_MENU
77 typedef struct
78 {
79   const char* str;
80   unsigned short length;
81 } TEXT;
82 #endif /* !NCURSES_OPAQUE_MENU */
83
84 struct tagMENU;
85
86 typedef struct tagITEM 
87 #if !NCURSES_OPAQUE_MENU
88 {
89   TEXT           name;        /* name of menu item                         */
90   TEXT           description; /* description of item, optional in display  */ 
91   struct tagMENU *imenu;      /* Pointer to parent menu                    */
92   void           *userptr;    /* Pointer to user defined per item data     */ 
93   Item_Options   opt;         /* Item options                              */ 
94   short          index;       /* Item number if connected to a menu        */
95   short          y;           /* y and x location of item in menu          */
96   short          x;
97   bool           value;       /* Selection value                           */
98                              
99   struct tagITEM *left;       /* neighbor items                            */
100   struct tagITEM *right;
101   struct tagITEM *up;
102   struct tagITEM *down;
103
104 }
105 #endif /* !NCURSES_OPAQUE_MENU */
106 ITEM;
107
108 typedef void (*Menu_Hook)(struct tagMENU *);
109
110 typedef struct tagMENU 
111 #if 1                                   /* not yet: !NCURSES_OPAQUE_MENU   */
112 {
113   short          height;                /* Nr. of chars high               */
114   short          width;                 /* Nr. of chars wide               */
115   short          rows;                  /* Nr. of items high               */
116   short          cols;                  /* Nr. of items wide               */
117   short          frows;                 /* Nr. of formatted items high     */
118   short          fcols;                 /* Nr. of formatted items wide     */
119   short          arows;                 /* Nr. of items high (actual)      */
120   short          namelen;               /* Max. name length                */
121   short          desclen;               /* Max. description length         */
122   short          marklen;               /* Length of mark, if any          */
123   short          itemlen;               /* Length of one item              */
124   short          spc_desc;              /* Spacing for descriptor          */
125   short          spc_cols;              /* Spacing for columns             */
126   short          spc_rows;              /* Spacing for rows                */ 
127   char          *pattern;               /* Buffer to store match chars     */
128   short          pindex;                /* Index into pattern buffer       */
129   WINDOW        *win;                   /* Window containing menu          */
130   WINDOW        *sub;                   /* Subwindow for menu display      */
131   WINDOW        *userwin;               /* User's window                   */
132   WINDOW        *usersub;               /* User's subwindow                */
133   ITEM          **items;                /* array of items                  */ 
134   short          nitems;                /* Nr. of items in menu            */
135   ITEM          *curitem;               /* Current item                    */
136   short          toprow;                /* Top row of menu                 */
137   chtype         fore;                  /* Selection attribute             */
138   chtype         back;                  /* Nonselection attribute          */
139   chtype         grey;                  /* Inactive attribute              */
140   unsigned char  pad;                   /* Pad character                   */
141
142   Menu_Hook      menuinit;              /* User hooks                      */
143   Menu_Hook      menuterm;
144   Menu_Hook      iteminit;
145   Menu_Hook      itemterm;
146
147   void          *userptr;               /* Pointer to menus user data      */
148   char          *mark;                  /* Pointer to marker string        */
149
150   Menu_Options   opt;                   /* Menu options                    */
151   unsigned short status;                /* Internal state of menu          */
152 }
153 #endif /* !NCURSES_OPAQUE_MENU */
154 MENU;
155
156
157 /* Define keys */
158
159 #define REQ_LEFT_ITEM           (KEY_MAX + 1)
160 #define REQ_RIGHT_ITEM          (KEY_MAX + 2)
161 #define REQ_UP_ITEM             (KEY_MAX + 3)
162 #define REQ_DOWN_ITEM           (KEY_MAX + 4)
163 #define REQ_SCR_ULINE           (KEY_MAX + 5)
164 #define REQ_SCR_DLINE           (KEY_MAX + 6)
165 #define REQ_SCR_DPAGE           (KEY_MAX + 7)
166 #define REQ_SCR_UPAGE           (KEY_MAX + 8)
167 #define REQ_FIRST_ITEM          (KEY_MAX + 9)
168 #define REQ_LAST_ITEM           (KEY_MAX + 10)
169 #define REQ_NEXT_ITEM           (KEY_MAX + 11)
170 #define REQ_PREV_ITEM           (KEY_MAX + 12)
171 #define REQ_TOGGLE_ITEM         (KEY_MAX + 13)
172 #define REQ_CLEAR_PATTERN       (KEY_MAX + 14)
173 #define REQ_BACK_PATTERN        (KEY_MAX + 15)
174 #define REQ_NEXT_MATCH          (KEY_MAX + 16)
175 #define REQ_PREV_MATCH          (KEY_MAX + 17)
176
177 #define MIN_MENU_COMMAND        (KEY_MAX + 1)
178 #define MAX_MENU_COMMAND        (KEY_MAX + 17)
179
180 /*
181  * Some AT&T code expects MAX_COMMAND to be out-of-band not
182  * just for menu commands but for forms ones as well.
183  */
184 #if defined(MAX_COMMAND)
185 #  if (MAX_MENU_COMMAND > MAX_COMMAND)
186 #    error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
187 #  elif (MAX_COMMAND != (KEY_MAX + 128))
188 #    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
189 #  endif
190 #else
191 #  define MAX_COMMAND (KEY_MAX + 128)
192 #endif
193
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
269 extern MENU_EXPORT(bool)        item_value (const ITEM *);
270 extern MENU_EXPORT(bool)        item_visible (const ITEM *);
271
272 extern MENU_EXPORT(void)        menu_format (const MENU *,int *,int *);
273
274 #if NCURSES_SP_FUNCS
275 extern MENU_EXPORT(MENU *)      NCURSES_SP_NAME(new_menu) (SCREEN*, ITEM **);
276 #endif
277
278 #ifdef __cplusplus
279   }
280 #endif
281
282 #endif /* ETI_MENU */