/*
 +----------------------------------------------------------------------+
 |                           pro_ext.h                                  |
 +----------------------------------------------------------------------+


 ================                   ===========
   ==         ===                     ==       ==
   ==           =                     ==        ==
   ==                                 ==        ==
   ==          ===     =====  =====   ==       ==  ===   ====        ===
   =====    ==     ==    ==    ==     =========      == ==   ==   ==     ==
   ==      ==       ==    ==  ==      ==             ===         ==       ==
   ==     ==         ==    ===        ==             ==         ==         ==
   ==      ==       ==    == ==       ==             ==          ==       ==
   ==       ==     ==    ==   ==      ==             ==           ==     ==
 =======       ===     =====  ====  ======         ======            ===

 +--------------------------------------------------------------------------+
 |                   FoxPro -- Relational Database System                   |
 +--------------------------------------------------------------------------+
 |                                                                          |
 |     Copyright (c) 1989,1990 Fox Holdings Inc., Toledo, Ohio 43615        |
 |     as an unpublished licensed proprietary work.  All rights reserved.   |
 |                                                                          |
 |     This software contains valuable trade secrets and proprietary        |
 |     information, and is protected by federal copyright laws, the         |
 |     violation of which can result in civil damages and criminal pro-     |
 |     secution.  Access to these source materials is granted only by       |
 |     explicit written permission from Fox Holdings Inc.                   |
 |                                                                          |
 +--------------------------------------------------------------------------+
*/

#ifndef PRO_EXT_INCLUDED

#define PRO_EXT_INCLUDED

/* Semi-portable way to deal with 'far' pointers */
#ifndef FAR
#define FAR __far
#endif

#ifndef GLOBAL_INCLUDED
typedef unsigned MHANDLE;	/* A memory handle.			*/
typedef int	 NTI;		/* A name table index.			*/
#define TRUE	1
#define FALSE	0
#define YES	1
#define NO	0
#endif

#if I80386
#define MHANDLE unsigned short
#endif

#ifndef PROTYPES_INCLUDED
typedef unsigned long Ticks;	/* A timer tick count.			*/
#endif

#ifndef __386__
#pragma aux default parm routine [ax bx cx dx] modify [es];
#endif

typedef unsigned long WHandle;	/* A Window Handle			*/
typedef long MENUID;		/* A Menu id.				*/
typedef long MenuId;		/* A Menu id.				*/
typedef long ITEMID;		/* An item id.				*/
typedef long ItemId;		/* An item id.				*/

typedef int	 FCHAN;		/* A file I/O channel.			*/
#define SCHEMEWIDTH	11
typedef char Scheme[SCHEMEWIDTH];/* A FoxPro color scheme		*/


#ifndef FOXWIND_INCLUDED

typedef WHandle WHANDLE;	/* Users can use WHANDLE 		*/

/* 	_WOpen() flag values.			*/

#define WCURSOR     (1<<1)  /* Enable the cursor			*/
#define ZOOM	    (1<<2)  /* Permit the window to be zoomed           */
#define ADJ         (1<<3)  /* Allow Window Size to be Adjusted         */
#define CLOSE	    (1<<4)  /* Permit Closing of System Window          */
#define MOVE	    (1<<5)  /* Allow the window to be moved		*/
#define HSCROLLBAR  (1<<6)  /* Show Horizontal Scrollbars               */
#define VSCROLLBAR  (1<<7)  /* Show Vertical Scrollbars                 */
#define AUTOSCROLL  (1<<8)  /* Window should Auto scroll    		*/
#define WEVENT	    (1<<10) /* Participates in activate/deact events	*/
#define SHADOW      (1<<11) /* Window will produce a shadow		*/
#define	WMODAL      (1<<12) /* Window is a modal window			*/
#define	WMINIMIZE   (1<<13) /* Window can be minimized			*/

#endif

#ifndef FOXEVENT_INCLUDED

