Leaked source code of windows server 2003
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.

366 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: L A N W I Z . C P P
  7. //
  8. // Contents: Implementation of the LAN wizard page
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl 16 Oct 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "devdatatip.h"
  18. #include "lanwiz.h"
  19. #include "ncsetup.h"
  20. #include "util.h"
  21. #include "ncui.h"
  22. // Constructor and Destructor
  23. CLanWizPage::CLanWizPage(IUnknown * punk)
  24. {
  25. Assert(punk);
  26. m_punk = punk;
  27. m_pnc = NULL;
  28. m_pnccAdapter = NULL;
  29. m_hwndList = NULL;
  30. m_hilCheckIcons = NULL;
  31. m_fReadOnly = FALSE;
  32. m_hwndDataTip = NULL;
  33. }
  34. // Methods that set the Netcfg interfaces the dialog needs.
  35. // Should be only by INetLanConnectionWizardUi->SetDeviceComponent
  36. // and right before initializing the wizard dialog each time
  37. HRESULT CLanWizPage::SetNetcfg(INetCfg * pnc)
  38. {
  39. Assert(pnc);
  40. if (m_pnc)
  41. {
  42. // Release it
  43. ReleaseObj(m_pnc);
  44. }
  45. m_pnc = pnc;
  46. AddRefObj(pnc);
  47. return S_OK;
  48. }
  49. HRESULT CLanWizPage::SetAdapter(INetCfgComponent * pnccAdapter)
  50. {
  51. Assert(pnccAdapter);
  52. if (m_pnccAdapter)
  53. {
  54. // Release it
  55. ReleaseObj(m_pnccAdapter);
  56. }
  57. m_pnccAdapter = pnccAdapter;
  58. AddRefObj(pnccAdapter);
  59. return S_OK;
  60. }
  61. // Initialize dialog
  62. LRESULT CLanWizPage::OnInitDialog(UINT uMsg, WPARAM wParam,
  63. LPARAM lParam, BOOL& fHandled)
  64. {
  65. m_hwndList = GetDlgItem(IDC_LVW_COMPLIST);
  66. m_Handles.m_hList = m_hwndList;
  67. m_Handles.m_hAdd = GetDlgItem(IDC_PSH_ADD);
  68. m_Handles.m_hRemove = GetDlgItem(IDC_PSH_REMOVE);
  69. m_Handles.m_hProperty = GetDlgItem(IDC_PSH_PROPERTIES);
  70. m_Handles.m_hDescription = GetDlgItem(IDC_TXT_COMPDESC);
  71. // set the font of the device description: IDC_DEVICE_DESC to bold
  72. HFONT hCurFont = (HFONT)::SendMessage(GetDlgItem(IDC_DEVICE_DESC), WM_GETFONT, 0,0);
  73. if (hCurFont) // if not using system font
  74. {
  75. int cbBuffer;
  76. cbBuffer = GetObject(hCurFont, 0, NULL);
  77. if (cbBuffer)
  78. {
  79. void * lpvObject = new BYTE[cbBuffer];
  80. if (lpvObject)
  81. {
  82. int nRet = GetObject(hCurFont, cbBuffer, lpvObject);
  83. if (nRet)
  84. {
  85. LOGFONT * pLogFont =
  86. reinterpret_cast<LOGFONT *>(lpvObject);
  87. pLogFont->lfWeight = FW_BOLD;
  88. HFONT hNewFont = CreateFontIndirect(pLogFont);
  89. if (hNewFont)
  90. {
  91. ::SendMessage(GetDlgItem(IDC_DEVICE_DESC), WM_SETFONT, (WPARAM)hNewFont, TRUE);
  92. }
  93. }
  94. delete[] lpvObject;
  95. }
  96. }
  97. }
  98. return 0;
  99. }
  100. // Destroy dialog
  101. LRESULT CLanWizPage::OnDestroyDialog(UINT uMsg, WPARAM wParam,
  102. LPARAM lParam, BOOL& fHandled)
  103. {
  104. // Release netcfg interfaces, they should be reinitialized
  105. // the next time the dialog is brought up
  106. ReleaseObj(m_pnc);
  107. ReleaseObj(m_pnccAdapter);
  108. UninitListView(m_hwndList);
  109. // Destroy our check icons
  110. if (m_hilCheckIcons)
  111. {
  112. ImageList_Destroy(m_hilCheckIcons);
  113. }
  114. // release binding path objects and component objects we kept
  115. ReleaseAll(m_hwndList, &m_listBindingPaths);
  116. return 0;
  117. }
  118. // Wizard page notification handlers
  119. LRESULT CLanWizPage::OnActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  120. {
  121. HRESULT hr = S_OK;
  122. // Fill in the adapter description
  123. AssertSz(m_pnccAdapter, "We don't have a valid adapter!");
  124. if (m_pnccAdapter)
  125. {
  126. PWSTR pszwDeviceName;
  127. hr = m_pnccAdapter->GetDisplayName(&pszwDeviceName);
  128. if (SUCCEEDED(hr))
  129. {
  130. SetDlgItemText(IDC_DEVICE_DESC, pszwDeviceName);
  131. CoTaskMemFree(pszwDeviceName);
  132. }
  133. // Create a data tip for the device to display location
  134. // info and MAc address.
  135. //
  136. PWSTR pszDevNodeId = NULL;
  137. PWSTR pszBindName = NULL;
  138. // Get the pnp instance id of the device.
  139. (VOID) m_pnccAdapter->GetPnpDevNodeId (&pszDevNodeId);
  140. // Get the device's bind name
  141. (VOID) m_pnccAdapter->GetBindName (&pszBindName);
  142. // Create the tip and associate it with the description control.
  143. // Note if the tip was already created, then only the text
  144. // will be modified.
  145. //
  146. CreateDeviceDataTip (m_hWnd, &m_hwndDataTip, IDC_DEVICE_DESC,
  147. pszDevNodeId, pszBindName);
  148. CoTaskMemFree (pszDevNodeId);
  149. CoTaskMemFree (pszBindName);
  150. }
  151. // refresh the listview for the new adapter
  152. // Now setup the BindingPathObj collection and List view
  153. hr = HrInitListView(m_hwndList, m_pnc, m_pnccAdapter,
  154. &m_listBindingPaths, &m_hilCheckIcons);
  155. // now set the buttons
  156. LvSetButtons(m_hWnd, m_Handles, m_fReadOnly, m_punk);
  157. ::PostMessage(::GetParent(m_hWnd),
  158. PSM_SETWIZBUTTONS,
  159. (WPARAM)0,
  160. (LPARAM)(PSWIZB_BACK | PSWIZB_NEXT));
  161. return 0;
  162. }
  163. LRESULT CLanWizPage::OnKillActive(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  164. {
  165. BOOL fError;
  166. fError = FValidatePageContents( m_hWnd,
  167. m_Handles.m_hList,
  168. m_pnc,
  169. m_pnccAdapter,
  170. &m_listBindingPaths
  171. );
  172. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, fError);
  173. return fError;
  174. }
  175. // Push button handlers
  176. LRESULT CLanWizPage::OnAdd(WORD wNotifyCode, WORD wID,
  177. HWND hWndCtl, BOOL& fHandled)
  178. {
  179. HRESULT hr = S_OK;
  180. // $REVIEW(tongl 1/7/99): We can't let user do anything till this
  181. // is returned (Raid #258690)
  182. // disable all buttons on this dialog
  183. static const int nrgIdc[] = {IDC_PSB_Add,
  184. IDC_PSB_Remove,
  185. IDC_PSB_Properties};
  186. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  187. // disable wizard buttons till we are done
  188. ::SendMessage(GetParent(), PSM_SETWIZBUTTONS, 0, 0);
  189. hr = HrLvAdd(m_hwndList, m_hWnd, m_pnc, m_pnccAdapter, &m_listBindingPaths);
  190. // Reset the buttons and the description text based on the changed selection
  191. LvSetButtons(m_hWnd, m_Handles, m_fReadOnly, m_punk);
  192. ::SendMessage(GetParent(), PSM_SETWIZBUTTONS, 0, (LPARAM)(PSWIZB_NEXT | PSWIZB_BACK));
  193. TraceError("CLanWizPage::OnAdd", hr);
  194. return 0;
  195. }
  196. LRESULT CLanWizPage::OnRemove(WORD wNotifyCode, WORD wID,
  197. HWND hWndCtl, BOOL& fHandled)
  198. {
  199. HRESULT hr = S_OK;
  200. // $REVIEW(tongl 1/7/99): We can't let user do anything till this
  201. // is returned (Raid #258690)
  202. // disable all buttons on this dialog
  203. static const int nrgIdc[] = {IDC_PSB_Add,
  204. IDC_PSB_Remove,
  205. IDC_PSB_Properties};
  206. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  207. hr = HrLvRemove(m_hwndList, m_hWnd, m_pnc, m_pnccAdapter,
  208. &m_listBindingPaths);
  209. if (NETCFG_S_REBOOT == hr)
  210. {
  211. // tell the user the component they removed cannot be re-added until
  212. // setup completes
  213. //$REVIEW - scottbri - Notifing the user maybe optional,
  214. //$REVIEW as little can be done on their part
  215. }
  216. // Reset the buttons and the description text based on the changed selection
  217. LvSetButtons(m_hWnd, m_Handles, m_fReadOnly, m_punk);
  218. TraceError("CLanWizPage::OnRemove", hr);
  219. return 0;
  220. }
  221. LRESULT CLanWizPage::OnProperties(WORD wNotifyCode, WORD wID,
  222. HWND hWndCtl, BOOL& fHandled)
  223. {
  224. HRESULT hr = S_OK;
  225. // $REVIEW(tongl 1/7/99): We can't let user do anything till this
  226. // is returned (Raid #258690)
  227. // disable all buttons on this dialog
  228. static const int nrgIdc[] = {IDC_PSB_Add,
  229. IDC_PSB_Remove,
  230. IDC_PSB_Properties};
  231. EnableOrDisableDialogControls(m_hWnd, celems(nrgIdc), nrgIdc, FALSE);
  232. // disable wizard buttons till we are done
  233. ::SendMessage(GetParent(), PSM_SETWIZBUTTONS, 0, 0);
  234. hr = HrLvProperties(m_hwndList, m_hWnd, m_pnc, m_punk,
  235. m_pnccAdapter, &m_listBindingPaths, NULL);
  236. // Reset the buttons and the description text based on the changed selection
  237. LvSetButtons(m_hWnd, m_Handles, m_fReadOnly, m_punk);
  238. ::SendMessage(GetParent(), PSM_SETWIZBUTTONS, 0, (LPARAM)(PSWIZB_NEXT | PSWIZB_BACK));
  239. TraceError("CLanWizPage::OnProperties", hr);
  240. return 0;
  241. }
  242. // List view handlers
  243. LRESULT CLanWizPage::OnClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  244. {
  245. if (idCtrl == IDC_LVW_COMPLIST)
  246. {
  247. OnListClick(m_hwndList, m_hWnd, m_pnc, m_punk,
  248. m_pnccAdapter, &m_listBindingPaths, FALSE);
  249. }
  250. return 0;
  251. }
  252. LRESULT CLanWizPage::OnDbClick(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  253. {
  254. if (idCtrl == IDC_LVW_COMPLIST)
  255. {
  256. // If we're in read-only mode, treat a double click as a single click
  257. //
  258. OnListClick(m_hwndList, m_hWnd, m_pnc, m_punk,
  259. m_pnccAdapter, &m_listBindingPaths, !m_fReadOnly);
  260. }
  261. return 0;
  262. }
  263. LRESULT CLanWizPage::OnKeyDown(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  264. {
  265. if (idCtrl == IDC_LVW_COMPLIST)
  266. {
  267. LV_KEYDOWN* plvkd = (LV_KEYDOWN*)pnmh;
  268. OnListKeyDown(m_hwndList, &m_listBindingPaths, plvkd->wVKey);
  269. }
  270. return 0;
  271. }
  272. LRESULT CLanWizPage::OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& fHandled)
  273. {
  274. // Reset the buttons and the description text based on the changed selection
  275. LvSetButtons(m_hWnd, m_Handles, m_fReadOnly, m_punk);
  276. return 0;
  277. }
  278. LRESULT CLanWizPage::OnDeleteItem(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  279. {
  280. NM_LISTVIEW * pnmlv = reinterpret_cast<NM_LISTVIEW *>(pnmh);
  281. LvDeleteItem(m_hwndList, pnmlv->iItem);
  282. return 0;
  283. }