/*------------------------------------------------------------------------------*
 * File Name:				 													*
 * Creation: 																	*
 * Purpose: OriginC Source C file												*
 * Copyright (c) ABCD Corp.	2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010		*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 * Frank	4/23/04		QA70-6086 v8.0861	DELECT_FUNCTION_CANT_GETDETAIL		*
 * Frank 	5/5/04		QA70-6086			ADD_PARAMETER_OF_FUNCTION_NAME  	*
 * Frank	5/12/04   	QA70-6086 v8.0872	CHANGE_FORMULA_GET					*
 * Frank	5/21/04		QA70-6148 v8.0875	FEATURE_OF_SHARE_FUNCTION			*
 * Frank	5/26/04		QA70-6086 v8.0878	FUNCTION_GET_PICTURE_SOURCE_NAME	*
 * Danice 	5/27/04 	QA70-6086 V8.0878	SET_ATTRIB_AFTER_CATE_NODE_EXPAND	*
 * Danice 6/2/04 v8.0881 HIDE_CATEGORY_DESCRIPTION_FOR_TEMP						*
 *	CPY 6/5/04 USER_NAME_SHOULD_BE_LOGIN_USER_NOT_REG_USER						*
 * Danice 6/7/04 v8.0884 ALLOW_SELECTION_AFTER_UPDATE_CHANGE					*
 * Frank  6/7/04 v8.0884 UPDATE_SELECT_ROW_AFTER_DEL_INVALID_FUNCTION			*
 * Danice 6/9/04 v8.0885 ADD_EDIT_STATUS										*
 * Danice 6/9/04 v8.0885 RIGHT_CLICK_SUPPORT_SELECTION							*
 * Danice 6/18/04 v8.0890 SELECT_NEXT_SECTION_WHEN_DELETE						*
 * Frank	6/18/04 v8.0892 ADD_FUNCTION_FORM_VALUE_REPLACE_FUNCTION_TYPE		*
 * Danice 6/23/04 v8.0893 ENABLE_BUTTON_AT_FIRST_SELECTION						*
 * Danice 6/23/04 v8.0893 SUPPORT_EMPTY_FUNCTION_LIST							*
 * Danice 6/23/04 v8.0893 DISABLE_LIST_RENAME									*
 * Frank  6/25/04 v8.0895 DUPLICATE_READ_IN_FUNCTION_DETAIL						*
 * Frank 7/15/04 v8.0908 QA70-6583   UPDATE_PARAMETERS_COUNT					*
 *	YuI 7/23/04 v7.5103 QA70-6582 GETN_MULTILINE_TEXT_IMPLEMENTATION			*
 * Frank 8/2/04 v8.0908 QA70-6583   CHECK_DEL_LAST_CATEGORY						*
 * Frank 8/4/04 v8.0110 QA70-6086   ADD_OC_OPTION_IN_TYPE_LIST					*
 * Danice 10/9/04 v8.0146 USE_GETN_STRLIST										*
 * Frank 11/10/04 v8.0160 QA70-6086   REMEMBER_LAST_USE_FUNCTION				*
 * Danice 11/11/04 v8.0162 ADD_TWO_NEW_BTN										*
 * Danice 11/11/04 v8.0162 DERIVE_FROM_LIST_TREE_SPLITTER						*
 * Frank v8.0168b	12/01/04			FIXED_PROBLEM_NEWBASE_CLASS				*
 * Frank v8.0169	12/04/04			FIXED_NAMING_SHARE_PREVIEW_BUG			*
 * Frank v8.0169	12/07/04			FIXED_CODE_BUILDER_CHANGED_BUG			*
 * Danice 12/15/04 v8.0173 NUMERICFUNCTION_EX_CLASS								*
 * Danice 12/16/04 v8.0175 CODE_CLEAN_UP_REMOVE_DUPLICATE						*
 * Iris 01/18/05 CENTRALIZE_FUNCTION_NAME_CODES									*
 * DG 1/18/05 v8.0184 REMOVE_LIST_ID											*
 * DG 1/18/05 v8.0184 QA70-7331 SUPPORT_X_FUNCTION								*
 * DG 1/26/05 v8.0186 CATEGORY_NAME_SAVE_ONCE_CHANGE							*
 * DG 2/17/05 CENTRALIZE_XFO_AND_NFO											*
 * DG 2/28/05 SAVE_LIST_INSTEAD_LOADING_EACH_TIME								*
 * DG 3/1/05 APPLY_X_FUNCTION_CHANGE											*
 * DG 3/2/05 FOR_QUICK_LOADING													*
 * DG 3/9/05 v8.0201 DISABLE_GUI_INTERFACE_IN_FO								*
 * DG 3/23/05 v8.0209 CODE_REUSE_BASE_ON_BASE_CLASS_CHANGE						*
 * DG 3/30/05 v8.0212 CLEAN_DUPLICATE_MORE										*
 * DG 4/7/05 v8.0217 VC_FUNCTION_SUPPORT										*
 * DG 5/11/05 v8.0229 ENABLE_BUTTON_WHEN_EDITING								*
 * DG 6/7/06 QA70-7785 v8.0246 WEB_XF_SUPPORTED									*
 * DG 7/8/05 v8.0263 REMOVE_WEB_XF												*
 *	YuI 09/07/05 NLSF_CODE_BUILDER_COMMUNICATION_FIX							*
 * Jasmine 09/26/05 v8.0310 SPLITTER_INIT_SIZE_ON_READY							*
 * Jasmine 10/11/05 QA70-8114 v8.0315 ADD_INIT_AND_AFTER_FITTING_SCRIPTS		*
 * Jasmine 11/12/05 v8.0335 QA70-8114  REMOVE_GET_UPDATE_BUTTON					*
 * Jasmine 11/15/05 QA70-8307 v8.0335 ADD_PARAMETERS_SETTINGS					*
 * Jasmine 02/09/06 UPDATE_TO_GUI												*
 * jasmine 03/02/06 TOP_LEVEL_CHANGE											*
 * Jasmine 03/02/06 ENABLE_NEW_ADD_DEL_FOR_CATEGORY								*
 * Jasmine 04/07/06 v8.0386 SPLITTER_INIT_SIZE_NOT_CALL							*
 * Jasmine 05/18/06 v8.0411 RETURN_SEL_FUNCTION									*
 *	CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL									*
 * Hong 7/18/06 ADD_BUTTON_SIMULATE                                             *
 * Hong 7/31/06 FIX_RIGHT_DOUBLE_CLICK_DISPLAY_ERROR							*
 * Joseph 9/06/06  SAVE_USER_FUNCTION											*
 * TD 9-2-06 QA70-9012 DYNACONTROL_MULTILINEEDIT_BUTTON							*
 * Jasmine 11/01/06 FIX_FO_BUG													*
 * Jasmine 11/02/06 FUNC_AND_FILE_NAME_ONE_TO_ONE								*
 * Jasmine 11/07/06 ALLOW_RENAME_USER_DEFINED_CATEGORY							*
 * Jasmine 11/23/06 GET_SETTING_FROM_PARA_SETTING_DLG							*
 * Jasmine 11/24/06 SEL_FUNC_AFTER_OPEN											*
 * Jasmine 01/27/07 KEEP_FOCUS_IN_DYNA_CTRL										*
 * Jasmine 03/01/07 ADD_FO_HELP_TAB												*
 * AW 03/01/07 v8.0272c FIX_BUG_initOrganizerArray_IN_OC						*
 * Jasmine 03/02/07 UPDATE_DYNACONTROL_ON_FUNC_TYPE_CHANGE						*
 * Jasmine 03/05/07 ACTIVE_HELP_TAB_IF_SELECT_USER_DEFINED_FUNC					*
 * Jasmine 05/11/07 ADD_DERIVATIVES_CHECKBOX									*
 * Jasmine 05/15/07 USE_DATA_ID_REPLACE_ROW_NUM									*
 * Jasmine 05/21/07 NEED_GET_ENUM_FROM_ALL_CATEGORY								*
 * Jasmine 05/29/07 ONLY_SHOW_SPECIFIED_CATEGORY_FOR_SPECIAL_FIT 				*
 * Jasmine 06/11/07 INTERACTIVE_CHANGE_SAVING_BETWEEN_FO_AND_NLFIT				*
 * Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION						*
 * Jasmine 06/14/07 SET_RESET_BUTTON_STATUS										*
 * Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON						*
 * Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_SAVE_BUTTON						*
 * Jake 07/13/07 V8.0658 FIX_FAILED_TO_GET_DIRECTOR_POS_WHEN_CATEGORYNAME_EQU_FUNCTIONNAME	*
 * Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE*
 * Jasmine 07/24/07 TRIM_TAB_CHAR_IN_SCRIPT										*
 * Jasmine 07/24/07 FIX_BUG_NO_REVIEW_WHEN_FIRST_TIME_OPEN						*
 * Jasmine 08/08/07 DISABLE_NEW_FUNCTION_IF_SELECT_SEPARATOR_AS_CATEGORY		*
 * Jasmine 10/08/07 CANNOT_REMOVE_SHARED_FUNCTION								*
 * Folger 12/14/07 CENTRALIZED_CODE_OF_HIDING_RESERVE_CATEGORIES				*
 * Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
 * Jasmine 05/12/08 QA80-11524 TRIM_TAB_TO_FIX_TAB_MORE_AND_MORE_BUG_BUT_IT_MAKE_OTHER_BUG
 *	Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION		*
 * Jasmine 07/28/08 MODIFY_DEFINE_PEAK_FUNC_ERRMSG_BY_MAX_REQUEST				*
 * Sim 10-09-2008 QA80-12345 ADD_STAR_INDICATE_THEME_VALUE_CHANGE				*
 *	Sophy 11/6/08 QA80-12442 SHOW_WARNING_WHEN_SAVE_READ_ONLY_FILE				*
 *	Kyle 01/13/2009 v8.0995d SHOW_ERROR_MESSAGE_WHEN_THE_FILE_WITH_THE_SAME_NAME_EXISTS
 *	TD 03-06-2009 QA80-13204 FUNC_ORG_DLG_FLASHING								*
 *	Kyle 03/26/2009 QA80-13291-P4 NEW_EDIT_BOX_FOR_REFERENCES_INFORMATION		*
 *	Jasmine 04/16/09 SUSPENSION_POINTS_INDICATE_MENU_WILL_OPEN_DIALOG			*
 *	Kyle 08/06/2009 QA80-14077 ADD_UNIT_FOR_PARAMETER_SETTINGS					*
 *	Jasmine 06/13/10 ORG-305-P1 SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE				*
 *	Jasmine 06/24/10/ORG-2-S5 OPEN_FITTING_FUNCTION_WIZARD						*
 *	Folger 07/13/10 ORG-543 PROMPT_USER_FOR_WHETHER_COPY_FDF_TO_UFF_WHEN_ADD_IN_FO
 *	Jacky 07/16/10 ORG-545-P1 FIX_FO_BUILDER_BUTTON_ENABLE_AND_CHANGE_OPEN_PAGE *
 *	Sophy 7/19/2010 ORG-591-P3 PASS_SETTINGS_FROM_FO_TO_BUILDER_WHEN_NOT_SAVED	*
 *	jasmine 07/21/10 ORG-623-P1 WROMG_LOGIC_MAKE_ClearChangedGUITree_FAIL		*
 *	Folger 09/06/2010 ORG-958-P5 FAIED_TO_SAVE_FDF_NAME_NEW_FUNCION_IN_FFW_OPEN_FROM_FO
 *------------------------------------------------------------------------------*/
 

#ifndef	_FO_TREE_EDIT_SPLITTER
#define _FO_TREE_EDIT_SPLITTER

///Kevin 11/03/05
//#define STR_DLG_NAME 			"Function Organizeraaa"	//no use any more CPY 2/15/07 removed this
								
#define STR_FDF_DLG_NAME		_L("Fitting Function Organizer")
#define	STR_XF_DLG_NAME			"X-Function Organizer"
///Joseph 9/06/06  SAVE_USER_FUNCTION
#define BRANCH_INFO_NAME		0
///End SAVE_USER_FUNCTION
///-------------------------------------------------------

///DG SAVE_LIST_INSTEAD_LOADING_EACH_TIME
//#define STR_FILE_FUNCTION_LIST		GetOriginPath(ORIGIN_PATH_USER)+"FOFunctionList.xml"	///DG VC_FUNCTION_SUPPORT : we have vc level function supported now
///end SAVE_LIST_INSTEAD_LOADING_EACH_TIME

enum {
	FO_NEW_CATE=0,
	FO_SAVE,
	FO_NEW,
	FO_DUPLICATE,
	FO_ADD,
	FO_DELETE
};
enum { SAVE_SUCCESS, SAVE_FUNCTION_FAIL, SAVE_CATEGORY_FAIL };
enum { NAME_OK, AUTO_RENAME, UNDO_RENAME };
enum { LEVEL_CATEGORY, LEVEL_FUNCTION};
///Jasmine 03/21/06 ADD_FUNC_FORM
/// YuI 7/22/04 v7.5102 QA70-6404 NEW_FUNCTION_MANAGER
///Jasmine 11/15/05 QA70-8307 v8.0335 ADD_PARAMETERS_SETTINGS
///Jasmine 10/11/05 QA70-8114 v8.0315 ADD_INIT_AND_AFTER_FITTING_SCRIPTS
//enum {NAME, FILENAME, DESCRIPTION, TYPE, INDEPENDENT_VARS, DEPENDENT_VARS, PARAMETER_NAMES, PARA_INIT, FUNCTION, CONSTRAINTS, DERIVED_PARAMETERS, FUNC_SHARE, DETAIL_ITEM_TOTAL_NUM};
//enum {NAME, FILENAME, DESCRIPTION, TYPE, INDEPENDENT_VARS, DEPENDENT_VARS, PARAMETER_NAMES, PARAMETER_UPPER_BOUNDS, PARAMETER_LOWER_BOUNDS, PARA_INIT, INIT_SCRIPTS, AFTER_FITTING_SCRIPTS, FUNCTION, CONSTRAINTS, DERIVED_PARAMETERS, FUNC_SHARE, DETAIL_ITEM_TOTAL_NUM};
//enum {NAME, FILENAME, DESCRIPTION, TYPE, INDEPENDENT_VARS, DEPENDENT_VARS, PARAMETER_NAMES, PARAMETERS_SETTINGS, PARA_INIT, INIT_SCRIPTS, AFTER_FITTING_SCRIPTS, FUNCTION, CONSTRAINTS, DERIVED_PARAMETERS, FUNC_SHARE, DETAIL_ITEM_TOTAL_NUM};
//enum {NAME, FILENAME, DESCRIPTION, TYPE, INDEPENDENT_VARS, DEPENDENT_VARS, PARAMETER_NAMES, PARAMETERS_SETTINGS, PARA_INIT, INIT_SCRIPTS, AFTER_FITTING_SCRIPTS, FORM, FUNCTION, CONSTRAINTS, DERIVED_PARAMETERS, FUNC_SHARE, DETAIL_ITEM_TOTAL_NUM};	///Jasmine 05/15/07 USE_DATA_ID_REPLACE_ROW_NUM
///End ADD_INIT_AND_AFTER_FITTING_SCRIPTS
///End ADD_PARAMETERS_SETTINGS
/// end NEW_FUNCTION_MANAGER
///End ADD_FUNC_FORM

///DG 1/25/05 Row index for X-Function
//enum { FUNCNAME=0, CATENAME=0 };	///DG 3/10/05 no need
//enum { INDEX_FIT_FUNCTION, INDEX_X_FUNCTION, INDEX_WEB_XF, TOTAL_ORGANIZER_NUM };	///DG WEB_XF_SUPPORTED
enum { INDEX_FIT_FUNCTION, INDEX_X_FUNCTION, TOTAL_ORGANIZER_NUM };	///DG WEB_XF_SUPPORTED	///DG REMOVE_WEB_XF

enum {FOEDIT_READ_DETAIL, FOEDIT_DATA_DIRTY, FOEDIT_UPDATE_FINISHED };


enum {FO_FDF, FO_XF};		///Kevin Function Type

#define WM_USER_ON_UPDATE_DYNA_CONTROL	(WM_USER + 1016)	///Jasmine 03/02/07 UPDATE_DYNACONTROL_ON_FUNC_TYPE_CHANGE

//Indicate
//#define CHAR_UNSAVE_SIGN				'*' ///---Sim 10-09-2008 QA80-12345 ADD_STAR_INDICATE_THEME_VALUE_CHANGE move to oc_sys.h for use it at dynadlg.h
#define CHAR_DIVIDE_LASTUSE_ITEM		'|'

//Category tree node attribute
#define STR_GETTREE_ATTRIB 				"Expanded"
//#define STR_XF_VAR_DATA_NODEID_ATTRIB	"VarNodeID"		///DG APPLY_X_FUNCTION_CHANGE	///DG CENTRALIZE_XFO_AND_NFO

//Error message
#define ERROR_ERROR_DIAOLG				_L("Error!")
#define ERROR_WARNING_DIALOG			_L("Warning!")

