[comp.sys.ibm.pc] twindow.h

wang@m.cs.uiuc.edu (Eric Wang) (11/06/89)

Somebody recently requested a copy of twindow.h, the header file for Al
Stevens' PD window system for Turbo C.  After rummaging through my ziphives,
I've finally unearthed my copy of it.  Note that this represents the header
file after it had evolved in a real commercial environment for about one
standard year, so it's not exactly like the book.  All of the differences
should be additions that won't harm anything already written, i.e. it's
backwards-compatible.  I don't think I removed anything.

----- cut here ---- cut here -----
/*****************************************************************************
 *  twindow.h -- Header file for twindow.lib.
 *****************************************************************************/
#define YES     1
#define NO      0
#define ERROR  -1
#define OK      0

/*****************************************************************************
*                                                                            *
*                          Window Colors                                     *
*                                                                            *
*****************************************************************************/
#define RED     4
#define GREEN   2
#define BLUE    1
#define WHITE   (RED+GREEN+BLUE)
#define YELLOW  (RED+GREEN)
#define AQUA    (GREEN+BLUE)
#define MAGENTA (RED+BLUE)
#define BLACK   0
#define BRIGHT  8
#define DIM     0


#define BORDER  0
#define TITLE   1
#define ACCENT  2
#define NORMAL  3
#define ALL     4

/*****************************************************************************
*                                                                            *
*                       Window Controller Structures                         *
*                                                                            *
*****************************************************************************/
typedef struct field {           /* Data entry field description            */
   char *fmask;                  /* Field data entry mask                   */
   int fprot;                    /* Field protection                        */
   char *fbuff;                  /* Field buffer                            */
   int ftype;                    /* Field type                              */
   int frow;                     /* Field row                               */
   int fcol;                     /* Field column                            */
   void (*fhelp)();              /* Field help function                     */
   char *fhwin;                  /* Field help window                       */
   int flx, fly;                 /* Help window location                    */
   int (*finit)();               /* Field initialization funtion (ERW)      */
   int (*fvalid)();              /* Field validation function               */
   struct field *fnxt;           /* Field "below" current field             */
   struct field *fprv;           /* Field "above" current field             */
   struct field *fright;         /* Field to "right" of current field       */
   struct field *fleft;          /* Field to "left" of current field        */
} FIELD;

typedef struct _wnd {
   int _wv;                      /* True if window is visible               */
   int _hd;                      /* True if window was hidden               */
   char *_ws;                    /* Points to window save block             */
   char *_tl;                    /* Points to window title                  */
   int _wx;                      /* NW x coordinate                         */
   int _wy;                      /* NW y coordinate                         */
   int _ww;                      /* Window width                            */
   int _wh;                      /* Window height                           */
   int _wsp;                     /* Scroll pointer                          */
   int _sp;                      /* Selection pointer                       */
   int _cr;                      /* Cursor x location                       */
   int btype;                    /* Border type                             */
   int wcolor[4];                /* Colors for window                       */
   int _pn;                      /* Previous normal color                   */
   struct _wnd *_nx;             /* Points to next window                   */
   struct _wnd *_pv;             /* Points to previous window               */
   FIELD *_fh;                   /* Points to first data entry field        */
   FIELD *_fc;                   /* Current data entry field                */
   FIELD *_ft;                   /* Points to last data entry field         */
} WINDOW;

typedef struct w_menu {
   char *mname;
   char **mselcs;
   void (**func)();
} MENU;

#define SAV     (wnd->_ws)
#define WTITLE  (wnd->_tl)
#define COL     (wnd->_wx)
#define ROW     (wnd->_wy)
#define WIDTH   (wnd->_ww)
#define HEIGHT  (wnd->_wh)
#define SCROLL  (wnd->_wsp)
#define SELECT  (wnd->_sp)
#define WCURS   (wnd->_cr)
#define WBORDER (wnd->wcolor[BORDER])
#define WTITLEC (wnd->wcolor[TITLE])
#define WACCENT (wnd->wcolor[ACCENT])
#define WNORMAL (wnd->wcolor[NORMAL])
#define PNORMAL (wnd->_pn)
#define BTYPE   (wnd->btype)
#define NEXT    (wnd->_nx)
#define PREV    (wnd->_pv)
#define WCOLOR  (wnd->wcolor)
#define VISIBLE (wnd->_wv)
#define HIDDEN  (wnd->_hd)
#define FHEAD   (wnd->_fh)
#define FCURR   (wnd->_fc)
#define FTAIL   (wnd->_ft)

#define NW      (wcs[wnd->btype].nw)
#define NE      (wcs[wnd->btype].ne)
#define SE      (wcs[wnd->btype].se)
#define SW      (wcs[wnd->btype].sw)
#define SIDE    (wcs[wnd->btype].side)
#define LINE    (wcs[wnd->btype].line)

