#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>


//put additional include files here

//put your own support static functions here

static void init(MarkerInfo& mi)
{
	vector vx, vy;

	// example with 5 markers
	#define	MARKER_COUNT	5
	
	vx.SetSize(MARKER_COUNT);
	vy.SetSize(MARKER_COUNT);
	
	for(int ii=0; ii<MARKER_COUNT; ii++)
	{
		// if marker follows parent:
		//    vx is 1st dimension index (data point index for plot)
		//    vy is 2nd dimension index (maybe used for surface later)
		vx[ii] = ii;
		vy[ii] = 0;
	}
	
	mi.SetWidth(0);
	mi.SetFollowsParent();
	
	TreeNode tr = mi;
	tr.Data.X.dVals = vx;
	tr.Data.Y.dVals = vy;
}



int dm(MarkerInfo& mi, EventInfo& ei)
{
	int iRet = 0;
	
	switch( ei.GetEvent() )
	{
	case OE_INIT_ANCHORS:
		init(mi);
		iRet = OCD_MODIFY|OCD_REPAINT;
		break;
		
	case OE_GRAPHOBJ_EDIT:
		if( ei.GetSenderId() == mi.GetID() )
		{
			out_int("edit: param = ", ei.GetSenderParam());
		}
		break;
		
	case OE_GRAPHOBJ_EDITING:
		if( ei.GetSenderId() == mi.GetID() )
		{
			out_int("editing: param = ", ei.GetSenderParam());
		}
		break;
	
	case OE_MOVE:
		if( ei.GetSenderId() == mi.GetID() )
		{
			out_int("move: param = ", ei.GetSenderParam());
		}
		break;
		
	case OE_MOVING:
		if( ei.GetSenderId() == mi.GetID() )
		{
			out_int("moving: param = ", ei.GetSenderParam());
		}
		break;
		
	case OE_KEYDOWN:
		printf("key down: anchorID=%d, senderparam=%d, wparam=%d, lparam=%d\n", ei.GetSenderId(), ei.GetSenderParam(), ei.wParam.nVal, ei.lParam.nVal);
		break;
		
	case OE_KEYUP:
		printf("key up: anchorID=%d, senderparam=%d, wparam=%d, lparam=%d\n", ei.GetSenderId(), ei.GetSenderParam(), ei.wParam.nVal, ei.lParam.nVal);
		break;
	}
	
	return iRet;	
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int dm_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return dm_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int dm_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void dm_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int dm_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
