#ifndef _EVENT_BASE_H_
#define _EVENT_BASE_H_

#include <tk.h>
#include <tcl.h>

#include <map>
#include <string>
#include <vector>

#include "../../../tobject.h"
#include "../../../ptr.h"

#include "../../tcl_interp.h"
#include "../../tcl_guid.h"

#include "efield.h"

using namespace std;

class TkBase;

namespace event
{

/**
 * \brief EHeader field represent common event attributes
 * \date 01-12-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class EHeader
{
public:
	int serial;
	string id;
	int time;
	string root;
	string subwindow;
	string type;
	string widget;
	bool sendevent;

	TkBase* source;
};

class EBase;

/**
 * \brief EBase is base class for all widget event handlers.
 * \date 01-12-2006
 *
 * \author Ondrej Svejdar
 *
 * \todo 
 *
 * \bug 
 *
 */
class EBase
{
	int fieldsLength;
public:
	typedef map<string,EBase*> t_bind_table;
private:
	static t_bind_table bindTable;

	static EBase* getEventById(const string& id);

	void createBind(TclInterp* interp,Tk_Uid widgetName);

	TkBase* widget;
	const char* eventType;
	const EField** eventFields;
protected:
	bool anyListenerRegistred;
	TclGuid guid;

	EBase(const char* eventType,const EField* eventFields[]);
	~EBase();

	virtual int preprocessEvent(EHeader& header,Tcl_Interp* interp,int objc,Tcl_Obj* CONST objv[])=0;

	void afterListenerRegistred();
	void bind(TkBase* const widget);
public:
	/**
	 * \brief This method is invoked directly by Tcl lib, parameters are parsed and distribued as event.
	 * \param clientData custom data (empty)
	 * \param interp interpret
	 * \param objc number of arguments
	 * \param objv[] arguments array
	 * \return TCL_OK (always), just for compatibility reasons
	 */
	static int handleEvent(ClientData clientData,Tcl_Interp* interp,int objc,Tcl_Obj* CONST objv[]);
};

};

#endif/*_EVENT_BASE_H_*/

