/*
 *	WinLIB PRO
 *	Core package header file
 *
 *	Original WinLIB PRO header by Ken Hollis and Karl 0ygard
 *	This header file by Ken Hollis
 *
 *	This header file contains the calls, indices and prototypes to all
 *	of the functions present to the WinLIB PRO Core package.  No part
 *	of this header file may be modified, unless for personal use
 *	only.
 *
 *	For a complete listing of all of the Core package's or any of the
 *	package functions, please refer to "PACKAGE.DOC" for more info.
 *	To order a package, please refer to that same document, or see
 *	the internal help screen, or use IGORView to get more info.
 */

#define WM_CREATED	24893	/* Message sent to window when successfully created */
#define WM_KILL		24894	/* Message sent to window when about to be killed */
#define WM_DIALOG	24895	/* Message sent to window upon dialog action */
#define WM_KEYBD	24896	/* Message sent to window upon keypress */
#define WM_BUTTON	24897	/* Message sent to window upon button press */
#define	WM_FKEY		24900	/* Message sent to window upon function key selection */
#define	WM_HELP		24901	/* Message sent to window upon help key selection */
#define	WM_UNDO		24902	/* Message sent to window upon undo key selection */
#define	WM_KBRESET	24903	/* Message sent to window upon keyboard reset (TOS 1.0-1.2) */
#define	WM_MENU		24904	/* Message sent to window upon menu selection */

#define WC_NOTOBJECTABLE	0	/* Window can be closed w/o asking */
#define WC_OBJECTABLE		1	/* Pause before closing window */
#define	WC_FORCED			2	/* Force window to be closed */

#define TRUE			1	/* Boolean TRUE */
#define FALSE			0	/* Boolean FALSE */
#define FAIL			-1	/* Boolean FAIL */
#define NOMORE		FAIL	/* Window open failure (no more wins) */

#define W_OPEN				0x01	/* Window is currently opened */
#define W_MINIMIZED 		0x02	/* Window is minimized */
#define W_UNUNTOPPABLE		0x04	/* Window cannot be untopped */
#define W_FULLERMINIMIZES	0x08	/* Window fuller box minimizes */
#define W_BEVENT			0x10	/* Window accepts bkgnd clicks */
#define W_MODAL				0x20	/* Window is modal */
#define	W_TIMER				0x0400	/* Window is a timer */
#define	W_DIALOG			0x0800	/* Window is a dialog */
#define	W_RESERVED1			0x2000	/* These are reserved */
#define	W_RESERVED2			0x4000	/* . */
#define	W_RESERVED3			0x8000	/* for future use */
#define W_DIAL				W_OPEN | W_FULLERMINIMIZES
#define W_ALERT				W_OPEN | W_FULLERMINIMIZES | W_UNUNTOPPABLE | W_MODAL

#define	W_MOVE_ATTRIBUTES	NAME|MOVER
#define	W_DIAINF_ATTRIBUTES	NAME|CLOSER|FULLER|MOVER|INFO

#define WF_MINIMIZE 		24890	/* Minimizable window */
#define WF_UNUNTOPPABLE		24891	/* Cannot untop window */
#define WF_MODAL			24892	/* Modal dialog box */
#define	WF_TIMER			24896	/* Timer window */
#define	WF_DIALOG			24897	/* Dialog window */

#define T_STOPPED	0					/* Timer stopped */
#define T_RUNNING	1					/* Timer running */
#define	T_PAUSED	2					/* Timer paused */
#define	T_RESUMED	T_RUNNING			/* Timer resumed */

#define	APGI_REGFONT	0	/* Regular font information */
#define	APGI_SMFONT		1	/* Small font information */
#define	APGI_COLORS		2	/* Resolution and color information */
#define	APGI_LANGUAGE	3	/* Language information */
#define	APGI_ENVIRON1	4	/* Environment #1 */
#define	APGI_ENVIRON2	5	/*       .     #2 */
#define	APGI_ENVIRON3	6	/*       .     #3 */
#define	APGI_RESVD1		7	/* Reserved for OS usage */
#define	APGI_MOUSE		8	/* Mouse support information */
#define	APGI_MENU		9	/* Menu support information */
#define	APGI_SHEL		10	/* Shel_write information */
#define	APGI_WINDOW		11	/* Extended WF_ support information */
#define	APGI_MESSAGE	12	/* Extended message information */
#define	APGI_OBJLIB		13	/* Object library information */
#define	APGI_FORMLIB	14	/* Form library information */
#define	APGI_WLGETINFO	-1	/* Get WinLIB PRO information (general) */

