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