#include "gosGml.hpp"

//===========================================================================//
// File:	 rollover.cpp													 //
// Project:  gosGml														     //
// Contents:																 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 7/18/00   DP     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 2000 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//


#include "rollover.h"
//typedef void (*RolloverCallback)(int x, int y, char* ImageName, int ImageID);


Rollover::Rollover()
{
	H=new Hash<RolloverCallback,char*>(101);
}

Rollover::~Rollover()
{
	delete H;
}

DWORD Rollover::Add(ImageData* Image, RolloverCallback AddFunc)
{
	char* IDS=IDtoStr(Image);
	NameValuePair<RolloverCallback,char*>* NVP=new NameValuePair<RolloverCallback,char*>(IDS,AddFunc);
	H->AddHash(NVP);
	return Image->Handle;
}

void Rollover::Remove(ImageData* Image)
{
	char* IDS=IDtoStr(Image);
	NameValuePair<RolloverCallback,char*>* NVP=new NameValuePair<RolloverCallback,char*>(IDS);
	H->RemoveItem(NVP);
	delete NVP;
}

void Rollover::Clear()
{
	H->Clear();
}

void Rollover::CallOn(ImageData* Image)
{
	char* IDS=IDtoStr(Image);
	RolloverCallback FC=H->FindHit(IDS);
	if(FC)
		(*FC)(Image->x,Image->y,Image->Name,Image->Handle);
}
/*
struct ImageData
{
	char* Name;
	DWORD Handle;
	int x;
	int y;
};
*/
char* Rollover::IDtoStr(ImageData* Image)
{
	int lenn,lenx,leny,lenh;
	char* Res,*Tx,*Ty,*Th;
	char* Buff=new char[20];
	lenn=mstrlen(Image->Name);
	Tx=_itoa( Image->x, Buff, 10 );
	lenx=strlen(Tx);
	Ty=_itoa( Image->y, Buff, 10 );
	leny=strlen(Ty);
	Th=_itoa( Image->Handle, Buff, 10 );
	lenh=strlen(Th);
	Res=new char[lenn+lenx+leny+lenh+2];
	mstrcpy(Res,Image->Name);
	strcpy(Res+lenn,Tx);
	*(Res+lenn+lenx)='|';
	strcpy(Res+1+lenn+lenx,Ty);
	strcpy(Res+1+lenn+lenx+leny,Th);
	delete[] Buff;
	//delete[] Tx;
	//delete[] Ty;
	//delete[] Th;
	return Res;
}