/*
\\              Header file for editor class
*/

        #define REG(x)  register __ ## x
        #define ASM             __asm
        #define SAVEDS  __saveds

        #define EDITOR_TAGS     0x80880000            ,         /* Base for tags */
        #define EDITOR_COOKIE   MAKE_ID('E','D','I','T')        /* Magic cookie for safety */
        #define AUX_COOKIE      MAKE_ID('A','U','X','B')        /* ditto... */

        #define MUIC_Editor     "Editor.mcc"
        #define EditorObject    MUI_NewObject(MUIC_Editor

struct InstanceData
{
                Object          *Obj;               
                APTR            LinePool;
                ULONG           Cookie;  
                UBYTE           LineBuffer[1024];        
        struct  MinList         LineList;
        struct  Hook            *TabHook;
        struct  Hook            *InputHook;
        struct  Hook            *RenderHook;
        struct  RastPort        RastPort;
        struct  TmpRas          TempRaster;
        struct  LineData        *TopVisLoc;
        struct  LineData        *CurrLine;   
        struct  TextFont        *Font;
        struct  TextAttr        *SuppliedFont;                       
                LONG            Lines;             
                LONG            LinesVisible;      
                LONG            ColsVisible;       
                UBYTE           textcol, backcol, seltextcol, selbackcol, curstextcol, cursbackcol;      
                LONG            oldy, oldx, curry, currx, topvisy, topvisx, oldvisy;       
                LONG            marky, markx, idealx, clickcolumn;
                ULONG           topdrawny;
                ULONG           BufferSize;
                ULONG           LastCode;
                ULONG           QuietCount;
                ULONG           SysSetCount;
                UWORD           TabSize;
                ULONG           Flags;
                ULONG           doublesecs, doublemicros;
                
};

        #define DRAWLINE                (1<<0)  /* If set, redraw the current line */
        #define DRAWALL                 (1<<1)  /* If set, full redraw */
        #define KEEPIDEALX              (1<<2)  /* Prevent alteration of data->idealx */
        #define DRAWSCROLL              (1<<3)  /* If set, scroll visible area */
        #define CUSTOMFONT              (1<<4)  /* We have opened the font ourselves */
        #define FOLLOWCURSOR            (1<<5)  /* If set, we want the visible area to follow the cursor */
        #define DRAGGING                (1<<6)  /* User is dragging cursor with mouse */
        #define CHANGED                 (1<<7)  /* If set, buffer has been altered */
        #define DRAWMARKED              (1<<8)  /* Draw between oldy and curry */
        #define MARKING                 (1<<9)  /* If set, in the process of marking */
        #define USESYSKEYS              (1<<10) /* If set, use keys defined in MUI prefs */
        #define FOLLOWVISIBLE           (1<<11) /* If set, update cursor to follow vis area */
        #define ISEMPTY                 (1<<12) /* Set when lines = 1, buffersize = 0 */
        #define DRAWINSERT              (1<<13) /* A newline has been added... */
        #define DRAWREMOVE              (1<<14) /* A line has been deleted... */
        #define AUTOINDENT              (1<<15) /* Automatically indent lines... */
        #define FREEFLOAT               (1<<16) /* Lines are extended to meet cursor, trimmed after */

struct ReadData 
{               /* Used by load functions */
        APTR Handle, Buffer;
        UBYTE *LineBuff, *BuffPos;
        ULONG BuffSize, BytesLeft, BytesRead;
        UWORD Mode;
        Object *Obj;
        struct Hook *hook;
};

/*      /\ /\ /\                Private data ends */

struct AuxBuffer 
{      
        ULONG Cookie;
        APTR  PoolHeader;                                /* ...this is IN the memory pool! */
        struct MinList LineList;
        ULONG Lines, curry, currx, marky, markx, topvisy, topvisx, Flags;
};

struct LineData
{
        struct MinNode Node;
        UWORD  Length;           /* Length of line */
        UBYTE  Data[1];            /* Actual string (NULL terminated - NULL is not counted in length) */
};

