#include <windows.h>
#include <stdio.h>
#include <bncs_string.h>
#include <bncs_config.h>
#include "StatusDisplayRouter.h"

#define PNL_MAIN	1

#define TIMER_SETUP	1

// this nasty little macro to make our class visible to the outside world
EXPORT_BNCS_SCRIPT( StatusDisplayRouter )

// constructor - equivalent to ApplCore STARTUP
StatusDisplayRouter::StatusDisplayRouter( bncs_client_callback * parent, const char * path ) : bncs_script_helper( parent, path )
{
	// show a panel from file p1.bncs_ui and we'll know it as our panel PNL_MAIN
	panelShow( PNL_MAIN, "router.bncs_ui" );
	routerRegister(3, 1, 12);
	routerPoll(3, 1, 12);

	// you may need this call to set the size of this component 
	//  if it's used in a popup window 
//	setSize( 1024,668 );		// set the size explicitly
//	setSize( PNL_MAIN );		// set the size to the same as the specified panel
}

// destructor - equivalent to ApplCore CLOSEDOWN
StatusDisplayRouter::~StatusDisplayRouter()
{
}

// all button pushes and notifications come here
void StatusDisplayRouter::buttonCallback( buttonNotify *b )
{

}

// all revertives come here
int StatusDisplayRouter::revertiveCallback( revertiveNotify * r )
{
	switch( r->device() )
	{
		case 3:
			bncs_string imageFile;
			imageFile = setImage(r->info());
			bncs_string destination;
			destination = "Dest" + bncs_string(r->index());
 			textPut( "pixmap", imageFile, PNL_MAIN, destination );
			break;
	}
	return 0;
}

// all database name changes come back here
void StatusDisplayRouter::databaseCallback( revertiveNotify * r )
{
}

// all parent notifications come here i.e. when this script is just one 
//  component of another dialog then our host might want to tell us things
bncs_string StatusDisplayRouter::parentCallback( parentNotify *p )
{
	if( p->command() == "return" )
	{
		if( p->value() == "all" )
		{	// Persisting values for bncs_vis_ed
			bncs_stringlist sl;
			
			sl << bncs_string( "myParam=%1" ).arg( m_myParam );
			
			return sl.toString( '\n' );
		}

		else if( p->value() == "myParam" )
		{	// Specific value being asked for by a textGet
			return( bncs_string( "%1=%2" ).arg( p->value() ).arg( m_myParam ) );
		}

	}
	else if( p->command() == "instance" && p->value() != m_instance )
	{	// Our instance is being set/changed
		m_instance = p->value();
		//Do something instance-change related here
	}

	else if( p->command() == "myParam" )
	{	// Persisted value or 'Command' being set here
		m_myParam = p->value();
	}

	// ***** CONNECTIONS EVENTS HELPER LIST *****
	else if( p->command() == "_events" )
	{	// Helper-list of everything in this component generated by hostNotify's
		bncs_stringlist sl;

		sl << "notify=*";		
		
		return sl.toString( '\n' );
	}

	// ***** CONNECTIONS COMMANDS HELPER LIST *****
	else if( p->command() == "_commands" )
	{	// Helper-list of any commands/parameters you might want to set at run-time
		bncs_stringlist sl;
		
		sl << "myParam=[value]";
		
		return sl.toString( '\n' );
	}

	return "";
}

// timer events come here
void StatusDisplayRouter::timerCallback( int id )
{
	switch( id )
	{
	case TIMER_SETUP:
		timerStop(id);
		break;

	default:	// Unhandled timer event
		timerStop(id);
		break;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// Callbacks above - Methods below ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
bncs_string StatusDisplayRouter::setImage(int indexNumber)
{
	bncs_string imageFile;
	switch (indexNumber)
	{
	case 1:	imageFile = "/images/BBC1.png";	break;
	case 2:	imageFile = "/images/BBC2.png"; break;
	case 3: imageFile = "/images/ITV.png"; break;
	case 4: imageFile = "/images/CBeebies.png"; break;
	case 5: imageFile = "/images/Cam1.png"; break;
	case 6: imageFile = "/images/Cam2.png"; break;
	case 7: imageFile = "/images/Cam3.png"; break;
	case 8: imageFile = "/images/Cam4.png"; break;
	case 9: imageFile = "/images/VT.png"; break;
	case 10: imageFile = "/images/Bars.png"; break;
	case 11: imageFile = "/images/TestCard.png"; break;
	case 12: imageFile = "/images/Jack.png"; break;
	default: imageFile = "/images/FileNotFound.png"; break;

	}


	return imageFile;
}

