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