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