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.

377 lines
13 KiB

  1. /*
  2. * c o n n e c t . c p p
  3. *
  4. * Purpose:
  5. * Implements connection dialog tab page
  6. *
  7. * Owner:
  8. * brettm.
  9. *
  10. * Copyright (C) Microsoft Corp. 1993, 1994.
  11. */
  12. #include "pch.hxx"
  13. #include <commctrl.h>
  14. #include <imnxport.h>
  15. #include "acctman.h"
  16. #include "acctui.h"
  17. #include "connect.h"
  18. #include "dllmain.h"
  19. #include "resource.h"
  20. #include "accthelp.h"
  21. #include "server.h"
  22. #include "demand.h"
  23. ASSERTDATA
  24. /*
  25. * p r o t o t y p e s
  26. *
  27. */
  28. void EnableConnectoidWindows(HWND hwnd)
  29. {
  30. BOOL fEnable, fLan;
  31. HWND hwndCombo, hwndModem;
  32. hwndModem = GetDlgItem(hwnd, IDC_MODEM_CHECK);
  33. fLan = (BST_CHECKED == IsDlgButtonChecked(hwnd, idcLan));
  34. if (hwndModem != NULL)
  35. EnableWindow(hwndModem, fLan);
  36. if (fLan &&
  37. hwndModem != NULL &&
  38. BST_CHECKED == Button_GetCheck(hwndModem))
  39. fEnable = TRUE;
  40. else if (BST_CHECKED == IsDlgButtonChecked(hwnd, idcRas))
  41. fEnable = TRUE;
  42. else
  43. fEnable = FALSE;
  44. hwndCombo = GetDlgItem(hwnd, idcRasConnection);
  45. EnableWindow(hwndCombo, fEnable);
  46. EnableWindow(GetDlgItem(hwnd, idcRasAdd), fEnable);
  47. EnableWindow(GetDlgItem(hwnd, idcRasDesc), fEnable);
  48. EnableWindow(GetDlgItem(hwnd, idchkConnectOnStartup), fEnable);
  49. if (fEnable)
  50. fEnable = (ComboBox_GetCurSel(hwndCombo) != CB_ERR);
  51. EnableWindow(GetDlgItem(hwnd, idcRasProp), fEnable);
  52. }
  53. void ConnectPage_InitDialog(HWND hwnd, LPSTR szEntryName, LPSTR szBackup, DWORD iConnectType, BOOL fFirstInit)
  54. {
  55. HWND hwndCombo, hwndModem;
  56. int iSel;
  57. DWORD dw;
  58. Assert(szEntryName != NULL);
  59. hwndCombo = GetDlgItem(hwnd, idcRasConnection);
  60. if (fFirstInit)
  61. {
  62. SetIntlFont(hwndCombo);
  63. HrFillRasCombo(hwndCombo, FALSE, NULL);
  64. }
  65. // Fill in the connection type and if the person already has a
  66. // RAS connection set up make the combo box select that one by
  67. // default
  68. CheckRadioButton(hwnd, idcLan, idcRas, idcLan + iConnectType);
  69. hwndModem = GetDlgItem(hwnd, IDC_MODEM_CHECK);
  70. if (iConnectType == CONNECTION_TYPE_LAN &&
  71. hwndModem != NULL &&
  72. szBackup != NULL)
  73. {
  74. Button_SetCheck(hwndModem, BST_CHECKED);
  75. szEntryName = szBackup;
  76. }
  77. iSel = (*szEntryName != 0) ? ComboBox_FindStringExact(hwndCombo, -1, szEntryName) : 0;
  78. ComboBox_SetCurSel(hwndCombo, iSel);
  79. EnableConnectoidWindows(hwnd);
  80. }
  81. // if pAcct is NULL, we're in the wizard, otherwise we're in the prop sheet
  82. void ConnectPage_WMCommand(HWND hwnd, HWND hwndCmd, int id, WORD wCmd, IImnAccount *pAcct)
  83. {
  84. BOOL fEnable;
  85. if (wCmd == BN_CLICKED)
  86. {
  87. switch (id)
  88. {
  89. case idcRasAdd:
  90. ConnectPage_MakeNewConnection(hwnd);
  91. EnableWindow(GetDlgItem(hwnd, idcRasProp),
  92. ComboBox_GetCurSel(GetDlgItem(hwnd, idcRasConnection)) != CB_ERR);
  93. break;
  94. case idcRasProp:
  95. ConnectPage_EditConnection(hwnd);
  96. break;
  97. default:
  98. EnableConnectoidWindows(hwnd);
  99. if (pAcct != NULL)
  100. {
  101. PropSheet_Changed(GetParent(hwnd), hwnd);
  102. PropSheet_QuerySiblings(GetParent(hwnd), SM_SETDIRTY, PAGE_RAS);
  103. }
  104. break;
  105. }
  106. }
  107. else if (wCmd == CBN_SELENDOK && id == idcRasConnection)
  108. {
  109. EnableConnectoidWindows(hwnd);
  110. if (pAcct != NULL)
  111. {
  112. PropSheet_Changed(GetParent(hwnd), hwnd);
  113. PropSheet_QuerySiblings(GetParent(hwnd), SM_SETDIRTY, PAGE_RAS);
  114. }
  115. }
  116. }
  117. const static HELPMAP g_rgCtxMapConnect[] = {
  118. {idcLan, IDH_NEWS_SERV_CNKT_LAN},
  119. {idcManual, IDH_NEWS_SERV_CNKT_MAN},
  120. {idcRas, IDH_NEWS_SERV_CNKT_DIALUP},
  121. {idcRasDesc, IDH_NEWS_SERV_CNKT_DIALUP_CONNECT},
  122. {idcRasConnection, IDH_NEWS_SERV_CNKT_DIALUP_CONNECT},
  123. {idcRasProp, IDH_NEWS_SERV_CNKT_PROPS},
  124. {idcRasAdd, IDH_NEWS_SERV_CNKT_ADD},
  125. {idchkConnectOnStartup, IDH_INETCOMM_AUTO_CONNECT},
  126. {IDC_MODEM_CHECK, IDH_CONNECTION_VIA_MODEM},
  127. {0,0}};
  128. INT_PTR CALLBACK ConnectPage_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  129. {
  130. ACCTTYPE type;
  131. NMHDR *pnmh;
  132. CAccount *pAcct;
  133. BOOL fModem;
  134. int iSel;
  135. HWND hwndModem, hwndCombo;
  136. SERVER_TYPE sfType;
  137. char *psz, szEntryName[CCHMAX_CONNECTOID], szBackup[CCHMAX_CONNECTOID];
  138. TCHAR szRes[CCHMAX_STRINGRES];
  139. DWORD dw, dwFlags;
  140. pAcct = (CAccount *)GetWindowLongPtr(hwnd, DWLP_USER);
  141. switch (uMsg)
  142. {
  143. case WM_INITDIALOG:
  144. // Get the ServerParams and store them in our extra bytes
  145. pAcct = (CAccount *)((PROPSHEETPAGE *)lParam)->lParam;
  146. SetWindowLongPtr(hwnd, DWLP_USER, (LPARAM)pAcct);
  147. Assert(pAcct);
  148. pAcct->GetAccountType(&type);
  149. Assert(type == ACCT_MAIL || type == ACCT_NEWS);
  150. // Get the connection info
  151. if (FAILED(pAcct->GetPropSz(AP_RAS_CONNECTOID, szEntryName, ARRAYSIZE(szEntryName))))
  152. szEntryName[0] = 0;
  153. if (FAILED(pAcct->GetPropDw(AP_RAS_CONNECTION_TYPE, &dw)))
  154. dw = CONNECTION_TYPE_LAN;
  155. if (!!(pAcct->m_dwDlgFlags & ACCTDLG_BACKUP_CONNECT) &&
  156. SUCCEEDED(pAcct->GetPropSz(AP_RAS_BACKUP_CONNECTOID, szBackup, ARRAYSIZE(szBackup))))
  157. {
  158. psz = szBackup;
  159. }
  160. else
  161. {
  162. psz = NULL;
  163. }
  164. ConnectPage_InitDialog(hwnd, szEntryName, psz, dw, TRUE);
  165. if (FAILED(pAcct->GetPropDw(AP_RAS_CONNECTION_FLAGS, &dw)))
  166. dw = 0;
  167. Button_SetCheck(GetDlgItem(hwnd, idchkConnectOnStartup), !!(dw & CF_AUTO_CONNECT) ? BST_CHECKED : BST_UNCHECKED);
  168. if (type == ACCT_MAIL)
  169. {
  170. LoadString(g_hInstRes, idsMailConDlgLabel, szRes, ARRAYSIZE(szRes));
  171. SetWindowText(GetDlgItem(hwnd, idcRasDlgLabel), szRes);
  172. // figure out what kind of server we are
  173. PropSheet_QuerySiblings(GetParent(hwnd), MSM_GETSERVERTYPE, (LPARAM)&sfType);
  174. if (sfType == SERVER_MAIL || sfType == SERVER_IMAP)
  175. ShowWindow(GetDlgItem(hwnd, idchkConnectOnStartup), SW_HIDE);
  176. }
  177. PropSheet_QuerySiblings(GetParent(hwnd), SM_INITIALIZED, PAGE_RAS);
  178. PropSheet_UnChanged(GetParent(hwnd), hwnd);
  179. return (TRUE);
  180. case WM_HELP:
  181. case WM_CONTEXTMENU:
  182. return OnContextHelp(hwnd, uMsg, wParam, lParam, g_rgCtxMapConnect);
  183. case WM_COMMAND:
  184. ConnectPage_WMCommand(hwnd, GET_WM_COMMAND_HWND(wParam, lParam),
  185. GET_WM_COMMAND_ID(wParam, lParam),
  186. GET_WM_COMMAND_CMD(wParam, lParam),
  187. pAcct);
  188. return (TRUE);
  189. case WM_NOTIFY:
  190. pnmh = (NMHDR *)lParam;
  191. switch (pnmh->code)
  192. {
  193. case PSN_APPLY:
  194. // BEGIN validation
  195. hwndCombo = GetDlgItem(hwnd, idcRasConnection);
  196. fModem = FALSE;
  197. if (IsDlgButtonChecked(hwnd, idcLan))
  198. {
  199. dw = CONNECTION_TYPE_LAN;
  200. hwndModem = GetDlgItem(hwnd, IDC_MODEM_CHECK);
  201. if (hwndModem != NULL)
  202. fModem = Button_GetCheck(hwndModem);
  203. }
  204. else if (IsDlgButtonChecked(hwnd, idcManual))
  205. {
  206. dw = CONNECTION_TYPE_MANUAL;
  207. }
  208. else
  209. {
  210. dw = CONNECTION_TYPE_RAS;
  211. }
  212. if (dw == CONNECTION_TYPE_RAS || fModem)
  213. {
  214. iSel = ComboBox_GetCurSel(hwndCombo);
  215. if (iSel == CB_ERR)
  216. {
  217. SetFocus(hwndCombo);
  218. InvalidAcctProp(hwnd, NULL, idsErrChooseConnection, iddServerProp_Connect);
  219. return(TRUE);
  220. }
  221. ComboBox_GetLBText(hwndCombo, iSel, szEntryName);
  222. }
  223. // END validation
  224. pAcct->SetPropDw(AP_RAS_CONNECTION_TYPE, dw);
  225. if (fModem)
  226. pAcct->SetPropSz(AP_RAS_BACKUP_CONNECTOID, szEntryName);
  227. else
  228. pAcct->SetProp(AP_RAS_BACKUP_CONNECTOID, NULL, 0);
  229. dwFlags = 0;
  230. if (dw != CONNECTION_TYPE_RAS)
  231. {
  232. pAcct->SetProp(AP_RAS_CONNECTOID, NULL, 0);
  233. }
  234. else
  235. {
  236. pAcct->SetPropSz(AP_RAS_CONNECTOID, szEntryName);
  237. // figure out what kind of server we are
  238. pAcct->GetAccountType(&type);
  239. if (type == ACCT_MAIL)
  240. PropSheet_QuerySiblings(GetParent(hwnd), MSM_GETSERVERTYPE, (LPARAM)&sfType);
  241. else
  242. sfType = SERVER_NEWS;
  243. if (sfType != SERVER_MAIL)
  244. {
  245. if (IsDlgButtonChecked(hwnd, idchkConnectOnStartup))
  246. dwFlags = CF_AUTO_CONNECT;
  247. }
  248. }
  249. pAcct->SetPropDw(AP_RAS_CONNECTION_FLAGS, dwFlags);
  250. PropSheet_UnChanged(GetParent(hwnd), hwnd);
  251. dw = PAGE_RAS;
  252. PropSheet_QuerySiblings(GetParent(hwnd), SM_SAVECHANGES, (LPARAM)&dw);
  253. if (dw == -1)
  254. {
  255. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  256. return(TRUE);
  257. }
  258. break;
  259. }
  260. return(TRUE);
  261. }
  262. return (FALSE);
  263. }
  264. /*******************************************************************
  265. NAME: EditConnectoid
  266. SYNOPSIS: Brings up RNA dialog for connectoid properties for
  267. selected connectoid
  268. ********************************************************************/
  269. BOOL ConnectPage_EditConnection(HWND hDlg)
  270. {
  271. BOOL fRet = FALSE;
  272. HWND hwndCombo = GetDlgItem(hDlg, idcRasConnection);
  273. Assert(hwndCombo);
  274. // shouldn't get here unless there is selection in combo box
  275. Assert(ComboBox_GetCurSel(hwndCombo) >= 0);
  276. TCHAR szEntryName[RAS_MaxEntryName + 1] = "";
  277. ComboBox_GetText(hwndCombo, szEntryName, sizeof(szEntryName));
  278. if (lstrlen(szEntryName))
  279. {
  280. if (SUCCEEDED(HrEditPhonebookEntry(hDlg, szEntryName, NULL)))
  281. fRet = TRUE;
  282. }
  283. return fRet;
  284. }
  285. /*******************************************************************
  286. NAME: MakeNewConnectoid
  287. SYNOPSIS: Launches RNA new connectoid wizard; selects newly
  288. created connectoid (if any) in combo box
  289. ********************************************************************/
  290. BOOL ConnectPage_MakeNewConnection(HWND hDlg)
  291. {
  292. BOOL fRet=FALSE;
  293. if (SUCCEEDED(HrCreatePhonebookEntry(hDlg, NULL)))
  294. {
  295. HWND hwndCombo = GetDlgItem(hDlg, idcRasConnection);
  296. Assert(hwndCombo);
  297. HrFillRasCombo(hwndCombo, TRUE, NULL);
  298. fRet = TRUE;
  299. }
  300. else
  301. {
  302. // Bug #27986 - Let the user know why we failed do do anything, eh?
  303. AcctMessageBox(hDlg, MAKEINTRESOURCE(idsAccountManager), MAKEINTRESOURCE(idsErrNoRas1),
  304. MAKEINTRESOURCE(idsErrNoRas2), MB_OK | MB_ICONINFORMATION);
  305. }
  306. return fRet;
  307. }