/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/****************************************************************************
 * This source file was written by Acorn Computers Limited. It is part of   *
 * the RISCOS library for writing applications in C for RISC OS. It may be  *
 * used freely in the creation of programs for Archimedes. It should be     *
 * used with Acorn's C Compiler Release 3 or later.                         *
 *                                                                          *
 ***************************************************************************/

/* Title:   wimp.h
 * Purpose: C interface to RISC OS Wimp routines.
 *
 */

# ifndef __wimp_h
# define __wimp_h

# ifndef __os_h
# include "os.h"
# endif

# ifndef __sprite_h
# include "sprite.h"
# endif

#ifndef BOOL
#define BOOL int
#define TRUE 1
#define FALSE 0
#endif

#define wimp_spritearea ((sprite_area *)1)

typedef enum {                     /* window flag set */

  wimp_WMOVEABLE = 0x00000002,     /* is moveable */
  wimp_REDRAW_OK = 0x00000010,     /* can be redrawn entirely by wimp
                                    * ie. no user graphics */
  wimp_WPANE     = 0x00000020,     /* window is stuck over tool window */
  wimp_WTRESPASS = 0x00000040,     /* window is allowed to go outside
                                    * main area */
  wimp_WSCROLL_R1= 0x00000100,     /* scroll request returned when
                                    * scroll button clicked- auto repeat*/
  wimp_SCROLL_R2 = 0x00000200,     /* as SCROLL_R1, debounced, no auto */
  wimp_REAL_COLOURS = 0x000000400, /* use real window colours. */
  wimp_BACK_WINDOW = 0x000000800,  /* this window is a background window. */
  wimp_HOT_KEYS = 0x000001000,     /* generate events for 'hot keys' */

  wimp_WOPEN  = 0x00010000,        /* window is open */
  wimp_WTOP   = 0x00020000,        /* window is on top (not covered) */
  wimp_WFULL  = 0x00040000,        /* window is full size */
  wimp_WCLICK_TOGGLE = 0x00080000, /* open_window_request was due to click
                                    * on toggle-size button */
  wimp_WFOCUS = 0x00100000,        /* window has input focus */

  wimp_WBACK  = 0x01000000,        /* window has back button */
  wimp_WQUIT  = 0x02000000,        /* has a quit button */
  wimp_WTITLE = 0x04000000,        /* has a title bar */
  wimp_WTOGGLE= 0x08000000,        /* has a toggle-size button */
  wimp_WVSCR  = 0x10000000,        /* has vertical scroll bar */
  wimp_WSIZE  = 0x20000000,        /* has size box */
  wimp_WHSCR  = 0x40000000,        /* has horizontal scroll bar */
  wimp_WNEW   = ~0x7fffffff        /* use these new flags */
                                   /* NB! always set the WNEW flag */
} wimp_wflags;

typedef enum {
  wimp_WCTITLEFORE,
  wimp_WCTITLEBACK,
  wimp_WCWKAREAFORE,
  wimp_WCWKAREABACK,
  wimp_WCSCROLLOUTER,
  wimp_WCSCROLLINNER,
  wimp_WCTITLEHI,
  wimp_WCRESERVED
} wimp_wcolours;
/* If work area background is 255 then it isn't painted. */
/* If title foreground is 255 then you get no borders, title etc. at all */

typedef enum {                      /* icon flag set */
  wimp_ITEXT      = 0x00000001,     /* icon contains text */
  wimp_ISPRITE    = 0x00000002,     /* icon is a sprite */
  wimp_IBORDER    = 0x00000004,     /* icon has a border */
  wimp_IHCENTRE   = 0x00000008,     /* text is horizontally centred */
  wimp_IVCENTRE   = 0x00000010,     /* text is vertically centred */
  wimp_IFILLED    = 0x00000020,     /* icon has a filled background */
  wimp_IFONT      = 0x00000040,     /* text is an anti-aliased font */
  wimp_IREDRAW    = 0x00000080,     /* redraw needs application's help */
  wimp_INDIRECT   = 0x00000100,     /* icon data is 'indirected' */
  wimp_IRJUST     = 0x00000200,     /* text right justified in box */
  wimp_IESG_NOC   = 0x00000400,     /* if selected by right button, don't
                                     * cancel other icons in same ESG */
  wimp_IHALVESPRITE=0x00000800,     /* plot sprites half-size */
  wimp_IBTYPE     = 0x00001000,     /* 4-bit field: button type */
  wimp_ISELECTED  = 0x00200000,     /* icon selected by user (inverted) */
  wimp_INOSELECT  = 0x00400000,     /* icon cannot be selected (shaded) */
  wimp_IDELETED   = 0x00800000,     /* icon has been deleted */
  wimp_IFORECOL   = 0x01000000,     /* 4-bit field: foreground colour */
  wimp_IBACKCOL   = 0x10000000      /* 4-bit field: background colour */
} wimp_iconflags;