enum ULONG {
        MUIA_Editor_BackCol = (int) (EDITOR_TAGS + 1),  /* ISG Background Colour                        */
        MUIA_Editor_Changed,                            /* .SG Set when buffer is changed               */
        MUIA_Editor_CurrColumn,                         /* .SG Cursor X Pos after tab expansion         */
        MUIA_Editor_CurrX,                              /* .SG Cursor X Pos                             */
        MUIA_Editor_CurrY,                              /* .SG Cursor Y Pos                             */
        MUIA_Editor_CursBackCol,                        /* ISG Cursor Background Colour                 */
        MUIA_Editor_CursTextCol,                        /* ISG Cursor Text Colour                       */
        MUIA_Editor_FollowCurs,                         /* ISG Make vis. area follows curs.             */
        MUIA_Editor_FollowVis,                          /* ISG if TRUE, update cursor pos to follow vis area */
        MUIA_Editor_InputHook,                          /* ISG Hook for custom input control            */
        MUIA_Editor_IsEmpty,                            /* ..G TRUE if editor is completely empty       */
        MUIA_Editor_LastCode,                           /* ..G Last Code passed through editor          */
        MUIA_Editor_Lines,                              /* ..G Lines in buffer                          */
        MUIA_Editor_MarkX,                              /* .SG Start Mark X pos                         */
        MUIA_Editor_MarkY,                              /* .SG Start Mark Y pos                         */
        MUIA_Editor_Quiet,                              /* .SG If TRUE, no rendering                    */
        MUIA_Editor_SelBackCol,                         /* ISG Sel. Background col.                     */
        MUIA_Editor_SelTextCol,                         /* ISG Selected Text col.                       */
        MUIA_Editor_TabHook,                            /* ISG Hook for custom tab control              */
        MUIA_Editor_TabSize,                            /* ISG Size of tabs                             */
        MUIA_Editor_TextCol,                            /* ISG Text Colour                              */
        MUIA_Editor_UseSysKeys,                         /* ISG If TRUE, use defined keys                */
        MUIA_Editor_Version,                            /* ..G Current editor version                   */
        MUIA_Editor_VisCols,                            /* ..G Number of columns visible                */
        MUIA_Editor_VisibleX,                           /* .SG Left of visible area                     */
        MUIA_Editor_VisibleY,                           /* .SG Top of visible area                      */
        MUIA_Editor_VisLines,                           /* ..G Number of lines visible                  */
        MUIA_Editor_Font,                               /* ISG Current object font (also MUIA_Font...)  */
        MUIA_Editor_RenderHook,                         /* ISG Hook function for line rendering         */
        MUIA_Editor_AutoIndent,                         /* ISG TRUE if indenting is to be carried over  */
        MUIA_Editor_IdealX,                             /* ..G Current `preferred' x position           */
        MUIA_Editor_ClickColumn,                        /* ..G Column mouse was last clicked on         */ 
        MUIA_Editor_Marking,                            /* .SG TRUE if currently marking                */
        MUIA_Editor_FloatCursor,                        /* ISG TRUE if cursor is freefloating           */
        MUIM_Editor_ClearBuffer = (int) (EDITOR_TAGS + 500),    /* Empty buffer */
        MUIM_Editor_Import,                                     /* Import text */
        MUIM_Editor_Export,                                     /* Export text */
        MUIM_Editor_Replace,                                    /* Replace specified line */
        MUIM_Editor_Insert,                                     /* Insert text at x, y */
        MUIM_Editor_Delete,                                     /* Remove Text at x, y */
        MUIM_Editor_GetLine,                                    /* Returns pointer to linedata of specified line */
        MUIM_Editor_Paste,                                      /* Guesses on a postcard to... */
        MUIM_Editor_Copy,                                       /* This acts as Copy/Cut/Delete depending on flags */
        MUIM_Editor_AddLine,                                    /* Insert a new line at line y */
        MUIM_Editor_RemLine,                                    /* Remove line y */
        MUIM_Editor_Search,                                     /* Search for a specified string */
        MUIM_Editor_SwapBuffer,                                 /* Swap current buffer for new */
        MUIM_Editor_KillBuffer,                                 /* Kill detached buffer */
        MUIM_Editor_ImportAux,                                  /* Import directly to detached buffer */
        MUIM_Editor_ExportAux,                                  /* Export directly from detached buffer */
};

        #define LOADMODE_ASCII  0       /* Load/Save as ascii (raw) */
        #define LOADMODE_FTXT   1       /* Load/Save as IFF FTXT */
        #define LF_LOADMODE     1       /* Mask for loadmode */
        #define LF_HOOK         2       /* Calls supplied hook every 32768 bytes/32 lines */

        #define CF_STORE        1       /* When copying, store marked data */
        #define CF_DELETE       2       /* When copying, delete source */
        #define CF_UNMARK       4       /* When copying, unmark after (has no effect on cut) */

        #define SMODE_COMPLEX   1       /* Use pattern matching for string */
        #define SMODE_REVERSE   2       /* Search backwards... */
        #define SMODE_NOCASE    4       /* Case insensitive */

        #define MUIV_Editor_Min         0               /* Arguments used when  */
        #define MUIV_Editor_Max         0xFFFFFFFF      /*      setting X and Y */
        #define MUIV_Editor_Prev        0xFFFFFFFE
        #define MUIV_Editor_Next        0xFFFFFFFD
        #define MUIV_Editor_CurrPos     0xFFFFFFFC

