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

#include <o8dlg.h>
#include <..\OriginLab\PAWizCore.h>
#include <..\OriginLab\XFWizard_utils.h>
#include <xfGraph_utils.h>

#include <..\OriginLab\Graph_utils.h>
#include <..\Originlab\curve_utils.h>
#include <..\Originlab\nlsf_utils.h>

#include <..\OriginLab\XFunctionEx.h>
#include <event_utils.h>

/*------------------------------------------------------------------------------*
 * Modification Log:  															*
 * Iris 2008-10-24 FIX_CRASH_WHEN_CLICK_FINISH_IN_PA_FIT_IF_SUBTRACT_BASELINE	*
 * Kyle 11/13/2008 SUBTRACTED_DATA_IS_STORED_IN_TEMPORARY_WORKSHEET				*
 *	Folger 12/08/08 v8.0983b RUNTIME_ERROR_WHEN_LOAD_THEME_FROM_FITTING_WITH_CONSTANT_BASELINE
 *	Sim 01-07-2008 QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE							*
 *	Folger 10/09/09 BETTER_INPUT_ERROR_HANDLING_IN_PAMULTIY						*
 *------------------------------------------------------------------------------*/

#define	PA_BEFORE_EXECUTED				"BeforeExecuted"
#define	PA_INITIALIZED					"Initialized"

#define _STR_SCALE_BUTTONS_LIST 		("Scale")
//#define _STR_SUBTRACT_BUTTONS_LIST 		("Subtract Now|Undo")///sandy 2009-3-5 add rescale button
#define _STR_SUBTRACT_BUTTONS_LIST 		("Subtract Now|Undo|Rescale")

enum
{
	IND_BTN_SUBTRACT,
	IND_BTN_UNDO,
	IND_BTN_RESCALE, ///sandy 2009-3-5 add rescale button

};


///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
//static void _switch_to_preview_layer(PAWizCore* paCore)
static void _switch_to_preview_layer(PAWizCore* paCore, bool bRescale)
{
	if(!paCore)
	{
		ASSERT(false);
		return;
	}
	GraphLayer gl;
	paCore->GetPreviewLayer(gl);
	
	///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
	if(bRescale)
		gl.Rescale();

}
//static bool _create_parent_plot(PAWizCore* paCore, XYRange xyo, TreeNode& trOriginPlot)
//{	
	//if(!paCore)
	//{
		//ASSERT(false);
		//return false;
	//}
	//
	//GraphLayer gl;
	//paCore->GetPreviewLayer(gl);
	//
	//DataPlot dp;
	//if(!pa_create_dataplot_with_style_during_wiz(xyo, gl, dp, trOriginPlot))
		//return false;
	//
	////if(!update_data_context_to_page(gp, xyo, PFW_PARENT_PLOT_TAGNAME)) //no store in page now
		////return false;
	//
	//return true;
//}
/*static bool _remove_parent_plot_from_page(Page& pg)
{
	if(!pg.IsValid() )
		return false;
	
	HWND hwnd;
	Tree trGetN;
	load_GetN_from_page(pg, trGetN, hwnd, STR_STORAGE_NAME);

	trGetN.RemoveChild(PFW_PARENT_PLOT_TAGNAME);
	
	return save_GetN_to_page(pg, trGetN,  hwnd, STR_STORAGE_NAME);	
}*/

static bool _subtract_baseline_range(PAWizCore* paCore, XYRange& xyBaseline, bool bUndo = false)
{	
	ASSERT(paCore);
	
	XYRange xyo;
	if(!paCore->GetOriginalRange(xyo))
	{
		error_report("fail in get xyrange in PACore!");
	}
	
	vector vxo, vyo;
	BOOL bb = xyo.GetData(vyo, vxo);
	ASSERT(bb);
	
	vector vxTemp, vyTemp;//sandy 2008-10-21 add
	if(!bUndo)//subtract
	{
		XYRange xyBaseTemp;
		vector vbx, vby;
		if( !paCore->GetBaselineRange(xyBaseTemp) )
			return false;
		bb = xyBaseTemp.GetData(vby, vbx);
		ASSERT(bb);

		//sandy 2008-10-21 add
		//if(!subtract_baseline(vxo, vyo, vbx, vby))
			//return false;
		vxTemp = vxo;
		vyTemp = vyo;
		if(!subtract_baseline(vxTemp, vyTemp, vbx, vby))
			return false;		

	}
	//sandy 2008-10-21 add
	//xyBaseline.SetData(&vyo, &vxo, 0, NULL, 0);
	xyBaseline.SetData(&vyTemp, &vxTemp, 0, NULL, 0);
	
	bool bSubtract = !bUndo;
	paCore->SetSubtractedMode(bSubtract);
	
	/*
	Page pg = Project.Pages();
	if(bUndo)
		_remove_parent_plot_from_page(pg);//Sandy 2008-4-21 remove parent plot when undo
	*/
	return true;
}