/* If the icon contains anti-aliased text then the colour fields
give the font handle: */
#define wimp_IFONTH 0x01000000

typedef enum {                /* button types */
  wimp_BIGNORE,               /* ignore all mouse ops */
  wimp_BNOTIFY,
  wimp_BCLICKAUTO,
  wimp_BCLICKDEBOUNCE,
  wimp_BSELREL,
  wimp_BSELDOUBLE,
  wimp_BDEBOUNCEDRAG,
  wimp_BRELEASEDRAG,
  wimp_BDOUBLEDRAG,
  wimp_BSELNOTIFY,
  wimp_BCLICKDRAGDOUBLE,
  wimp_BCLICKSEL,              /* useful for on/off and radio buttons */
  /* 12 & 13 reserved */
  wimp_BWRITABLEDRAG = 14,
  wimp_BWRITABLE
} wimp_ibtype;

typedef enum {                 /* button state bits */
  wimp_BRIGHT       = 0x001,
  wimp_BMID         = 0x002,
  wimp_BLEFT        = 0x004,
  wimp_BDRAGRIGHT   = 0x010,
  wimp_BDRAGLEFT    = 0x040,
  wimp_BCLICKRIGHT  = 0x100,
  wimp_BCLICKLEFT   = 0x400
} wimp_bbits;

typedef enum {
  wimp_MOVE_WIND = 1,                 /* change position of window */
  wimp_SIZE_WIND = 2,                 /* change size of window */
  wimp_DRAG_HBAR = 3,                 /* drag horizontal scroll bar */
  wimp_DRAG_VBAR = 4,                 /* drag vertical scroll bar */
  wimp_USER_FIXED = 5,                /* user drag box - fixed size */
  wimp_USER_RUBBER = 6,               /* user drag box - rubber box */
  wimp_USER_HIDDEN = 7                /* user drag box - invisible box */
} wimp_dragtype;

/*****************************************************************************/

typedef int wimp_w; /* abstract window handle */
typedef int wimp_i; /* abstract icon handle */
typedef int wimp_t; /* abstract task handle */

typedef union {           /* the data field in an icon */
  char text[12];          /* up to 12 bytes of text */
  char sprite_name[12];   /* up to 12 bytes of sprite name */
  struct {
    char *name;
    void *spritearea;     /* 0->use the common sprite area */
                          /* 1->use the wimp sprite area */
    BOOL nameisname;      /* if FALSE, name is in fact a sprite pointer. */
  } indirectsprite;
  struct {                /* if indirect */
    char *buffer;         /* pointer to text buffer */
    char *validstring;    /* pointer to validation string */
    int bufflen;          /* length of text buffer */
  } indirecttext;
} wimp_icondata;

typedef struct {
  int x0, y0, x1, y1;
} wimp_box;

typedef struct {
  wimp_box box;           /* screen coords of work area */
  int scx, scy;           /* scroll bar positions */
  wimp_w behind;          /* handle to open window behind, or -1 if top */
  wimp_wflags flags;      /* word of flag bits defined above */
  char colours[8];        /* colours: index using wimp_wcolours. */
  wimp_box ex;            /* maximum extent of work area */
  wimp_iconflags titleflags;     /* icon flags for title bar */
  wimp_iconflags workflags;      /* just button type relevant */
  void *spritearea;       /* 0->use the common sprite area */
                          /* 1->use the wimp sprite area */
  int minsize;            /* two 16-bit OS-unit fields, (width/height)
                             giving min size of window. 0->use title. */
  wimp_icondata title;    /* title icon data */
  int nicons;             /* no. of icons in window */
} wimp_wind;
/* If there are any icon definitions, they should follow this structure
immediately in memory. */

typedef struct {          /* result of get_info call. */
  wimp_w w;
  wimp_wind info;
} wimp_winfo;
/* Space for icons must follow. */

typedef struct {          /* icon description structure */
  wimp_box box;           /* bounding box - relative to
                           * window origin (work area top left) */
  wimp_iconflags flags;   /* word of flag bits defined above */
  wimp_icondata data;     /* union of bits & bobs as above */
} wimp_icon;

typedef struct wimp_menustr *wimp_menuptr;
/* Only for the circular reference in menuitem/str. */

typedef struct {          /* structure for creating icons. */
  wimp_w w;
  wimp_icon i;
} wimp_icreate;

typedef struct {
  wimp_w w;               /* window handle */
  wimp_box box;           /* position on screen of visible work area */
  int x, y;               /* 'real' coordinates of visible work area */
  wimp_w behind;          /* handle of window to go behind (-1 = top,
                           * -2 = bottom, -3 = iconised) */
} wimp_openstr;

