/*
 * Name:	MG 2a Iconify the MG window using Leo Schwab's iconify()
 * routine. Last Edit:	07-Jan-88	mic@emx.utexas.edu Created:
 * 04-Jan-88	mic@emx.utexas.edu
 */

#include "do_iconify.h"
#ifdef	DO_ICONIFY

#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#ifdef LATTICE
#include <proto/all.h>
#else
#include <functions.h>
#endif

#undef	TRUE
#undef	FALSE
#include "def.h"
#include "iconify.h"

#ifdef	ANSI
#include <string.h>
#endif

/*
 * Simple Mg 3a icon image.  We need a more imaginative one.
 */


UWORD  mg3a[216] = {
	/* bitplane #0 */
	0x0000, 0x0000, 0x0000, 0x0000,
	0x0000, 0x0000, 0x0000, 0x0000,
	0x0000, 0x0000, 0x0000, 0x0000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x387F, 0x1FFF, 0x0FFF, 0xF000,
	0x3C3F, 0x3FFE, 0xE7FF, 0xF000,
	0x3CBE, 0x3FFE, 0x73FF, 0xF000,
	0x3CBE, 0x3EFF, 0xF7EF, 0xF000,
	0x3C9C, 0x3C47, 0xE793, 0xF000,
	0x3C9D, 0x3D9F, 0xCFBB, 0xF000,
	0x3CC9, 0x39BF, 0xE7F3, 0xF000,
	0x3CCB, 0x39BF, 0xF3CB, 0xF000,
	0x3CCB, 0x3D3E, 0x73BB, 0xF000,
	0x3CE3, 0x3C7E, 0xE73A, 0xF000,
	0x3866, 0x1E1F, 0x0F80, 0xF000,
	0x3FFF, 0xFCCF, 0xFFFF, 0xF000,
	0x3FFF, 0xFDEF, 0xFFFF, 0xF000,
	0x3FFF, 0xFDDF, 0xFFFF, 0xF000,
	0x3FFF, 0xFC1F, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x3FFF, 0xFFFF, 0xFFFF, 0xF000,
	0x0000, 0x0000, 0x0000, 0x0000,
	0x0000, 0x0000, 0x0000, 0x0000,

	/* bitplane #1 */
	0xFFFF, 0xFFFF, 0xFFFF, 0xFE00,
	0xFFFF, 0xFFFF, 0xFFFF, 0xFE00,
	0xFFFF, 0xFFFF, 0xFFFF, 0xFE00,
	0xC000, 0x0000, 0x0000, 0x0E00,
	0xCFFF, 0xFFFF, 0xFFFF, 0xEE00,
	0xC87F, 0x1FFF, 0x0FFF, 0xEE00,
	0xCC3F, 0x3FFE, 0xE7FF, 0xEE00,
	0xCCBE, 0x3FFE, 0x73FF, 0xEE00,
	0xCCBE, 0x3EFF, 0xF7EF, 0xEE00,
	0xCC9C, 0x3C47, 0xE793, 0xEE00,
	0xCC9D, 0x3D9F, 0xCFBB, 0xEE00,
	0xCCC9, 0x39BF, 0xE7F3, 0xEE00,
	0xCCCB, 0x39BF, 0xF3CB, 0xEE00,
	0xCCCB, 0x3D3E, 0x73BB, 0xEE00,
	0xCCE3, 0x3C7E, 0xE73A, 0xEE00,
	0xC866, 0x1E1F, 0x0F80, 0xEE00,
	0xCFFF, 0xFCCF, 0xFFFF, 0xEE00,
	0xCFFF, 0xFDEF, 0xFFFF, 0xEE00,
	0xCC00, 0x0000, 0x0000, 0xEE00,
	0xCFFF, 0xFC1F, 0xFFFF, 0xEE00,
	0xCF80, 0x0000, 0x0000, 0x0E00,
	0xCFFF, 0xFFFF, 0xFFFF, 0xEE00,
	0xCE00, 0x0000, 0x0000, 0x2E00,
	0xCFFF, 0xFFFF, 0xFFFF, 0xEE00,
	0xC000, 0x0000, 0x0000, 0x0E00,
	0xFFFF, 0xFFFF, 0xFFFF, 0xFE00,
	0xFFFF, 0xFFFF, 0xFFFF, 0xFE00,
};

static struct Image iconimg = {	/* Icon Image  */
	0, 0,
/*	54, 20, 2,*/
	54, 27, 2,
	NULL,			/* filled in later */
	0x3, 0,
	NULL
};

/*
 * Iconify MG's window using tthide(), iconify(), and ttshow().
 */

int 
tticon(f, n)
{
	static UWORD    iconX = 0, iconY = 0;
	UWORD          *chipbitmap;
	struct Image   *chipimg;
	extern short    toggling;

	/* copy the bitmap into chip memory */
	if (NULL == (chipbitmap = (UWORD *)
		 AllocMem((ULONG) sizeof(mg3a), MEMF_CHIP | MEMF_PUBLIC))) {
		ewprintf("Can't allocate image bitmap");
		return FALSE;
	}
	bcopy((char *) mg3a, (char *) chipbitmap, (int) sizeof(mg3a));

	/* copy the image structure too */
	if (NULL == (chipimg = (struct Image *)
	      AllocMem((ULONG) sizeof(iconimg), MEMF_CHIP | MEMF_PUBLIC))) {
		FreeMem(chipbitmap, (ULONG) sizeof(iconimg));
		ewprintf("Can't allocate image structure");
		return FALSE;
	}
	bcopy((char *) &iconimg, (char *) chipimg, (int) sizeof(iconimg));
	chipimg->ImageData = chipbitmap;

	/* hide the window, display the icon, then redisplay the window */
	tthide(FALSE);		/* not resizing */

	iconify(&iconX, &iconY, chipimg->Width, chipimg->Height, NULL,
		(APTR) chipimg, (int) ICON_IMAGE);	/* iconify	 */
	FreeMem(chipimg, (ULONG) sizeof(iconimg));
	FreeMem(chipbitmap, (ULONG) sizeof(mg3a));

	ttshow(FALSE);		/* no resize */
	return TRUE;
}
#else
#include "nullfile.h"
#endif				/* DO_ICONIFY */

