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.

366 lines
7.7 KiB

  1. #include "faxcfgwz.h"
  2. BOOL g_bInitializing = FALSE; // TRUE during DoInitDevLimitDlg()
  3. DWORD
  4. CountSelectedDev(
  5. HWND hDlg
  6. )
  7. /*++
  8. Routine Description:
  9. Count selected devices
  10. Arguments:
  11. hDlg - Handle to the "Device limit" page
  12. Return Value:
  13. Number of the selected devices
  14. --*/
  15. {
  16. DWORD dw;
  17. HWND hwndLv;
  18. DWORD dwSelected=0; // count selected devices
  19. DEBUG_FUNCTION_NAME(TEXT("OnDevSelect()"));
  20. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  21. for (dw = 0; dw < g_wizData.dwDeviceCount; ++dw)
  22. {
  23. if(ListView_GetCheckState(hwndLv, dw))
  24. {
  25. ++dwSelected;
  26. }
  27. }
  28. return dwSelected;
  29. }
  30. VOID
  31. OnDevSelect(
  32. HWND hDlg
  33. )
  34. /*++
  35. Routine Description:
  36. Handle device selection
  37. Arguments:
  38. hDlg - Handle to the "Device limit" page
  39. Return Value:
  40. None
  41. --*/
  42. {
  43. HWND hwndLv;
  44. INT iItem;
  45. DWORD dwSelectNum; // count selected devices
  46. DEBUG_FUNCTION_NAME(TEXT("OnDevSelect()"));
  47. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  48. dwSelectNum = CountSelectedDev(hDlg);
  49. if(dwSelectNum > g_wizData.dwDeviceLimit)
  50. {
  51. //
  52. // If the user exceeds the device limit
  53. // uncheck selected device
  54. //
  55. iItem = ListView_GetNextItem(hwndLv, -1, LVNI_ALL | LVNI_SELECTED);
  56. if(iItem == -1)
  57. {
  58. Assert(FALSE);
  59. }
  60. else
  61. {
  62. ListView_SetCheckState(hwndLv, iItem, FALSE);
  63. }
  64. DisplayMessageDialog(hDlg, MB_OK | MB_ICONSTOP, 0, IDS_DEV_LIMIT_ERROR, g_wizData.dwDeviceLimit);
  65. }
  66. ShowWindow(GetDlgItem(hDlg, IDCSTATIC_NO_DEVICE_ERR), (dwSelectNum > 0) ? SW_HIDE : SW_SHOW);
  67. ShowWindow(GetDlgItem(hDlg, IDC_STATIC_NO_DEVICE), (dwSelectNum > 0) ? SW_HIDE : SW_SHOW);
  68. }
  69. VOID
  70. DoInitDevLimitDlg(
  71. HWND hDlg
  72. )
  73. /*++
  74. Routine Description:
  75. Init the "Device limit" page
  76. Arguments:
  77. hDlg - Handle to the "Device limit" page
  78. Return Value:
  79. None
  80. --*/
  81. {
  82. DWORD dw;
  83. DWORD dwSelected=0; // count selected devices
  84. BOOL bCheck;
  85. HWND hwndLv;
  86. INT iIndex;
  87. LV_ITEM lvItem = {0};
  88. DEBUG_FUNCTION_NAME(TEXT("DoInitDevLimitDlg()"));
  89. g_bInitializing = TRUE;
  90. InitDeviceList(hDlg, IDC_DEVICE_LIST);
  91. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  92. //
  93. // Fill the list of devices and select the first item.
  94. //
  95. lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  96. lvItem.iImage = DI_Modem;
  97. for (dw = 0; dw < g_wizData.dwDeviceCount; ++dw)
  98. {
  99. lvItem.iItem = dw;
  100. lvItem.pszText = g_wizData.pDevInfo[dw].szDeviceName;
  101. lvItem.lParam = dw;
  102. iIndex = ListView_InsertItem(hwndLv, &lvItem);
  103. bCheck = FALSE;
  104. if((dwSelected < g_wizData.dwDeviceLimit) &&
  105. (g_wizData.pDevInfo[dw].bSend ||
  106. (FAX_DEVICE_RECEIVE_MODE_OFF != g_wizData.pDevInfo[dw].ReceiveMode)))
  107. {
  108. bCheck = TRUE;
  109. ++dwSelected;
  110. }
  111. ListView_SetCheckState(hwndLv, iIndex, bCheck);
  112. }
  113. //
  114. // Select the first item.
  115. //
  116. ListView_SetItemState(hwndLv, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  117. OnDevSelect(hDlg);
  118. ListView_SetColumnWidth(hwndLv, 0, LVSCW_AUTOSIZE_USEHEADER );
  119. g_bInitializing = FALSE;
  120. }
  121. void
  122. DoSaveDevLimit(
  123. HWND hDlg
  124. )
  125. /*++
  126. Routine Description:
  127. Save the user's choice for devices
  128. Arguments:
  129. hDlg - Handle to the "Device limit" page
  130. Return Value:
  131. None
  132. --*/
  133. {
  134. DWORD dw;
  135. HWND hwndLv;
  136. BOOL bSelected;
  137. DEBUG_FUNCTION_NAME(TEXT("DoSaveDevLimit()"));
  138. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  139. for (dw = 0; dw < g_wizData.dwDeviceCount; ++dw)
  140. {
  141. bSelected = ListView_GetCheckState(hwndLv, dw);
  142. g_wizData.pDevInfo[dw].bSelected = bSelected;
  143. if(!bSelected)
  144. {
  145. g_wizData.pDevInfo[dw].bSend = FALSE;
  146. g_wizData.pDevInfo[dw].ReceiveMode = FAX_DEVICE_RECEIVE_MODE_OFF;
  147. }
  148. }
  149. }
  150. INT_PTR
  151. CALLBACK
  152. DevLimitDlgProc (
  153. HWND hDlg,
  154. UINT uMsg,
  155. WPARAM wParam,
  156. LPARAM lParam
  157. )
  158. /*++
  159. Routine Description:
  160. Procedure for handling the "Send Device" page
  161. Arguments:
  162. hDlg - Identifies the property sheet page
  163. uMsg - Specifies the message
  164. wParam - Specifies additional message-specific information
  165. lParam - Specifies additional message-specific information
  166. Return Value:
  167. Depends on the value of message parameter
  168. --*/
  169. {
  170. switch (uMsg)
  171. {
  172. case WM_INITDIALOG :
  173. {
  174. DoInitDevLimitDlg(hDlg);
  175. return TRUE;
  176. }
  177. case WM_COMMAND:
  178. switch(LOWORD(wParam))
  179. {
  180. default:
  181. break;
  182. }
  183. break;
  184. case WM_NOTIFY :
  185. {
  186. LPNMHDR lpnm = (LPNMHDR) lParam;
  187. switch (lpnm->code)
  188. {
  189. case PSN_SETACTIVE :
  190. // Enable the Back and Finish button
  191. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  192. break;
  193. case PSN_WIZBACK :
  194. {
  195. //
  196. // Handle a Back button click here
  197. //
  198. if(RemoveLastPage(hDlg))
  199. {
  200. return TRUE;
  201. }
  202. break;
  203. }
  204. case PSN_WIZNEXT :
  205. //
  206. // Handle a Next button click, if necessary
  207. //
  208. DoSaveDevLimit(hDlg);
  209. SetLastPage(IDD_DEVICE_LIMIT_SELECT);
  210. if(CountSelectedDev(hDlg) == 0)
  211. {
  212. //
  213. // go to the completion page
  214. //
  215. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_WIZARD_COMPLETE);
  216. return TRUE;
  217. }
  218. break;
  219. case PSN_RESET :
  220. {
  221. // Handle a Cancel button click, if necessary
  222. break;
  223. }
  224. case LVN_ITEMCHANGED:
  225. {
  226. //
  227. // need to validate the control after changing selection by keyboard
  228. //
  229. if(!g_bInitializing)
  230. {
  231. OnDevSelect(hDlg);
  232. }
  233. break;
  234. }
  235. case NM_DBLCLK:
  236. {
  237. //
  238. // Handle a double click event
  239. //
  240. INT iItem;
  241. HWND hwndLv;
  242. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  243. iItem = ((LPNMITEMACTIVATE) lParam)->iItem;
  244. ListView_SetCheckState(hwndLv, iItem, !ListView_GetCheckState(hwndLv, iItem));
  245. // we don't have break here because we'll go through NM_CLICK
  246. }
  247. case NM_CLICK:
  248. {
  249. //
  250. // Handle a Click event
  251. //
  252. INT iItem;
  253. HWND hwndLv;
  254. hwndLv = GetDlgItem(hDlg, IDC_DEVICE_LIST);
  255. iItem = ((LPNMITEMACTIVATE) lParam)->iItem;
  256. ListView_SetItemState(hwndLv, iItem, LVIS_SELECTED, LVIS_SELECTED);
  257. break;
  258. }
  259. default :
  260. break;
  261. }
  262. }
  263. break;
  264. default:
  265. break;
  266. }
  267. return FALSE;
  268. }