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

#include <..\OriginLab\fu_utils.h>
#include <..\Originlab\Import_Utils.h>
#include <..\Originlab\DialogEx.h>
#include <GetNBox.h>
#include <XFBase.h>

#include <..\OriginLab\AscImpOptions.h>

//-------- CPY 2/24/2007 ADDING_CUSTOM_BUTTON4
enum {
	//CUSTOM_BOTTON_NEW = 1,
	///Joseph 03/07/07 GETNE_EVENT_BEGINNING_ID_CHANGED
	//CUSTOM_BUTTON_LOAD,
	CUSTOM_BUTTON_LOAD = GETNE_ON_CUSTOM_BUTTON1,
	///End GETNE_EVENT_BEGINNING_ID_CHANGED
	CUSTOM_BUTTON_SAVEAS,
	CUSTOM_BUTTON_SAVE,
};
//------- end ADDING_CUSTOM_BUTTON4

#define NONE_XF_NAME	"<none>"
///---Sim 04-27-2010 ORG-29-P2 IMP_2D_BIN_SUPPORT_FILTER_SETTINGS_AND_SAVE_FILE_INFO_INTO_BOOK
//#define ALL_IMP_XF_NAMES "ASCII|ImpWAV|ImpCSV|ImpImage|ImpExcel|ImpMatlab\
|ImppClamp|ImpMDF|ImpSPE|ImpSPC|ImpNITDM|ImpNIDIAdem|ImpNetCDF|ImpMNTB|ImpKG|ImpJNB|ImpJcamp|ImpFamos|ImpEP|ImpDT|ImpSIE|ImpIgorPro|ImpHEKA|impODQ|impNetCDFEx|impCDF|impHDF5" ///Sophy 8/24/2009 add filters for impnetCDF, impCDF, impHDF5
#define ALL_IMP_XF_NAMES "ASCII|ImpWAV|ImpCSV|ImpImage|ImpExcel|ImpMatlab\
|ImppClamp|ImpMDF|ImpSPE|ImpSPC|ImpNITDM|ImpNIDIAdem|ImpNetCDF|ImpMNTB|ImpKG|ImpJNB|ImpJcamp|ImpFamos|ImpEP|ImpDT|ImpSIE|ImpIgorPro|ImpHEKA|impODQ|impNetCDFEx|impCDF|impHDF5|impBin2d|impEDF|impIAEASPE"
///---END ORG-29-P2 IMP_2D_BIN_SUPPORT_FILTER_SETTINGS_AND_SAVE_FILE_INFO_INTO_BOOK

static bool s_bChangeSetting = false;

#define STR_FILTER_FILE_GROUP "OriginFilterFiles"

/// Hong 08/15/07 v8.0682 RESTRAIN_USER_SAVE_FILTER_INTO_SYSTEM_GROUP_FOLDER
enum
{
	FILTER_USER_FOLDER,
	FILTER_SYSTEM_FOLDER,
	FILTER_GROUP_FOLDER,
};

static int _is_filter_from_system_group_folder(string& strFileName)
{	
	int nRet = FILTER_SYSTEM_FOLDER;
	string strPath = okutil_get_origin_path(ORIGIN_PATH_SYSTEM) + FILTERS_FOLDER_NAME;
	if ( strFileName.Find(strPath) < 0 )
	{
		strPath = okutil_get_origin_path(ORIGIN_PATH_GROUP);
		//if ( strFileName.Find(strPath) < 0 )
		if ( strPath.IsEmpty() || strFileName.Find(strPath) < 0 ) /// Hong 09/28/07 v8.0709 GROUP_PATH_CAN_BE_EMPTY 
			return FILTER_USER_FOLDER;
		
		nRet = FILTER_GROUP_FOLDER;
	}
	
	return nRet;
}
/// end RESTRAIN_USER_SAVE_FILTER_INTO_SYSTEM_GROUP_FOLDER

//put your own support static functions here
int find_str_no_case(LPCSTR lpcszSource, LPCSTR lpcszSub)
{
	string strSource = lpcszSource;
	string strSub = lpcszSub;
	
	strSource.MakeLower();
	strSub.MakeLower();
	
	return strSource.Find(strSub);
}

static bool check_setting_invalid(TreeNode& trSetting, string& strMsg)
{
	strMsg.Empty();
	
	string strXFName;
	if ( trSetting.xfname )
		strXFName = trSetting.xfname.strVal;
	
	if ( strXFName.IsEmpty() )
	{
		strMsg = "Please fill XFunction Name.";
		return false;
	}
	
	return true;
}

/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
static bool _is_supported_filter(int nType)
{
	return ( FILTER_TYPE_XFUNC == nType || FILTER_TYPE_ASCII == nType || FILTER_TYPE_BINARY == nType );
}

static string _get_xfname(const TreeNode& trFilter, int nType)
{
	ASSERT(_is_supported_filter(nType));
	
	if ( FILTER_TYPE_ASCII == nType )
		return STR_FILTER_TYPE_ASCII;
	else if ( FILTER_TYPE_BINARY == nType )
		return STR_FILTER_TYPE_BINARY;
	
	ASSERT(trFilter);
	string		strXFName;
	fuGetXFunctionName(trFilter, strXFName);
	return strXFName;
}

