1 /**************************************************************************** 2 * Copyright 2018-2019,2020 Thomas E. Dickey * 3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. * 4 * * 5 * Permission is hereby granted, free of charge, to any person obtaining a * 6 * copy of this software and associated documentation files (the * 7 * "Software"), to deal in the Software without restriction, including * 8 * without limitation the rights to use, copy, modify, merge, publish, * 9 * distribute, distribute with modifications, sublicense, and/or sell * 10 * copies of the Software, and to permit persons to whom the Software is * 11 * furnished to do so, subject to the following conditions: * 12 * * 13 * The above copyright notice and this permission notice shall be included * 14 * in all copies or substantial portions of the Software. * 15 * * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 23 * * 24 * Except as contained in this notice, the name(s) of the above copyright * 25 * holders shall not be used in advertising or otherwise to promote the * 26 * sale, use or other dealings in this Software without prior written * 27 * authorization. * 28 ****************************************************************************/ 29 30 /**************************************************************************** 31 * Author: Juergen Pfeifer, 1995,1997 * 32 ****************************************************************************/ 33 34 /* $Id: form.h,v 0.30 2020/02/02 23:34:34 tom Exp $ */ 35 36 #ifndef FORM_H 37 #define FORM_H 38 /* *INDENT-OFF*/ 39 40 #include <curses.h> 41 #include <eti.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #ifndef FORM_PRIV_H 48 typedef void *FIELD_CELL; 49 #endif 50 51 #ifndef NCURSES_FIELD_INTERNALS 52 #define NCURSES_FIELD_INTERNALS /* nothing */ 53 #endif 54 55 typedef int Form_Options; 56 typedef int Field_Options; 57 58 /********** 59 * _PAGE * 60 **********/ 61 62 typedef struct pagenode 63 #if !NCURSES_OPAQUE_FORM 64 { 65 short pmin; /* index of first field on page */ 66 short pmax; /* index of last field on page */ 67 short smin; /* index of top leftmost field on page */ 68 short smax; /* index of bottom rightmost field on page */ 69 } 70 #endif /* !NCURSES_OPAQUE_FORM */ 71 _PAGE; 72 73 /********** 74 * FIELD * 75 **********/ 76 77 typedef struct fieldnode 78 #if 1 /* not yet: !NCURSES_OPAQUE_FORM */ 79 { 80 unsigned short status; /* flags */ 81 short rows; /* size in rows */ 82 short cols; /* size in cols */ 83 short frow; /* first row */ 84 short fcol; /* first col */ 85 int drows; /* dynamic rows */ 86 int dcols; /* dynamic cols */ 87 int maxgrow; /* maximum field growth */ 88 int nrow; /* off-screen rows */ 89 short nbuf; /* additional buffers */ 90 short just; /* justification */ 91 short page; /* page on form */ 92 short index; /* into form -> field */ 93 int pad; /* pad character */ 94 chtype fore; /* foreground attribute */ 95 chtype back; /* background attribute */ 96 Field_Options opts; /* options */ 97 struct fieldnode * snext; /* sorted order pointer */ 98 struct fieldnode * sprev; /* sorted order pointer */ 99 struct fieldnode * link; /* linked field chain */ 100 struct formnode * form; /* containing form */ 101 struct typenode * type; /* field type */ 102 void * arg; /* argument for type */ 103 FIELD_CELL * buf; /* field buffers */ 104 void * usrptr; /* user pointer */ 105 /* 106 * The wide-character configuration requires extra information. Because 107 * there are existing applications that manipulate the members of FIELD 108 * directly, we cannot make the struct opaque, except by changing the ABI. 109 * Offsets of members up to this point are the same in the narrow- and 110 * wide-character configuration. But note that the type of buf depends on 111 * the configuration, and is made opaque for that reason. 112 */ 113 NCURSES_FIELD_INTERNALS 114 } 115 #endif /* NCURSES_OPAQUE_FORM */ 116 FIELD; 117 118 119 /********* 120 * FORM * 121 *********/ 122 123 typedef struct formnode 124 #if 1 /* not yet: !NCURSES_OPAQUE_FORM */ 125 { 126 unsigned short status; /* flags */ 127 short rows; /* size in rows */ 128 short cols; /* size in cols */ 129 int currow; /* current row in field window */ 130 int curcol; /* current col in field window */ 131 int toprow; /* in scrollable field window */ 132 int begincol; /* in horiz. scrollable field */ 133 short maxfield; /* number of fields */ 134 short maxpage; /* number of pages */ 135 short curpage; /* index into page */ 136 Form_Options opts; /* options */ 137 WINDOW * win; /* window */ 138 WINDOW * sub; /* subwindow */ 139 WINDOW * w; /* window for current field */ 140 FIELD ** field; /* field [maxfield] */ 141 FIELD * current; /* current field */ 142 _PAGE * page; /* page [maxpage] */ 143 void * usrptr; /* user pointer */ 144 145 void (*forminit)(struct formnode *); 146 void (*formterm)(struct formnode *); 147 void (*fieldinit)(struct formnode *); 148 void (*fieldterm)(struct formnode *); 149 150 } 151 #endif /* !NCURSES_OPAQUE_FORM */ 152 FORM; 153 154 155 /************** 156 * FIELDTYPE * 157 **************/ 158 159 typedef struct typenode 160 #if !NCURSES_OPAQUE_FORM 161 { 162 unsigned short status; /* flags */ 163 long ref; /* reference count */ 164 struct typenode * left; /* ptr to operand for | */ 165 struct typenode * right; /* ptr to operand for | */ 166 167 void* (*makearg)(va_list *); /* make fieldtype arg */ 168 void* (*copyarg)(const void *); /* copy fieldtype arg */ 169 void (*freearg)(void *); /* free fieldtype arg */ 170 171 #if NCURSES_INTEROP_FUNCS 172 union { 173 bool (*ofcheck)(FIELD *,const void *); /* field validation */ 174 bool (*gfcheck)(FORM*,FIELD *,const void*); /* generic field validation */ 175 } fieldcheck; 176 union { 177 bool (*occheck)(int,const void *); /* character validation */ 178 bool (*gccheck)(int,FORM*, 179 FIELD*,const void*); /* generic char validation */ 180 } charcheck; 181 union { 182 bool (*onext)(FIELD *,const void *); /* enumerate next value */ 183 bool (*gnext)(FORM*,FIELD*,const void*); /* generic enumerate next */ 184 } enum_next; 185 union { 186 bool (*oprev)(FIELD *,const void *); /* enumerate prev value */ 187 bool (*gprev)(FORM*,FIELD*,const void*); /* generic enumerate prev */ 188 } enum_prev; 189 void* (*genericarg)(void*); /* Alternate Arg method */ 190 #else 191 bool (*fcheck)(FIELD *,const void *); /* field validation */ 192 bool (*ccheck)(int,const void *); /* character validation */ 193 194 bool (*next)(FIELD *,const void *); /* enumerate next value */ 195 bool (*prev)(FIELD *,const void *); /* enumerate prev value */ 196 #endif 197 } 198 #endif /* !NCURSES_OPAQUE_FORM */ 199 FIELDTYPE; 200 201 typedef void (*Form_Hook)(FORM *); 202 203 /*************************** 204 * miscellaneous #defines * 205 ***************************/ 206 207 /* field justification */ 208 #define NO_JUSTIFICATION (0) 209 #define JUSTIFY_LEFT (1) 210 #define JUSTIFY_CENTER (2) 211 #define JUSTIFY_RIGHT (3) 212 213 /* field options */ 214 #define O_VISIBLE (0x0001U) 215 #define O_ACTIVE (0x0002U) 216 #define O_PUBLIC (0x0004U) 217 #define O_EDIT (0x0008U) 218 #define O_WRAP (0x0010U) 219 #define O_BLANK (0x0020U) 220 #define O_AUTOSKIP (0x0040U) 221 #define O_NULLOK (0x0080U) 222 #define O_PASSOK (0x0100U) 223 #define O_STATIC (0x0200U) 224 #define O_DYNAMIC_JUSTIFY (0x0400U) /* ncurses extension */ 225 #define O_NO_LEFT_STRIP (0x0800U) /* ncurses extension */ 226 #define O_EDGE_INSERT_STAY (0x1000U) /* ncurses extension */ 227 #define O_INPUT_LIMIT (0x2000U) /* ncurses extension */ 228 229 /* form options */ 230 #define O_NL_OVERLOAD (0x0001U) 231 #define O_BS_OVERLOAD (0x0002U) 232 233 /* form driver commands */ 234 #define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */ 235 #define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */ 236 #define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */ 237 #define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */ 238 239 #define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */ 240 #define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */ 241 #define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */ 242 #define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */ 243 #define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */ 244 #define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */ 245 #define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */ 246 #define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */ 247 #define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */ 248 #define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */ 249 #define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */ 250 #define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */ 251 252 #define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */ 253 #define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */ 254 #define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */ 255 #define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */ 256 #define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */ 257 #define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */ 258 #define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */ 259 #define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */ 260 #define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */ 261 #define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */ 262 #define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */ 263 #define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */ 264 #define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */ 265 #define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */ 266 267 #define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */ 268 #define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */ 269 #define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */ 270 #define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */ 271 #define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */ 272 #define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */ 273 #define REQ_DEL_WORD (KEY_MAX + 37) /* delete word at cursor */ 274 #define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */ 275 #define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */ 276 #define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */ 277 #define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */ 278 #define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */ 279 #define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */ 280 #define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */ 281 #define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */ 282 #define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */ 283 #define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */ 284 #define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */ 285 #define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */ 286 #define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */ 287 #define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */ 288 #define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */ 289 #define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */ 290 #define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */ 291 292 #define REQ_VALIDATION (KEY_MAX + 55) /* validate field */ 293 #define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */ 294 #define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */ 295 296 #define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */ 297 #define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */ 298 299 #if defined(MAX_COMMAND) 300 # if (MAX_FORM_COMMAND > MAX_COMMAND) 301 # error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND 302 # elif (MAX_COMMAND != (KEY_MAX + 128)) 303 # error Something is wrong -- MAX_COMMAND is already inconsistently defined. 304 # endif 305 #else 306 # define MAX_COMMAND (KEY_MAX + 128) 307 #endif 308 309 /************************* 310 * standard field types * 311 *************************/ 312 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALPHA; 313 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALNUM; 314 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ENUM; 315 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_INTEGER; 316 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_NUMERIC; 317 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_REGEXP; 318 319 /************************************ 320 * built-in additional field types * 321 * They are not defined in SVr4 * 322 ************************************/ 323 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_IPV4; /* Internet IP Version 4 address */ 324 325 /*********************** 326 * FIELDTYPE routines * 327 ***********************/ 328 extern NCURSES_EXPORT(FIELDTYPE *) new_fieldtype ( 329 bool (* const field_check)(FIELD *,const void *), 330 bool (* const char_check)(int,const void *)); 331 extern NCURSES_EXPORT(FIELDTYPE *) link_fieldtype( 332 FIELDTYPE *, FIELDTYPE *); 333 334 extern NCURSES_EXPORT(int) free_fieldtype (FIELDTYPE *); 335 extern NCURSES_EXPORT(int) set_fieldtype_arg (FIELDTYPE *, 336 void * (* const make_arg)(va_list *), 337 void * (* const copy_arg)(const void *), 338 void (* const free_arg)(void *)); 339 extern NCURSES_EXPORT(int) set_fieldtype_choice (FIELDTYPE *, 340 bool (* const next_choice)(FIELD *,const void *), 341 bool (* const prev_choice)(FIELD *,const void *)); 342 343 /******************* 344 * FIELD routines * 345 *******************/ 346 extern NCURSES_EXPORT(FIELD *) new_field (int,int,int,int,int,int); 347 extern NCURSES_EXPORT(FIELD *) dup_field (FIELD *,int,int); 348 extern NCURSES_EXPORT(FIELD *) link_field (FIELD *,int,int); 349 350 extern NCURSES_EXPORT(int) free_field (FIELD *); 351 extern NCURSES_EXPORT(int) field_info (const FIELD *,int *,int *,int *,int *,int *,int *); 352 extern NCURSES_EXPORT(int) dynamic_field_info (const FIELD *,int *,int *,int *); 353 extern NCURSES_EXPORT(int) set_max_field ( FIELD *,int); 354 extern NCURSES_EXPORT(int) move_field (FIELD *,int,int); 355 extern NCURSES_EXPORT(int) set_field_type (FIELD *,FIELDTYPE *,...); 356 extern NCURSES_EXPORT(int) set_new_page (FIELD *,bool); 357 extern NCURSES_EXPORT(int) set_field_just (FIELD *,int); 358 extern NCURSES_EXPORT(int) field_just (const FIELD *); 359 extern NCURSES_EXPORT(int) set_field_fore (FIELD *,chtype); 360 extern NCURSES_EXPORT(int) set_field_back (FIELD *,chtype); 361 extern NCURSES_EXPORT(int) set_field_pad (FIELD *,int); 362 extern NCURSES_EXPORT(int) field_pad (const FIELD *); 363 extern NCURSES_EXPORT(int) set_field_buffer (FIELD *,int,const char *); 364 extern NCURSES_EXPORT(int) set_field_status (FIELD *,bool); 365 extern NCURSES_EXPORT(int) set_field_userptr (FIELD *, void *); 366 extern NCURSES_EXPORT(int) set_field_opts (FIELD *,Field_Options); 367 extern NCURSES_EXPORT(int) field_opts_on (FIELD *,Field_Options); 368 extern NCURSES_EXPORT(int) field_opts_off (FIELD *,Field_Options); 369 370 extern NCURSES_EXPORT(chtype) field_fore (const FIELD *); 371 extern NCURSES_EXPORT(chtype) field_back (const FIELD *); 372 373 extern NCURSES_EXPORT(bool) new_page (const FIELD *); 374 extern NCURSES_EXPORT(bool) field_status (const FIELD *); 375 376 extern NCURSES_EXPORT(void *) field_arg (const FIELD *); 377 378 extern NCURSES_EXPORT(void *) field_userptr (const FIELD *); 379 380 extern NCURSES_EXPORT(FIELDTYPE *) field_type (const FIELD *); 381 382 extern NCURSES_EXPORT(char *) field_buffer (const FIELD *,int); 383 384 extern NCURSES_EXPORT(Field_Options) field_opts (const FIELD *); 385 386 /****************** 387 * FORM routines * 388 ******************/ 389 390 extern NCURSES_EXPORT(FORM *) new_form (FIELD **); 391 392 extern NCURSES_EXPORT(FIELD **) form_fields (const FORM *); 393 extern NCURSES_EXPORT(FIELD *) current_field (const FORM *); 394 395 extern NCURSES_EXPORT(WINDOW *) form_win (const FORM *); 396 extern NCURSES_EXPORT(WINDOW *) form_sub (const FORM *); 397 398 extern NCURSES_EXPORT(Form_Hook) form_init (const FORM *); 399 extern NCURSES_EXPORT(Form_Hook) form_term (const FORM *); 400 extern NCURSES_EXPORT(Form_Hook) field_init (const FORM *); 401 extern NCURSES_EXPORT(Form_Hook) field_term (const FORM *); 402 403 extern NCURSES_EXPORT(int) free_form (FORM *); 404 extern NCURSES_EXPORT(int) set_form_fields (FORM *,FIELD **); 405 extern NCURSES_EXPORT(int) field_count (const FORM *); 406 extern NCURSES_EXPORT(int) set_form_win (FORM *,WINDOW *); 407 extern NCURSES_EXPORT(int) set_form_sub (FORM *,WINDOW *); 408 extern NCURSES_EXPORT(int) set_current_field (FORM *,FIELD *); 409 extern NCURSES_EXPORT(int) unfocus_current_field (FORM *); 410 extern NCURSES_EXPORT(int) field_index (const FIELD *); 411 extern NCURSES_EXPORT(int) set_form_page (FORM *,int); 412 extern NCURSES_EXPORT(int) form_page (const FORM *); 413 extern NCURSES_EXPORT(int) scale_form (const FORM *,int *,int *); 414 extern NCURSES_EXPORT(int) set_form_init (FORM *,Form_Hook); 415 extern NCURSES_EXPORT(int) set_form_term (FORM *,Form_Hook); 416 extern NCURSES_EXPORT(int) set_field_init (FORM *,Form_Hook); 417 extern NCURSES_EXPORT(int) set_field_term (FORM *,Form_Hook); 418 extern NCURSES_EXPORT(int) post_form (FORM *); 419 extern NCURSES_EXPORT(int) unpost_form (FORM *); 420 extern NCURSES_EXPORT(int) pos_form_cursor (FORM *); 421 extern NCURSES_EXPORT(int) form_driver (FORM *,int); 422 # if NCURSES_WIDECHAR 423 extern NCURSES_EXPORT(int) form_driver_w (FORM *,int,wchar_t); 424 # endif 425 extern NCURSES_EXPORT(int) set_form_userptr (FORM *,void *); 426 extern NCURSES_EXPORT(int) set_form_opts (FORM *,Form_Options); 427 extern NCURSES_EXPORT(int) form_opts_on (FORM *,Form_Options); 428 extern NCURSES_EXPORT(int) form_opts_off (FORM *,Form_Options); 429 extern NCURSES_EXPORT(int) form_request_by_name (const char *); 430 431 extern NCURSES_EXPORT(const char *) form_request_name (int); 432 433 extern NCURSES_EXPORT(void *) form_userptr (const FORM *); 434 435 extern NCURSES_EXPORT(Form_Options) form_opts (const FORM *); 436 437 extern NCURSES_EXPORT(bool) data_ahead (const FORM *); 438 extern NCURSES_EXPORT(bool) data_behind (const FORM *); 439 440 #if NCURSES_SP_FUNCS 441 extern NCURSES_EXPORT(FORM *) NCURSES_SP_NAME(new_form) (SCREEN*, FIELD **); 442 #endif 443 444 #ifdef __cplusplus 445 } 446 #endif 447 /* *INDENT-ON*/ 448 449 #endif /* FORM_H */ 450