#ifndef GOLDED_API_H
#define GOLDED_API_H
/*
**      $Filename: fd/GoldED.h
**      $Release: 4.2
**
**      GoldED API definitions.
**
**      (C) Copyright 1995 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

/* global preferences of GoldED (most entries are read-only) */

struct GlobalConfig {

    /* screen related entries */

    UWORD            F_ScreenType;                   /* screen type (WBench/Public/Custom) */
    UBYTE           *F_ScrnName;                     /* screen name */
    UWORD            F_OverscanType;                 /* overscan mode */
    UWORD            F_Depth;                        /* screen depth */
    UWORD            F_Colors[256][3][2];            /* screen colors */
    BOOL             F_AutoScroll;                   /* autoscroll of screen enabled ? */
    UWORD            F_AutoScrollX;                  /* screen width */
    UWORD            F_AutoScrollY;                  /* screen height */
    ULONG            F_ModeID;                       /* screen mode ID */
    BOOL             F_BorderBlank;                  /* blank screen borders */
    BOOL             F_Shanghai;                     /* shanghai windows ? */
    BOOL             F_ShowIcons;                    /* show icons ? */
    UWORD            F_SliderMode;                   /* slider type */
    BOOL             F_AdjustOverscan;               /* don't-save-screen-size flag */
    BOOL             F_ChunkyPixel;                  /* chunky pixel (non-ECS) display ? */
    BOOL             F_Barlabel;                     /* use barlabel within menus ? */
    BOOL             F_Clock;                        /* clock on ? */

    struct TextAttr *F_TxtFontAttr;                  /* text font */
    struct TextAttr *F_PrvFontAttr;                  /* preview font */
    struct TextAttr *F_WinFontAttr;                  /* requester font */
    struct TextAttr *F_GadFontAttr;                  /* gadget font */
    struct TextAttr *F_ScrFontAttr;                  /* screen font */
    struct TextAttr *F_BldFontAttr;                  /* bold font */

    /* GUI related entries */

    BOOL             F_NewLook;                      /* window look */
    UWORD            F_EditWinW;                     /* default window width */
    UWORD            F_EditWinH;                     /* default window height */
    UWORD            F_WinX;                         /* default window position (X) */
    UWORD            F_WinY;                         /* default win position    (Y) */
    BOOL             F_BottomSlider;                 /* bottom slider ? */
    UWORD            F_SliderRight;                  /* scroller dimensions */
    UWORD            F_SliderBottom;                 /* scroller dimensions */
    UWORD            F_ArrangeLeft;                  /* arrange-window margin */
    UWORD            F_ArrangeRight;                 /* arrange-window margin */
    UWORD            F_ArrangeTop;                   /* arrange-window margin */
    UWORD            F_ArrangeBottom;                /* arrange-window margin */
    UWORD            F_ArrangeWeight;                /* arrange-window weight for current window */
    BOOL             F_AutoArrange;                  /* rearrange windows automatically ? */
    BOOL             F_CenterWin;                    /* center windows ? */
    UWORD            F_ScrollBorderX;                /* scroll border (left/right) */
    UWORD            F_ScrollBorderY;                /* scroll border (top/bottom) */
    BOOL             F_SimpleMessages;               /* use status bar instead of requester ? */
    BOOL             F_FastScroll;                   /* dynamic scrolling */
    BOOL             F_FullScreen;                   /* use full screen while aranging windows */

    /* file requester preferences */

    UWORD            F_ASLLeft;                      /* ASL file requester dimensions */
    UWORD            F_ASLTop;                       /* ASL file requester dimensions */
    UWORD            F_ASLWidth;                     /* ASL file requester dimensions */
    UWORD            F_ASLHeight;                    /* ASL file requester dimensions */
    BOOL             F_UseASL;                       /* use ASL file requester */

    /* misc preferences */

    WORD             F_TaskPri;                      /* task priority */
    UWORD            F_ErrorBeep;                    /* error beep volume */
    BOOL             F_HotKey;                       /* hotkey enabled ? */
    BOOL            *F_User;                         /* pointer to array of 20 user vaiables */
    UBYTE           *F_ARexx;                        /* name of ARexx port */
    UWORD            F_TextMenu;                     /* maintain file menu */
    BOOL             F_StyleGuide;                   /* case-insensitive menu shortcuts */
    ULONG            F_Version;                      /* editor version */
    ULONG            F_Fixlevel;                     /* editor bugfix level */
    UBYTE           *F_Console;                      /* default console */

