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