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.

303 lines
8.9 KiB

  1. /*******************************************************************************
  2. *
  3. * Copyright 1999 American Power Conversion, All Rights Reserved
  4. *
  5. * TITLE: UPSCUSTOM.C
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: SteveT
  10. *
  11. * DATE: 07 June, 1999
  12. *
  13. * DESCRIPTION: This file contains all of the functions that support the
  14. * custom UPS Interface Configuration dialog.
  15. ********************************************************************************/
  16. #include "upstab.h"
  17. #include "..\pwrresid.h"
  18. #include "..\PwrMn_cs.h"
  19. /*
  20. * forward declarations
  21. */
  22. void initUPSCustomDlg(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  23. void setRadioButtons(HWND hDlg, DWORD dwTmpConfig);
  24. DWORD getRadioButtons(HWND hDlg, DWORD dwTmpConfig);
  25. static struct _customData *g_CustomData;
  26. /*
  27. * local declarations
  28. */
  29. static const DWORD g_UPSCustomHelpIDs[] =
  30. {
  31. IDC_CUSTOM_CAVEAT, NO_HELP,
  32. IDC_ONBAT_CHECK,idh_positive_negative_powerfail,
  33. IDC_ONBAT_POS,idh_positive_negative_powerfail,
  34. IDC_ONBAT_NEG,idh_positive_negative_powerfail,
  35. IDC_LOWBAT_CHECK,idh_positive_negative_low_battery,
  36. IDC_LOWBAT_POS,idh_positive_negative_low_battery,
  37. IDC_LOWBAT_NEG,idh_positive_negative_low_battery,
  38. IDC_TURNOFF_CHECK,idh_positive_negative_shutdown,
  39. IDC_TURNOFF_POS,idh_positive_negative_shutdown,
  40. IDC_TURNOFF_NEG,idh_positive_negative_shutdown,
  41. IDB_CUSTOM_BACK,idh_back,
  42. IDB_CUSTOM_FINISH,idh_finish,
  43. IDC_STATIC, NO_HELP,
  44. IDC_CUSTOM_FRAME, NO_HELP,
  45. 0,0
  46. };
  47. /*
  48. * BOOL CALLBACK UPSCustomDlgProc (HWND hDlg,
  49. * UINT uMsg,
  50. * WPARAM wParam,
  51. * LPARAM lParam);
  52. *
  53. * Description: This is a standard DialogProc associated with the UPS custom dialog
  54. *
  55. * Additional Information: See help on DialogProc
  56. *
  57. * Parameters:
  58. *
  59. * HWND hDlg :- Handle to dialog box
  60. *
  61. * UINT uMsg :- message ID
  62. *
  63. * WPARAM wParam :- Specifies additional message-specific information.
  64. *
  65. * LPARAM lParam :- Specifies additional message-specific information.
  66. *
  67. * Return Value: Except in response to the WM_INITDIALOG message, the dialog
  68. * box procedure should return nonzero if it processes the
  69. * message, and zero if it does not.
  70. */
  71. INT_PTR CALLBACK UPSCustomDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  72. {
  73. BOOL bRes = TRUE;
  74. switch (uMsg)
  75. {
  76. case WM_INITDIALOG:
  77. {
  78. initUPSCustomDlg(hDlg,uMsg,wParam,lParam);
  79. break;
  80. }
  81. case WM_COMMAND:
  82. {
  83. switch (LOWORD(wParam))
  84. {
  85. case IDC_ONBAT_CHECK:
  86. EnableWindow( GetDlgItem( hDlg, IDC_ONBAT_POS ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_ONBAT_CHECK)) );
  87. EnableWindow( GetDlgItem( hDlg, IDC_ONBAT_NEG ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_ONBAT_CHECK)) );
  88. break;
  89. case IDC_LOWBAT_CHECK:
  90. EnableWindow( GetDlgItem( hDlg, IDC_LOWBAT_POS ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_LOWBAT_CHECK)) );
  91. EnableWindow( GetDlgItem( hDlg, IDC_LOWBAT_NEG ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_LOWBAT_CHECK)) );
  92. break;
  93. case IDC_TURNOFF_CHECK:
  94. EnableWindow( GetDlgItem( hDlg, IDC_TURNOFF_POS ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_TURNOFF_CHECK)) );
  95. EnableWindow( GetDlgItem( hDlg, IDC_TURNOFF_NEG ), (BST_CHECKED == IsDlgButtonChecked(hDlg,IDC_TURNOFF_CHECK)) );
  96. break;
  97. case IDB_CUSTOM_BACK:
  98. case IDB_CUSTOM_FINISH:
  99. {
  100. // save the options settings
  101. *(g_CustomData->lpdwCurrentCustomOptions) = getRadioButtons( hDlg,
  102. *(g_CustomData->lpdwCurrentCustomOptions));
  103. EndDialog(hDlg,wParam);
  104. break;
  105. }
  106. case IDCANCEL: // escape key
  107. {
  108. EndDialog(hDlg,wParam);
  109. break;
  110. }
  111. default:
  112. bRes = FALSE;
  113. }
  114. break;
  115. }
  116. case WM_CLOSE:
  117. {
  118. EndDialog(hDlg,IDCANCEL);
  119. break;
  120. }
  121. case WM_HELP: //F1 or question box
  122. {
  123. WinHelp(((LPHELPINFO)lParam)->hItemHandle,
  124. PWRMANHLP,
  125. HELP_WM_HELP,
  126. (ULONG_PTR)(LPTSTR)g_UPSCustomHelpIDs);
  127. break;
  128. }
  129. case WM_CONTEXTMENU: // right mouse click help
  130. {
  131. WinHelp((HWND)wParam,
  132. PWRMANHLP,
  133. HELP_CONTEXTMENU,
  134. (ULONG_PTR)(LPTSTR)g_UPSCustomHelpIDs);
  135. break;
  136. }
  137. default:
  138. {
  139. bRes = FALSE;
  140. }
  141. }
  142. return bRes;
  143. }
  144. /*
  145. * void initUPSCustomDlg (HWND hDlg,
  146. * UINT uMsg,
  147. * WPARAM wParam,
  148. * LPARAM lParam);
  149. *
  150. * Description: initializes global data and controls for UPS custom dialog
  151. *
  152. * Additional Information:
  153. *
  154. * Parameters:
  155. *
  156. * HWND hDlg :- Handle to dialog box
  157. *
  158. * UINT uMsg :- message ID
  159. *
  160. * WPARAM wParam :- Specifies additional message-specific information.
  161. *
  162. * LPARAM lParam :- Specifies additional message-specific information.
  163. *
  164. * Return Value: none
  165. */
  166. void initUPSCustomDlg(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  167. {
  168. TCHAR szCustomCaption[MAX_PATH] = _T("");
  169. g_CustomData = (struct _customData*)lParam;
  170. /*
  171. * initialize the title of the dialog box
  172. * We can't get "here" without a port being
  173. * defined, so there's no need to check that
  174. * one is returned; is has to have been
  175. */
  176. LoadString( GetUPSModuleHandle(),
  177. IDS_CUSTOM_CAPTION,
  178. szCustomCaption,
  179. sizeof(szCustomCaption)/sizeof(TCHAR));
  180. // Check buffer to ensure that there is sufficient room to append the port to the caption string
  181. if ((_tcslen(szCustomCaption) + _tcslen(g_CustomData->lpszCurrentPort)) < (sizeof(szCustomCaption)/sizeof(TCHAR))) {
  182. _tcscat( szCustomCaption, g_CustomData->lpszCurrentPort);
  183. }
  184. SetWindowText( hDlg, szCustomCaption);
  185. /*
  186. * init the radio buttons according to the UPS options flags.
  187. */
  188. setRadioButtons( hDlg, *(g_CustomData->lpdwCurrentCustomOptions));
  189. }
  190. /*
  191. * void setRadioButtons (HWND hDlg);
  192. *
  193. * Description: updates the polarity radio buttons
  194. *
  195. * Additional Information:
  196. *
  197. * Parameters:
  198. *
  199. * HWND hDlg :- Handle to dialog box
  200. *
  201. * Return Value: none
  202. */
  203. void setRadioButtons(HWND hDlg, DWORD dwTmpConfig)
  204. {
  205. /*
  206. * set the radio buttons
  207. * NOTE: These funcs require the button IDs to be sequential
  208. */
  209. CheckDlgButton (hDlg, IDC_ONBAT_CHECK , (BOOL) dwTmpConfig & UPS_POWERFAILSIGNAL);
  210. CheckDlgButton (hDlg, IDC_LOWBAT_CHECK , (BOOL) dwTmpConfig & UPS_LOWBATTERYSIGNAL);
  211. CheckDlgButton (hDlg, IDC_TURNOFF_CHECK , (BOOL) dwTmpConfig & UPS_SHUTOFFSIGNAL);
  212. CheckRadioButton( hDlg,
  213. IDC_ONBAT_POS,
  214. IDC_ONBAT_NEG,
  215. (dwTmpConfig & UPS_POSSIGONPOWERFAIL)?IDC_ONBAT_POS:IDC_ONBAT_NEG);
  216. EnableWindow( GetDlgItem( hDlg, IDC_ONBAT_POS ), (BOOL) dwTmpConfig & UPS_POWERFAILSIGNAL );
  217. EnableWindow( GetDlgItem( hDlg, IDC_ONBAT_NEG ), (BOOL) dwTmpConfig & UPS_POWERFAILSIGNAL );
  218. CheckRadioButton( hDlg,
  219. IDC_LOWBAT_POS,
  220. IDC_LOWBAT_NEG,
  221. (dwTmpConfig & UPS_POSSIGONLOWBATTERY)?IDC_LOWBAT_POS:IDC_LOWBAT_NEG);
  222. EnableWindow( GetDlgItem( hDlg, IDC_LOWBAT_POS ), (BOOL) dwTmpConfig & UPS_LOWBATTERYSIGNAL );
  223. EnableWindow( GetDlgItem( hDlg, IDC_LOWBAT_NEG ), (BOOL) dwTmpConfig & UPS_LOWBATTERYSIGNAL );
  224. CheckRadioButton( hDlg,
  225. IDC_TURNOFF_POS,
  226. IDC_TURNOFF_NEG,
  227. (dwTmpConfig & UPS_POSSIGSHUTOFF)?IDC_TURNOFF_POS:IDC_TURNOFF_NEG);
  228. EnableWindow( GetDlgItem( hDlg, IDC_TURNOFF_POS ), (BOOL) dwTmpConfig & UPS_SHUTOFFSIGNAL );
  229. EnableWindow( GetDlgItem( hDlg, IDC_TURNOFF_NEG ), (BOOL) dwTmpConfig & UPS_SHUTOFFSIGNAL );
  230. }
  231. /*
  232. * void getRadioButtons (HWND hDlg);
  233. *
  234. * Description: reads the polarity radio buttons
  235. *
  236. * Additional Information:
  237. *
  238. * Parameters:
  239. *
  240. * HWND hDlg :- Handle to dialog box
  241. *
  242. * Return Value: none
  243. */
  244. DWORD getRadioButtons(HWND hDlg, DWORD dwTmpConfig)
  245. {
  246. /*
  247. * NOTE: We are forcing the UPS, PowerFail signal, Low Battery signal
  248. * and Turn Off signal bits to true, just as a precautionary measure.
  249. */
  250. // dwTmpConfig |= UPS_DEFAULT_SIGMASK;
  251. // dwTmpConfig |= UPS_INSTALLED;
  252. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_ONBAT_CHECK)) ?
  253. (dwTmpConfig | UPS_POWERFAILSIGNAL) :
  254. (dwTmpConfig & ~UPS_POWERFAILSIGNAL);
  255. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_LOWBAT_CHECK)) ?
  256. (dwTmpConfig | UPS_LOWBATTERYSIGNAL) :
  257. (dwTmpConfig & ~UPS_LOWBATTERYSIGNAL);
  258. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_TURNOFF_CHECK)) ?
  259. (dwTmpConfig | UPS_SHUTOFFSIGNAL) :
  260. (dwTmpConfig & ~UPS_SHUTOFFSIGNAL);
  261. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_ONBAT_POS)) ?
  262. (dwTmpConfig | UPS_POSSIGONPOWERFAIL) :
  263. (dwTmpConfig & ~UPS_POSSIGONPOWERFAIL);
  264. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_LOWBAT_POS)) ?
  265. (dwTmpConfig | UPS_POSSIGONLOWBATTERY) :
  266. (dwTmpConfig & ~UPS_POSSIGONLOWBATTERY);
  267. dwTmpConfig = (BST_CHECKED==IsDlgButtonChecked(hDlg,IDC_TURNOFF_POS)) ?
  268. (dwTmpConfig | UPS_POSSIGSHUTOFF) :
  269. (dwTmpConfig & ~UPS_POSSIGSHUTOFF);
  270. return dwTmpConfig;
  271. }