1 /****************************************************************************
2 * Copyright (c) 1998 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 <juergen.pfeifer@gmx.net> 1995,1997 *
31 ****************************************************************************/
36 #if defined(__sun__) && defined(__GNUC__)
40 #include <cmFormConfigure.h>
42 /* figure out which curses.h to include */
43 # if defined(CURSES_HAVE_NCURSES_H)
45 # elif defined(CURSES_HAVE_NCURSES_NCURSES_H)
46 # include <ncurses/ncurses.h>
47 # elif defined(CURSES_HAVE_NCURSES_CURSES_H)
48 # include <ncurses/curses.h>
60 typedef int Form_Options
;
61 typedef int Field_Options
;
68 short pmin
; /* index of first field on page */
69 short pmax
; /* index of last field on page */
70 short smin
; /* index of top leftmost field on page */
71 short smax
; /* index of bottom rightmost field on page */
78 typedef struct fieldnode
{
79 unsigned short status
; /* flags */
80 short rows
; /* size in rows */
81 short cols
; /* size in cols */
82 short frow
; /* first row */
83 short fcol
; /* first col */
84 int drows
; /* dynamic rows */
85 int dcols
; /* dynamic cols */
86 int maxgrow
; /* maximum field growth */
87 int nrow
; /* offscreen rows */
88 short nbuf
; /* additional buffers */
89 short just
; /* justification */
90 short page
; /* page on form */
91 short index
; /* into form -> field */
92 int pad
; /* pad character */
93 chtype fore
; /* foreground attribute */
94 chtype back
; /* background attribute */
95 Field_Options opts
; /* options */
96 struct fieldnode
* snext
; /* sorted order pointer */
97 struct fieldnode
* sprev
; /* sorted order pointer */
98 struct fieldnode
* link
; /* linked field chain */
99 struct formnode
* form
; /* containing form */
100 struct typenode
* type
; /* field type */
101 void * arg
; /* argument for type */
102 char * buf
; /* field buffers */
103 void * usrptr
; /* user pointer */
110 typedef struct typenode
{
111 unsigned short status
; /* flags */
112 long ref
; /* reference count */
113 struct typenode
* left
; /* ptr to operand for | */
114 struct typenode
* right
; /* ptr to operand for | */
116 void* (*makearg
)(va_list *); /* make fieldtype arg */
117 void* (*copyarg
)(const void *); /* copy fieldtype arg */
118 void (*freearg
)(void *); /* free fieldtype arg */
120 bool (*fcheck
)(FIELD
*,const void *); /* field validation */
121 bool (*ccheck
)(int,const void *); /* character validation */
123 bool (*next
)(FIELD
*,const void *); /* enumerate next value */
124 bool (*prev
)(FIELD
*,const void *); /* enumerate prev value */
132 typedef struct formnode
{
133 unsigned short status
; /* flags */
134 short rows
; /* size in rows */
135 short cols
; /* size in cols */
136 int currow
; /* current row in field window*/
137 int curcol
; /* current col in field window*/
138 int toprow
; /* in scrollable field window */
139 int begincol
; /* in horiz. scrollable field */
140 short maxfield
; /* number of fields */
141 short maxpage
; /* number of pages */
142 short curpage
; /* index into page */
143 Form_Options opts
; /* options */
144 WINDOW
* win
; /* window */
145 WINDOW
* sub
; /* subwindow */
146 WINDOW
* w
; /* window for current field */
147 FIELD
** field
; /* field [maxfield] */
148 FIELD
* current
; /* current field */
149 _PAGE
* page
; /* page [maxpage] */
150 void * usrptr
; /* user pointer */
152 void (*forminit
)(struct formnode
*);
153 void (*formterm
)(struct formnode
*);
154 void (*fieldinit
)(struct formnode
*);
155 void (*fieldterm
)(struct formnode
*);
159 typedef void (*Form_Hook
)(FORM
*);
161 /***************************
162 * miscellaneous #defines *
163 ***************************/
165 /* field justification */
166 #define NO_JUSTIFICATION (0)
167 #define JUSTIFY_LEFT (1)
168 #define JUSTIFY_CENTER (2)
169 #define JUSTIFY_RIGHT (3)
172 #define O_VISIBLE (0x0001)
173 #define O_ACTIVE (0x0002)
174 #define O_PUBLIC (0x0004)
175 #define O_EDIT (0x0008)
176 #define O_WRAP (0x0010)
177 #define O_BLANK (0x0020)
178 #define O_AUTOSKIP (0x0040)
179 #define O_NULLOK (0x0080)
180 #define O_PASSOK (0x0100)
181 #define O_STATIC (0x0200)
184 #define O_NL_OVERLOAD (0x0001)
185 #define O_BS_OVERLOAD (0x0002)
187 /* form driver commands */
188 #define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */
189 #define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */
190 #define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */
191 #define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */
193 #define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */
194 #define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */
195 #define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */
196 #define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */
197 #define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */
198 #define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */
199 #define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */
200 #define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */
201 #define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */
202 #define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */
203 #define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */
204 #define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */
206 #define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */
207 #define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */
208 #define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */
209 #define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */
210 #define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */
211 #define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */
212 #define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */
213 #define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */
214 #define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */
215 #define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */
216 #define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */
217 #define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */
218 #define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */
219 #define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */
221 #define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */
222 #define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */
223 #define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */
224 #define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */
225 #define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */
226 #define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */
227 #define REQ_DEL_WORD (KEY_MAX + 37) /* delete line at cursor */
228 #define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */
229 #define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */
230 #define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */
231 #define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */
232 #define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */
233 #define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */
234 #define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */
235 #define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */
236 #define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */
237 #define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */
238 #define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */
239 #define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */
240 #define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */
241 #define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */
242 #define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */
243 #define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */
244 #define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */
246 #define REQ_VALIDATION (KEY_MAX + 55) /* validate field */
247 #define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */
248 #define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */
250 #define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */
251 #define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */
253 #if defined(MAX_COMMAND)
254 # if (MAX_FORM_COMMAND > MAX_COMMAND)
255 # error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND
256 # elif (MAX_COMMAND != (KEY_MAX + 128))
257 # error Something is wrong -- MAX_COMMAND is already inconsistently defined.
260 # define MAX_COMMAND (KEY_MAX + 128)
263 /*************************
264 * standard field types *
265 *************************/
266 extern FIELDTYPE
*TYPE_ALPHA
,
273 /************************************
274 * built-in additional field types *
275 * They are not defined in SVr4 *
276 ************************************/
277 extern FIELDTYPE
*TYPE_IPV4
; /* Internet IP Version 4 address */
279 /***********************
281 ***********************/
282 extern FORM
*_nc_Default_Form
;
283 extern FIELD
*_nc_Default_Field
;
286 /***********************
287 * FIELDTYPE routines *
288 ***********************/
291 bool (* const field_check
)(FIELD
*,const void *),
292 bool (* const char_check
)(int,const void *)),
293 *link_fieldtype(FIELDTYPE
*,FIELDTYPE
*);
295 extern int free_fieldtype(FIELDTYPE
*),
296 set_fieldtype_choice (FIELDTYPE
*,
297 bool (* const next_choice
)(FIELD
*,const void *),
298 bool (* const prev_choice
)(FIELD
*,const void *));
303 extern FIELD
*new_field(int,int,int,int,int,int),
304 *dup_field(FIELD
*,int,int),
305 *link_field(FIELD
*,int,int);
307 extern int free_field(FIELD
*),
308 field_info(const FIELD
*,int *,int *,int *,int *,int *,int *),
309 dynamic_field_info(const FIELD
*,int *,int *,int *),
310 set_max_field( FIELD
*,int),
311 move_field(FIELD
*,int,int),
312 set_field_type(FIELD
*,FIELDTYPE
*,...),
313 set_new_page(FIELD
*,bool),
314 set_field_just(FIELD
*,int),
315 field_just(const FIELD
*),
316 set_field_fore(FIELD
*,chtype
),
317 set_field_back(FIELD
*,chtype
),
318 set_field_pad(FIELD
*,int),
319 field_pad(const FIELD
*),
320 set_field_buffer(FIELD
*,int,const char *),
321 set_field_status(FIELD
*,bool),
322 set_field_userptr(FIELD
*, void *),
323 set_field_opts(FIELD
*,Field_Options
),
324 field_opts_on(FIELD
*,Field_Options
),
325 field_opts_off(FIELD
*,Field_Options
);
327 extern chtype
field_fore(const FIELD
*),
328 field_back(const FIELD
*);
330 extern bool new_page(const FIELD
*),
331 field_status(const FIELD
*);
333 extern void *field_arg(const FIELD
*);
335 extern void *field_userptr(const FIELD
*);
338 *field_type(const FIELD
*);
340 extern char* field_buffer(const FIELD
*,int);
343 field_opts(const FIELD
*);
348 extern FORM
*new_form(FIELD
**);
350 extern FIELD
**form_fields(const FORM
*),
351 *current_field(const FORM
*);
353 extern WINDOW
*form_win(const FORM
*),
354 *form_sub(const FORM
*);
357 form_init(const FORM
*),
358 form_term(const FORM
*),
359 field_init(const FORM
*),
360 field_term(const FORM
*);
362 extern int free_form(FORM
*),
363 set_form_fields(FORM
*,FIELD
**),
364 field_count(const FORM
*),
365 set_form_win(FORM
*,WINDOW
*),
366 set_form_sub(FORM
*,WINDOW
*),
367 set_current_field(FORM
*,FIELD
*),
368 field_index(const FIELD
*),
369 set_form_page(FORM
*,int),
370 form_page(const FORM
*),
371 scale_form(const FORM
*,int *,int *),
372 set_form_init(FORM
*,Form_Hook
),
373 set_form_term(FORM
*,Form_Hook
),
374 set_field_init(FORM
*,Form_Hook
),
375 set_field_term(FORM
*,Form_Hook
),
378 pos_form_cursor(FORM
*),
379 form_driver(FORM
*,int),
380 set_form_userptr(FORM
*,void *),
381 set_form_opts(FORM
*,Form_Options
),
382 form_opts_on(FORM
*,Form_Options
),
383 form_opts_off(FORM
*,Form_Options
),
384 form_request_by_name(const char *);
387 *form_request_name(int);
389 extern void *form_userptr(const FORM
*);
392 form_opts(const FORM
*);
394 extern bool data_ahead(const FORM
*),
395 data_behind(const FORM
*);