/*------------------------------------------------------------------------------*
 * File Name: XFWizard_utils.h													*
 * Creation: Sim 03-20-2007														*
 * Purpose: Origin C Header Files												*
 * Copyright (c) ABCD Corp.	2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010		*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 *	Sim 01-07-2008 QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE							*
 *	Sim 01-13-2009 XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE				*
 *	Sim 01-07-2009 QA81-14898 SHOW_GUI_SETTINGS_FOR_XFWIZ_OPERATION				*
 *------------------------------------------------------------------------------*/

#ifndef _XF_WIZ_UTILS_H
#define _XF_WIZ_UTILS_H

#include <..\OriginLab\XFWiz.h> ///---Sim 01-13-2009 XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE
#include <..\OriginLab\XFCore.h>

///Jasmine 11/05/08 THIS_UTIL_FUNC_CAN_USE_IN_OTHER_XFWIZ_LIKE_NANOSIZER
///Sandy 2008-9-9 ADD_UTIL_FUNC_TO_CONSTRUCT_IT_TREE_FOR_AVOID_FILE_AUTO_LOAD_TO_MUCH_IN_PA_OXF
///---Sim 01-13-2009 XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE
//bool	construct_tree_for_input_range_of_xf(TreeNode& trIO,  const string strXF, const DataRange& dr);
bool	xfwiz_construct_input_range(XFWizInputOutputRange *pXFWizIO, LPCSTR lpcszXFName, const DataRange& dr);
///---END XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE


///End THIS_UTIL_FUNC_CAN_USE_IN_OTHER_XFWIZ_LIKE_NANOSIZER

//int		run_wiz_nodlg(XFCore* pxfc, Page &pgSource, Tree &trTheme = NULL, TreeNode &trInputsOutputs = NULL, DWORD dwUIDOp = 0);
//int		open_wiz_dlg(XFCore* pxfc, Page &pgSource, Tree &trTheme = NULL, TreeNode &trInputsOutputs = NULL, DWORD dwUIDOp = 0);

#define NODE_NAME_XF_WIZ_CORE_POINTER nXFCorePointer ///---Sim 01-07-2008 QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE
#define STR_ATTRIB_XF_WIZ_CORE_POINTER "XFCorePointer"
void	set_xf_core_handler(TreeNode &trGetN, XFCore* pxfc);
XFCore*	get_xf_core_handler(const TreeNode &trGetN);
///---Sim 01-07-2008 QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE
XFCore*	get_xf_core_handler(int nPointer);
///---END QA80-12833 FIX_APPLY_XF_WIZ_XF_TWICE

XFCore*	get_current_xf_core_handler();

///---Sim 01-13-2009 XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE
// int template<TClass>(LPCSTR lpcszThemeName, const XFWizTheme *pXFWizTheme, const XFWizInputOutputRange *pXFWizIO, DWORD dwOPUID)
#define TEMPLATE_run_wiz_nodlg(TEMPLATE_CLASS_WIZ_MANAGER, lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID) \
{ \
	TEMPLATE_CLASS_WIZ_MANAGER objWizManager(lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID); \
	XFWizScript xfwizSpt(objWizManager); \
	if ( !xfwizSpt.Run() ) \
		return -1; \
	return 0; \
}