static bool _subtract_button_event(TreeNode& trGetN)
{	
	PAWizCore* paCore = (PAWizCore*)get_xf_core_handler(trGetN);
	ASSERT(paCore);	
	
	TreeNode trBtnGroup = trGetN.btn_subtract;
	
	//int nUsableButton = -1;
	///Sandy 2009-3-5 add rescale button
	if(IND_BTN_RESCALE == trBtnGroup.nVal)
	{
		GraphLayer gl;
		paCore->GetPreviewLayer(gl);
		gl.Rescale();		
	}
	else
	{
		XYRange xy;
		paCore->GetSubtractedRange(xy);	
		
		bool bSubtract = IND_BTN_SUBTRACT == trBtnGroup.nVal;
		bool bUndo = !bSubtract;
		if(_subtract_baseline_range(paCore, xy,  bUndo))
		{
			trGetN.subtract.nVal = bSubtract;
			
			vector<int> vn(1);
			vn[0] = bSubtract? IND_BTN_SUBTRACT : IND_BTN_UNDO;
			disable_buttons_in_group(vn, trBtnGroup);
	
			trGetN.autosubtract.nVal = bSubtract;
			trGetN.autosubtract.Enable = !bSubtract;
	
		}
		
		if(bSubtract)
	//		_create_parent_plot(paCore, xy, trGetN.trOrgPlot);
			//create_subtracted_plot(paCore, bUndo);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
			create_subtracted_plot(paCore, bUndo, trGetN.rescale.nVal);
		else
			//_switch_to_preview_layer(paCore);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
			_switch_to_preview_layer(paCore, trGetN.rescale.nVal);
	}
	


	
	return true;
}