    /* private stuffs follows */
};

/* peferences of current text (read-only) */

struct EditConfig {

    struct Node               Node;                  /* it's a linked list */
    ULONG                     Magic;                 /* magic number */
    struct LineNode          *TextNodes;             /* pointer to node of 1st line */
    ULONG                     Lines;                 /* number of lines    (abs) */
    ULONG                     reserved1;             /* reserved */
    UWORD                     reserved2;             /* reserved */
    UWORD                     Column;                /* cursor x position  (abs) */
    ULONG                     Line;                  /* current line number */
    UWORD                     LastChangeColumn;      /* column of last change */
    ULONG                     LastChangeLine;        /* line of last change */
    ULONG                     MaxLines;              /* size of line ptr array */
    UBYTE                     Path[141];             /* document's directory */
    UBYTE                     Name[141];             /* document's name */
    UBYTE                    *CurrentBuffer;         /* line buffer of current line */
    UWORD                     CurrentLen;            /* bytes in buffer */
    UBYTE                    *UndoBuffer;            /* undo buffer */
    UWORD                     UndoLen;               /* bytes in undo buffer */
    ULONG                     UndoLine;              /* line number of undo buffer */
    BOOL                      LineModified;          /* flag: line has changed */
    BOOL                      DocModified;           /* document-modified flag */
    UWORD                     BlockStartX;           /* block start (column) */
    ULONG                     BlockStartY;           /* block start (line) */
    UWORD                     BlockEndX;             /* block end   (column) */
    ULONG                     BlockEndY;             /* block end   (line) */
    UWORD                     Marker;                /* marker mode (see below) */
    ULONG                     SearchLine;            /* start line for find */
    UWORD                     SearchColumn;          /* start column for find */
    long                      Protection;            /* file's protection bits */
    BOOL                      Folds;                 /* any folds ? */
    BOOL                      LineNotFixed;          /* line-may-be-changed flag */
    BOOL                      ReadOnly;              /* disable save ? */
    UBYTE                     Comment[80];           /* file comment */
    UWORD                     BackupCounter;         /* AutoBackup counter [min] */
    BOOL                      ValidName;             /* file named ? */

    /* private stuff follows */
};

#define BLOCKMODE_NONE  0                            /* marker modes */
#define BLOCKMODE_LINE  1
#define BLOCKMODE_CHAR  2

/* each line of a text has an associated line node, describing the line contents */

struct LineNode {

    UWORD            Len;                            /* line's length */
    UBYTE           *Text;                           /* pointer to text data */
    struct Fold     *Fold;                           /* pointer to folded sub block */
    APTR             UserData;                       /* user data (reserved) */
};

/* each block of folded lines has a fold root */

struct Fold {

    ULONG            Lines;                          /* lines within folded block */
    struct LineNode *TextNodes;                      /* pointer to node of 1st line */
};

/* Basic preferences of current window */

struct WindowSupportInfo {

    struct Node               Node;                  /* it's a linked list */
    struct Window            *Window;                /* associated window */
    struct EditConfig        *EditConfig;            /* text buffer (if any) */
    UWORD                     Sleep;                 /* >0: show busy pointer */
    struct Menu              *Menu;                  /* menu bar (if any) */
    struct Gadget            *GadgetList;            /* pointer to 1st gadget (if any) */
    void                     *(*CleanUp)(void);      /* window's cleanUp function */
    void                     *(*Server)(void);       /* window's handler */
    void                     *(*CallBack)(APTR);     /* all purpose callback function */
    APTR                      Data;                  /* ptr to variables */
    ULONG                     DataSize;              /* size of variables */
    ULONG                     Mode;                  /* all purpose buffer */
    LONG                      Buffer;                /* all purpose buffer */
    UWORD                     Type;                  /* window/server type (1 = text window) */
    UWORD                     ExitGadget;            /* gadget to be used on ESC */
    UWORD                     Left;                  /* window dimensions */
    UWORD                     Top;                   /* window dimensions */
    UWORD                     Width;                 /* window dimensions */
    UWORD                     Height;                /* window dimensions */

    /* private stuff follows */
};

/*
   API modification requests are passed to the editor if the client wants to
   edit the current text without using the ARexx interface. API modification
   requests are attached to APIMessage structures (see below).
*/

struct APIModifyRequest {

