menu.h revision 1.9 1 /* $NetBSD: menu.h,v 1.9 2000/05/11 14:01:28 blymn Exp $ */
2
3 /*-
4 * Copyright (c) 1998-1999 Brett Lymn (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software withough specific prior written permission
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 *
27 */
28
29 #ifndef _MENU_H_
30 #define _MENU_H_
31
32 #include <curses.h>
33 #include <eti.h>
34
35 /* requests for the menu_driver call */
36 #define REQ_BASE_NUM (0x100)
37 #define REQ_LEFT_ITEM (0x101)
38 #define REQ_RIGHT_ITEM (0x102)
39 #define REQ_UP_ITEM (0x103)
40 #define REQ_DOWN_ITEM (0x104)
41 #define REQ_SCR_ULINE (0x105)
42 #define REQ_SCR_DLINE (0x106)
43 #define REQ_SCR_DPAGE (0x107)
44 #define REQ_SCR_UPAGE (0x108)
45 #define REQ_FIRST_ITEM (0x109)
46 #define REQ_LAST_ITEM (0x10a)
47 #define REQ_NEXT_ITEM (0x10b)
48 #define REQ_PREV_ITEM (0x10c)
49 #define REQ_TOGGLE_ITEM (0x10d)
50 #define REQ_CLEAR_PATTERN (0x10e)
51 #define REQ_BACK_PATTERN (0x10f)
52 #define REQ_NEXT_MATCH (0x110)
53 #define REQ_PREV_MATCH (0x111)
54
55 #define MAX_COMMAND (0x111) /* last menu driver request - for application
56 defined commands */
57
58 /* Menu options */
59 typedef unsigned int OPTIONS;
60
61 /* and the values they can have */
62 #define O_ONEVALUE (0x1)
63 #define O_SHOWDESC (0x2)
64 #define O_ROWMAJOR (0x4)
65 #define O_IGNORECASE (0x8)
66 #define O_SHOWMATCH (0x10)
67 #define O_NONCYCLIC (0x20)
68 #define O_SELECTABLE (0x40)
69
70 typedef struct __menu_str {
71 char *string;
72 int length;
73 } MENU_STR;
74
75 typedef struct __menu MENU;
76 typedef struct __item ITEM;
77
78 typedef void (*Menu_Hook) (MENU *);
79
80 struct __item {
81 MENU_STR name;
82 MENU_STR description;
83 char *userptr;
84 int visible; /* set if item is visible */
85 int selected; /* set if item has been selected */
86 int row; /* menu row this item is on */
87 int col; /* menu column this item is on */
88 OPTIONS opts;
89 MENU *parent; /* menu this item is bound to */
90 int index; /* index number for this item, if attached */
91 /* The following are the item's neighbours - makes menu
92 navigation easier */
93 ITEM *left;
94 ITEM *right;
95 ITEM *up;
96 ITEM *down;
97 };
98
99 struct __menu {
100 int rows; /* max number of rows to be displayed */
101 int cols; /* max number of columns to be displayed */
102 int item_rows; /* number of item rows we have */
103 int item_cols; /* number of item columns we have */
104 int cur_row; /* current cursor row */
105 int cur_col; /* current cursor column */
106 MENU_STR mark; /* menu mark string */
107 MENU_STR unmark; /* menu unmark string */
108 OPTIONS opts; /* options for the menu */
109 char *pattern; /* the pattern buffer */
110 int plen; /* pattern buffer length */
111 int match_len; /* length of pattern matched */
112 int posted; /* set if menu is posted */
113 attr_t fore; /* menu foreground */
114 attr_t back; /* menu background */
115 attr_t grey; /* greyed out (nonselectable) menu item */
116 int pad; /* filler char between name and description */
117 char *userptr;
118 int top_row; /* the row that is at the top of the menu */
119 int max_item_width; /* widest item */
120 int col_width; /* width of the menu columns - this is not always
121 the same as the widest item */
122 int item_count; /* number of items attached */
123 ITEM **items; /* items associated with this menu */
124 int cur_item; /* item cursor is currently positioned at */
125 int in_init; /* set when processing an init or term function call */
126 Menu_Hook menu_init; /* call this when menu is posted */
127 Menu_Hook menu_term; /* call this when menu is unposted */
128 Menu_Hook item_init; /* call this when menu posted & after
129 current item changes */
130 Menu_Hook item_term; /* call this when menu unposted & just
131 before current item changes */
132 WINDOW *menu_win; /* the menu window */
133 WINDOW *menu_subwin; /* the menu subwindow */
134 int we_created;
135 };
136
137
138 /* Public function prototypes. */
139 __BEGIN_DECLS
140 int menu_driver(MENU *, int);
141 int scale_menu(MENU *, int *, int *);
142 int set_top_row(MENU *, int);
143 int pos_menu_cursor(MENU *);
144 int top_row(MENU *);
145
146 int free_menu(MENU *);
147 char menu_back(MENU *);
148 char menu_fore(MENU *);
149 void menu_format(MENU *, int *, int *);
150 char menu_grey(MENU *);
151 Menu_Hook menu_init(MENU *);
152 char *menu_mark(MENU *);
153 OPTIONS menu_opts(MENU *);
154 int menu_opts_off(MENU *, OPTIONS);
155 int menu_opts_on(MENU *, OPTIONS);
156 int menu_pad(MENU *);
157 char *menu_pattern(MENU *);
158 WINDOW *menu_sub(MENU *);
159 Menu_Hook menu_term(MENU *);
160 char *menu_unmark (MENU *);
161 char *menu_userptr(MENU *);
162 WINDOW *menu_win(MENU *);
163 MENU *new_menu(ITEM **);
164 int post_menu(MENU *);
165 int set_menu_back(MENU *, attr_t);
166 int set_menu_fore(MENU *, attr_t);
167 int set_menu_format(MENU *, int, int);
168 int set_menu_grey(MENU *, attr_t);
169 int set_menu_init(MENU *, Menu_Hook);
170 int set_menu_items(MENU *, ITEM **);
171 int set_menu_mark(MENU *, char *);
172 int set_menu_opts(MENU *, OPTIONS);
173 int set_menu_pad(MENU *, int);
174 int set_menu_pattern(MENU *, char *);
175 int set_menu_sub(MENU *, WINDOW *);
176 int set_menu_term(MENU *, Menu_Hook);
177 int set_menu_unmark(MENU *, char *);
178 int set_menu_userptr(MENU *, char *);
179 int set_menu_win(MENU *, WINDOW *);
180 int unpost_menu(MENU *);
181
182 ITEM *current_item(MENU *);
183 int free_item(ITEM *);
184 int item_count(MENU *);
185 char *item_description(ITEM *);
186 int item_index(ITEM *);
187 Menu_Hook item_init(MENU *);
188 char *item_name(ITEM *);
189 OPTIONS item_opts(ITEM *);
190 int item_opts_off(ITEM *, OPTIONS);
191 int item_opts_on(ITEM *, OPTIONS);
192 Menu_Hook item_term(MENU *);
193 char *item_userptr(ITEM *);
194 int item_value(ITEM *);
195 int item_visible(ITEM *);
196 ITEM **menu_items(MENU *);
197 ITEM *new_item(char *, char *);
198 int set_current_item(MENU *, ITEM *);
199 int set_item_init(MENU *, Menu_Hook);
200 int set_item_opts(ITEM *, OPTIONS);
201 int set_item_term(MENU *, Menu_Hook);
202 int set_item_userptr(ITEM *, char *);
203 int set_item_value(ITEM *, int);
204
205 __END_DECLS
206
207 #endif /* !_MENU_H_ */
208