/*  _FindWindow() return values.		*/
#define inBorder 	 0	/* In the window border region		*/
#define inHelp		 1	/* In the Help region			*/
#define inContent	 2	/* In the content/text region		*/
#define inDrag		 3	/* In the Drag/Title bar region		*/
#define inGrow		 4	/* In the grow/resize region		*/
#define inGoAway	 5	/* In the goAway/close region		*/
#define inZoom		 6	/* In the zoom region			*/
#define inVUpArrow	 7	/* In the vertical up arrow region	*/
#define inVDownArrow	 8	/* In the vertical down arrow region	*/
#define inVPageUp	 9	/* In the vertical page up region	*/
#define inVPageDown	10	/* In the vertical page down region	*/
#define inVThumb	11	/* In the vertical thumb region		*/
#define inHUpArrow	12	/* In the horizontal up arrow region	*/
#define inHDownArrow    13      /* In the horizontal down arrow region	*/
#define inHPageUp       14      /* In the horizontal page up region	*/
#define inHPageDown     15      /* In the horizontal page down region	*/
#define inHThumb        16      /* In the horizontal thumb region	*/
#define inMenuBar	17	/* In the menu bar			*/

/* EventRec.what values		*/

#define	nullEvent	    	0	/* Null				*/
#define mouseDownEvent	    	1	/* Mouse down			*/
#define keyDownEvent	    	2	/* Key down			*/
#define activateEvent	    	3	/* Activate window		*/
#define deactivateEvent	    	4	/* Deactivate window		*/
#define	updateEvent		5	/* Redraw window		*/
#define	menuHitEvent		6	/* Menu Hit			*/
#define	menuUpdateEvent		7	/* Menu Update required		*/
#define	closeEvent		8	/* Close window 		*/
#define	hideEvent		9	/* Hide window    		*/
#define	showEvent	       10	/* Show window    		*/
#define hotkeyEvent	       11	/* An ON KEY LABEL was pressed  */
#define sizeEvent	       12	/* Size window event		*/
#define zoomEvent	       13	/* Zoom window event		*/

/* EventRec.modifiers defines */

#define charCodeMask	0x0fff		/* Character code mask		*/
#define	shiftCodeMask	0xf000		/* Shift key mask		*/

#define	shiftKey	0x1000		/* Either shift key    1 - down	*/
#define	ctrlKey		0x2000		/* Control key         1 - down	*/
#define	altKey		0x4000		/* Alternate key       1 - down	*/
#define	literalKey	0x8000		/* This key is interpreted literally */

/* EventRec.mbState code defines */

#define	leftButton	(1<<0)		/* Left button status   1 - down */
#define	rightButton	(1<<1)		/* Right button status  1 - down */
#define	centerButton	(1<<2)		/* Center button status 1 - down */

/* EventRec.mcState code defines */

#define posChange	(1<<0)		/* Position change        1 - change   */
#define leftPressed	(1<<1)		/* Left button pressed    1 - pressed  */
#define leftReleased	(1<<2)		/* Left button released   1 - released */
#define rightPressed	(1<<3)		/* Right button pressed   1 - pressed  */
#define rightReleased	(1<<4)		/* Right button released  1 - released */
#define centerPressed	(1<<5)		/* Center button pressed  1 - pressed  */
#define centerReleased	(1<<6)		/* Center button released 1 - released */

#endif

/* Flag values for _InKey()	*/
#define SHOWCURSOR	(1<<0)
#define HIDECURSOR	(1<<1)
#define MOUSEACTIVE	(1<<2)

/* Flag values for the _ALen() function	*/

enum {
    AL_ELEMENTS,
    AL_SUBSCRIPT1,
    AL_SUBSCRIPT2
};

/* FPFI is a 32 bit pointer to a function returning an int */
typedef int (FAR *FPFI)();

#ifndef PROTYPES_INCLUDED

