#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	mask_unmask,
	mask_mask,
};
#include <event_utils.h>
#include <..\originlab\XFunctionEx.h>
/// Jake 04/25/07 CREATE_THIS_XF_TO_MASK_THE_DATA_EACH_CELL
/// Jake 05/08/07 DEGUB_FOR_COL_AND_ROW_SELECTION
/// Max 1/28/08 ADD_UNMASK

///Jake 06/06/07 MODIFY_TO_COMMON_MASK_FOR_RANGE
/* 
#define		EQUAL(a,b)	abs((a)-(b)) <	1e-6

enum{
	_CONDITION_EQUAL = 0,
	_CONDITION_LESSTHAN,
	_CONDITION_LESSTHAN_EQUAL,
	_CONDITION_GREATER,
	_CONDITION_GREATER_EQUAL,
	_CONDITION_LESSTHAN_GREATER,
};

void _select_rows_in_col(Worksheet& wks,vector<uint>& vnRowIndices,int r1,int r2,int col, double val,int condition)
{
	Column cc(wks, col);
	vector<double> vData = cc.GetDataObject();
	//----Jake 05/08/07 DEGUB_FOR_COL_AND_ROW_SELECTION
	if ( -1 == r2 )
		r2 = vData.GetSize() -1;
	for(int nr = r1; nr <= r2 && nr < vData.GetSize(); nr++){
		switch (condition)
		{
		case _CONDITION_EQUAL : 
			if(EQUAL(vData[nr], val))
				vnRowIndices.Add(nr);
			break;
		case _CONDITION_LESSTHAN : 
			if(vData[nr] < val)
				vnRowIndices.Add(nr);
			break;
		case _CONDITION_LESSTHAN_EQUAL : 
			if(vData[nr] <= val)
				vnRowIndices.Add(nr);
			break;
		case _CONDITION_GREATER : 
			if(vData[nr] > val)
				vnRowIndices.Add(nr);
			break;
		case _CONDITION_GREATER_EQUAL : 
			if(vData[nr] >= val)
				vnRowIndices.Add(nr);
			break;
	    case _CONDITION_LESSTHAN_GREATER :
	    	if(vData[nr] != val)
	    		vnRowIndices.Add(nr);
	    	break;
		default:
			break;
		}
	}
}
    //end DEGUB_FOR_COL_AND_ROW_SELECTION

void _set_cell_mask(vector<uint> vnRowIndices, Worksheet& wks, int r1, int r2, int col)
{
	vector<uint> vuBegin, vuEnd;
	int nRange = find_contiguous_range(vnRowIndices, vuBegin, vuEnd);
	for(int ii = 0;ii < vuBegin.GetSize();ii++){
		string script = "worksheet -s " + (col+1) + " " + (vuBegin[ii]+1) + " " + (col+1) + " " + (vuEnd[ii]+1) + ";";
		script += "mark -w1;";
		wks.LT_execute(script);
	}
}
*/
///end MODIFY_TO_COMMON_MASK_FOR_RANGE

void wcellmask(const Range& irng, const int& mask)
{
	//int r1, c1, r2, c2;
	////vector<string> vsSigns = {"==", "<", "<=", ">", ">=", "!="};
	//Worksheet wksTemp;
	//int nNumData;
	//if(irng)
		//nNumData= irng.GetNumData();
	//for(int nSubRange = 0; nSubRange < nNumData; nSubRange++)
	//{
		//irng.GetRange(nSubRange, r1, c1, r2, c2, wksTemp);
		//if(-1 == c2) 
			//c2 = wksTemp.GetNumCols() - 1;//----Jake 05/08/07 DEGUB_FOR_COL_AND_ROW_SELECTION
		////for(int nc = c1; nc <= c2; nc++)
		////{
			////vector<uint> vnRowIndices;
			////_select_rows_in_col(wksTemp, vnRowIndices, r1, r2, nc, val,condition);
			////_set_cell_mask(vnRowIndices, wksTemp, r1, r2, nc);
		////}
		//string strScript = "worksheet -s " + (c1+1) + " " + (r1+1) + " " + (c2+1) + " " + (r2+1) + ";";
		///// Max 1/28/08 ADD_UNMASK
		////strScript += "mark -w1;";
		//if(mask)
		//{
			//strScript += "mark -w1;";
		//}
		//else
		//{	
			//strScript += "mark -wd;";
		//}
		///// END ADD_UNMASK
		//wksTemp.LT_execute(strScript);
	//}
	irng.SetMask(mask);
}

//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 wcellmask_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return wcellmask_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	///Jake 06/06/07 ADD_ERROR_CHECKING 
	Range rRange;
	TreeNode tr = trGetN.irng;
	okxf_resolve_tree_construct_range(&tr,&rRange);
	int nNumData= rRange.GetNumData();
	if(0 == nNumData)
	{
		strErrMsg = XFERR_NO_RANGE_SELECTED;
		bOKEnable = false;
	}
	///end ADD_ERROR_CHECKING
	return true;
	

}

int wcellmask_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 wcellmask_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 wcellmask_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