static int _get_filter_type(LPCSTR lpcszXFName)
{
	if ( 0 == lstrcmp(STR_FILTER_TYPE_ASCII, lpcszXFName) )
		return FILTER_TYPE_ASCII;
	else if ( 0 == lstrcmp(STR_FILTER_TYPE_BINARY, lpcszXFName) )
		return FILTER_TYPE_BINARY;
	
	return FILTER_TYPE_XFUNC;
}

static void _apply_filter_to_options(const TreeNode& trFilter, TreeNode& trOptions, int nType)
{
	if ( FILTER_TYPE_ASCII == nType )
		FilterToOptions(trFilter, trOptions);
	else if ( FILTER_TYPE_BINARY == nType )
		BinaryFilterToOptions(trFilter, trOptions);
	else
	{
		ASSERT(FILTER_TYPE_XFUNC == nType);
		tree_copy_values_by_id(trFilter, trOptions);
	}
}

static void _apply_options_to_filter(const TreeNode& trOptions, TreeNode& trFilter, int nType)
{
	if ( FILTER_TYPE_ASCII == nType )
		OptionsToFilter(trOptions, trFilter);
	else if ( FILTER_TYPE_BINARY == nType )
		BinaryOptionsToFilter(trOptions, trFilter);
	else
	{
		ASSERT(FILTER_TYPE_XFUNC == nType);
		tree_whole_copy_values_by_id(trOptions, trFilter);
		if ( trFilter.options )
			trFilter.options.Remove(); // exclude branch node
	}
}

static void _update_shown_status(TreeNode& trGetN, int nType)
{
	trGetN.gsetting.opdlg.Show = (FILTER_TYPE_BINARY == nType) ? false : true;
}
/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ

///---Sim 02-27-2008 QA80-11163 IMPORT_RENAME_BOTH_BOOK_LONG_AND_SHORT_NAME
// not used again
/*
static void check_enable(TreeNode& trGetN)
{
	///---Sim 03-13-2007 CENTRALIZE_FILE_NAME_OPTIONS_ENABLE
	//int nEnable = (0 == trGetN.autorn.nVal) ? 1 : 0;
	//
	//trGetN.sheet.Enable = nEnable;
	//trGetN.book.Enable = nEnable;
//
	//trGetN.sheet.Enable = nEnable;
	//int nWksTrimEnable = (nEnable && (1 == trGetN.sheet.nVal)) ? 1 : 0;
	//trGetN.stfrom.Enable = nWksTrimEnable;
	//trGetN.stto.Enable = nWksTrimEnable;
	//
	//trGetN.book.Enable = nEnable;
	//int nWkbkTrimEnable = (nEnable && (1 == trGetN.book.nVal)) ? 1 : 0;
	//trGetN.bkfrom.Enable = nWkbkTrimEnable;
	//trGetN.bkto.Enable = nWkbkTrimEnable;
	
	bool bRenameWks, bRenameWksPartial, bRenameWkbk, bRenameWkbkPartial, bRenameWkbkIncludePath, bAppendIncludePath;
	///---Sim 02-27-2008 QA80-11163 IMPORT_RENAME_BOTH_BOOK_LONG_AND_SHORT_NAME
	//getEnableValueForFileNameOptions(trGetN.autorn.nVal, trGetN.sheet.nVal, trGetN.book.nVal, trGetN.bkComments.nVal, trGetN.colComments.nVal,
		//bRenameWks, bRenameWksPartial, bRenameWkbk, bRenameWkbkPartial, bRenameWkbkIncludePath, bAppendIncludePath);
	bool bRenameWkBkLnOnly;
	getEnableValueForFileNameOptions(trGetN.autorn.nVal, trGetN.sheet.nVal, trGetN.book.nVal, trGetN.bkComments.nVal, trGetN.colComments.nVal,
		bRenameWks, bRenameWksPartial, bRenameWkbk, bRenameWkbkPartial, bRenameWkBkLnOnly, bRenameWkbkIncludePath, bAppendIncludePath);
	///---END QA80-11163 IMPORT_RENAME_BOTH_BOOK_LONG_AND_SHORT_NAME

	trGetN.sheet.Enable 	= bRenameWks;
	trGetN.stfrom.Enable 	= bRenameWksPartial;
	trGetN.stto.Enable 		= bRenameWksPartial;
	
	trGetN.book.Enable = bRenameWkbk;
	trGetN.bkfrom.Enable 	= bRenameWkbkPartial;
	trGetN.bkto.Enable 	= bRenameWkbkPartial;
	//trGetN..Enable	= bRenameWkBkLnOnly; ///---Sim 02-27-2008 QA80-11163 IMPORT_RENAME_BOTH_BOOK_LONG_AND_SHORT_NAME
	trGetN.bkincpath.Enable	= bRenameWkbkIncludePath;
	
	trGetN.incpath.Enable	= bAppendIncludePath;	
	///---END CENTRALIZE_FILE_NAME_OPTIONS_ENABLE
}
*/
///---END QA80-11163 IMPORT_RENAME_BOTH_BOOK_LONG_AND_SHORT_NAME

