1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // LocalPropertiesDialog.cpp : implementation file
29 #include "TestToolRes.h" // main symbols
30 #include "LocalPropertiesDialog.h"
31 #include "eCosSocket.h"
35 static char THIS_FILE[] = __FILE__;
38 /////////////////////////////////////////////////////////////////////////////
39 // CLocalPropertiesDialog dialog
42 CLocalPropertiesDialog::CLocalPropertiesDialog(bool bHideX10Controls)
43 : CeCosDialog(IDD_TT_PROPERTIES2, NULL),
44 m_bHideX10Controls(bHideX10Controls)
46 //{{AFX_DATA_INIT(CLocalPropertiesDialog)
51 void CLocalPropertiesDialog::DoDataExchange(CDataExchange* pDX)
53 CeCosDialog::DoDataExchange(pDX);
54 if(pDX->m_bSaveAndValidate){
55 m_bSerial=(TRUE==((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->GetCheck());
57 CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
58 int i=pCombo->GetCurSel();
59 pCombo->GetLBText(i, m_strPort.GetBuffer(pCombo->GetLBTextLen(i)));
60 m_strPort.ReleaseBuffer();
63 pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
64 i=pCombo->GetCurSel();
65 pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
66 strBaud.ReleaseBuffer();
67 m_nBaud=_ttoi(strBaud);
69 ((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(m_bSerial);
70 ((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(!m_bSerial);
73 CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
74 if(pCombo->GetCount()>0){
76 for(int i=0;i<pCombo->GetCount();i++){
78 pCombo->GetLBText(i, strPort.GetBuffer(pCombo->GetLBTextLen(i)));
79 strPort.ReleaseBuffer();
80 if(0==strPort.Compare(m_strPort)){
85 pCombo->SetCurSel(nSel);
87 pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
89 for(int i=0;i<pCombo->GetCount();i++){
91 pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
92 strBaud.ReleaseBuffer();
93 if(m_nBaud==_ttoi(strBaud)){
98 pCombo->SetCurSel(nSel);
100 //{{AFX_DATA_MAP(CLocalPropertiesDialog)
101 DDX_Text(pDX, IDC_TT_LOCALTCPIPHOST, m_strLocalTCPIPHost);
102 DDX_Text(pDX, IDC_TT_LOCALTCPIPPORT, m_nLocalTCPIPPort);
103 DDV_MinMaxUInt(pDX, m_nLocalTCPIPPort, 1, 65535);
104 DDX_CBIndex(pDX, IDC_TT_RESET, m_nReset);
105 DDX_Text(pDX, IDC_TT_RESETSTRING, m_strReset);
110 BEGIN_MESSAGE_MAP(CLocalPropertiesDialog, CeCosDialog)
111 //{{AFX_MSG_MAP(CLocalPropertiesDialog)
112 ON_BN_CLICKED(IDC_TT_RADIO_SERIAL, OnRadioSerial)
113 ON_BN_CLICKED(IDC_TT_RADIO_TCPIP, OnRadioTcpip)
114 ON_CBN_SELCHANGE(IDC_TT_RESET, OnSelchangeReset)
118 /////////////////////////////////////////////////////////////////////////////
119 // CLocalPropertiesDialog message handlers
121 void CLocalPropertiesDialog::SetButtons(bool bFromDataExchange)
123 if(!bFromDataExchange){
126 GetDlgItem(IDC_TT_LOCAL_PORT)->EnableWindow(m_bSerial);
127 GetDlgItem(IDC_TT_BAUD)->EnableWindow(m_bSerial);
128 GetDlgItem(IDC_TT_LOCALTCPIPHOST)->EnableWindow(!m_bSerial);
129 GetDlgItem(IDC_TT_LOCALTCPIPPORT)->EnableWindow(!m_bSerial);
130 static const UINT arIDs[]={IDC_TT_RESETSTRING};
131 for(int i=0;i<sizeof arIDs/sizeof arIDs[0];i++){
132 GetDlgItem(arIDs[i])->EnableWindow(RESET_X10==m_nReset);
136 BOOL CLocalPropertiesDialog::OnInitDialog()
138 if(m_bHideX10Controls){
139 // Hide these controls:
140 static const UINT arIDs1[]={IDC_TT_STATIC_RESET, IDC_TT_STATIC_METHOD, IDC_TT_RESET};
141 for(int i=0;i<sizeof arIDs1/sizeof arIDs1[0];i++){
142 GetDlgItem(arIDs1[i])->ShowWindow(SW_HIDE);
144 // Move the bottom buttons up
146 GetDlgItem(IDC_TT_STATIC_RESET)->GetWindowRect(rect);
147 ScreenToClient(rect);
149 static const arIDs2[]={IDOK, IDCANCEL};
151 for(i=0;i<sizeof arIDs2/sizeof arIDs2[0];i++){
152 CWnd *pWnd=GetDlgItem(arIDs2[i]);
153 pWnd->GetWindowRect(rect);
154 ScreenToClient(rect);
155 int nHeight=rect.Height();
156 nDelta=rect.top-nTop;
158 rect.bottom=rect.top+nHeight;
159 pWnd->MoveWindow(rect);
166 CeCosDialog::OnInitDialog();
167 CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT);
168 TCHAR szPort[]=_T("COMx");
169 for(TCHAR c=_TCHAR('1');c<=_TCHAR('8');c++){
171 pCombo->AddString(szPort);
173 UpdateData(false); // because only now has the port combo been populated
174 return TRUE; // return TRUE unless you set the focus to a control
175 // EXCEPTION: OCX Property Pages should return FALSE
178 void CLocalPropertiesDialog::OnRadioSerial()
180 ((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(FALSE);
184 void CLocalPropertiesDialog::OnRadioTcpip()
186 ((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(FALSE);
190 void CLocalPropertiesDialog::OnOK()
194 HANDLE handle=CreateFile(m_strPort, GENERIC_READ ,0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL );
195 if(INVALID_HANDLE_VALUE!=handle){
197 } else if (IDNO==MessageBox(_T("The currently selected serial port is not accessible. Use this setting anyway?"),NULL,MB_YESNO|MB_DEFBUTTON2)){
201 if(!m_bSerial && !CeCosSocket::IsLegalHostPort(CeCosSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort))){
202 MessageBox(_T("Please provide a valid host/port combination for TCP/IP connection"));
203 } else if (RESET_X10==m_nReset && m_strReset.IsEmpty()){
204 MessageBox(_T("Please provide a valid reset string for X10 reset"));
210 void CLocalPropertiesDialog::OnSelchangeReset()