#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here
#include <GetNBox.h>
#include <..\originlab\theme_utils.h> ///---Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
#include <..\originlab\fu_utils.h>
#include <..\originlab\import_utils.h> 
#include <..\originlab\XFunctionEx.h> 
#include <..\originlab\JCAMPfile.h>

//put your own support static functions here
///////////////////////////////////////////////////////////////////////
//////// modification log
/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
/// Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
/// Sim 06-25-2007 UPDATE_ORGANIZER
/// Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
/// Hong 07/16/08 v8.0902c FIX_JCAMP_IMPORT_FAIL_AVOID_DUPLICATE_SHEEET_NAME
/// Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
///////////////////////////////////////////////////////////////////////

//enum {
	//IML_REPLACE = 0, // ASCIMP_MODE_REPLACE_DATA,
	//IML_NEW_BK, // ASCIMP_MODE_NEW_BOOKS,
	//IML_NEW_SHT, // ASCIMP_MODE_NEW_SHEETS,
//};

static bool s_bFileValid = true;
static bool s_bRangeValid = true;
#define OK_SURE(_OK_ENABLE) _OK_ENABLE = (s_bFileValid && s_bRangeValid);

/// Hong 10/18/07 v8.0728 REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE
#define JCAMP_1ST_FILE_IMPORT_MODE_LIST 	LIST_IMPORT_MODE_REPLACE_BOOK_SHEET_COLUMN
#define JCAMP_IMPORT_MODE_LIST	(JCAMP_1ST_FILE_IMPORT_MODE_LIST & (~IW_FLAG_IMPMODE_REPLACE))
/// end REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE

static void _shift_error_code(int& nRet)
{
	switch ( nRet )
	{
	case JCAMP_ERR_INVALID_FILE:
		nRet = IMPERR_INVALID_FILE;
		break;
	case JCAMP_ERR_INVALID_VAR_TYPR:
		nRet = IMPERR_JCAMP_INVALID_VAR_TYPR;
		break;
	case JCAMP_ERR_INVALID_DATA_TYPR:
		nRet = IMPERR_JCAMP_INVALID_DATA_TYPR;
		break;
	case JCAMP_ERR_UNSUPPORT_DATA:
		nRet = IMPERR_UNSUPPORT_VERSION;
		break;
	default:
		nRet = CER_UNKNOWN_ERROR;
	}
}

static BOOL _construct_tree_setting(StringArray& vsFileNames, TreeNode& trInfo)
{
	int nCount = vsFileNames.GetSize();
	string strFileName, strTag, strInfo;
	if ( trInfo )
		trInfo.RemoveChildrenWithPrefix();
	
	GETN_USE(trInfo)
	for ( int nIndex = 0; nIndex < nCount; nIndex++ )
	{
		strFileName = vsFileNames[nIndex];
		if ( !strFileName.IsFile() )
			return false;

		strTag.Format("file%d", nIndex+1);
		strInfo.Format("File Size: %s ", GetFileSize(strFileName));
		GETN_STR(strTag, GetFileName(strFileName, false), strInfo )
		GETN_READ_ONLY
	}
	return true;
}

static bool _file_name_event(TreeNode& trGetN, string& strErrMsg)
{
	string strFileName = trGetN.fname.strVal;
	TreeNode trNode = trGetN.trFiles;
	
	trNode.RemoveChildrenWithPrefix();
	
	if (!check_imported_file_name(strFileName, strErrMsg))
		return false;
	
	StringArray vsFileNames;
	separate_multiline_files(strFileName, vsFileNames);
	if ( !_construct_tree_setting(vsFileNames, trNode) )
	{
		// clean the trFiles on GUI
		trNode.RemoveChildrenWithPrefix();
		strErrMsg = CER_INVALID_IMPORT_DATA_FILE;
		return false;
	}
	
	return true;
}

