/*	TEditCore.h
 *
 *		This contains the editing core for editing the text inside of
 *	a handle. This knows how to segment the handle into lines, to
 *	get and fetch those lines, and to update when text is inserted or
 *	deleted.
 *
 *		This is a primitive replacement for the TextEdit engine in the
 *	Macintosh OS
 *
 *		Note that I use the '\n' character as the EOL character.
 */

/*  XT - An example text editor application built with the YAAF library
 *
 *	PUBLIC DOMAIN: The source kit of 'xt' has been placed into the
 *	public domain by the author, William Edward Woody, on the hope
 *	that the source kit will provide a useful example of using the
 *	YAAF Library.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#ifndef PandaWave_TEDITCORE
#define PandaWave_TEDITCORE

#include <XHandle.h>

/************************************************************************/
/*																		*/
/*	Class Declaration													*/
/*																		*/
/************************************************************************/

/*	TEditCore
 *
 *		The edit core; this only knows how to insert and delete data
 *	but doesn't know how to display
 */

class TEditCore {
	public:
								TEditCore();
								~TEditCore();
		
		/*
		 *	Handle access.
		 */
		
		XGHandle				*GetHandle()
									{
										return fText;
									}
		void					SetHandle(XGHandle *text)
									{
										fText = text;
										UpdateHandle();
									}
		void					UpdateHandle();
		
		/*
		 *	Line access
		 */
		
		unsigned long			GetNumLines();
		unsigned long			GetLineOffset(unsigned long);
		unsigned long			GetLineLength(unsigned long);
		
		/*
		 *	Hit detect support
		 */
		
		unsigned long			CharToLine(unsigned long);
		
		/*
		 *	Selection support
		 */
		
		void					GetSelect(unsigned long *, unsigned long *);
		void					SetSelect(unsigned long, unsigned long);
		
		/*
		 *	Keyboard manipulation
		 */
		
		void					InsertChar(char);
		void					DeleteChar();

		/*
		 *	Cut/copy/paste/clear
		 */
		
		void					CutText(XGHandle &);
		void					CopyText(XGHandle &);
		void					PasteText(XGHandle &);
		void					ClearText(void);
		
	private:
		void					Insert(unsigned long,unsigned long,char *);
		void					Delete(unsigned long,unsigned long);

		unsigned long			fStart;
		unsigned long			fEnd;
		XGHandle				*fText;
		XGHandle				fStarts;
};


#endif // PandaWave_TEDITCORE