// int template<TClass>(LPCSTR lpcszThemeName, const XFWizTheme *pXFWizTheme, const XFWizInputOutputRange *pXFWizIO, DWORD dwOPUID)
#define TEMPLATE_open_wiz_dlg(TEMPLATE_CLASS_WIZ_MANAGER, lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID) \
{ \
	LPCSTR lpcszUsedThemeName = lpcszThemeName; \
	if ( lpcszUsedThemeName ) \
	{ \
		/* dialog mode default use <default> theme if existing */ \
		if ( theme_is_factory_default(lpcszUsedThemeName) ) \
			lpcszUsedThemeName = STR_DEFAULT; \
	} \
	\
	TEMPLATE_CLASS_WIZ_MANAGER *pWizManager = new TEMPLATE_CLASS_WIZ_MANAGER(lpcszUsedThemeName, pXFWizTheme, pXFWizIO, dwOPUID); \
	if ( NULL == pWizManager ) \
		return -1; \
	\
	XFWizDlg *pXFWizDlg = new XFWizDlg(pWizManager); /* modeless dialog hold this pointer */ \
	if ( NULL == pXFWizDlg ) \
		return -1; \
	\
	HWND hWndParent = GetWindow(); \
	if ( 0 == dwOPUID ) \
	{ \
		if ( pXFWizDlg->Create(hWndParent) ) \
		{ \
			/*---Sim 12-12-2008 QA80-12764-P3 PA_MODAL_DIALOG_ALSO_FORCE_SET_SHOW_FLAG_AS_ON_PAGE_CHANGE_EVENT_NEED_IT*/ \
			/* Dialog OnReady will always show dialog */ \
			/*pXFWizDlg->Show(true);*/ \
			/*---END QA80-12764-P3 PA_MODAL_DIALOG_ALSO_FORCE_SET_SHOW_FLAG_AS_ON_PAGE_CHANGE_EVENT_NEED_IT*/ \
		} \
		/* Dialog OnDestroy event will release pXFWizDlg; */ \
	} \
	else /* change param must open model dialog, QA80-12741*/ \
	{ \
		int nRet = pXFWizDlg->DoModal(hWndParent); \
		delete pXFWizDlg; /*---Sim 12-09-2008 QA80-12741 OPERATION_UNPROTECT_IO_RANGE_IN_EXEC_TIME_OF_CHANGE_PARAM_FUNC*/ \
		if ( IDCANCEL == nRet ) /* For fix when click cancel on change parameter dialog due to refresh padlock icon */ \
			return -1; \
	} \
	\
	return 0; \
}

///---Sim 01-07-2009 QA81-14898 SHOW_GUI_SETTINGS_FOR_XFWIZ_OPERATION*/
// int template<TClass>(LPCSTR lpcszThemeName, const XFWizTheme *pXFWizTheme, const XFWizInputOutputRange *pXFWizIO, DWORD dwOPUID)
#define TEMPLATE_show_wiz_dlg_gui(TEMPLATE_CLASS_WIZ_MANAGER, lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID) \
{ \
	TEMPLATE_CLASS_WIZ_MANAGER objWizManager(lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID); \
	XFWizShowGUI xfwizShowGUI(objWizManager); \
	if ( !xfwizShowGUI.Show() ) \
		return -1; \
	return 0; \
}
///---END QA81-14898 SHOW_GUI_SETTINGS_FOR_XFWIZ_OPERATION*/

// int template<TClass>(UINT msg, const XFWizTheme *pXFWizTheme, const XFWizInputOutputRange *pXFWizIO, DWORD dwOPUID, int nExeMode)
#define TEMPLATE_run_wiz(TEMPLATE_CLASS_WIZ_MANAGER, msg, pXFWizTheme, pXFWizIO, dwOPUID, nExeMode) \
{ \
	switch ( msg ) \
	{ \
	case WIZOPH_EXECUTE: \
		TEMPLATE_run_wiz_nodlg(TEMPLATE_CLASS_WIZ_MANAGER, NULL, pXFWizTheme, pXFWizIO, dwOPUID); \
	\
	case WIZOPH_DO_CHANGE_PARAMS_WIZDLG: \
		TEMPLATE_open_wiz_dlg(TEMPLATE_CLASS_WIZ_MANAGER, NULL, pXFWizTheme, pXFWizIO, dwOPUID); \
	/*///---Sim 01-07-2009 QA81-14898 SHOW_GUI_SETTINGS_FOR_XFWIZ_OPERATION*/ \
	case WIZOPH_SHOW_WIZDLG_GUI: \
		TEMPLATE_show_wiz_dlg_gui(TEMPLATE_CLASS_WIZ_MANAGER, NULL, pXFWizTheme, pXFWizIO, dwOPUID); \
	/*///---END QA81-14898 SHOW_GUI_SETTINGS_FOR_XFWIZ_OPERATION*/ \
	} \
	\
	return -1; \
}
///---END XFWIZ_CHANGE_PARAM_MAY_CHANGE_THEME_AND_IO_RANGE

#endif // _XF_WIZ_UTILS_H