void pa_basetreat(const int& autosubtract, const int& rescale, const int& btn_subtract, const int& subtract, const int& fit, const string& strfunc, const int& fit_bk, const string& hint_addback, const int& fixbase, const string& hint_fixbase, const int& nXFCorePointer)
{
	///---Sim 01-07-2008 QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE
	//PAWizCore* paCore = (PAWizCore*)get_xf_core_handler(getnhandler);
	PAWizCore* paCore = (PAWizCore*)get_xf_core_handler(NODE_NAME_XF_WIZ_CORE_POINTER);
	///---END QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE
	if(!paCore)
		XF_THROW(XF_ERR_INVALID_PA_INSTANCE);	
		
	
	int goal = paCore->GetCurrGoal();	
	
	XYRange xySubtracted; 
	paCore->GetSubtractedRange(xySubtracted);
	if(autosubtract == true && subtract == false) //if not subtract
		_subtract_baseline_range(paCore, xySubtracted);
	
	if(true == autosubtract || true == subtract)
	{			
		//----- Iris 2008-10-24 FIX_CRASH_WHEN_CLICK_FINISH_IN_PA_FIT_IF_SUBTRACT_BASELINE
		///Kyle 11/13/2008 SUBTRACTED_DATA_IS_STORED_IN_TEMPORARY_WORKSHEET
		//if(goal == PA_GOAL_FIT_PEAK)
			//paCore->UpdateSubtractedDataToSourcePage();//default is create
		///End SUBTRACTED_DATA_IS_STORED_IN_TEMPORARY_WORKSHEET
		paCore->GetSubtractedRange(xySubtracted); // get range from new creately worksheet
		//----- end FIX_CRASH_WHEN_CLICK_FINISH_IN_PA_FIT_IF_SUBTRACT_BASELINE
		
		//_create_parent_plot(paCore, xySubtracted, trOrgPlot);
		//create_subtracted_plot(paCore, false);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
		create_subtracted_plot(paCore, false, rescale);
	}
	///Sandy 2008-4-11 add check box to decide if baseline fix with peaks
	
	if(goal == PA_GOAL_FIT_PEAK)		///Jasmine 05/06/08 NO_FIT_BASELINE_IF_BASELINE_SUBTRACTED
	{	
		paCore->SetBaselineFitMode(fit);
		if(fit)	///Jasmine 05/16/08 PA_FIX_BASELINE_AVAILABLE_IF_FIT_BASELINE_WITH_PEAK
			paCore->SetBaseParamFixMode(fixbase);
		
		///Sandy 2008-5-13 if constant baseline, always fit with peak when no subtract,  and set function= constant
		if( PA_BM_CONSTANT == paCore->GetBaseMode() )
		{
			paCore->SetBaselineFitMode(true);
			
			/*-----Sandy 2008-10-30 DON'T_KNOW_WHY_JASMINE_DO_THIS_AND_IT_MAKE_CONSTANT_BASELINE_NO_FIX
			if(fit)	///Jasmine 05/16/08 PA_FIX_BASELINE_AVAILABLE_IF_FIT_BASELINE_WITH_PEAK
				paCore->SetBaseParamFixMode(false);
			*/
			///Sandy 2008-9-27 remove since pa_make_baseline_param_tree will add function name as label of root-treenode
			//paCore->SetBaselineFitFunc(0);// 0 is the index of constant function
			
			XYRange xyBaseline;
			vector vxbase, vybase;
			if( !paCore->GetBaselineRange(xyBaseline) )
				ASSERT(false);
			
			vector vParams(1);
			if( xyBaseline.GetData(vybase, vxbase) )
				vParams[0] = vybase[0];
			else
				ASSERT(false);
			
		
			Tree treeParams;
			//------ Folger 12/08/08 v8.0983b RUNTIME_ERROR_WHEN_LOAD_THEME_FROM_FITTING_WITH_CONSTANT_BASELINE
			//if( !pa_make_baseline_param_tree(treeParams, "Constant", vParams) || !paCore->UpdateInfoTree(treeParams, PA_TREE_BASELINE_FIT_INFO, true) )//true means set
				//XF_THROW(XFERR_FAIL_CONVERT_BASELINE_PARAM_TREE);
			if ( !pa_make_baseline_param_tree(treeParams, "Constant", vParams) )
				XF_THROW(XFERR_FAIL_CONVERT_BASELINE_PARAM_TREE);
			treeParams.SetAttribute(STR_BASEFUNC_FROM_BASECREATE_XF_ATTRIB, 1);
			paCore->UpdateInfoTree(treeParams, PA_TREE_BASELINE_FIT_INFO, true) 
			//------ eND RUNTIME_ERROR_WHEN_LOAD_THEME_FROM_FITTING_WITH_CONSTANT_BASELINE
		}
		///end
		
		//----- Iris 2008-10-24 FIX_CRASH_WHEN_CLICK_FINISH_IN_PA_FIT_IF_SUBTRACT_BASELINE move to funcution begining to do this before do subtract and plot subtract data range
		/*
		///Sandy 2008-10-24 add
		if(true == autosubtract || true == subtract)
			paCore->UpdateSubtractedDataToSourcePage();//default is create
		*/
		//----- end FIX_CRASH_WHEN_CLICK_FINISH_IN_PA_FIT_IF_SUBTRACT_BASELINE
	}
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int pa_basetreat_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return pa_basetreat_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	PAWizCore* paCore = (PAWizCore*)get_xf_core_handler(trGetN);
	if(!paCore)
		return false;
		
	switch(nEventID)
	{
	case GETNE_ON_INIT:
		int nInit = false;
		if( !trGetN.GetAttribute(PA_INITIALIZED, nInit) )
		{
			trGetN.SetAttribute(PA_INITIALIZED, true);
			break;
		}
		
		XYRange xyTemp;
		paCore->GetSubtractedRange(xyTemp);	///Jasmine 04/08/08 DONOT_CLEAN_PARENT_PLOT_DATA
				
		if(true == trGetN.autosubtract.nVal || true == trGetN.subtract.nVal)
		{
			if( false == trGetN.subtract.nVal )			
			{
				_subtract_baseline_range(paCore, xyTemp, true);// undo subtract
				//_switch_to_preview_layer(paCore);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
				_switch_to_preview_layer(paCore, trGetN.rescale.nVal);
	
				TreeNode trSubtractBtns = trGetN.btn_subtract;
				vector<int> vn = { IND_BTN_UNDO};
				disable_buttons_in_group(vn, trSubtractBtns);
			}
			else
			{			
				//_create_parent_plot(paCore, xyTemp, trGetN.trOrgPlot);
				//create_subtracted_plot(paCore, false);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
				create_subtracted_plot(paCore, false, trGetN.rescale.nVal);
			}
			
		}
		
		break;
	
	case GETNE_ON_UNDO:
		trGetN.RemoveAttribute(PA_INITIALIZED);
		trGetN.RemoveAttribute(PA_BEFORE_EXECUTED);
		
		//undo subtract		
		paCore->SetSubtractedMode(false);
		//_switch_to_preview_layer(paCore);///Sandy 2009-3-6  RYAN_SUGGEST_RESCALE_SAVE_TO_THEME
		_switch_to_preview_layer(paCore, trGetN.rescale.nVal);
	
		//clean_up_peaks_data(paCore);///sandy 2008-10-14 add
		paCore->CleanUpContextRange(PA_DR_PEAKSRANGE);
		paCore->CleanUpContextRange(PA_DR_SUBTRACTED);
		///Kyle 11/13/2008 SUBTRACTED_DATA_IS_STORED_IN_TEMPORARY_WORKSHEET
		//if(paCore->GetCurrGoal() == PA_GOAL_FIT_PEAK)	
			//paCore->UpdateSubtractedDataToSourcePage(true);//true = destroy
		///End SUBTRACTED_DATA_IS_STORED_IN_TEMPORARY_WORKSHEET
		
		///Sandy 2008-10-16 should undo all status store in pacore
		paCore->SetBaselineFitMode(false);
		paCore->SetBaseParamFixMode(false);
		break;
	}
	
	
		
	if(0 == lstrcmpi(lpcszNodeName, "btn_subtract"))
	{
		_subtract_button_event(trGetN);		
		//return true;//sandy 2008-4-11 can not return right now.
	}
	
	if(0 == lstrcmpi(lpcszNodeName, "btn_rescale"))
	{
	
	}
	
	///Sandy 2008-4-11 update fit baseline with peaks option only when goal == fit peaks
	if(0 == lstrcmpi(lpcszNodeName, "btn_subtract")||0 == lstrcmpi(lpcszNodeName, "autosubtract")
		||0 == lstrcmpi(lpcszNodeName, "fit")|| nEventID == GETNE_ON_INIT)//nEventID == GETNE_ON_RESTORE ||
	{
		if( paCore->GetCurrGoal() == PA_GOAL_FIT_PEAK )
		{			
			//back up the fit check box statue when user changing idea
			if(0 == lstrcmpi(lpcszNodeName, "fit"))
			{
				trGetN.fit_bk.nVal = trGetN.fit.nVal;
			}
			
			//update fit check box and fit function string
			int nFunction 		= paCore->GetBaselineFitFunc();			
			bool bHasSubtracted = paCore->GetSubtractedMode();			
			bool bCanFitWithPeaks = (!(trGetN.autosubtract.nVal == true || bHasSubtracted)) && (0 <= nFunction);
			
			///Sandy 2008-12-3 if constant baseline, disable fit and fix, with both checked
			bool bConstantFitWithPeaks = (PA_BM_CONSTANT == paCore->GetBaseMode());			
			
			if(bCanFitWithPeaks)
			{
				string strFuncName, strFileName;
				nlsf_get_func(nFunction, strFuncName, strFileName, STR_PA_NLSF_CAT_BASELINE);
				trGetN.strfunc.strVal = strFuncName;
				trGetN.fit.nVal = trGetN.fit_bk.nVal;
				
				///Sandy 2008-12-3 if constant baseline, disable fit and fix, with both checked
				if(bConstantFitWithPeaks)
				{
					trGetN.fit.nVal = 1;
					///Sandy 2009-2-18 Easwar suggested "if I do not subtract, the option should be to fit with the peaks so the value is set to be variable instead of fixed"
					//trGetN.fixbase.nVal = 1;
				}
	
			}
			else
			{
				trGetN.fit_bk.nVal = trGetN.fit.nVal;
				trGetN.fit.nVal = 0;
			}
			
			//Sandy 2008-12-3 if constant baseline, disable fit and fix, with both checked
			//trGetN.fit.Enable = bCanFitWithPeaks;
			
			trGetN.fit.Enable = bCanFitWithPeaks && !bConstantFitWithPeaks;
			///Sandy 2009-2-18 Easwar suggested "if I do not subtract, the option should be to fit with the peaks so the value is set to be variable instead of fixed"
			//trGetN.fixbase.Enable = !bConstantFitWithPeaks;
			
			trGetN.strfunc.Show = ( (bCanFitWithPeaks && trGetN.fit.nVal == 1) ? true:false);
			
			///Sandy 2008-4-14 append for CP's final design
			trGetN.hint_addback.Show = (bCanFitWithPeaks && trGetN.fit.nVal == 0? true:false);
			trGetN.fixbase.Show = ((bCanFitWithPeaks && trGetN.fit.nVal == 1) ? true:false);  
	
			//trGetN.hint_fixbase.Show = ((bCanFitWithPeaks && trGetN.fit.nVal == 1) ? true:false);
			trGetN.hint_fixbase.Show = ((bCanFitWithPeaks && trGetN.fit.nVal == 1 && !bConstantFitWithPeaks) ? true:false);
			///end
			
	
			
			
		}
		return true;
	}
	//end
	
	return false;

}

