#include "Hex Editor.h"

/*!
 *	@header			HexWindow
 *	@discussion		This is my data structure for saving all data which pertains to one editing session. Each window has one and only one associated HexWindow class.
 */

/*!
 *	@class			HexWindow
 *	@abstract		Stors data pertinanet to a window.
 *	@discussion		This class is stored in the refcon of the window, and contains all the methods necessary to maintain the window's groovy looks :-)
 */

typedef class HexWindow
{
/*!	@var window			Stores the Mac OS <tt>WindowRef</tt> pertaining to this window.	*/
	WindowRef			window;
/*!	@var header			Header control (the grey bar at the top of the window).	*/
	ControlRef			header;
/*!	@var left			Left hand side static text control (in the header).	*/
	ControlRef			left;
/*!	@var right			Right hand side static text control (in the header).	*/
	ControlRef			right;
/*!	@var scrollbar		Scroll bar down the right hand side	*/
	ControlRef			scrollbar;
#if !TARGET_API_MAC_CARBON
/*!	@var themeSavvy		True if this window is using an Appearance Manager WDEF. (Also used to determine if Appearance controls should be drawn if this window.)	*/
	Boolean				themeSavvy;
#endif
	
public:	// all these variables should be private
	// non-controls version
/*!	@var hexRect		The text well in which hexadecimal is drawn	*/
	Rect				hexRect;
/*!	@var asciiRect		The text well in which ASCII is drawn	*/
	Rect				asciiRect;
/*!	@var selStart		offset of first char of selection	*/
	UInt32				selStart;
/*!	@var selEnd			if selEnd == selStart, no selection exists	*/
	UInt32				selEnd;
/*!	@var timer			blinks the insertion point	*/
	EventLoopTimerRef	timer;
	
	Handle				data;
	Boolean				editingHex;		// currently editing in hexadecimal?
	Boolean				editedHigh;		// already typed part of this char
	Boolean				activeWindow;	// is this window the user focus?
	Boolean				insertionPointVisable;
	SInt8				hexChar;		// the data currently being typed
	
	UInt32				firstline;		// first line of valid data
	UInt32				lastline;		// last line of valid data
	UInt32				topline;		// line at top of screen
	UInt32				bottomline;		// line at bottom of screen
	
public:	
	// methods
						HexWindow( WindowRef newWindow = null );
						~HexWindow( void );
	// events
/*!
 *	@function			BoundsChanging
 */
	OSStatus			BoundsChanging( EventRef event );
/*!
 *	@function			BoundsChanged
 */
	OSStatus			BoundsChanged( EventRef event );
/*!
 *	@function			ContentClick
 */
	OSStatus			ContentClick( EventRef event );
/*!
 *	@function			DrawContent
 */
	OSStatus			DrawContent( EventRef event = null );
/*!
 *	@function			UpdateHexInfo
 */
	OSStatus			UpdateHexInfo( void );
/*!
 *	@function			InsertBytes
 */
	Boolean				InsertBytes( void *data, signed long length, unsigned long offset );
	friend OSStatus		Plug_InitInstance( Plug_PlugInRef plug, Plug_ResourceRef resource );
}	HexWindow,			*HexWindowPtr;