/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "ui/ui_event_handler.h"

		using namespace GS::S2D;


//------------------------------------------------------------------------------
EventHandler		*EventTable::GetHandler(EventCode code) const
{
	ListForeachPtr(EventHandler *, h, handler_list)
		if	(h->GetCode() == code)
			return h;
	return NULL;
}
EventHandler		*EventTable::SetHandler(EventCode code, GS::Script::Object *h, GS::Script::Object *c)
{
	EventHandler *handler = GetHandler(code);

	if	(!handler)
	{
		handler = new EventHandler(code);
		handler_list.Add(handler);
	}

	handler->handler = h;
	handler->context = c;
	return handler;
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void				EventTable::DeleteHandler(EventCode code)
{
	handler_list.Remove(GetHandler(code));
}
bool				EventTable::HasHandlerContext(EventCode code) const
{
	EventHandler *handler = GetHandler(code);
	if	(!handler)
		return false;
	return asbool(handler);
}
//------------------------------------------------------------------------------