#define	SHANDLE			'HNDL'
#define	SSTATE			'STAT'
#define	SKIND			'KIND'
#define	SEDITOBJECT		'EOBJ'
#define	SEDITPOS		'EPOS'
#define	SHASEDIT		'HASE'
#define	SEDITDISP		'EDSP'
#define	SAMOUNTMOVED	'AMTM'

typedef struct hotkeys {
	char key;
	int objnum;
} HOTKEYS;

typedef struct image
{
	int		*hi_on, *hi_off, *lo_on, *lo_off;
} IMAGE;

typedef struct images
{
	int		count;
	IMAGE	*image;
} IMAGES;

typedef struct window
{
	int				handle;				/* Handle of window */
	int				state;				/* Current state of window
											W_OPEN				  = automatically opened
											W_MINIMIZED			  = "minimized"
											W_UNUNTOPPABLE		  = un-untoppable window
																	(i.e. requires full attention - should be used with W_MODAL)
											W_FULLERMINIMIZES	  = window is minimized rather than fulled when FULLER is selected
											W_BACKGROUND		  = window which can be clicked in in the background
											W_MODAL 			  = window which blocks mouse clicks to all other windows,
																	*even* if they have the W_BACKGROUND mode
																	(i.e. requires full attention - should be used with W_UNUNTOPPABLE)
											W_DIALOG			  = W_OPEN | W_FULLERMINIMIZES
											W_ALERT				  = W_OPEN | W_FULLERMINIMIZES | W_UNUNTOPPABLE | W_MODAL
										 */
	int				kind;				/* Visual attributes of window */
	GRECT			size;
	char			title[128], info[128], origtitle[128];
										/* Title, info and original (untouched) title for window */
	struct window	*prev, *next;		/* Pointer to previous and next window in chain */
	OBJECT			*menubar;			/* Menu bar */
	OBJECT			*tree;				/* Pointer to resource tree */
	int				edobject, edpos;	/* First editable field in resource tree, and position of cursor */
	int				has_edit;			/* Does the dialog box have an editable object? */
	int				edit_disp;			/* Editing cursor displayed flag */
	int				slidpos[10],slidmax[10];	/* Position and maximum position of sliders at any given time */
	long			slidacc[10],slidstep[10];	/* Slider accumulator and step accumulator for the slider routine */
	void			*WndDispatcher;		/* Dispatcher procedures for window */
	void			*user;				/* User parameters to give Dispatcher routines */
	char			*textlines;			/* Text to show inside a window if you've got a text window... */
	int				topline;			/* Line to start printing text from */
	int				amount_moved;		/* Direction, and number of lines that need to be redrawn, the quick way. */
	int				popups[20];			/* These are the selections that have been clicked for your popups. */
	HOTKEYS			hot_keys[20];		/* Hotkey (dialog) information */
	HOTKEYS			hot_text[20];		/* Hotkey (text) information */
	OBJECT			*wininfo;			/* Window elements making up window tree.  It's cheating, but it works! */
	int				toppointer;			/* Character pointer to the first character in the top line */
} WINDOW;

typedef struct timer
{
	long	clock;
	long	ev_mtcount;					/* Timer counter */
	void	*TmrDispatcher;				/* Dispatcher procedure */
	void	*user;						/* User parameters to give Dispatcher routine */
	int		status;						/* Status of timer */
} TIMER;