    struct APIModifyRequest  *mr_Next;               /* next modification request or NULL */
    ULONG                     mr_Line;               /* cursor line */
    UWORD                     mr_Column;             /* cursor column */
    UBYTE                    *mr_Data;               /* modification request: data (cursor movement only if NULL) */
    UWORD                     mr_Size;               /* modification request: bytes */
};

/*
  
 API messages  are  sent  from  GoldED  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 GoldED wants you to close your windows). The
 client will always recieve a pointer to basic configuration data of the current
 text (api_Config) and of the current window (api_WinInfo). Some classes provide
 additional data using the api_Data field. After having  processed  the  message
 you should update the api_Error field.

*/

struct APIMessage {

    struct Message            api_Message;           /* embedded message structure */
    ULONG                     api_State;             /* message state (valid/invalid) */
    struct APIMessage        *api_Next;              /* next APIMessage */
    struct GlobalConfig      *api_Global;            /* preferences of GoldED */
    struct EditConfig        *api_Config;            /* preferences of current text */
    struct WindowSupportInfo *api_WinInfo;           /* preferences of current window */
    ULONG                     api_Class;             /* notify class (see below) */
    ULONG                     api_Action;            /* notify code  (see below) */
    ULONG                     api_Qualifier;         /* intuition qualifier of last input event */
    APTR                      api_Data;              /* all-purpose slot; usage depends on api_Class */
    ULONG                     api_Error;             /* set by client: return code (see below) */
    ULONG                     api_Refresh;           /* set by client: display refresh request */
    struct APIModifyRequest  *api_Modify;            /* set by client: modification request */
};

/* Additional data passed to clients as api_Data during API_ACTION_COMMAND events (see below) */

struct APIRexxNotify {

    UBYTE                    *arn_Command;           /* command string passed to client (read-only), command part uppercase */
    LONG                      arn_RC;                /* client's primary return code */
    UBYTE                    *arn_CommandResult;     /* command result string (referenced, not copied by GoldED) */
    UBYTE                    *arn_CommandError;      /* command error  string (referenced, not copied by GoldED) */
};

/* Classes. Clients will recieve events of classes they have asked for only */

#define API_CLASS_ROOT       (1L<<0)                 /* must be supported by all clients */
#define API_CLASS_SCREEN     (1L<<1)                 /* screen handling (open/close) */
#define API_CLASS_KEY        (1L<<2)                 /* keyboard events */
#define API_CLASS_REXX       (1L<<3)                 /* ARexx commands */

/* Supported refresh types (api_Refresh) */

#define API_REFRESH_LINE     (1L<<1)                 /* make GoldED redraw current line */
#define API_REFRESH_DISPLAY  (1L<<2)                 /* make GoldED redraw the current text */
#define API_REFRESH_SYNC     (1L<<3)                 /* adjust view according to cursor position (redraw if necessary) */
#define API_REFRESH_NOMARKER (1L<<4)                 /* hide marker */
#define API_REFRESH_MARKER   (1L<<8)                 /* refresh marker */

/* Supported api_Action values for API_CLASS_ROOT */

#define API_ACTION_NOP        0                      /* no operation */
#define API_ACTION_DIE        1                      /* close your windows (before replying message) & quit */
#define API_ACTION_CONFIG     2                      /* open your preferences requester */
#define API_ACTION_INTRODUCE  3                      /* return static tag list describing your client (tags listed below) */

/* API_ACTION_INTRODUCE tags */

#define API_Client_Name       (TAG_USER + 1)         /* ti_Data pointing to client's name (UBYTE *) */
#define API_Client_Copyright  (TAG_USER + 2)         /* ti_Data pointing to copyright string  (UBYTE *) */
#define API_Client_Purpose    (TAG_USER + 3)         /* ti_Data pointing to short description of client (UBYTE *) */
#define API_Client_Template   (TAG_USER + 4)         /* ti_Data pointing to a command template (UBYTE *); multiple use allowed */

/* Supported api_Action values for API_CLASS_KEY */

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

/* Supported api_Action values for API_CLASS_SCREEN */

#define API_ACTION_HIDE       1                      /* close your windows (before replying message) */
#define API_ACTION_SHOW       2                      /* open your windows (except config windows) */

/* Supported api_Action values for API_CLASS_REXX */

#define API_ACTION_COMMAND    1                      /* internal/ARexx command passed to client (pointer to APIRexxNotify in api_Data) */

/* Supported api_Error values */

#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 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, no further processing by GoldED */

#endif
