//****************************************************************
//* Part 0: My data types
//****************************************************************
#define  False 0
#define  True  !(False)

typedef struct {
	int MinX, MinY, MaxX, MaxY;
} t_BoxenLuder;

//****************************************************************
//* 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;

//****************************************************************
// 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 {
	t_BoxenLuder BoundingBox;
	unsigned IconFlags;
	t_IconData IconData;
} t_Icon;

// Some useful constants
#define IconFlags_IconBar 0x3102 // Sprite, Indirect, Click
#define IconFlags_TextWhiteDirect 0x7000021 // Black on white, Text
#define IconFlags_TextWhiteIndirect 0x7000121
#define IconFlags_TextTransparentDirect 0x7000001 // Black on white, Text
#define IconFlags_TextTransparentIndirect 0x7000101

#define IconBar_IconLeft (t_WindowHandle)(-2)
#define IconBar_IconRight (t_WindowHandle)(-1)

#define WimpSpriteArea (t_SpriteArea*)1

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

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

typedef struct {
	t_BoxenLuder Visible;
	int  ScrollX, ScrollY;
	t_WindowHandle WindowStack; // -1
	unsigned WindowFlags;
	char TitleForground; //7
	char TitleBackground; // 2
	char WorkareaForground; // 7
	char WorkareaBackground; // 1
	char ScrollbarBackground; //3
	char ScrollbarForeground; // 1
	char TitleFocusBackground; // 12
	char ExtraFlags;
	t_BoxenLuder Workarea;
	unsigned TitleIconFlags;
	int WorkareaButtonType;
	t_SpriteArea *ToolSpriteArea; // -1 (WimpSpriteArea)
	int MinArea; // Width & Height in 16 Bit each!
	t_IconData TitleIconData;
	int IconCount;
} t_WindowHeader;

typedef struct {
	t_WindowHeader WindowHeader;
	t_Icon WindowIcon[];
} t_Window;

#define Window_OpenInFront (t_WindowHandle)(-1)
#define WindowFlags_InfoWindow 0x84000050


//****************************************************************
// 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 {
	unsigned MenuFlags;
	union {
		t_Menu *SubMenu;
		t_WindowHandle Window;
		int Warning;
	} MenuLink;
	unsigned IconFlags;
	t_IconData IconData;
} t_MenuItem;

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

#define MenuFlags_Standard 0
#define MenuFlags_Mask_Last (1<<7)
#define MenuFlags_Mask_Dashes (1<<1)
#define MenuFlags_Mask_Tick (1<<0)


//****************************************************************
//* 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;