typedef struct { /* result for window state enquiry */
  wimp_openstr o;
  wimp_wflags flags;
} wimp_wstate;

typedef enum {               /* event types */
  wimp_ENULL,                /* null event */
  wimp_EREDRAW,              /* redraw event */
  wimp_EOPEN,
  wimp_ECLOSE,
  wimp_EPTRLEAVE,
  wimp_EPTRENTER,
  wimp_EBUT,                 /* mouse button change */
  wimp_EUSERDRAG,
  wimp_EKEY,
  wimp_EMENU,
  wimp_ESCROLL,
  wimp_ELOSECARET,
  wimp_EGAINCARET,
  wimp_ESEND = 17,        /* send message, don't worry if it doesn't arrive */
  wimp_ESENDWANTACK = 18, /* send message, return ack if not acknowledged */
  wimp_EACK = 19          /* acknowledge receipt of message. */
} wimp_etype;

typedef enum {               /* event type masks */
  wimp_EMNULL     = 1 << wimp_ENULL,
  wimp_EMREDRAW   = 1 << wimp_EREDRAW,
  wimp_EMOPEN     = 1 << wimp_EOPEN,
  wimp_EMCLOSE    = 1 << wimp_ECLOSE,
  wimp_EMPTRLEAVE = 1 << wimp_EPTRLEAVE,
  wimp_EMPTRENTER = 1 << wimp_EPTRENTER,
  wimp_EMBUT      = 1 << wimp_EBUT,
  wimp_EMUSERDRAG = 1 << wimp_EUSERDRAG,
  wimp_EMKEY      = 1 << wimp_EKEY,
  wimp_EMMENU     = 1 << wimp_EMENU,
  wimp_EMSCROLL   = 1 << wimp_ESCROLL,
  wimp_EMLOSECARET= 1 << wimp_ELOSECARET,
  wimp_EMGAINCARET= 1 << wimp_EGAINCARET,
  wimp_EMSEND     = 1 << wimp_ESEND,
  wimp_EMSENDWANTACK
                  = 1 << wimp_ESENDWANTACK,
  wimp_EMACK      = 1 << wimp_EACK
} wimp_emask;

typedef struct {
  wimp_w w;
  wimp_box box;           /* work area coordinates */
  int scx, scy;           /* scroll bar positions */
  wimp_box g;             /* current graphics window */
} wimp_redrawstr;

typedef struct {
  int x, y;         /* mouse x and y */
  wimp_bbits bbits; /* button state */
  wimp_w w;         /* window handle, or -1 if none */
  wimp_i i;         /* icon handle, or -1 if none */
} wimp_mousestr;

typedef struct {
  wimp_w w;
  wimp_i i;
  int x, y;                /* offset relative to window origin */
  int height;              /* -1 if calc within icon
                            * bit 24 -> VDU-5 type caret
                            * bit 25 -> caret invisible
                            * bit 26 -> bits 16..23 contain colour
                            * bit 27 -> colour is "real" colour */
  int index;               /* position within icon */
} wimp_caretstr;

