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