static void set_display_format(TreeNode& trGetN)
{
	string strCombo, strMapping;
	
	// import mode
	strCombo = getImportModeListString(strMapping);
	trGetN.impmode.ID = TRGP_ENUM_LIST;
	trGetN.impmode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
	trGetN.impmode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
	/// Hong 05/09/07 v8.0614 ADD_FIRST_FILE_IMPORT_MODE
	trGetN.firstmode.ID = TRGP_ENUM_LIST;
	trGetN.firstmode.SetAttribute(STR_COMBO_ATTRIB, strCombo);
	trGetN.firstmode.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
	/// END ADD_FIRST_FILE_IMPORT_MODE
	
	// page type
	strCombo = _L("Worksheet|Matrix|None");
	strMapping = EXIST_WKS;
	strMapping += "|";
	strMapping += EXIST_MATRIX;
	strMapping += "|";
	strMapping += EXIST_NONE;

	trGetN.pgtype.ID = TRGP_ENUM_LIST;
	trGetN.pgtype.SetAttribute(STR_COMBO_ATTRIB, strCombo);
	trGetN.pgtype.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
}

static bool load_filter(const string& strFileName, TreeNode& trSetting)
{
	Tree trFilter;
	if( strFileName.IsEmpty() )
		return false; // nothing more to do
	
	if( !fuLoad(trFilter, strFileName) )
		return false; // nothing more to do 
	
	int nType = fuGetType(trFilter);
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//if ( !(FILTER_TYPE_XFUNC == nType || FILTER_TYPE_ASCII == nType) )
		//return false;
	//
	//bool bXF = (FILTER_TYPE_XFUNC == nType);
	if ( !_is_supported_filter(nType) )
		return false;
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	
	/*
	// Copy settings from filter to X-Function settings
	string str;
	
	if( fuGetXFunctionName(trFilter, str) )
		trSetting.xf.strVal = str;
	
	if( fuGetFileSpec(trFilter, str) )
		trSetting.ext.strVal = str;
	
	if( fuGetDescription(trFilter, str) )
		trSetting.label.strVal = str;
	
	trSetting.show.nVal = fuGetShowFilterInOpenList(trFilter); // Hong 04/17/07 QA80-9634 V8.0602b FILTER_SHOW_IN_FILE_OPEN_LIST
	
	trSetting.autorn.nVal 		= fuIsAutoRename(trFilter);
	
	trSetting.sheet.nVal 		= fuIsRenameWks(trFilter);
	trSetting.stfrom.nVal 		= fuGetWksTrimFrom(trFilter);
	trSetting.stto.nVal 		= fuGetWksTrimTo(trFilter);
	
	trSetting.book.nVal 		= fuXFIsRenameWorkbook(trFilter);
	trSetting.bkfrom.nVal 		= fuGetWkBkTrimFrom(trFilter);
	trSetting.bkto.nVal 		= fuGetWkBkTrimTo(trFilter);
	trSetting.bkincpath.nVal 	= fuXFIsRenameBookIncludePath(trFilter);
	
	trSetting.bkComments.nVal 	= fuXFIsAppendFileNameToWorkBookComments(trFilter);
	trSetting.colComments.nVal	= fuXFIsAppendFileNameToColumnComments(trFilter);
	trSetting.incpath.nVal 		= fuXFIsAppendFileNameIncludePath(trFilter);
	
	trSetting.pgtype.nVal = fuGetTargetPage(trFilter);
	
	trSetting.impmode.nVal = fuGetImportMode(trFilter);
	
	trSetting.firstmode.nVal = fuGet1stImportMode(trFilter);/// Hong 05/09/07 v8.0614 ADD_FIRST_FILE_IMPORT_MODE
	
	trSetting.template.strVal = fuGetStr(trFilter, IDE_DISP_IMP_PAGETEMPLATE, "");
	
	trSetting.bOpenXFDlg.nVal = fuGetXFSetting(trFilter);
	
	trSetting.bShowTime.nVal =  fuGetShowTime(trFilter);
	trSetting.bSparkLine.nVal = fuGetSparkLine(trFilter);

	
	trSetting.skipst.nVal = fuGetStartPoint(trFilter);
	trSetting.skiped.nVal = fuGetEndPoint(trFilter);
	trSetting.skipnum.nVal = fuGetSkipPoint(trFilter);

	string strScript;
	fuGetPostImportScript(trFilter, strScript);
	trSetting.script.strVal = strScript;
	*/
	
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//string strXFuncName;
	//if ( bXF )
		//fuGetXFunctionName(trFilter, strXFuncName);
	//else // ASCII
		//strXFuncName = STR_FILTER_TYPE_ASCII;
	string 		strXFuncName = _get_xfname(trFilter, nType);
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		
	if ( trSetting.xfname )
	{
		trSetting.xfname.strVal = strXFuncName;
	}

	if ( trSetting.gsetting )
	{
		tree_copy_values_by_id(trFilter, trSetting.gsetting);
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		_update_shown_status(trSetting, nType);
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	}
	
	if ( trSetting.options )
	{
		construct_options(trSetting.options, strXFuncName);
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		//if ( bXF )
			//tree_copy_values_by_id(trFilter, trSetting.options);
		//else // ASCII
			//FilterToOptions(trFilter, trSetting.options);
		_apply_filter_to_options(trFilter, trSetting.options, nType);
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	}
	
	return true;
}

