#ifndef EDITOR_CONFIG_H
#define EDITOR_CONFIG_H

/*
**      $Filename: developer/include/editor.h
**      $Release:  6.0.0
**
**      Editor includes
**
**      (C) Copyright 1999 Dietmar Eilert
**          All Rights Reserved
*/

#ifndef EXEC_TYPES_H
#include <exec/types.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.h>
#endif

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

#ifndef REXX_STORAGE_H
#include <rexx/storage.h>
#endif

/* Each line of a text is described by a line node */

struct LineNode {

    UWORD                 Len;                       /* line's length */
    ULONG                 Line;                      /* locked line number */
    UBYTE                *Text;                      /* pointer to text data */
    struct SpecialInfo   *SpecialInfo;               /* pointer to node extension */
    APTR                  UserData;                  /* syntax parser data */
};


/* node extensions are attached to line nodes (LineNode->SpecialInfo) to store special data */

struct SpecialInfo {

    UWORD                 ID;                        /* extension ID (see below) */

    /* more data follows (extension specific) */
};

/* supported line node extensions (SpecialInfo->ID) */

#define EXTENSION_FOLD    0L                         /* line is a fold header */
#define EXTENSION_BREAK   1L                         /* breakpoint data */

/* some useful macros for checking text lines (struct LineNode *(a)) */

#define IS_FOLD(a)        ((a)->SpecialInfo  && ((a)->SpecialInfo->ID == EXTENSION_FOLD ))
#define IS_BREAK(a)       ((a)->SpecialInfo  && ((a)->SpecialInfo->ID == EXTENSION_BREAK))

#define GET_FOLD(a)       (((a)->SpecialInfo && ((a)->SpecialInfo->ID == EXTENSION_FOLD )) ? ((struct Fold       *)(a)->SpecialInfo) : NULL)
#define GET_BREAKPOINT(a) (((a)->SpecialInfo && ((a)->SpecialInfo->ID == EXTENSION_BREAK)) ? ((struct Breakpoint *)(a)->SpecialInfo) : NULL)

/* node extensions (extended SpecialInfo blocks) */

struct Fold {

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


struct BreakPoint {

    UWORD                 ID;                        /* ID: NODE_EXTENSION_BREAK */
    ULONG                 Line;                      /* absolute line number */
    UWORD                 State;                     /* current breakpoint state */
};

/*

  Peferences of a text buffer (suggest use: read-only); a pointer to this
  structure can be found in APIMessages: APIMessages->APIInstance->api_Environment.

*/

struct EditConfig {

    struct Node         Node;                        /* it's a linked list */
    ULONG               Magic;                       /* useful to scan memory for this number */
    UBYTE              *Name;                        /* document's name      (symbolic) */
    UBYTE              *Path;                        /* document's directory (symbolic) */
    BOOL                ValidName;                   /* file named ? */
    BOOL                ReadOnly;                    /* text is read-only */
    struct LineNode    *TextNodes;                   /* pointer to 1st line's node */
    BOOL                Folds;                       /* any folds ? */
    ULONG               MaxLines;                    /* size of dynamic nodes array */
    ULONG               Lines;                       /* number of lines */
    ULONG               Line;                        /* cursor position */
    UWORD               Column;                      /* cursor position (byte offset) */
    UWORD               LastChangeColumn;            /* column of last change */
    ULONG               LastChangeLine;              /* line of last change */
    UBYTE              *CurrentBuffer;               /* pointer to current line buffer */
    UWORD               CurrentLen;                  /* bytes in buffer */
    UBYTE              *UndoBuffer;                  /* pointer undo buffer */
    UWORD               UndoLen;                     /* bytes in undo buffer */
    ULONG               UndoLine;                    /* line number of undo buffer */
    BOOL                LineModified;                /* flag: line   has been modified */
    BOOL                DocModified;                 /* flag: buffer has been modified */
    UWORD               Marker;                      /* marker mode */
    BOOL                FlowMark;                    /* marker ink flow while moving ? */
    UWORD               BlockStartX;                 /* block start */
    ULONG               BlockStartY;                 /* block start */
    UWORD               BlockEndX;                   /* block end */
    ULONG               BlockEndY;                   /* block end */
    ULONG               SearchLine;                  /* find start: line */
    UWORD               SearchColumn;                /* find start: column */
    ULONG               Protection;                  /* protection bits */
    BOOL                LineNotFixed;                /* line-may-be-changed flag */
    UWORD               BackupCounter;               /* backup timer [min] */
    BOOL                Preview;                     /* preview active ? */
    BOOL                Frozen;                      /* text frozen ? */
    UBYTE               Comment[80];                 /* file comment */
    ULONG               Reserved1[10];               /* reserved */
    ULONG               Reserved2[10];               /* reserved */
    UWORD               Cursor;                      /* cursor position (visual) */
    BOOL                CRLF;                        /* save CR-LF format ? */