#define STR_ERROR_CATEGORY_NAME_INVALID		_L("Auto rename it? Select No to Undo") //"Invalid Category Name.\nAuto rename it? Select No to Undo"
#define STR_ERROR_FUNCTION_NAME_INVALID		_L("Auto rename it? Select No to Undo") //"Invalid Function Name.\nAuto rename it? Select No to Undo"

#define STR_PROMPTS_DEL_SECTION			_L("Are you sure you want to delete?\nCannot undo operation!")

#define DYNA_CONTROL_CONTENET_CHANGE	-1	//-----Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE

///Jasmine 06/28/10/ORG-2-S5 OPEN_FITTING_FUNCTION_WIZARD
///------ Folger 09/06/2010 ORG-958-P5 FAIED_TO_SAVE_FDF_NAME_NEW_FUNCION_IN_FFW_OPEN_FROM_FO
//typedef	bool (*FP_TREENODE_HWND)(TreeNode& trFunc, HWND hWndParent = NULL, int nMode = 0);
///------ End FAIED_TO_SAVE_FDF_NAME_NEW_FUNCION_IN_FFW_OPEN_FROM_FO
///End OPEN_FITTING_FUNCTION_WIZARD

//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
enum	//context menu
{
	FO_MENU_MOVE,
	FO_MENU_SHARE,
	FO_MENU_DUPLICATE,
	FO_MENU_REMOVE,
};
//------

class FOListControlMenu : public MenuBase
{
public:
	FOListControlMenu(int nRow, int nCol, bool bAllowSave, bool bDisableChangeListItem=false, bool bSelCate = false, bool bShared = false) : MenuBase()
	{
		//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
		/////Jasmine 03/02/06 ENABLE_NEW_ADD_DEL_FOR_CATEGORY
		////now the top level is category, should allow new and add function, and delete
		//int nChangeListItemFlags=bDisableChangeListItem ? MF_GRAYED | MF_DISABLED : MF_ENABLED;
		///*
		//if(bSelCate)
			//Add(_L("New Category"), OnMenuItem);
		////Add(_L("Save"), OnMenuItem);
		//Add(_L("Save"), OnMenuItem, bAllowSave ? MF_ENABLED : MF_GRAYED | MF_DISABLED);
		//if(bSelCate)
			//Add(_L("New Function"), OnMenuItem, nChangeListItemFlags);
		//else
			//Add(_L("New"), OnMenuItem, nChangeListItemFlags);
		//Add(_L("Duplicate"), OnMenuItem, nChangeListItemFlags);
		//Add(_L("Add"), OnMenuItem, nChangeListItemFlags);
		//Add(_L("Delete"), OnMenuItem, bAllowSave && !bDisableChangeListItem ? MF_ENABLED : MF_GRAYED | MF_DISABLED);
		//*/
		//Add(_L("New Category"), OnMenuItem);
		//Add(_L("Save"), 		OnMenuItem, bAllowSave ? MF_ENABLED : MF_GRAYED | MF_DISABLED);
		//Add(_L("New Function"), OnMenuItem);
		//Add(_L("Duplicate"), 	OnMenuItem, nChangeListItemFlags);
		//Add(_L("Add"), 			OnMenuItem);
		//Add(_L("Delete"), 		OnMenuItem, bAllowSave ? MF_ENABLED : MF_GRAYED | MF_DISABLED);
		/////End ENABLE_NEW_ADD_DEL_FOR_CATEGORY
		if ( !bSelCate )
		{
			///Jasmine 04/16/09 SUSPENSION_POINTS_INDICATE_MENU_WILL_OPEN_DIALOG
			Add(_L("Move To") + STR_THREE_DOTS, OnMenuItem, bShared ? MF_GRAYED | MF_DISABLED : MF_ENABLED);
			Add(_L("Share To") + STR_THREE_DOTS, OnMenuItem, bShared ? MF_GRAYED | MF_DISABLED : MF_ENABLED);
			///End SUSPENSION_POINTS_INDICATE_MENU_WILL_OPEN_DIALOG
			Add(_L("Duplicate"), OnMenuItem);
			Add(_L("Remove"), OnMenuItem, bShared ? MF_GRAYED | MF_DISABLED : MF_ENABLED);
		}
		//------ End ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
	}

	int DoTrackPopup(int nx, int ny, HWND hWndParent)
	{
		TrackPopupMenu(0,  nx, ny, hWndParent);
		int nCmd;
		if(!GetCommand(nCmd))
			return -1;
		
		return nCmd;
	}
	
};

class GridTreeFunctionList : public GridTreeControl
{
public:
	void Init(int nID, WndContainer& dlg)
	{
		m_nId = nID;
		GridTreeControl::Init(nID, dlg);

		m_flx.SelectionMode = flexSelectionByRow;
		//m_flx.AllowSelection = true;
		//m_flx.Editable = flexEDKbdMouse;	///Danice DISABLE_LIST_RENAME
		m_flx.Editable = flexEDNone;
		
	}
	
	bool IsReady()
	{
		return m_trList.IsValid();
	}
	
	void SetCollapsed(int nRow, int nState = flexOutlineCollapsed)
	{
		SetIsCollapsed(nRow, nState);
	}
	
	int GetCollapsed(int nRow)
	{
		if(!IsInGrid(nRow, 0))
			return -1;
		return GetIsCollapsed(nRow);
	}
	
	void ShowNewMember(TreeNode& trNew, int nRow)
	{
		SelRow(nRow);
	}
	
	void SetSectionUnsave(TreeNode& trFunc, int nRow)
	{
		if(!trFunc )
			return;
		string strTemp;
		if(!trFunc.GetAttribute(STR_CHANGED_ATTRIB, strTemp))
			trFunc.SetAttribute(STR_CHANGED_ATTRIB, "");
		string str = GetCell(nRow, 0); //m_flx.Text;
		if(0 != str.Right(1).Compare((string)CHAR_UNSAVE_SIGN))
		{
			str+=(string)CHAR_UNSAVE_SIGN;
			SetCell(nRow, 0, str);
		}
	}
	
	bool ClearUnsaveSign(TreeNode& trFunc, int nFuncInRow)
	{
		string strFile;
		if(trFunc.IsValid() && !trFunc.GetAttribute(STR_CHANGED_ATTRIB, strFile))
		{
			//If save success, clear unsave sign
			strFile = GetCell(nFuncInRow, 0);
			if(0 == strFile.Right(1).Compare((string)CHAR_UNSAVE_SIGN))
			{
				strFile.TrimRight(CHAR_UNSAVE_SIGN);
				SetCell(nFuncInRow, 0, strFile);
			}
			return true;
		}
		return false;
	}
	void DelRows(int nRow)
	{
		int nCurLevel=GetLevel(nRow);
		
		int nRows = m_flx.Rows;
		for(; nRows > nRow+1 && nCurLevel < GetLevel(nRow+1);)	//delete row
		{
			m_flx.RemoveItem(nRow+1);
			nRows--;
		}
		if((nRows <= nRow+1 || nCurLevel != GetLevel(nRow+1)) && 0 < nRow)	//select previous row if the del row is the end, else, select next row
		{
			//for(int nSelRow = nRow-1; nCurLevel != GetLevel(nSelRow); nSelRow--)	///DG 2/1/05 single node of parent, should sel parent
			for(int nSelRow = nRow-1; nCurLevel < GetLevel(nSelRow); nSelRow--)
				;
			m_flx.Row = nSelRow;
		}
		m_flx.RemoveItem(nRow);
	}
	void DelRow(int nRow)
	{
		int nCurLevel=GetLevel(nRow);
		if(nCurLevel != GetLevel(nRow+1))
			m_flx.Row = nRow - 1;
		m_flx.RemoveItem(nRow);
	}
	int RemoveItem(vector<int> vnIndex, int nFromRow)
	{
		int nTotalRemove=0;
		for(int ii=0; ii<vnIndex.GetSize(); ii++)
		{
			m_flx.RemoveItem(nFromRow+vnIndex[ii]-nTotalRemove);
			nTotalRemove++;
		}
		return nTotalRemove;
	}
	///DG FOR_QUICK_LOADING
	/*
	//nParentRow=-1 means find in top level
	int FindChildRow(string strName, int nParentRow=-1)
	{
		int nChildLevel=GetLevel(nParentRow)+1;
		int nFind=FindRow(strName, 0, false, true, nParentRow);
		for(; (-1 != nFind) && (GetLevel(nFind) != nChildLevel || GetParent(nFind) != nParentRow); )
			nFind=FindRow(strName, 0, false, true, nFind+1);
		
		return nFind;
	}
	*/
	///end FOR_QUICK_LOADING
	///Jasmine 05/29/07 ONLY_SHOW_SPECIFIED_CATEGORY_FOR_SPECIAL_FIT 
	bool ShowSelCategory(int nSelRow)
	{
		if(-1 == nSelRow)
			return false;
		int nCategoryRow = LEVEL_CATEGORY == GetLevel(nSelRow)? nSelRow : GetParent(nSelRow);
		if(-1 == nCategoryRow)
			return false;
		int nRows = GetRows();
		HideRow();
		HideRow(nCategoryRow, false);
		for(int nRow = nCategoryRow + 1; nRows > nRow && LEVEL_FUNCTION == GetLevel(nRow); nRow++)
			HideRow(nRow, false);
		return true;
	}
	///End ONLY_SHOW_SPECIFIED_CATEGORY_FOR_SPECIAL_FIT
	
	//------ Folger 12/14/07 CENTRALIZED_CODE_OF_HIDING_RESERVE_CATEGORIES
	bool HideReserveCategories()
	{
		string strCateReserve = STR_CATE_RESERVE;
		vector<string> vsCateReserve;
		strCateReserve.GetTokens(vsCateReserve, '|');
		for (int ii=0; ii<vsCateReserve.GetSize(); ++ii)
		{
			int nRow = FindRow(vsCateReserve[ii]);
			if (nRow < 0)
				continue;
			HideRow(nRow++);
			for (; GetLevel(nRow) == LEVEL_FUNCTION; nRow++)
				HideRow(nRow);
		}
		return true;
	}
	//------
	
private:
	TreeNode	m_trList;
	int 		m_nId; // child ID of control

};

//------ Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION
class BooleanRestoreHelper
{
public:
	BooleanRestoreHelper(bool& b)
	{
		m_pb = &b;
		m_bValue = b;
		b = false;
	}
	
	~BooleanRestoreHelper()
	{
		*m_pb = m_bValue;
	}
	
private:
	bool	*m_pb;
	bool	m_bValue;
};
//------ End FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION



