#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here

/*------------------------------------------------------------------------------*
 * Modification Log:															*
 * Iris 10/21/2010 ORG-1303 CLEANUP_XFS_ERROR_CODE								*
 */
 
//put your own support static functions here

#define CDSET_INI_SECTION "cdset"


void cdset(const int& index)
{
	// if nIndex>0, set index to current working directory, else display all settings	
	//string strXCD; 
	
	///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
	string strMsg;  
	string strCWD;
	ocu_load_msg_str(XF_SYSTEM_CURRENT_WORKING_FOLDER, &strCWD);
	///end UPDATE_XF_ERR_THROW
	
	string strIndex;
	strIndex.Format("%d", index);
	INIFile ini;
	
	if(index>0)
	{
		string strWorking = okutil_get_custom_path();
		if( strWorking.IsPath() )
		{
			ini.WriteString(CDSET_INI_SECTION, strIndex, strWorking);
			///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
			//printf("%d=%s\nhas been set.\n",index, strWorking);
			int nIndex = index;
			ocu_load_msg_str(XF_CDSET_HAS_BEEN_SET, &strMsg, strWorking, &nIndex);
			/// Iris 10/21/2010 ORG-1303 CLEANUP_XFS_ERROR_CODE
			//warning_msg_box(strMsg, false, 'E');
			warning_msg_box(strMsg, false, 'R');
			///End CLEANUP_XFS_ERROR_CODE
			///end UPDATE_XF_ERR_THROW
		}
		else
			///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
			//printf("%s is not defined, so cannot be set.\n", STR_C_W_D);
			/// Iris 10/21/2010 ORG-1303 CLEANUP_XFS_ERROR_CODE
			//warning_msg_box(XF_CDSET_NOT_DEFINE_CAN_NOT_SET, strCWD, false, 'E');
			XF_THROW_EX(XF_CDSET_NOT_DEFINE_CAN_NOT_SET, strCWD);
			///End CLEANUP_XFS_ERROR_CODE
			///end UPDATE_XF_ERR_THROW
	}	
	else if(index==0)
	{
		//get all keys
		StringArray saKeys;
		ini.GetKeyNames(saKeys, CDSET_INI_SECTION);
		for( int iKey = 0; iKey < saKeys.GetSize(); iKey++ )
		{
		  	string str = ini.ReadString(CDSET_INI_SECTION, saKeys[iKey]);
	        string strResolved;
	        okutil_resolve_str_expression(str , &strResolved);
	        ///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
	 		//printf("    %s = %s\n", saKeys[iKey], strResolved);
	 		strMsg.Format("    %s = %s", saKeys[iKey], strResolved);
	 		warning_msg_box(strMsg, false, 'R');
	 		///end UPDATE_XF_ERR_THROW
		}
	}
}

//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 cdset_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return cdset_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int cdset_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 cdset_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//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 cdset_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
