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