/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
//	class FunctionListSplitter : public TreeDynaSplitter //ListTreeEditSplitter	///TreeEditSplitter //CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
class FunctionListSplitter : public TreeDynaSplitterWithCBCommunication //ListTreeEditSplitter	///TreeEditSplitter //CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
{
public:
	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	//	FunctionListSplitter() : TreeDynaSplitter()//ListTreeEditSplitter()
	//	{
	//	}
	FunctionListSplitter()
	{
	}
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	
	~FunctionListSplitter()
	{
		//SaveDefaultSettings();	///DG 3/11/05 move save and load default into base class
		SaveDefaultSettings(CHAR_DIVIDE_LASTUSE_ITEM, STR_FDF_DLG_NAME);
		//saveFunctionList();	///DG VC_FUNCTION_SUPPORT
	}
	///Jasmine 09/26/05 v8.0310 SPLITTER_INIT_SIZE_ON_READY
	void OnReady()
	{
		//ListTreeEditSplitter::OnReady();
		/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
		//	TreeDynaSplitter::OnReady();
		TreeDynaSplitterWithCBCommunication::OnReady();
		/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	}
	///End SPLITTER_INIT_SIZE_ON_READY
	
	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	/*
	TreeNode	GetSelFuncDetail()
	{
		return m_trFunctionDetail;
	}
	*/
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	bool UpdateFunctionDetail( TreeNode &trFunction)
	{
		m_trFunctionDetail.Reset();
		if(GetCurrentFO().IsFunction(trFunction))
		{
			///DG 8/17/05 : use current function detail
			/*
			Tree tr;
			TreeNode trFunctionDetail=tr.AddNode(GetCurrentFO().GetFunctionName(trFunction));
			
			//GetCurrentFO().NumFunctionOrganizer::Load(trFunctionDetail, GetCurrentFO().GetFuncFileName(trFunction, true)); ///DG QA70-7430 now temp use as following, there are bug this using
			NumFunctionOrganizer nfo;
			if(nfo.Load(trFunctionDetail, GetCurrentFO().GetFuncFileName(trFunction, true)))
			{
				m_trFunctionDetail.AddNode(trFunctionDetail);
				return true;
			}
			*/
			if(GetCurrentFO().ConstructFunctionDetail(trFunction, m_trFunctionDetail))
				return true;
			///end
		}
		return false;
	}
	void GetButtonStatus(vector<bool> &vbBtnStatus)
	{
		vbBtnStatus.SetSize(TOTAL_BTN_NUM);
		
		///DG WEB_XF_SUPPORTED
		FunctionOrganizer& fo = GetCurrentFO();
		if(fo.IsReadOnlyFunction())
		{
			vbBtnStatus = false;
			return;
		}
		///end WEB_XF_SUPPORTED
		bool bCanRemove = !fo.IsSharedFunction(m_trSel);	///Jasmine 10/08/07 CANNOT_REMOVE_SHARED_FUNCTION
		bool bSystem = fo.IsSysFunction(m_trSel);	///Jasmine 06/14/07 SET_RESET_BUTTON_STATUS
		bool bUnEditableSysFunc=fo.IsUnEditableSysFunction(m_trSel);
		bool bClickTopLevel=m_trList.GetLevel(m_nSelRow) == 0;
		//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_SAVE_BUTTON
		//vbBtnStatus[INDEX_BTN_SAVE]= !bUnEditableSysFunc;
		vbBtnStatus[INDEX_BTN_SAVE]= !bUnEditableSysFunc && fo.CheckChanged(m_trSel);
		//--------end MORE_CONSTRAINTS_TO_ENABLE_SAVE_BUTTON
		vbBtnStatus[INDEX_BTN_NEW_CATE]= true;
		///Jasmine 03/02/06 ENABLE_NEW_ADD_DEL_FOR_CATEGORY, now the top level is category
		vbBtnStatus[INDEX_BTN_NEW_FUNC]= true;//!bClickTopLevel;
		///Sophy 7/19/2010 ORG-545-P1 PROPER_UPDATE_BUILDER_BUTTON_STATE_ON_SEL_CHANGE
		//vbBtnStatus[INDEX_BTN_WIZARD]= true;///Jasmine 06/24/10/ORG-2-S5 OPEN_FITTING_FUNCTION_WIZARD
		vbBtnStatus[INDEX_BTN_WIZARD]= !bSystem && !bClickTopLevel;
		///end PROPER_UPDATE_BUILDER_BUTTON_STATE_ON_SEL_CHANGE
		vbBtnStatus[INDEX_BTN_DUPL]= !bClickTopLevel;	//only available for function
		vbBtnStatus[INDEX_BTN_ADD]= true;//!bClickTopLevel;
		//vbBtnStatus[INDEX_BTN_DEL]= !bUnEditableSysFunc;//!bClickTopLevel && !bUnEditableSysFunc;
		vbBtnStatus[INDEX_BTN_DEL]= !bUnEditableSysFunc && bCanRemove;	///Jasmine 10/08/07 CANNOT_REMOVE_SHARED_FUNCTION
		///Hong 7/18/06 ADD_BUTTON_SIMULATE
		vbBtnStatus[INDEX_BTN_SIMULATE]= !bClickTopLevel && -1 < GetSimulateType();//true;
		///end ADD_BUTTON_SIMULATE
		///End ENABLE_NEW_ADD_DEL_FOR_CATEGORY
		//vbBtnStatus[INDEX_BTN_GET_UPDATES]= fo.IsCheckForUpdatedSupported();///DG CHECK_FOR_UPDATES	///Jasmine 11/12/05 v8.0335 QA70-8114  REMOVE_GET_UPDATE_BUTTON
		//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
		//vbBtnStatus[INDEX_BTN_RESET] = (!bClickTopLevel && bSystem);	///Jasmine 06/14/07 SET_RESET_BUTTON_STATUS
		vbBtnStatus[INDEX_BTN_RESET] = (!bClickTopLevel && bSystem && (fo.CheckChanged(m_trSel) || getCustomizeFuncNameIndex(m_trSel) >= 0));
		//--------end MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
	}
	///Jasmine 10/19/07 QA70-10558 CHECK_INDEPENDENT_VARIABLE_NUMBER_TO_OPEN_SIMCURVE
	int GetSimulateType()
	{
		return GetCurrentFO().GetSimulateType(m_trSel);
	}
	///End CHECK_INDEPENDENT_VARIABLE_NUMBER_TO_OPEN_SIMCURVE
	void LoadDefaultFunctionRow()
	{
		vector<string> vsLastUseItem;
		if(!LoadDefaultSettings(vsLastUseItem, CHAR_DIVIDE_LASTUSE_ITEM, STR_FDF_DLG_NAME))
		{
			m_trList.SelRow(0);
			return;
		}
		
		int nParentRow=-1, nSize=vsLastUseItem.GetSize(), nSelRow;
		///DG FOR_QUICK_LOADING
		//GetCurrentFO(atoi(vsLastUseItem[nSize-1]), true);// too early
		for(int ii=nSize-1; ii>0; ii--)
		{
			///Jasmine 06/13/10 ORG-305-P1 SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
			//nParentRow=atof(vsLastUseItem[ii]);
			nParentRow = m_trList.FindRow(vsLastUseItem[ii], 0, true, true, nParentRow);			
			///End SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
			
			if(0 > nParentRow)
				break;
			m_trList.SetCollapsed(nParentRow, flexOutlineExpanded);
		}
		
		///Jasmine 06/13/10 ORG-305-P1 SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
		//nSelRow=atof(vsLastUseItem[0]);
		nSelRow = m_trList.FindRow(vsLastUseItem[0], 0, true, true, nParentRow);			
		///End SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
		if(m_trList.GetParent(nSelRow) != nParentRow)
			nSelRow=nParentRow;
		///end FOR_QUICK_LOADING
		
		///Jasmine 06/13/10 ORG-305-P1 SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
		if(0 > nSelRow || nSelRow >= m_trList.GetRows())
		{
			nSelRow = nParentRow;
			if(0 > nParentRow || nParentRow >= m_trList.GetRows())
				nSelRow = 0;
		}
		///End SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
		m_trList.SelRow(nSelRow);
	}
	///Jasmine 06/11/07 INTERACTIVE_CHANGE_SAVING_BETWEEN_FO_AND_NLFIT
	bool ResetSelSection()
	{
		PROFILE_HRGLASS
		if(GetCurrentFO().IsFunction(m_trSel))
		{
			if(GetCurrentFO().Reset(m_trSel))
			{
				ShowListContent();
				onFunctionSave();
				//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
				int nIndex = getCustomizeFuncNameIndex(m_trSel);
				if (nIndex >= 0)
					m_vsFuncName.RemoveAt(nIndex);
				//--------end MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
			}
		}
		else
		{
			GetCurrentFO().ResetCategory(m_trSel);
			clearSectionUnSaveSign(m_trSel, m_nSelRow);
		}
		ClearChangedGUITree(m_trSel);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		return true;
	}
	///End INTERACTIVE_CHANGE_SAVING_BETWEEN_FO_AND_NLFIT
	bool SaveSelSection()	//check change
	{
		PROFILE_HRGLASS
		string strPrompts;
		if(!checkchanged(m_trSel))
			return true;
		if(GetCurrentFO().IsFunction(m_trSel))
		{
			///Sophy 11/6/08 QA80-12442 SHOW_WARNING_WHEN_SAVE_READ_ONLY_FILE 
			//if(!GetCurrentFO().Save(m_trSel))
				//strPrompts=_L("Save Function fail!");
			if(!GetCurrentFO().Save(m_trSel, NULL, &strPrompts ))
				; //Sophy, failed, do noting
			///end SHOW_WARNING_WHEN_SAVE_READ_ONLY_FILE
			else
			{	//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
				onFunctionSave();
			//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
				string strFunction;
				m_trSel.GetAttribute(STR_LABEL_ATTRIB, strFunction);
				m_vsFuncName.Add(strFunction);
			}
			//--------end MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
		}
		else
		{
			vector<string> vsSaveFail;
			GetCurrentFO().SaveCategory(m_trSel, vsSaveFail);
			if(0 < vsSaveFail.GetSize())
				strPrompts=getSaveFailPromptsStr(vsSaveFail);
			clearSectionUnSaveSign(m_trSel, m_nSelRow);
		}
		if(!strPrompts.IsEmpty())
			return onSaveFail(strPrompts);
		ClearChangedGUITree(m_trSel);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		return true;
	}
	bool SaveAll()
	{
		PROFILE_HRGLASS
		string strPrompts;
		vector<string> vsSaveFail;
		saveAllCategory(vsSaveFail);
		if(vsSaveFail.GetSize() > 0)
			strPrompts=getSaveFailPromptsStr(vsSaveFail);
		clearSectionUnSaveSign(GetListTree(), 0);
		if(!strPrompts.IsEmpty())
			return onSaveFail(strPrompts);
		return true;
	}
	//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
	//bool DelSelSection()
	bool DelSelSection(bool bShowMsg = true, bool bRemoveFile = true)
	//------
	{
		bool bFunction = GetCurrentFO().IsFunction(m_trSel);
		TreeNode trTopCategory=m_trSel.Parent();
		bool bLastCategory=isTopLevelCategory(trTopCategory) && trTopCategory.GetNodeCount()<=1;
		if(bLastCategory)
		{
			string strShowMsg = _L("Can't delete last category!");
			MessageBox( GetSafeHwnd(), strShowMsg, ERROR_WARNING_DIALOG, MB_OK) ;//== IDOK )
			return false;
		}
		//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
		if ( bShowMsg )
		{
		//------
			if(IDNO == MessageBox(GetSafeHwnd(), STR_PROMPTS_DEL_SECTION, ERROR_ATTENTION_DIAOLG, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION))
				return false;
		//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
		}
		//------
		bool bSuccess=false;
		PROFILE_HRGLASS
		//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
		string strLabel;
		m_trSel.GetAttribute(STR_LABEL_ATTRIB, strLabel);
		int nRows = m_trList.GetRows();
		int nCopyCount = 0;
		for(int nRow = 0; nRow < nRows; nRow++)//set other row with same label(the same function)
		{
			TreeNode trRow = GetTreeNode(nRow);
			if(trRow && GetCurrentFO().IsFunction(trRow))
			{
				string strTemp;
				trRow.GetAttribute(STR_LABEL_ATTRIB, strTemp);
				if ( strTemp.CompareNoCase(strLabel) == 0 )
					++nCopyCount;
			}
		}
		bRemoveFile &= (nCopyCount == 1);
		//------
		if(bFunction)
			bSuccess=GetCurrentFO().Delete(m_trSel, bRemoveFile);
		else
			bSuccess=GetCurrentFO().DeleteCategory(m_trSel, bRemoveFile);
		///jasmine 07/21/10 ORG-623-P1 WROMG_LOGIC_MAKE_ClearChangedGUITree_FAIL
		if(bSuccess)
		{
			//m_trSel.Remove();
			{
				//------ Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION
				BooleanRestoreHelper	bHelper(m_bReady);
				//------
				if(bFunction)
					m_trList.DelRow(m_nSelRow);
				else
					m_trList.DelRows(m_nSelRow);
			}
		
			ClearChangedGUITree(m_trSel, false);
			m_trSel.Remove();
			
			forceSelection();
		}
		//ClearChangedGUITree(m_trSel, false);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		///End WROMG_LOGIC_MAKE_ClearChangedGUITree_FAIL
		return true;
	}
	void NewCategory()
	{
		PROFILE_HRGLASS
		int nn;
		TreeNode trCategorys=getCategoryParent(nn, GetCurrentFO().IsAllowedMultiLevelCategory());
		if(!trCategorys)
			return ;
		string strNodeName=tree_get_enum_node_name(trCategorys, STR_NODE_CATEGORY);
		string strName=tree_get_enum_attribute_value(trCategorys, STR_LABEL_ATTRIB, STR_NEW_CATEGORY_PREFIX);
		TreeNode trNewCate=trCategorys.AddNode(strNodeName);
		if(GetCurrentFO().NewCategory(trNewCate, strName))
			addNewToList(trNewCate);
		else
			trNewCate.Remove();
	}
	void NewFunction()
	{
		PROFILE_HRGLASS
		int nCategoryRow;
		TreeNode trCate=getCategory(nCategoryRow);
		if(!trCate)
			return ;
		
		///Jasmine 08/08/07 DISABLE_NEW_FUNCTION_IF_SELECT_SEPARATOR_AS_CATEGORY
		string strCate;
		trCate.GetAttribute(STR_LABEL_ATTRIB, strCate);
		if(-1 < m_vsSeparators.Find(strCate))
			return ;		
		///End DISABLE_NEW_FUNCTION_IF_SELECT_SEPARATOR_AS_CATEGORY
		string strNodeName=tree_get_enum_node_name(trCate, STR_NODE_FUNCTION), strFuncName;
		TreeNode trFunc=trCate.AddNode(strNodeName);
		//strFuncName=tree_get_enum_attribute_value(trCate, STR_LABEL_ATTRIB, GetCurrentFO().GetFunctionNameStr(STR_NEW_FUNCTION_PREFIX, USER_FOLDER));
		strFuncName = GetCurrentFO().CreateNewFunctionName(trCate.Parent(), STR_LABEL_ATTRIB, STR_NEW_FUNCTION_PREFIX, " (User)");//Hong 8/01/06 FIX_NEW_FUNCTION_NAME	///Jasmine 05/21/07 NEED_GET_ENUM_FROM_ALL_CATEGORY
		GetCurrentFO().New(trFunc, strFuncName);
		addNewToList(trFunc);
		
		//if(!checkCollapsed(trCate))
			//setCollapsed(trCate);
		Control ctrl;
		OnAfterCollapse(ctrl, nCategoryRow, 0);	//change category icon
	}
	///Jasmine 06/28/10/ORG-2-S5 OPEN_FITTING_FUNCTION_WIZARD
	void NewFunctionInWizard()
	{
		PROFILE_HRGLASS
		
		//open wizard
		
		//--- Jacky 07/16/10 ORG-545-P1 FIX_FO_BUILDER_BUTTON_ENABLE_AND_CHANGE_OPEN_PAGE 
		Tree trFDF;
		///Sophy 7/19/2010 ORG-591-P3 PASS_SETTINGS_FROM_FO_TO_BUILDER_WHEN_NOT_SAVED
		//string strSel = GetSel(false);
		//string strFunctionName = strSel.GetToken(1, '|');
	    //string strFDFFile;
 		//string strCategory;
 		//if ( !nlf_get_fdf_filename(strFunctionName, &strCategory, NULL, &strFDFFile) || 			
 			//!nlsf_load_FDF_to_tree(strFDFFile, &trFDF, FDFT_CONVERT_BOOL_TO_01, true))
 		//trFDF.SetAttribute(STR_CATEGORY_ATTRIB, strCategory);
 		//trFDF.SetAttribute(STR_FILENAME_ATTRIB, strFDFFile);
 		///end PASS_SETTINGS_FROM_FO_TO_BUILDER_WHEN_NOT_SAVED
 		string strCategory = GetCurrentFO().GetLabel(m_trSel.Parent());
 		if ( !GetCurrentFO().ConstructFunctionDetail(m_trSel, trFDF) )
 		{
 			ASSERT(FALSE);
 		}
 		trFDF.SetAttribute(STR_CATEGORY_ATTRIB, strCategory);
 		//--- end FIX_FO_BUILDER_BUTTON_ENABLE_AND_CHANGE_OPEN_PAGE
 		///Sophy 7/27/2010 ORG-591-P3 PEAKFUNCTION_CHECKBOX_STATE_NOT_KEEP_FROM_FO_TO_FFW_WHEN_NOT_VALID_PEAKFUNCTION
 		int nPeakFunction = 0;
 		TreeNode trPeakFunction = m_trSel.GetNode(STR_PEAK_CHECK_ATTRIB);
 		if ( trPeakFunction )
 			nPeakFunction = trPeakFunction.nVal;
 		trFDF.SetAttribute(STR_PEAK_CHECK_ATTRIB, nPeakFunction);
 		///end PEAKFUNCTION_CHECKBOX_STATE_NOT_KEEP_FROM_FO_TO_FFW_WHEN_NOT_VALID_PEAKFUNCTION
		///Sophy 7/13/2010 ORG-545-P1 SUPPORT_CREATE_OR_EDIT_ON_GOAL_PAGE
		FUNC_OPEN_FFW _pfn = Project.FindFunction("OpenFitFuncWizDlg", "Originlab\\FitFuncWiz.c", true);
		//FP_TREENODE_HWND _pfn = Project.FindFunction("OpenFFWDlgWithGoalPage", "Originlab\\FitFuncWiz.c", true);
		///end SUPPORT_CREATE_OR_EDIT_ON_GOAL_PAGE
		///------ Folger 09/06/2010 ORG-958-P5 FAIED_TO_SAVE_FDF_NAME_NEW_FUNCION_IN_FFW_OPEN_FROM_FO
		//if( !_pfn || !_pfn(trFDF, GetSafeHwnd()) )
		NumFunctionOrganizer&	NFO = (NumFunctionOrganizer&)GetCurrentFO();
		if( !_pfn || !_pfn(trFDF, GetSafeHwnd(), 0, &NFO) )
		///------ End FAIED_TO_SAVE_FDF_NAME_NEW_FUNCION_IN_FFW_OPEN_FROM_FO
			return;			
			
		//find category
		trFDF.GetAttribute(STR_CATEGORY_ATTRIB, strCategory);
		if(-1 < m_vsSeparators.Find(strCategory))
			return ;		
		
		TreeNode trCate;
		int nCategoryRow = m_trList.FindRow(strCategory);
		if(0 <= nCategoryRow)
		{
			trCate = GetTreeNode(nCategoryRow);
		}
		else
		{
			string strNodeName = tree_get_enum_node_name(m_trFunctions, STR_NODE_CATEGORY);
			trCate = m_trFunctions.AddNode(strNodeName);
			if(GetCurrentFO().NewCategory(trCate, strCategory))
				addNewToList(trCate);
			else
			{
				trCate.Remove();
				return;
			}
			nCategoryRow = m_trList.FindRow(strCategory);
		}
		if(!trCate)
			return ;
		
		//add function
		string strFuncName, strFDFname, strFileName;
		nlf_get_func_names(trFDF, strFuncName, strFDFname, &strFileName);
		///Sophy 7/15/2010 ORG-543-P3 EDIT_USER_FDF_FROM_FO_SHOULD_NOT_ADD_DUPLICATED_COPY
		TreeNode trOldFunction = trCate.FindNodeByAttribute(STR_FILENAME_ATTRIB, strFileName, FALSE);
		if ( trOldFunction )
		{
			trOldFunction.Reset(true);
			GetCurrentFO().Load(trOldFunction, strFileName, strFuncName); //reload
		}
		else
		{
		///end EDIT_USER_FDF_FROM_FO_SHOULD_NOT_ADD_DUPLICATED_COPY
			string strNodeName = tree_get_enum_node_name(trCate, STR_NODE_FUNCTION);
			TreeNode trNewFunction = trCate.AddNode(strNodeName);
			if(GetCurrentFO().Add(trNewFunction, strFileName, strFuncName))
			{
				GetCurrentFO().SetLabel(trNewFunction, ""); //clear for getting an un-repeat name
				strFuncName = GetCurrentFO().GetFunctionNameStr(strFuncName, okutil_get_origin_path_type(strFuncName));
				GetCurrentFO().SetLabel(trNewFunction, strFuncName);
				addNewToList(trNewFunction, false, -1, true, &nCategoryRow);
			}
			else
				trNewFunction.Remove();
		}

		if(!checkCollapsed(trCate))
			setCollapsed(trCate);
		SetSectionUnsave(m_trSel, false);	///Sophy 7/19/2010 ORG-591-P3 PASS_SETTINGS_FROM_FO_TO_BUILDER_WHEN_NOT_SAVED
		UpdateDynaControl(true, GETNEVENT_ON_INIT, true, 0, false);	///Sophy 7/15/2010 ORG-543-P3 EDIT_USER_FDF_FROM_FO_SHOULD_NOT_ADD_DUPLICATED_COPY
	}
	///End OPEN_FITTING_FUNCTION_WIZARD
	