static void _prepare_tree_info(TreeNode& trInfo, TreeNode& trData)
{
	//trInfo.RemoveChild("XUNITS");
	//trInfo.RemoveChild("YUNITS");
	//trInfo.RemoveChild("XLABEL");
	//trInfo.RemoveChild("YLABEL");
	//trInfo.RemoveChild("XFACTOR");
	//trInfo.RemoveChild("YFACTOR");
	trInfo.RemoveChild("FIRSTX");
	trInfo.RemoveChild("LASTX");
	while(trInfo.RemoveChild("NPOINTS"));
	trInfo.RemoveChild("FIRSTY");
	trInfo.RemoveChild("MAXX");
	trInfo.RemoveChild("MINX");
	trInfo.RemoveChild("MAXY");
	trInfo.RemoveChild("MINY");
	//trInfo.RemoveChild("RUNITS");
	//trInfo.RemoveChild("AUNITS");
	trInfo.RemoveChild("FIRSTR");
	trInfo.RemoveChild("LASTR");
	trInfo.RemoveChild("MAXA");
	trInfo.RemoveChild("MINA");
	//trInfo.RemoveChild("RFACTOR");
	//trInfo.RemoveChild("AFACTOR");
	trInfo.RemoveChild("FIRSTR");
//	trInfo.RemoveChild("ALIAS");
//	trInfo.RemoveChild("ZPD");
	trInfo.RemoveChild("VARNAME");	
	while(trInfo.RemoveChild("SYMBOL"));
	trInfo.RemoveChild("VARTYPE");
	trInfo.RemoveChild("VARFORM");
	trInfo.RemoveChild("VARDIM");
	trInfo.RemoveChild("UNITS");
	trInfo.RemoveChild("FIRST");
	trInfo.RemoveChild("LAST");
	trInfo.RemoveChild("MIN");
	trInfo.RemoveChild("MAX");	
	trInfo.RemoveChild("FACTOR");
	while(trInfo.RemoveChild("PAGE"));
	trInfo.RemoveChild("DELTAX");
	
	string strVarType = trData.FirstNode.tagName;
	while(trInfo.RemoveChild(strVarType));
}


