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.

483 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A L A N E P S H . C P P
  7. //
  8. // Contents: Dialog box handling for the ATM LAN Emulation configuration.
  9. //
  10. // Notes:
  11. //
  12. // Author: v-lcleet 08/10/1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "alaneobj.h"
  18. #include "alanepsh.h"
  19. #include "alanehlp.h"
  20. #include "ncatlui.h"
  21. #include <stlalgor.h>
  22. //
  23. // CALanePsh
  24. //
  25. // Constructor/Destructor methods
  26. //
  27. CALanePsh::CALanePsh(CALaneCfg* palcfg, CALaneCfgAdapterInfo * pAdapterInfo,
  28. const DWORD * adwHelpIDs)
  29. {
  30. AssertSz(palcfg, "We don't have a CALaneCfg*");
  31. AssertSz(pAdapterInfo, "We don't have a CALaneCfgAdapterInfo *");
  32. m_palcfg = palcfg;
  33. m_pAdapterInfo = pAdapterInfo;
  34. m_adwHelpIDs = adwHelpIDs;
  35. return;
  36. }
  37. CALanePsh::~CALanePsh(VOID)
  38. {
  39. return;
  40. }
  41. LRESULT CALanePsh::OnInitDialog(UINT uMsg, WPARAM wParam,
  42. LPARAM lParam, BOOL& bHandled)
  43. {
  44. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  45. m_fEditState = FALSE;
  46. // Get the Add ELAN button text
  47. WCHAR szAddElan[16] = {0};
  48. GetDlgItemText(IDC_ELAN_ADD, szAddElan, celems(szAddElan));
  49. szAddElan[lstrlenW(szAddElan) - 3]; // remove ampersand
  50. m_strAddElan = szAddElan;
  51. // get hwnd to the adapter and elan list
  52. // m_hAdapterList = GetDlgItem(IDC_ADAPTER_LIST);
  53. m_hElanList = GetDlgItem(IDC_ELAN_LIST);
  54. // get hwnd to the three buttons
  55. m_hbtnAdd = GetDlgItem(IDC_ELAN_ADD);
  56. m_hbtnEdit = GetDlgItem(IDC_ELAN_EDIT);
  57. m_hbtnRemove = GetDlgItem(IDC_ELAN_REMOVE);
  58. // fill in adapter list
  59. SendAdapterInfo();
  60. // fill in elan list
  61. SendElanInfo();
  62. // set the state of the buttons
  63. SetButtons();
  64. SetChangedFlag();
  65. return 0;
  66. }
  67. LRESULT CALanePsh::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  68. {
  69. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  70. return 0;
  71. }
  72. LRESULT CALanePsh::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  73. {
  74. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  75. Assert(lphi);
  76. if (HELPINFO_WINDOW == lphi->iContextType)
  77. {
  78. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  79. m_adwHelpIDs);
  80. }
  81. return 0;
  82. }
  83. LRESULT CALanePsh::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  84. {
  85. BOOL err = FALSE; // Allow page to lose active status
  86. // Check duplicate Elan names on the same ATM adapter
  87. int iDupElanName = CheckDupElanName();
  88. if (iDupElanName >=0)
  89. {
  90. NcMsgBox(m_hWnd, IDS_MSFT_LANE_TEXT, IDS_DUPLICATE_ELANNAME,
  91. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  92. err = TRUE;
  93. }
  94. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, err);
  95. return err;
  96. }
  97. int CALanePsh::CheckDupElanName()
  98. {
  99. int ret = -1;
  100. int idx = 0;
  101. for(ELAN_INFO_LIST::iterator iterElan = m_pAdapterInfo->m_lstElans.begin();
  102. iterElan != m_pAdapterInfo->m_lstElans.end();
  103. iterElan++)
  104. {
  105. // skip deleted ones
  106. if (!(*iterElan)->m_fDeleted)
  107. {
  108. ELAN_INFO_LIST::iterator iterElanComp = iterElan;
  109. iterElanComp++;
  110. while (iterElanComp != m_pAdapterInfo->m_lstElans.end())
  111. {
  112. if (!(*iterElanComp)->m_fDeleted)
  113. {
  114. if (!lstrcmpW( ((*iterElan)->SzGetElanName()),
  115. ((*iterElanComp)->SzGetElanName())))
  116. {
  117. // we find a duplicate name
  118. ret = idx;
  119. break;
  120. }
  121. }
  122. iterElanComp++;
  123. }
  124. // duplicate name found
  125. if (ret >=0 )
  126. break;
  127. // move next
  128. idx ++;
  129. }
  130. }
  131. return ret;
  132. }
  133. LRESULT CALanePsh::OnAdd(WORD wNotifyCode, WORD wID,
  134. HWND hWndCtl, BOOL& bHandled)
  135. {
  136. CALaneCfgElanInfo * pElanInfo = NULL;
  137. CElanPropertiesDialog * pDlgProp = NULL;
  138. m_fEditState = FALSE;
  139. // create a new ELAN info object
  140. pElanInfo = new CALaneCfgElanInfo;
  141. // create the dialog object, passing in the new ELAN info ptr
  142. pDlgProp = new CElanPropertiesDialog(this, pElanInfo, g_aHelpIDs_IDD_ELAN_PROPERTIES);
  143. if (pElanInfo && pDlgProp)
  144. {
  145. // see if user hit ADD
  146. if (pDlgProp->DoModal() == IDOK)
  147. {
  148. // Push the Elan onto the the adapter's list
  149. m_pAdapterInfo->m_lstElans.push_back(pElanInfo);
  150. // Mark it so miniport gets created if user hits OK/APPLY
  151. pElanInfo->m_fCreateMiniportOnPropertyApply = TRUE;
  152. pElanInfo = NULL; // don't let cleanup delete it
  153. // refresh the ELAN list
  154. SendElanInfo();
  155. // set the state of the buttons
  156. SetButtons();
  157. }
  158. }
  159. // release objects as needed
  160. if (pElanInfo)
  161. delete pElanInfo;
  162. if (pDlgProp)
  163. delete pDlgProp;
  164. return 0;
  165. }
  166. LRESULT CALanePsh::OnEdit(WORD wNotifyCode, WORD wID,
  167. HWND hWndCtl, BOOL& bHandled)
  168. {
  169. CALaneCfgElanInfo * pElanInfo;
  170. int idx;
  171. m_fEditState = TRUE;
  172. // get index of current ELAN selection
  173. idx = (int) ::SendMessage(m_hElanList, LB_GETCURSEL, 0, 0);
  174. Assert(idx >= 0);
  175. // get the ElanInfo pointer from the current selection
  176. pElanInfo = (CALaneCfgElanInfo *)::SendMessage(m_hElanList,
  177. LB_GETITEMDATA, idx, 0L);
  178. // create the dialog, passing in the ELAN info ptr
  179. CElanPropertiesDialog * pDlgProp = new CElanPropertiesDialog(this, pElanInfo,
  180. g_aHelpIDs_IDD_ELAN_PROPERTIES);
  181. if (pDlgProp->DoModal() == IDOK)
  182. {
  183. // refresh the ELAN list
  184. SendElanInfo();
  185. }
  186. delete pDlgProp;
  187. return 0;
  188. }
  189. LRESULT CALanePsh::OnRemove(WORD wNotifyCode, WORD wID,
  190. HWND hWndCtl, BOOL& bHandled)
  191. {
  192. CALaneCfgElanInfo * pElanInfo;
  193. int idx;
  194. // get index of current ELAN selection
  195. idx = (int) ::SendMessage(m_hElanList, LB_GETCURSEL, 0, 0);
  196. Assert(idx >= 0);
  197. // get the ElanInfo pointer from the current selection
  198. pElanInfo = (CALaneCfgElanInfo *)::SendMessage(m_hElanList,
  199. LB_GETITEMDATA, idx, 0L);
  200. // mark as deleted
  201. pElanInfo->m_fDeleted = TRUE;
  202. pElanInfo->m_fRemoveMiniportOnPropertyApply = TRUE;
  203. // RAID 31445: ATM: AssertFail in \engine\remove.cpp line 180
  204. // when add & remove ELAN w/o committing changes.
  205. // mbend 20 May 2000
  206. //
  207. // Remove newly created adapters
  208. if (pElanInfo->m_fCreateMiniportOnPropertyApply)
  209. {
  210. ELAN_INFO_LIST::iterator iter = find(
  211. m_pAdapterInfo->m_lstElans.begin(),
  212. m_pAdapterInfo->m_lstElans.end(),
  213. pElanInfo);
  214. Assert(m_pAdapterInfo->m_lstElans.end() != iter);
  215. m_pAdapterInfo->m_lstElans.erase(iter);
  216. delete pElanInfo;
  217. }
  218. // refresh the ELAN list
  219. SendElanInfo();
  220. // set the state of the buttons
  221. SetButtons();
  222. return 0;
  223. }
  224. void CALanePsh::SendAdapterInfo()
  225. {
  226. ATMLANE_ADAPTER_INFO_LIST::iterator iterLstAdapters;
  227. CALaneCfgAdapterInfo * pAdapterInfo;
  228. return;
  229. }
  230. void CALanePsh::SendElanInfo()
  231. {
  232. ELAN_INFO_LIST::iterator iterLstElans;
  233. CALaneCfgElanInfo * pElanInfo = NULL;
  234. // pAdapterInfo = GetSelectedAdapter();
  235. Assert (NULL != m_pAdapterInfo);
  236. ::SendMessage(m_hElanList, LB_RESETCONTENT, 0, 0L);
  237. // loop thru the ELANs
  238. for (iterLstElans = m_pAdapterInfo->m_lstElans.begin();
  239. iterLstElans != m_pAdapterInfo->m_lstElans.end();
  240. iterLstElans++)
  241. {
  242. int idx;
  243. pElanInfo = *iterLstElans;
  244. // only add to list if not deleted
  245. if (!pElanInfo->m_fDeleted)
  246. {
  247. // set name to "unspecified" or actual specified name
  248. if (0 == lstrlen(pElanInfo->SzGetElanName()))
  249. {
  250. idx = ::SendMessage(m_hElanList, LB_ADDSTRING, 0,
  251. (LPARAM)(SzLoadIds(IDS_ALANECFG_UNSPECIFIEDNAME)));
  252. }
  253. else
  254. {
  255. idx = ::SendMessage(m_hElanList, LB_ADDSTRING, 0,
  256. (LPARAM)((PCWSTR)(pElanInfo->SzGetElanName())));
  257. }
  258. // store pointer to ElanInfo with text
  259. if (idx != LB_ERR)
  260. ::SendMessage(m_hElanList, LB_SETITEMDATA, idx,
  261. (LPARAM)(pElanInfo));
  262. }
  263. }
  264. // select the first one
  265. ::SendMessage(m_hElanList, LB_SETCURSEL, 0, (LPARAM)0);
  266. return;
  267. }
  268. CALaneCfgElanInfo *CALanePsh::GetSelectedElan()
  269. {
  270. int nCount;
  271. int idx;
  272. DWORD_PTR dw;
  273. CALaneCfgElanInfo *pElanInfo = NULL;
  274. nCount = (int) ::SendMessage(m_hElanList, LB_GETCOUNT, 0, 0);
  275. if (nCount > 0)
  276. {
  277. idx = (int) ::SendMessage(m_hElanList, LB_GETCURSEL, 0, 0);
  278. if (LB_ERR != idx)
  279. {
  280. dw = ::SendMessage(m_hElanList, LB_GETITEMDATA, idx, (LPARAM)0);
  281. if (dw && ((DWORD_PTR)LB_ERR != dw))
  282. {
  283. pElanInfo = (CALaneCfgElanInfo *)dw;
  284. }
  285. }
  286. }
  287. return pElanInfo;
  288. }
  289. void CALanePsh::SetButtons()
  290. {
  291. int nCount;
  292. // get count of Elans in list
  293. nCount = (int) ::SendMessage(m_hElanList, LB_GETCOUNT, 0, 0);
  294. if (!nCount)
  295. {
  296. // remove the default on the remove button, if any
  297. ::SendMessage(m_hbtnRemove, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, TRUE );
  298. // move focus to Add button
  299. ::SetFocus(m_hbtnAdd);
  300. }
  301. // enable/disable "Edit" and "Remove" buttons based existing Elans
  302. ::EnableWindow(m_hbtnEdit, !!nCount);
  303. ::EnableWindow(m_hbtnRemove, !!nCount);
  304. return;
  305. }
  306. //
  307. // CElanPropertiesDialog
  308. //
  309. CElanPropertiesDialog::CElanPropertiesDialog(CALanePsh * pCALanePsh,
  310. CALaneCfgElanInfo *pElanInfo,
  311. const DWORD * adwHelpIDs)
  312. {
  313. m_pParentDlg = pCALanePsh;
  314. m_pElanInfo = pElanInfo;
  315. m_adwHelpIDs = adwHelpIDs;
  316. return;
  317. }
  318. LRESULT CElanPropertiesDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  319. LPARAM lParam, BOOL& fHandled)
  320. {
  321. // change the ok button to add if we are not editing
  322. if (m_pParentDlg->m_fEditState == FALSE)
  323. SetDlgItemText(IDOK, m_pParentDlg->m_strAddElan.c_str());
  324. // Set the position of the pop up dialog to be right over the listbox
  325. // on parent dialog
  326. HWND hList = ::GetDlgItem(m_pParentDlg->m_hWnd, IDC_ELAN_LIST);
  327. RECT rect;
  328. ::GetWindowRect(hList, &rect);
  329. SetWindowPos(NULL, rect.left, rect.top, 0,0,
  330. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  331. // Save handle to the edit box
  332. m_hElanName = GetDlgItem(IDC_ELAN_NAME);
  333. // ELAN names have a 32 character limit
  334. ::SendMessage(m_hElanName, EM_SETLIMITTEXT, ELAN_NAME_LIMIT, 0);
  335. // fill in the edit box with the current elan's name
  336. ::SetWindowText(m_hElanName, m_pElanInfo->SzGetElanName());
  337. ::SendMessage(m_hElanName, EM_SETSEL, 0, -1);
  338. ::SetFocus(m_hElanName);
  339. return TRUE;
  340. }
  341. LRESULT CElanPropertiesDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  342. LPARAM lParam, BOOL& fHandled)
  343. {
  344. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  345. return 0;
  346. }
  347. LRESULT CElanPropertiesDialog::OnHelp(UINT uMsg, WPARAM wParam,
  348. LPARAM lParam, BOOL& fHandled)
  349. {
  350. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  351. Assert(lphi);
  352. if (HELPINFO_WINDOW == lphi->iContextType)
  353. {
  354. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  355. m_adwHelpIDs);
  356. }
  357. return 0;
  358. }
  359. LRESULT CElanPropertiesDialog::OnOk(WORD wNotifyCode, WORD wID,
  360. HWND hWndCtl, BOOL& fHandled)
  361. {
  362. WCHAR szElan[ELAN_NAME_LIMIT + 1];
  363. // Get the current name from the control and
  364. // store in the elan info
  365. ::GetWindowText(m_hElanName, szElan, ELAN_NAME_LIMIT + 1);
  366. m_pElanInfo->SetElanName(szElan);
  367. EndDialog(IDOK);
  368. return 0;
  369. }
  370. LRESULT CElanPropertiesDialog::OnCancel(WORD wNotifyCode, WORD wID,
  371. HWND hWndCtl, BOOL& fHandled)
  372. {
  373. EndDialog(IDCANCEL);
  374. return 0;
  375. }