/* Message action codes are allocated just like SWI codes. */
typedef enum {
  wimp_MCLOSEDOWN    = 0, /* Reply if any dialogue with the user is required,
                             and the closedown sequence will be aborted. */
  wimp_MDATASAVE     = 1, /* request to identify directory */
  wimp_MDATASAVEOK   = 2, /* reply to message type 1 */
  wimp_MDATALOAD     = 3, /* request to load/insert dragged icon */
  wimp_MDATALOADOK   = 4, /* reply that file has been loaded */
  wimp_MDATAOPEN     = 5, /* warning that an object is to be opened */
  wimp_MRAMFETCH     = 6, /* transfer data to buffer in my workspace */
  wimp_MRAMTRANSMIT  = 7, /* I have transferred some data to a buffer in your
                             workspace */
  wimp_MPREQUIT      = 8,
  wimp_PALETTECHANGE = 9,
  wimp_SAVEDESK      = 10, /* Wimp 2.43 onwards - desktop closedown message */
  wimp_MDEVICECLAIM  = 11, /* Broadcast before an application can claim parallel port, RS232 port etc. */
  wimp_MDEVICEINUSE  = 12, /* Reply if another application is already using the device */
  wimp_MDATASAVED    = 13, /* A file previously saved has become 'safe' */
  wimp_MSHUTDOWN     = 14, /* Someone called TaskManager_Shutdown with b3 set */
  wimp_MCLAIMENTITY  = 15, /* Clipboard claim entity */
  wimp_MDATAREQUEST  = 16, /* Clipboard request data */
  wimp_MDRAGGING     = 17, /* Clipboard drag in progress */
  wimp_MDRAGCLAIM    = 18, /* Clipboard drag claimed */
  wimp_MAPPCONTROL   = 21,

  wimp_MFILER_OPEN_DIR            = 0x400, /* Filer */
  wimp_MFILER_CLOSE_DIR           = 0x401,
  wimp_MFILER_OPEN_DIR_AT         = 0x402,
  wimp_MFILER_SELECTION_DIRECTORY = 0x403,
  wimp_MFILER_ADD_SELECTION       = 0x404,
  wimp_MFILER_ACTION              = 0x405,
  wimp_MFILER_CONTROL_ACTION      = 0x406,
  wimp_MFILER_SELECTION           = 0x407,
  wimp_MFILER_DEVICEPATH          = 0x408,

  wimp_MHELPREQUEST  = 0x502,         /* interactive help request */
  wimp_MHELPREPLY    = 0x503,         /* interactive help message */
  wimp_MHELPENABLE   = 0x504,         /* interactive help control */

  wimp_MNOTIFY       = 0x40040,  /* net filer notify broadcast */

  wimp_MMENUWARN     = 0x400c0,  /* menu warning sent if wimp_MSUBLINKMSG set */
  wimp_MMODECHANGE   = 0x400c1,
  wimp_MINITTASK     = 0x400c2,
  wimp_MCLOSETASK    = 0x400c3,
  wimp_MSLOTCHANGE   = 0x400c4,       /* Slot size has altered */
  wimp_MSETSLOT      = 0x400c5,       /* Task manager requests application
                                         to change its slot size */
  wimp_MTASKNAMERQ   = 0x400c6,       /* Request task name */
  wimp_MTASKNAMEIS   = 0x400c7,       /* Reply to task name request */
  wimp_MTASKSTARTED  = 0x400c8,       /* Broadcast by task to indicate that it has now fully started */

  wimp_MMENUSDELETED = 0x400c9,
  wimp_MICONIZE      = 0x400ca,
  wimp_MWINDOWCLOSED = 0x400cb,
  wimp_MWINDOWINFO   = 0x400cc,
  wimp_MSWAP         = 0x400cd,
  wimp_MTOOLSCHANGED = 0x400ce,
  wimp_MFONTCHANGED  = 0x400cf,
  wimp_MICONIZEAT    = 0x400d0,
  wimp_MTOGGLEBACKDROP         = 0x400d1,
  wimp_MSCREENEDGENOTIFICATION = 0x400d2,

  /* Messages for dialogue with printer applications */

  wimp_MPrintFile       = 0x80140,    /* Printer app's first response to */
                                      /* a DATASAVE */
  wimp_MWillPrint       = 0x80141,    /* Acknowledgement of PrintFile */
  wimp_MPrintSave       = 0x80142,    /* Print without drag to printer icon */
  wimp_MPrintInit       = 0x80143,    /* !printers has loaded */
  wimp_MPrintError      = 0x80144,    /* error report by !printers */
  wimp_MPrintTypeOdd    = 0x80145,    /* Broadcast when strange files */
                                      /* dropped on the printer */
  wimp_MPrintTypeKnown  = 0x80146,    /* Ack to above */
  wimp_MSetPrinter      = 0x80147     /* New printer application installed */

} wimp_msgaction;

typedef struct {          /* message block header. */
  int size;               /* 20<=size<=256, multiple of 4 */
  wimp_t task;            /* task handle of sender (filled in by wimp) */
  int my_ref;             /* unique ref number (filled in by wimp) */
  int your_ref;           /* (0==>none) if non-zero, acknowledge */
  wimp_msgaction action;  /* message action code */
} wimp_msghdr;
/* size is the size of the whole msgstr, see below. */


typedef struct {
  wimp_w w;               /* window in which save occurs. */
  wimp_i i;               /* icon there */
  int x;                  /* position within that window of destination of save. */
  int y;
  int estsize;            /* estimated size of data, in bytes */
  int type;               /* file type of data to save */
  char leaf[212];         /* proposed leaf-name of file, 0-terminated */
} wimp_msgdatasave;

typedef struct {
  /* w, i, x, y, type, estsize copied unaltered from DataSave message. */
  wimp_w w;               /* window in which save occurs. */
  wimp_i i;               /* icon there */
  int x;                  /* position within that window of destination of save. */
  int y;
  int estsize;            /* estimated size of data, in bytes */
  int type;               /* file type of data to save */
  char name[212];         /* the name of the file to save */
} wimp_msgdatasaveok;

typedef struct {
  wimp_w w;               /* target window */
  wimp_i i;               /* target icon */
  int x;                  /* target coords in target window work area */
  int y;
  int size;               /* must be 0 */
  int type;               /* type of file */
  char name[212];         /* the filename follows. */
} wimp_msgdataload;

/* for a data load reply, no arguments are required. */

