/********************************************************************
 *																	*
 *	Extended appl_getinfo for WinLIB PRO							*
 *	Copyright (C) 1994, Bitgate Software and Clever Bits			*
 *																	*
 *	This routine is not intended to replace appl_getinfo for the	*
 *	TOS versions that handle it; it just allows for the usage of an	*
 *	extended type of appl_getinfo for WinLIB PRO as of now.  In		*
 *	short, it provides a substitute for programmers who are using	*
 *	this part of the library for compatibility purposes.			*
 *																	*
 ********************************************************************
 *																	*
 *	Update log:														*
 *		*NONE*														*
 *																	*
 ********************************************************************/

#include "winlib.h"
#include "tos.h"

APINFO	globapinfo;

#ifndef __APPL__
#define __APPL__
#endif

/*
 *	Setup appl_getinfo array for TOS<4.0 users
 *	Self explanatory
 */
GLOBAL void WAppl_SetupInfo()
{
	globapinfo.resnum = Getrez();
	globapinfo.colsup = num_colors;
	globapinfo.colicons = 0;
	globapinfo.newrsc = 0;
	globapinfo.langidx = 0;
	globapinfo.multitask = 2;
	globapinfo.extndapfind = 0;
	globapinfo.applsrch = 0;
	globapinfo.rcfix = 0;
	globapinfo.objcxfind = 0;
	globapinfo.menuclick = 0;
	globapinfo.shel_w_r = 0;
	globapinfo.applread = 0;
	globapinfo.shelget = 0;
	globapinfo.mbar1 = 0;
	globapinfo.mbar2 = 0;
	globapinfo.gmouse = 1;
	globapinfo.osmouse = 2;
	globapinfo.submnus = 0;
	globapinfo.popupmnus = 1;
	globapinfo.scrollable = 0;
	globapinfo.exmnsel = 0;
	globapinfo.wf_support = 0;
	globapinfo.wf_gadgets = 0;
	globapinfo.extra_msgs = 0;
	globapinfo.msgbitfld = 0;
	globapinfo.msg_behavior = 0;
	globapinfo.obj3d = 1;
	globapinfo.sysvar = 0;
	globapinfo.tedinfofonts = 0;
	globapinfo.fldial = 1;
	globapinfo.magix = 0;
	globapinfo.cpret = 0;
	globapinfo.wlver = 0x0060;
}

/*
 *	Customized appl_getinfo from TOS 4.0+
 *
 *	Called EXACTLY the same way appl_getinfo is called, and all
 *	indices for ap_gtype are the same.  Any 1/0 flags return 2 if
 *	the information is non-standard to TOS, or is different in WinLIB
 *
 *	Returns: FAIL on failure/non-handled codes (TOS < 4.0)
 *			 FALSE on any other failure (non-recognized)
 *			 TRUE on success
 */
GLOBAL int WAppl_GetInfo(int ap_gtype, int *ap_gout1, int *ap_gout2,
				  int *ap_gout3, int *ap_gout4)
{
	int ret;

	*ap_gout1 = 0;
	*ap_gout2 = 0;
	*ap_gout3 = 0;
	*ap_gout4 = 0;
	ret = 0;

	if ((AES_VERSION<0x0400) && (ap_gtype > 0)) {
		switch(ap_gtype) {
			case 0:
			case 1:
			case 7:
			case 10:
				ret = FAIL;
				break;

			case 2:
				*ap_gout1 = globapinfo.resnum;
				*ap_gout2 = globapinfo.colsup;
				*ap_gout3 = globapinfo.colicons;
				*ap_gout4 = globapinfo.newrsc;
				ret = TRUE;
				break;

			case 3:
				*ap_gout1 = globapinfo.langidx;
				ret = TRUE;
				break;

			case 4:
				*ap_gout1 = globapinfo.multitask;
				*ap_gout2 = globapinfo.extndapfind;
				*ap_gout3 = globapinfo.applsrch;
				*ap_gout4 = globapinfo.rcfix;
				ret = TRUE;
				break;

			case 5:
				*ap_gout1 = globapinfo.objcxfind;
				*ap_gout2 = 0;
				*ap_gout3 = globapinfo.menuclick;
				*ap_gout4 = globapinfo.shel_w_r;
				ret = TRUE;
				break;

			case 6:
				*ap_gout1 = globapinfo.applread;
				*ap_gout2 = globapinfo.shelget;
				*ap_gout3 = globapinfo.mbar1;
				*ap_gout4 = globapinfo.mbar2;
				ret = TRUE;
				break;

			case 8:
				*ap_gout1 = globapinfo.gmouse;
				*ap_gout2 = globapinfo.osmouse;
				ret = TRUE;
				break;

			case 9:
				*ap_gout1 = globapinfo.submnus;
				*ap_gout2 = globapinfo.popupmnus;
				*ap_gout3 = globapinfo.scrollable;
				*ap_gout4 = globapinfo.exmnsel;
				ret = TRUE;
				break;

			case 11:
				*ap_gout1 = globapinfo.wf_support;
				*ap_gout2 = 0;
				*ap_gout3 = globapinfo.wf_gadgets;
				*ap_gout4 = 0;
				ret = TRUE;
				break;

			case 12:
				*ap_gout1 = globapinfo.extra_msgs;
				*ap_gout2 = globapinfo.msgbitfld;
				*ap_gout3 = globapinfo.msg_behavior;
				ret = TRUE;
				break;

			case 13:
				*ap_gout1 = globapinfo.obj3d;
				*ap_gout2 = globapinfo.sysvar;
				*ap_gout3 = globapinfo.tedinfofonts;
				*ap_gout4 = 0;
				ret = TRUE;
				break;

			case 14:
				*ap_gout1 = globapinfo.fldial;
				*ap_gout2 = globapinfo.magix;
				*ap_gout3 = globapinfo.cpret;
				*ap_gout4 = 0;
				ret = TRUE;
				break;
		}
	}

	if ((AES_VERSION>=0x0400) && (ap_gtype<0)) {
		int d1, d2, d3, d4;

		ret = appl_getinfo(ap_gtype, &d1, &d2, &d3, &d4);

		*ap_gout1 = d1;
		*ap_gout2 = d2;
		*ap_gout3 = d3;
		*ap_gout4 = d4;
	}

	if (ap_gtype<0) {
		switch(ap_gtype) {
			case -1:
				*ap_gout1 = globapinfo.wlver;
				ret = TRUE;
				break;
		}
	}

	return(ret);
}