	//Copy a function or category
	void DuplicateSection()
	{
		PROFILE_HRGLASS
		TreeNode trNew;
		int nCategoryRow;
		TreeNode trParent;
		string strNodeName, strName;
		if(GetCurrentFO().IsFunction(m_trSel))
		{
			trParent=getCategory(nCategoryRow);
			if(!trParent)
				return ;
			strNodeName=tree_get_enum_node_name(trParent, STR_NODE_FUNCTION);
			trNew=trParent.AddNode(strNodeName);
			strName=tree_get_enum_attribute_value(trParent, STR_LABEL_ATTRIB, GetCurrentFO().GetFunctionNameStr(STR_DUPLICATE_PREFIX+GetCurrentFO().GetFunctionName(m_trSel), USER_FOLDER));
			if(!GetCurrentFO().Duplicate(trNew, m_trSel, strName))
			{
				trNew.Remove();
				return;
			}
		}
		else
		{
			trParent=getCategoryParent(nCategoryRow);
			if(!trParent)
				return ;
			///DG 3/7/05 REMOVE_REPEAT : sys function save into user, when duplicate, remove one
			Tree tr;
			tr.AddNode(m_trSel);
			TreeNode tnSrc=tr.FirstNode;
			removeRepeatFunction(tnSrc);
			///end REMOVE_REPEAT
			strNodeName=tree_get_enum_node_name(trParent, STR_NODE_CATEGORY);
			trNew=trParent.AddNode(strNodeName);
			strName=tree_get_enum_attribute_value(trParent, STR_LABEL_ATTRIB, STR_DUPLICATE_PREFIX+GetCurrentFO().GetLabel(m_trSel));
			if(!GetCurrentFO().DuplCategory(trNew, tnSrc, strName))
			{
				trNew.Remove();
				return;
			}
			setCollapsed(trNew);
		}
		addNewToList(trNew);
	}
	bool AddFunction()
	{
		int nCategoryRow;
		TreeNode trNew, trCurrentCate=getCategory(nCategoryRow);
		if(!trCurrentCate)
			return false;
		vector<string> vsFuncFile;
		string strNodeName, strFuncName;
		if(0 < GetCurrentFO().GetMultiOpenBox(vsFuncFile))
		{
			PROFILE_HRGLASS
			for(int ii=0; ii<vsFuncFile.GetSize(); ii++)
			{
				///Jasmine 11/02/06 FIX_FO_BUG
				//check function name
				strFuncName = GetCurrentFO().GetFunctionName(vsFuncFile[ii]);
				string strError;
				bool bOK = true;
				while(!GetCurrentFO().CheckFuncName(strFuncName, trCurrentCate, &strError, vsFuncFile[ii]))
				{
					bOK = false;
					if(!strError.CompareNoCase(STR_ERROR_NAME_EXIST))
					{//the function is already in this category
						MessageBox(GetSafeHwnd(), strError, ERROR_ATTENTION_DIAOLG, MB_OK | MB_ICONEXCLAMATION);
						break;
					}
					string strWarning;
					strWarning.Format(_L("The function name \"%s\" is used by another function."), strFuncName);
					GETN_TREE(trRename)
					GETN_STR(Warn, "", strWarning)	GETN_READ_ONLY_COLOR
					GETN_STR(Name, _L("Function Name"), strFuncName)
					if(!GetNBox(trRename, _L("Rename")))//, strWarning, NULL, NULL, NULL))
						break;
					bOK = true;
					strFuncName = trRename.Name.strVal;
				}
				if(!bOK)
					continue;
				//check file
				string strUserFolder = GetCurrentFO().GetFunctionFolder(USER_FOLDER) + strFuncName + "." + STR_FIT_FUNCTION_FILE_EXT;
				if(strUserFolder.CompareNoCase(vsFuncFile[ii]) && strUserFolder.IsFile())
				{
					if(IDNO == MessageBox(GetSafeHwnd(), "Would you like to replace the existing file\n"+strUserFolder+" ?", ERROR_ATTENTION_DIAOLG, MB_YESNO | MB_ICONEXCLAMATION))
						continue;
				}				
				strNodeName=tree_get_enum_node_name(trCurrentCate, STR_NODE_FUNCTION);
				trNew=trCurrentCate.AddNode(strNodeName);
				if(GetCurrentFO().Add(trNew, vsFuncFile[ii], strFuncName))
				{
					GetCurrentFO().SetLabel(trNew, ""); //clear for getting an un-repeat name
					//strFuncName=tree_get_enum_attribute_value(trCurrentCate, STR_LABEL_ATTRIB, GetCurrentFO().GetFunctionNameStr(GetCurrentFO().GetFunctionName(trNew), USER_FOLDER));
					//strFuncName=tree_get_enum_attribute_value(trCurrentCate, STR_LABEL_ATTRIB, GetCurrentFO().GetFunctionName(trNew), " (User)");
					//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
					//strFuncName = GetCurrentFO().GetFunctionNameStr(strFuncName, USER_FOLDER);
					strFuncName = GetCurrentFO().GetFunctionNameStr(strFuncName, okutil_get_origin_path_type(vsFuncFile[ii]));
					//------
					GetCurrentFO().SetLabel(trNew, strFuncName);
					addNewToList(trNew);
				}
				else
					trNew.Remove();
			}
			if(!checkCollapsed(trCurrentCate))
				setCollapsed(trCurrentCate);
		}
		return true;
	}
	
	bool CheckIfUnSave()
	{
		//------------- CPY 9/2/05 GRAPH_TREE_SPLITTER_SAMPLE_CODE_CLEANUP
		//foreach(TreeNode tr in m_trFunctions.Children)
		TreeNode trFunc = GetListTree();
		foreach(TreeNode tr in trFunc.Children)
		//-------------
		{
			foreach(TreeNode trCategory in tr.Children)
			{
				if(checkchanged(trCategory))
					return true;
			}
		}
		return false;
	}
	
	///Jasmine 06/11/07 INTERACTIVE_CHANGE_SAVING_BETWEEN_FO_AND_NLFIT
	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
	void SetSectionUnSaveSign(TreeNode trFDFs)
	{
		if(!trFDFs)
			return;
		vector<string> vsFuncs;
		///Jasmine 06/11/07 NEW_MECHANISM_TO_SAVE_BUILT_IN_FUNCTION
		string strLabel;
		foreach(TreeNode cNode in trFDFs.Children)
		{
			cNode.GetAttribute(STR_LABEL_ATTRIB, strLabel);
			vsFuncs.Add(strLabel);
		}
		for(int ii = 0; ii < vsFuncs.GetSize(); ii++)
		{
			int nSelRow = m_trList.FindRow(vsFuncs[ii]);
			if(-1 < nSelRow)
			{
				TreeNode trRow = GetTreeNode(nSelRow);
				SetSectionUnsave(trRow);
			}
		}
		///End NEW_MECHANISM_TO_SAVE_BUILT_IN_FUNCTION
	}
	void SetSectionUnsave(TreeNode& trUnsave, bool bSetUnsave = true)
	{
		if(!trUnsave)
			return;		
		string strLabel;
		trUnsave.GetAttribute(STR_LABEL_ATTRIB, strLabel);
		int nRows = m_trList.GetRows();
		for(int nRow = 0; nRow < nRows; nRow++)//set other row with same label(the same function)
		{
			TreeNode trRow = GetTreeNode(nRow);
			if(trRow && GetCurrentFO().IsFunction(trRow))
			{
				string strTemp;
				trRow.GetAttribute(STR_LABEL_ATTRIB, strTemp);
				if(!strLabel.CompareNoCase(strTemp))
				{
					if(bSetUnsave)
					{
						m_trList.SetSectionUnsave(trRow, nRow);
						//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
						trRow.Replace(trUnsave, true, true);
						//------
					}
					else
					{
						GetCurrentFO().ClearChanged(trRow);

						m_trList.ClearUnsaveSign(trRow, nRow);
					}
				}
			}
		}			
	}
	///End MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
	///End INTERACTIVE_CHANGE_SAVING_BETWEEN_FO_AND_NLFIT
	///Jasmine 05/18/06 RETURN_SEL_FUNCTION
	///Hong 7/18/06 ADD_SUPPOSE_FOR_CATEGORY
	//string GetSel()
	string GetSel(bool bSkipCategory = false)	///Jasmine 05/21/07 allow return category
	///end ADD_SUPPOSE_FOR_CATEGORY
	{
		string strFunc, strCate;
		if(!GetCurrentFO().IsFunction(m_trSel))
		{
			///Hong 7/18/06 ADD_SUPPOSE_FOR_CATEGORY
			if(!bSkipCategory)
			{
				m_trSel.GetAttribute(STR_LABEL_ATTRIB, strCate);
				return strCate;
			}
			///end ADD_SUPPOSE_FOR_CATEGORY
			return "";
		}	
		bool bRet = m_trSel.GetAttribute(STR_LABEL_ATTRIB, strFunc);
		TreeNode trP = m_trSel.Parent();
		if(trP.IsValid())
			bRet = trP.GetAttribute(STR_LABEL_ATTRIB, strCate);
		strCate = strCate + "|" + strFunc;
		return strCate;
	}
	///Jasmine 11/24/06 SEL_FUNC_AFTER_OPEN
	bool SetSel(LPCSTR lpcszSel)
	{
		string strFunc(lpcszSel), strCate;
		if(!lstrlen(strFunc))
			return false;
		strCate = strFunc.GetToken(0, '|');
		strFunc = strFunc.GetToken(1, '|');
		if(!lstrlen(strCate) || !lstrlen(strFunc))
			return false;
		int nSelRow = m_trList.FindRow(strCate);
		if(nSelRow > -1)
		{
			m_trList.SetCollapsed(nSelRow, flexOutlineExpanded);
			///Jake 07/13/07 V8.0658 FIX_FAILED_TO_GET_DIRECTOR_POS_WHEN_CATEGORYNAME_EQU_FUNCTIONNAME
			/*
			int nSelFuncRow = m_trList.FindRow(strFunc, 0, false, true, nSelRow);
			*/
			int nStartRow = (strCate.Compare(strFunc))? nSelRow : nSelRow + 1;
			int nSelFuncRow = m_trList.FindRow(strFunc, 0, false, true, nStartRow);
			///end FIX_FAILED_TO_GET_DIRECTOR_POS_WHEN_CATEGORYNAME_EQU_FUNCTIONNAME
			if(nSelFuncRow > -1) nSelRow = nSelFuncRow;
		}		
		if(nSelRow == -1)
			return false;	
		//m_nSelRow = nSelRow;	///Jasmine 07/24/07 FIX_BUG_NO_REVIEW_WHEN_FIRST_TIME_OPEN, do later in OnListRowChange
		m_trList.SelRow(nSelRow);
		m_trSel=ShowListContent();
		return true;
	}
	///End SEL_FUNC_AFTER_OPEN
	///Jasmine 05/29/07 ONLY_SHOW_SPECIFIED_CATEGORY_FOR_SPECIAL_FIT 
	bool ShowSelCategory()
	{
		return m_trList.ShowSelCategory(m_nSelRow);		
	}
	///End ONLY_SHOW_SPECIFIED_CATEGORY_FOR_SPECIAL_FIT

	//------ Folger 12/14/07 CENTRALIZED_CODE_OF_HIDING_RESERVE_CATEGORIES
	bool HideReserveCategories()
	{
		return m_trList.HideReserveCategories();
	}
	//------
	
	///Jasmine 03/01/07 ADD_FO_HELP_TAB
	string	GetCurrentRowLabel()
	{
		int nEditRow, nID;
		TreeNode tnActive =	m_DynaCntrl.GetActiveTreeNode(nEditRow);	
		if(!tnActive.IsValid())
			return "General";
		tnActive.GetAttribute(STR_DATAID_ATTRIB, nID);
		switch(nID)
		{
		case FUNC_TREE_FUNC_NAME_ID:
			return STR_FUNC_NAME;
			break;
		case FUNC_TREE_FILE_NAME_ID:
			return "File Name";
			break;
		case FUNC_TREE_DESCRIPTION_ID:
			return STR_FUNC_DESCRIPTION;
			break;
		///Kyle 03/26/2009 QA80-13291-P4 NEW_EDIT_BOX_FOR_REFERENCES_INFORMATION
		case FUNC_TREE_REFERENCES_ID:
			return STR_FUNC_REFERENCES;
			break;
		///End NEW_EDIT_BOX_FOR_REFERENCES_INFORMATION
		case FUNC_TREE_FUNC_TYPE_ID:
			return STR_FUNC_TYPE;
			break;
		case FUNC_TREE_FUNC_SOURCE_ID:
			return STR_FUNCTION_SOURCE;
			break;
		case FUNC_TREE_INDEPENDENT_VARS_ID:
			return STR_FUNC_INDEPENDENT_VARS;
			break;
		case FUNC_TREE_DEPENDENT_VARS_ID:
			return STR_FUNC_DEPENDENT_VARS;
			break;
		case FUNC_TREE_PARAMETER_NAMES_ID:
			return STR_FUNC_PARAMETER_NAMES;
			break;
		case FUNC_TREE_FUNC_FORM_ID:
			return STR_FUNC_FORM;
			break;
		///Jasmine 05/11/07 ADD_DERIVATIVES_CHECKBOX
		case FUNC_TREE_ENABLE_DERIVATIVES_ID:
			return STR_FUNC_ANALYTICAL_DERIVATIVES;
			break;
		///ADD_DERIVATIVES_CHECKBOX
		case FUNC_TREE_FUNCTION_ID:
			string strVal;
			TreeNode trParent = tnActive.Parent();
			if(trParent.IsValid())
			{
				TreeNode tr = trParent.GetNode(cvt_str_to_tag_name(STR_FUNC_TYPE), false);
				if(tr.IsValid() && tr.strVal.Compare(STR_FUNCTION_TYPE_USER_DEFINE))
					return "Function Description";
				tr = trParent.GetNode(cvt_str_to_tag_name(STR_FUNC_FORM), false);
				if(tr.IsValid())
					strVal = tr.strVal;
				if(!strVal.Compare(STR_FUNCTION_FORM_ORIGIN_C))
					return "Function OriginC";
				if(!strVal.Compare(STR_FUNCTION_FORM_EQUATIONS))
					return "Function Equations";
				if(!strVal.Compare(STR_FUNCTION_FORM_EXPRESSION))
					return "Function Expression";
				if(!strVal.Compare(STR_FUNCTION_FORM_Y_SCRIPT))
					return "Function YScript";
			}
			break;
		case FUNC_TREE_OC_FUNC_HEADER_ID:
			return "";
			break;
		case FUNC_TREE_OC_PARA_INIT_HEADER_ID:
			return "";
			break;
		case FUNC_TREE_IS_PEAK_FUNC_ID:			///Jasmine 07/08/08 QA80-9434 DEFINE_PEAK_FUNC_IN_FO
			return STR_PEAK_FUNC_CHECK_E;		//need update FOHints.txt
			break;
		case FUNC_TREE_PARAMETERS_SETTINGS_ID:
			return STR_FUNC_PARAMETERS_SETTINGS;
			break;
		case FUNC_TREE_ENABLE_PARA_INIT_ID:
			return STR_FUNC_ENABLE_PARAMETERS_INIT;//"Initialization Scripts";
			break;
		case FUNC_TREE_PARA_INIT_ID:
			return STR_FUNC_PARA_INIT;
			break;
		case FUNC_TREE_INIT_SCRIPT_ID:
			return STR_FUNC_SCRIPT_BEFORE_FITTING;
			break;
		case FUNC_TREE_SCRIPT_AFTER_FITTING_ID:
			return STR_FUNC_SCRIPT_AFTER_FITTING;
			break;
		///Jasmine 11/24/09 QA80-14726 80_HAS_MISSED_CONSTANTS_SECTION
		case FUNC_TREE_CONSTANTS_ID:
			return STR_FUNC_CONSTANTS;
			break;
		///End 80_HAS_MISSED_CONSTANTS_SECTION
		case FUNC_TREE_ENABLE_CONSTRAINTS_ID:
			return STR_FUNC_GENERAL_CONSTRAINTS;
			break;
		case FUNC_TREE_CONSTRAINTS_ID:
			return STR_FUNC_CONSTRAINTS;
			break;
		case FUNC_TREE_DERIVED_PARAMS_ID:
			return STR_FUNC_DERIVED_PARAMS;
			break;
			
		///Kyle 08/06/2009 QA80-14077 ADD_UNIT_FOR_PARAMETER_SETTINGS
		case FUNC_TREE_DERIV_PARAM_SETTINGS_ID:
			return STR_FUNC_DERIVED_PARAM_SETTINGS;
			break;
		///End ADD_UNIT_FOR_PARAMETER_SETTINGS
		}
		return "";
	}	
	///End ADD_FO_HELP_TAB
protected:

/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	/*
	EVENTS_BEGIN
		//------------- begin required events
		// the following events are required for the splitter and related controls
		ON_INIT(OnInitSplitter)
		ON_DESTROY(OnDestroy)
		ON_SIZE(OnCtrlResize)
		ON_GETNDLG_MSGS(GetTreeEditPaneID())
		//------------- end required events
		ON_USER_MSG(WM_USER_RESIZE_CONTROLS, OnInitPaneSizs)	///Jasmine 04/07/06 SPLITTER_INIT_SIZE_NOT_CALL
		ON_GRID_ROW_COL_CHANGE(GetMainPaneID(), OnListRowChange)
		ON_GRID_BEFORE_MOUSE_DOWN(GetMainPaneID(), OnClickList)
		ON_GRID_DBLCLICK(GetMainPaneID(), OnListDblClick)
		
		ON_GRID_AFTER_COLLAPSE(GetMainPaneID(), OnAfterCollapse)
		
		ON_USER_MSG(WM_USER_TREEEDITOR_VALUE_CHANGE, OnAfterValueChange)
	
		/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
		/*
		/// YuI 7/23/04 v7.5103 QA70-6582 GETN_MULTILINE_TEXT_IMPLEMENTATION
		/// TD 9-2-06 QA70-9012 DYNACONTROL_MULTILINEEDIT_BUTTON
		//ON_BN_CLICKED(IDC_OPEN_IN_CODE_BUILDER_BUTTON, OnOpenInCodeBuilder)
		ON_MENU_CMD(IDC_OPEN_IN_CODE_BUILDER_BUTTON, OnOpenInCodeBuilder)
		/// end DYNACONTROL_MULTILINEEDIT_BUTTON
		ON_USER_MSG(WM_USER_ON_CONTENT_CHANGE, OnContentChange)
		/// end GETN_MULTILINE_TEXT_IMPLEMENTATION
		*/
		/*
		ON_MENU_CMD(IDC_OPEN_IN_CODE_BUILDER_BUTTON_PARA_SETTINGS,	OnOpenInCodeBuilderParaSettings)
		/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	EVENTS_END
	*/
	DECLARE_MESSAGE_MAP
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO

	BOOL OnInitSplitter()
	{
		//ListTreeEditSplitter::OnInitSplitter(&m_trList);
		/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
		//	TreeDynaSplitter::OnInitSplitter(&m_trList);
		TreeDynaSplitterWithCBCommunication::OnInitSplitter(&m_trList);
		/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
		
		initOrganizerArray();	///DG CLEAN_DUPLICATE_MORE
		initFunctionTree();
		///DG 4/20/05 REWRITE_TREE_GET_NODE
		/*
		///---DG 3/22/05
		ShowList(m_trFunctions, STR_FILENAME_ATTRIB);
		//UpdateList(STR_FILENAME_ATTRIB);
		///---end
		*/
		ShowList(GetListTree(), 0, STR_FILENAME_ATTRIB);
		///end REWRITE_TREE_GET_NODE
		
		SetAllCollapsed();

		m_nSelRow = -1;	//Default select none
		
		m_nEditStatus = FOEDIT_UPDATE_FINISHED;	
		getBuiltInCategoryList();///Jasmine 11/07/06 ALLOW_RENAME_USER_DEFINED_CATEGORY
		SetReady();
		LoadDefaultFunctionRow();	///Frank 11/10/04 v8.0160 QA70-6086   REMEMBER_LAST_USE_FUNCTION
		
		load_function_name_from_customize_xml(m_vsFuncName);	//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
		
		return true;
	}

	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	//virtual
	void	OnCodeBuilderSave()
	{
		if(!m_trFunctionDetail)
			return;
		///Jasmine 07/24/07 TRIM_TAB_CHAR_IN_SCRIPT
		/*
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_PARA_INIT_GUI).strVal=GetCurrentFO().GetNodeCheckAdd(m_trFunctionDetail, STR_FUNC_PARA_INIT, true, "Script").strVal;
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_FUNCTION).strVal=GetCurrentFO().GetNodeCheckAdd(m_trFunctionDetail, STR_FUNC_FORMULA, true, "Script").strVal;
		
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_OC_FUNC_HEADER).strVal=GetCurrentFO().GetNodeCheckAdd(m_trFunctionDetail, STR_FUNC_OC_FUNC_HEADER, true, "Script").strVal;
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_OC_PARA_INIT_HEADER).strVal=GetCurrentFO().GetNodeCheckAdd(m_trFunctionDetail, STR_FUNC_OC_PARA_INIT_HEADER, true, "Script").strVal;
		*/
		/// Hong 11/06/07 v8.0741 MORE_LOCALIZATION
		//vector<string> vsTo = {STR_FUNC_PARA_INIT_GUI, STR_FUNC_FUNCTION, STR_FUNC_OC_FUNC_HEADER, STR_FUNC_OC_PARA_INIT_HEADER};
		//vector<string> vsFrom = {STR_FUNC_PARA_INIT, STR_FUNC_FORMULA, STR_FUNC_OC_FUNC_HEADER, STR_FUNC_OC_PARA_INIT_HEADER};
		vector<string> vsTo, vsFrom;
		vsTo.Add(STR_FUNC_PARA_INIT_GUI);
		vsTo.Add(STR_FUNC_FUNCTION);
		vsTo.Add(STR_FUNC_OC_FUNC_HEADER);
		vsTo.Add(STR_FUNC_OC_PARA_INIT_HEADER);
		
		vsFrom.Add(STR_FUNC_PARA_INIT);
		vsFrom.Add(STR_FUNC_FORMULA);
		vsFrom.Add(STR_FUNC_OC_FUNC_HEADER);
		vsFrom.Add(STR_FUNC_OC_PARA_INIT_HEADER);
		/// end MORE_LOCALIZATION
		for(int ii = 0; ii < vsTo.GetSize(); ii++)
		{
			string str = GetCurrentFO().GetNodeCheckAdd(m_trFunctionDetail, vsFrom[ii], true, "Script").strVal;
			//str.Remove('\t');		///Jasmine 05/12/08 QA80-11524 TRIM_TAB_TO_FIX_TAB_MORE_AND_MORE_BUG_BUT_IT_MAKE_OTHER_BUG
			GetCurrentFO().GetNodeCheckAdd(m_trSel, vsTo[ii]).strVal = str;
		}
		///End TRIM_TAB_CHAR_IN_SCRIPT
		/// TD 9-2-06 QA70-9012 DYNACONTROL_MULTILINEEDIT_BUTTON
		GetCurrentFO().MarkChanged(m_trSel); //Mark the node as changed so it may be saved
		TreeDynaSplitterWithCBCommunication::OnCodeBuilderSave(); 
		OnAfterValueChange(DYNA_CONTROL_CONTENET_CHANGE, -1);	//-----Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE
		/// end DYNACONTROL_MULTILINEEDIT_BUTTON
	}
	
	///Jasmine 06/13/10 ORG-305-P1 SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
	//virtual 
	void SaveDefaultSettings(char chDelimiter, LPCSTR lpcszDlgName=NULL)
	{		
		TreeDynaSplitterWithCBCommunication::SaveDefaultSettings(chDelimiter, lpcszDlgName);
		string strRegItem(lpcszDlgName);
		strRegItem+=STR_LASTUSE_REG_ITEM;
		vector<string> vsRows;
		string strLastUseIndex;
		for(int nRow=GetSelList(); nRow>=0; nRow=m_trList.GetParent(nRow))
		{
			TreeNode trNode=GetTreeNode(nRow);
			if(trNode)
				vsRows.Add( GetCurrentFO().GetLabel(trNode) );
		}
		strLastUseIndex.SetTokens(vsRows, chDelimiter);		
		SaveSetting(strRegItem, strLastUseIndex, lpcszDlgName);
	}
	///End SAVE_FUNCTION_NAME_IS_MORE_FLEXIBLE
	
	BOOL	UpdateFuncDetail()
	{
		if( GetCurrentFO().IsFunction(m_trSel) )
		{
			m_trFunctionDetail.Reset();
			GetCurrentFO().ConstructFunctionDetail(m_trSel, m_trFunctionDetail);
			return TRUE;
		}
		
		return FALSE;
	}
	
	BOOL	OnOpenInCodeBuilderParaSettings()
	{
		///Jasmine 04/02/07 FOParametersSetting is ready, so comment these
		////temp
		//MessageBox(GetSafeHwnd(),"not ready");
		//return TRUE;
		////
		if( !UpdateFuncDetail() )
			return FALSE;
		int nEditRow = 1;
		TreeNode tnActive =	m_DynaCntrl.GetActiveTreeNode(nEditRow);
		
		///Jasmine 07/08/08 QA80-9434 DEFINE_PEAK_FUNC_IN_FO
		FUNC_TREENODE_TREENODE_DWORD_HWND pfn = Project.FindFunction("FOParametersSetting", "OriginLab\\FOParametersSettingDlg.c", true);
		if( pfn )
		{
			Window Wnd = GetParent();
			if(!Wnd)
				return false;
			
			TreeNode trPeakFunc = m_trSel.GetNode( cvt_str_to_tag_name(STR_PEAK_FUNC_CHECK_E) );
			if( pfn(m_trFunctionDetail, trPeakFunc, 0, Wnd.GetSafeHwnd()) && m_trFunctionDetail.IsValid() )
		///End DEFINE_PEAK_FUNC_IN_FO
			{
				///Jasmine 07/14/10 ORG-486-S1 CENTRALIZE_PEAK_ATTRIB_TO_NLFIT
				GetCurrentFO().CheckCopyPeakAttributeNodes(trPeakFunc.nVal, m_trFunctionDetail, m_trSel);
				///End CENTRALIZE_PEAK_ATTRIB_TO_NLFIT
				
				string strNewValue; 
				TreeNode trParaSetting = m_trFunctionDetail.GetNode(cvt_str_to_tag_name(STR_FUNC_FIT_PARAM), false);	///Jasmine  07/09/07 NO_CASE_SENSTIVE
				if(!trParaSetting.IsValid())
					return false;
				foreach(TreeNode cNode in trParaSetting.Children)
				{
					if(cNode.tagName.CompareNoCase(STR_FUNC_NAMES))
						strNewValue += cNode.tagName +" = "+ cNode.strVal +"\n";
				}				
				///Jasmine 11/23/06 GET_SETTING_FROM_PARA_SETTING_DLG
				//updateGUI(nEditRow, strNewValue);
				tnActive.strVal = strNewValue;			
				//UpdateDynaControl(true, GETNEVENT_ON_INIT, true);//refresh GUI
				UpdateDynaControl(true, 0, false, DYNACONTROL_UPDATE_RECONSTRUCT);
				SetSectionUnsave(m_trSel);//m_trList.SetSectionUnsave(m_trSel, m_nSelRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
				m_nEditStatus = FOEDIT_UPDATE_FINISHED;
				///End GET_SETTING_FROM_PARA_SETTING_DLG
				
				int nRow = tree_get_subnode_index(m_trSel, cvt_str_to_tag_name(STR_FUNC_PARAMETERS_SETTINGS));
				//OnAfterValueChange(DYNA_CONTROL_CONTENET_CHANGE, -1);		//-----Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE
				OnAfterValueChange(nRow, -1);
				return true;
			}
		}
	}
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	
	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	/*
	/// YuI 7/23/04 v7.5103 QA70-6582 GETN_MULTILINE_TEXT_IMPLEMENTATION
	/// TD 9-2-06 QA70-9012 DYNACONTROL_MULTILINEEDIT_BUTTON
	//BOOL 	OnOpenInCodeBuilder(Control ctrl)
	BOOL 	OnOpenInCodeBuilder()
	/// end DYNACONTROL_MULTILINEEDIT_BUTTON
	{
		//----- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//int nEditRow = m_treeEditCntrl.GetEditRow();
		//m_treeEditCntrl.OnKillFocus();
		int nEditRow = 1;// dolater
		/// TD 9-2-06 QA70-9012 DYNACONTROL_MULTILINEEDIT_BUTTON
		TreeNode tnActive =	m_DynaCntrl.GetActiveTreeNode(nEditRow);
		/// end DYNACONTROL_MULTILINEEDIT_BUTTON

		//-----
		// a little bit of redundancy here
		// TreeEditControl post message
		// and this function will be called in message handler of WM_USER_TREEEDITOR_VALUE_CHANGE
		// but because of PostMessage (not SendMessage) it will be too late already
		// so I have to update function branch of the tree righght here
		
		///DG 8/17/05 : use current function expression
		//TreeNode trFuncDetail=m_trFunctionDetail.FirstNode;
		///end
		if( GetCurrentFO().IsFunction(m_trSel) )
		{
			m_trFunctionDetail.Reset();
			GetCurrentFO().ConstructFunctionDetail(m_trSel, m_trFunctionDetail);
			TreeNode trFuncDetailWrap = m_trFunctionDetail;///jasmine 11/15/05 QA70-8307 v8.0335 ADD_PARAMETERS_SETTINGS  //TD 4-26-06 USE_WRAP_TO_ALLOW_INTERNAL_UPDATE
			Tree trFuncDetail;
			trFuncDetail = m_trFunctionDetail;
			
			switch( nEditRow )
			{
				case PARA_INIT:
					Functions.EditFunctionInCodeBuilder(trFuncDetailWrap, *this, TRUE);	 //TD 4-26-06 USE_WRAP_TO_ALLOW_INTERNAL_UPDATE
					return TRUE;
	
				case FUNCTION:
					Functions.EditFunctionInCodeBuilder(trFuncDetailWrap, *this); //TD 4-26-06 USE_WRAP_TO_ALLOW_INTERNAL_UPDATE
					return TRUE;		
				///Jasmine 11/15/05 QA70-8307 v8.0335 ADD_PARAMETERS_SETTINGS
				case PARAMETERS_SETTINGS:
					//MessageBox(GetSafeHwnd(),"not ready");
					///Jasmine 01/25/06 Jasmine 01/25/06 PARA_SETTING_DLG doing...
					//string strPath;
					//strPath.Format("%sOriginC\\OriginLab\\FOParametersSettingDlg.c", GetAppPath(TRUE));
					FUNC_TREENODE_DWORD_HWND pfn = Project.FindFunction("FOParametersSetting", "OriginLab\\FOParametersSettingDlg.c");//, strPath);
					if( pfn )
					{
						///Jasmine 02/09/06 UPDATE_TO_GUI
						//return pfn(trFuncDetail, 0, GetWindow());
						Window Wnd = GetParent();
						if(!Wnd)
							return false;
						if(pfn(trFuncDetail, 0, Wnd.GetSafeHwnd()) && trFuncDetail.IsValid())
						{
							string strNewValue; 
							TreeNode trParaSetting = trFuncDetail.GetNode("FittingParameters");
							if(!trParaSetting.IsValid())
								return false;
							foreach(TreeNode cNode in trParaSetting.Children)
							{
								if(cNode.tagName.CompareNoCase(STR_FUNC_NAMES))
									strNewValue = strNewValue + cNode.tagName +" = "+ cNode.strVal +"\n";
							}
							updateGUI(nEditRow, strNewValue);//don't know why GetN Tree can't remember the change
							return true;
							
						}
						///End UPDATE_TO_GUI
					}
					
					return FALSE;
				///End ADD_PARAMETERS_SETTINGS
				
				///Jasmine 10/11/05 QA70-8114 v8.0315 ADD_INIT_AND_AFTER_FITTING_SCRIPTS
				//need VC support
				case INIT_SCRIPTS:
					
				case AFTER_FITTING_SCRIPTS:
					
				///End ADD_INIT_AND_AFTER_FITTING_SCRIPTS
			}
		}
		
		return FALSE;
	}
	
	
	void OnContentChange(DWORD wParam, DWORD lParam)
	{
		switch( (uint) lParam )
		{
		case FUNCTION_MANAGER_ON_CODE_BUILDER_OPEN_FUNCTION:
			OnCodeBuilderBeginEdit();
			break;
			
		case FUNCTION_MANAGER_ON_CODE_BUILDER_CLOSE_FUNCTION:
			OnCodeBuilderEndEdit();
			break;
			
		case FUNCTION_MANAGER_ON_CODE_BUILDER_SAVE_FUNCTION:
			OnCodeBuilderSave();
			break;
		}
	}
	*/
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO


	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	/*
	void	OnCodeBuilderBeginEdit()
	{
	}
	
	void	OnCodeBuilderEndEdit()
	{
	}
	
	void	OnCodeBuilderSave()
	{
		///Frank v8.0169	12/07/04			FIXED_CODE_BUILDER_CHANGED_BUG	
		/// YuI 09/07/05 NLSF_CODE_BUILDER_COMMUNICATION_FIX
		// I did not understand why it was here
		// m_trFunctionDetail.FirstNode returned GeneralINformation node which is obviously not correct
		//	TreeNode trFuncDetail=m_trFunctionDetail.FirstNode;
		TreeNode trFuncDetail=m_trFunctionDetail;
		/// end NLSF_CODE_BUILDER_COMMUNICATION_FIX
		if(!trFuncDetail)
			return;
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_PARA_INIT).strVal=GetCurrentFO().GetNodeCheckAdd(trFuncDetail, STR_FUNC_PARA_INIT, true, "Script").strVal;
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_FUNCTION).strVal=GetCurrentFO().GetNodeCheckAdd(trFuncDetail, STR_FUNC_FORMULA, true, "Script").strVal;
		
		/// YuI 09/07/05 NLSF_CODE_BUILDER_COMMUNICATION_FIX
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_OC_FUNC_HEADER).strVal=GetCurrentFO().GetNodeCheckAdd(trFuncDetail, STR_FUNC_OC_FUNC_HEADER, true, "Script").strVal;
		GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_OC_PARA_INIT_HEADER).strVal=GetCurrentFO().GetNodeCheckAdd(trFuncDetail, STR_FUNC_OC_PARA_INIT_HEADER, true, "Script").strVal;
		/// end NLSF_CODE_BUILDER_COMMUNICATION_FIX

		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		/*
		m_treeEditCntrl.ReInit();
		m_trList.SetSectionUnsave(m_trSel, m_nSelRow);
		*/
		/*
	}
	/// end GETN_MULTILINE_TEXT_IMPLEMENTATION
	*/
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO	
	//Use this name for the over loading, do this to reset GetNTree
	void ConstructTree()
	{
		GETN_TREE(lrTree)
		GETN_STR(Message, _L("Welcome :"), _L("Click the list in the left to view the function or category detail"))
		GETN_READ_ONLY
		
		m_paramTree = lrTree;
	}
	///Jasmine 03/01/07 ADD_FO_HELP_TAB
	void OnEditRowChange(Control ctrl)
	{
		int nEditRow;
		TreeNode tnActive =	m_DynaCntrl.GetActiveTreeNode(nEditRow);	
		if(!tnActive.IsValid())
			return;
		Window Wnd = GetParent();
		if(Wnd)
			Wnd.PostMessage(WM_USER_ON_CHANGE_FUNC_HELP);
	}
	///End ADD_FO_HELP_TAB
	//update function or category detail by the selection
	void OnListRowChange(Control ctrl)
	{
		if(!IsReady())
			return;
		if(FOEDIT_UPDATE_FINISHED != m_nEditStatus)
		{
			//if don't finish updating, return to current row until it finish
			m_trList.SelRow(m_nSelRow);
			return;
		}
		
		PROFILE_HRGLASS //----- CPY 5/25/04 v7.5878 FO_ADD_PROFILE_DUE_TO_SLOW_LAUNCH
		
		int nNewSelect = GetSelList();
		//if selected function or category change
		if(m_nSelRow != nNewSelect)
		{
			//m_nEditStatus = FOEDIT_READ_DETAIL;
			m_nSelRow=nNewSelect;
			GetCurrentFO(m_nSelRow, true);
			///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
			//m_trSel=ShowListContent();			
			m_trSel=GetTreeNode(m_nSelRow);
			CheckLoadChangedGUITree(m_trSel);
			ShowListContent();
			///End MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
			///jasmine 03/02/06 TOP_LEVEL_CHANGE
			//FO reduce levels -- category and function, so comment useless codes
			/*
			if(getTreeLevel(m_trSel) == 0)
			{
				m_treeEditCntrl.SetReady(false);
				//select top level, set un editable
				m_paramTree.Enable=false;
				m_treeEditCntrl.Update(m_paramTree, true, true);
			}
			else if(GetCurrentFO().IsFunction(m_trSel))
				onFunctionSel();
			*/
			///Jasmine 03/02/07 DISABLE_BTNS_IF_SELECT_SEPARATOR
			bool bSeparator;
			if(GetCurrentFO().IsFunction(m_trSel))
				onFunctionSel();
			///Jasmine 11/07/06 ALLOW_RENAME_USER_DEFINED_CATEGORY
			else//allow editing user-defineed category name
			{
				string strName;
				m_trSel.GetAttribute(STR_LABEL_ATTRIB, strName);
				if(-1 == m_vsBuiltInCates.Find(strName))
				{
					TreeNode trEdit = GetTree(true, false);			
					trEdit.name.Enable = true;
					UpdateDynaControl(true, GETNEVENT_ON_INIT, true, 0, false);
				}
				bSeparator = (-1 < m_vsSeparators.Find(strName));
			}
			///End ALLOW_RENAME_USER_DEFINED_CATEGORY
			///End TOP_LEVEL_CHANGE
			updatePrev();
			setButtonStatus(bSeparator);
			///End DISABLE_BTNS_IF_SELECT_SEPARATOR
			//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
			//m_treeEditCntrl.SetReady(true);
			SetReady(true);
			//----
		}
		//m_nEditStatus = FOEDIT_UPDATE_FINISHED;
	}