typedef wimp_msgdataload wimp_msgdataopen;
/* The data provided when opening a file is exactly the same. the
window, x, y refer to the bottom lh corner of the icon that represents the
file being opened, or w=-1 if there is no such. */

typedef struct {             /* transfer data in memory */
  char *addr;                /* address of data to transfer */
  int nbytes;                /* number of bytes to transfer */
} wimp_msgramfetch;

typedef struct {             /* I have transferred some data to a buffer in your workspace */
  char *addr;                /* copy of value sent in RAMfetch */
  int nbyteswritten;         /* number of bytes written */
} wimp_msgramtransmit;

typedef struct {           /* Save state for restart */
  int filehandle;          /* RISC OS file handle (not a C one!) */
} wimp_msgsavedesk;

typedef struct {
  int major;         /* Major device number */
  int minor;         /* Minor device number */
  char information[228];   /* Null-terminated information string */
} wimp_msgdevice;

typedef struct {
  int flags;             /* entity flags */
#define wimp_MCLAIMENTITY_flags_caretselect (1+2)
#define wimp_MCLAIMENTITY_flags_clipboard   (4)
} wimp_msgclaimentity;

typedef struct {
  wimp_w w;              /* target window */
  void *h;               /* internal handle */
  int x;                 /* target coords in target window work area */
  int y;
  int flags;             /* request type */
#define wimp_MDATAREQUEST_flags_clipboard   (4)
  int types[1];          /* array of types in order of preference */
#define wimp_MDATAREQUEST_types_end         (-1)
} wimp_msgdatarequest;

typedef struct {
  wimp_w w;               /* target window */
  wimp_i i;               /* target icon */
  int x;                  /* target coords in target window work area */
  int y;
  int flags;
#define wimp_MDRAGGING_flags_datafromselection (2)
#define wimp_MDRAGGING_flags_datafromclipboard (4)
#define wimp_MDRAGGING_flags_deletesource      (8)
#define wimp_MDRAGGING_flags_donotclaim        (16)
  wimp_box box;
  int types[1];          /* array of types */
#define wimp_MDRAGGING_types_end               (-1)
} wimp_msgdragging;

typedef struct {
  int flags;             /* request type */
#define wimp_MDRAGCLAIM_flags_ptrchanged    (1)
#define wimp_MDRAGCLAIM_flags_removedragbox (2)
#define wimp_MDRAGCLAIM_flags_deletesource  (8)
  int types[1];          /* array of types */
#define wimp_MDRAGCLAIM_types_end           (-1)
} wimp_msgdragclaim;

typedef struct {
  int version;
  int flags;
#define wimp_MAPPCONTROL_flags_immediate    (1)
  int op;
#define wimp_MAPPCONTROL_op_stop            (0)
#define wimp_MAPPCONTROL_op_wakeup          (1)
#define wimp_MAPPCONTROL_op_pause           (2)
#define wimp_MAPPCONTROL_op_minimisememory  (3)
#define wimp_MAPPCONTROL_op_openconfig      (4)
} wimp_msgappcontrol;

typedef struct {
  wimp_mousestr m;       /* where the help is required */
} wimp_msghelprequest;

typedef struct {
  char text[200];        /* the helpful string */
} wimp_msghelpreply;

typedef struct {
  wimp_menuptr submenu;
  int x;
  int y;
  int menu[1];           /* list of menu hit indices (0..n-1 for each menu) */
                         /* as for wimp_EMENU, terminated by -1 */
} wimp_msgmenuwarn;

typedef struct {         /* structure used in all print messages */
  int filler[5] ;
  int type ;             /* filetype */
  char name[256-44] ;    /* filename */
} wimp_msgprint ;

typedef struct {          /* message block */
  wimp_msghdr hdr;
  union {
    char chars[236];
    int words[59];             /* max data size. */
    wimp_msgdatasave    datasave;
    wimp_msgdatasaveok  datasaveok;
    wimp_msgdataload    dataload;
    wimp_msgdataopen    dataopen;
    wimp_msgramfetch    ramfetch;
    wimp_msgramtransmit ramtransmit;
    wimp_msghelprequest helprequest;
    wimp_msghelpreply   helpreply;
    wimp_msgmenuwarn    menuwarn;
    wimp_msgprint       print;
    wimp_msgsavedesk    savedesk;
    wimp_msgdevice      device;
    wimp_msgclaimentity claimentity;
    wimp_msgdatarequest datarequest;
    wimp_msgdragging    dragging;
    wimp_msgdragclaim   dragclaim;
    wimp_msgappcontrol  appcontrol;
  } data;
} wimp_msgstr;

