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.

474 lines
14 KiB

4 years ago
  1. /******************************Module*Header*******************************\
  2. * Module Name: dialog.c
  3. *
  4. * Dialog box functions for the OpenGL-based 3D Text screen saver.
  5. *
  6. * Created: 12-24-94 -by- Marc Fortier [marcfo]
  7. *
  8. * Copyright (c) 1994 Microsoft Corporation
  9. \**************************************************************************/
  10. #include <windows.h>
  11. #include <commdlg.h>
  12. #include <scrnsave.h>
  13. #include <GL\gl.h>
  14. #include <math.h>
  15. #include <memory.h>
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <malloc.h>
  21. #include <sys\timeb.h>
  22. #include <time.h>
  23. #include "sscommon.h"
  24. #include "sstext3d.h"
  25. // Global screen saver settings.
  26. static int idsStyles[NUM_DEMOS] =
  27. {IDS_DEMO_STRING, IDS_DEMO_CLOCK};
  28. static int idsRotStyles[NUM_ROTSTYLES] =
  29. { IDS_ROTSTYLE_NONE,
  30. IDS_ROTSTYLE_SEESAW,
  31. IDS_ROTSTYLE_WOBBLE,
  32. IDS_ROTSTYLE_RANDOM
  33. };
  34. // local funtions
  35. LONG WndProc(HWND, UINT, WPARAM, LPARAM);
  36. static void InitAttrContext( AttrContext *pac );
  37. static void getFont( HWND hDlg);
  38. static void updateDialogControls(HWND hDlg);
  39. /******************************Public*Routine******************************\
  40. * getIniSettings
  41. *
  42. * Get the screen saver configuration options from .INI file/registry.
  43. *
  44. * History:
  45. * Jan. 95 -by- Marc Fortier [marcfo]
  46. * - Wrote it.
  47. * Apr. 28, 95 : [marcfo]
  48. * - Call common function ss_GetDefaultBmp to get a default bmp file
  49. * Nov. 95 [marcfo]
  50. * - Use ss registry helper functions
  51. *
  52. \**************************************************************************/
  53. void
  54. getIniSettings()
  55. {
  56. int options;
  57. int optMask = 1;
  58. TCHAR szDefaultBitmap[MAX_PATH];
  59. int iPos;
  60. // Initialize the global AttrContext
  61. InitAttrContext( &gac );
  62. // Load resources
  63. LoadString(hMainInstance, IDS_GENNAME, szScreenSaver,
  64. sizeof(szScreenSaver) / sizeof(TCHAR));
  65. // Get registry settings
  66. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  67. {
  68. // get demo type
  69. gac.demoType = ss_GetRegistryInt( IDS_DEMOTYPE, DEMO_STRING );
  70. SS_CLAMP_TO_RANGE2( gac.demoType, 0, MAX_DEMO);
  71. // get rotation style
  72. gac.rotStyle = ss_GetRegistryInt( IDS_ROTSTYLE, ROTSTYLE_RANDOM );
  73. SS_CLAMP_TO_RANGE2( gac.rotStyle, 0, NUM_ROTSTYLES-1 );
  74. // get tesselation
  75. iPos = ss_GetRegistryInt( IDS_TESSELATION, 10 );
  76. SS_CLAMP_TO_RANGE2( iPos, MIN_SLIDER, MAX_SLIDER );
  77. gac.fTesselFact = (float)iPos / 100.0f;
  78. // get size
  79. gac.uSize = ss_GetRegistryInt( IDS_SIZE, 50 );
  80. SS_CLAMP_TO_RANGE2( gac.uSize, MIN_SLIDER, MAX_SLIDER );
  81. // get speed
  82. gac.iSpeed = ss_GetRegistryInt( IDS_SPEED, 50 );
  83. SS_CLAMP_TO_RANGE2( gac.iSpeed, MIN_SLIDER, MAX_SLIDER );
  84. // get surface style
  85. gac.surfStyle = ss_GetRegistryInt( IDS_SURFSTYLE, SURFSTYLE_SOLID );
  86. SS_CLAMP_TO_RANGE2(gac.surfStyle, 0, SURFSTYLE_TEX);
  87. // get font, attributes, and charset
  88. ss_GetRegistryString( IDS_FONT, TEXT("Arial"), gac.szFontName, LF_FACESIZE);
  89. options = ss_GetRegistryInt( IDS_FONT_ATTRIBUTES, 0 );
  90. if( options >= 0 ) {
  91. optMask = 1;
  92. gac.bBold = ((options & optMask) != 0);
  93. optMask <<=1;
  94. gac.bItalic = ((options & optMask) != 0);
  95. }
  96. gac.charSet = ss_GetRegistryInt( IDS_CHARSET, 0 );
  97. // get display string
  98. ss_GetRegistryString( IDS_TEXT, TEXT("OpenGL"), gac.szText, TEXT_LIMIT+1);
  99. // Determine the default .bmp file
  100. ss_GetDefaultBmpFile( szDefaultBitmap );
  101. // Is there a texture specified in the registry that overrides the
  102. // default?
  103. ss_GetRegistryString( IDS_TEXTURE, szDefaultBitmap, gac.texFile.szPathName,
  104. MAX_PATH);
  105. gac.texFile.nOffset = ss_GetRegistryInt( IDS_TEXTURE_FILE_OFFSET, 0 );
  106. }
  107. }
  108. /**************************************************************************\
  109. * ConfigInit
  110. *
  111. \**************************************************************************/
  112. BOOL
  113. ss_ConfigInit( HWND hDlg )
  114. {
  115. return TRUE;
  116. }
  117. /**************************************************************************\
  118. * InitAttrContext
  119. *
  120. * Initialize some of the values in the attribute context
  121. *
  122. * History:
  123. * Jan. 95 -by- Marc Fortier [marcfo]
  124. * Wrote it.
  125. \**************************************************************************/
  126. static void
  127. InitAttrContext( AttrContext *pac )
  128. {
  129. // set some default values
  130. pac->demoType = DEMO_STRING;
  131. pac->surfStyle = SURFSTYLE_SOLID;
  132. pac->fTesselFact = 1.0f;
  133. pac->uSize = 50;
  134. pac->iSpeed = 50;
  135. pac->texFile.szPathName[0] = '\0';
  136. pac->texFile.nOffset = 0;
  137. }
  138. /******************************Public*Routine******************************\
  139. * saveIniSettings
  140. *
  141. * Save the screen saver configuration option to the .INI file/registry.
  142. *
  143. * History:
  144. * Jan. 95 -by- Marc Fortier [marcfo]
  145. * Wrote it.
  146. * Nov. 95 [marcfo]
  147. * - Use ss registry helper functions
  148. \**************************************************************************/
  149. static void
  150. saveIniSettings(HWND hDlg)
  151. {
  152. int options;
  153. int optMask = 1;
  154. GetWindowText( GetDlgItem(hDlg, DLG_TEXT_ENTER), gac.szText, TEXT_LIMIT+1);
  155. if( ss_RegistrySetup( hMainInstance, IDS_SAVERNAME, IDS_INIFILE ) )
  156. {
  157. ss_WriteRegistryInt( IDS_DEMOTYPE, gac.demoType );
  158. ss_WriteRegistryInt( IDS_ROTSTYLE, gac.rotStyle );
  159. ss_WriteRegistryInt( IDS_TESSELATION,
  160. ss_GetTrackbarPos(hDlg, DLG_SETUP_TESSEL) );
  161. ss_WriteRegistryInt( IDS_SIZE,
  162. ss_GetTrackbarPos(hDlg, DLG_SETUP_SIZE) );
  163. ss_WriteRegistryInt( IDS_SPEED,
  164. ss_GetTrackbarPos(hDlg, DLG_SETUP_SPEED) );
  165. ss_WriteRegistryInt( IDS_SURFSTYLE, gac.surfStyle );
  166. ss_WriteRegistryString( IDS_FONT, gac.szFontName );
  167. optMask = 1;
  168. options = gac.bBold ? optMask : 0;
  169. optMask <<= 1;
  170. options |= gac.bItalic ? optMask : 0;
  171. ss_WriteRegistryInt( IDS_FONT_ATTRIBUTES, options );
  172. ss_WriteRegistryInt( IDS_CHARSET, gac.charSet );
  173. ss_WriteRegistryString( IDS_TEXT, gac.szText );
  174. ss_WriteRegistryString( IDS_TEXTURE, gac.texFile.szPathName );
  175. ss_WriteRegistryInt( IDS_TEXTURE_FILE_OFFSET, gac.texFile.nOffset );
  176. }
  177. }
  178. /******************************Public*Routine******************************\
  179. * setupDialogControls
  180. *
  181. * Do initial setup of dialog controls.
  182. *
  183. * History:
  184. * Jan. 95 -by- Marc Fortier [marcfo]
  185. * Wrote it.
  186. \**************************************************************************/
  187. static void
  188. setupDialogControls(HWND hDlg)
  189. {
  190. int pos;
  191. InitCommonControls();
  192. // initialize sliders
  193. // tesselation slider
  194. pos = (int)(gac.fTesselFact * 100.0f);
  195. ss_SetupTrackbar( hDlg, DLG_SETUP_TESSEL, MIN_SLIDER, MAX_SLIDER, 1, 9,
  196. pos );
  197. // size slider
  198. ss_SetupTrackbar( hDlg, DLG_SETUP_SIZE, MIN_SLIDER, MAX_SLIDER, 1, 9,
  199. gac.uSize );
  200. // speed slider
  201. ss_SetupTrackbar( hDlg, DLG_SETUP_SPEED, MIN_SLIDER, MAX_SLIDER, 1, 9,
  202. gac.iSpeed);
  203. // set state of other controls
  204. updateDialogControls(hDlg);
  205. }
  206. /******************************Public*Routine******************************\
  207. * updateDialogControls
  208. *
  209. * Updates dialog controls according to current state
  210. *
  211. * History:
  212. * Jan. 95 -by- Marc Fortier [marcfo]
  213. * Wrote it.
  214. \**************************************************************************/
  215. static void
  216. updateDialogControls(HWND hDlg)
  217. {
  218. int pos;
  219. BOOL bTexSurf;
  220. BOOL bText;
  221. bTexSurf = (gac.surfStyle == SURFSTYLE_TEX );
  222. CheckDlgButton(hDlg, IDC_RADIO_SOLID, !bTexSurf );
  223. CheckDlgButton(hDlg, IDC_RADIO_TEX , bTexSurf );
  224. // set up demo-specific configure button
  225. bText = (gac.demoType == DEMO_STRING) ? TRUE : FALSE;
  226. EnableWindow(GetDlgItem(hDlg, DLG_TEXT_ENTER), bText );
  227. CheckDlgButton(hDlg, IDC_DEMO_STRING, bText );
  228. CheckDlgButton(hDlg, IDC_DEMO_CLOCK, !bText );
  229. // texture: only enable if surfStyle is texture
  230. EnableWindow(GetDlgItem(hDlg, DLG_SETUP_TEX), bTexSurf );
  231. }
  232. /******************************Public*Routine******************************\
  233. * getFont
  234. *
  235. * Calls ChooseFont dialog
  236. *
  237. * History:
  238. * Jan. 95 -by- Marc Fortier [marcfo]
  239. * Wrote it.
  240. \**************************************************************************/
  241. static void
  242. getFont( HWND hDlg)
  243. {
  244. CHOOSEFONT cf = {0};
  245. LOGFONT lf = {0};
  246. HFONT hfont, hfontOld;
  247. HDC hdc;
  248. hdc = GetDC( hDlg );
  249. // Create and select a font.
  250. cf.lStructSize = sizeof(CHOOSEFONT);
  251. cf.hwndOwner = hDlg;
  252. cf.lpLogFont = &lf;
  253. cf.hInstance = hMainInstance;
  254. cf.lpTemplateName = (LPTSTR) MAKEINTRESOURCE(IDD_FONT);
  255. cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_TTONLY |
  256. CF_ENABLETEMPLATE | CF_NOSIMULATIONS;
  257. // setup logfont with current settings
  258. lstrcpy(lf.lfFaceName, gac.szFontName);
  259. lf.lfWeight = (gac.bBold) ? FW_BOLD : FW_NORMAL;
  260. lf.lfItalic = (gac.bItalic) ? (BYTE) 1 : 0;
  261. lf.lfCharSet = gac.charSet;
  262. lf.lfHeight = -37; // value ???
  263. if( ChooseFont(&cf) ) {
  264. // retrieve settings into gac
  265. lstrcpy( gac.szFontName, lf.lfFaceName );
  266. gac.bBold = (lf.lfWeight == FW_NORMAL) ? FALSE : TRUE;
  267. gac.bItalic = (lf.lfItalic) ? TRUE : FALSE;
  268. gac.charSet = lf.lfCharSet;
  269. }
  270. }
  271. BOOL WINAPI RegisterDialogClasses(HANDLE hinst)
  272. {
  273. return TRUE;
  274. }
  275. /******************************Public*Routine******************************\
  276. * ScreenSaverConfigureDialog
  277. *
  278. * Processes messages for the configuration dialog box.
  279. *
  280. * History:
  281. * Jan. 95 -by- Marc Fortier [marcfo]
  282. * - Wrote it.
  283. * Apr. 28, 95 : [marcfo]
  284. * - Call common function ss_GetTextureBitmap to load bmp texture
  285. *
  286. \**************************************************************************/
  287. BOOL ScreenSaverConfigureDialog(HWND hDlg, UINT message,
  288. WPARAM wParam, LPARAM lParam)
  289. {
  290. int wTmp;
  291. TCHAR szStr[GEN_STRING_SIZE];
  292. HANDLE hInst;
  293. BOOL bEnable;
  294. HWND hText;
  295. switch (message) {
  296. case WM_INITDIALOG:
  297. getIniSettings();
  298. setupDialogControls(hDlg);
  299. // setup rotStyle combo box
  300. for (wTmp = 0; wTmp < NUM_ROTSTYLES; wTmp++) {
  301. LoadString(hMainInstance, idsRotStyles[wTmp], szStr,
  302. GEN_STRING_SIZE);
  303. SendDlgItemMessage(hDlg, DLG_SETUP_ROTSTYLE, CB_ADDSTRING, 0,
  304. (LPARAM) szStr);
  305. }
  306. SendDlgItemMessage(hDlg, DLG_SETUP_ROTSTYLE, CB_SETCURSEL,
  307. gac.rotStyle, 0);
  308. // display current string in box
  309. SendDlgItemMessage( hDlg, DLG_TEXT_ENTER, EM_LIMITTEXT, TEXT_LIMIT,0);
  310. SetWindowText( GetDlgItem(hDlg, DLG_TEXT_ENTER), gac.szText );
  311. return TRUE;
  312. case WM_COMMAND:
  313. switch (LOWORD(wParam)) {
  314. case DLG_SETUP_TYPES:
  315. switch (HIWORD(wParam))
  316. {
  317. case CBN_EDITCHANGE:
  318. case CBN_SELCHANGE:
  319. gac.demoType =
  320. SendDlgItemMessage(hDlg, DLG_SETUP_TYPES,
  321. CB_GETCURSEL, 0, 0);
  322. updateDialogControls(hDlg);
  323. break;
  324. default:
  325. break;
  326. }
  327. return FALSE;
  328. case DLG_SETUP_ROTSTYLE:
  329. switch (HIWORD(wParam))
  330. {
  331. case CBN_EDITCHANGE:
  332. case CBN_SELCHANGE:
  333. gac.rotStyle =
  334. SendDlgItemMessage(hDlg, DLG_SETUP_ROTSTYLE,
  335. CB_GETCURSEL, 0, 0);
  336. updateDialogControls(hDlg);
  337. break;
  338. default:
  339. break;
  340. }
  341. return FALSE;
  342. case DLG_SETUP_TEX:
  343. // Run choose texture dialog
  344. ss_SelectTextureFile( hDlg, &gac.texFile );
  345. break;
  346. case DLG_SETUP_FONT:
  347. getFont(hDlg);
  348. break;
  349. case IDC_RADIO_SOLID:
  350. case IDC_RADIO_TEX:
  351. gac.surfStyle = IDC_TO_SURFSTYLE( LOWORD(wParam) );
  352. updateDialogControls(hDlg);
  353. break;
  354. case IDC_DEMO_STRING:
  355. case IDC_DEMO_CLOCK:
  356. gac.demoType = IDC_TO_DEMOTYPE( LOWORD(wParam) );
  357. updateDialogControls(hDlg);
  358. if( LOWORD(wParam) == IDC_DEMO_STRING ) {
  359. // set selected text focus
  360. SetFocus( GetDlgItem(hDlg, DLG_TEXT_ENTER) );
  361. SendDlgItemMessage( hDlg, DLG_TEXT_ENTER,
  362. EM_SETSEL, 0, -1 );
  363. }
  364. break;
  365. case IDOK:
  366. saveIniSettings(hDlg);
  367. EndDialog(hDlg, TRUE);
  368. break;
  369. case IDCANCEL:
  370. EndDialog(hDlg, FALSE);
  371. break;
  372. default:
  373. break;
  374. }
  375. return TRUE;
  376. break;
  377. default:
  378. return 0;
  379. }
  380. return 0;
  381. }