form.h revision 1.2 1 1.2 blymn /* $NetBSD: form.h,v 1.2 2001/01/04 12:30:37 blymn Exp $ */
2 1.1 blymn
3 1.1 blymn /*-
4 1.1 blymn * Copyright (c) 1998-1999 Brett Lymn
5 1.1 blymn * (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
6 1.1 blymn * All rights reserved.
7 1.1 blymn *
8 1.1 blymn * This code has been donated to The NetBSD Foundation by the Author.
9 1.1 blymn *
10 1.1 blymn * Redistribution and use in source and binary forms, with or without
11 1.1 blymn * modification, are permitted provided that the following conditions
12 1.1 blymn * are met:
13 1.1 blymn * 1. Redistributions of source code must retain the above copyright
14 1.1 blymn * notice, this list of conditions and the following disclaimer.
15 1.1 blymn * 2. The name of the author may not be used to endorse or promote products
16 1.1 blymn * derived from this software withough specific prior written permission
17 1.1 blymn *
18 1.1 blymn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 blymn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 blymn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 blymn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 blymn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 blymn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 blymn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 blymn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 blymn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 blymn * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 blymn *
29 1.1 blymn *
30 1.1 blymn */
31 1.1 blymn
32 1.1 blymn #ifndef FORM_H
33 1.1 blymn #define FORM_H 1
34 1.1 blymn #include <sys/queue.h>
35 1.1 blymn #include <stdarg.h>
36 1.1 blymn #include <curses.h>
37 1.1 blymn #include <eti.h>
38 1.1 blymn
39 1.1 blymn /* Define the types of field justification that can be used. */
40 1.1 blymn #define NO_JUSTIFICATION 0
41 1.1 blymn #define JUSTIFY_RIGHT 1
42 1.1 blymn #define JUSTIFY_LEFT 2
43 1.1 blymn #define JUSTIFY_CENTER 3
44 1.1 blymn
45 1.1 blymn /* Define the max and min valid justification styles for range checking */
46 1.1 blymn #define MIN_JUST_STYLE NO_JUSTIFICATION
47 1.1 blymn #define MAX_JUST_STYLE JUSTIFY_CENTER
48 1.1 blymn
49 1.1 blymn /* Options for the fields */
50 1.1 blymn typedef unsigned int Form_Options;
51 1.1 blymn
52 1.1 blymn #define O_VISIBLE 0x001 /* Field is visible */
53 1.1 blymn #define O_ACTIVE 0x002 /* Field is active in the form */
54 1.1 blymn #define O_PUBLIC 0x004 /* The contents entered into the field is echoed */
55 1.1 blymn #define O_EDIT 0x008 /* Can edit the field */
56 1.1 blymn #define O_WRAP 0x010 /* The field contents can line wrap */
57 1.1 blymn #define O_BLANK 0x020 /* Blank the field on modification */
58 1.1 blymn #define O_AUTOSKIP 0x040 /* Skip to next field when current is full */
59 1.1 blymn #define O_NULLOK 0x080 /* Field is allowed to contain no data */
60 1.1 blymn #define O_STATIC 0x100 /* Field is not dynamic */
61 1.1 blymn #define O_PASSOK 0x200 /* ??? */
62 1.1 blymn
63 1.1 blymn /* Form driver requests */
64 1.1 blymn #define REQ_MIN_REQUEST 0x100 /* must equal value of the first request */
65 1.1 blymn
66 1.1 blymn #define REQ_NEXT_PAGE 0x100 /* next page in form */
67 1.1 blymn #define REQ_PREV_PAGE 0x101 /* previous page in form */
68 1.1 blymn #define REQ_FIRST_PAGE 0x102 /* goto first page in form */
69 1.1 blymn #define REQ_LAST_PAGE 0x103 /* goto last page in form */
70 1.1 blymn
71 1.1 blymn #define REQ_NEXT_FIELD 0x104 /* move to the next field */
72 1.1 blymn #define REQ_PREV_FIELD 0x105 /* move to the previous field */
73 1.1 blymn #define REQ_FIRST_FIELD 0x106 /* goto the first field */
74 1.1 blymn #define REQ_LAST_FIELD 0x107 /* goto the last field */
75 1.1 blymn
76 1.1 blymn #define REQ_SNEXT_FIELD 0x108 /* move to the next field in sorted order */
77 1.1 blymn #define REQ_SPREV_FIELD 0x109 /* move to the prev field in sorted order */
78 1.1 blymn #define REQ_SFIRST_FIELD 0x10a /* move to the first sorted field */
79 1.1 blymn #define REQ_SLAST_FIELD 0x10b /* move to the last sorted field */
80 1.1 blymn
81 1.1 blymn #define REQ_LEFT_FIELD 0x10c /* go left one field */
82 1.1 blymn #define REQ_RIGHT_FIELD 0x10d /* go right one field */
83 1.1 blymn #define REQ_UP_FIELD 0x10e /* go up one field */
84 1.1 blymn #define REQ_DOWN_FIELD 0x10f /* go down one field */
85 1.1 blymn
86 1.1 blymn #define REQ_NEXT_CHAR 0x110 /* move to the next char in field */
87 1.1 blymn #define REQ_PREV_CHAR 0x111 /* move to the previous char in field */
88 1.1 blymn #define REQ_NEXT_LINE 0x112 /* go to the next line in the field */
89 1.1 blymn #define REQ_PREV_LINE 0x113 /* go to the previous line in the field */
90 1.1 blymn #define REQ_NEXT_WORD 0x114 /* go to the next word in the field */
91 1.1 blymn #define REQ_PREV_WORD 0x115 /* go to the previous word in the field */
92 1.1 blymn #define REQ_BEG_FIELD 0x116 /* go to the beginning of the field */
93 1.1 blymn #define REQ_END_FIELD 0x117 /* go to the end of the field */
94 1.1 blymn #define REQ_BEG_LINE 0x118 /* go to the beginning of the line */
95 1.1 blymn #define REQ_END_LINE 0x119 /* go to the end of the line */
96 1.1 blymn #define REQ_LEFT_CHAR 0x11a /* move left in the field */
97 1.1 blymn #define REQ_RIGHT_CHAR 0x11b /* move right in the field */
98 1.1 blymn #define REQ_UP_CHAR 0x11c /* move up in the field */
99 1.1 blymn #define REQ_DOWN_CHAR 0x11d /* move down in the field */
100 1.1 blymn
101 1.1 blymn #define REQ_NEW_LINE 0x11e /* insert/overlay a new line */
102 1.1 blymn #define REQ_INS_CHAR 0x11f /* insert a blank char at the cursor */
103 1.1 blymn #define REQ_INS_LINE 0x120 /* insert a blank line at the cursor */
104 1.1 blymn
105 1.1 blymn #define REQ_DEL_CHAR 0x121 /* delete the current character */
106 1.1 blymn #define REQ_DEL_PREV 0x122 /* delete the character before the current */
107 1.1 blymn #define REQ_DEL_LINE 0x123 /* delete the current line */
108 1.1 blymn #define REQ_DEL_WORD 0x124 /* delete the word at the cursor */
109 1.1 blymn #define REQ_CLR_EOL 0x125 /* clear to the end of the line */
110 1.1 blymn #define REQ_CLR_EOF 0x126 /* clear to the end of the field */
111 1.1 blymn #define REQ_CLR_FIELD 0x127 /* clear the field */
112 1.1 blymn
113 1.1 blymn #define REQ_OVL_MODE 0x128 /* overlay mode */
114 1.1 blymn #define REQ_INS_MODE 0x129 /* insert mode */
115 1.1 blymn
116 1.1 blymn #define REQ_SCR_FLINE 0x12a /* scroll field forward one line */
117 1.1 blymn #define REQ_SCR_BLINE 0x12b /* scroll field backward one line */
118 1.1 blymn #define REQ_SCR_FPAGE 0x12c /* scroll field forward one page */
119 1.1 blymn #define REQ_SCR_BPAGE 0x12d /* scroll field backward one page */
120 1.1 blymn #define REQ_SCR_FHPAGE 0x12e /* scroll field forward half a page */
121 1.1 blymn #define REQ_SCR_BHPAGE 0x12f /* scroll field backward half a page */
122 1.1 blymn
123 1.1 blymn #define REQ_SCR_FCHAR 0x130 /* horizontal scroll forward a character */
124 1.1 blymn #define REQ_SCR_BCHAR 0x131 /* horizontal scroll backward a character */
125 1.1 blymn #define REQ_SCR_HFLINE 0x132 /* horizontal scroll forward a line */
126 1.1 blymn #define REQ_SCR_HBLINE 0x133 /* horizontal scroll backward a line */
127 1.1 blymn #define REQ_SCR_HFHALF 0x134 /* horizontal scroll forward half a line */
128 1.1 blymn #define REQ_SCR_HBHALF 0x135 /* horizontal scroll backward half a line */
129 1.1 blymn
130 1.1 blymn #define REQ_VALIDATION 0x136 /* validate the field */
131 1.1 blymn #define REQ_PREV_CHOICE 0x137 /* display previous field choice */
132 1.1 blymn #define REQ_NEXT_CHOICE 0x138 /* display next field choice */
133 1.1 blymn
134 1.1 blymn #define REQ_MAX_COMMAND 0x138 /* must match the last driver command */
135 1.1 blymn
136 1.1 blymn typedef struct _form_string {
137 1.1 blymn size_t allocated;
138 1.1 blymn unsigned int length;
139 1.1 blymn char *string;
140 1.1 blymn } FORM_STR;
141 1.1 blymn
142 1.1 blymn typedef struct _form_field FIELD;
143 1.1 blymn typedef struct _form_struct FORM;
144 1.1 blymn typedef struct _form_fieldtype FIELDTYPE;
145 1.1 blymn
146 1.1 blymn typedef struct _formi_page_struct _FORMI_PAGE_START;
147 1.1 blymn typedef struct formi_type_link_struct _FORMI_TYPE_LINK;
148 1.1 blymn
149 1.1 blymn typedef void (*Form_Hook)(FORM *);
150 1.1 blymn
151 1.1 blymn /* definition of a field in the form */
152 1.1 blymn struct _form_field {
153 1.1 blymn unsigned int rows; /* rows in the field */
154 1.1 blymn unsigned int cols; /* columns in the field */
155 1.1 blymn unsigned int drows; /* dynamic rows */
156 1.1 blymn unsigned int dcols; /* dynamic columns */
157 1.1 blymn unsigned int max; /* maximum growth */
158 1.1 blymn unsigned int form_row; /* starting row in the form subwindow */
159 1.1 blymn unsigned int form_col; /* starting column in the form subwindow */
160 1.1 blymn unsigned int nrows; /* number of off screen rows */
161 1.1 blymn int index; /* index of this field in form fields array. */
162 1.1 blymn int nbuf; /* number of buffers associated with this field */
163 1.1 blymn int buf0_status; /* set to true if buffer 0 has changed. */
164 1.1 blymn int justification; /* justification style of the field */
165 1.1 blymn int overlay; /* set to true if field is in overlay mode */
166 1.1 blymn unsigned int start_char; /* starting char in string (horiz scroll) */
167 1.1 blymn unsigned int start_line; /* starting line in field (vert scroll) */
168 1.1 blymn unsigned int hscroll; /* amount of horizontal scroll... */
169 1.1 blymn unsigned int row_count; /* number of rows actually used in field */
170 1.1 blymn unsigned int cursor_xpos; /* x pos of cursor in field */
171 1.1 blymn unsigned int cursor_ypos; /* y pos of cursor in field */
172 1.1 blymn short page_break; /* start of a new page on the form if 1 */
173 1.1 blymn short page; /* number of the page this field is on */
174 1.1 blymn chtype fore; /* character attributes for the foreground */
175 1.1 blymn chtype back; /* character attributes for the background */
176 1.1 blymn int pad; /* padding character */
177 1.1 blymn Form_Options opts; /* options for the field */
178 1.1 blymn FORM *parent; /* the form this field is bound to, if any */
179 1.1 blymn FIELD *up; /* field above this one */
180 1.1 blymn FIELD *down; /* field below this one */
181 1.1 blymn FIELD *left; /* field to the left of this one */
182 1.1 blymn FIELD *right; /* field to the right of this one */
183 1.1 blymn void *userptr; /* user defined pointer. */
184 1.1 blymn FIELD *link; /* used if fields are linked */
185 1.1 blymn FIELDTYPE *type; /* type struct for the field */
186 1.1 blymn CIRCLEQ_ENTRY(_form_field) glue; /* circle queue glue for sorting fields */
187 1.1 blymn char *args; /* args for field type. */
188 1.1 blymn FORM_STR *buffers; /* array of buffers for the field */
189 1.1 blymn };
190 1.1 blymn
191 1.1 blymn /* define the types of fields we can have */
192 1.1 blymn extern FIELDTYPE *TYPE_ALNUM;
193 1.1 blymn extern FIELDTYPE *TYPE_ALPHA;
194 1.1 blymn extern FIELDTYPE *TYPE_ENUM;
195 1.1 blymn extern FIELDTYPE *TYPE_INTEGER;
196 1.1 blymn extern FIELDTYPE *TYPE_NUMERIC;
197 1.1 blymn extern FIELDTYPE *TYPE_REGEXP;
198 1.1 blymn extern FIELDTYPE *TYPE_USER;
199 1.1 blymn
200 1.1 blymn /* definition of a field type. */
201 1.1 blymn struct _form_fieldtype {
202 1.1 blymn unsigned flags; /* status of the type */
203 1.1 blymn unsigned refcount; /* in use if > 0 */
204 1.1 blymn _FORMI_TYPE_LINK *link; /* set if this type is linked */
205 1.1 blymn char *args;
206 1.1 blymn
207 1.1 blymn
208 1.1 blymn char * (*make_args)(va_list *); /* make the args for the type */
209 1.1 blymn char * (*copy_args)(char *); /* copy the args for the type */
210 1.1 blymn void (*free_args)(char *); /* free storage used by the args */
211 1.1 blymn int (*field_check)(FIELD *, char *); /* field validation routine */
212 1.1 blymn int (*char_check)(int, char *); /* char validation routine */
213 1.1 blymn int (*next_choice)(FIELD *, char *); /* function to select next
214 1.1 blymn choice */
215 1.1 blymn int (*prev_choice)(FIELD *, char *); /* function to select prev
216 1.1 blymn choice */
217 1.1 blymn };
218 1.1 blymn
219 1.1 blymn /*definition of a form */
220 1.1 blymn
221 1.1 blymn struct _form_struct {
222 1.1 blymn int in_init; /* true if performing a init or term function */
223 1.1 blymn int posted; /* the form is posted */
224 1.1 blymn WINDOW *win; /* window for the form */
225 1.1 blymn WINDOW *subwin; /* subwindow for the form */
226 1.1 blymn void *userptr; /* user defined pointer */
227 1.1 blymn Form_Options opts; /* options for the form */
228 1.1 blymn Form_Hook form_init; /* function called when form posted and
229 1.1 blymn after page change */
230 1.1 blymn Form_Hook form_term; /* function called when form is unposted and
231 1.1 blymn before page change */
232 1.1 blymn Form_Hook field_init; /* function called when form posted and after
233 1.1 blymn current field changes */
234 1.1 blymn Form_Hook field_term; /* function called when form unposted and
235 1.1 blymn before current field changes */
236 1.1 blymn int field_count; /* number of fields attached */
237 1.1 blymn int cur_field; /* current field */
238 1.1 blymn int page; /* current page of form */
239 1.1 blymn int max_page; /* number of pages in the form */
240 1.1 blymn int subwin_created; /* libform made the window */
241 1.1 blymn _FORMI_PAGE_START *page_starts; /* dynamic array of fields that start
242 1.1 blymn the pages */
243 1.1 blymn CIRCLEQ_HEAD(_formi_sort_head, _form_field) sorted_fields; /* sorted field
244 1.1 blymn list */
245 1.1 blymn FIELD **fields; /* array of fields attached to this form. */
246 1.1 blymn };
247 1.1 blymn
248 1.1 blymn /* Public function prototypes. */
249 1.1 blymn __BEGIN_DECLS
250 1.1 blymn
251 1.1 blymn FIELD *current_field(FORM *);
252 1.1 blymn int data_ahead(FORM *);
253 1.1 blymn int data_behind(FORM *);
254 1.1 blymn FIELD *dup_field(FIELD *, int, int);
255 1.1 blymn int dynamic_field_info(FIELD *, int *, int *, int *);
256 1.1 blymn char *field_arg(FIELD *);
257 1.1 blymn chtype field_back(FIELD *);
258 1.1 blymn char *field_buffer(FIELD *, int);
259 1.1 blymn int field_count(FORM *);
260 1.1 blymn chtype field_fore(FIELD *);
261 1.1 blymn int field_index(FIELD *);
262 1.1 blymn int field_info __P((FIELD *, int *, int *, int *, int *,
263 1.1 blymn int *, int *));
264 1.1 blymn Form_Hook field_init(FORM *);
265 1.1 blymn int field_just(FIELD *);
266 1.1 blymn Form_Options field_opts(FIELD *);
267 1.1 blymn int field_opts_off(FIELD *, Form_Options);
268 1.1 blymn int field_opts_on(FIELD *, Form_Options);
269 1.1 blymn int field_pad(FIELD *);
270 1.1 blymn int field_status(FIELD *);
271 1.1 blymn Form_Hook field_term(FORM *);
272 1.1 blymn FIELDTYPE *field_type(FIELD *);
273 1.2 blymn void *field_userptr(FIELD *);
274 1.1 blymn int form_driver(FORM *, int);
275 1.1 blymn FIELD **form_fields(FORM *);
276 1.1 blymn Form_Hook form_init(FORM *);
277 1.1 blymn Form_Options form_opts(FORM *);
278 1.1 blymn int form_opts_off(FORM *, Form_Options);
279 1.1 blymn int form_opts_on(FORM *, Form_Options);
280 1.1 blymn int form_page(FORM *);
281 1.1 blymn WINDOW *form_sub(FORM *);
282 1.1 blymn Form_Hook form_term(FORM *);
283 1.2 blymn void *form_userptr(FORM *);
284 1.1 blymn WINDOW *form_win(FORM *);
285 1.1 blymn int free_field(FIELD *);
286 1.1 blymn int free_fieldtype(FIELDTYPE *);
287 1.1 blymn int free_form(FORM *);
288 1.1 blymn FIELD *link_field(FIELD *, int, int);
289 1.1 blymn FIELDTYPE *link_fieldtype(FIELDTYPE *, FIELDTYPE *);
290 1.1 blymn int move_field(FIELD *, int, int);
291 1.1 blymn FIELD *new_field(int, int, int, int, int, int);
292 1.1 blymn FIELDTYPE *new_fieldtype(int (* field_check)(FIELD *, char *),
293 1.1 blymn int (* char_check)(int, char *));
294 1.1 blymn FORM *new_form(FIELD **);
295 1.1 blymn int new_page(FIELD *);
296 1.1 blymn int pos_form_cursor(FORM *);
297 1.1 blymn int post_form(FORM *);
298 1.1 blymn int scale_form(FORM *, int *, int *);
299 1.1 blymn int set_current_field(FORM *, FIELD *);
300 1.1 blymn int set_field_back(FIELD *, chtype);
301 1.1 blymn int set_field_buffer(FIELD *, int, char *);
302 1.1 blymn int set_field_fore(FIELD *, chtype);
303 1.1 blymn int set_field_init(FORM *, Form_Hook);
304 1.1 blymn int set_field_just(FIELD *, int);
305 1.1 blymn int set_field_opts(FIELD *, Form_Options);
306 1.1 blymn int set_field_pad(FIELD *, int);
307 1.1 blymn int set_field_status(FIELD *, int);
308 1.1 blymn int set_field_term(FORM *, Form_Hook);
309 1.1 blymn int set_field_type(FIELD *, FIELDTYPE *, ...);
310 1.2 blymn int set_field_userptr(FIELD *, void *);
311 1.1 blymn int set_fieldtype_arg(FIELDTYPE *, char *(*)(va_list *),
312 1.1 blymn char *(*)(char *),
313 1.1 blymn void (*)(char *));
314 1.1 blymn int set_fieldtype_choice(FIELDTYPE *, int (*)(FIELD *, char *),
315 1.1 blymn int (*)(FIELD *, char *));
316 1.1 blymn int set_form_fields(FORM *, FIELD **);
317 1.1 blymn int set_form_init(FORM *, Form_Hook);
318 1.1 blymn int set_form_opts(FORM *, Form_Options);
319 1.1 blymn int set_form_page(FORM *, int);
320 1.1 blymn int set_form_sub(FORM *, WINDOW *);
321 1.1 blymn int set_form_term(FORM *, Form_Hook);
322 1.2 blymn int set_form_userptr(FORM *, void *);
323 1.1 blymn int set_form_win(FORM *, WINDOW *);
324 1.1 blymn int set_max_field(FIELD *, int);
325 1.1 blymn int set_new_page(FIELD *, int);
326 1.1 blymn int unpost_form(FORM *);
327 1.1 blymn
328 1.1 blymn __END_DECLS
329 1.1 blymn
330 1.1 blymn #endif FORM_H
331