#ifndef __Event__H
#define __Event__H

#include "Coords.h"

typedef struct
{
	ScreenPos	pos;
	int		height;
	int		index;
} CCaret;

typedef enum
{
	EEvent_Null		= 0,
	EEvent_WindowRedraw	= 1,
	EEvent_WindowOpen	= 2,
	EEvent_WindowClose	= 3,
	EEvent_WindowPtrLeave	= 4,
	EEvent_WindowPtrEnter	= 5,
	EEvent_Mouse		= 6,
	EEvent_Drag		= 7,
	EEvent_Key		= 8,
	EEvent_Menu		= 9,
	EEvent_WindowScroll	= 10,
	EEvent_WindowLoseCaret	= 11,
	EEvent_WindowGainCaret	= 12,
	EEvent_PollWord		= 13,
	EEvent_Message		= 17,
	EEvent_MessageWantAck	= 18,
	EEvent_MessageAck	= 19
} EEventType;

typedef enum
{
	EMsg_Quit			= 0,
	EMsg_DataSave			= 1,
	EMsg_DataSaveAck		= 2,
	EMsg_DataLoad			= 3,
	EMsg_DataLoadAck		= 4,
	EMsg_DataOpen			= 5,
	EMsg_RAMFetch			= 6,
	EMsg_RAMTransmit		= 7,
	EMsg_PreQuit			= 8,
	EMsg_PaletteChange		= 9,
	EMsg_SaveDesktop		= 10,
	EMsg_DeviceClaim		= 11,
	EMsg_DeviceInUse		= 12,
	EMsg_DataSaved			= 13,
	EMsg_Shutdown			= 14,
	EMsg_ClaimEntity		= 15, /* Clipboard */
	EMsg_DataRequest		= 16, /* from Clipboard */
	EMsg_Dragging			= 17,
	EMsg_DragClaim			= 18,
	EMsg_FilerOpenDir		= 0x400,
	EMsg_FilerCloseDir		= 0x401,
	EMsg_FilerOpenDirAt		= 0x402,
	EMsg_FilerSelectionDirectory	= 0x403,
	EMsg_FilerAddSelection		= 0x404,
	EMsg_FilerAction		= 0x405,
	EMsg_FilercontrolAction		= 0x406,
	EMsg_FilerSelection		= 0x407,
	EMsg_AlarmSet			= 0x500,
	EMsg_AlarmGoneOff		= 0x501,
	EMsg_HelpRequest		= 0x502,
	EMsg_HelpReply			= 0x503,
	EMsg_Notify			= 0x40040,
	EMsg_MenuWarning		= 0x400c0,
	EMsg_ModeChange			= 0x400c1,
	EMsg_TaskInitialise		= 0x400c2,
	EMsg_TaskCloseDown		= 0x400c3,
	EMsg_SlotSize			= 0x400c4,
	EMsg_SetSlot			= 0x400c5,
	EMsg_TaskNameRq			= 0x400c6,
	EMsg_TaskNameIs			= 0x400c7,
	EMsg_TaskStarted		= 0x400c8,
	EMsg_MenusDeleted		= 0x400c9,
	EMsg_Iconize			= 0x400ca,
	EMsg_WindowClosed		= 0x400cb,
	EMsg_WindowInf			= 0x400cc,
	EMsg_FontChanged		= 0x400cf,
	EMsg_PrintFile			= 0x80140,
	EMsg_WillPrint			= 0x80141,
	EMsg_PrintSave			= 0x80142,
	EMsg_PrintInit			= 0x80143,
	EMsg_PrintError			= 0x80144,
	EMsg_PrintTypeOdd		= 0x80145,
	EMsg_PrintTypeKnown		= 0x80146,
	EMsg_SetPrinter			= 0x80147,
	EMsg_PSPrinterQuery		= 0x8014c,
	EMsg_PSPrinterAck		= 0x8014d,
	EMsg_PSPrinterModified		= 0x8014e,
	EMsg_PSPrinterDefaults		= 0x8014f,
	EMsg_PSPrinterDefaulted		= 0x80150,
	EMsg_PSPrinterNotPS		= 0x80151,
	EMsg_ResetPrinter		= 0x80152,
	EMsg_PSIsFontPrintRunning	= 0x80153,
	EMsg_TaskWindow_Input		= 0x808c0,
	EMsg_TaskWindow_Output		= 0x808c1,
	EMsg_TaskWindow_Ego		= 0x808c2,
	EMsg_TaskWindow_Morio		= 0x808c3,
	EMsg_TaskWindow_Morite		= 0x808c4,
	EMsg_TaskWindow_NewTask		= 0x808c5,
	EMsg_TaskWindow_Suspend		= 0x808c6,
	EMsg_TaskWindow_Resume		= 0x808c7
} EMsgType;