typedef struct {
    short h;
    short v;
} Point;

typedef struct {
    short top;
    short left;
    short bottom;
    short right;
} Rect;

#endif

#ifndef FOXMENU_INCLUDED

/*- Menu structure type entry definitions used by _NewMenu()	*/

#define MPOPUP		1		/* Menu is a POPUP type menu	*/
#define MPAD		2		/* Menu is a PAD type menu	*/
#define MBAR		3		/* Menu is a BAR type menu	*/

#endif

/* These are the API identifiers for the System Menu Constants.  	*/

enum {
    _LASTITEM = -2, _FIRSTITEM,

    _SYSMENU,
    _SYSMSYSTEM, _SYSMFILE, _SYSMEDIT, _SYSMDATA, _SYSMRECORD, _SYSMPROG,
    _SYSMWINDOW,

    _SYSTEM,
    _SYSTEMABOUT, _SYSTEMHELP, _SYSTEMMACRO, _SYSTEMSEP100, _SYSTEMFILER,
    _SYSTEMCALC, _SYSTEMDIARY, _SYSTEMSPECIAL, _SYSTEMASCII,
    _SYSTEMCAPTURE, _SYSTEMPUZZLE,

    _FILE,
    _FILENEW, _FILEOPEN, _FILECLOSE, _FILECLOSEALL, _FILESEP100, _FILESAVE,
    _FILESAVEAS, _FILEREVERT, _FILESEP200, _FILESETUP, _FILEPRINT, _FILESEP300,
    _FILEQUIT,

    _EDIT,
    _EDITUNDO, _EDITREDO, _EDITSEP100, _EDITCUT, _EDITCOPY, _EDITPASTE,
    _EDITCLEAR, _EDITSEP200, _EDITSELECTALL, _EDITSEP300, _EDITGOTO,
    _EDITFIND, _EDITFINDAGAIN, _EDITREPLACE, _EDITREPLACEALL,
    _EDITSEP400, _EDITPREF,

    _DATA,
    _DATASETUP,	_DATABROWSE, _DATASEP100, _DATAAPPEND, _DATACOPY, _DATASORT,
    _DATATOTAL,	_DATASEP200, _DATAAVERAGE, _DATACOUNT, _DATASUM, _DATACALCULATE,
    _DATAREPORT, _DATALABEL, _DATASEP300, _DATAPACK, _DATAREINDEX,

    _RECORD,
    _RECORDAPPEND, _RECORDCHANGE, _RECORDSEP100, _RECORDGOTO, _RECORDLOCATE,
    _RECORDCONTINUE, _RECORDSEEK, _RECORDSEP200, _RECORDREPLACE, _RECORDDELETE,
    _RECORDRECALL,

    _PROG,
    _PROGDO, _PROGSEP100, _PROGCANCEL, _PROGRESUME, _PROGSEP200,
    _PROGCOMPILE, _PROGGENERATE, _PROGDOCUMENT, _PROGGRAPH,

    _WINDOW,
    _WINDOWHIDE, _WINDOWHIDEALL, _WINDOWSHOWALL, _WINDOWCLEAR, _WINDOWSEP100,
    _WINDOWMOVE, _WINDOWSIZE, _WINDOWZOOM, _WINDOWMINMAX, _WINDOWROTATE,
    _WINDOWCOLOR, _WINDOWSEP200, _WINDOWCOMMAND, _WINDOWDEBUG, _WINDOWTRACE,
    _WINDOWVIEW,

    _REPORT, _LABEL, _BROWSE, _MACRO, _DIARY, _DAFILER, _SCREEN,
    _MBLDR, _PROJECT, _RQBE

};


/* Now anyone can simulate a breakpoint with BreakPoint() */
#pragma aux _BreakPoint = 0xcc;	/* INT 3				*/

void _BreakPoint(void);