	//After update detail change, then arrow change select
	void OnRowColChange(Control cntrl)
	{
		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		/*
		if(FOEDIT_UPDATE_FINISHED == m_nEditStatus)
			m_treeEditCntrl.OnRowColChange();
		*/
	}
	//set status as dirty, lock editing before it is finished
	void OnCellChange(Control cntrl, int nRow, int nCol)
	{
		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		/*
		if(!IsReady() || !m_treeEditCntrl.IsReady() || FOEDIT_UPDATE_FINISHED != m_nEditStatus)
			return;
		*/
		m_nEditStatus = FOEDIT_DATA_DIRTY;
	}
	//when expand category then read its function detail from fdf file
	void OnAfterCollapse(Control cntrl, int nRow, short nState)
	{
		if(!IsReady())
			return;
		
		PROFILE_HRGLASS
		
		if( 2 != nState )
		{
			if(GetListTree().IsValid() && 0 == nState)
			{
				m_trList.SetCellIcon(nRow, 0, IDI_FOLDER_OPEN, MODULE_ORIGIN); ///DG FOLDER_WITH_DISPLAY_ICON
				TreeNode trCate = GetTreeNode(nRow);
				//if(trCate && GetCurrentFO().IsFunction(trCate.FirstNode))	///DG 2/24/05 x function has more category and degree is uncertain
				if(trCate)
				{
					bool bRet=checkCollapsed(trCate);
					if(	!bRet )
					{
						vector<int> vnInvalidFunctionIndex;
						///DG 4/1/05 CLEAN_DUPLICATE_MORE
						GetCurrentFO(nRow, false).LoadCategory(trCate, vnInvalidFunctionIndex);
						///end CLEAN_DUPLICATE_MORE
						m_trList.RemoveItem(vnInvalidFunctionIndex, nRow);
						setCollapsed(trCate);
					}
				}
			}
		}
		else
			m_trList.SetCellIcon(nRow, 0, IDI_FOLDER_CLOSED, MODULE_ORIGIN); ///DG FOLDER_WITH_DISPLAY_ICON
	}
	
	//Click on List, set the button status
	void OnClickList(Control cntrl, short nButton, short nShift, float X, float Y, BOOL* pCancel)
	{
		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		/*
		if(-1 < m_treeEditCntrl.GetSelectedRow())
			m_treeEditCntrl.ValidateChanged();
		
		int nClickRow, nClickCol;
		m_trList.GetMouseCell(nClickRow, nClickCol);
		
		if(nClickRow == m_nSelRow)
			setButtonStatus();
		else if(MK_RBUTTON == nButton) //allow right click selection
		{
			//if(0 <= nClickRow && FOEDIT_UPDATE_FINISHED == m_nEditStatus && nClickRow != m_nSelRow)
			if(0 <= nClickRow && nClickRow != m_nSelRow)
			{
				m_treeEditCntrl.SelRow(-1);	//Read selected section detail, avoid the value change event
				m_trList.SelRow(nClickRow);
			}
		}
		*/
	}
	
	void OnListDblClick(Control ctrl)
	{
		int nClickRow, nClickCol;
		m_trList.GetMouseCell(nClickRow, nClickCol);
		///Hong 7/31/06 FIX_RIGHT_DOUBLE_CLICK_DISPLAY_ERROR
		//if(!GetCurrentFO().IsFunction(m_trSel))
		TreeNode trClickNode = GetTreeNode(nClickRow);
		if(!GetCurrentFO().IsFunction(trClickNode))
		///end FIX_RIGHT_DOUBLE_CLICK_DISPLAY_ERROR
			forceCollapse(nClickRow, true);
	}
	
	///DG 5/11/05 v8.0229 ENABLE_BUTTON_WHEN_EDITING : we disable this button because change will be lost when we click this button before, now it's fixed.
	/*
	//Before edit detail, set the button status
	void OnBeforeMouseDown(Control cntrl, short nButton, short nShift, float X, float Y, BOOL* pCancel)
	{
		if(m_nSelRow >= 0)
			setButtonStatus(true);
		
		m_treeEditCntrl.OnBeforeMouseDown(nButton, nShift, X, Y, pCancel);
	}
	*/
	///end ENABLE_BUTTON_WHEN_EDITING
	
	//Support for right click
	bool OnShowMenu(UINT nResIDCtrl, int nx, int ny)
	{
		int nRow, nCol;
		FunctionOrganizer& fo = GetCurrentFO();
		if(GetMainPaneID() == nResIDCtrl)
		{
			//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
			/*
			///DG WEB_XF_SUPPORTED
			if(fo.IsReadOnlyFunction())
				return true;
			///end WEB_XF_SUPPORTED
			
			m_trList.FindCell(nx, ny, nRow, nCol);
			if(0 != nCol || nRow != m_nSelRow || FOEDIT_UPDATE_FINISHED != m_nEditStatus)
			 	return false;
			bool bUnEditableSysFunc=fo.IsUnEditableSysFunction(m_trSel);
			bool bClickTopLevel=m_trList.GetLevel(m_nSelRow) == 0;
			FOListControlMenu myMenu(nRow, nCol, !bUnEditableSysFunc, bClickTopLevel, !fo.IsFunction(m_trSel));
			int nCmd = myMenu.DoTrackPopup(nx, ny, GetSafeHwnd());
			if(0 > nCmd)
				return false;

			//switch(nCmd + fo.IsFunction(m_trSel))	///Jasmine 03/02/06 ENABLE_NEW_ADD_DEL_FOR_CATEGORY
			switch(nCmd)
			{
			case FO_NEW_CATE:
				NewCategory();
				break;
			case FO_SAVE:
				SaveSelSection();
				break;
			case FO_NEW:
				NewFunction();
				break;
			case FO_DUPLICATE:
				DuplicateSection();
				break;
			case FO_ADD:
				AddFunction();
				break;
			case FO_DELETE:
				DelSelSection();
				break;
			default :
				break;
			}
			*/
			m_trList.GetMouseCell(nRow, nCol);
			if ( nRow >= 0 )
				m_trList.SelRow(nRow);
			if ( nRow < 0 )
				return false;
						
			bool bUnEditableSysFunc=fo.IsUnEditableSysFunction(m_trSel);
			bool bClickTopLevel=m_trList.GetLevel(m_nSelRow) == 0;
			FOListControlMenu myMenu(nRow, nCol, !bUnEditableSysFunc, bClickTopLevel, !fo.IsFunction(m_trSel), fo.IsSharedFunction(m_trSel));
			int nCmd = myMenu.DoTrackPopup(nx, ny, GetSafeHwnd());
			if(0 > nCmd)
				return false;
			
			switch ( nCmd )
			{
			case FO_MENU_MOVE:
			case FO_MENU_SHARE:
				{
					NLFunctionList &tmpList = (NLFunctionList&)fo;
					vector<string> vsCategories;
					tmpList.GetCategoryList(vsCategories);
					
					string strCategory;
					TreeNode trCategory = m_trSel.Parent();
					if ( trCategory )
						trCategory.GetAttribute(STR_LABEL_ATTRIB, strCategory);
					string strCombo;
					strCombo.SetTokens(vsCategories, '|');
					
					GETN_TREE(tr)
					GETN_STRLIST(Categories, nCmd == FO_MENU_MOVE ? _L("Move To") : _L("Share To"), strCategory, strCombo);
					
					if ( GetNBox(tr, nCmd == FO_MENU_MOVE ? _L("Move") : _L("Share"), NULL, NULL, NULL, GetSafeHwnd()) )
					{
						string strTarget = tr.Categories.strVal;
						if ( strTarget.CompareNoCase(strCategory) != 0 && strTarget.Find("---") < 0 )
						{
							TreeNode trTargetCategory = findCategoryByName(strTarget);
							if ( trTargetCategory )
							{
								PROFILE_HRGLASS
								string strError;
								///Kyle 01/13/2009 v8.0995d SHOW_ERROR_MESSAGE_WHEN_THE_FILE_WITH_THE_SAME_NAME_EXISTS
								//if ( !GetCurrentFO().CheckFuncName(m_trSel.FunctionName.strVal, trTargetCategory, &strError, m_trSel.FileNameFDF.strVal, true) )
								if ( !GetCurrentFO().CheckFuncName(m_trSel.FunctionName, trTargetCategory, &strError, m_trSel.FileNameFDF.strVal, true) )
								///End SHOW_ERROR_MESSAGE_WHEN_THE_FILE_WITH_THE_SAME_NAME_EXISTS
								{
									MessageBox(GetSafeHwnd(), strError, ERROR_ATTENTION_DIAOLG, MB_OK | MB_ICONEXCLAMATION);
									return false;
								}
								Tree trTmp;
								trTmp.Replace(m_trSel);
								if ( nCmd == FO_MENU_MOVE )
								{
									//------ Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION
									BooleanRestoreHelper	bHelper(m_bReady);
									//------
									DelSelSection(false, false);
								}
								string strNodeName = tree_get_enum_node_name(trTargetCategory, STR_NODE_FUNCTION);
								TreeNode trNew = trTargetCategory.AddNode(strNodeName);
								if ( trNew.Replace(trTmp, true, true) )
								{
									int nParentRow = -1;
									do
									{
										nParentRow = m_trList.FindRow(strTarget, 0, false, true, nParentRow);
									}while ( nParentRow >= 0 && m_trList.GetLevel(nParentRow) != LEVEL_CATEGORY );
									if ( nParentRow >= 0 )
									{
										forceCollapse(nParentRow);
										{
											//------ Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION
											BooleanRestoreHelper	bHelper(m_bReady);
											//------
											addNewToList(trNew, true, -1, true, &nParentRow);
										}
										//------ Folger 07/23/08 FIX_SCROLL_BAR_MISSING_WHEN_MOVE_AND_SHARE_FIT_FUNCTION
										//ShowListContent();
										forceSelection();
										//------
										SaveSelSection();
									}
								}
							}
						}
					}
				}
				break;
			case FO_MENU_DUPLICATE:
				DuplicateSection();
				break;
			case FO_MENU_REMOVE:
				DelSelSection();
				break;
			}
			//------ End ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
		}
		else
		{
			//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
			//dolater
			/*
			m_treeEditCntrl.FindCell(nx, ny, nRow, nCol);
			TreeNode trSel=m_treeEditCntrl.GetTreeNode(nRow, nCol);
			if(-1 < fo.OnShowMenu(trSel, m_trSel, nx, ny, GetSafeHwnd(), nRow))
			{
				ShowListContent();	//refresh
				m_trList.SetSectionUnsave(m_trSel, m_nSelRow);	//changed
			}
			*/
		}
		return true;
	}
	//Update detail by change
	void OnAfterValueChange(int nRow, DWORD lParam)
	{
		if(!m_trSel || FOEDIT_READ_DETAIL == m_nEditStatus)
			return;
		
		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		///Jasmine 11/01/06 FIX_FO_BUG
		//get GUI tree. 
		///Joseph 9/06/06  SAVE_USER_FUNCTION
		///*
		//TreeNode trRow=m_treeEditCntrl.GetTreeNode(nRow);
		//TreeNode trRow = tree_get_node(m_trSel,nRow);
		TreeNode trEdit = GetTree(true, false);
		TreeNode trRow = tree_get_node(trEdit, nRow);
		///End SAVE_USER_FUNCTION
		///End FIX_FO_BUG
		bool bUndoOperation=false, bSetUnSave=true;
		//-----Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE
		if (trRow)
		{
		//-----End MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE
			string 	strError, strNewValue=trRow.strVal;
			int 	nID = -1;
			
			if(GetCurrentFO().IsUnEditableSysFunction(m_trSel))
			{
				bUndoOperation=true;
				strError=STR_ERROR_SYS_FUNC_UNEDITABLE;
			}
			else if(GetCurrentFO().IsCategory(m_trSel))
			{
				if(BRANCH_INFO_NAME == nRow)
				{
					bSetUnSave=false;	//category will be saved once change
					if(GetCurrentFO().UpdateCateName(trRow, m_trSel, &strError))
					{
						m_trList.SetCell(m_nSelRow, 0, trRow.strVal);
						clearParentSectionUnSaveSign(m_trSel, m_nSelRow);
					}
					else
						bUndoOperation=true;
				}
			}
			else
			{
				///Jasmine 05/15/07 USE_DATA_ID_REPLACE_ROW_NUM	
				trRow.GetAttribute(STR_DATAID_ATTRIB, nID);
				GetCurrentFO().OnAfterValueChange(trRow, m_trSel, nID, &bUndoOperation, &strError);
				//if(!bUndoOperation && NAME == nRow)	//update list name
				if(!bUndoOperation && FUNC_TREE_FUNC_NAME_ID == nID)	
				///End USE_DATA_ID_REPLACE_ROW_NUM
				///Jasmine 11/02/06 FUNC_AND_FILE_NAME_ONE_TO_ONE 
				{
					m_trList.SetCell(m_nSelRow, 0, GetCurrentFO().GetFunctionName(m_trSel, true));
					//file name change, refresh GUI
					//UpdateDynaControl(true, GETNEVENT_ON_INIT, true);
					UpdateDynaControl(true, 0, false, DYNACONTROL_UPDATE_RECONSTRUCT);	///Jasmine 01/27/07 KEEP_FOCUS_IN_DYNA_CTRL
				}
				///End FUNC_AND_FILE_NAME_ONE_TO_ONE
			}
			
			//string strUpdatedValue=trRow.strVal;
			if(!strError.IsEmpty())
				MessageBox(GetSafeHwnd(), strError, ERROR_ATTENTION_DIAOLG, MB_OK | MB_ICONEXCLAMATION);
		}		//-----Folger 07/23/07 MODIFY_DYNA_CONTROL_VALUE_BY_OPENING_DIALOG_CHANGE_BUTTON_STATE
		///Joseph 9/06/06  SAVE_USER_FUNCTION
		//if(strUpdatedValue != strNewValue)
			//m_treeEditCntrl.SetCell(nRow, 1, strUpdatedValue);
		///End SAVE_USER_FUNCTION
		if(!bUndoOperation && bSetUnSave)
		{
			SetSectionUnsave(m_trSel); //m_trList.SetSectionUnsave(m_trSel, m_nSelRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
			CheckAddChangedGUITree(m_trSel);
		}
		///Joseph 9/06/06  SAVE_USER_FUNCTION
		//*/
		///End SAVE_USER_FUNCTION
		m_nEditStatus = FOEDIT_UPDATE_FINISHED;
		//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
		setButtonStatus();
		//--------end MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
	}
	///Jasmine 03/02/07 UPDATE_DYNACONTROL_ON_FUNC_TYPE_CHANGE	
	/// TD 03-06-2009 QA80-13204 FUNC_ORG_DLG_FLASHING
	//void OnFunctionTypeChange(int nRow = 0, DWORD lParam = 0)
	//{
	//	UpdateDynaControl(true, GETNEVENT_ON_INIT, false, DYNACONTROL_UPDATE_RECONSTRUCT);
	//}
	void OnFunctionTypeChange(DWORD dwEventType, DWORD dwUpdateBits)
	{
		UpdateDynaControl(true, dwEventType, false, dwUpdateBits);
	}
	/// end FUNC_ORG_DLG_FLASHING
	///End UPDATE_DYNACONTROL_ON_FUNC_TYPE_CHANGE
	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
	void CheckLoadChangedGUITree(TreeNode& trGUI)
	{
		if(!trGUI || !GetCurrentFO().IsFunction(trGUI))
			return;
		string strLabel;
		trGUI.GetAttribute(STR_LABEL_ATTRIB, strLabel);
		TreeNode trChanged = m_trGUIs.FindNodeByAttribute(STR_LABEL_ATTRIB, strLabel, FALSE);
		if(trChanged)
			trGUI.Replace(trChanged, TRUE, TRUE, FALSE);
	}
	void CheckAddChangedGUITree(TreeNode& trGUI)
	{
		if(!trGUI || !GetCurrentFO().IsFunction(trGUI))
			return;
		string strLabel;
		trGUI.GetAttribute(STR_LABEL_ATTRIB, strLabel);
		TreeNode trChanged = m_trGUIs.FindNodeByAttribute(STR_LABEL_ATTRIB, strLabel, FALSE);
		if(!trChanged)
			trChanged = m_trGUIs.AddNode(cvt_str_to_tag_name(strLabel));
		trChanged.Replace(trGUI, TRUE, TRUE, FALSE);
		string strTemp;
		bool bRet = trChanged.GetAttribute(STR_CHANGED_ATTRIB, strTemp);
		if(!bRet)
			ERR_MSG("CheckAddChangedGUITree fail");
	}
	void ClearChangedGUITree(TreeNode& trGUI, bool bClear = true)
	{
		if(!trGUI)
			return;
		if(GetCurrentFO().IsFunction(trGUI))
		{
			string strLabel;
			trGUI.GetAttribute(STR_LABEL_ATTRIB, strLabel);
			if(-1 == m_trList.FindRow(strLabel) || bClear)//no such function
			{
				TreeNode trChanged = m_trGUIs.FindNodeByAttribute(STR_LABEL_ATTRIB, strLabel, FALSE);
				if(trChanged)
					trChanged.Remove();
			}
		}
		else
		{
			foreach(TreeNode cNode in trGUI.Children)
				ClearChangedGUITree(cNode);
		}
	}
	///End MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
protected:
	string getSaveFailPromptsStr(vector<string> vsSaveFail)
	{
		string strList;
		strList = "The following function save fail: (Total "+ vsSaveFail.GetSize() +" Functions)\n\n";
		strList += get_unsave_file_list(vsSaveFail);
		return strList;
	}
	bool onSaveFail(string strPrompts)
	{
		MessageBox(GetSafeHwnd(), strPrompts, "Attention", MB_OK | MB_ICONEXCLAMATION);
		return false;
	}
	
