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.

596 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. devstat.c
  5. Abstract:
  6. Functions for handling events in the "Device Status" tab of
  7. the fax server configuration property sheet
  8. Environment:
  9. Fax configuration applet
  10. Revision History:
  11. 03/13/96 -davidx-
  12. Created it.
  13. mm/dd/yy -author-
  14. description
  15. --*/
  16. #include "faxcpl.h"
  17. //
  18. // Information about the fax device list view on "Send Options" page
  19. //
  20. static COLUMNINFO faxDeviceListViewColumnInfo[] = {
  21. { COLUMN_DEVICE_NAME, 2 },
  22. { COLUMN_STATUS, 1 },
  23. { 0, 0 },
  24. };
  25. VOID
  26. DoActivateDeviceStatus(
  27. HWND hDlg
  28. )
  29. /*++
  30. Routine Description:
  31. Called when the "Device Status" property page is activated
  32. Arguments:
  33. hDlg - Window handle to the "Device Status" property page
  34. Return Value:
  35. NONE
  36. --*/
  37. {
  38. HWND hwndLV;
  39. //
  40. // Reinitialize the fax device list view if necessary
  41. //
  42. if (!IsFaxDeviceListInSync(DEVICE_STATUS_PAGE) &&
  43. (hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)))
  44. {
  45. InitFaxDeviceListView(hwndLV, 0, faxDeviceListViewColumnInfo);
  46. }
  47. SetFaxDeviceListInSync(DEVICE_STATUS_PAGE);
  48. }
  49. VOID
  50. DoRefreshDevStatus(
  51. HWND hDlg
  52. )
  53. /*++
  54. Routine Description:
  55. Refresh the fax device list on "Device Status" property page
  56. Arguments:
  57. hDlg - Window handle to the "Device Status" property page
  58. Return Value:
  59. NONE
  60. --*/
  61. {
  62. PFAX_PORT_INFO pFaxPortInfo, pSaved;
  63. DWORD cPorts;
  64. INT index;
  65. //
  66. // Talk with the fax service to get the current status of each device
  67. //
  68. if (gConfigData->hFaxSvc &&
  69. (pSaved = pFaxPortInfo = FaxSvcEnumPorts(gConfigData->hFaxSvc, &cPorts)))
  70. {
  71. for (index=0; index < gConfigData->cDevices; index++)
  72. gConfigData->pDevInfo[index].State = FPS_UNAVAILABLE;
  73. for ( ; cPorts--; pFaxPortInfo++) {
  74. for (index=0; index < gConfigData->cDevices; index++) {
  75. if (gConfigData->pDevInfo[index].DeviceId == pFaxPortInfo->DeviceId) {
  76. gConfigData->pDevInfo[index].State = pFaxPortInfo->State;
  77. break;
  78. }
  79. }
  80. }
  81. //
  82. // Redisplay the fax device status
  83. //
  84. FaxFreeBuffer(pSaved);
  85. UpdateFaxDeviceListViewColumns(GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST),
  86. faxDeviceListViewColumnInfo,
  87. 1);
  88. }
  89. }
  90. VOID
  91. SetTimeField(
  92. HWND hwnd,
  93. PFILETIME pFileTime
  94. )
  95. /*++
  96. Routine Description:
  97. Display the specified time value in a text field
  98. Arguments:
  99. hwnd - Window handle to the text field
  100. pFileTime - Time value to be displayed
  101. Return Value:
  102. NONE
  103. --*/
  104. {
  105. SYSTEMTIME systemTime;
  106. TCHAR timeString[64];
  107. if (! FileTimeToSystemTime(pFileTime, &systemTime) ||
  108. ! GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systemTime, NULL, timeString, 64))
  109. {
  110. Error(("Bad time value: error = %d\n", GetLastError()));
  111. timeString[0] = NUL;
  112. }
  113. SetWindowText(hwnd, timeString);
  114. }
  115. BOOL CALLBACK
  116. SendStatusProc(
  117. HWND hDlg,
  118. UINT uMsg,
  119. WPARAM wParam,
  120. LPARAM lParam
  121. )
  122. /*++
  123. Routine Description:
  124. Dialog procedure for displaying send device status dialog
  125. Arguments:
  126. hDlg - Handle to dialog window
  127. uMsg - Message
  128. wParam, lParam - Parameters
  129. Return Value:
  130. Depends on message
  131. --*/
  132. #define SetStatusTextField(hDlg, idc, p) \
  133. SetDlgItemText(hDlg, idc, (p) ? (p) : TEXT(""))
  134. {
  135. PFAX_DEVICE_STATUS pDevStatus;
  136. switch (uMsg) {
  137. case WM_INITDIALOG:
  138. pDevStatus = (PFAX_DEVICE_STATUS) lParam;
  139. if (pDevStatus == NULL || pDevStatus->SizeOfStruct != sizeof(FAX_DEVICE_STATUS)) {
  140. Error(("Corrupted FAX_DEVICE_STATUS structure\n"));
  141. return TRUE;
  142. }
  143. SetStatusTextField(hDlg, IDC_DEVSTAT_DEVICE, pDevStatus->DeviceName);
  144. SetStatusTextField(hDlg, IDC_DEVSTAT_SENDER, pDevStatus->SenderName);
  145. SetStatusTextField(hDlg, IDC_DEVSTAT_DOCUMENT, pDevStatus->DocumentName);
  146. SetStatusTextField(hDlg, IDC_DEVSTAT_TO, pDevStatus->RecipientName);
  147. SetStatusTextField(hDlg, IDC_DEVSTAT_FAXNUMBER, pDevStatus->PhoneNumber);
  148. SetDlgItemInt(hDlg, IDC_DEVSTAT_TOTAL_BYTES, pDevStatus->Size, FALSE);
  149. SetDlgItemInt(hDlg, IDC_DEVSTAT_CURRENT_PAGE, pDevStatus->CurrentPage, FALSE);
  150. SetDlgItemInt(hDlg, IDC_DEVSTAT_TOTAL_PAGES, pDevStatus->TotalPages, FALSE);
  151. //
  152. // Start time and submitted time
  153. //
  154. SetTimeField(GetDlgItem(hDlg, IDC_DEVSTAT_STARTEDAT),
  155. &pDevStatus->StartTime);
  156. SetTimeField(GetDlgItem(hDlg, IDC_DEVSTAT_SUBMITTEDAT),
  157. &pDevStatus->SubmittedTime);
  158. //
  159. // Status string
  160. //
  161. if (pDevStatus->Status == 0) {
  162. SetStatusTextField(hDlg, IDC_DEVSTAT_STATUS, pDevStatus->StatusString);
  163. } else {
  164. LPTSTR pStatusString;
  165. pStatusString = MakeDeviceStatusString(pDevStatus->Status);
  166. SetStatusTextField(hDlg, IDC_DEVSTAT_STATUS, pStatusString);
  167. MemFree(pStatusString);
  168. }
  169. return TRUE;
  170. case WM_COMMAND:
  171. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  172. case IDOK:
  173. case IDCANCEL:
  174. EndDialog(hDlg, IDCANCEL);
  175. return TRUE;
  176. }
  177. break;
  178. }
  179. return FALSE;
  180. }
  181. BOOL CALLBACK
  182. ReceiveStatusProc(
  183. HWND hDlg,
  184. UINT uMsg,
  185. WPARAM wParam,
  186. LPARAM lParam
  187. )
  188. /*++
  189. Routine Description:
  190. Dialog procedure for displaying receive device status dialog
  191. Arguments:
  192. hDlg - Handle to dialog window
  193. uMsg - Message
  194. wParam, lParam - Parameters
  195. Return Value:
  196. Depends on message
  197. --*/
  198. {
  199. PFAX_DEVICE_STATUS pDevStatus;
  200. switch (uMsg) {
  201. case WM_INITDIALOG:
  202. pDevStatus = (PFAX_DEVICE_STATUS) lParam;
  203. if (pDevStatus == NULL || pDevStatus->SizeOfStruct != sizeof(FAX_DEVICE_STATUS)) {
  204. Error(("Corrupted FAX_DEVICE_STATUS structure\n"));
  205. return TRUE;
  206. }
  207. SetStatusTextField(hDlg, IDC_DEVSTAT_DEVICE, pDevStatus->DeviceName);
  208. SetStatusTextField(hDlg, IDC_DEVSTAT_SENDER, pDevStatus->Tsid);
  209. SetStatusTextField(hDlg, IDC_DEVSTAT_TO, pDevStatus->Csid);
  210. //
  211. // Start time
  212. //
  213. SetTimeField(GetDlgItem(hDlg, IDC_DEVSTAT_STARTEDAT),
  214. &pDevStatus->StartTime);
  215. //
  216. // Status string
  217. //
  218. if (pDevStatus->Status == 0) {
  219. SetStatusTextField(hDlg, IDC_DEVSTAT_STATUS, pDevStatus->StatusString);
  220. } else {
  221. LPTSTR pStatusString;
  222. pStatusString = MakeDeviceStatusString(pDevStatus->Status);
  223. SetStatusTextField(hDlg, IDC_DEVSTAT_STATUS, pStatusString);
  224. MemFree(pStatusString);
  225. }
  226. return TRUE;
  227. case WM_COMMAND:
  228. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  229. case IDOK:
  230. case IDCANCEL:
  231. EndDialog(hDlg, IDCANCEL);
  232. return TRUE;
  233. }
  234. break;
  235. }
  236. return FALSE;
  237. }
  238. VOID
  239. DoShowStatusDetails(
  240. HWND hDlg
  241. )
  242. /*++
  243. Routine Description:
  244. Display detailed status of the currently selected fax device
  245. Arguments:
  246. hDlg - Window handle to the "Device Status" property page
  247. Return Value:
  248. NONE
  249. --*/
  250. {
  251. HWND hwndLV;
  252. INT index;
  253. PFAX_DEVICE_STATUS pDevStatus = NULL;
  254. //
  255. // Get the index of the currently selected item and
  256. // count the total number of items in the list view
  257. //
  258. if ((hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)) == NULL ||
  259. (index = ListView_GetNextItem(hwndLV, -1, LVNI_ALL|LVNI_SELECTED)) < 0 ||
  260. (index >= gConfigData->cDevices))
  261. {
  262. return;
  263. }
  264. //
  265. // Call the fax service to get the status of the specified device
  266. //
  267. pDevStatus = FaxSvcGetDeviceStatus(gConfigData->hFaxSvc, gConfigData->pDevInfo[index].DeviceId);
  268. if (pDevStatus == NULL) {
  269. DisplayMessageDialog(hDlg,
  270. 0,
  271. 0,
  272. IDS_DEVICE_STATUS_ERROR,
  273. gConfigData->pDevInfo[index].DeviceName);
  274. FaxFreeBuffer(pDevStatus);
  275. return;
  276. }
  277. //
  278. // Display appropriate status dialog depending on the current job type
  279. //
  280. switch (pDevStatus->JobType) {
  281. case JT_SEND:
  282. DialogBoxParam(ghInstance,
  283. MAKEINTRESOURCE(IDD_SEND_STATUS),
  284. hDlg,
  285. SendStatusProc,
  286. (LPARAM) pDevStatus);
  287. break;
  288. case JT_RECEIVE:
  289. DialogBoxParam(ghInstance,
  290. MAKEINTRESOURCE(IDD_RECEIVE_STATUS),
  291. hDlg,
  292. ReceiveStatusProc,
  293. (LPARAM) pDevStatus);
  294. break;
  295. default:
  296. if (pDevStatus->JobType != 0)
  297. Error(("Unknown job type: %d\n", pDevStatus->JobType));
  298. DisplayMessageDialog(hDlg,
  299. MB_OK | MB_ICONINFORMATION,
  300. IDS_DEVICE_STATUS,
  301. IDS_DEVICE_STATUS_IDLE,
  302. gConfigData->pDevInfo[index].DeviceName);
  303. break;
  304. }
  305. FaxFreeBuffer(pDevStatus);
  306. }
  307. VOID
  308. HandleDevStatusListViewMessage(
  309. HWND hDlg,
  310. LPNMHDR pNMHdr
  311. )
  312. /*++
  313. Routine Description:
  314. Handle notification events from the fax device list
  315. Arguments:
  316. hDlg - Window handle to the "Device Status" property page
  317. pNMHdr - Points to an NMHDR structure
  318. Return Value:
  319. NONE
  320. --*/
  321. {
  322. HWND hwndLV = pNMHdr->hwndFrom;
  323. switch (pNMHdr->code) {
  324. case LVN_KEYDOWN:
  325. if (((LV_KEYDOWN *) pNMHdr)->wVKey != VK_RETURN)
  326. break;
  327. case NM_DBLCLK:
  328. DoShowStatusDetails(hDlg);
  329. break;
  330. }
  331. }
  332. BOOL
  333. DeviceStatusProc(
  334. HWND hDlg,
  335. UINT message,
  336. UINT wParam,
  337. LONG lParam
  338. )
  339. /*++
  340. Routine Description:
  341. Procedure for handling the "Device Status" tab
  342. Arguments:
  343. hDlg - Identifies the property sheet page
  344. message - Specifies the message
  345. wParam - Specifies additional message-specific information
  346. lParam - Specifies additional message-specific information
  347. Return Value:
  348. Depends on the value of message parameter
  349. --*/
  350. {
  351. LPNMHDR pNMHdr;
  352. switch (message) {
  353. case WM_INITDIALOG:
  354. GetFaxDeviceAndConfigInfo();
  355. return TRUE;
  356. case WM_COMMAND:
  357. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  358. case IDC_REFRESH:
  359. DoRefreshDevStatus(hDlg);
  360. return TRUE;
  361. case IDC_DETAILS:
  362. DoShowStatusDetails(hDlg);
  363. break;
  364. }
  365. break;
  366. case WM_NOTIFY:
  367. pNMHdr = (NMHDR *) lParam;
  368. if (pNMHdr->hwndFrom == GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)) {
  369. HandleDevStatusListViewMessage(hDlg, pNMHdr);
  370. } else switch (pNMHdr->code) {
  371. case PSN_SETACTIVE:
  372. DoActivateDeviceStatus(hDlg);
  373. break;
  374. case PSN_APPLY:
  375. return PSNRET_NOERROR;
  376. }
  377. break;
  378. case WM_HELP:
  379. case WM_CONTEXTMENU:
  380. return HandleHelpPopup(hDlg, message, wParam, lParam, DEVICE_STATUS_PAGE);
  381. }
  382. return FALSE;
  383. }