/* Alternate values for parmCount to modify how FoxPro treats the function */
#define	INTERNAL	-1	/* Not callable from FoxPro 		*/
#define CALLONLOAD	-2	/* Call when library is loaded 		*/
#define CALLONUNLOAD	-3	/* Call when library is unloaded 	*/

/* The FoxInfo structure contains the descriptions of the functions
   contained in the library.
*/

typedef struct {
    char FAR *	funcName;	/* Function name (all caps) 		*/
    FPFI 	function;	/* Actual function address 		*/
    short 	parmCount;	/* # parameters specified or a flag value */
    char FAR *	parmTypes;	/* Parameter list description 		*/
} FoxInfo;

typedef struct _FoxTable {
    struct _FoxTable FAR *nextLibrary;	/* Linked list of libraries 	*/
    short infoCount;		/* # of functions in this library 	*/
    FoxInfo FAR *infoPtr;	/* Function list 			*/
} FoxTable;

/* An expression's value	*/
typedef struct {
    char		ev_type;
    char 		ev_padding;
    short  		ev_width;
    unsigned short 	ev_length;
    long 		ev_long;
    double 		ev_real;
    MHANDLE		ev_handle;
} Value;

/* A reference to a database or memory variable	*/
typedef struct {
    char	l_type;
    short 	l_where,	/* Database number or -1 for memory	*/
		l_NTI,		/* Variable name table offset		*/
		l_offset,	/* Index into database			*/
		l_subs,		/* # subscripts specified 0 <= x <= 2	*/
		l_sub1, l_sub2;	/* subscript integral values		*/
} Locator;

/* A parameter to a library function.		*/
typedef union {
    Value 	val;
    Locator 	loc;            /* An 'R' in l_type means the Locator	*/
				/* part of this union is in use.	*/
} Parameter;

/* A paramter list to a library function.	*/
typedef struct {
    short int 	pCount;		/* Number of Parameters PASSED.		*/
    Parameter   p[1];		/* pCount Parameters.			*/
} ParamBlk;

/* Event record definitions */
typedef struct
{   unsigned short	what;		/* Event code			*/
    Ticks		when;		/* Ticks since startup		*/
    Point		where;		/* Mouse location		*/
    unsigned long	message;	/* Key/window			*/
    unsigned long	misc;		/* Event dependant misc info	*/
    unsigned long	misc2;		/* Event dependant misc info	*/
    unsigned char	mbState;  	/* Mouse buttons state          */
    unsigned char	mcState;	/* Mouse cond activate state    */
    unsigned short 	modifiers;
} EventRec;

/* Flags for the _DBStatus function */
#define DB_BOF		1	/* BOF()				*/
#define DB_EOF		2	/* EOF()				*/
#define DB_RLOCKED	4	/* Current record is RLOCKed		*/
#define DB_FLOCKED	8	/* Database is FLOCKed			*/
#define DB_EXCLUSIVE	16	/* Database is open EXCLUSIVEly		*/
#define DB_READONLY	32	/* Database is READONLY			*/

/* Flag values for _DBLock()	*/
#define DBL_RECORD	0
#define DBL_FILE	1

/* Flag values for the _NewVar function	*/
#define NV_PUBLIC	0
#define NV_PRIVATE	1

/* Mode flag values for the __FIO function	*/
#define FIO_FGETS 	0
#define FIO_FREAD 	1
#define FIO_FPUTS 	2
#define FIO_FWRITE 	3

/* Mode flag values for the _FOpen function	*/
#define FO_READONLY	0
#define FO_WRITEONLY	1
#define FO_READWRITE	2

/* Mode flag values for the _FCreate function	*/
#define FC_NORMAL	0
#define FC_READONLY	1
#define FC_HIDDEN	2
#define FC_SYSTEM  	4
#define FC_TEMPORARY	128

/* Mode flag values for the _FSeek function	*/
#define FS_FROMBOF	0	/* From beginning of file	*/
#define FS_RELATIVE	1	/* From current position	*/
#define FS_FROMEOF	2	/* From end of file		*/

