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

//put your own support static functions here

///Folger 05/08/07 LANGUAGE_SETTING
//void language(const string& next, string& current)
//{
	//next.MakeUpper();
	//char szCurr[2]={0, '\0'};//=the language the Origin gui is currently using. It is determined at startup registry setting, or by regional settings.
	//char szNext[2]={0, '\0'};
	//char szValidLanguages[4];//MAX_NUM_LANGS_SUPPORTED
	//BOOL bIsNextSupported = TRUE;
	//if( !okutil_is_language_supported(next, szValidLanguages, FALSE) )
	//{
		//printf(_L("Language %s is not supported by this installation."), next);
		//printf("\n");
		//printf(_L("This installation supports language(s) %s"), szValidLanguages);
		//printf("\n");
		//
		//bIsNextSupported = FALSE;
	//}
	////-- get current language
	//okutil_set_resource_lang(NULL, szCurr, NULL);
	//if(bIsNextSupported)
		//szNext[0] = next[0];
	//else
		//szNext[0] = szCurr[0];
	//
	////-- set registry
	//okutil_set_resource_lang(szNext, NULL, NULL);
	//
	//// set output
	//current = szCurr;
		//
	//printf(_L("Current language is %s. "), szCurr);
	//printf("\n");
	//printf(_L("Language will be %c at next startup."), szNext[0]);
	//printf("\n");
	//
//}

void language(const string& info, const int& sw, const int& allusers, const string& info2)
{
	char lang[5];
	okutil_is_language_supported("E", lang, false);
	string strText = lang[sw];
	///DSC 8/22/08 QA70-12080 CHANGE_LANGUAGE_FOR_ALL_USERS
	// User may have set language originally for current user, then later wants to apply change to all users. 
	// Checking the box will call okutil_set_resource_lang again even if strText[0] == okutil_get_current_lang() already
	// if (strText[0] != okutil_get_current_lang())
	if (strText[0] != okutil_get_current_lang() || 0!=allusers)
	{
		///DSC 8/22/08 QA70-12080 CHANGE_LANGUAGE_FOR_ALL_USERS
		BOOL bAllUsers = allusers;
		if(!is_running_as_administrator(TRUE))
			bAllUsers = 0;
	
		okutil_set_resource_lang(strText, NULL, NULL, &bAllUsers);
		///end CHANGE_LANGUAGE_FOR_ALL_USERS
		///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		//warning_msg_box(_L("Restart Origin to view the language change."), true);
		//------ Folger 11/22/07 SHOW_WARNING_MESSAGE_WHEN_CURRENT_UNICODE_SETTING_NOT_SUPPORT_SELECTED_LANGUAGE
		BOOL bCheck = false;
		get_ACP(&strText[0], &bCheck);
		warning_msg_box(bCheck ? XFWARN_LAN_RESTART_TO_VIEW_CHANGE : XFWARN_LAN_REGION_SETTING, true);
		//------
		///end UPDATE_XF_ERR_THROW
	}
	///End LANGUAGE_SETTING
}

//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 language_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return language_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	
	///Folger 05/08/07 LANGUAGE_SETTING
	if (nEventID == GETNE_ON_INIT)
	{
		///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		//trGetN.info.strVal = _L("* Make sure your operation system supports other languages.");
		string strMsg;
		ocu_load_msg_str(XF_LANGUAGE_SUPPORT_OTHERS, &strMsg);
		trGetN.info.strVal = strMsg;
		///end Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		trGetN.info.SetAttribute(STR_LABEL_ATTRIB, "");
		trGetN.info.Enable = 2;
	
		char lang[5];
		okutil_is_language_supported("E", lang, false);
		char chCur = okutil_get_current_lang();
		int nSel;
		string strCombo;
		for (int ii=0; lang[ii]!=0; ii++)
		{
			switch (lang[ii])
				{
				case 'E':
					strCombo += "English|";
					break;
				case 'G':
					strCombo += "German|";
					break;
				case 'J':
					strCombo += "Japanese|";
					break;
				case 'C':
					strCombo += "Chinese|";
					break;
				default:
					break;
				}
			if (lang[ii] == chCur)
			{
				nSel = ii;
			}
		}
		trGetN.sw.SetAttribute(STR_ID_ATTRIB, TRGP_ENUM_LIST);
		trGetN.sw.SetAttribute(STR_COMBO_ATTRIB, strCombo);
		trGetN.sw.nVal = nSel;
	}
	///End LANGUAGE_SETTING
	return false;

}

int language_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 language_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	
	if(nGetNDialog > 0)
	{
		if(!is_running_as_administrator(TRUE))
		{
			trGetN.allusers.Show = 0;
			trGetN.info2.Show = 0;
		}
	}
	
	
}
//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 language_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