typedef union {
    wimp_openstr o;         /* for redraw, close, enter, leave events */
    struct {
      wimp_mousestr m;
      wimp_bbits b;} but;   /* for button change event */
    wimp_box dragbox;       /* for user drag box event */
    struct {wimp_caretstr c; int chcode;} key;  /* for key events */
    int menu[10];           /* for menu event: terminated by -1 */
    struct {wimp_openstr o; int x, y;} scroll;  /* for scroll request */
                                       /* x=-1 for left, +1 for right */
                                       /* y=-1 for down, +1 for up    */
                             /* scroll by +/-2 -> page scroll request */
    wimp_caretstr c;        /* for caret gain/lose. */
    wimp_msgstr msg;        /* for messages. */
} wimp_eventdata;

typedef struct {            /* wimp event description */
  wimp_etype e;             /* event type */
  wimp_eventdata data;
} wimp_eventstr;

typedef struct {
  char title[12];         /* menu title (optional) */
  char tit_fcol, tit_bcol, work_fcol, work_bcol; /* colours */
  int width, height;      /* size of following menu items */
  int gap;                /* vertical gap between items */
} wimp_menuhdr;

typedef enum {           /* menu item flag set */
  wimp_MTICK       = 1,
  wimp_MSEPARATE   = 2,
  wimp_MWRITABLE   = 4,
  wimp_MSUBLINKMSG = 8, /* show a => flag, and inform program when it
                           is activated. */
  wimp_MLAST = 0x80,    /* signal last item in the menu */
  wimp_MINDIRECTED = 0x100
} wimp_menuflags;
/* use wimp_INOSELECT to shade the item as unselectable,
and the button type to mark it as writable. */

typedef struct {
  wimp_menuflags flags;         /* menu entry flags */
  wimp_menuptr submenu;         /* wimp_menustr* pointer to sub menu,
                                   or wimp_w dialogue box,
                                   or -1 if no submenu */
  wimp_iconflags iconflags;     /* icon flags for the entry */
  wimp_icondata data;           /* icon data for the entry */
} wimp_menuitem;
/* submenu can also be a wimp_w, in which case the window is opened as a
dialogue box within the menu tree. */

typedef struct wimp_menustr {
  wimp_menuhdr hdr;
  /* wimp_menuitem item[];*/ /* Zero or more menu items follow in memory */
} wimp_menustr;

typedef struct {
  wimp_w window;
  wimp_dragtype type;
  wimp_box box;           /* initial position for drag box */
  wimp_box parent;        /* parent box for drag box */
} wimp_dragstr;

typedef struct {
  wimp_w window;          /* handle */
  int bit_mask;           /* bit set => consider this bit */
  int bit_set;            /* desired bit setting */
} wimp_which_block;

typedef struct {
  int shape_num;          /* pointer shape number (0 turn off pointer) */
  char * shape_data;      /* shape data, NULL pointer implies existing
                           * shape */
  int width, height;      /* Width and height in pixels. Width = 4 * n,
                           * where n is an integer. */
  int activex, activey;   /* active point (pixels from top left) */
} wimp_pshapestr;

typedef struct {
  char f[256];            /* initialise all to zero before using for
                           * first load_template, then just use
                           * repeatedly without altering */
} wimp_font_array;

typedef struct {               /* template reading structure */
        int reserved;          /* ignore - implementation detail */
        wimp_wind *buf;        /* pointer to space for putting template in */
        char *work_free;       /* pointer to start of free wimp workspace -
                                * you have to provide the wimp system with
                                * workspace to store its redirected icons in*/
        char *work_end;        /* end of workspace you are offerring to wimp*/
        wimp_font_array *font; /* points to font reference count array, 0
                                * pointer implies fonts not allowed */
        char *name;            /* name to match with (can be wildcarded) */
        int index;             /* pos. in index to search from (0 = start) */
} wimp_template;

typedef union {
  struct {char gcol; char red; char green; char blue;} bytes;
  int word;
} wimp_paletteword;
/* The gcol char (least significant) is a gcol colour except in 8-bpp
modes, when bits 0..2 are the tint and bits 3..7 are the gcol colour. */

typedef struct {
  wimp_paletteword c[16];              /* wimp colours 0..15 */
  wimp_paletteword screenborder, mouse1, mouse2, mouse3;
} wimp_palettestr;

/*****************************************************************************/

os_error *wimp_initialise(int * v);
/* Close & delete all windows, return wimp version number. */

#ifdef __WIMP_COMPILE
os_error *wimp_taskinit (char *name, int *version /*inout*/,
                         wimp_t *t /*out*/, wimp_msgaction *messages);
#else
os_error *wimp_taskinit (char *name, int *version /*inout*/,
                         wimp_t *t /*out*/, ...);
#endif
/* Name is the name of the program. Used instead of wimp_initialise, returns
   your task handle. *Version should be at least 200 on entry, and will
   return the current wimp version number. If *version >= 300, a
   wimp_MCLOSEDOWN-terminated list of message numbers must be given.*/