/* Mode flag values for the __WStat function	*/
#define WS_TOP		0
#define WS_BOTTOM	1
#define WS_LEFT		2
#define WS_RIGHT	3
#define WS_HEIGHT	4
#define WS_WIDTH	5
#define WS_SETPORT	7

/* Mode flag values for the __WControl function	*/
#define WC_CLEAR	0
#define WC_CLOSE        1
#define WC_HIDE         2
#define WC_SHOW         3
#define WC_SELECT       4
#define WC_SENDBEHIND   5

/* Mode flag values for the __WAdjust function	*/
#define WA_MOVE		0
#define WA_SIZE         1
#define WA_POSCURSOR    2

/* Mode flag value for the __WPort function	*/
#define WP_ONTOP	0
#define WP_OUTPUT	1

/* Mode flag value for the _WZoom function	*/
#define WZ_MAXIMIZED	0
#define WZ_NORMAL	1
#define WZ_MINIMIZED	2

/* Border strings for typical window borders.	*/
#define WO_DOUBLEBOX    "\x0cd\x0cd\x0ba\x0ba\x0c9\x0bb\x0c8\x0bc\x0cd\x0cd\x0ba\x0ba\x0c9\x0bb\x0c8\x0bc"
#define WO_SINGLEBOX    "\x0c4\x0c4\x0b3\x0b3\x0da\x0bf\x0c0\x0d9\x0c4\x0c4\x0b3\x0b3\x0da\x0bf\x0c0\x0d9"
#define WO_PANELBORDER  "\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db\x0db"
#define WO_SYSTEMBORDER "\x020\x020\x020\x020\x0fe\x0f0\x020\x0f9\x020\x020\x020\x020\x020\x020\x020\x020"

#ifndef FOXWIND_INCLUDED

/* Border string offsets.			*/
#define selectBorder	    0
#define deselectBorder      8

#define topEdge             0
#define bottomEdge          1
#define leftEdge            2
#define rightEdge           3
#define topLeftCorner       4
#define topRightCorner      5
#define bottomLeftCorner    6
#define bottomRightCorner   7
#define maxBorderLen 	   17	/* Border string length (maximum)	   */
#endif


#ifndef COLORS_INCLUDED

#define BLACK_ON 	0x00   /* Foreground color attributes		   */
#define BLUE_ON		0x01
#define GREEN_ON	0x02
#define CYAN_ON		0x03
#define	RED_ON		0x04
#define MAGENTA_ON	0x05
#define BROWN_ON	0x06
#define WHITE_ON	0x07

#define BLACK	(BLACK_ON << 4)	/* Background color attributes.		   */
#define BLUE	(BLUE_ON << 4)
#define GREEN	(GREEN_ON << 4)
#define CYAN	(CYAN_ON << 4)
#define RED	(RED_ON << 4)
#define MAGENTA (MAGENTA_ON << 4)
#define BROWN	(BROWN_ON << 4)
#define WHITE	(WHITE_ON << 4)

#define BRIGHT	0x08		/* Intensify foreground color		    */
#define BLINK	0x80		/* Blink this				    */


/* The following values are used in the WA_ISSHADOW column of the
   schemes to indicate whether the window casts a shadow.		*/

#define CASTSSHADOW (BRIGHT | BLACK_ON | BLACK)
#define CASTSNOSHADOW (BRIGHT | WHITE_ON | WHITE | BLINK)


/* Color scheme numbers for use by _WOpen and others	*/

enum
{
    USER_SCHEME,
    USERMENU_SCHEME,
    MBAR_SCHEME,
    POPUP_SCHEME,
    DIALOG_SCHEME,
    MODAL_POPUP_SCHEME,
    ALERT_SCHEME,
    WINDOW_SCHEME,
    NONMODAL_POPUP_SCHEME,
    BROWSE_SCHEME,
    REPORT_SCHEME,
    ALERT_POPUP_SCHEME
};

