/*------------------------------------------------------------------------------*
 * File Name: ColMatValues.c					 								*
 * Creation: Danice																*
 * Purpose: OriginC Source C file												*
 * Copyright (c) Originlab Corp.	2005, 2006									*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 * Danice 7/29/04 v80106 QA70-6599 ROW_NUM_ONE_BASE_SAME_AS_OLD_DIALOG			*
 * Danice 8/11/04 v8.0114 QA70-6599 PROMPT_CHANGE_BEFORE_SET_OTHERS				*
 * SY 12/29/2004 v8.0181 USING_DIALOGEX_H_INSTEAD_OF_DIALOG_H					*
 * DG 6/9/05 QA70-6599 v8.0248 REDESIGN_COL_PROPERTIES							*
 * DG 8/1/05 QA70-7883 v8.0277 SAME_AS_75_ADD_SELECTION							*
 * Jasmine 04/24/06 QA70-8625 SET_COL_VAL_DLG_MODELESS							*
 * Jasmine 04/27/06 MODIFICATION_UPDATE_COLUMN_LIST								*
 * Jasmine 04/30/06 MULTI_FOR_PREVIOUS_SCRIPT									*
 * CPY 5/9/06 BEFORE_SCRIPT_IN_TAB												*
 *	CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE									*
 *	CPY 6/10/2006 OPEN_DLG_WHEN_COL_NOT_SELECTED								*
 * Jasmine 06/29/06 TEMP_ADD_SOME_RNG_FUNC										*
 *  Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE										*
 *	Jasmine 08/28/06 FORCE_TO_UPDATE											*
 *	jasmine 08/28/06 SHARE_DLG_WITH_MAT											*
 *	Jasmine 09/25/06 SHARE_COL_BROWSER_WITH_MAT									*
 *	Jasmine 09/28/06 SIMPLE_RANGE_NOTATION										*
 *	Jasmine 10/23/06 UPDATE_IF_MATOBJ_CHANGE									*
 *	Jasmine 10/23/06 CHANGE_TEXT_TO_EASY_UNDERSTAND								*
 *	Jasmine 10/27/06 GET_RANGE_STRING											*
 *	CPY 10/31/06 DATA_OBJ_FROM_COL_PROP_DIALOG									*
 *	Jasmine 11/06/06 EXECUTE_FORMULA_BUG_ALWAYS_RETURN_FALSE					*
 *	Jasmine 01/15/07 REMOVE_FUNCTION_BROWSER									*
 *	CPY 2/12/2007 SCRIPT_EDIT_BOX_SHOULD_BE_FIXED_WIDTH_FONT					*
 *	Jasmine 03/05/07 CHANGE_COL_TO_WCOL_FOR_INDEX								*
 *	Jasmine 03/27/06 DLG_RESIZE_PAINT_MESS										*
 *	Jasmine 04/03/07 REMOVE_INVF_ETC_PER_MAX_REQUEST							*
 *	Jake 04/18/07 ADD_FIRST_AND_LAST_BUTTON										*	
 *	Jake 04/26/07 ADD_MISCELLANEOUSFUN_CATEGORY									*
 *	Jasmine 06/20/07 FIX_BUG_OF_SPECIFIED_FONT									*
 *	Jasmine 06/22/07 REMEMBER_RECALCULATE_SETTING								*
 *	Jasmine 06/26/07 ADD_LT_VECTOR_FUNC											*
 *	Jasmine 07/10/07 REMOVE_UNWANTED_PARENTHESIS								*
 *	AW 07/13/07 QA80-10056 NEED_DEL_OP_AFTER_UNDO_SETVALUE_WITH_AUTO			*
 *	Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE						*
 *	Jasmine 09/03/07 REMOVE_EXPGROW2_BY_MAX_REQUIRE								*
 *	CPY 10/2/2007 QA70-10375 USE_CACHED_FONT									*
 *	CPY 11/3/2007 SET_COL_VALUES_AUTO_NEED_LOCALIZATION							*
 *	ML 11/5/2007 PROOPER_MENU_LANGUAGE_WHEN_MENU_COMES_FROM_DLG_RESOURCE		*
 *	CPY 11/28/2007 QA70-10754 AUTO_SHOULD_NOT_BE_ZERO_IN_SET_COL_VALUES			*
 *	Jasmine 01/31/08 QA80-11034 APPLY_CHANGE_FIRST								*
 *	Jasmine 06/11/08 QA80-11679 m_pDataOB_INVALID_WHEN_SWITCH_FROM_MAT_TO_NO_COL_SEL_WKS
 *  Kyle 07/14/08 QA80-11830 LIMIT_THE_MIN_WIDTH_OF_SET_COLUMN_VALUES_DLG		*
 *	Jasmine 08/14/08 QA80-12018 UPDATE_FROM_TO_ONCE_SELECTION_CHANGE			*
 *	Jasmine 09/03/08 ACTIVE_LAYER_IS_NOT_CURRENT_LAYER_IF_SLECTION_NOT_GOOD		*
 *	Jasmine 10/06/08 QA80-12308 STUPID_WAY_TO_REFRESH_MENU_BAR					*
 *	Kyle 12/04/2008 QA70-9982-S1 MERGE_OC_NUMERIC_STRING_VECTOR_TO_OC_FUNCTION	*
 *	Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
 *	Kyle 12/08/2008 CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE		*
 *	Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
 *	Jasmine 12/15/08 v8.0986c QA80-12779 DETECT_FOCUS_POSITION_TO_ADD_STRING	*
 *	Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE			*
 *	Folger 12/15/08 QA80-12773 v8.0986c ADD_$_FOR_OC_FUNCTION_WHICH_RETURN_STRING
 *	Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
 *	Kyle 12/26/2008 FIX_RUNTIME_ERROR_WHEN_FOCUS_NOT_IN_ANYWHERE				*
 *  Iris 12/30/2008 v8.0992 FILTER_DISRELATED_FUNC_FROM_WKS_OR_MAT_SET_VALUE_MENU*
 *  Iris 01/04/2009 v8.0993c MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST				*
 *  Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS		*
 *	YuI 02/04/09 QA70-12831 COLUMN_FORMULA_TO_REMEMBER_THE_RANGE				*
 *  Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS
 *	Jasmine 03/04/09 DEFINE_LT_VAR_BUTTON										*
 *	Kenny 04/27/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
 *	Kyle 04/30/2009 SUPPORT_DEFINING_VARIABLES_IN_SET_VALUES_DIALOG				*
 *	CPY 5/11/09 QA70-12554 MAT_SET_VALUES_NEED_RANGE_SUPPORT					*
 *	CPY 5/13/09 QA70-12554-P1 MAT_SET_VALUES_RANGE_SUPPORT_ONLY_IF_NO_RECALC	*
 *	Kyle 05/19/2009 QA80-13635 NO_NEED_TO_UPDATE_RANGE_ON_WKS_ACTIVED			*
 *	Kyle 05/21/2009 NEW_STRUCTURE_OF_SET_COLUMN_VALUES_DIALOG_F_X_PULL_DOWN_MENU*
 * Kenny 06/18/2009 INSERT_USER_VAR_DLG_SUPPORT_DISABLE_INSERT_AS_LINK_BTN		*
 * Kenny 06/19/2009 INSERT_USER_DEFINED_VAR_TO_BEFORE_FORMULA_SCRIPTS_PANEL		*
 *	Kyle 06/25/2009 ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU					*
 *	Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
 *	CPY 7/18/09 QA80-13746 SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP					*
 *	Kyle 07/20/2009 QA80-13746-P2 SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP
 *	Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU					*
 *	Kyle 07/29/2009 QA80-14038 FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY
 *	Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
 *	Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED		*
 *	Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV								*
 *	Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED						*
 *	Kenny 09/03/2009 QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS			*
 *	Sophy 9/9/2009 INSERT_VAR_DLG_NEED_TO_KNOW_CUR_SEL_COLUMN_FROM_SET_COL_VALUES_DLG
 *	Sophy 9/10/2009 QA80-14297 HIDE_SET_COL_VALS_DLG_WHEN_NO_VALID_DATA_SELECTED*
 *	Kyle 09/14/2009 QA80-12308 NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
 *	Kyle 09/14/2009 ADD_WCOL(_ThisColNum)_UNDER_VARIABLE_CONSTANT				*
 *	Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL*
 *	Folger 09/21/09 QA80-14283 GET_RID_OF_ONSELECTIONCHANGE_EVENT_DURING_GRID_ATTACH
 *	Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS						*
 *	Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU			*
 *	Kyle 11/18/2009 QA80-14691 WANT_DOUBLE_CLICK_TO_HIGHLIGHT_A_WORD_IN_EDIT_BOX*
 *	Kyle 11/23/2009 DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES						*
 *	Kenny 11/26/2009 QA81-14748 INSERT_VAR_DLG_FAILED_TO_SHOW_IMPORT_FILE_LEVEL_INFO*
 *	Kenny 12/22/2009 QA81-14748-P2 INSERT_USER_VAR_DLG_FAILS_TO_SHOW_MULTILINE_NODE*
 *	Kenny 12/22/2009 QA81-14748-P3 INSERT_USER_VAR_DLG_FAILS_TO_INSERT_DROP_LIST_STRINGS*
 *	Kenny 12/24/2009 QA81-14748-P3 INSERT_USER_VAR_DLG_FAILS_TO_INSERT_CHECK_BOX_NODE_VALUE*
 *	Folger 05/18/10 ORG-124-P1 WRONG_INIT_ROW_RANGE_IN_SCV_WHEN_OPEN_WITH_HIGHLIGHT_WHOLE_COLUMN
 *	Folger 06/01/10 ORG-120 DATA_DISPLAY_DIALOG_IMPROVEMENT						*
 *	Folger 10/14/2010 ORG-1252 MULTIPANE_DIALOG_BAD_LAYOUT_IF_INVALID_PANE_HEIGHT_IN_REGISTRY
 *------------------------------------------------------------------------------*/
 
////////////////////////////////////////////////////////////////////////////////////
// Including the system header file Origin.h should be sufficient for most Origin
// applications and is recommended. Origin.h includes many of the most common system
// header files and is automatically pre-compiled when Origin runs the first time.
// Programs including Origin.h subsequently compile much more quickly as long as
// the size and number of other included header files is minimized. All NAG header
// files are now included in Origin.h and no longer need be separately included.
//
// Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h
// system header file.
#include <Origin.h>
#include "DialogEx.h"
//#include <fdftree.h>

#define  _DMSG(_str) //out_str(_str);

#define BASE_WINDOW ResizeDialog
#include "TreeEditEvents.h"
//#include "FunctionGroup.h"
//#include "NumFunctionOrganizer.h"
//#include "SplitterControl.h"
//#include "ColAccess.h"
#include "DataObjectManager.h"
//#include "ColValueDesignation.h"
#include "FunctionsMenu.h"		///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
///Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS 
#ifdef _ADD_FITTING_FUNCTIONS_TO_SCV
#include "SetValuesCommon.h"
#endif // _ADD_FITTING_FUNCTIONS_TO_SCV
///End SCV_ADD_FITTING_FUNCTIONS

///Kyle 06/25/2009 ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU
#ifdef SET_VALUES_SUPPORT_DEFINE_VARIBLE
#include "InsertUserVar.h"
#endif
///End ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU

#include <Profiler.h>
#include <Time.h>

#define HOUR_GLASS			waitCursor junk;
#define _SHOW_TIME			Profiler junk;
#define PROFILE_HRGLASS		HOUR_GLASS

#define WM_USER_ADD_VALUE_BY_SELECTION 		(WM_USER + 1010)
#define WM_USER_APPLY_FINISHED				(WM_USER + 1011)	///Sophy 5/12/2008 v8.0860 QA80-11031-P1 FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
#include <OCLT.h>
#include <event_utils.h>
#include "ColMatValues.h"
typedef string (*FUNCFB) (HWND hParent = NULL);

//---- CPY 11/3/2007 SET_COL_VALUES_AUTO_NEED_LOCALIZATION
#define _L_STR_EMPTY _L("Empty")  //CPY 11/3/07
bool is_str_auto(LPCSTR lpcsz)
{
	int nn = okutil_cvt_str_to_predefined_type(lpcsz);
	return PDS_AUTO == nn? true:false;
}
//---- end SET_COL_VALUES_AUTO_NEED_LOCALIZATION

bool s_bSetCalValFirstTime = true; //----- CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE

//----- CPY 7/18/09 QA80-13746 SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP
///Kyle 07/20/2009 QA80-13746-P2 SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP, move to Analysis_utils
//static bool is_str_good_for_col_func(const string& str)
//{
	//if(str.IsEmpty())
		//return false;
	//
	//if(is_str_numeric(str))
		//return false;
	//LPSTR lpsz = find_any_of_characters_in_str(str,"\"([{}])");
	//if(lpsz)
		//return false;
	//
	//return true;
//}
///End SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP
//-----
///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
//static string make_colSN_LN_str(LPCSTR lpcszSN, LPCSTR lpcszLN)
static string make_colSN_LN_str(LPCSTR lpcszSN, LPCSTR lpcszLN, bool bMatrix)
///End CONSIDER_MAT_IN_COL_MAT_MENU
{
	string str;
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	//str.Format("Col(%s)", lpcszSN);
	if(bMatrix)
		str.Format("Mat(%s)", lpcszSN);
	else
		str.Format("Col(%s)", lpcszSN);
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	
	string strLongName(lpcszLN);
	if(!strLongName.IsEmpty())
		str += ": " + strLongName;
	return str;
}
//lpcszMenu_colSN_LN_str constructed from make_colSN_LN_str above 
///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
//static string make_LT_col_func_str(LPCSTR lpcszMenu_colSN_LN_str, Worksheet* pwks)
static string make_LT_col_func_str(LPCSTR lpcszMenu_colSN_LN_str, Datasheet* pDs)
///End CONSIDER_MAT_IN_COL_MAT_MENU
{
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	MatrixLayer ml(*pDs);
	bool bMatrix = ml.IsValid();
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	string strColSN, strLN;
	string str(lpcszMenu_colSN_LN_str);
	int nIndex = str.Find(':');
	if(nIndex > 0)
	{
		strColSN = str.Left(nIndex);strColSN.TrimRight();
		strLN = str.Mid(nIndex+1);strLN.TrimLeft();strLN.TrimRight();
	}
	else
		strColSN = str;
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	//int n1 = lstrlen("Col(");
	int n1 = bMatrix ? lstrlen("Mat(") : lstrlen("Col(");
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	int n2 = strColSN.GetLength()-1; // terminating )
	string strSN = strColSN.Mid(n1, n2-n1);
	//string strName = strSN;
	//--- CPY 7/21/09 QA80-13746-P2 SCV_VC_CHANGE_APPLY_TO_CENTRALIZE_OC_CODE
	/*
	if(pwks && is_str_good_for_col_func(strLN) ) //prefer LN unless if is in conflict with a SN or not a good str
	{
		Column cc = pwks->Columns(strLN);
		if(!cc)
		///Kyle 07/20/2009 QA80-13746-P2 SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP
			//strName = strLN;
		{
			int nCount = 0;			// count of columns with the same long name
			for(int nCol=pwks->GetNumCols()-1; nCol >= 0; nCol--)
			{
				Column col(*pwks, nCol);
				ASSERT(col);
				string str = col.GetLongName();
				if(str.CompareNoCase(strLN) == 0)
					nCount++;
			}
			ASSERT(nCount >= 1);
			if(nCount <= 1)				// no duplicate
				strName = strLN;
		}
		///End SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP
	}
	str.Format("Col(%s)", strName);
	*/
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	//if(pwks)
	//{
	//	Column cc = pwks->Columns(strSN);
	//	cc.GetRangeString(str, NTYPE_NO_BOOKSHEET | NTYPE_GOOD_LN_OR_SN);
	//}
	//else
	//	str.Format("Col(%s)", strSN);
	DataObject ob;
	if(pDs)
	{
		if(ml)			// FindCol will fail for matrix
		{
			//ob = pDs->FindCol(strSN);
			foreach(MatrixObject mo in ml.MatrixObjects)
			{
				string strTmp = mo.GetName();
				if(0 == strTmp.CompareNoCase(strSN))
				{
					ob = mo;
					break;
				}
			}
		}
		else
		{
			Worksheet wks(*pDs);
			ob = wks.Columns(strSN);
		}
		ASSERT(ob);
	}
	if(ob)
	{
		ob.GetRangeString(str, NTYPE_NO_BOOKSHEET | NTYPE_GOOD_LN_OR_SN);
	}
	else
	{
		string strFormat = bMatrix ? "Mat(%s)" : "Col(%s)";
		str.Format(strFormat, strSN);
	}
	
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	//--- end SCV_COL_COLUMN_BROWSER_AND_RANGE_BROWSER_SHOW_SN_LN_CLEANUP_VC_CHANGE
	return str;
}
//----- end SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP

/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////	Set Values Menu	/////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
SetValuesMenu::SetValuesMenu(HMENU &hMenu) : Menu(hMenu)
{
	//m_vsRecents.SetSize(0);
	loadFavorite();
	m_nCols = 0;///Jasmine 04/27/06 MODIFICATION_UPDATE_COLUMN_LIST
	//m_bMatrixTags = FALSE;		///Kyle 09/14/2009 QA80-12308 NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
	m_pFuncMenu = NULL;	///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
}
SetValuesMenu::~SetValuesMenu()
{
	saveFavorite();
	delete m_pFuncMenu;	///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
}

///Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
BOOL SetValuesMenu::Load(HMENU hMenu)
{
	BOOL bRet = Menu::Load(hMenu);
	if(bRet)				// reset all the settings
	{
		m_nCols = 0;
		//m_bMatrixTags = FALSE;			///Kyle 09/14/2009 QA80-12308 NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
		m_strSection = "";
		m_strFile = "";
		m_nSample = 0;
		m_nFormula = 0;
		m_nRecFormula = 0;
		m_vsRecFormula.SetSize(0);
	}
	return bRet;
}
///End UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED

#define POS_COL1	1
#define POS_COLA	2

#define COL1		"wcol(1)"//"Col(A)"	///Jasmine 03/05/07 CHANGE_COL_TO_WCOL_FOR_INDEX
#define COLA		"Col(A)"

#define MAT1		"Mat(1)"
#define MATA		"Mat(A)"


// this function remove the popup-menu items for Col(1) and Col(A)
// And reinserts them with proper names
///Kyle 09/14/2009 QA80-12308 NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
/*
void SetValuesMenu::update_submenu_titles(BOOL bMatrix)
{

   if(bMatrix == m_bMatrixTags)
	   return;

	HMENU hMainMenu = GetSafeHmenu();
	if(!hMainMenu)
		return;
	
	//save the submenus
	HMENU hmColA = GetSubMenu(hMainMenu, POS_COLA);
	HMENU hmCol1 = GetSubMenu(hMainMenu, POS_COL1);

	//Modify strings
	ModifyMenu(POS_COL1, MF_BYPOSITION|MF_POPUP, (uint)hmCol1, bMatrix ? MAT1 : COL1);
	ModifyMenu(POS_COLA, MF_BYPOSITION|MF_POPUP, (uint)hmColA, bMatrix ? MATA : COLA);
	
	m_bMatrixTags = bMatrix;
}
*/
///End NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
//#define		OC_CATEGORY_FUNCTION_SEPARATOR		':'
//
//#define		SORTED_SUB_FUNCTIONS								\
	//if ( vsSubFuncs.GetSize() > 0 )								\
	//{															\
		//vsSubFuncs.Sort(SORT_ASCENDING, TRUE, vnIndices);		\
		//vsSubFunctions.Reorder(vnIndices);						\
		//vsSotredFuncs.Append(vsSubFunctions);					\
		//vsSubFuncs.SetSize(0);									\
		//vsSubFunctions.SetSize(0);								\
	//}
