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