	///---DG CLEAN_DUPLICATE_MORE
protected:
	/*
	FunctionOrganizer& GetCurrentFO()
	{
		return m_arrFO.GetAt(m_nCurOrganizerIndex);
	}
	*/
	FunctionOrganizer& GetCurrentFO(int nRow=-1, bool SetAsCurrentOrganizer=false)
	{
		int nIndex=-1;
		if(-1 == nRow)
		{
			nIndex=m_nCurOrganizerIndex;
		}
		else
		{
			TreeNode trNode=GetTreeNode(nRow);
			//nIndex = isXFunction(trNode) ? INDEX_X_FUNCTION : INDEX_FIT_FUNCTION;	///DG WEB_XF_SUPPORTED
			nIndex = getFunctionArrayIndex(trNode);
			if(SetAsCurrentOrganizer)
				m_nCurOrganizerIndex = nIndex;
		}
		return m_arrFO.GetAt(nIndex);
	}
private :
	void initOrganizerArray()
	{
		m_arrFO.SetAsOwner(true);
		
		FunctionOrganizer *pFO;
		pFO = new NumFunctionOrganizerEx;
		///------ Folger 07/13/10 ORG-543 PROMPT_USER_FOR_WHETHER_COPY_FDF_TO_UFF_WHEN_ADD_IN_FO
		pFO->SetOwnerHwnd(GetSafeHwnd());
		///------ End PROMPT_USER_FOR_WHETHER_COPY_FDF_TO_UFF_WHEN_ADD_IN_FO
		/// AW 03/01/07 v8.0272c FIX_BUG_initOrganizerArray_IN_OC
		//int nRet=m_arrFO.Add(*pFO);
		int nIndex=m_arrFO.Add(*pFO);
		/// END FIX_BUG_initOrganizerArray_IN_OC
		pFO = NULL;
#ifdef XF_ORGANIZER //CPY DSC 12/9/05 REMOVE_XF_ORGANIZER		
		pFO = new XFunctionOrganizerEx;
		nRet=m_arrFO.Add(*pFO);
		pFO = NULL;
#endif
		
		///---DG REMOVE_WEB_XF
		/*
		///DG WEB_XF_SUPPORTED
		pFO = new WebXF;
		nRet=m_arrFO.Add(*pFO);
		pFO = NULL;
		///end WEB_XF_SUPPORTED
		*/
		///---end REMOVE_WEB_XF
		
		//report error
		/// AW 03/01/07 v8.0272c FIX_BUG_initOrganizerArray_IN_OC
		//if(1 > nRet)
		if(0 > nIndex)
		/// END FIX_BUG_initOrganizerArray_IN_OC		
		{
			error_report("Invalid array, organizer init fail");
			ASSERT(0);
		}
	}
	///---end CLEAN_DUPLICATE_MORE
	
	void initFunctionTree() ///DG CENTRALIZE_XFO_AND_NFO
	{
		///DG VC_FUNCTION_SUPPORT : we have vc level function supported now
		/*
		string strListFile=STR_FILE_FUNCTION_LIST;
		///DG 4/6/05 : we should ignore the old build junk file
		//if(strListFile.IsFile() && LoadListSource(strListFile)) //LoadListSource() will return error_report() if load fail, so first check IsFile()
			//return;
		if(strListFile.IsFile())
		{
			string strINIFile=nlf_get_ini_filepath(ORIGIN_PATH_USER);
			if(1 > file_time_compare(strINIFile, strListFile) && LoadListSource(strListFile))
				return;
		}
		///end
		*/
		///end  VC_FUNCTION_SUPPORT
	
	///Kevin	11/03/05---------------------------
		/*TreeNode trFO;
		TreeNode trFunc = GetListTree();
		for(int ii=0; ii<m_arrFO.GetSize(); ii++)
		{
			FunctionOrganizer &FO=m_arrFO.GetAt(ii);
			FO.DisableGUIInterface();
			//FO.GetCategoryList(m_trFunctions);
			FO.GetCategoryList(trFunc);
		}*/
		TreeNode trFunc = GetListTree();
		FunctionOrganizer &FO=m_arrFO.GetAt(m_nFuncType);
		FO.DisableGUIInterface();
		FO.GetCategoryList(trFunc);

	///------------------------------------------
		
		//SetListTree(m_trFunctions);
		UpdateListTree();
	}
	///DG SAVE_LIST_INSTEAD_LOADING_EACH_TIME
	///DG VC_FUNCTION_SUPPORT
	/*
	void saveFunctionList()
	{
		//trim function detail
		removeFunctionDetail(m_trFunctions);
		string strListFile=STR_FILE_FUNCTION_LIST;
		if(!m_trFunctions.Save(strListFile))
			DeleteFile(strListFile);
	}
	
	void removeFunctionDetail(TreeNode &tr)
	{
		if(GetCurrentFO().IsFunction(tr))
		{
			//roll back change
			string strOldVal;
			if(GetCurrentFO().CheckChanged(tr, &strOldVal) && !strOldVal.IsEmpty())
			{
				int nPath;
				GetCurrentFO().GetFuncFileName(tr, true, &nPath);
				GetCurrentFO().SetFunctionName(tr, strOldVal, &nPath);
			}
			if(tr.GetAttribute(STR_OLDFILENAME_ATTRIB, strOldVal))
				GetCurrentFO().SetFuncFileName(tr, strOldVal);
			tr.Reset(true);
			GetCurrentFO().ClearChanged(tr);
		}
		else if(GetCurrentFO().CheckChanged(tr))	//DG 3/7/05, unsave category has not been created, remove it
			tr.Remove();
		else if((isCategoryTree(tr) && checkCollapsed(tr)) || isTopLevelCategory(tr) || (tr.FirstNode && isTopLevelCategory(tr.FirstNode)))
		{
			clearCollapsed(tr);
			foreach(TreeNode trNode in tr.Children)
				removeFunctionDetail(trNode);
		}
	}
	*/
	///end VC_FUNCTION_SUPPORT
	
	void setButtonStatus(bool bChangeListBtnDisable=false)
	{
		Window Wnd = GetParent();
		if(Wnd)
			Wnd.PostMessage(WM_USER_BUTTON_ENABLE, bChangeListBtnDisable);
	}
	
	void updatePrev()
	{
		UpdateFunctionDetail(m_trSel);
		///Jasmine 03/05/07 ACTIVE_HELP_TAB_IF_SELECT_USER_DEFINED_FUNC
		int nType = -1;
		string strType;
		TreeNode tr = m_trSel.GetNode(cvt_str_to_tag_name(STR_FUNC_TYPE), false);
		if(tr.IsValid())
			strType = tr.strVal;
		if(strType.Compare(m_strType))
			nType = strType.Compare(STR_FUNCTION_TYPE_USER_DEFINE)? FO_VIEW_FUNC_PREV : FO_VIEW_FUNC_HELP;
		m_strType = strType;
		//call parent to update preview
		Window Wnd = GetParent();
		if(Wnd)
			//Wnd.PostMessage(WM_USER_ON_FUNC_CHANGE);
			Wnd.PostMessage(WM_USER_ON_FUNC_CHANGE, GetCurrentFO().IsAllowSimulation(), nType);
	}	///End ACTIVE_HELP_TAB_IF_SELECT_USER_DEFINED_FUNC
	///Jasmine 11/23/06 GET_SETTING_FROM_PARA_SETTING_DLG
	//no use
	/////Jasmine 02/09/06 UPDATE_TO_GUI
	//bool updateGUI(int nRow, LPCSTR lpcszValue)
	//{
		////---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		////dolater
		///*
		//string strNewValue = lpcszValue, strOldValue;
		//TreeNode trRow=m_treeEditCntrl.GetTreeNode(nRow);
		//strOldValue = trRow.strVal;
		//if(strNewValue.IsEmpty() || !strOldValue.CompareNoCase(strNewValue))
			//return false;
		//trRow.strVal = strNewValue;
		//m_treeEditCntrl.SetCell(nRow, 1, strNewValue); 
		//updatePrev();
		//OnAfterValueChange(nRow, 1);
		//*/
		//return true;
	//}
	/////End UPDATE_TO_GUI
	///End GET_SETTING_FROM_PARA_SETTING_DLG
	void onFunctionSel()
	{
		//set detail tree view, whether contain branch '+' and its space
		//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
		//dolater
		/*
		ShowTreeCollapsedSymbol(GetCurrentFO().IsDetailTreeView());
		*/
	}
	bool saveAllCategory(vector<string> &vsSaveFail)
	{
		TreeNode trFO;
		//vector<string> vsNodes = {STR_FIT_FUNCTION_NODE, STR_X_FUNCTION_NODE, STR_WEB_XF_NODE};	///DG WEB_XF_SUPPORTED	///DG REMOVE_WEB_XF
		//vector<string> vsNodes = {STR_FIT_FUNCTION_NODE, STR_X_FUNCTION_NODE};
		///-----Frank 11/09/05
		//for(int ii=0; ii<TOTAL_ORGANIZER_NUM; ii++)
		for(int ii=0; ii<= INDEX_FIT_FUNCTION; ii++)
		///------
		{
			FunctionOrganizer &FO=m_arrFO.GetAt(ii);
			//------------- CPY 9/2/05 GRAPH_TREE_SPLITTER_SAMPLE_CODE_CLEANUP
			///-----Frank 11/09/05
			//trFO=m_trFunctions.GetNode(vsNodes[ii]);
			//TreeNode trFunc = GetListTree();
			//trFO = trFunc.GetNode(vsNodes[ii]);
			trFO = GetListTree();
			///-----
			//-------------
			if(!trFO)
				error_report("Get function node fail");
			foreach(TreeNode trCategory in trFO.Children)
			{
				if(checkCollapsed(trCategory))
					FO.SaveCategory(trCategory, vsSaveFail);
			}
		}
		return true;
	}
	///DG WEB_XF_SUPPORTED
	/*
	bool isXFunction(const TreeNode& trFunction)
	{
		int nDataID=-1;
		for(TreeNode trParent=trFunction; trParent.IsValid() && !isTopLevelCategory(trParent, &nDataID); trParent=trParent.Parent())
			;
		if(ID_X_FUNCTION == nDataID)
			return true;
		return false;
	}
	*/
	int getFunctionArrayIndex(const TreeNode& trFunction)
	{
		int nDataID=-1;
		for(TreeNode trParent=trFunction; trParent.IsValid() && !isTopLevelCategory(trParent, &nDataID); trParent=trParent.Parent())
			;
		switch(nDataID)
		{
		case ID_X_FUNCTION:
			return INDEX_X_FUNCTION;
		case ID_FIT_FUNCTION:
			return INDEX_FIT_FUNCTION;
		//case ID_WEB_XF:	///DG REMOVE_WEB_XF
			//return INDEX_WEB_XF;
		default:
			break;
		}
		return -1;
	}
	///end WEB_XF_SUPPORTED
	
