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.

682 lines
18 KiB

  1. /*
  2. File gentab.c
  3. Implements the ui behind the general tab for the
  4. connections dialup server ui.
  5. Paul Mayfield, 10/2/97
  6. */
  7. #include "rassrv.h"
  8. #include <tapi.h>
  9. // Help maps
  10. static const DWORD phmGenTab[] =
  11. {
  12. CID_GenTab_LV_Devices, IDH_GenTab_LV_Devices,
  13. CID_GenTab_CB_Multilink, IDH_GenTab_CB_Multilink,
  14. CID_GenTab_PB_Properties, IDH_GenTab_PB_Properties,
  15. CID_GenTab_CB_Vpn, IDH_GenTab_CB_Vpn,
  16. CID_GenTab_CB_ShowIcons, IDH_GenTab_CB_ShowIcons,
  17. 0, 0
  18. };
  19. // Fills in the property sheet structure with the information
  20. // required to display the general tab.
  21. //
  22. DWORD
  23. GenTabGetPropertyPage(
  24. IN LPPROPSHEETPAGE ppage,
  25. IN LPARAM lpUserData)
  26. {
  27. // Initialize
  28. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  29. // Fill in the values
  30. ppage->dwSize = sizeof(PROPSHEETPAGE);
  31. ppage->hInstance = Globals.hInstDll;
  32. ppage->pszTemplate = MAKEINTRESOURCE(PID_GenTab);
  33. ppage->pfnDlgProc = GenTabDialogProc;
  34. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  35. ppage->lParam = lpUserData;
  36. ppage->dwFlags = PSP_USECALLBACK;
  37. return NO_ERROR;
  38. }
  39. // Error reporting
  40. //
  41. VOID
  42. GenTabDisplayError(
  43. IN HWND hwnd,
  44. IN DWORD dwErr)
  45. {
  46. ErrDisplayError(
  47. hwnd,
  48. dwErr,
  49. ERR_GENERALTAB_CATAGORY,
  50. 0,
  51. Globals.dwErrorData);
  52. }
  53. //
  54. // Returns the index of an to display icon based on the type of incoming
  55. // connection and whether or not it should be checked.
  56. //
  57. INT
  58. GenTabGetIconIndex(
  59. IN DWORD dwType,
  60. IN BOOL bEnabled)
  61. {
  62. if (dwType == INCOMING_TYPE_PHONE)
  63. {
  64. return DI_Phone;
  65. }
  66. else
  67. {
  68. return DI_Direct;
  69. }
  70. }
  71. //
  72. // Fills in the device list with the list of the devices stored in the
  73. // device database. Also, initializes the checked/unchecked status
  74. // of each device.
  75. //
  76. DWORD
  77. GenTabFillDeviceList(
  78. IN HWND hwndDlg,
  79. IN HWND hwndLV,
  80. IN HANDLE hDevDatabase)
  81. {
  82. LV_ITEM lvi;
  83. LV_COLUMN lvc;
  84. DWORD dwCount, i, dwErr, dwType;
  85. HANDLE hDevice;
  86. PWCHAR pszName;
  87. char pszAName[1024];
  88. BOOL bEnabled;
  89. // Get the count of all the users
  90. dwErr = devGetDeviceCount(hDevDatabase, &dwCount);
  91. if (dwErr != NO_ERROR)
  92. {
  93. GenTabDisplayError(hwndLV, ERR_DEVICE_DATABASE_CORRUPT);
  94. return dwErr;
  95. }
  96. // Initialize the list item
  97. ZeroMemory(&lvi, sizeof(LV_ITEM));
  98. lvi.mask = LVIF_TEXT | LVIF_IMAGE;
  99. // If there are devices to display then populate the list box
  100. // with them
  101. if (dwCount > 0)
  102. {
  103. ListView_SetDeviceImageList(hwndLV, Globals.hInstDll);
  104. // Looop through all of the devices adding them to the list
  105. for (i=0; i<dwCount; i++)
  106. {
  107. dwErr = devGetDeviceHandle(hDevDatabase, i, &hDevice);
  108. if (dwErr == NO_ERROR)
  109. {
  110. devGetDeviceName (hDevice, &pszName);
  111. devGetDeviceEnable (hDevice, &bEnabled);
  112. devGetDeviceType (hDevice, &dwType);
  113. lvi.iImage = GenTabGetIconIndex(dwType, bEnabled);
  114. lvi.iItem = i;
  115. lvi.pszText = pszName;
  116. lvi.cchTextMax = wcslen(pszName)+1;
  117. ListView_InsertItem(hwndLV,&lvi);
  118. ListView_SetCheck(hwndLV, i, bEnabled);
  119. }
  120. }
  121. // Select the first item in the list view if any items exist
  122. //
  123. ListView_SetItemState(
  124. hwndLV,
  125. 0,
  126. LVIS_SELECTED | LVIS_FOCUSED,
  127. LVIS_SELECTED | LVIS_FOCUSED);
  128. // Initialize the alignment of the text that gets displayed
  129. lvc.mask = LVCF_FMT;
  130. lvc.fmt = LVCFMT_LEFT;
  131. }
  132. // If there are no devices then we display a message in the big
  133. // white box explaining that we have no devices to show.
  134. else
  135. {
  136. PWCHAR pszLine1, pszLine2;
  137. pszLine1 = (PWCHAR)
  138. PszLoadString(Globals.hInstDll, SID_NO_DEVICES1);
  139. pszLine2 = (PWCHAR)
  140. PszLoadString(Globals.hInstDll, SID_NO_DEVICES2);
  141. lvi.mask = LVIF_TEXT;
  142. lvi.iItem = 0;
  143. lvi.pszText = pszLine1;
  144. lvi.cchTextMax = wcslen(pszLine1);
  145. ListView_InsertItem(hwndLV, &lvi);
  146. lvi.iItem = 1;
  147. lvi.pszText = pszLine2;
  148. lvi.cchTextMax = wcslen(pszLine2);
  149. ListView_InsertItem(hwndLV, &lvi);
  150. // Initialize the alignment of the text that gets displayed
  151. lvc.mask = LVCF_FMT;
  152. lvc.fmt = LVCFMT_CENTER;
  153. // Disable the list view
  154. EnableWindow(hwndLV, FALSE);
  155. // Disable the properties button while you're at it
  156. EnableWindow(
  157. GetDlgItem(hwndDlg, CID_GenTab_PB_Properties),
  158. FALSE);
  159. }
  160. // Add a colum so that we'll display in report view
  161. ListView_InsertColumn(hwndLV, 0, &lvc);
  162. ListView_SetColumnWidth(hwndLV, 0, LVSCW_AUTOSIZE_USEHEADER);
  163. return NO_ERROR;
  164. }
  165. //
  166. // This function causes the multilink check box behave in a way that
  167. // allows the user to see how multilink works.
  168. //
  169. DWORD
  170. GenTabAdjustMultilinkAppearance(
  171. IN HWND hwndDlg,
  172. IN HANDLE hDevDatabase,
  173. IN HANDLE hMiscDatabase)
  174. {
  175. DWORD dwErr = NO_ERROR, i, dwEndpointsEnabled;
  176. HWND hwndML = GetDlgItem(hwndDlg, CID_GenTab_CB_Multilink);
  177. BOOL bDisable, bUncheck, bFlag = FALSE, bIsServer;
  178. do
  179. {
  180. // Initialize default behavior in case of an error
  181. //
  182. bDisable = TRUE;
  183. bUncheck = FALSE;
  184. // Find out how many endpoints are enabled for inbound calls
  185. //
  186. dwErr = devGetEndpointEnableCount(
  187. hDevDatabase,
  188. &dwEndpointsEnabled);
  189. if (dwErr != NO_ERROR)
  190. {
  191. break;
  192. }
  193. // If multiple devices are not enabled for inbound calls then
  194. // multilink is meaningless. Disable the multilink control and
  195. // uncheck it.
  196. //
  197. if (dwEndpointsEnabled < 2)
  198. {
  199. bUncheck = TRUE;
  200. bDisable = TRUE;
  201. dwErr = NO_ERROR;
  202. break;
  203. }
  204. // The multilink check only makes sense on NT Server. This is
  205. // based on the following assumptions
  206. // 1. You only disable multilink so that you can free lines
  207. // for additional callers.
  208. // 2. PPP will enforce that you only have one caller over
  209. // modem device on nt wks anyway.
  210. //
  211. miscGetProductType(hMiscDatabase, &bIsServer);
  212. if (! bIsServer)
  213. {
  214. bDisable = TRUE;
  215. bUncheck = FALSE;
  216. dwErr = NO_ERROR;
  217. break;
  218. }
  219. // Otherwise, multilink makes sense. Enable the multilink
  220. // control and set its check according to what the system says
  221. bDisable = FALSE;
  222. bUncheck = FALSE;
  223. dwErr = miscGetMultilinkEnable(hMiscDatabase, &bFlag);
  224. if (dwErr != NO_ERROR)
  225. {
  226. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  227. break;
  228. }
  229. } while (FALSE);
  230. // Cleanup
  231. {
  232. EnableWindow(hwndML, !bDisable);
  233. if (bUncheck)
  234. {
  235. SendMessage(
  236. hwndML,
  237. BM_SETCHECK,
  238. BST_UNCHECKED,
  239. 0);
  240. }
  241. else
  242. {
  243. SendMessage(
  244. hwndML,
  245. BM_SETCHECK,
  246. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  247. 0);
  248. }
  249. }
  250. return dwErr;
  251. }
  252. //
  253. // Initializes the general tab. By now a handle to the general
  254. // database has been placed in the user data of the dialog
  255. //
  256. DWORD
  257. GenTabInitializeDialog(
  258. IN HWND hwndDlg,
  259. IN WPARAM wParam,
  260. IN LPARAM lParam)
  261. {
  262. DWORD dwErr, dwCount;
  263. BOOL bFlag, bIsServer = FALSE;
  264. HANDLE hDevDatabase = NULL, hMiscDatabase = NULL;
  265. HWND hwndLV = GetDlgItem(hwndDlg, CID_GenTab_LV_Devices);;
  266. // Get handles to the databases we're interested in
  267. //
  268. RasSrvGetDatabaseHandle(
  269. hwndDlg,
  270. ID_DEVICE_DATABASE,
  271. &hDevDatabase);
  272. RasSrvGetDatabaseHandle(
  273. hwndDlg,
  274. ID_MISC_DATABASE,
  275. &hMiscDatabase);
  276. // Set the logging level
  277. //
  278. miscSetRasLogLevel(hMiscDatabase, MISCDB_RAS_LEVEL_ERR_AND_WARN);
  279. // Fill in the list view will all available devices
  280. //
  281. ListView_InstallChecks(hwndLV, Globals.hInstDll);
  282. GenTabFillDeviceList(hwndDlg, hwndLV, hDevDatabase);
  283. // Adjust the multilink control
  284. //
  285. miscGetProductType(hMiscDatabase, &bIsServer);
  286. if (bIsServer)
  287. {
  288. GenTabAdjustMultilinkAppearance(
  289. hwndDlg,
  290. hDevDatabase,
  291. hMiscDatabase);
  292. }
  293. else
  294. {
  295. ShowWindow(
  296. GetDlgItem(hwndDlg, CID_GenTab_CB_Multilink),
  297. SW_HIDE);
  298. }
  299. // Initialize the vpn check
  300. //
  301. dwErr = devGetVpnEnable(hDevDatabase, &bFlag);
  302. if (dwErr != NO_ERROR)
  303. {
  304. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  305. return dwErr;
  306. }
  307. SendMessage(
  308. GetDlgItem(hwndDlg, CID_GenTab_CB_Vpn),
  309. BM_SETCHECK,
  310. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  311. 0);
  312. // Initialize the show icons check
  313. //
  314. dwErr = miscGetIconEnable(hMiscDatabase, &bFlag);
  315. if (dwErr != NO_ERROR)
  316. {
  317. GenTabDisplayError(hwndDlg, ERR_DEVICE_DATABASE_CORRUPT);
  318. return dwErr;
  319. }
  320. SendMessage(
  321. GetDlgItem(hwndDlg, CID_GenTab_CB_ShowIcons),
  322. BM_SETCHECK,
  323. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  324. 0);
  325. //
  326. //for bug 154607 whistler, Enable/Disable Show Icon on taskbar
  327. //check box according to Policy
  328. //
  329. {
  330. BOOL fShowStatistics = TRUE;
  331. HRESULT hr;
  332. INetConnectionUiUtilities * pNetConUtilities = NULL;
  333. hr = HrCreateNetConnectionUtilities(&pNetConUtilities);
  334. if ( SUCCEEDED(hr))
  335. {
  336. fShowStatistics =
  337. INetConnectionUiUtilities_UserHasPermission(
  338. pNetConUtilities, NCPERM_Statistics);
  339. EnableWindow( GetDlgItem(hwndDlg, CID_GenTab_CB_ShowIcons), fShowStatistics );
  340. INetConnectionUiUtilities_Release(pNetConUtilities);
  341. }
  342. }
  343. return NO_ERROR;
  344. }
  345. //
  346. // Deals with changes in the check of a device
  347. //
  348. DWORD
  349. GenTabHandleDeviceCheck(
  350. IN HWND hwndDlg,
  351. IN INT iItem)
  352. {
  353. HANDLE hDevDatabase = NULL, hMiscDatabase = NULL, hDevice = NULL;
  354. DWORD dwErr;
  355. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  356. RasSrvGetDatabaseHandle(hwndDlg, ID_MISC_DATABASE, &hMiscDatabase);
  357. // Set the enabling of the given device
  358. dwErr = devGetDeviceHandle(hDevDatabase, (DWORD)iItem, &hDevice);
  359. if (dwErr == NO_ERROR)
  360. {
  361. // Set the device
  362. devSetDeviceEnable(
  363. hDevice,
  364. ListView_GetCheck(GetDlgItem(hwndDlg, CID_GenTab_LV_Devices),
  365. iItem));
  366. // Update the multilink check
  367. GenTabAdjustMultilinkAppearance(
  368. hwndDlg,
  369. hDevDatabase,
  370. hMiscDatabase);
  371. }
  372. return NO_ERROR;
  373. }
  374. //
  375. // Go through the list view and get the device enablings and
  376. // commit them to the database.
  377. //
  378. DWORD
  379. GenTabCommitDeviceSettings(
  380. IN HWND hwndLV,
  381. IN HANDLE hDevDatabase)
  382. {
  383. return NO_ERROR;
  384. }
  385. //
  386. // Processes the activation of the general tab. Return TRUE to
  387. // report that the message has been handled.
  388. //
  389. BOOL
  390. GenTabSetActive (
  391. IN HWND hwndDlg)
  392. {
  393. HANDLE hDevDatabase = NULL;
  394. DWORD dwErr, dwCount, dwId;
  395. PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
  396. // Find out if we're the device page in the incoming wizard.
  397. dwErr = RasSrvGetPageId (hwndDlg, &dwId);
  398. if (dwErr != NO_ERROR)
  399. {
  400. return dwErr;
  401. }
  402. if (dwId == RASSRVUI_DEVICE_WIZ_TAB)
  403. {
  404. // Find out if there are any devices to show
  405. RasSrvGetDatabaseHandle(
  406. hwndDlg,
  407. ID_DEVICE_DATABASE,
  408. &hDevDatabase);
  409. dwErr = devGetDeviceCount (hDevDatabase, &dwCount);
  410. // If there are no devices or if there's a database problem,
  411. // don't allow this page to be activated.
  412. if ((dwErr != NO_ERROR) || (dwCount == 0))
  413. {
  414. SetWindowLongPtr (hwndDlg, DWLP_MSGRESULT, (LONG_PTR)-1);
  415. }
  416. }
  417. PropSheet_SetWizButtons(
  418. GetParent(hwndDlg),
  419. PSWIZB_NEXT | PSWIZB_BACK);
  420. return TRUE;
  421. }
  422. //
  423. // Displays properties for the given device
  424. //
  425. DWORD
  426. GenTabRaiseProperties (
  427. IN HWND hwndDlg,
  428. IN DWORD dwIndex)
  429. {
  430. HANDLE hDevDatabase = NULL, hDevice = NULL;
  431. DWORD dwId, dwErr;
  432. // Get the device id
  433. RasSrvGetDatabaseHandle(
  434. hwndDlg,
  435. ID_DEVICE_DATABASE,
  436. &hDevDatabase);
  437. dwErr = devGetDeviceHandle(hDevDatabase, dwIndex, &hDevice);
  438. if (dwErr != NO_ERROR)
  439. {
  440. return ERROR_CAN_NOT_COMPLETE;
  441. }
  442. if (devGetDeviceId(hDevice, &dwId) != NO_ERROR)
  443. {
  444. return ERROR_CAN_NOT_COMPLETE;
  445. }
  446. // Launch the device properties dialog
  447. dwErr = lineConfigDialogW(dwId, hwndDlg, NULL);
  448. if (dwErr == LINEERR_OPERATIONUNAVAIL)
  449. {
  450. GenTabDisplayError(hwndDlg, ERR_DEVICE_HAS_NO_CONFIG);
  451. dwErr = NO_ERROR;
  452. }
  453. return dwErr;
  454. }
  455. //
  456. // WM_COMMAND handler
  457. //
  458. DWORD
  459. GenTabCommand(
  460. IN HWND hwndDlg,
  461. IN WPARAM wParam)
  462. {
  463. HANDLE hMiscDatabase = NULL, hDevDatabase = NULL;
  464. RasSrvGetDatabaseHandle(
  465. hwndDlg,
  466. ID_MISC_DATABASE,
  467. &hMiscDatabase);
  468. RasSrvGetDatabaseHandle(
  469. hwndDlg,
  470. ID_DEVICE_DATABASE,
  471. &hDevDatabase);
  472. switch (wParam)
  473. {
  474. case CID_GenTab_CB_Multilink:
  475. miscSetMultilinkEnable(
  476. hMiscDatabase,
  477. (BOOL)SendDlgItemMessage(
  478. hwndDlg,
  479. CID_GenTab_CB_Multilink,
  480. BM_GETCHECK,
  481. 0,
  482. 0));
  483. break;
  484. case CID_GenTab_CB_Vpn:
  485. devSetVpnEnable(
  486. hDevDatabase,
  487. (BOOL)SendDlgItemMessage(
  488. hwndDlg,
  489. CID_GenTab_CB_Vpn,
  490. BM_GETCHECK,
  491. 0,
  492. 0));
  493. break;
  494. case CID_GenTab_CB_ShowIcons:
  495. miscSetIconEnable(
  496. hMiscDatabase,
  497. (BOOL)SendDlgItemMessage(
  498. hwndDlg,
  499. CID_GenTab_CB_ShowIcons,
  500. BM_GETCHECK,
  501. 0,
  502. 0));
  503. break;
  504. case CID_GenTab_PB_Properties:
  505. GenTabRaiseProperties (
  506. hwndDlg,
  507. ListView_GetSelectionMark(
  508. GetDlgItem(hwndDlg, CID_GenTab_LV_Devices)));
  509. break;
  510. }
  511. return NO_ERROR;
  512. }
  513. //
  514. // This is the dialog procedure that responds to messages sent
  515. // to the general tab.
  516. //
  517. INT_PTR
  518. CALLBACK
  519. GenTabDialogProc(
  520. IN HWND hwndDlg,
  521. IN UINT uMsg,
  522. IN WPARAM wParam,
  523. IN LPARAM lParam)
  524. {
  525. // Filter the customized list view messages
  526. if (ListView_OwnerHandler(
  527. hwndDlg,
  528. uMsg,
  529. wParam,
  530. lParam,
  531. LvDrawInfoCallback )
  532. )
  533. {
  534. return TRUE;
  535. }
  536. // Filter the customized ras server ui page messages. By
  537. // filtering messages through here, we are able to call
  538. // RasSrvGetDatabaseHandle below
  539. //
  540. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  541. {
  542. return TRUE;
  543. }
  544. // Process other messages as normal
  545. switch (uMsg)
  546. {
  547. case WM_INITDIALOG:
  548. return FALSE;
  549. break;
  550. case WM_HELP:
  551. case WM_CONTEXTMENU:
  552. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmGenTab);
  553. break;
  554. case WM_NOTIFY:
  555. {
  556. NM_LISTVIEW* pLvNotifyData;
  557. NMHDR* pNotifyData = (NMHDR*)lParam;
  558. switch (pNotifyData->code) {
  559. //
  560. // Note: PSN_APPLY and PSN_CANCEL are handled
  561. // by RasSrvMessageFilter
  562. //
  563. case PSN_SETACTIVE:
  564. // Initailize the dialog if it isn't already
  565. //
  566. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  567. {
  568. GenTabInitializeDialog(hwndDlg, wParam, lParam);
  569. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)1);
  570. }
  571. if (GenTabSetActive (hwndDlg))
  572. return TRUE;
  573. break;
  574. // The check of an item is changing
  575. case LVXN_SETCHECK:
  576. pLvNotifyData = (NM_LISTVIEW*)lParam;
  577. GenTabHandleDeviceCheck(
  578. hwndDlg,
  579. pLvNotifyData->iItem);
  580. break;
  581. case LVXN_DBLCLK:
  582. pLvNotifyData = (NM_LISTVIEW*)lParam;
  583. GenTabRaiseProperties(
  584. hwndDlg,
  585. pLvNotifyData->iItem);
  586. break;
  587. }
  588. }
  589. break;
  590. case WM_COMMAND:
  591. GenTabCommand(hwndDlg, wParam);
  592. break;
  593. }
  594. return FALSE;
  595. }