os_error *wimp_create_wind(wimp_wind *, wimp_w *);
/* define (but not display) window, return window handle */

os_error *wimp_create_icon(wimp_icreate *, wimp_i *result);
/* add icon definition to that of window, return icon handle */

os_error *wimp_delete_wind(wimp_w);

os_error *wimp_delete_icon(wimp_w, wimp_i);

os_error *wimp_open_wind(wimp_openstr *);
/* make window appear on screen */

os_error *wimp_close_wind(wimp_w);
/* Remove from active list the window with handle in integer argument. */

os_error *wimp_poll(wimp_emask mask, wimp_eventstr *result);
/* Poll next event from the WIMP */

void wimp_save_fp_state_on_poll(void) ;
/* Activates saving of floating point state on calls to wimp_poll
 * and wimp_pollidle; this is needed if you do any floating point at
 * all, as other programs may corrupt the FP status word, which is
 * effectively a global in your program
 */

void wimp_corrupt_fp_state_on_poll(void) ;
/* Disables saving of floating point state on calls to wimp_poll
 * and wimp_pollidle; use only if you never use FP at all
 */

os_error *wimp_redraw_wind(wimp_redrawstr*, BOOL* /*out*/);
/* Draw window outline and icons. Return FALSE if there's nothing to draw. */

os_error *wimp_update_wind(wimp_redrawstr*, BOOL* /*out*/);
/* Return visible portion of window. Return FALSE if nothing to redraw. */

os_error *wimp_get_rectangle(wimp_redrawstr*, BOOL*);
/* return next rectangle in list, or FALSE if done. */

os_error *wimp_get_wind_state(wimp_w, wimp_wstate * result);
/* read current window state */

os_error *wimp_get_wind_info(wimp_winfo * result);
/* On entry result->w gives the window in question. Space for any
icons must follow *result. */

os_error *wimp_set_icon_state(wimp_w, wimp_i,
  wimp_iconflags value, wimp_iconflags mask);
/* Set icon's flags as (old_state & ~mask) ^ value */

os_error *wimp_get_icon_info(wimp_w, wimp_i, wimp_icon * result);
/* Get current state of icon */

os_error *wimp_get_point_info(wimp_mousestr * result);
/* Give info regarding the state of the mouse */

os_error *wimp_drag_box(wimp_dragstr *);
/* start the wimp dragging a box */

os_error *wimp_force_redraw(wimp_redrawstr * r);
/* Mark an area of the screen as invalid.
If r->wimp_w == -1 then use screen coordinates. Only the first
five fields of r are valid. */

os_error *wimp_set_caret_pos(wimp_caretstr *);
/* set pos./size of text caret */

os_error *wimp_get_caret_pos(wimp_caretstr *);
/* get pos./size of text caret */

os_error *wimp_create_menu(wimp_menustr *m, int x, int y);
/* 'pop up' menu structure. Set m==(wimp_menustr*)-1 to clear the
menu tree. */

os_error *wimp_decode_menu(wimp_menustr *, void *, void *);

os_error *wimp_which_icon(wimp_which_block *, wimp_i * results);
/* The results appear in an array, terminated by a (wimp_i) -1. */

os_error *wimp_set_extent(wimp_redrawstr *);
/* Alter extent of a window's work area - only handle and 1st set of
4 coordinates are looked at. */

os_error *wimp_set_point_shape(wimp_pshapestr *);
/* set pointer shape on screen */

os_error *wimp_open_template(char * name);
/* opens named file to allow load_template to
read a template from the file. */

os_error *wimp_close_template(void);
/* close currently open template file */

os_error *wimp_load_template(wimp_template *);
/* load a window template from open file into buffer */

os_error *wimp_processkey(int chcode);
/* Hand back to the wimp a key that you do not understand. */

os_error *wimp_closedown(void);

os_error *wimp_taskclose(wimp_t);
/* Calls closedown in the multi-tasking form. */

os_error *wimp_starttask(char *clicmd);
/* Start a new wimp task, with the given CLI command. */

os_error *wimp_getwindowoutline(wimp_redrawstr *r);
/* set r->w on entry. On exit, r->box will be the screen coordinates
of the window, including border, title, scroll bars. */

os_error *wimp_pollidle(wimp_emask mask, wimp_eventstr *result, int earliest);
/* Like wimp_poll, but do not return before earliest return time.
This is a value produced by OS_ReadMonotonicTime. */

os_error *wimp_ploticon(wimp_icon*);
/* Called only within update or redraw loop. Just does the plotting,
this need not be a real icon attached to a window. */

os_error *wimp_setmode(int mode);
/* Set the screen mode. Palette colours are maintained, if possible. */

os_error *wimp_readpalette(wimp_palettestr*);

