#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
enum{
	dest_page,
	dest_layer,
	dest_spepage,
	dest_spelayer,
};
enum{
	update_reconstruct,
	update_update,
};
enum{
	legend_separate,
	legend_combine,
};
enum{
	order_descend,
	order_ascend,
};
enum{
	mode_comment,
	mode_dr,
	mode_lu,
	mode_udpara,
	mode_lname,
	mode_sname,
	mode_lpara,
	mode_custom,
};

/// Iris 07/19/2007 INIT_MODE_VAL_FROM_PAGE_SETTINGS
/// Iris 07/25/2007 SHOULD_CHANGE_LEGEND_POSITION_IN_THIS_XF
/// Iris 07/26/2007 FIX_RECONSTRUCT_STILL_SHOW_YERR_IN_LEGEND
/// Hong 08/08/07 QA80-10064 FIX_LEGEND_COMBINE_FAIL_KEEP_ORIGIN_ORDER
/// Sim 09-05-2008 CLEAN_DEFAULT_THEME
/// Army 07/06/2009 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER

//put additional include files here
#include <..\originlab\graph_utils.h>
#include <..\originlab\theme_utils.h>
//put your own support static functions here

//static vector<string> s_vsLegendFormat = {"@LM", "@R", "@U", "@LD", "@LA", "@LS", "@LP"};
/// Iris 07/27/2007 IMPROVE_CUSTOM_FORMAT_EDITABLE_COMBO
//static vector<string> s_vsCustomLegendFormat = {"@D","@LG","@LM","@LN","@LA","@LS","@LL","@LU","@LH","@LC","@LP<n>","@LD<n>","@LQ<n>","@U","@W","@WL","@WS"};
///end IMPROVE_CUSTOM_FORMAT_EDITABLE_COMBO

/*
static int _get_legend_count(const GraphLayer& gl)
{	

	GraphObject	goLegend = gl.GraphObjects(GO_LEGEND_NAME);
	if(!goLegend.IsValid())
		return -1;
	
	if(goLegend.Text.IsEmpty())
		return 0;
	
	vector<string> vsText;
	str_separate(goLegend.Text,"\r\n",vsText);
	
	return vsText.GetSize();
}
*/
/// Hong 07/24/07 v8.0666 MORE_RELIABLE
static bool _update_getn_by_update(TreeNode& trGetN)
{
	bool bEnable = (update_reconstruct == trGetN.update.nVal) ? true : false;	
	/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	trGetN.order.Enable = bEnable;
	trGetN.order.Show = bEnable;
	/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	GraphPage gp = Project.Pages();

	/// Hong 08/03/07 QA80-10064-P5 HIDDEN_LEGEND_WHEN_ACTIVE_LAYER
	//if ( 1 == gp.Layers.Count() )
	if ( dest_layer == trGetN.dest.nVal || 1 == gp.Layers.Count() )
	/// end HIDDEN_LEGEND_WHEN_ACTIVE_LAYER
		bEnable = false;
	
	trGetN.legend.Enable = bEnable;
	trGetN.legend.Show = bEnable;
		
	return true;
}
/// end MORE_RELIABLE

/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
static bool _update_getn_by_dest(TreeNode& trGetN)
{
	bool bDestPage = (dest_page == trGetN.dest.nVal) ? 1 : 0;
	trGetN.legend.Enable = bDestPage;
	/// Hong 07/24/07 v8.0666 MORE_RELIABLE
	//if ( bDestPage ) // as layout will reconstrcut all legend, so do this limite
	//{
	//	trGetN.update.Enable = ENABLE_READ_ONLY;
	//	trGetN.update.nVal = update_reconstruct;
	//}
	//else
	//{
	//	trGetN.update.Enable = ENABLE;
	//}
	trGetN.mode.Enable = bDestPage;
	trGetN.mode.Show = bDestPage;
	
	_update_getn_by_update(trGetN);
	/// end MORE_RELIABLE
	return true;
}
/// end MORE_OPTIONS_FOR_LEGEND_UPDATE

