#define  False 0
#define  True  !(False)

//****************************************************************
//* Part 1: RISC OS Data types 
//****************************************************************

// For some things I get so-called Handles
typedef int t_TaskHandle;
typedef int t_WindowHandle;
typedef int t_IconHandle;

//****************************************************************
// Windows

typedef int t_Window;

//****************************************************************
// Icons

typedef int t_SpriteArea;

// Icon data
typedef union {
	char IconText[12];
	struct {
		char *Text;
		char *Validation;
		int Length;
	}	IconTextIndirect;
	struct {
		char *Sprite;
		t_SpriteArea *Area;
		int Length;
	}	IconSpriteIndirect;
} t_IconData;

// Icon
typedef struct {
	int MinX, MinY, MaxX, MaxY;
	int IconFlags;
	t_IconData IconData;
} t_Icon;

// Some useful constants
#define IconBarIconFlags 0x3102 // Sprite, Indirect, Click
#define IconBarIconLeft (t_WindowHandle)(-2)
#define IconBarIconRight (t_WindowHandle)(-1)
#define WimpSpriteArea (t_SpriteArea*)1

//****************************************************************
// Keys
#define KeyShift 0
#define KeyCtrl 1
#define KeyAlt 2
#define KeyOffsetLeft 3
#define KeyoffsetRight 6

//****************************************************************
// Menus

typedef struct {
	union {
		char Text[12];
		t_IconData IconData;
	} Title;
	char TitleForeground; // 7
	char TitleBackground; // 2
	char BodyForeground; // 7
	char BodyBackground; // 0
	int Width; // Automatic
	int Height; // 44
	int Gap; //0
} t_MenuHeader;

// Since MenuItem needs Menu and vice versa this is the trick
typedef struct t_Menu t_Menu;

typedef struct {
	int MenuFlags;
	union {
		t_Menu *SubMenu;
		t_WindowHandle Window;
		int Warning;
	} MenuLink;
	int IconFlags;
	t_IconData IconData;
} t_MenuItem;

struct t_Menu {
	t_MenuHeader MenuHeader;
	t_MenuItem MenuItem[];
};

#define MenuFlagsStandard 0
#define MenuFlagsLastMask (1<<7)
#define MenuFlagsDashesMask (1<<1)
#define MenuFlagsTickMask (1<<0)
#define MenuIconFlagsSimple 0x7000021 // Black on white, Text


//****************************************************************
//* Part 2: SWI Paramters
//****************************************************************

//****************************************************************
// Polling

#define TASK 0x4B534154
#define PollMask_Standard 0x3831

#define ReasonCode_MouseClick 6
#define ReasonCode_MenuSelection 9
#define ReasonCode_UserMessage 17
#define ReasonCode_UserMessageRecorded 18

#define WindowBackground (t_WindowHandle)(-1)
#define WindowIconbar (t_WindowHandle)(-2)

#define UserMessage_Quit 0

#define MouseButtonRight  0x1
#define MouseButtonMiddle 0x2
#define MouseButtonLeft   0x4

// Wimp Poll Block as a buffer
typedef struct {
	char Data[256];
} t_Buffer256;

// Wimp Poll block for a user message
typedef struct {
	int MessageLength;
	int SenderHandle;
	int MyRef;
	int YourRef;
	int MessageCode;
	char MessageData[236];
} t_WimpUserMessage;

// Wimp Poll block for a mouse click
typedef struct {
	int MouseX, MouseY;
	int Buttons;
	t_WindowHandle Window;
	t_IconHandle Icon;
	char MessageData[236];
} t_WimpMouseClick;

// Wimp Poll block for menu selection
typedef struct {
	int MenuItem[63];  // = 256 Bytes
} t_WimpMenuSelection;

// Wimp Poll Block with multiple formats
typedef union {
	t_Buffer256 Block;
	t_WimpUserMessage UserMessage;
	t_WimpMouseClick MouseClick;
	t_WimpMenuSelection MenuSelection;
} t_WimpPollBlock;

//****************************************************************
// Icon SWIs

// Block for SWI Wimp_CreateIcon
typedef struct {
	t_WindowHandle Window;
	t_Icon Icon;
} t_WimpCreateIconBlock;

// Block for SWI Wimp_DeleteIcon
typedef struct {
	t_WindowHandle Window;
	t_IconHandle Icon;
} t_WimpDeleteIconBlock;

