#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	label_no,
	label_ln,
	label_u,
	label_c,
	label_p1,
	label_p2,
	label_d1,
	label_d2,
};
//put additional include files here

//--------- modification log -------------------------
//CPY 11/22/08, changed all the label_* to be shorter
//---------


static int _check_input_worksheet(TreeNode& trGetN)
{
	Worksheet wks;
	okxf_resolve_string_get_origin_object(trGetN.w.strVal, &wks);

	if(!wks)
		return CER_INVALID_WKS;
	if(wks.GetNumCols()<=0)
		return XFERR_WKS_IS_EMPTY;
	return CER_NO_ERROR;
}



void wmvsn(Worksheet& w, const string& prefix, const string& hint, const int& label, const int& undo)
{
	if(!w)
		XF_THROW(XFERR_INVALID_ARG);
	int nLabelType;
	switch(label)
	{
	case label_ln:
		nLabelType = RCLT_LONG_NAME;
		break;
	case label_u:
		nLabelType = RCLT_UNIT;
		break;
	case label_c:
		nLabelType = RCLT_COMMENT;
		break;
	case label_p1:
		nLabelType = RCLT_PARAM;
		break;
	case label_p2:
		nLabelType = RCLT_PARAM + 1;
		break;
	case label_d1:
		nLabelType = RCLT_UDL;
		break;
	case label_d2:
		nLabelType = RCLT_UDL + 1;
		break;
	default:
		nLabelType = RCLT_INVALID;
	}
	int nRet = w.MoveShortNames(prefix, undo, NULL, nLabelType);
	if(nRet < 0)
	{
		string strErrMsg;
		if(nRet == -2)		// short name too long
		{
			//--- CPY 11/22/08
			//string strErrMsg = _L("Failed, length of short name overflows, prefix to long or the Worksheet has too many columns");
			//Project.OutStringToResultsLog(strErrMsg);
			string strErrMsg = _L("Length of short name overflows, try using a shorter prefix or use default");
			warning_msg_box(strErrMsg, false);
			//---
		}
		else
			XF_THROW(CER_UNKNOWN_ERROR);
	}
}

//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 wmvsn_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return wmvsn_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	int nErr = _check_input_worksheet(trGetN);
	if(nErr)
	{
		strErrMsg = nErr;
		bOKEnable = false;
	}
	return false;

}

int wmvsn_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 wmvsn_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if(nGetNDialog == 0 && !(dwCntrl & LTXF_SHOW_DIALOG))	// xf startup and without dialog
	{
		if(CER_NO_ERROR != _check_input_worksheet(trGetN))
			nRet = XFEVT_ABORT;
	}
}
//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 wmvsn_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