typedef struct
{
	int		e;
	const void*	pdata;
} CEvent;

typedef bool (*event_handler)(const CEvent* pe, void *handle);

typedef struct
{
	CCaret	caret;
	int	code;
} Event_Key;

typedef struct
{
	HWind		w;
	CRect		box;
	int		scx;
	int		scy;
	HWind		behind;
	int		dx;
	int		dy;
} Event_WindowScroll;

typedef struct
{
	int	size;
	HTask	task;
	int	id;
	int	ref;
	int	action;
} Msg_Hdr;

typedef struct
{
	Msg_Hdr	hdr;
	union
	{
		char	chars[236];
		int	words[59];
	} data;
} Msg;

typedef struct
{
	Msg_Hdr	hdr;
	void*	submenu;
	int	x;
	int	y;
	int	item[55];
} Msg_MenuWarning;

typedef struct
{
	Msg_Hdr	hdr;
	void*	menu;
} Msg_MenusDeleted;

typedef struct
{
	Msg_Hdr	hdr;
	Mouse	m;
} Msg_HelpRequest;

typedef struct
{
	Msg_Hdr	hdr;
	char	text[236];
} Msg_HelpReply;

typedef struct
{
	Msg_Hdr	hdr;
	int	file;
} Msg_SaveDesktop;

typedef struct
{
	Msg_Hdr		hdr;
	ScreenPos	pos;
	int		size;
	file_type	type;
	char		name[212];
} Msg_FileData;

typedef struct
{
	Msg_Hdr	hdr;
	void*	buffer;
	int	len;
} Msg_RAMData;

typedef struct
{
	Msg_Hdr	hdr;
	HWind	w;
	HTask	t;
	char	title[20];
} Msg_Iconize;

typedef struct
{
	Msg_Hdr	hdr;
	HWind	w;
} Msg_WindowClosed;

typedef struct
{
	Msg_Hdr	hdr;
	HWind	w;
	char	sprite[8];
	char	title[20];
} Msg_WindowInf;

typedef struct
{
	Msg_Hdr	hdr;
	int	font;
} Msg_FontChanged;

typedef struct
{
	Msg_Hdr		hdr;
	ScreenPos	pos;
	int		flags;
	CRect		box;
	file_type	types[50];
} Msg_Dragging;

typedef struct
{
	Msg_Hdr		hdr;
	int		flags;
	file_type	types[58];
} Msg_DragClaim;

typedef enum
{
	EEntity_Caret		= 1,
	EEntity_Selection	= 2,
	EEntity_Clipboard	= 4
} EEntity;

typedef struct
{
	Msg_Hdr		hdr;
	int		flags;
} Msg_ClaimEntity;

typedef struct
{
	Msg_Hdr		hdr;
	ScreenPos	pos;
	int		flags;
	file_type	types[54];
} Msg_DataRequest;

typedef struct
{
	Msg_Hdr		hdr;
	int		fs;
	int		flags;
	char		name[228];
} Msg_FilerOpenDir;

typedef struct
{
	Msg_Hdr		hdr;
	int		fs;
	int		reserved;
	int		x;
	int		y;
	int		width;
	int		height;
	char		mode;
	char		name[211];
} Msg_FilerOpenDirAt;

#endif
