/**
*
*  BWINDOW.H	Header file for Turbo C TOOLS Window Functions
*
*  Version	6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
*
**/


#ifndef DEF_BWINDOW		/* Prevent second reading of	    */
#define DEF_BWINDOW  1		/* these definitions.		    */

#include <bscreens.h>		/* Turbo C TOOLS Screen functions.  */
#include <bkeybrd.h>		/* Turbo C TOOLS Keyboard functions.*/

#define WN_EXT_ERROR 1		/* 1 if wnerror() is external, 0 if */
				/* it's a macro.                    */



/********************************************************************/
/* Definitions of data types.					    */
/********************************************************************/

typedef struct			/* LOC structure:		    */
{				/* row and column relative to a     */
    int row,col;		/* rectangular region.		    */
} LOC;


typedef struct			/* REGION structure:		    */
{				/*   rectangular region on a	    */
				/*   screen.			    */
    LOC ul;			/* Upper left  corner.		    */
    LOC lr;			/* Lower right corner.		    */
} REGION;


typedef struct			/* CELL structure:		    */
{				/* character and attribute byte on  */
    char ch,attr;		/* a PC screen. 		    */
} CELL;


typedef struct			/* DIM structure:		    */
{				/* height and width of a	    */
    int h,w;			/* rectangular region.		    */
} DIM;


typedef struct			/* IMAGE structure:		    */
{				/*   a copy of a rectangular	    */
				/*   portion of a screen's data.    */
    DIM  dim;			/* Dimensions of the rectangle.     */
    CELL *pdata;		/* Pointer to array of cells	    */
				/*   containing the data, row	    */
				/*   by row.			    */
} IMAGE;


typedef struct			/* WHERE structure:		    */
{				/* device, page, and location	    */
				/* where a window may be shown.     */
				/*				    */
    int  dev;			/* Device where shown:	COLOR,	    */
				/* MONO, or ABSENT if not shown.    */
				/*				    */
    int  page;			/* Video page number:  0 to 7	    */
				/*				    */
    LOC  corner;		/* Upper left corner of region	    */
				/* where window data is shown	    */
				/* (does not include border).	    */
} WHERE;


typedef struct bjoint {
    unsigned char  row; 	/* Row and column of joint relative */
    unsigned char  col; 	/* to upper-left of border.  (0,0). */
    char	   jtype;	/* IBM graphic char for joint.	    */
    char	   _dummy;	/* Structure alignment. 	    */
    struct bjoint *next;	/* Pointer to next joint in linked  */
} BJOINT;			/* list of joints.		    */


typedef struct {
    int     type;		/* Type of border:		    */
				/*    0 = no border.		    */
				/*   31 = Character "ch" border.    */
				/*				    */
				/*	  T R B L		    */
				/*	  o t o f		    */
				/*	  p   t t		    */
				/*				    */
				/*    1 = S S S S no title.	    */
				/*    2 = S S S D no title.	    */
				/*    3 = D S S S no title.	    */
				/*    4 = D S S D no title.	    */
				/*    5 = S D S S no title.	    */
				/*    6 = S D S D no title.	    */
				/*    7 = D D S S no title.	    */
				/*    8 = D D S D no title.	    */
				/*    9 = S S D S no title.	    */
				/*   10 = S S D D no title.	    */
				/*   11 = D S D S no title.	    */
				/*   12 = D S D D no title.	    */
				/*   13 = S D D S no title.	    */
				/*   14 = S D D D no title.	    */
				/*   15 = D D D S no title.	    */
				/*   16 = D D D D no title.	    */
				/*				    */
				/* OR the above with:		    */
				/*   0x0020- top-left-title	    */
				/*   0x0040- top-center-title	    */
				/*   0x0080- top-right-title	    */
				/*   0x0100- bottom-left-title	    */
				/*   0x0200- bottom-center-title    */
				/*   0x0400- bottom-right-title     */
				/*				    */
				/* OR the above with:		    */
				/*   0x0800- border has joints.     */
				/*				    */
    int     attr;		/* Attribute of border. 	    */
    char    ch; 		/* Border character (if type==0).   */
    char    _dummy;		/* Structure alignment. 	    */
    char   *pttitle;		/* Title on top border. 	    */
    char   *pbtitle;		/* Title on bottom border.	    */
    int     ttattr;		/* Attributes of top title.	    */
    int     btattr;		/* Attributes of bottom title.	    */
    BJOINT *pjoints;		/* Pointer to linked list of joints.*/
} BORDER;


