#include <stream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>

#include "GUICINCLUDE:GUIC_Screen.hpp"
#include "GUICINCLUDE:GUIC_Application.hpp"
#include "GUICINCLUDE:GUIC_GGFXPicture.hpp"
#include "GUICINCLUDE:GUIC_Button.hpp"
#include "GUICINCLUDE:GUIC_Text.hpp"
#include "GUICINCLUDE:GUIC_Frame.hpp"
#include "GUICINCLUDE:GUIC_Event.hpp"
#include "GUICINCLUDE:GUIC_Exceptions.hpp"
#include "GUICINCLUDE:GUIC_FileExamine.hpp"
#include "GUICINCLUDE:GUIC_Error.hpp"

#include "InformationWindow.hpp"

/*********************************************************************************************************/

InformationWindowC::InformationWindowC 	(GUIC_ApplicationC &a, GUIC_ScreenC &s) : GUIC_WindowC (-1,-1,63,28)
{
	app 		= &a;
	screen	= &s;
	pic1		= 0;
	pic2		= 0;
	
	frame1	= new GUIC_FrameC		( 1, 1,30,26, "Picture To Be Copied");
	frame2	= new GUIC_FrameC		(32, 1,30,26, "Existing Picture");
	text1		= new GUIC_TextC			( 2,24,28, 2, "");
	text2		= new GUIC_TextC			(33,24,28, 2, "");
	
	text1->setBorder(FALSE);
	text2->setBorder(FALSE);
	
	text1->setJustification(GUIC_Center);
	text2->setJustification(GUIC_Center);
	
	add (frame1);
	add (frame2);
	add (text1);
	add (text2);
	
	app->addPrefs("InformationWindow",	this);

	setGuideContext("InformationWindow");
	setTitle ( "Information" );

	activate();
}
InformationWindowC::~InformationWindowC	(VOID)
{
	cleanUp();
}

/*********************************************************************************************************/

STRPTR	InformationWindowC::getClass		(VOID)
{
	return "InformationWindowC";
}

BOOL		InformationWindowC::action			(GUIC_EventC &e)
{
	switch (e.id)
		{
		case GUIC_OpenWindow:
			return TRUE;
			break;
		case GUIC_CloseWindow:
			if (pic1) { remove(pic1); delete pic1; pic1=0; }
			if (pic2) { remove(pic2); delete pic2; pic2=0; }
			text1->set("");
			text2->set("");
			screen->remove(this);
			return TRUE;
			break;
		}
	
	return FALSE;
}

VOID 		InformationWindowC::setPictures	(STRPTR fileName1, STRPTR fileName2)
{
	CHAR buffer[100];

	sleep();

	if (pic1) { remove(pic1); delete pic1; pic1=0; }
	if (pic2) { remove(pic2); delete pic2; pic2=0; }
	
	try
		{
		// Picture 1
		pic1 = new GUIC_GGFXPictureC( 2,2,28,22,fileName1);

		pic1->setScaled(TRUE);
		pic1->setCentered(TRUE);

		GUIC_FileExamineC f1 (fileName1);
		sprintf(buffer, "%ld x %ld (%ld Bytes)", pic1->getWidth(), pic1->getHeight(), f1.getSize() );

		text1->set(buffer);

		add (pic1);

		// Picture 2
		pic2 = new GUIC_GGFXPictureC(33,2,28,22,fileName2);

		pic2->setScaled(TRUE);
		pic2->setCentered(TRUE);

		GUIC_FileExamineC f2 (fileName2);
		sprintf(buffer, "%ld x %ld (%ld Bytes)", pic2->getWidth(), pic2->getHeight(), f2.getSize() );
		text2->set(buffer);

		add (pic2);	
		}
	catch (GUIC_Exception &e)
		{
		GUIC_ErrorC err ("Exception caught:", e.getMessage() );
		err.request(this);
		}
	
	waken();
}

/*********************************************************************************************************/

VOID 		InformationWindowC::cleanUp			(VOID)
{	
	if (pic1) { remove(pic1); delete pic1; pic1=0; }
	if (pic2) { remove(pic2); delete pic2; pic2=0; }

	delete frame1;
	delete frame2;
	delete text1;
	delete text2;	
}

