#include "ekeypress.h"

using namespace event;

const char* EKeyPress::eventType="KeyPress";
const EField* EKeyPress::eventFields[]=
{
	&EField::SERIAL,
	&EField::ID,
	&EField::TIME,
	&EField::ROOT_WINDOW,
	&EField::SUB_WINDOW,
	&EField::TYPE,
	&EField::WIDGET_PATHNAME,
	&EField::SENDEVENT,

	&EField::KEYCODE,
	&EField::STATE,
	&EField::PRINT_CHAR,
	&EField::KEYSYM,
	&EField::KEYSYM_DECIMAL,
	&EField::X_ROOT,
	&EField::Y_ROOT,

	&EField::END
};

int EKeyPress::preprocessEvent(EHeader& header,Tcl_Interp* interp,int objc,Tcl_Obj* CONST objv[])
{
	int keyCode;
	string state;
	string printChar;
	string keySym;
	int keySymDecimal;
	int x;
	int y;

	int index=10;

	Tcl_GetIntFromObj(interp,objv[index++],&keyCode);
	state=Tcl_GetString(objv[index++]);
	printChar=Tcl_GetString(objv[index++]);
	keySym=Tcl_GetString(objv[index++]);
	Tcl_GetIntFromObj(interp,objv[index++],&keySymDecimal);
	Tcl_GetIntFromObj(interp,objv[index++],&x);
	Tcl_GetIntFromObj(interp,objv[index++],&y);
	
	for(t_listeners::iterator it=listeners.begin();it!=listeners.end();it++)
	{
		(*it)->onKeyPress(header,keyCode,state,printChar,keySym,keySymDecimal,x,y);
	}

	return TCL_OK;
}

