#ifndef __Event__H
#define __Event__H

#include "WimpLib:Caret.h"
#include "WimpLib:Coords.h"

#ifdef __cplusplus
extern "C" {
#endif

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
	// User events
	, EEvent_MenuOpen        = 0x0f000000
	, EEvent_MenuClose       = 0x0f000001
	, EEvent_SelectionChange = 0x0f000002
	, EEvent_OnUpdate        = 0x0f000003
	, EEvent_ClipboardUpdate = 0x0f000004
} 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_ReleaseEntity           = 19
	, 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_StrongHelp              = 0x43b00
	, 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
{
	CCaret  caret;
	int32_t code;
} Event_Key;

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


typedef struct
{
	int32_t hit[10];
} Event_MenuOpen;

typedef struct
{
	void* pWList;
	int   Index; // -1 in case of multiple selection
} Event_SelectionChange;

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

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

typedef struct
{
	Msg_Hdr hdr;
	void*   submenu;
	int32_t x;
	int32_t y;
	int32_t hit[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;
	int32_t file;
} Msg_SaveDesktop;

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

typedef struct
{
	Msg_Hdr hdr;
	void*   buffer;
	int32_t 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;
	uint32_t font;
} Msg_FontChanged;

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

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

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

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

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

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

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

#ifdef __cplusplus
}
#endif

#endif
