Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

613 lines
18 KiB

  1. //
  2. // propdisplay.cpp: display property sheet dialog proc
  3. //
  4. // Tab B
  5. //
  6. // Copyright Microsoft Corporation 2000
  7. // nadima
  8. #include "stdafx.h"
  9. #define TRC_GROUP TRC_GROUP_UI
  10. #define TRC_FILE "propdisplay"
  11. #include <atrcapi.h>
  12. #include "sh.h"
  13. #include "commctrl.h"
  14. #include "propdisplay.h"
  15. COLORSTRINGMAP g_ColorStringTable[] =
  16. {
  17. {8, UI_IDS_COLOR_256, UI_IDB_COLOR8, UI_IDB_COLOR8_DITHER, TEXT("")},
  18. #ifndef OS_WINCE
  19. {15, UI_IDS_COLOR_15bpp, UI_IDB_COLOR16, UI_IDB_COLOR8_DITHER, TEXT("")},
  20. #endif
  21. {16, UI_IDS_COLOR_16bpp, UI_IDB_COLOR16, UI_IDB_COLOR8_DITHER, TEXT("")},
  22. {24, UI_IDS_COLOR_24bpp, UI_IDB_COLOR24, UI_IDB_COLOR8_DITHER, TEXT("")}
  23. };
  24. #define NUM_COLORSTRINGS sizeof(g_ColorStringTable)/sizeof(COLORSTRINGMAP)
  25. //
  26. // LUT of valid screen resolutions
  27. //
  28. const SCREENRES g_ScreenResolutions[] =
  29. {
  30. {640,480},
  31. {800,600},
  32. {1024,768},
  33. {1152,864},
  34. {1280,1024},
  35. {1600,1200}
  36. };
  37. #define NUM_SCREENRES sizeof(g_ScreenResolutions)/sizeof(SCREENRES)
  38. //
  39. // Controls that need to be disabled/enabled
  40. // during connection (for progress animation)
  41. //
  42. CTL_ENABLE connectingDisableCtlsPDisplay[] = {
  43. #ifndef OS_WINCE
  44. {IDC_RES_SLIDER, FALSE},
  45. #endif
  46. {IDC_CHECK_DISPLAY_BBAR, FALSE},
  47. {IDC_COMBO_COLOR_DEPTH, FALSE}
  48. };
  49. const UINT numConnectingDisableCtlsPDisplay =
  50. sizeof(connectingDisableCtlsPDisplay)/
  51. sizeof(connectingDisableCtlsPDisplay[0]);
  52. CPropDisplay* CPropDisplay::_pPropDisplayInstance = NULL;
  53. CPropDisplay::CPropDisplay(HINSTANCE hInstance, CTscSettings* pTscSet, CSH* pSh)
  54. {
  55. DC_BEGIN_FN("CPropDisplay");
  56. _hInstance = hInstance;
  57. CPropDisplay::_pPropDisplayInstance = this;
  58. _pTscSet = pTscSet;
  59. _pSh = pSh;
  60. TRC_ASSERT(_pTscSet,(TB,_T("_pTscSet is null")));
  61. TRC_ASSERT(_pSh,(TB,_T("_pSh is null")));
  62. if(!LoadDisplayourcesPgStrings())
  63. {
  64. TRC_ERR((TB, _T("Failed LoadDisplayourcesPgStrings()")));
  65. }
  66. _fSwitchedColorComboBmp = FALSE;
  67. DC_END_FN();
  68. }
  69. CPropDisplay::~CPropDisplay()
  70. {
  71. CPropDisplay::_pPropDisplayInstance = NULL;
  72. }
  73. INT_PTR CALLBACK CPropDisplay::StaticPropPgDisplayDialogProc(HWND hwndDlg,
  74. UINT uMsg,
  75. WPARAM wParam,
  76. LPARAM lParam)
  77. {
  78. //
  79. // Delegate to appropriate instance (only works for single instance dialogs)
  80. //
  81. DC_BEGIN_FN("StaticDialogBoxProc");
  82. DCINT retVal = 0;
  83. TRC_ASSERT(_pPropDisplayInstance, (TB, _T("Display dialog has NULL static instance ptr\n")));
  84. retVal = _pPropDisplayInstance->PropPgDisplayDialogProc( hwndDlg,
  85. uMsg,
  86. wParam,
  87. lParam);
  88. DC_END_FN();
  89. return retVal;
  90. }
  91. INT_PTR CALLBACK CPropDisplay::PropPgDisplayDialogProc (HWND hwndDlg,
  92. UINT uMsg,
  93. WPARAM wParam,
  94. LPARAM lParam)
  95. {
  96. DC_BEGIN_FN("PropPgDisplayDialogProc");
  97. switch(uMsg)
  98. {
  99. case WM_INITDIALOG:
  100. {
  101. #ifndef OS_WINCE
  102. int i;
  103. #endif
  104. //
  105. // Position the dialog within the tab
  106. //
  107. SetWindowPos( hwndDlg, HWND_TOP,
  108. _rcTabDispayArea.left, _rcTabDispayArea.top,
  109. _rcTabDispayArea.right - _rcTabDispayArea.left,
  110. _rcTabDispayArea.bottom - _rcTabDispayArea.top,
  111. 0);
  112. _fSwitchedColorComboBmp = FALSE;
  113. //
  114. // Fill the color combo up to the current
  115. // supported screen depth
  116. //
  117. InitColorCombo(hwndDlg);
  118. InitScreenResTable();
  119. #ifndef OS_WINCE
  120. HWND hwndResTrackBar = GetDlgItem( hwndDlg, IDC_RES_SLIDER);
  121. if(!hwndResTrackBar)
  122. {
  123. return FALSE;
  124. }
  125. SendMessage(hwndResTrackBar, TBM_SETRANGE,
  126. (WPARAM) TRUE,
  127. (LPARAM) MAKELONG(0, _numScreenResOptions-1));
  128. SendMessage(hwndResTrackBar, TBM_SETPAGESIZE,
  129. (WPARAM) 0,
  130. (LPARAM) 1);
  131. //
  132. // Choose the current entry on the trackbar
  133. //
  134. int deskWidth = _pTscSet->GetDesktopWidth();
  135. int deskHeight = _pTscSet->GetDesktopHeight();
  136. int curSelection = 0;
  137. if(_pTscSet->GetStartFullScreen())
  138. {
  139. //Fullscreen is the last option
  140. curSelection = _numScreenResOptions - 1;
  141. }
  142. else
  143. {
  144. for(i=0; i<_numScreenResOptions; i++)
  145. {
  146. if(deskWidth == _screenResTable[i].width &&
  147. deskHeight == _screenResTable[i].height)
  148. {
  149. curSelection = i;
  150. break;
  151. }
  152. }
  153. }
  154. SendMessage(hwndResTrackBar, TBM_SETSEL,
  155. (WPARAM) TRUE, //redraw
  156. (LPARAM) 0);
  157. SendMessage(hwndResTrackBar, TBM_SETPOS,
  158. (WPARAM) TRUE, //redraw
  159. (LPARAM) curSelection);
  160. OnUpdateResTrackBar(hwndDlg);
  161. #endif
  162. CheckDlgButton(hwndDlg, IDC_CHECK_DISPLAY_BBAR,
  163. _pTscSet->GetDisplayBBar() ?
  164. BST_CHECKED : BST_UNCHECKED);
  165. OnUpdateColorCombo(hwndDlg);
  166. _pSh->SH_ThemeDialogWindow(hwndDlg, ETDT_ENABLETAB);
  167. return TRUE;
  168. }
  169. break; //WM_INITDIALOG
  170. #ifndef OS_WINCE
  171. case WM_DISPLAYCHANGE:
  172. {
  173. OnUpdateResTrackBar(hwndDlg);
  174. OnUpdateColorCombo(hwndDlg);
  175. }
  176. break;
  177. case WM_HSCROLL:
  178. {
  179. OnUpdateResTrackBar(hwndDlg);
  180. }
  181. break; //WM_HSCROLL
  182. #endif
  183. case WM_TSC_ENABLECONTROLS:
  184. {
  185. //
  186. // wParam is TRUE to enable controls,
  187. // FALSE to disable them
  188. //
  189. CSH::EnableControls( hwndDlg,
  190. connectingDisableCtlsPDisplay,
  191. numConnectingDisableCtlsPDisplay,
  192. wParam ? TRUE : FALSE);
  193. }
  194. break;
  195. //
  196. // On return to connection UI
  197. // (e.g after a disconnection)
  198. //
  199. case WM_TSC_RETURNTOCONUI:
  200. {
  201. //
  202. // Update the controls
  203. //
  204. #ifndef OS_WINCE
  205. OnUpdateResTrackBar(hwndDlg);
  206. #endif
  207. OnUpdateColorCombo(hwndDlg);
  208. }
  209. break;
  210. case WM_SAVEPROPSHEET: //Intentional fallthru
  211. case WM_DESTROY:
  212. {
  213. //
  214. // Save page settings
  215. //
  216. #ifndef OS_WINCE
  217. HWND hwndResTrackBar = GetDlgItem( hwndDlg, IDC_RES_SLIDER);
  218. int maxRes = (int)SendMessage( hwndResTrackBar,
  219. TBM_GETRANGEMAX,
  220. TRUE, 0);
  221. int iRes = (int)SendMessage( hwndResTrackBar, TBM_GETPOS, 0, 0);
  222. #else
  223. int iRes = _numScreenResOptions - 1;
  224. int maxRes = iRes;
  225. #endif
  226. int bppIdx = (int)SendMessage(
  227. GetDlgItem(hwndDlg,IDC_COMBO_COLOR_DEPTH),
  228. CB_GETCURSEL, 0, 0);
  229. _pTscSet->SetColorDepth(g_ColorStringTable[bppIdx].bpp);
  230. //rightmost setting, display 'fullscreen'
  231. _pTscSet->SetStartFullScreen(iRes == maxRes);
  232. _pTscSet->SetDesktopWidth(_screenResTable[iRes].width);
  233. _pTscSet->SetDesktopHeight(_screenResTable[iRes].height);
  234. BOOL fShowBBar = IsDlgButtonChecked(hwndDlg,
  235. IDC_CHECK_DISPLAY_BBAR);
  236. _pTscSet->SetDisplayBBar(fShowBBar);
  237. //
  238. // Flag that we've switched this to allow
  239. // proper cleanup on dialog termination
  240. //
  241. if (_fSwitchedColorComboBmp)
  242. {
  243. HBITMAP hbmOld = (HBITMAP) SendDlgItemMessage(hwndDlg,
  244. IDC_COLORPREVIEW, STM_GETIMAGE,
  245. IMAGE_BITMAP, (LPARAM)0);
  246. //
  247. // Cleanup
  248. //
  249. if (hbmOld)
  250. {
  251. DeleteObject(hbmOld);
  252. }
  253. }
  254. }
  255. break; //WM_DESTROY
  256. case WM_COMMAND:
  257. {
  258. switch(LOWORD(wParam))
  259. {
  260. case IDC_COMBO_COLOR_DEPTH:
  261. {
  262. if(HIWORD(wParam) == CBN_SELCHANGE)
  263. {
  264. OnUpdateColorCombo( hwndDlg);
  265. }
  266. }
  267. break;
  268. }
  269. }
  270. break; //WM_COMMAND
  271. }
  272. DC_END_FN();
  273. return 0;
  274. }
  275. //
  276. // Load resources for the local resources dialog
  277. //
  278. BOOL CPropDisplay::LoadDisplayourcesPgStrings()
  279. {
  280. DC_BEGIN_FN("LoadDisplayourcesPgStrings");
  281. //
  282. // Load color strings
  283. //
  284. for(int i = 0; i< NUM_COLORSTRINGS; i++)
  285. {
  286. if (!LoadString( _hInstance,
  287. g_ColorStringTable[i].resID,
  288. g_ColorStringTable[i].szString,
  289. COLOR_STRING_MAXLEN ))
  290. {
  291. TRC_ERR((TB, _T("Failed to load color string %d"),
  292. g_ColorStringTable[i].resID));
  293. return FALSE;
  294. }
  295. }
  296. //
  297. // Load display resolution strings
  298. //
  299. if (!LoadString( _hInstance,
  300. UI_IDS_SUPPORTED_RES,
  301. _szScreenRes,
  302. SH_SHORT_STRING_MAX_LENGTH))
  303. {
  304. TRC_ERR((TB, _T("Failed to load UI_IDS_SUPPORTED_RES")));
  305. return FALSE;
  306. }
  307. if (!LoadString(_hInstance,
  308. UI_IDS_FULLSCREEN,
  309. _szFullScreen,
  310. SH_SHORT_STRING_MAX_LENGTH))
  311. {
  312. TRC_ERR((TB, _T("Failed to load UI_IDS_FULLSCREEN")));
  313. return FALSE;
  314. }
  315. DC_END_FN();
  316. return TRUE;
  317. }
  318. #ifndef OS_WINCE
  319. BOOL CPropDisplay::OnUpdateResTrackBar(HWND hwndPropPage)
  320. {
  321. DC_BEGIN_FN("OnUpdateResTrackBar");
  322. HWND hwndResTrackBar = GetDlgItem( hwndPropPage, IDC_RES_SLIDER);
  323. int maxRes = (int)SendMessage( hwndResTrackBar, TBM_GETRANGEMAX, TRUE, 0);
  324. int iRes = (int)SendMessage( hwndResTrackBar, TBM_GETPOS, 0, 0);
  325. if(iRes == maxRes)
  326. {
  327. //rightmost setting, display 'fullscreen'
  328. SetDlgItemText( hwndPropPage, IDC_LABEL_SCREENRES,
  329. _szFullScreen);
  330. }
  331. else
  332. {
  333. LPTSTR szResString = NULL;
  334. TRC_ASSERT( iRes < NUM_SCREENRES,
  335. (TB,_T("Track bar gives out of range screen res:%d"),
  336. iRes));
  337. if(iRes < NUM_SCREENRES)
  338. {
  339. INT res[2];
  340. res[0] = _screenResTable[iRes].width;
  341. res[1] = _screenResTable[iRes].height;
  342. szResString = CSH::FormatMessageVArgs(_szScreenRes,
  343. res[0],
  344. res[1] );
  345. if (szResString)
  346. {
  347. SetDlgItemText( hwndPropPage, IDC_LABEL_SCREENRES,
  348. szResString);
  349. LocalFree(szResString);
  350. szResString = NULL;
  351. }
  352. else
  353. {
  354. TRC_ERR((TB,_T("FormatMessage failed 0x%x"),
  355. GetLastError()));
  356. }
  357. }
  358. }
  359. DC_END_FN();
  360. return TRUE;
  361. }
  362. #endif
  363. BOOL CPropDisplay::OnUpdateColorCombo(HWND hwndPropPage)
  364. {
  365. //
  366. // Update the color picker
  367. //
  368. HWND hwndColorCombo = GetDlgItem( hwndPropPage, IDC_COMBO_COLOR_DEPTH);
  369. int curColorSel = SendMessage( (HWND)hwndColorCombo, CB_GETCURSEL, 0, 0);
  370. UINT screenBpp = 0;
  371. if(curColorSel >= 0 && curColorSel < NUM_COLORSTRINGS)
  372. {
  373. int bmpResID = g_ColorStringTable[curColorSel].bitmapResID;
  374. HBITMAP hbm = NULL;
  375. screenBpp = CSH::SH_GetScreenBpp();
  376. if(screenBpp <= 8)
  377. {
  378. //
  379. // Low color
  380. //
  381. bmpResID = g_ColorStringTable[curColorSel].bitmapLowColorResID;
  382. }
  383. #ifdef OS_WINCE
  384. hbm = (HBITMAP)LoadImage(_hInstance,
  385. MAKEINTRESOURCE(bmpResID),
  386. IMAGE_BITMAP,
  387. 0, 0, 0);
  388. #else
  389. hbm = (HBITMAP)LoadImage(_hInstance,
  390. MAKEINTRESOURCE(bmpResID),
  391. IMAGE_BITMAP,
  392. 0, 0, LR_CREATEDIBSECTION);
  393. #endif
  394. if (hbm)
  395. {
  396. HBITMAP hbmOld = (HBITMAP) SendDlgItemMessage(hwndPropPage,
  397. IDC_COLORPREVIEW, STM_SETIMAGE,
  398. IMAGE_BITMAP, (LPARAM)hbm);
  399. //
  400. // Flag that we've switched this to allow
  401. // proper cleanup on dialog termination
  402. //
  403. _fSwitchedColorComboBmp = TRUE;
  404. if (hbmOld)
  405. {
  406. DeleteObject(hbmOld);
  407. }
  408. }
  409. }
  410. return TRUE;
  411. }
  412. //
  413. // Build the table of valid screen size settings
  414. // The table (_screenResTable) is the union of:
  415. // - entries of g_ScreenResolutions up to and including max resolution
  416. // - the system max resolution (if not present in g_ScreenResolutions)
  417. // - a fullscreen entry (max resolution in fullscreen)
  418. //
  419. void CPropDisplay::InitScreenResTable()
  420. {
  421. DC_BEGIN_FN("InitScreenResTable");
  422. RECT rcMaxScreen;
  423. _numScreenResOptions = 0;
  424. int xMaxSize = 0;
  425. int yMaxSize = 0;
  426. if (CSH::GetLargestMonitorRect(&rcMaxScreen))
  427. {
  428. xMaxSize = rcMaxScreen.right - rcMaxScreen.left;
  429. yMaxSize = rcMaxScreen.bottom - rcMaxScreen.top;
  430. }
  431. else
  432. {
  433. xMaxSize = GetSystemMetrics(SM_CXSCREEN);
  434. yMaxSize = GetSystemMetrics(SM_CYSCREEN);
  435. }
  436. xMaxSize = xMaxSize > MAX_DESKTOP_WIDTH ? MAX_DESKTOP_WIDTH : xMaxSize;
  437. yMaxSize = yMaxSize > MAX_DESKTOP_HEIGHT ? MAX_DESKTOP_HEIGHT : yMaxSize;
  438. BOOL bAddedLargest = FALSE;
  439. for(int i=0; i<NUM_SCREENRES; i++)
  440. {
  441. if(g_ScreenResolutions[i].width > xMaxSize ||
  442. g_ScreenResolutions[i].height > yMaxSize)
  443. {
  444. break;
  445. }
  446. else if (g_ScreenResolutions[i].width == xMaxSize &&
  447. g_ScreenResolutions[i].height == yMaxSize)
  448. {
  449. bAddedLargest = TRUE;
  450. }
  451. _screenResTable[i].width = g_ScreenResolutions[i].width;
  452. _screenResTable[i].height = g_ScreenResolutions[i].height;
  453. _numScreenResOptions++;
  454. }
  455. if(!bAddedLargest)
  456. {
  457. //Screen size is not in the table so add it
  458. _screenResTable[_numScreenResOptions].width = xMaxSize;
  459. _screenResTable[_numScreenResOptions].height = yMaxSize;
  460. _numScreenResOptions++;
  461. }
  462. //
  463. // Now add an entry for fullscreen
  464. //
  465. _screenResTable[_numScreenResOptions].width = xMaxSize;
  466. _screenResTable[_numScreenResOptions].height = yMaxSize;
  467. _numScreenResOptions++;
  468. DC_END_FN();
  469. }
  470. void CPropDisplay::InitColorCombo(HWND hwndPropPage)
  471. {
  472. DC_BEGIN_FN("InitColorCombo");
  473. HDC hdc = GetDC(NULL);
  474. TRC_ASSERT((NULL != hdc), (TB,_T("Failed to get DC")));
  475. int screenBpp = 8;
  476. if(hdc)
  477. {
  478. screenBpp = GetDeviceCaps(hdc, BITSPIXEL);
  479. TRC_NRM((TB, _T("HDC %p has %u bpp"), hdc, screenBpp));
  480. ReleaseDC(NULL, hdc);
  481. }
  482. //
  483. // We support only 256 color or higher, so on 16 color, we will
  484. // display 256 color
  485. //
  486. if (screenBpp < 8) {
  487. screenBpp = 8;
  488. }
  489. int selectedBpp = _pTscSet->GetColorDepth();
  490. int selectedBppIdx = 0;
  491. //
  492. // This call can be used to re-intialize a combo
  493. // so delete any items first
  494. //
  495. #ifndef OS_WINCE
  496. INT ret = 1;
  497. while(ret && ret != CB_ERR)
  498. {
  499. ret = SendDlgItemMessage(hwndPropPage,
  500. IDC_COMBO_COLOR_DEPTH,
  501. CBEM_DELETEITEM,
  502. 0,0);
  503. }
  504. #else
  505. SendDlgItemMessage(hwndPropPage, IDC_COMBO_COLOR_DEPTH, CB_RESETCONTENT, 0, 0);
  506. #endif
  507. for(int i=0; i<NUM_COLORSTRINGS; i++)
  508. {
  509. if(g_ColorStringTable[i].bpp > screenBpp)
  510. {
  511. break;
  512. }
  513. else
  514. {
  515. if(selectedBpp == g_ColorStringTable[i].bpp)
  516. {
  517. selectedBppIdx = i;
  518. }
  519. SendDlgItemMessage(hwndPropPage,
  520. IDC_COMBO_COLOR_DEPTH,
  521. CB_ADDSTRING,
  522. 0,
  523. (LPARAM)(PDCTCHAR)g_ColorStringTable[i].szString);
  524. }
  525. }
  526. SendDlgItemMessage(hwndPropPage, IDC_COMBO_COLOR_DEPTH,CB_SETCURSEL,
  527. (WPARAM)selectedBppIdx,0);
  528. DC_END_FN();
  529. }