/*
leda uses the fucking exit for destroying the window , so no destructors are called and nothing
works properly (i wonder in their exaples do theu now that)??????
this window handles all events be assign a function for each one of them
also every time the algorithm processes an event it checks a flag th _exitraised
wich is set by the close_window function so that it will exit from the
begin_msg_translation normaly and then call destructros normaly
*/

class actualwindow : public window
{
	bool	_exitraised;
public:
	actualwindow(const char *);
	virtual ~actualwindow(){};

	void close_window() { _exitraised=true; };
	void begin_msg_translation();

//message handlers
	virtual void on_msg_wndresize(){};
	virtual void on_msg_mousemove(point){};
	virtual void on_msg_mousedown(int,point){};
	virtual void on_msg_mouseup(int,point){};
	virtual void on_msg_keydown(int){};
	virtual void on_msg_keyup(int){};

};

actualwindow::actualwindow(const char *szlabel):window(szlabel),_exitraised(false)
{
}

void actualwindow::begin_msg_translation()
{
	//if a callere cals exit then it will be parsed imidately, as this exit will come
	//from a function inside read_event, so just after the function enters , 
	//the raised flag will be processed

	double x,y;
	int val;
	unsigned long time;
	int event;
	do
	{
		event = read_event(val,x,y,time);
		switch(event)
		{
		case(configure_event):
			on_msg_wndresize();
			break;
		case(motion_event):
			on_msg_mousemove(point(x,y));
			break;
		case(button_press_event):
			on_msg_mousedown(val,point(x,y));
			break;
		case(button_release_event):
			on_msg_mouseup(val,point(x,y));
			break;
		case(key_press_event):
			on_msg_keydown(val);
			break;
		case(key_release_event):
			on_msg_keyup(val);
			break;
		}
	}while(!_exitraised);
}