/* Color index numbers used by _WSetAttr() and _WAttr()	*/

enum
{
    WA_PENCOLOR = -1,	/* CURRENT PEN COLOR				*/

    WA_NORMAL,		/* normal text					*/
    WA_ENHANCED,	/* enhanced text				*/
    WA_BORDER,		/* window border				*/
    WA_FOREMOST,	/* title when foremost				*/
    WA_TITLE,		/* title otherwise				*/
    WA_SELECTED,	/* selected text				*/
    WA_HOTKEY,		/* control hotkeys				*/
    WA_SHADOW,		/* color of shadows that fall on this window. 	*/
    WA_ENABLED,		/* enabled control				*/
    WA_DISABLED,	/* disabled control				*/
    WA_ISSHADOW 	/* window casts a shad				*/
};


#endif


/* Prototypes for the API Functions */

/* Streaming output routines 	*/
void _PutChr(int character);
void _PutStr(char FAR *string);
void _PutValue(Value FAR *val);

/* Memory management functions */
MHANDLE _AllocHand(unsigned int hsize);
void _FreeHand(MHANDLE hand);
void FAR *_HandToPtr(MHANDLE hand);
unsigned _GetHandSize(MHANDLE hand);
int _SetHandSize(MHANDLE hand, unsigned int size);
void _HLock(MHANDLE hand);
void _HUnLock(MHANDLE hand);
void FAR *_Alloca(unsigned int size);
void FAR *__Alloca(unsigned int size);
unsigned int _StackAvail(void);
int _MemAvail(unsigned int);
#define _Alloca(size)	((_StackAvail()>(unsigned)size) ? __Alloca(((size)+1)&0xfffe): 0)
#pragma aux __Alloca =	0x29 0xc4 /* sub sp, ax */\
			0x89 0xe0 /* mov ax, sp */\
                        0x8c 0xd2 /* mov dx, ss */\
                        parm caller [ax] value[ax dx] modify [sp];

/* String handling functions	*/
int  _StrLen(char FAR *string);
void _StrCpy(char FAR *dest, char FAR *src);
int  _StrCmp(char FAR *string1, char FAR *string2);

/* Memory management functions	*/
void _MemMove(void FAR *dest, void FAR *src, unsigned int length);
int  _MemCmp(void FAR *ptr, void FAR *ptr2, unsigned int length);
void _MemFill(void FAR *ptr, int character, unsigned int length);
#pragma aux _MemFill parm [es di] [ax] [cx] modify [ax];
#pragma aux _MemCmp  parm [es di] [dx si] [ax] modify nomemory [ax si di];

/* Functions to set the return value of a library functiion	*/
void _RetVal(Value FAR *val);
void _RetChar(char FAR *string);
void _RetInt(long ival, int width);
void _RetFloat(double flt, int width, int dec);
void _RetDateStr(char FAR *string);
void _RetLogical(int);

/* Database Input/Output functions */
long _DBRecNo(int workarea);
long _DBRecCount(int workarea);
int  _DBStatus(int workarea);
int _DBRead(int workarea, long record);
int _DBWrite(int workarea);
int  _DBAppend(int workarea, int carryflag);
long _DBRewind(int workarea);
long _DBSkip(int workarea, long distance);
long _DBUnwind(int workarea);
int _DBReplace(Locator FAR *fld, Value FAR *val);
long _DBSeek(Value FAR *val);
int _DBLock(int workarea, int what);
void _DBUnLock(int workarea);

/* Memo Field Input/Output functions */
FCHAN _MemoChan(int workarea);
long _AllocMemo(Locator FAR *fld, long size);
long _FindMemo(Locator FAR *fld);
long _MemoSize(Locator FAR *fld);

