/*
\\		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	DUMAUX_COOKIE	MAKE_ID('D','A','U','X')	/* A fake auxbuffer (e.g. curr buffer) */

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


/*	\/ \/ \/		Data private to class/objects */

	#ifdef EDITORCLASS

	#define	EDITOR_VERSION		1		/* Value returned on version query */
	#define	EDITOR_REVISION	12		/*   ""		""		""	revision	""	  */

	#define	LOADBUFFERSIZE		16384	/*	Buffers used for loading/saving */
	#define	SAVEBUFFERSIZE		32768

struct ClassData {		/* Instance data for each object */
	Object *obj;
	ULONG cookie;
	APTR linepool;
	struct MinList linelist;
	LONG lines, linesvisible, colsvisible;
	UBYTE textcol, backcol, seltextcol, selbackcol, curstextcol, cursbackcol;
	struct MUI_PenSpec textspec, backspec, seltextspec;
	struct MUI_PenSpec selbackspec, curstextspec, cursbackspec;
	LONG oldy, curry, currx, topvisy, topvisx, oldvisy, scany;
	LONG marky, markx, idealx, clickcolumn;
	ULONG topdrawny, buffersize, lastcode, quietcount, syssetcount;
	struct linedata *topvisloc, *currline, *scanloc;
	UWORD tabsize, markmode;
	struct TextFont *font;
	struct TextAttr *suppliedfont;
	UBYTE linebuffer[1024];
	UBYTE kludge, lineflags;
	UBYTE *expandbuff;
	ULONG flags, doublesecs, doublemicros, triplesecs, triplemicros;
	struct RastPort rp;
	struct TmpRas rptmpras;
	struct Hook *tabhook, *inputhook, *renderhook;
	UBYTE *debugname;
	ULONG debugnest;
};

	#define	DRAWLINE			(1<<0)	/* If set, redraw 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 */
	#define	SHOW				(1<<17)	/* Object is between show/hide */
	#define	RENDEROK			(1<<18)	/* Bitmap & TmpRas are Allocated */
	#define	OVERWRITE		(1<<19)	/* If set, overwrite mode */
	#define	TSPEC				(1<<21)	/* If set, a text spec is being used */
	#define	BSPEC				(1<<22)	/*		""		 back		""		""			 */
	#define	STSPEC			(1<<23)	/*		""		 selected text	""			 */
	#define	SBSPEC			(1<<24)	/*		""		 selected back	""			 */
	#define	CTSPEC			(1<<25)	/*		""		 cursor text	""			 */
	#define	CBSPEC			(1<<26)	/*		""		 cursor back	""			 */
	#define	READONLY			(1<<27)	/* If set, editor is read only */
	#define	DRAWCHANGED		(1<<28)	/* If set, draw any changed lines */

struct readdata {		/* Used by load functions */
	APTR handle, buffer;
	UBYTE *linebuff, *buffpos;
	ULONG buffsize, bytesleft, bytesread;
	UWORD mode;
	Object *obj;
	struct Hook *hook;
};

	#include <EditorClass/Support_protos.h>
	#include <EditorClass/Input_protos.h>
	#include <EditorClass/Editor_protos.h>
	#include <EditorClass/Methods_protos.h>
	#include <EditorClass/Draw_protos.h>
	#include <EditorClass/Hook_protos.h>
	#include <EditorClass/Disk_protos.h>
	#include <proto/customlib.h>

	#endif	/* EDITORCLASS */

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

struct auxbuffer {	/* Detached buffers use this struct... */
	ULONG cookie;
	APTR poolheader;				/* ...this is IN the memory pool! */
	struct MinList linelist;
	ULONG lines, curry, currx, marky, markx, topvisy, topvisx, flags;
};

	#define	LINE_REDRAW		1		/* Line must be redrawn */
	#define	LINE_NOMARK		2		/* Line can't be marked (or copied/deleted) */
	#define	LINE_NOEDIT		4		/* Line can't be edited (or merged) */

struct linedata {		/* Each individual line... */
	struct MinNode node;
	UWORD	len;						/* Length of line */
	UBYTE flags;					/* Line specific flags */
	UBYTE data[1];					/* Actual string (NULL terminated - NULL is not counted in length) */
};