void impJCAMP(const string& fname, const TreeNode& trFiles, const TreeNode& options, Range& orng, TreeNode& finfo)
{
	Worksheet wks;	
	int c1,c2;	
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//orng.GetRange(wks, c1, c2);
	WorksheetPage wp;
	if ( !GetRangeInfo(orng, wks, wp, c1, c2) )
		XF_THROW(XFERR_INVALID_RANGE);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	if(!wks)
		XF_THROW(CER_INVALID_WKS);
	
	///---Sim 03-09-2007 TEMP_FIX_HIGHLINE_REPLACE_DATA	
	/// Hong 09/08/07 v8.0698b FIX_FAIL_DUMP_OUTPUT_RANGE_ORNG
	/*
	if ( orng )
	{
		orng.Reset();
		orng.Add(wks, 0);
	}
	*/
	reset_range_to_first_obj(orng, wks);
	/// end FIX_FAIL_DUMP_OUTPUT_RANGE_ORNG
	///---END TEMP_FIX_HIGHLINE_REPLACE_DATA
	
	/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
	Tree trBaseInfo;
	//if( finfo )
		//trInfo = finfo;
	/// end FINFO_IS_ONLY_OUTPUT
	
	//int nListIndexToImportMode[] = {
		//ASCIMP_MODE_REPLACE_DATA,
		//ASCIMP_MODE_NEW_BOOKS,
		//ASCIMP_MODE_NEW_SHEETS
	//};
	//int nFileImportMode = ASCIMP_MODE_NEW_SHEETS;
	//if( 0 <= impmode && impmode < (sizeof(nListIndexToImportMode) / sizeof(int)) )
		//nFileImportMode = nListIndexToImportMode[impmode];
	//int nFileImportMode = _GetImportModeFromListIndex(impmode + 1); // Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
			
	//support default filter is empty
	TreeNode tnUsingFilter;
	double dDefault = 0.;
	/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
	//if ( fuGetDouble(trFilter, IDE_DISP_IMP_ORIGINVER, dDefault) )
	//	tnUsingFilter = trFilter;
	if ( fuGetDouble(options, IDE_DISP_IMP_ORIGINVER, dDefault) )
		tnUsingFilter = options;
	
	int nFileImportMode = fuGetImportMode(tnUsingFilter);
	/// end ADD_OPTION_TREE_FOR_MAKE_FILTER
	
		
	int nRet, nCols;
	/// Hong 03/28/07 v8.0591 CENTRALIZE_CHECK_CALID_RANGE
	//WorksheetPage wp;
	//wks.GetParent(wp);
	/// end CENTRALIZE_CHECK_CALID_RANGE
	StringArray vsFileNames;
	separate_multiline_files(fname, vsFileNames);
	
	///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
	/*
	XFunction xfSparkLine;
	TreeNode trXFSparkLine;
	
	/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
	bool bSparkLines = fuGetSparkLine(tnUsingFilter);
	/// end ADD_OPTION_TREE_FOR_MAKE_FILTER
	if ( bSparkLines )
	{
		if(!xfSparkLine.Load(&trXFSparkLine, "sparklines", 0, true, true, true))
		{
			XF_THROW(IMPERR_IMPORT_FUNC_ERR);
		}
		xfSparkLine.SetArg("sel", 0);
	}
	*/
	int nSparklines = fuGetSparkLine(tnUsingFilter);
	///---END SUPPORT_SMART_SPARKLINE
	
	int nFileCount = vsFileNames.GetSize();
	if ( nFileCount <= 0 )
		XF_THROW(CER_INVALID_IMPORT_DATA_FILE);
	
	int nIndexLayer = wks.GetIndex();
	Layer lyOlder;
	bool bNewLayer, bEmptyLayer;
	set_active_layer(wks);
	
	waitCursor wc; 
	for ( int ii = 0; ii < nFileCount; ii++ )
	{
		JCAMPFile jcampFile(vsFileNames[ii]);
		lyOlder = wp.Layers();
		/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
		/* remove temp code
		///---Sim 04-30-2007 TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		if ( 0 == ii )
		{
			int nImportMode = get_first_file_import_mode(FILE_TYPE_JCAMP);
			TreeNode trInValid;
			
			wks = GetTargetLayer(wp, nIndexLayer, ii, trInValid, true, orng, nImportMode, c1);
		}
		else
		{
			wks = GetTargetLayer(wp, nIndexLayer, ii, tnUsingFilter, true, orng, nFileImportMode, c1);
		}
		///---END TEMP_FIX_IMPORT_MODE_FOR_SINGLE_FILE
		*/		
		wks = GetTargetLayer(wp, nIndexLayer, ii, tnUsingFilter, true, orng, nFileImportMode, c1);
		/// end ADD_OPTION_TREE_FOR_MAKE_FILTER
		bNewLayer = !is_same_layer(lyOlder, wks); 
	
		Tree trFileInfo;
		/// Hong 07/16/08 v8.0902c FIX_JCAMP_IMPORT_FAIL_AVOID_DUPLICATE_SHEEET_NAME
		//nRet = jcampFile.Import(wks, trFileInfo, c1);
		nRet = jcampFile.Import(wks, trFileInfo, c1, 0);
		/// end FIX_JCAMP_IMPORT_FAIL_AVOID_DUPLICATE_SHEEET_NAME
		if(nRet == JCAMP_WARN_Y_VAL_CHECK_NOT_EQUAL)
		{
			warning_msg_box(IMPERR_JCAMP_WARN_Y_VAL_CHECK_NOT_EQUAL, false);
		}
		else if(nRet != JCAMP_NO_ERROR)
		{
			_shift_error_code(nRet);
			XF_THROW_EX(nRet, vsFileNames[ii]);
		}
		/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
		DataRange drImported;
		drImported.Add(wks, c1, STR_RANGE_STR, wks.GetNumCols() - 1);
		
		setPageAndLayerName(drImported, vsFileNames[ii], tnUsingFilter, 0);
		impinfo_UpdateExistingData(wp, drImported);
		
		Tree trDataRange;
		getRangeInfo(trDataRange, drImported);
		/// end ADD_OPTION_TREE_FOR_MAKE_FILTER
		
		bEmptyLayer = (1 == is_sheet_empty(wks)) ? true : false;
		if ( bNewLayer && bEmptyLayer )
		{
			wks.Destroy();
		}
		set_active_layer(wp.Layers()); 
		
		Worksheet wkstemp = wks;
		vector<int> vnIDs;
		wks_get_show_labels(wkstemp, vnIDs);
		//vnIDs.Add(RCLT_SAMPLE_RATE);
		vector<uint> vIndex;
		///---Sim 08-06-2007 SUPPORT_SMART_SPARKLINE
		/*
		if( bSparkLines )
		{
			xfSparkLine.SetArg("c1", c1+1); // XF sparklines use LT index
			xfSparkLine.SetArg("wks", wkstemp);
			if ( !xfSparkLine.Evaluate() )
			{
				XF_THROW(XFERR_INVALID_MATOBJ);
				return;	
			}
			if(vnIDs.Find(vIndex, RCLT_SPARKLINE) <= 0)
				vnIDs.Add(RCLT_SPARKLINE);
		}
		*/
		bool bSparklines = update_sparkline(nSparklines, wks, c1);
		
		if (bSparklines && vnIDs.Find(vIndex, RCLT_SPARKLINE) <= 0)
			vnIDs.Add(RCLT_SPARKLINE);
		///---END SUPPORT_SMART_SPARKLINE
		if(jcampFile.Get3dDataFlag() && vnIDs.Find(vIndex, RCLT_PARAM) <= 0)
			vnIDs.Add(RCLT_PARAM);
		wks_add_show_labels(wkstemp, vnIDs, true);
		
		/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
		//trInfo = trFileInfo.Header;
		//_prepare_tree_info(trInfo, trFileInfo.Data);
		string strFile;
		strFile.Format("File%d", nIndexLayer + 1); // file index to be 1
		TreeNode trInfo = trBaseInfo.AddNode(strFile);		
		trInfo.Replace(trFileInfo.Header.Clone(), true, true);
		_prepare_tree_info(trInfo, trFileInfo.Data);
		/// end FINFO_IS_ONLY_OUTPUT
		/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
		//impinfo_AddFile(wks, vsFileNames[ii], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, trFilter);
		impinfo_AddFile(wks, vsFileNames[ii], trInfo, ASCIMP_MODE_NEW_SHEETS, FILTER_TYPE_XFUNC, tnUsingFilter, ii + 1, trDataRange);
		/// end ADD_OPTION_TREE_FOR_MAKE_FILTER
	} 
	//refresh_organizer_gui(wp); ///---Sim 06-25-2007 UPDATE_ORGANIZER
	if( finfo )
		finfo.Replace(trBaseInfo.Clone(), true, true);/// Hong 01/10/06 FINFO_IS_ONLY_OUTPUT
}

