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

form.h

Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2003,2004 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.h,v 0.20 2004/12/04 22:22:10 tom Exp $ */
00034 
00035 #ifndef FORM_H
00036 #define FORM_H
00037 
00038 #include <curses.h>
00039 #include <eti.h>
00040 
00041 #ifdef __cplusplus
00042   extern "C" {
00043 #endif
00044 
00045 #ifndef FORM_PRIV_H
00046 typedef void *FIELD_CELL;
00047 #endif
00048 
00049 #ifndef NCURSES_FIELD_INTERNALS
00050 #define NCURSES_FIELD_INTERNALS /* nothing */
00051 #endif
00052 
00053 typedef int Form_Options;
00054 typedef int Field_Options;
00055 
00056         /**********
00057         *  _PAGE  *
00058         **********/
00059 
00060 typedef struct {
00061   short pmin;           /* index of first field on page                 */
00062   short pmax;           /* index of last field on page                  */
00063   short smin;           /* index of top leftmost field on page          */
00064   short smax;           /* index of bottom rightmost field on page      */
00065 } _PAGE;
00066 
00067         /**********
00068         *  FIELD  *
00069         **********/
00070 
00071 typedef struct fieldnode {
00072   unsigned short        status;         /* flags                        */
00073   short                 rows;           /* size in rows                 */
00074   short                 cols;           /* size in cols                 */
00075   short                 frow;           /* first row                    */
00076   short                 fcol;           /* first col                    */
00077   int                   drows;          /* dynamic rows                 */
00078   int                   dcols;          /* dynamic cols                 */
00079   int                   maxgrow;        /* maximum field growth         */
00080   int                   nrow;           /* off-screen rows              */
00081   short                 nbuf;           /* additional buffers           */
00082   short                 just;           /* justification                */
00083   short                 page;           /* page on form                 */
00084   short                 index;          /* into form -> field           */
00085   int                   pad;            /* pad character                */
00086   chtype                fore;           /* foreground attribute         */
00087   chtype                back;           /* background attribute         */
00088   Field_Options         opts;           /* options                      */
00089   struct fieldnode *    snext;          /* sorted order pointer         */
00090   struct fieldnode *    sprev;          /* sorted order pointer         */
00091   struct fieldnode *    link;           /* linked field chain           */
00092   struct formnode *     form;           /* containing form              */
00093   struct typenode *     type;           /* field type                   */
00094   void *                arg;            /* argument for type            */
00095   FIELD_CELL *          buf;            /* field buffers                */
00096   void *                usrptr;         /* user pointer                 */
00097   /*
00098    * The wide-character configuration requires extra information.  Because
00099    * there are existing applications that manipulate the members of FIELD
00100    * directly, we cannot make the struct opaque.  Offsets of members up to
00101    * this point are the same in the narrow- and wide-character configuration.
00102    * But note that the type of buf depends on the configuration, and is made
00103    * opaque for that reason.
00104    */
00105   NCURSES_FIELD_INTERNALS
00106 } FIELD;
00107 
00108         /**************
00109         *  FIELDTYPE  *
00110         **************/
00111 
00112 typedef struct typenode {
00113   unsigned short        status;                 /* flags                */
00114   long                  ref;                    /* reference count      */
00115   struct typenode *     left;                   /* ptr to operand for | */
00116   struct typenode *     right;                  /* ptr to operand for | */
00117 
00118   void* (*makearg)(va_list *);                  /* make fieldtype arg   */
00119   void* (*copyarg)(const void *);               /* copy fieldtype arg   */
00120   void  (*freearg)(void *);                     /* free fieldtype arg   */
00121 
00122   bool  (*fcheck)(FIELD *,const void *);        /* field validation     */
00123   bool  (*ccheck)(int,const void *);            /* character validation */
00124 
00125   bool  (*next)(FIELD *,const void *);          /* enumerate next value */
00126   bool  (*prev)(FIELD *,const void *);          /* enumerate prev value */
00127 
00128 } FIELDTYPE;
00129 
00130         /*********
00131         *  FORM  *
00132         *********/
00133 
00134 typedef struct formnode {
00135   unsigned short        status;         /* flags                        */
00136   short                 rows;           /* size in rows                 */
00137   short                 cols;           /* size in cols                 */
00138   int                   currow;         /* current row in field window  */
00139   int                   curcol;         /* current col in field window  */
00140   int                   toprow;         /* in scrollable field window   */
00141   int                   begincol;       /* in horiz. scrollable field   */
00142   short                 maxfield;       /* number of fields             */
00143   short                 maxpage;        /* number of pages              */
00144   short                 curpage;        /* index into page              */
00145   Form_Options          opts;           /* options                      */
00146   WINDOW *              win;            /* window                       */
00147   WINDOW *              sub;            /* subwindow                    */
00148   WINDOW *              w;              /* window for current field     */
00149   FIELD **              field;          /* field [maxfield]             */
00150   FIELD *               current;        /* current field                */
00151   _PAGE *               page;           /* page [maxpage]               */
00152   void *                usrptr;         /* user pointer                 */
00153 
00154   void                  (*forminit)(struct formnode *);
00155   void                  (*formterm)(struct formnode *);
00156   void                  (*fieldinit)(struct formnode *);
00157   void                  (*fieldterm)(struct formnode *);
00158 
00159 } FORM;
00160 
00161 typedef void (*Form_Hook)(FORM *);
00162 
00163         /***************************
00164         *  miscellaneous #defines  *
00165         ***************************/
00166 
00167 /* field justification */
00168 #define NO_JUSTIFICATION        (0)
00169 #define JUSTIFY_LEFT            (1)
00170 #define JUSTIFY_CENTER          (2)
00171 #define JUSTIFY_RIGHT           (3)
00172 
00173 /* field options */
00174 #define O_VISIBLE               (0x0001U)
00175 #define O_ACTIVE                (0x0002U)
00176 #define O_PUBLIC                (0x0004U)
00177 #define O_EDIT                  (0x0008U)
00178 #define O_WRAP                  (0x0010U)
00179 #define O_BLANK                 (0x0020U)
00180 #define O_AUTOSKIP              (0x0040U)
00181 #define O_NULLOK                (0x0080U)
00182 #define O_PASSOK                (0x0100U)
00183 #define O_STATIC                (0x0200U)
00184 
00185 /* form options */
00186 #define O_NL_OVERLOAD           (0x0001U)
00187 #define O_BS_OVERLOAD           (0x0002U)
00188 
00189 /* form driver commands */
00190 #define REQ_NEXT_PAGE    (KEY_MAX + 1)  /* move to next page            */
00191 #define REQ_PREV_PAGE    (KEY_MAX + 2)  /* move to previous page        */
00192 #define REQ_FIRST_PAGE   (KEY_MAX + 3)  /* move to first page           */
00193 #define REQ_LAST_PAGE    (KEY_MAX + 4)  /* move to last page            */
00194 
00195 #define REQ_NEXT_FIELD   (KEY_MAX + 5)  /* move to next field           */
00196 #define REQ_PREV_FIELD   (KEY_MAX + 6)  /* move to previous field       */
00197 #define REQ_FIRST_FIELD  (KEY_MAX + 7)  /* move to first field          */
00198 #define REQ_LAST_FIELD   (KEY_MAX + 8)  /* move to last field           */
00199 #define REQ_SNEXT_FIELD  (KEY_MAX + 9)  /* move to sorted next field    */
00200 #define REQ_SPREV_FIELD  (KEY_MAX + 10) /* move to sorted prev field    */
00201 #define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field   */
00202 #define REQ_SLAST_FIELD  (KEY_MAX + 12) /* move to sorted last field    */
00203 #define REQ_LEFT_FIELD   (KEY_MAX + 13) /* move to left to field        */
00204 #define REQ_RIGHT_FIELD  (KEY_MAX + 14) /* move to right to field       */
00205 #define REQ_UP_FIELD     (KEY_MAX + 15) /* move to up to field          */
00206 #define REQ_DOWN_FIELD   (KEY_MAX + 16) /* move to down to field        */
00207 
00208 #define REQ_NEXT_CHAR    (KEY_MAX + 17) /* move to next char in field   */
00209 #define REQ_PREV_CHAR    (KEY_MAX + 18) /* move to prev char in field   */
00210 #define REQ_NEXT_LINE    (KEY_MAX + 19) /* move to next line in field   */
00211 #define REQ_PREV_LINE    (KEY_MAX + 20) /* move to prev line in field   */
00212 #define REQ_NEXT_WORD    (KEY_MAX + 21) /* move to next word in field   */
00213 #define REQ_PREV_WORD    (KEY_MAX + 22) /* move to prev word in field   */
00214 #define REQ_BEG_FIELD    (KEY_MAX + 23) /* move to first char in field  */
00215 #define REQ_END_FIELD    (KEY_MAX + 24) /* move after last char in fld  */
00216 #define REQ_BEG_LINE     (KEY_MAX + 25) /* move to beginning of line    */
00217 #define REQ_END_LINE     (KEY_MAX + 26) /* move after last char in line */
00218 #define REQ_LEFT_CHAR    (KEY_MAX + 27) /* move left in field           */
00219 #define REQ_RIGHT_CHAR   (KEY_MAX + 28) /* move right in field          */
00220 #define REQ_UP_CHAR      (KEY_MAX + 29) /* move up in field             */
00221 #define REQ_DOWN_CHAR    (KEY_MAX + 30) /* move down in field           */
00222 
00223 #define REQ_NEW_LINE     (KEY_MAX + 31) /* insert/overlay new line      */
00224 #define REQ_INS_CHAR     (KEY_MAX + 32) /* insert blank char at cursor  */
00225 #define REQ_INS_LINE     (KEY_MAX + 33) /* insert blank line at cursor  */
00226 #define REQ_DEL_CHAR     (KEY_MAX + 34) /* delete char at cursor        */
00227 #define REQ_DEL_PREV     (KEY_MAX + 35) /* delete char before cursor    */
00228 #define REQ_DEL_LINE     (KEY_MAX + 36) /* delete line at cursor        */
00229 #define REQ_DEL_WORD     (KEY_MAX + 37) /* delete word at cursor        */
00230 #define REQ_CLR_EOL      (KEY_MAX + 38) /* clear to end of line         */
00231 #define REQ_CLR_EOF      (KEY_MAX + 39) /* clear to end of field        */
00232 #define REQ_CLR_FIELD    (KEY_MAX + 40) /* clear entire field           */
00233 #define REQ_OVL_MODE     (KEY_MAX + 41) /* begin overlay mode           */
00234 #define REQ_INS_MODE     (KEY_MAX + 42) /* begin insert mode            */
00235 #define REQ_SCR_FLINE    (KEY_MAX + 43) /* scroll field forward a line  */
00236 #define REQ_SCR_BLINE    (KEY_MAX + 44) /* scroll field backward a line */
00237 #define REQ_SCR_FPAGE    (KEY_MAX + 45) /* scroll field forward a page  */
00238 #define REQ_SCR_BPAGE    (KEY_MAX + 46) /* scroll field backward a page */
00239 #define REQ_SCR_FHPAGE   (KEY_MAX + 47) /* scroll field forward  half page */
00240 #define REQ_SCR_BHPAGE   (KEY_MAX + 48) /* scroll field backward half page */
00241 #define REQ_SCR_FCHAR    (KEY_MAX + 49) /* horizontal scroll char       */
00242 #define REQ_SCR_BCHAR    (KEY_MAX + 50) /* horizontal scroll char       */
00243 #define REQ_SCR_HFLINE   (KEY_MAX + 51) /* horizontal scroll line       */
00244 #define REQ_SCR_HBLINE   (KEY_MAX + 52) /* horizontal scroll line       */
00245 #define REQ_SCR_HFHALF   (KEY_MAX + 53) /* horizontal scroll half line  */
00246 #define REQ_SCR_HBHALF   (KEY_MAX + 54) /* horizontal scroll half line  */
00247 
00248 #define REQ_VALIDATION   (KEY_MAX + 55) /* validate field               */
00249 #define REQ_NEXT_CHOICE  (KEY_MAX + 56) /* display next field choice    */
00250 #define REQ_PREV_CHOICE  (KEY_MAX + 57) /* display prev field choice    */
00251 
00252 #define MIN_FORM_COMMAND (KEY_MAX + 1)  /* used by form_driver          */
00253 #define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver          */
00254 
00255 #if defined(MAX_COMMAND)
00256 #  if (MAX_FORM_COMMAND > MAX_COMMAND)
00257 #    error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND
00258 #  elif (MAX_COMMAND != (KEY_MAX + 128))
00259 #    error Something is wrong -- MAX_COMMAND is already inconsistently defined.
00260 #  endif
00261 #else
00262 #  define MAX_COMMAND (KEY_MAX + 128)
00263 #endif
00264 
00265         /*************************
00266         *  standard field types  *
00267         *************************/
00268 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALPHA;
00269 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ALNUM;
00270 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_ENUM;
00271 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_INTEGER;
00272 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_NUMERIC;
00273 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_REGEXP;
00274 
00275         /************************************
00276         *  built-in additional field types  *
00277         *  They are not defined in SVr4     *
00278         ************************************/
00279 extern NCURSES_EXPORT_VAR(FIELDTYPE *) TYPE_IPV4;      /* Internet IP Version 4 address */
00280 
00281         /***********************
00282         *   Default objects    *
00283         ***********************/
00284 extern NCURSES_EXPORT_VAR(FORM *)       _nc_Default_Form;
00285 extern NCURSES_EXPORT_VAR(FIELD *)      _nc_Default_Field;
00286 
00287 
00288         /***********************
00289         *  FIELDTYPE routines  *
00290         ***********************/
00291 extern NCURSES_EXPORT(FIELDTYPE *) new_fieldtype (
00292                     bool (* const field_check)(FIELD *,const void *),
00293                     bool (* const char_check)(int,const void *));
00294 extern NCURSES_EXPORT(FIELDTYPE *) link_fieldtype(
00295                     FIELDTYPE *, FIELDTYPE *);
00296 
00297 extern NCURSES_EXPORT(int)      free_fieldtype (FIELDTYPE *);
00298 extern NCURSES_EXPORT(int)      set_fieldtype_arg (FIELDTYPE *,
00299                     void * (* const make_arg)(va_list *),
00300                     void * (* const copy_arg)(const void *),
00301                     void (* const free_arg)(void *));
00302 extern NCURSES_EXPORT(int)       set_fieldtype_choice (FIELDTYPE *,
00303                     bool (* const next_choice)(FIELD *,const void *),
00304                     bool (* const prev_choice)(FIELD *,const void *));
00305 
00306         /*******************
00307         *  FIELD routines  *
00308         *******************/
00309 extern NCURSES_EXPORT(FIELD *)  new_field (int,int,int,int,int,int);
00310 extern NCURSES_EXPORT(FIELD *)  dup_field (FIELD *,int,int);
00311 extern NCURSES_EXPORT(FIELD *)  link_field (FIELD *,int,int);
00312 
00313 extern NCURSES_EXPORT(int)      free_field (FIELD *);
00314 extern NCURSES_EXPORT(int)      field_info (const FIELD *,int *,int *,int *,int *,int *,int *);
00315 extern NCURSES_EXPORT(int)      dynamic_field_info (const FIELD *,int *,int *,int *);
00316 extern NCURSES_EXPORT(int)      set_max_field ( FIELD *,int);
00317 extern NCURSES_EXPORT(int)      move_field (FIELD *,int,int);
00318 extern NCURSES_EXPORT(int)      set_field_type (FIELD *,FIELDTYPE *,...);
00319 extern NCURSES_EXPORT(int)      set_new_page (FIELD *,bool);
00320 extern NCURSES_EXPORT(int)      set_field_just (FIELD *,int);
00321 extern NCURSES_EXPORT(int)      field_just (const FIELD *);
00322 extern NCURSES_EXPORT(int)      set_field_fore (FIELD *,chtype);
00323 extern NCURSES_EXPORT(int)      set_field_back (FIELD *,chtype);
00324 extern NCURSES_EXPORT(int)      set_field_pad (FIELD *,int);
00325 extern NCURSES_EXPORT(int)      field_pad (const FIELD *);
00326 extern NCURSES_EXPORT(int)      set_field_buffer (FIELD *,int,const char *);
00327 extern NCURSES_EXPORT(int)      set_field_status (FIELD *,bool);
00328 extern NCURSES_EXPORT(int)      set_field_userptr (FIELD *, void *);
00329 extern NCURSES_EXPORT(int)      set_field_opts (FIELD *,Field_Options);
00330 extern NCURSES_EXPORT(int)      field_opts_on (FIELD *,Field_Options);
00331 extern NCURSES_EXPORT(int)      field_opts_off (FIELD *,Field_Options);
00332 
00333 extern NCURSES_EXPORT(chtype)   field_fore (const FIELD *);
00334 extern NCURSES_EXPORT(chtype)   field_back (const FIELD *);
00335 
00336 extern NCURSES_EXPORT(bool)     new_page (const FIELD *);
00337 extern NCURSES_EXPORT(bool)     field_status (const FIELD *);
00338 
00339 extern NCURSES_EXPORT(void *)   field_arg (const FIELD *);
00340 
00341 extern NCURSES_EXPORT(void *)   field_userptr (const FIELD *);
00342 
00343 extern NCURSES_EXPORT(FIELDTYPE *)      field_type (const FIELD *);
00344 
00345 extern NCURSES_EXPORT(char *)   field_buffer (const FIELD *,int);
00346 
00347 extern NCURSES_EXPORT(Field_Options)    field_opts (const FIELD *);
00348 
00349         /******************
00350         *  FORM routines  *
00351         ******************/
00352 
00353 extern NCURSES_EXPORT(FORM *)   new_form (FIELD **);
00354 
00355 extern NCURSES_EXPORT(FIELD **) form_fields (const FORM *);
00356 extern NCURSES_EXPORT(FIELD *)  current_field (const FORM *);
00357 
00358 extern NCURSES_EXPORT(WINDOW *) form_win (const FORM *);
00359 extern NCURSES_EXPORT(WINDOW *) form_sub (const FORM *);
00360 
00361 extern NCURSES_EXPORT(Form_Hook)        form_init (const FORM *);
00362 extern NCURSES_EXPORT(Form_Hook)        form_term (const FORM *);
00363 extern NCURSES_EXPORT(Form_Hook)        field_init (const FORM *);
00364 extern NCURSES_EXPORT(Form_Hook)        field_term (const FORM *);
00365 
00366 extern NCURSES_EXPORT(int)      free_form (FORM *);
00367 extern NCURSES_EXPORT(int)      set_form_fields (FORM *,FIELD **);
00368 extern NCURSES_EXPORT(int)      field_count (const FORM *);
00369 extern NCURSES_EXPORT(int)      set_form_win (FORM *,WINDOW *);
00370 extern NCURSES_EXPORT(int)      set_form_sub (FORM *,WINDOW *);
00371 extern NCURSES_EXPORT(int)      set_current_field (FORM *,FIELD *);
00372 extern NCURSES_EXPORT(int)      field_index (const FIELD *);
00373 extern NCURSES_EXPORT(int)      set_form_page (FORM *,int);
00374 extern NCURSES_EXPORT(int)      form_page (const FORM *);
00375 extern NCURSES_EXPORT(int)      scale_form (const FORM *,int *,int *);
00376 extern NCURSES_EXPORT(int)      set_form_init (FORM *,Form_Hook);
00377 extern NCURSES_EXPORT(int)      set_form_term (FORM *,Form_Hook);
00378 extern NCURSES_EXPORT(int)      set_field_init (FORM *,Form_Hook);
00379 extern NCURSES_EXPORT(int)      set_field_term (FORM *,Form_Hook);
00380 extern NCURSES_EXPORT(int)      post_form (FORM *);
00381 extern NCURSES_EXPORT(int)      unpost_form (FORM *);
00382 extern NCURSES_EXPORT(int)      pos_form_cursor (FORM *);
00383 extern NCURSES_EXPORT(int)      form_driver (FORM *,int);
00384 extern NCURSES_EXPORT(int)      set_form_userptr (FORM *,void *);
00385 extern NCURSES_EXPORT(int)      set_form_opts (FORM *,Form_Options);
00386 extern NCURSES_EXPORT(int)      form_opts_on (FORM *,Form_Options);
00387 extern NCURSES_EXPORT(int)      form_opts_off (FORM *,Form_Options);
00388 extern NCURSES_EXPORT(int)      form_request_by_name (const char *);
00389 
00390 extern NCURSES_EXPORT(const char *)     form_request_name (int);
00391 
00392 extern NCURSES_EXPORT(void *)   form_userptr (const FORM *);
00393 
00394 extern NCURSES_EXPORT(Form_Options)     form_opts (const FORM *);
00395 
00396 extern NCURSES_EXPORT(bool)     data_ahead (const FORM *);
00397 extern NCURSES_EXPORT(bool)     data_behind (const FORM *);
00398 
00399 #ifdef __cplusplus
00400   }
00401 #endif
00402 
00403 #endif  /* FORM_H */

© sourcejam.com 2005-2008