Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

form.priv.h

Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *   Author:  Juergen Pfeifer, 1995,1997                                    *
00031  ****************************************************************************/
00032 
00033 /* $Id: form.priv.h,v 0.25 2005/03/05 23:47:26 tom Exp $ */
00034 
00035 #ifndef FORM_PRIV_H
00036 #define FORM_PRIV_H 1
00037 
00038 #include "curses.priv.h"
00039 #include "mf_common.h"
00040 
00041 #if USE_WIDEC_SUPPORT
00042 #include <wchar.h>
00043 #include <wctype.h>
00044 
00045 #ifndef MB_LEN_MAX
00046 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
00047 #endif
00048 
00049 #define FIELD_CELL NCURSES_CH_T
00050 
00051 #define NCURSES_FIELD_INTERNALS char** expanded; WINDOW *working;
00052 #define NCURSES_FIELD_EXTENSION , (char **)0, (WINDOW *)0
00053 
00054 #else
00055 
00056 #define FIELD_CELL char
00057 
00058 #define NCURSES_FIELD_EXTENSION /* nothing */
00059 
00060 #endif
00061 
00062 #include "form.h"
00063 
00064 /* form  status values */
00065 #define _OVLMODE         (0x04U) /* Form is in overlay mode                */
00066 #define _WINDOW_MODIFIED (0x10U) /* Current field window has been modified */
00067 #define _FCHECK_REQUIRED (0x20U) /* Current field needs validation         */
00068 
00069 /* field status values */
00070 #define _CHANGED         (0x01U) /* Field has been changed                 */
00071 #define _NEWTOP          (0x02U) /* Vertical scrolling occurred            */
00072 #define _NEWPAGE         (0x04U) /* field begins new page of form          */
00073 #define _MAY_GROW        (0x08U) /* dynamic field may still grow           */
00074 
00075 /* fieldtype status values */
00076 #define _LINKED_TYPE     (0x01U) /* Type is a linked type                  */
00077 #define _HAS_ARGS        (0x02U) /* Type has arguments                     */
00078 #define _HAS_CHOICE      (0x04U) /* Type has choice methods                */
00079 #define _RESIDENT        (0x08U) /* Type is built-in                       */
00080 
00081 /* This are the field options required to be a selectable field in field
00082    navigation requests */
00083 #define O_SELECTABLE (O_ACTIVE | O_VISIBLE)
00084 
00085 /* If form is NULL replace form argument by default-form */
00086 #define Normalize_Form(form) \
00087   ((form) = (form != 0) ? (form) : _nc_Default_Form)
00088 
00089 /* If field is NULL replace field argument by default-field */
00090 #define Normalize_Field(field) \
00091   ((field) = (field != 0) ? (field) : _nc_Default_Field)
00092 
00093 /* Retrieve forms window */
00094 #define Get_Form_Window(form) \
00095   ((form)->sub?(form)->sub:((form)->win?(form)->win:stdscr))
00096 
00097 /* Calculate the size for a single buffer for this field */
00098 #define Buffer_Length(field) ((field)->drows * (field)->dcols)
00099 
00100 /* Calculate the total size of all buffers for this field */
00101 #define Total_Buffer_Size(field) \
00102    ( (Buffer_Length(field) + 1) * (1+(field)->nbuf) * sizeof(FIELD_CELL) )
00103 
00104 /* Logic to determine whether or not a field is single lined */
00105 #define Single_Line_Field(field) \
00106    (((field)->rows + (field)->nrow) == 1)
00107 
00108 /* Logic to determine whether or not a field is selectable */
00109 #define Field_Is_Selectable(f)     (((unsigned)((f)->opts) & O_SELECTABLE)==O_SELECTABLE)
00110 #define Field_Is_Not_Selectable(f) (((unsigned)((f)->opts) & O_SELECTABLE)!=O_SELECTABLE)
00111 
00112 typedef struct typearg
00113   {
00114     struct typearg *left;
00115     struct typearg *right;
00116   }
00117 TypeArgument;
00118 
00119 /* This is a dummy request code (normally invalid) to be used internally
00120    with the form_driver() routine to position to the first active field
00121    on the form
00122 */
00123 #define FIRST_ACTIVE_MAGIC (-291056)
00124 
00125 #define ALL_FORM_OPTS  (                \
00126                         O_NL_OVERLOAD  |\
00127                         O_BS_OVERLOAD   )
00128 
00129 #define ALL_FIELD_OPTS (Field_Options)( \
00130                         O_VISIBLE |\
00131                         O_ACTIVE  |\
00132                         O_PUBLIC  |\
00133                         O_EDIT    |\
00134                         O_WRAP    |\
00135                         O_BLANK   |\
00136                         O_AUTOSKIP|\
00137                         O_NULLOK  |\
00138                         O_PASSOK  |\
00139                         O_STATIC   )
00140 
00141 #define C_BLANK ' '
00142 #define is_blank(c) ((c)==C_BLANK)
00143 
00144 #define C_ZEROS '\0'
00145 
00146 extern NCURSES_EXPORT_VAR(const FIELDTYPE *) _nc_Default_FieldType;
00147 
00148 extern NCURSES_EXPORT(TypeArgument *) _nc_Make_Argument (const FIELDTYPE*, va_list*, int*);
00149 extern NCURSES_EXPORT(TypeArgument *) _nc_Copy_Argument (const FIELDTYPE*, const TypeArgument*, int*);
00150 extern NCURSES_EXPORT(void) _nc_Free_Argument (const FIELDTYPE*, TypeArgument*);
00151 extern NCURSES_EXPORT(bool) _nc_Copy_Type (FIELD*, FIELD const *);
00152 extern NCURSES_EXPORT(void) _nc_Free_Type (FIELD *);
00153 
00154 extern NCURSES_EXPORT(int) _nc_Synchronize_Attributes (FIELD*);
00155 extern NCURSES_EXPORT(int) _nc_Synchronize_Options (FIELD*, Field_Options);
00156 extern NCURSES_EXPORT(int) _nc_Set_Form_Page (FORM*, int, FIELD*);
00157 extern NCURSES_EXPORT(int) _nc_Refresh_Current_Field (FORM*);
00158 extern NCURSES_EXPORT(FIELD *) _nc_First_Active_Field (FORM*);
00159 extern NCURSES_EXPORT(bool) _nc_Internal_Validation (FORM*);
00160 extern NCURSES_EXPORT(int) _nc_Set_Current_Field (FORM*, FIELD*);
00161 extern NCURSES_EXPORT(int) _nc_Position_Form_Cursor (FORM*);
00162 
00163 #if USE_WIDEC_SUPPORT
00164 extern NCURSES_EXPORT(wchar_t *) _nc_Widen_String(char *, int *);
00165 #endif
00166 
00167 #ifdef TRACE
00168 
00169 #define returnField(code)       TRACE_RETURN(code,field)
00170 #define returnFieldPtr(code)    TRACE_RETURN(code,field_ptr)
00171 #define returnForm(code)        TRACE_RETURN(code,form)
00172 #define returnFieldType(code)   TRACE_RETURN(code,field_type)
00173 #define returnFormHook(code)    TRACE_RETURN(code,form_hook)
00174 
00175 extern NCURSES_EXPORT(FIELD **)     _nc_retrace_field_ptr (FIELD **);
00176 extern NCURSES_EXPORT(FIELD *)      _nc_retrace_field (FIELD *);
00177 extern NCURSES_EXPORT(FIELDTYPE *)  _nc_retrace_field_type (FIELDTYPE *);
00178 extern NCURSES_EXPORT(FORM *)  _nc_retrace_form (FORM *);
00179 extern NCURSES_EXPORT(Form_Hook)  _nc_retrace_form_hook (Form_Hook);
00180 
00181 #else /* !TRACE */
00182 
00183 #define returnFieldPtr(code)    return code
00184 #define returnFieldType(code)   return code
00185 #define returnField(code)       return code
00186 #define returnForm(code)        return code
00187 #define returnFormHook(code)    return code
00188 
00189 #endif /* TRACE/!TRACE */
00190 
00191 /*
00192  * Use Check_CTYPE_Field() to simplify FIELDTYPE's that use only the ccheck()
00193  * function.
00194  */
00195 #if USE_WIDEC_SUPPORT
00196 #define Check_CTYPE_Field(result, buffer, width, ccheck) \
00197   while (*buffer && *buffer == ' ') \
00198     buffer++; \
00199   if (*buffer) \
00200     { \
00201       bool blank = FALSE; \
00202       int len; \
00203       int n; \
00204       wchar_t *list = _nc_Widen_String((char *)buffer, &len); \
00205       if (list != 0) \
00206         { \
00207           result = TRUE; \
00208           for (n = 0; n < len; ++n) \
00209             { \
00210               if (blank) \
00211                 { \
00212                   if (list[n] != ' ') \
00213                     { \
00214                       result = FALSE; \
00215                       break; \
00216                     } \
00217                 } \
00218               else if (list[n] == ' ') \
00219                 { \
00220                   blank = TRUE; \
00221                   result = (n + 1 >= width); \
00222                 } \
00223               else if (!ccheck(list[n], NULL)) \
00224                 { \
00225                   result = FALSE; \
00226                   break; \
00227                 } \
00228             } \
00229           free(list); \
00230         } \
00231     }
00232 #else
00233 #define Check_CTYPE_Field(result, buffer, width, ccheck) \
00234   while (*buffer && *buffer == ' ') \
00235     buffer++; \
00236   if (*buffer) \
00237     { \
00238       unsigned char *s = buffer; \
00239       int l = -1; \
00240       while (*buffer && ccheck(*buffer, NULL)) \
00241         buffer++; \
00242       l = (int)(buffer - s); \
00243       while (*buffer && *buffer == ' ') \
00244         buffer++; \
00245       result = ((*buffer || (l < width)) ? FALSE : TRUE); \
00246     }
00247 #endif
00248 
00249 #endif /* FORM_PRIV_H */

© sourcejam.com 2005-2008