typedef enum
{				/* Values for the WN_SENSOR type    */
				/*   field.			    */
    WN_LEFT_ARROW,		/* Left scroll arrow.		    */
    WN_RIGHT_ARROW,		/* Right scroll arrow.		    */
    WN_UP_ARROW,		/* Up scroll arrow.		    */
    WN_DOWN_ARROW,		/* Down scroll arrow.		    */
    WN_IN_WINDOW,		/* Inside window's viewport.        */
    WN_ON_BORDER,		/* On window's border.              */
    WN_OUT_WINDOW		/* Outside the window completely.   */
} WN_SENSOR_TYPE;

#define WN_LAST_SENSOR	WN_OUT_WINDOW


#define WN_VIEWPORT 0
#define WN_DATA     1
#define WN_SCREEN   2

typedef struct wn_sensor	/* WN_SENSOR structure: linked list */
{				/*   of window sensors. 	    */
    WN_SENSOR_TYPE    type;	/* The type of sensor this is.	    */
    unsigned	      relative; /* Whether the sensor is relative   */
				/*   to the screen, viewport, or    */
				/*   data area. 		    */
    REGION	      hot;	/* The "hot" region for the sensor. */
    LOC 	      corner;	/* Displayed corner for the sensor. */
    DIM 	      size;	/* Displayed size of the sensor.    */
    CELL	      *pimage;	/* Sensor's image.                  */
    struct wn_sensor  *pnext;	/* Pointers to the next and	    */
    struct wn_sensor  *pprev;	/* previous sensors in the list.    */
} WN_SENSOR;


typedef enum			/* WN_ACTION:			    */
{				/*   values for the WN_EVENT action */
				/*   field.			    */
    WN_NULL,			/* No action.			    */
    WN_SCROLL_LEFT,		/* Move left.			    */
    WN_SCROLL_RIGHT,		/* Move right.			    */
    WN_SCROLL_UP,		/* Move up.			    */
    WN_SCROLL_DOWN,		/* Move down.			    */
    WN_PAGE_LEFT,		/* Page left.			    */
    WN_PAGE_RIGHT,		/* Page right.			    */
    WN_PAGE_UP, 		/* Page up.			    */
    WN_PAGE_DOWN,		/* Page down.			    */
    WN_LEFT_EDGE,		/* Go to left edge.		    */
    WN_RIGHT_EDGE,		/* Go to right edge.		    */
    WN_TOP_EDGE,		/* Go to top edge.		    */
    WN_BOTTOM_EDGE,		/* Go to bottom edge.		    */
    WN_ABORT,			/* Abort read.			    */
    WN_TRANSMIT,		/* Finish read. 		    */
    WN_INVALID_ACTION		/* Invalid window action.	    */
} WN_ACTION;


#define WN_ABSENT_EVENT 0
#define WN_KB_EVENT	1
#define WN_MOUSE_EVENT	2


typedef struct			/* MOUSE_EVENT structure:	    */
{				/*				    */
    unsigned long   event;	/*   Mouse characteristics to pay   */
    unsigned long   ignore;	/*   attention to & ignore.	    */
    unsigned	    location;	/*   Location code.		    */
} MOUSE_EVENT;


typedef struct
{				/* WN_EVENT structure:		    */
    unsigned	     event_type;/* WN_KB_EVENT or WN_MOUSE_EVENT.   */
    union			/* event union: 		    */
    {				/* The basic data of a keyboard or  */
	KEY_SEQUENCE keystroke; /* mouse event. 		    */
	MOUSE_EVENT  mouse;	/*				    */
    } event;			/*				    */
    void	     *pdata;	/* Event related data.		    */
    unsigned	     data_size; /* Size of data pointed to by pdata.*/
} WN_EVENT;


typedef struct wn_event_list	       /* WN_EVENT_LIST structure:  */
{				       /*   WN_EVENT, identifying   */
    unsigned		  signature;   /*   signature, & pointers   */
    WN_EVENT		  win_event;   /*   to next and previous    */
    struct wn_event_list  *pnext;      /*   items in event list.    */
    struct wn_event_list  *pprev;
} WN_EVENT_LIST;