typedef struct applinfo
{
	/* Standard messages */
	int	resnum;			/* Current resolution */
	int colsup;			/* Number of colors supported */
	int	colicons;		/* Color icons supported */
	int newrsc;			/* New resource file supported */
	int langidx;		/* Language index */
	int multitask;		/* Preemptive multitasking */
	int extndapfind;	/* Extended ap_find */
	int	applsrch;		/* Appl_search */
	int rcfix;			/* rsrc_rcfix */
	int objcxfind;		/* objc_xfind */
	int menuclick;		/* menu_click */
	int shel_w_r;		/* shel_write/shel_read */
	int applread;		/* appl_read(-1) */
	int	shelget;		/* shel_get(-1) */
	int mbar1;			/* menu_bar(-1) */
	int mbar2;			/* menu_bar(MENU_INSTL) */
	int gmouse;			/* graf_mouse(258-260) */
	int osmouse;		/* Mouse maintained by OS */
	int submnus;		/* Submenus supported */
	int popupmnus;		/* Popup menus supported */
	int scrollable;		/* Scrollable menus supported */
	int exmnsel;		/* Extended MN_SELECTED */
	int wf_support;		/* Extended WF_ support */
	int wf_gadgets;		/* New window gadget support */
	int extra_msgs;		/* Extra messages supported */
	int msgbitfld;		/* Bitfield of extra messages supported */
	int msg_behavior;	/* Message behavior */
	int obj3d;			/* 3D Objects supported */
	int sysvar;			/* objc_sysvar */
	int tedinfofonts;	/* Fonts in TEDINFO structures */
	int fldial;			/* Flying dialogs supported */
	int magix;			/* Mag!x keyboard conversion tables */
	int cpret;			/* Cursor position always returned */

	/* WinLIB Standard messages */
	int	wlver;			/* Current version of WinLIB PRO */
} APINFO;

extern	int		VDIhandle;
extern	int		ColSupported, Life, Return, Ap_ID;
extern	int		gr_cw, gr_ch, gr_bw, gr_bh, small_font, large_font;
extern	int		color_font, num_colors;
extern	int		num_planes;
extern	int		rsrc_array[15];
extern	char	*prgnameheader;
extern	void	*_MainDispatcher, *_MainKeyDispatcher;
extern	GRECT	desk;
extern	MFDB	screen;
extern	TIMER	Timer;
extern	APINFO	globapinfo;
extern	OBJECT	*MYALERT, *desktop, *iconpopup;
extern	WINDOW	*WindowChain;

int		___DialEditDispatcher(WINDOW *win, int msg_buf[8]);
int		___EditOptionDispatcher(WINDOW *win, int msg_buf[8]);
int		___ExtOptionDispatcher(WINDOW *win, int msg_buf[8]);
int		___ExtendedDispatcher(WINDOW *win, int msg_buf[8]);
int		___MainHelpDispatcher(WINDOW *win, int msg_buf[8]);
int		___MainOptionDispatcher(WINDOW *win, int msg_buf[8]);

void	box(int x, int y, int w, int h, int color);
void	box_fill(int x, int y, int w, int h, int color);
void	domenu(WINDOW *win);
void	edit_off(WINDOW *win);
void	edit_on(WINDOW *win);
void	edit_pos(WINDOW *win, int where);
void	fill(int x, int y, int color);
void	fillarea(int x1, int y1, int x2, int y2, int interior, int color);
int		find_position(OBJECT *obj, int No, int mx);
void	init_images(void);
void	init_mfdb(MFDB *fm, int *adr, int w, int h, int st, int pl);
void	line(int x1, int y1, int x2, int y2);
void	no_click(void);
void	point(int x, int y, int color);
void	position_fix(OBJECT *obj);
int		rc_intersect(GRECT *r1, GRECT *r2);
int		rc_inside(int x, int y, GRECT *r);
void	reset_vdi(void);
void	restore_clip(void);

int		AlertDispatcher(WINDOW *win, int msg_buf[]);
int		CallControlPanel(OBJECT *menu_addr);
void	CallInternalHelp(void);
void	ChangeObjectText(OBJECT *obj, int idx, char *txt, int fnt, int just);
void	DoHorizontalSlide(WINDOW *win, int number, int trackix,
					int slidix, int leftix, int rightix, int whichix,
					int trakstep, int strtrack);
void	DoVerticalSlide(WINDOW *win, int number, int trackix,
					int slidix, int upix, int downix, int whichix,
					int trakstep, int strtrack);