static bool save_filter(const string& strFileName, TreeNode& trSetting)
{
	Tree trFilter;
	//fuPrepareDefault(trFilter, FILTER_TYPE_XFUNC);
	
	/*
	fuSetXFunctionName(trFilter, trSetting.xf.strVal);
	
	fuSetFileSpec(trFilter, trSetting.ext.strVal);
	
	fuSetDescription(trFilter, trSetting.label.strVal);
	
	fuSetShowFilterInOpenList(trFilter, trSetting.show.nVal); // Hong 04/17/07 QA80-9634 V8.0602b FILTER_SHOW_IN_FILE_OPEN_LIST
	
	fuSetAutoRename(trFilter, trSetting.autorn.nVal);
	
	fuSetRenameWks(trFilter, trSetting.sheet.nVal);
	fuSetWksTrimFrom(trFilter, trSetting.stfrom.nVal);
	fuSetWksTrimTo(trFilter, trSetting.stto.nVal);
	
	fuXFSetRenameWorkbook(trFilter, trSetting.book.nVal);
	fuSetWkBkTrimFrom(trFilter, trSetting.bkfrom.nVal);
	fuSetWkBkTrimTo(trFilter, trSetting.bkto.nVal);
	fuXFSetRenameBookIncludePath(trFilter, trSetting.bkincpath.nVal);
	
	fuXFSetAppendFileNameToWorkBookComments(trFilter, trSetting.bkComments.nVal);
	fuXFSetAppendFileNameToColumnComments(trFilter, trSetting.colComments.nVal);
	fuXFSetAppendFileNameIncludePath(trFilter, trSetting.incpath.nVal);
	
	fuSetTargetPage(trFilter, trSetting.pgtype.nVal);
	
	fuSetImportMode(trFilter, trSetting.impmode.nVal);
	
	fuSet1stImportMode(trFilter, trSetting.firstmode.nVal);/// Hong 05/09/07 v8.0614 ADD_FIRST_FILE_IMPORT_MODE
	
	fuSetStr(trFilter, IDE_DISP_IMP_PAGETEMPLATE, trSetting.template.strVal);
	
	fuSetXFSetting(trFilter, trSetting.bOpenXFDlg.nVal); 
	fuSetShowTime(trFilter, trSetting.bShowTime.nVal);
	fuSetSparkLine(trFilter, trSetting.bSparkLine.nVal);

	fuSetStartPoint(trFilter, trSetting.skipst.nVal);
	fuSetEndPoint(trFilter, trSetting.skiped.nVal);
	fuSetSkipPoint(trFilter, trSetting.skipnum.nVal);
	
	fuSetPostImportScript(trFilter, trSetting.script.strVal);
	*/
	
	string strXFName;
	if ( trSetting.xfname )
		strXFName = trSetting.xfname.strVal;
	
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//bool bXF = ( STR_FILTER_TYPE_ASCII != strXFName );
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ

	/// EJP 2008-02-12 v8.0803 QA80-11060 DO_NOT_LOSE_NODES_NOT_USED_BY_IWFILTER
	//string strOriginalFileName = trGetN.fname.strVal;
	string strOriginalFileName = trSetting.fname.strVal; /// Hong v8.0809 FIX_IWFILTER_FAIL_COMPILE
	///---Sim 03-11-2008 FIX_NEW_DEFAULT_FILTER_ERROR fix for runtime error, wait for #11253 fixed
	//if( !strOriginalFileName.IsEmpty() || !trFilter.Load(strOriginalFileName) )
	bool bFilterFromFile = false;
	if ( !strOriginalFileName.IsEmpty() )
	{
		Tree trFilterFromFile;
		///---Sim 10-31-2008 FIX_LOAD_FILTER_WITHOUT_NEWEST_SETTINGS
		// etc. pClamp 8.0675 filter miss iRenameWkBkLongNameOnly
		//if ( trFilterFromFile.Load(strOriginalFileName) )
		if ( fuLoad(trFilterFromFile, strOriginalFileName) )
		///---END FIX_LOAD_FILTER_WITHOUT_NEWEST_SETTINGS
		{
			trFilter.Replace(trFilterFromFile);
			bFilterFromFile = true;
		}
	}
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//if ( !bFilterFromFile )
	/////---END FIX_NEW_DEFAULT_FILTER_ERROR
	///// end DO_NOT_LOSE_NODES_NOT_USED_BY_IWFILTER
		//fuPrepareDefault(trFilter, (bXF ? FILTER_TYPE_XFUNC : FILTER_TYPE_ASCII) );
	int			nType = _get_filter_type(strXFName);
	if ( !bFilterFromFile )
		fuPrepareDefault(trFilter, nType);
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	
	if ( trSetting.options )
	{
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		/*
		if ( bXF )
		{
			///---Sim 06-06-2007 CHANGE_FILTER_TAGNAME_ISSUE
			//tree_copy_values_by_id(trSetting.options, trFilter);
			//trFilter.Replace(trSetting.options);
			tree_whole_copy_values_by_id(trSetting.options, trFilter);
			if ( trFilter.options )
				trFilter.options.Remove(); // exclude branch node
			///---END CHANGE_FILTER_TAGNAME_ISSUE
		}
		else // ASCII
		{
			OptionsToFilter(trSetting.options, trFilter);
		}
		*/
		_apply_options_to_filter(trSetting.options, trFilter, nType);
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	}
	
	if ( trSetting.gsetting )
	{
		fuSetPostImportScript(trFilter, ""); // prepare script node for copy value by id
		tree_copy_values_by_id(trSetting.gsetting, trFilter);
	}
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//if ( bXF )
	if ( FILTER_TYPE_XFUNC == nType )
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		fuSetXFunctionName(trFilter, strXFName);
	
	return fuSave(trFilter, strFileName);	
}