	//Only top level: fit function and X function, have ID
	bool isTopLevelCategory(TreeNode &tr, int *pnID=NULL)
	{
		int nn=tr.DataID;
		if(NULL != pnID)
			*pnID=nn;
		return nn>=0;
	}
	//bool isSysFuncAndUnEditable(TreeNode trSysFunc)
	//{
		//if(!GetCurrentFO().IsSysFunction(trSysFunc))
			//return false;
		////string strUserFile=GetCurrentFO().GetFunctionFileFullPath(GetCurrentFO().GetFuncFileName(trSysFunc), USER_FOLDER);
		//string strUserFile=GetCurrentFO().GetFuncFilePath(trSysFunc, USER_FOLDER);
		//return strUserFile.IsFile();
	//}
	void onFunctionSave()
	{
		updatePrev();	///Danice 12/24/04 : update preview after save
		//m_trList.ClearUnsaveSign(m_trSel, m_nSelRow);
		clearParentSectionUnSaveSign(m_trSel, m_nSelRow);
		int nn;
		TreeNode trCategory = getCategory( nn );
		///Jasmine 06/08/07 NEW_MECHANISM_TO_SAVE_BUILT_IN_FUNCTION	
		/*
		//Save a change sys function will save it to user folder, need reload ...
		if( GetCurrentFO().IsSysFunction(m_trSel))
		{
			string strNewNode = tree_get_enum_node_name(trCategory, STR_NEW_FUNCTION_PREFIX);
			TreeNode trNew;
			if(m_trSel.NextNode)
				trNew = trCategory.InsertNode(m_trSel.NextNode, strNewNode);
			else
				trNew = trCategory.AddNode(strNewNode);
			trNew.Replace(m_trSel);
			string strFileName=GetCurrentFO().GetFuncFileName(m_trSel);
			GetCurrentFO().SetFuncFileName(trNew, GetCurrentFO().GetFunctionFileFullPath(strFileName, USER_FOLDER));
			GetCurrentFO().SetLabel(trNew, GetCurrentFO().GetFunctionNameStr( GetCurrentFO().GetFunctionName(m_trSel), USER_FOLDER));

			addNewToList(trNew, false, m_nSelRow+1);
		}
		*/
		///End NEW_MECHANISM_TO_SAVE_BUILT_IN_FUNCTION
	}
	int findRowToAdd(TreeNode &trNewItem, int nParentRow, int &nCurrentTreeLevel)
	{
		nCurrentTreeLevel=getTreeLevel(trNewItem);
		return findNextSameLevelRow(nParentRow, nCurrentTreeLevel-1);	//level-1 is parent level
	}
	int findNextSameLevelRow(int nCurrentRow, int nCurLevel)
	{
		for(int nRow = nCurrentRow+1; nCurLevel < m_trList.GetLevel(nRow); nRow++)
			//if(nRow >= m_trList.GetRows())
				//break;
			;
		return nRow;
	}
	///DG 1/28/05
	int getTreeLevel(TreeNode &tr)
	{
		//return tree_get_level(tr)-tree_get_level(m_trFunctions.FirstNode);	//
		//------------- CPY 9/2/05 GRAPH_TREE_SPLITTER_SAMPLE_CODE_CLEANUP
		//return tree_get_level(tr)-tree_get_level(m_trFunctions.FindNodeByAttribute(STR_DATAID_ATTRIB, ID_FIT_FUNCTION));	//
		///-----Frank 11/09/05
		//TreeNode trFunc = GetListTree();
		//return tree_get_level(tr)-tree_get_level(trFunc.FindNodeByAttribute(STR_DATAID_ATTRIB, ID_FIT_FUNCTION));
		return tree_get_level(tr)-1;
		///-----
		//-------------
	}
	///end
	bool isCategoryTree(TreeNode &tr)
	{
		if(!isTopLevelCategory(tr) && !GetCurrentFO().IsFunction(tr))
			return true;
		return false;
	}
	TreeNode getCategory(int &nCategoryRow)
	{
		if(GetCurrentFO().IsFunction(m_trSel))
		{
			nCategoryRow=m_trList.GetParent(m_nSelRow);
			return m_trSel.Parent();
		}
		else if(isCategoryTree(m_trSel))
		{
			nCategoryRow=m_nSelRow;
			return m_trSel;
		}
		else //top level
		{
			TreeNode trJunk;
			return trJunk;
		}
	}
	
	//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
	TreeNode findCategoryByName(LPCSTR lpcszName)
	{
		foreach ( TreeNode trCategory in m_trFunctions.Children )
		{
			string strName;
			trCategory.GetAttribute(STR_LABEL_ATTRIB, strName);
			if ( strName.CompareNoCase(lpcszName) == 0 )
				return trCategory;
		}
	}
	//------
	
	TreeNode getCategoryParent(int &nParentRow, bool bUseItselfAsParent=false)
	{
		TreeNode trCategory=getCategory(nParentRow);
		if(trCategory)
		{
			if(bUseItselfAsParent)	//use for xfunction, every category can be parent category
				return trCategory;
			nParentRow=m_trList.GetParent(nParentRow);
			return trCategory.Parent();
		}
		//this list don't have category
		nParentRow=m_nSelRow;
		return m_trSel;
	}
	void addNewToList(TreeNode &tr, bool bSetFunctionUnSave=true, int nRow=-1, bool bShowLast=true, int *pnParentRow = NULL)
	{
		int nTreeLevel, nParentRow, nFromRow;
		if ( pnParentRow )
			nParentRow = *pnParentRow;
		else
		{
			TreeNode trParent=getCategory(nParentRow);
			if(!trParent)
				nParentRow=m_nSelRow;
		}
		nFromRow=findRowToAdd(tr, nParentRow, nTreeLevel);
		if(-1 == nRow)
			nRow=nFromRow;
		else
			nFromRow=nRow;
		AddTreeRows(tr, nTreeLevel, &nRow);
		///---DG 2/25/05 : move set/clear unsave part into this class
		//m_trList.OnAddNewToList(tr, nFromRow, GetCurrentFO().IsFunction(tr), bShowLast, bSetFunctionUnSave);
		if(bSetFunctionUnSave)
		{
			SetSectionUnSaveSign(tr, nFromRow);
			if(isCategoryTree(tr))
			{
				//top category has been create
				GetCurrentFO().ClearChanged(tr);
				SetSectionUnsave(tr, false);//m_trList.ClearUnsaveSign(tr, nFromRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
				
				forceCollapse(nFromRow);
				Control ctrl;
				OnAfterCollapse(ctrl, nFromRow, 0);	///change category icon
			}
		}
		m_trList.ShowNewMember(tr, nRow-1);
		///---end
		//force collapse
		nParentRow=m_trList.GetParent(nFromRow);
		forceCollapse(nParentRow);
	}
	//return total handle row number
	int SetSectionUnSaveSign(TreeNode &tr, int nBeginRow)
	{
		int nNumClear=1; //consider itself first
		//if(GetCurrentFO().IsFunction(tr)) ///DG 2/25/05 : There are still category unsave
		//{
			SetSectionUnsave(tr);//m_trList.SetSectionUnsave(tr, nBeginRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		//}
		//else
		if(isCategoryTree(tr))
		{
			//set subnode
			foreach(TreeNode trNode in tr.Children)
				nNumClear+=SetSectionUnSaveSign(trNode, nBeginRow+nNumClear);
		}
		return nNumClear;
	}
	///DG 3/7/05 REMOVE_REPEAT
	void removeRepeatFunction(TreeNode &tr)
	{
		if(GetCurrentFO().IsUnEditableSysFunction(tr))
			tr.Remove();
		else if(!GetCurrentFO().IsFunction(tr))
		{
			foreach(TreeNode trNode in tr.Children)
				removeRepeatFunction(trNode);
		}
	}
	///end REMOVE_REPEAT

	//return clear number of sub section
	int clearSectionUnSaveSign(TreeNode& tr, int nBeginRow)
	{
		clearParentSectionUnSaveSign(tr, nBeginRow);
		return clearSubSectionUnSaveSign(tr, nBeginRow);
	}
	int clearParentSectionUnSaveSign(TreeNode &tr, int nBeginRow)
	{
		SetSectionUnsave(tr, false);//m_trList.ClearUnsaveSign(tr, nBeginRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		TreeNode trParent=tr.Parent();
		if(trParent)
			clearParentSectionUnSaveSign(trParent, m_trList.GetParent(nBeginRow));
		return 1;
	}
	int clearSubSectionUnSaveSign(TreeNode &tr, int nBeginRow)
	{
		SetSectionUnsave(tr, false);//m_trList.ClearUnsaveSign(tr, nBeginRow);	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
		int nNumClear=1;
		if(isCategoryTree(tr))
		{
			//clear subnode
			foreach(TreeNode trNode in tr.Children)
				nNumClear+=clearSectionUnSaveSign(trNode, nBeginRow+nNumClear);
		}
		return nNumClear;
	}
	///DG 2/15/05 share is not allowed now
	/*
	void onSharedChange()
	{
		int nShared=m_trSel.UserInfo.nVal;
		int nFolder= 1 == nShared ? ALL_USER_FOLDER : USER_FOLDER;
		string strVal, strTemp;
		strVal=GetCurrentFO().GetFunctionNameStr(GetCurrentFO().GetNodeCheckAdd(m_trSel, STR_FUNC_NAME).strVal, nFolder);
		
		if(!GetCurrentFO().CheckChanged(m_trSel, &strTemp) || strTemp.IsEmpty())
		{
			strTemp=GetCurrentFO().GetFunctionName(m_trSel);
			GetCurrentFO().MarkChanged(m_trSel, &strTemp);
		}
		GetCurrentFO().SetFunctionName(m_trSel, strVal);
		m_trList.SetCell(m_nSelRow, 0, strVal);
	}
	*/
	///end
	bool isOCFunctionForm(TreeNode &trFunction)
	{
		string strFunctionForm = trFunction.GeneralInformation.FunctionForm.strVal ;
		if(0  == strFunctionForm.CompareNoCase(ORIGINC_FUNCTION_TYPE_IN_COMBO))
			return true;
		return false;
	}
	
	//check if the string is a valid C identifier name.
	bool isNameOK(string& strName, bool bAutoRename = false)
	{
		string strAutoName = strName;
		strAutoName.MakeValidCName();
		if(0 != strAutoName.Compare(strName))
		{
			if(bAutoRename)
				strName = strAutoName;
			return false;
		}
		return true;
	}
	void removeRepeatAndEmptyItem(vector<string>& vsLists)
	{
		for(int ii=0; ii<vsLists.GetSize(); ii++)
		{
			for(int nn=ii; vsLists[nn].IsEmpty() || -1 != (nn=vsLists.Find(vsLists[ii], ii+1)); nn=ii)
			{
				vsLists.RemoveAt(nn);
				break;
			}
		}
	}
	//Check if category and its function is unsaved
	bool checkchanged(TreeNode& trCategory)
	{
		if(GetCurrentFO().CheckChanged(trCategory))
			return true;
		if(checkCollapsed(trCategory) || isTopLevelCategory(trCategory))
		{
			foreach(TreeNode trFunc in trCategory.Children)
			{
				if(!GetCurrentFO().IsFunction(trFunc) && checkchanged(trFunc))	//function degree is not certain
					return true;
				if(GetCurrentFO().CheckChanged(trFunc))
					return true;
			}
		}
		return false;
	}
	void forceSelection()
	{
		m_nSelRow=-1;
		Control ctrl;
		OnListRowChange(ctrl);
	}
	void forceCollapse(int nRow, bool bForceChange=false)
	{
		int nState=m_trList.GetCollapsed(nRow);
		if(flexOutlineCollapsed == nState)
			m_trList.SetCollapsed(nRow, flexOutlineExpanded);
		else if(bForceChange && flexOutlineExpanded == nState)
			m_trList.SetCollapsed(nRow, flexOutlineCollapsed);
	}
	///DG 4/8/05 move them into utility function
	/*
	string getEnumNodeName(TreeNode &trNode, string strPrefix)
	{
		vector<string> vsNodeNames;
		tree_get_node_names(trNode, vsNodeNames, true);
		//return strPrefix+(string)getEnumNumber(vsNodeNames, strPrefix);
		int nNum=getEnumNumber(vsNodeNames, strPrefix);
		string strNum= 0==nNum ? "" : (string)nNum;
		return strPrefix+strNum;
	}
	string getEnumAttribVal(TreeNode &trNode, string strAttribute, string strPrefix)
	{
		vector<string> vsAttribVals;
		tree_get_attributes(trNode, vsAttribVals, strAttribute, true);
		int nNum=getEnumNumber(vsAttribVals, strPrefix);
		string strNum= 0==nNum ? "" : (string)nNum;
		return strPrefix+strNum;
	}
	int getEnumNumber(vector<string> vsVals, string strPrefix)
	{
		if(-1 == vsVals.Find(strPrefix))
			return 0;
		for(int ii=1; ;ii++)
		{
			if(-1 == vsVals.Find(strPrefix+(string)ii))
				return ii;
		} 
	}
	*/
	///end
	bool checkCollapsed(TreeNode &trCategory)
	{
		string strTemp;
		return trCategory.GetAttribute(STR_GETTREE_ATTRIB, strTemp );
	}
	void setCollapsed(TreeNode &trCategory)
	{
		trCategory.SetAttribute(STR_GETTREE_ATTRIB, "");
	}
	void clearCollapsed(TreeNode &trCategory)
	{
		trCategory.RemoveAttribute(STR_GETTREE_ATTRIB);
	}
	///Jasmine 11/07/06 ALLOW_RENAME_USER_DEFINED_CATEGORY
	void getBuiltInCategoryList()
	{
		string strNLSFIniFilePath = okutil_get_origin_path(ORIGIN_PATH_SYSTEM, NULL, TRUE) + "NLSF.INI";
		INIFile iniNLSF(strNLSFIniFilePath);
		int nKeysCount = iniNLSF.GetKeyNames(m_vsBuiltInCates, STR_NODE_CATEGORY);
		///Jasmine 03/02/07 DISABLE_BTNS_IF_SELECT_SEPARATOR
		for(int ii = 0; ii < nKeysCount; ii++)
		{
			string strValue = iniNLSF.ReadString(STR_NODE_CATEGORY, m_vsBuiltInCates[ii]);
			if(!strValue.CompareNoCase("separator"))
				m_vsSeparators.Add(m_vsBuiltInCates[ii]);
		}
		///End DISABLE_BTNS_IF_SELECT_SEPARATOR
	}
	///End ALLOW_RENAME_USER_DEFINED_CATEGORY
	//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
	int getCustomizeFuncNameIndex(TreeNode& trFunction)
	{
		int nType;
		okutil_fo_GetFuncFileName(&trFunction, true, &nType);
		if(SYS_FOLDER == nType)
		{
			string strFunction;
			trFunction.GetAttribute(STR_LABEL_ATTRIB, strFunction);
			return m_vsFuncName.Find(strFunction);
		}
		return -1;
	}
	//--------end MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
///Kevin 11/03/05
public:
	void setFuncType(int nFuncType)
	{
		m_nFuncType = nFuncType;
	}

	void setFuncTypeName(int nFuncType)
	{
		if(FO_FDF == nFuncType) 
			m_strFuncType = STR_FDF_DLG_NAME;
		else
			m_strFuncType = STR_XF_DLG_NAME;
	}
	//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
	//moved here from TreeEditSplitter.h
	TreeNode GetListTree()
	{
		TreeNode trTemp = m_trFunctions;
		
		return trTemp;
	}
	void UpdateListTree()
	{
		SetListTree(m_trFunctions);
	}
	//---- end CHANGE_FO_TO_USE_NEW_DYNA_CTRL
	
private:
	GridTreeFunctionList		m_trList;	//Function and category list

	Array<FunctionOrganizer&>	m_arrFO;
	int							m_nCurOrganizerIndex;

	/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	//	Tree						m_trFunctionDetail;
	/// end NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
	
	int 						m_nEditStatus;

	int							m_nFuncType;	///Kevin to separate FO into XF and FDF
	
	string						m_strFuncType;
	string						m_strType;///Jasmine 03/05/07 ACTIVE_HELP_TAB_IF_SELECT_USER_DEFINED_FUNC
	//---- CPY 5/29/06 CHANGE_FO_TO_USE_NEW_DYNA_CTRL
	Tree				m_trFunctions; // moved here from TreeEditSplitter.h
	//----
	Tree						m_trGUIs;	///Jasmine 06/13/07 MAKE_CONNECTION_BETWEEN_SAME_FUNCTION
	vector<string>				m_vsBuiltInCates;///Jasmine 11/07/06 ALLOW_RENAME_USER_DEFINED_CATEGORY
	vector<string>				m_vsSeparators;	///Jasmine 03/02/07 DISABLE_BTNS_IF_SELECT_SEPARATOR
	vector<string>				m_vsFuncName;		//--------Folger 07/11/07 MORE_CONSTRAINTS_TO_ENABLE_RESET_BUTTON
};

/// YuI 10/04/06 NEED_COMMON_BASE_CLASS_FOR_NLSF_AND_FO
BEGIN_MESSAGE_MAP_DERIV(FunctionListSplitter, TreeDynaSplitterWithCBCommunication)
	ON_INIT(OnInitSplitter)
	ON_DESTROY(OnDestroy)
	ON_SIZE(OnCtrlResize)
	ON_GETNDLG_MSGS(GetTreeEditPaneID())
	ON_USER_MSG(WM_USER_RESIZE_CONTROLS, OnInitPaneSizs)	///Jasmine 04/07/06 SPLITTER_INIT_SIZE_NOT_CALL
	ON_GRID_ROW_COL_CHANGE(GetTreeEditPaneID(), OnEditRowChange)	///Jasmine 03/01/07 ADD_FO_HELP_TAB
	ON_GRID_ROW_COL_CHANGE(GetMainPaneID(), OnListRowChange)
	ON_GRID_BEFORE_MOUSE_DOWN(GetMainPaneID(), OnClickList)
	ON_GRID_DBLCLICK(GetMainPaneID(), OnListDblClick)	
	ON_GRID_AFTER_COLLAPSE(GetMainPaneID(), OnAfterCollapse)
	ON_USER_MSG(WM_USER_TREEEDITOR_VALUE_CHANGE, OnAfterValueChange)
	ON_USER_MSG(WM_USER_ON_UPDATE_DYNA_CONTROL, OnFunctionTypeChange)	///Jasmine 03/02/07 UPDATE_DYNACONTROL_ON_FUNC_TYPE_CHANGE	
	ON_MENU_CMD(IDC_OPEN_IN_CODE_BUILDER_BUTTON_PARA_SETTINGS,	OnOpenInCodeBuilderParaSettings)
	ON_CONTEXTMENU(OnShowMenu)		//------ Folger 02/18/08 QA80-10976 ADD_MOVE_ETC_OPERATIONS_IN_FUNCTION_ORGANIZER_CONTEXTMENU
END_MESSAGE_MAP_DERIV


#endif _FO_TREE_EDIT_SPLITTER