typedef struct			/* BWINDOW structure:		    */
{				/*   everything needed to control   */
				/*   an individual window.	    */
				/*				    */
    unsigned signature; 	/* Identifying signature.	    */
				/*				    */
    LOC      cur_loc;		/* Location of window's own         */
				/* cursor relative to window's      */
				/* data area.			    */
				/*				    */
    CUR_TYPE cur_type;		/* Cursor type. 		    */
				/*				    */
    IMAGE    img;		/* Contents of data area.	    */
				/*				    */
    DIM      view_size; 	/* Size of window's viewport.       */
				/*				    */
    LOC      data_origin;	/* Coordinates of data area which   */
				/* appear at (0,0) in the viewport. */
				/*				    */
    WHERE    where_shown;	/* Where window is currently	    */
				/* shown.			    */
				/*				    */
    IMAGE    prev;		/* Previous contents of screen	    */
				/* (before window was shown),	    */
				/* including data under border.     */
				/*				    */
    WHERE    where_prev;	/* Region occupied by window	    */
				/* (including border).		    */
				/*				    */
    struct bwin_node *pnode;	/* Pointer to window node	    */
				/* among all windows on a video     */
				/* display page.		    */
				/*				    */
    BORDER   bord;		/* Border description.		    */
				/*				    */
    WN_SENSOR *psensors;	/* Window sensor list.		    */
				/*				    */
    WN_EVENT_LIST *pevent_list; /* Window event list.		    */
				/*				    */
    int      attr;		/* Default attributes for data	    */
				/* area.			    */
    unsigned cur_left_marg,	/* Left, right, top, and bottom     */
	     cur_right_marg,	/* margins to maintain during	    */
	     cur_top_marg,	/* cursor "auto-track" feature.     */
	     cur_bottom_marg;	/*				    */

    struct			/* "options" substructure:          */
    {				/*   items set by user request.     */
				/*				    */
	unsigned delayed   : 1; /* Output postponed until next	    */
				/* update.			    */
				/*				    */
	unsigned cur_off   : 1; /* Cursor invisible.		    */
				/*				    */
	unsigned removable : 1; /* Removable (hence previous	    */
				/* contents of screen must be	    */
				/* preserved).			    */
				/*				    */
	unsigned hidden    : 1; /* Invisible, yet attached to a     */
				/* location on a display page.	    */
				/*				    */
	unsigned cur_track : 1; /* Always keep cursor visible in    */
				/* the viewport.		    */
				/*				    */
	unsigned _dummy    :11; /* Pad to word boundary 	    */
    } options;

    struct			/* "internals" substructure:        */
    {				/*   not directly set by user.	    */
				/*				    */
	unsigned frozen     :1; /* Updates postponed involuntarily. */
				/*				    */
	unsigned dirty	    :1; /* Output request(s) are	    */
				/* awaiting update.		    */
				/*				    */
	unsigned		/* Some portion of data area is     */
	    any_data_covered:1; /* covered by another window.	    */
				/*				    */
	unsigned cur_frozen :1; /* Not selected for visible	    */
				/* cursor.			    */
				/*				    */
	unsigned temp_hid   :1; /* Temporarily hidden by	    */
				/* internal operations. 	    */
				/*				    */
	unsigned _dummy    :11; /* Pad to word boundary 	    */
    } internals;
} BWINDOW;


typedef struct bwin_node	/* WIN_NODE structure:		    */
{				/*   node in the linked lists which */
				/*   govern the hierarchy of	    */
				/*   windows on each display page.  */
				/*				    */
    unsigned signature; 	/* Identifying signature.	    */
				/*				    */
    struct bwin_node *above;	/* Window above this one (or	    */
				/* NIL if this is top window).	    */
				/*				    */
    struct bwin_node *below;	/* Window below this one (or	    */
				/* NIL if this is bottom window).   */
				/*				    */
    BWINDOW	     *pwin;	/* BWINDOW structure belonging	    */
				/* to this node.		    */
} WIN_NODE;



/********************************************************************/
/* Internal Data Types. 					    */
/********************************************************************/

typedef struct
{
    WN_ACTION	    action;	    /* The action to be taken.	    */
    KEY_SEQUENCE    key_sequence;   /* Key sequence to trigger it.  */
} WN_KEY;


typedef struct
{
    WN_ACTION	    action;	    /* The action to be taken.	    */
    MOUSE_EVENT     mouse;	    /* Mouse event to trigger it.   */
} WN_MOUSE;


/********************************************************************/
/* Internal Windows Macros.					    */
/********************************************************************/

		/* Signature to identify genuine BWINDOW structure. */
#define BWIN_SIGN   0xe928
#define BWIN_DEAD	 0

		/* Signature to identify genuine WIN_NODE structure.*/
#define BNODE_SIGN  0xd928
#define BNODE_DEAD	 0

		/* Signature to identify genuine WN_EVENT_LIST	    */
		/* structure.					    */
#define BEVENT_SIGN 0x65ab
#define BEVENT_DEAD	 0

				/* Height of a REGION		    */
#define REGION_H(region) ((region).lr.row - (region).ul.row + 1)

				/* Width of a REGION		    */
#define REGION_W(region) ((region).lr.col - (region).ul.col + 1)

#define BBRD_HASJOINTS	  0x800
#define BBRD_TYPE	  0x01f
#define BBRD_TITLE	  0x7e0

#define B_WNPRBF_SIZE	  1024

#define B_NATIVE_MAX_ROWS 25	/* Max rows supported by compiler's */
				/* native text windows. 	    */