    /* more (private) data follows */
};


/* marker modes (EditConfig->Marker) */

#define BLOCKMODE_NONE    0L
#define BLOCKMODE_LINE    1L
#define BLOCKMODE_CHAR    2L
#define BLOCKMODE_COLUMN  3L


/* preferences of text windows (read-only); attached to Window->UserData  */

struct WindowSupportInfo {

    struct Node               Node;                  /* it's a linked list */
    ULONG                     RequesterID;           /* window type (= title ID) */

    /* window data */

    struct ScreenSupportInfo *ScreenSupportInfo;     /* screen handle */
    struct Window            *Window;                /* window handle */

    /* window handlers */

    struct Window *(*Server )(struct ScreenSupportInfo *, struct Window *, UWORD, APTR);
    void           (*CleanUp)(struct WindowSupportInfo *);

    APTR                      Reserved1;
    APTR                      Reserved2;

    /* window dimensions */

    UWORD                     Type;                  /* window/server type */
    UWORD                     Left;                  /* window position */
    UWORD                     Top;                   /* window position */
    UWORD                     Width;                 /* window size */
    UWORD                     Height;                /* window size */

    /* scaling information */

    struct TextAttr          *FontAttr;              /* scaling information: font */
    UWORD                     FontX;                 /* scaling information: font width */
    UWORD                     FontY;                 /* scaling information: font height */

    /* rendering information */

    struct RastPort          *RastPort;              /* current rastport */

    /* text configuration (if any) */

    struct EditConfig        *EditConfig;            /* text buffer */
    UWORD                     TopColumn;             /* first column */
    ULONG                     TopLine;               /* first row */
    UWORD                     DisplayW;              /* display size [chars] */
    UWORD                     DisplayH;              /* display size [chars] */
    UWORD                     FontW;                 /* current font size X */
    UWORD                     FontH;                 /* current font size Y */
    BOOL                      Modified;              /* visual status of modified flag */

    /* PRIVATE DATA FOLLOWS */
};

/*
   Definition of the APIModifyRequest data structure. Clients may create API
   orders (see developer/api/include/aplilib.h) of the type API_ORDER_MODIFY
   (stored in APIOrder->api_Flags) which have an APIModifyRequest as data
   block (APIOrder->Data). The editor will modify the line specified in the
   APIModifyRequest. Only unfolded text lines can be modified using these
   orders (this is a restriction of the editor's undo/redo system).

   Modify requests can be used to set the cursor position, too, by passing
   NULL as new text (APIModifyRequest->mr_Data).

*/

#define API_ORDER_MODIFY 0

struct APIModifyRequest {

    ULONG                 mr_Line;                   /* cursor line */
    UWORD                 mr_Column;                 /* cursor column */
    UBYTE                *mr_Data;                   /* new text */
    UWORD                 mr_Size;                   /* new length */
};

/*
   Definition of the APIUnparseRequest data structure. Clients may create API
   orders (see developer/api/include/aplilib.h) of the type API_ORDER_UNPARSE
   (stored in APIOrder->api_Flags) which have an APIUnparseRequest as data
   block (APIOrder->Data). The editor will refresh syntax highlighting of the
   text node specified by the APIUnparseRequest.

*/

#define API_ORDER_UNPARSE 1

struct APIUnparseRequest {

    struct LineNode      *ur_LineNode;               /* text node to be unparsed */
};

#endif
