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

    MODUL
	global.h

    DESCRIPTION
	Defines/structs that mostly all sources depend on.

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

#ifndef GLOBAL_H
#define GLOBAL_H

/**************************************
		Includes
**************************************/


/**************************************
	    Globale Variable
**************************************/


/**************************************
	Defines und Strukturen
**************************************/
typedef unsigned char		ubyte;
typedef unsigned short		uword;
typedef unsigned short		ushort; 	    /* HD added */
typedef unsigned long		ulong;
typedef int			Line;
typedef int			Column;
typedef char			Bool;

typedef struct Node		NODE;
typedef struct MinNode		MNODE;
typedef struct List		LIST;
typedef struct MinList		MLIST;
typedef struct MsgPort		PORT;
typedef struct Window		WIN;
typedef struct Screen		SCREEN;
typedef struct Message		MSG;
typedef struct TextAttr 	TA;
typedef struct TextFont 	FONT;
typedef struct RastPort 	RP;
typedef struct IntuiMessage	IMESS;
typedef struct IntuitionBase	IBASE;
typedef struct Menu		MENU;
typedef struct MenuItem 	ITEM;
typedef struct IntuiText	ITEXT;
typedef struct Process		PROC;
typedef ubyte		      * LINE;

/* as long as DAS doesn't align after const strings don't define const */
#define CONST	    const


/*
New def. for line:

typedef struct {
     ushort  flags;	// flags
     ubyte   lvl;	// folding level
     VString text;	// text
} LINE;
*/


/* Config-Info */
struct Config
{
    Column wwcol;	    /*	word wrap column		    */

    ushort winx;	    /*	save state of non-icon window	    */
    ushort winy;
    ushort winwidth;
    ushort winheight;

    ushort iwinx, iwiny;    /*	save state of icon window	    */

    ushort aslleft;	    /* pos of FileReq */
    ushort asltop;
    ushort aslwidth;
    ushort aslheight;

    Column tabstop;	    /* size of tabs */
    Column margin;

    int   fgpen;	    /* Pens */
    int   bgpen;
    int   hgpen;
    int   tpen;
    int   bbpen;

    Bool  insertmode;
    Bool  ignorecase;
    Bool  wordwrap;
    Bool  autosplit;	    /* Split line automatically ? */
    Bool  autoindent;	    /* Autoindent cursor after <RETURN> ? */
    Bool  autounblock;	    /* Automatic Unblock on new BLOCK-command ? */
};


struct GlobalFlags
{
    ULONG debug : 1;		/* Do debugging */
    ULONG NoRequest : 1;	/* PATCH_NULL: disable requestors		*/
    ULONG Showtitle : 1;	/* Used by untitle to disable some title calls	*/
    ULONG Msgchk : 1;		/* Force message queue check for break		*/
    ULONG Windowcycling : 1;	/* PATCH_NULL : SELECT last SELECT next == SELECT first */
    ULONG ActivateToFront : 1;	/* PATCH_NULL : SELECTed windows are moved to front	*/
    ULONG SourceBreaks : 1;	/* PATCH_NULL : errors in source abort the read 	*/
    ULONG Savetabs : 1; 	/* SaveTabs mode?				*/

    ULONG SimpleTabs : 1;	/* PATCH_NULL [25 Jan 1993] : SaveTabs mode only until firstnb ? */
    ULONG memoryfail : 1;	/* out of memory flag				*/
    ULONG Comlinemode : 1;	/* Is commandline active ?			*/
    ULONG Abortcommand : 1;	/* Should loop-command (while/repeat) abort ?   */
    ULONG global_search : 1;	/* Do a global search ? 			*/
    ULONG Quitflag : 1; 	/* Should DME close actual window ?		*/
    ULONG QuitAll : 1;		/* Should DME quit ?				*/
    ULONG Overide : 1;		/* Quit even if file was modified		*/

    ULONG Wdisable : 1; 	/* Disable icon save				*/
    ULONG MForceTitle : 1;	/* Force refresh of title			*/
    ULONG FollowCursor : 1;	/* Make sure cursor is visible			*/
};