#define wnreterr(errnum) return ((wnerror (errnum)), NIL)
#define wnreterz(errnum) return ((wnerror (errnum)), 0)
#define wnretern(errnum) return (wnerror (errnum))

#define wnreterv(errnum)					     \
    {								     \
	wnerror (errnum);					     \
	return; 						     \
    }

#define wnvalidn(pnode) 					     \
    {								     \
	if (wnvalnod (pnode) == NIL)				     \
	    wnreterr (WN_BAD_NODE);				     \
    }

#define wnvalidw(pwin)						     \
    {								     \
	if (wnvalwin (pwin) == NIL)				     \
	    wnreterr (WN_BAD_WIN);				     \
    }

#define wnvalide(pevent)					     \
    {								     \
	if (wnvalevn (pevent) == NIL)				     \
	    wnreterr (WN_BAD_EVENT);				     \
    }

#define wnvalnod(pnode)  (wnvalno0((pnode),(BNODE_SIGN)))

#define wnvalwin(pwin)	 (wnvalwi0((pwin),(BWIN_SIGN)))

#define wnvalevn(pevent) (wnvalev0((pevent),(BEVENT_SIGN)))

		/* Construct a new attribute from a given attribute */
		/* and fore and back, either of which may be -1.    */
#define wndoattr(attr, fore, back)				     \
	utnybbyt ((back) == -1 ? uthinyb (attr) : (back),	     \
		  (fore) == -1 ? utlonyb (attr) : (fore))

		/* Update a window's image.                         */
#define wnputimg(pwin)						     \
	wnnupblk((pwin), 0, 0, (wndata_h(pwin) - 1),		     \
		  (wndata_w(pwin) - 1), WN_UPDATE)

		/* Macros to find a window's dimensions.            */

		/* Width & height of data area (no border).	    */
#define wndata_w(pwin)	((pwin)->img.dim.w)
#define wndata_h(pwin)	((pwin)->img.dim.h)

		/* Width & height of window's border.               */
#define wnbord_w(pwin)	((pwin)->prev.dim.w)
#define wnbord_h(pwin)	((pwin)->prev.dim.h)

		/* Width & height of window's viewport (no border). */
#define wnview_w(pwin)	((pwin)->view_size.w)
#define wnview_h(pwin)	((pwin)->view_size.h)


/********************************************************************/
/* Error codes. 						    */
/********************************************************************/

#define WN_NO_ERROR	    0
#define WN_NO_MEMORY	    1
#define WN_ILL_DIM	    2
#define WN_NULL_PTR	    3
#define WN_BAD_WIN	    4
#define WN_BAD_DEV	    5
#define WN_BAD_PAGE	    6
#define WN_BAD_NODE	    7
#define WN_ALREADY_SHOWN    8
#define WN_NOT_SHOWN	    9
#define WN_CANT_HIDE	   10
#define WN_COVERED	   11
#define WN_BAD_OPT	   12
#define WN_HARD 	   13
#define WN_ILL_VALUE	   14
#define WN_PR_OVERFLOW	   15

#define WN_NO_EVENT	   30
#define WN_EVENT_EXISTS    31
#define WN_BAD_EVENT	   32
#define WN_NO_EXIT	   33



/********************************************************************/
/* Constants (type of borders and title(s)) for WNPUTBOR/WNDSPLAY.  */
/********************************************************************/

#define BBRD_NO_BORDER 0x000
#define BBRD_CHAR      0x01f

		/* The letters in the part after the underscore in  */
		/* the following definitions are symbolic names for */
		/* line styles.  A border style with double lines   */
		/* on the top and left, and single lines on the     */
		/* right and bottom would be BBRD_DSDS.  The order  */
		/* of sides in the definition is clockwise from the */
		/* top. 					    */
#define BBRD_SSSS      0x001
#define BBRD_SSSD      0x002
#define BBRD_DSSS      0x003
#define BBRD_DSSD      0x004
#define BBRD_SDSS      0x005
#define BBRD_SDSD      0x006
#define BBRD_DDSS      0x007
#define BBRD_DDSD      0x008
#define BBRD_SSDS      0x009
#define BBRD_SSDD      0x00a
#define BBRD_DSDS      0x00b
#define BBRD_DSDD      0x00c
#define BBRD_SDDS      0x00d
#define BBRD_SDDD      0x00e
#define BBRD_DDDS      0x00f
#define BBRD_DDDD      0x010

		/* The letters in the part after the underscore in  */
		/* the following definitions are symbolic names for */
		/* title styles.  A title style with a top centered */
		/* title would be BBRD_TCT; one with a bottom right */
		/* title would be BBRD_BRT, and so on.		    */
#define BBRD_NO_TITLE  0x000
#define BBRD_TLT       0x020
#define BBRD_TCT       0x040
#define BBRD_TRT       0x080
#define BBRD_BLT       0x100
#define BBRD_BCT       0x200
#define BBRD_BRT       0x400



