form.priv.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /****************************************************************************
  2. * Copyright (c) 1998-2006,2008 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.priv.h,v 0.27 2008/09/08 20:29:05 tom Exp $ */
  32. #ifndef FORM_PRIV_H
  33. #define FORM_PRIV_H 1
  34. #include "curses.priv.h"
  35. #include "mf_common.h"
  36. #if USE_WIDEC_SUPPORT
  37. #if HAVE_WCTYPE_H
  38. #include <wctype.h>
  39. #endif
  40. #ifndef MB_LEN_MAX
  41. #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
  42. #endif
  43. #define FIELD_CELL NCURSES_CH_T
  44. #define NCURSES_FIELD_INTERNALS char** expanded; WINDOW *working;
  45. #define NCURSES_FIELD_EXTENSION , (char **)0, (WINDOW *)0
  46. #else
  47. #define FIELD_CELL char
  48. #define NCURSES_FIELD_EXTENSION /* nothing */
  49. #endif
  50. #include "form.h"
  51. /* form status values */
  52. #define _OVLMODE (0x04U) /* Form is in overlay mode */
  53. #define _WINDOW_MODIFIED (0x10U) /* Current field window has been modified */
  54. #define _FCHECK_REQUIRED (0x20U) /* Current field needs validation */
  55. /* field status values */
  56. #define _CHANGED (0x01U) /* Field has been changed */
  57. #define _NEWTOP (0x02U) /* Vertical scrolling occurred */
  58. #define _NEWPAGE (0x04U) /* field begins new page of form */
  59. #define _MAY_GROW (0x08U) /* dynamic field may still grow */
  60. /* fieldtype status values */
  61. #define _LINKED_TYPE (0x01U) /* Type is a linked type */
  62. #define _HAS_ARGS (0x02U) /* Type has arguments */
  63. #define _HAS_CHOICE (0x04U) /* Type has choice methods */
  64. #define _RESIDENT (0x08U) /* Type is built-in */
  65. /* This are the field options required to be a selectable field in field
  66. navigation requests */
  67. #define O_SELECTABLE (O_ACTIVE | O_VISIBLE)
  68. /* If form is NULL replace form argument by default-form */
  69. #define Normalize_Form(form) \
  70. ((form) = (form != 0) ? (form) : _nc_Default_Form)
  71. /* If field is NULL replace field argument by default-field */
  72. #define Normalize_Field(field) \
  73. ((field) = (field != 0) ? (field) : _nc_Default_Field)
  74. /* Retrieve forms window */
  75. #define Get_Form_Window(form) \
  76. ((form)->sub?(form)->sub:((form)->win?(form)->win:stdscr))
  77. /* Calculate the size for a single buffer for this field */
  78. #define Buffer_Length(field) ((field)->drows * (field)->dcols)
  79. /* Calculate the total size of all buffers for this field */
  80. #define Total_Buffer_Size(field) \
  81. ( (Buffer_Length(field) + 1) * (1+(field)->nbuf) * sizeof(FIELD_CELL) )
  82. /* Logic to determine whether or not a field is single lined */
  83. #define Single_Line_Field(field) \
  84. (((field)->rows + (field)->nrow) == 1)
  85. /* Logic to determine whether or not a field is selectable */
  86. #define Field_Is_Selectable(f) (((unsigned)((f)->opts) & O_SELECTABLE)==O_SELECTABLE)
  87. #define Field_Is_Not_Selectable(f) (((unsigned)((f)->opts) & O_SELECTABLE)!=O_SELECTABLE)
  88. typedef struct typearg
  89. {
  90. struct typearg *left;
  91. struct typearg *right;
  92. }
  93. TypeArgument;
  94. /* This is a dummy request code (normally invalid) to be used internally
  95. with the form_driver() routine to position to the first active field
  96. on the form
  97. */
  98. #define FIRST_ACTIVE_MAGIC (-291056)
  99. #define ALL_FORM_OPTS ( \
  100. O_NL_OVERLOAD |\
  101. O_BS_OVERLOAD )
  102. #define ALL_FIELD_OPTS (Field_Options)( \
  103. O_VISIBLE |\
  104. O_ACTIVE |\
  105. O_PUBLIC |\
  106. O_EDIT |\
  107. O_WRAP |\
  108. O_BLANK |\
  109. O_AUTOSKIP|\
  110. O_NULLOK |\
  111. O_PASSOK |\
  112. O_STATIC )
  113. #define C_BLANK ' '
  114. #define is_blank(c) ((c)==C_BLANK)
  115. #define C_ZEROS '\0'
  116. extern NCURSES_EXPORT_VAR(const FIELDTYPE *) _nc_Default_FieldType;
  117. extern NCURSES_EXPORT(TypeArgument *) _nc_Make_Argument (const FIELDTYPE*, va_list*, int*);
  118. extern NCURSES_EXPORT(TypeArgument *) _nc_Copy_Argument (const FIELDTYPE*, const TypeArgument*, int*);
  119. extern NCURSES_EXPORT(void) _nc_Free_Argument (const FIELDTYPE*, TypeArgument*);
  120. extern NCURSES_EXPORT(bool) _nc_Copy_Type (FIELD*, FIELD const *);
  121. extern NCURSES_EXPORT(void) _nc_Free_Type (FIELD *);
  122. extern NCURSES_EXPORT(int) _nc_Synchronize_Attributes (FIELD*);
  123. extern NCURSES_EXPORT(int) _nc_Synchronize_Options (FIELD*, Field_Options);
  124. extern NCURSES_EXPORT(int) _nc_Set_Form_Page (FORM*, int, FIELD*);
  125. extern NCURSES_EXPORT(int) _nc_Refresh_Current_Field (FORM*);
  126. extern NCURSES_EXPORT(FIELD *) _nc_First_Active_Field (FORM*);
  127. extern NCURSES_EXPORT(bool) _nc_Internal_Validation (FORM*);
  128. extern NCURSES_EXPORT(int) _nc_Set_Current_Field (FORM*, FIELD*);
  129. extern NCURSES_EXPORT(int) _nc_Position_Form_Cursor (FORM*);
  130. #if USE_WIDEC_SUPPORT
  131. extern NCURSES_EXPORT(wchar_t *) _nc_Widen_String(char *, int *);
  132. #endif
  133. #ifdef TRACE
  134. #define returnField(code) TRACE_RETURN(code,field)
  135. #define returnFieldPtr(code) TRACE_RETURN(code,field_ptr)
  136. #define returnForm(code) TRACE_RETURN(code,form)
  137. #define returnFieldType(code) TRACE_RETURN(code,field_type)
  138. #define returnFormHook(code) TRACE_RETURN(code,form_hook)
  139. extern NCURSES_EXPORT(FIELD **) _nc_retrace_field_ptr (FIELD **);
  140. extern NCURSES_EXPORT(FIELD *) _nc_retrace_field (FIELD *);
  141. extern NCURSES_EXPORT(FIELDTYPE *) _nc_retrace_field_type (FIELDTYPE *);
  142. extern NCURSES_EXPORT(FORM *) _nc_retrace_form (FORM *);
  143. extern NCURSES_EXPORT(Form_Hook) _nc_retrace_form_hook (Form_Hook);
  144. #else /* !TRACE */
  145. #define returnFieldPtr(code) return code
  146. #define returnFieldType(code) return code
  147. #define returnField(code) return code
  148. #define returnForm(code) return code
  149. #define returnFormHook(code) return code
  150. #endif /* TRACE/!TRACE */
  151. /*
  152. * Use Check_CTYPE_Field() to simplify FIELDTYPE's that use only the ccheck()
  153. * function.
  154. */
  155. #if USE_WIDEC_SUPPORT
  156. #define Check_CTYPE_Field(result, buffer, width, ccheck) \
  157. while (*buffer && *buffer == ' ') \
  158. buffer++; \
  159. if (*buffer) \
  160. { \
  161. bool blank = FALSE; \
  162. int len; \
  163. int n; \
  164. wchar_t *list = _nc_Widen_String((char *)buffer, &len); \
  165. if (list != 0) \
  166. { \
  167. result = TRUE; \
  168. for (n = 0; n < len; ++n) \
  169. { \
  170. if (blank) \
  171. { \
  172. if (list[n] != ' ') \
  173. { \
  174. result = FALSE; \
  175. break; \
  176. } \
  177. } \
  178. else if (list[n] == ' ') \
  179. { \
  180. blank = TRUE; \
  181. result = (n + 1 >= width); \
  182. } \
  183. else if (!ccheck(list[n], NULL)) \
  184. { \
  185. result = FALSE; \
  186. break; \
  187. } \
  188. } \
  189. free(list); \
  190. } \
  191. }
  192. #else
  193. #define Check_CTYPE_Field(result, buffer, width, ccheck) \
  194. while (*buffer && *buffer == ' ') \
  195. buffer++; \
  196. if (*buffer) \
  197. { \
  198. unsigned char *s = buffer; \
  199. int l = -1; \
  200. while (*buffer && ccheck(*buffer, NULL)) \
  201. buffer++; \
  202. l = (int)(buffer - s); \
  203. while (*buffer && *buffer == ' ') \
  204. buffer++; \
  205. result = ((*buffer || (l < width)) ? FALSE : TRUE); \
  206. }
  207. #endif
  208. #endif /* FORM_PRIV_H */