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.

380 lines
10 KiB

  1. // ATlkDlg.cpp : Implementation of CATLKRoutingDlg and CATLKGeneralDlg
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include "atlkobj.h"
  5. #include "ncatlui.h"
  6. #include "ncui.h"
  7. #include "atlkhlp.h"
  8. extern const WCHAR c_szDevice[];
  9. extern const WCHAR c_szNetCfgHelpFile[];
  10. const WCHAR c_chAmpersand = L'&';
  11. const WCHAR c_chAsterisk = L'*';
  12. const WCHAR c_chColon = L':';
  13. const WCHAR c_chPeriod = L'.';
  14. const WCHAR c_chQuote = L'\"';
  15. const WCHAR c_chSpace = L' ';
  16. //
  17. // Function: PGetCurrentAdapterInfo
  18. //
  19. // Purpose: Based on the currently selected item in the adapter combobox.
  20. // Extract and return the AdapterInfo *
  21. //
  22. // Parameters: pATLKEnv [IN] - Enviroment block for this property page
  23. //
  24. // Returns: CAdapterInfo *, Pointer to the adapter info if it exists,
  25. // NULL otherwise
  26. //
  27. static CAdapterInfo *PGetCurrentAdapterInfo(CATLKEnv * pATLKEnv)
  28. {
  29. Assert(NULL != pATLKEnv);
  30. if (pATLKEnv->AdapterInfoList().empty())
  31. {
  32. return NULL;
  33. }
  34. else
  35. {
  36. return pATLKEnv->AdapterInfoList().front();
  37. }
  38. }
  39. //
  40. // Function: CATLKGeneralDlg::CATLKGeneralDlg
  41. //
  42. // Purpose: ctor for the CATLKGeneralDlg class
  43. //
  44. // Parameters: pmsc - Ptr to the ATLK notification object
  45. // pATLKEnv - Ptr to the current ATLK configuration
  46. //
  47. // Returns: nothing
  48. //
  49. CATLKGeneralDlg::CATLKGeneralDlg(CATlkObj *pmsc, CATLKEnv * pATLKEnv)
  50. {
  51. m_pmsc = pmsc;
  52. m_pATLKEnv = pATLKEnv;
  53. Assert(NULL != m_pATLKEnv);
  54. }
  55. //
  56. // Function: CATLKGeneralDlg::~CATLKGeneralDlg
  57. //
  58. // Purpose: dtor for the CATLKGeneralDlg class
  59. //
  60. // Parameters: none
  61. //
  62. // Returns: nothing
  63. //
  64. CATLKGeneralDlg::~CATLKGeneralDlg()
  65. {
  66. // Don't free m_pmsc or m_pATLKEnv, they're borrowed only
  67. }
  68. //
  69. // Function: CATLKGeneralDlg::HandleChkBox
  70. //
  71. // Purpose: Process the BN_PUSHBUTTON message for ATLK's General page
  72. //
  73. // Parameters: Standard ATL params
  74. //
  75. // Returns: LRESULT, 0L
  76. //
  77. LRESULT CATLKGeneralDlg::HandleChkBox(WORD wNotifyCode, WORD wID,
  78. HWND hWndCtl, BOOL& bHandled)
  79. {
  80. if (BN_CLICKED == wNotifyCode)
  81. {
  82. UINT uIsCheckBoxChecked;
  83. uIsCheckBoxChecked = IsDlgButtonChecked(CHK_GENERAL_DEFAULT);
  84. ::EnableWindow(GetDlgItem(CMB_GENERAL_ZONE),
  85. uIsCheckBoxChecked);
  86. ::EnableWindow(GetDlgItem(IDC_TXT_ZONELIST),
  87. uIsCheckBoxChecked);
  88. }
  89. return 0;
  90. }
  91. //
  92. // Function: CATLKGeneralDlg::OnInitDialog
  93. //
  94. // Purpose: Process the WM_INITDIALOG message for ATLK's General page
  95. //
  96. // Parameters: Standard ATL params
  97. //
  98. // Returns: LRESULT, 0L
  99. //
  100. LRESULT
  101. CATLKGeneralDlg::OnInitDialog(UINT uMsg, WPARAM wParam,
  102. LPARAM lParam, BOOL& bHandled)
  103. {
  104. tstring strDefPort;
  105. CAdapterInfo * pAI = PGetCurrentAdapterInfo(m_pATLKEnv);
  106. HWND hwndChk = GetDlgItem(CHK_GENERAL_DEFAULT);
  107. HCURSOR WaitCursor;
  108. WaitCursor = BeginWaitCursor();
  109. // If no adapters we're successfully added, disable everything
  110. if (NULL == pAI)
  111. {
  112. ::EnableWindow(hwndChk, FALSE);
  113. ::EnableWindow(GetDlgItem(CMB_GENERAL_ZONE), FALSE);
  114. ::EnableWindow(GetDlgItem(IDC_TXT_ZONELIST), FALSE);
  115. ::EnableWindow(::GetDlgItem(::GetParent(m_hWnd), IDOK), FALSE);
  116. EndWaitCursor(WaitCursor);
  117. return 0L;
  118. }
  119. // Retain what we currently consider the "Default" adapter
  120. strDefPort = c_szDevice;
  121. strDefPort += pAI->SzBindName();
  122. if (0 == _wcsicmp(strDefPort.c_str(), m_pATLKEnv->SzDefaultPort()))
  123. {
  124. ::CheckDlgButton(m_hWnd, CHK_GENERAL_DEFAULT, 1);
  125. ::EnableWindow(hwndChk, FALSE);
  126. }
  127. else
  128. {
  129. // Disable the zone combo if the current adapter is not the
  130. // default adapter.
  131. ::EnableWindow(GetDlgItem(CMB_GENERAL_ZONE), FALSE);
  132. ::EnableWindow(GetDlgItem(IDC_TXT_ZONELIST), FALSE);
  133. }
  134. // danielwe: RAID #347398: Hide the checkbox completely if this is a
  135. // LocalTalk adapter.
  136. //
  137. if (pAI->DwMediaType() == MEDIATYPE_LOCALTALK)
  138. {
  139. ::ShowWindow(GetDlgItem(CHK_GENERAL_DEFAULT), SW_HIDE);
  140. }
  141. // Populate the Zone dialog
  142. RefreshZoneCombo();
  143. SetChangedFlag();
  144. EndWaitCursor(WaitCursor);
  145. return 1L;
  146. }
  147. //
  148. // Function: CATLKGeneralDlg::RefreshZoneCombo()
  149. //
  150. // Purpose: Populate the Zone combo box with the supplied list of zones
  151. //
  152. // Parameters: pAI - Adapter info
  153. //
  154. // Returns: none
  155. //
  156. VOID CATLKGeneralDlg::RefreshZoneCombo()
  157. {
  158. HWND hwndComboZones = GetDlgItem(CMB_GENERAL_ZONE);
  159. INT nIdx;
  160. CAdapterInfo * pAI = PGetCurrentAdapterInfo(m_pATLKEnv);
  161. if (NULL == pAI)
  162. return; // No adapter selected, available
  163. ::SendMessage(hwndComboZones, CB_RESETCONTENT, 0, 0L);
  164. // Populate the Zone dialog
  165. if (!pAI->FSeedingNetwork() || !m_pATLKEnv->FRoutingEnabled())
  166. {
  167. // this port is not seeding the network
  168. // if we found a router on this port then add the found zone
  169. // list to the desired zone box. Else do nothing.
  170. if(pAI->FRouterOnNetwork())
  171. {
  172. if (pAI->LstpstrDesiredZoneList().empty())
  173. return;
  174. if (FALSE == FAddZoneListToControl(&pAI->LstpstrDesiredZoneList()))
  175. return;
  176. nIdx = ::SendMessage(hwndComboZones, CB_FINDSTRINGEXACT, -1,
  177. (LPARAM)m_pATLKEnv->SzDesiredZone());
  178. ::SendMessage(hwndComboZones, CB_SETCURSEL,
  179. ((CB_ERR == nIdx) ? 0 : nIdx), 0L);
  180. }
  181. }
  182. else
  183. {
  184. // This port is seeding the network, populate the zone list with the
  185. // zones managed by this port.
  186. if (pAI->LstpstrZoneList().empty())
  187. return;
  188. if (FALSE == FAddZoneListToControl(&pAI->LstpstrZoneList()))
  189. return;
  190. nIdx = ::SendMessage(hwndComboZones, CB_FINDSTRINGEXACT,
  191. -1, (LPARAM)m_pATLKEnv->SzDesiredZone());
  192. if (CB_ERR == nIdx)
  193. nIdx = ::SendMessage(hwndComboZones, CB_FINDSTRINGEXACT,
  194. -1, (LPARAM)pAI->SzDefaultZone());
  195. ::SendMessage(hwndComboZones, CB_SETCURSEL,
  196. ((CB_ERR == nIdx) ? 0 : nIdx), 0L);
  197. }
  198. }
  199. //
  200. // Function: CATLKGeneralDlg::FAddZoneListToControl
  201. //
  202. // Purpose: Populate the Zone combo box with the supplied list of zones
  203. //
  204. // Parameters: plstpstr - Pointer to a list of pointers to tstrings
  205. //
  206. // Returns: BOOL, TRUE if at least one zone was added to the combo box
  207. //
  208. BOOL CATLKGeneralDlg::FAddZoneListToControl(list<tstring*> * plstpstr)
  209. {
  210. HWND hwndComboZones = GetDlgItem(CMB_GENERAL_ZONE);
  211. list<tstring*>::iterator iter;
  212. tstring * pstr;
  213. Assert(NULL != plstpstr);
  214. for (iter = plstpstr->begin();
  215. iter != plstpstr->end();
  216. iter++)
  217. {
  218. pstr = *iter;
  219. ::SendMessage(hwndComboZones, CB_ADDSTRING, 0, (LPARAM)pstr->c_str());
  220. }
  221. return (0 != ::SendMessage(hwndComboZones, CB_GETCOUNT, 0, 0L));
  222. }
  223. //
  224. // Function: CATLKGeneralDlg::OnOk
  225. //
  226. // Purpose: Process the PSN_APPLY notification for the property page
  227. //
  228. // Parameters: Standard ATL params
  229. //
  230. // Returns: LRESULT, 0L
  231. //
  232. LRESULT
  233. CATLKGeneralDlg::OnOk(INT idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  234. {
  235. INT nIdx;
  236. CAdapterInfo * pAI = PGetCurrentAdapterInfo(m_pATLKEnv);
  237. HWND hwndComboZones = GetDlgItem(CMB_GENERAL_ZONE);
  238. if (NULL == pAI)
  239. {
  240. return 0;
  241. }
  242. if (IsDlgButtonChecked(CHK_GENERAL_DEFAULT))
  243. {
  244. tstring strPortName;
  245. // Retain adapter selection as the default port
  246. //
  247. strPortName = c_szDevice;
  248. strPortName += pAI->SzBindName();
  249. if (wcscmp(strPortName.c_str(), m_pATLKEnv->SzDefaultPort()))
  250. {
  251. m_pATLKEnv->SetDefaultPort(strPortName.c_str());
  252. m_pATLKEnv->SetDefAdapterChanged(TRUE);
  253. // Tell the user what checking the box means...
  254. //
  255. tstring str;
  256. str = SzLoadIds(IDS_ATLK_INBOUND_MSG1);
  257. str += SzLoadIds(IDS_ATLK_INBOUND_MSG2);
  258. ::MessageBox(m_hWnd, str.c_str(),
  259. SzLoadIds(IDS_CAPTION_NETCFG), MB_OK);
  260. }
  261. }
  262. else
  263. {
  264. // If the check box is not checked then the zone combo is
  265. // disabled and its contents don't need to be retained.
  266. return 0;
  267. }
  268. // Retain the zone selection as the default zone
  269. nIdx = ::SendMessage(hwndComboZones, CB_GETCURSEL, 0, 0L);
  270. if (CB_ERR != nIdx)
  271. {
  272. WCHAR szBuf[MAX_ZONE_NAME_LEN + 1];
  273. if (CB_ERR != ::SendMessage(hwndComboZones, CB_GETLBTEXT, nIdx,
  274. (LPARAM)(PCWSTR)szBuf))
  275. {
  276. // If the new zone is different then the original, then
  277. // mark the adapter as dirty
  278. if (0 != _wcsicmp(szBuf, m_pATLKEnv->SzDesiredZone()))
  279. {
  280. // If the earlier desired zone was NOT NULL, only then
  281. // mark adapter dirty to request a PnP to the stack
  282. if (0 != _wcsicmp(c_szEmpty, m_pATLKEnv->SzDesiredZone()))
  283. {
  284. pAI->SetDirty(TRUE);
  285. }
  286. }
  287. m_pATLKEnv->SetDesiredZone(szBuf);
  288. }
  289. }
  290. return 0;
  291. }
  292. //+---------------------------------------------------------------------------
  293. //
  294. // Method: CATLKGeneralDlg::OnContextMenu
  295. //
  296. // Desc: Bring up context-sensitive help
  297. //
  298. // Args: Standard command parameters
  299. //
  300. // Return: LRESULT
  301. //
  302. LRESULT
  303. CATLKGeneralDlg::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  304. {
  305. if (g_aHelpIDs_DLG_ATLK_GENERAL != NULL)
  306. {
  307. ::WinHelp(m_hWnd,
  308. c_szNetCfgHelpFile,
  309. HELP_CONTEXTMENU,
  310. (ULONG_PTR)g_aHelpIDs_DLG_ATLK_GENERAL);
  311. }
  312. return 0;
  313. }
  314. //+---------------------------------------------------------------------------
  315. //
  316. // Method: CATLKGeneralDlg::OnHelp
  317. //
  318. // Desc: Bring up context-sensitive help when dragging ? icon over a control
  319. //
  320. // Args: Standard command parameters
  321. //
  322. // Return: LRESULT
  323. //
  324. //
  325. LRESULT
  326. CATLKGeneralDlg::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& fHandled)
  327. {
  328. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  329. Assert(lphi);
  330. if ((g_aHelpIDs_DLG_ATLK_GENERAL != NULL) && (HELPINFO_WINDOW == lphi->iContextType))
  331. {
  332. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  333. c_szNetCfgHelpFile,
  334. HELP_WM_HELP,
  335. (ULONG_PTR)g_aHelpIDs_DLG_ATLK_GENERAL);
  336. }
  337. return 0;
  338. }