/********************************************************************/
/* Constants (direction of scroll) for WNSCRBLK.		    */
/********************************************************************/

#define WNSCR_UP    0
#define WNSCR_DOWN  1
#define WNSCR_RIGHT 2
#define WNSCR_LEFT  3



/********************************************************************/
/* Constants (option OR values) for WNWRSTRN.			    */
/********************************************************************/

#define WN_NO_UPDATE  0x04
#define WN_UPDATE     0x00
#define WN_LF_LF      0x08
#define WN_LF_CRLF    0x00
#define WN_NO_SCROLL  0x10
#define WN_SCROLL     0x00
#define WN_NO_TRACK   0x20
#define WN_CHAR_TRACK 0x00



/********************************************************************/
/* Window control items & status items for WNGETOPT & WNSETOPT.     */
/* Negative item codes require the window to be currently	    */
/* displayed (although it may be hidden).			    */
/********************************************************************/

#define WN_DEVICE	     1	/* Where the window is		    */
#define WN_PAGE 	   (-2) /* displayed			    */
#define WN_ROW_CORNER	   (-3) /*				    */
#define WN_COL_CORNER	   (-4) /*				    */
				/*				    */
#define WN_HIDDEN	   (-5) /* Whether it's hidden.             */
				/*				    */
#define WN_CUR_OFF	     6	/* Cursor on/off state		    */
#define WN_CUR_HIGH	     7	/* Cursor scan lines		    */
#define WN_CUR_LOW	     8	/*				    */

				/* User-controllable options	    */
#define WN_DELAYED	     9	/*				    */
#define WN_REMOVABLE	    10	/*				    */

#define WN_FROZEN	    11	/* Internal effects of		    */
#define WN_DIRTY	    12	/*   displaying windows 	    */
#define WN_ANY_DATA_COVERED 13	/*				    */

#define WN_ROWS 	    14	/* Dimensions of data area	    */
#define WN_COLS 	    15	/*				    */
				/*				    */
#define WN_ROW_REL	    16	/* Cursor location relative to	    */
#define WN_COL_REL	    17	/* data area			    */
				/*				    */
#define WN_ROW_ABS	  (-18) /* Absolute cursor location on	    */
#define WN_COL_ABS	  (-19) /* screen			    */

#define WN_ROW_OVERALL	  (-27) /* Location of window with	    */
#define WN_COL_OVERALL	  (-28) /* border.			    */
#define WN_HT_OVERALL	  (-29) /* Dimensions of window with	    */
#define WN_WID_OVERALL	  (-30) /* existing border.		    */
				/*				    */
#define WN_ATTR 	    20	/* Default attributes for data	    */
				/* area 			    */
				/*				    */
#define WN_BOR_TYPE	    22	/* Border type			    */
#define WN_BOR_CHAR	    23	/* Border character		    */
#define WN_BOR_ATTR	    24	/* Border attribute		    */
#define WN_BOR_TTATTR	    32	/* Border top title attribute	    */
#define WN_BOR_BTATTR	    33	/* Border bottom title attribute    */
				/*				    */
#define WN_IS_CURRENT	    25	/* Whether this is the current	    */
				/* window			    */
				/*				    */
#define WN_ACTIVE_CUR	  (-26) /* Whether this window (among	    */
				/* all the windows displayed on     */
				/* its page) is the one whose	    */
				/* cursor is active.		    */
				/*				    */
#define WN_PREV_ALLOC	    31	/* Whether space has been allocated */
				/* for the text underneath this     */
				/* window (when displayed and not   */
				/* hidden).			    */
				/*				    */
#define WN_CUR_TRACK	    34	/* Whether the window's data area   */
				/* will always be positioned so     */
				/* so that the cursor is visible in */
				/* the viewport.		    */
				/*				    */
#define WN_CUR_L_MARG	    35	/* The number of columns to leave   */
#define WN_CUR_R_MARG	    36	/* as a margin on the left and	    */
				/* right when performing cursor     */
				/* auto tracking.		    */
				/*				    */
#define WN_CUR_T_MARG	    37	/* The number of rows to leave as a */
#define WN_CUR_B_MARG	    38	/* margin on the top and bottom     */
				/* when performing cursor auto	    */
				/* tracking.			    */
				/*				    */
#define WN_HT_VIEW	  (-39) /* The height and width of the	    */
#define WN_WID_VIEW	  (-40) /* window's viewport.               */
				/*				    */



/********************************************************************/
/* Constants (option OR values) for WNSCRLBR.			    */
/********************************************************************/

#define WN_HORIZONTAL 0x01
#define WN_VERTICAL   0x02



