/*
 *
 *  AM --- AmigaMail
 *  (C) 1991, 1992 by Christian Riede
 *
 *  AM is distributed in the hope that it will be useful, but WITHOUT ANY
 *  WARRANTY.  No author or distributor accepts responsibility to anyone
 *  for the consequences of using it or for whether it serves any
 *  particular purpose or works at all, unless he says so in writing.
 *  Refer to the GNU General Public License, Version 1, for full details.
 *  
 *  Everyone is granted permission to copy, modify and redistribute AM,
 *  but only under the conditions described in the GNU General Public
 *  License, Version 1.  A copy of this license is supposed to have been 
 *  given to you along with AM so you can know your rights and responsi-
 *  bilities.  It should be in a file named COPYING.  Among other things,
 *  the copyright notice and this notice must be preserved on all copies.
 *
 *  
 *
 */

#include "am.h"

/*
 *  libraries 
 */

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;

/* 
 *  Intuition structures 
 */

struct Window *Window;
struct Screen *Screen;
/* Our windows dimensions */
static int WLeft,WTop,WWidth,WHeight;

void Panic(int ret,char *message)
{
	/* show message */
	if (message)
		if (*message)
			if (IntuitionBase) SimpleRequest(Window,message);
			else puts(message);

	/* clear intuition stuff */
	if (Window) CloseWindow(Window);
	if (Screen) UnlockPubScreen(0,Screen);

	/* close libraries */
	if (GfxBase) CloseLibrary((struct Library *) GfxBase);
	if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
}


int main(int argc, char *argv[])
{
    unsigned long vpmid;
    struct DimensionInfo di;
    struct Rectangle *rect;
 
	if (!(IntuitionBase = (struct IntuitionBase *)
		OpenLibrary((UBYTE *)"intuition.library",AM_LIBRARY_VERSION)))
		Panic(20,"can't open intuition.library");

	if (!(GfxBase = (struct GfxBase *)
		OpenLibrary((UBYTE *)"graphics.library",AM_LIBRARY_VERSION)))
		Panic(20,"Can't open graphics.library");

	if (!(Screen = LockPubScreen((UBYTE *)PUBSCREENNAME)))
		Panic(20,"Can't lock AM's public screen");
		
	if ((vpmid = GetVPModeID(&Screen->ViewPort )) != INVALID_ID) 
	{
		GetDisplayInfoData(0, (UBYTE *)&di, sizeof(struct DimensionInfo), DTAG_DIMS, vpmid);
		rect = &di.TxtOScan;
		WTop = Screen->BarHeight+2L;
		WWidth = rect->MaxX;
		WHeight = rect->MaxY-(Screen->BarHeight+2L);
	}
	else 
		Panic(20,"Can't Get VPModeID!");

	if (!(Window = OpenWindowTags(0,
			WA_PubScreen,Screen,
			WA_Left,0L,
			WA_Top,WTop,
			WA_Width,WWidth,
			WA_Height,WHeight,
			WA_MinWidth,640L,
			WA_MinHeight,180L,
			WA_MaxWidth,1024L,
			WA_MaxHeight,1024L,
			WA_DragBar,TRUE,
			WA_DepthGadget,TRUE,
			WA_CloseGadget,TRUE,
			WA_SizeGadget,TRUE,
			WA_Activate,TRUE,
			WA_SmartRefresh,TRUE,
			WA_GimmeZeroZero,TRUE,
			TAG_END)))
			Panic(20,"Can't open Window!");
		

	

	/* OK, that was it */
	Panic(0,"");
}
