/*
 *  Routines dealing with processing of Yak's icon
 *  (be they for tooltypes or AppIcon purposes).
 *  
 *  MWS, Tuesday 13-Oct-92
 */
#include <exec/types.h>
#include <dos/dos.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/wb.h>
#include <proto/icon.h>

static struct DiskObject *yakobj;

BOOL
GetOurIcon(struct WBStartup *WBenchMsg)
{
	if (WBenchMsg)
		yakobj = GetDiskObject(WBenchMsg->sm_ArgList->wa_Name);
	return yakobj ? TRUE : FALSE;
}

void
FreeOurIcon()
{
	if (yakobj) FreeDiskObject(yakobj);
}

/* like ArgString() */
char *
TTString(char *name, char *def)
{
	char *what;
	if (yakobj)
		if (what = FindToolType(yakobj->do_ToolTypes, name))
			return what;
	return def;
}

/* like ArgInt() */
LONG
TTInt(char *name, LONG def)
{
	char *what;
	if (yakobj)
		if (what = FindToolType(yakobj->do_ToolTypes, name))
			StrToLong(what, &def);
	return def;
}

/* simple extension to ArgXXX routines */
BOOL
TTBool(char *name, BOOL def)
{
	char	*s;

	s = TTString(name, def ? "YES" : "NO");

	return	((strcmp(s, "YES") == 0) ||
		(strcmp(s, "TRUE") == 0) ||
		(strcmp(s, "ON") == 0)) ? TRUE : FALSE;
}

#ifdef APPICON

LONG appsigflag;

static struct AppIcon *yakappicon;
static struct MsgPort *appport;

/* create our AppIcon */
BOOL
AddYakIcon(char *name)
{
	if (yakobj)
		if (appport = CreateMsgPort())
		{
			yakobj->do_CurrentX = TTInt("ICONXPOS", NO_ICON_POSITION);
			yakobj->do_CurrentY = TTInt("ICONYPOS", NO_ICON_POSITION);
			if (yakappicon = AddAppIconA(0,0L,name,appport,0L,yakobj,0L))
			{
				appsigflag = 1 << appport->mp_SigBit;
				return TRUE;
			}
			else DeleteMsgPort(appport);
		}
	return FALSE;
}

/* bye bye icon... */
void
RemoveYakIcon()
{
	if (yakappicon) RemoveAppIcon(yakappicon);
	if (appport) DeleteMsgPort(appport);
}

/* just clear the port */
void
RespondToYakIcon()
{
	struct Message *msg;
	while (msg = GetMsg(appport))
		ReplyMsg(msg);
}

#endif /* APPICON */