Source code of Windows XP (NT5)
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.

2275 lines
69 KiB

  1. /*****************************************************************************\
  2. FILE: AdvAppearPg.cpp
  3. DESCRIPTION:
  4. This code will display a "Advanced Appearances" tab in the
  5. "Advanced Display Properties" dialog.
  6. ??????? ?/??/1993 Created
  7. BryanSt 3/23/2000 Updated and Converted to C++
  8. Copyright (C) Microsoft Corp 1993-2000. All rights reserved.
  9. \*****************************************************************************/
  10. #include "priv.h"
  11. #include "PreviewSM.h"
  12. #include "AdvAppearPg.h"
  13. #include "BaseAppearPg.h"
  14. #include "regutil.h"
  15. #include "CoverWnd.h"
  16. #include "fontfix.h"
  17. // The following are the indices into the above array.
  18. #define COLORFLAG_SOLID 0x0001
  19. #define COLOR_MAX_400 (COLOR_INFOBK + 1)
  20. #define CURRENT_ELEMENT_NONE -2 // This means that no element is selected.
  21. // used by ChooseColor dialog
  22. COLORREF g_CustomColors[16]; // This is the user customized palette. We could put this into the class.
  23. CAdvAppearancePage * g_pAdvAppearancePage = NULL;
  24. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25. //this order has to match the enum order in look.h
  26. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  27. LOOK_ELEMENT g_elements[] = {
  28. /* ELEMENT_APPSPACE */ {COLOR_APPWORKSPACE, SIZE_NONE, FALSE, COLOR_NONE, FONT_NONE, ELNAME_APPSPACE, -1, COLOR_NONE, {-1,-1,-1,-1}},
  29. /* ELEMENT_DESKTOP */ {COLOR_BACKGROUND, SIZE_NONE, FALSE, COLOR_NONE, FONT_NONE, ELNAME_DESKTOP, -1, COLOR_NONE, {-1,-1,-1,-1}},
  30. /* ELEMENT_INACTIVEBORDER */ {COLOR_INACTIVEBORDER, SIZE_FRAME, FALSE, COLOR_NONE, FONT_NONE, ELNAME_INACTIVEBORDER, -1, COLOR_NONE, {-1,-1,-1,-1}},
  31. /* ELEMENT_ACTIVEBORDER */ {COLOR_ACTIVEBORDER, SIZE_FRAME, FALSE, COLOR_NONE, FONT_NONE, ELNAME_ACTIVEBORDER, -1, COLOR_NONE, {-1,-1,-1,-1}},
  32. /* ELEMENT_INACTIVECAPTION */ {COLOR_INACTIVECAPTION, SIZE_CAPTION, TRUE, COLOR_INACTIVECAPTIONTEXT,FONT_CAPTION,ELNAME_INACTIVECAPTION, -1,COLOR_GRADIENTINACTIVECAPTION, {-1,-1,-1,-1}},
  33. /* ELEMENT_INACTIVESYSBUT1 */ {COLOR_NONE, SIZE_CAPTION, FALSE, COLOR_NONE, FONT_NONE, -1, ELEMENT_ACTIVESYSBUT1, COLOR_NONE, {-1,-1,-1,-1}},
  34. /* ELEMENT_INACTIVESYSBUT2 */ {COLOR_NONE, SIZE_CAPTION, FALSE, COLOR_NONE, FONT_NONE, -1, ELEMENT_ACTIVESYSBUT1, COLOR_NONE, {-1,-1,-1,-1}},
  35. /* ELEMENT_ACTIVECAPTION */ {COLOR_ACTIVECAPTION, SIZE_CAPTION, TRUE, COLOR_CAPTIONTEXT, FONT_CAPTION, ELNAME_ACTIVECAPTION, -1, COLOR_GRADIENTACTIVECAPTION, {-1,-1,-1,-1}},
  36. /* ELEMENT_ACTIVESYSBUT1 */ {COLOR_NONE, SIZE_CAPTION, FALSE, COLOR_NONE, FONT_NONE, ELNAME_CAPTIONBUTTON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  37. /* ELEMENT_ACTIVESYSBUT2 */ {COLOR_NONE, SIZE_CAPTION, FALSE, COLOR_NONE, FONT_NONE, -1, ELEMENT_ACTIVESYSBUT1, COLOR_NONE, {-1,-1,-1,-1}},
  38. /* ELEMENT_MENUNORMAL */ {COLOR_MENU, SIZE_MENU, TRUE, COLOR_MENUTEXT, FONT_MENU, ELNAME_MENU, -1, COLOR_NONE, {-1,-1,-1,-1}},
  39. /* ELEMENT_MENUSELECTED */ {COLOR_HIGHLIGHT, SIZE_MENU, TRUE, COLOR_HIGHLIGHTTEXT, FONT_MENU, ELNAME_MENUSELECTED, -1, COLOR_NONE, {-1,-1,-1,-1}},
  40. /* ELEMENT_MENUDISABLED */ {COLOR_MENU, SIZE_MENU, TRUE, COLOR_NONE, FONT_MENU, -1, ELEMENT_MENUNORMAL, COLOR_NONE, {-1,-1,-1,-1}},
  41. /* ELEMENT_WINDOW */ {COLOR_WINDOW, SIZE_NONE, FALSE, COLOR_WINDOWTEXT, FONT_NONE, ELNAME_WINDOW, -1, COLOR_NONE, {-1,-1,-1,-1}},
  42. /* ELEMENT_MSGBOX */ {COLOR_NONE, SIZE_NONE, TRUE, COLOR_WINDOWTEXT, FONT_MSGBOX, ELNAME_MSGBOX, -1, COLOR_NONE, {-1,-1,-1,-1}},
  43. /* ELEMENT_MSGBOXCAPTION */ {COLOR_ACTIVECAPTION, SIZE_CAPTION, TRUE, COLOR_CAPTIONTEXT, FONT_CAPTION, -1, ELEMENT_ACTIVECAPTION, COLOR_GRADIENTACTIVECAPTION, {-1,-1,-1,-1}},
  44. /* ELEMENT_MSGBOXSYSBUT */ {COLOR_3DFACE, SIZE_CAPTION, TRUE, COLOR_BTNTEXT, FONT_CAPTION, -1, ELEMENT_ACTIVESYSBUT1, COLOR_NONE, {-1,-1,-1,-1}},
  45. // do not even try to set a scrollbar color the system will ignore you
  46. /* ELEMENT_SCROLLBAR */ {COLOR_NONE, SIZE_SCROLL, FALSE, COLOR_NONE, FONT_NONE, ELNAME_SCROLLBAR, -1, COLOR_NONE, {-1,-1,-1,-1}},
  47. /* ELEMENT_SCROLLUP */ {COLOR_NONE, SIZE_SCROLL, FALSE, COLOR_NONE, FONT_NONE, -1, ELEMENT_SCROLLBAR, COLOR_NONE, {-1,-1,-1,-1}},
  48. /* ELEMENT_SCROLLDOWN */ {COLOR_NONE, SIZE_SCROLL, FALSE, COLOR_NONE, FONT_NONE, -1, ELEMENT_SCROLLBAR, COLOR_NONE, {-1,-1,-1,-1}},
  49. /* ELEMENT_BUTTON */ {COLOR_3DFACE, SIZE_NONE, FALSE, COLOR_BTNTEXT, FONT_NONE, ELNAME_BUTTON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  50. /* ELEMENT_SMCAPTION */ {COLOR_NONE, SIZE_SMCAPTION, TRUE, COLOR_NONE, FONT_SMCAPTION,ELNAME_SMALLCAPTION, -1, COLOR_NONE, {-1,-1,-1,-1}},
  51. /* ELEMENT_ICON */ {COLOR_NONE, SIZE_ICON, FALSE, COLOR_NONE, FONT_ICONTITLE,ELNAME_ICON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  52. /* ELEMENT_ICONHORZSPACING */ {COLOR_NONE, SIZE_DXICON, FALSE, COLOR_NONE, FONT_NONE, ELNAME_DXICON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  53. /* ELEMENT_ICONVERTSPACING */ {COLOR_NONE, SIZE_DYICON, FALSE, COLOR_NONE, FONT_NONE, ELNAME_DYICON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  54. /* ELEMENT_INFO */ {COLOR_INFOBK, SIZE_NONE, TRUE, COLOR_INFOTEXT, FONT_STATUS, ELNAME_INFO, -1, COLOR_NONE, {-1,-1,-1,-1}},
  55. /* ELEMENT_HOTTRACKAREA */ {COLOR_HOTLIGHT, SIZE_NONE, FALSE, COLOR_NONE, FONT_NONE, ELNAME_HOTTRACKAREA, -1, COLOR_NONE, {-1,-1,-1,-1}}
  56. };
  57. #if 0
  58. // go fix look.h if you decide to add this back in
  59. /* ELEMENT_SMICON */ {COLOR_NONE, SIZE_SMICON, FALSE, COLOR_NONE, FONT_NONE, ELNAME_SMICON, -1, COLOR_NONE, {-1,-1,-1,-1}},
  60. #endif
  61. #define ELCUR (g_elements[m_iCurElement])
  62. #define ELCURFONT (m_fonts[ELCUR.iFont])
  63. void LoadCustomColors(void);
  64. BOOL Font_GetNameFromList(HWND hwndList, INT iItem, LPTSTR pszFace, INT cchFaceMax, LPTSTR pszScript, INT cchScriptMax);
  65. void Font_AddSize(HWND hwndPoints, int iNewPoint, BOOL bSort);
  66. int CALLBACK Font_EnumSizes(LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC lpntm, int Type, LPARAM lData);
  67. //============================================================================================================
  68. // *** Globals ***
  69. //============================================================================================================
  70. const static DWORD aAdvAppearanceHelpIds[] = {
  71. IDC_ADVAP_LOOKPREV, IDH_DISPLAY_APPEARANCE_GRAPHIC,
  72. IDC_ADVAP_ELEMENTSLABEL, IDH_DISPLAY_APPEARANCE_ITEM_LIST,
  73. IDC_ADVAP_ELEMENTS, IDH_DISPLAY_APPEARANCE_ITEM_LIST,
  74. IDC_ADVAP_MAINSIZE, IDH_DISPLAY_APPEARANCE_ITEM_SIZE,
  75. IDC_ADVAP_SIZELABEL, IDH_DISPLAY_APPEARANCE_ITEM_SIZE,
  76. IDC_ADVAP_SIZEARROWS, IDH_DISPLAY_APPEARANCE_ITEM_SIZE,
  77. IDC_ADVAP_COLORLABEL, IDH_DISPLAY_APPEARANCE_ITEM_COLOR,
  78. IDC_ADVAP_MAINCOLOR, IDH_DISPLAY_APPEARANCE_ITEM_COLOR,
  79. IDC_ADVAP_GRADIENTLABEL, IDH_DISPLAY_APPEARANCE_ITEM_COLOR2,
  80. IDC_ADVAP_GRADIENT, IDH_DISPLAY_APPEARANCE_ITEM_COLOR2,
  81. IDC_ADVAP_FONTLABEL, IDH_DISPLAY_APPEARANCE_FONT_LIST,
  82. IDC_ADVAP_FONTNAME, IDH_DISPLAY_APPEARANCE_FONT_LIST,
  83. IDC_ADVAP_FONTSIZELABEL, IDH_DISPLAY_APPEARANCE_FONT_SIZE,
  84. IDC_ADVAP_FONTSIZE, IDH_DISPLAY_APPEARANCE_FONT_SIZE,
  85. IDC_ADVAP_FNCOLORLABEL, IDH_DISPLAY_APPEARANCE_FONT_COLOR,
  86. IDC_ADVAP_TEXTCOLOR, IDH_DISPLAY_APPEARANCE_FONT_COLOR,
  87. IDC_ADVAP_FONTBOLD, IDH_DISPLAY_APPEARANCE_FONT_BOLD,
  88. IDC_ADVAP_FONTITAL, IDH_DISPLAY_APPEARANCE_FONT_ITALIC,
  89. 0, 0
  90. };
  91. #define SZ_HELPFILE_ADVAPPEARANCE TEXT("display.hlp")
  92. //===========================
  93. // *** Class Internals & Helpers ***
  94. //===========================
  95. // a new font name was chosen. build a new point size list.
  96. void CAdvAppearancePage::_SelectName(HWND hDlg, int iSel)
  97. {
  98. INT dwItemData;
  99. HWND hwndFontSize = GetDlgItem(hDlg, IDC_ADVAP_FONTSIZE);
  100. HDC hdc;
  101. // build the approriate point size list
  102. SendMessage(hwndFontSize, CB_RESETCONTENT, 0, 0L);
  103. dwItemData = LOWORD(SendDlgItemMessage(hDlg, IDC_ADVAP_FONTNAME, CB_GETITEMDATA, (WPARAM)iSel, 0L));
  104. if (LOWORD(dwItemData) == TRUETYPE_FONTTYPE)
  105. {
  106. INT i;
  107. for (i = 6; i <= 24; i++)
  108. Font_AddSize(hwndFontSize, i, FALSE);
  109. }
  110. else
  111. {
  112. LOGFONT lf;
  113. Font_GetNameFromList(GetDlgItem(hDlg, IDC_ADVAP_FONTNAME),
  114. iSel,
  115. lf.lfFaceName,
  116. ARRAYSIZE(lf.lfFaceName),
  117. NULL,
  118. 0);
  119. hdc = GetDC(NULL);
  120. lf.lfCharSet = (BYTE)(HIWORD(dwItemData));
  121. #ifdef WINDOWS_ME
  122. lf.lfPitchAndFamily = MONO_FONT;
  123. #else
  124. lf.lfPitchAndFamily = 0;
  125. #endif
  126. EnumFontFamiliesEx(hdc, &lf, (FONTENUMPROC)Font_EnumSizes, (LPARAM)this, 0);
  127. ReleaseDC(NULL, hdc);
  128. }
  129. }
  130. // new font was chosen. select the proper point size
  131. // return: actual point size chosen
  132. int Font_SelectSize(HWND hDlg, int iCurPoint)
  133. {
  134. int i, iPoint = 0;
  135. HWND hwndFontSize = GetDlgItem(hDlg, IDC_ADVAP_FONTSIZE);
  136. i = (int)SendMessage(hwndFontSize, CB_GETCOUNT, 0, 0L);
  137. // the loop stops with i=0, so we get some selection for sure
  138. for (i--; i > 0; i--)
  139. {
  140. iPoint = LOWORD(SendMessage(hwndFontSize, CB_GETITEMDATA, (WPARAM)i, 0L));
  141. // walking backwards through list, find equal or next smallest
  142. if (iCurPoint >= iPoint)
  143. break;
  144. }
  145. SendMessage(hwndFontSize, CB_SETCURSEL, (WPARAM)i, 0L);
  146. return iPoint;
  147. }
  148. int CAdvAppearancePage::_HeightToPoint(int nHeight)
  149. {
  150. if (nHeight < 0)
  151. {
  152. nHeight = -nHeight;
  153. }
  154. return MulDiv(nHeight, 72, m_nCachedNewDPI);
  155. }
  156. int CAdvAppearancePage::_PointToHeight(int nPoints)
  157. {
  158. if (nPoints > 0)
  159. {
  160. nPoints = -nPoints;
  161. }
  162. // Heights must always be negative. NTUSER is full of bugs when
  163. // the values are positive.
  164. return MulDiv(nPoints, m_nCachedNewDPI, 72);
  165. }
  166. /*
  167. ** initialize the constant dialog components
  168. **
  169. ** initialize the list of element names. this stays constant with the
  170. ** possible exception that some items might be added/removed depending
  171. ** on some special case conditions.
  172. */
  173. void Look_InitDialog(HWND hDlg)
  174. {
  175. int iEl, iName;
  176. TCHAR szName[CCH_MAX_STRING];
  177. HWND hwndElements;
  178. LOGFONT lf;
  179. HFONT hfont;
  180. int oldWeight;
  181. LoadCustomColors();
  182. hwndElements = GetDlgItem(hDlg, IDC_ADVAP_ELEMENTS);
  183. for (iEl = 0; iEl < ARRAYSIZE(g_elements); iEl++)
  184. {
  185. if ((g_elements[iEl].iResId != -1) &&
  186. LoadString(HINST_THISDLL, g_elements[iEl].iResId, szName, ARRAYSIZE(szName)))
  187. {
  188. iName = (int)SendMessage(hwndElements, CB_FINDSTRINGEXACT, 0, (LPARAM)szName);
  189. if (iName == CB_ERR)
  190. iName = (int)SendMessage(hwndElements, CB_ADDSTRING, 0, (LPARAM)szName);
  191. // reference back to item in array
  192. if (iName != CB_ERR)
  193. SendMessage(hwndElements, CB_SETITEMDATA, (WPARAM)iName, (LPARAM)iEl);
  194. }
  195. }
  196. // make bold button have bold text
  197. hfont = (HFONT)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTBOLD, WM_GETFONT, 0, 0L);
  198. GetObject(hfont, sizeof(lf), &lf);
  199. oldWeight = lf.lfWeight;
  200. lf.lfWeight = FW_BOLD;
  201. hfont = CreateFontIndirect(&lf);
  202. if (hfont)
  203. SendDlgItemMessage(hDlg, IDC_ADVAP_FONTBOLD, WM_SETFONT, (WPARAM)hfont, 0L);
  204. // make italic button have italic text
  205. lf.lfWeight = oldWeight;
  206. lf.lfItalic = TRUE;
  207. hfont = CreateFontIndirect(&lf);
  208. if (hfont)
  209. {
  210. SendDlgItemMessage(hDlg, IDC_ADVAP_FONTITAL, WM_SETFONT, (WPARAM)hfont, 0L);
  211. }
  212. }
  213. HRESULT CAdvAppearancePage::_OnFontNameChanged(HWND hDlg)
  214. {
  215. HRESULT hr = E_NOTIMPL;
  216. TCHAR szBuf[MAX_PATH];
  217. int nIndex = (int)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTNAME, CB_GETCURSEL,0,0L);
  218. DWORD dwItemData = (DWORD)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTNAME, CB_GETITEMDATA, (WPARAM)nIndex, 0);
  219. _SelectName(hDlg, nIndex);
  220. Font_SelectSize(hDlg, _HeightToPoint(ELCURFONT.lf.lfHeight));
  221. Font_GetNameFromList(GetDlgItem(hDlg, IDC_ADVAP_FONTNAME), nIndex, szBuf, ARRAYSIZE(szBuf), NULL, 0);
  222. // Change font to currently selected name and charset.
  223. _ChangeFontName(hDlg, szBuf, HIWORD(dwItemData));
  224. return hr;
  225. }
  226. HRESULT CAdvAppearancePage::_OnSizeChange(HWND hDlg, WORD wEvent)
  227. {
  228. HRESULT hr = E_NOTIMPL;
  229. int nIndex;
  230. if ((wEvent == EN_CHANGE) && (m_iCurElement >= 0) && (ELCUR.iSize >= 0))
  231. {
  232. nIndex = (int)LOWORD(SendDlgItemMessage(hDlg, IDC_ADVAP_SIZEARROWS, UDM_GETPOS,0,0L));
  233. _ChangeSize(hDlg, nIndex, TRUE);
  234. }
  235. else if (wEvent == EN_KILLFOCUS)
  236. {
  237. nIndex = (int)SendDlgItemMessage(hDlg, IDC_ADVAP_SIZEARROWS, UDM_GETPOS,0,0L);
  238. if (HIWORD(nIndex) != 0)
  239. {
  240. SetDlgItemInt(hDlg, IDC_ADVAP_MAINSIZE, (UINT)LOWORD(nIndex), FALSE);
  241. }
  242. }
  243. return hr;
  244. }
  245. HRESULT CAdvAppearancePage::_OnInitAdvAppearanceDlg(HWND hDlg)
  246. {
  247. m_fInUserEditMode = FALSE;
  248. // initialize some globals
  249. _hwnd = hDlg;
  250. m_cyBorderSM = ClassicGetSystemMetrics(SM_CYBORDER);
  251. m_cxBorderSM = ClassicGetSystemMetrics(SM_CXBORDER);
  252. m_cxEdgeSM = ClassicGetSystemMetrics(SM_CXEDGE);
  253. m_cyEdgeSM = ClassicGetSystemMetrics(SM_CYEDGE);
  254. Look_InitDialog(hDlg);
  255. _InitSysStuff();
  256. _InitFontList(hDlg);
  257. // paint the preview
  258. _Repaint(hDlg, TRUE);
  259. _SelectElement(hDlg, ELEMENT_DESKTOP, LSE_SETCUR);
  260. m_fInUserEditMode = TRUE;
  261. // theme ownerdrawn color picker button
  262. m_hTheme = OpenThemeData(GetDlgItem(hDlg, IDC_ADVAP_MAINCOLOR), WC_BUTTON);
  263. return S_OK;
  264. }
  265. HRESULT CAdvAppearancePage::_LoadState(IN const SYSTEMMETRICSALL * pState)
  266. {
  267. HRESULT hr = E_INVALIDARG;
  268. if (pState)
  269. {
  270. _SetMyNonClientMetrics((const LPNONCLIENTMETRICS)&(pState->schemeData.ncm));
  271. m_dwChanged = pState->dwChanged;
  272. // Set Sizes
  273. m_sizes[SIZE_DXICON].CurSize = pState->nDXIcon;
  274. m_sizes[SIZE_DYICON].CurSize = pState->nDYIcon;
  275. m_sizes[SIZE_ICON].CurSize = pState->nIcon;
  276. m_sizes[SIZE_SMICON].CurSize = pState->nSmallIcon;
  277. // Set Fonts
  278. m_fonts[FONT_ICONTITLE].lf = pState->schemeData.lfIconTitle;
  279. m_fModifiedScheme = pState->fModifiedScheme;
  280. for (int nIndex = 0; nIndex < ARRAYSIZE(m_rgb); nIndex++)
  281. {
  282. m_rgb[nIndex] = pState->schemeData.rgb[nIndex];
  283. }
  284. hr = S_OK;
  285. }
  286. return hr;
  287. }
  288. HRESULT CAdvAppearancePage::_OnDestroy(HWND hDlg)
  289. {
  290. _DestroySysStuff();
  291. HFONT hfont, hfontOther;
  292. hfontOther = (HFONT)SendDlgItemMessage(hDlg, IDC_ADVAP_MAINSIZE, WM_GETFONT, 0, 0L);
  293. hfont = (HFONT)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTBOLD, WM_GETFONT, 0, 0L);
  294. if (hfont && (hfont != hfontOther))
  295. {
  296. DeleteObject(hfont);
  297. }
  298. hfont = (HFONT)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTITAL, WM_GETFONT, 0, 0L);
  299. if (hfont && (hfont != hfontOther))
  300. {
  301. DeleteObject(hfont);
  302. }
  303. if (m_hTheme)
  304. {
  305. CloseThemeData(m_hTheme);
  306. m_hTheme = NULL;
  307. }
  308. _hwnd = NULL;
  309. return S_OK;
  310. }
  311. INT_PTR CAdvAppearancePage::_OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  312. {
  313. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  314. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  315. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  316. int nIndex;
  317. TCHAR szBuf[100];
  318. switch (idCtrl)
  319. {
  320. case IDOK:
  321. EndDialog(hDlg, IDOK);
  322. break;
  323. case IDCANCEL:
  324. EndDialog(hDlg, IDCANCEL);
  325. break;
  326. case IDC_ADVAP_ELEMENTS:
  327. if(wEvent == CBN_SELCHANGE)
  328. {
  329. nIndex = (int)SendDlgItemMessage(hDlg, IDC_ADVAP_ELEMENTS, CB_GETCURSEL,0,0L);
  330. nIndex = LOWORD(SendDlgItemMessage(hDlg, IDC_ADVAP_ELEMENTS, CB_GETITEMDATA, (WPARAM)nIndex, 0L));
  331. _SelectElement(hDlg, nIndex, LSE_NONE);
  332. }
  333. break;
  334. case IDC_ADVAP_FONTNAME:
  335. if(wEvent == CBN_SELCHANGE)
  336. {
  337. _OnFontNameChanged(hDlg);
  338. }
  339. break;
  340. case IDC_ADVAP_FONTSIZE:
  341. switch (wEvent)
  342. {
  343. case CBN_SELCHANGE:
  344. nIndex = (int)SendDlgItemMessage(hDlg, IDC_ADVAP_FONTSIZE, CB_GETCURSEL,0,0L);
  345. nIndex = LOWORD(SendDlgItemMessage(hDlg, IDC_ADVAP_FONTSIZE, CB_GETITEMDATA, (WPARAM)nIndex, 0L));
  346. _ChangeFontSize(hDlg, nIndex);
  347. break;
  348. case CBN_EDITCHANGE:
  349. GetWindowText(GetDlgItem(hDlg, IDC_ADVAP_FONTSIZE), szBuf, ARRAYSIZE(szBuf));
  350. _ChangeFontSize(hDlg, StrToInt(szBuf));
  351. break;
  352. }
  353. break;
  354. case IDC_ADVAP_FONTBOLD:
  355. case IDC_ADVAP_FONTITAL:
  356. if (wEvent == BN_CLICKED)
  357. {
  358. BOOL fCheck = !IsDlgButtonChecked(hDlg, LOWORD(wParam));
  359. CheckDlgButton(hDlg, LOWORD(wParam), fCheck);
  360. _ChangeFontBI(hDlg, LOWORD(wParam), fCheck);
  361. }
  362. break;
  363. case IDC_ADVAP_MAINSIZE:
  364. _OnSizeChange(hDlg, wEvent);
  365. break;
  366. case IDC_ADVAP_GRADIENT:
  367. case IDC_ADVAP_MAINCOLOR:
  368. case IDC_ADVAP_TEXTCOLOR:
  369. if (wEvent == BN_CLICKED)
  370. _PickAColor(hDlg, idCtrl);
  371. break;
  372. default:
  373. //TraceMsg(TF_ALWAYS, "in CMailBoxProcess::_OnCommand() wEvent=%#08lx, idCtrl=%#08lx", wEvent, idCtrl);
  374. break;
  375. }
  376. return fHandled;
  377. }
  378. INT_PTR CALLBACK CAdvAppearancePage::AdvAppearDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  379. {
  380. CAdvAppearancePage * pThis = (CAdvAppearancePage *)GetWindowLongPtr(hDlg, DWLP_USER);
  381. if (WM_INITDIALOG == wMsg)
  382. {
  383. pThis = (CAdvAppearancePage *) lParam;
  384. if (pThis)
  385. {
  386. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  387. }
  388. }
  389. if (pThis)
  390. return pThis->_AdvAppearDlgProc(hDlg, wMsg, wParam, lParam);
  391. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  392. }
  393. // This Property Sheet appear in the top level of the "Display Control Panel".
  394. INT_PTR CAdvAppearancePage::_AdvAppearDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  395. {
  396. switch(message)
  397. {
  398. case WM_NOTIFY:
  399. break;
  400. case WM_INITDIALOG:
  401. _OnInitAdvAppearanceDlg(hDlg);
  402. break;
  403. case WM_DESTROY:
  404. _OnDestroy(hDlg);
  405. break;
  406. case WM_DRAWITEM:
  407. switch (wParam)
  408. {
  409. case IDC_ADVAP_GRADIENT:
  410. case IDC_ADVAP_MAINCOLOR:
  411. case IDC_ADVAP_TEXTCOLOR:
  412. _DrawButton(hDlg, (LPDRAWITEMSTRUCT)lParam);
  413. return TRUE;
  414. }
  415. break;
  416. case WM_SETTINGCHANGE:
  417. case WM_SYSCOLORCHANGE:
  418. case WM_DISPLAYCHANGE:
  419. _PropagateMessage(hDlg, message, wParam, lParam);
  420. break;
  421. case WM_QUERYNEWPALETTE:
  422. case WM_PALETTECHANGED:
  423. SendDlgItemMessage(hDlg, IDC_ADVAP_LOOKPREV, message, wParam, lParam);
  424. return TRUE;
  425. case WM_HELP:
  426. WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_ADVAPPEARANCE, HELP_WM_HELP, (DWORD_PTR) aAdvAppearanceHelpIds);
  427. break;
  428. case WM_CONTEXTMENU: // right mouse click
  429. WinHelp((HWND) wParam, SZ_HELPFILE_ADVAPPEARANCE, HELP_CONTEXTMENU, (DWORD_PTR) aAdvAppearanceHelpIds);
  430. break;
  431. case WM_COMMAND:
  432. _OnCommand(hDlg, message, wParam, lParam);
  433. break;
  434. case WM_THEMECHANGED:
  435. if (m_hTheme)
  436. {
  437. CloseThemeData(m_hTheme);
  438. }
  439. m_hTheme = OpenThemeData(GetDlgItem(hDlg, IDC_ADVAP_MAINCOLOR), WC_BUTTON);
  440. break;
  441. }
  442. return FALSE;
  443. }
  444. const UINT g_colorFlags[COLOR_MAX] = {
  445. /* COLOR_SCROLLBAR */ 0,
  446. /* COLOR_DESKTOP */ 0,
  447. /* COLOR_ACTIVECAPTION */ COLORFLAG_SOLID,
  448. /* COLOR_INACTIVECAPTION */ COLORFLAG_SOLID,
  449. /* COLOR_MENU */ COLORFLAG_SOLID,
  450. /* COLOR_WINDOW */ COLORFLAG_SOLID,
  451. /* COLOR_WINDOWFRAME */ COLORFLAG_SOLID,
  452. /* COLOR_MENUTEXT */ COLORFLAG_SOLID,
  453. /* COLOR_WINDOWTEXT */ COLORFLAG_SOLID,
  454. /* COLOR_CAPTIONTEXT */ COLORFLAG_SOLID,
  455. /* COLOR_ACTIVEBORDER */ 0,
  456. /* COLOR_INACTIVEBORDER */ 0,
  457. /* COLOR_APPWORKSPACE */ 0,
  458. /* COLOR_HIGHLIGHT */ COLORFLAG_SOLID,
  459. /* COLOR_HIGHLIGHTTEXT */ COLORFLAG_SOLID,
  460. /* COLOR_3DFACE */ COLORFLAG_SOLID,
  461. /* COLOR_3DSHADOW */ COLORFLAG_SOLID,
  462. /* COLOR_GRAYTEXT */ COLORFLAG_SOLID,
  463. /* COLOR_BTNTEXT */ COLORFLAG_SOLID,
  464. /* COLOR_INACTIVECAPTIONTEXT */ COLORFLAG_SOLID,
  465. /* COLOR_3DHILIGHT */ COLORFLAG_SOLID,
  466. /* COLOR_3DDKSHADOW */ COLORFLAG_SOLID,
  467. /* COLOR_3DLIGHT */ COLORFLAG_SOLID,
  468. /* COLOR_INFOTEXT */ COLORFLAG_SOLID,
  469. /* COLOR_INFOBK */ 0,
  470. /* COLOR_3DALTFACE */ 0,
  471. /* COLOR_HOTLIGHT */ COLORFLAG_SOLID,
  472. /* COLOR_GRADIENTACTIVECAPTION */ COLORFLAG_SOLID,
  473. /* COLOR_GRADIENTINACTIVECAPTION */ COLORFLAG_SOLID,
  474. /* COLOR_MENUHILIGHT */ 0,
  475. /* COLOR_MENUBAR */ 0
  476. };
  477. #define RGB_PALETTE 0x02000000
  478. // make the color a solid color if it needs to be.
  479. // on a palette device make is a palette relative color, if we need to.
  480. COLORREF CAdvAppearancePage::_NearestColor(int iColor, COLORREF rgb)
  481. {
  482. rgb &= 0x00FFFFFF;
  483. // if we are on a palette device, we need to do special stuff...
  484. if (m_bPalette)
  485. {
  486. if (g_colorFlags[iColor] & COLORFLAG_SOLID)
  487. {
  488. if (IsPaletteColor(m_hpal3D, rgb))
  489. rgb |= RGB_PALETTE;
  490. else
  491. rgb = GetNearestPaletteColor(m_hpalVGA, rgb);
  492. }
  493. else
  494. {
  495. if (IsPaletteColor(m_hpal3D, rgb))
  496. rgb |= RGB_PALETTE;
  497. else if (IsPaletteColor((HPALETTE)GetStockObject(DEFAULT_PALETTE), rgb))
  498. rgb ^= 0x000001; // force a dither
  499. }
  500. }
  501. else
  502. {
  503. // map color to nearest color if we need to for this UI element.
  504. if (g_colorFlags[iColor] & COLORFLAG_SOLID)
  505. {
  506. HDC hdc = GetDC(NULL);
  507. rgb = GetNearestColor(hdc, rgb);
  508. ReleaseDC(NULL, hdc);
  509. }
  510. }
  511. return rgb;
  512. }
  513. void CAdvAppearancePage::_PickAColor(HWND hDlg, int CtlID)
  514. {
  515. COLORPICK_INFO cpi;
  516. int iColor;
  517. switch (CtlID)
  518. {
  519. case IDC_ADVAP_GRADIENT:
  520. iColor = ELCUR.iGradientColor;
  521. break;
  522. case IDC_ADVAP_MAINCOLOR:
  523. iColor = ELCUR.iMainColor;
  524. break;
  525. case IDC_ADVAP_TEXTCOLOR:
  526. iColor = ELCUR.iTextColor;
  527. break;
  528. default:
  529. return;
  530. }
  531. cpi.hwndParent = GetDlgItem(hDlg, CtlID);
  532. cpi.hwndOwner = GetDlgItem(hDlg, CtlID); // Color button
  533. cpi.hpal = m_hpal3D;
  534. cpi.rgb = m_rgb[iColor];
  535. cpi.flags = CC_RGBINIT | CC_FULLOPEN;
  536. if ((iColor == COLOR_3DFACE) && m_bPalette)
  537. {
  538. cpi.flags |= CC_ANYCOLOR;
  539. }
  540. else if (g_colorFlags[iColor] & COLORFLAG_SOLID)
  541. {
  542. cpi.flags |= CC_SOLIDCOLOR;
  543. }
  544. if (ChooseColorMini(&cpi) && _ChangeColor(hDlg, iColor, cpi.rgb))
  545. {
  546. _SetColor(hDlg, CtlID, m_brushes[iColor]);
  547. _Repaint(hDlg, FALSE);
  548. }
  549. }
  550. // ------------------------ magic color utilities --------------------------
  551. /*
  552. ** set a color in the 3D palette.
  553. */
  554. void CAdvAppearancePage::_Set3DPaletteColor(COLORREF rgb, int iColor)
  555. {
  556. int iPalette;
  557. PALETTEENTRY pe;
  558. if (!m_hpal3D)
  559. return;
  560. switch (iColor)
  561. {
  562. case COLOR_3DFACE:
  563. iPalette = 16;
  564. break;
  565. case COLOR_3DSHADOW:
  566. iPalette = 17;
  567. break;
  568. case COLOR_3DHILIGHT:
  569. iPalette = 18;
  570. break;
  571. default:
  572. return;
  573. }
  574. pe.peRed = GetRValue(rgb);
  575. pe.peGreen = GetGValue(rgb);
  576. pe.peBlue = GetBValue(rgb);
  577. pe.peFlags = 0;
  578. SetPaletteEntries(m_hpal3D, iPalette, 1, (LPPALETTEENTRY)&pe);
  579. }
  580. // ------------end--------- magic color utilities --------------------------
  581. void CAdvAppearancePage::_InitUniqueCharsetArray(void)
  582. {
  583. UINT uiCharsets[MAX_CHARSETS];
  584. Font_GetCurrentCharsets(uiCharsets, ARRAYSIZE(uiCharsets));
  585. // Find the unique Charsets and save that in a global array.
  586. Font_GetUniqueCharsets(uiCharsets, m_uiUniqueCharsets, MAX_CHARSETS, &m_iCountCharsets);
  587. }
  588. HRESULT CAdvAppearancePage::_InitFonts(void)
  589. {
  590. for (int nIndex = 0; nIndex < ARRAYSIZE(m_fonts); nIndex++)
  591. {
  592. if (m_fonts[nIndex].hfont)
  593. {
  594. DeleteObject(m_fonts[nIndex].hfont);
  595. m_fonts[nIndex].hfont = NULL;
  596. }
  597. m_fonts[nIndex].hfont = CreateFontIndirect(&m_fonts[nIndex].lf);
  598. }
  599. return S_OK;
  600. }
  601. HRESULT CAdvAppearancePage::_FreeFonts(void)
  602. {
  603. for (int nIndex = 0; nIndex < ARRAYSIZE(m_fonts); nIndex++)
  604. {
  605. if (m_fonts[nIndex].hfont)
  606. {
  607. DeleteObject(m_fonts[nIndex].hfont);
  608. m_fonts[nIndex].hfont = NULL;
  609. }
  610. }
  611. return S_OK;
  612. }
  613. // new data has been set. flush out current objects and rebuild
  614. void CAdvAppearancePage::_RebuildSysStuff(BOOL fInit)
  615. {
  616. int i;
  617. SelectObject(g_hdcMem, GetStockObject(BLACK_BRUSH));
  618. SelectObject(g_hdcMem, GetStockObject(SYSTEM_FONT));
  619. _InitFonts();
  620. if (fInit)
  621. {
  622. HPALETTE hpal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
  623. if (hpal)
  624. {
  625. PALETTEENTRY pal[4];
  626. // get current magic colors
  627. pal[0].peFlags = 0;
  628. pal[1].peFlags = 0;
  629. pal[2].peFlags = 0;
  630. pal[3].peFlags = 0;
  631. if (GetPaletteEntries(hpal, 8, 4, pal))
  632. {
  633. SetPaletteEntries(m_hpal3D, 16, 4, pal);
  634. // set up magic colors in the 3d palette
  635. if (!IsPaletteColor(hpal, m_rgb[COLOR_3DFACE]))
  636. _Set3DPaletteColor(m_rgb[COLOR_3DFACE], COLOR_3DFACE);
  637. if (!IsPaletteColor(hpal, m_rgb[COLOR_3DSHADOW]))
  638. _Set3DPaletteColor(m_rgb[COLOR_3DSHADOW], COLOR_3DSHADOW);
  639. if (!IsPaletteColor(hpal, m_rgb[COLOR_3DHILIGHT]))
  640. _Set3DPaletteColor(m_rgb[COLOR_3DHILIGHT], COLOR_3DHILIGHT);
  641. }
  642. }
  643. }
  644. for (i = 0; i < COLOR_MAX; i++)
  645. {
  646. if (m_brushes[i])
  647. DeleteObject(m_brushes[i]);
  648. m_brushes[i] = CreateSolidBrush(_NearestColor(i, m_rgb[i]));
  649. }
  650. if (m_iCurElement >= 0)
  651. {
  652. // we changed the brushes out from under the buttons...
  653. _SetColor(NULL, IDC_ADVAP_MAINCOLOR, ((ELCUR.iMainColor != COLOR_NONE) ? m_brushes[ELCUR.iMainColor] : NULL));
  654. _SetColor(NULL, IDC_ADVAP_GRADIENT, ((ELCUR.iGradientColor != COLOR_NONE) ? m_brushes[ELCUR.iGradientColor] : NULL));
  655. _SetColor(NULL, IDC_ADVAP_TEXTCOLOR, ((ELCUR.iTextColor != COLOR_NONE) ? m_brushes[ELCUR.iTextColor] : NULL));
  656. }
  657. }
  658. //
  659. // simple form of Shell message box, does not handle param replacment
  660. // just calls LoadString and MessageBox
  661. //
  662. int WINAPI DeskShellMessageBox(HINSTANCE hAppInst, HWND hWnd, LPCTSTR lpcText, LPCTSTR lpcTitle, UINT fuStyle)
  663. {
  664. TCHAR achText[CCH_MAX_STRING];
  665. TCHAR achTitle[CCH_MAX_STRING];
  666. if (HIWORD(lpcText) == 0)
  667. {
  668. LoadString(hAppInst, LOWORD(lpcText), achText, ARRAYSIZE(achText));
  669. lpcText = (LPCTSTR)achText;
  670. }
  671. if (HIWORD(lpcTitle) == 0)
  672. {
  673. if (LOWORD(lpcTitle) == 0)
  674. GetWindowText(hWnd, achTitle, ARRAYSIZE(achTitle));
  675. else
  676. LoadString(hAppInst, LOWORD(lpcTitle), achTitle, ARRAYSIZE(achTitle));
  677. lpcTitle = (LPCTSTR)achTitle;
  678. }
  679. return MessageBox(hWnd, lpcText, lpcTitle, fuStyle);
  680. }
  681. HRESULT CAdvAppearancePage::_InitColorAndPalette(void)
  682. {
  683. m_bPalette = FALSE;
  684. HDC hdc = GetDC(NULL);
  685. if (hdc)
  686. {
  687. m_bPalette = GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE;
  688. ReleaseDC(NULL, hdc);
  689. }
  690. DWORD pal[21];
  691. HPALETTE hpal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
  692. pal[1] = RGB(255, 255, 255);
  693. pal[2] = RGB(0, 0, 0 );
  694. pal[3] = RGB(192, 192, 192);
  695. pal[4] = RGB(128, 128, 128);
  696. pal[5] = RGB(255, 0, 0 );
  697. pal[6] = RGB(128, 0, 0 );
  698. pal[7] = RGB(255, 255, 0 );
  699. pal[8] = RGB(128, 128, 0 );
  700. pal[9] = RGB(0 , 255, 0 );
  701. pal[10] = RGB(0 , 128, 0 );
  702. pal[11] = RGB(0 , 255, 255);
  703. pal[12] = RGB(0 , 128, 128);
  704. pal[13] = RGB(0 , 0, 255);
  705. pal[14] = RGB(0 , 0, 128);
  706. pal[15] = RGB(255, 0, 255);
  707. pal[16] = RGB(128, 0, 128);
  708. if (GetPaletteEntries(hpal, 11, 1, (LPPALETTEENTRY)&pal[17]))
  709. {
  710. pal[0] = MAKELONG(0x300, 17);
  711. m_hpalVGA = CreatePalette((LPLOGPALETTE)pal);
  712. // get magic colors
  713. if (GetPaletteEntries(hpal, 8, 4, (LPPALETTEENTRY)&pal[17]))
  714. {
  715. pal[0] = MAKELONG(0x300, 20);
  716. m_hpal3D = CreatePalette((LPLOGPALETTE)pal);
  717. }
  718. }
  719. return S_OK;
  720. }
  721. // get all of the interesting system information and put it in the tables
  722. HRESULT CAdvAppearancePage::_InitSysStuff(void)
  723. {
  724. int nIndex;
  725. _InitColorAndPalette();
  726. // clean out the memory
  727. for (nIndex = 0; nIndex < ARRAYSIZE(m_fonts); nIndex++)
  728. {
  729. m_fonts[nIndex].hfont = NULL;
  730. }
  731. // build all the brushes/fonts we need
  732. _RebuildSysStuff(TRUE);
  733. // Get the current System and User charsets based on locales and UI languages.
  734. _InitUniqueCharsetArray();
  735. return S_OK;
  736. }
  737. /*
  738. ** clean up any mess made in maintaining system information
  739. ** also, write out any global changes in our setup.
  740. */
  741. void CAdvAppearancePage::_DestroySysStuff(void)
  742. {
  743. int i;
  744. HKEY hkAppear;
  745. SelectObject(g_hdcMem, GetStockObject(BLACK_BRUSH));
  746. SelectObject(g_hdcMem, GetStockObject(SYSTEM_FONT));
  747. _FreeFonts();
  748. for (i = 0; i < COLOR_MAX; i++)
  749. {
  750. if (m_brushes[i])
  751. {
  752. DeleteObject(m_brushes[i]);
  753. m_brushes[i] = NULL;
  754. }
  755. }
  756. m_hbrGradientColor = m_hbrMainColor = m_hbrTextColor = NULL;
  757. // save out possible changes to custom color table
  758. if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_APPEARANCE, &hkAppear) == ERROR_SUCCESS)
  759. {
  760. RegSetValueEx(hkAppear, REGSTR_VAL_CUSTOMCOLORS, 0L, REG_BINARY,
  761. (LPBYTE)g_CustomColors, sizeof(g_CustomColors));
  762. RegCloseKey(hkAppear);
  763. }
  764. // reset these so they init properly
  765. m_iCurElement = CURRENT_ELEMENT_NONE;
  766. m_iPrevSize = SIZE_NONE;
  767. m_bPalette = FALSE;
  768. m_fInUserEditMode = FALSE;
  769. }
  770. //------------------------ mini font picker controls --------------------------
  771. // Add a facename/script combination to the font dropdown combo list.
  772. //
  773. // The strings are formatted as "FaceName (ScriptName)"
  774. INT Font_AddNameToList(HWND hwndList, LPTSTR pszFace, LPTSTR pszScript)
  775. {
  776. // Create temp buffer to hold a face name, a script name, one space
  777. // two parens and a NUL char.
  778. //
  779. // i.e.: "Arial (Western)"
  780. #ifdef DEBUG
  781. TCHAR szFaceAndScript[LF_FACESIZE + LF_FACESIZE + 4];
  782. #endif //DEBUG
  783. LPTSTR pszDisplayName = pszFace;
  784. INT iItem;
  785. // We decided not to show the scriptnames; Only facenames will be shown.
  786. // For the purpose of debugging, I leave the script name in debug versions only.
  787. #ifdef DEBUG
  788. if (NULL != pszScript && TEXT('\0') != *pszScript)
  789. {
  790. //
  791. // Font has a script name. Append it to the facename in parens.
  792. // This format string controls the appearance of the font names
  793. // in the list. If you change this, you must also change the
  794. // extraction logic in Font_GetNameFromList().
  795. //
  796. wsprintf(szFaceAndScript, TEXT("%s(%s)"), pszFace, pszScript);
  797. pszDisplayName = szFaceAndScript;
  798. }
  799. #endif //DEBUG
  800. //
  801. // Add the display name string to the listbox.
  802. //
  803. iItem = (INT)SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM)pszDisplayName);
  804. if (CB_ERR != iItem)
  805. {
  806. //
  807. // Ensure the drop-down combo list will show the entire string.
  808. //
  809. HDC hdc = GetDC(hwndList);
  810. if (NULL != hdc)
  811. {
  812. SIZE sizeItem;
  813. //
  814. // Make sure the list's font is selected into the DC before
  815. // calculating the text extent.
  816. //
  817. HFONT hfontList = (HFONT)SendMessage(hwndList, WM_GETFONT, 0, 0);
  818. HFONT hfontOld = (HFONT)SelectObject(hdc, hfontList);
  819. if (GetTextExtentPoint32(hdc, pszDisplayName, lstrlen(pszDisplayName), &sizeItem))
  820. {
  821. //
  822. // Get the current width of the dropped list.
  823. //
  824. INT cxList = (int)SendMessage(hwndList, CB_GETDROPPEDWIDTH, 0, 0);
  825. //
  826. // We need the length of this string plus two
  827. // widths of a vertical scroll bar.
  828. //
  829. sizeItem.cx += (ClassicGetSystemMetrics(SM_CXVSCROLL) * 2);
  830. if (sizeItem.cx > cxList)
  831. {
  832. //
  833. // List is not wide enough. Increase the width.
  834. //
  835. SendMessage(hwndList, CB_SETDROPPEDWIDTH, (WPARAM)sizeItem.cx, 0);
  836. }
  837. }
  838. SelectObject(hdc, hfontOld);
  839. ReleaseDC(hwndList, hdc);
  840. }
  841. }
  842. return iItem;
  843. }
  844. // Retrieve a font name from the font dropdown combo list.
  845. // Optionally, retrieve the script name string.
  846. BOOL Font_GetNameFromList(
  847. HWND hwndList, // HWND of combo.
  848. INT iItem, // Index of item in list.
  849. LPTSTR pszFace, // Destination for face name.
  850. INT cchFaceMax, // Chars in face name buffer.
  851. LPTSTR pszScript, // Optional. Can be NULL
  852. INT cchScriptMax // Optional. Ignored if pszScript is NULL
  853. )
  854. {
  855. BOOL bResult = FALSE;
  856. TCHAR szItemText[LF_FACESIZE + LF_FACESIZE + 4];
  857. if (pszScript)
  858. {
  859. StrCpyN(pszScript, TEXT(""), cchScriptMax);
  860. }
  861. if (CB_ERR != SendMessage(hwndList, CB_GETLBTEXT, (WPARAM)iItem, (LPARAM)szItemText))
  862. {
  863. LPTSTR pszEnd, pszParen; // Lookahead pointer
  864. LPCTSTR pszStart = pszEnd = pszParen = szItemText; // "Start" anchor pointer.
  865. //
  866. // Find the left paren.
  867. //
  868. for ( ; *pszEnd; pszEnd++) {
  869. if (TEXT('(') == *pszEnd)
  870. pszParen = pszEnd;
  871. }
  872. if(pszParen > pszStart) //Did we find a parenthis?
  873. pszEnd = pszParen; // Then that is the end of the facename.
  874. if (pszEnd > pszStart)
  875. {
  876. // Found it. Copy face name.
  877. INT cchCopy = (int)(pszEnd - pszStart) + 1; //Add one for the null terminator
  878. if (cchCopy > cchFaceMax)
  879. cchCopy = cchFaceMax;
  880. lstrcpyn(pszFace, pszStart, cchCopy); //(cchCopy-1) bytes are copies followed by a null
  881. bResult = TRUE;
  882. if (*pszEnd && (NULL != pszScript))
  883. {
  884. // Caller wants the script part also.
  885. pszStart = ++pszEnd;
  886. // Find the right paren.
  887. while(*pszEnd && TEXT(')') != *pszEnd)
  888. pszEnd++;
  889. if (*pszEnd && pszEnd > pszStart)
  890. {
  891. // Found it. Copy script name.
  892. cchCopy = (int)(pszEnd - pszStart) + 1;
  893. if (cchCopy > cchScriptMax)
  894. cchCopy = cchScriptMax;
  895. lstrcpyn(pszScript, pszStart, cchCopy);
  896. }
  897. }
  898. }
  899. }
  900. return bResult;
  901. }
  902. // Locate a facename/charset pair in the font list.
  903. INT Font_FindInList(HWND hwndList, LPCTSTR pszFaceName)
  904. {
  905. INT cItems = (int)SendMessage(hwndList, CB_GETCOUNT, 0, 0);
  906. INT i;
  907. for (i = 0; i < cItems; i++)
  908. {
  909. // All items in the fontlist have the same charset (SYSTEM_LOCALE_CHARSET).So, no point
  910. // in checking for the charset.
  911. //
  912. // Let's just get the facename and see if it matches.
  913. TCHAR szFaceName[LF_FACESIZE + 1];
  914. Font_GetNameFromList(hwndList, i, szFaceName, ARRAYSIZE(szFaceName), NULL, 0);
  915. if (0 == lstrcmpi(szFaceName, pszFaceName))
  916. {
  917. //
  918. // Face name matches.
  919. //
  920. return i;
  921. }
  922. }
  923. // No match found.
  924. return -1;
  925. }
  926. // Determine if a given font should be included in the font list.
  927. //
  928. // dwType arg is DEVICE_FONTTYPE, RASTER_FONTTYPE, TRUETYPE_FONTTYPE.
  929. // EXTERNAL_FONTTYPE is a private code. These are the
  930. // values returned to the enumproc from GDI.
  931. BOOL Font_IncludeInList(
  932. LPENUMLOGFONTEX lpelf,
  933. DWORD dwType
  934. )
  935. {
  936. BOOL bResult = TRUE; // Assume it's OK to include.
  937. BYTE lfCharSet = lpelf->elfLogFont.lfCharSet;
  938. #define EXTERNAL_FONTTYPE 8
  939. // Exclusions:
  940. //
  941. // 1. Don't display WIFE font for appearance because WIFE fonts are not
  942. // allowed to be any system use font such as menu/caption as it
  943. // realizes the font before WIFE gets initialized. B#5427
  944. //
  945. // 2. Exclude SYMBOL fonts.
  946. //
  947. // 3. Exclude OEM fonts.
  948. //
  949. // 4. Exclude vertical fonts.
  950. if (EXTERNAL_FONTTYPE & dwType ||
  951. lfCharSet == SYMBOL_CHARSET ||
  952. lfCharSet == OEM_CHARSET ||
  953. TEXT('@') == lpelf->elfLogFont.lfFaceName[0])
  954. {
  955. bResult = FALSE;
  956. }
  957. return bResult;
  958. }
  959. int CALLBACK Font_EnumNames(LPENUMLOGFONTEX lpelf, LPNEWTEXTMETRIC lpntm, DWORD dwType, LPARAM lData)
  960. {
  961. ENUMFONTPARAM * pEnumFontParam = (ENUMFONTPARAM *)lData;
  962. return pEnumFontParam->pThis->_EnumFontNames(lpelf, lpntm, dwType, pEnumFontParam);
  963. }
  964. int CAdvAppearancePage::_EnumFontNames(LPENUMLOGFONTEX lpelf, LPNEWTEXTMETRIC lpntm, DWORD Type, ENUMFONTPARAM * pEnumFontParam)
  965. {
  966. // Should font be included in the "Font" list?
  967. if (Font_IncludeInList(lpelf, Type))
  968. {
  969. int j;
  970. LOGFONT lf = lpelf->elfLogFont; //Make a local copy of the given font
  971. BYTE bSysCharset = lf.lfCharSet; //Preserve the system charset we got.
  972. BOOL fSupportsAllCharsets = TRUE;
  973. //The given font supports the system charset; Let's check if it supports the other charsets
  974. for(j = 1; j < m_iCountCharsets; j++)
  975. {
  976. lf.lfCharSet = (BYTE)m_uiUniqueCharsets[j]; //Let's try the next charset in the array.
  977. if(EnumFontFamiliesEx(pEnumFontParam->hdc, &lf, (FONTENUMPROC)Font_EnumValidCharsets, (LPARAM)0, 0) != 0)
  978. {
  979. // EnumFontFamiliesEx would have returned a zero if Font_EnumValidCharsets was called
  980. // even once. In other words, it returned a non-zero because not even a single font existed
  981. // that supported the given charset. Therefore, we need to skip this font.
  982. fSupportsAllCharsets = FALSE;
  983. break;
  984. }
  985. }
  986. if(fSupportsAllCharsets)
  987. {
  988. int i;
  989. // Yep. Add it to the list.
  990. i = Font_AddNameToList(pEnumFontParam->hwndFontName, lpelf->elfLogFont.lfFaceName, lpelf->elfScript);
  991. if (i != CB_ERR)
  992. {
  993. // Remember the font type and charset in the itemdata.
  994. //
  995. // LOWORD = Type
  996. // HIWORD = System Charset
  997. SendMessage(pEnumFontParam->hwndFontName, CB_SETITEMDATA, (WPARAM)i, MAKELPARAM(Type, bSysCharset));
  998. }
  999. }
  1000. }
  1001. return 1;
  1002. }
  1003. void CAdvAppearancePage::_InitFontList(HWND hDlg)
  1004. {
  1005. LOGFONT lf;
  1006. ENUMFONTPARAM EnumFontParam;
  1007. // Enumerate all fonts on the system.
  1008. // _EnumFontNames will filter out ones we don't want to show.
  1009. lf.lfFaceName[0] = TEXT('\0') ;
  1010. lf.lfCharSet = (BYTE)m_uiUniqueCharsets[SYSTEM_LOCALE_CHARSET]; //Use charset from the System Locale.
  1011. #ifdef WINDOWS_ME
  1012. lf.lfPitchAndFamily = MONO_FONT;
  1013. #else
  1014. lf.lfPitchAndFamily = 0;
  1015. #endif
  1016. EnumFontParam.hwndFontName = GetDlgItem(hDlg, IDC_ADVAP_FONTNAME);
  1017. EnumFontParam.hdc = GetDC(NULL);
  1018. EnumFontParam.pThis = this;
  1019. EnumFontFamiliesEx(EnumFontParam.hdc, &lf, (FONTENUMPROC)Font_EnumNames, (LPARAM)&EnumFontParam, 0);
  1020. ReleaseDC(NULL, EnumFontParam.hdc);
  1021. }
  1022. void Font_AddSize(HWND hwndPoints, int iNewPoint, BOOL bSort)
  1023. {
  1024. TCHAR szBuf[10];
  1025. int i, iPoint, count;
  1026. // find the sorted place for this point size
  1027. if (bSort)
  1028. {
  1029. count = (int)SendMessage(hwndPoints, CB_GETCOUNT, 0, 0L);
  1030. for (i=0; i < count; i++)
  1031. {
  1032. iPoint = LOWORD(SendMessage(hwndPoints, CB_GETITEMDATA, (WPARAM)i, 0L));
  1033. // don't add duplicates
  1034. if (iPoint == iNewPoint)
  1035. return;
  1036. // belongs before this one
  1037. if (iPoint > iNewPoint)
  1038. break;
  1039. }
  1040. }
  1041. else
  1042. i = -1;
  1043. wsprintf(szBuf, TEXT("%d"), iNewPoint);
  1044. i = (int)SendMessage(hwndPoints, CB_INSERTSTRING, (WPARAM)i, (LPARAM)szBuf);
  1045. if (i != CB_ERR)
  1046. SendMessage(hwndPoints, CB_SETITEMDATA, (WPARAM)i, (LPARAM)iNewPoint);
  1047. }
  1048. // enumerate sizes for a non-TrueType font
  1049. int CALLBACK Font_EnumSizes(LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC lpntm, int Type, LPARAM lData)
  1050. {
  1051. CAdvAppearancePage * pThis = (CAdvAppearancePage *) lData;
  1052. if (pThis)
  1053. {
  1054. return pThis->_EnumSizes(lpelf, lpntm, Type);
  1055. }
  1056. return 1;
  1057. }
  1058. int CAdvAppearancePage::_EnumSizes(LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC lpntm, int Type)
  1059. {
  1060. if (lpntm && _hwnd)
  1061. {
  1062. HWND hwndFontSize = GetDlgItem(_hwnd, IDC_ADVAP_FONTSIZE);
  1063. Font_AddSize(hwndFontSize, _HeightToPoint(lpntm->tmHeight - lpntm->tmInternalLeading), TRUE);
  1064. }
  1065. return 1;
  1066. }
  1067. // a new element was picked, resulting in needing to set up a new font.
  1068. void CAdvAppearancePage::_NewFont(HWND hDlg, int iFont)
  1069. {
  1070. int iSel;
  1071. BOOL bBold;
  1072. // find the name in the list and select it
  1073. iSel = Font_FindInList(GetDlgItem(hDlg, IDC_ADVAP_FONTNAME), m_fonts[iFont].lf.lfFaceName);
  1074. SendDlgItemMessage(hDlg, IDC_ADVAP_FONTNAME, CB_SETCURSEL, (WPARAM)iSel, 0L);
  1075. _SelectName(hDlg, iSel);
  1076. Font_SelectSize(hDlg, _HeightToPoint(m_fonts[iFont].lf.lfHeight));
  1077. // REVIEW: should new size (returned above) be set in logfont?
  1078. CheckDlgButton(hDlg, IDC_ADVAP_FONTITAL, m_fonts[iFont].lf.lfItalic);
  1079. if (m_fonts[iFont].lf.lfWeight > FW_MEDIUM)
  1080. bBold = TRUE;
  1081. else
  1082. bBold = FALSE;
  1083. CheckDlgButton(hDlg, IDC_ADVAP_FONTBOLD, bBold);
  1084. }
  1085. // enable/disable the font selection controls.
  1086. // also involves blanking out anything meaningful if disabling.
  1087. void Font_EnableControls(HWND hDlg, BOOL bEnable)
  1088. {
  1089. if (!bEnable)
  1090. {
  1091. SendDlgItemMessage(hDlg, IDC_ADVAP_FONTNAME, CB_SETCURSEL, (WPARAM)-1, 0L);
  1092. SendDlgItemMessage(hDlg, IDC_ADVAP_FONTSIZE, CB_SETCURSEL, (WPARAM)-1, 0L);
  1093. CheckDlgButton(hDlg, IDC_ADVAP_FONTITAL, 0);
  1094. CheckDlgButton(hDlg, IDC_ADVAP_FONTBOLD, 0);
  1095. }
  1096. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTNAME), bEnable);
  1097. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTSIZE), bEnable);
  1098. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTSIZELABEL), bEnable);
  1099. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTLABEL), bEnable);
  1100. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTBOLD), bEnable);
  1101. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FONTITAL), bEnable);
  1102. }
  1103. //--------end------------- mini font picker controls --------------------------
  1104. void CAdvAppearancePage::_SetColor(HWND hDlg, int id, HBRUSH hbrColor)
  1105. {
  1106. HWND hwndItem;
  1107. switch (id)
  1108. {
  1109. case IDC_ADVAP_GRADIENT:
  1110. m_hbrGradientColor = hbrColor;
  1111. break;
  1112. case IDC_ADVAP_MAINCOLOR:
  1113. m_hbrMainColor = hbrColor;
  1114. break;
  1115. case IDC_ADVAP_TEXTCOLOR:
  1116. m_hbrTextColor = hbrColor;
  1117. break;
  1118. default:
  1119. return;
  1120. }
  1121. hwndItem = GetDlgItem(hDlg, id);
  1122. if (hwndItem)
  1123. {
  1124. InvalidateRect(hwndItem, NULL, FALSE);
  1125. UpdateWindow(hwndItem);
  1126. }
  1127. }
  1128. void CAdvAppearancePage::_DrawDownArrow(HDC hdc, LPRECT lprc, BOOL bDisabled)
  1129. {
  1130. HBRUSH hbr;
  1131. int x, y;
  1132. x = lprc->right - m_cxEdgeSM - 5;
  1133. y = lprc->top + ((lprc->bottom - lprc->top)/2 - 1);
  1134. if (bDisabled)
  1135. {
  1136. hbr = GetSysColorBrush(COLOR_3DHILIGHT);
  1137. hbr = (HBRUSH) SelectObject(hdc, hbr);
  1138. x++;
  1139. y++;
  1140. PatBlt(hdc, x, y, 5, 1, PATCOPY);
  1141. PatBlt(hdc, x+1, y+1, 3, 1, PATCOPY);
  1142. PatBlt(hdc, x+2, y+2, 1, 1, PATCOPY);
  1143. SelectObject(hdc, hbr);
  1144. x--;
  1145. y--;
  1146. }
  1147. hbr = GetSysColorBrush(bDisabled ? COLOR_3DSHADOW : COLOR_BTNTEXT);
  1148. hbr = (HBRUSH) SelectObject(hdc, hbr);
  1149. PatBlt(hdc, x, y, 5, 1, PATCOPY);
  1150. PatBlt(hdc, x+1, y+1, 3, 1, PATCOPY);
  1151. PatBlt(hdc, x+2, y+2, 1, 1, PATCOPY);
  1152. SelectObject(hdc, hbr);
  1153. lprc->right = x;
  1154. }
  1155. // draw the color combobox thing
  1156. //
  1157. // also, if button was depressed, popup the color picker
  1158. //
  1159. void CAdvAppearancePage::_DrawButton(HWND hDlg, LPDRAWITEMSTRUCT lpdis)
  1160. {
  1161. SIZE thin = { m_cxEdgeSM / 2, m_cyEdgeSM / 2 };
  1162. RECT rc = lpdis->rcItem;
  1163. HDC hdc = lpdis->hDC;
  1164. BOOL bFocus = ((lpdis->itemState & ODS_FOCUS) &&
  1165. !(lpdis->itemState & ODS_DISABLED));
  1166. if (!thin.cx) thin.cx = 1;
  1167. if (!thin.cy) thin.cy = 1;
  1168. if (!m_hTheme)
  1169. {
  1170. if (lpdis->itemState & ODS_SELECTED)
  1171. {
  1172. DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
  1173. OffsetRect(&rc, 1, 1);
  1174. }
  1175. else
  1176. {
  1177. DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_ADJUST);
  1178. }
  1179. FillRect(hdc, &rc, GetSysColorBrush(COLOR_3DFACE));
  1180. }
  1181. else
  1182. {
  1183. int iStateId;
  1184. if (lpdis->itemState & ODS_SELECTED)
  1185. {
  1186. iStateId = PBS_PRESSED;
  1187. }
  1188. else if (lpdis->itemState & ODS_HOTLIGHT)
  1189. {
  1190. iStateId = PBS_HOT;
  1191. }
  1192. else if (lpdis->itemState & ODS_DISABLED)
  1193. {
  1194. iStateId = PBS_DISABLED;
  1195. }
  1196. else if (lpdis->itemState & ODS_FOCUS)
  1197. {
  1198. iStateId = PBS_DEFAULTED;
  1199. }
  1200. else
  1201. {
  1202. iStateId = PBS_NORMAL;
  1203. }
  1204. DrawThemeBackground(m_hTheme, hdc, BP_PUSHBUTTON, iStateId, &rc, 0);
  1205. GetThemeBackgroundContentRect(m_hTheme, hdc, BP_PUSHBUTTON, iStateId, &rc, &rc);
  1206. }
  1207. if (bFocus)
  1208. {
  1209. InflateRect(&rc, -thin.cx, -thin.cy);
  1210. DrawFocusRect(hdc, &rc);
  1211. InflateRect(&rc, thin.cx, thin.cy);
  1212. }
  1213. InflateRect(&rc, 1-thin.cx, -m_cyEdgeSM);
  1214. rc.left += m_cxEdgeSM;
  1215. _DrawDownArrow(hdc, &rc, lpdis->itemState & ODS_DISABLED);
  1216. InflateRect(&rc, -thin.cx, 0);
  1217. DrawEdge(hdc, &rc, EDGE_ETCHED, BF_RIGHT);
  1218. rc.right -= ( 2 * m_cxEdgeSM ) + thin.cx;
  1219. // color sample
  1220. if ( !(lpdis->itemState & ODS_DISABLED) )
  1221. {
  1222. HPALETTE hpalOld = NULL;
  1223. HBRUSH hbr = 0;
  1224. switch (lpdis->CtlID)
  1225. {
  1226. case IDC_ADVAP_GRADIENT:
  1227. hbr = m_hbrGradientColor;
  1228. break;
  1229. case IDC_ADVAP_MAINCOLOR:
  1230. hbr = m_hbrMainColor;
  1231. break;
  1232. case IDC_ADVAP_TEXTCOLOR:
  1233. hbr = m_hbrTextColor;
  1234. break;
  1235. }
  1236. FrameRect(hdc, &rc, GetSysColorBrush(COLOR_BTNTEXT));
  1237. InflateRect(&rc, -thin.cx, -thin.cy);
  1238. if (m_hpal3D)
  1239. {
  1240. hpalOld = SelectPalette(hdc, m_hpal3D, FALSE);
  1241. RealizePalette(hdc);
  1242. }
  1243. if (hbr)
  1244. {
  1245. hbr = (HBRUSH) SelectObject(hdc, hbr);
  1246. PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, PATCOPY);
  1247. SelectObject(hdc, hbr);
  1248. }
  1249. if (hpalOld)
  1250. {
  1251. SelectPalette(hdc, hpalOld, TRUE);
  1252. RealizePalette(hdc);
  1253. }
  1254. }
  1255. }
  1256. //--------end------------- color stuff --------------------------------------
  1257. void LoadCustomColors(void)
  1258. {
  1259. HKEY hkSchemes;
  1260. DWORD dwType, dwSize;
  1261. // if no colors are there, initialize to all white
  1262. for (int nIndex = 0; nIndex < ARRAYSIZE(g_CustomColors); nIndex++)
  1263. {
  1264. g_CustomColors[nIndex] = RGB(255, 255, 255);
  1265. }
  1266. // select the current scheme
  1267. if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_APPEARANCE, &hkSchemes) == ERROR_SUCCESS)
  1268. {
  1269. // also, since this key is already open, get the custom colors
  1270. dwSize = sizeof(g_CustomColors);
  1271. dwType = REG_BINARY;
  1272. // It's okay if this call fails. We handle the case where the user
  1273. // didn't create custom colors.
  1274. RegQueryValueEx(hkSchemes, REGSTR_VAL_CUSTOMCOLORS, NULL, &dwType, (LPBYTE)g_CustomColors, &dwSize);
  1275. RegCloseKey(hkSchemes);
  1276. }
  1277. }
  1278. static void RemoveBlanks(LPTSTR lpszString)
  1279. {
  1280. LPTSTR lpszPosn;
  1281. /* strip leading blanks */
  1282. lpszPosn = lpszString;
  1283. while(*lpszPosn == TEXT(' ')) {
  1284. lpszPosn++;
  1285. }
  1286. if (lpszPosn != lpszString)
  1287. lstrcpy(lpszString, lpszPosn);
  1288. /* strip trailing blanks */
  1289. if ((lpszPosn=lpszString+lstrlen(lpszString)) != lpszString) {
  1290. lpszPosn = CharPrev(lpszString, lpszPosn);
  1291. while(*lpszPosn == TEXT(' '))
  1292. lpszPosn = CharPrev(lpszString, lpszPosn);
  1293. lpszPosn = CharNext(lpszPosn);
  1294. *lpszPosn = TEXT('\0');
  1295. }
  1296. }
  1297. HRESULT CAdvAppearancePage::_SelectElement(HWND hDlg, int iElement, DWORD dwFlags)
  1298. {
  1299. BOOL bEnable;
  1300. int i;
  1301. BOOL bEnableGradient;
  1302. BOOL bGradient = FALSE;
  1303. if ((iElement == m_iCurElement) && !(dwFlags & LSE_ALWAYS))
  1304. {
  1305. return S_OK;
  1306. }
  1307. ClassicSystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, (PVOID)&bGradient, 0);
  1308. m_iCurElement = iElement;
  1309. // if needed, find this element in the combobox and select it
  1310. if (dwFlags & LSE_SETCUR)
  1311. {
  1312. i = (int)SendDlgItemMessage(hDlg, IDC_ADVAP_ELEMENTS, CB_GETCOUNT,0,0L);
  1313. for (i--; i >=0 ; i--)
  1314. {
  1315. // if this is the one that references our element, stop
  1316. if (iElement == (int)LOWORD(SendDlgItemMessage(hDlg, IDC_ADVAP_ELEMENTS, CB_GETITEMDATA, (WPARAM)i, 0L)))
  1317. break;
  1318. }
  1319. SendDlgItemMessage(hDlg, IDC_ADVAP_ELEMENTS, CB_SETCURSEL, (WPARAM)i,0L);
  1320. }
  1321. bEnable = (ELCUR.iMainColor != COLOR_NONE);
  1322. if (bEnable)
  1323. _SetColor(hDlg, IDC_ADVAP_MAINCOLOR, m_brushes[ELCUR.iMainColor]);
  1324. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_MAINCOLOR), bEnable);
  1325. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_COLORLABEL), bEnable);
  1326. bEnableGradient = ((ELCUR.iGradientColor != COLOR_NONE));
  1327. if (bEnableGradient)
  1328. _SetColor(hDlg, IDC_ADVAP_GRADIENT, m_brushes[ELCUR.iGradientColor]);
  1329. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_GRADIENT), (bEnableGradient && bGradient));
  1330. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_GRADIENTLABEL), (bEnableGradient && bGradient));
  1331. bEnable = (ELCUR.iFont != FONT_NONE);
  1332. if (bEnable)
  1333. {
  1334. _NewFont(hDlg, ELCUR.iFont);
  1335. }
  1336. Font_EnableControls(hDlg, bEnable);
  1337. // size may be based on font
  1338. _DoSizeStuff(hDlg, FALSE);
  1339. bEnable = (ELCUR.iSize != SIZE_NONE);
  1340. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_MAINSIZE), bEnable);
  1341. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_SIZEARROWS), bEnable);
  1342. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_SIZELABEL), bEnable);
  1343. bEnable = (ELCUR.iTextColor != COLOR_NONE);
  1344. if (bEnable)
  1345. _SetColor(hDlg, IDC_ADVAP_TEXTCOLOR, m_brushes[ELCUR.iTextColor]);
  1346. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_TEXTCOLOR), bEnable);
  1347. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_FNCOLORLABEL), bEnable);
  1348. return S_OK;
  1349. }
  1350. void CAdvAppearancePage::_Repaint(HWND hDlg, BOOL bRecalc)
  1351. {
  1352. HWND hwndLookPrev;
  1353. hwndLookPrev = GetDlgItem(hDlg, IDC_ADVAP_LOOKPREV);
  1354. if (bRecalc)
  1355. {
  1356. _SyncSize(hDlg);
  1357. RECT rc;
  1358. GetClientRect(hwndLookPrev, &rc);
  1359. _Recalc(&rc);
  1360. }
  1361. _RepaintPreview(hwndLookPrev);
  1362. }
  1363. void CAdvAppearancePage::_SetCurSizeAndRange(HWND hDlg)
  1364. {
  1365. if (ELCUR.iSize == SIZE_NONE)
  1366. SetDlgItemText(hDlg, IDC_ADVAP_MAINSIZE, TEXT(""));
  1367. else
  1368. {
  1369. SendDlgItemMessage(hDlg, IDC_ADVAP_SIZEARROWS, UDM_SETRANGE, 0,
  1370. MAKELPARAM(m_elCurrentSize.MaxSize, m_elCurrentSize.MinSize));
  1371. SetDlgItemInt(hDlg, IDC_ADVAP_MAINSIZE, m_elCurrentSize.CurSize, TRUE);
  1372. }
  1373. }
  1374. void CAdvAppearancePage::_SyncSize(HWND hDlg)
  1375. {
  1376. if (m_iPrevSize != SIZE_NONE)
  1377. m_sizes[m_iPrevSize].CurSize = m_elCurrentSize.CurSize;
  1378. if (m_iCurElement >= 0)
  1379. m_iPrevSize = ELCUR.iSize;
  1380. }
  1381. void CAdvAppearancePage::_UpdateSizeBasedOnFont(HWND hDlg, BOOL fComputeIdeal)
  1382. {
  1383. if ((ELCUR.iSize != SIZE_NONE) && (ELCUR.iFont != FONT_NONE))
  1384. {
  1385. TEXTMETRIC tm;
  1386. HFONT hfontOld = (HFONT) SelectObject(g_hdcMem, ELCURFONT.hfont);
  1387. GetTextMetrics(g_hdcMem, &tm);
  1388. if (ELCUR.iSize == SIZE_MENU)
  1389. {
  1390. // Include external leading for menus
  1391. tm.tmHeight += tm.tmExternalLeading;
  1392. }
  1393. if (hfontOld)
  1394. {
  1395. SelectObject(g_hdcMem, hfontOld);
  1396. }
  1397. m_elCurrentSize.MinSize = tm.tmHeight + 2 * m_cyBorderSM;
  1398. if (fComputeIdeal)
  1399. {
  1400. if ((ELCUR.iSize == SIZE_CAPTION || ELCUR.iSize == SIZE_MENU) &&
  1401. (m_elCurrentSize.MinSize < (ClassicGetSystemMetrics(SM_CYICON)/2 + 2 * m_cyBorderSM)))
  1402. {
  1403. m_elCurrentSize.CurSize = ClassicGetSystemMetrics(SM_CYICON)/2 + 2 * m_cyBorderSM;
  1404. }
  1405. else // if (m_elCurrentSize.CurSize < m_elCurrentSize.MinSize)
  1406. {
  1407. m_elCurrentSize.CurSize = m_elCurrentSize.MinSize;
  1408. }
  1409. }
  1410. else if (m_elCurrentSize.CurSize < m_elCurrentSize.MinSize)
  1411. {
  1412. m_elCurrentSize.CurSize = m_elCurrentSize.MinSize;
  1413. }
  1414. }
  1415. }
  1416. void CAdvAppearancePage::_DoSizeStuff(HWND hDlg, BOOL fCanSuggest)
  1417. {
  1418. _SyncSize(hDlg);
  1419. if (ELCUR.iSize != SIZE_NONE)
  1420. {
  1421. m_elCurrentSize = m_sizes[ELCUR.iSize];
  1422. if (ELCUR.fLinkSizeToFont)
  1423. {
  1424. _UpdateSizeBasedOnFont(hDlg, fCanSuggest);
  1425. }
  1426. if (m_elCurrentSize.CurSize < m_elCurrentSize.MinSize)
  1427. {
  1428. m_elCurrentSize.CurSize = m_elCurrentSize.MinSize;
  1429. }
  1430. else if (m_elCurrentSize.CurSize > m_elCurrentSize.MaxSize)
  1431. {
  1432. m_elCurrentSize.CurSize = m_elCurrentSize.MaxSize;
  1433. }
  1434. }
  1435. _SetCurSizeAndRange(hDlg);
  1436. }
  1437. void CAdvAppearancePage::_RebuildCurFont(HWND hDlg)
  1438. {
  1439. if (ELCURFONT.hfont)
  1440. DeleteObject(ELCURFONT.hfont);
  1441. ELCURFONT.hfont = CreateFontIndirect(&ELCURFONT.lf);
  1442. _DoSizeStuff(hDlg, TRUE);
  1443. _Repaint(hDlg, TRUE);
  1444. }
  1445. void CAdvAppearancePage::_Changed(HWND hDlg, DWORD dwChange)
  1446. {
  1447. if (m_fInUserEditMode)
  1448. {
  1449. if ((dwChange != SCHEME_CHANGE) && (dwChange != DPI_CHANGE))
  1450. {
  1451. // We keep track if we have customized settings from the stock Scheme.
  1452. m_fModifiedScheme = TRUE;
  1453. }
  1454. else
  1455. {
  1456. dwChange = METRIC_CHANGE | COLOR_CHANGE;
  1457. }
  1458. m_dwChanged |= dwChange;
  1459. }
  1460. }
  1461. void CAdvAppearancePage::_ChangeFontName(HWND hDlg, LPCTSTR szBuf, INT iCharSet)
  1462. {
  1463. if (lstrcmpi(ELCURFONT.lf.lfFaceName, szBuf) == 0 &&
  1464. ELCURFONT.lf.lfCharSet == iCharSet)
  1465. {
  1466. return;
  1467. }
  1468. lstrcpy(ELCURFONT.lf.lfFaceName, szBuf);
  1469. ELCURFONT.lf.lfCharSet = (BYTE)iCharSet;
  1470. _RebuildCurFont(hDlg);
  1471. _Changed(hDlg, METRIC_CHANGE);
  1472. }
  1473. void CAdvAppearancePage::_ChangeFontSize(HWND hDlg, int Points)
  1474. {
  1475. if (ELCURFONT.lf.lfHeight != _PointToHeight(Points))
  1476. {
  1477. ELCURFONT.lf.lfHeight = _PointToHeight(Points);
  1478. _RebuildCurFont(hDlg);
  1479. _Changed(hDlg, METRIC_CHANGE);
  1480. }
  1481. }
  1482. void CAdvAppearancePage::_ChangeFontBI(HWND hDlg, int id, BOOL bCheck)
  1483. {
  1484. if (id == IDC_ADVAP_FONTBOLD) // bold
  1485. {
  1486. if (bCheck)
  1487. ELCURFONT.lf.lfWeight = FW_BOLD;
  1488. else
  1489. ELCURFONT.lf.lfWeight = FW_NORMAL;
  1490. }
  1491. else // italic
  1492. {
  1493. ELCURFONT.lf.lfItalic = (BYTE)bCheck;
  1494. }
  1495. _RebuildCurFont(hDlg);
  1496. _Changed(hDlg, METRIC_CHANGE);
  1497. }
  1498. void CAdvAppearancePage::_ChangeSize(HWND hDlg, int NewSize, BOOL bRepaint)
  1499. {
  1500. if (m_elCurrentSize.CurSize != NewSize)
  1501. {
  1502. m_elCurrentSize.CurSize = NewSize;
  1503. if (bRepaint)
  1504. {
  1505. _Repaint(hDlg, TRUE);
  1506. }
  1507. _Changed(hDlg, METRIC_CHANGE);
  1508. }
  1509. }
  1510. BOOL CAdvAppearancePage::_ChangeColor(HWND hDlg, int iColor, COLORREF rgb)
  1511. {
  1512. COLORREF rgbShadow, rgbHilight, rgbWatermark;
  1513. if ((rgb & 0x00FFFFFF) == (m_rgb[iColor] & 0x00FFFFFF))
  1514. return FALSE;
  1515. if (iColor == COLOR_3DFACE)
  1516. {
  1517. rgbShadow = AdjustLuma(rgb, m_i3DShadowAdj, m_fScale3DShadowAdj);
  1518. rgbHilight = AdjustLuma(rgb, m_i3DHilightAdj, m_fScale3DHilightAdj);
  1519. rgbWatermark = AdjustLuma(rgb, m_iWatermarkAdj, m_fScaleWatermarkAdj);
  1520. _Set3DPaletteColor(rgb, COLOR_3DFACE);
  1521. _Set3DPaletteColor(rgbShadow, COLOR_3DSHADOW);
  1522. _Set3DPaletteColor(rgbHilight, COLOR_3DHILIGHT);
  1523. // update colors tagged to 3DFACE
  1524. m_rgb[COLOR_3DFACE] = rgb;
  1525. m_rgb[COLOR_3DLIGHT] = rgb; // BOGUS TEMPORARY
  1526. m_rgb[COLOR_ACTIVEBORDER] = rgb;
  1527. m_rgb[COLOR_INACTIVEBORDER] = rgb;
  1528. m_rgb[COLOR_MENU] = rgb;
  1529. // update colors tagged to 3DSHADOW
  1530. m_rgb[COLOR_GRAYTEXT] = rgbShadow;
  1531. m_rgb[COLOR_APPWORKSPACE] = rgbShadow;
  1532. m_rgb[COLOR_3DSHADOW] = rgbShadow;
  1533. m_rgb[COLOR_INACTIVECAPTION] = rgbShadow;
  1534. // update colors tagged to 3DHIGHLIGHT
  1535. m_rgb[COLOR_3DHILIGHT] = rgbHilight;
  1536. m_rgb[COLOR_SCROLLBAR] = rgbHilight;
  1537. if ((m_rgb[COLOR_SCROLLBAR] & 0x00FFFFFF) ==
  1538. (m_rgb[COLOR_WINDOW] & 0x00FFFFFF))
  1539. {
  1540. m_rgb[COLOR_SCROLLBAR] = RGB( 192, 192, 192 );
  1541. }
  1542. }
  1543. else
  1544. {
  1545. m_rgb[iColor] = rgb;
  1546. }
  1547. _RebuildSysStuff(FALSE);
  1548. _Changed(hDlg, COLOR_CHANGE);
  1549. return TRUE;
  1550. }
  1551. void CAdvAppearancePage::_PropagateMessage(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  1552. {
  1553. HWND hwndChild;
  1554. // Don't propagate during exit since this is only for good looks, and the Up/Down's
  1555. // get confused if they get a WM_SETTINGSHCANGED while they are getting destroyed
  1556. if (m_fProprtySheetExiting)
  1557. return;
  1558. for (hwndChild = ::GetWindow(hwnd, GW_CHILD); hwndChild != NULL;
  1559. hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT))
  1560. {
  1561. #ifdef DBG_PRINT
  1562. TCHAR szTmp[256];
  1563. GetClassName(hwndChild, szTmp, 256);
  1564. TraceMsg(TF_GENERAL, "desk (PropagateMessage): SendingMessage( 0x%08lX cls:%s, 0x%08X, 0x%08lX, 0x%08lX )\n", hwndChild, szTmp, uMessage, wParam, lParam ));
  1565. #endif
  1566. SendMessage(hwndChild, uMessage, wParam, lParam);
  1567. TraceMsg(TF_GENERAL,"desk (PropagateMessage): back from SendingMessage\n");
  1568. }
  1569. }
  1570. void CAdvAppearancePage::_UpdateGradientButton(HWND hDlg)
  1571. {
  1572. BOOL bEnableGradient = FALSE;
  1573. BOOL bGradient = FALSE;
  1574. ClassicSystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, (PVOID)&bGradient, 0);
  1575. if (m_iCurElement >= 0)
  1576. {
  1577. bEnableGradient = ((ELCUR.iGradientColor != COLOR_NONE));
  1578. }
  1579. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_GRADIENT), (bEnableGradient && bGradient));
  1580. EnableWindow(GetDlgItem(hDlg, IDC_ADVAP_GRADIENTLABEL), (bEnableGradient && bGradient));
  1581. }
  1582. //--------end------------- manage system settings --------------------------
  1583. // Fill in a NONCLIENTMETRICS structure with latest preview stuff
  1584. void CAdvAppearancePage::_GetMyNonClientMetrics(LPNONCLIENTMETRICS lpncm)
  1585. {
  1586. lpncm->iBorderWidth = (LONG)m_sizes[SIZE_FRAME].CurSize;
  1587. lpncm->iScrollWidth = lpncm->iScrollHeight = (LONG)m_sizes[SIZE_SCROLL].CurSize;
  1588. lpncm->iSmCaptionWidth = lpncm->iSmCaptionHeight = (LONG)m_sizes[SIZE_SMCAPTION].CurSize;
  1589. lpncm->iMenuWidth = lpncm->iMenuHeight = (LONG)m_sizes[SIZE_MENU].CurSize;
  1590. // #355378:
  1591. // PRE-WHISTLER: Caption Height always matched Width. They were authored this way and
  1592. // the UI forced them to be the same. I don't know if apps rely on this behavior but they
  1593. // could have. The Status Bar icon is equal to the min(CaptionWidth, CaptionHeight).
  1594. // The user really wants their caption buttons to be square, so that also wants
  1595. // them to be equal. A caption width of 18 makes the icon be 16, anything else causes
  1596. // icon stretch and looks really bad.
  1597. //
  1598. // WHISTLER: In Whistler, our designers want a height of 25 so it looks nicer. They
  1599. // want the width to remain 18 so the icon is 16 pixels (inctlpan.c) in each direction. This means that
  1600. // this code can no longer force them to be even. ScottHan forces the captionbar buttons to
  1601. // be square solving that problem. I will now keep the aspect ratio so I scale them correctly.
  1602. // If we are close, I will snap to 18 to fix rounding errors.
  1603. lpncm->iCaptionHeight = (LONG)m_sizes[SIZE_CAPTION].CurSize;
  1604. lpncm->iCaptionWidth = (int) (m_fCaptionRatio * lpncm->iCaptionHeight);
  1605. // Don't shrink the caption width below 18 point until the caption height also gets below 18.
  1606. if (lpncm->iCaptionWidth < 18 && lpncm->iCaptionHeight >= 18)
  1607. {
  1608. lpncm->iCaptionWidth = 18;
  1609. }
  1610. if ((lpncm->iCaptionWidth <= 19) && (lpncm->iCaptionWidth >= 17) &&
  1611. (1.0f != m_fCaptionRatio))
  1612. {
  1613. // Icons only really look good at 16 pixels, so we need to set lpncm->iCaptionWidth to make the
  1614. // Caption bar icon 16 pixels. (#355378)
  1615. lpncm->iCaptionWidth = 18;
  1616. }
  1617. LFtoLF32(&(m_fonts[FONT_CAPTION].lf), &(lpncm->lfCaptionFont));
  1618. LFtoLF32(&(m_fonts[FONT_SMCAPTION].lf), &(lpncm->lfSmCaptionFont));
  1619. LFtoLF32(&(m_fonts[FONT_MENU].lf), &(lpncm->lfMenuFont));
  1620. LFtoLF32(&(m_fonts[FONT_STATUS].lf), &(lpncm->lfStatusFont));
  1621. LFtoLF32(&(m_fonts[FONT_MSGBOX].lf), &(lpncm->lfMessageFont));
  1622. }
  1623. // given a NONCLIENTMETRICS structure, make it preview's current setting
  1624. void CAdvAppearancePage::_SetMyNonClientMetrics(const LPNONCLIENTMETRICS lpncm)
  1625. {
  1626. m_sizes[SIZE_FRAME].CurSize = (int)lpncm->iBorderWidth;
  1627. m_sizes[SIZE_SCROLL].CurSize = (int)lpncm->iScrollWidth;
  1628. m_sizes[SIZE_SMCAPTION].CurSize = (int)lpncm->iSmCaptionHeight;
  1629. m_sizes[SIZE_MENU].CurSize = (int)lpncm->iMenuHeight;
  1630. m_sizes[SIZE_CAPTION].CurSize = (int)lpncm->iCaptionHeight;
  1631. m_fCaptionRatio = ((float) lpncm->iCaptionWidth / (float) lpncm->iCaptionHeight);
  1632. LF32toLF(&(lpncm->lfCaptionFont), &(m_fonts[FONT_CAPTION].lf));
  1633. LF32toLF(&(lpncm->lfSmCaptionFont), &(m_fonts[FONT_SMCAPTION].lf));
  1634. LF32toLF(&(lpncm->lfMenuFont), &(m_fonts[FONT_MENU].lf));
  1635. LF32toLF(&(lpncm->lfStatusFont), &(m_fonts[FONT_STATUS].lf));
  1636. LF32toLF(&(lpncm->lfMessageFont), &(m_fonts[FONT_MSGBOX].lf));
  1637. }
  1638. //--------end------------- scheme stuff --------------------------------------
  1639. HRESULT CAdvAppearancePage::_IsDirty(IN BOOL * pIsDirty)
  1640. {
  1641. HRESULT hr = E_INVALIDARG;
  1642. if (pIsDirty)
  1643. {
  1644. *pIsDirty = (NO_CHANGE != m_dwChanged);
  1645. hr = S_OK;
  1646. }
  1647. return hr;
  1648. }
  1649. //===========================
  1650. // *** IAdvancedDialog Interface ***
  1651. //===========================
  1652. HRESULT CAdvAppearancePage::DisplayAdvancedDialog(IN HWND hwndParent, IN IPropertyBag * pBasePage, IN BOOL * pfEnableApply)
  1653. {
  1654. HRESULT hr = E_INVALIDARG;
  1655. if (hwndParent && pBasePage && pfEnableApply)
  1656. {
  1657. // Load State Into Advanced Dialog
  1658. ATOMICRELEASE(g_pAdvAppearancePage);
  1659. g_pAdvAppearancePage = this;
  1660. AddRef();
  1661. *pfEnableApply = FALSE;
  1662. if (FAILED(SHPropertyBag_ReadInt(pBasePage, SZ_PBPROP_DPI_MODIFIED_VALUE, &m_nCachedNewDPI)))
  1663. {
  1664. m_nCachedNewDPI = DPI_PERSISTED; // Default to the default DPI.
  1665. }
  1666. // Display Advanced Dialog
  1667. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_APPEARANCE_ADVANCEDPG), hwndParent, CAdvAppearancePage::AdvAppearDlgProc, (LPARAM)this))
  1668. {
  1669. // The user clicked OK, so merge modified state back into base dialog
  1670. _IsDirty(pfEnableApply);
  1671. // The user clicked Okay in the dialog so merge the dirty state from the
  1672. // advanced dialog into the base dialog.
  1673. int nIndex;
  1674. SYSTEMMETRICSALL state = {0};
  1675. state.dwChanged = m_dwChanged;
  1676. state.schemeData.version = SCHEME_VERSION;
  1677. state.schemeData.wDummy = 0;
  1678. state.schemeData.ncm.cbSize = sizeof(state.schemeData.ncm);
  1679. for (nIndex = 0; nIndex < ARRAYSIZE(m_rgb); nIndex++)
  1680. {
  1681. state.schemeData.rgb[nIndex] = m_rgb[nIndex];
  1682. }
  1683. _GetMyNonClientMetrics(&state.schemeData.ncm);
  1684. // Set Sizes
  1685. state.nDXIcon = m_sizes[SIZE_DXICON].CurSize;
  1686. state.nDYIcon = m_sizes[SIZE_DYICON].CurSize;
  1687. state.nIcon = m_sizes[SIZE_ICON].CurSize;
  1688. state.nSmallIcon = m_sizes[SIZE_SMICON].CurSize;
  1689. state.fModifiedScheme = m_fModifiedScheme;
  1690. // Set Fonts
  1691. state.schemeData.lfIconTitle = m_fonts[FONT_ICONTITLE].lf;
  1692. VARIANT var = {0};
  1693. hr = pBasePage->Read(SZ_PBPROP_SYSTEM_METRICS, &var, NULL);
  1694. if (SUCCEEDED(hr) && (VT_BYREF == var.vt) && var.byref)
  1695. {
  1696. SYSTEMMETRICSALL * pCurrent = (SYSTEMMETRICSALL *) var.byref;
  1697. state.fFlatMenus = pCurrent->fFlatMenus; // Maintain this value.
  1698. state.fHighContrast = pCurrent->fHighContrast; // Maintain this value.
  1699. }
  1700. hr = SHPropertyBag_WriteByRef(pBasePage, SZ_PBPROP_SYSTEM_METRICS, (void *)&state);
  1701. }
  1702. ATOMICRELEASE(g_pAdvAppearancePage);
  1703. }
  1704. return hr;
  1705. }
  1706. //===========================
  1707. // *** IUnknown Interface ***
  1708. //===========================
  1709. ULONG CAdvAppearancePage::AddRef()
  1710. {
  1711. return InterlockedIncrement(&m_cRef);
  1712. }
  1713. ULONG CAdvAppearancePage::Release()
  1714. {
  1715. if (InterlockedDecrement(&m_cRef))
  1716. return m_cRef;
  1717. delete this;
  1718. return 0;
  1719. }
  1720. HRESULT CAdvAppearancePage::QueryInterface(REFIID riid, void **ppvObj)
  1721. {
  1722. static const QITAB qit[] = {
  1723. QITABENT(CAdvAppearancePage, IPersist),
  1724. QITABENT(CAdvAppearancePage, IObjectWithSite),
  1725. QITABENT(CAdvAppearancePage, IAdvancedDialog),
  1726. { 0 },
  1727. };
  1728. return QISearch(this, qit, riid, ppvObj);
  1729. }
  1730. int g_nSizeInitArray[9][3] =
  1731. {
  1732. {0, 0, 50}, // SIZE_FRAME
  1733. {0, 8, 100}, // SIZE_SCROLL
  1734. {0, 8, 100}, // SIZE_CAPTION
  1735. {0, 4, 100}, // SIZE_SMCAPTION
  1736. {0, 8, 100}, // SIZE_MENU
  1737. {0, 0, 150}, // SIZE_DXICON - x spacing
  1738. {0, 0, 150}, // SIZE_DYICON - y spacing
  1739. {0, 16, 72}, // SIZE_ICON - shell icon size
  1740. {0, 8, 36},
  1741. };
  1742. //===========================
  1743. // *** Class Methods ***
  1744. //===========================
  1745. CAdvAppearancePage::CAdvAppearancePage(IN const SYSTEMMETRICSALL * pState) : CObjectCLSID(&PPID_AdvAppearance), m_cRef(1)
  1746. {
  1747. int nIndex;
  1748. DllAddRef();
  1749. // This needs to be allocated in Zero Inited Memory.
  1750. // Assert that all Member Variables are inited to Zero.
  1751. ASSERT(!m_hpal3D);
  1752. ASSERT(!m_hpalVGA);
  1753. ASSERT(!m_hbrMainColor);
  1754. ASSERT(!m_hbrTextColor);
  1755. ASSERT(!m_hbrGradientColor);
  1756. m_dwChanged = NO_CHANGE;
  1757. m_iCurElement = CURRENT_ELEMENT_NONE; // start off as not even "not set"
  1758. m_iPrevSize = SIZE_NONE;
  1759. m_bPalette = FALSE;
  1760. m_fInUserEditMode = FALSE;
  1761. m_fProprtySheetExiting = FALSE;
  1762. m_i3DShadowAdj = -333;
  1763. m_i3DHilightAdj = 500;
  1764. m_iWatermarkAdj = -50;
  1765. m_fScale3DShadowAdj = TRUE;
  1766. m_fScale3DHilightAdj = TRUE;
  1767. m_fScaleWatermarkAdj = TRUE;
  1768. m_hTheme = NULL;
  1769. m_iCountCharsets = 0;
  1770. for (nIndex = 0; nIndex < ARRAYSIZE(m_uiUniqueCharsets); nIndex++)
  1771. {
  1772. m_uiUniqueCharsets[nIndex] = DEFAULT_CHARSET;
  1773. }
  1774. for (int nIndex1 = 0; nIndex1 < ARRAYSIZE(g_nSizeInitArray); nIndex1++)
  1775. {
  1776. m_sizes[nIndex1].CurSize = g_nSizeInitArray[nIndex1][0];
  1777. m_sizes[nIndex1].MinSize = g_nSizeInitArray[nIndex1][1];
  1778. m_sizes[nIndex1].MaxSize = g_nSizeInitArray[nIndex1][2];
  1779. }
  1780. CreateGlobals();
  1781. _LoadState(pState);
  1782. }
  1783. CAdvAppearancePage::~CAdvAppearancePage()
  1784. {
  1785. if (m_hpal3D)
  1786. {
  1787. DeleteObject(m_hpal3D);
  1788. m_hpal3D = NULL;
  1789. }
  1790. if (m_hpalVGA)
  1791. {
  1792. DeleteObject(m_hpalVGA);
  1793. m_hpalVGA = NULL;
  1794. }
  1795. if (g_hdcMem)
  1796. {
  1797. DeleteDC(g_hdcMem);
  1798. g_hdcMem = NULL;
  1799. }
  1800. DllRelease();
  1801. }
  1802. HRESULT CAdvAppearancePage_CreateInstance(OUT IAdvancedDialog ** ppAdvDialog, IN const SYSTEMMETRICSALL * pState)
  1803. {
  1804. HRESULT hr = E_INVALIDARG;
  1805. if (ppAdvDialog)
  1806. {
  1807. CAdvAppearancePage * ptsp = new CAdvAppearancePage(pState);
  1808. if (ptsp)
  1809. {
  1810. hr = ptsp->QueryInterface(IID_PPV_ARG(IAdvancedDialog, ppAdvDialog));
  1811. ptsp->Release();
  1812. }
  1813. else
  1814. {
  1815. *ppAdvDialog = NULL;
  1816. hr = E_OUTOFMEMORY;
  1817. }
  1818. }
  1819. return hr;
  1820. }