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