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.

673 lines
18 KiB

  1. //
  2. // propperf.cpp: local resources property sheet dialog proc
  3. //
  4. // Tab E
  5. //
  6. // Copyright Microsoft Corporation 2000
  7. // nadima
  8. #include "stdafx.h"
  9. #define TRC_GROUP TRC_GROUP_UI
  10. #define TRC_FILE "propperf"
  11. #include <atrcapi.h>
  12. #include "sh.h"
  13. #include "commctrl.h"
  14. #include "propperf.h"
  15. CPropPerf* CPropPerf::_pPropPerfInstance = NULL;
  16. //
  17. // Lookup tables
  18. //
  19. //
  20. // Controls that need to be disabled/enabled
  21. // during connection (for progress animation)
  22. //
  23. CTL_ENABLE connectingDisableCtlsPPerf[] = {
  24. {UI_IDC_STATIC_CHOOSE_SPEED, FALSE},
  25. {IDC_COMBO_PERF_OPTIMIZE, FALSE},
  26. {UI_IDC_STATIC_OPTIMIZE_PERF, FALSE},
  27. {IDC_CHECK_DESKTOP_BKND, FALSE},
  28. {IDC_CHECK_SHOW_FWD, FALSE},
  29. {IDC_CHECK_MENU_ANIMATIONS, FALSE},
  30. {IDC_CHECK_THEMES, FALSE},
  31. {IDC_CHECK_BITMAP_CACHING, FALSE},
  32. {IDC_CHECK_ENABLE_ARC, FALSE}
  33. };
  34. const UINT numConnectingDisableCtlsPPerf =
  35. sizeof(connectingDisableCtlsPPerf)/
  36. sizeof(connectingDisableCtlsPPerf[0]);
  37. //
  38. // MAP from optimization level to disabled feature list
  39. // Disabled features list
  40. //
  41. // Index is the optimization level, entry is the disabled feature list
  42. //
  43. DWORD g_dwMapOptLevelToDisabledList[NUM_PERF_OPTIMIZATIONS] =
  44. {
  45. // 28K
  46. TS_PERF_DISABLE_WALLPAPER |
  47. TS_PERF_DISABLE_FULLWINDOWDRAG |
  48. TS_PERF_DISABLE_MENUANIMATIONS |
  49. TS_PERF_DISABLE_THEMING,
  50. // 56K
  51. TS_PERF_DISABLE_WALLPAPER |
  52. TS_PERF_DISABLE_FULLWINDOWDRAG |
  53. TS_PERF_DISABLE_MENUANIMATIONS,
  54. // Broadband
  55. TS_PERF_DISABLE_WALLPAPER,
  56. // LAN
  57. TS_PERF_DISABLE_NOTHING,
  58. //
  59. // CUSTOM (defaults to same as 56K
  60. // 56K
  61. //
  62. // NOTE: This value gets changed at runtime
  63. // to reflect the current custom settings
  64. //
  65. TS_PERF_DISABLE_WALLPAPER |
  66. TS_PERF_DISABLE_FULLWINDOWDRAG |
  67. TS_PERF_DISABLE_MENUANIMATIONS
  68. };
  69. //
  70. // Mask of flags that can be set by checkboxes
  71. //
  72. #define CHECK_BOX_PERF_MASK (TS_PERF_DISABLE_WALLPAPER | \
  73. TS_PERF_DISABLE_FULLWINDOWDRAG | \
  74. TS_PERF_DISABLE_MENUANIMATIONS | \
  75. TS_PERF_DISABLE_THEMING | \
  76. TS_PERF_DISABLE_BITMAPCACHING | \
  77. TS_PERF_DISABLE_CURSORSETTINGS) \
  78. CPropPerf::CPropPerf(HINSTANCE hInstance, CTscSettings* pTscSet, CSH* pSh)
  79. {
  80. DC_BEGIN_FN("CPropPerf");
  81. _hInstance = hInstance;
  82. CPropPerf::_pPropPerfInstance = this;
  83. _pTscSet = pTscSet;
  84. _hwndDlg = NULL;
  85. _fSyncingCheckboxes = FALSE;
  86. _pSh = pSh;
  87. TRC_ASSERT(_pTscSet,(TB,_T("_pTscSet is null")));
  88. TRC_ASSERT(_pSh,(TB,_T("_pSh is null")));
  89. DC_END_FN();
  90. }
  91. CPropPerf::~CPropPerf()
  92. {
  93. CPropPerf::_pPropPerfInstance = NULL;
  94. }
  95. INT_PTR CALLBACK CPropPerf::StaticPropPgPerfDialogProc(HWND hwndDlg,
  96. UINT uMsg,
  97. WPARAM wParam,
  98. LPARAM lParam)
  99. {
  100. //
  101. // Delegate to appropriate instance (only works for single instance dialogs)
  102. //
  103. DC_BEGIN_FN("StaticDialogBoxProc");
  104. DCINT retVal = 0;
  105. TRC_ASSERT(_pPropPerfInstance, (TB,
  106. _T("perf dialog has NULL static instance ptr\n")));
  107. retVal = _pPropPerfInstance->PropPgPerfDialogProc( hwndDlg,
  108. uMsg,
  109. wParam,
  110. lParam);
  111. DC_END_FN();
  112. return retVal;
  113. }
  114. INT_PTR CALLBACK CPropPerf::PropPgPerfDialogProc (HWND hwndDlg,
  115. UINT uMsg,
  116. WPARAM wParam,
  117. LPARAM lParam)
  118. {
  119. DC_BEGIN_FN("PropPgPerfDialogProc");
  120. switch(uMsg)
  121. {
  122. case WM_INITDIALOG:
  123. {
  124. #ifndef OS_WINCE
  125. int i;
  126. #endif
  127. _hwndDlg = hwndDlg;
  128. //
  129. // Position the dialog within the tab
  130. //
  131. SetWindowPos( hwndDlg, HWND_TOP,
  132. _rcTabDispayArea.left, _rcTabDispayArea.top,
  133. _rcTabDispayArea.right - _rcTabDispayArea.left,
  134. _rcTabDispayArea.bottom - _rcTabDispayArea.top,
  135. 0);
  136. InitPerfCombo();
  137. SyncCheckBoxesToPerfFlags(
  138. _pTscSet->GetPerfFlags());
  139. //
  140. // AutoReconnection checkbox
  141. //
  142. CheckDlgButton(hwndDlg, IDC_CHECK_ENABLE_ARC,
  143. _pTscSet->GetEnableArc() ?
  144. BST_CHECKED : BST_UNCHECKED);
  145. _pSh->SH_ThemeDialogWindow(hwndDlg, ETDT_ENABLETAB);
  146. return TRUE;
  147. }
  148. break; //WM_INITDIALOG
  149. case WM_TSC_ENABLECONTROLS:
  150. {
  151. //
  152. // wParam is TRUE to enable controls,
  153. // FALSE to disable them
  154. //
  155. CSH::EnableControls( hwndDlg,
  156. connectingDisableCtlsPPerf,
  157. numConnectingDisableCtlsPPerf,
  158. wParam ? TRUE : FALSE);
  159. }
  160. break;
  161. case WM_SAVEPROPSHEET: //Intentional fallthru
  162. case WM_DESTROY:
  163. {
  164. BOOL fEnableArc;
  165. //
  166. // Save page settings
  167. //
  168. DWORD dwCheckBoxPerfFlags = GetPerfFlagsFromCheckboxes();
  169. DWORD dwPerfFlags = MergePerfFlags( dwCheckBoxPerfFlags,
  170. _pTscSet->GetPerfFlags(),
  171. CHECK_BOX_PERF_MASK );
  172. fEnableArc = IsDlgButtonChecked(hwndDlg, IDC_CHECK_ENABLE_ARC);
  173. _pTscSet->SetEnableArc(fEnableArc);
  174. _pTscSet->SetPerfFlags(dwPerfFlags);
  175. }
  176. break; //WM_DESTROY
  177. case WM_COMMAND:
  178. {
  179. switch(DC_GET_WM_COMMAND_ID(wParam))
  180. {
  181. case IDC_COMBO_PERF_OPTIMIZE:
  182. {
  183. if(HIWORD(wParam) == CBN_SELCHANGE)
  184. {
  185. OnPerfComboSelChange();
  186. }
  187. }
  188. break;
  189. default:
  190. {
  191. if (HIWORD(wParam) == BN_CLICKED)
  192. {
  193. //
  194. // One of the checkboxes has been checked
  195. // (prevent recursive looping due to feedback)
  196. //
  197. if (!_fSyncingCheckboxes)
  198. {
  199. OnCheckBoxStateChange((int)LOWORD(wParam));
  200. }
  201. }
  202. }
  203. break;
  204. }
  205. }
  206. break;
  207. }
  208. DC_END_FN();
  209. return 0;
  210. }
  211. BOOL CPropPerf::InitPerfCombo()
  212. {
  213. INT ret = 1;
  214. DC_BEGIN_FN("InitPerfCombo");
  215. TRC_ASSERT(g_fPropPageStringMapInitialized,
  216. (TB,_T("Perf strings not loaded")));
  217. TRC_ASSERT(_hwndDlg,
  218. (TB,_T("_hwndDlg not set")));
  219. if (!g_fPropPageStringMapInitialized)
  220. {
  221. return FALSE;
  222. }
  223. #ifndef OS_WINCE
  224. while (ret && ret != CB_ERR)
  225. {
  226. ret = SendDlgItemMessage(_hwndDlg,
  227. IDC_COMBO_PERF_OPTIMIZE,
  228. CBEM_DELETEITEM,
  229. 0,0);
  230. }
  231. #else
  232. SendDlgItemMessage(_hwndDlg, IDC_COMBO_PERF_OPTIMIZE, CB_RESETCONTENT, 0, 0);
  233. #endif
  234. //
  235. // Only set up to the last but one string in the table
  236. // as the last string is only used in the perf page
  237. //
  238. for (int i=0; i<NUM_PERF_OPTIMIZATIONS+1; i++)
  239. {
  240. if (NUM_PERF_OPTIMIZATIONS-1 == i)
  241. {
  242. //
  243. // Skip the last but one string it's the
  244. // custom entry for the main dialog
  245. //
  246. continue;
  247. }
  248. SendDlgItemMessage(_hwndDlg,
  249. IDC_COMBO_PERF_OPTIMIZE,
  250. CB_ADDSTRING,
  251. 0,
  252. (LPARAM)(PDCTCHAR)g_PerfOptimizeStringTable[i].szString);
  253. }
  254. //
  255. // Set the optimization level according to the disabled feature list
  256. //
  257. DWORD dwPerfFlags = _pTscSet->GetPerfFlags();
  258. int optLevel = MapPerfFlagsToOptLevel(dwPerfFlags);
  259. TRC_ASSERT(optLevel >= 0 && optLevel < NUM_PERF_OPTIMIZATIONS,
  260. (TB,_T("optlevel %d out of range"), optLevel));
  261. SendDlgItemMessage(_hwndDlg, IDC_COMBO_PERF_OPTIMIZE,CB_SETCURSEL,
  262. (WPARAM)optLevel,0);
  263. DC_END_FN();
  264. return TRUE;
  265. }
  266. //
  267. // Notification that the perf combo's selection has changed
  268. //
  269. VOID CPropPerf::OnPerfComboSelChange()
  270. {
  271. int curSel = 0;
  272. DWORD dwDisableFeatureList = 0;
  273. DC_BEGIN_FN("OnPerfComboSelChange");
  274. //
  275. // Figure out what the new selected item is
  276. //
  277. curSel = SendDlgItemMessage(_hwndDlg,
  278. IDC_COMBO_PERF_OPTIMIZE,
  279. CB_GETCURSEL,
  280. 0,0);
  281. if (curSel < 0)
  282. {
  283. curSel = 0;
  284. }
  285. TRC_ASSERT(curSel < NUM_PERF_OPTIMIZATIONS,
  286. (TB,_T("curSel (%d) > NUM_PERF_OPTIMIZATIONS (%d)"),
  287. curSel,NUM_PERF_OPTIMIZATIONS));
  288. if (curSel >= NUM_PERF_OPTIMIZATIONS)
  289. {
  290. curSel = NUM_PERF_OPTIMIZATIONS - 1;
  291. }
  292. //
  293. // Map that to a list of disabled features
  294. //
  295. dwDisableFeatureList = MapOptimizationLevelToPerfFlags(curSel);
  296. //
  297. // Check and uncheck the checkboxes
  298. //
  299. SyncCheckBoxesToPerfFlags(dwDisableFeatureList);
  300. DC_END_FN();
  301. }
  302. //
  303. // Static method. Maps an optimization to the disabled feature list
  304. // (packed in a DWORD)
  305. // Params:
  306. // [in] optLevel - optimization level from 0 to NUM_PERF_OPTIMIZATIONS-1
  307. // [return] DWORD feature list
  308. //
  309. DWORD CPropPerf::MapOptimizationLevelToPerfFlags(int optLevel)
  310. {
  311. DWORD dwPerfFlags = 0;
  312. DC_BEGIN_FN("MapOptimizationLevelToPerfFlags");
  313. if (optLevel < 0)
  314. {
  315. TRC_ERR((TB,_T("Opt level out of range %d"),optLevel));
  316. optLevel = 0;
  317. }
  318. if (optLevel >= NUM_PERF_OPTIMIZATIONS)
  319. {
  320. TRC_ERR((TB,_T("Opt level out of range %d"),optLevel));
  321. optLevel = NUM_PERF_OPTIMIZATIONS - 1;
  322. }
  323. dwPerfFlags = g_dwMapOptLevelToDisabledList[optLevel];
  324. TRC_NRM((TB,_T("Return disable list 0x%x"),dwPerfFlags));
  325. DC_END_FN();
  326. return dwPerfFlags;
  327. }
  328. //
  329. // Toggles checkboxes to match the disabled feature list
  330. // NOTE: the checkboxes represent 'enabled' features i.e the negation
  331. // of the list
  332. //
  333. VOID CPropPerf::SyncCheckBoxesToPerfFlags(DWORD dwPerfFlagss)
  334. {
  335. DC_BEGIN_FN("SyncCheckBoxesToPerfFlags");
  336. //
  337. // Prevent recursive sets based on change notifications
  338. // for the checkboxes (As they could change the combo leading
  339. // to a subsequent change in the checkboxes, etc...)
  340. //
  341. _fSyncingCheckboxes = TRUE;
  342. //
  343. // Wallpaper (Desktop background)
  344. //
  345. CheckDlgButton(_hwndDlg, IDC_CHECK_DESKTOP_BKND,
  346. (dwPerfFlagss & TS_PERF_DISABLE_WALLPAPER ?
  347. BST_UNCHECKED : BST_CHECKED));
  348. //
  349. // Fullwindow drag
  350. //
  351. CheckDlgButton(_hwndDlg, IDC_CHECK_SHOW_FWD,
  352. (dwPerfFlagss & TS_PERF_DISABLE_FULLWINDOWDRAG ?
  353. BST_UNCHECKED : BST_CHECKED));
  354. //
  355. // Menu animations
  356. //
  357. CheckDlgButton(_hwndDlg, IDC_CHECK_MENU_ANIMATIONS,
  358. (dwPerfFlagss & TS_PERF_DISABLE_MENUANIMATIONS ?
  359. BST_UNCHECKED : BST_CHECKED));
  360. //
  361. // Theming
  362. //
  363. CheckDlgButton(_hwndDlg, IDC_CHECK_THEMES,
  364. (dwPerfFlagss & TS_PERF_DISABLE_THEMING ?
  365. BST_UNCHECKED : BST_CHECKED));
  366. //
  367. // Bitmap caching
  368. //
  369. CheckDlgButton(_hwndDlg, IDC_CHECK_BITMAP_CACHING,
  370. (dwPerfFlagss & TS_PERF_DISABLE_BITMAPCACHING ?
  371. BST_UNCHECKED : BST_CHECKED));
  372. _fSyncingCheckboxes = FALSE;
  373. DC_END_FN();
  374. }
  375. //
  376. // Maps the disabled feature list to the appropriate optimization level
  377. //
  378. INT CPropPerf::MapPerfFlagsToOptLevel(DWORD dwPerfFlags)
  379. {
  380. DC_BEGIN_FN("MapPerfFlagsToOptLevel");
  381. for (int i=0;i<NUM_PERF_OPTIMIZATIONS;i++)
  382. {
  383. if (g_dwMapOptLevelToDisabledList[i] == dwPerfFlags)
  384. {
  385. return i;
  386. }
  387. }
  388. DC_END_FN();
  389. //
  390. // Didn't find an entry so return the last optimization level (custom)
  391. //
  392. return (NUM_PERF_OPTIMIZATIONS-1);
  393. }
  394. //
  395. // Called whenever a checkbox's state changes (Checked or unchecked)
  396. //
  397. //
  398. VOID CPropPerf::OnCheckBoxStateChange(int checkBoxID)
  399. {
  400. DWORD dwCheckBoxPerfFlags = 0;
  401. DWORD dwPerfFlags = 0;
  402. int optLevel = 0;
  403. int curSel = 0;
  404. DC_BEGIN_FN("OnCheckBoxStateChange");
  405. //
  406. // Pickup the current disabled feature list from the
  407. // checkboxes
  408. //
  409. dwCheckBoxPerfFlags = GetPerfFlagsFromCheckboxes();
  410. dwPerfFlags = MergePerfFlags( dwCheckBoxPerfFlags,
  411. _pTscSet->GetPerfFlags(),
  412. CHECK_BOX_PERF_MASK );
  413. //
  414. // Figure out the optimization level
  415. //
  416. optLevel = MapPerfFlagsToOptLevel(dwPerfFlags);
  417. TRC_ASSERT(optLevel >= 0 && optLevel < NUM_PERF_OPTIMIZATIONS,
  418. (TB,_T("optlevel %d out of range"), optLevel));
  419. //
  420. // If the combo is at a different opt level then switch it to
  421. // the new level
  422. //
  423. curSel = SendDlgItemMessage(_hwndDlg,
  424. IDC_COMBO_PERF_OPTIMIZE,
  425. CB_GETCURSEL,
  426. 0,0);
  427. //
  428. // Update the custom disabled list based on the current
  429. // settings
  430. //
  431. UpdateCustomDisabledList(dwPerfFlags);
  432. if (curSel != optLevel)
  433. {
  434. SendDlgItemMessage(_hwndDlg, IDC_COMBO_PERF_OPTIMIZE,CB_SETCURSEL,
  435. (WPARAM)optLevel,0);
  436. }
  437. DC_END_FN();
  438. }
  439. //
  440. // Queries the checkboxes and returns the disabled feature list
  441. // as a DWORD of flags
  442. //
  443. DWORD CPropPerf::GetPerfFlagsFromCheckboxes()
  444. {
  445. DWORD dwPerfFlags = 0;
  446. DC_BEGIN_FN("GetPerfFlagsFromCheckboxes");
  447. //
  448. // Wallpaper (Desktop background)
  449. //
  450. if (!IsDlgButtonChecked(_hwndDlg,IDC_CHECK_DESKTOP_BKND))
  451. {
  452. dwPerfFlags |= TS_PERF_DISABLE_WALLPAPER;
  453. }
  454. //
  455. // Fullwindow drag
  456. //
  457. if (!IsDlgButtonChecked(_hwndDlg,IDC_CHECK_SHOW_FWD))
  458. {
  459. dwPerfFlags |= TS_PERF_DISABLE_FULLWINDOWDRAG;
  460. }
  461. //
  462. // Menu animations
  463. //
  464. if (!IsDlgButtonChecked(_hwndDlg,IDC_CHECK_MENU_ANIMATIONS))
  465. {
  466. dwPerfFlags |= TS_PERF_DISABLE_MENUANIMATIONS;
  467. }
  468. //
  469. // Themeing
  470. //
  471. if (!IsDlgButtonChecked(_hwndDlg,IDC_CHECK_THEMES))
  472. {
  473. dwPerfFlags |= TS_PERF_DISABLE_THEMING;
  474. }
  475. //
  476. // Bitmap caching
  477. //
  478. if (!IsDlgButtonChecked(_hwndDlg,IDC_CHECK_BITMAP_CACHING))
  479. {
  480. dwPerfFlags |= TS_PERF_DISABLE_BITMAPCACHING;
  481. }
  482. TRC_NRM((TB,_T("Return disable list 0x%x"),dwPerfFlags));
  483. DC_END_FN();
  484. return dwPerfFlags;
  485. }
  486. //
  487. // Called to initialize the 'custom' disabled property
  488. // list (e.g called at initialization time or after loading
  489. // new settings
  490. //
  491. VOID CPropPerf::UpdateCustomDisabledList(DWORD dwPerfFlags)
  492. {
  493. DC_BEGIN_FN("InitCustomDisabledList");
  494. //
  495. //
  496. //
  497. INT optLevel = MapPerfFlagsToOptLevel(dwPerfFlags);
  498. if (CUSTOM_OPTIMIZATION_LEVEL == optLevel)
  499. {
  500. //
  501. // Store this as the new set of custom settings
  502. //
  503. TRC_NRM((TB,_T("Recording new custom setting: 0x%x"),
  504. dwPerfFlags));
  505. g_dwMapOptLevelToDisabledList[CUSTOM_OPTIMIZATION_LEVEL] =
  506. dwPerfFlags;
  507. }
  508. DC_END_FN();
  509. }
  510. BOOL CPropPerf::EnableCheckBoxes(BOOL fEnable)
  511. {
  512. DC_BEGIN_FN("EnableCheckBoxes");
  513. //
  514. // Wallpaper (Desktop background)
  515. //
  516. EnableWindow( GetDlgItem(_hwndDlg, IDC_CHECK_DESKTOP_BKND),
  517. fEnable );
  518. //
  519. // Fullwindow drag
  520. //
  521. EnableWindow( GetDlgItem(_hwndDlg, IDC_CHECK_SHOW_FWD),
  522. fEnable );
  523. //
  524. // Menu animations
  525. //
  526. EnableWindow( GetDlgItem(_hwndDlg, IDC_CHECK_MENU_ANIMATIONS),
  527. fEnable );
  528. //
  529. // Theming
  530. //
  531. EnableWindow( GetDlgItem(_hwndDlg, IDC_CHECK_THEMES),
  532. fEnable );
  533. //
  534. // Bitmap caching
  535. //
  536. EnableWindow( GetDlgItem(_hwndDlg, IDC_CHECK_BITMAP_CACHING),
  537. fEnable );
  538. //
  539. // Title static control
  540. //
  541. EnableWindow( GetDlgItem(_hwndDlg, UI_IDC_STATIC_OPTIMIZE_PERF),
  542. fEnable );
  543. DC_END_FN();
  544. return TRUE;
  545. }
  546. //
  547. // Merge perf flags from two sources
  548. // 1) dwCheckBoxFlags - flags that come from the checkboxes
  549. // 2) dwOrig set of passed in flags
  550. //
  551. // Use dwMask to preserve original flags that should not be affected
  552. // by the checkboxes
  553. //
  554. // return - merged flags
  555. //
  556. DWORD CPropPerf::MergePerfFlags(DWORD dwCheckBoxFlags,
  557. DWORD dwOrig,
  558. DWORD dwMask)
  559. {
  560. DWORD dwNewFlags;
  561. DC_BEGIN_FN("MergePerfFlags");
  562. dwNewFlags = (dwOrig & ~dwMask) | (dwCheckBoxFlags & dwMask);
  563. DC_END_FN();
  564. return dwNewFlags;
  565. }