//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 impJCAMP_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return impJCAMP_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	OK_SURE(bOKEnable);
	
	///support D&D show Dlg, if trFiles no child, should construct it
	if ( (GETNE_ON_INIT == nEventID && trGetN.trFiles.Children.Count() == 0) || GETNE_ON_THEME == nEventID )
	{
		s_bFileValid = _file_name_event(trGetN, strErrMsg);
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = CER_INVALID_PAGE;
		
		OK_SURE(bOKEnable);	
		return true;
	}
	
	//check file name if is invalid
	if ( 0 == lstrcmp(lpcszNodeName, "fname") )
	{
		s_bFileValid = _file_name_event(trGetN, strErrMsg);
		OK_SURE(bOKEnable);
		return true;
	}
	
	//check range if is invalid
	if( 0 == lstrcmp(lpcszNodeName, "orng") )
	{
		s_bRangeValid = !trGetN.orng.strVal.IsEmpty();
		if(!s_bRangeValid)
			strErrMsg = CER_INVALID_PAGE;
		
		OK_SURE(bOKEnable);
		return true;
	}
	return false;

}

int impJCAMP_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	/// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
	if ( 0 == strcmp(lpcszVarName, "options") )
	{
		constructOptionsForXF(tr, true, true, true, false, false, false);
		
		// custom import mode list
		///---Sim 05-08-2007 ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode tr1stImportMode = tree_get_node_by_id(tr, IDE_DISPIMP_1STMODE, true);
		if ( tr1stImportMode )
		{
			string strCombo, strMapping;
			//strCombo = getImportModeListString(strMapping, LIST_IMPORT_MODE_REPLACE_BOOK_SHEET_COLUMN);
			strCombo = getImportModeListString(strMapping, JCAMP_1ST_FILE_IMPORT_MODE_LIST); /// Hong 10/18/07 v8.0728 REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE
			tr1stImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			tr1stImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			tr1stImportMode.nVal = ASCIMP_MODE_REPLACE_DATA;
		}
		///---END ADD_OPTIONS_FOR_IMPORT_MODE_OF_1ST_FILE
		TreeNode trImportMode = tree_get_node_by_id(tr, IDE_IMP_IMPORTMODE, true);
		if ( trImportMode )
		{
			string strCombo, strMapping;
			//strCombo = getImportModeListString(strMapping, LIST_IMPORT_MODE_REPLACE_BOOK_SHEET_COLUMN);
			strCombo = getImportModeListString(strMapping, JCAMP_IMPORT_MODE_LIST); /// Hong 10/18/07 v8.0728 REMOVE_REPLACE_OUT_OF_MULTI_FILE_IMPORT_MODE
			trImportMode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
			trImportMode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
			trImportMode.nVal = ASCIMP_MODE_NEW_SHEETS;
		}
				
		fuSetXFunctionName(tr, "impJCAMP");
		return 0;
	}
	///---END ADD_OPTION_TREE_FOR_MAKE_FILTER
	
	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 impJCAMP_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if(nGetNDialog > 0)
	{
		trGetN.finfo.Show = 0;
		//trGetN.trFilter.Show = 0; /// Hong 06/07/05 v8.0635 ADD_OPTION_TREE_FOR_MAKE_FILTER
	}
	if(nGetNDialog >= 0)
	{
		if ( LTXF_FROM_GUI_MENU == dwCntrl )
			trGetN.fname.strVal = "";
		//TreeNode trFilter = trGetN.trFilter;
		//if ( trFilter.IsValid() && trFilter.GetNodeCount()>0 )
		//{
			//int nImportMode = IML_NEW_SHT; // default new sheet
			//switch ( fuGetImportMode(trFilter) )
			//{
			//case ASCIMP_MODE_REPLACE_DATA:
				//nImportMode = IML_REPLACE;
				//break;
			//case ASCIMP_MODE_NEW_BOOKS:
				//nImportMode = IML_NEW_BK;
				//break;
			//case ASCIMP_MODE_NEW_SHEETS:
				//nImportMode = IML_NEW_SHT;
				//break;
			//default:
			//}
			//trGetN.impmode.nVal = nImportMode; 
			//trGetN.sparklines.nVal = fuGetSparkLine(trFilter);
		//}
	}
	if(nGetNDialog > -1)
	{
		string strFileName = trGetN.fname.strVal;
		
		/// Hong 04/10/07 v8.0597b IGNORE_FNAME$_WHEN_FROM_MENU
		if ( LTXF_FROM_GUI_MENU & dwCntrl ) // if from menu, ignore default value fname$
			strFileName = "";
		/// end IGNORE_FNAME$_WHEN_FROM_MENU
		
		if(is_empty_or_unassigned(strFileName))
		{			
			/// Hong 05/31/07 v8.0630 MORE_ON_ACCESS_TO_FDLOG
			//int nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", "Import JCAMP-DX file", true);
			int nFilesRet;
			if ( 0 != nGetNDialog )
			{
				int nShowOptionsDlg = 1;
				/// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				//nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", _L("Import JCAMP-DX file"),
				//	OPENBOX_FLAG_MULTIFILES, NULL, NULL, _L("Show Options Dialog"), &nShowOptionsDlg);
				///---Sim 10-27-2008 QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
				//nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", NULL,
					//OPENBOX_FLAG_MULTIFILES, NULL, NULL, STR_SHOW_OPT_DLG, &nShowOptionsDlg);
				nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", NULL,
					OPENBOX_FLAG_MULTIFILES, NULL, NULL, get_show_options_label(trGetN), &nShowOptionsDlg);
				///---END QA80-12422 SUPPORT_SAVE_SHEET_THEME_FOR_ALL_SHEET_IMPORT_FILE
				/// end CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
				nRet = (nShowOptionsDlg ? XFEVT_PROCEED : XFEVT_PROCEED_NO_DLG);
			}
			else
			{
				//nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", _L("Import JCAMP-DX file"), true);
				nFilesRet = get_open_box_by_file_group(strFileName, "JCAMP", NULL, true); /// Hong 09/26/07 8.0709 CLEAN_OPEN_SAVE_DIALOG_TITLE_TO_DEFAULT
			}
			/// end MORE_ON_ACCESS_TO_FDLOG
			/// end THEME_FILENAME_WORKBOOK_AND_WORKSHEET
			if ( 0 == nFilesRet )
			{
				nRet = XFEVT_ABORT;
				//warning_msg_box(XFERR_UI_USER_CANCEL, false);
				return;
			}
			///---END HANDLE_USER_CANCEL_OPEN_FILE_BOX
			trGetN.fname.strVal = strFileName;
			string strErrMsg;
			if( !_file_name_event(trGetN, strErrMsg) )
			{
				/// Hong 03/21/07 v8.0586 FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				//nRet = XFEVT_ABORT;
				//warning_msg_box(strErrMsg, false);
				int nErrMsg = atoi(strErrMsg);
				nRet = XFEVT_ABORT;
				warning_msg_box(nErrMsg, false, 'E'); // should pass an int ///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
				/// end FIX_FAIL_DUMP_CORRECT_ERROR_STRING
				return;
			}
		}
	}
}
//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 impJCAMP_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