/* Memory variable manipulation functions */
NTI _NewVar(char FAR *name, Locator FAR *loc, int flag);
int _Release(NTI nti);
int _Store(Locator FAR *loc, Value FAR *val);
int _Load(Locator FAR *loc, Value FAR *val);
long _ALen(NTI nti, int mode);
int _FindVar(NTI nti, int where, Locator FAR *loc);
NTI _NameTableIndex(char FAR *name);

/* File Input/Output */

FCHAN __FOpen(char FAR *filename, int mode, int create);

#define _FOpen(filename, mode)		__FOpen(filename, mode, NO)
#define _FCreate(filename, mode)	__FOpen(filename, mode, YES)

int __FFlush(FCHAN chan, int close);

#define _FFlush(chan)	__FFlush(chan, NO)
#define _FClose(chan)	__FFlush(chan, YES)

int __FStat(FCHAN chan, int error);

#define _FEOF(chan)	__FStat(chan, NO)
#define _FError()	__FStat(0, YES)

unsigned int __FIO(FCHAN chan, char FAR *buffer, unsigned int maxlen, int mode);

#define _FGets(chan, buffer, maxlen)	__FIO(chan, buffer, maxlen, FIO_FGETS)
#define _FRead(chan, buffer, maxlen)	__FIO(chan, buffer, maxlen, FIO_FREAD)
#define _FPuts(chan, buffer)		__FIO(chan, buffer, 0, 	    FIO_FPUTS)
#define _FWrite(chan, buffer, maxlen)	__FIO(chan, buffer, maxlen, FIO_FWRITE)

long 	_FSeek(FCHAN chan, long position, int mode);
int 	_FCHSize(FCHAN chan, long length);
int 	_FCopy(FCHAN dchan, long dpos, FCHAN schan, long spos, long len);

/* User Interface routines */
unsigned _ActivateHandler(FPFI handler);
void 	_DeActivateHandler(unsigned);
unsigned _ActivateIdle(FPFI handler);
void	_DeActivateIdle(unsigned);
int 	_GetNextEvent(EventRec FAR *event);
void 	_DefaultProcess(EventRec FAR *event);
int 	_InKey(int timeout, int flag);
int 	_MousePos(Point FAR *pt);

/* Windowing routines.	*/
int 	_FindWindow(WHANDLE FAR *wh, Point pt);
void 	_GlobalToLocal(Point FAR *pt, WHANDLE wh);
WHANDLE _WOpen(int top, int left, int bottom, int right, int flag, int
	       scheme_num, Scheme FAR *scheme, char FAR *bord);

void 	_RefreshDisplay(void);

#define _WTop(wh)	((unsigned)__WStat(wh, WS_TOP))
#define _WBottom(wh)	((unsigned)__WStat(wh, WS_BOTTOM))
#define _WLeft(wh)	((unsigned)__WStat(wh, WS_LEFT))
#define _WRight(wh)	((unsigned)__WStat(wh, WS_RIGHT))
#define _WHeight(wh)	((unsigned)__WStat(wh, WS_HEIGHT))
#define _WWidth(wh)	((unsigned)__WStat(wh, WS_WIDTH))
#define _WSetPort(wh)	((WHANDLE)__WStat(wh, WS_SETPORT))

unsigned long __WStat(WHANDLE wh, int mode);

#define _WClear(wh)	__WControl(wh, WC_CLEAR)
#define _WClose(wh)	__WControl(wh, WC_CLOSE)
#define _WHide(wh)	__WControl(wh, WC_HIDE)
#define _WShow(wh)	__WControl(wh, WC_SHOW)
#define _WSelect(wh)	__WControl(wh, WC_SELECT)
#define	_WSendBehind(w) __WControl(w, WC_SENDBEHIND)

void __WControl(WHANDLE wh, int mode);

#define _WMove(wh, pt)		__WAdjust(wh, pt, WA_MOVE)
#define _WSize(wh, pt)		__WAdjust(wh, pt, WA_SIZE)
#define _WPosCursor(wh, pt)	__WAdjust(wh, pt, WA_POSCURSOR)

