#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here

//put your own support static functions here

#define	CONVERT_ROW_INDEX(_nR)					_nR = LABEL_INDEX_TO_NEGATIVE_ROW(vnLabelTypes[_nR+ nTypesSize])


void get_wks_sel(string& str, const string& sep, const Worksheet& wks)
{
	if ( !wks )
		XF_THROW(CER_INVALID_WKS);
	
	str.Empty();
		
	Grid		grid;
	grid.Attach(wks);	
	vector<int> vR1, vC1, vR2, vC2;
	int			nSel = 0;
	if ( (nSel = grid.GetSelection(vR1, vC1, vR2, vC2, TRUE)) > 0 )
	{
		vector<int>	vnLabelTypes;
		int			nTypesSize = 0;
		vector<string>	vs(nSel);
		
		for ( int ii=0; ii<nSel; ++ii )
		{
			string	strC1 = vC1[ii] + 1;
			string	strC2 = vC2[ii] + 1;
			if ( 0 == vC1[ii] && -1 == vC2[ii] )
			{
				strC1.Empty();
				strC2.Empty();
			}
			
			int		nR1 = vR1[ii];
			int		nR2 = vR2[ii];
			if ( vR1[ii] < 0 )
			{
				ASSERT(vR2[ii] < 0);
				if ( 0 == nTypesSize )
				{					
					grid.GetShowLabels(vnLabelTypes);
					nTypesSize = vnLabelTypes.GetSize();
				}
				
				CONVERT_ROW_INDEX(nR1);
				CONVERT_ROW_INDEX(nR2);
			}			
			++nR1;
			++nR2;
			
			string		strTemp;
			okutil_create_range_string(&strTemp, strC1, &nR1, strC2, &nR2);
			vs[ii].Format("%s!%s", wks.m_strBookSheet, strTemp);
		}
		
		ocu_set_tokens_by_str(&str, &vs, sep);
	}
}

//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 get_wks_sel_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return get_wks_sel_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

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