/*****************************************************************************
 *  Exports
 *****************************************************************************/
extern int kbdwait;

/*****************************************************************************
*                                                                            *
*                 Function prototypes and macros                             *
*                                                                            *
*****************************************************************************/

/*****************************************************************************
*                                                                            *
*              General-purpose functions and macros                          *
*                                                                            *
*****************************************************************************/
void clear(int, int, int, int);         /* ULC = 0,0.   */
void cursor(int, int);                  /* ULC = 0,0.   */
int vmode(void);
void locate(int, int);
void cur_cursor(int *, int *);
int cursor_type(void);
void set_cursor_type(int);
int get_char(void);
int scroll_lock(void);
void vpoke(unsigned, unsigned, unsigned);
int vpeek(unsigned, unsigned);

/*****************************************************************************
*                                                                            *
*                 Window functions and macros                                *
*                                                                            *
*****************************************************************************/
WINDOW *establish_window(int, int, int, int);
#define ESTABLISH_WINDOW(x, y, h, w)                    \
    if ((wnd = establish_window(x, y, h, w)) == NULL)   \
        return(ERROR)

void set_border(WINDOW *, int);
void set_colors(WINDOW *, int, int, int, int);
void set_intensity(WINDOW *, int);
void set_title(WINDOW *, char *);
void redraw_window(WINDOW *);
void display_window(WINDOW *);
void delete_window(WINDOW *);
void clear_window(WINDOW *);
void hide_window(WINDOW *);
void wprintf(WINDOW *, char *, ...);
void wputchar(WINDOW *, int);
void close_all(void);
void wcursor(WINDOW *, int, int);
void error_message(char *);
void clear_error(void);
void error_msg(char *);
void confirm_message(char *);
void clear_confirm(void);
int  confirm_msg(char *);
int get_selection(WINDOW *, int *, char *);

#define reverse_video(wnd) wnd->wcolor[3]=wnd->wcolor[2]
#define normal_video(wnd) wnd->wcolor[3]=wnd->_pn
#define rmove_window(wnd, x, y) repos_wnd(wnd, x, y, 0)
#define move_window(wnd, x, y) repos_wnd(wnd, COL-x, ROW-y, 0)
#define forefront(wnd) repos_wnd(wnd, 0, 0, 1)
#define rear_window(wnd) repos_wnd(wnd, 0, 0, -1)
#define memcpy(d, s, n) memmove(d, s, n)

/*****************************************************************************
*                                                                            *
*                 Internal to window processes                               *
*                                                                            *
*****************************************************************************/
void accent(WINDOW *);
void deaccent(WINDOW *);
void scroll(WINDOW *, int);
void repos_wnd(WINDOW *, int, int, int);
void acline(WINDOW *, int);

#define accent(wnd) acline(wnd, WACCENT)
#define deaccent(wnd) acline(wnd, WNORMAL)
#define clr(bg,fg,in) ((fg)|(bg<<4)|(in))
#define vad(x,y) ((y)*160+(x)*2)

#ifdef FASTWINDOWS
    #define chat(ch,at) ((ch&255)|(at<<8))
    #define displ(w,x,y,c,a) vpoke(VSG,vad(x+COL,y+ROW),chat(c,a))
    #define dget(w,x,y) vpeek(VSG,vad(x+COL,y+ROW))
    #define verify_wnd(w) (*(w)=listtail)!=0
#else
    void displ(WINDOW *, int, int, int, int);
#endif

/*****************************************************************************
*                                                                            *
*                       Menu function                                        *
*                                                                            *
*****************************************************************************/
void menu_select(char *, MENU *, int);

/*****************************************************************************
*                                                                            *
*                       Help functions                                       *
*                                                                            *
*****************************************************************************/
void load_help(char *);
void set_help(char *, int, int);

/*****************************************************************************
*                                                                            *
*                       Data entry functions                                 *
*                                                                            *
*****************************************************************************/
void init_template(WINDOW *);
FIELD *establish_field(WINDOW *, int, int, char *, char *, char);
#define ESTABLISH_FIELD(x, y, m, b, t)                          \
    if ((fld = establish_field(wnd, x, y, m, b, t)) == NULL)    \
        return(ERROR)

void clear_template(WINDOW *);
void field_tally(WINDOW *);
void data_value(WINDOW *, FIELD *);
void data_update(WINDOW *, FIELD *, char *);
int  data_entry(WINDOW *);
void wprompt(WINDOW *, int, int, char *);
void field_window(FIELD *, int, int, char *);
void home_field(WINDOW *wnd);

void right_justify(char *);
void right_justify_zero_fill(char *);
int spaces(char *);

#define field_protect(f,s)  f->fprot  = s
#define field_help(f,h)     f->fhelp  = h
#define field_init(f,v)     f->finit  = v
#define field_validate(f,v) f->fvalid = v

/* eof */