void __WAdjust(WHANDLE wh, Point pt, int mode);

#define _WOnTop()	__WPort(WP_ONTOP)
#define _WGetPort()	__WPort(WP_OUTPUT)

WHANDLE __WPort(int mode);

void	_WZoom(WHANDLE wh, int newstate);

void	__WSetTitle(WHANDLE wh, char FAR *text, int mode);

#define WT_SETFOOTER	0
#define WT_SETTITLE	1
#define WT_GETFOOTER	2
#define WT_GETTITLE	3

#define _WSetFooter(wh, footer)	__WSetTitle(wh, footer, WT_SETFOOTER)
#define _WSetTitle(wh, title)	__WSetTitle(wh, title, WT_SETTITLE)
#define _WFooter(wh, footer)	__WSetTitle(wh, footer, WT_GETFOOTER)
#define _WTitle(wh, title)	__WSetTitle(wh, title, WT_GETTITLE)

void 	_WScroll(WHANDLE wh, Rect r, int dv, int dh);
#define _WClearRect(wh, r)	_WScroll(wh, r, 0, 0);

Point	_WGetCursor(WHANDLE wh);
int	_WAttr(WHANDLE wh, int color);
void 	_WSetAttr(WHANDLE wh, int color, int attr);
void	_WPutChr(WHANDLE wh, int character);
void 	_WPutStr(WHANDLE wh, char FAR *str);

/* Functions to execute FoxPro statements and evaluate FoxPro expressions */

int _Execute(char FAR *stmt);
int _Evaluate(Value FAR *val, char FAR *expr);

/* Menuing functions.		*/

long 	__MenuStat(long x, int mode);

#define	_MenuId(literal)		__MenuStat(literal, 0)
#define	_GetNewItemId(menuid)	        __MenuStat(menuid, 1)
#define _CountItems(menuid)	        __MenuStat(menuid, 2)
#define	_GetNewMenuId()		       	__MenuStat(0, 3)

int 	_MenuInteract(MenuId FAR *menuid, ItemId FAR *itemid);

void 	__MenuAction(MenuId menuid, int mode);

#define _ActivateMenu(menuid)		__MenuAction(menuid, 0)
#define _DeActivateMenu(menuid)         __MenuAction(menuid, 1)
#define	_DisposeMenu(menuid)            __MenuAction(menuid, 2)

int 	_NewMenu(int mtype, MenuId menuid);
void 	_SetMenuColor(MenuId menuid, int scheme);
ItemId	_GetItemId(MenuId menuid, long index);
int 	_NewItem(MenuId menuid, ItemId itemid, ItemId beforeid, char FAR *prompt);
void	_DisposeItem(MenuId menuid, ItemId itemid);
void	_SetMenuPoint(MenuId menuid, Point loc);


void 	_SetItemSubMenu(MenuId menuid, ItemId itemid, MenuId submenuid);
void 	_SetItemColor(MenuId menuid, ItemId itemid, int scheme);
void 	_GetItemText(MenuId menuid, ItemId itemid, char FAR *text);
void	_SetItemText(MenuId menuid, ItemId itemid, char FAR *text);
int	_GetItemCmdKey(MenuId menuid, ItemId itemid, char FAR *text);
void	_SetItemCmdKey(MenuId menuid, ItemId itemid, int key, char FAR *text);
void 	_OnSelection(MenuId menuid, ItemId itemid, FPFI routine);

/* FoxPro Dialogs	*/
int 	_Dialog(int scheme, char FAR *text, char FAR *button1,
		char FAR *button2, char FAR *button3, int def, int esc);


/* Error Handling	*/
void 	_Error(int code);
void	_UserError(char FAR *message);
int	_ErrorInfo(int code, char FAR *message);

#if I80386
#undef MHANDLE
#endif

#endif