static void hide_getn_options(TreeNode trGetN)
{
	///---Sim 03-21-2008 FIX_SEE_FILENAME_CLEARLY
	//trGetN.fname.Enable = 0;
	trGetN.fname.Enable = ENABLE_READ_ONLY;
	///---END FIX_SEE_FILENAME_CLEARLY
	trGetN.ifilter.Show = 0;
}

static bool save_as_filter(string& strFileName, TreeNode& trSetting)
{
	//string strPath = GetFilePath(strFileName);
	/// Hong 08/15/07 v8.0682 CREATE_USER_FILTER_FOLDER_USER_FIRST_SAVE_FILTER
	//string strPath = is_empty_or_unassigned(strFileName) ? 
	//			get_file_group_default_path(STR_FILTER_FILE_GROUP) : GetFilePath(strFileName);
	// Fisher 03/26/08 SET_DEFAULT_TO_UFF
	//string strUserFilterPath = GetAppPath() + FILTERS_FOLDER_NAME;
	string strUserFilterPath = GetAppPath(false) + FILTERS_FOLDER_NAME;
	if ( !strUserFilterPath.IsPath() )
		CreateDirectory(strUserFilterPath, NULL);
	
	string strPath = is_empty_or_unassigned(strFileName) ? strUserFilterPath : GetFilePath(strFileName);
	/// end CREATE_USER_FILTER_FOLDER_USER_FIRST_SAVE_FILTER
	strFileName = GetSaveAsBox("[Origin Filter Files(*.oif)] *.oif", strPath, strFileName);
		
	if ( strFileName.IsEmpty() )
		return false;
	
	int nRet, nErrMsg = CER_CAN_NOT_SAVE_INTO_SYSTEM_FOLDER;
	if ( nRet = _is_filter_from_system_group_folder(strFileName) )
	{
		if ( FILTER_GROUP_FOLDER == nRet )
			nErrMsg = CER_CAN_NOT_SAVE_INTO_GROUP_FOLDER;
		
		warning_msg_box(nErrMsg, true);
		return false;
	}
	return save_filter(strFileName, trSetting);
	
	//return true;
}

static bool construct_general_setting(TreeNode trSetting)
{
	string strCombo, strMapping;
	strCombo = _L("Worksheet|Matrix|None");
	strMapping = EXIST_WKS;
	strMapping += "|";
	strMapping += EXIST_MATRIX;
	strMapping += "|";
	strMapping += EXIST_NONE;
	
	trSetting.RemoveChildrenWithPrefix();
	GETN_USE(trSetting)
		GETN_STR(ext, _L("File Name Filter (e.g. *.dat or *.dat; myfile??.*)"), "*.*") GETN_ID(IDE_DISP_IMP_FILESPEC)
		GETN_STR(label, _L("Filter Description"), "") GETN_ID(IDE_DISP_IMP_DESCRIPTION)
		GETN_LIST(page, _L("Page Type"), EXIST_WKS, strCombo)
			//GETN_STR_COMBO(strCombo)
			GETN_ADD_INT_MAP(strMapping)
			GETN_ID(IDE_DISP_IMP_PAGETYPE)
		GETN_CHECK(inlist, _L("Show Filter in File:Open List"), 0) GETN_ID(IDE_DISPIMP_SHOWFILTERINOPENLIST)
		GETN_CHECK(opdlg, _L("Open XF Dialog"), 0) GETN_ID(IDE_XFIMP_OPENSETTING)
		//GETN_STR(script, _L("Labtalk Scipt after Import"), "") GETN_ID(IDE_IMP_POSTIMPSCRIPT)
		GETN_MULTILINE_TEXT(script, _L("Labtalk Script after Import"), "") GETN_ID(IDE_IMP_POSTIMPSCRIPT)
		
	return true;
}

