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.

302 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. priority.c
  5. Abstract:
  6. Functions for handling events in the "Device Priority" tab of
  7. the fax server configuration property sheet
  8. Environment:
  9. Fax configuration applet
  10. Revision History:
  11. 05/06/96 -davidx-
  12. Created it.
  13. mm/dd/yy -author-
  14. description
  15. --*/
  16. #include "faxcpl.h"
  17. VOID
  18. DoActivateDevicePriority(
  19. HWND hDlg
  20. )
  21. /*++
  22. Routine Description:
  23. Called when the "Device Priority" property page is activated
  24. Arguments:
  25. hDlg - Window handle to the "Device Priority" property page
  26. Return Value:
  27. NONE
  28. --*/
  29. {
  30. //
  31. // Information about the fax device list view
  32. //
  33. static COLUMNINFO faxDeviceListViewColumnInfo[] = {
  34. { COLUMN_DEVICE_NAME, 1 },
  35. { 0, 0 },
  36. };
  37. HWND hwndLV;
  38. //
  39. // Reinitialize the fax device list view if necessary
  40. //
  41. if (!IsFaxDeviceListInSync(DEVICE_PRIORITY_PAGE) &&
  42. (hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)))
  43. {
  44. InitFaxDeviceListView(hwndLV, 0, faxDeviceListViewColumnInfo);
  45. }
  46. SetFaxDeviceListInSync(DEVICE_PRIORITY_PAGE);
  47. }
  48. BOOL
  49. DoSaveDevicePriority(
  50. HWND hDlg
  51. )
  52. /*++
  53. Routine Description:
  54. Save the information on the "Device Priority" property page
  55. Arguments:
  56. hDlg - Handle to the "Device Priority" property page
  57. Return Value:
  58. TRUE if successful, FALSE if there is an error
  59. --*/
  60. {
  61. INT index;
  62. //
  63. // Check if anything on this page was changed
  64. //
  65. Verbose(("Saving 'Receive Options' page ...\n"));
  66. if (! GetChangedFlag(DEVICE_PRIORITY_PAGE))
  67. return TRUE;
  68. //
  69. // Assign priority to fax devices: smaller number corresponds to lower priority
  70. //
  71. for (index=0; index < gConfigData->cDevices; index++)
  72. gConfigData->pDevInfo[index].Priority = gConfigData->cDevices - index + 1;
  73. //
  74. // Save the fax device information if this is the last modified page
  75. //
  76. gConfigData->priorityChanged = TRUE;
  77. return SaveFaxDeviceAndConfigInfo(hDlg, DEVICE_PRIORITY_PAGE);
  78. }
  79. VOID
  80. DoChangeDevicePriority(
  81. HWND hDlg,
  82. INT direction
  83. )
  84. /*++
  85. Routine Description:
  86. Increment or decrement the priority of current selected fax device
  87. Arguments:
  88. hDlg - Handle to the "Device Priority" property page
  89. direction - Whether to increment or decrement the device priority
  90. -1 to increment device priority
  91. 1 to decrement device priority
  92. Return Value:
  93. NONE
  94. --*/
  95. {
  96. HWND hwndLV;
  97. INT index, newIndex, nItems;
  98. //
  99. // Get the index of the currently selected item and
  100. // count the total number of items in the list view
  101. //
  102. if ((hwndLV = GetDlgItem(hDlg, IDC_FAX_DEVICE_LIST)) == NULL ||
  103. (nItems = ListView_GetItemCount(hwndLV)) == -1 ||
  104. (index = ListView_GetNextItem(hwndLV, -1, LVNI_ALL|LVNI_SELECTED)) == -1)
  105. {
  106. return;
  107. }
  108. //
  109. // Calculate the new item index
  110. //
  111. Assert(nItems <= gConfigData->cDevices && index < nItems);
  112. if ((newIndex = index + direction) >= 0 && newIndex < nItems) {
  113. CONFIG_PORT_INFO_2 portInfo;
  114. portInfo = gConfigData->pDevInfo[index];
  115. gConfigData->pDevInfo[index] = gConfigData->pDevInfo[newIndex];
  116. gConfigData->pDevInfo[newIndex] = portInfo;
  117. gConfigData->faxDeviceSyncFlag = 0;
  118. DoActivateDevicePriority(hDlg);
  119. //
  120. // Keep the original fax device selected
  121. //
  122. ListView_SetItemState(hwndLV,
  123. newIndex,
  124. LVIS_SELECTED|LVIS_FOCUSED,
  125. LVIS_SELECTED|LVIS_FOCUSED);
  126. }
  127. }
  128. BOOL
  129. DevicePriorityProc(
  130. HWND hDlg,
  131. UINT message,
  132. UINT wParam,
  133. LONG lParam
  134. )
  135. /*++
  136. Routine Description:
  137. Procedure for handling the "Device Priority" tab
  138. Arguments:
  139. hDlg - Identifies the property sheet page
  140. message - Specifies the message
  141. wParam - Specifies additional message-specific information
  142. lParam - Specifies additional message-specific information
  143. Return Value:
  144. Depends on the value of message parameter
  145. --*/
  146. {
  147. INT cmdId;
  148. switch (message) {
  149. case WM_INITDIALOG:
  150. GetFaxDeviceAndConfigInfo();
  151. SendMessage(GetDlgItem(hDlg, IDC_MOVEUP),
  152. BM_SETIMAGE,
  153. IMAGE_ICON,
  154. (WPARAM) LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_ARROWUP)));
  155. SendMessage(GetDlgItem(hDlg, IDC_MOVEDOWN),
  156. BM_SETIMAGE,
  157. IMAGE_ICON,
  158. (LPARAM) LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_ARROWDOWN)));
  159. return TRUE;
  160. case WM_COMMAND:
  161. switch (cmdId = GET_WM_COMMAND_ID(wParam, lParam)) {
  162. case IDC_MOVEUP:
  163. case IDC_MOVEDOWN:
  164. DoChangeDevicePriority(hDlg, (cmdId == IDC_MOVEUP) ? -1 : 1);
  165. break;
  166. default:
  167. return FALSE;
  168. }
  169. SetChangedFlag(hDlg, DEVICE_PRIORITY_PAGE, TRUE);
  170. return TRUE;
  171. case WM_NOTIFY:
  172. switch (((NMHDR *) lParam)->code) {
  173. case PSN_SETACTIVE:
  174. DoActivateDevicePriority(hDlg);
  175. break;
  176. case PSN_APPLY:
  177. //
  178. // User pressed OK or Apply - validate inputs and save changes
  179. //
  180. if (! DoSaveDevicePriority(hDlg)) {
  181. SetWindowLong(hDlg, DWL_MSGRESULT, -1);
  182. return PSNRET_INVALID_NOCHANGEPAGE;
  183. } else {
  184. SetChangedFlag(hDlg, DEVICE_PRIORITY_PAGE, FALSE);
  185. return PSNRET_NOERROR;
  186. }
  187. }
  188. break;
  189. case WM_HELP:
  190. case WM_CONTEXTMENU:
  191. return HandleHelpPopup(hDlg, message, wParam, lParam, DEVICE_PRIORITY_PAGE);
  192. }
  193. return FALSE;
  194. }