struct ImportMSG 
{      
        ULONG MethodID;
        BPTR  FileHandle;
        ULONG Flags;
        struct Hook *ProgHook;
};
struct AdjustMSG 
{      
        ULONG MethodID;
        ULONG x, y;
        ULONG Size;
        UBYTE *String;          
};
struct GetLineMSG 
{     
        ULONG MethodID;
        ULONG Line;
};
struct CutPasteMSG 
{    
        ULONG MethodID;
        ULONG ClipNum;
        ULONG Flags;            
};
struct SearchMSG 
{    
        ULONG MethodID;
        UBYTE *Pattern;
        ULONG Flags;
        ULONG *xpos, *ypos;
};
struct AddLineMSG
{     
        ULONG MethodID;
        ULONG Line;
        UBYTE *String;        
        ULONG Length;           
};
struct SwapBuffMSG 
{
        ULONG MethodID;
        struct AuxBuffer *Buff;
};

struct ImportAuxMSG 
{
        ULONG   MethodID;
        struct  AuxBuffer *Buff;
        BPTR    FileHandle;
        ULONG   Flags;
        struct  Hook *ProgHook;
};

        
        #include "Disk_protos.h"
        #include "Draw_protos.h"
        #include "Editor_protos.h"
        #include "Hook_protos.h"
        #include "Input_protos.h"
        #include "Libinit_protos.h"
        #include "Support_protos.h"

        #define MSG_CODE                0x00FF  /* The code part - the character used etc */
        #define MSG_TYPE                0x0300  /* The type of message - char, special */

        #define MSG_CHAR                0x100
        #define MSG_SPECIAL             0x200

        #define SPC_NOP          0              /* Do nothing */
        #define SPC_EOL          1              /* End of line */
        #define SPC_SOL          2              /* Start of line */
        #define SPC_DEOL         3              /* Delete to EOL */
        #define SPC_DSOL         4              /* Delete to SOL */
        #define SPC_EOF          5              /* End of file (bottom line) */
        #define SPC_SOF          6              /* Start of file (top line) */
        #define SPC_NW           7              /* Next word/line */
        #define SPC_PW           8              /* Previous word/line */
        #define SPC_NC           9              /* Next character/line */
        #define SPC_PC          10              /* Prev character/line */
        #define SPC_DNW         11              /* Delete next word */
        #define SPC_DPW         12              /* Delete previous word */
        #define SPC_DNC         13              /* Delete next character */
        #define SPC_DPC         14              /* Delete previous character */
        #define SPC_PL          15              /* Previous line */
        #define SPC_NL          16              /* Next line */
        #define SPC_PP          17              /* Previous page */
        #define SPC_NP          18              /* Next page */
        #define SPC_NOBJ        19              /* Next obj in window cyclechain */
        #define SPC_POBJ        20              /* Previous obj in cyclechain */

struct TabMSG 
{        
        ULONG currx;
};

struct InputMSG 
{            
        ULONG Defaction;
        struct IntuiMessage *imsg;
};

struct RenderMSG 
{     
        struct RastPort *rp;
        struct TextFont *tf;
        UBYTE *String;
        LONG StrLen, curspos, markmin, markmax, linelen, xsize;
        UBYTE textcol, backcol, marktextcol, markbackcol, curstextcol, cursbackcol;
};
