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

//put additional include files here

/*	Joseph 11/06/06	 SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC        */
//put your own support static functions here
///Joseph 11/06/06	 SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
//FUNC_CREATE_XFS fnOne=Project.FindFunction("create_doc", "originlab\\xfdocument.c", true, true, true);
//FUNC_CREATE_XFS fnAll=Project.FindFunction("create_all_xf_docs", "originlab\\xfdocument.c", true, true, true);
typedef bool (* FUNC_CREATE_XFS)(const string& strXFName, const string& category, const int& nlanguage, const string& strFolder, bool bCHMDoc);
typedef bool (* FUNC_CREATE_ALL_XFS)(const string& strXFName, const int& nlanguage, const string& strFolder, bool bCHMDoc);

//void xf2doc(const string& xfname, const string& category, const int& language, const string& path, const int& chm, const int& allxf)

void xf2doc(const string& xfname, const string& category, const int& language, const string& path, const int& chm, const int& allxf)
{
	///End	SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
	//code begin
	FUNC_CREATE_XFS fnOne=Project.FindFunction("create_doc", "originlab\\xfdocument.c", true, true, true);
	///Joseph 11/06/06	 SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
	//FUNC_CREATE_XFS fnAll=Project.FindFunction("create_all_xf_docs", "originlab\\xfdocument.c", true, true, true);
	FUNC_CREATE_ALL_XFS fnAll=Project.FindFunction("create_all_xf_docs", "originlab\\xfdocument.c", true, true, true);
	///End SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
	// Bring up hour glass
	waitCursor wCur;
	
	///Cheney 2007-6-18 UPDATE_XF_ERR_THROW
	//string strFailPrompts("Fail during call create function");
	///end UPDATE_XF_ERR_THROW
	//if(xfname.IsEmpty() || "<optional>"==xfname || "<>"==xfname)	//create all x-function document
	if(1 == allxf)
	{
		if(!fnAll || !fnAll(xfname, language, path, chm))
		{
			///Cheney 2007-6-18 UPDATE_XF_ERR_THROW
			//out_str(strFailPrompts);
			warning_msg_box(XFERR_FAIL_DURING_CALL_CREATE_FUNC, false, 'E');
			///end UPDATE_XF_ERR_THROW
			return;
		}
	}
	else	//create a xf document
	{
		///Joseph 11/06/06	 SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
		//if(!fnOne || !fnOne(xfname, language, path, chm))
		if(!fnOne || !fnOne(xfname, category, language, path, chm))	
		///End SUPPORT_FOLDER_AND_MATCH_ON_CREATE_DOC
		{
			///Cheney 2007-6-18 UPDATE_XF_ERR_THROW
			//out_str(strFailPrompts);
			warning_msg_box(XFERR_FAIL_DURING_CALL_CREATE_FUNC, false, 'E');
			///end UPDATE_XF_ERR_THROW
			return;
		}
	}
	///end
}

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

}

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