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.

511 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. diaglog.c
  5. Abstract:
  6. Functions for handling events in the "Diagnostics Logging" tab of
  7. the fax server configuration property sheet
  8. Environment:
  9. Fax configuration applet
  10. Revision History:
  11. 03/22/96 -davidx-
  12. Created it.
  13. mm/dd/yy -author-
  14. description
  15. --*/
  16. #include "faxcpl.h"
  17. VOID
  18. UpdateLoggingLevels(
  19. HWND hwndLV
  20. )
  21. /*++
  22. Routine Description:
  23. Display current logging level for each category
  24. Arguments:
  25. hwndLV - Specifies the list view window
  26. Return Value:
  27. NONE
  28. --*/
  29. {
  30. INT index, nItems, strId;
  31. TCHAR buffer[MAX_TITLE_LEN];
  32. LV_ITEM lvi;
  33. //
  34. // Count the number of items in the list view
  35. //
  36. if (hwndLV == NULL ||
  37. (nItems = ListView_GetItemCount(hwndLV)) == -1 ||
  38. gConfigData->pFaxConfig == NULL ||
  39. nItems > (INT) gConfigData->NumberCategories)
  40. {
  41. return;
  42. }
  43. ZeroMemory(&lvi, sizeof(lvi));
  44. lvi.mask = LVIF_TEXT;
  45. lvi.iSubItem = 1;
  46. lvi.pszText = buffer;
  47. for (index=0; index < nItems; index++) {
  48. //
  49. // Map logging level to radio button control ID
  50. //
  51. switch (gConfigData->pFaxLogging[index].Level) {
  52. case FAXLOG_LEVEL_MIN:
  53. strId = IDS_LOGGING_MIN;
  54. break;
  55. case FAXLOG_LEVEL_MED:
  56. strId = IDS_LOGGING_MED;
  57. break;
  58. case FAXLOG_LEVEL_MAX:
  59. strId = IDS_LOGGING_MAX;
  60. break;
  61. default:
  62. strId = IDS_LOGGING_NONE;
  63. break;
  64. }
  65. if (! LoadString(ghInstance, strId, buffer, MAX_TITLE_LEN))
  66. buffer[0] = NUL;
  67. lvi.iItem = index;
  68. if (! ListView_SetItem(hwndLV, &lvi))
  69. Error(("ListView_SetItem failed\n"));
  70. }
  71. }
  72. VOID
  73. DoInitDiagLog(
  74. HWND hDlg
  75. )
  76. /*++
  77. Routine Description:
  78. Perform one-time initialization of "Diagnostics Logging" property page
  79. Arguments:
  80. hDlg - Window handle to the "Diagnostics Logging" property page
  81. Return Value:
  82. NONE
  83. --*/
  84. {
  85. HWND hwndLV;
  86. RECT rect;
  87. LV_COLUMN lvc;
  88. TCHAR buffer[MAX_TITLE_LEN];
  89. //
  90. // Connect to the fax service and retrieve the list of fax devices
  91. //
  92. GetFaxDeviceAndConfigInfo();
  93. //
  94. // Insert two columns: Category and Logging Level
  95. //
  96. if (! (hwndLV = GetDlgItem(hDlg, IDC_LOGGING_LIST)))
  97. return;
  98. GetClientRect(hwndLV, &rect);
  99. rect.right -= rect.left;
  100. ZeroMemory(&lvc, sizeof(lvc));
  101. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  102. lvc.fmt = LVCFMT_LEFT;
  103. lvc.pszText = buffer;
  104. lvc.cx = rect.right * 2 / 3;
  105. lvc.iSubItem = 0;
  106. LoadString(ghInstance, IDS_CATEGORY, buffer, MAX_TITLE_LEN);
  107. if (ListView_InsertColumn(hwndLV, 0, &lvc) == -1) {
  108. Error(("ListView_InsertColumn failed\n"));
  109. return;
  110. }
  111. lvc.cx = rect.right / 3 - GetSystemMetrics(SM_CXVSCROLL);
  112. lvc.iSubItem = 1;
  113. LoadString(ghInstance, IDS_LOGGING_LEVEL, buffer, MAX_TITLE_LEN);
  114. if (ListView_InsertColumn(hwndLV, 1, &lvc) == -1) {
  115. Error(("ListView_InsertColumn failed\n"));
  116. return;
  117. }
  118. //
  119. // Insert an item for each category
  120. //
  121. if (gConfigData->pFaxConfig) {
  122. LV_ITEM lvi;
  123. DWORD index;
  124. ZeroMemory(&lvi, sizeof(lvi));
  125. lvi.iSubItem = 0;
  126. lvi.mask = LVIF_TEXT;
  127. for (index=0; index < gConfigData->NumberCategories; index++) {
  128. lvi.iItem = index;
  129. lvi.pszText = gConfigData->pFaxLogging[index].Name;
  130. if (ListView_InsertItem(hwndLV, &lvi) == -1) {
  131. Error(("ListView_InsertItem failed\n"));
  132. break;
  133. }
  134. }
  135. }
  136. UpdateLoggingLevels(hwndLV);
  137. //
  138. // The initial selection is the first category in the list
  139. //
  140. ListView_SetItemState(hwndLV, 0, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
  141. }
  142. BOOL
  143. DoSaveDiagLog(
  144. HWND hDlg
  145. )
  146. /*++
  147. Routine Description:
  148. Save the information on the "Diagnostics Logging" property page
  149. Arguments:
  150. hDlg - Handle to the "Diagnostics Logging" property page
  151. Return Value:
  152. TRUE if successful, FALSE if there is an error
  153. --*/
  154. {
  155. //
  156. // Check if anything on this page was changed
  157. //
  158. Verbose(("Saving 'Diagnostics Logging' page ...\n"));
  159. if (! GetChangedFlag(DIAG_LOG_PAGE))
  160. return TRUE;
  161. //
  162. // Save the fax device information if this is the last modified page
  163. //
  164. return SaveFaxDeviceAndConfigInfo(hDlg, DIAG_LOG_PAGE);
  165. }
  166. VOID
  167. DoChangeLoggingCategory(
  168. HWND hDlg,
  169. HWND hwndLV
  170. )
  171. /*++
  172. Routine Description:
  173. Called when the changes the category selection
  174. Arguments:
  175. hDlg - Handle to the "Diagnostics Logging" property page
  176. hwndLV - Handle to the logging category list view
  177. Return Value:
  178. NONE
  179. --*/
  180. {
  181. INT index, itemId;
  182. DWORD level = 0xffffffff;
  183. //
  184. // Find the common level shared by selected categories
  185. //
  186. if (hwndLV == NULL || gConfigData->pFaxLogging == NULL)
  187. return;
  188. if ((index = ListView_GetNextItem(hwndLV, -1, LVNI_ALL|LVNI_SELECTED)) != -1) {
  189. Assert(index < (INT) gConfigData->NumberCategories);
  190. level = gConfigData->pFaxLogging[index].Level;
  191. while ((index = ListView_GetNextItem(hwndLV, index, LVNI_ALL|LVNI_SELECTED)) != -1) {
  192. Assert(index < (INT) gConfigData->NumberCategories );
  193. if (gConfigData->pFaxLogging[index].Level != level) {
  194. level = 0xffffffff;
  195. break;
  196. }
  197. }
  198. }
  199. //
  200. // Map logging level to radio button control ID
  201. //
  202. switch (level) {
  203. case FAXLOG_LEVEL_NONE:
  204. itemId = IDC_LOG_NONE;
  205. break;
  206. case FAXLOG_LEVEL_MIN:
  207. itemId = IDC_LOG_MIN;
  208. break;
  209. case FAXLOG_LEVEL_MED:
  210. itemId = IDC_LOG_MED;
  211. break;
  212. case FAXLOG_LEVEL_MAX:
  213. itemId = IDC_LOG_MAX;
  214. break;
  215. default:
  216. itemId = 0;
  217. break;
  218. }
  219. for (index=IDC_LOG_NONE; index <= IDC_LOG_MAX; index++)
  220. CheckDlgButton(hDlg, index, (index == itemId) ? BST_CHECKED : BST_UNCHECKED);
  221. }
  222. VOID
  223. DoChangeLoggingLevel(
  224. HWND hDlg,
  225. INT itemId
  226. )
  227. /*++
  228. Routine Description:
  229. Change the logging level of the currently selected categories
  230. Arguments:
  231. hDlg - Handle to the "Diagnostics Logging" property page
  232. itemId - Control ID of the selected logging level
  233. Return Value:
  234. NONE
  235. --*/
  236. {
  237. HWND hwndLV;
  238. DWORD level;
  239. INT index = -1;
  240. if (!(hwndLV = GetDlgItem(hDlg, IDC_LOGGING_LIST)) || gConfigData->pFaxLogging == NULL)
  241. return;
  242. switch (itemId) {
  243. case IDC_LOG_NONE:
  244. level = FAXLOG_LEVEL_NONE;
  245. break;
  246. case IDC_LOG_MIN:
  247. level = FAXLOG_LEVEL_MIN;
  248. break;
  249. case IDC_LOG_MED:
  250. level = FAXLOG_LEVEL_MED;
  251. break;
  252. case IDC_LOG_MAX:
  253. level = FAXLOG_LEVEL_MAX;
  254. break;
  255. }
  256. while ((index = ListView_GetNextItem(hwndLV, index, LVNI_ALL|LVNI_SELECTED)) != -1) {
  257. Assert(index < (INT) gConfigData->NumberCategories);
  258. gConfigData->pFaxLogging[index].Level = level;
  259. }
  260. UpdateLoggingLevels(hwndLV);
  261. }
  262. BOOL
  263. DiagLogProc(
  264. HWND hDlg,
  265. UINT message,
  266. UINT wParam,
  267. LONG lParam
  268. )
  269. /*++
  270. Routine Description:
  271. Procedure for handling the "Diagnostics Logging" tab
  272. Arguments:
  273. hDlg - Identifies the property sheet page
  274. message - Specifies the message
  275. wParam - Specifies additional message-specific information
  276. lParam - Specifies additional message-specific information
  277. Return Value:
  278. Depends on the value of message parameter
  279. --*/
  280. {
  281. INT cmdId;
  282. NMHDR *pNMHdr;
  283. switch (message) {
  284. case WM_INITDIALOG:
  285. DoInitDiagLog(hDlg);
  286. return TRUE;
  287. case WM_COMMAND:
  288. switch (cmdId = GET_WM_COMMAND_ID(wParam, lParam)) {
  289. case IDC_LOG_NONE:
  290. case IDC_LOG_MIN:
  291. case IDC_LOG_MED:
  292. case IDC_LOG_MAX:
  293. DoChangeLoggingLevel(hDlg, cmdId);
  294. SetChangedFlag(hDlg, DIAG_LOG_PAGE, TRUE);
  295. return TRUE;
  296. default:
  297. break;
  298. }
  299. break;
  300. case WM_NOTIFY:
  301. pNMHdr = (NMHDR *) lParam;
  302. if (pNMHdr->hwndFrom == GetDlgItem(hDlg, IDC_LOGGING_LIST)) {
  303. if (pNMHdr->code == LVN_ITEMCHANGED)
  304. DoChangeLoggingCategory(hDlg, pNMHdr->hwndFrom);
  305. } else if (pNMHdr->code == PSN_APPLY) {
  306. //
  307. // User pressed OK or Apply - validate inputs and save changes
  308. //
  309. if (! DoSaveDiagLog(hDlg)) {
  310. SetWindowLong(hDlg, DWL_MSGRESULT, -1);
  311. return PSNRET_INVALID_NOCHANGEPAGE;
  312. } else {
  313. SetChangedFlag(hDlg, DIAG_LOG_PAGE, FALSE);
  314. return PSNRET_NOERROR;
  315. }
  316. }
  317. break;
  318. case WM_HELP:
  319. case WM_CONTEXTMENU:
  320. return HandleHelpPopup(hDlg, message, wParam, lParam, DIAG_LOG_PAGE);
  321. }
  322. return FALSE;
  323. }