Rollback from r3608 to r3606
[public/netxms.git] / src / console / win32 / CreateNetSrvDlg.cpp
1 // CreateNetSrvDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "CreateNetSrvDlg.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CCreateNetSrvDlg dialog
16
17
18 CCreateNetSrvDlg::CCreateNetSrvDlg(CWnd* pParent /*=NULL*/)
19 : CCreateObjectDlg(CCreateNetSrvDlg::IDD, pParent)
20 {
21 //{{AFX_DATA_INIT(CCreateNetSrvDlg)
22 m_iPort = 0;
23 m_iProtocolType = -1;
24 m_iProtocolNumber = 0;
25 m_strRequest = _T("");
26 m_strResponse = _T("");
27 //}}AFX_DATA_INIT
28 }
29
30
31 void CCreateNetSrvDlg::DoDataExchange(CDataExchange* pDX)
32 {
33 CCreateObjectDlg::DoDataExchange(pDX);
34 //{{AFX_DATA_MAP(CCreateNetSrvDlg)
35 DDX_Control(pDX, IDC_COMBO_TYPES, m_wndTypeList);
36 DDX_Text(pDX, IDC_EDIT_PORT, m_iPort);
37 DDV_MinMaxLong(pDX, m_iPort, 0, 65535);
38 DDX_Radio(pDX, IDC_RADIO_TCP, m_iProtocolType);
39 DDX_Text(pDX, IDC_EDIT_PROTO, m_iProtocolNumber);
40 DDV_MinMaxLong(pDX, m_iProtocolNumber, 0, 255);
41 DDX_Text(pDX, IDC_EDIT_REQUEST, m_strRequest);
42 DDX_Text(pDX, IDC_EDIT_RESPONSE, m_strResponse);
43 //}}AFX_DATA_MAP
44 }
45
46
47 BEGIN_MESSAGE_MAP(CCreateNetSrvDlg, CCreateObjectDlg)
48 //{{AFX_MSG_MAP(CCreateNetSrvDlg)
49 ON_CBN_SELCHANGE(IDC_COMBO_TYPES, OnSelchangeComboTypes)
50 ON_BN_CLICKED(IDC_RADIO_TCP, OnRadioTcp)
51 ON_BN_CLICKED(IDC_RADIO_UDP, OnRadioUdp)
52 ON_BN_CLICKED(IDC_RADIO_ICMP, OnRadioIcmp)
53 ON_BN_CLICKED(IDC_RADIO_OTHER, OnRadioOther)
54 //}}AFX_MSG_MAP
55 END_MESSAGE_MAP()
56
57 /////////////////////////////////////////////////////////////////////////////
58 // CCreateNetSrvDlg message handlers
59
60 BOOL CCreateNetSrvDlg::OnInitDialog()
61 {
62 int i;
63
64 CCreateObjectDlg::OnInitDialog();
65
66 // Add service types to combo box
67 for(i = 0; g_szServiceType[i] != NULL; i++)
68 m_wndTypeList.AddString(g_szServiceType[i]);
69 m_wndTypeList.SelectString(-1, g_szServiceType[m_iServiceType]);
70
71 SetProtocolCtrls();
72
73 return TRUE;
74 }
75
76
77 //
78 // Handler for OK button
79 //
80
81 void CCreateNetSrvDlg::OnOK()
82 {
83 GetServiceType();
84 CCreateObjectDlg::OnOK();
85 }
86
87
88 //
89 // Handler for selection change in service type list
90 //
91
92 void CCreateNetSrvDlg::OnSelchangeComboTypes()
93 {
94 GetServiceType();
95 if (m_iServiceType != NETSRV_CUSTOM)
96 {
97 SetDlgItemText(IDC_EDIT_PROTO, _T("6"));
98 SendDlgItemMessage(IDC_RADIO_TCP, BM_SETCHECK, BST_CHECKED, 0);
99 SendDlgItemMessage(IDC_RADIO_UDP, BM_SETCHECK, BST_UNCHECKED, 0);
100 SendDlgItemMessage(IDC_RADIO_ICMP, BM_SETCHECK, BST_UNCHECKED, 0);
101 SendDlgItemMessage(IDC_RADIO_OTHER, BM_SETCHECK, BST_UNCHECKED, 0);
102 }
103 SetProtocolCtrls();
104 }
105
106
107 //
108 // Set states of IP protocol selection controls
109 //
110
111 void CCreateNetSrvDlg::SetProtocolCtrls()
112 {
113 BOOL bEnable;
114
115 bEnable = (m_iServiceType == NETSRV_CUSTOM) ? TRUE : FALSE;
116 EnableDlgItem(this, IDC_RADIO_TCP, bEnable);
117 EnableDlgItem(this, IDC_RADIO_UDP, bEnable);
118 EnableDlgItem(this, IDC_RADIO_ICMP, bEnable);
119 EnableDlgItem(this, IDC_RADIO_OTHER, bEnable);
120 EnableDlgItem(this, IDC_EDIT_PROTO,
121 SendDlgItemMessage(IDC_RADIO_OTHER, BM_GETCHECK) == BST_CHECKED);
122 }
123
124
125 //
126 // Get selected service type from combo box
127 //
128
129 void CCreateNetSrvDlg::GetServiceType()
130 {
131 TCHAR szBuffer[256];
132
133 // Determine service type
134 m_wndTypeList.GetWindowText(szBuffer, 256);
135 for(m_iServiceType = 0; g_szServiceType[m_iServiceType] != NULL; m_iServiceType++)
136 if (!_tcscmp(szBuffer, g_szServiceType[m_iServiceType]))
137 break;
138 }
139
140
141 //
142 // Handle radio button clicks
143 //
144
145 void CCreateNetSrvDlg::OnRadioTcp()
146 {
147 SetDlgItemText(IDC_EDIT_PROTO, _T("6"));
148 EnableDlgItem(this, IDC_EDIT_PROTO, FALSE);
149 }
150
151 void CCreateNetSrvDlg::OnRadioUdp()
152 {
153 SetDlgItemText(IDC_EDIT_PROTO, _T("17"));
154 EnableDlgItem(this, IDC_EDIT_PROTO, FALSE);
155 }
156
157 void CCreateNetSrvDlg::OnRadioIcmp()
158 {
159 SetDlgItemText(IDC_EDIT_PROTO, _T("1"));
160 EnableDlgItem(this, IDC_EDIT_PROTO, FALSE);
161 }
162
163 void CCreateNetSrvDlg::OnRadioOther()
164 {
165 EnableDlgItem(this, IDC_EDIT_PROTO, TRUE);
166 }