enum editortags {
	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_ReadOnly,		/* ISG TRUE if you want to lock editor */
	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 */
	MUIA_Editor_Debug,			/* IS. Set to name of debug log, or NULL */
	MUIA_Editor_OverWrite,		/* ISG TRUE if overwrite mode is active */
	MUIA_Editor_TripleClick,	/* ... Becomes true on triple mouse click */
	MUIA_Editor_MarkMode,		/* ISG System used for marking */
	MUIA_Editor_TextSpec,		/* ISG PenSpec for text colour */
	MUIA_Editor_BackSpec,		/* ISG PenSpec for background colour */
	MUIA_Editor_SelTextSpec,	/* ISG PenSpec for selected text */
	MUIA_Editor_SelBackSpec,	/* ISG PenSpec for selected background */
	MUIA_Editor_CursTextSpec,	/* ISG PenSpec for cursor text */
	MUIA_Editor_CursBackSpec,	/* ISG PenSpec for cursor background */
	MUIA_Editor_MemSaveSize,	/* ..G Size needed for a save to memory */

	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 */
	MUIM_Editor_GetAux,			/* Get a (dummy) auxbuffer for current buffer */
};

	#define LOADMODE_ASCII	0	/* Load/Save as ascii (raw) */
	#define LOADMODE_FTXT	1	/* Load/Save as IFF FTXT */
	#define LOADMODE_MEM		2	/* Load/Save direct to memory */
	#define LF_LOADMODE		3	/* Mask for loadmode */
	#define LF_HOOK			4	/*	Calls supplied hook every 32768 bytes/32 lines */
	#define LF_NOCLEAR		8	/* Don't clear before loading (i.e. merge) */

	#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 SMODE_USECURR	8	/* Include current cursor pos in search */

	#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

	#define MUIV_Editor_Mark_None				0		/* Modes used for marking */
	#define MUIV_Editor_Mark_DoubleClick	1
	#define MUIV_Editor_Mark_Drag				2

struct importmsg {	/* Message format for MUIM_Editor_Import/Export */
	ULONG MethodID;
	BPTR filehandle;
	ULONG flags;
	struct Hook *proghook;
};
struct adjustmsg {	/* Message format for replace/insert/delete */
	ULONG MethodID;
	ULONG x, y;
	ULONG size;
	UBYTE *string;		/* Only for insert (?) */
};
struct getlinemsg {	/* Message format for getline */
	ULONG MethodID;
	ULONG line;
};
struct cutpastemsg {	/* Message format for cut/copy/paste */
	ULONG MethodID;
	ULONG clipnum;
	ULONG flags;		/* Only for cut/paste */
};
struct searchmsg {	/* Message format for search */
	ULONG MethodID;
	UBYTE *pattern;
	ULONG flags;
	ULONG *xpos, *ypos;
};
struct addlinemsg {	/* Message format for add/remove line */
	ULONG MethodID;
	ULONG line;
	UBYTE *string;		/* Only for... */
	ULONG length;		/* ...addline */
};
struct swapbuffmsg {	/* Message format for get/swap/kill buffer */
	ULONG MethodID;
	struct auxbuffer *buff;		/* In swap: if null, create new */
};										/* In kill: if null, do nothing */
struct importauxmsg { /* Message format for import/export detached buffer */
	ULONG MethodID;
	struct auxbuffer *buff;
	BPTR filehandle;
	ULONG flags;
	struct Hook *proghook;
};

/* A custom input message: */

	#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 {		/* The message passed to the custom tab hook */
	ULONG currx;
};

struct inputmsg {		/* The message passed to the custom input hook */
	ULONG defaction;
	struct IntuiMessage *imsg;
};

struct rendermsg {	/* The message passed to the custom render hook */
	struct RastPort *rp;
	struct TextFont *tf;
	UBYTE *string;
	LONG strlen, curspos, markmin, markmax, linelen, xsize;
	UBYTE textcol, backcol, marktextcol, markbackcol, curstextcol, cursbackcol;
};