int		HoldSelection(void);
void	HorizontalSlideReset(WINDOW *win, int number, int maximum, int initial,
					int trackix, int slidix, int strtrack, int redraw);
void	LockScreenUpdate(void);
void	Objc_Change(OBJECT *tree, int ob_cobject, int ob_crecvd, int ob_cnewstate, int ob_credraw);
int		Rsrc_Free(void);
void	UnlockScreenUpdate(void);
void	VerticalSlideReset(WINDOW *win, int number, int maximum, int initial,
					int slidix, int trackix, int strtrack, int redraw);
int		WAppl_GetInfo(int ap_gtype, int *ap_gout1, int *ap_gout2, int *ap_gout3, int *ap_gout4);
void	WAppl_SetupInfo();
int		WCallAlertDispatcher(WINDOW *win, int alexit, int alnumber);
int		WCallBtnDispatcher(WINDOW *win, int mx, int my, int button, int kstate, int bclicks);
int		WCallDlgDispatcher(WINDOW *win, int message);
int		WCallEtcDispatcher(int msg_buf[]);
int		WCallFKeyDispatcher(WINDOW *win, int fkeynum);
int		WCallHelpDispatcher(WINDOW *win);
int		WCallKeyDispatcher(int key);
int		WCallResetDispatcher(WINDOW *win, int mode);
int		WCallTmrDispatcher(TIMER *timer);
int		WCallUndoDispatcher(WINDOW *win);
int		WCallWKeyDispatcher(WINDOW *win, int key);
int		WCallWndDispatcher(WINDOW *win, int msg_buf[]);
void	WCruelCloseWindow(WINDOW *win);
void	WCloseWindow(WINDOW *win, int message);
void	WCreateTimer(int status, long ev_tcount, int TmrDispatcher(TIMER *), void *user);
WINDOW	*WCreateWindow(int state, int kind,
						char *title, char *info,
						int object, int edobject,
						int menubar,
						int WndDispatcher(WINDOW *, int[]),
						void *user,
						int x, int y, int w, int h,
						OBJECT *obj, char textarray[]);
int		WDoDial(void);
void	WDie(int returns);
void	WDragBox(int width, int height, int beginx, int beginy,
				int boundx, int boundy, int boundw, int boundh,
				int linecolor, int linetype, int linepattern,
				int *endx, int *endy, int animate);
int		WForm_button(WINDOW *win, int obj, int clicks, int *nxtobj);
int		WForm_keybd(WINDOW *win, int key, int kstate, int *nobj, int *nchr);
int		WFormCustAlert(int icn, char *text1, char *at1, char *at2, char *at3, char *at4, char *at5,
						char *bt1, char *bt2, char *bt3);
int		WInit(int ap_id, int *work_out,
				int DeskWndDispatcher(WINDOW *, int[]),
				int MainDispatcher(int[]),
				int KeyDispatcher(int),
				char *prgname, char *header);
void	WInitAlert(void);
int		WIsTopped(int handle);
void	WKillWindow(WINDOW *win);
void	WKillAllWindows(void);
void	WMoveWindow(WINDOW *win, int x, int y, int w, int h);
int		WMenuBar(OBJECT *me_btree, int me_bshow);
void	WMsgWindow(WINDOW *win, int msg_buf[]);
int		WOpenWindow(WINDOW *win);
void	WReassignWindow(WINDOW *win,
						int state, int kind, char *title, char *info, 
						int object, int edobject, int edpos,
						int menubar, int WndDispatcher(WINDOW *, int[]), 
						void *user, int w, int h,
						OBJECT *obj, char textarray[], int redraw);
void	WRedrawAllWindows(void);
void	WRedrawWindow(WINDOW *win, int x, int y, int w, int h);
void	WStartTimer(void);
void	WStopTimer(void);
void	WTerm(void);
TIMER	*WTimerStat(void);
void	WTopWindow(WINDOW *win);
void	WUpdateWindowDlg(WINDOW *win, int x, int y, int w, int h, int obj);
void	WUpdateWindowMenu(WINDOW *win, int x, int y, int w, int h);
int		WWindGet(WINDOW *win, int wi_gfield, ...);
int		WWindSet(WINDOW *win, int wi_sfield, ...);
