OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [testtool/] [win32/] [LocalPropertiesDialog.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// LocalPropertiesDialog.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
#include "TestToolRes.h"                // main symbols
27
#include "LocalPropertiesDialog.h"
28
#include "eCosSocket.h"
29
#ifdef _DEBUG
30
#define new DEBUG_NEW
31
#undef THIS_FILE
32
static char THIS_FILE[] = __FILE__;
33
#endif
34
 
35
/////////////////////////////////////////////////////////////////////////////
36
// CLocalPropertiesDialog dialog
37
 
38
 
39
CLocalPropertiesDialog::CLocalPropertiesDialog(bool bHideX10Controls)
40
  : CeCosDialog(IDD_TT_PROPERTIES2, NULL),
41
  m_bHideX10Controls(bHideX10Controls)
42
{
43
  //{{AFX_DATA_INIT(CLocalPropertiesDialog)
44
  //}}AFX_DATA_INIT
45
}
46
 
47
 
48
void CLocalPropertiesDialog::DoDataExchange(CDataExchange* pDX)
49
{
50
  CeCosDialog::DoDataExchange(pDX);
51
  if(pDX->m_bSaveAndValidate){
52
    m_bSerial=(TRUE==((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->GetCheck());
53
 
54
    CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
55
    int i=pCombo->GetCurSel();
56
    pCombo->GetLBText(i, m_strPort.GetBuffer(pCombo->GetLBTextLen(i)));
57
    m_strPort.ReleaseBuffer();
58
 
59
    CString strBaud;
60
    pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
61
    i=pCombo->GetCurSel();
62
    pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
63
    strBaud.ReleaseBuffer();
64
    m_nBaud=_ttoi(strBaud);
65
  } else {
66
    ((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(m_bSerial);
67
    ((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(!m_bSerial);
68
    SetButtons(true);
69
 
70
    CComboBox *pCombo=((CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT));
71
    if(pCombo->GetCount()>0){
72
      int nSel=0;
73
      for(int i=0;i<pCombo->GetCount();i++){
74
        CString strPort;
75
        pCombo->GetLBText(i, strPort.GetBuffer(pCombo->GetLBTextLen(i)));
76
        strPort.ReleaseBuffer();
77
        if(0==strPort.Compare(m_strPort)){
78
          nSel=i;
79
          break;
80
        }
81
      }
82
      pCombo->SetCurSel(nSel);
83
    }
84
    pCombo=((CComboBox *)GetDlgItem(IDC_TT_BAUD));
85
    int nSel=0;
86
    for(int i=0;i<pCombo->GetCount();i++){
87
      CString strBaud;
88
      pCombo->GetLBText(i, strBaud.GetBuffer(pCombo->GetLBTextLen(i)));
89
      strBaud.ReleaseBuffer();
90
      if(m_nBaud==_ttoi(strBaud)){
91
        nSel=i;
92
        break;
93
      }
94
    }
95
    pCombo->SetCurSel(nSel);
96
  }
97
  //{{AFX_DATA_MAP(CLocalPropertiesDialog)
98
  DDX_Text(pDX, IDC_TT_LOCALTCPIPHOST, m_strLocalTCPIPHost);
99
  DDX_Text(pDX, IDC_TT_LOCALTCPIPPORT, m_nLocalTCPIPPort);
100
  DDV_MinMaxUInt(pDX, m_nLocalTCPIPPort, 1, 65535);
101
  DDX_CBIndex(pDX, IDC_TT_RESET, m_nReset);
102
  DDX_Text(pDX, IDC_TT_RESETSTRING, m_strReset);
103
  //}}AFX_DATA_MAP
104
}
105
 
106
 
107
BEGIN_MESSAGE_MAP(CLocalPropertiesDialog, CeCosDialog)
108
//{{AFX_MSG_MAP(CLocalPropertiesDialog)
109
ON_BN_CLICKED(IDC_TT_RADIO_SERIAL, OnRadioSerial)
110
ON_BN_CLICKED(IDC_TT_RADIO_TCPIP, OnRadioTcpip)
111
ON_CBN_SELCHANGE(IDC_TT_RESET, OnSelchangeReset)
112
//}}AFX_MSG_MAP
113
END_MESSAGE_MAP()
114
 
115
/////////////////////////////////////////////////////////////////////////////
116
// CLocalPropertiesDialog message handlers
117
 
118
void CLocalPropertiesDialog::SetButtons(bool bFromDataExchange)
119
{
120
  if(!bFromDataExchange){
121
    UpdateData(TRUE);
122
  }
123
  GetDlgItem(IDC_TT_LOCAL_PORT)->EnableWindow(m_bSerial);
124
  GetDlgItem(IDC_TT_BAUD)->EnableWindow(m_bSerial);
125
  GetDlgItem(IDC_TT_LOCALTCPIPHOST)->EnableWindow(!m_bSerial);
126
  GetDlgItem(IDC_TT_LOCALTCPIPPORT)->EnableWindow(!m_bSerial);
127
  static const UINT arIDs[]={IDC_TT_RESETSTRING};
128
  for(int i=0;i<sizeof arIDs/sizeof arIDs[0];i++){
129
    GetDlgItem(arIDs[i])->EnableWindow(RESET_X10==m_nReset);
130
  }
131
}
132
 
133
BOOL CLocalPropertiesDialog::OnInitDialog()
134
{
135
  if(m_bHideX10Controls){
136
    // Hide these controls:
137
    static const UINT arIDs1[]={IDC_TT_STATIC_RESET, IDC_TT_STATIC_METHOD, IDC_TT_RESET};
138
    for(int i=0;i<sizeof arIDs1/sizeof arIDs1[0];i++){
139
      GetDlgItem(arIDs1[i])->ShowWindow(SW_HIDE);
140
    }
141
    // Move the bottom buttons up
142
    CRect rect;
143
    GetDlgItem(IDC_TT_STATIC_RESET)->GetWindowRect(rect);
144
    ScreenToClient(rect);
145
    int nTop=rect.top;
146
    static const arIDs2[]={IDOK, IDCANCEL};
147
    int nDelta=0;
148
    for(i=0;i<sizeof arIDs2/sizeof arIDs2[0];i++){
149
      CWnd *pWnd=GetDlgItem(arIDs2[i]);
150
      pWnd->GetWindowRect(rect);
151
      ScreenToClient(rect);
152
      int nHeight=rect.Height();
153
      nDelta=rect.top-nTop;
154
      rect.top=nTop;
155
      rect.bottom=rect.top+nHeight;
156
      pWnd->MoveWindow(rect);
157
    }
158
    GetWindowRect(rect);
159
    rect.bottom-=nDelta;
160
    MoveWindow(rect);
161
  }
162
 
163
  CeCosDialog::OnInitDialog();
164
  CComboBox *pCombo=(CComboBox *)GetDlgItem(IDC_TT_LOCAL_PORT);
165
  TCHAR szPort[]=_T("COMx");
166
  for(TCHAR c=_TCHAR('1');c<=_TCHAR('8');c++){
167
    szPort[3]=c;
168
    pCombo->AddString(szPort);
169
  }
170
  UpdateData(false); // because only now has the port combo been populated
171
  return TRUE;  // return TRUE unless you set the focus to a control
172
  // EXCEPTION: OCX Property Pages should return FALSE
173
}
174
 
175
void CLocalPropertiesDialog::OnRadioSerial()
176
{
177
  ((CButton *)GetDlgItem(IDC_TT_RADIO_TCPIP))->SetCheck(FALSE);
178
  SetButtons();
179
}
180
 
181
void CLocalPropertiesDialog::OnRadioTcpip()
182
{
183
  ((CButton *)GetDlgItem(IDC_TT_RADIO_SERIAL))->SetCheck(FALSE);
184
  SetButtons();
185
}
186
 
187
void CLocalPropertiesDialog::OnOK()
188
{
189
  UpdateData();
190
 
191
  HANDLE handle=CreateFile(m_strPort, GENERIC_READ ,0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL );
192
  if(INVALID_HANDLE_VALUE!=handle){
193
    CloseHandle(handle);
194
  } else if (IDNO==MessageBox(_T("The currently selected serial port is not accessible.  Use this setting anyway?"),NULL,MB_YESNO|MB_DEFBUTTON2)){
195
    return;
196
  }
197
 
198
  if(!m_bSerial && !CeCosSocket::IsLegalHostPort(CeCosSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort))){
199
    MessageBox(_T("Please provide a valid host/port combination for TCP/IP connection"));
200
  } else if (RESET_X10==m_nReset && m_strReset.IsEmpty()){
201
    MessageBox(_T("Please provide a valid reset string for X10 reset"));
202
  } else {
203
    CeCosDialog::OnOK();
204
  }
205
}
206
 
207
void CLocalPropertiesDialog::OnSelchangeReset()
208
{
209
  SetButtons();
210
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.