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