//
//static	void	_make_oc_function_names(vector<string>& vsFuncNames, const vector<string>& vsCategories, const vector<string>& vsRetTypes, const vector<string>& vsArgs)
//{
	//ASSERT(vsFuncNames.GetSize() == vsCategories.GetSize());
	//
	//vector<string>		vsFunctionNames(vsFuncNames.GetSize());
	//
	//int		ii=0;
	//for ( ; ii<vsFuncNames.GetSize(); ++ii )
	//{
		//if ( vsCategories[ii].IsEmpty() )
			//vsFunctionNames[ii].Format("%s %s%s", vsRetTypes[ii], vsFuncNames[ii], vsArgs[ii]);
		//else
			//vsFunctionNames[ii].Format("%s %c %s %s%s", vsCategories[ii] ,OC_CATEGORY_FUNCTION_SEPARATOR, vsRetTypes[ii], vsFuncNames[ii], vsArgs[ii]);
	//}
	//
	//vector<uint>	vnIndices;
	//
	///// First sorted by categories
	//vsCategories.Sort(SORT_ASCENDING, TRUE, vnIndices);
	//vsFuncNames.Reorder(vnIndices);
	//vsFunctionNames.Reorder(vnIndices);
	//
	///// Then by functions
	///// not found any nested sort for vector<string> ... temp write one here
	//vector<string>		vsSubFuncs;
	//vector<string>		vsSubFunctions;
	//vector<string>		vsSotredFuncs;
	//string	str;
	//for ( ii=0; ii<vsCategories.GetSize(); ++ii )
	//{
		//if ( vsCategories[ii].Compare(str) == 0 )
		//{
			//vsSubFuncs.Add(vsFuncNames[ii]);
			//vsSubFunctions.Add(vsFunctionNames[ii]);
			//continue;
		//}
		//
		//SORTED_SUB_FUNCTIONS
		//
		//str = vsCategories[ii];
		//vsSubFuncs.Add(vsFuncNames[ii]);
		//vsSubFunctions.Add(vsFunctionNames[ii]);
	//}
	//
	//SORTED_SUB_FUNCTIONS
	//
	//vsFuncNames = vsSotredFuncs;
//}
//
//static	void	_check_get_oc_func_str(string& str)
//{
	//string	strName = str.GetToken(1, OC_CATEGORY_FUNCTION_SEPARATOR);
	//if ( !strName.IsEmpty() )
	//{
		//strName.TrimLeft();
		//strName.TrimRight();
		//str = strName;
	//}
//}
/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU

