/*  GadTools layout toolkit
**
**  Copyright © 1993-1995 by Olaf `Olsen' Barthel
**  Freely distributable.
*/

#include "gtlayout_global.h"

#ifdef DO_HEXHOOK
ULONG __asm __saveds
LTP_HexEditRoutine(register __a0 struct Hook *hook,register __a2 struct SGWork *sgw,register __a1 ULONG *msg)
{
	ULONG result = FALSE;

	if(*msg == SGH_KEY)
	{
		BOOLEAN 	 activate	= TRUE;
		LayoutHandle	*handle 	= hook -> h_Data;
		ObjectNode	*node;

		if(sgw -> IEvent -> ie_Code == 0x5F && handle -> HelpHook)
		{
			sgw -> Code	= 0x5F;
			sgw -> Actions	= (sgw -> Actions & ~SGA_BEEP) | SGA_END | SGA_USE;

			LTP_AddHistory(sgw);

			return(TRUE);
		}

		if(sgw -> IEvent -> ie_Code == CURSORUP || sgw -> IEvent -> ie_Code == CURSORDOWN)
			LTP_HandleHistory(sgw);

		if(GETOBJECT(sgw -> Gadget,node))
		{
			if(node -> Type == INTEGER_KIND)
			{
				if(node -> Special . Integer . LastGadget)
					activate = FALSE;

				result = TRUE;

				if(!LTP_ConvertNum((node -> Min < 0),sgw -> WorkBuffer,(LONG *)&sgw -> StringInfo -> LongInt))
				{
					sgw -> EditOp	= EO_BADFORMAT;
					sgw -> Actions	= SGA_BEEP;
				}
			}
		}

		if(sgw -> EditOp == EO_ENTER && !(sgw -> IEvent -> ie_Qualifier & QUALIFIER_SHIFT))
		{
			if(activate && handle -> AutoActivate)
				sgw -> Actions |= SGA_NEXTACTIVE;

			if(!(sgw -> Actions & SGA_NEXTACTIVE))
				sgw -> Code = '\r';
		}

		if(sgw -> Actions & SGA_END)
			LTP_AddHistory(sgw);
	}

	return(result);
}
#endif
