/*------------------------------------------------------------------------------*
 * File Name: ImpWizUserDefined.c												*
 * Creation: 																	*
 * Purpose: Origin C file containing Application Utilities						*
 * Copyright (c) OriginLab Corp.	2002-2007									*
 * All Rights Reserved															*
 * 																				*
 * Modification Log:															*
 * EJP 2005-08-22 v8.0292 QA70-7996 IMPWIZ_SUPPORT_XFUNC						*
 * EJP 2007-02-26 v8.0571 REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ					*
 *------------------------------------------------------------------------------*/
 

#include <Origin.h>

/// EJP 2005-08-29 v8.0296 QA70-7996 IMPWIZ_SUPPORT_XFUNC
#include <iw_xf.h>
/// end IMPWIZ_SUPPORT_XFUNC

#include "IWfirst.h"


///Danice 12/25/03 v7.5788 NOTUSE_SHOW
DWORD ImpWizUserDefinedPage::OnShowStatus(DWORD InternalStatus)
{
	return (IS_FILTER_TYPE_USERDEFINED ? PSS_Show : PSS_Ignore);
}
///END NOTUSE_SHOW

BOOL ImpWizUserDefinedPage::OnInit_UserDefined()			///Jason 12/12/03 v7.5780 CHANGE_SOME_FUNCTION_NAME
{
	ON_PAGE_CHECK_USER_DEFINED
	
	///Danice PAGE_INIT_ONCE
	if(!ImpWizardPage::Init())
		return FALSE;
	///END PAGE_INIT_ONCE

	///Jason 12/12/03 v7.5780 MOVED_INIT_FUNCTION	
	m_editPath = GetItem(IDC_USER_DEF_FOLDER_PATH);
	m_editFunc = GetItem(IDC_USER_DEFINED_FUNCTION);
	///End MOVED_INIT_FUNCTION

	/// EJP 2007-02-26 v8.0571 REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
	///// EJP 08-13-2004 v8.0117 QA70-6472 IMPORT_INFO_STORAGE_CLEANUP
	//m_ebClass = GetItem(IDC_USER_DEFINED_CLASS);
	///// end IMPORT_INFO_STORAGE_CLEANUP
	///// end REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
	
	return TRUE;
}

BOOL ImpWizUserDefinedPage::OnActive_UserDefined()			///Jason 12/12/03 v7.5780 CHANGE_SOME_FUNCTION_NAME
{
	ON_PAGE_CHECK_USER_DEFINED
	return UserDefined_Update();
}

BOOL ImpWizUserDefinedPage::OnKillActive_UserDefined()		///Jason 12/12/03 v7.5780 CHANGE_SOME_FUNCTION_NAME
{
	ON_PAGE_CHECK_USER_DEFINED
	return UserDefined_Update(FALSE);
}

BOOL ImpWizUserDefinedPage::OnClickBrowse_UserDefined(Control ctrl)	///Jason 12/12/03 v7.5780 CHANGE_SOME_FUNCTION_NAME
{
	string strPath = GetOpenBox("[Origin C (*.c;*.cpp)] *.c;*.cpp");
	if( !strPath.IsEmpty() )
	{
		///Jason 12/12/03 v7.5780 MOVE_TO_INIT_USERDEFINED	
		//Edit editPath = ImportWizDlg.GetItem(IDC_USER_DEF_FOLDER_PATH, IDD_IW_USER_DEFINED);
		///End MOVE_TO_INIT_USERDEFINED
		m_editPath.Text = strPath;
	}
	return TRUE;
}

/// EJP 2007-02-26 v8.0571 REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
///// EJP 08-13-2004 v8.0117 QA70-6472 IMPORT_INFO_STORAGE_CLEANUP
//BOOL ImpWizUserDefinedPage::OnClickUseClass(Control ctrl)
//{
	//UpdateEditEnable();
	//return TRUE;
//}
//
//BOOL ImpWizUserDefinedPage::OnClickUseFunc(Control ctrl)
//{
	//UpdateEditEnable();
	//return TRUE;
//}
//
//void ImpWizUserDefinedPage::UpdateEditEnable()
//{
	//int nUse = GetCheckedRadioButton(IDC_USE_OC_CLASS, IDC_USE_OC_FUNC);
	//m_ebClass.Enable = (IDC_USE_OC_CLASS == nUse);
	//m_editFunc.Enable = (IDC_USE_OC_FUNC == nUse);
//}
///// end IMPORT_INFO_STORAGE_CLEANUP
/// end REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ

BOOL ImpWizUserDefinedPage::UserDefined_Update(BOOL bTreeToDlg) //=TRUE)	
{
	///Jason 12/12/03 v7.5780 MOVE_TO_INIT_USERDEFINED	
	//Edit editPath = ImportWizDlg.GetItem(IDC_USER_DEF_FOLDER_PATH, IDD_IW_USER_DEFINED);
	//Edit editFunc = ImportWizDlg.GetItem(IDC_USER_DEFINED_FUNCTION, IDD_IW_USER_DEFINED);

	///End MOVE_TO_INIT_USERDEFINED
	 
	if( bTreeToDlg )
	{
		/// EJP 2007-02-26 v8.0571 REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
		///// EJP 08-13-2004 v8.0117 QA70-6472 IMPORT_INFO_STORAGE_CLEANUP
		/////	string strOCFile, strOCFunction;
		/////	fuGetUserDefinedFunction(s_trFilter, strOCFile, strOCFunction);
		/////	m_editPath.Text = strOCFile;
		/////	m_editFunc.Text = strOCFunction;
		//string strOCFile, strOCFunction, strOCClass;

		/////---Sim 09-01-2006 GET_USER_DEFINE_FUNCTION_OR_CLASS
		//int nUse = IDC_USE_OC_CLASS;
		////if( !fuGetUserDefinedClass(s_trFilter, strOCFile, strOCClass) &&
		////	fuGetUserDefinedFunction(s_trFilter, strOCFile, strOCFunction) )
		//fuGetUserDefinedClass(s_trFilter, strOCFile, strOCClass);
		//fuGetUserDefinedFunction(s_trFilter, strOCFile, strOCFunction);
		//if( strOCClass.IsEmpty() && strOCFunction.IsEmpty() )
		//{
			//nUse = IDC_USE_OC_FUNC;
		//}
		/////---END GET_USER_DEFINE_FUNCTION_OR_CLASS
		///// Hong 01/17/07 FIX_PAGE_BACK_ERROR_CHECK_CLASS
		//if( strOCClass.IsEmpty() && !strOCFunction.IsEmpty() )
		//{
			//nUse = IDC_USE_OC_FUNC;
		//}
		///// end FIX_PAGE_BACK_ERROR_CHECK_CLASS
		//CheckRadioButton(IDC_USE_OC_CLASS, IDC_USE_OC_FUNC, nUse);
		//UpdateEditEnable();

		//m_editPath.Text = strOCFile;
		//m_ebClass.Text = strOCClass;
		//m_editFunc.Text = strOCFunction;
		///// end IMPORT_INFO_STORAGE_CLEANUP
		/// Hong 03/11/07 FIX_FAIL_INIT_BY_FILTER
		//fuGetUserDefinedFunction(s_trFilter, m_editPath.Text, m_editFunc.Text);
		string strPath, strFunc;
		fuGetUserDefinedFunction(s_trFilter, strPath, strFunc);
		m_editPath.Text = strPath;
		m_editFunc.Text = strFunc;
		/// end FIX_FAIL_INIT_BY_FILTER
		/// end REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
	}
	else // dialog to tree
	{
		/// EJP 2007-02-26 v8.0571 REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
		///// EJP 08-13-2004 v8.0117 QA70-6472 IMPORT_INFO_STORAGE_CLEANUP
		/////fuSetUserDefinedFunction(s_trFilter, m_editPath.Text, m_editFunc.Text);
		//int nUse = GetCheckedRadioButton(IDC_USE_OC_CLASS, IDC_USE_OC_FUNC);
		//if( IDC_USE_OC_CLASS == nUse )
		//{
			//fuSetUserDefinedClass(s_trFilter, m_editPath.Text, m_ebClass.Text);
		//}
		//else
		//{
			//fuSetUserDefinedFunction(s_trFilter, m_editPath.Text, m_editFunc.Text);
		//}
		///// end IMPORT_INFO_STORAGE_CLEANUP
		fuSetUserDefinedFunction(s_trFilter, m_editPath.Text, m_editFunc.Text);
		/// end REMOVE_OC_CLASS_SUPPORT_FROM_IMPWIZ
	}

	return TRUE;	
}

/// EJP 2005-08-22 v8.0292 QA70-7996 IMPWIZ_SUPPORT_XFUNC
DWORD ImpWizXFuncOptionsPage::OnShowStatus(DWORD InternalStatus)
{
#ifdef ENABLE_IMPWIZ_SUPPORT_XFUNC
	return (IS_FILTER_TYPE_XFUNC ? PSS_Show : PSS_Ignore);
#else // !ENABLE_IMPWIZ_SUPPORT_XFUNC
	return PSS_Ignore;
#endif // !ENABLE_IMPWIZ_SUPPORT_XFUNC
}

BOOL ImpWizXFuncOptionsPage::OnInit()
{
	if( IS_FILTER_TYPE_XFUNC )
		return TRUE;
	return FALSE;
}

BOOL ImpWizXFuncOptionsPage::OnActive()
{
#ifdef ENABLE_IMPWIZ_SUPPORT_XFUNC
	Window* pwnd = GetParentWndPtr();
	pwnd = pwnd->GetParentWndPtr();
	pwnd->ShowWindow(SW_HIDE);
	
	///Page pg; // how to pass NULL for Page&
	Layer ly;
	Tree tr; // how to pass NULL for TreeNode&
	int nRet; // X-Function return value
	CallImportWizardXFunction(ly, m_pSheet->GetFileName(), 0, m_pSheet->m_trFilter, tr, IWXF_EDIT_OPTIONS, nRet);
	if( nRet )
		m_pSheet->NextPage(TRUE);
	else
		m_pSheet->PrevPage(TRUE);

	pwnd->ShowWindow(SW_NORMAL);
#endif // !ENABLE_IMPWIZ_SUPPORT_XFUNC
	return TRUE;
}

BOOL ImpWizXFuncOptionsPage::OnKillActive()
{
	return TRUE;
}
/// end IMPWIZ_SUPPORT_XFUNC
