#ifndef API_H
#define API_H
/*
**      $Filename: fd/api.h
**      $Release: 6
**
**      API-2 definitions.
**
**      (C) Copyright 1996 Dietmar Eilert
**          All Rights Reserved
*/

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_LISTS_H
#include <exec/lists.h>
#endif

#ifndef EXEC_LISTS_H
#include <exec/lists.h>
#endif

#ifndef INTUITION_INTUITION_H
#include <intuition/intuition.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem>
#endif

#ifndef WORKBENCH_WORKBENCH_H
#include <workbench/workbench.h>
#endif

#ifndef MAKE_ID
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
#endif

#define API_MAGIC  MAKE_ID('A','P','I','2')

/* library base */

struct APIBase {

    struct Library  Libary;                          /* standard library */
    UWORD           pad;                             /* we are now longwod aligned */
    ULONG           Magic;                           /* used to recognize API libraries */
};


/* -------------------------------- APIMessage ---------------------------------

 API messages are sent from a host (or an instance of the host)  to  clients.
 API messages are linked (api_Next; may be NULL). The client has to check the
 api_State field before processing the message  (must  be  API_STATE_NOTIFY).
 Check  the  api_Class  field  to  determine  the  basic  message  type (e.g.
 API_CLASS_SCREEN if the message is related to screen  handling).  Check  the
 api_Action  field  to  determine the actual command (e.g. API_ACTION_HIDE if
 the host wants you to close  your  windows).  A  client  should  update  the
 api_Error field after having processed the message.

*/

struct APIMessage {

    /* info slots (read-only) */

    ULONG                     api_State;             /* set by host: API message state (see below) */
    struct APIMessage        *api_Next;              /* set by host: next APIMessage */
    struct APIInstance       *api_Instance;          /* set by host: sender (instance of host) */

    /* command slots */

    ULONG                     api_Class;             /* set by host: notify class (see below) */
    ULONG                     api_Action;            /* set by host: notify code  (see below) */
    ULONG                     api_Qualifier;         /* set by host: intuition qualifier of last input event */
    APTR                      api_Data;              /* set by host: all-purpose slot; usage depends on api_Class */
    UBYTE                    *api_Command;           /* set by host: command string passed to client (read-only), command part uppercase */

    /* return code slots */

    LONG                      api_RC;                /* set by client: client's primary return code */
    UBYTE                    *api_CommandResult;     /* set by client: command result string */
    UBYTE                    *api_CommandError;      /* set by client: command error  string */
    ULONG                     api_Error;             /* set by client: return code (see below) */
    ULONG                     api_Refresh;           /* set by client: display refresh request */
    struct APIOrder          *api_Order;             /* set by client: orders (depends on command set of host) */
};


/* supported api_State values */

#define API_STATE_IGNORE      0                      /* this messages should be ignored */
#define API_STATE_NOTIFY      1                      /* this is a standard notify message */
#define API_STATE_CONSUMED    2                      /* message consumed; won't be passed to other clients */


/* api action classes */

#define API_CLASS_SCREEN      (1L<<1)                /* screen handling  */
#define API_CLASS_KEY         (1L<<2)                /* keyboard event */
#define API_CLASS_COMMAND     (1L<<3)                /* command event */
#define API_CLASS_MOUSE       (1L<<4)                /* mouseclick event */
#define API_CLASS_REFRESH     (1L<<5)                /* refresh request  */
#define API_CLASS_SYSTEM      (1L<<6)                /* notifies */


/* Supported api_Action values for API_CLASS_KEY */

#define API_ACTION_VANILLAKEY 1                      /* vanillakey event; key code passed in api_Data */
#define API_ACTION_RAWKEY     2                      /* rawkey event; key code passed in api_Data */


/* Supported api_Action values for API_CLASS_SCREEN */

#define API_ACTION_HIDE       1                      /* close your window(s) - host will close display */
#define API_ACTION_SHOW       2                      /* open  your window(s) - host display available */


/* Supported api_Action values for API_CLASS_COMMAND */

#define API_ACTION_COMMAND    1                      /* command passed to client (api_Command) */


/* Supported api_Action values for API_CLASS_MOUSE */

#define API_ACTION_CLICK      1                      /* mouse click into client area (api_Data points to coordinates) */