/********************************************************************/
/* Constants (option OR values) for WNREAD and WNPOLL.		    */
/********************************************************************/

#define WN_KNOWN_EVENTS     0x00
#define WN_UNKNOWN_TRANSMIT 0x01
#define WN_ALL_TRANSMIT     0x03
#define WN_KBIGNORE	    0x04

#define WN_USE_MOUSE	    0x00
#define WN_NO_MOUSE	    0x08



/********************************************************************/
/* User Macros. 						    */
/********************************************************************/

#define wncreate(height,width,attr)				     \
	(wncreat0((height),(width),(attr),(BWIN_SIGN),(BNODE_SIGN)))

#define wndsplay(pwin, pwhere, pbord)				     \
	(wnvdisp((pwin),(pwhere),wndata_h((pwin)),wndata_w((pwin)),  \
		  0,0,(pbord)))

		/* Write a character to the current window	    */
		/* TTY-style.					    */
#define wnwrtty(ch, fore, back) 				     \
	(wnwrttyx (b_pcurwin, (ch), (fore), (back),		     \
		   WN_UPDATE | WN_LF_LF))

		/* Write a string to the current window TTY-style   */
		/* with scrolling and end-of-line character wrap.   */
#define wnwrstr(pbuffer, fore, back)				     \
	(wnwrstrn (b_pcurwin, (pbuffer), 0, (fore), (back),	     \
		   WN_UPDATE | CHARS_ONLY))

		/* Change attributes on current window (but don't   */
		/* change default).				    */
#define wnattr(fore, back)					     \
	(wnatrblk(b_pcurwin, 0, 0, (wndata_h(b_pcurwin) - 1),	     \
		  (wndata_w(b_pcurwin) - 1), (fore), (back),	     \
		  WN_UPDATE))

		/* Set up and allow user input in a window oriented */
		/* edit field.					    */
#define wnfield(pwin,pinitstr,pretstr,target_size,pfield_control,pfinal) \
	(edbase((pwin), (pinitstr), (pretstr), (target_size),	    \
	       (pfield_control), (pfinal), (PED_RET_FUNC) wnretinf, \
	       (PED_SET_FUNC) wnsetcur, (PED_WRITE_FUNC) wnwrrect))


/********************************************************************/
/* Global variables						    */
/********************************************************************/

extern int	b_wnerr;	/* Most recent error		    */
				/* (WN_NO_ERROR if none).	    */

extern BWINDOW *b_pcurwin;	/* Window selected for I/O	    */
				/* (NIL if none).		    */

extern long	b_win_hold;	/* Amount of time to wait before    */
				/* reporting MO_HOLD events.	    */

extern unsigned b_win_delay;	/* Amount of time to wait between   */
				/* successive window polls.	    */

extern WN_KEY	b_winkeys[];	/* Array of default window key	    */
				/* assignments. 		    */

extern WN_MOUSE b_winmouse[];	/* Array of default window mouse    */
				/* assignments. 		    */


/********************************************************************/
/* Global variables for internal use only			    */
/********************************************************************/

extern char	*b_wnprbf;	/* Buffer allocated for WNPRINTF.   */

extern unsigned int b_wnbfsz;	/* Size of buffer allocated for     */
				/* WNPRINTF.			    */

				/* List of windows displayed on     */
				/* each page (NIL if none).	    */
extern WIN_NODE *(b_wnlist[MAX_DEVICES][MAX_PAGES]);

				/* The window (on each page)	    */
				/* selected to have a visible	    */
				/* cursor (NIL if none).	    */
extern WIN_NODE *(b_pactnode[MAX_DEVICES][MAX_PAGES]);




/********************************************************************/
/* User function declarations by category.			    */
/********************************************************************/
		/* Window destruction.				    */

int cdecl wndstroy (BWINDOW *); /* Detach from screen & discard     */
				/* memory structures (does not	    */
				/* alter screen).		    */


		/* Controlling/retrieving window options & status.  */

BWINDOW *cdecl wnsetopt (	/* Set option.			    */
		 BWINDOW *,	/*				    */
		 int, int);	/*				    */
				/*				    */
BWINDOW *cdecl wngetopt (	/* Retrieve option or status.	    */
		 BWINDOW *,	/*				    */
		 int,int *);	/*				    */


		/* Error reporting.				    */

#if WN_EXT_ERROR		/*				    */
				/* External version:		    */
int cdecl wnerror(int); 	/* Set or clear error code and	    */
				/* return it.			    */
#else				/* Macro version:		    */
#define wnerror(ercode) \	/*				    */
	  (b_wnerr = (ercode))	/*				    */
#endif				/*				    */


		 /* Displaying/removing  windows.		    */

BWINDOW *cdecl wnremove (	/* Remove window from display page. */
		 BWINDOW *);	/*				    */
				/*				    */