static bool construct_options(TreeNode trOptions, LPCSTR lpcszXFName)
{
	string strXFName = lpcszXFName;
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//bool bXF = ( STR_FILTER_TYPE_ASCII != strXFName );
	//
	//if ( bXF )
	int			nType = _get_filter_type(strXFName);
	if ( FILTER_TYPE_XFUNC == nType )
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	{
		
		if ( !( is_empty_or_unassigned(strXFName) || "<none>" == strXFName ) )
		{
			XFBase xf;
			DWORD dwCntrl = 0;
			if ( !xf.Load(strXFName, dwCntrl) )
				return error_report(_L("Failed to load import xfunction!"));
			
			Tree trJunk;
			TreeNode trGetN;
			xf.GetGUI(trJunk, trGetN);
			
			///---Sim 10-29-2008 v9.926b QA80-12484 IMPORT_EXCEL_FILTER_NEED_SPECIAL_HANDLING
			update_getn_LT_variables(trGetN, strXFName, true);
			///---END v9.926b QA80-12484 IMPORT_EXCEL_FILTER_NEED_SPECIAL_HANDLING

			if ( trGetN.options )
			{
				///---Sim 10-29-2008 v9.926b QA80-12484 IMPORT_EXCEL_FILTER_NEED_SPECIAL_HANDLING
				TreeNode trGetNLT = trGetN.options.GetNode(STR_NODE_NAME_GETN_LT);
				if ( trGetNLT )
					trGetNLT.Show = true;
				///---END v9.926b QA80-12484 IMPORT_EXCEL_FILTER_NEED_SPECIAL_HANDLING
				
				string strLabel;
				trOptions.GetAttribute(STR_LABEL_ATTRIB, strLabel);
				trOptions.Replace(trGetN.options);
				trOptions.SetAttribute(STR_LABEL_ATTRIB, strLabel);
				return true;
			}
		}
	}
	
	//fuPrepareDefault(trOptions, FILTER_TYPE_XFUNC);
	string strLabel;
	trOptions.GetAttribute(STR_LABEL_ATTRIB, strLabel);
	trOptions.RemoveChildrenWithPrefix();
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//if ( bXF )
		//constructOptionsForXF(trOptions, true, true, true, true, true, true, true,true);
	//else
		//construct_ascii_import_options(trOptions, false);
	if ( FILTER_TYPE_ASCII == nType )
		construct_ascii_import_options(trOptions, false);
	else if ( FILTER_TYPE_BINARY == nType )
		construct_binary_import_options(trOptions);
	else
		constructOptionsForXF(trOptions, true, true, true, true, true, true, true,true);
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	trOptions.SetAttribute(STR_LABEL_ATTRIB, strLabel);
	// .. maybe need to do other thing.
	
	return true;
}
		

void iwfilter(const string& fname, const string& xfname, const TreeNode& gsetting, const TreeNode& options, const TreeNode& ifilter, TreeNode& ofilter)
{
	/// Hong 09/13/07 v8.0702 SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
	///---Sim 09-30-2007 FIX_INVALID_STRING_OBJ
	if ( NULL == (&xfname) )
		XF_THROW(XFERR_INVALID_ARG);
	//if ( xfname.IsEmpty() )
	if ( NONE_XF_NAME == xfname || xfname.IsEmpty() ) 
		XF_THROW(XFERR_INVALID_ARG);
	///---END FIX_INVALID_STRING_OBJ
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//int nType = FILTER_TYPE_XFUNC;
	//if ( "ASCII" == xfname )
		//nType = FILTER_TYPE_ASCII;
	int			nType = _get_filter_type(xfname);
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	///---Sim 09-30-2007 GENERATE_OUTPUT_FILTER_TREE
	if ( ofilter )
		//fuPrepareDefault(ofilter, nType);
	{
		// duplicate code
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		//bool bXF = ( STR_FILTER_TYPE_ASCII != xfname );
		//fuPrepareDefault(ofilter, (bXF ? FILTER_TYPE_XFUNC : FILTER_TYPE_ASCII) );
		fuPrepareDefault(ofilter, nType);
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		
		if ( options )
		{
			/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			//if ( bXF )
			//{
				//tree_whole_copy_values_by_id(options, ofilter);
				//if ( ofilter.options )
					//ofilter.options.Remove(); // exclude branch node
			//}
			//else // ASCII
			//{
				//OptionsToFilter(options, ofilter);
			//}
			_apply_options_to_filter(options, ofilter, nType);
			/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		}
		
		if ( gsetting )
		{
			fuSetPostImportScript(ofilter, ""); // prepare script node for copy value by id
			tree_copy_values_by_id(gsetting, ofilter);
		}
	
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		//if ( bXF )
		if ( FILTER_TYPE_XFUNC == nType )
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			fuSetXFunctionName(ofilter, xfname);		
	}
	///---END GENERATE_OUTPUT_FILTER_TREE
	/// end SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
}

