
// --------------------------------------------------------------------------

#ifndef CPP_AWINDOW_H
#define CPP_AWINDOW_H

#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>

#include <clib/intuition_protos.h>
#include <clib/exec_protos.h>

#ifdef __cplusplus
extern "C" {
#endif
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
#ifdef __cplusplus
}
#endif

// CPP Includes

#include <exec/aTask.h>
#include <exec/aMessage.h>
#include <exec/aSemaphore.h>

class aWindow
{
protected:
	Window      *m_Window;
	RastPort    *m_RastPort;

   aProcess *aw_Task;
	aMsgPort aw_MsgPort;
	aSemaphore as_Synch;

	static void __saveds ProcessMessage(aWindow* us);

public:
	aWindow();
	virtual ~aWindow();

	virtual BOOL Open(int width = 640,int height = 400,char *wTitle = NULL,long wFlags = -1,long wIDCMP = -1);
	void Close();

	virtual void OnMessage(Window *window = NULL,IntuiMessage *msg = NULL) {}
	virtual void OnNewSize(APTR msg = NULL) {}
	virtual void OnRefresh(APTR msg = NULL) {}
	virtual void OnKey(long Key = 0,long Qualifier = 0) {}
	virtual void OnRawKey(long Key = 0,long Qualifier = 0) {}
	virtual void OnMenuPick(long men,long qualifier) {};

	virtual void OnClose(); // is called by the wind process when Close() is called

	void SetWindowTitle(char *val);
	RastPort *GetRastPort() { return m_RastPort; }
	operator Window*() { return m_Window; }
	Screen* GetScreen() 
	{ 
		if (m_Window)
			return m_Window->WScreen;

		return NULL;
	};
	aMsgPort* GetMsgPort()
	{
		if (m_Window)
			return (&aw_MsgPort);
		else
			return NULL;
	}

	void operator=(aWindow&);

};


#endif // CPP_AWINDOW_H