typedef struct _ED
{
    NODE	    node;	/* for list */
    WIN 	  * win;	/* actual window */
    struct Gadget * propgad;	/* Pointer to our PropGadget */
    FONT	  * font;	/* actual font! */
    Line	    topline;
    Column	    topcolumn;	/* top left edge of window in the text */
    Line	    line;
    Column	    column;	/* actual cursor position */
    long	    lines,
		    maxlines;	/* number of text-lines we use and how much we
				   have at most */
    LINE	  * list;	/* list of text-lines */
    ubyte	    name[64];
    ubyte	    wtitle[130];
    ULONG	    modified : 1;   /* is text modified ? */
    ULONG	    iconmode : 1;   /* window in icon mode */
    ULONG	    viewmode : 1;   /* PATCH_NULL: disable changes to text */
    BPTR	    dirlock;	/* directory lock */

    APTR	    textvars;	    /* PATCH_NULL: list of localized vars  */
    char	    textflags[4];   /* PATCH_NULL: field of local flags    */
    APTR	    package;	    /* PATCH_NULL: ptr to current Package  */
/* --- I have decided not to use Packages but multiple Menues and Keytables */
    APTR	    menustrip;	    /* PATCH_NULL: ptr to current MenuStrip */
    APTR	    keytable;	    /* PATCH_NULL: ptr to current KeyTable  */
    APTR	    package;	    /* PATCH_NULL: ptr to current Package   */

    /*
     *	CONFIG INFORMATION
     */
    struct Config config;

} ED;


#define beginconfig	    config
#define CONFIG_SIZE	    (sizeof(struct Config))
#define CONFIG_VERSION	    "XDMECNFG0001"


/* Define Colors */
#define TEXT_FPEN   Ep->config.fgpen
#define TEXT_BPEN   Ep->config.bgpen
#define BLOCK_FPEN  Ep->config.hgpen
#define BLOCK_BPEN  Ep->config.bbpen
#define TITLE_FPEN  TEXT_FPEN
#define TITLE_BPEN  Ep->config.tpen
#define TEXT_MASK   (TEXT_FPEN | TEXT_BPEN)
#define BLOCK_MASK  (TEXT_FPEN | TEXT_BPEN | BLOCK_FPEN | BLOCK_BPEN)


/* Block-Types
    note:   BSxxx is invalid if BSline < 0,
	    BExxx is invalid if BEline < 0
    If BlockType == BT_NONE, one must not check any other values.
*/
#define BT_NONE     0	    /* No current block */
#define BT_LINE     1	    /* Block is full-line */
#define BT_NORMAL   2	    /* Block starts at BScolumn/BSline and ends at
			       BEcolumn/BEline */
#define BT_VERTICAL 3	    /* Block is a rectangle from BScolumn/BSline to
			       BEcolumn/BEline */
/*
    Current state of block (temporary)
*/
#define BF_START    64	    /* Move BSxxx instead of BExxx */
#define BF_ACTIVE   128     /* Block is currently beeing marked (values of
			       block may change) */

/* Result of lineflags(line): */
#define LINE_ABOVE	1	/* line < Ep->Topline */
#define LINE_VISIBLE	2	/* line >= Ep->Topline && line < Ep->Topline + Rows */
#define LINE_BELOW	4	/* line >= Ep->Topline + Rows */

/* Where in the block am I actually ?

   BP_INSIDE+BP_START	- Inside 1. line of block
   BP_START		- In the same line in which block starts but not inside
			  block.
   BP_START+END+INSIDE	- I am in the only line the block has.
   BP_START+BP_END	- dito but not INSIDE the block
*/
#define BP_OUTSIDE	    0
#define BP_INSIDE	    1	    /* Inside block (anywhere) */
#define BP_START	    2	    /* line == BSline */
#define BP_END		    4	    /* line == BEline */


typedef struct
{
    ED	 * ep;		    /* the editor the block is in */
    USHORT type;	    /* BT_xxx */
    USHORT flags;
    Line   start_line;	    /* start- and endline */
    Line   end_line;
    Column start_column;    /* start- and endcolumn */
    Column end_column;
} Block;


struct TextMarker
{
    ED	 * ep;		    /* The editor the marker is for */
    Line   line;	    /* line and column */
    Column column;
};


/* Macros */

#define redraw_textline(line)  redraw_textlineseg(line,Ep->topcolumn,Ep->topcolumn+Columns)


/**************************************
	       Prototypes
**************************************/


#endif /* GLOBAL_H */

/******************************************************************************
*****  ENDE global.h
******************************************************************************/