os_error *wimp_setpalette(wimp_palettestr*);
/* The bytes.gcol values of each field of the palettestr are ignored,
only the absolute colours are taken into account. */

os_error *wimp_setcolour(int colour);
/* bits 0..3 = wimp colour (translate for current mode)
        4..6 = gcol action
        7    = foreground/background.
*/

os_error *wimp_spriteop(int reason_code, char *name) ;
/* call SWI Wimp_SpriteOp */
os_error *wimp_spriteop_full(os_regset *) ;
/* call SWI Wimp_SpriteOp allowing full information to be passed */

sprite_area *wimp_baseofsprites(void);
/* Returns the area for Wimp sprites in the RMA. This may be moved about by mergespritefile. */

sprite_area *wimp_baseofromsprites(void);
/* Returns the area for Wimp sprites in the ROM. */

os_error *wimp_blockcopy(wimp_w, wimp_box *source, int x, int y);
/* Copy the source box (defined in window coords) to the given destination
(in window coords). Invalidate any portions of the destination that cannot be
updated using on-screen copy. */

typedef enum {
  wimp_EOK            = 1,      /* put in "OK" box */
  wimp_ECANCEL        = 2,      /* put in "CANCEL" box */
  wimp_EHICANCEL      = 4,      /* highlight CANCEL rather than OK. */
  wimp_ENOSPACETOCONT = 8,      /* omit "press space to continue" */
  wimp_ENOERRORFROM   = 16,     /* no "Error from" prefix */
  wimp_ENOBLOCK       = 32,     /* return immediately with box open */
  wimp_ESIMOKCANCEL   = 64,     /* simulate OK/CANCEL */
  wimp_ENOBEEP        = 128,    /* be quiet */
  wimp_EUSECATEGORY   = 256,    /* use categories */
  wimp_ECAT_RESERVED0 = 0<<9,
  wimp_ECAT_INFO      = 1<<9,
  wimp_ECAT_WARNING   = 2<<9,
  wimp_ECAT_STOP      = 3<<9,
  wimp_ECAT_QUESTION  = 4<<9,
  wimp_ECAT_USER1     = 5<<9,
  wimp_ECAT_USER2     = 6<<9,
  wimp_ECAT_RESERVED7 = 7<<9
} wimp_errflags;
/* If OK and CANCEL are both 0 you get an OK. */

os_error *wimp_reporterror(os_error*, wimp_errflags, char *name);
/* Produces an error window. Uses sprite called "error" in the wimp sprite
pool. name should be the program name, appearing after "error in " at the
head of the dialogue box. */

os_error *wimp_sendmessage(wimp_etype code, wimp_msgstr* msg, wimp_t dest);
/* dest can also be 0, in which case the message is sent to every task in
turn, including the sender. msg can also be any other wimp_eventdata* value.
*/

os_error *wimp_sendwmessage(
  wimp_etype code, wimp_msgstr *msg, wimp_w w, wimp_i i);
/* Send a message to the owner of a specific window/icon. msg can also be
any other wimp_eventdata* value. */

os_error *wimp_create_submenu(wimp_menustr *sub, int x, int y);
/* sub can also be a wimp_w, in which case it is opened by the wimp
as a dialogue box. */

os_error *wimp_slotsize(int *currentslot /*inout*/,
                        int *nextslot /*inout*/,
                        int *freepool /*out*/);
/* currentslot/nextslot==-1 -> just read setting. */

os_error *wimp_transferblock(
  wimp_t sourcetask,
  char *sourcebuf,
  wimp_t desttask,
  char *destbuf,
  int buflen);
/* Transfer memory between domains. */

os_error *wimp_setfontcolours(int foreground, int background);
/* Set font manager colours. The wimp handles how many shades etc. to use. */

os_error *wimp_readpixtrans(sprite_area *area, sprite_id *id,
                         sprite_factors *factors, sprite_pixtrans *pixtrans);
/* Tells you how the WIMP will plot a sprite when asked to PutSpriteScaled */


typedef enum
        {  wimp_command_TITLE = 0,
           wimp_command_ACTIVE = 1,
           wimp_command_CLOSE_PROMPT = 2,
           wimp_command_CLOSE_NOPROMPT = 3
        }  wimp_command_tag;

typedef struct
        {
          wimp_command_tag tag;
          char *title;
        } wimp_commandwind;

os_error *wimp_commandwindow(wimp_commandwind commandwindow);

/* Open a text window for normal VDU 4-type output
   Note:  the tag types correspond to the 4 kinds of call to
   SWI wimp_CommandWindow shown in the Programmer's Ref Manual.
   Title is only required if tag == wimp_command_TITLE.
   It is the application's responsibility to set the tag correctly.
 */

# endif

/* end wimp.h */