int pa_basetreat_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void pa_basetreat_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	if( nGetNDialog >= 0 )
	{
		PAWizCore* paCore = (PAWizCore*)get_xf_core_handler(trGetN);
		if(!paCore)
		{
			nRet = XFEVT_ABORT;
			return;
		}
	
		trGetN.SetAttribute(STR_HELPID_ATTRIB, IDD_PA_BASELINE_TREATMENT);
		
		///------ Folger 10/09/09 BETTER_INPUT_ERROR_HANDLING_IN_PAMULTIY
		//XYRange yi;
		//vector vx, vy;
		//if( !paCore->GetOriginalRange(yi) || !yi.GetData(vy, vx) || vx.GetSize()<=0)
		//{
			//nRet = XFEVT_ABORT;
			//return;
		//}
		///------ End BETTER_INPUT_ERROR_HANDLING_IN_PAMULTIY
		
		//following codes should be only executed when from previous xf to this xf
		int bExecuted = false;
		if(trGetN.GetAttribute(PA_BEFORE_EXECUTED, bExecuted))
			return;
		
		
		//XYRange xyTemp;
		//paCore->GetSubtractedRange(xyTemp);
		//xyTemp.SetData(&vy, &vx, 0, NULL, 0);
		
		///Sandy 2008-3-24 if for fitting, subtracted data should output to user worksheet	
		//_update_oy(trGetN);	
		
		//---save plot style
		//GraphLayer gl = Project.ActiveLayer();
		//if(gl)
		//{
		////Sandy 2008-4-15 to fix refresh problem after remove anchor plot
			//TreeNode trOPlot = trGetN.trOrgPlot;
			//if(trOPlot)
			//{
				//DataPlot dp;
				//get_plot_from_xyr_in_gl(gl, yi, dp);				
				////string str;//debug message
				////str.Format("paw_basecond_before_execute, original plot is %s", dp.IsValid()?"valid":"invalid");
				////ERR_MSG(str);
				//
				//pa_keep_dataplot_style_during_wiz(dp, trOPlot);
			//}	
		//}
		//---
		
		if(true == trGetN.subtract.nVal)
		{
			trGetN.autosubtract.nVal = true;
			trGetN.subtract.nVal = false;
		}
		
		//---set button gui
		if ( nGetNDialog > 0 )
		{
			TreeNode trSubtractBtns = trGetN.btn_subtract;
			trSubtractBtns.SetAttribute(STR_LABEL_ATTRIB, "");
			trSubtractBtns.SetAttribute(STR_ID_ATTRIB, ONODETYPE_PUSHBUTTON_GROUP);
			DWORD dwDisplyBits = DISPLAY_EDITOR_HORZ | DISPLAY_EDITOR_LEFT;
			trSubtractBtns.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
			trSubtractBtns.SetAttribute(STR_COMBO_ATTRIB, _STR_SUBTRACT_BUTTONS_LIST);	
			vector<int> vn = { IND_BTN_UNDO};
			disable_buttons_in_group(vn, trSubtractBtns);
			
			
			dwDisplyBits = DISPLAY_EDITOR_CHECK_ON_LEFT;
			trGetN.autosubtract.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
			trGetN.autosubtract.Enable = false == trGetN.subtract.nVal;
			
			////Sandy 2009-3-6 add auto rescale check box
			trGetN.rescale.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
	
			
			///Sandy 2008-4-11 show fit baseline with peaks option only when goal == fit peaks
			int goal = paCore->GetCurrGoal();
			
			trGetN.fit.Show = (goal == PA_GOAL_FIT_PEAK ? true:false);
			if(trGetN.fit.Show)
			{
				trGetN.fit.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
			}
			trGetN.strfunc.Show = (goal == PA_GOAL_FIT_PEAK ? true:false);
			trGetN.strfunc.Enable = ENABLE_READ_ONLY;
			
			///Sandy 2008-4-14 append for CP's final design
			trGetN.hint_addback.Show = (goal == PA_GOAL_FIT_PEAK ? true:false);
			trGetN.fixbase.Show = (goal == PA_GOAL_FIT_PEAK ? true:false);  
			if(trGetN.fixbase.Show)
				trGetN.fixbase.SetAttribute(STR_ATTRIB_DISPFMT, (string)dwDisplyBits);
			trGetN.hint_fixbase.Show = (goal == PA_GOAL_FIT_PEAK ? true:false);
			//end 
			
		}		
		//---
	
		trGetN.SetAttribute(PA_BEFORE_EXECUTED, true);
		
		return;
	}	
	
	
}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int pa_basetreat_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