/* Supported api_Action values for API_CLASS_REFRESH */

#define API_ACTION_RESIZED    1                      /* client area has been resized */


/* Supported api_Action values for API_CLASS_SYSTEM */

#define API_ACTION_WELCOME    1                      /* start client */
#define API_ACTION_EXIT       2                      /* host requests client to quit */

/* Supported api_Error values - set by client */

#define API_ERROR_OK          0                      /* notify successfully processed */
#define API_ERROR_FAIL        1                      /* processing of notify failed */
#define API_ERROR_UNKNOWN     2                      /* unknown api_Code/api_Class detected */


/* supported refresh types (api_Refresh) - requested by client */

#define API_REFRESH_DISPLAY   (1L<<1)                /* redraw display      */
#define API_REFRESH_LINE      (1L<<2)                /* redraw current line */
#define API_REFRESH_SYNC      (1L<<3)                /* sync view           */
#define API_REFRESH_NOMARKER  (1L<<4)                /* hide selection      */
#define API_REFRESH_MARKER    (1L<<8)                /* refresh marker      */


/* ---------------------------------- APIHost ----------------------------------

 Host description (read-only): provided by host

*/

struct APIHost {

    ULONG                     api_APIVersion;        /* interface standard supported by host */
    ULONG                     api_Version;           /* release code */
    ULONG                     api_Serial;            /* serial code of host */
    UBYTE                    *api_Name;              /* application name */
    UBYTE                    *api_Info;              /* application info */
    APTR                      api_Environment;       /* configuration (host-specific) */

    /* private data may follow (depends on host) */
};

#define API_INTERFACE_VERSION 2


/* -------------------------------- APIInstance --------------------------------

 Instance description (read-only): provided by host.

*/

struct APIInstance {

    struct APIHost           *api_Host;              /* host application */
    UBYTE                    *api_Name;              /* instance name */
    APTR                      api_Environment;       /* configuration (host-specific) */
    struct Screen            *api_Screen;            /* screen used by instance */
    struct Window            *api_Window;            /* window used by instance */
    struct APIContainer      *api_Area;              /* reserved area provided by instance */

    /* private data may follow (depends on host) */
};


/* --------------------------------- APIClient ---------------------------------

 Client description (read-only): provided by client

*/


struct APIClient {

    ULONG                     api_APIVersion;        /* interface standard supported by client */
    ULONG                     api_Version;           /* release code */
    UBYTE                    *api_Name;              /* client name */
    UBYTE                    *api_Info;              /* client info */
    UBYTE                   **api_Commands;          /* command list (NULL-terminated) */
    ULONG                     api_Serial;            /* serial code of client */
    ULONG                     api_Classes;           /* class request */
    struct APIContainer      *api_Area;              /* area request */

    /* private data may follow (depends on client) */
};


/* ------------------------------------ APIOrder -------------------------------

 Orders (host-specific) are created by clients and attached to APIMessages

*/


struct APIOrder {

    struct APIOrder          *api_Next;              /* next order or NULL */
    APTR                      api_Data;              /* host-specific data */

    /* more data may follow */
};


/* ------------------------------- APIContainer --------------------------------

 Reserved area provided by instance, controlled by client (numeric values are
 overridden by alignment flags)

*/

struct APIContainer {

    struct Window            *api_Window;            /* window   */
    struct Screen            *api_Screen;            /* screen   */
    struct RastPort          *api_Rast;              /* rastport */
    UWORD                    *api_Align;             /* alignment flags */
    UWORD                    *api_Left;              /* dimensions */
    UWORD                    *api_Top;               /* dimensions */
    UWORD                    *api_Width;             /* dimensions */
    UWORD                    *api_Height;            /* dimensions */
};

#define API_CONTAINER_ALIGN_TOP         0            /* alignment flag */
#define API_CONTAINER_ALIGN_BOTTOM      1            /* alignment flag */
#define API_CONTAINER_ALIGN_LEFT        2            /* alignment flag */
#define API_CONTAINER_ALIGN_RIGHT       4            /* alignment flag */
#define API_CONTAINER_ALIGN_RELWIDTH    8            /* alignment flag */
#define API_CONTAINER_ALIGN_RELHEIGHT   16           /* alignment flag */

#endif
