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.

217 lines
6.0 KiB

  1. //
  2. //
  3. //
  4. #include "stdafx.h"
  5. #include "CacheOpt.h"
  6. LRESULT
  7. CCacheOptPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  8. {
  9. if (NULL == m_pData)
  10. {
  11. ASSERT(FALSE);
  12. ::EndDialog(hDlg, 0);
  13. return -1;
  14. }
  15. m_bInitDone = FALSE;
  16. DoDataExchange();
  17. m_FileChooser.Init(this,
  18. FC_DIRECTORY_ONLY | FC_FORWRITE, IDC_CACHE_PATH, IDC_BROWSE);
  19. CString title;
  20. if (title.LoadString(_Module.GetResourceInstance(), IDS_SELECT_CACHE_PATH))
  21. m_FileChooser.SetDialogTitle(title);
  22. m_FileChooser.SetPath(m_pData->m_DiskCacheDir);
  23. UDACCEL toAcc[3] = {{1, 1}, {3, 5}, {6, 10}};
  24. m_eng_cache.SetRange32(0, 0x7fffffff);
  25. m_eng_cache.SetPos32(m_pData->m_ScriptEngCacheMax);
  26. m_eng_cache.SetAccel(3, toAcc);
  27. m_cache_size.SetRange32(0, 0x7fffffff);
  28. m_cache_size.SetPos32(m_pData->m_TotalCacheSize);
  29. m_cache_size.SetAccel(3, toAcc);
  30. m_inmem_unlim.SetRange32(0, m_pData->m_TotalCacheSize);
  31. m_inmem_unlim.SetPos32(m_pData->m_UnlimCacheInMemorySize);
  32. m_inmem_unlim.SetAccel(3, toAcc);
  33. m_inmem_lim.SetRange32(0, m_pData->m_TotalCacheSize);
  34. m_inmem_lim.SetPos32(m_pData->m_LimCacheInMemorySize);
  35. m_inmem_lim.SetAccel(3, toAcc);
  36. UINT id = IDC_UNLIMITED_CACHE;
  37. if (m_pData->m_NoCache)
  38. id = IDC_NO_CACHE;
  39. else if (m_pData->m_LimCache)
  40. id = IDC_LIMITED_CACHE;
  41. OnCacheSwitch(0, id, NULL);
  42. AdjustTracker();
  43. DoDataExchange();
  44. m_bInitDone = TRUE;
  45. return FALSE;
  46. };
  47. BOOL
  48. CCacheOptPage::OnKillActive()
  49. {
  50. if (m_bInitDone)
  51. {
  52. DoDataExchange(TRUE);
  53. if (m_pData->m_LimCache)
  54. {
  55. if (m_pData->m_LimCacheInMemorySize > m_pData->m_TotalCacheSize)
  56. {
  57. ::SetFocus(GetDlgItem(IDC_INMEM_LIM_EDIT));
  58. return FALSE;
  59. }
  60. }
  61. CString buf;
  62. if (FC_SUCCESS != m_FileChooser.GetFileName(buf))
  63. return FALSE;
  64. DWORD attr = ::GetFileAttributes(buf);
  65. if (-1 == (int)attr)
  66. {
  67. CError err(GetLastError());
  68. err.MessageBox(MB_OK);
  69. ::SetFocus(GetDlgItem(IDC_CACHE_PATH));
  70. SendDlgItemMessage(IDC_CACHE_PATH, EM_SETSEL, 0, -1);
  71. return FALSE;
  72. }
  73. if ( (attr & FILE_ATTRIBUTE_READONLY) != 0
  74. || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0
  75. || PathIsNetworkPath(buf)
  76. )
  77. {
  78. CString cap, msg;
  79. cap.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  80. msg.LoadString(_Module.GetResourceInstance(), IDS_READ_ONLY_DIRECTORY);
  81. SendDlgItemMessage(IDC_CACHE_PATH, EM_SETSEL, 0, -1);
  82. MessageBox(msg, cap);
  83. ::SetFocus(GetDlgItem(IDC_CACHE_PATH));
  84. return FALSE;
  85. }
  86. StrCpy(m_pData->m_DiskCacheDir, buf);
  87. }
  88. return TRUE;
  89. }
  90. void
  91. CCacheOptPage::OnCacheSwitch(UINT, UINT nID, HWND)
  92. {
  93. switch (nID)
  94. {
  95. case IDC_NO_CACHE:
  96. m_pData->m_NoCache = TRUE;
  97. m_pData->m_UnlimCache = FALSE;
  98. m_pData->m_LimCache = FALSE;
  99. break;
  100. case IDC_UNLIMITED_CACHE:
  101. m_pData->m_NoCache = FALSE;
  102. m_pData->m_UnlimCache = TRUE;
  103. m_pData->m_LimCache = FALSE;
  104. break;
  105. case IDC_LIMITED_CACHE:
  106. m_pData->m_NoCache = FALSE;
  107. m_pData->m_UnlimCache = FALSE;
  108. m_pData->m_LimCache = TRUE;
  109. break;
  110. }
  111. m_NoCacheBtn.SetCheck(m_pData->m_NoCache);
  112. m_UnlimCacheBtn.SetCheck(m_pData->m_UnlimCache);
  113. m_LimCacheBtn.SetCheck(m_pData->m_LimCache);
  114. m_inmem_unlim.EnableWindow(m_pData->m_UnlimCache);
  115. ::EnableWindow(GetDlgItem(IDC_INMEM_UNLIM_EDIT), m_pData->m_UnlimCache);
  116. m_inmem_lim.EnableWindow(m_pData->m_LimCache);
  117. ::EnableWindow(GetDlgItem(IDC_INMEM_LIM_EDIT), m_pData->m_LimCache);
  118. m_cache_size.EnableWindow(m_pData->m_LimCache);
  119. ::EnableWindow(GetDlgItem(IDC_CACHE_SIZE_EDIT), m_pData->m_LimCache);
  120. m_cache_dist.EnableWindow(m_pData->m_LimCache);
  121. SET_MODIFIED(TRUE);
  122. }
  123. void
  124. CCacheOptPage::OnChangeCacheSize(UINT nCode, UINT nID, HWND)
  125. {
  126. if (::IsWindow(m_cache_dist.m_hWnd) && m_bInitDone)
  127. {
  128. DoDataExchange(TRUE, IDC_CACHE_SIZE_EDIT);
  129. AdjustTracker();
  130. m_inmem_lim.SetRange32(0, m_pData->m_TotalCacheSize);
  131. // Here we could adjust in memory size to be less or equal to the total size,
  132. // but I decided that it could be annoying: what if user deleted last zero
  133. // in total size control, and in memory size turned to be larger than total size.
  134. // We immediately will cut it to total, and to fix this mistake user will need
  135. // to touch two places. It will be too bad.
  136. SET_MODIFIED(TRUE);
  137. }
  138. }
  139. void
  140. CCacheOptPage::OnChangeInmemCacheSize(UINT nCode, UINT nID, HWND)
  141. {
  142. if (::IsWindow(m_cache_dist.m_hWnd) && m_bInitDone)
  143. {
  144. DoDataExchange(TRUE, nID);
  145. AdjustTracker();
  146. SET_MODIFIED(TRUE);
  147. }
  148. }
  149. void
  150. CCacheOptPage::OnTrackBarScroll(UINT nSBCode, UINT nPos, HWND hwnd)
  151. {
  152. BOOL bChange = FALSE;
  153. switch (nSBCode)
  154. {
  155. case SB_THUMBPOSITION:
  156. m_pData->m_LimCacheInMemorySize = nPos;
  157. bChange = TRUE;
  158. break;
  159. case SB_LINELEFT:
  160. m_pData->m_LimCacheInMemorySize -= m_cache_dist.GetLineSize();
  161. bChange = TRUE;
  162. break;
  163. case SB_LINERIGHT:
  164. m_pData->m_LimCacheInMemorySize += m_cache_dist.GetLineSize();
  165. bChange = TRUE;
  166. break;
  167. case SB_PAGELEFT:
  168. m_pData->m_LimCacheInMemorySize -= m_cache_dist.GetPageSize();
  169. bChange = TRUE;
  170. break;
  171. case SB_PAGERIGHT:
  172. m_pData->m_LimCacheInMemorySize += m_cache_dist.GetPageSize();
  173. bChange = TRUE;
  174. break;
  175. case SB_THUMBTRACK:
  176. case SB_LEFT:
  177. case SB_RIGHT:
  178. case SB_ENDSCROLL:
  179. break;
  180. }
  181. if (bChange)
  182. {
  183. DoDataExchange(FALSE, IDC_INMEM_LIM_EDIT);
  184. SET_MODIFIED(TRUE);
  185. }
  186. }
  187. void
  188. CCacheOptPage::AdjustTracker()
  189. {
  190. if (::IsWindow(m_cache_dist.m_hWnd))
  191. {
  192. m_cache_dist.SetRange(0, m_pData->m_TotalCacheSize, TRUE);
  193. m_cache_dist.SetPos(m_pData->m_LimCacheInMemorySize);
  194. m_cache_dist.SetPageSize(m_pData->m_TotalCacheSize / 10);
  195. m_cache_dist.SetLineSize(m_pData->m_TotalCacheSize / 25);
  196. m_cache_dist.SetTicFreq(m_pData->m_TotalCacheSize / 25);
  197. }
  198. }