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.

496 lines
12 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: A U N I D L G . C P P
  7. //
  8. // Contents: ATMUNI call manager dialogbox message handler implementation
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 21 Mar 1997
  13. //
  14. //-----------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "arpsobj.h"
  18. #include "auniobj.h"
  19. #include "atmutil.h"
  20. #include "aunidlg.h"
  21. #include "ncatlui.h"
  22. #include "ncstl.h"
  23. //#include "ncui.h"
  24. #include "atmhelp.h"
  25. const int c_nColumns =3;
  26. const int c_nMAX_PVC_ID_LEN =10;
  27. //
  28. // CUniPage
  29. //
  30. CUniPage::CUniPage(CAtmUniCfg * pAtmUniCfg, const DWORD * adwHelpIDs)
  31. {
  32. Assert(pAtmUniCfg);
  33. m_patmunicfg = pAtmUniCfg;
  34. m_adwHelpIDs = adwHelpIDs;
  35. m_pAdapterInfo = pAtmUniCfg->GetSecondMemoryAdapterInfo();
  36. m_fModified = FALSE;
  37. }
  38. CUniPage::~CUniPage()
  39. {
  40. }
  41. LRESULT CUniPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  42. LPARAM lParam, BOOL& bHandled)
  43. {
  44. // initialize PVC name list view
  45. int nIndex;
  46. m_hPVCList = GetDlgItem(IDC_LVW_PVC_LIST);
  47. // Calculate column width
  48. RECT rect;
  49. ::GetClientRect(m_hPVCList, &rect);
  50. int colWidth = (rect.right/(c_nColumns*2));
  51. // set the column header
  52. // The mask specifies that the fmt, width and pszText members
  53. // of the structure are valid
  54. LV_COLUMN lvCol = {0};
  55. lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
  56. lvCol.fmt = LVCFMT_LEFT; // left-align column
  57. // Add the two columns and header text.
  58. for (nIndex = 0; nIndex < c_nColumns; nIndex++)
  59. {
  60. // column header text
  61. if (0 == nIndex) // first column
  62. {
  63. lvCol.cx = colWidth*4;
  64. lvCol.pszText = (PWSTR) SzLoadIds(IDS_PVC_NAME);
  65. }
  66. else if (1 == nIndex)
  67. {
  68. lvCol.cx = colWidth;
  69. lvCol.pszText = (PWSTR) SzLoadIds(IDS_PVC_VPI);
  70. }
  71. else if (2 == nIndex)
  72. {
  73. lvCol.cx = colWidth;
  74. lvCol.pszText = (PWSTR) SzLoadIds(IDS_PVC_VCI);
  75. }
  76. int iNewItem = ListView_InsertColumn(GetDlgItem(IDC_LVW_PVC_LIST),
  77. nIndex, &lvCol);
  78. AssertSz((iNewItem == nIndex), "Invalid item inserted to list view !");
  79. }
  80. // insert existing PVCs into the list view
  81. int idx =0;
  82. for (PVC_INFO_LIST::iterator iterPvc = m_pAdapterInfo->m_listPVCs.begin();
  83. iterPvc != m_pAdapterInfo->m_listPVCs.end();
  84. iterPvc ++)
  85. {
  86. if ((*iterPvc)->m_fDeleted)
  87. continue;
  88. InsertNewPvc(*iterPvc, idx);
  89. idx++;
  90. }
  91. // select the first item
  92. ListView_SetItemState(GetDlgItem(IDC_LVW_PVC_LIST), 0, LVIS_SELECTED, LVIS_SELECTED);
  93. SetButtons();
  94. return 0;
  95. }
  96. LRESULT CUniPage::OnContextMenu(UINT uMsg, WPARAM wParam,
  97. LPARAM lParam, BOOL& fHandled)
  98. {
  99. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  100. return 0;
  101. }
  102. LRESULT CUniPage::OnHelp(UINT uMsg, WPARAM wParam,
  103. LPARAM lParam, BOOL& fHandled)
  104. {
  105. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  106. Assert(lphi);
  107. if (HELPINFO_WINDOW == lphi->iContextType)
  108. {
  109. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  110. m_adwHelpIDs);
  111. }
  112. return 0;
  113. }
  114. LRESULT CUniPage::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  115. {
  116. BOOL nResult = PSNRET_NOERROR;
  117. if (!IsModified())
  118. {
  119. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  120. return nResult;
  121. }
  122. m_patmunicfg->SetSecondMemoryModified();
  123. SetModifiedTo(FALSE); // this page is no longer modified
  124. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, nResult);
  125. return nResult;
  126. }
  127. LRESULT CUniPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  128. {
  129. BOOL err = FALSE;
  130. // Error checking: unique Vci\Vpi pair
  131. int iDupPvcIdx = CheckDupPvcId();
  132. if (iDupPvcIdx >=0)
  133. {
  134. NcMsgBox(m_hWnd, IDS_MSFT_UNI_TEXT, IDS_DUPLICATE_PVC,
  135. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  136. ListView_SetItemState(GetDlgItem(IDC_LVW_PVC_LIST), iDupPvcIdx,
  137. LVIS_SELECTED, LVIS_SELECTED);
  138. err = TRUE;
  139. }
  140. return err;
  141. }
  142. int CUniPage::CheckDupPvcId()
  143. {
  144. int ret = -1;
  145. int idx = 0;
  146. for(PVC_INFO_LIST::iterator iterPvc = m_pAdapterInfo->m_listPVCs.begin();
  147. iterPvc != m_pAdapterInfo->m_listPVCs.end();
  148. iterPvc ++)
  149. {
  150. if ((*iterPvc)->m_fDeleted)
  151. continue;
  152. PVC_INFO_LIST::iterator iterPvcComp = iterPvc;
  153. iterPvcComp ++;
  154. while (iterPvcComp != m_pAdapterInfo->m_listPVCs.end())
  155. {
  156. if (!(*iterPvcComp)->m_fDeleted)
  157. {
  158. if ( ((*iterPvc)->m_dwVpi == (*iterPvcComp)->m_dwVpi) &&
  159. ((*iterPvc)->m_dwVci == (*iterPvcComp)->m_dwVci))
  160. {
  161. // we find a duplicate address
  162. ret = idx;
  163. break;
  164. }
  165. }
  166. iterPvcComp++;
  167. }
  168. // duplicate address found
  169. if (ret >=0 )
  170. break;
  171. // move next
  172. idx ++;
  173. }
  174. return ret;
  175. }
  176. LRESULT CUniPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  177. {
  178. return 0;
  179. }
  180. LRESULT CUniPage::OnCancel(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  181. {
  182. return 0;
  183. }
  184. LRESULT CUniPage::OnAddPVC(WORD wNotifyCode, WORD wID,
  185. HWND hWndCtl, BOOL& bHandled)
  186. {
  187. // make a new PVC Info structure and pass to the dialog
  188. tstring strNewPvcId;
  189. GetNewPvcId(m_pAdapterInfo, &strNewPvcId);
  190. CPvcInfo * pDlgPvcInfo = new CPvcInfo(strNewPvcId.c_str());
  191. if (pDlgPvcInfo == NULL)
  192. {
  193. return(ERROR_NOT_ENOUGH_MEMORY);
  194. }
  195. pDlgPvcInfo->m_dwPVCType = PVC_CUSTOM;
  196. pDlgPvcInfo->SetDefaults(PVC_CUSTOM);
  197. CPVCMainDialog * pPvcMainDlg = new CPVCMainDialog(this, pDlgPvcInfo,
  198. g_aHelpIDs_IDD_PVC_Main);
  199. if (pPvcMainDlg == NULL)
  200. {
  201. return(ERROR_NOT_ENOUGH_MEMORY);
  202. }
  203. if (pPvcMainDlg->DoModal() == IDOK)
  204. {
  205. // add the new PVC
  206. m_pAdapterInfo->m_listPVCs.push_back(pDlgPvcInfo);
  207. int nCount = ListView_GetItemCount(m_hPVCList);
  208. // insert the new item at the end of list
  209. InsertNewPvc(pDlgPvcInfo, nCount);
  210. SetButtons();
  211. PageModified();
  212. }
  213. else
  214. {
  215. delete pDlgPvcInfo;
  216. }
  217. delete pPvcMainDlg;
  218. return 0;
  219. }
  220. LRESULT CUniPage::OnPVCProperties(WORD wNotifyCode, WORD wID,
  221. HWND hWndCtl, BOOL& bHandled)
  222. {
  223. // mark the PVC as deleted and from the list view
  224. // get the current selected item and remove it
  225. int iSelected = ListView_GetNextItem(m_hPVCList, -1, LVNI_SELECTED);
  226. if (iSelected != -1)
  227. {
  228. LV_ITEM lvItem;
  229. lvItem.mask = LVIF_PARAM;
  230. lvItem.iItem = iSelected;
  231. lvItem.iSubItem = 0;
  232. if (ListView_GetItem(m_hPVCList, &lvItem))
  233. {
  234. CPvcInfo * pPvcInfo = NULL;
  235. pPvcInfo = reinterpret_cast<CPvcInfo *>(lvItem.lParam);
  236. if (pPvcInfo)
  237. {
  238. CPvcInfo * pDlgPvcInfo = new CPvcInfo(pPvcInfo->m_strPvcId.c_str());
  239. if (pDlgPvcInfo)
  240. {
  241. *pDlgPvcInfo = *pPvcInfo;
  242. CPVCMainDialog * pPvcMainDlg = new CPVCMainDialog(this, pDlgPvcInfo,
  243. g_aHelpIDs_IDD_PVC_Main);
  244. if (pPvcMainDlg->DoModal() == IDOK)
  245. {
  246. // update PVC info
  247. *pPvcInfo = *pDlgPvcInfo;
  248. // update the list view
  249. UpdatePvc(pDlgPvcInfo, iSelected);
  250. // set the new state of the Add\Remove\Property buttons
  251. SetButtons();
  252. if (pPvcMainDlg->m_fDialogModified)
  253. PageModified();
  254. }
  255. delete pDlgPvcInfo;
  256. delete pPvcMainDlg;
  257. }
  258. }
  259. }
  260. }
  261. else // no current selection
  262. {
  263. NcMsgBox(::GetActiveWindow(), IDS_MSFT_UNI_TEXT, IDS_NO_ITEM_SELECTED,
  264. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  265. }
  266. return 0;
  267. }
  268. LRESULT CUniPage::OnRemovePVC(WORD wNotifyCode, WORD wID,
  269. HWND hWndCtl, BOOL& bHandled)
  270. {
  271. // get the selected PVC, make a copy and pass to the dialog
  272. int iSelected = ListView_GetNextItem(m_hPVCList, -1, LVNI_SELECTED);
  273. if (iSelected != -1)
  274. {
  275. LV_ITEM lvItem;
  276. lvItem.mask = LVIF_PARAM;
  277. lvItem.iItem = iSelected;
  278. lvItem.iSubItem = 0;
  279. if (ListView_GetItem(m_hPVCList, &lvItem))
  280. {
  281. CPvcInfo * pPvcInfo = NULL;
  282. pPvcInfo = reinterpret_cast<CPvcInfo *>(lvItem.lParam);
  283. if (pPvcInfo)
  284. {
  285. // mark as deleted
  286. pPvcInfo->m_fDeleted = TRUE;
  287. // delete from list view
  288. ListView_DeleteItem(m_hPVCList, iSelected);
  289. }
  290. }
  291. SetButtons();
  292. PageModified();
  293. }
  294. return 0;
  295. }
  296. LRESULT CUniPage::OnPVCListChange(WORD wNotifyCode, WORD wID,
  297. HWND hWndCtl, BOOL& bHandled)
  298. {
  299. return 0;
  300. }
  301. void CUniPage::InsertNewPvc(CPvcInfo * pPvcInfo, int idx)
  302. {
  303. LV_ITEM lvItem = {0};
  304. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  305. int ret;
  306. // name
  307. lvItem.iItem = idx;
  308. lvItem.iSubItem=0;
  309. lvItem.lParam = reinterpret_cast<LPARAM>(pPvcInfo);
  310. lvItem.pszText = (PWSTR)(pPvcInfo->m_strName.c_str());
  311. ret = ListView_InsertItem(m_hPVCList, &lvItem);
  312. // VPI
  313. lvItem.iItem = idx;
  314. lvItem.iSubItem=1;
  315. WCHAR szVpi[MAX_VPI_LENGTH];
  316. wsprintfW(szVpi, c_szItoa, pPvcInfo->m_dwVpi);
  317. lvItem.pszText = szVpi;
  318. SendDlgItemMessage(IDC_LVW_PVC_LIST, LVM_SETITEMTEXT, idx, (LPARAM)&lvItem);
  319. // VCI
  320. lvItem.iItem = idx;
  321. lvItem.iSubItem=2;
  322. WCHAR szVci[MAX_VCI_LENGTH];
  323. wsprintfW(szVci, c_szItoa, pPvcInfo->m_dwVci);
  324. lvItem.pszText = szVci;
  325. SendDlgItemMessage(IDC_LVW_PVC_LIST, LVM_SETITEMTEXT, idx, (LPARAM)&lvItem);
  326. }
  327. void CUniPage::UpdatePvc(CPvcInfo * pPvcInfo, int idx)
  328. {
  329. LV_ITEM lvItem = {0};
  330. lvItem.mask = LVIF_TEXT;
  331. int ret;
  332. // name
  333. lvItem.iItem = idx;
  334. lvItem.iSubItem=0;
  335. lvItem.pszText = (PWSTR)(pPvcInfo->m_strName.c_str());
  336. ret = SendDlgItemMessage(IDC_LVW_PVC_LIST, LVM_SETITEMTEXT, idx, (LPARAM)&lvItem);
  337. // VPI
  338. lvItem.iItem = idx;
  339. lvItem.iSubItem=1;
  340. WCHAR szVpi[MAX_VPI_LENGTH];
  341. wsprintfW(szVpi, c_szItoa, pPvcInfo->m_dwVpi);
  342. lvItem.pszText = szVpi;
  343. ret = SendDlgItemMessage(IDC_LVW_PVC_LIST, LVM_SETITEMTEXT, idx, (LPARAM)&lvItem);
  344. // VCI
  345. lvItem.iItem = idx;
  346. lvItem.iSubItem=2;
  347. WCHAR szVci[MAX_VCI_LENGTH];
  348. wsprintfW(szVci, c_szItoa, pPvcInfo->m_dwVci);
  349. lvItem.pszText = szVci;
  350. ret = SendDlgItemMessage(IDC_LVW_PVC_LIST, LVM_SETITEMTEXT, idx, (LPARAM)&lvItem);
  351. }
  352. void CUniPage::SetButtons()
  353. {
  354. int nCount = ListView_GetItemCount(m_hPVCList);
  355. if (nCount == 0)
  356. ::SetFocus(m_hPVCList);
  357. ::EnableWindow(GetDlgItem(IDC_PBN_PVC_Remove), nCount);
  358. ::EnableWindow(GetDlgItem(IDC_PBN_PVC_Properties), nCount);
  359. }
  360. void CUniPage::GetNewPvcId(CUniAdapterInfo * pAdapterInfo,
  361. tstring * pstrNewPvcId)
  362. {
  363. Assert(pstrNewPvcId);
  364. tstring strPvcId;
  365. WCHAR szPvcId[c_nMAX_PVC_ID_LEN];
  366. int uiPvcNum = pAdapterInfo->m_listPVCs.size();
  367. _itow(uiPvcNum, szPvcId, 10);
  368. strPvcId = c_szPVC;
  369. strPvcId += szPvcId;
  370. while (!IsUniquePvcId(pAdapterInfo, strPvcId))
  371. {
  372. uiPvcNum++;
  373. _itow(uiPvcNum, szPvcId, 10);
  374. strPvcId = c_szPVC;
  375. strPvcId += szPvcId;
  376. }
  377. *pstrNewPvcId = strPvcId;
  378. }
  379. BOOL CUniPage::IsUniquePvcId(CUniAdapterInfo * pAdapterInfo,
  380. tstring& strNewPvcId)
  381. {
  382. BOOL fUnique = TRUE;
  383. for (PVC_INFO_LIST::iterator iterPvcInfo = pAdapterInfo->m_listPVCs.begin();
  384. iterPvcInfo != pAdapterInfo->m_listPVCs.end();
  385. iterPvcInfo++)
  386. {
  387. if (strNewPvcId == (*iterPvcInfo)->m_strName)
  388. {
  389. fUnique = FALSE;
  390. break;
  391. }
  392. }
  393. return fUnique;
  394. }