// GatewaySettingsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "afxres.h"
#include "palmtool.h"
#include "UdpSocket.h"
#include "tcpsocket.h"
#include "GatewaySettingsDlg.h"

#include "..\\inc\\p_util.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGatewaySettingsDlg dialog


CGatewaySettingsDlg::CGatewaySettingsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGatewaySettingsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGatewaySettingsDlg)
	m_strDualModePrefix = _T("");
	//}}AFX_DATA_INIT
}


void CGatewaySettingsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGatewaySettingsDlg)
	DDX_Control(pDX, IDC_DUALMODE, m_ctlDualMode);
	DDX_Text(pDX, IDC_DUALMODEPREFIX, m_strDualModePrefix);
	DDV_MaxChars(pDX, m_strDualModePrefix, 2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGatewaySettingsDlg, CDialog)
	//{{AFX_MSG_MAP(CGatewaySettingsDlg)
	ON_CBN_SELCHANGE(IDC_DUALMODE, OnSelchangeDualmode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGatewaySettingsDlg message handlers

BOOL CGatewaySettingsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	int i;
	CString strText;

	GetDlgItemText(IDOK, strText);

	if( !strcmp(strText, "È·  ¶¨"))
	{
		for(i = 0; i < DUAL_MODE_MAX; i++)
			m_ctlDualMode.AddString((char *)(g_cDualModeDisplay_GB[0] + i * DUALMODE_DISPLAY_LEN));
	}
	else if (!strcmp(strText, "OK"))
	{
		for(i = 0; i < DUAL_MODE_MAX; i++)
			m_ctlDualMode.AddString((char *)(g_cDualModeDisplay[0] + i * DUALMODE_DISPLAY_LEN));
	}

	/* 0x00015f:		   Dual mode, 0 to disable, 1 pstn first, 2 ip first */ 
    m_ctlDualMode.SetCurSel(AfxGetApp()->GetProfileInt(_T("PhoneSettings"), _T("DualMode"), 0));

	/* 0x000069--0x00006a: to access local outer line */ 
	m_strDualModePrefix = AfxGetApp()->GetProfileString(_T("PhoneSettings"), _T("DualModePrefix"), _T("0"));

	OnSelchangeDualmode();

	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGatewaySettingsDlg::OnOK() 
{
	UpdateData();

	/* 0x00015f:		   Dual mode, 0 to disable, 1 pstn first, 2 ip first */ 
	AfxGetApp()->WriteProfileInt(_T("PhoneSettings"), _T("DualMode"), m_ctlDualMode.GetCurSel());
	
	/* 0x000069--0x00006a: to access local outer line */ 
	AfxGetApp()->WriteProfileString(_T("PhoneSettings"), _T("DualModePrefix"), m_strDualModePrefix);

	CDialog::OnOK();
}

void CGatewaySettingsDlg::OnSelchangeDualmode() 
{
	BOOL m_bDualMode;

	if((m_ctlDualMode.GetCurSel()) != 0)
		m_bDualMode = TRUE;
	else
		m_bDualMode = FALSE;

//	UpdateData();
	GetDlgItem(IDC_DUALMODEPREFIX)->EnableWindow(m_bDualMode);
}
