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.

373 lines
14 KiB

  1. /*---------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** g_cache.c **
  6. ** **
  7. ** Glyph cache dialog - TSREG **
  8. ** 07-01-98 a-clindh Created **
  9. **---------------------------------------------*/
  10. #include <windows.h>
  11. #include <commctrl.h>
  12. #include <TCHAR.H>
  13. #include <stdlib.h>
  14. #include "tsreg.h"
  15. #include "resource.h"
  16. HWND g_hwndGlyphCacheDlg;
  17. ///////////////////////////////////////////////////////////////////////////////
  18. INT_PTR CALLBACK GlyphCache(HWND hDlg, UINT nMsg,
  19. WPARAM wParam, LPARAM lParam)
  20. {
  21. NMHDR *lpnmhdr;
  22. static UINT nGlyphBuffer;
  23. static HWND hwndSlider[NUMBER_OF_SLIDERS];
  24. static HWND hwndSliderEditBuddy[NUMBER_OF_SLIDERS];
  25. static HWND hwndComboTextFrag;
  26. static TCHAR lpszRegPath[MAX_PATH];
  27. TCHAR lpszBuffer[5];
  28. HWND hwndCtl;
  29. int i, nKeyVal;
  30. int nPos;
  31. LPHELPINFO lphi;
  32. //
  33. // get a pointer to the NMHDR struct for apply button
  34. //
  35. lpnmhdr = ((LPNMHDR)lParam);
  36. switch (nMsg) {
  37. case WM_VSCROLL:
  38. hwndCtl = (HWND) (lParam);
  39. i = (int)GetWindowLongPtr(hwndCtl, GWLP_USERDATA);
  40. DisplayControlValue(hwndSlider, hwndSliderEditBuddy, i);
  41. break;
  42. case WM_INITDIALOG:
  43. g_hwndGlyphCacheDlg = hDlg;
  44. LoadString (g_hInst, IDS_REG_PATH,
  45. lpszRegPath, sizeof (lpszRegPath));
  46. hwndComboTextFrag = GetDlgItem(hDlg, IDC_CBO_TXT_FRAG);
  47. InitMiscControls( hDlg, hwndComboTextFrag);
  48. for (i = 0; i < NUMBER_OF_SLIDERS; i++) {
  49. //
  50. // get handles to slider contrls and static edit boxes
  51. //
  52. hwndSlider[i] = GetDlgItem(hDlg, (IDC_SLIDER1 + i));
  53. hwndSliderEditBuddy[i] = GetDlgItem(hDlg, (IDC_STATIC1 + i));
  54. //
  55. // save the index of the control
  56. //
  57. SetWindowLongPtr(hwndSlider[i], GWLP_USERDATA, i);
  58. SendMessage(hwndSlider[i], TBM_SETRANGE, FALSE,
  59. (LPARAM) MAKELONG(1, 8));
  60. //
  61. // get value from registry and check it
  62. //
  63. nGlyphBuffer = GetRegKeyValue(i + GLYPHCACHEBASE);
  64. if ( (nGlyphBuffer) < MIN_GLYPH_CACHE_SIZE ||
  65. (nGlyphBuffer > MAX_GLYPH_CACHE_SIZE) ) {
  66. nGlyphBuffer =
  67. g_KeyInfo[i + GLYPHCACHEBASE].DefaultKeyValue;
  68. }
  69. //
  70. // set the current key value
  71. //
  72. g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue =
  73. nGlyphBuffer;
  74. _itot( nGlyphBuffer, (lpszBuffer), 10);
  75. //
  76. // display the value in the static edit control
  77. //
  78. SetWindowText(hwndSliderEditBuddy[i], lpszBuffer);
  79. //
  80. // position the thumb on the slider control
  81. //
  82. nGlyphBuffer = g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue;
  83. #ifdef _X86_ // EXECUTE ASSEMBLER CODE ONLY IF X86 PROCESSOR
  84. // BSF: Bit Scan Forward -
  85. // Scans the value contained in the EAX regiseter
  86. // for the first significant (1) bit.
  87. // This function returns the location of the first
  88. // significant bit. The function is used in this
  89. // application as a base 2 logarythm. The location
  90. // of the bit is determined, stored in the nPos
  91. // variable, and nPos is used to set the slider
  92. // control. ie. If the register value is 4, nPos
  93. // is set to 2 (00000100). 10 minus 2 (position 8
  94. // on the slider control) represents the value 4.
  95. __asm
  96. {
  97. BSF EAX, nGlyphBuffer
  98. MOV nPos, EAX
  99. }
  100. nPos = 10 - nPos;
  101. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, (LPARAM)nPos);
  102. #else
  103. switch (nGlyphBuffer) {
  104. case 4:
  105. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 8);
  106. break;
  107. case 8:
  108. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 7);
  109. break;
  110. case 16:
  111. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 6);
  112. break;
  113. case 32:
  114. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 5);
  115. break;
  116. case 64:
  117. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 4);
  118. break;
  119. case 128:
  120. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 3);
  121. break;
  122. case 256:
  123. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 2);
  124. break;
  125. case 512:
  126. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 1);
  127. break;
  128. }
  129. #endif
  130. } // end for loop
  131. break;
  132. case WM_NOTIFY:
  133. //
  134. // save settings on OK button
  135. //
  136. switch (lpnmhdr->code) {
  137. case PSN_HELP:
  138. lphi = (LPHELPINFO) lParam;
  139. WinHelp(lphi->hItemHandle,
  140. g_lpszPath, HELP_CONTENTS, lphi->iCtrlId);
  141. break;
  142. case PSN_APPLY:
  143. for (i = 0; i < NUMBER_OF_SLIDERS; i++) {
  144. if ( (g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue ==
  145. g_KeyInfo[i+GLYPHCACHEBASE].DefaultKeyValue) ||
  146. (g_KeyInfo[i+GLYPHCACHEBASE].CurrentKeyValue ==
  147. 0)) {
  148. DeleteRegKey(i + GLYPHCACHEBASE, lpszRegPath);
  149. } else {
  150. SetRegKey(i + GLYPHCACHEBASE, lpszRegPath);
  151. }
  152. } // ** end for loop
  153. if (g_KeyInfo[GLYPHINDEX].CurrentKeyValue ==
  154. g_KeyInfo[GLYPHINDEX].DefaultKeyValue) {
  155. DeleteRegKey(GLYPHINDEX, lpszRegPath);
  156. } else {
  157. SetRegKey(GLYPHINDEX, lpszRegPath);
  158. }
  159. if (g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue ==
  160. g_KeyInfo[TEXTFRAGINDEX].DefaultKeyValue) {
  161. DeleteRegKey(TEXTFRAGINDEX, lpszRegPath);
  162. } else {
  163. SetRegKey(TEXTFRAGINDEX, lpszRegPath);
  164. }
  165. }
  166. break;
  167. case WM_HELP:
  168. lphi = (LPHELPINFO) lParam;
  169. WinHelp(lphi->hItemHandle,
  170. g_lpszPath, HELP_CONTEXTPOPUP, lphi->iCtrlId);
  171. break;
  172. case WM_COMMAND:
  173. switch LOWORD (wParam) {
  174. case IDC_RADIO_NONE:
  175. g_KeyInfo[GLYPHINDEX].CurrentKeyValue = NONE;
  176. break;
  177. case IDC_RADIO_PARTIAL:
  178. g_KeyInfo[GLYPHINDEX].CurrentKeyValue = PARTIAL;
  179. break;
  180. case IDC_RADIO_FULL:
  181. g_KeyInfo[GLYPHINDEX].CurrentKeyValue = FULL;
  182. break;
  183. case IDC_GLYPH_BTN_RESTORE:
  184. CheckDlgButton(hDlg, IDC_RADIO_FULL, TRUE);
  185. CheckDlgButton(hDlg, IDC_RADIO_PARTIAL, FALSE);
  186. CheckDlgButton(hDlg, IDC_RADIO_NONE, FALSE);
  187. _itot(g_KeyInfo[TEXTFRAGINDEX].DefaultKeyValue,
  188. lpszBuffer, 10);
  189. SendMessage(hwndComboTextFrag, CB_SELECTSTRING, -1,
  190. (LPARAM)(LPCSTR) lpszBuffer);
  191. g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue =
  192. g_KeyInfo[TEXTFRAGINDEX].DefaultKeyValue;
  193. g_KeyInfo[GLYPHINDEX].CurrentKeyValue =
  194. g_KeyInfo[GLYPHINDEX].DefaultKeyValue;
  195. for (i = 0; i < NUMBER_OF_SLIDERS; i++) {
  196. g_KeyInfo[i+GLYPHCACHEBASE].CurrentKeyValue =
  197. g_KeyInfo[i+GLYPHCACHEBASE].DefaultKeyValue;
  198. _itot(g_KeyInfo[i + GLYPHCACHEBASE].DefaultKeyValue,
  199. (lpszBuffer), 10);
  200. //
  201. // display the value in the static edit control
  202. //
  203. SetWindowText(hwndSliderEditBuddy[i], lpszBuffer);
  204. //
  205. // position the thumb on the slider control
  206. //
  207. nGlyphBuffer = g_KeyInfo[i +
  208. GLYPHCACHEBASE].DefaultKeyValue;
  209. #ifdef _X86_ // EXECUTE ASSEMBLER CODE ONLY IF X86 PROCESSOR
  210. // BSF: Bit Scan Forward -
  211. // Scans the value contained in the EAX regiseter
  212. // for the first significant (1) bit.
  213. // This function returns the location of the first
  214. // significant bit. The function is used in this
  215. // application as a base 2 logarythm. The location
  216. // of the bit is determined, stored in the nPos
  217. // variable, and nPos is used to set the slider
  218. // control. ie. If the register value is 4, nPos
  219. // is set to 2 (00000100). 10 minus 2 (position 8
  220. // on the slider control) represents the value 4.
  221. __asm
  222. {
  223. BSF EAX, nGlyphBuffer
  224. MOV nPos, EAX
  225. }
  226. nPos = 10 - nPos;
  227. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE,
  228. (LPARAM)nPos);
  229. #else
  230. switch (nGlyphBuffer) {
  231. case 4:
  232. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 8);
  233. break;
  234. case 8:
  235. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 7);
  236. break;
  237. case 16:
  238. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 6);
  239. break;
  240. case 32:
  241. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 5);
  242. break;
  243. case 64:
  244. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 4);
  245. break;
  246. case 128:
  247. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 3);
  248. break;
  249. case 256:
  250. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 2);
  251. break;
  252. case 512:
  253. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 1);
  254. break;
  255. }
  256. #endif
  257. }
  258. break;
  259. }
  260. switch HIWORD (wParam) {
  261. case CBN_EDITUPDATE:
  262. //
  263. // capture typed text
  264. //
  265. GetWindowText(hwndComboTextFrag, lpszBuffer, 5);
  266. nKeyVal = _ttoi(lpszBuffer);
  267. g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue = nKeyVal;
  268. break;
  269. case CBN_KILLFOCUS:
  270. //
  271. // save value when control looses focus
  272. //
  273. GetWindowText(hwndComboTextFrag, lpszBuffer, 5);
  274. nKeyVal = _ttoi(lpszBuffer);
  275. g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue = nKeyVal;
  276. break;
  277. }
  278. }
  279. return FALSE;
  280. }
  281. ///////////////////////////////////////////////////////////////////////////////
  282. //
  283. // Returns the integer value related to the coresponding cell.
  284. ///////////////////////////////////////////////////////////////////////////////
  285. int GetCellSize(int nPos, int i)
  286. {
  287. if (nPos >= 1 && nPos <= NUM_SLIDER_STOPS) {
  288. return g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue =
  289. (1 << ((NUM_SLIDER_STOPS + 2) - nPos));
  290. } else {
  291. return 0;
  292. }
  293. }
  294. ///////////////////////////////////////////////////////////////////////////////
  295. //
  296. // Display the slider control value in it's corresponding static edit box.
  297. ///////////////////////////////////////////////////////////////////////////////
  298. void DisplayControlValue(HWND hwndSlider[], HWND hwndSliderEditBuddy[], int i)
  299. {
  300. int nPos;
  301. TCHAR lpszBuffer[5];
  302. nPos = (int) SendMessage(hwndSlider[i], TBM_GETPOS, 0,0);
  303. _itot(GetCellSize(nPos, i), lpszBuffer, 10);
  304. SetWindowText(hwndSliderEditBuddy[i], lpszBuffer);
  305. }
  306. // end of file
  307. ///////////////////////////////////////////////////////////////////////////////