BWINDOW *cdecl wnupdate (	/* Satisfy pending output requests. */
		 BWINDOW *);	/*				    */
				/*				    */
BWINDOW *cdecl wnrevupd (void); /* Read image of current window     */
				/* from the screen.		    */
				/*				    */
int	 cdecl wnredraw (int,	/* Redisplay all windows on a	    */
		 int);		/* display page and restore cursor. */


		/* Cursor action.				    */

BWINDOW *cdecl wncursor (	/* Select for visible cursor	    */
		 BWINDOW *);	/* (deselect other windows shown    */
				/* on this display page.)	    */
				/*				    */
BWINDOW *cdecl wncurmov (int,	/* Move current window's cursor     */
		 int);		/* relative to the window's data    */
				/* area.			    */
				/*				    */
BWINDOW *cdecl wncurpos (int *, /* Return current window's cursor   */
		 int *);	/* position relative to the	    */
				/* window's data area.              */


		/* Miscellaneous.				    */

BWINDOW *cdecl wnselect (	/* Select window for I/O (deselect  */
		 BWINDOW *);	/* all other windows) making this   */
				/* the "current" window.            */
				/*				    */
unsigned cdecl wnsetbuf (	/* Make scratch buffer for WNPRINTF.*/
		 unsigned);	/*				    */
				/*				    */
BWINDOW *cdecl wnscrlbr (	/* Make scrollbar sensors.	    */
		 BWINDOW *, int,/*				    */
		 int, unsigned, /*				    */
		 int);		/*				    */
void	 cdecl wnzapsen(	/* Zap a window's sensor list.      */
		 BWINDOW *);	/*				    */

		/* Window output.				    */

void	 cdecl wnwrap (int,	/* Write a string TTY-style with    */
	   const char *, int,	/* word wrap.			    */
		 int, int);	/*				    */
				/*				    */
void	 cdecl wnwrstrn (	/* Write a string of a given length */
		 BWINDOW *,	/* TTY-style with end-of-line	    */
	   const char *, int,	/* character wrap.		    */
		 int, int, int);/*				    */
				/*				    */
int	 cdecl wnwrbuf (int,	/* Write a buffer to a given	    */
		 int, int,	/* location in the current window's */
	   const char *, int,	/* data area.			    */
		 int, int);	/*				    */
				/*				    */
int	 cdecl wnprintf (	/* Do a PRINTF to the current	    */
	   const char *, ...);	/* window.			    */
				/*				    */
BWINDOW *cdecl wnwrrect (	/* Write to a rectangular region of */
		 BWINDOW *, int,/* a window.			    */
		 int, int, int, /*				    */
		 const char *,	/*				    */
		 int, int, int);/*				    */
				/*				    */


		/* Window input.				    */

int	 cdecl wnrdbuf (int,	/* Read part of the current	    */
		 int, int,	/* window's data area into a        */
		 char *, int);	/* buffer.			    */
				/*				    */
char	 cdecl wnquery (char *, /* Return input from operator.	    */
		 int,int *);	/*				    */
				/*				    */
WN_EVENT *cdecl wnread (	/* Display a window and accept user */
		  BWINDOW *,	/* responses.			    */
		  const WHERE *,/*				    */
		  int, int,	/*				    */
		  int, int,	/*				    */
		  const 	/*				    */
		    BORDER *,	/*				    */
		  WN_EVENT *,	/*				    */
		  int); 	/*				    */
				/*				    */
WN_EVENT *cdecl wnpoll( 	/* Poll the mouse/keyboard once for */
		WN_EVENT_LIST *,/* a user response belonging to a   */
		unsigned *,	/* specified set of events.	    */
		unsigned *,	/*				    */
		WN_EVENT *);	/*				    */
				/*				    */
int	 cdecl wninitev (	/* Initialize window event list.    */
		 BWINDOW *);	/*				    */
				/*				    */
int	 cdecl wnchgevn (	/* Change a window event in the     */
	       WN_EVENT_LIST **,/* specified event list.	    */
	       WN_EVENT *,	/*				    */
	       WN_ACTION);	/*				    */
				/*				    */
int	 cdecl wnremevn(	/* Delete a window event in the     */
	       WN_EVENT_LIST **,/* specified event list.	    */
	       const		/*				    */
		 WN_EVENT *);	/*				    */
				/*				    */
void	 cdecl wnzapevn(	/* Release the entire event list    */
	      WN_EVENT_LIST **);/* specified.	       .	    */
				/*				    */


		/* Window scrolling.				    */

BWINDOW *cdecl wnscrblk (	/* Scroll a block-section of a	    */
		 BWINDOW *,	/* window a specified number of     */
		 int, int, int, /* rows/columns.		    */
		 int, int, int, /*				    */
		 int, int, int);/*				    */
				/*				    */
