Windows NT 4.0 source code leak
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.

328 lines
8.4 KiB

4 years ago
  1. /******************************Module*Header*******************************\
  2. * Module Name: preferen.c
  3. *
  4. * Code to support the preferneces dialog box.
  5. *
  6. *
  7. * Created: dd-mm-94
  8. * Author: Stephen Estrop [StephenE]
  9. *
  10. * Copyright (c) 1994 Microsoft Corporation
  11. \**************************************************************************/
  12. #pragma warning( once : 4201 4214 )
  13. #define NOOLE
  14. #include <windows.h> /* required for all Windows applications */
  15. #include <windowsx.h>
  16. #include "resource.h"
  17. #include "cdplayer.h"
  18. #include "preferen.h"
  19. /* --------------------------------------------------------------------
  20. ** Other stuff
  21. ** --------------------------------------------------------------------
  22. */
  23. #include <commctrl.h>
  24. WNDPROC lpfnDefBtnProc;
  25. HWND hwndPrefDlg;
  26. LRESULT CALLBACK
  27. SubClassedBtnProc(
  28. HWND hwnd,
  29. UINT message,
  30. WPARAM wParam,
  31. LPARAM lParam
  32. );
  33. /* -------------------------------------------------------------------------
  34. ** Private Globals
  35. ** -------------------------------------------------------------------------
  36. */
  37. BOOL fSmallFont;
  38. /******************************Public*Routine******************************\
  39. * PreferencesDlgProc
  40. *
  41. *
  42. *
  43. * History:
  44. * dd-mm-93 - StephenE - Created
  45. *
  46. \**************************************************************************/
  47. BOOL CALLBACK
  48. PreferencesDlgProc(
  49. HWND hwnd,
  50. UINT message,
  51. WPARAM wParam,
  52. LPARAM lParam
  53. )
  54. {
  55. #if WINVER >= 0x0400
  56. #include "literals.h"
  57. #include "helpids.h"
  58. static const DWORD aIds[] = {
  59. IDC_STOP_CD_ON_EXIT, IDH_CD_STOP_CD_ON_EXIT,
  60. IDC_SAVE_ON_EXIT, IDH_CD_SAVE_ON_EXIT,
  61. IDC_SHOW_TOOLTIPS, IDH_CD_SHOW_TOOLTIPS,
  62. IDC_INTRO_PLAY_LEN, IDH_CD_INTRO_LENGTH,
  63. IDC_INTRO_SPINBTN, IDH_CD_INTRO_LENGTH,
  64. IDC_SMALL_FONT, IDH_CD_DISPLAY_FONT,
  65. IDC_LARGE_FONT, IDH_CD_DISPLAY_FONT,
  66. IDC_LED_DISPLAY, IDH_CD_DISPLAY_FONT,
  67. 0, 0
  68. };
  69. #endif
  70. switch ( message ) {
  71. HANDLE_MSG( hwnd, WM_INITDIALOG, Preferences_OnInitDialog );
  72. HANDLE_MSG( hwnd, WM_COMMAND, Preferences_OnCommand );
  73. #ifdef DAYTONA
  74. HANDLE_MSG( hwnd, WM_CTLCOLORDLG, Common_OnCtlColor );
  75. HANDLE_MSG( hwnd, WM_CTLCOLORSTATIC, Common_OnCtlColor );
  76. HANDLE_MSG( hwnd, WM_CTLCOLORBTN, Common_OnCtlColor );
  77. #endif
  78. #if WINVER >= 0x0400
  79. case WM_HELP:
  80. WinHelp( ((LPHELPINFO)lParam)->hItemHandle, g_HelpFileName,
  81. HELP_WM_HELP, (DWORD)(LPVOID)aIds );
  82. break;
  83. case WM_CONTEXTMENU:
  84. WinHelp( (HWND)wParam, g_HelpFileName,
  85. HELP_CONTEXTMENU, (DWORD)(LPVOID)aIds );
  86. break;
  87. #endif
  88. default:
  89. return FALSE;
  90. }
  91. }
  92. /*****************************Private*Routine******************************\
  93. * Preferences_OnInitDialog
  94. *
  95. *
  96. *
  97. * History:
  98. * dd-mm-94 - StephenE - Created
  99. *
  100. \**************************************************************************/
  101. BOOL
  102. Preferences_OnInitDialog(
  103. HWND hwnd,
  104. HWND hwndFocus,
  105. LPARAM lParam
  106. )
  107. {
  108. fSmallFont = g_fSmallLedFont;
  109. if (!g_fSmallLedFont) {
  110. LED_ToggleDisplayFont( GetDlgItem( hwnd, IDC_LED_DISPLAY ), g_fSmallLedFont );
  111. }
  112. Button_SetCheck( GetDlgItem( hwnd, IDC_SMALL_FONT ), g_fSmallLedFont );
  113. Button_SetCheck( GetDlgItem( hwnd, IDC_LARGE_FONT ), !g_fSmallLedFont );
  114. Button_SetCheck( GetDlgItem( hwnd, IDC_STOP_CD_ON_EXIT ), g_fStopCDOnExit );
  115. Button_SetCheck( GetDlgItem( hwnd, IDC_SAVE_ON_EXIT ), g_fSaveOnExit );
  116. Button_SetCheck( GetDlgItem( hwnd, IDC_SHOW_TOOLTIPS ), g_fToolTips );
  117. #if WINVER >= 0x400
  118. /*
  119. ** Set up the intro play length edit field
  120. */
  121. Edit_LimitText( GetDlgItem( hwnd, IDC_INTRO_PLAY_LEN ), 2 );
  122. SetDlgItemInt( hwnd, IDC_INTRO_PLAY_LEN, g_IntroPlayLength, TRUE );
  123. SendDlgItemMessage( hwnd, IDC_INTRO_SPINBTN, UDM_SETRANGE, 0,
  124. MAKELPARAM( INTRO_UPPER_LEN, INTRO_LOWER_LEN) );
  125. /*
  126. ** Subclass the OK button so that we can perform validation on the
  127. ** intro play length.
  128. */
  129. lpfnDefBtnProc = SubclassWindow( GetDlgItem(hwnd, IDOK),
  130. SubClassedBtnProc );
  131. hwndPrefDlg = hwnd;
  132. #endif
  133. return TRUE;
  134. }
  135. /*****************************Private*Routine******************************\
  136. * Preferences_OnCommand
  137. *
  138. *
  139. *
  140. * History:
  141. * dd-mm-94 - StephenE - Created
  142. *
  143. \**************************************************************************/
  144. void
  145. Preferences_OnCommand(
  146. HWND hwnd,
  147. int id,
  148. HWND hwndCtl,
  149. UINT codeNotify
  150. )
  151. {
  152. switch (id) {
  153. case IDC_SMALL_FONT:
  154. if (!fSmallFont) {
  155. fSmallFont = TRUE;
  156. LED_ToggleDisplayFont( GetDlgItem( hwnd, IDC_LED_DISPLAY ), fSmallFont );
  157. }
  158. break;
  159. case IDC_LARGE_FONT:
  160. if (fSmallFont) {
  161. fSmallFont = FALSE;
  162. LED_ToggleDisplayFont( GetDlgItem( hwnd, IDC_LED_DISPLAY ), fSmallFont );
  163. }
  164. break;
  165. case IDOK:
  166. if ( fSmallFont != g_fSmallLedFont ) {
  167. g_fSmallLedFont = fSmallFont;
  168. LED_ToggleDisplayFont( g_hwndControls[INDEX(IDC_LED)], g_fSmallLedFont );
  169. UpdateDisplay( DISPLAY_UPD_LED );
  170. }
  171. g_fToolTips = Button_GetCheck( GetDlgItem( hwnd, IDC_SHOW_TOOLTIPS ));
  172. EnableToolTips( g_fToolTips );
  173. g_fSaveOnExit = Button_GetCheck( GetDlgItem( hwnd, IDC_SAVE_ON_EXIT ) );
  174. g_fStopCDOnExit = Button_GetCheck( GetDlgItem( hwnd, IDC_STOP_CD_ON_EXIT ) );
  175. #if WINVER >= 0x400
  176. {
  177. BOOL fSuccess;
  178. g_IntroPlayLength = (int)GetDlgItemInt( hwnd, IDC_INTRO_PLAY_LEN,
  179. &fSuccess, TRUE );
  180. /*
  181. ** As the edit field has already been validated the call above
  182. ** should not fail. But just make one final check...
  183. */
  184. if (!fSuccess) {
  185. g_IntroPlayLength = 10;
  186. }
  187. /*
  188. ** Make sure that the intro length is kept within its correct
  189. ** bounds.
  190. */
  191. g_IntroPlayLength = min(g_IntroPlayLength, INTRO_UPPER_LEN);
  192. g_IntroPlayLength = max(g_IntroPlayLength, INTRO_LOWER_LEN);
  193. }
  194. #endif
  195. /* fall thru */
  196. case IDCANCEL:
  197. EndDialog( hwnd, id );
  198. break;
  199. }
  200. }
  201. #if WINVER >= 0x400
  202. /*****************************Private*Routine******************************\
  203. * SubClassedBtnProc
  204. *
  205. * This function is used to ensure that the Intro play length edit field
  206. * always contains a valid integer number. Valid numbers are between
  207. * INTRO_LOWER_LEN and INTRO_UPPER_LEN inclusive.
  208. * ie. INTRO_LOWER_LEN >= i >= INTRO_UPPER_LEN
  209. *
  210. * History:
  211. * dd-mm-94 - StephenE - Created
  212. *
  213. \**************************************************************************/
  214. LRESULT CALLBACK
  215. SubClassedBtnProc(
  216. HWND hwnd,
  217. UINT message,
  218. WPARAM wParam,
  219. LPARAM lParam
  220. )
  221. {
  222. /*
  223. ** When the user clicks on the OK button we get a BM_SETSTATE message
  224. ** with wParam != 0. When we get this message we should ensure that
  225. ** the Intro length edit box contains a valid integer number.
  226. */
  227. if ( (message == BM_SETSTATE) && (wParam != 0) ) {
  228. BOOL fSuccess;
  229. int i;
  230. /*
  231. ** Read the current edit field value.
  232. */
  233. i = (int)GetDlgItemInt( hwndPrefDlg, IDC_INTRO_PLAY_LEN,
  234. &fSuccess, TRUE );
  235. /*
  236. ** if the above call failed it probably means that the users
  237. ** has entered junk in the edit field - so default back to the
  238. ** original value of g_IntroPlayLength.
  239. */
  240. if (!fSuccess) {
  241. i = g_IntroPlayLength;
  242. }
  243. /*
  244. ** Make sure that the intro length is kept within its correct
  245. ** bounds.
  246. */
  247. if (i < INTRO_LOWER_LEN) {
  248. i = INTRO_LOWER_LEN;
  249. fSuccess = FALSE;
  250. }
  251. else if (i > INTRO_UPPER_LEN) {
  252. i = INTRO_UPPER_LEN;
  253. fSuccess = FALSE;
  254. }
  255. /*
  256. ** We only update the edit field if its value has
  257. ** become invalid.
  258. */
  259. if (!fSuccess) {
  260. SetDlgItemInt( hwndPrefDlg, IDC_INTRO_PLAY_LEN, i, TRUE );
  261. UpdateWindow( GetDlgItem( hwndPrefDlg, IDC_INTRO_PLAY_LEN ) );
  262. }
  263. }
  264. /*
  265. ** Make sure that we pass on all messages to the buttons original
  266. ** window proc.
  267. */
  268. return CallWindowProc( lpfnDefBtnProc, hwnd, message, wParam, lParam);
  269. }
  270. #endif