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.

1491 lines
44 KiB

  1. /*****************************************************************************\
  2. FILE: EffectsAdvPg.cpp
  3. DESCRIPTION:
  4. This code will display the Effect tab in the Advanced Display Control
  5. panel.
  6. BryanSt 4/13/2000 Updated and Converted to C++
  7. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  8. \*****************************************************************************/
  9. #include "precomp.hxx"
  10. #pragma hdrstop
  11. #include "EffectsAdvPg.h"
  12. typedef struct
  13. {
  14. DWORD dwControlID;
  15. DWORD dwHelpContextID;
  16. }POPUP_HELP_ARRAY;
  17. POPUP_HELP_ARRAY phaMainDisplay[] = {
  18. { (DWORD)IDC_ICONS, (DWORD)IDH_DISPLAY_EFFECTS_DESKTOP_ICONS },
  19. { (DWORD)IDC_CHANGEICON, (DWORD)IDH_DISPLAY_EFFECTS_CHANGE_ICON_BUTTON },
  20. { (DWORD)IDC_LARGEICONS, (DWORD)IDH_DISPLAY_EFFECTS_LARGE_ICONS_CHECKBOX },
  21. { (DWORD)IDC_ICONHIGHCOLOR, (DWORD)IDH_DISPLAY_EFFECTS_ALL_COLORS_CHECKBOX },
  22. { (DWORD)IDC_ICONDEFAULT, (DWORD)IDH_DISPLAY_EFFECTS_DEFAULT_ICON_BUTTON },
  23. { (DWORD)IDC_MENUANIMATION, (DWORD)IDH_DISPLAY_EFFECTS_ANIMATE_WINDOWS },
  24. { (DWORD)IDC_FONTSMOOTH, (DWORD)IDH_DISPLAY_EFFECTS_SMOOTH_FONTS_CHECKBOX },
  25. { (DWORD)IDC_SHOWDRAG, (DWORD)IDH_DISPLAY_EFFECTS_DRAG_WINDOW_CHECKBOX },
  26. { (DWORD)IDC_KEYBOARDINDICATORS, (DWORD)IDH_DISPLAY_EFFECTS_HIDE_KEYBOARD_INDICATORS },
  27. { (DWORD)IDC_GRPBOX_1, (DWORD)IDH_COMM_GROUPBOX },
  28. { (DWORD)IDC_GRPBOX_2, (DWORD)IDH_COMM_GROUPBOX },
  29. { (DWORD)IDC_COMBOEFFECT, (DWORD)IDH_DISPLAY_EFFECTS_ANIMATE_LISTBOX },
  30. { (DWORD)IDC_COMBOFSMOOTH, (DWORD)IDH_DISPLAY_EFFECTS_SMOOTH_FONTS_LISTBOX },
  31. { (DWORD)0, (DWORD)0 },
  32. { (DWORD)0, (DWORD)0 }, // double-null terminator NECESSARY!
  33. };
  34. /* Not using this table for win9x after win2k backport -- jonburs
  35. POPUP_HELP_ARRAY phaMainWinPlus[] = {
  36. { (DWORD)IDC_ICONS, (DWORD)IDH_PLUS_PLUSPACK_LIST },
  37. { (DWORD)IDC_CHANGEICON, (DWORD)IDH_PLUS_PLUSPACK_CHANGEICON },
  38. { (DWORD)IDC_LARGEICONS, (DWORD)IDH_PLUS_PLUSPACK_LARGEICONS },
  39. { (DWORD)IDC_ICONHIGHCOLOR, (DWORD)IDH_PLUS_PLUSPACK_ALLCOLORS },
  40. { (DWORD)IDC_GRPBOX_1, (DWORD)IDH_COMM_GROUPBOX },
  41. { (DWORD)IDC_GRPBOX_2, (DWORD)IDH_COMM_GROUPBOX },
  42. { (DWORD)0, (DWORD)0 },
  43. { (DWORD)0, (DWORD)0 }, // double-null terminator NECESSARY!
  44. };
  45. */
  46. POPUP_HELP_ARRAY * g_phaHelp = NULL;
  47. TCHAR g_szHelpFile[32];
  48. BOOL g_fCoInitDone = FALSE; // track state of OLE CoInitialize()
  49. HWND g_hWndList; // handle to the list view window
  50. HIMAGELIST g_hIconList; // handles to image lists for large icons
  51. ULONG g_ulFontInformation, g_ulNewFontInformation;
  52. typedef struct tagDefIcons
  53. {
  54. int iIndex;
  55. UINT uPath;
  56. TCHAR szFile[16];
  57. }DEFICONS;
  58. DEFICONS sDefaultIcons[NUM_ICONS] =
  59. {
  60. { 0,PATH_WIN ,TEXT("\\EXPLORER.EXE")}, // "My Computer" default icon
  61. { 0,PATH_SYS ,TEXT("\\mydocs.dll")}, // "My Documents" default icon
  62. #ifdef INET_EXP_ICON
  63. { 0,PATH_IEXP,TEXT("\\iexplore.exe")}, // "Internet Explorer" default icon
  64. #endif
  65. {17,PATH_SYS, TEXT("\\shell32.dll")}, // "Net Neighbourhood" default icon
  66. {32,PATH_SYS, TEXT("\\shell32.dll")}, // "Trash full" default icon
  67. {31,PATH_SYS, TEXT("\\shell32.dll")}, // "Trash empty" default icon
  68. #ifdef DIRECTORY_ICON
  69. { 0,PATH_SYS, TEXT("\\dsfolder.dll")}, // "Directory" default icon
  70. #endif
  71. };
  72. //need to be L"..." since SHGetRestriction takes only LPCWSTR and this file is compiled as ANSI
  73. #define POLICY_KEY_EXPLORER L"Explorer"
  74. #define POLICY_VALUE_ANIMATION L"NoChangeAnimation"
  75. #define POLICY_VALUE_KEYBOARDNAV L"NoChangeKeyboardNavigationIndicators"
  76. #ifdef CLEARTYPECOMBO
  77. BOOL RegisterTextEdgeClass(void);
  78. INT_PTR CALLBACK TextEdgeDlgProc( HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam );
  79. BOOL DisplayFontSmoothingDetails(HWND hWnd, BOOL* pfFontSmoothing, DWORD *pdwSmoothingType);
  80. static void EnableDlgItem(HWND dlg, int idkid, BOOL val);
  81. void ShowTextRedraw(HWND hDlg);
  82. #endif // CLEARTYPECOMBO
  83. //===========================
  84. // *** Class Internals & Helpers ***
  85. //===========================
  86. STDAPI SHPropertyBag_WriteByRef(IN IPropertyBag * pPropertyPage, IN LPCWSTR pwzPropName, IN void * p)
  87. {
  88. HRESULT hr = E_INVALIDARG;
  89. if (pPropertyPage && pwzPropName && p)
  90. {
  91. VARIANT va;
  92. va.vt = VT_BYREF;
  93. va.byref = p;
  94. hr = pPropertyPage->Write(pwzPropName, &va);
  95. }
  96. return hr;
  97. }
  98. STDAPI SHPropertyBag_ReadByRef(IN IPropertyBag * pPropertyPage, IN LPCWSTR pwzPropName, IN void * p, IN SIZE_T cbSize)
  99. {
  100. HRESULT hr = E_INVALIDARG;
  101. if (pPropertyPage && pwzPropName && p)
  102. {
  103. VARIANT va;
  104. hr = pPropertyPage->Read(pwzPropName, &va, NULL);
  105. if (SUCCEEDED(hr))
  106. {
  107. if ((VT_BYREF == va.vt) && va.byref)
  108. {
  109. CopyMemory(p, va.byref, cbSize);
  110. }
  111. else
  112. {
  113. hr = E_FAIL;
  114. }
  115. }
  116. }
  117. return hr;
  118. }
  119. // ExtractPlusColorIcon
  120. //
  121. // Extract Icon from a file in proper Hi or Lo color for current system display
  122. //
  123. // from FrancisH on 6/22/95 with mods by TimBragg
  124. HRESULT ExtractPlusColorIcon( LPCTSTR szPath, int nIndex, HICON *phIcon,
  125. UINT uSizeLarge, UINT uSizeSmall)
  126. {
  127. IShellLink *psl;
  128. HRESULT hres;
  129. HICON hIcons[2]; // MUST! - provide for TWO return icons
  130. if (!g_fCoInitDone)
  131. {
  132. if (SUCCEEDED(CoInitialize(NULL)))
  133. g_fCoInitDone = TRUE;
  134. }
  135. *phIcon = NULL;
  136. if (SUCCEEDED(hres = CoCreateInstance(CLSID_ShellLink, NULL,
  137. CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl)))
  138. {
  139. if (SUCCEEDED(hres = psl->SetIconLocation(szPath, nIndex)))
  140. {
  141. IExtractIcon *pei;
  142. if (SUCCEEDED(hres = psl->QueryInterface(IID_IExtractIcon, (void**)&pei)))
  143. {
  144. if (SUCCEEDED(hres = pei->Extract(szPath, nIndex,
  145. &hIcons[0], &hIcons[1], (UINT)MAKEWPARAM((WORD)uSizeLarge,
  146. (WORD)uSizeSmall))))
  147. {
  148. *phIcon = hIcons[0]; // Return first icon to caller
  149. }
  150. pei->Release();
  151. }
  152. }
  153. psl->Release();
  154. }
  155. return hres;
  156. } // end ExtractPlusColorIcon()
  157. BOOL FadeEffectAvailable()
  158. {
  159. BOOL fFade = FALSE, fTestFade = FALSE;
  160. SystemParametersInfo( SPI_GETMENUFADE, 0, (PVOID)&fFade, 0 );
  161. if (fFade)
  162. return TRUE;
  163. SystemParametersInfo( SPI_SETMENUFADE, 0, (PVOID)1, 0);
  164. SystemParametersInfo( SPI_GETMENUFADE, 0, (PVOID)&fTestFade, 0 );
  165. SystemParametersInfo( SPI_SETMENUFADE, 0, IntToPtr(fFade), 0);
  166. return (fTestFade);
  167. }
  168. HRESULT CEffectsPage::_OnApply(HWND hDlg)
  169. {
  170. HRESULT hr = S_OK;
  171. // Full Color Icons
  172. if (m_pEffectsState && (m_pEffectsState->_nOldHighIconColor != m_pEffectsState->_nHighIconColor))
  173. {
  174. if ((GetBitsPerPixel() < 16) && (m_pEffectsState->_nHighIconColor == 16)) // Display mode won't support icon high colors
  175. {
  176. TCHAR szTemp1[512];
  177. TCHAR szTemp2[256];
  178. LoadString(g_hInst, IDS_256COLORPROBLEM, szTemp1, ARRAYSIZE(szTemp1));
  179. LoadString(g_hInst, IDS_ICONCOLORWONTWORK, szTemp2, ARRAYSIZE(szTemp2));
  180. StrCatBuff(szTemp1, szTemp2, ARRAYSIZE(szTemp1));
  181. LoadString(g_hInst, IDS_EFFECTS, szTemp2, ARRAYSIZE(szTemp2));
  182. MessageBox(hDlg, szTemp1, szTemp2, MB_OK|MB_ICONINFORMATION);
  183. }
  184. }
  185. return hr;
  186. }
  187. HRESULT CEffectsPage::_OnInit(HWND hDlg)
  188. {
  189. HRESULT hr = S_OK;
  190. TCHAR szRes[100];
  191. if (!m_pEffectsState)
  192. {
  193. return E_INVALIDARG;
  194. }
  195. //////////////////////////////////////////////////////////////////////////
  196. // Load the state from persisted form (registry) to the state struct
  197. //////////////////////////////////////////////////////////////////////////
  198. m_nIndex = 0;
  199. g_bMirroredOS = IS_MIRRORING_ENABLED();
  200. // Create our list view and fill it with the system icons
  201. _CreateListView(hDlg);
  202. // Get the name of our help file. For Memphis, it's
  203. // IDS_HELPFILE_PLUS for NT it's IDS_HELPFILE.
  204. // g_phaHelp = phaMainWinPlus;
  205. // Running Win2k shellport, want Win2k helpfile and resources
  206. g_phaHelp = phaMainDisplay;
  207. LoadString(g_hInst, IDS_HELPFILE, g_szHelpFile, 32);
  208. //////////////////////////////////////////////////////////////////////////
  209. // Update UI based on the state struct
  210. //////////////////////////////////////////////////////////////////////////
  211. if (m_pEffectsState->_nLargeIcon == ICON_INDETERMINATE)
  212. {
  213. HWND hItem = GetDlgItem(hDlg, IDC_LARGEICONS);
  214. SendMessage(hItem, BM_SETSTYLE, (WPARAM)LOWORD(BS_AUTO3STATE), MAKELPARAM(FALSE,0));
  215. }
  216. // Set CheckBoxes
  217. SendMessage((HWND)GetDlgItem(hDlg, IDC_LARGEICONS), BM_SETCHECK, (WPARAM)m_pEffectsState->_nLargeIcon, 0);
  218. SendMessage((HWND)GetDlgItem(hDlg, IDC_MENUSHADOWS), BM_SETCHECK, (WPARAM)m_pEffectsState->_fMenuShadows, 0);
  219. SendMessage((HWND)GetDlgItem(hDlg, IDC_ICONHIGHCOLOR ), BM_SETCHECK, (WPARAM)(BOOL)(m_pEffectsState->_nHighIconColor == 16), 0);
  220. SendMessage((HWND)GetDlgItem(hDlg, IDC_MENUANIMATION), BM_SETCHECK, (WPARAM)m_pEffectsState->_wpMenuAnimation, 0);
  221. SendMessage((HWND)GetDlgItem(hDlg, IDC_FONTSMOOTH), BM_SETCHECK, (WPARAM)m_pEffectsState->_fFontSmoothing, 0);
  222. SendMessage((HWND)GetDlgItem(hDlg, IDC_SHOWDRAG), BM_SETCHECK, (WPARAM)m_pEffectsState->_fDragWindow, 0);
  223. SendMessage((HWND)GetDlgItem(hDlg, IDC_KEYBOARDINDICATORS), BM_SETCHECK, (WPARAM)(m_pEffectsState->_fKeyboardIndicators ? BST_UNCHECKED : BST_CHECKED), 0);
  224. // Set Effects Drop Down
  225. HWND hwndCombo = GetDlgItem(hDlg,IDC_COMBOEFFECT);
  226. ComboBox_ResetContent(hwndCombo);
  227. LoadString(g_hInst, IDS_FADEEFFECT, szRes, ARRAYSIZE(szRes) );
  228. ComboBox_AddString(hwndCombo, szRes);
  229. LoadString(g_hInst, IDS_SCROLLEFFECT, szRes, ARRAYSIZE(szRes) );
  230. ComboBox_AddString(hwndCombo, szRes);
  231. ComboBox_SetCurSel(hwndCombo, (MENU_EFFECT_FADE == m_pEffectsState->_dwAnimationEffect) ? 0 : 1);
  232. EnableWindow(hwndCombo, (UINT)m_pEffectsState->_wpMenuAnimation);
  233. if (!FadeEffectAvailable())
  234. {
  235. ShowWindow(GetDlgItem(hDlg, IDC_COMBOEFFECT), SW_HIDE);
  236. }
  237. if (0 != SHGetRestriction(NULL,POLICY_KEY_EXPLORER,POLICY_VALUE_ANIMATION))
  238. {
  239. //disable
  240. //0= enable
  241. //non-0= disable
  242. //relies on the fact that if the key does not exist it returns 0 as well
  243. EnableWindow((HWND)GetDlgItem(hDlg, IDC_MENUANIMATION), FALSE);
  244. EnableWindow((HWND)GetDlgItem(hDlg, IDC_COMBOEFFECT), FALSE);
  245. }
  246. hwndCombo = GetDlgItem(hDlg,IDC_COMBOFSMOOTH);
  247. #ifdef CLEARTYPECOMBO
  248. ComboBox_ResetContent(hwndCombo);
  249. LoadString(g_hInst, IDS_STANDARDSMOOTHING, szRes, ARRAYSIZE(szRes));
  250. ComboBox_AddString(hwndCombo, szRes);
  251. LoadString(g_hInst, IDS_CLEARTYPE, szRes, ARRAYSIZE(szRes));
  252. ComboBox_AddString(hwndCombo, szRes);
  253. BOOL fTemp;
  254. ComboBox_SetCurSel(hwndCombo, m_pEffectsState->_dwFontSmoothingType-1);
  255. if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, (PVOID)&fTemp, 0))
  256. {
  257. EnableWindow((HWND)hwndCombo, m_pEffectsState->_fFontSmoothing);
  258. }
  259. else
  260. {
  261. ShowWindow(hwndCombo, SW_HIDE);
  262. ShowWindow(GetDlgItem(hDlg, IDC_SHOWME), SW_HIDE);
  263. }
  264. #else
  265. ShowWindow(hwndCombo, SW_HIDE);
  266. ShowWindow(GetDlgItem(hDlg, IDC_SHOWME), SW_HIDE);
  267. #endif //CLEARTYPECOMBO
  268. if (0 != SHGetRestriction(NULL,POLICY_KEY_EXPLORER,POLICY_VALUE_KEYBOARDNAV))
  269. {
  270. //disable, see comment for animation
  271. EnableWindow((HWND)GetDlgItem(hDlg, IDC_KEYBOARDINDICATORS), FALSE);
  272. }
  273. //disable and uncheck things if we are on terminal server
  274. BOOL bEffectsEnabled;
  275. if (!SystemParametersInfo(SPI_GETUIEFFECTS, 0, (PVOID) &bEffectsEnabled, 0))
  276. {
  277. // This flag is only available on Win2k and later. We're depending
  278. // on the call returning false if the flag doesn't exist...
  279. bEffectsEnabled = TRUE;
  280. }
  281. if (!bEffectsEnabled || SHGetMachineInfo(GMI_TSCLIENT))
  282. {
  283. EnableWindow((HWND)GetDlgItem( hDlg, IDC_MENUANIMATION), FALSE);
  284. EnableWindow((HWND)GetDlgItem(hDlg, IDC_ICONHIGHCOLOR), FALSE);
  285. EnableWindow((HWND)GetDlgItem(hDlg, IDC_KEYBOARDINDICATORS), FALSE);
  286. EnableWindow((HWND)GetDlgItem(hDlg, IDC_FONTSMOOTH), FALSE);
  287. ShowWindow(GetDlgItem( hDlg, IDC_COMBOEFFECT ), SW_HIDE);
  288. SendDlgItemMessage(hDlg, IDC_MENUANIMATION, BM_SETCHECK, 0, 0);
  289. SendDlgItemMessage(hDlg, IDC_ICONHIGHCOLOR, BM_SETCHECK, 0, 0);
  290. SendDlgItemMessage(hDlg, IDC_KEYBOARDINDICATORS, BM_SETCHECK, 0, 0);
  291. SendDlgItemMessage(hDlg, IDC_FONTSMOOTH, BM_SETCHECK, 0, 0);
  292. }
  293. // We remove the Keyboard indicators check box on non-NT platform since User32
  294. // does not provide the functionality to implement the feature.
  295. if (!g_RunningOnNT)
  296. {
  297. HWND hwndSWC = GetDlgItem(hDlg, IDC_SHOWDRAG);
  298. HWND hwndKI = GetDlgItem(hDlg, IDC_KEYBOARDINDICATORS);
  299. HWND hwndGroup = GetDlgItem(hDlg, IDC_GRPBOX_2);
  300. // Hide the Hide keyboard cues check box on non-NT platform
  301. ShowWindow(hwndKI, SW_HIDE);
  302. // Calculate the bottom margin
  303. RECT rect;
  304. RECT rectGroup;
  305. GetWindowRect(hwndKI, &rect);
  306. GetWindowRect(hwndGroup, &rectGroup);
  307. int margin = rectGroup.bottom - rect.bottom;
  308. GetWindowRect(hwndSWC, &rect);
  309. SetWindowPos(hwndGroup, HWND_TOP, 0, 0, rectGroup.right - rectGroup.left,
  310. rect.bottom - rectGroup.top + margin, SWP_NOMOVE | SWP_NOZORDER);
  311. }
  312. return hr;
  313. }
  314. HRESULT CEffectsPage::_OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  315. {
  316. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  317. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  318. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  319. BOOL bDorked = FALSE;
  320. switch (idCtrl)
  321. {
  322. case IDOK:
  323. EndDialog(hDlg, IDOK);
  324. break;
  325. case IDCANCEL:
  326. EndDialog(hDlg, IDCANCEL);
  327. break;
  328. case IDC_LARGEICONS:
  329. if (m_pEffectsState)
  330. {
  331. m_pEffectsState->_nLargeIcon = (int)SendMessage ( (HWND)lParam, BM_GETCHECK, 0, 0 );
  332. bDorked = TRUE;
  333. }
  334. break;
  335. case IDC_MENUSHADOWS:
  336. if (m_pEffectsState)
  337. {
  338. m_pEffectsState->_fMenuShadows = (int)SendMessage ( (HWND)lParam, BM_GETCHECK, 0, 0 );
  339. bDorked = TRUE;
  340. }
  341. break;
  342. case IDC_ICONHIGHCOLOR:
  343. if (m_pEffectsState)
  344. {
  345. m_pEffectsState->_nHighIconColor = 4;
  346. if (SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == TRUE)
  347. {
  348. m_pEffectsState->_nHighIconColor = 16;
  349. }
  350. bDorked = TRUE;
  351. }
  352. break;
  353. case IDC_SHOWDRAG:
  354. if (m_pEffectsState)
  355. {
  356. m_pEffectsState->_fDragWindow = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  357. bDorked = TRUE;
  358. }
  359. break;
  360. case IDC_MENUANIMATION:
  361. if (m_pEffectsState)
  362. {
  363. switch (m_pEffectsState->_wpMenuAnimation)
  364. {
  365. case BST_UNCHECKED:
  366. m_pEffectsState->_wpMenuAnimation = BST_CHECKED;
  367. break;
  368. case BST_CHECKED:
  369. m_pEffectsState->_wpMenuAnimation = BST_UNCHECKED;
  370. break;
  371. case BST_INDETERMINATE:
  372. m_pEffectsState->_wpMenuAnimation = BST_UNCHECKED;
  373. break;
  374. }
  375. SendMessage( (HWND)lParam, BM_SETCHECK, (WPARAM)m_pEffectsState->_wpMenuAnimation, 0 );
  376. EnableWindow((HWND)GetDlgItem( hDlg, IDC_COMBOEFFECT), (BST_CHECKED == m_pEffectsState->_wpMenuAnimation));
  377. bDorked = TRUE;
  378. }
  379. break;
  380. case IDC_COMBOEFFECT:
  381. if ((wEvent == CBN_SELCHANGE) && m_pEffectsState)
  382. {
  383. m_pEffectsState->_dwAnimationEffect = (DWORD)ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBOEFFECT)) + 1;
  384. bDorked = TRUE;
  385. }
  386. break;
  387. #ifdef CLEARTYPECOMBO
  388. case IDC_COMBOFSMOOTH:
  389. if ((wEvent == CBN_SELCHANGE) && m_pEffectsState)
  390. {
  391. m_pEffectsState->_dwFontSmoothingType = (DWORD)ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBOFSMOOTH)) + 1;
  392. bDorked = TRUE;
  393. }
  394. break;
  395. #endif
  396. case IDC_FONTSMOOTH:
  397. if (m_pEffectsState)
  398. {
  399. m_pEffectsState->_fFontSmoothing = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  400. #ifdef CLEARTYPECOMBO
  401. EnableWindow((HWND)GetDlgItem( hDlg, IDC_COMBOFSMOOTH), m_pEffectsState->_fFontSmoothing);
  402. if (m_pEffectsState->_fFontSmoothing)
  403. m_pEffectsState->_dwFontSmoothingType = ((DWORD)ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBOFSMOOTH)) + 1);
  404. #endif
  405. bDorked = TRUE;
  406. }
  407. break;
  408. case IDC_CHANGEICON:
  409. if (m_pEffectsState)
  410. {
  411. INT i = m_pEffectsState->_IconData[m_nIndex].iOldIndex;
  412. WCHAR szTemp[ MAX_PATH ];
  413. TCHAR szExp[ MAX_PATH ];
  414. ExpandEnvironmentStrings(m_pEffectsState->_IconData[m_nIndex].szOldFile, szExp, ARRAYSIZE(szExp));
  415. if (g_RunningOnNT)
  416. {
  417. SHTCharToUnicode(szExp, szTemp, ARRAYSIZE(szTemp));
  418. }
  419. else
  420. {
  421. SHTCharToAnsi(szExp, (LPSTR)szTemp, ARRAYSIZE(szTemp));
  422. }
  423. if (PickIconDlg(hDlg, (LPTSTR)szTemp, ARRAYSIZE(szTemp), &i) == TRUE)
  424. {
  425. HICON hIcon;
  426. if (g_RunningOnNT)
  427. {
  428. SHUnicodeToTChar(szTemp, m_pEffectsState->_IconData[m_nIndex].szNewFile, ARRAYSIZE(m_pEffectsState->_IconData[m_nIndex].szNewFile));
  429. }
  430. else
  431. {
  432. SHAnsiToTChar((LPSTR)szTemp, m_pEffectsState->_IconData[m_nIndex].szNewFile, ARRAYSIZE(m_pEffectsState->_IconData[m_nIndex].szNewFile));
  433. }
  434. m_pEffectsState->_IconData[m_nIndex].iNewIndex = i;
  435. ExtractPlusColorIcon(m_pEffectsState->_IconData[m_nIndex].szNewFile, m_pEffectsState->_IconData[m_nIndex].iNewIndex, &hIcon, 0, 0);
  436. ImageList_ReplaceIcon(g_hIconList, m_nIndex, hIcon);
  437. ListView_RedrawItems(g_hWndList, m_nIndex, m_nIndex);
  438. bDorked = TRUE;
  439. }
  440. SetFocus(g_hWndList);
  441. }
  442. break;
  443. case IDC_ICONDEFAULT:
  444. {
  445. TCHAR szTemp[_MAX_PATH];
  446. HICON hIcon;
  447. switch( sDefaultIcons[m_nIndex].uPath )
  448. {
  449. case PATH_WIN:
  450. GetWindowsDirectory( szTemp, ARRAYSIZE(szTemp) );
  451. break;
  452. #ifdef INET_EXP_ICON
  453. case PATH_IEXP:
  454. if (g_RunningOnNT)
  455. {
  456. StrCpyN(szTemp, TEXT("%SystemDrive%"), ARRAYSIZE(szTemp));
  457. }
  458. else
  459. {
  460. GetWindowsDirectory( szTemp, ARRAYSIZE(szTemp) );
  461. // Clear out path after drive, ie: C:
  462. szTemp[ 2 ] = 0;
  463. }
  464. StrCatBuff(szTemp, c_szIEXP, ARRAYSIZE(szTemp));
  465. break;
  466. #endif
  467. case PATH_SYS:
  468. default:
  469. GetSystemDirectory( szTemp, ARRAYSIZE(szTemp) );
  470. break;
  471. }
  472. if (m_pEffectsState)
  473. {
  474. StrCatBuff(szTemp, sDefaultIcons[m_nIndex].szFile, ARRAYSIZE(szTemp));
  475. StrCpyN(m_pEffectsState->_IconData[m_nIndex].szNewFile, szTemp, ARRAYSIZE(m_pEffectsState->_IconData[m_nIndex].szNewFile));
  476. m_pEffectsState->_IconData[m_nIndex].iNewIndex = sDefaultIcons[m_nIndex].iIndex;
  477. ExtractPlusColorIcon(m_pEffectsState->_IconData[m_nIndex].szNewFile, m_pEffectsState->_IconData[m_nIndex].iNewIndex, &hIcon, 0, 0);
  478. ImageList_ReplaceIcon(g_hIconList, m_nIndex, hIcon);
  479. ListView_RedrawItems(g_hWndList, m_nIndex, m_nIndex);
  480. bDorked = TRUE;
  481. SetFocus(g_hWndList);
  482. }
  483. }
  484. break;
  485. case IDC_KEYBOARDINDICATORS:
  486. if (m_pEffectsState)
  487. {
  488. m_pEffectsState->_fKeyboardIndicators = ((SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED) ? FALSE : TRUE);
  489. bDorked = TRUE;
  490. }
  491. break;
  492. default:
  493. break;
  494. }
  495. // If the user dorked with a setting, tell the property manager we
  496. // have outstanding changes. This will enable the "Apply Now" button...
  497. if (bDorked)
  498. {
  499. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  500. }
  501. return fHandled;
  502. }
  503. INT_PTR CALLBACK PropertySheetDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  504. {
  505. CEffectsPage * pThis = (CEffectsPage *)GetWindowLongPtr(hDlg, DWLP_USER);
  506. if (WM_INITDIALOG == wMsg)
  507. {
  508. pThis = (CEffectsPage *) lParam;
  509. if (pThis)
  510. {
  511. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  512. }
  513. }
  514. if (pThis)
  515. return pThis->_PropertySheetDlgProc(hDlg, wMsg, wParam, lParam);
  516. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  517. }
  518. //---------------------------------------------------------------------------
  519. //
  520. // PropertySheetDlgProc()
  521. //
  522. // The dialog procedure for the "PlusPack" property sheet page.
  523. //
  524. //---------------------------------------------------------------------------
  525. INT_PTR CEffectsPage::_PropertySheetDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  526. {
  527. BOOL bDorked = FALSE;
  528. switch( uMessage )
  529. {
  530. case WM_INITDIALOG:
  531. _OnInit(hDlg);
  532. break;
  533. case WM_DESTROY:
  534. if (g_fCoInitDone)
  535. {
  536. CoUninitialize();
  537. g_fCoInitDone = FALSE;
  538. }
  539. if (g_hmodShell32)
  540. {
  541. FreeLibrary(g_hmodShell32);
  542. g_hmodShell32 = NULL;
  543. }
  544. break;
  545. case WM_COMMAND:
  546. _OnCommand(hDlg, uMessage, wParam, lParam);
  547. break;
  548. case WM_NOTIFY:
  549. switch( ((NMHDR *)lParam)->code )
  550. {
  551. #ifdef CLEARTYPECOMBO
  552. case NM_CLICK:
  553. switch (wParam)
  554. {
  555. case IDC_SHOWME:
  556. if (m_pEffectsState)
  557. {
  558. DWORD dwSmoothingType = m_pEffectsState->_dwFontSmoothingType;
  559. BOOL fFontSmoothing = m_pEffectsState->_fFontSmoothing;
  560. if (DisplayFontSmoothingDetails(hDlg, &fFontSmoothing, &dwSmoothingType) &&
  561. ((m_pEffectsState->_dwFontSmoothingType != dwSmoothingType)
  562. || (m_pEffectsState->_fFontSmoothing != fFontSmoothing)))
  563. {
  564. m_pEffectsState->_dwFontSmoothingType = dwSmoothingType;
  565. m_pEffectsState->_fFontSmoothing = fFontSmoothing;
  566. bDorked = TRUE;
  567. SendMessage( GetParent( hDlg ), PSM_CHANGED, (WPARAM)hDlg, 0L );
  568. ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_COMBOFSMOOTH), dwSmoothingType - 1);
  569. if (fFontSmoothing)
  570. {
  571. EnableWindow(GetDlgItem(hDlg,IDC_COMBOFSMOOTH), TRUE);
  572. }
  573. else
  574. {
  575. EnableWindow(GetDlgItem(hDlg,IDC_COMBOFSMOOTH), FALSE);
  576. }
  577. SendMessage( (HWND)GetDlgItem( hDlg, IDC_FONTSMOOTH ),
  578. BM_SETCHECK,
  579. (WPARAM) fFontSmoothing,
  580. 0
  581. );
  582. }
  583. }
  584. break;
  585. }
  586. break;
  587. #endif
  588. case LVN_ITEMCHANGED: // The selection changed in our listview
  589. if( wParam == IDC_ICONS )
  590. {
  591. // Find out who's selected now
  592. for( m_nIndex = 0; m_nIndex < NUM_ICONS;m_nIndex++ )
  593. {
  594. if( ListView_GetItemState(g_hWndList, m_nIndex, LVIS_SELECTED))
  595. {
  596. break;
  597. }
  598. }
  599. }
  600. break;
  601. default:
  602. break;
  603. }
  604. break;
  605. case WM_HELP:
  606. {
  607. LPHELPINFO lphi = (LPHELPINFO)lParam;
  608. if( lphi->iContextType == HELPINFO_WINDOW )
  609. {
  610. WinHelp( (HWND)lphi->hItemHandle, (LPTSTR)g_szHelpFile,
  611. HELP_WM_HELP, (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)g_phaHelp));
  612. }
  613. }
  614. break;
  615. case WM_CONTEXTMENU:
  616. // first check for dlg window
  617. if( (HWND)wParam == hDlg )
  618. {
  619. // let the def dlg proc decide whether to respond or ignore;
  620. // necessary for title bar sys menu on right click
  621. return FALSE; // didn't process message EXIT
  622. }
  623. else
  624. {
  625. // else go for the controls
  626. WinHelp( (HWND)wParam, (LPTSTR)g_szHelpFile,
  627. HELP_CONTEXTMENU, (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)g_phaHelp));
  628. }
  629. break;
  630. default:
  631. return FALSE;
  632. }
  633. return(TRUE);
  634. }
  635. /****************************************************************************
  636. *
  637. * FUNCTION: CreateListView(HWND)
  638. *
  639. * PURPOSE: Creates the list view window and initializes it
  640. *
  641. ****************************************************************************/
  642. HWND CEffectsPage::_CreateListView(HWND hWndParent)
  643. {
  644. LV_ITEM lvI; // List view item structure
  645. TCHAR szTemp[MAX_PATH];
  646. BOOL bEnable = FALSE;
  647. #ifdef JIGGLE_FIX
  648. RECT rc;
  649. #endif
  650. UINT flags = ILC_MASK | ILC_COLOR24;
  651. // Create a device independant size and location
  652. LONG lWndunits = GetDialogBaseUnits();
  653. int iWndx = LOWORD(lWndunits);
  654. int iWndy = HIWORD(lWndunits);
  655. int iX = ((11 * iWndx) / 4);
  656. int iY = ((15 * iWndy) / 8);
  657. int iWidth = ((163 * iWndx) / 4);
  658. int iHeight = ((40 * iWndy) / 8);
  659. // Ensure that the common control DLL is loaded.
  660. InitCommonControls();
  661. // Get the list view window
  662. g_hWndList = GetDlgItem(hWndParent, IDC_ICONS);
  663. if(g_hWndList == NULL)
  664. return NULL;
  665. if(IS_WINDOW_RTL_MIRRORED(hWndParent))
  666. {
  667. flags |= ILC_MIRROR;
  668. }
  669. // initialize the list view window
  670. // First, initialize the image lists we will need
  671. g_hIconList = ImageList_Create( 32, 32, flags, NUM_ICONS, 0 ); // create an image list for the icons
  672. // load the icons and add them to the image lists
  673. // get the icon files and indexes from the registry, including for the Default recycle bin
  674. for (iX = 0; iX < ARRAYSIZE(m_pEffectsState->_IconData); iX++)
  675. {
  676. HICON hIcon;
  677. ExtractPlusColorIcon(m_pEffectsState->_IconData[iX].szNewFile, m_pEffectsState->_IconData[iX].iNewIndex, &hIcon, 0, 0);
  678. // Added this "if" to fix bug 2831. We want to use SHELL32.DLL
  679. // icon 0 if there is no icon in the file specified in the
  680. // registry (or if the registry didn't specify a file).
  681. if(hIcon == NULL)
  682. {
  683. GetSystemDirectory(szTemp, ARRAYSIZE(szTemp));
  684. PathAppend(szTemp, TEXT("shell32.dll"));
  685. StrCpyN(m_pEffectsState->_IconData[iX].szOldFile, szTemp, ARRAYSIZE(m_pEffectsState->_IconData[iX].szNewFile));
  686. StrCpyN(m_pEffectsState->_IconData[iX].szNewFile, szTemp, ARRAYSIZE(m_pEffectsState->_IconData[iX].szNewFile));
  687. m_pEffectsState->_IconData[iX].iOldIndex = m_pEffectsState->_IconData[iX].iNewIndex = 0;
  688. ExtractPlusColorIcon(szTemp, 0, &hIcon, 0, 0);
  689. }
  690. if (ImageList_AddIcon(g_hIconList, hIcon) == -1)
  691. {
  692. return NULL;
  693. }
  694. }
  695. // Make sure that all of the icons were added
  696. if( ImageList_GetImageCount(g_hIconList) < NUM_ICONS )
  697. return FALSE;
  698. ListView_SetImageList(g_hWndList, g_hIconList, LVSIL_NORMAL);
  699. // Make sure the listview has WS_HSCROLL set on it.
  700. DWORD dwStyle = GetWindowLong(g_hWndList, GWL_STYLE);
  701. SetWindowLong(g_hWndList, GWL_STYLE, (dwStyle & (~WS_VSCROLL)) | WS_HSCROLL);
  702. // Finally, let's add the actual items to the control. Fill in the LV_ITEM
  703. // structure for each of the items to add to the list. The mask specifies
  704. // the the .pszText, .iImage, and .state members of the LV_ITEM structure are valid.
  705. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
  706. lvI.state = 0;
  707. lvI.stateMask = 0;
  708. for( iX = 0; iX < NUM_ICONS; iX++ )
  709. {
  710. TCHAR szAppend[64];
  711. BOOL bRet;
  712. bRet = IconGetRegValueString(c_aIconRegKeys[iX].pclsid, NULL, NULL, szTemp, ARRAYSIZE(szTemp));
  713. // if the title string was in the registry, else we have to use the default in our resources
  714. if( (bRet) && (lstrlen(szTemp) > 0))
  715. {
  716. if( LoadString(g_hInst, c_aIconRegKeys[iX].iTitleResource, szAppend, 64) != 0)
  717. {
  718. StrCatBuff(szTemp, szAppend, ARRAYSIZE(szTemp));
  719. }
  720. }
  721. else
  722. {
  723. LoadString(g_hInst, c_aIconRegKeys[iX].iDefaultTitleResource, szTemp, ARRAYSIZE(szTemp));
  724. }
  725. lvI.iItem = iX;
  726. lvI.iSubItem = 0;
  727. lvI.pszText = szTemp;
  728. lvI.iImage = iX;
  729. if(ListView_InsertItem(g_hWndList, &lvI) == -1)
  730. return NULL;
  731. }
  732. #ifdef JIGGLE_FIX
  733. // To fix long standing listview bug, we need to "jiggle" the listview
  734. // window size so that it will do a recompute and realize that we need a
  735. // scroll bar...
  736. GetWindowRect(g_hWndList, &rc);
  737. MapWindowPoints( NULL, hWndParent, (LPPOINT)&rc, 2 );
  738. MoveWindow(g_hWndList, rc.left, rc.top, rc.right - rc.left+1, rc.bottom - rc.top, FALSE );
  739. MoveWindow(g_hWndList, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE );
  740. #endif
  741. // Set First item to selected
  742. ListView_SetItemState (g_hWndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  743. // Get Selected item
  744. for (m_nIndex = 0; m_nIndex < NUM_ICONS; m_nIndex++)
  745. {
  746. if (ListView_GetItemState(g_hWndList, m_nIndex, LVIS_SELECTED))
  747. {
  748. bEnable = TRUE;
  749. break;
  750. }
  751. }
  752. EnableWindow( GetDlgItem( hWndParent, IDC_CHANGEICON ), bEnable );
  753. EnableWindow( GetDlgItem( hWndParent, IDC_ICONDEFAULT ), bEnable );
  754. return g_hWndList;
  755. }
  756. HRESULT CEffectsPage::_IsDirty(IN BOOL * pIsDirty)
  757. {
  758. HRESULT hr = E_INVALIDARG;
  759. if (pIsDirty && m_pEffectsState)
  760. {
  761. // Ask state if it's dirty
  762. *pIsDirty = m_pEffectsState->IsDirty();
  763. hr = S_OK;
  764. }
  765. return hr;
  766. }
  767. //===========================
  768. // *** IAdvancedDialog Interface ***
  769. //===========================
  770. HRESULT CEffectsPage::DisplayAdvancedDialog(IN HWND hwndParent, IN IPropertyBag * pBasePage, IN BOOL * pfEnableApply)
  771. {
  772. HRESULT hr = E_INVALIDARG;
  773. if (hwndParent && pBasePage && pfEnableApply)
  774. {
  775. // Load State Into Advanced Dialog
  776. if (m_pEffectsState)
  777. {
  778. delete m_pEffectsState;
  779. m_pEffectsState = NULL;
  780. }
  781. *pfEnableApply = FALSE;
  782. CEffectState * pEffectClone;
  783. hr = SHPropertyBag_ReadByRef(pBasePage, SZ_PBPROP_EFFECTSSTATE, (void *)&pEffectClone, sizeof(pEffectClone));
  784. if (SUCCEEDED(hr))
  785. {
  786. // We want a copy of their state
  787. hr = pEffectClone->Clone(&m_pEffectsState);
  788. if (SUCCEEDED(hr))
  789. {
  790. LinkWindow_RegisterClass();
  791. // Display Advanced Dialog
  792. if (IDOK == DialogBoxParam(g_hInst, MAKEINTRESOURCE(PROP_SHEET_DLG), hwndParent, PropertySheetDlgProc, (LPARAM)this))
  793. {
  794. // The user clicked OK, so merge modified state back into base dialog
  795. _IsDirty(pfEnableApply);
  796. // The user clicked Okay in the dialog so merge the dirty state from the
  797. // advanced dialog into the base dialog.
  798. hr = SHPropertyBag_WriteByRef(pBasePage, SZ_PBPROP_EFFECTSSTATE, (void *)m_pEffectsState);
  799. m_pEffectsState = NULL;
  800. }
  801. }
  802. LinkWindow_UnregisterClass(g_hInst);
  803. }
  804. }
  805. return hr;
  806. }
  807. //===========================
  808. // *** IUnknown Interface ***
  809. //===========================
  810. ULONG CEffectsPage::AddRef()
  811. {
  812. m_cRef++;
  813. return m_cRef;
  814. }
  815. ULONG CEffectsPage::Release()
  816. {
  817. Assert(m_cRef > 0);
  818. m_cRef--;
  819. if (m_cRef > 0)
  820. return m_cRef;
  821. delete this;
  822. return 0;
  823. }
  824. HRESULT CEffectsPage::QueryInterface(REFIID riid, void **ppvObj)
  825. {
  826. HRESULT hr = E_NOINTERFACE;
  827. static const QITAB qit[] =
  828. {
  829. QITABENT(CEffectsPage, IObjectWithSite),
  830. QITABENT(CEffectsPage, IAdvancedDialog),
  831. { 0 },
  832. };
  833. return QISearch(this, qit, riid, ppvObj);
  834. }
  835. //===========================
  836. // *** Class Methods ***
  837. //===========================
  838. CEffectsPage::CEffectsPage() : m_cRef(1)
  839. {
  840. // This needs to be allocated in Zero Inited Memory.
  841. // Assert that all Member Variables are inited to Zero.
  842. m_fDirty = FALSE;
  843. }
  844. CEffectsPage::~CEffectsPage()
  845. {
  846. if (m_pEffectsState)
  847. {
  848. delete m_pEffectsState;
  849. }
  850. }
  851. HRESULT CEffectsPage_CreateInstance(OUT IAdvancedDialog ** ppAdvDialog)
  852. {
  853. HRESULT hr = E_INVALIDARG;
  854. if (ppAdvDialog)
  855. {
  856. CEffectsPage * pThis = new CEffectsPage();
  857. if (pThis)
  858. {
  859. hr = pThis->QueryInterface(IID_PPV_ARG(IAdvancedDialog, ppAdvDialog));
  860. pThis->Release();
  861. }
  862. else
  863. {
  864. *ppAdvDialog = NULL;
  865. hr = E_OUTOFMEMORY;
  866. }
  867. }
  868. return hr;
  869. }
  870. #ifdef CLEARTYPECOMBO
  871. static void EnableDlgChild( HWND dlg, HWND kid, BOOL val )
  872. {
  873. if( !val && ( kid == GetFocus() ) )
  874. {
  875. // give prev tabstop focus
  876. SendMessage( dlg, WM_NEXTDLGCTL, 1, 0L );
  877. }
  878. EnableWindow( kid, val );
  879. }
  880. static void EnableDlgItem( HWND dlg, int idkid, BOOL val )
  881. {
  882. EnableDlgChild( dlg, GetDlgItem( dlg, idkid ), val );
  883. }
  884. #define TEXTEDGE_CLASS TEXT("TextEdge")
  885. #define SZ_SAMPLETEXT TEXT("The quick brown fox jumps over the lazy dog")
  886. void ShowTextRedraw(HWND hDlg)
  887. {
  888. HWND hWnd;
  889. hWnd = GetDlgItem(hDlg, IDC_TEXTSAMPLE);
  890. InvalidateRgn (hWnd, NULL, TRUE);
  891. }
  892. // Handle to the DLL
  893. extern HINSTANCE g_hInst;
  894. void GetFontInfo(HWND hDlg)
  895. {
  896. BOOL bOldSF = FALSE;
  897. BOOL bOldCT = FALSE;
  898. CheckDlgButton(hDlg, IDC_MONOTEXT, FALSE);
  899. CheckDlgButton(hDlg, IDC_AATEXT, FALSE);
  900. CheckDlgButton(hDlg, IDC_CTTEXT, FALSE);
  901. if (g_ulFontInformation)
  902. {
  903. if (g_ulFontInformation == FONT_SMOOTHING_AA)
  904. {
  905. CheckDlgButton(hDlg, IDC_AATEXT, TRUE);
  906. }
  907. else if (g_ulFontInformation == FONT_SMOOTHING_CT)
  908. {
  909. CheckDlgButton(hDlg, IDC_CTTEXT, TRUE);
  910. }
  911. CheckDlgButton(hDlg, IDC_MONOTEXT, TRUE);
  912. }
  913. else
  914. {
  915. CheckDlgButton(hDlg, IDC_MONOTEXT, FALSE);
  916. EnableDlgItem(hDlg,IDC_AATEXT,FALSE);
  917. EnableDlgItem(hDlg,IDC_CTTEXT,FALSE);
  918. EnableDlgItem(hDlg,IDC_AASHOW,FALSE);
  919. EnableDlgItem(hDlg,IDC_CTSHOW,FALSE);
  920. }
  921. g_ulNewFontInformation = g_ulFontInformation;
  922. }
  923. HRESULT Text_OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  924. {
  925. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  926. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  927. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  928. BOOL bDorked = FALSE;
  929. switch (idCtrl)
  930. {
  931. case IDC_MONOTEXT:
  932. if (wEvent == BN_CLICKED)
  933. {
  934. if (IsDlgButtonChecked(hDlg, IDC_MONOTEXT))
  935. {
  936. EnableDlgItem(hDlg, IDC_AATEXT,TRUE);
  937. EnableDlgItem(hDlg, IDC_CTTEXT,TRUE);
  938. EnableDlgItem(hDlg, IDC_AASHOW,TRUE);
  939. EnableDlgItem(hDlg, IDC_CTSHOW,TRUE);
  940. CheckDlgButton(hDlg, IDC_AATEXT, FALSE);
  941. CheckDlgButton(hDlg, IDC_CTTEXT, FALSE);
  942. if (g_ulFontInformation == FONT_SMOOTHING_AA)
  943. {
  944. CheckDlgButton(hDlg, IDC_AATEXT, TRUE);
  945. g_ulNewFontInformation = FONT_SMOOTHING_AA;
  946. }
  947. else if (g_ulFontInformation == FONT_SMOOTHING_CT)
  948. {
  949. CheckDlgButton(hDlg, IDC_CTTEXT, TRUE);
  950. g_ulNewFontInformation = FONT_SMOOTHING_CT;
  951. }
  952. else
  953. {
  954. CheckDlgButton(hDlg, IDC_AATEXT, TRUE);
  955. g_ulNewFontInformation = FONT_SMOOTHING_AA;
  956. }
  957. }
  958. else
  959. {
  960. EnableDlgItem(hDlg,IDC_AATEXT,FALSE);
  961. EnableDlgItem(hDlg,IDC_CTTEXT,FALSE);
  962. EnableDlgItem(hDlg,IDC_AASHOW,FALSE);
  963. EnableDlgItem(hDlg,IDC_CTSHOW,FALSE);
  964. g_ulNewFontInformation = 0;
  965. }
  966. bDorked = TRUE;
  967. }
  968. break;
  969. case IDC_AATEXT:
  970. case IDC_CTTEXT:
  971. if (wEvent == BN_CLICKED)
  972. {
  973. ULONG ulFontInformation;
  974. ulFontInformation = 0;
  975. if ( LOWORD(wParam) == IDC_AATEXT)
  976. ulFontInformation = FONT_SMOOTHING_AA;
  977. else if ( LOWORD(wParam) == IDC_CTTEXT)
  978. ulFontInformation = FONT_SMOOTHING_CT;
  979. if (ulFontInformation != g_ulNewFontInformation)
  980. {
  981. g_ulNewFontInformation = ulFontInformation;
  982. bDorked = TRUE;
  983. }
  984. }
  985. break;
  986. default:
  987. break;
  988. }
  989. // If the user dorked with a setting, tell the property manager we
  990. // have outstanding changes. This will enable the "Apply Now" button...
  991. if (bDorked)
  992. {
  993. ShowTextRedraw(hDlg);
  994. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  995. bDorked = FALSE;
  996. }
  997. return fHandled;
  998. }
  999. //---------------------------------------------------------------------------
  1000. //
  1001. // TextEdgeDlgProc()
  1002. //
  1003. // The dialog procedure for the "TextEdge" property sheet page.
  1004. //
  1005. //---------------------------------------------------------------------------
  1006. INT_PTR CALLBACK TextEdgeDlgProc( HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam )
  1007. {
  1008. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE)GetWindowLongPtr( hDlg, DWLP_USER );
  1009. static int iIndex, iX;
  1010. static TCHAR szHelpFile[32];
  1011. switch( uMessage )
  1012. {
  1013. case WM_INITDIALOG:
  1014. // Need to add some code for help, but it is later.
  1015. GetFontInfo(hDlg);
  1016. break;
  1017. case WM_DESTROY:
  1018. break;
  1019. case WM_COMMAND:
  1020. Text_OnCommand(hDlg, uMessage, wParam, lParam);
  1021. break;
  1022. case WM_NOTIFY:
  1023. switch( ((NMHDR *)lParam)->code )
  1024. {
  1025. case PSN_APPLY: // OK or Apply clicked
  1026. {
  1027. HDC hDC = GetDC( NULL );
  1028. break;
  1029. }
  1030. case PSN_RESET:
  1031. g_ulNewFontInformation = g_ulFontInformation;
  1032. break;
  1033. default:
  1034. break;
  1035. }
  1036. break;
  1037. default:
  1038. return FALSE;
  1039. }
  1040. return(TRUE);
  1041. }
  1042. void ShowTextSample(HWND hWnd)
  1043. {
  1044. HFONT hfont;
  1045. HFONT hfontT;
  1046. RECT rc;
  1047. LOGFONT lf;
  1048. HDC hdc;
  1049. SIZE TextExtent;
  1050. INT yPos;
  1051. INT i, j, k, tmp;
  1052. INT LogPixelY;
  1053. INT yHeight;
  1054. hdc = GetDC(hWnd);
  1055. GetWindowRect(hWnd, &rc);
  1056. yHeight = (rc.bottom - rc.top) / 2;
  1057. ZeroMemory (&lf, sizeof(LOGFONT));
  1058. LogPixelY = GetDeviceCaps(hdc, LOGPIXELSY);
  1059. // This code can put on WM_CREATE
  1060. SetTextAlign(hdc, TA_LEFT| TA_TOP);
  1061. lf.lfPitchAndFamily = FF_ROMAN | VARIABLE_PITCH;
  1062. lstrcpy(lf.lfFaceName, TEXT("Times New Roman"));
  1063. i = (8 * LogPixelY + 36) / 72; // initial ppem size
  1064. j = (4 * LogPixelY + 36) / 72; // pixel size increment
  1065. if (g_ulNewFontInformation == FONT_SMOOTHING_AA)
  1066. {
  1067. lf.lfQuality = ANTIALIASED_QUALITY;
  1068. }
  1069. else if (g_ulNewFontInformation == FONT_SMOOTHING_CT)
  1070. {
  1071. lf.lfQuality = CLEARTYPE_QUALITY;
  1072. }
  1073. else
  1074. {
  1075. lf.lfQuality = NONANTIALIASED_QUALITY ;
  1076. }
  1077. yPos = 2;
  1078. tmp = i;
  1079. for (k = 0; k < 4; k++, i=i+j)
  1080. {
  1081. INT yNext;
  1082. lf.lfHeight = -i;
  1083. hfont = CreateFontIndirect(&lf);
  1084. hfontT = (HFONT)SelectObject(hdc, hfont);
  1085. GetTextExtentPoint(hdc, SZ_SAMPLETEXT, lstrlen(SZ_SAMPLETEXT), &TextExtent);
  1086. yNext = yPos + TextExtent.cy;
  1087. if (yNext > yHeight)
  1088. {
  1089. break;
  1090. }
  1091. ExtTextOut(hdc, 2, yPos, 0, &rc, SZ_SAMPLETEXT, lstrlen(SZ_SAMPLETEXT), NULL);
  1092. yPos = yNext;
  1093. SelectObject(hdc, hfontT);
  1094. DeleteObject(hfont);
  1095. }
  1096. yPos = yHeight + 2;
  1097. yHeight = (rc.bottom - rc.top);
  1098. i = tmp;
  1099. lf.lfItalic = TRUE;
  1100. for (k = 0; k < 4; k++, i=i+j)
  1101. {
  1102. INT yNext;
  1103. lf.lfHeight = -i;
  1104. hfont = CreateFontIndirect(&lf);
  1105. hfontT = (HFONT)SelectObject(hdc, hfont);
  1106. GetTextExtentPoint(hdc, SZ_SAMPLETEXT, lstrlen(SZ_SAMPLETEXT), &TextExtent);
  1107. yNext = yPos + TextExtent.cy;
  1108. if (yNext > yHeight)
  1109. {
  1110. break;
  1111. }
  1112. ExtTextOut(hdc, 2, yPos, 0, &rc, SZ_SAMPLETEXT, lstrlen(SZ_SAMPLETEXT), NULL);
  1113. yPos = yNext;
  1114. SelectObject(hdc, hfontT);
  1115. DeleteObject(hfont);
  1116. }
  1117. ReleaseDC(hWnd, hdc);
  1118. }
  1119. LRESULT CALLBACK TextEdgeWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  1120. {
  1121. PAINTSTRUCT ps;
  1122. switch(message)
  1123. {
  1124. case WM_CREATE:
  1125. break;
  1126. case WM_DESTROY:
  1127. break;
  1128. case WM_PALETTECHANGED:
  1129. break;
  1130. //fallthru
  1131. case WM_QUERYNEWPALETTE:
  1132. break;
  1133. case WM_PAINT:
  1134. BeginPaint(hWnd,&ps);
  1135. ShowTextSample(hWnd);
  1136. EndPaint(hWnd,&ps);
  1137. return 0;
  1138. }
  1139. return DefWindowProc(hWnd,message,wParam,lParam);
  1140. }
  1141. BOOL RegisterTextEdgeClass(void)
  1142. {
  1143. WNDCLASS wc;
  1144. wc.style = CS_HREDRAW | CS_VREDRAW;
  1145. wc.lpfnWndProc = TextEdgeWndProc;
  1146. wc.cbClsExtra = 0;
  1147. wc.cbWndExtra = 0;
  1148. wc.hInstance = g_hInst;
  1149. wc.hIcon = NULL;
  1150. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1151. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  1152. wc.lpszMenuName = NULL;
  1153. wc.lpszClassName = TEXTEDGE_CLASS;
  1154. if (!RegisterClass(&wc))
  1155. return FALSE;
  1156. return TRUE;
  1157. }
  1158. BOOL DisplayFontSmoothingDetails(HWND hWnd, BOOL* pfFontSmoothing, DWORD *pdwSmoothingType)
  1159. {
  1160. BOOL bRet = TRUE;
  1161. PROPSHEETPAGE apsp[1];
  1162. PROPSHEETHEADER psh;
  1163. RegisterTextEdgeClass();
  1164. psh.nStartPage = 0;
  1165. psh.dwSize = sizeof(psh);
  1166. //
  1167. // Disable Apply button
  1168. //
  1169. psh.dwFlags = PSH_PROPTITLE | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  1170. psh.hwndParent = hWnd;
  1171. psh.hInstance = g_hInst;
  1172. psh.pszIcon = NULL;
  1173. //
  1174. // psh.nStartPage is set above.
  1175. //
  1176. psh.pszCaption = MAKEINTRESOURCE(IDS_TEXTPROP);
  1177. psh.nPages = 1;
  1178. psh.ppsp = apsp;
  1179. apsp[0].dwSize = sizeof(PROPSHEETPAGE);
  1180. apsp[0].dwFlags = PSP_DEFAULT;
  1181. apsp[0].hInstance = g_hInst;
  1182. apsp[0].pszTemplate = MAKEINTRESOURCE(DLG_TEXTEDGE);
  1183. apsp[0].pfnDlgProc = TextEdgeDlgProc;
  1184. apsp[0].lParam = 0;
  1185. if (*pfFontSmoothing)
  1186. {
  1187. g_ulFontInformation = *pdwSmoothingType;
  1188. }
  1189. else
  1190. {
  1191. g_ulFontInformation = 0;
  1192. }
  1193. if (psh.nStartPage >= psh.nPages)
  1194. {
  1195. psh.nStartPage = 0;
  1196. }
  1197. if (PropertySheet(&psh) != -1)
  1198. bRet = FALSE;
  1199. if (g_ulNewFontInformation == 0)
  1200. {
  1201. *pfFontSmoothing = FALSE;
  1202. }
  1203. else
  1204. {
  1205. *pfFontSmoothing = TRUE;
  1206. *pdwSmoothingType = (DWORD) g_ulNewFontInformation;
  1207. }
  1208. return TRUE;
  1209. }
  1210. #endif // CLEARTYPECOMBO
  1211. #include "..\common\propsext.cpp"