///jasmine 08/28/06 SHARE_DLG_WITH_MAT	
///Jasmine 04/27/06 MODIFICATION_UPDATE_COLUMN_LIST
/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
//void SetValuesMenu::ConstructDlgMenu(const vector<string>& vsColNames, bool bUpdateFunc, bool bSwitch, int nType)// = false
///Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
//void SetValuesMenu::ConstructDlgMenu(const vector<string>& vsColNames, int nFuncMenuInitMode, bool bSwitch, int nType)// = false
void SetValuesMenu::ConstructDlgMenu(const vector<string>& vsColSNames, const vector<string>& vsColLNames, int nFuncMenuInitMode, bool bSwitch, int nType)
///End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
{
	if(bSwitch)  
	{		
		saveFavorite();
		switch(nType)
		{
		case EXIST_MATRIX:
			m_strSection = STR_MFORMULA_SECTIONS;
			m_strFile = STR_FAVORITE_MFORMULA_FILE;
			break;
		case EXIST_WKS:
		default:
			m_strSection = STR_FORMULA_SECTIONS;
			m_strFile = STR_FAVORITE_FORMULA_FILE;
			break;
		}
		loadFavorite();
		///Jasmine 05/12/06 
		vector<string> vsKeyNames;
		//----- CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE
		//INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
		//iniFile.GetKeyNames(vsKeyNames, STR_FORMULA_SECTIONS);
		//Load Sample
		///////RemoveOld//////////////////////
		if(0 < m_nSample)
		{
			//to be insert from
			InsertMenu(IDC_LOAD_FORMULA_SAMPLE, MF_STRING, IDC_SET_VALUE_EMPTY10, _L_STR_EMPTY);
			//remove all item
			for(int ii=0; ii<m_nSample; ii++)
				RemoveMenu(IDC_LOAD_FORMULA_SAMPLE+ii, MF_STRING);
		}
		m_nSample = 0;
		/////////////////////////////
		string strFormula = okutil_get_origin_path(ORIGIN_PATH_SYSTEM) + m_strFile;//STR_FAVORITE_FORMULA_FILE_SYS;
		okutil_get_file_sections(strFormula, &vsKeyNames);
		for(int ii=0; ii<vsKeyNames.GetSize(); ii++)
			AddToFormulaList(vsKeyNames[ii], ii, false);
		/*
		if(s_bSetCalValFirstTime && ) // may need to check
		{
			FileCopy(STR_FAVORITE_FORMULA_FILE_SYS, strFormula);
			s_bSetCalValFirstTime = false;
		}*/
		//Load User's Formula
		if(0 < m_nFormula)
		{
			//to be insert from
			InsertMenu(IDC_LOAD_FORMULA, MF_STRING, IDC_SET_VALUE_EMPTY9, _L_STR_EMPTY);
			//remove all item
			for(ii=0; ii<m_nFormula; ii++)
				RemoveMenu(IDC_LOAD_FORMULA+ii, MF_STRING);
		}
		m_nFormula = 0;
		/////////////////////////////
		strFormula = okutil_get_origin_path(ORIGIN_PATH_USER) + m_strFile;//STR_FAVORITE_FORMULA_FILE;
	//--CPY 5/17/06, this is not needed
	/*	if(!strFormula.IsFile())
		{
			HANDLE hFile = CreateFile(strFormula,GENERIC_READ, FILE_SHARE_READ,// share for reading
										NULL,                  			  		// no security
										CREATE_NEW,            					// new file only
										FILE_ATTRIBUTE_NORMAL,     				// normal file
										NULL);									// no attr. template
			if(hFile == INVALID_HANDLE_VALUE)
				return;
			CloseHandle(hFile);
		}
	*/
		vsKeyNames.SetSize(0);
		okutil_get_file_sections(strFormula, &vsKeyNames);
		//-----
		for(ii=0; ii<vsKeyNames.GetSize(); ii++)
			AddToFormulaList(vsKeyNames[ii], ii);
		///End ADD_FORMULA_LIST
		//Load Last Use
		///////RemoveOld//////////////////////
		if(0 < m_nRecFormula)
		{
			//to be insert from
			InsertMenu(IDC_RECENT_FILE_LIST_BEGIN2, MF_STRING, IDC_SET_VALUE_EMPTY11, _L_STR_EMPTY);
			//remove all item
			for(ii=0; ii<m_nRecFormula; ii++)
				RemoveMenu(IDC_RECENT_FILE_LIST_BEGIN2+ii, MF_STRING);
		}
		m_nRecFormula = 0;
		/////////////////////////////
		if(0 < m_vsRecFormula.GetSize())
			addToFavoritesList(m_vsRecFormula, false)
	}

	//update_submenu_titles(EXIST_MATRIX ==  nType);		///Kyle 09/14/2009 QA80-12308 NO_NEED_TO_SWITCH_SUB_MENU_TITLES_SINCE_IT_IS_LOADED_FROM_DIFF_RESOURCE
	///Jasmine 03/05/07 CHANGE_COL_TO_WCOL_FOR_INDEX
	
	string strPrefix1, strPrefix2;
	switch(nType)
	{
	case EXIST_MATRIX:
		strPrefix1 = strPrefix2 = "Mat(";		
		break;
	case EXIST_WKS:
	default:
		strPrefix1 = "wcol(";
		strPrefix2 = "Col(";
		break;
	}
	//bool bEllipsis=false;	//no need
	
	//remove old column list
	if(m_nCols > 0)
	{
		RemoveMenu(IDC_BROWSE_COLUMNS_SEPARATOR, MF_SEPARATOR);
		RemoveMenu(IDC_BROWSE_COLUMNS_SEPARATOR + 1, MF_SEPARATOR);
		for(int nCol = 0; nCol < m_nCols; nCol++)
		{
			RemoveMenu(IDC_SET_VALUE_COL_LIST_BEGIN + nCol, MF_STRING);
			RemoveMenu(IDC_SET_VALUE_COL_LIST_END - nCol, MF_STRING);
		}
	}
	///Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	/*
	for(int nCol=0; nCol<vsColNames.GetSize(); nCol++)
	{
		if(MAX_COL_NUM_IN_MENU < nCol)	//not list all menu, if exist cols > max number, add "..."
		{
			//add in resource, so comment these 
			//InsertMenu(IDC_SET_VALUE_EMPTY, MF_STRING, IDC_BROWSE_COLUMNS, "...");
			//ModifyMenu(IDC_BROWSE_COLUMNS, MF_STRING, IDC_BROWSE_COLUMNS, "...");
			
			//bEllipsis = true;
			break;
		}
		
		//InsertMenu(IDC_SET_VALUE_EMPTY, MF_STRING, IDC_SET_VALUE_COL_LIST_BEGIN+nCol, strPrefix+(nCol+1)+")");
		InsertMenu(IDC_BROWSE_COLUMNS2, MF_STRING, IDC_SET_VALUE_COL_LIST_BEGIN+nCol, strPrefix1+(nCol+1)+")");
		InsertMenu(IDC_BROWSE_COLUMNS, MF_STRING, IDC_SET_VALUE_COL_LIST_END-nCol, strPrefix2+vsColNames[nCol]+")");
	}
	*/
	int nSize = vsColSNames.GetSize() < vsColLNames.GetSize() ? vsColSNames.GetSize() : vsColLNames.GetSize();
	for(int nCol=0; nCol<nSize; nCol++)
	{
		if(MAX_COL_NUM_IN_MENU < nCol)	//not list all menu, if exist cols > max number, add "..."
			break;
		///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
		//string strColString = make_colSN_LN_str(vsColSNames[nCol], vsColLNames[nCol]);
		string strColString = make_colSN_LN_str(vsColSNames[nCol], vsColLNames[nCol], EXIST_MATRIX ==  nType);
		///End CONSIDER_MAT_IN_COL_MAT_MENU
		
		InsertMenu(IDC_BROWSE_COLUMNS2, MF_STRING, IDC_SET_VALUE_COL_LIST_BEGIN+nCol, strPrefix1+(nCol+1)+")");
		InsertMenu(IDC_BROWSE_COLUMNS, MF_STRING, IDC_SET_VALUE_COL_LIST_END-nCol, strColString);
	}
	///End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	///End CHANGE_COL_TO_WCOL_FOR_INDEX
	//RemoveMenu(IDC_SET_VALUE_EMPTY, MF_STRING);
	//if(!bEllipsis)
		//InsertMenu(IDC_BROWSE_COLUMNS, MF_SEPARATOR, IDC_BROWSE_COLUMNS_SEPARATOR, NULL);
	InsertMenu(IDC_BROWSE_COLUMNS2, MF_SEPARATOR, IDC_BROWSE_COLUMNS_SEPARATOR + 1);
	InsertMenu(IDC_BROWSE_COLUMNS, MF_SEPARATOR, IDC_BROWSE_COLUMNS_SEPARATOR);
		
	m_nCols = nCol;	
	
	/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	//if(!bUpdateFunc)//init the function list when dlg open, and mostly, no need to update in the rest of time
	if(MENU_NOT_INIT == nFuncMenuInitMode)
	///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
		return;
	
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	////1. General
	////2. Special
	////3. Nag Special
	////4. Statistics
	////5. CDF
	////6. PDF
	////7. INV
	////8. RND
	////init Function List and Favorites List when open dlg
	/////Jake 07/10/07 ADD_FUNCTION_TYPE
	//vector<string> vsGeneralFunctions = {"abs()","acos()","angle(,)","asin()","atan()","cos()","cosh()","exp()","int()","ln()","log()","mod(,)","nint()","prec(,)",
									     //"rmod(,)","round(,)","sin()","sinh()","sqrt()","tan()", "tanh()"};
									     /////Jake 07/23/07 REVOME_FUNCTIONS
									     //
	/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	////vector<string> vsSpecialFunctions = /*{"Boltzmann(x,A1,A2,x0,dx)","Dhyperbl(x,P1,P2,P3,P4,P5)", "ExpAssoc(x,y0,A1,t1,A2,t2)",//"erf()",///Jasmine 07/10/07 ERF_IN_BFC_NAG_SF
										 ////"ExpDecay3(x,y0,x0,A1,t1,A2,t2,A3,t3)",*/ 
										 ////{/*"ExpGrow2(x,y0,x0,A1,t1,A2,t2)","gammaln()","Gauss(x,y0,xc,w,A)","Hyperbl(x,P1,P2)",*/	///Jasmine 09/03/07 REMOVE_EXPGROW2_BY_MAX_REQUIRE
										 ////"beta(,)","incbeta(,,)","incf(,,)","incgama(,)","inverf()","j0()","j1()","jn(,)",/*"Logistic(x,A1,A2,x0,p)","Lorentz(x,y0,xc,w,A)",
										 ////"Poly(x,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)","Pulse(x,y0,x0,A,t1,P,t2)",*/"y0()","y1()","yn(,)"};
										 ///////end REVOME_FUNCTIONS
										 //
	//
	//vector<string> vsSpecialFunctions = {"beta(,)","incbeta(,,)","incf(,,)","incgama(,)","inverf()","j0()","j1()","jn(,)", "y0()","y1()","yn(,)"};
	/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//
	/////END ADD_FUNCTION_TYPE
	////vector<string> vsStatisticsFunctions = {"invf(,,)","invprob()","invt(,)","prob()","qcd2()","qcd3()","qcd4()","ftable(,,)","ttable(,)"};
	//vector<string> vsStatisticsFunctions = {"ave(,)","diff()","cov(,,,)","histogram(,,,)","percentile(,)","qcd2()","qcd3()","qcd4()","ss(,)","sum()"};	///Jasmine 04/03/07 REMOVE_INVF_ETC_PER_MAX_REQUEST
	//
	////----Jake 04/26/07 ADD_MISCELLANEOUSFUN_CATEGORY 
	//vector<string> vsMiscellaneousFunctions = {"data(,,)", "errof()", "FindMasks()", "peaks(,,)","sort()","tReplace(,,,)", "xof()"}; ///Jasmine 06/26/07 ADD_LT_VECTOR_FUNC, from sdk\mseries.c static PSTR func_names[]
	//vector<string> vsCommonVariables = {"_ThisColNum", "i", "pi"}; 		///Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE 
	//
	//int nNewID = IDC_BASIC_FUNCTIONS_BEGIN;
	//for(int ii=0; ii<vsGeneralFunctions.GetSize(); ii++)
		//InsertMenu(IDC_SET_VALUE_EMPTY1, MF_STRING, nNewID++, vsGeneralFunctions[ii]);
	//for(ii=0; ii<vsSpecialFunctions.GetSize(); ii++)
		//InsertMenu(IDC_SET_VALUE_EMPTY2, MF_STRING, nNewID++, vsSpecialFunctions[ii]);
	//for(ii=0; ii<vsStatisticsFunctions.GetSize(); ii++)
		//InsertMenu(IDC_SET_VALUE_EMPTY4, MF_STRING, nNewID++, vsStatisticsFunctions[ii]);
	////----Jake 04/26/07 ADD_MISCELLANEOUSFUN_CATEGORY
	//for(ii=0; ii<vsMiscellaneousFunctions.GetSize(); ii++)
		//InsertMenu(IDC_SET_VALUE_EMPTY12, MF_STRING, nNewID++, vsMiscellaneousFunctions[ii]);
	////end ADD_MISCELLANEOUSFUN_CATEGORY
	//
	/////Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE 
	//for(ii=0; ii<vsCommonVariables.GetSize(); ii++)
		//InsertMenu(IDC_SET_VALUE_EMPTY16, MF_STRING, nNewID++, vsCommonVariables[ii]);
	/////End MENU_ITEM_FOR_COMMON_VARIABLE
	//
	//RemoveMenu(IDC_SET_VALUE_EMPTY1, MF_STRING);
	//RemoveMenu(IDC_SET_VALUE_EMPTY2, MF_STRING);
	//RemoveMenu(IDC_SET_VALUE_EMPTY4, MF_STRING);
	//RemoveMenu(IDC_SET_VALUE_EMPTY12, MF_STRING);//----Jake 04/26/07 ADD_MISCELLANEOUSFUN_CATEGORY
	//RemoveMenu(IDC_SET_VALUE_EMPTY16, MF_STRING);///Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE 
	//
	/////Jasmine 04/27/06 ADD_NAF_SP_CDF_PDF_INV_RNG
	////add Cumulative Distribution Functions. Probability density functions...
	/////Kyle 12/04/2008 QA70-9982-S1 MERGE_OC_NUMERIC_STRING_VECTOR_TO_OC_FUNCTION
	////vector<uint> vnPosIDs = {IDC_SET_VALUE_EMPTY3, IDC_SET_VALUE_EMPTY5, IDC_SET_VALUE_EMPTY6, IDC_SET_VALUE_EMPTY7, IDC_SET_VALUE_EMPTY8,IDC_SET_VALUE_EMPTY13,IDC_SET_VALUE_EMPTY14,IDC_SET_VALUE_EMPTY15};//Jake 07/10/07 ADD_FUNCTION_TYPE
	////vector<int>	 vnType = {BFC_NAG_SF, BFC_CDF, BFC_PDF, BFC_INV, BFC_RNG,BFC_OC_RETURN_NUMERIC,BFC_OC_RETURN_STRING,BFC_OC_RETURN_VECTOR};//Jake 07/10/07 ADD_FUNCTION_TYPE
	//vector<uint> vnPosIDs = {IDC_SET_VALUE_EMPTY3, IDC_SET_VALUE_EMPTY5, IDC_SET_VALUE_EMPTY6, IDC_SET_VALUE_EMPTY7, IDC_SET_VALUE_EMPTY8};
	//vector<int>	 vnType = {BFC_NAG_SF, BFC_CDF, BFC_PDF, BFC_INV, BFC_RNG};
	/////End MERGE_OC_NUMERIC_STRING_VECTOR_TO_OC_FUNCTION
	//for(ii = 0; ii < vnPosIDs.GetSize(); ii++)
	//{
		/////Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
		////vector<string> vsFuncNames, vsArgs;
		////int nCount = find_LT_functions(vsFuncNames, vsArgs, vnType[ii]);
		//vector<string> vsRetTypes, vsFuncNames, vsArgs;
		//int nCount = find_LT_functions(vsRetTypes, vsFuncNames, vsArgs, vnType[ii]);
		/////End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
		//for(int jj = 0; jj < nCount; jj++)
			//InsertMenu(vnPosIDs[ii], MF_STRING, nNewID++, vsFuncNames[jj] + vsArgs[jj]);
		//if(nCount > 0)
			//RemoveMenu(vnPosIDs[ii], MF_STRING);
	//}
	//
	/////Kyle 12/04/2008 QA70-9982-S1 MERGE_OC_NUMERIC_STRING_VECTOR_TO_OC_FUNCTION
	//vector<string> vsRetTypes, vsFuncNames, vsArgs;
	//vector<string>	vsCategories;		///------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//vector<int> vnOCType = {BFC_OC_RETURN_NUMERIC, BFC_OC_RETURN_STRING, BFC_OC_RETURN_VECTOR};
	//int nCount;
	//for(ii = 0; ii < vnOCType.GetSize(); ii++)
	//{
		//vector<string> vsTempRetTypes, vsTempFuncs, vsTempArgs;
		/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
		////nCount += find_LT_functions(vsTempRetTypes, vsTempFuncs, vsTempArgs, vnOCType[ii]);
		//vector<string>	vsCategoriesTmp;
		//nCount += find_LT_functions(vsTempRetTypes, vsTempFuncs, vsTempArgs, vnOCType[ii], false, &vsCategoriesTmp);
		/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
		//vsRetTypes.Append(vsTempRetTypes);
		//vsFuncNames.Append(vsTempFuncs);
		//vsArgs.Append(vsTempArgs);
		//vsCategories.Append(vsCategoriesTmp);	///------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//}
	//
	/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//_make_oc_function_names(vsFuncNames, vsCategories, vsRetTypes, vsArgs);
	/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//
	//for(ii = 0; ii < nCount; ii++)
		/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
		////InsertMenu(IDC_SET_VALUE_EMPTY13, MF_STRING, nNewID++, vsRetTypes[ii] + " " + vsFuncNames[ii] + vsArgs[ii]);
		//InsertMenu(IDC_SET_VALUE_EMPTY13, MF_STRING, nNewID++, vsFuncNames[ii]);
		/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	//if(nCount > 0)
		//RemoveMenu(IDC_SET_VALUE_EMPTY13, MF_STRING);
	/////End MERGE_OC_NUMERIC_STRING_VECTOR_TO_OC_FUNCTION
	//
	//
	//if(0 < m_vsRecFunc.GetSize())
	//{
		////InsertMenu(IDC_SET_VALUE_EMPTY, MF_SEPARATOR, IDC_BROWSE_COLUMNS_SEPARATOR + 2);
		//addToFavoritesList(m_vsRecFunc);
	//}
	///Kyle 05/21/2009 NEW_STRUCTURE_OF_SET_COLUMN_VALUES_DIALOG_F_X_PULL_DOWN_MENU
	//vector<uint> vnCategoryIDs = {	IDC_FUNCTION_MENU_MATH, IDC_FUNCTION_MENU_STATS, IDC_FUNCTION_MENU_CDF, IDC_FUNCTION_MENU_PDF, IDC_FUNCTION_MENU_INV,
									//IDC_FUNCTION_MENU_DATE_TIME, IDC_FUNCTION_MENU_TEXT, IDC_FUNCTION_MENU_DATA_GENERATION, IDC_FUNCTION_MENU_NAG,
									//IDC_FUNCTION_MENU_MISCELLANEOUS, IDC_FUNCTION_MENU_USER_DEFINED, IDC_FUNCTION_MENU_VARIABLE_CONSTANT, IDC_FUNCTION_MENU_DISTRIBUTIONS };
#ifdef NEW_STRUCTURE_OF_SET_COL_VAL_F_X_POLL_DOWN_MENU
	vector<uint> vnCategoryIDs = {	IDC_FUNCTION_MENU_MATH, IDC_FUNCTION_MENU_STATS, IDC_FUNCTION_MENU_CDF, IDC_FUNCTION_MENU_PDF, IDC_FUNCTION_MENU_INV,
									IDC_FUNCTION_MENU_DATE_TIME, IDC_FUNCTION_MENU_TEXT, 
									IDC_FUNCTION_MENU_DATA_GENERATION, IDC_FUNCTION_MENU_DATASET_INFORMATION, IDC_FUNCTION_MENU_DATA_MANIPULATION,
									IDC_FUNCTION_MENU_NAG,
									IDC_FUNCTION_MENU_MISCELLANEOUS, IDC_FUNCTION_MENU_USER_DEFINED, IDC_FUNCTION_MENU_VARIABLE_CONSTANT, IDC_FUNCTION_MENU_DISTRIBUTIONS };
#else
	vector<uint> vnCategoryIDs = {	IDC_FUNCTION_MENU_MATH, IDC_FUNCTION_MENU_STATS, IDC_FUNCTION_MENU_CDF, IDC_FUNCTION_MENU_PDF, IDC_FUNCTION_MENU_INV,
									IDC_FUNCTION_MENU_DATE_TIME, IDC_FUNCTION_MENU_TEXT, IDC_FUNCTION_MENU_DATA_GENERATION, IDC_FUNCTION_MENU_NAG,
									IDC_FUNCTION_MENU_MISCELLANEOUS, IDC_FUNCTION_MENU_USER_DEFINED, IDC_FUNCTION_MENU_VARIABLE_CONSTANT, IDC_FUNCTION_MENU_DISTRIBUTIONS };
#endif //NEW_STRUCTURE_OF_SET_COL_VAL_F_X_POLL_DOWN_MENU
	///End NEW_STRUCTURE_OF_SET_COLUMN_VALUES_DIALOG_F_X_PULL_DOWN_MENU

	
	///Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS
#ifdef _ADD_FITTING_FUNCTIONS_TO_SCV
	vnCategoryIDs.Add(IDC_FUNCTION_MENU_FIT_FUNC);
#endif // _ADD_FITTING_FUNCTIONS_TO_SCV
	///End SCV_ADD_FITTING_FUNCTIONS

	/// Iris 12/30/2008 v8.0992 FILTER_DISRELATED_FUNC_FROM_WKS_OR_MAT_SET_VALUE_MENU								
	//FunctionsMenu FuncMenu(GetSafeHmenu(), STR_FAVORITE_SECTIONS, vnCategoryIDs);
	//FuncMenu.Construct();
	HMENU hMenu = GetSafeHmenu();
	//string strSection = STR_FAVORITE_SECTIONS; /// Iris 01/04/2009 v8.0993c MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
	///Kyle 07/29/2009 QA80-14038 FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY, the menu is reloaded, so no need to clear it
	//bool bClearList = (nFuncMenuInitMode == MENU_REINIT); /// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS			
	///End FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY
	if(EXIST_WKS == nType)
	{
		///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
		/*
		/// Iris 01/04/2009 v8.0993c MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
		//WksFunctionsMenu FuncMenu(hMenu, strSection, vnCategoryIDs);
		WksFunctionsMenu FuncMenu(hMenu, STR_WKS_FAVORITE_SECTIONS, vnCategoryIDs);
		///end MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
		
		/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
		//FuncMenu.Construct();
		///Kyle 07/29/2009 QA80-14038 FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY, the menu is reloaded, so no need to clear it
		//FuncMenu.Construct(bClearList);
		FuncMenu.Construct();
		///End FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY
		///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS		]
		*/
		if ( bSwitch || m_pFuncMenu == NULL )
		{
			delete m_pFuncMenu;
			m_pFuncMenu = new WksFunctionsMenu(hMenu, STR_WKS_FAVORITE_SECTIONS, vnCategoryIDs);
			m_pFuncMenu->Construct();
		}
		///end MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	}
	else if(EXIST_MATRIX == nType)
	{		
		/// Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS
		vector<uint> vecIndex;
		if( vnCategoryIDs.Find(vecIndex, IDC_FUNCTION_MENU_DATE_TIME) > 0 )
			vnCategoryIDs.RemoveAt(vecIndex[0]);
		
		if( vnCategoryIDs.Find(vecIndex, IDC_FUNCTION_MENU_DATA_GENERATION) > 0 )
			vnCategoryIDs.RemoveAt(vecIndex[0]);
		///end MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS

		///Kyle 05/21/2009 NEW_STRUCTURE_OF_SET_COLUMN_VALUES_DIALOG_F_X_PULL_DOWN_MENU
#ifdef NEW_STRUCTURE_OF_SET_COL_VAL_F_X_POLL_DOWN_MENU
		if( vnCategoryIDs.Find(vecIndex, IDC_FUNCTION_MENU_DATASET_INFORMATION) > 0 )
			vnCategoryIDs.RemoveAt(vecIndex[0]);
		
		if( vnCategoryIDs.Find(vecIndex, IDC_FUNCTION_MENU_DATA_MANIPULATION) > 0 )
			vnCategoryIDs.RemoveAt(vecIndex[0]);
#endif //NEW_STRUCTURE_OF_SET_COL_VAL_F_X_POLL_DOWN_MENU
		///End NEW_STRUCTURE_OF_SET_COLUMN_VALUES_DIALOG_F_X_PULL_DOWN_MENU
		
		///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
		/*
		/// Iris 01/04/2009 v8.0993c MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
		//MatFunctionsMenu FuncMenu(hMenu, strSection, vnCategoryIDs);
		MatFunctionsMenu FuncMenu(hMenu, STR_MAT_FAVORITE_SECTIONS, vnCategoryIDs);
		///end MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST		
		
		/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
		//FuncMenu.Construct();
		///Kyle 07/29/2009 QA80-14038 FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY, the menu is reloaded, so no need to clear it
		//FuncMenu.Construct(bClearList);
		FuncMenu.Construct();
		///End FIX_ITEM_ID_DUPLICATED_IF_THERE_ARE_TOO_MANY_FUNCTIONS_IN_ONE_CATETORY
		///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS		
		*/
		if ( bSwitch || m_pFuncMenu == NULL )
		{
			delete m_pFuncMenu;
			m_pFuncMenu = new MatFunctionsMenu(hMenu, STR_MAT_FAVORITE_SECTIONS, vnCategoryIDs);
			m_pFuncMenu->Construct();
		}
		///end MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	}
	else
		ASSERT(0);	
	///end FILTER_DISRELATED_FUNC_FROM_WKS_OR_MAT_SET_VALUE_MENU
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
}///End MODIFICATION_UPDATE_COLUMN_LIST


///Kyle 04/30/2009 SUPPORT_DEFINING_VARIABLES_IN_SET_VALUES_DIALOG
/* keep the logic to construct "Other Sheets" popup here for future use
#ifdef SET_VALUES_SUPPORT_DEFINE_VARIBLE
string SetValuesMenu::GetColumnString(int nID)
{
	string strCol = GetMenuString(nID);
	string strBook, strSheet;
	if(m_mapColIDRange.Lookup(nID, strBook, strSheet))
	{
		string strTemp;
		okutil_create_complete_range_string_obj(&strTemp, strBook, strSheet, strCol);
		strCol = strTemp;
	}
	return strCol;
}


class ColumnsListMenu : public Menu
{
public:
	ColumnsListMenu(int nIDBegin, const vector<string>& vsLabels)
	{
		for(int ii=0; ii<vsLabels.GetSize(); ii++)
			Add(vsLabels[ii], nIDBegin++);
	}
};
void SetValuesMenu::constructColSubMenu(const vector<string>& vsColNames, int nType, const BookObjectsInfo& otherObjects)
{
	// add column of the active sheet, to be improved
	string strPrefix1, strPrefix2;
	switch(nType)
	{
	case EXIST_MATRIX:
		strPrefix1 = strPrefix2 = "Mat(";		
		break;
	case EXIST_WKS:
	default:
		strPrefix1 = "wcol(";
		strPrefix2 = "Col(";
		break;
	}
	//bool bEllipsis=false;	//no need
	
	//remove old column list
	if(m_nCols > 0)
	{
		RemoveMenu(IDC_BROWSE_COLUMNS_SEPARATOR, MF_SEPARATOR);
		RemoveMenu(IDC_BROWSE_COLUMNS_SEPARATOR + 1, MF_SEPARATOR);
		for(int nCol = 0; nCol < m_nCols; nCol++)
		{
			RemoveMenu(IDC_SET_VALUE_COL_LIST_BEGIN + nCol, MF_STRING);
			RemoveMenu(IDC_SET_VALUE_COL_LIST_END - nCol, MF_STRING);
		}
	}
	m_nCols = vsColNames.GetSize();
	if(m_nCols > MAX_COL_NUM_IN_MENU)
		m_nCols = MAX_COL_NUM_IN_MENU;
	
	Menu popupWCol(GetPopupHmenu(IDC_BROWSE_COLUMNS2));
	string strPopup;
	popupWCol.GetMenuString(-1, strPopup, MF_BYPOSITION | MF_STRING);
	out_str(strPopup);

	Menu popupCol(GetPopupHmenu(IDC_BROWSE_COLUMNS));
	if(m_nCols)
	{
		popupWCol.InsertMenu(0, MF_SEPARATOR | MF_BYPOSITION, IDC_BROWSE_COLUMNS_SEPARATOR + 1);
		popupCol.InsertMenu(0, MF_SEPARATOR | MF_BYPOSITION, IDC_BROWSE_COLUMNS_SEPARATOR);
	}
	for(int nCol=m_nCols-1; nCol>=0; nCol--)
	{
		popupWCol.InsertMenu(0, MF_STRING | MF_BYPOSITION, IDC_SET_VALUE_COL_LIST_BEGIN+nCol, strPrefix1+(nCol+1)+")");
		popupCol.InsertMenu(0, MF_STRING | MF_BYPOSITION, IDC_SET_VALUE_COL_LIST_END-nCol, strPrefix2+vsColNames[nCol]+")");
	}

	//// simple testing code for Tarak to test Menu::AddPopup()
	//////////////////////////////////////////////////////////////////////////////////////////////
	//Menu testOtherSheet;
	//testOtherSheet.Add("Sheet2", IDC_SET_VALUE_COL_LIST_BEGIN + m_nCols);
	//testOtherSheet.Add("Sheet2", IDC_SET_VALUE_COL_LIST_END - m_nCols);
	//popupWCol.AddPopup("Other Sheets", testOtherSheet);			//==>Other Sheets is added after Column Browser..., but it's sub item is not added and something error if move mouse on this popup
	//////////////////////////////////////////////////////////////////////////////////////////////

	// add column of the active sheet, to do
	// the class should keep m_popupWColOthers and m_popupColOthers since IDC_OTHER_SHEET_EMPTY2 and IDC_OTHER_SHEET_EMPTY will be removed and there is no other ways to get the popup
	if( !m_popupWColOthers.GetSafeHmenu() || !m_popupColOthers.GetSafeHmenu() )
	{
		HMENU hWMenu = GetPopupHmenu(IDC_OTHER_SHEET_EMPTY2);
		HMENU hMenu = GetPopupHmenu(IDC_OTHER_SHEET_EMPTY);
		if(!hWMenu || !hMenu)
			return;
		m_popupWColOthers.Load(hWMenu);
		m_popupColOthers.Load(hMenu);
		if(!m_popupWColOthers.GetSafeHmenu() || !m_popupColOthers.GetSafeHmenu())
			return;
	}
	m_popupWColOthers.RemoveAllItems();
	m_popupColOthers.RemoveAllItems();
	m_mapColIDRange.Clear();
	
	string& strBook = otherObjects.strBook;
	vector<string>& vsOtherSheets = otherObjects.vsOtherSheets;
	const vector<string>& vsColsOfOthers = otherObjects.vsColsOfOthers;
	const vector<int>& vnColsOfOthers = otherObjects.vnColsOfOthers;
	
	m_mapColIDRange.SetBook(strBook);
	
	int nIDWColBegin = IDC_SET_VALUE_COL_LIST_BEGIN + m_nCols;
	int nIDColEnd	= IDC_SET_VALUE_COL_LIST_END - m_nCols;
	int nOffset = 0;
	int nSheets = vsOtherSheets.GetSize();
	for(int nSheet = 0; nSheet < nSheets; nSheet++)
	{
		vector<string> vsWColLabels, vsColLabels;
		vsWColLabels.SetSize(vnColsOfOthers[nSheet]);
		vsColLabels.SetSize(vnColsOfOthers[nSheet]);
		for(int ii=0; ii<vnColsOfOthers[nSheet]; ii++)
		{
			vsWColLabels[ii] = strPrefix1 + (ii+1) + ")";
			vsColLabels[ii] = strPrefix2 + vsColsOfOthers[ii + nOffset] + ")";
		}
		int nBeginID = nIDWColBegin,
			nEndID = nIDWColBegin + vnColsOfOthers[nSheet] -1;
		ColumnsListMenu menuWCols(nIDWColBegin, vsWColLabels);
		m_mapColIDRange.AddOneRange(nBeginID, nEndID, vsOtherSheets[nSheet]);

		nBeginID = nIDColEnd - vnColsOfOthers[nSheet] + 1;
		nEndID = nIDColEnd;
		ColumnsListMenu menuCols(nBeginID, vsColLabels);
		m_mapColIDRange.AddOneRange(nBeginID, nEndID, vsOtherSheets[nSheet]);

		m_popupWColOthers.AddPopup(vsOtherSheets[nSheet], menuWCols);
		m_popupColOthers.AddPopup(vsOtherSheets[nSheet], menuCols);

		nIDWColBegin += vnColsOfOthers[nSheet];
		nIDColEnd -= vnColsOfOthers[nSheet];
		nOffset += vnColsOfOthers[nSheet];
	}
	
}
#endif //SET_VALUES_SUPPORT_DEFINE_VARIBLE
*/
///End SUPPORT_DEFINING_VARIABLES_IN_SET_VALUES_DIALOG



///End SHARE_DLG_WITH_MAT
///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
//void SetValuesMenu::UpdateFuncHistoryList(const string& strNew)
//{
	//int nTotalItems = m_vsRecFunc.GetSize();
	//if(0 < nTotalItems)
	//{
		////to be insert from
		//InsertMenu(IDC_RECENT_FILE_LIST_BEGIN, MF_STRING, IDC_SET_VALUE_EMPTY, _L_STR_EMPTY);
		////remove all item
		//for(int ii=0; ii<nTotalItems; ii++)
			//RemoveMenu(IDC_RECENT_FILE_LIST_BEGIN+ii, MF_STRING);
	//}
	//
	//int nFind = m_vsRecFunc.Find(strNew);
	//if(-1==nFind && MAX_COL_NUM_IN_MENU<nTotalItems)
		//nFind = 0;
	//
		//if(-1 != nFind)
		//m_vsRecFunc.RemoveAt(nFind);
	//m_vsRecFunc.Add(strNew);
	//
	//addToFavoritesList(m_vsRecFunc);
//}
///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
void SetValuesMenu::UpdateFormulaHistoryList(const string& strNew)
{
	int nTotalItems = m_vsRecFormula.GetSize();
	if(0 < nTotalItems)
	{
		//to be insert from
		InsertMenu(IDC_RECENT_FILE_LIST_BEGIN2, MF_STRING, IDC_SET_VALUE_EMPTY11, _L_STR_EMPTY);
		//remove all item
		for(int ii=0; ii<nTotalItems; ii++)
			RemoveMenu(IDC_RECENT_FILE_LIST_BEGIN2+ii, MF_STRING);
	}
	
	int nFind = m_vsRecFormula.Find(strNew);
	if(-1==nFind && MAX_COL_NUM_IN_MENU<nTotalItems)
		nFind = 0;
	
	if(-1 != nFind)
		m_vsRecFormula.RemoveAt(nFind);
	m_vsRecFormula.Add(strNew);
	
	addToFavoritesList(m_vsRecFormula, false);
}
///jasmine 08/28/06 SHARE_DLG_WITH_MAT
///Jasmine 05/12/06 ADD_FORMULA_LIST
void SetValuesMenu::AddToFormulaList(LPCSTR lpcsz, int nNum, bool bUser)// = 0, = true
{//add string to Formula Menu -> Load
	int nPos = IDC_SET_VALUE_EMPTY9, nID = IDC_LOAD_FORMULA;
	string strName = lpcsz;
	if(!bUser)
	{	nPos = IDC_SET_VALUE_EMPTY10; nID = IDC_LOAD_FORMULA_SAMPLE;	m_nSample++;}
	else
		m_nFormula++;
	if(nNum)
	{
		InsertMenu(nID + nNum - 1, MF_STRING, nID + nNum, strName);	
		return;
	}
	InsertMenu(nPos, MF_STRING, nID, strName);
	RemoveMenu(nPos, MF_STRING);
}
///End ADD_FORMULA_LIST
void SetValuesMenu::addToFavoritesList(const vector<string>& vsList, bool bFunc)//=true
{//bFunc = true, add to function's last use list; bFunc = false, add to formula's last use list
	int nPosition = IDC_SET_VALUE_EMPTY, nID = IDC_RECENT_FILE_LIST_BEGIN;
	if(!bFunc)
	{
		nPosition = IDC_SET_VALUE_EMPTY11; nID = IDC_RECENT_FILE_LIST_BEGIN2; m_nRecFormula = vsList.GetSize();
	}
	
	for(int ii=vsList.GetSize()-1; ii>=0; ii--)
		InsertMenu(nPosition, MF_STRING, nID+ii, vsList[ii]);
	
	RemoveMenu(nPosition, MF_STRING);
}
string SetValuesMenu::GetMenuString(int uCmdID)
{
	string str;
	GetMenuString(uCmdID, str, MF_STRING);
	return str;
}
//----- CPY 7/18/09 QA80-13746 SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP
/////Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
//string SetValuesMenu::GetColumnString(int uCmdID)
//{
//	string str;
//	GetMenuString(uCmdID, str, MF_STRING);
//	parse_colSN_LN_str(str, &str);
//	return str;
//}
/////End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
//string SetValuesMenu::GetColumnString(int uCmdID, Worksheet* pwks)
string SetValuesMenu::GetColumnString(int uCmdID, Datasheet* pDs)
///End CONSIDER_MAT_IN_COL_MAT_MENU
{
	string str;
	GetMenuString(uCmdID, str, MF_STRING);
	string strTmp = str;
	strTmp.MakeUpper();
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	//if(strTmp.Find("WCOL") != 0 && strTmp.Find("COL") >= 0)
	//	str = make_LT_col_func_str(str, pwks);
	if(uCmdID > MAX_COL_NUM_IN_MENU + IDC_SET_VALUE_COL_LIST_BEGIN)				// excluding WCol(1)
		str = make_LT_col_func_str(str, pDs);
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	
	return str;
}
//----- end SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP

void SetValuesMenu::loadFavorite()
{
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//m_vsRecFunc.SetSize(0);
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	m_vsRecFormula.SetSize(0);	
	vector<string> vsKeyNames;
	INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	////function
	//iniFile.GetKeyNames(vsKeyNames, STR_FAVORITE_SECTIONS);
	//for(int ii=0; ii<vsKeyNames.GetSize(); ii++)
	//{
		//m_vsRecFunc.Add(iniFile.ReadString(STR_FAVORITE_SECTIONS, vsKeyNames[ii]));
	//}
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//formula
	iniFile.GetKeyNames(vsKeyNames, m_strSection);//STR_FORMULA_SECTIONS);
	for(int ii=0; ii<vsKeyNames.GetSize(); ii++)
	{
		m_vsRecFormula.Add(iniFile.ReadString(m_strSection, vsKeyNames[ii]));//STR_FORMULA_SECTIONS
	}
}
void SetValuesMenu::saveFavorite()
{
	//if(0 >= m_vsRecents.GetSize())
		//return;
		
	INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
	
	//clear sections first
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//if(m_vsRecFunc.GetSize() && m_vsRecFormula.GetSize())
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
		clearFavoriteList();
	//functions
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//for(int ii=0; ii<m_vsRecFunc.GetSize(); ii++)
	//{
		//update_ini_line(iniFile, STR_FAVORITE_SECTIONS, STR_FAVORITE_FUNCTIONS_PREFIX+(string)ii, m_vsRecFunc[ii]);
	//}
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//formula
	for(int ii=0; ii<m_vsRecFormula.GetSize(); ii++)
	{
		update_ini_line(iniFile, m_strSection, STR_FORMULA_PREFIX+(string)ii, m_vsRecFormula[ii]);//STR_FORMULA_SECTIONS
	}
}
void SetValuesMenu::clearFavoriteList()
{
	INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//update_ini_line(iniFile, STR_FAVORITE_SECTIONS, NULL, NULL );//clean functions
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	update_ini_line(iniFile, m_strSection, NULL, NULL );//clean formula	//STR_FORMULA_SECTIONS
}
///End SHARE_DLG_WITH_MAT

/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////	Column Values	/////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
static ColValuesDlg* s_pColValueDlg;///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS

int ColValuesDlg::getMenuResourceID()
{
	int nPageType = getPageType();
	if( EXIST_WKS == nPageType )
		return IDR_SET_VALUES_MENU;
	
	if( EXIST_MATRIX == nPageType )
		return IDR_MAT_SET_VALUES_MENU;
	
	return 0;
}

BOOL ColValuesDlg::OnInitDialog()
{
	ShowWindow(SW_HIDE); //CPY, start out hidden to avoid flashing when moving into last used position
	///Jasmine 04/30/06 MULTI_FOR_PREVIOUS_SCRIPT
	vector<string>  vstrTipsUpDown;
	vstrTipsUpDown.SetSize(2);
	vstrTipsUpDown[0] = _L("Show Scripts");
	vstrTipsUpDown[1] = _L("Hide Scripts");	
	//ResizeDialog::OnInitDialog(IDC_SET_VAL_EXPRESSIONS, "ColMatSetValuesDlg");
	vector<uint> vnBottomTab={IDC_SET_VAL_PRE_SCRIPTS, 0};
	vector<string> vsButtomTab;
	vsButtomTab.SetSize(1);
	vsButtomTab[0] = _L("Before Formula Scripts");
	//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifdef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
	MultiPaneDlg::OnInitDialog(IDC_SET_VAL_EXPRESSIONS, IDC_SHOW_BOTTOM, IDC_SET_VAL_PRE_SCRIPTS, vstrTipsUpDown, STR_DLG_NAME, 0, NULL, false);
	GetItem(IDC_SET_VAL_BOTTOM_TAB).Visible = false;
#else
	///------ Folger 10/14/2010 ORG-1252 MULTIPANE_DIALOG_BAD_LAYOUT_IF_INVALID_PANE_HEIGHT_IN_REGISTRY
	//MultiPaneDlg::OnInitDialog(IDC_SET_VAL_EXPRESSIONS, IDC_SHOW_BOTTOM, IDC_SET_VAL_BOTTOM_TAB, vstrTipsUpDown, STR_DLG_NAME, 0, vsButtomTab, false);	//true to open bottom pane, false to close
	MultiPaneDlg::OnInitDialog(IDC_SET_VAL_EXPRESSIONS, IDC_SHOW_BOTTOM, IDC_SET_VAL_BOTTOM_TAB, vstrTipsUpDown, STR_DLG_NAME, 0, vsButtomTab, false, NULL, MULTIPANEDLGINIT_RESET_PANE_SIZE_IF_TOO_SMALL);	//true to open bottom pane, false to close
	///------ End MULTIPANE_DIALOG_BAD_LAYOUT_IF_INVALID_PANE_HEIGHT_IN_REGISTRY
#endif
	//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
	///End MULTI_FOR_PREVIOUS_SCRIPT
	
	/// Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS
	/*
	InitToolBar(IDR_SET_VALUES_MENU);
	/// ML 11/5/2007 PROOPER_MENU_LANGUAGE_WHEN_MENU_COMES_FROM_DLG_RESOURCE
	SetLangMenu(IDR_SET_VALUES_MENU);
	/// end PROOPER_MENU_LANGUAGE_WHEN_MENU_COMES_FROM_DLG_RESOURCE
	*/
	int nMenuID = getMenuResourceID();
	InitToolBar(nMenuID);
	SetLangMenu(nMenuID);
	///end MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS

	m_textCol = GetItem(IDC_SET_VALUE_TEXT);
	m_edRowsFrom = GetItem(IDC_SET_VAL_ROW_FROM_ED);
	m_edRowsTo = GetItem(IDC_SET_VAL_ROW_TO_ED);
	//---- CPY 5/11/09 QA70-12554 MAT_SET_VALUES_NEED_RANGE_SUPPORT
	m_edColsFrom = GetItem(IDC_SET_VAL_COL_FROM_ED);
	m_edColsTo   = GetItem(IDC_SET_VAL_COL_TO_ED);
	//----
	m_btnPrevious = GetItem(IDC_PREVIOUS_BTN);
	m_btnNext = GetItem(IDC_NEXT_BTN);
	
	//----Jake 04/18/07 ADD_FIRST_AND_LAST_BUTTON
	m_btnLast = GetItem(IDC_LAST_BTN);
	m_btnFirst = GetItem(IDC_FIRST_BTN);
	//----end ADD_FIRST_AND_LAST_BUTTON
	
	///Kyle 06/25/2009 ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU
	//GetItem(IDC_DEFINE_BTN).Visible = false;	///Jasmine 03/05/09 DEFINE_BTN_WILL_SHOW_AFTER_SR5_RELEASE 
#ifdef SET_VALUES_SUPPORT_DEFINE_VARIBLE
	/// Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED
// 	BitmapRadioButton btnDefRngBtn = GetItem(IDC_DEFINE_RANGE_BTN);
// 	if(btnDefRngBtn)
// 	{
// 		btnDefRngBtn.Visible = true;
// 		vector<string> vsTips;
// 		vsTips.Add(_L("Define Range Variable"));
// 		btnDefRngBtn.Init(1, IDB_DEF_RANGE_BTN, 16, vsTips);
// 	}
// 	
// 	BitmapRadioButton btnDefPageInfoBtn = GetItem(IDC_DEFINE_PAGE_INFO_BTN);
// 	if(btnDefPageInfoBtn)
// 	{
// 		btnDefPageInfoBtn.Visible = true;
// 		vector<string> vsTips;
// 		vsTips.Add(_L("Define Page Info Variable"));
// 		btnDefPageInfoBtn.Init(1, IDB_DEF_PAGE_INFO_BTN, 16, vsTips);
// 	}
// #else
	/// End QA81-14241 DEFINE_VARIABLE_MENU_WANTED
	Control ctrlDefBtn = GetItem(IDC_DEFINE_RANGE_BTN);
	if(ctrlDefBtn)
		ctrlDefBtn.Visible = false;
	ctrlDefBtn = GetItem(IDC_DEFINE_PAGE_INFO_BTN);
	if(ctrlDefBtn)
		ctrlDefBtn.Visible = false;
#endif
///End ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU

	m_btnApply=GetItem(IDC_APPLY_BTN);
	m_btnUndo=GetItem(IDC_UNDO_BTN);
	m_btnUndo.Visible = false;	///DG 8/19/05 : undo not power, confusing
	//------- CPY 07/26/06 QA70-8847 COLUMN_FORMULA_FROM_ORIGIN_C_REVAMP
	//m_btnAutoUpdate=GetItem(IDC_SET_VAL_AUTO_CHK);
	m_comboAutoUpdate = GetItem(IDC_SET_VAL_AUTO_CHK);
	m_comboAutoUpdate.ResetContent();
	//string strCombo = _L(STR_AU_COMBO);
	string strCombo = GetLocalized(STR_AU_COMBO); /// Hong 11/07/07 v.8.0742 FIX_ERROR_LOCALIZED
	vector<string> vsCombo;
	strCombo.GetTokens(vsCombo,'|');
	for(int ii = 0; ii < vsCombo.GetSize(); ii++)
		m_comboAutoUpdate.AddString(vsCombo[ii]);
	///Jasmine 06/22/07 REMEMBER_RECALCULATE_SETTING
	int nAutoUpdate = LoadSetting(STR_AUTO_UPDATE, AU_ON_COMMAND, STR_DLG_NAME);
	m_comboAutoUpdate.SetCurSel(nAutoUpdate);
	///End REMEMBER_RECALCULATE_SETTING
	//-------
	///Kyle 11/18/2009 QA80-14691 WANT_DOUBLE_CLICK_TO_HIGHLIGHT_A_WORD_IN_EDIT_BOX, do this before GetItem()
	m_edExpression.SetDbClkSelWord();
	m_edPrescripts.SetDbClkSelWord();
	///End WANT_DOUBLE_CLICK_TO_HIGHLIGHT_A_WORD_IN_EDIT_BOX
	m_edExpression=GetItem(IDC_SET_VAL_EXPRESSIONS);
	m_edPrescripts=GetItem(IDC_SET_VAL_PRE_SCRIPTS); //CPY 05/01/06 MULTI_FOR_PREVIOUS_SCRIPT
	///Jasmine 06/20/07 FIX_BUG_OF_SPECIFIED_FONT
	//------ CPY 2/12/2007 SCRIPT_EDIT_BOX_SHOULD_BE_FIXED_WIDTH_FONT
	//---- CPY 10/2/2007 QA70-10375 USE_CACHED_FONT
	//m_edExpression.SetFont(ANSI_FIXED_FONT);//SYSTEM_FIXED_FONT
	//m_edPrescripts.SetFont(ANSI_FIXED_FONT);
	m_edExpression.UseSysFont(GSFI_SYSTEM_MENU, true);
	m_edPrescripts.UseSysFont(GSFI_SYSTEM_MENU, true);
	//---- end USE_CACHED_FONT
	//------ end SCRIPT_EDIT_BOX_SHOULD_BE_FIXED_WIDTH_FONT
	///End FIX_BUG_OF_SPECIFIED_FONT
	HMENU 	hMenu = getDlgMenu();
	m_pDlgMenu = new SetValuesMenu(hMenu);
	m_bLayerChanged = true;///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS
	m_strCurFormulaName = "";
	//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifdef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
	GetItem(IDC_SCRIPT_TITLE).Visible = IsBottomPaneShown();
#else
	GetItem(IDC_SCRIPT_TITLE).Visible = false;
#endif
	//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
	m_bOnDoingApply = false;	///Sophy 5/12/2008 v8.0860 QA80-11031-P1 FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
	return true;
}
BOOL ColValuesDlg::OnReady()
{
	UpdateDlgSize();///Jasmine 04/30/06 MULTI_FOR_PREVIOUS_SCRIPT		
	UpdateDlgShow();
	
	SetInitReady();
	
	/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	//initCtrlValue(true);///Jasmine 04/27/06 MODIFICATION_UPDATE_COLUMN_LIST
	initCtrlValue(MENU_INIT);
	///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	
	//OnActivePageChange();
	m_edExpression.SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE);	///for richedit event
	m_edPrescripts.SendMessage(EM_SETEVENTMASK, 0, ENM_CHANGE);
	ShowWindow(SW_NORMAL);
	return true;
}
BOOL ColValuesDlg::OnDestroy()
{
	SaveSetting(STR_AUTO_UPDATE, m_comboAutoUpdate.GetCurSel(), STR_DLG_NAME);	///Jasmine 06/22/07 REMEMBER_RECALCULATE_SETTING
	//--- CPY 10/31/06 DATA_OBJ_FROM_COL_PROP_DIALOG
	if(m_pDataOB)
	{
		delete m_pDataOB;
		m_pDataOB = NULL;
		//out_str("OnDestroy found obj still not deleted");
	}
	//---

	if(m_pDlgMenu)
	{
		delete m_pDlgMenu;
		m_pDlgMenu=NULL;
	}
	///Jasmine 04/30/06 MULTI_FOR_PREVIOUS_SCRIPT	
	MultiPaneDlg::OnDestroy();//ResizeDialog::OnDestroy();
	///Kenny 04/28/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
	//delete this;	///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS
	//s_pColValueDlg = NULL;
	if (m_bDeleteOnDestroy)
	{
		delete this;
		s_pColValueDlg = NULL;
	}
	///End QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
	return true;
}
///Kyle 07/14/08 QA80-11830 LIMIT_THE_MIN_WIDTH_OF_SET_COLUMN_VALUES_DLG
int	ColValuesDlg::GetTotalWidth(bool bMin)// = false
{
	return MIN_MAIN_DLG_WIDTH;
}
///End LIMIT_THE_MIN_WIDTH_OF_SET_COLUMN_VALUES_DLG
BOOL ColValuesDlg::OnDlgResize(int nType, int cx, int cy)
{
	if(!IsInitReady())
		return TRUE;
	MoveControlsHelper	_temp(this);		///Jasmine 03/27/06 DLG_RESIZE_PAINT_MESS
	
	//IDC_UNDO_BTN is no longer used
	uint nButtonIDs[] = {IDOK, IDCANCEL, IDC_APPLY_BTN, 0}; //CPY 5/17/06 CHANGED_BACK_TO_OK_CANCEL,Greg said should allow single click to close
	MultiPaneDlg::OnDlgResize(nButtonIDs, cx, cy, false);
	RECT rApply;
	if(!GetControlClientRect(IDC_APPLY_BTN, rApply))
		return true;// problem with resource

	uint nRecalcButtonIDs[] = {IDC_SET_VAL_RECALCULATE, IDC_SET_VAL_AUTO_CHK, 0};
	ArrangeControlsLeftRight(nRecalcButtonIDs, GetControlGap(), rApply.top);
	//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifdef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
	repositionBottomPaneControl();
#endif
	//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
	
	///Jasmine 03/04/09 DEFINE_LT_VAR_BUTTON
#ifdef SET_VALUES_SUPPORT_DEFINE_VARIBLE
	///Kyle 06/25/2009 ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU
	//RECT rDefine;
	//if( !GetControlClientRect(IDC_DEFINE_BTN, rDefine) )
		//ASSERT(FALSE);
	//else
	//{
		//int nWidth 	= RECT_WIDTH(rDefine);
		//int nHeight = RECT_HEIGHT(rDefine);
		//
		//RECT rEdit;
		//GetControlClientRect(IDC_SET_VAL_EXPRESSIONS, rEdit);			
		//rDefine.right = rEdit.right;
		//rDefine.left = rDefine.right - nWidth;
		//
		//RECT rFirst;
		//GetControlClientRect(IDC_FIRST_BTN, rFirst);		
		//rDefine.bottom = rFirst.bottom;
		//rDefine.top = rDefine.bottom - nHeight;
		//
		//MoveControl(GetItem(IDC_DEFINE_BTN), rDefine);
	//}
	RECT rDefRng, rDefPageInfo;
	if( !GetControlClientRect(IDC_DEFINE_RANGE_BTN, rDefRng) && !GetControlClientRect(IDC_DEFINE_PAGE_INFO_BTN, rDefPageInfo))
		ASSERT(FALSE);
	else
	{
		int nWidth 	= RECT_WIDTH(rDefRng);
		int nHeight = RECT_HEIGHT(rDefRng);
		if(RECT_WIDTH(rDefPageInfo) > nWidth)
			nWidth = RECT_WIDTH(rDefPageInfo);
		if(RECT_HEIGHT(rDefPageInfo) > nHeight)
			nHeight = RECT_HEIGHT(rDefPageInfo);
		
		RECT rEdit;
		GetControlClientRect(IDC_SET_VAL_EXPRESSIONS, rEdit);			
		rDefPageInfo.right = rEdit.right;
		rDefPageInfo.left = rDefPageInfo.right - nWidth;
		
		RECT rFirst;
		GetControlClientRect(IDC_FIRST_BTN, rFirst);		
		rDefPageInfo.bottom = rFirst.bottom;
		rDefPageInfo.top = rDefPageInfo.bottom - nHeight;
		
		MoveControl(GetItem(IDC_DEFINE_PAGE_INFO_BTN), rDefPageInfo);
		
		rDefRng = rDefPageInfo;
		rDefRng.right = rDefPageInfo.left - GetControlGap();
		rDefRng.left = rDefRng.right - nWidth;
		MoveControl(GetItem(IDC_DEFINE_RANGE_BTN), rDefRng);
	}
	///End ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU
#endif //SET_VALUES_SUPPORT_DEFINE_VARIBLE
	///End DEFINE_LT_VAR_BUTTON
	
	return true;
}
//---CPY 5/9/06 BEFORE_SCRIPT_IN_TAB
int ColValuesDlg::GetBottomPaneSubControls(vector<uint>& vnCntrls)
{
	//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifndef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
	vnCntrls.SetSize(0);
	vnCntrls.Add(IDC_SET_VAL_PRE_SCRIPTS);
	return m_BottomTab.GetCurSel();
#else
	return 0;
#endif
	//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
}
//---end BEFORE_SCRIPT_IN_TAB

//--- CPY 10/10/2007 SEP_HELP_ID_FOR_COL_MAT_DLG
// return true to use built-in help system and nHelpID should be used
// return false if no need for generic help
BOOL ColValuesDlg::OnHelp(int &nHelpID, int nIdCtrlFocus)
{
	if( getPageType() == EXIST_WKS)
	{
		nHelpID = IDD_SET_COL_VALUES;
	}
	return true;
}
//---


///Jasmine 01/15/07 REMOVE_FUNCTION_BROWSER, we do not plan to accomplish Function Brower in 8.0
/*
BOOL ColValuesDlg::OnOCEditorKey(Control oCntrl, UINT msg, UINT wParam, UINT lParam)
{
	if('H' == wParam && CNTRL_DOWN)
	{
		OnOpenFB();
		return true;
	}
	return false;
}
*/
///End REMOVE_FUNCTION_BROWSER
BOOL ColValuesDlg::OnClickOK()
{
	Control ctrl;
	OnApply(ctrl);
	return true;
}
BOOL ColValuesDlg::OnClickCancel()
{
	return true;
}
BOOL ColValuesDlg::OnSelCols(int nID)
{
	///Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	//string str = m_pDlgMenu->GetMenuString(nID);
	//----- CPY 7/18/09 QA80-13746 SCV_COL_FX_MENU_SHOW_SN_LN_CLEANUP
	//string str = m_pDlgMenu->GetColumnString(nID);
	///Kyle 07/27/2009 QA80-13746-P5 CONSIDER_MAT_IN_COL_MAT_MENU
	//string str = m_pDlgMenu->GetColumnString(nID, m_pDataOB?m_pDataOB->GetWorksheetPtr():NULL);
	string str = m_pDlgMenu->GetColumnString(nID, m_pDataOB?m_pDataOB->GetDatasheetPtr():NULL);
	///End CONSIDER_MAT_IN_COL_MAT_MENU
	//-----
	///End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	
	insertStrToFormula(str);
	return true;
}

///Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS 
#ifdef _ADD_FITTING_FUNCTIONS_TO_SCV

typedef BOOL (*FUNC_SIMULATE_CURVE_DLG) (string& strFormula, const FunctionInfo& funcInfo, const SetValContext& stContext, HWND hParent = NULL);

bool	ColValuesDlg::openSimulateCurveDlg(string& strFormula, const FunctionInfo* pFuncInfo)
{
	if(!pFuncInfo)
		return false;

	SetValContext stContext;
	Column col;
	UINT colUID = 0;
	if ( m_pDataOB && m_pDataOB->GetColumn(col) )
		colUID = col.GetUID(TRUE);
	stContext.nObjUID = colUID;
	stContext.nPageType = getPageType();
	
	FUNC_SIMULATE_CURVE_DLG pfn_simulate_curve_dlg = Project.FindFunction("InsertFunctionFormula", "Originlab\\FunctionFormulaDlg.cpp", true);
	return pfn_simulate_curve_dlg && pfn_simulate_curve_dlg(strFormula, *pFuncInfo, stContext, GetSafeHwnd());
}

BOOL ColValuesDlg::OnUIUpdateFittingFunc(CmdUI cmd)
{
	FunctionsMenu* pMenu = m_pDlgMenu->GetFunctionsMenu();
	if( !pMenu )
		return false;
	return pMenu->OnUpdateFittingFunc(cmd);
}

#endif // _ADD_FITTING_FUNCTIONS_TO_SCV
///End SCV_ADD_FITTING_FUNCTIONS

///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU, same as OnSelFunction
//BOOL ColValuesDlg::OnSelFromHistory(int nID)
//{
	//OnSelFunction(nID);
	//return true;
//}
///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
BOOL ColValuesDlg::OnSelFunction(int nID)
{
	///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	//string str = m_pDlgMenu->GetMenuString(nID);
	//m_pDlgMenu->UpdateFuncHistoryList(str);
	//
	//insertStrToFormula(str, true);
	
	///Kyle 09/14/2009 ADD_WCOL(_ThisColNum)_UNDER_VARIABLE_CONSTANT
	/*
	/// Iris 01/04/2009 v8.0993c MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
	//FunctionsMenu FuncMenu(getDlgMenu(), STR_FAVORITE_SECTIONS);
	string strSection = EXIST_MATRIX == getPageType()? STR_MAT_FAVORITE_SECTIONS : STR_WKS_FAVORITE_SECTIONS;
	FunctionsMenu FuncMenu(getDlgMenu(), strSection);
	///end MAT_WKS_SHOULD_HOLD_DIFF_FAVORITE_LIST
	string strFormula = FuncMenu.GetFunctionString(nID);

	string strLabel;
	FuncMenu.GetMenuString(nID, strLabel, MF_STRING);
	FuncMenu.UpdateFuncHistoryList(strLabel);
	*/
	///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	//FunctionsMenu* pMenu = NULL;
	//if( EXIST_MATRIX == getPageType() )
		//pMenu = new MatFunctionsMenu(getDlgMenu(), STR_MAT_FAVORITE_SECTIONS);
	//else
		//pMenu = new WksFunctionsMenu(getDlgMenu(), STR_WKS_FAVORITE_SECTIONS);	
	FunctionsMenu* pMenu = m_pDlgMenu->GetFunctionsMenu();
	ASSERT(pMenu != NULL);
	///end MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	string strFormula = pMenu->GetFunctionString(nID);

	///Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS
#ifdef _ADD_FITTING_FUNCTIONS_TO_SCV
	string strLabel = pMenu->GetMenuString(nID);			// a derived method
	pMenu->UpdateFuncHistoryList(strLabel);
#else // _ADD_FITTING_FUNCTIONS_TO_SCV
	///SCV_ADD_FITTING_FUNCTIONS

	string strLabel;
	pMenu->GetMenuString(nID, strLabel, MF_STRING);
	pMenu->UpdateFuncHistoryList(strLabel);
	///Kyle 11/04/2009 QA80-14584 SCV_ADD_FITTING_FUNCTIONS
#endif // _ADD_FITTING_FUNCTIONS_TO_SCV
	///SCV_ADD_FITTING_FUNCTIONS

	///Sophy 11/6/2009 QA80-14584 MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	//delete pMenu; should be handled in m_pDlgMenu(SetValuesMenu class);
	///end MORE_WORK_ON_SCV_FUTTING_FUNCTIONS_MENU
	///End ADD_WCOL(_ThisColNum)_UNDER_VARIABLE_CONSTANT

	insertStrToFormula(strFormula, true);
	///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	return true;
}
///Jasmine 04/29/06 OPEN_COLUMN_BROWSER
//BOOL ColValuesDlg::OnOpenBrowser()
//{
	////
	//MessageBox(GetSafeHwnd(), "Column Browser is not ready.");
	////
//}
///Jasmine 09/03/08 ACTIVE_LAYER_IS_NOT_CURRENT_LAYER_IF_SLECTION_NOT_GOOD
///Jasmine 09/25/06 SHARE_COL_BROWSER_WITH_MAT
//typedef BOOL (*FUNC_STR_BOOL_HWND) (string& strSel, bool bName, HWND hParent);
typedef BOOL (*FUNC_STR_BOOL_HWND) (string& strSel, int nType, bool bName, HWND hParent, LPCSTR lpcszWks);
bool ColValuesDlg::openBrowser(bool bShortName)//true
{	
	string strPath = "Originlab\\ColumnBrowser.c";
	FUNC_STR_BOOL_HWND pfn = Project.FindFunction("OpenColumnBrowser", strPath);
	
	string strSheetName;
	if(m_pDataOB)
	{
		string str = m_pDataOB->GetSelectionStr();
		vector<string> vs;
		if( 0 < str.GetTokens(vs, '|') )
		{
			string strBook, strSheet;	
			okutil_parse_one_xyrange_formatted_string(vs[0], &strBook, &strSheet);

			strSheetName = make_book_sheet_name(strBook, strSheet);
		}
	}
	
	string strCol;	
	//if(!pfn || !pfn(strCol, bShortName, GetSafeHwnd()))
	if( !pfn || !pfn(strCol, getPageType(), bShortName, GetSafeHwnd(), strSheetName) )
		return true;
///End ACTIVE_LAYER_IS_NOT_CURRENT_LAYER_IF_SLECTION_NOT_GOOD
	insertStrToFormula(strCol);
	return true;
}
///End SHARE_COL_BROWSER_WITH_MAT
///Jasmine 01/15/07 REMOVE_FUNCTION_BROWSER
/*
BOOL ColValuesDlg::OnOpenFB()
{
	string strFunction = openFunctionBrowser();
	if(!strFunction.IsEmpty())
	{
		m_pDlgMenu->UpdateFuncHistoryList(strFunction);
		
		insertStrToFormula(strFunction, true);
	}
	return true;
}
*/
///End REMOVE_FUNCTION_BROWSER
BOOL ColValuesDlg::OnSelFromLastUse(int nID)
{
	if(OnLoadFormula(nID) || OnLoadSample(nID))
		return true;
	return false;
}
BOOL ColValuesDlg::OnLoadSample(int nID)
{
	return loadFormula(nID, okutil_get_origin_path(ORIGIN_PATH_SYSTEM) + m_strFile);//STR_FAVORITE_FORMULA_FILE_SYS);///jasmine 08/28/06 SHARE_DLG_WITH_MAT
}

///Jasmine 05/12/06 
BOOL ColValuesDlg::OnLoadFormula(int nID)
{
	return loadFormula(nID, okutil_get_origin_path(ORIGIN_PATH_USER) + m_strFile);//STR_FAVORITE_FORMULA_FILE);	///jasmine 08/28/06 SHARE_DLG_WITH_MAT
}
bool ColValuesDlg::loadFormula(int nID, LPCSTR lpcszFile)// = STR_FAVORITE_FORMULA_FILE
{
	string strName, strFormula, strFile = lpcszFile;
	strName = m_pDlgMenu->GetMenuString(nID);
//----- CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE
//	INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
//	strFormula = iniFile.ReadString(STR_FORMULA_SECTIONS, strName);
//	//temp, no "/r" and "/n" in ini file
//	int ii = strFormula.Find("#");
//	if(-1 < ii)
//	{
//		strFormula.Delete(ii, 1);
//		strFormula.Insert(ii, STR_COL_FORMULAR_SEPARATOR);
//	}
//	//End temp
	// firat check if user foler has file
	int nRet = okutil_read_file_section(strFile, strName, &strFormula, NULL);	
	if(nRet<= 0)
		return false;
//-----
	onBeforeFormulaChange();
	bool bHasBeforeScript = formulaToDlg(strFormula);
	onAfterChange();
	m_strCurFormulaName = strName;
	//add to last use list
	m_pDlgMenu->UpdateFormulaHistoryList(m_strCurFormulaName);
	updateDialogTitle();///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
	return true;
}
BOOL ColValuesDlg::OnSaveFormula()
{
	if(m_strCurFormulaName.IsEmpty())
		return OnSaveFormulaAs();
	if(IDNO == MessageBox(GetSafeHwnd(), _L("Do you want to overwrite")+" "+ m_strCurFormulaName +_L("?"), _L("Attention!"), MB_YESNO))
		return FALSE;
	string strFormula = dlgToformula();
	okutil_write_file_section(okutil_get_origin_path(ORIGIN_PATH_USER) + m_strFile, m_strCurFormulaName, strFormula);//STR_FAVORITE_FORMULA_FILE///jasmine 08/28/06 SHARE_DLG_WITH_MAT
	return TRUE;
}
BOOL ColValuesDlg::OnSaveFormulaAs()
{
	//load saved names
	vector<string> vsKeyNames;
//----- CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE
//	INIFile	iniFile(STR_FAVORITE_LIST_SETTING_FILE);
//	iniFile.GetKeyNames(vsKeyNames, STR_FORMULA_SECTIONS);
//	string strNameList;
//	for(int ii = 0; ii < vsKeyNames.GetSize(); ii++)
//		strNameList = strNameList + "|" + vsKeyNames[ii];
//	if(strNameList.IsEmpty())
//		strNameList = "| ";
	okutil_get_file_sections(okutil_get_origin_path(ORIGIN_PATH_USER) + m_strFile, &vsKeyNames);//STR_FAVORITE_FORMULA_FILE///jasmine 08/28/06 SHARE_DLG_WITH_MAT
	string strNameList;
	strNameList.SetTokens(vsKeyNames, '|');
	if(!strNameList.IsEmpty())
		strNameList.Insert(0,"|");
//-----

	//get name to save
	string strName;
	GETN_TREE(trSaveAs)
	GETN_STR(Name, _L("Formula Name"), "")
	if(!strNameList.IsEmpty())
	{
		GETN_STR_COMBO(strNameList)
		_tmpSubNode.strVal = m_strCurFormulaName;
	}

	Window Wnd = GetWindow();
	if(!Wnd || !GetNBox(trSaveAs, _L("Save Formula As..."), _L("Input name for new formula"), NULL, NULL, Wnd.GetSafeHwnd()))
		return FALSE;
	strName	= trSaveAs.Name.strVal;
	strName.TrimLeft();	strName.TrimRight();
	if(strName.IsEmpty())
		return FALSE;
	int nIndex = vsKeyNames.Find(strName);
	if(-1 < nIndex && IDNO == MessageBox(GetSafeHwnd(), _L("Do you want to overwrite")+" "+ vsKeyNames[nIndex] +_L("?"), _L("Attention!"), MB_YESNO) )
		return FALSE;
	//save in ini file
	string strFormula = dlgToformula();
//----- CPY 5/12/06 FORMULA_SAVED_TO_SEPARATE_FILE
/*	//temp, shouldn't save "/r" and "/n" in ini file
	ii = strFormula.Find(STR_COL_FORMULAR_SEPARATOR);
	string str = STR_COL_FORMULAR_SEPARATOR;
	if(-1 < ii)
		strFormula.Delete(ii, str.GetLength() -1);
	//End temp
	update_ini_line(iniFile, STR_FORMULA_SECTIONS, strName, strFormula);
*/
	okutil_write_file_section(okutil_get_origin_path(ORIGIN_PATH_USER) + m_strFile, strName, strFormula);//STR_FAVORITE_FORMULA_FILE///jasmine 08/28/06 SHARE_DLG_WITH_MAT
//-----

	//add to Load Formula Menu
	if(0 > nIndex)//new formula name
	{
		int nNum = vsKeyNames.GetSize();
		m_pDlgMenu->AddToFormulaList(strName, nNum);		
	}
	m_strCurFormulaName = strName;
	m_pDlgMenu->UpdateFormulaHistoryList(m_strCurFormulaName);
	updateDialogTitle(); ///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
	return TRUE;
}
#ifdef SET_VALUES_SET_FONTS_FOR_RICH_EDIT	//---CPY 10/2/2007 REMOVE_FORMAT_FONT_FROM_SET_VALUES
/// TD 09-13-2007 QA80-10375 SUPPORT_USER_FONTS_IN_MULTILINE_DDK_RICHEDITS
BOOL ColValuesDlg::OnUpdateFont()
{
	SendMessage(WM_USER_USER_FONTS);
	return TRUE;
}
/// end SUPPORT_USER_FONTS_IN_MULTILINE_DDK_RICHEDITS
#endif

///End ADD_FORMULA_LIST
BOOL ColValuesDlg::OnApply(Control ctrl)
{
	if(isChanged())
	{
		m_bOnDoingApply = true;
		string strFormula = dlgToformula();
		beforeApplyFormula();
		//---- CPY 5/17/06 COL_FORMULA_AUTO_UPDATE_CLEANUP
		/*
		m_pDataOB->SetFormulaAutoUpdate(false);	//clear auto update first
		
		if(m_pDataOB->SetFormula(strFormula))
		{
			m_pDataOB->SetFormulaAutoUpdate(m_btnAutoUpdate.Check);
			
			afterApplyFormula();
		}
		*/
		///Jasmine 11/06/06 EXECUTE_FORMULA_BUG_ALWAYS_RETURN_FALSE
		//wait Yuri to fix this bug in ExecuteFormula
		//temp modification
		/// YuI 07/27/06 AUTOUPDATE_MODE_CLEANUP
		//	if(m_pDataOB->SetFormula(strFormula, m_comboAutoUpdate.GetCurSel()))
		//if( m_pDataOB->SetFormula(strFormula, m_comboAutoUpdate.GetCurSel()) && m_pDataOB->ExecuteFormula() )
		UndoBlock ub;	/// AW 07/13/07 QA80-10056 NEED_DEL_OP_AFTER_UNDO_SETVALUE_WITH_AUTO
		
		if( m_pDataOB->SetFormula(strFormula, m_comboAutoUpdate.GetCurSel()) )
		{
			m_pDataOB->ExecuteFormula();
		/// end AUTOUPDATE_MODE_CLEANUP
			afterApplyFormula(); 
		}
		
		//----
		///End EXECUTE_FORMULA_BUG_ALWAYS_RETURN_FALSE
		PostMessage(WM_USER_APPLY_FINISHED);	///Sophy 5/12/2008 v8.0860 QA80-11031-P1 FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY

	}

	return true;
}
BOOL ColValuesDlg::OnUndo(Control ctrl)
{
	string strTemp = dlgToformula();//m_edExpression.Text;
	//m_edExpression.Text = m_strUndo;
	formulaToDlg(m_strUndo);
	m_strUndo = strTemp;
	
	onAfterChange();
	return true;
}
BOOL ColValuesDlg::OnClickPrevious(Control ctrl)
{
	m_pDataOB->ActivePreviousObject();
	//OnSelectionChange();//temp, Jasmine 08/28/06 FORCE_TO_UPDATE
	//onActiveObjectChange();
	return true;
}
BOOL ColValuesDlg::OnClickNext(Control ctrl)
{
	m_pDataOB->ActiveNextObject();
	//OnSelectionChange();//temp, Jasmine 08/28/06 FORCE_TO_UPDATE
	//onActiveObjectChange();
	return true;
}

//----Jake 04/18/07 ADD_FIRST_AND_LAST_BUTTON
BOOL ColValuesDlg::OnClickLast(Control ctrl)
{
	m_pDataOB->ActiveLastObject();
	//OnSelectionChange();
	return true;
}
BOOL ColValuesDlg::OnClickFirst(Control ctrl)
{
	m_pDataOB->ActiveFirstObject();
	//OnSelectionChange();
	return true;
}
//----end ADD_FIRST_AND_LAST_BUTTON

///Jasmine 03/04/09 DEFINE_LT_VAR_BUTTON
#ifdef SET_VALUES_SUPPORT_DEFINE_VARIBLE

///Kyle 06/25/2009 ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU

/// Kenny 09/11/2009 QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
//typedef BOOL (*FUNC_RANGE_BROWSER) (vector<string>& vsResult, HWND hParent, int nPageType, bool bXYRange = false, bool bMultipleSelect = true, DWORD dwFilter = 0, LPCSTR lpcszDlg = NULL);
///------ Folger 06/01/10 ORG-120 DATA_DISPLAY_DIALOG_IMPROVEMENT
//typedef BOOL (*FUNC_RANGE_BROWSER) (vector<string>& vsResult, HWND hParent, int nPageType, bool bXYRange = false, bool bMultipleSelect = true, DWORD dwFilter = 0, LPCSTR lpcszDlg = NULL, UINT nSelectedColUID = 0);
///------ End DATA_DISPLAY_DIALOG_IMPROVEMENT
/// End QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS

BOOL ColValuesDlg::OnDefRngVar(Control ctrl)
/// Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED
{
	return InsertRangeVariable();
}

BOOL ColValuesDlg::InsertRangeVariable()
/// End QA81-14241 DEFINE_VARIABLE_MENU_WANTED
{
	/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	//static int nCountRng = 0;
	DataObjectVarInfo varInfo;
	bool bRet = m_pDataOB->GetVarInfo(varInfo);
	int& nCountRng = varInfo.nRangeVarCount;
	/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	vector<string> vsCols;
	FUNC_RANGE_BROWSER pfn = Project.FindFunction("RangeBrowser", "Originlab\\RangeBrowser.c", true);
	/// Kenny 09/11/2009 QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
	//if( !pfn || !pfn(vsCols, GetSafeHwnd(), getPageType(), false) )
	///Kyle 11/23/2009 DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	/*
	Column col;
	UINT colUID = 0;
	if ( m_pDataOB && m_pDataOB->GetColumn(col) )
		colUID = col.GetUID(TRUE);
	*/
	UINT objUID = 0;
	DataObject obj;
	if( m_pDataOB && m_pDataOB->GetObject(obj) )
		objUID = obj.GetUID(true);
	///End DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	int nPageType = getPageType();
	bool bXYRange = false;
	bool bMultipleSelect = true;
	DWORD dwFilter = 0;
	LPCSTR lpcszDlg = NULL;
	///Kyle 11/23/2009 DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	//if( !pfn || !pfn(vsCols, GetSafeHwnd(), nPageType, bXYRange, bMultipleSelect, dwFilter, lpcszDlg, colUID) )
	if( !pfn || !pfn(vsCols, GetSafeHwnd(), nPageType, bXYRange, bMultipleSelect, dwFilter, lpcszDlg, objUID) )
	///End DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	/// End QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
		return true;

	ASSERT(vsCols.GetSize() >= 1);
	if(vsCols.GetSize() < 1)
		return false;
	for(int ii=0; ii<vsCols.GetSize(); ii++)
	{
		nCountRng++;
		string strName = "r" + (string)nCountRng;
		string strCol = vsCols[ii];
		strCol.TrimLeft();
		insertDefVarScript("range", strName, strCol);
	}

	/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	bRet = m_pDataOB->SetVarInfo(varInfo);
	/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	return true;
}

///Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
//typedef bool (*FUNC_OPEN_INSERT_VAR_DLG) (string& str, int* lpType = NULL, DWORD dwCtrl = 0, bool* pbDisableLinkAndDefType = NULL, HWND hWndParent = NULL);
///Sophy 9/9/2009 INSERT_VAR_DLG_NEED_TO_KNOW_CUR_SEL_COLUMN_FROM_SET_COL_VALUES_DLG
//typedef bool (*FUNC_OPEN_INSERT_VAR_DLG) (string& str, int* lpType = NULL, vector<uint>* pvnDataTypes = NULL, DWORD dwCtrl = 0, bool* pbDisableLinkAndDefType = NULL, HWND hWndParent = NULL);
typedef bool (*FUNC_OPEN_INSERT_VAR_DLG) (string& str, int* lpType = NULL, vector<uint>* pvnDataTypes = NULL, DWORD dwCtrl = 0, bool* pbDisableLinkAndDefType = NULL, HWND hWndParent = NULL, UINT colUID = 0);
///end INSERT_VAR_DLG_NEED_TO_KNOW_CUR_SEL_COLUMN_FROM_SET_COL_VALUES_DLG

/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
//static bool _get_type_name_and_def_var_name(int nDataType, string& strType, string& strName)
static bool _get_type_name_and_def_var_name(int nDataType, string& strType, string& strName, DataObjectVarInfo& varInfo)
/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
{
	/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
// 	static int 	nCountIntVar = 0,
// 				nCountDoubleVar = 0,
// 				nCountStringVar = 0;
	int &nCountIntVar		= varInfo.nIntegerVarCount,
		&nCountDoubleVar	= varInfo.nDoubleVarCount,
		&nCountStringVar	= varInfo.nStringVarCount;
	/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL

	switch(nDataType)
	{
	case ONODETYPE_EDIT_BOX_NUMERIC_UINT:
	case ONODETYPE_EDIT_BOX_NUMERIC_INT:
	case ONODETYPE_DROPLIST_STRINGS:	/// Kenny 12/23/2009 QA81-14748-P3 INSERT_USER_VAR_DLG_FAILS_TO_INSERT_DROP_LIST_STRINGS
	case ONODETYPE_CHECKBOX:	/// Kenny 12/24/2009 QA81-14748-P3 INSERT_USER_VAR_DLG_FAILS_TO_INSERT_CHECK_BOX_NODE_VALUE
		nCountIntVar++;
		strType = "int";
		strName = "n" + nCountIntVar;
		break;

	case TRGP_DOUBLE:
		nCountDoubleVar++;
		strType = "double";
		strName = "d" + nCountDoubleVar;
		break;

	/// Kenny 01/04/2010 QA81-14748-P2 INSERT_USER_VAR_DLG_FAILS_TO_SHOW_MULTILINE_NODE
// 	case TRGP_STR:
// 		nCountStringVar++;
// 		strType = "string";
// 		strName = "str" + nCountStringVar;
// 		break;
// 
// 	default:
// 		return false;
	default:
		if ( IS_TEXT_NODE_ID(nDataType) )
		{
			nCountStringVar++;
			strType = "string";
			strName = "str" + nCountStringVar;
			return true;
		}
		return false;
	/// End QA81-14748-P2 INSERT_USER_VAR_DLG_FAILS_TO_SHOW_MULTILINE_NODE
	}
	return true;
}
///End SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE

BOOL ColValuesDlg::OnDefPageInfoVar(Control ctrl)
/// Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED
{
	return InsertInfoVariable();
}

BOOL ColValuesDlg::InsertInfoVariable()
{
	return OpenInsertInfoDlg();
}

BOOL ColValuesDlg::OpenInsertInfoDlg(bool bSwitchToLabelTab /*= false*/)
/// End QA81-14241 DEFINE_VARIABLE_MENU_WANTED
{
	///Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
	//static int 	nCountStringVar = 0,
	//			nCountNumericVar = 0;
	///End SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE

	string strType, strName, strVal = "cell";
	FUNC_OPEN_INSERT_VAR_DLG pfn = Project.FindFunction("InsertUserVarEx", "OriginLab\\InsertUserVar", true);
	bool bInsertAsLink = true;
	///Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
	//if(!pfn || !pfn(strVal, NULL, INSERT_INFO_FILTER_FILE_INFO | INSERT_INFO_INSERT_TO_CELL, &bInsertAsLink, GetSafeHwnd()) )		// need one more param to specify if insert as link or not since link button is disabled in the dialog
	vector<uint> vnDataTypes;
	///Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV
	//DWORD dwCtrl = INSERT_INFO_ENABLE_INSERT_MODE | INSERT_INFO_ENABLE_PROJECT_TREE | INSERT_INFO_FILTER_FILE_INFO | INSERT_INFO_VAL_FORMAT_LT;
	
	/// Kenny 11/26/2009 QA81-14748 INSERT_VAR_DLG_FAILED_TO_SHOW_IMPORT_FILE_LEVEL_INFO
	//DWORD dwCtrl = INSERT_INFO_ENABLE_VAR_TYPE | INSERT_INFO_ENABLE_PROJECT_TREE | INSERT_INFO_FILTER_FILE_INFO | INSERT_INFO_VAL_FORMAT_LT | INSERT_INFO_MULTI_INSERT;
	DWORD dwCtrl = INSERT_INFO_ENABLE_VAR_TYPE | INSERT_INFO_ENABLE_PROJECT_TREE | INSERT_INFO_VAL_FORMAT_LT | INSERT_INFO_MULTI_INSERT;
	/// End QA81-14748 INSERT_VAR_DLG_FAILED_TO_SHOW_IMPORT_FILE_LEVEL_INFO
	
	/// Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED
	if ( bSwitchToLabelTab )
	{
		dwCtrl |= INSERT_INFO_OPEN_LABEL_TAB;
	}
	/// End QA81-14241 DEFINE_VARIABLE_MENU_WANTED
	///End INSERT_MULTIPLE_TIMES_FOR_SCV
	/// Kenny 09/03/2009 QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
	//if(!pfn || !pfn(strVal, NULL, &vnDataTypes, dwCtrl, &bInsertAsLink, GetSafeHwnd()) )
	// Make the Insert as Link check box available and checked by default
	///Sophy 9/9/2009 INSERT_VAR_DLG_NEED_TO_KNOW_CUR_SEL_COLUMN_FROM_SET_COL_VALUES_DLG
	//if(!pfn || !pfn(strVal, NULL, &vnDataTypes, dwCtrl, NULL, GetSafeHwnd()) )
	///Kyle 11/23/2009 DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	/*
	Column col;
	UINT colUID = 0;
	if ( m_pDataOB && m_pDataOB->GetColumn(col) )
		colUID = col.GetUID(TRUE);
	if(!pfn || !pfn(strVal, NULL, &vnDataTypes, dwCtrl, NULL, GetSafeHwnd(), colUID) )
	*/
	UINT objUID = 0;
	DataObject obj;
	if ( m_pDataOB && m_pDataOB->GetObject(obj) )
		objUID = obj.GetUID(TRUE);
	if(!pfn || !pfn(strVal, NULL, &vnDataTypes, dwCtrl, NULL, GetSafeHwnd(), objUID) )
	///End DEFINE_VARIABLES_FOR_SET_MATRIX_VALUES
	///end INSERT_VAR_DLG_NEED_TO_KNOW_CUR_SEL_COLUMN_FROM_SET_COL_VALUES_DLG
	/// End QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
	///End SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
		return FALSE;
	///Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV, do nothing here, will be caught in OnInsertVars
	/*
	if(strVal.IsEmpty())
		return false;
	vector<string> vsVals;
	strVal.GetTokens(vsVals, '\n');
	ASSERT(vsVals.GetSize() == vnDataTypes.GetSize());			///Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
	for(int ii=0; ii<vsVals.GetSize(); ii++)
	{
		strVal = vsVals[ii];
		int nPos = strVal.Find("//");
		if(nPos >= 0)
		{
			strVal = strVal.Mid(nPos+2);
			strVal.TrimLeft();
		}
		///Kyle 08/13/2009 SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
		//if(strVal.Find('$') == strVal.GetLength()-1)
		//{
			//strType = "string";
			//nCountStringVar++;
			//strName = "str" + (string)nCountStringVar;
		//}
		//else
		//{
			//strType = "double";
			//nCountNumericVar++;
			//strName = "d" + (string)nCountNumericVar;
		//}
		if(!_get_type_name_and_def_var_name(vnDataTypes[ii], strType, strName))
			continue;
		///End SET_COLUMN_VALUES_SUPPORT_DEFINE_VARIABLES_IN_BASIC_DATA_TYPE
		insertDefVarScript(strType, strName, strVal);
	}
	*/
	///End INSERT_MULTIPLE_TIMES_FOR_SCV

	return true;
}

/// Kenny 09/01/2009 QA81-14241 DEFINE_VARIABLE_MENU_WANTED
BOOL ColValuesDlg::InsertColLabelVariable()
{
	return OpenInsertInfoDlg(true);
}
/// End QA81-14241 DEFINE_VARIABLE_MENU_WANTED

///Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV
void ColValuesDlg::insertVars(const vector<string>& vsVals, const vector<uint>& vnDataTypes)
{
	ASSERT(vsVals.GetSize() == vnDataTypes.GetSize());

	/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	DataObjectVarInfo varInfo;
	bool bRet = m_pDataOB->GetVarInfo(varInfo);
	/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL

	string strType, strName;
	for(int ii=0; ii<vsVals.GetSize(); ii++)
	{
		/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
		//if(!_get_type_name_and_def_var_name(vnDataTypes[ii], strType, strName))
		if(!_get_type_name_and_def_var_name(vnDataTypes[ii], strType, strName, varInfo))
		/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
			continue;
		insertDefVarScript(strType, strName, vsVals[ii]);
	}

	/// Kenny 09/15/2009 QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
	bRet = m_pDataOB->SetVarInfo(varInfo);
	/// End QA81-14241 SET_COL_VAL_DLG_NEED_REMEMBER_VAR_INDICES_INTO_EACH_COL
}

BOOL ColValuesDlg::OnInsertVars(uint wParam, uint lParam)
{
	LPCSTR lpcszStrRet = (LPCSTR)wParam;
	LPCSTR lpcszDataTypes = (LPCSTR)lParam;
	
	string strVals = lpcszStrRet;
	string strTypes = lpcszDataTypes;
	
	vector<string> vsVals, vsTypes;
	strVals.GetTokens(vsVals, '\n');
	strTypes.GetTokens(vsTypes, '|');
	
	vector<int> vnTypes;
	convert_string_vector_to_int_vector(vsTypes, vnTypes);
	vector<uint> vnDataTypes;
	vnDataTypes = vnTypes;
	
	insertVars(vsVals, vnDataTypes);

	return true;
}
///End INSERT_MULTIPLE_TIMES_FOR_SCV

void ColValuesDlg::insertDefVarScript(LPCSTR lpcszType, LPCSTR lpcszName, LPCSTR lpcszValue)
{
	if(lstrlen(lpcszType)==0 || lstrlen(lpcszName) == 0)
		return;

	// the string should only be inserted into Before Formula Scripts panel
	// so should show the bottom pane and set focus at it
	if(!IsBottomPaneShown())
		ShowBottomPane(true);
	Edit edit = GetItem(IDC_SET_VAL_PRE_SCRIPTS);
	///Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV, no need to do this, insert directly into this control
	/*
	SetFocus( edit.GetSafeHwnd() );
	
	// always insert to a new line, so put focus at the last line, and if it's not the first char, new one line
	int nTextLength = edit.Text.GetLength();
	edit.SetSel(nTextLength, nTextLength);		// move to end of all text
	bool bAddAsNewLine = (nTextLength > 0 && edit.LineLength(edit.GetLineCount()-1) > 0);
	*/
	bool bAddAsNewLine = true;
	RichEdit richEdit = edit;
	if(richEdit)
	{
		int nLines = richEdit.GetLineCount();
		string strLine;
		if(nLines > 0)
			strLine = richEdit.GetLine(nLines-1);

		bAddAsNewLine = !strLine.IsEmpty();
	}
	///End INSERT_MULTIPLE_TIMES_FOR_SCV

	// construct script
	string strScript;
	if( 0 == lstrcmpi(lpcszType, "string") )
		strScript.Format("%s %s$ = %s;", lpcszType, lpcszName, lpcszValue);
	/// Kenny 09/03/2009 QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
	///Sophy 9/9/2009 WRONG_EXPRESSION_WHEN_INSERT_NUMERIC_COL_COMMENTS_LABEL_AS_STRING
	//should update value string outside
	//else if ( 0 != lstrcmpi(lpcszType, "range") )
	//{
		//strScript.Format("%s %s = %%(%s);", lpcszType, lpcszName, lpcszValue);
	//}
	///end WRONG_EXPRESSION_WHEN_INSERT_NUMERIC_COL_COMMENTS_LABEL_AS_STRING
	/// End QA81-14241 DEFINE_VARIABLE_NEED_MORE_IMPROVEMENTS
	else
		strScript.Format("%s %s = %s;", lpcszType, lpcszName, lpcszValue);
	///Kyle 08/26/2009 INSERT_MULTIPLE_TIMES_FOR_SCV, insertStrToFormula will detect the focus and then insert the string, but the dialog lose its focus because it has a child dialog
	/*
	int nNameBegin = lstrlen(lpcszType) + 1;				// the first char of the var name
	if(bAddAsNewLine)
	{
		strScript = "\r\n" + strScript;			// new line
		nNameBegin+=2;
	}
	nNameBegin += nTextLength;

	insertStrToFormula(strScript);

	// select the name for editing
	int nNameEnd = nNameBegin + lstrlen(lpcszName);		// the last char of the var name
	edit.SetSel(nNameBegin, nNameEnd);
	*/
	if(bAddAsNewLine)
		strScript = "\r\n" + strScript;			// new line
	onBeforeFormulaChange();
	edit.Text = edit.Text + strScript;
	onAfterChange();
	///End INSERT_MULTIPLE_TIMES_FOR_SCV
}
///End ADD_TWO_BUTTONS_TO_DEF_VAR_AND_RESTORE_MENU
#endif //SET_VALUES_SUPPORT_DEFINE_VARIBLE
///End DEFINE_LT_VAR_BUTTON

///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS
BOOL ColValuesDlg::OnActiveLayerChange()
{
	///Sophy 11/13/2009 QA80-14584 SCV_SUPPORT_FUNCTION_FORMULA_SIMULATE_PREVIEW
	if ( okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_QUERY, DIALOGEVENTSPECIALBITS_ACTIVE_FRAME_CHANGE) )
	{
		return TRUE;
	}
	if ( okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_QUERY, DIALOGEVENTSPECIALBITS_FRAME_CHANGE_TEMPORARY) )
	{
		okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_REMOVE, DIALOGEVENTSPECIALBITS_FRAME_CHANGE_TEMPORARY);
		return TRUE;
	}
	///end SCV_SUPPORT_FUNCTION_FORMULA_SIMULATE_PREVIEW
	GetActiveLayer();
	m_bLayerChanged = true;
	///Jasmine 10/19/06 HIDE_DLG_IF_SEL_INVALID	
	int nType = getPageType();
	switch(nType)
	{
	case EXIST_WKS:
	case EXIST_MATRIX:
		Visible = true;
		break;
	default:
		Visible = false;
		return true;
	}
	///End HIDE_DLG_IF_SEL_INVALID
	OnSelectionChange();
	return true;
}
BOOL ColValuesDlg::OnActivePageChange()
{
	OnActiveLayerChange();
	return true;
}
BOOL ColValuesDlg::OnSelectionChange()
{
	///Sophy 11/13/2009 QA80-14584 SCV_SUPPORT_FUNCTION_FORMULA_SIMULATE_PREVIEW
	if ( okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_QUERY, DIALOGEVENTSPECIALBITS_SELECTION_CHANGE) )
	{
		return TRUE;
	}
	if ( okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_QUERY, DIALOGEVENTSPECIALBITS_SELECTION_CHANGE_TEMPORARY) )
	{
		okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_REMOVE, DIALOGEVENTSPECIALBITS_SELECTION_CHANGE_TEMPORARY);
		return TRUE;
	}
	///end SCV_SUPPORT_FUNCTION_FORMULA_SIMULATE_PREVIEW
	///------ Folger 09/21/09 QA80-14283 GET_RID_OF_ONSELECTIONCHANGE_EVENT_DURING_GRID_ATTACH
	if ( okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_QUERY, DIALOGEVENTSPECIALBITS_GRIDATTACH) )
	{
		okutil_dialog_event_special_bits_access(DIALOGEVENTSPECIALBITSOPTIONS_REMOVE, DIALOGEVENTSPECIALBITS_GRIDATTACH);
		return FALSE;
	}
	///------ End GET_RID_OF_ONSELECTIONCHANGE_EVENT_DURING_GRID_ATTACH

	///Sophy 5/12/2008 v8.0860 QA80-11031-P1 FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
	if( m_bOnDoingApply )
		return TRUE;
	///End FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
	
	// backup page type before changed data object since createDataObject will update m_nPageType
	int nCurrentPageType = m_nPageType; /// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS	
	
	///Jasmine 08/14/08 QA80-12018 UPDATE_FROM_TO_ONCE_SELECTION_CHANGE
	/*
	///Sophy 14/7/2008 QA80-11759-P1 FIX_AUTO_APPLY_CHANGING_VALUE_ON_IMPORT_NEW_IMAGE_INTO_MATRIX_CONTAINING_PREVIOUS_IMPORTED_IMAGE
	//out_str( GetRuntimeClass() );
	if( NULL != m_pDataOB && !m_pDataOB->IsDataObjectChanged( Project.ActiveLayer() ) )
		return TRUE;
	///end FIX_AUTO_APPLY_CHANGING_VALUE_ON_IMPORT_NEW_IMAGE_INTO_MATRIX_CONTAINING_PREVIOUS_IMPORTED_IMAGE
	*/
	if( NULL != m_pDataOB && m_pDataOB->IsDataObjectChanged( Project.ActiveLayer() ) )
	{
		///Jasmine 01/31/08 QA80-11034 APPLY_CHANGE_FIRST
		if(NULL != m_pDataOB)
			OnClickOK();
		///End APPLY_CHANGE_FIRST
	}
	///End UPDATE_FROM_TO_ONCE_SELECTION_CHANGE

	GetActiveLayer();///Jasmine 10/19/06 HIDE_DLG_IF_SEL_INVALID	
	//---- CPY 6/10/2006 OPEN_DLG_WHEN_COL_NOT_SELECTED
	if(NULL == m_pDataOB)
		createDataObject();

	///Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED, need disable some controls if no selection
	/////Jasmine 06/11/08 QA80-11679 m_pDataOB_INVALID_WHEN_SWITCH_FROM_MAT_TO_NO_COL_SEL_WKS
	//if(NULL == m_pDataOB)
	//{
		//ASSERT(0);
		//return FALSE;
	//}
	/////End m_pDataOB_INVALID_WHEN_SWITCH_FROM_MAT_TO_NO_COL_SEL_WKS
	////----
	//if(!m_pDataOB->IsProcessSelChange(m_layActive))
		//return TRUE;
	///End UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
	
	/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	//initCtrlValue(false);
	int nFuncMenuInitMode = (nCurrentPageType == getPageType()) ? MENU_NOT_INIT : MENU_REINIT;
	initCtrlValue(nFuncMenuInitMode);
	///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	
	m_strCurFormulaName = "";
	return TRUE;
}
///End SET_COL_VAL_DLG_MODELESS
///Jasmine 10/23/06 UPDATE_IF_MATOBJ_CHANGE
BOOL ColValuesDlg::OnChangeDataset()
{
	GetActiveLayer();
	if(getPageType() == EXIST_MATRIX)
	{
		OnActiveLayerChange();
	}
	return true;
}
///End UPDATE_IF_MATOBJ_CHANGE
BOOL ColValuesDlg::OnExpressionChange(Control ctrl)
{
	onAfterChange();
	return true;
}
BOOL ColValuesDlg::OnRowRangeChange(Control ctrl)
{
	onAfterChange();
	return true;
}
BOOL ColValuesDlg::OnChangeAutoUpdate(Control ctrl)
{
	//------- CPY 07/26/06 QA70-8847 COLUMN_FORMULA_FROM_ORIGIN_C_REVAMP
	//if(m_btnAutoUpdate.Check != m_pDataOB->IsFormulaAutoUpdate())
	//	m_btnApply.Enable = true;
	//
	//bool bRowEditable = !m_btnAutoUpdate.Check;
	if(m_comboAutoUpdate.GetCurSel() != m_pDataOB->GetFormulaAutoUpdateMode())
		m_btnApply.Enable = true;
	//-------
	///DG 9/1/05 SAME_AS_75
	//m_edRowsFrom.Enable = bRowEditable;
	//m_edRowsTo.Enable = bRowEditable;
	///end SAME_AS_75
	
	//---- CPY 5/13/09 QA70-12554-P1 MAT_SET_VALUES_RANGE_SUPPORT_ONLY_IF_NO_RECALC
	///Kyle 05/19/2009 QA80-13635 NO_NEED_TO_UPDATE_RANGE_ON_WKS_ACTIVED
	if(EXIST_MATRIX==getPageType())
	///End NO_NEED_TO_UPDATE_RANGE_ON_WKS_ACTIVED
	{
		vector<string> vs;
		updateMatrixRange(vs);
	}
	//----
	
	return true;
}
///Sophy 5/12/2008 v8.0860 QA80-11031-P1 FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
BOOL ColValuesDlg::OnFinishApply(DWORD wParam, DWORD lParam)
{
	m_bOnDoingApply = false;
	
	return TRUE;
}
///end FIX_LOADING_SAMPLE_FORMULA_INFINITE_LOOP_ON_CLICK_APPLY
//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifdef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
BOOL ColValuesDlg::OnShowBottomPane(Control ctrl)
{
	MultiPaneDlg::OnShowBottomPane(ctrl);
	if ((GetItem(IDC_SCRIPT_TITLE).Visible = IsBottomPaneShown()))
		repositionBottomPaneControl();
	return true;
}
#endif