//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 iwfilter_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return iwfilter_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	//out_str("------------Event----------------");
	//out_str(trGetN.xfname.strVal);
	if ( GETNE_ON_INIT == nEventID )
	{
		/*
		string strCombo;
		strCombo = "<none>|" + ALL_IMP_XF_NAMES;
		trGetN.xfname.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		//
		//set_display_format(trGetN);
	//
		//trGetN.fisrtmode.nVal = ASCIMP_MODE_REPLACE_DATA; /// Hong 05/09/07 v8.0614 ADD_FIRST_FILE_IMPORT_MODE
		//trGetN.impmode.nVal = ASCIMP_MODE_NEW_SHEETS;
		//trGetN.pgtype.nVal = EXIST_WKS;
		//
		//constructOptionsForXF(trGetN.options, true, true, true, true, true, true, true,true);
		//construct_general_setting(trGetN.gsetting);
		construct_options(trGetN.options, trGetN.xfname.strVal);
		
		//check_enable(trGetN);
		*/
		tree_set_attribute_to_all_nodes(trGetN.options, STR_ATTRIB_FORCE_NODE_EVENT_ON, "1");
		trGetN.SetAttribute(STR_ATTRIB_FORCE_CALL_NODE_EVENTS, 1);
		
		bBTN3Enable = _is_filter_from_system_group_folder(trGetN.fname.strVal) ? false : true;	/// Hong 08/15/07 v8.0682 RESTRAIN_USER_SAVE_FILTER_INTO_SYSTEM_GROUP_FOLDER		 
	
		s_bChangeSetting = false;
		return true;
	}
	if ( GETNE_ON_THEME == nEventID )
	{
		//set_display_format(trGetN);
		//check_enable(trGetN);
		
		s_bChangeSetting = false;
		return true;
	}
	
	if ( CUSTOM_BUTTON_LOAD == nEventID ) // open
	{
		string strFileName = trGetN.fname.strVal;
		
		if ( s_bChangeSetting )
		{
			string strMsg = "Setting of filter has been changed. Save to file?";
			if ( IDOK == MessageBox(GetWindow(), strMsg, "Question", MB_YESNO|MB_ICONQUESTION) )
			{	// save current setting to file			
				if ( !save_as_filter(strFileName, trGetN) )
					return false;
			}
		}
		
		int nFilesRet = get_open_box_by_file_group(strFileName, STR_FILTER_FILE_GROUP, "Origin Filter Files", (bool)false);
		if ( 0 == nFilesRet )
		{
			return false;
		}
	
		trGetN.fname.strVal = strFileName;
	
		bBTN3Enable = _is_filter_from_system_group_folder(trGetN.fname.strVal) ? false : true; /// Hong 08/15/07 v8.0682 RESTRAIN_USER_SAVE_FILTER_INTO_SYSTEM_GROUP_FOLDER			 	
		
		if ( !load_filter(strFileName, trGetN) )
			return false;
		tree_set_attribute_to_all_nodes(trGetN.options, STR_ATTRIB_FORCE_NODE_EVENT_ON, "1");
		trGetN.SetAttribute(STR_ATTRIB_FORCE_CALL_NODE_EVENTS, 1);
		
		//check_enable(trGetN);
		
		s_bChangeSetting = false;
		GETN_CHANGE_GRID
		return true;
	}
	if ( CUSTOM_BUTTON_SAVE == nEventID ) // save
	{
		string strMsg;
		if ( !check_setting_invalid(trGetN, strMsg) )
		{
			///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
			//warning_msg_box(strMsg, true, false, false);
			warning_msg_box(strMsg, true);
			///---END IMPROVE_WARNING_MESSAGE_POST_FUNCTION
			return false;
		}
		
		string strFileName = trGetN.fname.strVal;
		
		if ( strFileName.IsEmpty() )
		{
			if ( !save_as_filter(strFileName, trGetN) )
				return false;
		}
		else
		{
			save_filter(strFileName, trGetN);
		}
		
		trGetN.fname.strVal = strFileName;
		s_bChangeSetting = false;
		GETN_CHANGE_GRID
		return true;
	}
	if ( CUSTOM_BUTTON_SAVEAS == nEventID ) // save as
	{
		string strMsg;
		if ( !check_setting_invalid(trGetN, strMsg) )
		{
			///---Sim 06-19-2007 IMPROVE_WARNING_MESSAGE_POST_FUNCTION
			//warning_msg_box(strMsg, true, false, false);
			warning_msg_box(strMsg, true);
			///---END IMPROVE_WARNING_MESSAGE_POST_FUNCTION
			return false;
		}
		
		string strFileName = trGetN.fname.strVal;;
		
		if ( !save_as_filter(strFileName, trGetN) )
			return false;
		
		trGetN.fname.strVal = strFileName;
		s_bChangeSetting = false;
		GETN_CHANGE_GRID
		return true;
	}
	
	//if ( 0 == strcmp(lpcszNodeName, "autorn") 
		//|| 0 == strcmp(lpcszNodeName, "sheet")
		//|| 0 == strcmp(lpcszNodeName, "book") 
		//|| 0 == strcmp(lpcszNodeName, "bkComments") 
		//|| 0 == strcmp(lpcszNodeName, "colComments") 	)
	//{
		//check_enable(trGetN);
		//
		//s_bChangeSetting = true;
		//return true;
	//}
	
	if ( 0 == strcmp(lpcszNodeName, "xfname") )
	{
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		_update_shown_status(trGetN, _get_filter_type(trGetN.xfname.strVal));
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		construct_options(trGetN.options, trGetN.xfname.strVal);
		tree_set_attribute_to_all_nodes(trGetN.options, STR_ATTRIB_FORCE_NODE_EVENT_ON, "1");
		trGetN.SetAttribute(STR_ATTRIB_FORCE_CALL_NODE_EVENTS, 1);
		//out_str("------------xfname----------------");
		//out_tree(trGetN.options);
		
		//check_enable(trGetN);
		
		s_bChangeSetting = true;
		return true;
	}
	
	s_bChangeSetting = true;
	
	return false;

}

