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.

474 lines
14 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. #include "pch.hxx" // pch
  3. #pragma hdrstop
  4. #include "resource.h"
  5. #include "pgWelco2.h"
  6. // Intelli-menu regsitry
  7. #define REGSTR_EXPLORER TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer")
  8. #define REGSTR_INTELLIMENU REGSTR_EXPLORER TEXT("\\Advanced")
  9. #define REGSTR_IE TEXT("Software\\Microsoft\\Internet Explorer\\Main")
  10. #define STRMENU TEXT("IntelliMenus")
  11. #define FAVMENU TEXT("FavIntelliMenus")
  12. CWelcome2Pg::CWelcome2Pg(
  13. LPPROPSHEETPAGE ppsp
  14. ) : WizardPage(ppsp, IDS_WELCOME2TITLE, IDS_WELCOME2SUBTITLE)
  15. {
  16. m_dwPageId = IDD_WIZWELCOME2;
  17. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  18. m_pDisplayModes = NULL;
  19. m_nDisplayModes = 0;
  20. m_nBestDisplayMode = -1;
  21. m_IntlVal = FALSE;
  22. // These are our state variables so we know not to do these things twice.
  23. m_bMagnifierRun = FALSE;
  24. m_bResolutionSwitched = FALSE;
  25. m_bFontsChanged = FALSE;
  26. }
  27. CWelcome2Pg::~CWelcome2Pg(
  28. VOID
  29. )
  30. {
  31. if(m_pDisplayModes)
  32. delete [] m_pDisplayModes;
  33. }
  34. LRESULT
  35. CWelcome2Pg::OnInitDialog(
  36. HWND hwnd,
  37. WPARAM wParam,
  38. LPARAM lParam
  39. )
  40. {
  41. // Enumerate available video modes
  42. // Check if SM_CMONITORS is > 0 then set text so we don't
  43. // change resolution.
  44. DEVMODE dm;
  45. // Calculate number of display modes
  46. for(m_nDisplayModes=0;m_nDisplayModes<2000;m_nDisplayModes++) // Limit to 2000 display modes. If it is this high, something is wrong
  47. if(!EnumDisplaySettings(NULL, m_nDisplayModes, &dm))
  48. break;
  49. m_pDisplayModes = new CDisplayModeInfo[m_nDisplayModes];
  50. for(int i=0;i<m_nDisplayModes;i++)
  51. EnumDisplaySettings(NULL, i, &m_pDisplayModes[i].m_DevMode);
  52. m_nBestDisplayMode = -1;
  53. memset(&m_dvmdOrig, 0, sizeof(m_dvmdOrig));
  54. HDC hdc = GetDC(NULL); // Screen DC used to get current display settings
  55. // JMC: HOW DO WE GET dmDisplayFlags?
  56. // TODO: Maybe use ChangeDisplaySettings(NULL, 0) to restore original mode
  57. m_dvmdOrig.dmSize = sizeof(m_dvmdOrig);
  58. m_dvmdOrig.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | /* DM_DISPLAYFLAGS | */(g_Options.m_bWin95?0:DM_DISPLAYFREQUENCY);
  59. m_dvmdOrig.dmPelsWidth = GetDeviceCaps(hdc, HORZRES);
  60. m_dvmdOrig.dmPelsHeight = GetDeviceCaps(hdc, VERTRES);
  61. m_dvmdOrig.dmBitsPerPel = GetDeviceCaps(hdc, BITSPIXEL);
  62. m_dvmdOrig.dmDisplayFrequency = g_Options.m_bWin95?0:GetDeviceCaps(hdc, VREFRESH);
  63. ReleaseDC(NULL, hdc);
  64. for(i=0;i<m_nDisplayModes;i++)
  65. {
  66. // Skip anything 'higher' than current mode
  67. if( m_pDisplayModes[i].m_DevMode.dmPelsWidth > m_dvmdOrig.dmPelsWidth
  68. || m_pDisplayModes[i].m_DevMode.dmPelsHeight > m_dvmdOrig.dmPelsHeight
  69. || m_pDisplayModes[i].m_DevMode.dmBitsPerPel > m_dvmdOrig.dmBitsPerPel
  70. || (!g_Options.m_bWin95 && m_pDisplayModes[i].m_DevMode.dmDisplayFrequency > m_dvmdOrig.dmDisplayFrequency) )
  71. continue;
  72. // Skip this if it is 'worse' than the current best mode
  73. if( -1 != m_nBestDisplayMode
  74. && ( m_pDisplayModes[i].m_DevMode.dmPelsWidth < m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmPelsWidth
  75. || m_pDisplayModes[i].m_DevMode.dmPelsHeight < m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmPelsHeight
  76. || m_pDisplayModes[i].m_DevMode.dmBitsPerPel < m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmBitsPerPel
  77. || (!g_Options.m_bWin95 && m_pDisplayModes[i].m_DevMode.dmDisplayFrequency < m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmDisplayFrequency) ) )
  78. continue;
  79. // Skip anything 'less than' 800 x 600 (JMC: Used to be 640 x 480)
  80. if( m_pDisplayModes[i].m_DevMode.dmPelsWidth < 800
  81. || m_pDisplayModes[i].m_DevMode.dmPelsHeight < 600 )
  82. continue;
  83. // See if this is 'smaller' than the current resolution
  84. if( m_pDisplayModes[i].m_DevMode.dmPelsHeight < m_dvmdOrig.dmPelsHeight )
  85. m_nBestDisplayMode = i;
  86. }
  87. // Get original metrics
  88. GetNonClientMetrics(&m_ncmOrig, &m_lfIconOrig);
  89. SetCheckBoxesFromWelcomePageInfo();
  90. // Set the Personalized menu check box
  91. HKEY hKey;
  92. DWORD dwType;
  93. TCHAR lpszData[24];
  94. DWORD dwCount = 24;
  95. if(ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, REGSTR_INTELLIMENU,&hKey))
  96. {
  97. if ( ERROR_SUCCESS == RegQueryValueEx( hKey, STRMENU, NULL, &dwType, (LPBYTE)lpszData, &dwCount ) )
  98. {
  99. if ( lstrcmp(lpszData, TEXT("No") ) == 0 )
  100. m_IntlVal = TRUE;
  101. }
  102. }
  103. Button_SetCheck(GetDlgItem(hwnd, IDC_PERMENU), m_IntlVal);
  104. return 1;
  105. }
  106. void CWelcome2Pg::UpdateControls()
  107. {
  108. BOOL bChangeRes = Button_GetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION));
  109. BOOL bChangeFont = Button_GetCheck(GetDlgItem(m_hwnd, IDC_CHANGEFONTS));
  110. BOOL bMagnifier = Button_GetCheck(GetDlgItem(m_hwnd, IDC_USEMAGNIFY));
  111. DWORD_PTR result;
  112. if(bChangeRes && !m_bResolutionSwitched)
  113. {
  114. if(IDOK != StringTableMessageBox(m_hwnd,IDS_WIZCHANGESHAPPENINGTEXT, IDS_WIZCHANGESHAPPENINGTITLE, MB_OKCANCEL))
  115. {
  116. // The user does not want to do this
  117. Button_SetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), FALSE);
  118. }
  119. else
  120. {
  121. // Lets change the resolution
  122. if(DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&m_pDisplayModes[m_nBestDisplayMode].m_DevMode, CDS_TEST))
  123. {
  124. }
  125. else
  126. ChangeDisplaySettings(&m_pDisplayModes[m_nBestDisplayMode].m_DevMode, CDS_UPDATEREGISTRY | CDS_GLOBAL);
  127. if(IDOK != StringTableMessageBox(m_hwnd, IDS_WIZCANCELCHANGESTEXT, IDS_WIZCANCELCHANGESTITLE, MB_OKCANCEL))
  128. {
  129. // Restore original settings
  130. ChangeDisplaySettings(&m_dvmdOrig, CDS_UPDATEREGISTRY | CDS_GLOBAL);
  131. Button_SetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), FALSE);
  132. }
  133. else
  134. m_bResolutionSwitched = TRUE; // We REALLY changed the settings
  135. }
  136. }
  137. else if (!bChangeRes && m_bResolutionSwitched)
  138. {
  139. m_bResolutionSwitched = FALSE;
  140. // Restore original settings
  141. ChangeDisplaySettings(&m_dvmdOrig, CDS_UPDATEREGISTRY | CDS_GLOBAL);
  142. }
  143. if(bChangeFont && !m_bFontsChanged)
  144. {
  145. m_bFontsChanged = TRUE;
  146. // Get current metrics
  147. NONCLIENTMETRICS ncm;
  148. memset(&ncm, 0, sizeof(ncm));
  149. ncm.cbSize = sizeof(ncm);
  150. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  151. LOGFONT lf;
  152. memset(&lf, 0, sizeof(lf));
  153. lf.lfHeight = -MulDiv(g_Options.m_nMinimalFontSize, g_Options.m_nLogPixelsY, 72);
  154. lf.lfWeight = FW_BOLD;
  155. lf.lfCharSet = g_Options.m_lfCharSet;
  156. LoadString(g_hInstDll, IDS_SYSTEMFONTNAME, lf.lfFaceName, ARRAYSIZE(lf.lfFaceName));
  157. // Captions are BOLD
  158. ncm.lfCaptionFont = lf;
  159. lf.lfWeight = FW_NORMAL;
  160. ncm.lfSmCaptionFont = lf;
  161. ncm.lfMenuFont = lf;
  162. ncm.lfStatusFont = lf;
  163. ncm.lfMessageFont = lf;
  164. // DYNAMICS
  165. // JMC: TODO: Change caption height / menu height / button width to match.
  166. // JMC: HACK
  167. lf.lfWeight = FW_BOLD; // Caption is BOLD
  168. HFONT hFont = CreateFontIndirect(&lf);
  169. lf.lfWeight = FW_NORMAL; // Still need lf for ICON
  170. TEXTMETRIC tm;
  171. HDC hdc = GetDC(m_hwnd);
  172. HFONT hfontOld = (HFONT)SelectObject(hdc, hFont);
  173. GetTextMetrics(hdc, &tm);
  174. if (hfontOld)
  175. SelectObject(hdc, hfontOld);
  176. ReleaseDC(m_hwnd, hdc);
  177. /*int cyBorder = GetSystemMetrics(SM_CYBORDER);
  178. int nSize = abs(lf.lfHeight) + abs(tm.tmExternalLeading) + 2 * cyBorder;
  179. nSize = max(nSize, GetSystemMetrics(SM_CYICON)/2 + 2 * cyBorder);*/
  180. // The above calculation of metric sizes is incorrect, Morever, The other values
  181. // are also wrong..So using hardcoded values: Based on Display.cpl
  182. // BUG: Changes maybe required for 9x here!!
  183. if (g_Options.m_nMinimalFontSize >= 14 )
  184. ncm.iCaptionWidth = ncm.iCaptionHeight = 26;
  185. else
  186. ncm.iCaptionWidth = ncm.iCaptionHeight = 18;
  187. ncm.iSmCaptionWidth = 15;
  188. ncm.iSmCaptionHeight = 15;
  189. ncm.iMenuWidth = 18;
  190. ncm.iMenuHeight = 18;
  191. SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(ncm), &ncm, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
  192. SystemParametersInfo(SPI_SETICONTITLELOGFONT, sizeof(lf), &lf, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
  193. SendMessageTimeout(HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0, SMTO_ABORTIFHUNG, 5000, &result );
  194. SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, (LPARAM)__TEXT("WindowMetrics"),
  195. SMTO_ABORTIFHUNG, 5000, &result);
  196. // HACK - TODO Remove this from here
  197. g_Options.m_schemePreview.m_PortableNonClientMetrics.LoadOriginal();
  198. g_Options.m_schemeCurrent.m_PortableNonClientMetrics.LoadOriginal();
  199. }
  200. else if (!bChangeFont && m_bFontsChanged)
  201. {
  202. m_bFontsChanged = FALSE;
  203. SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(m_ncmOrig), &m_ncmOrig, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
  204. SystemParametersInfo(SPI_SETICONTITLELOGFONT, sizeof(m_lfIconOrig), &m_lfIconOrig, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
  205. SendMessageTimeout(HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0, SMTO_ABORTIFHUNG, 5000, &result);
  206. SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, (LPARAM)__TEXT("WindowMetrics"),
  207. SMTO_ABORTIFHUNG, 5000, &result);
  208. // HACK - TODO Remove this from here
  209. g_Options.m_schemePreview.m_PortableNonClientMetrics.LoadOriginal();
  210. g_Options.m_schemeCurrent.m_PortableNonClientMetrics.LoadOriginal();
  211. }
  212. if(bMagnifier && !m_bMagnifierRun)
  213. {
  214. // Start magnifier
  215. m_bMagnifierRun = TRUE;
  216. ShellExecute(NULL, NULL, __TEXT("Magnify.exe"), NULL, NULL, SW_SHOWNORMAL/*SW_SHOWMINIMIZED*/);
  217. }
  218. else if (!bMagnifier && m_bMagnifierRun)
  219. {
  220. // Stop magnifier
  221. m_bMagnifierRun = FALSE;
  222. TCHAR szMag[200];
  223. LoadString(g_hInstDll, IDS_NAMEOFMAGNIFIER, szMag, ARRAYSIZE(szMag));
  224. if(HWND hwnd = FindWindow(NULL, szMag))
  225. SendMessage(hwnd, WM_CLOSE, 0, 0);
  226. }
  227. }
  228. void CWelcome2Pg::SetCheckBoxesFromWelcomePageInfo()
  229. {
  230. // This algorithm chooses which check boxes to set based on the
  231. // minimal legible font size specified in g_Options.m_nMinimalFontSize
  232. // HACK:
  233. // g_Options.m_nMinimalFontSize = MulDiv(abs(g_Options.m_schemePreview.m_ncm.lfCaptionFont.lfHeight), 72, g_Options.m_nLogPixelsY);
  234. BOOL bSwitchRes = FALSE;
  235. BOOL bChangeFonts = FALSE;
  236. BOOL bUseMagnify = FALSE;
  237. switch(g_Options.m_nMinimalFontSize)
  238. {
  239. case 8:
  240. case 9: // Required for JPN
  241. case 10:
  242. case 11: // Required For JPN
  243. bChangeFonts = TRUE;
  244. break;
  245. case 12:
  246. bChangeFonts = TRUE;
  247. bSwitchRes = TRUE;
  248. break;
  249. case 14:
  250. case 15: // Required for JPN
  251. case 16:
  252. case 18:
  253. case 20:
  254. case 22:
  255. case 24:
  256. bChangeFonts = TRUE;
  257. bUseMagnify = TRUE;
  258. break;
  259. }
  260. // JMC: TODO: Handle if the user does not have permission to change
  261. // the display settings!!!!!!!!!!!!!!
  262. if(-1 == m_nBestDisplayMode)
  263. {
  264. bSwitchRes = FALSE;
  265. // SetWindowText(GetDlgItem(m_hwnd, IDC_SZRESMESSAGE),
  266. // __TEXT("There are no display resolutions that would be better for the size text you chose."));
  267. EnableWindow(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), FALSE);
  268. }
  269. else
  270. {
  271. #if 0 // We don't display special text any more
  272. TCHAR sz[200];
  273. TCHAR szTemp[1024];
  274. LoadString(g_hInstDll, IDS_DISPLAYRESOLUTIONINFO, szTemp, ARRAYSIZE(szTemp));
  275. wsprintf(sz, szTemp,
  276. m_dvmdOrig.dmPelsWidth,
  277. m_dvmdOrig.dmPelsHeight,
  278. m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmPelsWidth,
  279. m_pDisplayModes[m_nBestDisplayMode].m_DevMode.dmPelsHeight);
  280. SetWindowText(GetDlgItem(m_hwnd, IDC_SZRESMESSAGE), sz);
  281. #endif
  282. EnableWindow(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), TRUE);
  283. }
  284. Button_SetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), bSwitchRes);
  285. Button_SetCheck(GetDlgItem(m_hwnd, IDC_CHANGEFONTS), bChangeFonts);
  286. Button_SetCheck(GetDlgItem(m_hwnd, IDC_USEMAGNIFY), bUseMagnify);
  287. UpdateControls();
  288. }
  289. LRESULT
  290. CWelcome2Pg::OnCommand(
  291. HWND hwnd,
  292. WPARAM wParam,
  293. LPARAM lParam
  294. )
  295. {
  296. LRESULT lResult = 1;
  297. WORD wNotifyCode = HIWORD(wParam);
  298. WORD wCtlID = LOWORD(wParam);
  299. HWND hwndCtl = (HWND)lParam;
  300. // NOTE: DO NOT CALL UpdateControls()
  301. // UpdateControls() should only be called when entering this page
  302. // since it sets the check boxes based on the minimal font size
  303. // determined by the previous wizard page
  304. switch(wCtlID)
  305. {
  306. case IDC_SWITCHRESOLUTION:
  307. case IDC_CHANGEFONTS:
  308. case IDC_USEMAGNIFY:
  309. UpdateControls();
  310. lResult = 0;
  311. break;
  312. default:
  313. break;
  314. }
  315. return lResult;
  316. }
  317. LRESULT
  318. CWelcome2Pg::OnPSN_SetActive(
  319. HWND hwnd,
  320. INT idCtl,
  321. LPPSHNOTIFY pnmh
  322. )
  323. {
  324. // Call the base class
  325. WizardPage::OnPSN_SetActive(hwnd, idCtl, pnmh);
  326. // Make sure our check boxes reflect any change in the minimal
  327. // font size specified by g_Options.m_nMinimalFontSize
  328. if(g_Options.m_bWelcomePageTouched)
  329. {
  330. g_Options.m_bWelcomePageTouched = FALSE;
  331. SetCheckBoxesFromWelcomePageInfo();
  332. }
  333. return TRUE;
  334. }
  335. LRESULT
  336. CWelcome2Pg::OnPSN_WizNext(
  337. HWND hwnd,
  338. INT idCtl,
  339. LPPSHNOTIFY pnmh
  340. )
  341. {
  342. BOOL bIMenu = Button_GetCheck(GetDlgItem(m_hwnd, IDC_PERMENU));
  343. if (!m_bFontsChanged)
  344. {
  345. g_Options.m_schemePreview.m_nSelectedSize = g_Options.m_schemeOriginal.m_nSelectedSize;
  346. }
  347. // If Intelli-menus are changed
  348. if(bIMenu != m_IntlVal)
  349. {
  350. HKEY hKey;
  351. DWORD_PTR result;
  352. LPTSTR psz = bIMenu ? TEXT("No") : TEXT("Yes");
  353. // Change the Registry entries....
  354. if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, REGSTR_INTELLIMENU, &hKey) )
  355. {
  356. RegSetValueEx( hKey, STRMENU, 0, REG_SZ, (LPBYTE)psz,
  357. (lstrlen(psz) + 1) * sizeof(TCHAR) );
  358. RegCloseKey(hKey);
  359. }
  360. if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, REGSTR_IE, &hKey) )
  361. {
  362. RegSetValueEx( hKey, FAVMENU, 0, REG_SZ, (LPBYTE)psz,
  363. (lstrlen(psz) + 1) * sizeof(TCHAR) );
  364. RegCloseKey(hKey);
  365. }
  366. m_IntlVal = bIMenu;
  367. SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
  368. (LPARAM) 0, SMTO_ABORTIFHUNG, 5000, &result);
  369. }
  370. return WizardPage::OnPSN_WizNext(hwnd, idCtl, pnmh);
  371. }
  372. LRESULT
  373. CWelcome2Pg::OnPSN_WizBack(
  374. HWND hwnd,
  375. INT idCtl,
  376. LPPSHNOTIFY pnmh
  377. )
  378. {
  379. // Undo any changes
  380. Button_SetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION), FALSE);
  381. Button_SetCheck(GetDlgItem(m_hwnd, IDC_CHANGEFONTS), FALSE);
  382. Button_SetCheck(GetDlgItem(m_hwnd, IDC_USEMAGNIFY), FALSE);
  383. // While going back. Just update variables only. Don't apply changes.
  384. // DONOT call UpdateControls(): a-anilk
  385. BOOL bChangeRes = Button_GetCheck(GetDlgItem(m_hwnd, IDC_SWITCHRESOLUTION));
  386. BOOL bChangeFont = Button_GetCheck(GetDlgItem(m_hwnd, IDC_CHANGEFONTS));
  387. BOOL bMagnifier = Button_GetCheck(GetDlgItem(m_hwnd, IDC_USEMAGNIFY));
  388. m_bFontsChanged = FALSE;
  389. return WizardPage::OnPSN_WizBack(hwnd, idCtl, pnmh);
  390. }