//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
bool ColValuesDlg::GetActiveLayer()
{
	Layer lay = Project.ActiveLayer();
	m_layActive = lay;
	if(!lay)
	{
		error_report("Fail to get active layer");
		//m_paramTree.Reset();
		return false;
	}
	//---- CPY 10/31/06 DATA_OBJ_FROM_COL_PROP_DIALOG
	else if(m_pDataOB)
	{
		if(!m_pDataOB->IsLayerCompatible(lay))
		{
			delete m_pDataOB;
			m_pDataOB = NULL;
			_DMSG("Old m_pDataOB not compatible with new layer, deleted");
		}
	}
	//----

	return true;
}

/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
//void ColValuesDlg::initCtrlValue(bool bInit)//= false ///Jasmine 04/25/06 MODIFICATION_UPDATE_COLUMN_LIST
void ColValuesDlg::initCtrlValue(int nFuncMenuInitMode/* = MENU_INIT*/)
{
	GetActiveLayer();
	createDataObject();
	updateDialogCtrl();
	
	//initFunctionsList();
	if(m_bLayerChanged)///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS
	{
		/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
		//updateColumnList(bInit);
		updateColumnList(nFuncMenuInitMode);
		///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	}
	m_bLayerChanged = false;
}
//void ColValuesDlg::initFunctionsList()
//{
	/*
	//use this simple list first
	vector<string> vsFunctions = {"abs()", "acos()", "angle(,)", "asin()", "atan()", 
	"j0()", "j1()", "jn(,)", "cos()", "cosh()", "erf()", "exp()", "ftable(,,)", "gammaln()", "incbeta(,,)",
	"invf(,,)", "invprob()", "invt(,)", "ln()", "log()", "mod(,)", "nint()", "prec(,)",
	"prob()", "qcd2()", "qcd3()", "qcd4()", "rmod(,)", "round(,)", "sin()", "sinh()",
	"sqrt()", "tan()", "tanh()", "ttable(,)", "y0()", "y1()", "yn(,)"
	};
	
	m_combFunctions.ResetContent();
	for(int ii=0; ii<vsFunctions.GetSize(); ii++)
		m_combFunctions.AddString(vsFunctions[ii]);
	
	m_combFunctions.SetCurSel(0);
	*/
//}

/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
//void ColValuesDlg::updateColumnList(bool bInit)//false ///Jasmine 04/25/06 MODIFICATION_UPDATE_COLUMN_LIST
void ColValuesDlg::updateColumnList(int nFuncMenuInitMode)
///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
{
	///Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED, need disable some controls if no selection
	/*
	vector<string> vsCols;
	if(!m_pDataOB)
		return;
	///Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	//m_pDataOB->GetAllObjectsLongNames(vsCols);
	vector<string> vsLNames;
	m_pDataOB->GetAllObjectsNames(vsCols, vsLNames);
	///End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	*/
	///End UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
	
	int nType = getPageType();///jasmine 08/28/06 SHARE_DLG_WITH_MAT
	///Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
	vector<string> vsCols, vsLNames;
	if(m_pDataOB)
		m_pDataOB->GetAllObjectsNames(vsCols, vsLNames);
	else if(EXIST_WKS == nType  || EXIST_MATRIX == nType)			// no selection, but need update the menu base on the active layer
	{
		DataObjectManager *pDataOB = NULL;
		if(nType == EXIST_WKS)
		{

			Worksheet wks = m_layActive; /// TD 8-3-06 QA70-8843 DOWNCAST_BUG
			pDataOB = new ColumnValues(wks);
		}
		else
		{
			MatrixLayer mtx = m_layActive;
			pDataOB = new MatrixObjectValues(mtx);
		}
		ASSERT(pDataOB);
		pDataOB->GetAllObjectsNames(vsCols, vsLNames);
		delete pDataOB;
	}
	else
		return;
	///End UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
	

	///Jasmine 10/06/08 QA80-12308 STUPID_WAY_TO_REFRESH_MENU_BAR
	//ShowWindow(SW_HIDE);	 /// Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS, commented out to avoid dialog reflash.

	/// Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS
    if(MENU_NOT_INIT != nFuncMenuInitMode)
    {
		SetLangMenu(getMenuResourceID());
		
		HMENU hMenu = GetMenu(GetSafeHwnd());
		if(hMenu)
		{
			m_pDlgMenu->Detach();
			m_pDlgMenu->Load(hMenu);
		}	
    }
	///end MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS
	
	/// Iris 01/04/2009 v8.0993c RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS
	//m_pDlgMenu->ConstructDlgMenu(vsCols, bInit, m_bSwitch, nType);
	///Kyle 07/14/2009 QA80-13746 SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	//m_pDlgMenu->ConstructDlgMenu(vsCols, nFuncMenuInitMode, m_bSwitch, nType);
	///Kyle 08/20/2009 UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED, should update all items if MENU_NOT_INIT != nFuncMenuInitMode
	//m_pDlgMenu->ConstructDlgMenu(vsCols, vsLNames, nFuncMenuInitMode, m_bSwitch, nType);
	m_pDlgMenu->ConstructDlgMenu(vsCols, vsLNames, nFuncMenuInitMode, m_bSwitch || MENU_NOT_INIT != nFuncMenuInitMode, nType);
	///End UPDATE_THE_DIALOG_MENU_ONLY_ON_SELECTED_PAGE_CHANGED
	///End SHOWING_BOTH_LN_AND_SN_WITH_STANDARD_NOTATION_IN_THE_MENU_OF_SET_COLUMN_VALUE_DLG
	///end RECONSTRUCT_FUNCTION_MENU_SWITCH_MAT_AND_WKS	
	//ShowWindow(SW_NORMAL); /// Iris 2/13/2009 QA80-12790-P2 MAT_SHOULD_NOT_INCLUDE_DATATIME_AND_DATA_GENERATION_CATEGORYS, commented out to avoid dialog reflash.
	///End STUPID_WAY_TO_REFRESH_MENU_BAR
}
HMENU ColValuesDlg::getDlgMenu()
{
	HWND 	hWnd = GetSafeHwnd();
	HMENU 	hMenu = GetMenu(hWnd);
	return hMenu;
}
int ColValuesDlg::getPageType()
{
	//if(m_layActive)
	if(GetActiveLayer())
		return m_layActive.GetPage().GetType();
	
	return -1;
}

bool ColValuesDlg::createDataObject()
{
	if(m_pDataOB)
		delete m_pDataOB;
	m_pDataOB = NULL;
	///jasmine 08/28/06 SHARE_DLG_WITH_MAT
	int nPageType = getPageType();
	m_bSwitch = nPageType != m_nPageType;
	if(m_bSwitch)
		m_nPageType = nPageType;
	if(EXIST_WKS == nPageType  || EXIST_MATRIX == nPageType)
	{
		switch(nPageType)
		{
		case EXIST_WKS:
			if(is_wks_sel_valid(m_layActive))
			{
				Worksheet wks = m_layActive; /// TD 8-3-06 QA70-8843 DOWNCAST_BUG
				m_pDataOB = new ColumnValues(wks);
				m_strFile = STR_FAVORITE_FORMULA_FILE;
			}
			break;
		case EXIST_MATRIX:
			{
				MatrixLayer mtx = m_layActive;
				m_pDataOB = new MatrixObjectValues(mtx);
				m_strFile = STR_FAVORITE_MFORMULA_FILE;
			}
			break;
		default:
			return false;
		}///End SHARE_DLG_WITH_MAT
		return true;
	}
	return false;
}
///Kyle 12/08/2008 CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE
bool ColValuesDlg::isRangeChanged(const vector<int>& vnRows, const vector<int>& vnCols, int nColSelWay)
{
	if(EXIST_MATRIX == getPageType())
		return false;

	if(vnRows.GetSize() != 2)
		return true;
	
	if(vnRows[0] < -1 || vnRows[1] < -1)
		return false;

	int nNumRows = m_pDataOB->GetNumRows();
	if(nNumRows <= 0)
		return false;
	int nSelBeg = getRangeIndex(m_edRowsFrom.Text, true),
		nSelEnd = getRangeIndex(m_edRowsTo.Text, false),
		nForBeg = vnRows[0],
		nForEnd = vnRows[1];
	if(nSelBeg < 0)
		nSelBeg = 0;
	if(nSelEnd < 0)
		nSelEnd = nNumRows - 1;
	if(nForBeg < 0)
		nForBeg = 0;
	if(nForEnd < 0)
		nForEnd = nNumRows - 1;
	
	if(nForBeg > nSelBeg || nForEnd < nSelEnd)
		return true;

	return false;
}
///End CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE

//---- CPY 5/13/09 QA70-12554-P1 MAT_SET_VALUES_RANGE_SUPPORT_ONLY_IF_NO_RECALC
void ColValuesDlg::updateMatrixRange(vector<string>& vs)
{
	bool bEnable = AU_NONE == m_comboAutoUpdate.GetCurSel();

	m_edRowsFrom.Enable = m_edRowsTo.Enable = bEnable;
	m_edColsFrom.Enable = m_edColsTo.Enable = bEnable;
	if(!bEnable && 0==vs.GetSize()) // when disabling, must reset
	{
		string str = m_pDataOB->GetSelectionStr();
		str.GetTokens(vs, '|');
	}
	if(vs.GetSize() > 3)
	{
		m_edRowsFrom.Text = m_edColsFrom.Text = 1;
		m_edRowsTo.Text = vs[2];
		m_edColsTo.Text = vs[3];
	}
}
//----

void ColValuesDlg::updateDialogCtrl()
{
	int nPageType = getPageType(); 
	switch(nPageType)
	{
	case EXIST_WKS:
	case EXIST_MATRIX:
		///Sophy 9/10/2009 QA80-14297 HIDE_SET_COL_VALS_DLG_WHEN_NO_VALID_DATA_SELECTED
		//Visible = true;
		if ( m_pDataOB )
			Visible = true;
		else
		{
			Visible = false;
			return;
		}
		///end HIDE_SET_COL_VALS_DLG_WHEN_NO_VALID_DATA_SELECTED
		break;
	default:
		Visible = false;
		return;
	}
	///Sophy 9/10/2009 QA80-14297 HIDE_SET_COL_VALS_DLG_WHEN_NO_VALID_DATA_SELECTED hide the dialog, so no need to update label
	//if(!m_pDataOB)
	//{
		////---- CPY 6/10/2006 OPEN_DLG_WHEN_COL_NOT_SELECTED
		////error_report("DataObject is invalid, please check");
		//m_textCol.Text = _L("Please select a column");
		////----
		//return;
	//}
	///end HIDE_SET_COL_VALS_DLG_WHEN_NO_VALID_DATA_SELECTED
	
	string str = m_pDataOB->GetSelectionStr();
	vector<string> vs;
	str.GetTokens(vs, '|');
	
	///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
	//updateDialogTitle(vs[0]);
	updateDialogTitle();
	///End ADD_FORMATNAME_TO_TITLE
	///jasmine 08/28/06 SHARE_DLG_WITH_MAT
	switch(nPageType)
	{
	case EXIST_WKS:
		GetItem(IDC_SET_VAL_COL_TEXT).Visible = GetItem(IDC_SET_VAL_COL_TO_TEXT).Visible = GetItem(IDC_SET_VAL_COL_FROM_ED).Visible = GetItem(IDC_SET_VAL_COL_TO_ED).Visible = false;
		GetItem(IDC_SET_VAL_ROW_FROM_ED).Enable = GetItem(IDC_SET_VAL_ROW_TO_ED).Enable = true;
		GetItem(IDC_SET_VAL_COL_FROM_ED).Enable = GetItem(IDC_SET_VAL_COL_TO_ED).Enable = false;		
		//GetItem(IDC_SET_VAL_COL_FROM_ED).Text = GetItem(IDC_SET_VAL_COL_TO_ED).Text = (string)(atoi(vs[1]) + 1);//un-visible, no need now
		m_edRowsFrom.Text = vs[2];
		m_edRowsTo.Text = vs[3];
		m_pDataOB->GetName(str);
		string strFrom, strTo;
		//----- CPY 11/3/2007 SET_COL_VALUES_AUTO_NEED_LOCALIZATION
		//strFrom = vs[2].CompareNoCase("Auto")? vs[2] : 1;
		//strTo = vs[3].CompareNoCase("Auto")? vs[3] : m_pDataOB->GetNumRows();
		strFrom = is_str_auto(vs[2])? 						1 : vs[2];
		strTo = is_str_auto(vs[3])? m_pDataOB->GetNumRows()  : vs[3];
		//-----
		///Jasmine 09/28/06 SIMPLE_RANGE_NOTATION
		//m_textCol.Text.Format("%s!Col(%s)[%s:%s] = ", vs[0], str, strFrom, strTo);
		m_textCol.Text.Format("Col(%s) = ", str);
		///End SIMPLE_RANGE_NOTATION
		break;
	case EXIST_MATRIX:
		GetItem(IDC_SET_VAL_COL_TEXT).Visible = GetItem(IDC_SET_VAL_COL_TO_TEXT).Visible = GetItem(IDC_SET_VAL_COL_FROM_ED).Visible = GetItem(IDC_SET_VAL_COL_TO_ED).Visible = true;
		//---- CPY 5/11/09 QA70-12554 MAT_SET_VALUES_NEED_RANGE_SUPPORT
		//GetItem(IDC_SET_VAL_ROW_FROM_ED).Enable = GetItem(IDC_SET_VAL_ROW_TO_ED).Enable = false;
		//GetItem(IDC_SET_VAL_COL_FROM_ED).Enable = GetItem(IDC_SET_VAL_COL_TO_ED).Enable = false;		
		//m_edRowsFrom.Text = GetItem(IDC_SET_VAL_COL_FROM_ED).Text = 1;
		//m_edRowsTo.Text = vs[2];
		//GetItem(IDC_SET_VAL_COL_TO_ED).Text = vs[3];
		updateMatrixRange(vs);
		//----
		m_pDataOB->GetName(str);
		///Jasmine 09/28/06 SIMPLE_RANGE_NOTATION
		//m_textCol.Text.Format("%s!Mat(%s)(%s x %s) = ", vs[0], str, vs[2], vs[3]);
		///Jasmine 10/23/06 CHANGE_TEXT_TO_EASY_UNDERSTAND
		//m_textCol.Text.Format("Mat(%s) = ", str);
		m_textCol.Text = "Cell(i,j) = ";
		///End CHANGE_TEXT_TO_EASY_UNDERSTAND
		///End SIMPLE_RANGE_NOTATION
		break;
	}
	///End SHARE_DLG_WITH_MAT
	///Kyle 12/08/2008 CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE
	//string strFormula = m_pDataOB->GetFormula();
	int nColSelWay;
	vector<int> vnRows, vnCols;
	string strFormula = m_pDataOB->GetFormula(vnRows, vnCols, &nColSelWay);
	///End CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE
	//m_edExpression.Text = strFormula;
	/// YuI 02/04/09 QA70-12831 COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
	//	formulaToDlg(strFormula);
	///------ Folger 05/18/10 ORG-124-P1 WRONG_INIT_ROW_RANGE_IN_SCV_WHEN_OPEN_WITH_HIGHLIGHT_WHOLE_COLUMN
	//BOOL bUpdateRange = is_str_auto(vs[2]) && is_str_auto(vs[3]);
	/// here, I assume !m_bAllowChangeCol has the same meaning as "Open from Change Parameter"
	BOOL bUpdateRange = !m_bAllowChangeCol;
	///------ End WRONG_INIT_ROW_RANGE_IN_SCV_WHEN_OPEN_WITH_HIGHLIGHT_WHOLE_COLUMN
	formulaToDlg(strFormula, bUpdateRange);
	/// end COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
	bool bRangeChanged = isRangeChanged(vnRows, vnCols, nColSelWay);		///Kyle 12/08/2008 CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE
	//------- CPY 07/26/06 QA70-8847 COLUMN_FORMULA_FROM_ORIGIN_C_REVAMP
//	bool bAutoUpdate = m_pDataOB->IsFormulaAutoUpdate();
//	m_btnAutoUpdate.Check = bAutoUpdate;
	int nAutoUpdate = m_pDataOB->GetFormulaAutoUpdateMode();
	///Jasmine 06/22/07 REMEMBER_RECALCULATE_SETTING
	//if(strFormula.IsEmpty() && (AU_NONE == nAutoUpdate))
		//nAutoUpdate = AU_ON_COMMAND;	
	if(!strFormula.IsEmpty() || AU_NONE != nAutoUpdate)
		m_comboAutoUpdate.SetCurSel(nAutoUpdate);
	///End REMEMBER_RECALCULATE_SETTING
	//-------
	
	Control ctrl;
	OnChangeAutoUpdate(ctrl);	//update Row range control by auto update settings
	
	//m_btnApply.Enable = false;
	//m_btnUndo.Enable = false;
	m_btnApply.Enable = !strFormula.IsEmpty() && (AU_NONE == nAutoUpdate);	///DG 8/19/05
	m_btnApply.Enable = m_btnApply.Enable || (!strFormula.IsEmpty() && bRangeChanged);			///Kyle 12/08/2008 CHECK_IF_RANGE_SELECTED_DIFFERENT_FROM_FORMULA_RANGE
	
	///Kenny 04/27/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
	if (!m_bAllowChangeCol)
	{
		m_btnPrevious.Enable = m_btnNext.Enable = m_btnFirst.Enable = m_btnLast.Enable = FALSE;
		return;
	}
	///End QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER

	m_btnPrevious.Enable = m_pDataOB->HasPreviousObject();
	m_btnNext.Enable = m_pDataOB->HasNextObject();
	
	//----Jake 04/18/07 ADD_FIRST_AND_LAST_BUTTON
	m_btnFirst.Enable = m_pDataOB->HasPreviousObject();
	m_btnLast.Enable = m_pDataOB->HasNextObject();
	//----Jake ADD_FIRST_AND_LAST_BUTTON
}
//----- CPY 05/01/06 MULTI_FOR_PREVIOUS_SCRIPT
// we want to store formula and Prescript into same string, separated by ";\r\n#"

string ColValuesDlg::dlgToformula()
{
	string str1 = m_edExpression.Text;
	string str2 = m_edPrescripts.Text;
	str1.TrimLeft();str1.TrimRight();
	str2.TrimLeft();str2.TrimRight();
	if(!str2.IsEmpty())
	{
		str1 += STR_COL_FORMULAR_SEPARATOR;
		str1 += str2;
	}
	return str1;
}
// return true if formula has Script Before Formula
/// YuI 02/04/09 QA70-12831 COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
//	bool ColValuesDlg::formulaToDlg(LPCSTR lpcsz)
bool ColValuesDlg::formulaToDlg(LPCSTR lpcsz, BOOL bUpdateRange)
/// end COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
{
	/// YuI 12/29/08 QA70-12831 COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
	/*
	string str = lpcsz;
	int nPos = str.Find(STR_COL_FORMULAR_SEPARATOR);
	string str2;
	bool bHasBeforeScript = false;
	//---------CPY 5/14/06 QA70-8675 CURRENT_COL_LT_ACCESS	formula may have only script, then it begins with #
	if(nPos < 0 && !str.IsEmpty() && str[0] == '#')
	{
		str2=str.Mid(1);
		str.Empty();
		bHasBeforeScript = true;
	}
	else if(nPos >= 0)
	{
		str2 = str.Mid(nPos + lstrlen(STR_COL_FORMULAR_SEPARATOR));
		str = str.Left(nPos);
		bHasBeforeScript = true;
	}
	//---------
	m_edExpression.Text = str;
	*/
	string strFormula;
	string strPrescript;
	int nFrom = -1;
	int nTo = -1;
	okutil_parse_composite_column_formula(lpcsz, &strFormula, &strPrescript, &nFrom, &nTo);
	if( nFrom >= 0 )
		nFrom++;
	if( nTo >= 0 )
		nTo++;
	bool bHasBeforeScript = !strPrescript.IsEmpty();
	m_edExpression.Text = strFormula;
	if( nFrom >= 0 && bUpdateRange )
		m_edRowsFrom.Text = nFrom;
	if( nTo >= 0 && bUpdateRange )
		m_edRowsTo.Text = nTo;
	/// end COLUMN_FORMULA_TO_REMEMBER_THE_RANGE
	///Jasmine 06/20/07 FIX_BUG_OF_SPECIFIED_FONT, refresh
	if(IsBottomPaneShown())
	{
		m_edPrescripts.Visible = false;
		m_edPrescripts.Text = strPrescript;
		m_edPrescripts.Visible = true;
	}
	///End FIX_BUG_OF_SPECIFIED_FONT
	///Sophy 5/19/2008 QA80-11559 FIX_BUG_BEFORE_FORMULA_SCRIPTS_PANEL_EMPTY
	else
		m_edPrescripts.Text = strPrescript;
	///end FIX_BUG_BEFORE_FORMULA_SCRIPTS_PANEL_EMPTY
	
	//--- CPY 6/9/2006 LOAD_SAMPLE_CHECK_OPEN_BEFORE_SCRIPT_BOX
	if(bHasBeforeScript && !IsBottomPaneShown())
		ShowBottomPane(true);
	//---
	return bHasBeforeScript;
}
//-----

void ColValuesDlg::updateDialogTitle()
{
	///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
	string str = m_pDataOB->GetSelectionStr();
	vector<string> vs;
	str.GetTokens(vs, '|');
	///End ADD_FORMATNAME_TO_TITLE
	//string strText = STR_SET_VALUES_TITLE+" - ";
	string strText = STR_DLG_NAME + " - ";
	if(m_layActive)
		///Jasmine 10/27/06 GET_RANGE_STRING
		///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
		//strText += strLabel;
		//strText += vs[0]+"("+vs[1]+")";	///Jasmine 10/23/06 CHANGE_TEXT_TO_EASY_UNDERSTAND
		strText+=vs[0];
		///End ADD_FORMATNAME_TO_TITLE
		///End GET_RANGE_STRING
	else
		strText += _L("No Worksheet/Matrix Page active");
	///Joe 8/24/2006 ADD_FORMATNAME_TO_TITLE
	if(! m_strCurFormulaName.IsEmpty())
		strText = strText + "-" + m_strCurFormulaName;  
	///End ADD_FORMATNAME_TO_TITLE
	Text = strText;
}
string ColValuesDlg::openFunctionBrowser()
{
	Function fn = Project.FindFunction("FBopen", "OriginLab\\FunctionBrowser.cpp");
	FUNCFB pfn = fn;
	string strFunction;
	if(pfn)
	{
		strFunction=pfn(GetSafeHwnd());
	}
	return strFunction;
}
bool ColValuesDlg::isChanged()
{
	return m_btnApply.Enable;
}
void ColValuesDlg::onBeforeFormulaChange()
{
	m_strUndo = dlgToformula();//m_edExpression.Text;
	//m_btnUndo.Enable = true;
}
void ColValuesDlg::onAfterChange()
{
	m_btnApply.Enable = true;
}
void ColValuesDlg::insertStrToFormula(LPCSTR lpcsz, bool bFunctionStr)
{
	onBeforeFormulaChange();
	
	string strSel = m_edExpression.GetSelText();
	string strText=lpcsz;
	
	//------ Folger 12/15/08 QA80-12773 v8.0986c ADD_$_FOR_OC_FUNCTION_WHICH_RETURN_STRING
	bool	bStrRet = (strText.GetLength() > 0 && strText[strText.GetLength() - 1] == '$');
	//------ End ADD_$_FOR_OC_FUNCTION_WHICH_RETURN_STRING

	///Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE
	//if(bFunctionStr)
	///Kyle 09/14/2009 ADD_WCOL(_ThisColNum)_UNDER_VARIABLE_CONSTANT
	// consider the text as const variable if there is some text between '(' and ')', like wcol(_ThisColNum)
	//bool bParentheses = bFunctionStr && -1 < strText.Find('(') && -1 < strText.Find(')');
	int		nLeftBracketPos = strText.Find('(');
	int		nRightBracketPos = strText.Find(')');
	bool bParentheses = bFunctionStr && nLeftBracketPos >= 0 && nRightBracketPos > nLeftBracketPos;
	if(bParentheses)
	{
		string strTmp = strText.Mid(nLeftBracketPos + 1, nRightBracketPos - nLeftBracketPos - 1);
		strTmp.Remove(',');				// only
		strTmp.TrimLeft();
		strTmp.TrimRight();
		bParentheses = strTmp.IsEmpty();
	}
	///End ADD_WCOL(_ThisColNum)_UNDER_VARIABLE_CONSTANT
	if(bParentheses)
	///End MENU_ITEM_FOR_COMMON_VARIABLE
	{
		///Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
		int nSpaceIndex = strText.Find(' ');
		int nParenIndex = strText.Find('(');
		if(nSpaceIndex > 0 && nSpaceIndex < nParenIndex)	// space before (
		{
			int nLength = strText.GetLength() - nSpaceIndex - 1;		// length after the space
			strText = strText.Right(nLength);
			strText.TrimLeft();
		}
		///End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
		///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
		//strText.Delete(strText.GetLength()-1);	//trimright ')'
		//strText+=strSel+')';
		nParenIndex = strText.ReverseFind(')');		// the last ')'
		if(nParenIndex > 0)
			strText.Insert(nParenIndex, strSel);
		///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
	}
	
	///Jasmine 12/15/08 v8.0986c QA80-12779 DETECT_FOCUS_POSITION_TO_ADD_STRING
	Edit edit;
	if( isCursorInPrescript() )
		edit = GetItem(IDC_SET_VAL_PRE_SCRIPTS);
	else
		edit = GetItem(IDC_SET_VAL_EXPRESSIONS);
	
	edit.ReplaceSel(strText, true);
	///DG 9/1/05 CURSOR_INSIDE_FUNCTION
	///Jasmine 12/15/08 v8.0986c QA80-12779 MENU_ITEM_FOR_COMMON_VARIABLE
	//if(bFunctionStr && strSel.IsEmpty())
	if(bParentheses && strSel.IsEmpty())
	///End MENU_ITEM_FOR_COMMON_VARIABLE
	{
		long nBegin, nEnd;
		edit.GetSel(nBegin, nEnd);
		//------ Folger 12/15/08 QA80-12773 v8.0986c ADD_$_FOR_OC_FUNCTION_WHICH_RETURN_STRING
		//nBegin--;	//back one bit, before ')'
		nBegin -= bStrRet ? 2 : 1;	/// for string, back offset 2, ")$", otherwise offset 1 for ")"
		//------ End ADD_$_FOR_OC_FUNCTION_WHICH_RETURN_STRING
		m_edExpression.SetSel(nBegin, nBegin);
		edit.SetSel(nBegin, nBegin);
	}
	///end CURSOR_INSIDE_FUNCTION
	
	SetFocus(edit.GetSafeHwnd());	
	///End DETECT_FOCUS_POSITION_TO_ADD_STRING
	
	onAfterChange();
}
///Jasmine 12/15/08 v8.0986c QA80-12779 DETECT_FOCUS_POSITION_TO_ADD_STRING
bool ColValuesDlg::isCursorInPrescript()
{
	if(false == m_edPrescripts.Visible)
		return false;
	
	HWND hWnd = GetFocus();
	Window win(hWnd);
	///Kyle 12/26/2008 FIX_RUNTIME_ERROR_WHEN_FOCUS_NOT_IN_ANYWHERE
	if(!win)
		return false;
	///End FIX_RUNTIME_ERROR_WHEN_FOCUS_NOT_IN_ANYWHERE
	RECT rect;
	win.GetWindowRect(&rect);
	m_wndDlg.ScreenToClient(&rect);		
	
	RECT 	rr;
	GetClientRect(m_edPrescripts, rr);
	return (rect.top >= rr.top && rect.bottom <= rr.bottom && rect.left >= rr.left && rect.right <= rr.right);
}
///End DETECT_FOCUS_POSITION_TO_ADD_STRING

void ColValuesDlg::beforeApplyFormula()
{
	vector<int> vnRows;
	vnRows.Add(getRangeIndex(m_edRowsFrom.Text, true));
	vnRows.Add(getRangeIndex(m_edRowsTo.Text, false));
	//---- CPY 5/11/09 QA70-12554 MAT_SET_VALUES_NEED_RANGE_SUPPORT
	if(EXIST_MATRIX == getPageType())
	{		
		vector<int> vnCols;
		vnCols.Add(getRangeIndex(m_edColsFrom.Text, true));
		vnCols.Add(getRangeIndex(m_edColsTo.Text, false));
		m_pDataOB->SetRange(vnRows, vnCols);
		return;
	}
	//----
	m_pDataOB->SetRange(vnRows, NULL);
}
int ColValuesDlg::getRangeIndex(string strVal, bool bBegin)
{
	//----- CPY 11/3/2007 SET_COL_VALUES_AUTO_NEED_LOCALIZATION
	//if(0 == strVal.CompareNoCase("Auto"))
	if(is_str_auto(strVal))
	//-----
		//----- CPY 11/28/2007 QA70-10754 AUTO_SHOULD_NOT_BE_ZERO_IN_SET_COL_VALUES
		//return bBegin ? 0 : -1;
		return -1;
		//-----
	//return atoi(strVal);	///DG 8/16/05 : it's inconsistency with 7.5
	return atoi(strVal)-1;
}
void ColValuesDlg::onActiveObjectChange()
{
	createDataObject();
	updateDialogCtrl();
}

void ColValuesDlg::afterApplyFormula()
{
	m_btnApply.Enable = false;
}
//------Folger 07/20/07 USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	
#ifdef USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE
void ColValuesDlg::repositionBottomPaneControl()
{
	int nEdge = GetControlGap();
	Control ctrlTitle = GetItem(IDC_SCRIPT_TITLE);
	Control ctrlEdit = GetItem(IDC_SET_VAL_PRE_SCRIPTS);
	
	RECT rrScriptTitle;
	RECT rrScriptEdit;
	GetClientRect(ctrlTitle, rrScriptTitle);
	GetClientRect(ctrlEdit, rrScriptEdit);
	
	int nHeight = rrScriptTitle.bottom - rrScriptTitle.top;
	int nWidth = rrScriptTitle.right - rrScriptTitle.left;
	rrScriptTitle.left = rrScriptEdit.left;
	rrScriptTitle.right = rrScriptTitle.left + nWidth;
	rrScriptTitle.top = rrScriptEdit.top;
	rrScriptTitle.bottom = rrScriptTitle.top + nHeight;
	
	rrScriptEdit.top = rrScriptTitle.bottom + nEdge;
	
	MoveControl(ctrlTitle, rrScriptTitle);
	MoveControl(ctrlEdit, rrScriptEdit);
}
#endif
//------End USE_RICH_EDIT_DIRECTLY_IN_BOTTOM_PANE	

///Kyle 12/17/2008 QA80-12790-P1 v8.0988 CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
/////Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
////int find_LT_functions(vector<string>& vsNames, vector<string>& vsArg, int nCategory, bool bSimple = false)
/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
////int find_LT_functions(vector<string>& vsRetTypes, vector<string>& vsNames, vector<string>& vsArg, int nCategory, bool bSimple = false)
//int find_LT_functions(vector<string>& vsRetTypes, vector<string>& vsNames, vector<string>& vsArg, int nCategory, bool bSimple = false, vector<string>* pvsCategories = NULL)
/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
/////End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
//{
	//
	/////Jasmine 06/29/06 TEMP_ADD_SOME_RNG_FUNC
	////As other random number generator functions are not ready yet,
	////add: grnd(), rnd(), ran(), poisson() temporarily
	//if(BFC_RNG == nCategory)
	//{
		//vector<string> vsN = {"grnd", "normal", "poisson", "rnd", "ran","uniform"};
		//vsNames = vsN;
		//vector<string> vsA = {"()", "(,)", "(,,)", "()", "()","(,)"};
		//vsArg = vsA;
		//return vsN.GetSize();
	//}
	/////End TEMP_ADD_SOME_RNG_FUNC
	////---CPY 12/03/2008 compile err after Kyle 12/03/2008 QA70-9982-S2 OKUTIL_FIND_LT_FUNCTIONS_RETURN_FUNCTION_TYPES_AND_ARGUMENT_TYPES
	////int nCount = okutil_find_LT_functions(&vsNames, &vsArg, nCategory);
	//vector<string> vsArgTypes;
	/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	////int nCount = okutil_find_LT_functions(&vsNames, &vsRetTypes, &vsArg, &vsArgTypes, nCategory);
	//int nCount = okutil_find_LT_functions(&vsNames, &vsRetTypes, &vsArg, &vsArgTypes, nCategory, pvsCategories);
	/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
	////---
	////vsArg[0] = "a,b,c"...
	/////Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
	//if(nCategory >= BFC_NAG_SF && nCategory <= BFC_RNG)		// build in functions category, may need to be improved to use shortening argument type for argument name
	//{
	/////End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
		//for(int ii = 0; ii < nCount; ii++)
		//{
			//string str = vsArg[ii];
			//if(bSimple)
			//{
				//str.Empty();
				//int nToken = vsArg[ii].GetNumTokens(',');
				//for(int jj = 1; jj < nToken; jj++)
					//str += ",";	//str = ",,"
			//}
			/////Jasmine 07/10/07 REMOVE_UNWANTED_PARENTHESIS
			//str.TrimLeft('(');
			//str.TrimRight(')');
			/////End REMOVE_UNWANTED_PARENTHESIS
			//vsArg[ii] = "(" + str + ")";//vsArg[0] = "(a,b,c)" or "(,,)"
		//}
	//}
	/////Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
	//else	// oc function category
	//{
		//for(int ii = nCount - 1; ii >= 0; ii--)
		//{
			//vector<string> vsArgNames;
			//if(!_check_construct_shortening_argument_name(vsArgTypes[ii], vsArgNames))
			//{
				//vsRetTypes.RemoveAt(ii);
				//vsNames.RemoveAt(ii);
				//vsArg.RemoveAt(ii);
				/////------ Folger 12/12/08 QA80-12773 v8.0986 SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
				//if ( pvsCategories )
					//pvsCategories->RemoveAt(ii);
				/////------ End SUPPORT_SPECIFY_OC_FUNCTION_CATEGORY_IN_LABTALK_PRAGMA
				//nCount--;
				//continue;
			//}
			//string str;
			//if(bSimple)
			//{
				//int nToken = vsArg[ii].GetNumTokens(',');
				//for(int jj = 1; jj < nToken; jj++)
					//str += ",";	//str = ",,"
			//}
			//else
			//{
				//str.SetTokens(vsArgNames, ',');
			//}
			//vsArg[ii] = "(" + str + ")";
		//}
	//}
	/////End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
	//return nCount;
//}
//
/////Kyle 12/04/2008 QA70-9982-S2 CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
//static bool _check_construct_shortening_argument_name(string strArgTypes, vector<string>& vsArgNames)
//{
	//vector<string> vsArgTypes, vsName;
	//int nNumArgs = strArgTypes.GetTokens(vsArgTypes, ',');
	//if(nNumArgs <= 0)
		//return false;
	//vsArgNames.SetSize(nNumArgs);
	//for(int ii=0; ii<nNumArgs; ii++)
	//{
		//string strArgType = vsArgTypes[ii], strArgName;
		//if(strArgType.Compare("bool")==0)
			//strArgName = "b";
		//else if(strArgType.Compare("double")==0)
			//strArgName = "d";
		//else if(strArgType.Compare("int")==0 || strArgType.Compare("uint")==0)
			//strArgName = "n";
		//else if(strArgType.Find("string")==0)
			//strArgName = "str";
		//else if(strArgType.Find("vector<string>")==0)
			//strArgName = "vs";
		//else if(strArgType.Find("vector<int>")==0)
			//strArgName = "vn";
		//else if(strArgType.Find("vector<double>")==0)
			//strArgName = "vd";
		//else
			//return false;
		//
		//vsArgNames[ii] = strArgName;
	//}
	//return true;
//}
/////End CHECK_FUNCTION_PROTYPE_AND_CONSTRUCT_AGRUMENT_NAMES
///End CENTRALIZE_CODE_ABOUT_FUNCTIONS_LIST_TO_FUNCTIONS_MENU
/*
// generic func prototype for VC level calling
int ColumnValues(int nMsg=0, DWORD dwCntrl=0)
{
	bool bClose = OMSG_CLOSE==nMsg? true:false;
	bool bUpdate = OMSG_UPDATE==nMsg? true:false;

	if(bClose)
	{
		if(s_pColValuesDlg)
		{
			Window winDlg = s_pColValuesDlg->GetWindow();
			if(winDlg)
				winDlg.SendMessage(WM_CLOSE);
			delete s_pColValuesDlg;
			s_pColValuesDlg = NULL;
		}
		return 0;
	}
	// open or update
	if(!s_pColValuesDlg)
	{
		if(bUpdate)
			return 1;// not possible to update, since dialog not opened

		s_pColValuesDlg = new ColValuesDlg;
		s_pColValuesDlg->Create(GetWindow());
	}
	if(bUpdate)
		;//s_pColPropertiesDlg->Update();//"from global message");
	
	return 0;
}
*/

//--- CPY 7/25/05 COL_SET_VALUES_MODAL
// open DoModal for active DataObject
// return IDOK or IDCANCEL
int ColMatValues(int nMsg, DWORD dwCntrl = 0, LPVOID lpData = NULL)
{
	///Jasmine 04/24/06 SET_COL_VAL_DLG_MODELESS
	//ColValuesDlg	colDlg;
	
	//return colDlg.DoModalEx(GetWindow(OGW_MDICLIENT));
	
	bool bClose = OMSG_CLOSE==nMsg? true:false;
	bool bUpdate = OMSG_UPDATE==nMsg? true:false;

	///Kenny 04/27/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
	// dwCntrl == 1 means come from Change Parameter, otherwise dwCntrl == 0 as before.
	bool bIsFromChgParam = ( 1 == dwCntrl );	
	///End QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER

	if(bClose)
	{
		if(s_pColValueDlg)
		{
			Window winDlg = s_pColValueDlg->GetWindow();
			if(winDlg)
				winDlg.SendMessage(WM_CLOSE);
			///Kenny 04/27/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
			if(bIsFromChgParam)
				return 0;
			///End QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
			delete s_pColValueDlg;
			s_pColValueDlg = NULL;
		}
		return 0;
	}
	// open or update
	if(!s_pColValueDlg)
	{
		if(bUpdate)
			return 1;// not possible to update, since dialog not opened

		///Kenny 04/27/2009 QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
		//s_pColValueDlg = new ColValuesDlg;
		//s_pColValueDlg->Create(GetWindow(OGW_MDICLIENT));
		const BOOL bAllowChangeCol = !bIsFromChgParam;
		const BOOL bDeleteOnDestroy = !bIsFromChgParam;
		if (bIsFromChgParam)
		{
			ColValuesDlg dlg(bAllowChangeCol, bDeleteOnDestroy);
			s_pColValueDlg = &dlg;
			int nRet = dlg.DoModalEx( GetWindow(OGW_MDICLIENT) );
			s_pColValueDlg = NULL;
			return nRet;
		}
		else
		{
			s_pColValueDlg = new ColValuesDlg(bAllowChangeCol, bDeleteOnDestroy);
			s_pColValueDlg->Create(GetWindow(OGW_MDICLIENT));
		}
		///End QA80-13519-P1 SET_COL_VAL_DLG_SHOULD_BE_MODAL_IF_CHANGE_PARAMETER
	}
	if(bUpdate)
		;//s_pColValueDlg->Update();//"from global message");
	
	return 0;
}	///End SET_COL_VAL_DLG_MODELESS
//---
	
	
