root / lab4 / .minix-src / include / menu.h @ 13
History | View | Annotate | Download (7.21 KB)
1 |
/* $NetBSD: menu.h,v 1.13 2004/03/22 19:01:09 jdc Exp $ */
|
---|---|
2 |
|
3 |
/*-
|
4 |
* Copyright (c) 1998-1999 Brett Lymn (blymn@baea.com.au, brett_lymn@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 without 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 (KEY_MAX + 0x200) |
37 |
#define REQ_LEFT_ITEM (KEY_MAX + 0x201) |
38 |
#define REQ_RIGHT_ITEM (KEY_MAX + 0x202) |
39 |
#define REQ_UP_ITEM (KEY_MAX + 0x203) |
40 |
#define REQ_DOWN_ITEM (KEY_MAX + 0x204) |
41 |
#define REQ_SCR_ULINE (KEY_MAX + 0x205) |
42 |
#define REQ_SCR_DLINE (KEY_MAX + 0x206) |
43 |
#define REQ_SCR_DPAGE (KEY_MAX + 0x207) |
44 |
#define REQ_SCR_UPAGE (KEY_MAX + 0x208) |
45 |
#define REQ_FIRST_ITEM (KEY_MAX + 0x209) |
46 |
#define REQ_LAST_ITEM (KEY_MAX + 0x20a) |
47 |
#define REQ_NEXT_ITEM (KEY_MAX + 0x20b) |
48 |
#define REQ_PREV_ITEM (KEY_MAX + 0x20c) |
49 |
#define REQ_TOGGLE_ITEM (KEY_MAX + 0x20d) |
50 |
#define REQ_CLEAR_PATTERN (KEY_MAX + 0x20e) |
51 |
#define REQ_BACK_PATTERN (KEY_MAX + 0x20f) |
52 |
#define REQ_NEXT_MATCH (KEY_MAX + 0x210) |
53 |
#define REQ_PREV_MATCH (KEY_MAX + 0x211) |
54 |
|
55 |
#define MAX_COMMAND (KEY_MAX + 0x211) /* last menu driver request |
56 |
- for application defined
|
57 |
commands */
|
58 |
|
59 |
/* Menu options */
|
60 |
typedef unsigned int OPTIONS; |
61 |
|
62 |
/* and the values they can have */
|
63 |
#define O_ONEVALUE (0x1) |
64 |
#define O_SHOWDESC (0x2) |
65 |
#define O_ROWMAJOR (0x4) |
66 |
#define O_IGNORECASE (0x8) |
67 |
#define O_SHOWMATCH (0x10) |
68 |
#define O_NONCYCLIC (0x20) |
69 |
#define O_SELECTABLE (0x40) |
70 |
#define O_RADIO (0x80) |
71 |
|
72 |
typedef struct __menu_str { |
73 |
char *string;
|
74 |
int length;
|
75 |
} MENU_STR; |
76 |
|
77 |
typedef struct __menu MENU; |
78 |
typedef struct __item ITEM; |
79 |
|
80 |
typedef void (*Menu_Hook) (MENU *); |
81 |
|
82 |
struct __item {
|
83 |
MENU_STR name; |
84 |
MENU_STR description; |
85 |
char *userptr;
|
86 |
int visible; /* set if item is visible */ |
87 |
int selected; /* set if item has been selected */ |
88 |
int row; /* menu row this item is on */ |
89 |
int col; /* menu column this item is on */ |
90 |
OPTIONS opts; |
91 |
MENU *parent; /* menu this item is bound to */
|
92 |
int index; /* index number for this item, if attached */ |
93 |
/* The following are the item's neighbours - makes menu
|
94 |
navigation easier */
|
95 |
ITEM *left; |
96 |
ITEM *right; |
97 |
ITEM *up; |
98 |
ITEM *down; |
99 |
}; |
100 |
|
101 |
struct __menu {
|
102 |
int rows; /* max number of rows to be displayed */ |
103 |
int cols; /* max number of columns to be displayed */ |
104 |
int item_rows; /* number of item rows we have */ |
105 |
int item_cols; /* number of item columns we have */ |
106 |
int cur_row; /* current cursor row */ |
107 |
int cur_col; /* current cursor column */ |
108 |
MENU_STR mark; /* menu mark string */
|
109 |
MENU_STR unmark; /* menu unmark string */
|
110 |
OPTIONS opts; /* options for the menu */
|
111 |
char *pattern; /* the pattern buffer */ |
112 |
int plen; /* pattern buffer length */ |
113 |
int match_len; /* length of pattern matched */ |
114 |
int posted; /* set if menu is posted */ |
115 |
attr_t fore; /* menu foreground */
|
116 |
attr_t back; /* menu background */
|
117 |
attr_t grey; /* greyed out (nonselectable) menu item */
|
118 |
int pad; /* filler char between name and description */ |
119 |
char *userptr;
|
120 |
int top_row; /* the row that is at the top of the menu */ |
121 |
int max_item_width; /* widest item */ |
122 |
int col_width; /* width of the menu columns - this is not always |
123 |
the same as the widest item */
|
124 |
int item_count; /* number of items attached */ |
125 |
ITEM **items; /* items associated with this menu */
|
126 |
int cur_item; /* item cursor is currently positioned at */ |
127 |
int in_init; /* set when processing an init or term function call */ |
128 |
Menu_Hook menu_init; /* call this when menu is posted */
|
129 |
Menu_Hook menu_term; /* call this when menu is unposted */
|
130 |
Menu_Hook item_init; /* call this when menu posted & after
|
131 |
current item changes */
|
132 |
Menu_Hook item_term; /* call this when menu unposted & just
|
133 |
before current item changes */
|
134 |
WINDOW *menu_win; /* the menu window */
|
135 |
WINDOW *menu_subwin; /* the menu subwindow */
|
136 |
WINDOW *scrwin; /* the window to write to */
|
137 |
}; |
138 |
|
139 |
|
140 |
/* Public function prototypes. */
|
141 |
__BEGIN_DECLS |
142 |
int menu_driver(MENU *, int); |
143 |
int scale_menu(MENU *, int *, int *); |
144 |
int set_top_row(MENU *, int); |
145 |
int pos_menu_cursor(MENU *);
|
146 |
int top_row(MENU *);
|
147 |
|
148 |
int free_menu(MENU *);
|
149 |
char menu_back(MENU *);
|
150 |
char menu_fore(MENU *);
|
151 |
void menu_format(MENU *, int *, int *); |
152 |
char menu_grey(MENU *);
|
153 |
Menu_Hook menu_init(MENU *); |
154 |
char *menu_mark(MENU *);
|
155 |
OPTIONS menu_opts(MENU *); |
156 |
int menu_opts_off(MENU *, OPTIONS);
|
157 |
int menu_opts_on(MENU *, OPTIONS);
|
158 |
int menu_pad(MENU *);
|
159 |
char *menu_pattern(MENU *);
|
160 |
WINDOW *menu_sub(MENU *); |
161 |
Menu_Hook menu_term(MENU *); |
162 |
char *menu_unmark (MENU *);
|
163 |
char *menu_userptr(MENU *);
|
164 |
WINDOW *menu_win(MENU *); |
165 |
MENU *new_menu(ITEM **); |
166 |
int post_menu(MENU *);
|
167 |
int set_menu_back(MENU *, attr_t);
|
168 |
int set_menu_fore(MENU *, attr_t);
|
169 |
int set_menu_format(MENU *, int, int); |
170 |
int set_menu_grey(MENU *, attr_t);
|
171 |
int set_menu_init(MENU *, Menu_Hook);
|
172 |
int set_menu_items(MENU *, ITEM **);
|
173 |
int set_menu_mark(MENU *, char *); |
174 |
int set_menu_opts(MENU *, OPTIONS);
|
175 |
int set_menu_pad(MENU *, int); |
176 |
int set_menu_pattern(MENU *, char *); |
177 |
int set_menu_sub(MENU *, WINDOW *);
|
178 |
int set_menu_term(MENU *, Menu_Hook);
|
179 |
int set_menu_unmark(MENU *, char *); |
180 |
int set_menu_userptr(MENU *, char *); |
181 |
int set_menu_win(MENU *, WINDOW *);
|
182 |
int unpost_menu(MENU *);
|
183 |
|
184 |
ITEM *current_item(MENU *); |
185 |
int free_item(ITEM *);
|
186 |
int item_count(MENU *);
|
187 |
char *item_description(ITEM *);
|
188 |
int item_index(ITEM *);
|
189 |
Menu_Hook item_init(MENU *); |
190 |
char *item_name(ITEM *);
|
191 |
OPTIONS item_opts(ITEM *); |
192 |
int item_opts_off(ITEM *, OPTIONS);
|
193 |
int item_opts_on(ITEM *, OPTIONS);
|
194 |
int item_selected(MENU *, int **); /* return the item index of selected */ |
195 |
Menu_Hook item_term(MENU *); |
196 |
char *item_userptr(ITEM *);
|
197 |
int item_value(ITEM *);
|
198 |
int item_visible(ITEM *);
|
199 |
ITEM **menu_items(MENU *); |
200 |
ITEM *new_item(char *, char *); |
201 |
int set_current_item(MENU *, ITEM *);
|
202 |
int set_item_init(MENU *, Menu_Hook);
|
203 |
int set_item_opts(ITEM *, OPTIONS);
|
204 |
int set_item_term(MENU *, Menu_Hook);
|
205 |
int set_item_userptr(ITEM *, char *); |
206 |
int set_item_value(ITEM *, int); |
207 |
|
208 |
__END_DECLS |
209 |
|
210 |
#endif /* !_MENU_H_ */ |