Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

464 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // NetProp.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the network property sheet and pages.
  10. //
  11. // Author:
  12. // David Potter (davidp) June 9, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "NetProp.h"
  22. #include "HelpData.h"
  23. #include "ExcOper.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CNetworkPropSheet
  31. /////////////////////////////////////////////////////////////////////////////
  32. IMPLEMENT_DYNAMIC(CNetworkPropSheet, CBasePropertySheet)
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Message Maps
  35. BEGIN_MESSAGE_MAP(CNetworkPropSheet, CBasePropertySheet)
  36. //{{AFX_MSG_MAP(CNetworkPropSheet)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. //++
  41. //
  42. // CNetworkPropSheet::CNetworkPropSheet
  43. //
  44. // Routine Description:
  45. // Constructor.
  46. //
  47. // Arguments:
  48. // pParentWnd [IN OUT] Parent window for this property sheet.
  49. // iSelectPage [IN] Page to show first.
  50. //
  51. // Return Value:
  52. // None.
  53. //
  54. //--
  55. /////////////////////////////////////////////////////////////////////////////
  56. CNetworkPropSheet::CNetworkPropSheet(
  57. IN OUT CWnd * pParentWnd,
  58. IN UINT iSelectPage
  59. )
  60. : CBasePropertySheet(pParentWnd, iSelectPage)
  61. {
  62. m_rgpages[0] = &PageGeneral();
  63. } //*** CNetworkPropSheet::CNetworkPropSheet()
  64. /////////////////////////////////////////////////////////////////////////////
  65. //++
  66. //
  67. // CNetworkPropSheet::BInit
  68. //
  69. // Routine Description:
  70. // Initialize the property sheet.
  71. //
  72. // Arguments:
  73. // pci [IN OUT] Cluster item whose properties are to be displayed.
  74. // iimgIcon [IN] Index in the large image list for the image to use
  75. // as the icon on each page.
  76. //
  77. // Return Value:
  78. // TRUE Property sheet initialized successfully.
  79. // FALSE Error initializing property sheet.
  80. //
  81. //--
  82. /////////////////////////////////////////////////////////////////////////////
  83. BOOL CNetworkPropSheet::BInit(
  84. IN OUT CClusterItem * pci,
  85. IN IIMG iimgIcon
  86. )
  87. {
  88. // Call the base class method.
  89. if (!CBasePropertySheet::BInit(pci, iimgIcon))
  90. return FALSE;
  91. // Set the read-only flag if the handles are invalid.
  92. m_bReadOnly = PciNet()->BReadOnly()
  93. || (PciNet()->Cns() == ClusterNetworkStateUnknown);
  94. return TRUE;
  95. } //*** CNetworkPropSheet::BInit()
  96. /////////////////////////////////////////////////////////////////////////////
  97. //++
  98. //
  99. // CNetworkPropSheet::Ppages
  100. //
  101. // Routine Description:
  102. // Returns the array of pages to add to the property sheet.
  103. //
  104. // Arguments:
  105. // None.
  106. //
  107. // Return Value:
  108. // Page array.
  109. //
  110. //--
  111. /////////////////////////////////////////////////////////////////////////////
  112. CBasePropertyPage ** CNetworkPropSheet::Ppages(void)
  113. {
  114. return m_rgpages;
  115. } //*** CNetworkPropSheet::Pppges()
  116. /////////////////////////////////////////////////////////////////////////////
  117. //++
  118. //
  119. // CNetworkPropSheet::Cpages
  120. //
  121. // Routine Description:
  122. // Returns the count of pages in the array.
  123. //
  124. // Arguments:
  125. // None.
  126. //
  127. // Return Value:
  128. // Count of pages in the array.
  129. //
  130. //--
  131. /////////////////////////////////////////////////////////////////////////////
  132. int CNetworkPropSheet::Cpages(void)
  133. {
  134. return sizeof(m_rgpages) / sizeof(CBasePropertyPage *);
  135. } //*** CNetworkPropSheet::Cpages()
  136. //*************************************************************************//
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CNetworkGeneralPage property page
  139. /////////////////////////////////////////////////////////////////////////////
  140. IMPLEMENT_DYNCREATE(CNetworkGeneralPage, CBasePropertyPage)
  141. /////////////////////////////////////////////////////////////////////////////
  142. // Message Maps
  143. BEGIN_MESSAGE_MAP(CNetworkGeneralPage, CBasePropertyPage)
  144. //{{AFX_MSG_MAP(CNetworkGeneralPage)
  145. ON_BN_CLICKED(IDC_PP_NET_ROLE_ENABLE_NETWORK, OnEnableNetwork)
  146. //}}AFX_MSG_MAP
  147. ON_EN_CHANGE(IDC_PP_NET_NAME, CBasePropertyPage::OnChangeCtrl)
  148. ON_EN_CHANGE(IDC_PP_NET_DESC, CBasePropertyPage::OnChangeCtrl)
  149. ON_BN_CLICKED(IDC_PP_NET_ROLE_ALL_COMM, CBasePropertyPage::OnChangeCtrl)
  150. ON_BN_CLICKED(IDC_PP_NET_ROLE_INTERNAL_ONLY, CBasePropertyPage::OnChangeCtrl)
  151. ON_BN_CLICKED(IDC_PP_NET_ROLE_CLIENT_ONLY, CBasePropertyPage::OnChangeCtrl)
  152. ON_EN_CHANGE(IDC_PP_NET_ADDRESS_MASK, CBasePropertyPage::OnChangeCtrl)
  153. END_MESSAGE_MAP()
  154. /////////////////////////////////////////////////////////////////////////////
  155. //++
  156. //
  157. // CNetworkGeneralPage::CNetworkGeneralPage
  158. //
  159. // Routine Description:
  160. // Constructor.
  161. //
  162. // Arguments:
  163. // None.
  164. //
  165. // Return Value:
  166. // None.
  167. //
  168. //--
  169. /////////////////////////////////////////////////////////////////////////////
  170. CNetworkGeneralPage::CNetworkGeneralPage(void)
  171. : CBasePropertyPage(IDD, g_aHelpIDs_IDD_PP_NET_GENERAL)
  172. {
  173. //{{AFX_DATA_INIT(CNetworkGeneralPage)
  174. m_strName = _T("");
  175. m_strDesc = _T("");
  176. m_bEnabled = FALSE;
  177. m_nRole = -1;
  178. m_strAddressMask = _T("");
  179. m_strState = _T("");
  180. //}}AFX_DATA_INIT
  181. } //*** CNetworkGeneralPage::CNetworkGeneralPage()
  182. /////////////////////////////////////////////////////////////////////////////
  183. //++
  184. //
  185. // CNetworkGeneralPage::BInit
  186. //
  187. // Routine Description:
  188. // Initialize the page.
  189. //
  190. // Arguments:
  191. // psht [IN OUT] Property sheet to which this page belongs.
  192. //
  193. // Return Value:
  194. // TRUE Page initialized successfully.
  195. // FALSE Page failed to initialize.
  196. //
  197. //--
  198. /////////////////////////////////////////////////////////////////////////////
  199. BOOL CNetworkGeneralPage::BInit(IN OUT CBaseSheet * psht)
  200. {
  201. BOOL bSuccess;
  202. ASSERT_KINDOF(CNetworkPropSheet, psht);
  203. bSuccess = CBasePropertyPage::BInit(psht);
  204. if (bSuccess)
  205. {
  206. try
  207. {
  208. m_strName = PciNet()->StrName();
  209. m_strDesc = PciNet()->StrDescription();
  210. m_cnr = PciNet()->Cnr();
  211. m_strAddressMask = PciNet()->StrAddressMask();
  212. PciNet()->GetStateName(m_strState);
  213. if (m_cnr == ClusterNetworkRoleNone)
  214. {
  215. m_bEnabled = FALSE;
  216. m_nRole = -1;
  217. } // if: network is disabled
  218. else
  219. {
  220. m_bEnabled = TRUE;
  221. if (m_cnr == ClusterNetworkRoleClientAccess)
  222. m_nRole = 0;
  223. else if (m_cnr == ClusterNetworkRoleInternalUse)
  224. m_nRole = 1;
  225. else if (m_cnr == ClusterNetworkRoleInternalAndClient)
  226. m_nRole = 2;
  227. else
  228. {
  229. ASSERT(0);
  230. m_nRole = -1;
  231. m_bEnabled = FALSE;
  232. } // else; Unknown role
  233. } // else: network not disabled
  234. } // try
  235. catch (CException * pe)
  236. {
  237. pe->ReportError();
  238. pe->Delete();
  239. bSuccess = FALSE;
  240. } // catch: CException
  241. } // if: base class method was successful
  242. return bSuccess;
  243. } //*** CNetworkGeneralPage::BInit()
  244. /////////////////////////////////////////////////////////////////////////////
  245. //++
  246. //
  247. // CNetworkGeneralPage::DoDataExchange
  248. //
  249. // Routine Description:
  250. // Do data exchange between the dialog and the class.
  251. //
  252. // Arguments:
  253. // pDX [IN OUT] Data exchange object
  254. //
  255. // Return Value:
  256. // None.
  257. //
  258. //--
  259. /////////////////////////////////////////////////////////////////////////////
  260. void CNetworkGeneralPage::DoDataExchange(CDataExchange* pDX)
  261. {
  262. CBasePropertyPage::DoDataExchange(pDX);
  263. //{{AFX_DATA_MAP(CNetworkGeneralPage)
  264. DDX_Control(pDX, IDC_PP_NET_ADDRESS_MASK, m_editAddressMask);
  265. DDX_Control(pDX, IDC_PP_NET_ROLE_ENABLE_NETWORK, m_ckbEnable);
  266. DDX_Control(pDX, IDC_PP_NET_ROLE_CLIENT_ONLY, m_rbRoleClientOnly);
  267. DDX_Control(pDX, IDC_PP_NET_ROLE_INTERNAL_ONLY, m_rbRoleInternalOnly);
  268. DDX_Control(pDX, IDC_PP_NET_ROLE_ALL_COMM, m_rbRoleAllComm);
  269. DDX_Control(pDX, IDC_PP_NET_DESC, m_editDesc);
  270. DDX_Control(pDX, IDC_PP_NET_NAME, m_editName);
  271. DDX_Text(pDX, IDC_PP_NET_NAME, m_strName);
  272. DDX_Text(pDX, IDC_PP_NET_DESC, m_strDesc);
  273. DDX_Text(pDX, IDC_PP_NET_ADDRESS_MASK, m_strAddressMask);
  274. DDX_Text(pDX, IDC_PP_NET_CURRENT_STATE, m_strState);
  275. DDX_Radio(pDX, IDC_PP_NET_ROLE_CLIENT_ONLY, m_nRole);
  276. DDX_Check(pDX, IDC_PP_NET_ROLE_ENABLE_NETWORK, m_bEnabled);
  277. //}}AFX_DATA_MAP
  278. if (pDX->m_bSaveAndValidate)
  279. {
  280. // Validate the name.
  281. if (!NcIsValidConnectionName(m_strName))
  282. {
  283. ThrowStaticException((IDS) IDS_INVALID_NETWORK_CONNECTION_NAME);
  284. } // if: error validating the name
  285. // Convert address and address mask.
  286. if (m_bEnabled)
  287. {
  288. switch (m_nRole)
  289. {
  290. case 0:
  291. m_cnr = ClusterNetworkRoleClientAccess;
  292. break;
  293. case 1:
  294. m_cnr = ClusterNetworkRoleInternalUse;
  295. break;
  296. case 2:
  297. m_cnr = ClusterNetworkRoleInternalAndClient;
  298. break;
  299. default:
  300. ASSERT(0);
  301. break;
  302. } // switch: m_nRole
  303. } // if: network is enabled
  304. else
  305. m_cnr = ClusterNetworkRoleNone;
  306. } // if: saving data from dialog
  307. } //*** CNetworkGeneralPage::DoDataExchange()
  308. /////////////////////////////////////////////////////////////////////////////
  309. //++
  310. //
  311. // CNetworkGeneralPage::OnInitDialog
  312. //
  313. // Routine Description:
  314. // Handler for the WM_INITDIALOG message.
  315. //
  316. // Arguments:
  317. // None.
  318. //
  319. // Return Value:
  320. // TRUE Focus needs to be set.
  321. // FALSE Focus already set.
  322. //
  323. //--
  324. /////////////////////////////////////////////////////////////////////////////
  325. BOOL CNetworkGeneralPage::OnInitDialog(void)
  326. {
  327. CBasePropertyPage::OnInitDialog();
  328. // If read-only, set all controls to be either disabled or read-only.
  329. if (BReadOnly())
  330. {
  331. m_editName.SetReadOnly(TRUE);
  332. m_editDesc.SetReadOnly(TRUE);
  333. m_ckbEnable.EnableWindow(FALSE);
  334. m_rbRoleAllComm.EnableWindow(FALSE);
  335. m_rbRoleInternalOnly.EnableWindow(FALSE);
  336. m_rbRoleClientOnly.EnableWindow(FALSE);
  337. m_editAddressMask.SetReadOnly(TRUE);
  338. } // if: sheet is read-only
  339. else
  340. {
  341. m_editName.SetLimitText(NETCON_MAX_NAME_LEN);
  342. } // else: sheet is read/write
  343. OnEnableNetwork();
  344. return TRUE; // return TRUE unless you set the focus to a control
  345. // EXCEPTION: OCX Property Pages should return FALSE
  346. } //*** CNetworkGeneralPage::OnInitDialog()
  347. /////////////////////////////////////////////////////////////////////////////
  348. //++
  349. //
  350. // CNetworkGeneralPage::OnApply
  351. //
  352. // Routine Description:
  353. // Handler for when the Apply button is pressed.
  354. //
  355. // Arguments:
  356. // None.
  357. //
  358. // Return Value:
  359. // TRUE Page successfully applied.
  360. // FALSE Error applying page.
  361. //
  362. //--
  363. /////////////////////////////////////////////////////////////////////////////
  364. BOOL CNetworkGeneralPage::OnApply(void)
  365. {
  366. // Set the data from the page in the cluster item.
  367. try
  368. {
  369. CWaitCursor wc;
  370. PciNet()->SetName(m_strName);
  371. PciNet()->SetCommonProperties(
  372. m_strDesc,
  373. m_cnr
  374. );
  375. } // try
  376. catch (CException * pe)
  377. {
  378. pe->ReportError();
  379. pe->Delete();
  380. return FALSE;
  381. } // catch: CException
  382. return CBasePropertyPage::OnApply();
  383. } //*** CNetworkGeneralPage::OnApply()
  384. /////////////////////////////////////////////////////////////////////////////
  385. //++
  386. //
  387. // CNetworkGeneralPage::OnEnableNetwork
  388. //
  389. // Routine Description:
  390. // Handler for the BN_CLICKED message on the Enable network checkbox.
  391. //
  392. // Arguments:
  393. // None.
  394. //
  395. // Return Value:
  396. // None.
  397. //
  398. //--
  399. /////////////////////////////////////////////////////////////////////////////
  400. void CNetworkGeneralPage::OnEnableNetwork(void)
  401. {
  402. BOOL bEnabled;
  403. OnChangeCtrl();
  404. bEnabled = (!BReadOnly() && (m_ckbEnable.GetCheck() == BST_CHECKED));
  405. m_rbRoleAllComm.EnableWindow(bEnabled);
  406. m_rbRoleInternalOnly.EnableWindow(bEnabled);
  407. m_rbRoleClientOnly.EnableWindow(bEnabled);
  408. GetDlgItem(IDC_PP_NET_ROLE_CAPTION)->EnableWindow(bEnabled);
  409. if ( bEnabled
  410. && (m_rbRoleAllComm.GetCheck() != BST_CHECKED)
  411. && (m_rbRoleInternalOnly.GetCheck() != BST_CHECKED)
  412. && (m_rbRoleClientOnly.GetCheck() != BST_CHECKED))
  413. m_rbRoleAllComm.SetCheck(BST_CHECKED);
  414. } //*** CNetworkGeneralPage::OnEnableNetwork()