1 /****************************************************************************
2 * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
32 ****************************************************************************/
38 #define TEXT TEXT_ncurses
48 typedef int Menu_Options;
49 typedef int Item_Options;
52 #define O_ONEVALUE (0x01)
53 #define O_SHOWDESC (0x02)
54 #define O_ROWMAJOR (0x04)
55 #define O_IGNORECASE (0x08)
56 #define O_SHOWMATCH (0x10)
57 #define O_NONCYCLIC (0x20)
60 #define O_SELECTABLE (0x01)
65 unsigned short length;
68 typedef struct tagITEM
70 TEXT name; /* name of menu item */
71 TEXT description; /* description of item, optional in display */
72 struct tagMENU *imenu; /* Pointer to parent menu */
73 void *userptr; /* Pointer to user defined per item data */
74 Item_Options opt; /* Item options */
75 short index; /* Item number if connected to a menu */
76 short y; /* y and x location of item in menu */
78 bool value; /* Selection value */
80 struct tagITEM *left; /* neighbour items */
81 struct tagITEM *right;
87 typedef void (*Menu_Hook)(struct tagMENU *);
89 typedef struct tagMENU
91 short height; /* Nr. of chars high */
92 short width; /* Nr. of chars wide */
93 short rows; /* Nr. of items high */
94 short cols; /* Nr. of items wide */
95 short frows; /* Nr. of formatted items high */
96 short fcols; /* Nr. of formatted items wide */
97 short arows; /* Nr. of items high (actual) */
98 short namelen; /* Max. name length */
99 short desclen; /* Max. description length */
100 short marklen; /* Length of mark, if any */
101 short itemlen; /* Length of one item */
102 short spc_desc; /* Spacing for descriptor */
103 short spc_cols; /* Spacing for columns */
104 short spc_rows; /* Spacing for rows */
105 char *pattern; /* Buffer to store match chars */
106 short pindex; /* Index into pattern buffer */
107 WINDOW *win; /* Window containing menu */
108 WINDOW *sub; /* Subwindow for menu display */
109 WINDOW *userwin; /* User's window */
110 WINDOW *usersub; /* User's subwindow */
111 ITEM **items; /* array of items */
112 short nitems; /* Nr. of items in menu */
113 ITEM *curitem; /* Current item */
114 short toprow; /* Top row of menu */
115 chtype fore; /* Selection attribute */
116 chtype back; /* Nonselection attribute */
117 chtype grey; /* Inactive attribute */
118 unsigned char pad; /* Pad character */
120 Menu_Hook menuinit; /* User hooks */
125 void *userptr; /* Pointer to menus user data */
126 char *mark; /* Pointer to marker string */
128 Menu_Options opt; /* Menu options */
129 unsigned short status; /* Internal state of menu */
136 #define REQ_LEFT_ITEM (KEY_MAX + 1)
137 #define REQ_RIGHT_ITEM (KEY_MAX + 2)
138 #define REQ_UP_ITEM (KEY_MAX + 3)
139 #define REQ_DOWN_ITEM (KEY_MAX + 4)
140 #define REQ_SCR_ULINE (KEY_MAX + 5)
141 #define REQ_SCR_DLINE (KEY_MAX + 6)
142 #define REQ_SCR_DPAGE (KEY_MAX + 7)
143 #define REQ_SCR_UPAGE (KEY_MAX + 8)
144 #define REQ_FIRST_ITEM (KEY_MAX + 9)
145 #define REQ_LAST_ITEM (KEY_MAX + 10)
146 #define REQ_NEXT_ITEM (KEY_MAX + 11)
147 #define REQ_PREV_ITEM (KEY_MAX + 12)
148 #define REQ_TOGGLE_ITEM (KEY_MAX + 13)
149 #define REQ_CLEAR_PATTERN (KEY_MAX + 14)
150 #define REQ_BACK_PATTERN (KEY_MAX + 15)
151 #define REQ_NEXT_MATCH (KEY_MAX + 16)
152 #define REQ_PREV_MATCH (KEY_MAX + 17)
154 #define MIN_MENU_COMMAND (KEY_MAX + 1)
155 #define MAX_MENU_COMMAND (KEY_MAX + 17)
158 * Some AT&T code expects MAX_COMMAND to be out-of-band not
159 * just for menu commands but for forms ones as well.
161 #if defined(MAX_COMMAND)
162 # if (MAX_MENU_COMMAND > MAX_COMMAND)
163 # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
164 # elif (MAX_COMMAND != (KEY_MAX + 128))
165 # error Something is wrong -- MAX_COMMAND is already inconsistently defined.
168 # define MAX_COMMAND (KEY_MAX + 128)
172 /* --------- prototypes for libmenu functions ----------------------------- */
174 extern NCURSES_EXPORT(ITEM **) menu_items (const MENU *);
175 extern NCURSES_EXPORT(ITEM *) current_item (const MENU *);
176 extern NCURSES_EXPORT(ITEM *) new_item (const char *,const char *);
178 extern NCURSES_EXPORT(MENU *) new_menu (ITEM **);
180 extern NCURSES_EXPORT(Item_Options) item_opts (const ITEM *);
181 extern NCURSES_EXPORT(Menu_Options) menu_opts (const MENU *);
183 extern NCURSES_EXPORT(Menu_Hook) item_init (const MENU *);
184 extern NCURSES_EXPORT(Menu_Hook) item_term (const MENU *);
185 extern NCURSES_EXPORT(Menu_Hook) menu_init (const MENU *);
186 extern NCURSES_EXPORT(Menu_Hook) menu_term (const MENU *);
188 extern NCURSES_EXPORT(WINDOW *) menu_sub (const MENU *);
189 extern NCURSES_EXPORT(WINDOW *) menu_win (const MENU *);
191 extern NCURSES_EXPORT(const char *) item_description (const ITEM *);
192 extern NCURSES_EXPORT(const char *) item_name (const ITEM *);
193 extern NCURSES_EXPORT(const char *) menu_mark (const MENU *);
194 extern NCURSES_EXPORT(const char *) menu_request_name (int);
196 extern NCURSES_EXPORT(char *) menu_pattern (const MENU *);
198 extern NCURSES_EXPORT(void *) menu_userptr (const MENU *);
199 extern NCURSES_EXPORT(void *) item_userptr (const ITEM *);
201 extern NCURSES_EXPORT(chtype) menu_back (const MENU *);
202 extern NCURSES_EXPORT(chtype) menu_fore (const MENU *);
203 extern NCURSES_EXPORT(chtype) menu_grey (const MENU *);
205 extern NCURSES_EXPORT(int) free_item (ITEM *);
206 extern NCURSES_EXPORT(int) free_menu (MENU *);
207 extern NCURSES_EXPORT(int) item_count (const MENU *);
208 extern NCURSES_EXPORT(int) item_index (const ITEM *);
209 extern NCURSES_EXPORT(int) item_opts_off (ITEM *,Item_Options);
210 extern NCURSES_EXPORT(int) item_opts_on (ITEM *,Item_Options);
211 extern NCURSES_EXPORT(int) menu_driver (MENU *,int);
212 extern NCURSES_EXPORT(int) menu_opts_off (MENU *,Menu_Options);
213 extern NCURSES_EXPORT(int) menu_opts_on (MENU *,Menu_Options);
214 extern NCURSES_EXPORT(int) menu_pad (const MENU *);
215 extern NCURSES_EXPORT(int) pos_menu_cursor (const MENU *);
216 extern NCURSES_EXPORT(int) post_menu (MENU *);
217 extern NCURSES_EXPORT(int) scale_menu (const MENU *,int *,int *);
218 extern NCURSES_EXPORT(int) set_current_item (MENU *menu,ITEM *item);
219 extern NCURSES_EXPORT(int) set_item_init (MENU *,void(*)(MENU *));
220 extern NCURSES_EXPORT(int) set_item_opts (ITEM *,Item_Options);
221 extern NCURSES_EXPORT(int) set_item_term (MENU *,void(*)(MENU *));
222 extern NCURSES_EXPORT(int) set_item_userptr (ITEM *, void *);
223 extern NCURSES_EXPORT(int) set_item_value (ITEM *,bool);
224 extern NCURSES_EXPORT(int) set_menu_back (MENU *,chtype);
225 extern NCURSES_EXPORT(int) set_menu_fore (MENU *,chtype);
226 extern NCURSES_EXPORT(int) set_menu_format (MENU *,int,int);
227 extern NCURSES_EXPORT(int) set_menu_grey (MENU *,chtype);
228 extern NCURSES_EXPORT(int) set_menu_init (MENU *,void(*)(MENU *));
229 extern NCURSES_EXPORT(int) set_menu_items (MENU *,ITEM **);
230 extern NCURSES_EXPORT(int) set_menu_mark (MENU *, const char *);
231 extern NCURSES_EXPORT(int) set_menu_opts (MENU *,Menu_Options);
232 extern NCURSES_EXPORT(int) set_menu_pad (MENU *,int);
233 extern NCURSES_EXPORT(int) set_menu_pattern (MENU *,const char *);
234 extern NCURSES_EXPORT(int) set_menu_sub (MENU *,WINDOW *);
235 extern NCURSES_EXPORT(int) set_menu_term (MENU *,void(*)(MENU *));
236 extern NCURSES_EXPORT(int) set_menu_userptr (MENU *,void *);
237 extern NCURSES_EXPORT(int) set_menu_win (MENU *,WINDOW *);
238 extern NCURSES_EXPORT(int) set_top_row (MENU *,int);
239 extern NCURSES_EXPORT(int) top_row (const MENU *);
240 extern NCURSES_EXPORT(int) unpost_menu (MENU *);
241 extern NCURSES_EXPORT(int) menu_request_by_name (const char *);
242 extern NCURSES_EXPORT(int) set_menu_spacing (MENU *,int,int,int);
243 extern NCURSES_EXPORT(int) menu_spacing (const MENU *,int *,int *,int *);
246 extern NCURSES_EXPORT(bool) item_value (const ITEM *);
247 extern NCURSES_EXPORT(bool) item_visible (const ITEM *);
249 extern NCURSES_EXPORT(void) menu_format (const MENU *,int *,int *);
255 #endif /* ETI_MENU */