/// Hong 07/24/07 v8.0666 ADD_APPLY_BTN
/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
//static void _legend_update(int dest, int update, int legend, int mode, string custom)
///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
//static void _legend_update(int dest, int update, int legend, int mode, string custom, bool bAscending)
static void _legend_update(int dest, int update, int legend, int mode, string custom, bool bAscending, GraphPage& page= NULL, GraphLayer& layer =NULL)
///End SUPPORT_SPECIFY_PAGE_AND_LAYER
/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
{
	///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
	/*
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
	GraphLayer gl = Project.ActiveLayer();
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
	
	if(!gl.IsValid())
		XF_THROW(XFERR_INVALID_LAYER);
	
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE	
	//int nMode = (0 == setmode)? -1 : mode;
	//bool bReconstruct = (legend == legend_reconstruct)? true:false;
	//legend_update(gl, mode, true, bReconstruct, custom);	
	GraphPage gp = gl.GetPage();
	*/
	GraphLayer gl;
	GraphPage  gp;
	if(dest_spepage == dest)
	{
		gp=page;
		if(!page.IsValid())
			XF_THROW(XFERR_INVALID_PAGE);
	}
	else
	{
		if(dest_spelayer == dest)
			gl=layer;
		else
			gl = Project.ActiveLayer();
		if(!gl.IsValid())
			XF_THROW(XFERR_INVALID_LAYER);
		gp = gl.GetPage();
	}
	///End SUPPORT_SPECIFY_PAGE_AND_LAYER
	
	bool bReconstruct = (update_reconstruct == update)? true:false;
	
	///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
	//if ( dest_layer == dest )
	if ( dest_layer == dest || dest_spelayer == dest )
	///End SUPPORT_SPECIFY_PAGE_AND_LAYER
	{
		/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
		//legend_update(gl, mode, true, bReconstruct, custom);
		legend_update(gl, mode, true, bReconstruct, custom, false, bAscending);
		/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	}
	else
	{
		/// Hong 07/24/07 v8.0666 SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		bool bCreate = true;
		bool bOneforAll = is_page_one_legend_for_all(gp);
		if ( bOneforAll )
			bCreate = false;
		/// end SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		foreach (gl in gp.Layers)
		{
			/// Hong 07/24/07 v8.0666 SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
			//legend_update(gl, mode, true, bReconstruct, custom);
			/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
			//legend_update(gl, mode, bCreate, bReconstruct, custom, bOneforAll);
			legend_update(gl, mode, bCreate, bReconstruct, custom, bOneforAll, bAscending);
			/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
			/// end SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		}
		/// Hong 07/24/07 v8.0666 MORE_RELIABLE
		/// Iris 07/26/2007 FIX_RECONSTRUCT_STILL_SHOW_YERR_IN_LEGEND
		//if ( bReconstruct )
		bool bCombine = (legend_combine == legend) ? true : false;
		if ( bReconstruct && bCombine)
		///end FIX_RECONSTRUCT_STILL_SHOW_YERR_IN_LEGEND
		{ // only reconstruct will enable legend
		/// end MORE_RELIABLE
			/// Iris 07/26/2007 FIX_RECONSTRUCT_STILL_SHOW_YERR_IN_LEGEND
			//bool bCombine = (legend_combine == legend) ? true : false;
			///end FIX_RECONSTRUCT_STILL_SHOW_YERR_IN_LEGEND
			
			/// Hong 08/08/07 QA80-10064 FIX_LEGEND_COMBINE_FAIL_KEEP_ORIGIN_ORDER
			//legend_update_text_property(gp, bCombine);
			legend_combine(gp, 0, bAscending);
			/// end FIX_LEGEND_COMBINE_FAIL_KEEP_ORIGIN_ORDER
			
			/// Iris 07/25/2007 SHOULD_CHANGE_LEGEND_POSITION_IN_THIS_XF
			/*
			if ( !bCombine )
			{
				foreach (gl in gp.Layers)
				{
					GraphObject goLegend = gl.GraphObjects(GO_LEGEND_NAME);	
					if(goLegend)
					{
						legend_position(goLegend, true, LEGEND_POS_RIGHT);
						legend_position(goLegend, false, LEGEND_POS_TOP);
					}
				}
			}
			*/
			///end SHOULD_CHANGE_LEGEND_POSITION_IN_THIS_XF
		}
	}	
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE		
	///end UPDATE_CODES_BY_USING_NEW_FUNCTION
}
/// end ADD_APPLY_BTN

void legendupdate(const int& dest, const int& update, const int& legend, const int& order, const int& mode, const string& custom, const GraphPage& page, const GraphLayer& layer)
{
	/// Hong 07/24/07 v8.0666 ADD_APPLY_BTN
	/*
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
	GraphLayer gl = Project.ActiveLayer();
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
	if(!gl.IsValid())
		XF_THROW(XFERR_INVALID_LAYER);
	
	///Jake 07/20/07 UPDATE_CODES_BY_USING_NEW_FUNCTION
	*/	/*	
	GraphObject	goLegend = gl.GraphObjects(GO_LEGEND_NAME);
	if(!goLegend.IsValid())
	{
		legend_update(gl,mode,true);
		return;
	}
	
	
	int nPlotsCount = gl.DataPlots.Count();
	int nLegendCount = _get_legend_count(gl);
		
	//string strLegendFormat =(mode_custom == mode)? custom : s_vsLegendFormat[mode];
	string strLegendFormat;
	if(mode_custom == mode)
		strLegendFormat = custom ;
	else
		strLegendFormat = s_vsLegendFormat[mode];
		
	if(strLegendFormat.IsEmpty())
		XF_THROW(XFERR_INVALID_EXTRA_FORMAT);
	
	if(apply_allplots == apply)//need to update all legend text
	{	
		goLegend.Text.Empty();
		for(int ii = 0; ii < nPlotsCount; ii++)
		{
			legend_append_plot(gl,ii,strLegendFormat);
		}
		return; /// Iris 07/19/2007 SHOULD_DIRECTLY_RETURN_IF_RECONSTRUCT_ALL_LEGENDS
	}
	
	if(nPlotsCount > nLegendCount)//need append legend
	{
		for(int ii = nLegendCount; ii < nPlotsCount; ii++)
		{
			legend_append_plot(gl,ii,strLegendFormat);
		}
	}
	else if(nPlotsCount <  nLegendCount)//need detele legend
	{
		for(int ii = nLegendCount - 1; ii > nPlotsCount - 1; ii--)
		{
			legend_delete_plot(gl,ii);
		}
	}
	*/	
	/*	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE	
	//int nMode = (0 == setmode)? -1 : mode;
	//bool bReconstruct = (legend == legend_reconstruct)? true:false;
	//legend_update(gl, mode, true, bReconstruct, custom);	
	GraphPage gp = gl.GetPage();
	
	bool bReconstruct = (update_reconstruct == update)? true:false;
	
	if ( dest_layer == dest )
	{
		legend_update(gl, mode, true, bReconstruct, custom);
	}
	else
	{
		/// Hong 07/24/07 v8.0666 SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		bool bCreate = true;
		bool bOneforAll = is_page_one_legend_for_all(gp);
		if ( bOneforAll )
			bCreate = false;
		/// end SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		foreach (gl in gp.Layers)
		{
			/// Hong 07/24/07 v8.0666 SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
			//legend_update(gl, mode, true, bReconstruct, custom);
			legend_update(gl, mode, bCreate, bReconstruct, custom, bOneforAll);
			/// end SUPPORT_UPDATE_ONE_FOR_ALL_LEGEND
		}
		/// Hong 07/24/07 v8.0666 MORE_RELIABLE
		if ( bReconstruct )
		{ // only reconstruct will enable legend
		/// end MORE_RELIABLE
			bool bCombine = (legend_combine == legend) ? true : false;
			
			legend_update_text_property(gp, bCombine);
			
			if ( !bCombine )
			{
				foreach (gl in gp.Layers)
				{
					GraphObject goLegend = gl.GraphObjects(GO_LEGEND_NAME);	
					if(goLegend)
					{
						legend_position(goLegend, true, LEGEND_POS_LEFT);
						legend_position(goLegend, false, LEGEND_POS_TOP);
					}
				}
			}
		}
	}	
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE		
	///end UPDATE_CODES_BY_USING_NEW_FUNCTION
	*/
	///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
	/*
	/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	//_legend_update(dest, update, legend, mode, custom);
	
	_legend_update(dest, update, legend, mode, custom, order);
	/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	*/
	_legend_update(dest, update, legend, mode, custom, order, page, layer);
	///End SUPPORT_SPECIFY_PAGE_AND_LAYER
	/// end ADD_APPLY_BTN	
}

//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 legendupdate_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return legendupdate_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
	string strCombo;
	if( trGetN.dest && trGetN.dest.GetAttribute(STR_COMBO_ATTRIB, strCombo) )
	{
		string str1 = strCombo.GetToken(dest_page,'|');
		string str2 = strCombo.GetToken(dest_layer,'|');		
		string strComboNew = str1 + "|" + str2;
		trGetN.dest.SetAttribute(STR_COMBO_ATTRIB, strComboNew);	
	}
	///End SUPPORT_SPECIFY_PAGE_AND_LAYER
	
	GraphLayer gl;	
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
	//okxf_resolve_string_get_origin_object(trGetN.gl.strVal, &gl);
	gl = Project.ActiveLayer();
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
	if(!gl.IsValid())
	{
		strErrMsg = XFERR_INVALID_LAYER;
		bOKEnable = false;	
		return false;
	}	
		
	string	strCustomFormat;
	int 	nRet = xf_is_theme_applied(trGetN);
	///---Sim 09-05-2008 CLEAN_DEFAULT_THEME
	//bool 	bRet = ( nEventID == GETNE_ON_THEME && (THEME_NONE == nRet || THEME_FACTORY_DEFAULT == nRet)|| nEventID == GETNE_ON_INIT);
	bool 	bRet = ( nEventID == GETNE_ON_THEME && (THEME_NONE == nRet) || nEventID == GETNE_ON_INIT);
	///---END CLEAN_DEFAULT_THEME
	if(bRet)
	{
		GraphPage gp = gl.GetPage();
		
		/// Iris 07/31/2007 v8.0671 ADDED_UTILITY_FUNC_TO_GET_SET_LEGEND_MODE
		/*
		Tree tr;
		tr = gp.GetFormat(FPB_OTHER, FOB_OTHER, true, true);
		
		if( tr.Root.Legends.Type )
			trGetN.mode.nVal = tr.Root.Legends.Type.nVal;
		else
			error_report("fail to get Legends.Type node");	
			
		if(tr.Root.Legends.CustomFormat)
			strCustomFormat = tr.Root.Legends.CustomFormat.strVal;
		*/		
		string strCustomFormat;
		trGetN.mode.nVal = get_page_legend_mode(gp, strCustomFormat);
		///end ADDED_UTILITY_FUNC_TO_GET_SET_LEGEND_MODE
		
		/// Hong 07/24/07 v8.0666 MORE_RELIABLE
		if ( 1 == gp.Layers.Count() )
		{
			trGetN.dest.nVal = dest_page;
			trGetN.dest.Show = false;
		}
		/// end MORE_RELIABLE
	}
	
	trGetN.custom.Show = (trGetN.mode.nVal == mode_custom)? true : false;
	if ( GETNE_ON_INIT == nEventID )
	{
		trGetN.custom.strVal = strCustomFormat;
	}
	
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
	//trGetN.mode.Enable = trGetN.custom.Enable = trGetN.setmode.nVal; 
	if ( GETNE_ON_INIT == nEventID || GETNE_ON_THEME == nEventID )
	{
		_update_getn_by_dest(trGetN); 
	}
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
	
	/// Hong 07/24/07 v8.0666 ADD_APPLY_BTN
	if ( GETNE_ON_APPLY == nEventID )
	{		
		/// Hong QA80-10064 v8.0672 LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
		//_legend_update(trGetN.dest.nVal, trGetN.update.nVal, trGetN.legend.nVal, trGetN.mode.nVal, trGetN.custom.strVal);
		_legend_update(trGetN.dest.nVal, trGetN.update.nVal, trGetN.legend.nVal, trGetN.mode.nVal, trGetN.custom.strVal, trGetN.order.nVal);
		/// end LEGEND_ADD_ORDER_OPTION_WHEN_RECONSTRUCT
	}
	/// end ADD_APPLY_BTN
	
	/// Iris 07/27/2007 IMPROVE_CUSTOM_FORMAT_EDITABLE_COMBO
	// this check below is not right since we might support other custom format string later. 
	/*
	if(0 == lstrcmp(lpcszNodeName, "custom"))
	{
		
		if(s_vsCustomLegendFormat.Find(trGetN.custom.strVal) == -1 || trGetN.custom.strVal.IsEmpty())
		{
			bOKEnable = false;
			strErrMsg = XFERR_INVALID_EXTRA_FORMAT;
		}
	}
	*/
	///end IMPROVE_CUSTOM_FORMAT_EDITABLE_COMBO
	
	/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
	if( 0 == lstrcmp(lpcszNodeName, "dest") )
	{
		_update_getn_by_dest(trGetN);
	}
	/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
	
	/// Hong 07/24/07 v8.0666 MORE_RELIABLE
	if( 0 == lstrcmp(lpcszNodeName, "update") )
	{
		_update_getn_by_update(trGetN);
	}
	/// end MORE_RELIABLE
		
	return true;

}

