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