BWINDOW *cdecl wnscroll (	/* Vertically scroll current window.*/
		 int, int,	/*				    */
		 int, int);	/*				    */
				/*				    */
BWINDOW *cdecl wnhoriz (	/* Horizontally scroll current	    */
		 int, int,	/* window.			    */
		 int, int);	/*				    */
				/*				    */


		/* Attribute manipulation.			    */

BWINDOW *cdecl wnatrblk (	/* Change attributes on a block-    */
		 BWINDOW *,	/* section of a window. 	    */
		 int, int, int, /*				    */
		 int, int, int, /*				    */
		 int);		/*				    */
				/*				    */
BWINDOW *cdecl wnatrstr (	/* Change attributes on a stream-   */
		 BWINDOW *,	/* section of a window. 	    */
		 int, int, int, /*				    */
		 int, int,	/*				    */
		 int);		/*				    */
				/*				    */

		/* Virtual windows.				    */

BWINDOW *cdecl wnvdisp (	/* Display virtual window with	    */
		 BWINDOW *,	/* border.			    */
		 const WHERE *, /*				    */
		 int, int,	/*				    */
		 int, int,	/*				    */
		 const		/*				    */
		     BORDER *); /*				    */
				/*				    */
BWINDOW *cdecl wnorigin (	/* Set the coordinates of the data  */
		 BWINDOW *, int,/* area which will appear in the    */
		 int, int);	/* viewport's origin.               */
				/*				    */
BWINDOW *cdecl wnshoblk (	/* Shift the window's data area to  */
		 BWINDOW *,	/* show a specified block.	    */
		 const REGION *,/*				    */
		 const LOC *,	/*				    */
		 const LOC *,	/*				    */
		 int);		/*				    */
				/*				    */



/********************************************************************/
/* Internal functions by category				    */
/********************************************************************/

		/* Window creation.				    */

BWINDOW *cdecl wncreat0(int,int,int,unsigned,unsigned);


		/* Device & page switching.			    */

int cdecl wnseldev(const WHERE *,const DIM *,int *);


		/* Error detection.				    */

BWINDOW       *cdecl wnvalwi0(BWINDOW *,unsigned);
WIN_NODE      *cdecl wnvalno0(WIN_NODE *,unsigned);
WN_EVENT_LIST *cdecl wnvalev0(WN_EVENT_LIST *,unsigned);


		/* Restoring previous screen contents.		    */

BWINDOW *cdecl wnresprv(BWINDOW *);


		/* Handling IMAGE structures.			    */

BWINDOW *cdecl wnpimblk(BWINDOW *,int,int,int,int);
IMAGE	*cdecl wngetimg(IMAGE *,const WHERE *);


		/* Manipulating chains of WIN_NODEs.		    */

WIN_NODE *cdecl wnpgadd(BWINDOW *,int,int);
BWINDOW  *cdecl wnpgrem(BWINDOW *);


		/* Building borders.				    */

int cdecl wnputbor(const DIM *,const BORDER *,const WHERE *);


		/* Building sensor lists.			    */

int cdecl wnputsen(BWINDOW *);

		/* Handling window events.			    */

WN_EVENT *cdecl wnretevn(WN_EVENT_LIST *, const WN_EVENT *);

		/* Handling inter-window effects:  displaying,	    */
		/* overlapping, removing.			    */

BWINDOW *cdecl wnneedup(BWINDOW *);
BWINDOW *cdecl wnnupblk(BWINDOW *,int,int,int,int,int);
WIN_NODE *cdecl wncover(WIN_NODE *,const LOC *,const DIM *);
int cdecl wnovrlap(const LOC *,const DIM *,const LOC *,const DIM *);
BWINDOW *cdecl wnforget(BWINDOW *);
BWINDOW *cdecl wnhide(BWINDOW *);
BWINDOW *cdecl wnunhide(BWINDOW *);


		/* Window output.				    */

void cdecl wnwrttyx(BWINDOW *,char,int,int,int);


		/* Cursor handling.				    */

BWINDOW *cdecl wncurtrk(BWINDOW *, int, int);
void cdecl     wncurset(BWINDOW *);


		/* Native text window handling. 		    */

void cdecl wncmove(BWINDOW *, int, int);
void cdecl wnsetwin(int,int,int,int);
int  cdecl wnchkdm(BWINDOW *);
void cdecl wngetatr(BWINDOW *);
void cdecl wnsetatr(int);

		/* Window edit fields.				    */

int  cdecl wnretinf(BWINDOW *, CUR_INFO *, const LOC *, int, int);
int  cdecl wnsetcur(BWINDOW *, int, CUR_TYPE *, int, int);


#endif				/* Ends "#ifndef DEF_BWINDOW"       */
