]> ncurses.scripts.mit.edu Git - ncurses.git/blob - form/form.priv.h
ncurses 6.1 - patch 20190105
[ncurses.git] / form / form.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2017,2018 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 /****************************************************************************
30  *   Author:  Juergen Pfeifer, 1995,1997                                    *
31  ****************************************************************************/
32
33 /* $Id: form.priv.h,v 0.43 2018/04/14 21:06:14 Leon.Winter Exp $ */
34
35 #ifndef FORM_PRIV_H
36 #define FORM_PRIV_H 1
37 /* *INDENT-OFF*/
38 #include "curses.priv.h"
39
40 #define NCURSES_OPAQUE_FORM  0
41
42 #include "mf_common.h"
43
44 #if USE_WIDEC_SUPPORT
45 #if HAVE_WCTYPE_H
46 #include <wctype.h>
47 #endif
48
49 #ifndef MB_LEN_MAX
50 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
51 #endif
52
53 #define FIELD_CELL NCURSES_CH_T
54
55 #define NCURSES_FIELD_INTERNALS char** expanded; WINDOW *working;
56 #define NCURSES_FIELD_EXTENSION , (char **)0, (WINDOW *)0
57
58 #else
59
60 #define FIELD_CELL char
61
62 #define NCURSES_FIELD_EXTENSION /* nothing */
63
64 #endif
65
66 #include "form.h"
67
68         /***********************
69         *   Default objects    *
70         ***********************/
71 extern NCURSES_EXPORT_VAR(FORM *)      _nc_Default_Form;
72 extern NCURSES_EXPORT_VAR(FIELD *)     _nc_Default_Field;
73 extern NCURSES_EXPORT_VAR(FIELDTYPE *) _nc_Default_FieldType;
74
75 /* form  status values */
76 #define _OVLMODE         (0x04U) /* Form is in overlay mode                */
77 #define _WINDOW_MODIFIED (0x10U) /* Current field window has been modified */
78 #define _FCHECK_REQUIRED (0x20U) /* Current field needs validation         */
79
80 /* field status values */
81 #define _CHANGED         (0x01U) /* Field has been changed                 */
82 #define _NEWTOP          (0x02U) /* Vertical scrolling occurred            */
83 #define _NEWPAGE         (0x04U) /* field begins new page of form          */
84 #define _MAY_GROW        (0x08U) /* dynamic field may still grow           */
85
86 /* fieldtype status values */
87 #define _LINKED_TYPE     (0x01U) /* Type is a linked type                  */
88 #define _HAS_ARGS        (0x02U) /* Type has arguments                     */
89 #define _HAS_CHOICE      (0x04U) /* Type has choice methods                */
90 #define _RESIDENT        (0x08U) /* Type is built-in                       */
91 #define _GENERIC         (0x10U) /* A generic field type                   */
92
93 /* This are the field options required to be a selectable field in field
94    navigation requests */
95 #define O_SELECTABLE (O_ACTIVE | O_VISIBLE)
96
97 /* If form is NULL replace form argument by default-form */
98 #define Normalize_Form(form) \
99   ((form) = (form != 0) ? (form) : _nc_Default_Form)
100
101 /* If field is NULL replace field argument by default-field */
102 #define Normalize_Field(field) \
103   ((field) = (field != 0) ? (field) : _nc_Default_Field)
104
105 #if NCURSES_SP_FUNCS
106 #define Get_Form_Screen(form) \
107   ((form)->win ? _nc_screen_of((form->win)):CURRENT_SCREEN)
108 #else
109 #define Get_Form_Screen(form) CURRENT_SCREEN
110 #endif
111
112 /* Retrieve forms window */
113 #define Get_Form_Window(form) \
114   ((form)->sub \
115    ? (form)->sub \
116    : ((form)->win \
117       ? (form)->win \
118       : StdScreen(Get_Form_Screen(form))))
119
120 /* Calculate the size for a single buffer for this field */
121 #define Buffer_Length(field) ((field)->drows * (field)->dcols)
122
123 /* Calculate the total size of all buffers for this field */
124 #define Total_Buffer_Size(field) \
125    ( (size_t)(Buffer_Length(field) + 1) * (size_t)(1+(field)->nbuf) * sizeof(FIELD_CELL) )
126
127 /* Logic to determine whether or not a field is single lined */
128 #define Single_Line_Field(field) \
129    (((field)->rows + (field)->nrow) == 1)
130
131 #define Field_Has_Option(f,o)      ((((unsigned)(f)->opts) & o) != 0)
132
133 /* Logic to determine whether or not a field is selectable */
134 #define Field_Is_Selectable(f)     (((unsigned)((f)->opts) & O_SELECTABLE)==O_SELECTABLE)
135 #define Field_Is_Not_Selectable(f) (((unsigned)((f)->opts) & O_SELECTABLE)!=O_SELECTABLE)
136
137 typedef struct typearg
138   {
139     struct typearg *left;
140     struct typearg *right;
141   }
142 TypeArgument;
143
144 /* This is a dummy request code (normally invalid) to be used internally
145    with the form_driver() routine to position to the first active field
146    on the form
147 */
148 #define FIRST_ACTIVE_MAGIC (-291056)
149
150 #define ALL_FORM_OPTS  (                \
151                         O_NL_OVERLOAD  |\
152                         O_BS_OVERLOAD   )
153
154 #define STD_FIELD_OPTS (Field_Options)( \
155                         O_VISIBLE |\
156                         O_ACTIVE  |\
157                         O_PUBLIC  |\
158                         O_EDIT    |\
159                         O_WRAP    |\
160                         O_BLANK   |\
161                         O_AUTOSKIP|\
162                         O_NULLOK  |\
163                         O_PASSOK  |\
164                         O_STATIC)
165
166 #define ALL_FIELD_OPTS (Field_Options)( \
167                         STD_FIELD_OPTS |\
168                         O_DYNAMIC_JUSTIFY |\
169                         O_NO_LEFT_STRIP |\
170                         O_EDGE_INSERT_STAY)
171
172 #define C_BLANK ' '
173 #define is_blank(c) ((c)==C_BLANK)
174
175 #define C_ZEROS '\0'
176
177 extern NCURSES_EXPORT(TypeArgument *) _nc_Make_Argument (const FIELDTYPE*, va_list*, int*);
178 extern NCURSES_EXPORT(TypeArgument *) _nc_Copy_Argument (const FIELDTYPE*, const TypeArgument*, int*);
179 extern NCURSES_EXPORT(void) _nc_Free_Argument (const FIELDTYPE*, TypeArgument*);
180 extern NCURSES_EXPORT(bool) _nc_Copy_Type (FIELD*, FIELD const *);
181 extern NCURSES_EXPORT(void) _nc_Free_Type (FIELD *);
182
183 extern NCURSES_EXPORT(int) _nc_Synchronize_Attributes (FIELD*);
184 extern NCURSES_EXPORT(int) _nc_Synchronize_Options (FIELD*, Field_Options);
185 extern NCURSES_EXPORT(int) _nc_Set_Form_Page (FORM*, int, FIELD*);
186 extern NCURSES_EXPORT(int) _nc_Refresh_Current_Field (FORM*);
187 extern NCURSES_EXPORT(FIELD *) _nc_First_Active_Field (FORM*);
188 extern NCURSES_EXPORT(bool) _nc_Internal_Validation (FORM*);
189 extern NCURSES_EXPORT(int) _nc_Set_Current_Field (FORM*, FIELD*);
190 extern NCURSES_EXPORT(int) _nc_Position_Form_Cursor (FORM*);
191 extern NCURSES_EXPORT(void) _nc_Unset_Current_Field(FORM *form);
192
193 #if NCURSES_INTEROP_FUNCS
194 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_INTEGER(void);
195 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_ALNUM(void);
196 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_ALPHA(void);
197 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_ENUM(void);
198 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_NUMERIC(void);
199 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_REGEXP(void);
200 extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_IPV4(void);
201
202 extern NCURSES_EXPORT(FIELDTYPE *)
203 _nc_generic_fieldtype(bool (*const field_check) (FORM*, 
204                                                  FIELD *, 
205                                                  const void *),
206                       bool (*const char_check)  (int, 
207                                                  FORM*, 
208                                                  FIELD*, 
209                                                  const void *),
210                       bool (*const next)(FORM*,FIELD*,const void*),
211                       bool (*const prev)(FORM*,FIELD*,const void*),
212                       void (*freecallback)(void*));
213 extern NCURSES_EXPORT(int) _nc_set_generic_fieldtype(FIELD*, FIELDTYPE*, int (*)(void**));
214 extern NCURSES_EXPORT(WINDOW*) _nc_form_cursor(const FORM* , int* , int* );
215
216 #define INIT_FT_FUNC(func) {func}
217 #else
218 #define INIT_FT_FUNC(func) func
219 #endif
220
221 extern NCURSES_EXPORT(void) _nc_get_fieldbuffer(FORM*, FIELD*, FIELD_CELL*);
222
223 #if USE_WIDEC_SUPPORT
224 extern NCURSES_EXPORT(wchar_t *) _nc_Widen_String(char *, int *);
225 #endif
226
227 #ifdef TRACE
228
229 #define returnField(code)       TRACE_RETURN1(code,field)
230 #define returnFieldPtr(code)    TRACE_RETURN1(code,field_ptr)
231 #define returnForm(code)        TRACE_RETURN1(code,form)
232 #define returnFieldType(code)   TRACE_RETURN1(code,field_type)
233 #define returnFormHook(code)    TRACE_RETURN1(code,form_hook)
234
235 extern NCURSES_EXPORT(FIELD **)     _nc_retrace_field_ptr (FIELD **);
236 extern NCURSES_EXPORT(FIELD *)      _nc_retrace_field (FIELD *);
237 extern NCURSES_EXPORT(FIELDTYPE *)  _nc_retrace_field_type (FIELDTYPE *);
238 extern NCURSES_EXPORT(FORM *)       _nc_retrace_form (FORM *);
239 extern NCURSES_EXPORT(Form_Hook)    _nc_retrace_form_hook (Form_Hook);
240
241 #else /* !TRACE */
242
243 #define returnFieldPtr(code)    return code
244 #define returnFieldType(code)   return code
245 #define returnField(code)       return code
246 #define returnForm(code)        return code
247 #define returnFormHook(code)    return code
248
249 #endif /* TRACE/!TRACE */
250
251 /*
252  * Use Check_CTYPE_Field() to simplify FIELDTYPE's that use only the ccheck()
253  * function.
254  */
255 #if USE_WIDEC_SUPPORT
256 #define Check_CTYPE_Field(result, buffer, width, ccheck) \
257   while (*buffer && *buffer == ' ') \
258     buffer++; \
259   if (*buffer) \
260     { \
261       bool blank = FALSE; \
262       int len; \
263       int n; \
264       wchar_t *list = _nc_Widen_String((char *)buffer, &len); \
265       if (list != 0) \
266         { \
267           result = TRUE; \
268           for (n = 0; n < len; ++n) \
269             { \
270               if (blank) \
271                 { \
272                   if (list[n] != ' ') \
273                     { \
274                       result = FALSE; \
275                       break; \
276                     } \
277                 } \
278               else if (list[n] == ' ') \
279                 { \
280                   blank = TRUE; \
281                   result = (n + 1 >= width); \
282                 } \
283               else if (!ccheck(list[n], NULL)) \
284                 { \
285                   result = FALSE; \
286                   break; \
287                 } \
288             } \
289           free(list); \
290         } \
291     }
292 #else
293 #define Check_CTYPE_Field(result, buffer, width, ccheck) \
294   while (*buffer && *buffer == ' ') \
295     buffer++; \
296   if (*buffer) \
297     { \
298       unsigned char *s = buffer; \
299       int l = -1; \
300       while (*buffer && ccheck(*buffer, NULL)) \
301         buffer++; \
302       l = (int)(buffer - s); \
303       while (*buffer && *buffer == ' ') \
304         buffer++; \
305       result = ((*buffer || (l < width)) ? FALSE : TRUE); \
306     }
307 #endif
308 /* *INDENT-ON*/
309
310 #endif /* FORM_PRIV_H */