/****************************************************************************1* Copyright (c) 1998 Free Software Foundation, Inc. *2* *3* Permission is hereby granted, free of charge, to any person obtaining a *4* copy of this software and associated documentation files (the *5* "Software"), to deal in the Software without restriction, including *6* without limitation the rights to use, copy, modify, merge, publish, *7* distribute, distribute with modifications, sublicense, and/or sell *8* copies of the Software, and to permit persons to whom the Software is *9* furnished to do so, subject to the following conditions: *10* *11* The above copyright notice and this permission notice shall be included *12* in all copies or substantial portions of the Software. *13* *14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *15* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *17* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *20* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *21* *22* Except as contained in this notice, the name(s) of the above copyright *23* holders shall not be used in advertising or otherwise to promote the *24* sale, use or other dealings in this Software without prior written *25* authorization. *26****************************************************************************/2728/****************************************************************************29* Author: Juergen Pfeifer <[email protected]> 1995,1997 *30****************************************************************************/3132#include "mf_common.h"33#include "form.h"3435/* form status values */36#define _OVLMODE (0x04) /* Form is in overlay mode */37#define _WINDOW_MODIFIED (0x10) /* Current field window has been modified */38#define _FCHECK_REQUIRED (0x20) /* Current field needs validation */3940/* field status values */41#define _CHANGED (0x01) /* Field has been changed */42#define _NEWTOP (0x02) /* Vertical scrolling occurred */43#define _NEWPAGE (0x04) /* field begins new page of form */44#define _MAY_GROW (0x08) /* dynamic field may still grow */4546/* fieldtype status values */47#define _LINKED_TYPE (0x01) /* Type is a linked type */48#define _HAS_ARGS (0x02) /* Type has arguments */49#define _HAS_CHOICE (0x04) /* Type has choice methods */50#define _RESIDENT (0x08) /* Type is builtin */5152/* This are the field options required to be a selectable field in field53navigation requests */54#define O_SELECTABLE (O_ACTIVE | O_VISIBLE)5556/* If form is NULL replace form argument by default-form */57#define Normalize_Form(form) ((form)=(form)?(form):_nc_Default_Form)5859/* If field is NULL replace field argument by default-field */60#define Normalize_Field(field) ((field)=(field)?(field):_nc_Default_Field)6162/* Retrieve forms window */63#define Get_Form_Window(form) \64((form)->sub?(form)->sub:((form)->win?(form)->win:stdscr))6566/* Calculate the size for a single buffer for this field */67#define Buffer_Length(field) ((field)->drows * (field)->dcols)6869/* Calculate the total size of all buffers for this field */70#define Total_Buffer_Size(field) \71( (Buffer_Length(field) + 1) * (1+(field)->nbuf) )7273/* Logic to determine whether or not a field is single lined */74#define Single_Line_Field(field) \75(((field)->rows + (field)->nrow) == 1)7677/* Logic to determine whether or not a field is selectable */78#define Field_Is_Selectable(f) (((f)->opts & O_SELECTABLE)==O_SELECTABLE)79#define Field_Is_Not_Selectable(f) (((f)->opts & O_SELECTABLE)!=O_SELECTABLE)8081typedef struct typearg {82struct typearg *left;83struct typearg *right;84} TypeArgument;8586/* This is a dummy request code (normally invalid) to be used internally87with the form_driver() routine to position to the first active field88on the form89*/90#define FIRST_ACTIVE_MAGIC (-291056)9192#define ALL_FORM_OPTS ( \93O_NL_OVERLOAD |\94O_BS_OVERLOAD )9596#define ALL_FIELD_OPTS ( \97O_VISIBLE |\98O_ACTIVE |\99O_PUBLIC |\100O_EDIT |\101O_WRAP |\102O_BLANK |\103O_AUTOSKIP|\104O_NULLOK |\105O_PASSOK |\106O_STATIC )107108109#define C_BLANK ' '110#define is_blank(c) ((c)==C_BLANK)111112extern const FIELDTYPE* _nc_Default_FieldType;113114extern TypeArgument* _nc_Make_Argument(const FIELDTYPE*,va_list*,int*);115extern TypeArgument *_nc_Copy_Argument(const FIELDTYPE*,const TypeArgument*, int*);116extern void _nc_Free_Argument(const FIELDTYPE*,TypeArgument*);117extern bool _nc_Copy_Type(FIELD*, FIELD const *);118extern void _nc_Free_Type(FIELD *);119120extern int _nc_Synchronize_Attributes(FIELD*);121extern int _nc_Synchronize_Options(FIELD*,Field_Options);122extern int _nc_Set_Form_Page(FORM*,int,FIELD*);123extern int _nc_Refresh_Current_Field(FORM*);124extern FIELD* _nc_First_Active_Field(FORM*);125extern bool _nc_Internal_Validation(FORM*);126extern int _nc_Set_Current_Field(FORM*,FIELD*);127extern int _nc_Position_Form_Cursor(FORM*);128129130