/* Example Event CPX Skeleton */

#include <TOS.H>
#include "skel.h"
#include "skel.rsh"

CPXINFO *cpx_init();
BOOLEAN cpx_call();
void cpx_draw(), cpx_wmove(), cpx_key();

XCPB *xcpb;
CPXINFO cpxinfo;

CPXINFO
*cpx_init( Xcpb )
XCPB *Xcpb;
{
	xcpb = Xcpb;

	appl_init();

	if(xcpb->booting)
	{

		/* CPX's that do boot-time initialization do it here */

		/* Returning TRUE here tells XCONTROL to retain the header
		 * for later access by the user. If CPX is Set-Only,
		 * return FALSE.
		 */
	
		return ( (CPXINFO *) TRUE )
	} 
	else
	{
		/* If you haven't already done so, fix resource tree.
		 *
		 * DEFINE's and variables are from RSH file generated
		 * by the Atari Resource Construction Set.
		 */

		if(!SkipRshFix)
			(*xcpb->rsh_fix)( NUM_OBS, NUM_FRSTR, NUM_FRIMG,	NUM_TREE, rs_object, 	
				rs_tedinfo, rs_strings, rs_iconblk, rs_bitblk, rs_frstr, rs_frimg, 	
				rs_trindex, rs_imdope );

		cpxinfo.cpx_call = cpx_call;
		cpxinfo.cpx_draw = cpx_draw;
		cpxinfo.cpx_wmove = cpx_wmove;
		cpxinfo.cpx_timer = NULL;
		cpxinfo.cpx_key = cpx_key;
		cpxinfo.cpx_button = NULL;
		cpxinfo.cpx_m1 = NULL;
		cpxinfo.cpx_m2 = NULL;
		cpxinfo.cpx_hook = NULL;
		cpxinfo.cpx_close = NULL;

		/* Tell XCONTROL to send generic and keyboard
		 * messages.
		 */

		(*xcpb->Set_Evnt_Mask)( MU_MESAG | MU_KEYBD, NULL, NULL, -1L );

		return ( &cpxinfo );
	}
}

BOOLEAN
cpx_call( rect )
GRECT *rect;
{
	/* Put MAINFORM tree in *tree for object macros */

	OBJECT *tree = (OBJECT *)rs_trindex[ MAINFORM ];

	ObX( ROOT ) = rect->g_x;
	ObY( ROOT ) = rect->g_y;

	objc_draw( tree, ROOT, MAX_DEPTH, PTRS( rect ) );

	return ( TRUE );
}

VOID
cpx_draw( rect )
GRECT *rect;
{
	OBJECT *tree = (OBJECT *)rs_trindex[ MAINFORM ];
	GRECT *xrect, rect;

	xrect = (*xcpb->GetFirstRect)( rect );

	while( xrect )
	{
		rect = *xrect;
		objc_draw( tree, ROOT, MAX_DEPTH, ELTS( rect ) );
		xrect = (*xcpb->GetNextRect)();
	}
}

VOID
cpx_wmove( work )
GRECT *work;
{
	OBJECT *tree = (OBJECT *)rs_trindex[ MAINFORM ];

	ObX( tree ) = work->g_x;
	ObY( tree ) = work->g_y;
}

VOID
cpx_key( kstate, key, quit )
WORD kstate, key;
WORD *quit;
{
	/* Substitute case values for values you’re interested
	 * in.
	 */

	switch( key )
	{
		case KEY_1:
		case KEY_2:
	}
}

