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
9.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. scheme.c
  5. Abstract:
  6. Control Panel scheme converters
  7. The helper functions in this source file converts an ANSI-
  8. based Win95 scheme into a UNICODE-based NT scheme. Also
  9. supplied is a logical font converter, closely related
  10. to the scheme converter.
  11. Author:
  12. Jim Schmidt (jimschm) 9-Aug-1996
  13. Revision History:
  14. --*/
  15. #include "pch.h"
  16. #include "rulehlprp.h"
  17. #define COLOR_MAX_V1 25
  18. #define COLOR_MAX_V3 25
  19. #define COLOR_MAX_V4 29
  20. #define COLOR_MAX_NT 29 // this is a modified version 2 format, similar to 4
  21. //
  22. // Win95 uses a mix of LOGFONTA and a weird 16-bit LOGFONT
  23. // structure that uses SHORTs instead of LONGs.
  24. //
  25. typedef struct {
  26. SHORT lfHeight;
  27. SHORT lfWidth;
  28. SHORT lfEscapement;
  29. SHORT lfOrientation;
  30. SHORT lfWeight;
  31. BYTE lfItalic;
  32. BYTE lfUnderline;
  33. BYTE lfStrikeOut;
  34. BYTE lfCharSet;
  35. BYTE lfOutPrecision;
  36. BYTE lfClipPrecision;
  37. BYTE lfQuality;
  38. BYTE lfPitchAndFamily;
  39. char lfFaceName[LF_FACESIZE];
  40. } SHORT_LOGFONT, *PSHORT_LOGFONT;
  41. //
  42. // NT uses only UNICODE structures, and pads the members
  43. // to 32-bit boundaries.
  44. //
  45. typedef struct {
  46. SHORT version; // 2 for NT UNICODE
  47. WORD wDummy; // for alignment
  48. NONCLIENTMETRICSW ncm;
  49. LOGFONTW lfIconTitle;
  50. COLORREF rgb[COLOR_MAX_NT];
  51. } SCHEMEDATA_NT, *PSCHEMEDATA_NT;
  52. //
  53. // Win95 uses NONCLIENTMETRICSA which has LOGFONTA members,
  54. // but it uses a 16-bit LOGFONT as well.
  55. //
  56. #pragma pack(push)
  57. #pragma pack(1)
  58. typedef struct {
  59. SHORT version; // 1 for Win95 ANSI
  60. NONCLIENTMETRICSA ncm;
  61. SHORT_LOGFONT lfIconTitle;
  62. COLORREF rgb[COLOR_MAX_V1];
  63. } SCHEMEDATA_V1, *PSCHEMEDATA_V1;
  64. typedef struct {
  65. SHORT version; // 1 for Win95 ANSI
  66. NONCLIENTMETRICSA ncm;
  67. SHORT_LOGFONT lfIconTitle;
  68. COLORREF rgb[COLOR_MAX_V4];
  69. } SCHEMEDATA_V1A, *PSCHEMEDATA_V1A;
  70. typedef struct {
  71. SHORT version; // 3 for Win98 ANSI, 4 for portable format
  72. WORD Dummy;
  73. NONCLIENTMETRICSA ncm;
  74. LOGFONTA lfIconTitle;
  75. COLORREF rgb[COLOR_MAX_V3];
  76. } SCHEMEDATA_V3, *PSCHEMEDATA_V3;
  77. typedef struct {
  78. SHORT version; // 4 for Win32 format (whatever that means)
  79. WORD Dummy;
  80. NONCLIENTMETRICSA ncm;
  81. LOGFONTA lfIconTitle;
  82. COLORREF rgb[COLOR_MAX_V4];
  83. } SCHEMEDATA_V4, *PSCHEMEDATA_V4;
  84. #pragma pack(pop)
  85. //
  86. // Some utility functions
  87. //
  88. void
  89. ConvertLF (LOGFONTW *plfDest, const LOGFONTA *plfSrc)
  90. {
  91. plfDest->lfHeight = plfSrc->lfHeight;
  92. plfDest->lfWidth = plfSrc->lfWidth;
  93. plfDest->lfEscapement = plfSrc->lfEscapement;
  94. plfDest->lfOrientation = plfSrc->lfOrientation;
  95. plfDest->lfWeight = plfSrc->lfWeight;
  96. plfDest->lfItalic = plfSrc->lfItalic;
  97. plfDest->lfUnderline = plfSrc->lfUnderline;
  98. plfDest->lfStrikeOut = plfSrc->lfStrikeOut;
  99. plfDest->lfCharSet = plfSrc->lfCharSet;
  100. plfDest->lfOutPrecision = plfSrc->lfOutPrecision;
  101. plfDest->lfClipPrecision = plfSrc->lfClipPrecision;
  102. plfDest->lfQuality = plfSrc->lfQuality;
  103. plfDest->lfPitchAndFamily = plfSrc->lfPitchAndFamily;
  104. MultiByteToWideChar (OurGetACP(),
  105. 0,
  106. plfSrc->lfFaceName,
  107. -1,
  108. plfDest->lfFaceName,
  109. sizeof (plfDest->lfFaceName) / sizeof (WCHAR));
  110. }
  111. void
  112. ConvertLFShort (LOGFONTW *plfDest, const SHORT_LOGFONT *plfSrc)
  113. {
  114. plfDest->lfHeight = plfSrc->lfHeight;
  115. plfDest->lfWidth = plfSrc->lfWidth;
  116. plfDest->lfEscapement = plfSrc->lfEscapement;
  117. plfDest->lfOrientation = plfSrc->lfOrientation;
  118. plfDest->lfWeight = plfSrc->lfWeight;
  119. plfDest->lfItalic = plfSrc->lfItalic;
  120. plfDest->lfUnderline = plfSrc->lfUnderline;
  121. plfDest->lfStrikeOut = plfSrc->lfStrikeOut;
  122. plfDest->lfCharSet = plfSrc->lfCharSet;
  123. plfDest->lfOutPrecision = plfSrc->lfOutPrecision;
  124. plfDest->lfClipPrecision = plfSrc->lfClipPrecision;
  125. plfDest->lfQuality = plfSrc->lfQuality;
  126. plfDest->lfPitchAndFamily = plfSrc->lfPitchAndFamily;
  127. MultiByteToWideChar (OurGetACP(),
  128. 0,
  129. plfSrc->lfFaceName,
  130. -1,
  131. plfDest->lfFaceName,
  132. sizeof (plfDest->lfFaceName) / sizeof (WCHAR));
  133. }
  134. VOID
  135. ConvertNonClientMetrics (
  136. OUT NONCLIENTMETRICSW *Dest,
  137. IN NONCLIENTMETRICSA *Src
  138. )
  139. {
  140. Dest->cbSize = sizeof (NONCLIENTMETRICSW);
  141. Dest->iBorderWidth = Src->iBorderWidth;
  142. Dest->iScrollWidth = Src->iScrollWidth;
  143. Dest->iScrollHeight = Src->iScrollHeight;
  144. Dest->iCaptionWidth = Src->iCaptionWidth;
  145. Dest->iCaptionHeight = Src->iCaptionHeight;
  146. Dest->iSmCaptionWidth = Src->iSmCaptionWidth;
  147. Dest->iSmCaptionHeight = Src->iSmCaptionHeight;
  148. Dest->iMenuWidth = Src->iMenuWidth;
  149. Dest->iMenuHeight = Src->iMenuHeight;
  150. ConvertLF (&Dest->lfCaptionFont, &Src->lfCaptionFont);
  151. ConvertLF (&Dest->lfSmCaptionFont, &Src->lfSmCaptionFont);
  152. ConvertLF (&Dest->lfMenuFont, &Src->lfMenuFont);
  153. ConvertLF (&Dest->lfStatusFont, &Src->lfStatusFont);
  154. ConvertLF (&Dest->lfMessageFont, &Src->lfMessageFont);
  155. }
  156. //
  157. // And now the scheme converter
  158. //
  159. BOOL
  160. ValFn_ConvertAppearanceScheme (
  161. IN PDATAOBJECT ObPtr
  162. )
  163. {
  164. SCHEMEDATA_NT sd_nt;
  165. PSCHEMEDATA_V1 psd_v1;
  166. PSCHEMEDATA_V3 psd_v3;
  167. PSCHEMEDATA_V4 psd_v4;
  168. PSCHEMEDATA_V1A psd_v1a;
  169. BOOL Copy3dValues = FALSE;
  170. psd_v1 = (PSCHEMEDATA_V1) ObPtr->Value.Buffer;
  171. //
  172. // Validate the size (must be a known size)
  173. //
  174. if (ObPtr->Value.Size != sizeof (SCHEMEDATA_V1) &&
  175. ObPtr->Value.Size != sizeof (SCHEMEDATA_V3) &&
  176. ObPtr->Value.Size != sizeof (SCHEMEDATA_V4) &&
  177. ObPtr->Value.Size != sizeof (SCHEMEDATA_V1A)
  178. ) {
  179. DEBUGMSG ((
  180. DBG_WARNING,
  181. "ValFn_ConvertAppearanceScheme doesn't support scheme size of %u bytes. "
  182. "The supported sizes are %u, %u, %u, and %u.",
  183. ObPtr->Value.Size,
  184. sizeof (SCHEMEDATA_V1),
  185. sizeof (SCHEMEDATA_V1A),
  186. sizeof (SCHEMEDATA_V3),
  187. sizeof (SCHEMEDATA_V4)
  188. ));
  189. return TRUE;
  190. }
  191. //
  192. // Make sure the structure is a known version
  193. //
  194. if (psd_v1->version != 1 && psd_v1->version != 3 && psd_v1->version != 4) {
  195. DEBUGMSG ((
  196. DBG_WARNING,
  197. "ValFn_ConvertAppearanceScheme doesn't support version %u",
  198. psd_v1->version
  199. ));
  200. return TRUE;
  201. }
  202. //
  203. // Convert the structure
  204. //
  205. if (psd_v1->version == 1) {
  206. sd_nt.version = 2;
  207. ConvertNonClientMetrics (&sd_nt.ncm, &psd_v1->ncm);
  208. ConvertLFShort (&sd_nt.lfIconTitle, &psd_v1->lfIconTitle);
  209. ZeroMemory (sd_nt.rgb, sizeof (sd_nt.rgb));
  210. CopyMemory (
  211. &sd_nt.rgb,
  212. &psd_v1->rgb,
  213. min (sizeof (psd_v1->rgb), sizeof (sd_nt.rgb))
  214. );
  215. Copy3dValues = TRUE;
  216. } else if (psd_v1->version == 3 && ObPtr->Value.Size == sizeof (SCHEMEDATA_V1A)) {
  217. psd_v1a = (PSCHEMEDATA_V1A) psd_v1;
  218. sd_nt.version = 2;
  219. ConvertNonClientMetrics (&sd_nt.ncm, &psd_v1a->ncm);
  220. ConvertLFShort (&sd_nt.lfIconTitle, &psd_v1a->lfIconTitle);
  221. ZeroMemory (sd_nt.rgb, sizeof (sd_nt.rgb));
  222. CopyMemory (
  223. &sd_nt.rgb,
  224. &psd_v1a->rgb,
  225. min (sizeof (psd_v1a->rgb), sizeof (sd_nt.rgb))
  226. );
  227. Copy3dValues = TRUE;
  228. } else if (psd_v1->version == 3 && ObPtr->Value.Size == sizeof (SCHEMEDATA_V3)) {
  229. psd_v3 = (PSCHEMEDATA_V3) psd_v1;
  230. sd_nt.version = 2;
  231. ConvertNonClientMetrics (&sd_nt.ncm, &psd_v3->ncm);
  232. ConvertLF (&sd_nt.lfIconTitle, &psd_v3->lfIconTitle);
  233. ZeroMemory (sd_nt.rgb, sizeof (sd_nt.rgb));
  234. CopyMemory (
  235. &sd_nt.rgb,
  236. &psd_v3->rgb,
  237. min (sizeof (psd_v3->rgb), sizeof (sd_nt.rgb))
  238. );
  239. Copy3dValues = TRUE;
  240. } else if (psd_v1->version == 4) {
  241. psd_v4 = (PSCHEMEDATA_V4) psd_v1;
  242. sd_nt.version = 2;
  243. ConvertNonClientMetrics (&sd_nt.ncm, &psd_v4->ncm);
  244. ConvertLF (&sd_nt.lfIconTitle, &psd_v4->lfIconTitle);
  245. ZeroMemory (sd_nt.rgb, sizeof (sd_nt.rgb));
  246. CopyMemory (
  247. &sd_nt.rgb,
  248. &psd_v4->rgb,
  249. min (sizeof (psd_v4->rgb), sizeof (sd_nt.rgb))
  250. );
  251. } else {
  252. // not a possible case
  253. MYASSERT (FALSE);
  254. }
  255. if (Copy3dValues) {
  256. //
  257. // Make sure the NT structure has values for 3D colors
  258. //
  259. sd_nt.rgb[COLOR_HOTLIGHT] = sd_nt.rgb[COLOR_ACTIVECAPTION];
  260. sd_nt.rgb[COLOR_GRADIENTACTIVECAPTION] = sd_nt.rgb[COLOR_ACTIVECAPTION];
  261. sd_nt.rgb[COLOR_GRADIENTINACTIVECAPTION] = sd_nt.rgb[COLOR_INACTIVECAPTION];
  262. }
  263. return ReplaceValue (ObPtr, (LPBYTE) &sd_nt, sizeof (sd_nt));
  264. }
  265. //
  266. // And logfont converter
  267. //
  268. BOOL
  269. ValFn_ConvertLogFont (
  270. IN PDATAOBJECT ObPtr
  271. )
  272. {
  273. LOGFONTW lfNT;
  274. PSHORT_LOGFONT plf95;
  275. plf95 = (PSHORT_LOGFONT) ObPtr->Value.Buffer;
  276. if (ObPtr->Value.Size != sizeof (SHORT_LOGFONT)) {
  277. SetLastError (ERROR_SUCCESS);
  278. DEBUGMSG ((
  279. DBG_NAUSEA,
  280. "ValFn_ConvertLogFont skipped because data wasn't the right size. "
  281. "%u bytes, should be %u",
  282. ObPtr->Value.Size,
  283. sizeof (SHORT_LOGFONT)
  284. ));
  285. return FALSE;
  286. }
  287. ConvertLFShort (&lfNT, plf95);
  288. return ReplaceValue (ObPtr, (LPBYTE) &lfNT, sizeof (lfNT));
  289. }