form.h 17 KB

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