int iwfilter_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	
	//if ( 0 == strcmp(lpcszVarName, "impmode") )
	//{
		//string strCombo, strMapping;
		//strCombo = getImportModeListString(strMapping);
		//tr.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		//tr.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
		//tr.nVal = ASCIMP_MODE_NEW_SHEETS;
		//return 0;
	//}
	//
	//if ( 0 == strcmp(lpcszVarName, "pgtype") )
	//{
		//string strCombo, strMapping;
		//strCombo = "EXIST_WKS|EXIST_MATRIX|EXIST_NONE";
		//strMapping = EXIST_WKS;
		//strMapping += "|";
		//strMapping += EXIST_MATRIX;
		//strMapping += "|";
		//strMapping += EXIST_NONE;
	//
		//tr.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		//tr.SetAttribute(STR_INTMAP_ATTRIB, strMapping);
		//tr.nVal = EXIST_WKS;
		//return 0;
	//}
	
	//if ( 0 == strcmp(lpcszVarName, "gsetting") )
	//{
		//construct_general_setting(tr);
		//return 0;
	//}
	
	//if ( 0 == strcmp(lpcszVarName, "xfname") )
	//{
		//string strCombo;
		//strCombo = "<none>|ImppClamp|ImpWAV|ImpCSV|ImpMDF|ImpFamos";
		//tr.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		//out_tree(tr);
		//return 0;
	//}
	
	return -1;
}
//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 iwfilter_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	/// Hong 09/13/07 v8.0702 SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
	string strCombo;
	/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	//strCombo = NONE_XF_NAME + "|" + ALL_IMP_XF_NAMES;
	strCombo = NONE_XF_NAME + "|" + STR_FILTER_TYPE_BINARY + "|" + ALL_IMP_XF_NAMES + "|";
	/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	trGetN.xfname.SetAttribute(STR_COMBO_ATTRIB, strCombo);
	/// end SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
	
	///---Sim 09-30-2007 GENERATE_OUTPUT_FILTER_TREE
	//if ( nGetNDialog > 0 )
	if ( nGetNDialog >= 0 )
	///---END GENERATE_OUTPUT_FILTER_TREE
	{
		//out_str("------------before execute----------------");
		/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		//bool bXF = true;
		int			nType = FILTER_TYPE_XFUNC;
		/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		TreeNode trFilter;
		if ( trGetN.ifilter && trGetN.ifilter.GetNodeCount() > 0 )
		{
			trFilter = trGetN.ifilter;
			/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			//int nType = fuGetType(trFilter);
			//
			//if (FILTER_TYPE_ASCII == nType)
				//bXF = false;
			nType = fuGetType(trFilter);
			/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			//if ( !(FILTER_TYPE_XFUNC == nType || FILTER_TYPE_ASCII == nType) )
			if ( !_is_supported_filter(nType) )
			/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			{
				XF_WARN(_L("Not support this type of filter! Please select ASCII or XFunction filter."));
				TreeNode trInvalidNode;
				trFilter = trInvalidNode; //= NULL;
			}
		}
		/// Hong 09/13/07 v8.0702 SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
		//string strCombo;
		//strCombo = NONE_XF_NAME + "|" + ALL_IMP_XF_NAMES;
		//trGetN.xfname.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		/// end SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
		string strXFName = NONE_XF_NAME;
		///---Sim 09-30-2007 GENERATE_OUTPUT_FILTER_TREE
		if ( trGetN.xfname && !trGetN.xfname.IsEmpty() )
			strXFName = trGetN.xfname.strVal;
		///---END GENERATE_OUTPUT_FILTER_TREE
		if ( trFilter )
		{
			/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			//if ( bXF )
				//fuGetXFunctionName(trFilter, strXFName);
			//else // ASCII
				//strXFName = STR_FILTER_TYPE_ASCII;
			strXFName = _get_xfname(trFilter, nType);
			/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
	
			int nStart = find_str_no_case(strCombo, strXFName);
			if ( nStart < 0 )
			{
				XF_WARN(_L("This file type not in type list."));
				strXFName = NONE_XF_NAME;
				/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
				//bXF = true;
				/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
				TreeNode trInvalidNode;
				trFilter = trInvalidNode; //= NULL;
			}
			else // in type list
			{	// make xfunction name consistent, to prevent post unexpected xfname node event
				int nEnd = strCombo.Find('|', nStart);
				if ( nEnd < 0 )
					nEnd = strCombo.GetLength();
				strXFName = strCombo.Mid(nStart, nEnd - nStart);
			}
		}
		trGetN.xfname.strVal = strXFName;
		
		if ( trGetN.gsetting )
		{
			construct_general_setting(trGetN.gsetting);
			
			if ( trFilter )
				tree_copy_values_by_id(trFilter, trGetN.gsetting);
			//out_tree(trGetN.gsetting);
			/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			_update_shown_status(trGetN, nType);
			/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
		}
		
		if ( trGetN.options )
		{
			construct_options(trGetN.options, trGetN.xfname.strVal);
			
			if ( trFilter )
			{
				/// Hong 03/11/10 QA80-15192 SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
				//if ( bXF )
					//tree_copy_values_by_id(trFilter, trGetN.options);
				//else // ASCII
					//FilterToOptions(trFilter, trGetN.options);
				_apply_filter_to_options(trFilter, trGetN.options, nType);
				/// end SUPPORT_EDIT_BINARY_FILTER_CREATED_BY_IMPWIZ
			}
			//out_tree(trGetN.options);
		}
		
		hide_getn_options(trGetN);
		
	}
	/// Hong 09/13/07 v8.0702 SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
	//else if ( 0 == nGetNDialog )
	//{
		//nRet = XFEVT_PROCEED_WITH_DLG;
	//}
	/// end SIMPLE_SUPPORT_LT_GENEARATE_FILTER_TREE
}
//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 iwfilter_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