int legendupdate_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 legendupdate_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	///Army 07/06/2009 v8.1052 QA80-13651 SUPPORT_SPECIFY_PAGE_AND_LAYER
	if(0 == nGetNDialog)
	{
		GraphLayer gl2;
		GraphPage  gp2;
		if(dest_spelayer == trGetN.dest.nVal)
		{
			okxf_resolve_string_get_origin_object(trGetN.layer.strVal, &gl2);
			if(!gl2.IsValid())
			{
				warning_msg_box(XFERR_INVALID_GRAPH_LAYER, false);
				nRet = XFEVT_ABORT;
			}
		}
		if(dest_spepage == trGetN.dest.nVal)
		{
			okxf_resolve_string_get_origin_object(trGetN.page.strVal, &gp2);
			if(!gp2.IsValid())
			{
				warning_msg_box(CER_INVALID_PAGE, false);
				nRet = XFEVT_ABORT;
			}
		}	
	}
	///End SUPPORT_SPECIFY_PAGE_AND_LAYER
	if(nGetNDialog > 0)
	{
		GraphLayer gl;
		/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE
		//okxf_resolve_string_get_origin_object(trGetN.gl.strVal, &gl);
		gl = Project.ActiveLayer();
		/// end MORE_OPTIONS_FOR_LEGEND_UPDATE
		if(!gl.IsValid())
			XF_THROW(XFERR_INVALID_LAYER);
		
		/// Hong 07/23/07 QA80-10064 MORE_OPTIONS_FOR_LEGEND_UPDATE				
		_update_getn_by_dest(trGetN);
		/// end MORE_OPTIONS_FOR_LEGEND_UPDATE		
	    /*
		// get default legend mode to init "mode" and "custom" control
		int nLegendCount = _get_legend_count(gl);
		string strTypeFormat = legend_get_extra_format(gl, nLegendCount-1);
		
		if(!strTypeFormat.IsEmpty())
		{
			int nIndex = s_vsLegendFormat.Find(strTypeFormat);
			if(nIndex == -1)// is Custom type
			{
				trGetN.mode.nVal = mode_custom;
				trGetN.custom.strVal = strTypeFormat;
			}
			else
				trGetN.mode.nVal = nIndex;
		}
		/// Iris 07/19/2007 INIT_MODE_VAL_FROM_PAGE_SETTINGS
		else //if not specify mode for each legend, then need to read legend mode from Page Details dialog
		{
			
			Tree tr;
			tr = gl.GetPage().GetFormat(FPB_OTHER, FOB_OTHER, true, true);
			
			if( tr.Root.Legends.Type )
				trGetN.mode.nVal = tr.Root.Legends.Type.nVal;			
			else
				error_report("fail to get Legends.Type node");
		}
		//end INIT_MODE_VAL_FROM_PAGE_SETTINGS
		*/
		
		//trGetN.custom.Show = (trGetN.mode.nVal == mode_custom)? true:false;
	}
}
//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 legendupdate_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
